Skip to content

Commit 688952b

Browse files
authored
Enable verkle mode via Cancun fork block in genesis config (ethereum#23)
* add cancun fork to genesis. enable verkle with cancun fork * hack to create the statedb correctly when custom genesis is used * address review
1 parent d814087 commit 688952b

File tree

11 files changed

+51
-45
lines changed

11 files changed

+51
-45
lines changed

cmd/geth/chaincmd.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ var (
4949
ArgsUsage: "<genesisPath>",
5050
Flags: []cli.Flag{
5151
utils.DataDirFlag,
52-
utils.VerkleFlag,
5352
},
5453
Category: "BLOCKCHAIN COMMANDS",
5554
Description: `
@@ -201,10 +200,6 @@ func initGenesis(ctx *cli.Context) error {
201200
stack, _ := makeConfigNode(ctx)
202201
defer stack.Close()
203202

204-
if ctx.GlobalBool(utils.VerkleFlag.Name) {
205-
genesis.Config.UseVerkle = true
206-
}
207-
208203
for _, name := range []string{"chaindata", "lightchaindata"} {
209204
chaindb, err := stack.OpenDatabase(name, 0, 0, "", false)
210205
if err != nil {

cmd/geth/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ var (
150150
utils.MinerNotifyFullFlag,
151151
configFileFlag,
152152
utils.CatalystFlag,
153-
utils.VerkleFlag,
154153
}
155154

156155
rpcFlags = []cli.Flag{

cmd/geth/usage.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{
227227
utils.BloomFilterSizeFlag,
228228
cli.HelpFlag,
229229
utils.CatalystFlag,
230-
utils.VerkleFlag,
231230
},
232231
},
233232
}

cmd/utils/flags.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -775,11 +775,6 @@ var (
775775
Name: "catalyst",
776776
Usage: "Catalyst mode (eth2 integration testing)",
777777
}
778-
779-
VerkleFlag = cli.BoolFlag{
780-
Name: "verkle",
781-
Usage: "Enable geth with verkle trees (EXPERIMENTAL)",
782-
}
783778
)
784779

785780
// MakeDataDir retrieves the currently requested data directory, terminating
@@ -1454,7 +1449,7 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
14541449
// SetEthConfig applies eth-related command line flags to the config.
14551450
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
14561451
// Avoid conflicting network flags
1457-
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag, VerkleFlag)
1452+
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag)
14581453
CheckExclusive(ctx, LightServeFlag, SyncModeFlag, "light")
14591454
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
14601455
if ctx.GlobalString(GCModeFlag.Name) == "archive" && ctx.GlobalUint64(TxLookupLimitFlag.Name) != 0 {
@@ -1589,13 +1584,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
15891584
}
15901585
cfg.Genesis = core.DefaultGenesisBlock()
15911586
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
1592-
case ctx.GlobalBool(VerkleFlag.Name):
1593-
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
1594-
cfg.NetworkId = 86 // 'V'
1595-
}
1596-
cfg.Genesis = core.DefaultVerkleGenesisBlock()
1597-
cfg.Genesis.Config.UseVerkle = true
1598-
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
15991587
case ctx.GlobalBool(RopstenFlag.Name):
16001588
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
16011589
cfg.NetworkId = 3

consensus/misc/eip1559_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func copyConfig(original *params.ChainConfig) *params.ChainConfig {
4545
BerlinBlock: original.BerlinBlock,
4646
LondonBlock: original.LondonBlock,
4747
CatalystBlock: original.CatalystBlock,
48+
CancunBlock: original.CancunBlcok,
4849
Ethash: original.Ethash,
4950
Clique: original.Clique,
5051
}

core/blockchain.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,10 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
225225
futureBlocks, _ := lru.New(maxFutureBlocks)
226226

227227
bc := &BlockChain{
228-
chainConfig: chainConfig,
229-
cacheConfig: cacheConfig,
230-
db: db,
231-
triegc: prque.New(nil),
232-
stateCache: state.NewDatabaseWithConfig(db, &trie.Config{
233-
Cache: cacheConfig.TrieCleanLimit,
234-
Journal: cacheConfig.TrieCleanJournal,
235-
Preimages: cacheConfig.Preimages,
236-
UseVerkle: chainConfig.UseVerkle,
237-
}),
228+
chainConfig: chainConfig,
229+
cacheConfig: cacheConfig,
230+
db: db,
231+
triegc: prque.New(nil),
238232
quit: make(chan struct{}),
239233
shouldPreserve: shouldPreserve,
240234
bodyCache: bodyCache,
@@ -279,8 +273,16 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
279273
if err := bc.loadLastState(); err != nil {
280274
return nil, err
281275
}
276+
282277
// Make sure the state associated with the block is available
283278
head := bc.CurrentBlock()
279+
bc.stateCache = state.NewDatabaseWithConfig(db, &trie.Config{
280+
Cache: cacheConfig.TrieCleanLimit,
281+
Journal: cacheConfig.TrieCleanJournal,
282+
Preimages: cacheConfig.Preimages,
283+
UseVerkle: chainConfig.IsCancun(head.Header().Number),
284+
})
285+
284286
if _, err := state.New(head.Root(), bc.stateCache, bc.snaps); err != nil {
285287
// Head state is missing, before the state recovery, find out the
286288
// disk layer point of snapshot(if it's enabled). Make sure the
@@ -371,7 +373,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
371373
log.Warn("Enabling snapshot recovery", "chainhead", head.NumberU64(), "diskbase", *layer)
372374
recover = true
373375
}
374-
bc.snaps, _ = snapshot.New(bc.db, bc.stateCache.TrieDB(), bc.cacheConfig.SnapshotLimit, head.Root(), !bc.cacheConfig.SnapshotWait, true, recover, bc.Config().UseVerkle)
376+
bc.snaps, _ = snapshot.New(bc.db, bc.stateCache.TrieDB(), bc.cacheConfig.SnapshotLimit, head.Root(), !bc.cacheConfig.SnapshotWait, true, recover, chainConfig.IsCancun(head.Header().Number))
375377
}
376378
// Take ownership of this particular state
377379
go bc.update()

core/genesis.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,25 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
181181
// but the corresponding state is missing.
182182
header := rawdb.ReadHeader(db, stored, 0)
183183
var cfg *trie.Config = nil
184-
if genesis.Config.UseVerkle {
185-
cfg = &trie.Config{UseVerkle: true}
184+
if genesis == nil {
185+
// hacky: to open the statedb (check for missing genesis state below),
186+
// we need to know whether verkle is enabled which requires us to read the
187+
// chain config
188+
storedcfg := rawdb.ReadChainConfig(db, stored)
189+
if storedcfg == nil && storedcfg.CancunBlock != nil {
190+
if storedcfg.CancunBlock.Cmp(big.NewInt(0)) != 0 {
191+
panic("cancun block must be 0 (for now)")
192+
}
193+
194+
var blockNumber *big.Int
195+
if header != nil {
196+
blockNumber = new(big.Int).Set(header.Number)
197+
} else {
198+
blockNumber = big.NewInt(0)
199+
}
200+
201+
cfg = &trie.Config{UseVerkle: storedcfg.IsCancun(blockNumber)}
202+
}
186203
}
187204
if _, err := state.New(header.Root, state.NewDatabaseWithConfig(db, cfg), nil); err != nil {
188205
if genesis == nil {
@@ -265,7 +282,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
265282
}
266283
var trieCfg *trie.Config
267284
if g.Config != nil {
268-
trieCfg = &trie.Config{UseVerkle: g.Config.UseVerkle}
285+
trieCfg = &trie.Config{UseVerkle: g.Config.IsCancun(big.NewInt(int64(g.Number)))}
269286
}
270287
statedb, err := state.New(common.Hash{}, state.NewDatabaseWithConfig(db, trieCfg), nil)
271288
if err != nil {

core/state_processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func TestProcessStateless(t *testing.T) {
344344
BerlinBlock: big.NewInt(0),
345345
LondonBlock: big.NewInt(0),
346346
Ethash: new(params.EthashConfig),
347-
UseVerkle: true,
347+
CancunBlock: big.NewInt(0),
348348
}
349349
signer = types.LatestSigner(config)
350350
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")

core/vm/interpreter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
198198
// associated witness costs.
199199
inWitness := false
200200
var codePage common.Hash
201-
if in.evm.ChainConfig().UseVerkle {
201+
if in.evm.chainRules.IsCancun {
202202
index := trieUtils.GetTreeKeyCodeChunk(contract.Address().Bytes(), uint256.NewInt(pc/31))
203203

204204
var value [32]byte

eth/tracers/tracer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func TestNoStepExec(t *testing.T) {
207207
}
208208

209209
func TestIsPrecompile(t *testing.T) {
210-
chaincfg := &params.ChainConfig{ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, DAOForkSupport: false, EIP150Block: big.NewInt(0), EIP150Hash: common.Hash{}, EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), ByzantiumBlock: big.NewInt(100), ConstantinopleBlock: big.NewInt(0), PetersburgBlock: big.NewInt(0), IstanbulBlock: big.NewInt(200), MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(300), LondonBlock: big.NewInt(0), CatalystBlock: nil, Ethash: new(params.EthashConfig), Clique: nil}
210+
chaincfg := &params.ChainConfig{ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, DAOForkSupport: false, EIP150Block: big.NewInt(0), EIP150Hash: common.Hash{}, EIP155Block: big.NewInt(0), EIP158Block: big.NewInt(0), ByzantiumBlock: big.NewInt(100), ConstantinopleBlock: big.NewInt(0), PetersburgBlock: big.NewInt(0), IstanbulBlock: big.NewInt(200), MuirGlacierBlock: big.NewInt(0), BerlinBlock: big.NewInt(300), LondonBlock: big.NewInt(0), CatalystBlock: nil, CancunBlock: nil, Ethash: new(params.EthashConfig), Clique: nil}
211211
chaincfg.ByzantiumBlock = big.NewInt(100)
212212
chaincfg.IstanbulBlock = big.NewInt(200)
213213
chaincfg.BerlinBlock = big.NewInt(300)

0 commit comments

Comments
 (0)