diff --git a/chain/gen/gen.go b/chain/gen/gen.go index ebf868765..54040deb4 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -145,7 +145,7 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) { return nil, err } - genm1, k1, err := seed.PreSeal(maddr1, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, numSectors, m1temp, []byte("some randomness"), nil) + genm1, k1, err := seed.PreSeal(maddr1, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, numSectors, m1temp, []byte("some randomness"), nil, true) if err != nil { return nil, err } @@ -157,7 +157,7 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) { return nil, err } - genm2, k2, err := seed.PreSeal(maddr2, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, numSectors, m2temp, []byte("some randomness"), nil) + genm2, k2, err := seed.PreSeal(maddr2, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, numSectors, m2temp, []byte("some randomness"), nil, true) if err != nil { return nil, err } diff --git a/cmd/lotus-seed/main.go b/cmd/lotus-seed/main.go index 1e4f8fe0d..827c0f112 100644 --- a/cmd/lotus-seed/main.go +++ b/cmd/lotus-seed/main.go @@ -89,6 +89,10 @@ var preSealCmd = &cli.Command{ Value: "", Usage: "(optional) Key to use for signing / owner/worker addresses", }, + &cli.BoolFlag{ + Name: "fake-sectors", + Value: false, + }, }, Action: func(c *cli.Context) error { sdir := c.String("sector-dir") @@ -126,7 +130,7 @@ var preSealCmd = &cli.Command{ return err } - gm, key, err := seed.PreSeal(maddr, rp, abi.SectorNumber(c.Uint64("sector-offset")), c.Int("num-sectors"), sbroot, []byte(c.String("ticket-preimage")), k) + gm, key, err := seed.PreSeal(maddr, rp, abi.SectorNumber(c.Uint64("sector-offset")), c.Int("num-sectors"), sbroot, []byte(c.String("ticket-preimage")), k, c.Bool("fake-sectors")) if err != nil { return err } diff --git a/cmd/lotus-seed/seed/seed.go b/cmd/lotus-seed/seed/seed.go index 6650a8e6c..1d6c3da29 100644 --- a/cmd/lotus-seed/seed/seed.go +++ b/cmd/lotus-seed/seed/seed.go @@ -17,7 +17,9 @@ import ( "github.com/minio/blake2b-simd" "golang.org/x/xerrors" + ffi "github.com/filecoin-project/filecoin-ffi" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/sector-storage/zerocomm" "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin/market" @@ -33,7 +35,7 @@ import ( var log = logging.Logger("preseal") -func PreSeal(maddr address.Address, spt abi.RegisteredSealProof, offset abi.SectorNumber, sectors int, sbroot string, preimage []byte, key *types.KeyInfo) (*genesis.Miner, *types.KeyInfo, error) { +func PreSeal(maddr address.Address, spt abi.RegisteredSealProof, offset abi.SectorNumber, sectors int, sbroot string, preimage []byte, key *types.KeyInfo, fakeSectors bool) (*genesis.Miner, *types.KeyInfo, error) { mid, err := address.IDFromAddress(maddr) if err != nil { return nil, nil, err @@ -68,9 +70,17 @@ func PreSeal(maddr address.Address, spt abi.RegisteredSealProof, offset abi.Sect sid := abi.SectorID{Miner: abi.ActorID(mid), Number: next} next++ - preseal, err := presealSector(sb, sbfs, sid, spt, ssize, preimage) - if err != nil { - return nil, nil, err + var preseal *genesis.PreSeal + if !fakeSectors { + preseal, err = presealSector(sb, sbfs, sid, spt, ssize, preimage) + if err != nil { + return nil, nil, err + } + } else { + preseal, err = presealSectorFake(sbfs, sid, spt, ssize) + if err != nil { + return nil, nil, err + } } sealedSectors = append(sealedSectors, preseal) @@ -175,6 +185,30 @@ func presealSector(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, sid abi.Sector }, nil } +func presealSectorFake(sbfs *basicfs.Provider, sid abi.SectorID, spt abi.RegisteredSealProof, ssize abi.SectorSize) (*genesis.PreSeal, error) { + paths, done, err := sbfs.AcquireSector(context.TODO(), sid, 0, stores.FTSealed | stores.FTCache, true) + if err != nil { + return nil, xerrors.Errorf("acquire unsealed sector: %w", err) + } + defer done() + + if err := os.Mkdir(paths.Cache, 0755); err != nil { + return nil, xerrors.Errorf("mkdir cache: %w", err) + } + + commr, err := ffi.FauxRep(spt, paths.Cache, paths.Sealed) + if err != nil { + return nil, xerrors.Errorf("fauxrep: %w", err) + } + + return &genesis.PreSeal{ + CommR: commr, + CommD: zerocomm.ZeroPieceCommitment(abi.PaddedPieceSize(ssize).Unpadded()), + SectorID: sid.Number, + ProofType: spt, + }, nil +} + func cleanupUnsealed(sbfs *basicfs.Provider, sid abi.SectorID) error { paths, done, err := sbfs.AcquireSector(context.TODO(), sid, stores.FTUnsealed, stores.FTNone, stores.PathSealing) if err != nil { diff --git a/lotuspond/spawn.go b/lotuspond/spawn.go index 8100d784a..ef0ebaeab 100644 --- a/lotuspond/spawn.go +++ b/lotuspond/spawn.go @@ -49,7 +49,7 @@ func (api *api) Spawn() (nodeInfo, error) { } sbroot := filepath.Join(dir, "preseal") - genm, ki, err := seed.PreSeal(genMiner, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, 2, sbroot, []byte("8"), nil) + genm, ki, err := seed.PreSeal(genMiner, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, 2, sbroot, []byte("8"), nil, false) if err != nil { return nodeInfo{}, xerrors.Errorf("preseal failed: %w", err) } diff --git a/node/node_test.go b/node/node_test.go index b9837b1f0..6f33c6c57 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -189,7 +189,7 @@ func builder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test.TestN if err != nil { t.Fatal(err) } - genm, k, err := seed.PreSeal(maddr, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, test.GenesisPreseals, tdir, []byte("make genesis mem random"), nil) + genm, k, err := seed.PreSeal(maddr, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, test.GenesisPreseals, tdir, []byte("make genesis mem random"), nil, true) if err != nil { t.Fatal(err) }