lotus/storage/sealer/mock/util.go

82 lines
2.1 KiB
Go
Raw Normal View History

2020-03-23 11:40:02 +00:00
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"
2022-09-26 16:47:48 +00:00
"github.com/filecoin-project/go-state-types/builtin/v9/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) {
2020-03-23 11:40:02 +00:00
for i, b := range in {
out[i] = ^b
}
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(),
}
2022-10-05 14:10:04 +00:00
preseal.DealClientKey = k.KeyInfo
genm.Sectors[i] = preseal
}
return genm, &k.KeyInfo, nil
}