storage: Move mock PreCommit helper to the mock package
This commit is contained in:
parent
6afb43afbb
commit
12c91bb41d
72
extern/sector-storage/mock/util.go
vendored
72
extern/sector-storage/mock/util.go
vendored
@ -1,5 +1,22 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-commp-utils/zerocomm"
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
"github.com/filecoin-project/go-state-types/builtin/v8/market"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/wallet/key"
|
||||
"github.com/filecoin-project/lotus/genesis"
|
||||
)
|
||||
|
||||
func CommDR(in []byte) (out [32]byte) {
|
||||
for i, b := range in {
|
||||
out[i] = ^b
|
||||
@ -7,3 +24,58 @@ func CommDR(in []byte) (out [32]byte) {
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func PreSeal(spt abi.RegisteredSealProof, maddr address.Address, sectors int) (*genesis.Miner, *types.KeyInfo, error) {
|
||||
k, err := key.GenerateKey(types.KTBLS)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
ssize, err := spt.SectorSize()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
genm := &genesis.Miner{
|
||||
ID: maddr,
|
||||
Owner: k.Address,
|
||||
Worker: k.Address,
|
||||
MarketBalance: big.NewInt(0),
|
||||
PowerBalance: big.NewInt(0),
|
||||
SectorSize: ssize,
|
||||
Sectors: make([]*genesis.PreSeal, sectors),
|
||||
}
|
||||
|
||||
for i := range genm.Sectors {
|
||||
label, err := market.NewLabelFromString(fmt.Sprintf("%d", i))
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("failed to create label: %w", err)
|
||||
}
|
||||
|
||||
preseal := &genesis.PreSeal{}
|
||||
|
||||
preseal.ProofType = spt
|
||||
preseal.CommD = zerocomm.ZeroPieceCommitment(abi.PaddedPieceSize(ssize).Unpadded())
|
||||
d, _ := commcid.CIDToPieceCommitmentV1(preseal.CommD)
|
||||
r := CommDR(d)
|
||||
preseal.CommR, _ = commcid.ReplicaCommitmentV1ToCID(r[:])
|
||||
preseal.SectorID = abi.SectorNumber(i + 1)
|
||||
preseal.Deal = market.DealProposal{
|
||||
PieceCID: preseal.CommD,
|
||||
PieceSize: abi.PaddedPieceSize(ssize),
|
||||
Client: k.Address,
|
||||
Provider: maddr,
|
||||
Label: label,
|
||||
StartEpoch: 1,
|
||||
EndEpoch: 10000,
|
||||
StoragePricePerEpoch: big.Zero(),
|
||||
ProviderCollateral: big.Zero(),
|
||||
ClientCollateral: big.Zero(),
|
||||
}
|
||||
preseal.DealClientKey = k
|
||||
|
||||
genm.Sectors[i] = preseal
|
||||
}
|
||||
|
||||
return genm, &k.KeyInfo, nil
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ import (
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
testing2 "github.com/filecoin-project/lotus/node/modules/testing"
|
||||
"github.com/filecoin-project/lotus/node/repo"
|
||||
"github.com/filecoin-project/lotus/storage/mockstorage"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -247,7 +246,7 @@ func (n *Ensemble) Miner(minerNode *TestMiner, full *TestFullNode, opts ...NodeO
|
||||
|
||||
// Create the preseal commitment.
|
||||
if n.options.mockProofs {
|
||||
genm, k, err = mockstorage.PreSeal(proofType, actorAddr, sectors)
|
||||
genm, k, err = mock.PreSeal(proofType, actorAddr, sectors)
|
||||
} else {
|
||||
genm, k, err = seed.PreSeal(actorAddr, proofType, 0, sectors, tdir, []byte("make genesis mem random"), nil, true)
|
||||
}
|
||||
|
@ -1,74 +0,0 @@
|
||||
package mockstorage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-commp-utils/zerocomm"
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/big"
|
||||
markettypes "github.com/filecoin-project/go-state-types/builtin/v8/market"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/wallet/key"
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/mock"
|
||||
"github.com/filecoin-project/lotus/genesis"
|
||||
)
|
||||
|
||||
func PreSeal(spt abi.RegisteredSealProof, maddr address.Address, sectors int) (*genesis.Miner, *types.KeyInfo, error) {
|
||||
k, err := key.GenerateKey(types.KTBLS)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
ssize, err := spt.SectorSize()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
genm := &genesis.Miner{
|
||||
ID: maddr,
|
||||
Owner: k.Address,
|
||||
Worker: k.Address,
|
||||
MarketBalance: big.NewInt(0),
|
||||
PowerBalance: big.NewInt(0),
|
||||
SectorSize: ssize,
|
||||
Sectors: make([]*genesis.PreSeal, sectors),
|
||||
}
|
||||
|
||||
for i := range genm.Sectors {
|
||||
label, err := markettypes.NewLabelFromString(fmt.Sprintf("%d", i))
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("failed to create label: %w", err)
|
||||
}
|
||||
|
||||
preseal := &genesis.PreSeal{}
|
||||
|
||||
preseal.ProofType = spt
|
||||
preseal.CommD = zerocomm.ZeroPieceCommitment(abi.PaddedPieceSize(ssize).Unpadded())
|
||||
d, _ := commcid.CIDToPieceCommitmentV1(preseal.CommD)
|
||||
r := mock.CommDR(d)
|
||||
preseal.CommR, _ = commcid.ReplicaCommitmentV1ToCID(r[:])
|
||||
preseal.SectorID = abi.SectorNumber(i + 1)
|
||||
preseal.Deal = markettypes.DealProposal{
|
||||
PieceCID: preseal.CommD,
|
||||
PieceSize: abi.PaddedPieceSize(ssize),
|
||||
Client: k.Address,
|
||||
Provider: maddr,
|
||||
Label: label,
|
||||
StartEpoch: 1,
|
||||
EndEpoch: 10000,
|
||||
StoragePricePerEpoch: big.Zero(),
|
||||
ProviderCollateral: big.Zero(),
|
||||
ClientCollateral: big.Zero(),
|
||||
}
|
||||
preseal.DealClientKey = k
|
||||
|
||||
genm.Sectors[i] = preseal
|
||||
}
|
||||
|
||||
return genm, &k.KeyInfo, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user