From 74d94af03418c799350fc0f40d3758c23cd82ab8 Mon Sep 17 00:00:00 2001 From: Aayush Date: Mon, 6 Mar 2023 15:38:46 -0500 Subject: [PATCH] fix: state: short-circuit genesis state computation --- chain/consensus/compute_state.go | 10 +++++++++- chain/stmgr/execute.go | 8 -------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/chain/consensus/compute_state.go b/chain/consensus/compute_state.go index 747992e0a..cfb2cdf31 100644 --- a/chain/consensus/compute_state.go +++ b/chain/consensus/compute_state.go @@ -235,7 +235,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, } rErr := t.reward(ctx, vmi, em, epoch, ts, params) if rErr != nil { - return cid.Undef, cid.Undef, xerrors.Errorf("error applying reward: %w", err) + return cid.Undef, cid.Undef, xerrors.Errorf("error applying reward: %w", rErr) } } @@ -308,6 +308,14 @@ func (t *TipSetExecutor) ExecuteTipSet(ctx context.Context, } } + if ts.Height() == 0 { + // NB: This is here because the process that executes blocks requires that the + // block miner reference a valid miner in the state tree. Unless we create some + // magical genesis miner, this won't work properly, so we short circuit here + // This avoids the question of 'who gets paid the genesis block reward' + return blks[0].ParentStateRoot, blks[0].ParentMessageReceipts, nil + } + var parentEpoch abi.ChainEpoch pstate := blks[0].ParentStateRoot if blks[0].Height > 0 { diff --git a/chain/stmgr/execute.go b/chain/stmgr/execute.go index 60ee069d0..e67398299 100644 --- a/chain/stmgr/execute.go +++ b/chain/stmgr/execute.go @@ -52,14 +52,6 @@ func (sm *StateManager) TipSetState(ctx context.Context, ts *types.TipSet) (st c sm.stlk.Unlock() - if ts.Height() == 0 { - // NB: This is here because the process that executes blocks requires that the - // block miner reference a valid miner in the state tree. Unless we create some - // magical genesis miner, this won't work properly, so we short circuit here - // This avoids the question of 'who gets paid the genesis block reward' - return ts.Blocks()[0].ParentStateRoot, ts.Blocks()[0].ParentMessageReceipts, nil - } - st, rec, err = sm.tsExec.ExecuteTipSet(ctx, sm, ts, sm.tsExecMonitor, false) if err != nil { return cid.Undef, cid.Undef, err