From bb933ecba0b4a1c2007e1fe58c2797f39a16d0d6 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:45:04 +0100 Subject: [PATCH] Apply suggestions from code review --- core/overlay/conversion.go | 10 ++++------ core/state/database.go | 11 ++++++----- core/state_processor.go | 1 - 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/core/overlay/conversion.go b/core/overlay/conversion.go index d58ad311f29a..bf77ff0033f1 100644 --- a/core/overlay/conversion.go +++ b/core/overlay/conversion.go @@ -208,7 +208,7 @@ func (kvm *keyValueMigrator) migrateCollectedKeyValues(tree *trie.VerkleTrie) er if kvm.prepareErr != nil { return fmt.Errorf("failed to prepare key values: %w", kvm.prepareErr) } - fmt.Println("Prepared key values from base tree", "duration", time.Since(now)) + log.Info("Prepared key values from base tree", "duration", time.Since(now)) // Insert into the tree. if err := tree.InsertMigratedLeaves(kvm.newLeaves); err != nil { @@ -404,9 +404,7 @@ func OverlayVerkleTransition(statedb *state.StateDB, root common.Hash, maxMovedC if crypto.Keccak256Hash(addr[:]) != accIt.Hash() { return fmt.Errorf("preimage file does not match account hash: %s != %s", crypto.Keccak256Hash(addr[:]), accIt.Hash()) } - if count%100 == 0 { - fmt.Printf("Converting account address hash=%x addr=%x\n", accIt.Hash(), addr) - } + log.Trace("Converting account address", "hash", accIt.Hash(), "addr", addr) preimageSeek += int64(len(addr)) migrdb.SetCurrentAccountAddress(addr) } else { @@ -419,7 +417,7 @@ func OverlayVerkleTransition(statedb *state.StateDB, root common.Hash, maxMovedC } migrdb.SetCurrentPreimageOffset(preimageSeek) - fmt.Println("Collected key values from base tree", "count", count, "duration", time.Since(now), "last account hash", statedb.Database().GetCurrentAccountHash(), "last account address", statedb.Database().GetCurrentAccountAddress(), "storage processed", statedb.Database().GetStorageProcessed(), "last storage", statedb.Database().GetCurrentSlotHash()) + log.Info("Collected key values from base tree", "count", count, "duration", time.Since(now), "last account hash", statedb.Database().GetCurrentAccountHash(), "last account address", statedb.Database().GetCurrentAccountAddress(), "storage processed", statedb.Database().GetStorageProcessed(), "last storage", statedb.Database().GetCurrentSlotHash()) // Take all the collected key-values and prepare the new leaf values. // This fires a background routine that will start doing the work that @@ -434,7 +432,7 @@ func OverlayVerkleTransition(statedb *state.StateDB, root common.Hash, maxMovedC if err := mkv.migrateCollectedKeyValues(tt.Overlay()); err != nil { return fmt.Errorf("could not migrate key values: %w", err) } - fmt.Println("Inserted key values in overlay tree", "count", count, "duration", time.Since(now)) + log.Info("Inserted key values in overlay tree", "count", count, "duration", time.Since(now)) } return nil diff --git a/core/state/database.go b/core/state/database.go index 4032a0f9a256..cca65bb6f993 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -560,7 +560,7 @@ func (db *cachingDB) SaveTransitionState(root common.Hash) { enc := gob.NewEncoder(&buf) err := enc.Encode(db.CurrentTransitionState) if err != nil { - log.Crit("failed to encode transition state", "err", err) + log.Error("failed to encode transition state", "err", err) return } @@ -572,7 +572,7 @@ func (db *cachingDB) SaveTransitionState(root common.Hash) { rawdb.WriteVerkleTransitionState(db.DiskDB(), root, buf.Bytes()) } - fmt.Println("saving transition state", "storage processed", db.CurrentTransitionState.StorageProcessed, "addr", db.CurrentTransitionState.CurrentAccountAddress, "slot hash", db.CurrentTransitionState.CurrentSlotHash, "root", root, "ended", db.CurrentTransitionState.ended, "started", db.CurrentTransitionState.started) + log.Debug("saving transition state", "storage processed", db.CurrentTransitionState.StorageProcessed, "addr", db.CurrentTransitionState.CurrentAccountAddress, "slot hash", db.CurrentTransitionState.CurrentSlotHash, "root", root, "ended", db.CurrentTransitionState.ended, "started", db.CurrentTransitionState.started) } } @@ -590,6 +590,7 @@ func (db *cachingDB) LoadTransitionState(root common.Hash) { return } + // if a state could be read from the db, attempt to decode it if len(data) > 0 { var ( newts TransitionState @@ -605,12 +606,12 @@ func (db *cachingDB) LoadTransitionState(root common.Hash) { ts = &newts } - // Fallback + // Fallback that should only happen before the transition if ts == nil { // Initialize the first transition state, with the "ended" // field set to true if the database was created // as a verkle database. - fmt.Println("no transition state found, starting fresh", "is verkle", db.triedb.IsVerkle()) + log.Debug("no transition state found, starting fresh", "is verkle", db.triedb.IsVerkle()) // Start with a fresh state ts = &TransitionState{ended: db.triedb.IsVerkle()} } @@ -620,7 +621,7 @@ func (db *cachingDB) LoadTransitionState(root common.Hash) { // doesn't get overwritten. db.CurrentTransitionState = ts.Copy() - fmt.Println("loaded transition state", "storage processed", db.CurrentTransitionState.StorageProcessed, "addr", db.CurrentTransitionState.CurrentAccountAddress, "slot hash", db.CurrentTransitionState.CurrentSlotHash, "root", root, "ended", db.CurrentTransitionState.ended, "started", db.CurrentTransitionState.started) + log.Debug("loaded transition state", "storage processed", db.CurrentTransitionState.StorageProcessed, "addr", db.CurrentTransitionState.CurrentAccountAddress, "slot hash", db.CurrentTransitionState.CurrentSlotHash, "root", root, "ended", db.CurrentTransitionState.ended, "started", db.CurrentTransitionState.started) debug.PrintStack() } diff --git a/core/state_processor.go b/core/state_processor.go index f47187af20db..f26cbfdd3bea 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -61,7 +61,6 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen // returns the amount of gas that was used in the process. If any of the // transactions failed to execute due to insufficient gas it will return an error. func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) { - fmt.Println("process block", block.NumberU64()) var ( receipts types.Receipts usedGas = new(uint64)