lotus/storage/sbmock/preseal.go

55 lines
1.6 KiB
Go
Raw Normal View History

2020-01-13 20:47:27 +00:00
package sbmock
import (
"github.com/filecoin-project/go-address"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/specs-actors/actors/abi"
2020-02-23 15:50:36 +00:00
"github.com/filecoin-project/specs-actors/actors/abi/big"
2020-02-25 20:35:15 +00:00
"github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/filecoin-project/specs-actors/actors/crypto"
2020-01-13 20:47:27 +00:00
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
"github.com/filecoin-project/lotus/genesis"
)
2020-02-23 15:50:36 +00:00
func PreSeal(ssize abi.SectorSize, maddr address.Address, sectors int) (*genesis.Miner, *types.KeyInfo, error) {
k, err := wallet.GenerateKey(crypto.SigTypeBLS)
2020-01-13 20:47:27 +00:00
if err != nil {
2020-02-23 15:50:36 +00:00
return nil, nil, err
2020-01-13 20:47:27 +00:00
}
genm := &genesis.Miner{
2020-02-23 15:50:36 +00:00
Owner: k.Address,
Worker: k.Address,
MarketBalance: big.NewInt(0),
PowerBalance: big.NewInt(0),
SectorSize: ssize,
Sectors: make([]*genesis.PreSeal, sectors),
2020-01-13 20:47:27 +00:00
}
for i := range genm.Sectors {
preseal := &genesis.PreSeal{}
sdata := randB(uint64(abi.PaddedPieceSize(ssize).Unpadded()))
2020-01-13 20:47:27 +00:00
2020-02-26 22:54:34 +00:00
preseal.CommD = commDR(sdata)
2020-01-13 20:47:27 +00:00
preseal.CommR = commDR(preseal.CommD[:])
preseal.SectorID = abi.SectorNumber(i + 1)
2020-02-25 20:35:15 +00:00
preseal.Deal = market.DealProposal{
PieceCID: commcid.PieceCommitmentV1ToCID(preseal.CommD[:]),
PieceSize: abi.PaddedPieceSize(ssize),
2020-01-13 20:47:27 +00:00
Client: maddr,
Provider: maddr,
StartEpoch: 1,
2020-02-23 15:50:36 +00:00
EndEpoch: 10000,
StoragePricePerEpoch: big.Zero(),
ProviderCollateral: big.Zero(),
ClientCollateral: big.Zero(),
2020-01-13 20:47:27 +00:00
}
genm.Sectors[i] = preseal
}
2020-02-23 15:50:36 +00:00
return genm, &k.KeyInfo, nil
2020-01-14 02:04:33 +00:00
}