From fb3c16207f262fbee40ef371f4b2df73a5f9dece Mon Sep 17 00:00:00 2001 From: Aayush Date: Wed, 8 Nov 2023 07:26:28 -0500 Subject: [PATCH 1/2] fix: nv21fix migration: correctly upgrade system actor --- chain/consensus/filcns/upgrades.go | 13 +++++++++++++ chain/stmgr/forks.go | 2 +- chain/vm/fvm.go | 9 +++++++++ miner/miner.go | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/chain/consensus/filcns/upgrades.go b/chain/consensus/filcns/upgrades.go index c1f594a92..900f95e94 100644 --- a/chain/consensus/filcns/upgrades.go +++ b/chain/consensus/filcns/upgrades.go @@ -2063,6 +2063,19 @@ func upgradeActorsV12Fix(ctx context.Context, sm *stmgr.StateManager, cache stmg return cid.Undef, xerrors.Errorf("failed to perform migration: %w", err) } + systemState.BuiltinActors = newManifest.Data + newSystemHead, err := adtStore.Put(ctx, systemState) + if err != nil { + return cid.Undef, xerrors.Errorf("failed to put new system state: %w", err) + } + + systemActor.Head = newSystemHead + if err = actorsOut.SetActor(builtin.SystemActorAddr, systemActor); err != nil { + return cid.Undef, xerrors.Errorf("failed to put new system actor: %w", err) + } + + // Sanity checking + err = actorsIn.ForEach(func(a address.Address, inActor *types.Actor) error { outActor, err := actorsOut.GetActor(a) if err != nil { diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index 9d59b5428..16abaaf9a 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -177,7 +177,7 @@ func (us UpgradeSchedule) GetNtwkVersion(e abi.ChainEpoch) (network.Version, err func (sm *StateManager) HandleStateForks(ctx context.Context, root cid.Cid, height abi.ChainEpoch, cb ExecMonitor, ts *types.TipSet) (cid.Cid, error) { retCid := root u := sm.stateMigrations[height] - if u != nil && u.upgrade != nil { + if u != nil && u.upgrade != nil && height != build.UpgradeWatermelonFixHeight { migCid, ok, err := u.migrationResultCache.Get(ctx, root) if err == nil { if ok { diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index 901374a4f..47b4d3320 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -92,6 +92,15 @@ func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte log.Info("invalid consensus fault: submitted blocks are the same") return ret, totalGas } + + // workaround chain halt + if build.IsNearUpgrade(blockA.Height, build.UpgradeWatermelonFixHeight) { + return ret, totalGas + } + if build.IsNearUpgrade(blockB.Height, build.UpgradeWatermelonFixHeight) { + return ret, totalGas + } + // (1) check conditions necessary to any consensus fault // were blocks mined by same miner? diff --git a/miner/miner.go b/miner/miner.go index 2d802e2cf..510ea4f0e 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -324,7 +324,7 @@ minerLoop: "block-time", btime, "time", build.Clock.Now(), "difference", build.Clock.Since(btime)) } - if os.Getenv("LOTUS_MINER_NO_SLASHFILTER") != "_yes_i_know_i_can_and_probably_will_lose_all_my_fil_and_power_" { + if os.Getenv("LOTUS_MINER_NO_SLASHFILTER") != "_yes_i_know_i_can_and_probably_will_lose_all_my_fil_and_power_" && !build.IsNearUpgrade(base.TipSet.Height(), build.UpgradeWatermelonFixHeight) { witness, fault, err := m.sf.MinedBlock(ctx, b.Header, base.TipSet.Height()+base.NullRounds) if err != nil { log.Errorf(" SLASH FILTER ERRORED: %s", err) From ae75aa1d0da9930e29633f9d85fa788982b4eb5d Mon Sep 17 00:00:00 2001 From: Aayush Date: Wed, 8 Nov 2023 09:10:31 -0500 Subject: [PATCH 2/2] skip migration cache correctly --- chain/consensus/filcns/upgrades.go | 4 ++-- chain/stmgr/forks.go | 23 +++++++++++++---------- node/impl/full/sync.go | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/chain/consensus/filcns/upgrades.go b/chain/consensus/filcns/upgrades.go index 900f95e94..3fa3dd995 100644 --- a/chain/consensus/filcns/upgrades.go +++ b/chain/consensus/filcns/upgrades.go @@ -2064,7 +2064,7 @@ func upgradeActorsV12Fix(ctx context.Context, sm *stmgr.StateManager, cache stmg } systemState.BuiltinActors = newManifest.Data - newSystemHead, err := adtStore.Put(ctx, systemState) + newSystemHead, err := adtStore.Put(ctx, &systemState) if err != nil { return cid.Undef, xerrors.Errorf("failed to put new system state: %w", err) } @@ -2094,7 +2094,7 @@ func upgradeActorsV12Fix(ctx context.Context, sm *stmgr.StateManager, cache stmg return xerrors.Errorf("mismatched address for actor %s: %s != %s", a, inActor.Address, outActor.Address) } - if inActor.Head != outActor.Head { + if inActor.Head != outActor.Head && a != builtin.SystemActorAddr { return xerrors.Errorf("mismatched head for actor %s", a) } diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index 16abaaf9a..8d1ac1dfb 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -177,17 +177,19 @@ func (us UpgradeSchedule) GetNtwkVersion(e abi.ChainEpoch) (network.Version, err func (sm *StateManager) HandleStateForks(ctx context.Context, root cid.Cid, height abi.ChainEpoch, cb ExecMonitor, ts *types.TipSet) (cid.Cid, error) { retCid := root u := sm.stateMigrations[height] - if u != nil && u.upgrade != nil && height != build.UpgradeWatermelonFixHeight { - migCid, ok, err := u.migrationResultCache.Get(ctx, root) - if err == nil { - if ok { - log.Infow("CACHED migration", "height", height, "from", root, "to", migCid) - return migCid, nil + if u != nil && u.upgrade != nil { + if height != build.UpgradeWatermelonFixHeight { + migCid, ok, err := u.migrationResultCache.Get(ctx, root) + if err == nil { + if ok { + log.Infow("CACHED migration", "height", height, "from", root, "to", migCid) + return migCid, nil + } + } else if !errors.Is(err, datastore.ErrNotFound) { + log.Errorw("failed to lookup previous migration result", "err", err) + } else { + log.Debug("no cached migration found, migrating from scratch") } - } else if !errors.Is(err, datastore.ErrNotFound) { - log.Errorw("failed to lookup previous migration result", "err", err) - } else { - log.Debug("no cached migration found, migrating from scratch") } startTime := time.Now() @@ -195,6 +197,7 @@ func (sm *StateManager) HandleStateForks(ctx context.Context, root cid.Cid, heig // Yes, we clone the cache, even for the final upgrade epoch. Why? Reverts. We may // have to migrate multiple times. tmpCache := u.cache.Clone() + var err error retCid, err = u.upgrade(ctx, sm, tmpCache, cb, root, height, ts) if err != nil { log.Errorw("FAILED migration", "height", height, "from", root, "error", err) diff --git a/node/impl/full/sync.go b/node/impl/full/sync.go index 223f5c29e..4bf44363c 100644 --- a/node/impl/full/sync.go +++ b/node/impl/full/sync.go @@ -57,7 +57,7 @@ func (a *SyncAPI) SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) erro return xerrors.Errorf("loading parent block: %w", err) } - if a.SlashFilter != nil && os.Getenv("LOTUS_NO_SLASHFILTER") != "_yes_i_know_i_can_and_probably_will_lose_all_my_fil_and_power_" { + if a.SlashFilter != nil && os.Getenv("LOTUS_NO_SLASHFILTER") != "_yes_i_know_i_can_and_probably_will_lose_all_my_fil_and_power_" && !build.IsNearUpgrade(blk.Header.Height, build.UpgradeWatermelonFixHeight) { witness, fault, err := a.SlashFilter.MinedBlock(ctx, blk.Header, parent.Height) if err != nil { log.Errorf(" SLASH FILTER ERRORED: %s", err)