From 7fd51790298be62c3d7e50c4225d74c077665421 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Mon, 14 Apr 2025 12:16:30 +0200 Subject: [PATCH] fix failing tests --- consensus/beacon/consensus.go | 19 ++++++++----------- core/genesis.go | 2 +- core/state/database.go | 6 ------ core/state/statedb.go | 1 - 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index e06da9157b..b09a5cb4c8 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -353,9 +353,9 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types. // FinalizeAndAssemble implements consensus.Engine, setting the final state and // assembling the block. -func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt) (*types.Block, error) { +func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, statedb *state.StateDB, body *types.Body, receipts []*types.Receipt) (*types.Block, error) { if !beacon.IsPoSHeader(header) { - return beacon.ethone.FinalizeAndAssemble(chain, header, state, body, receipts) + return beacon.ethone.FinalizeAndAssemble(chain, header, statedb, body, receipts) } shanghai := chain.Config().IsShanghai(header.Number, header.Time) if shanghai { @@ -369,10 +369,10 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea } } // Finalize and assemble the block. - beacon.Finalize(chain, header, state, body) + beacon.Finalize(chain, header, statedb, body) // Assign the final state root to header. - header.Root = state.IntermediateRoot(true) + header.Root = statedb.IntermediateRoot(true) // Assemble the final block. block := types.NewBlock(header, body, receipts, trie.NewStackTrie(nil)) @@ -380,23 +380,20 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea // Create the block witness and attach to block. // This step needs to happen as late as possible to catch all access events. if chain.Config().IsVerkle(header.Number, header.Time) { - keys := state.AccessEvents().Keys() + //statedb.Database().SaveTransitionState(header.Root, &state.TransitionState{Ended: true}) + keys := statedb.AccessEvents().Keys() // Open the pre-tree to prove the pre-state against parent := chain.GetHeaderByNumber(header.Number.Uint64() - 1) if parent == nil { return nil, fmt.Errorf("nil parent header for block %d", header.Number) } - preTrie, err := state.Database().OpenTrie(parent.Root) + preTrie, err := statedb.Database().OpenTrie(parent.Root) if err != nil { return nil, fmt.Errorf("error opening pre-state tree root: %w", err) } - postTrie := state.GetTrie() - if postTrie == nil { - return nil, errors.New("post-state tree is not available") - } vktPreTrie, okpre := preTrie.(*trie.VerkleTrie) - vktPostTrie, okpost := state.GetTrie().(*trie.VerkleTrie) + vktPostTrie, okpost := statedb.GetTrie().(*trie.VerkleTrie) // The witness is only attached iff both parent and current block are // using verkle tree. diff --git a/core/genesis.go b/core/genesis.go index 58deafae08..2ef982afc8 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -473,7 +473,7 @@ func (g *Genesis) chainConfigOrDefault(ghash common.Hash, stored *params.ChainCo // IsVerkle indicates whether the state is already stored in a verkle // tree at genesis time. func (g *Genesis) IsVerkle() bool { - return g.Config.VerkleTime != nil && *g.Config.VerkleTime == g.Timestamp + return g != nil && g.Config != nil && g.Config.VerkleTime != nil && *g.Config.VerkleTime == g.Timestamp } // ToBlock returns the genesis block according to genesis specification. diff --git a/core/state/database.go b/core/state/database.go index d65489f4aa..22f2accd88 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -66,12 +66,6 @@ type Database interface { // Snapshot returns the underlying state snapshot. Snapshot() *snapshot.Tree - - // SaveTransitionState saves the tree transition progress markers to the database. - SaveTransitionState(common.Hash, *TransitionState) - - // LoadTransitionState loads the tree transition progress markers from the database. - LoadTransitionState(common.Hash) *TransitionState } // Trie is a Ethereum Merkle Patricia trie. diff --git a/core/state/statedb.go b/core/state/statedb.go index f431016413..e805885079 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1305,7 +1305,6 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool, noStorag return nil, err } } - s.db.SaveTransitionState(ret.root, &TransitionState{Ended: true}) if !ret.empty() { // If snapshotting is enabled, update the snapshot tree with this new version if snap := s.db.Snapshot(); snap != nil && snap.Snapshot(ret.originRoot) != nil {