From 876a028520e383d8fcdd3b089e2e411a3052c867 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Tue, 27 Feb 2024 12:38:43 -0300 Subject: [PATCH] fixes Signed-off-by: Ignacio Hagopian --- consensus/beacon/consensus.go | 9 +++++---- core/blockchain.go | 12 +++++++++--- core/state/database.go | 2 -- core/state/statedb.go | 3 +++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 701740f1cc1f..d4cd9d432b8a 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -347,10 +347,6 @@ func (beacon *Beacon) Prepare(chain consensus.ChainHeaderReader, header *types.H // Finalize implements consensus.Engine and processes withdrawals on top. func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) { - if false && !beacon.IsPoSHeader(header) { - beacon.ethone.Finalize(chain, header, state, txs, uncles, nil) - return - } // Withdrawals processing. for _, w := range withdrawals { // Convert amount from gwei to wei. @@ -373,6 +369,11 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types. log.Error("error performing the transition", "err", err) } } + + if !beacon.IsPoSHeader(header) { + beacon.ethone.Finalize(chain, header, state, txs, uncles, nil) + return + } } // FinalizeAndAssemble implements consensus.Engine, setting the final state and diff --git a/core/blockchain.go b/core/blockchain.go index bfd63020da43..e4d5f40b3cbc 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -322,7 +322,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis // for it to be able to recover if interrupted during the transition // but that's left out to a later PR since there's not really a need // right now. - bc.stateCache.InitTransitionStatus(true, true) + bc.stateCache.InitTransitionStatus(false, false) } if !bc.stateCache.Transitioned() && !bc.HasState(head.Root) { @@ -1530,6 +1530,8 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { return bc.insertChain(chain, true) } +var count int + // insertChain is the internal implementation of InsertChain, which assumes that // 1) chains are contiguous, and 2) The chain mutex is held. // @@ -1667,7 +1669,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) activeState.StopPrefetcher() } }() - for ; block != nil && err == nil || errors.Is(err, ErrKnownBlock); block, err = it.next() { // If the chain is terminating, stop processing blocks if bc.insertStopped() { @@ -1736,7 +1737,12 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) bc.stateCache.SetLastMerkleRoot(parent.Root) } } - statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps) + rootz := parent.Root + if count > 0 { + rootz = state.LastCommittedRoot + } + count++ + statedb, err := state.New(rootz, bc.stateCache, bc.snaps) if err != nil { return it.index, err } diff --git a/core/state/database.go b/core/state/database.go index 6c5e9b26fe14..d7ac62f36931 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -349,7 +349,6 @@ func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) { mpt Trie err error ) - fmt.Printf("opening trie with root %x, %v %v\n", root, db.InTransition(), db.Transitioned()) // TODO separate both cases when I can be certain that it won't // find a Verkle trie where is expects a Transitoion trie. @@ -415,7 +414,6 @@ func (db *cachingDB) OpenStorageTrie(stateRoot common.Hash, address common.Addre } } if db.InTransition() { - fmt.Printf("OpenStorageTrie during transition, state root=%x root=%x\n", stateRoot, root) mpt, err := db.openStorageMPTrie(db.LastMerkleRoot, address, root, nil) if err != nil { return nil, err diff --git a/core/state/statedb.go b/core/state/statedb.go index 6ce3b9b2b9b2..f0438a79f681 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1356,9 +1356,12 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er s.storagesOrigin = make(map[common.Address]map[common.Hash][]byte) s.stateObjectsDirty = make(map[common.Address]struct{}) s.stateObjectsDestruct = make(map[common.Address]*types.StateAccount) + LastCommittedRoot = root return root, nil } +var LastCommittedRoot common.Hash + // Prepare handles the preparatory steps for executing a state transition with. // This method must be invoked before state transition. //