Skip to content

Commit

Permalink
feat: bring ZkTrie in (#1076)
Browse files Browse the repository at this point in the history
Co-authored-by: colinlyguo <[email protected]>
  • Loading branch information
omerfirmak and colinlyguo authored Oct 31, 2024
1 parent 9f83e9d commit 6c4baae
Show file tree
Hide file tree
Showing 91 changed files with 3,653 additions and 1,631 deletions.
2 changes: 0 additions & 2 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ func runCmd(ctx *cli.Context) error {
triedb := trie.NewDatabase(db, &trie.Config{
Preimages: preimages,
HashDB: hashdb.Defaults,
// scroll related
IsUsingZktrie: genesisConfig.Config.Scroll.ZktrieEnabled(),
})
defer triedb.Close()
genesis := genesisConfig.MustCommit(db, triedb)
Expand Down
14 changes: 1 addition & 13 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ var (
GCModeFlag = &cli.StringFlag{
Name: "gcmode",
Usage: `Blockchain garbage collection mode, only relevant in state.scheme=hash ("full", "archive")`,
Value: GCModeArchive,
Value: GCModeFull,
Category: flags.StateCategory,
}
StateSchemeFlag = &cli.StringFlag{
Expand Down Expand Up @@ -2056,12 +2056,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
stack.Config().L1Confirmations = rpc.FinalizedBlockNumber
log.Info("Setting flag", "--l1.sync.startblock", "4038000")
stack.Config().L1DeploymentBlock = 4038000
// disable pruning
if ctx.String(GCModeFlag.Name) != GCModeArchive {
log.Crit("Must use --gcmode=archive")
}
log.Info("Pruning disabled")
cfg.NoPruning = true
case ctx.Bool(ScrollFlag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 534352
Expand All @@ -2072,12 +2066,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
stack.Config().L1Confirmations = rpc.FinalizedBlockNumber
log.Info("Setting flag", "--l1.sync.startblock", "18306000")
stack.Config().L1DeploymentBlock = 18306000
// disable pruning
if ctx.String(GCModeFlag.Name) != GCModeArchive {
log.Crit("Must use --gcmode=archive")
}
log.Info("Pruning disabled")
cfg.NoPruning = true
case ctx.Bool(DeveloperFlag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1337
Expand Down
14 changes: 5 additions & 9 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ type CacheConfig struct {
}

// triedbConfig derives the configures for trie database.
func (c *CacheConfig) triedbConfig(isUsingZktrie bool) *trie.Config {
config := &trie.Config{Preimages: c.Preimages, IsUsingZktrie: isUsingZktrie}
func (c *CacheConfig) triedbConfig() *trie.Config {
config := &trie.Config{Preimages: c.Preimages}
if c.StateScheme == rawdb.HashScheme {
config.HashDB = &hashdb.Config{
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
Expand All @@ -176,8 +176,8 @@ var defaultCacheConfig = &CacheConfig{
TrieCleanLimit: 256,
TrieDirtyLimit: 256,
TrieTimeLimit: 5 * time.Minute,
SnapshotLimit: 256,
SnapshotWait: true,
SnapshotLimit: 0, // Snapshots don't support zkTrie yet
SnapshotWait: false,
StateScheme: rawdb.HashScheme,
}

Expand Down Expand Up @@ -272,11 +272,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
cacheConfig = defaultCacheConfig
}
// Open trie database with provided config
triedbConfig := cacheConfig.triedbConfig(false)
if genesis != nil && genesis.Config != nil && genesis.Config.Scroll.ZktrieEnabled() {
cacheConfig.triedbConfig(true)
}
triedb := trie.NewDatabase(db, triedbConfig)
triedb := trie.NewDatabase(db, cacheConfig.triedbConfig())

// Setup the genesis block, commit the provided genesis specification
// to database if the genesis block is not present yet, or load the
Expand Down
3 changes: 2 additions & 1 deletion core/blockchain_repair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ func testLongReorgedSnapSyncingDeepRepair(t *testing.T, snapshots bool) {
}

func testRepair(t *testing.T, tt *rewindTest, snapshots bool) {
for _, scheme := range []string{rawdb.HashScheme, rawdb.PathScheme} {
for _, scheme := range []string{rawdb.HashScheme /*, rawdb.PathScheme*/} {
testRepairWithScheme(t, tt, snapshots, scheme)
}
}
Expand Down Expand Up @@ -1898,6 +1898,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s
// In this case the snapshot layer of B3 is not created because of existent
// state.
func TestIssue23496(t *testing.T) {
t.Skip("snapshot doesn't support zktrie")
testIssue23496(t, rawdb.HashScheme)
testIssue23496(t, rawdb.PathScheme)
}
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_sethead_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ func testLongReorgedSnapSyncingDeepSetHead(t *testing.T, snapshots bool) {
}

func testSetHead(t *testing.T, tt *rewindTest, snapshots bool) {
for _, scheme := range []string{rawdb.HashScheme, rawdb.PathScheme} {
for _, scheme := range []string{rawdb.HashScheme /*, rawdb.PathScheme*/} {
testSetHeadWithScheme(t, tt, snapshots, scheme)
}
}
Expand Down
3 changes: 3 additions & 0 deletions core/blockchain_snapshot_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build all_tests
// +build all_tests

// Copyright 2020 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
Expand Down
Loading

0 comments on commit 6c4baae

Please sign in to comment.