From 17039a5672f7e640f4dbf0a9bb82e2388c584ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 3 Jul 2020 02:23:45 +0200 Subject: [PATCH 1/3] Update FFI --- extern/filecoin-ffi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index 5342c7c97..6a143e06f 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit 5342c7c97d1a1df4650629d14f2823d52889edd9 +Subproject commit 6a143e06f923f3a4f544c7a652e8b4df420a3d28 From c3393ee18527ebead69c6fbceffebd2f29a92f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 3 Jul 2020 02:47:33 +0200 Subject: [PATCH 2/3] seed: Move sector preseal to separate func --- cmd/lotus-seed/seed/seed.go | 72 +++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/cmd/lotus-seed/seed/seed.go b/cmd/lotus-seed/seed/seed.go index 08ae91200..6650a8e6c 100644 --- a/cmd/lotus-seed/seed/seed.go +++ b/cmd/lotus-seed/seed/seed.go @@ -68,41 +68,12 @@ func PreSeal(maddr address.Address, spt abi.RegisteredSealProof, offset abi.Sect sid := abi.SectorID{Miner: abi.ActorID(mid), Number: next} next++ - pi, err := sb.AddPiece(context.TODO(), sid, nil, abi.PaddedPieceSize(ssize).Unpadded(), rand.Reader) + preseal, err := presealSector(sb, sbfs, sid, spt, ssize, preimage) if err != nil { return nil, nil, err } - trand := blake2b.Sum256(preimage) - ticket := abi.SealRandomness(trand[:]) - - fmt.Printf("sector-id: %d, piece info: %v\n", sid, pi) - - in2, err := sb.SealPreCommit1(context.TODO(), sid, ticket, []abi.PieceInfo{pi}) - if err != nil { - return nil, nil, xerrors.Errorf("commit: %w", err) - } - - cids, err := sb.SealPreCommit2(context.TODO(), sid, in2) - if err != nil { - return nil, nil, xerrors.Errorf("commit: %w", err) - } - - if err := sb.FinalizeSector(context.TODO(), sid, nil); err != nil { - return nil, nil, xerrors.Errorf("trim cache: %w", err) - } - - if err := cleanupUnsealed(sbfs, sid); err != nil { - return nil, nil, xerrors.Errorf("remove unsealed file: %w", err) - } - - log.Warn("PreCommitOutput: ", sid, cids.Sealed, cids.Unsealed) - sealedSectors = append(sealedSectors, &genesis.PreSeal{ - CommR: cids.Sealed, - CommD: cids.Unsealed, - SectorID: sid.Number, - ProofType: spt, - }) + sealedSectors = append(sealedSectors, preseal) } var minerAddr *wallet.Key @@ -165,6 +136,45 @@ func PreSeal(maddr address.Address, spt abi.RegisteredSealProof, offset abi.Sect return miner, &minerAddr.KeyInfo, nil } +func presealSector(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, sid abi.SectorID, spt abi.RegisteredSealProof, ssize abi.SectorSize, preimage []byte) (*genesis.PreSeal, error) { + pi, err := sb.AddPiece(context.TODO(), sid, nil, abi.PaddedPieceSize(ssize).Unpadded(), rand.Reader) + if err != nil { + return nil, err + } + + trand := blake2b.Sum256(preimage) + ticket := abi.SealRandomness(trand[:]) + + fmt.Printf("sector-id: %d, piece info: %v\n", sid, pi) + + in2, err := sb.SealPreCommit1(context.TODO(), sid, ticket, []abi.PieceInfo{pi}) + if err != nil { + return nil, xerrors.Errorf("commit: %w", err) + } + + cids, err := sb.SealPreCommit2(context.TODO(), sid, in2) + if err != nil { + return nil, xerrors.Errorf("commit: %w", err) + } + + if err := sb.FinalizeSector(context.TODO(), sid, nil); err != nil { + return nil, xerrors.Errorf("trim cache: %w", err) + } + + if err := cleanupUnsealed(sbfs, sid); err != nil { + return nil, xerrors.Errorf("remove unsealed file: %w", err) + } + + log.Warn("PreCommitOutput: ", sid, cids.Sealed, cids.Unsealed) + + return &genesis.PreSeal{ + CommR: cids.Sealed, + CommD: cids.Unsealed, + 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 { From bb3758f648ddcc7ef0adc762e5ffaf19fc341665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 3 Jul 2020 03:29:06 +0200 Subject: [PATCH 3/3] seed: Support fake preseals --- chain/gen/gen.go | 4 ++-- cmd/lotus-seed/main.go | 6 +++++- cmd/lotus-seed/seed/seed.go | 42 +++++++++++++++++++++++++++++++++---- lotuspond/spawn.go | 2 +- node/node_test.go | 2 +- 5 files changed, 47 insertions(+), 9 deletions(-) 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) }