2020-03-27 20:08:06 +00:00
|
|
|
package mockstorage
|
2020-01-13 20:47:27 +00:00
|
|
|
|
|
|
|
import (
|
2020-07-01 12:04:37 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
markettypes "github.com/filecoin-project/go-state-types/builtin/v8/market"
|
|
|
|
|
2020-01-13 20:47:27 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-11-20 00:28:18 +00:00
|
|
|
"github.com/filecoin-project/go-commp-utils/zerocomm"
|
2020-02-27 23:49:28 +00:00
|
|
|
commcid "github.com/filecoin-project/go-fil-commcid"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2020-08-17 13:26:18 +00:00
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/mock"
|
2022-03-12 18:07:35 +00:00
|
|
|
"golang.org/x/xerrors"
|
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-11-05 12:43:05 +00:00
|
|
|
func PreSeal(spt abi.RegisteredSealProof, maddr address.Address, sectors int) (*genesis.Miner, *types.KeyInfo, error) {
|
2020-10-11 18:12:01 +00:00
|
|
|
k, err := wallet.GenerateKey(types.KTBLS)
|
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
|
|
|
}
|
|
|
|
|
2020-11-05 12:43:05 +00:00
|
|
|
ssize, err := spt.SectorSize()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2020-02-18 07:15:30 +00:00
|
|
|
genm := &genesis.Miner{
|
2020-08-19 20:42:34 +00:00
|
|
|
ID: maddr,
|
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 {
|
2022-04-20 21:34:28 +00:00
|
|
|
label, err := markettypes.NewLabelFromString(fmt.Sprintf("%d", i))
|
2022-03-12 18:07:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, xerrors.Errorf("failed to create label: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-01-13 20:47:27 +00:00
|
|
|
preseal := &genesis.PreSeal{}
|
|
|
|
|
2020-11-05 12:43:05 +00:00
|
|
|
preseal.ProofType = spt
|
2020-03-26 02:50:56 +00:00
|
|
|
preseal.CommD = zerocomm.ZeroPieceCommitment(abi.PaddedPieceSize(ssize).Unpadded())
|
2020-02-27 23:49:28 +00:00
|
|
|
d, _ := commcid.CIDToPieceCommitmentV1(preseal.CommD)
|
2020-03-27 20:08:06 +00:00
|
|
|
r := mock.CommDR(d)
|
2020-07-16 00:25:24 +00:00
|
|
|
preseal.CommR, _ = commcid.ReplicaCommitmentV1ToCID(r[:])
|
2020-02-10 19:16:36 +00:00
|
|
|
preseal.SectorID = abi.SectorNumber(i + 1)
|
2022-04-20 21:34:28 +00:00
|
|
|
preseal.Deal = markettypes.DealProposal{
|
2020-02-27 00:42:39 +00:00
|
|
|
PieceCID: preseal.CommD,
|
2020-02-10 19:16:36 +00:00
|
|
|
PieceSize: abi.PaddedPieceSize(ssize),
|
2020-07-28 17:51:47 +00:00
|
|
|
Client: k.Address,
|
2020-01-13 20:47:27 +00:00
|
|
|
Provider: maddr,
|
2022-03-12 18:07:35 +00:00
|
|
|
Label: label,
|
2020-02-10 19:16:36 +00:00
|
|
|
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
|
|
|
}
|