From 277cbf9229793e859e6fa7337bdeb76e4d435800 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 14 Mar 2024 14:04:13 -0400 Subject: [PATCH] fix: stmgr: do not use cached migration results if absent from the blockstore (#11663) --- chain/stmgr/forks.go | 10 +++++++++- chain/stmgr/stmgr.go | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index 6d6f9ef65..9a2361961 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -182,7 +182,15 @@ func (sm *StateManager) HandleStateForks(ctx context.Context, root cid.Cid, heig if err == nil { if ok { log.Infow("CACHED migration", "height", height, "from", root, "to", migCid) - return migCid, nil + foundMigratedRoot, err := sm.ChainStore().StateBlockstore().Has(ctx, migCid) + if err != nil { + log.Errorw("failed to check whether previous migration result is present", "err", err) + } else if !foundMigratedRoot { + log.Errorw("cached migration result not found in blockstore, running migration again") + u.migrationResultCache.Delete(ctx, root) + } else { + return migCid, nil + } } } else if !errors.Is(err, datastore.ErrNotFound) { log.Errorw("failed to lookup previous migration result", "err", err) diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 49913e442..cd35d6d19 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -113,6 +113,10 @@ func (m *migrationResultCache) Store(ctx context.Context, root cid.Cid, resultCi return nil } +func (m *migrationResultCache) Delete(ctx context.Context, root cid.Cid) { + _ = m.ds.Delete(ctx, m.keyForMigration(root)) +} + type Executor interface { NewActorRegistry() *vm.ActorRegistry ExecuteTipSet(ctx context.Context, sm *StateManager, ts *types.TipSet, em ExecMonitor, vmTracing bool) (stateroot cid.Cid, rectsroot cid.Cid, err error)