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/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/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/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 3fb4a3fa43e5..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: @@ -714,6 +715,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 +982,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 } @@ -1011,7 +1015,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 +1025,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 +1039,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, @@ -1067,6 +1075,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()) { diff --git a/trie/utils/verkle.go b/trie/utils/verkle.go index ad6184baa99a..e2c1697adf10 100644 --- a/trie/utils/verkle.go +++ b/trie/utils/verkle.go @@ -25,11 +25,13 @@ import ( const ( VersionLeafKey = 0 - BalanceLeafKey = 1 - NonceLeafKey = 2 + BalanceLeafKey = 2 + NonceLeafKey = 1 CodeHashLeafKey = 3 CodeSizeLeafKey = 4 + BasicDataNonceOffset = 0 + maxPointCacheByteSize = 100 << 20 ) diff --git a/trie/verkle.go b/trie/verkle.go index f0568077fb35..db96c84b1504 100644 --- a/trie/verkle.go +++ b/trie/verkle.go @@ -129,7 +129,8 @@ func (t *VerkleTrie) GetAccount(addr common.Address) (*types.StateAccount, error } if len(values[utils.NonceLeafKey]) > 0 { - acc.Nonce = binary.LittleEndian.Uint64(values[utils.NonceLeafKey]) + 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 // been recreated after that, then its code keccak will NOT be 0. So return `nil` if @@ -172,11 +173,13 @@ 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[:] values[utils.BalanceLeafKey] = balance[:] values[utils.CodeHashLeafKey] = acc.CodeHash[:] - binary.LittleEndian.PutUint64(nonce[:], acc.Nonce) bbytes := acc.Balance.Bytes() if len(bbytes) > 0 { for i, b := range bbytes {