Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Feb 28, 2024
1 parent b4f3596 commit 876a028
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
9 changes: 5 additions & 4 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
//
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down

0 comments on commit 876a028

Please sign in to comment.