From 3b4a4ed1a5a2057acba0c926da112cc6a9eb114c Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Tue, 20 Aug 2024 15:34:21 -0300 Subject: [PATCH] preimages fixes Signed-off-by: Ignacio Hagopian --- consensus/beacon/consensus.go | 3 +-- core/genesis.go | 19 +++++-------------- tests/block_test_util.go | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 75729721cd71..acf5abeb1a99 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -28,7 +28,6 @@ import ( "github.com/ethereum/go-ethereum/core/overlay" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/trie" @@ -366,7 +365,7 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types. // fmt.Println("at block", header.Number, "performing transition?", state.Database().InTransition()) parent := chain.GetHeaderByHash(header.ParentHash) if err := overlay.OverlayVerkleTransition(state, parent.Root, chain.Config().OverlayStride); err != nil { - log.Error("error performing the transition", "err", err) + panic(fmt.Sprintf("error performing the transition: %s", err)) } } } diff --git a/core/genesis.go b/core/genesis.go index 93192472d2b5..5a3eca942655 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -30,7 +30,6 @@ import ( "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" - "github.com/ethereum/go-ethereum/core/state/snapshot" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" @@ -174,17 +173,6 @@ func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database, blockhas return err } - sdb := database - sdb.TrieDB().WritePreimages() - snaps, err := snapshot.New(snapshot.Config{AsyncBuild: false, CacheSize: 10}, sdb.DiskDB(), sdb.TrieDB(), types.EmptyRootHash) - if err != nil { - panic(err) - } - if snaps == nil { - panic("snapshot is nil") - } - snaps.Cap(types.EmptyRootHash, 0) - // Commit newly generated states into disk if it's not empty. if root != types.EmptyRootHash { if err := triedb.Commit(root, true); err != nil { @@ -343,7 +331,10 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen } // Just commit the new block if there is no stored genesis block. stored := rawdb.ReadCanonicalHash(db, 0) - if (stored == common.Hash{}) { + // TODO: remove `true`. The problem is that for test consumption, the genesis block is stored + // in the db and is unaware of preimage recording. This means that we won't enter this if and + // save the genesis block state with preimages enabled, thus missing the genesis preimages. + if true || (stored == common.Hash{}) { if genesis == nil { log.Info("Writing default main-net genesis block") genesis = DefaultGenesisBlock() @@ -573,7 +564,7 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *trie.Database) (*types.Block // Note the state changes will be committed in hash-based scheme, use Commit // if path-scheme is preferred. func (g *Genesis) MustCommit(db ethdb.Database) *types.Block { - triedb := trie.NewDatabaseWithConfig(db, &trie.Config{Verkle: g.Config != nil && g.Config.IsVerkle(big.NewInt(int64(g.Number)), g.Timestamp), Preimages: true}) + triedb := trie.NewDatabaseWithConfig(db, &trie.Config{Verkle: g.Config != nil && g.Config.IsVerkle(big.NewInt(int64(g.Number)), g.Timestamp)}) block, err := g.Commit(db, triedb) if err != nil { panic(err) diff --git a/tests/block_test_util.go b/tests/block_test_util.go index 00c73c93e0a6..9c0ee3b1a93d 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -119,7 +119,7 @@ func (t *BlockTest) Run(snapshotter bool, tracer vm.EVMLogger) error { // Wrap the original engine within the beacon-engine engine := beacon.New(ethash.NewFaker()) - cache := &core.CacheConfig{TrieCleanLimit: 0} + cache := &core.CacheConfig{TrieCleanLimit: 0, Preimages: true} if snapshotter { cache.SnapshotLimit = 1 cache.SnapshotWait = true