Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update code size in UpdateAccount + remove update from UpdateAccountCode #459

Draft
wants to merge 10 commits into
base: kaustinen-with-shapella
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/overlay/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:]
Expand Down
10 changes: 5 additions & 5 deletions core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

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

Expand All @@ -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()}
}
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions miner/payload_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package miner
import (
"crypto/sha256"
"encoding/binary"
"fmt"
"math/big"
"sync"
"time"
Expand Down Expand Up @@ -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
Expand All @@ -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))
}
Expand Down
9 changes: 9 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -1011,14 +1015,17 @@ 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
// of current interval is larger than the user-specified one.
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
Expand All @@ -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,
Expand Down Expand Up @@ -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()) {
Expand Down
6 changes: 4 additions & 2 deletions trie/utils/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
7 changes: 5 additions & 2 deletions trie/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Loading