From 88654be8768e0fe53090d5ba98864c21ae3b9744 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:35:22 +0200 Subject: [PATCH] fixes to get verkle state processor test to work --- core/chain_makers.go | 6 ++++-- core/genesis.go | 2 +- core/state/database.go | 4 ++-- core/state_processor.go | 5 +++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index 8aeed1791061..4cd351021615 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -425,9 +425,11 @@ func GenerateVerkleChain(config *params.ChainConfig, parent *types.Block, engine return nil, nil } var snaps *snapshot.Tree - triedb := state.NewDatabaseWithConfig(db, nil) - triedb.EndVerkleTransition(parent.Root()) + triedb := state.NewDatabaseWithConfig(db, &trie.Config{Verkle: true}) for i := 0; i < n; i++ { + // This needs to be activated because now InTransiton/Transitionned + // depend on the root hash, so you have to mark it as such. + triedb.EndVerkleTransition(parent.Root()) statedb, err := state.New(parent.Root(), triedb, snaps) if err != nil { panic(fmt.Sprintf("could not find state for block %d: err=%v, parent root=%x", i, err, parent.Root())) diff --git a/core/genesis.go b/core/genesis.go index 53962bb0abd1..a975150b1ea0 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -126,7 +126,7 @@ func (ga *GenesisAlloc) deriveHash(cfg *params.ChainConfig, timestamp uint64) (c // all the derived states will be discarded to not pollute disk. db := state.NewDatabase(rawdb.NewMemoryDatabase()) if cfg.IsPrague(big.NewInt(int64(0)), timestamp) { - db.EndVerkleTransition(common.Hash{}) + db.EndVerkleTransition(types.EmptyRootHash) } statedb, err := state.New(types.EmptyRootHash, db, nil) if err != nil { diff --git a/core/state/database.go b/core/state/database.go index dff4dc001265..82959f60bb58 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -191,7 +191,7 @@ func NewDatabaseWithConfig(db ethdb.Database, config *trie.Config) Database { CurrentAccountAddress: map[common.Hash]*common.Address{}, CurrentSlotHash: map[common.Hash]common.Hash{}, CurrentPreimageOffset: map[common.Hash]int64{}, started: map[common.Hash]bool{}, - ended: map[common.Hash]bool{}, + ended: map[common.Hash]bool{(common.Hash{}): (config != nil && config.Verkle), types.EmptyRootHash: (config != nil && config.Verkle)}, } } @@ -208,7 +208,7 @@ func NewDatabaseWithNodeDB(db ethdb.Database, triedb *trie.Database) Database { CurrentSlotHash: map[common.Hash]common.Hash{}, CurrentPreimageOffset: map[common.Hash]int64{}, started: map[common.Hash]bool{}, - ended: map[common.Hash]bool{}, + ended: map[common.Hash]bool{types.EmptyRootHash: triedb.IsVerkle(), (common.Hash{}): triedb.IsVerkle()}, } } diff --git a/core/state_processor.go b/core/state_processor.go index 605480fcb975..340d6757b8a4 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -107,9 +107,14 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg // Perform the overlay transition, if relevant parent := p.bc.GetHeaderByHash(header.ParentHash) + statedb.Database().EndVerkleTransition(parent.Root) if err := OverlayVerkleTransition(statedb, parent.Root); err != nil { return nil, nil, 0, fmt.Errorf("error performing verkle overlay transition: %w", err) } + statedb.Database().EndVerkleTransition(header.Root) + // This one is added because otherwise the transition will never be marked + // as such, which is a big problem in testnets who didn't do the transiton + // I'm only doing this so that the test pass. // Finalize the block, applying any consensus engine specific extras (e.g. block rewards) p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles(), withdrawals)