From bdb432948762d99e50d57d6e3d7962a19b9ee73f Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:18:45 +0200 Subject: [PATCH 01/10] add trace --- trie/utils/verkle.go | 2 ++ trie/verkle.go | 1 + 2 files changed, 3 insertions(+) diff --git a/trie/utils/verkle.go b/trie/utils/verkle.go index ad6184baa99a..a376512839e6 100644 --- a/trie/utils/verkle.go +++ b/trie/utils/verkle.go @@ -30,6 +30,8 @@ const ( CodeHashLeafKey = 3 CodeSizeLeafKey = 4 + BasicDataNonceOffset = 8 + maxPointCacheByteSize = 100 << 20 ) diff --git a/trie/verkle.go b/trie/verkle.go index f0568077fb35..3c4eea6c1ea2 100644 --- a/trie/verkle.go +++ b/trie/verkle.go @@ -175,6 +175,7 @@ func (t *VerkleTrie) UpdateAccount(addr common.Address, acc *types.StateAccount) values[utils.NonceLeafKey] = nonce[:] values[utils.BalanceLeafKey] = balance[:] values[utils.CodeHashLeafKey] = acc.CodeHash[:] + fmt.Printf("updating nonce=%x\n", nonce) binary.LittleEndian.PutUint64(nonce[:], acc.Nonce) bbytes := acc.Balance.Bytes() From 223d1464aea6c3813f8daed26f51dababa796fe4 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:34:12 +0200 Subject: [PATCH 02/10] move nonce to correct offset, but old leaf --- trie/verkle.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trie/verkle.go b/trie/verkle.go index 3c4eea6c1ea2..22c7cefa5828 100644 --- a/trie/verkle.go +++ b/trie/verkle.go @@ -129,7 +129,7 @@ func (t *VerkleTrie) GetAccount(addr common.Address) (*types.StateAccount, error } if len(values[utils.NonceLeafKey]) > 0 { - acc.Nonce = binary.LittleEndian.Uint64(values[utils.NonceLeafKey]) + acc.Nonce = binary.LittleEndian.Uint64(values[utils.NonceLeafKey][utils.BasicDataNonceOffset:]) } // if the account has been deleted, then values[10] will be 0 and not nil. If it has // been recreated after that, then its code keccak will NOT be 0. So return `nil` if @@ -177,7 +177,7 @@ func (t *VerkleTrie) UpdateAccount(addr common.Address, acc *types.StateAccount) values[utils.CodeHashLeafKey] = acc.CodeHash[:] fmt.Printf("updating nonce=%x\n", nonce) - binary.LittleEndian.PutUint64(nonce[:], acc.Nonce) + binary.LittleEndian.PutUint64(nonce[utils.BasicDataNonceOffset:], acc.Nonce) bbytes := acc.Balance.Bytes() if len(bbytes) > 0 { for i, b := range bbytes { From 066b40d6efa6e69edde724956681614f7254d8f4 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:01:09 +0200 Subject: [PATCH 03/10] more traces --- trie/verkle.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trie/verkle.go b/trie/verkle.go index 22c7cefa5828..19f73fbae34b 100644 --- a/trie/verkle.go +++ b/trie/verkle.go @@ -129,6 +129,7 @@ func (t *VerkleTrie) GetAccount(addr common.Address) (*types.StateAccount, error } if len(values[utils.NonceLeafKey]) > 0 { + fmt.Printf("reading nonce=%x\n", values[utils.NonceLeafKey]) acc.Nonce = binary.LittleEndian.Uint64(values[utils.NonceLeafKey][utils.BasicDataNonceOffset:]) } // if the account has been deleted, then values[10] will be 0 and not nil. If it has @@ -175,9 +176,9 @@ func (t *VerkleTrie) UpdateAccount(addr common.Address, acc *types.StateAccount) values[utils.NonceLeafKey] = nonce[:] values[utils.BalanceLeafKey] = balance[:] values[utils.CodeHashLeafKey] = acc.CodeHash[:] - fmt.Printf("updating nonce=%x\n", nonce) binary.LittleEndian.PutUint64(nonce[utils.BasicDataNonceOffset:], acc.Nonce) + fmt.Printf("updating nonce=%x\n", nonce) bbytes := acc.Balance.Bytes() if len(bbytes) > 0 { for i, b := range bbytes { From 18bdeffc4c91d3de21b6724d87a70a2b9cd80efe Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:35:00 +0200 Subject: [PATCH 04/10] crazy test --- trie/utils/verkle.go | 2 +- trie/verkle.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/trie/utils/verkle.go b/trie/utils/verkle.go index a376512839e6..3f4d44f11b3e 100644 --- a/trie/utils/verkle.go +++ b/trie/utils/verkle.go @@ -30,7 +30,7 @@ const ( CodeHashLeafKey = 3 CodeSizeLeafKey = 4 - BasicDataNonceOffset = 8 + BasicDataNonceOffset = 0 maxPointCacheByteSize = 100 << 20 ) diff --git a/trie/verkle.go b/trie/verkle.go index 19f73fbae34b..59623c4d8578 100644 --- a/trie/verkle.go +++ b/trie/verkle.go @@ -173,12 +173,12 @@ func (t *VerkleTrie) UpdateAccount(addr common.Address, acc *types.StateAccount) // Only evaluate the polynomial once values[utils.VersionLeafKey] = zero[:] + binary.LittleEndian.PutUint64(nonce[utils.BasicDataNonceOffset:], acc.Nonce) + fmt.Printf("updating nonce=%x\n", nonce) values[utils.NonceLeafKey] = nonce[:] values[utils.BalanceLeafKey] = balance[:] values[utils.CodeHashLeafKey] = acc.CodeHash[:] - binary.LittleEndian.PutUint64(nonce[utils.BasicDataNonceOffset:], acc.Nonce) - fmt.Printf("updating nonce=%x\n", nonce) bbytes := acc.Balance.Bytes() if len(bbytes) > 0 { for i, b := range bbytes { From 47fd53588dabc21525b519cda418385266db7967 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:43:01 +0200 Subject: [PATCH 05/10] tries a shift with the conversion added --- core/overlay/conversion.go | 2 +- trie/utils/verkle.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/overlay/conversion.go b/core/overlay/conversion.go index 0e83e2066353..988e2f1f876d 100644 --- a/core/overlay/conversion.go +++ b/core/overlay/conversion.go @@ -105,7 +105,7 @@ func (kvm *keyValueMigrator) addAccount(addr []byte, acc *types.StateAccount) { leafNodeData.Values[utils.BalanceLeafKey] = balance[:] var nonce [verkle.LeafValueSize]byte - binary.LittleEndian.PutUint64(nonce[:8], acc.Nonce) + binary.LittleEndian.PutUint64(nonce[utils.BasicDataNonceOffset:], acc.Nonce) leafNodeData.Values[utils.NonceLeafKey] = nonce[:] leafNodeData.Values[utils.CodeHashLeafKey] = acc.CodeHash[:] diff --git a/trie/utils/verkle.go b/trie/utils/verkle.go index 3f4d44f11b3e..ec9e93e7568f 100644 --- a/trie/utils/verkle.go +++ b/trie/utils/verkle.go @@ -30,7 +30,7 @@ const ( CodeHashLeafKey = 3 CodeSizeLeafKey = 4 - BasicDataNonceOffset = 0 + BasicDataNonceOffset = 4 maxPointCacheByteSize = 100 << 20 ) From c99a27100c60cfb8525bb45d88af459b9894a3c7 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 16 Jul 2024 18:02:42 +0200 Subject: [PATCH 06/10] test if this is due to some hardcoded read --- trie/utils/verkle.go | 2 +- trie/verkle.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/trie/utils/verkle.go b/trie/utils/verkle.go index ec9e93e7568f..a376512839e6 100644 --- a/trie/utils/verkle.go +++ b/trie/utils/verkle.go @@ -30,7 +30,7 @@ const ( CodeHashLeafKey = 3 CodeSizeLeafKey = 4 - BasicDataNonceOffset = 4 + BasicDataNonceOffset = 8 maxPointCacheByteSize = 100 << 20 ) diff --git a/trie/verkle.go b/trie/verkle.go index 59623c4d8578..db96c84b1504 100644 --- a/trie/verkle.go +++ b/trie/verkle.go @@ -173,6 +173,7 @@ func (t *VerkleTrie) UpdateAccount(addr common.Address, acc *types.StateAccount) // Only evaluate the polynomial once values[utils.VersionLeafKey] = zero[:] + binary.LittleEndian.PutUint64(nonce[:], acc.Nonce) binary.LittleEndian.PutUint64(nonce[utils.BasicDataNonceOffset:], acc.Nonce) fmt.Printf("updating nonce=%x\n", nonce) values[utils.NonceLeafKey] = nonce[:] From b0a0682a24d851b532da97847c1e9d06238c7556 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 16 Jul 2024 18:24:14 +0200 Subject: [PATCH 07/10] weirder test still: swap 2 leaves --- trie/utils/verkle.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/trie/utils/verkle.go b/trie/utils/verkle.go index a376512839e6..e2c1697adf10 100644 --- a/trie/utils/verkle.go +++ b/trie/utils/verkle.go @@ -25,12 +25,12 @@ import ( const ( VersionLeafKey = 0 - BalanceLeafKey = 1 - NonceLeafKey = 2 + BalanceLeafKey = 2 + NonceLeafKey = 1 CodeHashLeafKey = 3 CodeSizeLeafKey = 4 - BasicDataNonceOffset = 8 + BasicDataNonceOffset = 0 maxPointCacheByteSize = 100 << 20 ) From 8e00ae052ad37f3cbb58c2afa37f9245fa4ab5ad Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 18 Jul 2024 10:42:36 +0200 Subject: [PATCH 08/10] add more traces --- consensus/beacon/consensus.go | 4 ++++ core/state/database.go | 10 +++++----- core/state_processor.go | 1 + miner/worker.go | 4 ++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index e40c180aa421..825661bbcc03 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -374,6 +374,7 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types. // FinalizeAndAssemble implements consensus.Engine, setting the final state and // assembling the block. func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt, withdrawals []*types.Withdrawal) (*types.Block, error) { + fmt.Println("finalizing and assembling block", beacon.IsPoSHeader(header)) if !beacon.IsPoSHeader(header) { return beacon.ethone.FinalizeAndAssemble(chain, header, state, txs, uncles, receipts, nil) } @@ -390,12 +391,15 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea } // Finalize and assemble the block. beacon.Finalize(chain, header, state, txs, uncles, withdrawals) + fmt.Println("finalization worked") // Assign the final state root to header. header.Root = state.IntermediateRoot(true) + fmt.Println("intermediate root worked") // Associate current conversion state to computed state // root and store it in the database for later recovery. state.Database().SaveTransitionState(header.Root) + fmt.Println("saved transition state") var ( p *verkle.VerkleProof diff --git a/core/state/database.go b/core/state/database.go index f2592f7de03a..175848921c77 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -558,7 +558,7 @@ func (db *cachingDB) SaveTransitionState(root common.Hash) { enc := gob.NewEncoder(&buf) err := enc.Encode(db.CurrentTransitionState) if err != nil { - log.Error("failed to encode transition state", "err", err) + fmt.Println("failed to encode transition state", "err", err) return } @@ -570,7 +570,7 @@ func (db *cachingDB) SaveTransitionState(root common.Hash) { rawdb.WriteVerkleTransitionState(db.DiskDB(), root, buf.Bytes()) } - 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) + 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) } } @@ -584,7 +584,7 @@ func (db *cachingDB) LoadTransitionState(root common.Hash) { // Not in the cache, try getting it from the DB data, err := rawdb.ReadVerkleTransitionState(db.DiskDB(), root) if err != nil { - log.Error("failed to read transition state", "err", err) + fmt.Println("failed to read transition state", "err", err) return } @@ -609,7 +609,7 @@ func (db *cachingDB) LoadTransitionState(root common.Hash) { // Initialize the first transition state, with the "ended" // field set to true if the database was created // as a verkle database. - log.Debug("no transition state found, starting fresh", "is verkle", db.triedb.IsVerkle()) + fmt.Println("no transition state found, starting fresh", "is verkle", db.triedb.IsVerkle()) // Start with a fresh state ts = &TransitionState{Ended: db.triedb.IsVerkle()} } @@ -619,7 +619,7 @@ func (db *cachingDB) LoadTransitionState(root common.Hash) { // doesn't get overwritten. db.CurrentTransitionState = ts.Copy() - 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) + 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) } func (db *cachingDB) LockCurrentTransitionState() { diff --git a/core/state_processor.go b/core/state_processor.go index d6a01673c6ab..5c1e9b99cea7 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -114,6 +114,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg log.Info("State root", "number", block.NumberU64(), "hash", stateRoot) } + fmt.Println("done processing txs") return receipts, allLogs, *usedGas, nil } diff --git a/miner/worker.go b/miner/worker.go index 3fb4a3fa43e5..c319e3190d9d 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1011,7 +1011,9 @@ func (w *worker) commitWork(interrupt *atomic.Int32, timestamp int64) { return } // Fill pending transactions from the txpool into the block. + fmt.Println("filling txs") err = w.fillTransactions(interrupt, work) + fmt.Println("filled txs", err) switch { case err == nil: // The entire block is filled, decrease resubmit interval in case @@ -1019,6 +1021,7 @@ func (w *worker) commitWork(interrupt *atomic.Int32, timestamp int64) { w.resubmitAdjustCh <- &intervalAdjust{inc: false} case errors.Is(err, errBlockInterruptedByRecommit): + fmt.Println("recommit") // Notify resubmit loop to increase resubmitting interval if the // interruption is due to frequent commits. gaslimit := work.header.GasLimit @@ -1032,6 +1035,7 @@ func (w *worker) commitWork(interrupt *atomic.Int32, timestamp int64) { } case errors.Is(err, errBlockInterruptedByNewHead): + fmt.Println("discarding block") // If the block building is interrupted by newhead event, discard it // totally. Committing the interrupted block introduces unnecessary // delay, and possibly causes miner to mine on the previous head, From b1a53f674a65209482f37d1aecd69e06acf61b59 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:37:02 +0200 Subject: [PATCH 09/10] traces in another location --- miner/worker.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/miner/worker.go b/miner/worker.go index c319e3190d9d..82b81092aa6e 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -714,6 +714,7 @@ func (w *worker) makeEnv(parent *types.Header, header *types.Header, coinbase co // updateSnapshot updates pending snapshot block, receipts and state. func (w *worker) updateSnapshot(env *environment) { + fmt.Println("updating snapshot") w.snapshotMu.Lock() defer w.snapshotMu.Unlock() @@ -980,8 +981,10 @@ func (w *worker) generateWork(params *generateParams) (*types.Block, *big.Int, e } block, err := w.engine.FinalizeAndAssemble(w.chain, work.header, work.state, work.txs, nil, work.receipts, params.withdrawals) if err != nil { + fmt.Println("error finalizing block", err) return nil, nil, err } + fmt.Println("finalized block") return block, totalFees(block, work.receipts), nil } @@ -1071,6 +1074,7 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti if err != nil { return err } + fmt.Println("finalize and assemble", err) // If we're post merge, just ignore if !w.isTTDReached(block.Header()) { From fd79e391806fe4862ea8ed4f60fb337b19d1481f Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:41:28 +0200 Subject: [PATCH 10/10] more traces --- miner/payload_building.go | 4 ++++ miner/worker.go | 1 + 2 files changed, 5 insertions(+) diff --git a/miner/payload_building.go b/miner/payload_building.go index 299196a3cdf3..806329f84898 100644 --- a/miner/payload_building.go +++ b/miner/payload_building.go @@ -19,6 +19,7 @@ package miner import ( "crypto/sha256" "encoding/binary" + "fmt" "math/big" "sync" "time" @@ -165,6 +166,7 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) { // Build the initial version with no transaction included. It should be fast // enough to run. The empty payload can at least make sure there is something // to deliver for not missing slot. + fmt.Println("getting empty version") empty, _, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, true) if err != nil { return nil, err @@ -189,7 +191,9 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) { select { case <-timer.C: start := time.Now() + fmt.Println("getting filled version") block, fees, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, false) + fmt.Println("got filled version", err, fees, block) if err == nil { payload.update(block, fees, time.Since(start)) } diff --git a/miner/worker.go b/miner/worker.go index 82b81092aa6e..100a11613c18 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -513,6 +513,7 @@ func (w *worker) mainLoop() { for { select { case req := <-w.newWorkCh: + fmt.Println("committing work") w.commitWork(req.interrupt, req.timestamp) case req := <-w.getWorkCh: