Skip to content

Commit

Permalink
add switch to override the stride of the overlay conversion (#323)
Browse files Browse the repository at this point in the history
* add switch to override the stride of the overlay conversion

* set a default stride of 10k
  • Loading branch information
gballet authored Dec 5, 2023
1 parent dcb0a92 commit e842fd4
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 8 deletions.
4 changes: 4 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var (
utils.NoUSBFlag,
utils.USBFlag,
utils.SmartCardDaemonPathFlag,
utils.OverrideOverlayStride,
utils.OverrideCancun,
utils.OverridePrague,
utils.OverrideProofInBlock,
Expand Down
6 changes: 6 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
3 changes: 3 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
7 changes: 4 additions & 3 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions core/overlay/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e842fd4

Please sign in to comment.