Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Feb 22, 2024
1 parent 7c3c192 commit bb933ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
10 changes: 4 additions & 6 deletions core/overlay/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

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

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

0 comments on commit bb933ec

Please sign in to comment.