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

post-genesis transition #426

Merged
merged 8 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ var (
OverrideProofInBlock = &cli.BoolFlag{
Name: "override.blockproof",
Usage: "Manually specify the proof-in-block setting",
gballet marked this conversation as resolved.
Show resolved Hide resolved
Value: true,
Category: flags.EthCategory,
}
ClearVerkleCosts = &cli.BoolFlag{
Expand Down
5 changes: 4 additions & 1 deletion consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.
}

if chain.Config().IsPrague(header.Number, header.Time) {
fmt.Println("at block", header.Number, "performing transition?", state.Database().InTransition())
// uncomment when debugging
// fmt.Println("at block", header.Number, "performing transition?", state.Database().InTransition())
parent := chain.GetHeaderByHash(header.ParentHash)
if err := overlay.OverlayVerkleTransition(state, parent.Root, chain.Config().OverlayStride); err != nil {
log.Error("error performing the transition", "err", err)
Expand Down Expand Up @@ -392,6 +393,8 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea

// Assign the final state root to header.
header.Root = state.IntermediateRoot(true)
// Associate current conversion state to computed state
// root and store it in the database for later recovery.
state.Database().SaveTransitionState(header.Root)
gballet marked this conversation as resolved.
Show resolved Hide resolved

var (
Expand Down
3 changes: 3 additions & 0 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {
return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error())
}
// Verify that the advertised root is correct before
// it can be usedas an identifier for the conversion
gballet marked this conversation as resolved.
Show resolved Hide resolved
// status.
statedb.Database().SaveTransitionState(header.Root)
gballet marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
txLookupCacheLimit = 1024
maxFutureBlocks = 256
maxTimeFutureBlocks = 30
gballet marked this conversation as resolved.
Show resolved Hide resolved
TriesInMemory = 8192

// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
//
Expand Down Expand Up @@ -320,7 +319,7 @@
head := bc.CurrentBlock()

// Declare the end of the verkle transition if need be
if bc.chainConfig.Rules(head.Number, false /* XXX */, head.Time).IsPrague {
if bc.chainConfig.IsPrague(head.Number, head.Time) {
// TODO this only works when resuming a chain that has already gone
// through the conversion. All pointers should be saved to the DB
// for it to be able to recover if interrupted during the transition
Expand Down Expand Up @@ -972,7 +971,7 @@
if !bc.cacheConfig.TrieDirtyDisabled {
triedb := bc.triedb

for _, offset := range []uint64{0, 1, TriesInMemory - 1} {

Check failure on line 974 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / build

undefined: TriesInMemory

Check failure on line 974 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TriesInMemory

Check failure on line 974 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TriesInMemory

Check failure on line 974 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / test-process-verkle

undefined: TriesInMemory

Check failure on line 974 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / build

undefined: TriesInMemory
if number := bc.CurrentBlock().Number.Uint64(); number > offset {
recent := bc.GetBlockByNumber(number - offset)

Expand Down Expand Up @@ -1378,7 +1377,7 @@

current := block.NumberU64()
// Flush limits are not considered for the first TriesInMemory blocks.
if current <= TriesInMemory {

Check failure on line 1380 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / build

undefined: TriesInMemory

Check failure on line 1380 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TriesInMemory

Check failure on line 1380 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TriesInMemory

Check failure on line 1380 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / test-process-verkle

undefined: TriesInMemory

Check failure on line 1380 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / build

undefined: TriesInMemory
return nil
}
// If we exceeded our memory allowance, flush matured singleton nodes to disk
Expand All @@ -1390,7 +1389,7 @@
bc.triedb.Cap(limit - ethdb.IdealBatchSize)
}
// Find the next state trie we need to commit
chosen := current - TriesInMemory

Check failure on line 1392 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / build

undefined: TriesInMemory

Check failure on line 1392 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TriesInMemory

Check failure on line 1392 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TriesInMemory

Check failure on line 1392 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / test-process-verkle

undefined: TriesInMemory

Check failure on line 1392 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / build

undefined: TriesInMemory
flushInterval := time.Duration(bc.flushInterval.Load())
// If we exceeded time allowance, flush an entire trie to disk
if bc.gcproc > flushInterval {
Expand All @@ -1402,8 +1401,8 @@
} else {
// If we're exceeding limits but haven't reached a large enough memory gap,
// warn the user that the system is becoming unstable.
if chosen < bc.lastWrite+TriesInMemory && bc.gcproc >= 2*flushInterval {

Check failure on line 1404 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / build

undefined: TriesInMemory

Check failure on line 1404 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TriesInMemory

Check failure on line 1404 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / test-process-verkle

undefined: TriesInMemory

Check failure on line 1404 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / build

undefined: TriesInMemory
log.Info("State in memory for too long, committing", "time", bc.gcproc, "allowance", flushInterval, "optimum", float64(chosen-bc.lastWrite)/TriesInMemory)

Check failure on line 1405 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / build

undefined: TriesInMemory

Check failure on line 1405 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TriesInMemory) (typecheck)

Check failure on line 1405 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / test-process-verkle

undefined: TriesInMemory

Check failure on line 1405 in core/blockchain.go

View workflow job for this annotation

GitHub Actions / build

undefined: TriesInMemory
}
// Flush an entire trie and restart the counters
bc.triedb.Commit(header.Root, true)
Expand Down
4 changes: 2 additions & 2 deletions core/overlay/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func OverlayVerkleTransition(statedb *state.StateDB, root common.Hash, maxMovedC
// verkle transition: if the conversion process is in progress, move
// N values from the MPT into the verkle tree.
if migrdb.InTransition() {
fmt.Printf("Processing verkle conversion starting at %x %x, building on top of %x\n", migrdb.GetCurrentAccountHash(), migrdb.GetCurrentSlotHash(), root)
log.Debug("Processing verkle conversion starting", "account hash", migrdb.GetCurrentAccountHash(), "slot hash", migrdb.GetCurrentSlotHash(), "state root", root)
var (
now = time.Now()
tt = statedb.GetTrie().(*trie.TransitionTrie)
Expand Down Expand Up @@ -291,7 +291,7 @@ func OverlayVerkleTransition(statedb *state.StateDB, root common.Hash, maxMovedC
for count < maxMovedCount {
acc, err := types.FullAccount(accIt.Account())
if err != nil {
fmt.Println("Invalid account encountered during traversal", "error", err)
log.Error("Invalid account encountered during traversal", "error", err)
return err
}
vkt.SetStorageRootConversion(*migrdb.GetCurrentAccountAddress(), acc.Root)
Expand Down
3 changes: 0 additions & 3 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,6 @@ func (st *StateTransition) refundGas(refundQuotient uint64) {
remaining := new(big.Int).Mul(new(big.Int).SetUint64(st.gasRemaining), st.msg.GasPrice)
st.state.AddBalance(st.msg.From, remaining)

if st.gp.Gas() > math.MaxUint64-st.gasRemaining {
fmt.Println(st.gp.Gas(), refund, refundQuotient, st.gasUsed(), st.initialGas, st.gasUsed(), st.evm.Accesses, st.msg)
}

// Also return remaining gas to the block gas counter so it is
// available for the next transaction.
Expand Down
Loading