From e842fd4cdfa81549b4efb03343534f141efcf7ee Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:44:28 +0100 Subject: [PATCH] add switch to override the stride of the overlay conversion (#323) * add switch to override the stride of the overlay conversion * set a default stride of 10k --- cmd/geth/config.go | 4 ++++ cmd/geth/main.go | 1 + cmd/utils/flags.go | 6 ++++++ consensus/beacon/consensus.go | 2 +- core/blockchain.go | 3 +++ core/genesis.go | 7 ++++--- core/overlay/conversion.go | 5 ++--- eth/ethconfig/config.go | 3 +++ params/config.go | 3 ++- 9 files changed, 26 insertions(+), 8 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 4e861d75350b..cdd893d2a8ec 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -179,6 +179,10 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { v := ctx.Bool(utils.OverrideProofInBlock.Name) cfg.Eth.OverrideProofInBlock = &v } + if ctx.IsSet(utils.OverrideOverlayStride.Name) { + v := ctx.Uint64(utils.OverrideOverlayStride.Name) + cfg.Eth.OverrideOverlayStride = &v + } backend, eth := utils.RegisterEthService(stack, &cfg.Eth) // Configure log filter RPC API. diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 2945a3c4b1f9..e2e4ba25fe06 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -67,6 +67,7 @@ var ( utils.NoUSBFlag, utils.USBFlag, utils.SmartCardDaemonPathFlag, + utils.OverrideOverlayStride, utils.OverrideCancun, utils.OverridePrague, utils.OverrideProofInBlock, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 5f071d0a7479..0dd311706abb 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -263,6 +263,12 @@ var ( Value: 2048, Category: flags.EthCategory, } + OverrideOverlayStride = &cli.Uint64Flag{ + Name: "override.overlay-stride", + Usage: "Manually specify the stride of the overlay transition, overriding the bundled setting", + Value: 10000, + Category: flags.EthCategory, + } OverrideCancun = &cli.Uint64Flag{ Name: "override.cancun", Usage: "Manually specify the Cancun fork timestamp, overriding the bundled setting", diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 6582a7bfb90b..7f22d6369a60 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -373,7 +373,7 @@ 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()) parent := chain.GetHeaderByHash(header.ParentHash) - overlay.OverlayVerkleTransition(state, parent.Root) + overlay.OverlayVerkleTransition(state, parent.Root, chain.Config().OverlayStride) } } diff --git a/core/blockchain.go b/core/blockchain.go index 462eba746938..39485505bb05 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -253,6 +253,9 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis if overrides.OverrideProofInBlock != nil { chainConfig.ProofInBlocks = *overrides.OverrideProofInBlock } + if overrides.OverrideOverlayStride != nil { + chainConfig.OverlayStride = *overrides.OverrideOverlayStride + } log.Info("") log.Info(strings.Repeat("-", 153)) for _, line := range strings.Split(chainConfig.Description(), "\n") { diff --git a/core/genesis.go b/core/genesis.go index 1a63062c308a..9a022f64f335 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -291,9 +291,10 @@ func (e *GenesisMismatchError) Error() string { // ChainOverrides contains the changes to chain config. type ChainOverrides struct { - OverrideCancun *uint64 - OverridePrague *uint64 - OverrideProofInBlock *bool + OverrideCancun *uint64 + OverridePrague *uint64 + OverrideProofInBlock *bool + OverrideOverlayStride *uint64 } // SetupGenesisBlock writes or updates the genesis block in db. diff --git a/core/overlay/conversion.go b/core/overlay/conversion.go index e76aa5900173..0e9047920a0b 100644 --- a/core/overlay/conversion.go +++ b/core/overlay/conversion.go @@ -217,7 +217,7 @@ func (kvm *keyValueMigrator) migrateCollectedKeyValues(tree *trie.VerkleTrie) er } // OverlayVerkleTransition contains the overlay conversion logic -func OverlayVerkleTransition(statedb *state.StateDB, root common.Hash) error { +func OverlayVerkleTransition(statedb *state.StateDB, root common.Hash, maxMovedCount uint64) error { migrdb := statedb.Database() // verkle transition: if the conversion process is in progress, move @@ -274,14 +274,13 @@ func OverlayVerkleTransition(statedb *state.StateDB, root common.Hash) error { preimageSeek += int64(len(addr)) } - const maxMovedCount = 10000 // mkv will be assiting in the collection of up to maxMovedCount key values to be migrated to the VKT. // It has internal caches to do efficient MPT->VKT key calculations, which will be discarded after // this function. mkv := newKeyValueMigrator() // move maxCount accounts into the verkle tree, starting with the // slots from the previous account. - count := 0 + count := uint64(0) // if less than maxCount slots were moved, move to the next account for count < maxMovedCount { diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index b9660f5c60b3..fc9550147bcc 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -161,6 +161,9 @@ type Config struct { // OverrideProofInBlock OverrideProofInBlock *bool `toml:",omitempty"` + + // OverrideOverlayStride + OverrideOverlayStride *uint64 `toml:",omitempty"` } // CreateConsensusEngine creates a consensus engine for the given chain config. diff --git a/params/config.go b/params/config.go index 19e633a71def..a2df06893a22 100644 --- a/params/config.go +++ b/params/config.go @@ -301,7 +301,8 @@ type ChainConfig struct { IsDevMode bool `json:"isDev,omitempty"` // Proof in block - ProofInBlocks bool `json:"proofInBlocks,omitempty"` + ProofInBlocks bool `json:"proofInBlocks,omitempty"` + OverlayStride uint64 `json:"overlayStride,omitempty"` } // EthashConfig is the consensus engine configs for proof-of-work based sealing.