From 897ea21e965a67b9a5acdb9ff3e0c7b40c9e4373 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Tue, 20 Aug 2024 15:35:22 -0300 Subject: [PATCH] preimages fixes Signed-off-by: Ignacio Hagopian --- consensus/beacon/consensus.go | 3 +-- core/genesis.go | 20 +++++--------------- tests/block_test_util.go | 6 ++---- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 75729721cd71c..acf5abeb1a99f 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 93192472d2b58..b202f4dacfcba 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" @@ -173,18 +172,6 @@ func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database, blockhas if err != nil { 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 +330,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 +563,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 00c73c93e0a66..4cacfe18dcf18 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 @@ -148,9 +148,7 @@ func (t *BlockTest) Run(snapshotter bool, tracer vm.EVMLogger) error { return fmt.Errorf("post state validation failed: %v", err) } // Cross-check the snapshot-to-hash against the trie hash - // TODO: re-enable this whenever we decide how to handle the Overlay Tree situation - // for snapshot regeneration. - if snapshotter && false { + if snapshotter { if err := chain.Snapshots().Verify(chain.CurrentBlock().Root); err != nil { return err }