From 05aea3649731d4f450e313b0d248001573052a9b Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sat, 5 Sep 2020 00:40:56 -0400 Subject: [PATCH] Mark presealed sectors as proven --- api/test/window_post.go | 4 +-- chain/gen/genesis/miners.go | 61 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/api/test/window_post.go b/api/test/window_post.go index c5c8ec071..5e9078454 100644 --- a/api/test/window_post.go +++ b/api/test/window_post.go @@ -159,7 +159,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector head, err := client.ChainHead(ctx) require.NoError(t, err) - if head.Height() > di.PeriodStart+(miner2.WPoStProvingPeriod)+2 { + if head.Height() > (di.PeriodStart + (2 * miner2.WPoStProvingPeriod) + 2) { break } @@ -296,7 +296,7 @@ func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSector head, err := client.ChainHead(ctx) require.NoError(t, err) - waitUntil := head.Height() + 10 + waitUntil := head.Height() + miner2.WPoStProvingPeriod + 2 for { head, err := client.ChainHead(ctx) diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 6ad266b7d..b89319965 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "github.com/filecoin-project/specs-actors/actors/util/adt" "math/rand" "github.com/filecoin-project/lotus/chain/state" @@ -306,6 +307,10 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err) } } + + if activatePresealedSectors(ctx, vm, minerInfos[i].maddr) != nil { + return cid.Undef, xerrors.Errorf("activating presealed sectors: %w", err) + } } } @@ -410,3 +415,59 @@ func circSupply(ctx context.Context, vmi *vm.VM, maddr address.Address) abi.Toke return rt.TotalFilCircSupply() } + +func activatePresealedSectors(ctx context.Context, vm *vm.VM, maddr address.Address) error { + + return vm.MutateState(ctx, maddr, func(cst cbor.IpldStore, st *miner.State) error { + + ds, err := st.LoadDeadlines(adt.WrapStore(ctx, cst)) + if err != nil { + return err + } + + err = ds.ForEach(adt.WrapStore(ctx, cst), func(dlIdx uint64, dl *miner.Deadline) error { + parts, err := dl.PartitionsArray(adt.WrapStore(ctx, cst)) + if err != nil { + return err + } + + var partition miner.Partition + err = parts.ForEach(&partition, func(i int64) error { + _ = partition.ActivateUnproven() + err2 := parts.Set(uint64(i), &partition) + if err2 != nil { + return err2 + } + + return nil + }) + + if err != nil { + return err + } + + dl.Partitions, err = parts.Root() + if err != nil { + return err + } + + err = ds.UpdateDeadline(adt.WrapStore(ctx, cst), dlIdx, dl) + if err != nil { + return err + } + + return nil + }) + + if err != nil { + return err + } + + err = st.SaveDeadlines(adt.WrapStore(ctx, cst), ds) + if err != nil { + return err + } + + return nil + }) +}