From 2a7c4b62a9cce1b3d9cd3ad68d0c8b2acd25630c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 7 Apr 2021 18:14:24 +0300 Subject: [PATCH] eth: fix tracing state retrieval if requesting the non-dirty genesis --- eth/state_accessor.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/eth/state_accessor.go b/eth/state_accessor.go index d7564a084..84cfaf4d7 100644 --- a/eth/state_accessor.go +++ b/eth/state_accessor.go @@ -61,6 +61,16 @@ func (eth *Ethereum) stateAtBlock(block *types.Block, reexec uint64, base *state // the internal junks created by tracing will be persisted into the disk. database = state.NewDatabaseWithConfig(eth.chainDb, &trie.Config{Cache: 16}) + // If we didn't check the dirty database, do check the clean one, otherwise + // we would rewind past a persisted block (specific corner case is chain + // tracing from the genesis). + if !checkLive { + statedb, err = state.New(current.Root(), database, nil) + if err == nil { + return statedb, nil + } + } + // Database does not have the state for the given block, try to regenerate for i := uint64(0); i < reexec; i++ { if current.NumberU64() == 0 { return nil, errors.New("genesis state is missing")