Skip to content

Commit

Permalink
fixes to get verkle state processor test to work
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Oct 27, 2023
1 parent 99d180b commit 88654be
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 430 in core/chain_makers.go

View workflow job for this annotation

GitHub Actions / lint

`Transitionned` is a misspelling of `Transitioned` (misspell)
// 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()))
Expand Down
2 changes: 1 addition & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
}
}

Expand All @@ -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()},
}
}

Expand Down
5 changes: 5 additions & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 88654be

Please sign in to comment.