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

feat(snapshot): provide snapshot structure acceleration #324

Open
wants to merge 89 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
9485284
refactor: extract the zktrie logic into a new package, and prepare th…
mortal123 Apr 21, 2023
87d01e6
fix: reset the inner object for zktrie.Trie and zktrie.Secure
mortal123 Apr 21, 2023
8f18c57
Added tests for secure_trie_test and trie_test, skipping iterator and…
KevinYum Apr 23, 2023
c107000
adapt tests to zk-trie hash and encode contraints, remove benchmarks
KevinYum Apr 23, 2023
cbda0e0
feat: prove and verify for trie and secure trie
mortal123 Apr 23, 2023
ff4b17b
feat: struct BinaryPath to facilitate path representation
mortal123 Apr 23, 2023
406cf81
fix: proofs in statedb
mortal123 Apr 24, 2023
a6c009a
fix: set impl in trie
mortal123 Apr 24, 2023
4695cfc
fix: add zk trie magic bytes back
mortal123 Apr 25, 2023
fecd2f7
chore: secure trie add sanity checks for storage and account update
mortal123 Apr 25, 2023
9030b56
feat: add stack trie implementation
mortal123 Apr 25, 2023
85d7085
add test cases of proof_test for Trie
KevinYum Apr 26, 2023
ceeff53
fix: separate the use case of trie.Update and trie.UpdateAccount
mortal123 Apr 26, 2023
d9620b9
add test cases of proof_test for SecureTrie
KevinYum Apr 26, 2023
d77935d
fix: assign flag for leaf node in stack trie
mortal123 Apr 26, 2023
31ad213
chore: remove comments
mortal123 Apr 27, 2023
8c6e7dd
fix: fix bit order when update trie
mortal123 Apr 27, 2023
cf1d46b
chore: add key check in stacktrie
mortal123 Apr 27, 2023
095a0c0
add test cases of stacktrie_test
KevinYum Apr 27, 2023
dc98589
chore: replace zktrie with trie
mortal123 Apr 28, 2023
9df7803
chore: add binary path
mortal123 Apr 28, 2023
3c80d49
feat: trie iterator
mortal123 Apr 28, 2023
0cdb57f
feat: add proof range verify
mortal123 Apr 30, 2023
b16a518
fix test discrepancy introduced by commit e5af6e6
KevinYum May 2, 2023
c5df8ef
fix: remove debug log
mortal123 May 2, 2023
b857a85
feat: add iterator for secure trie
mortal123 May 2, 2023
2b5c2ac
chore: add key length checker in trie and stack_trie
mortal123 May 2, 2023
bec5e8e
fix: assign root hash for node iterator
mortal123 May 2, 2023
092de1e
fix: secure trie iterator bug
mortal123 May 2, 2023
065e203
Enforce trie_test and stacktrie_test cases to have key length of 32 b…
KevinYum May 2, 2023
1f07ad1
fix: make secure trie get key transform valid
mortal123 May 3, 2023
ef113e0
add test cases for iterator, align usage of key->secureKey conversion
KevinYum May 3, 2023
17e9f23
fix: save the unset internal node into cache
mortal123 May 4, 2023
826c66a
fix: range proof verification
mortal123 May 4, 2023
0eedd3a
fix: add trie update with kind method
mortal123 May 4, 2023
f217e05
chore: delete the snapshot disable
mortal123 May 4, 2023
43db248
fix: correcting account marshalling
mortal123 May 4, 2023
df91a1e
fix: check keys range in range proof verify
mortal123 May 4, 2023
945789f
add test cases for rangeVerify
KevinYum May 4, 2023
4c6e214
chore: fix minor issues and move poseidon hash into crypto packages
mortal123 May 5, 2023
48d8eaf
add basic benchmarks for geth and snap feature for comparison
KevinYum May 6, 2023
4de19cc
add snap sync
mortal123 May 8, 2023
895ac7f
fix iterator value decode bug
mortal123 May 8, 2023
fd8382d
enable cleans cache for trie database
mortal123 May 8, 2023
1816186
adopt proof tracer with secure trie
mortal123 May 9, 2023
6110df9
fix empty root hash
mortal123 May 9, 2023
c1339d8
allow snapshot diff layer do the accumulation when snapshot is genera…
mortal123 May 11, 2023
0e21b17
fix file import
mortal123 May 11, 2023
c67e3e4
make tests compilable
mortal123 May 11, 2023
b5850c2
dump log if zktrie is disabled
mortal123 May 11, 2023
af4ffc7
fix bugs for testing
mortal123 May 11, 2023
d596e08
add range proof test for account trie
KevinYum May 12, 2023
53e58c1
fix the checking method for trie node
mortal123 May 12, 2023
d7fb7c2
chore: go fmt with imports
mortal123 May 12, 2023
0120513
add node hash method
mortal123 May 12, 2023
a34513d
bug fix
mortal123 May 12, 2023
d61cef6
bug fix for zktrie proof
mortal123 May 12, 2023
ace8416
add test cases to sync(healer)
KevinYum May 12, 2023
0290fab
provide toString function for trie
mortal123 May 13, 2023
c5f6453
fix bug for hashing node proof key
mortal123 May 13, 2023
4ffc934
fix test code generate_test.go and genesis_test.go, handle correspond…
mortal123 May 13, 2023
6ca5353
fix testcases in statedb_test.go
mortal123 May 13, 2023
5bb7436
change compact encoding
mortal123 May 14, 2023
ee908e3
fix bugs and testcase (state sync)
mortal123 May 14, 2023
811e93a
disable DESTRUCT opcode testcase
mortal123 May 14, 2023
b3dce78
correcting the judgement of empty zktrie
mortal123 May 14, 2023
50640b3
add test cases for snap/sync_test (not passed yet)
KevinYum May 14, 2023
1a7417d
fix bugs for testcase and stacktrie
mortal123 May 14, 2023
7ada128
shrink test size for snap/sync_test to adapt poor trie performance
KevinYum May 15, 2023
239c07a
fix bugs for testcase
mortal123 May 15, 2023
77c4db5
fix tracer testcase
mortal123 May 15, 2023
fc90758
fix api testcase
mortal123 May 15, 2023
fee15c7
fix testcases in downloader and enable fast sync
mortal123 May 15, 2023
9dc5d2d
change the tree cap strategy
mortal123 May 16, 2023
71c9917
skip testcase related to zktrie database
mortal123 May 16, 2023
29b2943
Merge branch 'develop' of https://github.com/scroll-tech/go-ethereum …
mortal123 May 16, 2023
838aaaa
chore for pr check
mortal123 May 16, 2023
0fc49c5
makefile tests include zktrie
mortal123 May 16, 2023
868258f
fix bugs related account decode
mortal123 May 17, 2023
39b9d99
fix bugs of sync depth
mortal123 May 20, 2023
35cb810
add comment
mortal123 May 21, 2023
5deab05
enable zktrie snap sync
mortal123 May 23, 2023
ed09860
add benchmark for stacktrie
mortal123 May 23, 2023
987d7ad
eliminate inappropriate fmt printf
mortal123 May 23, 2023
1009e84
fix comment style in core/blockchain_test.go
mortal123 May 23, 2023
0059a2a
fix comment style
mortal123 May 23, 2023
ec5c3a9
merge from develop
mortal123 May 23, 2023
339e03f
fix account encoding in cmd snapshot
mortal123 May 24, 2023
8c6618f
Merge tag 'scroll-v3.3.1' of https://github.com/scroll-tech/go-ethere…
mortal123 May 29, 2023
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
Next Next commit
refactor: extract the zktrie logic into a new package, and prepare th…
…e module scaffolding required by the snapshot feature
  • Loading branch information
mortal123 committed May 9, 2023
commit 9485284ef3ed52003343555946067d5e91c0c337
5 changes: 3 additions & 2 deletions cmd/geth/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/rlp"
"github.com/scroll-tech/go-ethereum/trie"
"github.com/scroll-tech/go-ethereum/zktrie"
)

var (
Expand Down Expand Up @@ -226,7 +227,7 @@ func verifyState(ctx *cli.Context) error {
log.Error("Failed to load head block")
return errors.New("no head block")
}
snaptree, err := snapshot.New(chaindb, trie.NewDatabase(chaindb), 256, headBlock.Root(), false, false, false)
snaptree, err := snapshot.New(chaindb, zktrie.NewDatabase(chaindb), 256, headBlock.Root(), false, false, false)
if err != nil {
log.Error("Failed to open snapshot tree", "err", err)
return err
Expand Down Expand Up @@ -478,7 +479,7 @@ func dumpState(ctx *cli.Context) error {
if err != nil {
return err
}
snaptree, err := snapshot.New(db, trie.NewDatabase(db), 256, root, false, false, false)
snaptree, err := snapshot.New(db, zktrie.NewDatabase(db), 256, root, false, false, false)
if err != nil {
return err
}
Expand Down
17 changes: 10 additions & 7 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import (
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/metrics"
"github.com/scroll-tech/go-ethereum/params"
"github.com/scroll-tech/go-ethereum/trie"
"github.com/scroll-tech/go-ethereum/trie/zkproof"
"github.com/scroll-tech/go-ethereum/zktrie"
"github.com/scroll-tech/go-ethereum/zktrie/zkproof"
)

var (
Expand Down Expand Up @@ -240,16 +240,19 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
log.Warn("Using fee vault address", "FeeVaultAddress", *chainConfig.Scroll.FeeVaultAddress)
}

if !chainConfig.Scroll.ZktrieEnabled() {
panic("zktrie should be enabled")
}

bc := &BlockChain{
chainConfig: chainConfig,
cacheConfig: cacheConfig,
db: db,
triegc: prque.New(nil),
stateCache: state.NewDatabaseWithConfig(db, &trie.Config{
Cache: cacheConfig.TrieCleanLimit,
Journal: cacheConfig.TrieCleanJournal,
stateCache: state.NewDatabaseWithConfig(db, &zktrie.Config{
Cache: cacheConfig.TrieCleanLimit,
//Journal: cacheConfig.TrieCleanJournal,
Preimages: cacheConfig.Preimages,
Zktrie: chainConfig.Scroll.ZktrieEnabled(),
}),
quit: make(chan struct{}),
chainmu: syncx.NewClosableMutex(),
Expand Down Expand Up @@ -653,7 +656,7 @@ func (bc *BlockChain) FastSyncCommitHead(hash common.Hash) error {
if block == nil {
return fmt.Errorf("non existent block [%x..]", hash[:4])
}
if _, err := trie.NewSecure(block.Root(), bc.stateCache.TrieDB()); err != nil {
if _, err := zktrie.NewSecure(block.Root(), bc.stateCache.TrieDB()); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we totally drop any options for non-zktrie db within this PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I understand that there is no reason for us to use the original trie for related operations involving state? However, in some places where block, transaction and receipt trie are calculated, the original trie is still used

return err
}

Expand Down
22 changes: 2 additions & 20 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
// We have the genesis block in database(perhaps in ancient database)
// but the corresponding state is missing.
header := rawdb.ReadHeader(db, stored, 0)

var trieCfg *trie.Config

if genesis == nil {
storedcfg := rawdb.ReadChainConfig(db, stored)
if storedcfg == nil {
log.Warn("Found genesis block without chain config")
} else {
trieCfg = &trie.Config{Zktrie: storedcfg.Scroll.ZktrieEnabled()}
}
} else {
trieCfg = &trie.Config{Zktrie: genesis.Config.Scroll.ZktrieEnabled()}
}

if _, err := state.New(header.Root, state.NewDatabaseWithConfig(db, trieCfg), nil); err != nil {
if _, err := state.New(header.Root, state.NewDatabaseWithConfig(db, nil), nil); err != nil {
if genesis == nil {
genesis = DefaultGenesisBlock()
}
Expand Down Expand Up @@ -275,11 +261,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
if db == nil {
db = rawdb.NewMemoryDatabase()
}
var trieCfg *trie.Config
if g.Config != nil {
trieCfg = &trie.Config{Zktrie: g.Config.Scroll.ZktrieEnabled()}
}
statedb, err := state.New(common.Hash{}, state.NewDatabaseWithConfig(db, trieCfg), nil)
statedb, err := state.New(common.Hash{}, state.NewDatabaseWithConfig(db, nil), nil)
if err != nil {
panic(err)
}
Expand Down
40 changes: 11 additions & 29 deletions core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/scroll-tech/go-ethereum/core/rawdb"
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/ethdb"
"github.com/scroll-tech/go-ethereum/trie"
"github.com/scroll-tech/go-ethereum/zktrie"
)

const (
Expand Down Expand Up @@ -56,7 +56,7 @@ type Database interface {
ContractCodeSize(addrHash, codeHash common.Hash) (int, error)

// TrieDB retrieves the low level trie database used for data storage.
TrieDB() *trie.Database
TrieDB() *zktrie.Database
}

// Trie is a Ethereum Merkle Patricia trie.
Expand Down Expand Up @@ -91,11 +91,11 @@ type Trie interface {

// Commit writes all nodes to the trie's memory database, tracking the internal
// and external (for account tries) references.
Commit(onleaf trie.LeafCallback) (common.Hash, int, error)
Commit(onleaf zktrie.LeafCallback) (common.Hash, int, error)

// NodeIterator returns an iterator that returns nodes of the trie. Iteration
// starts at the key after the given start key.
NodeIterator(startKey []byte) trie.NodeIterator
NodeIterator(startKey []byte) zktrie.NodeIterator

// Prove constructs a Merkle proof for key. The result contains all encoded nodes
// on the path to the value at key. The value itself is also included in the last
Expand All @@ -117,33 +117,24 @@ func NewDatabase(db ethdb.Database) Database {
// NewDatabaseWithConfig creates a backing store for state. The returned database
// is safe for concurrent use and retains a lot of collapsed RLP trie nodes in a
// large memory cache.
func NewDatabaseWithConfig(db ethdb.Database, config *trie.Config) Database {
func NewDatabaseWithConfig(db ethdb.Database, config *zktrie.Config) Database {
csc, _ := lru.New(codeSizeCacheSize)
return &cachingDB{
zktrie: config != nil && config.Zktrie,
db: trie.NewDatabaseWithConfig(db, config),
db: zktrie.NewDatabaseWithConfig(db, config),
codeSizeCache: csc,
codeCache: fastcache.New(codeCacheSize),
}
}

type cachingDB struct {
db *trie.Database
db *zktrie.Database
codeSizeCache *lru.Cache
codeCache *fastcache.Cache
zktrie bool
}

// OpenTrie opens the main account trie at a specific root hash.
func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) {
if db.zktrie {
tr, err := trie.NewZkTrie(root, trie.NewZktrieDatabaseFromTriedb(db.db))
if err != nil {
return nil, err
}
return tr, nil
}
tr, err := trie.NewSecure(root, db.db)
tr, err := zktrie.NewSecure(root, db.db)
if err != nil {
return nil, err
}
Expand All @@ -152,14 +143,7 @@ func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) {

// OpenStorageTrie opens the storage trie of an account.
func (db *cachingDB) OpenStorageTrie(addrHash, root common.Hash) (Trie, error) {
if db.zktrie {
tr, err := trie.NewZkTrie(root, trie.NewZktrieDatabaseFromTriedb(db.db))
if err != nil {
return nil, err
}
return tr, nil
}
tr, err := trie.NewSecure(root, db.db)
tr, err := zktrie.NewSecure(root, db.db)
if err != nil {
return nil, err
}
Expand All @@ -169,9 +153,7 @@ func (db *cachingDB) OpenStorageTrie(addrHash, root common.Hash) (Trie, error) {
// CopyTrie returns an independent copy of the given trie.
func (db *cachingDB) CopyTrie(t Trie) Trie {
switch t := t.(type) {
case *trie.SecureTrie:
return t.Copy()
case *trie.ZkTrie:
case *zktrie.SecureTrie:
return t.Copy()
default:
panic(fmt.Errorf("unknown trie type %T", t))
Expand Down Expand Up @@ -218,6 +200,6 @@ func (db *cachingDB) ContractCodeSize(addrHash, codeHash common.Hash) (int, erro
}

// TrieDB retrieves any intermediate trie-node caching layer.
func (db *cachingDB) TrieDB() *trie.Database {
func (db *cachingDB) TrieDB() *zktrie.Database {
return db.db
}
5 changes: 3 additions & 2 deletions core/state/pruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/rlp"
"github.com/scroll-tech/go-ethereum/trie"
"github.com/scroll-tech/go-ethereum/zktrie"
)

const (
Expand Down Expand Up @@ -89,7 +90,7 @@ func NewPruner(db ethdb.Database, datadir, trieCachePath string, bloomSize uint6
if headBlock == nil {
return nil, errors.New("Failed to load head block")
}
snaptree, err := snapshot.New(db, trie.NewDatabase(db), 256, headBlock.Root(), false, false, false)
snaptree, err := snapshot.New(db, zktrie.NewDatabase(db), 256, headBlock.Root(), false, false, false)
if err != nil {
return nil, err // The relevant snapshot(s) might not exist
}
Expand Down Expand Up @@ -362,7 +363,7 @@ func RecoverPruning(datadir string, db ethdb.Database, trieCachePath string) err
// - The state HEAD is rewound already because of multiple incomplete `prune-state`
// In this case, even the state HEAD is not exactly matched with snapshot, it
// still feasible to recover the pruning correctly.
snaptree, err := snapshot.New(db, trie.NewDatabase(db), 256, headBlock.Root(), false, false, true)
snaptree, err := snapshot.New(db, zktrie.NewDatabase(db), 256, headBlock.Root(), false, false, true)
if err != nil {
return err // The relevant snapshot(s) might not exist
}
Expand Down
4 changes: 2 additions & 2 deletions core/state/snapshot/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/scroll-tech/go-ethereum/ethdb"
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/rlp"
"github.com/scroll-tech/go-ethereum/trie"
"github.com/scroll-tech/go-ethereum/zktrie"
)

// trieKV represents a trie key-value pair
Expand Down Expand Up @@ -361,7 +361,7 @@ func generateTrieRoot(db ethdb.KeyValueWriter, it Iterator, account common.Hash,
}

func stackTrieGenerate(db ethdb.KeyValueWriter, in chan trieKV, out chan common.Hash) {
t := trie.NewStackTrie(db)
t := zktrie.NewStackTrie(db)
for leaf := range in {
t.TryUpdate(leaf.key[:], leaf.value)
}
Expand Down
4 changes: 2 additions & 2 deletions core/state/snapshot/disklayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
"github.com/scroll-tech/go-ethereum/core/rawdb"
"github.com/scroll-tech/go-ethereum/ethdb"
"github.com/scroll-tech/go-ethereum/rlp"
"github.com/scroll-tech/go-ethereum/trie"
"github.com/scroll-tech/go-ethereum/zktrie"
)

// diskLayer is a low level persistent snapshot built on top of a key-value store.
type diskLayer struct {
diskdb ethdb.KeyValueStore // Key-value store containing the base snapshot
triedb *trie.Database // Trie node cache for reconstruction purposes
triedb *zktrie.Database // Trie node cache for reconstruction purposes
cache *fastcache.Cache // Cache to avoid hitting the disk for direct access

root common.Hash // Root hash of the base snapshot
Expand Down
30 changes: 15 additions & 15 deletions core/state/snapshot/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/metrics"
"github.com/scroll-tech/go-ethereum/rlp"
"github.com/scroll-tech/go-ethereum/trie"
"github.com/scroll-tech/go-ethereum/zktrie"
)

var (
Expand Down Expand Up @@ -146,7 +146,7 @@ func (gs *generatorStats) Log(msg string, root common.Hash, marker []byte) {
// generateSnapshot regenerates a brand new snapshot based on an existing state
// database and head block asynchronously. The snapshot is returned immediately
// and generation is continued in the background until done.
func generateSnapshot(diskdb ethdb.KeyValueStore, triedb *trie.Database, cache int, root common.Hash) *diskLayer {
func generateSnapshot(diskdb ethdb.KeyValueStore, triedb *zktrie.Database, cache int, root common.Hash) *diskLayer {
// Create a new disk layer with an initialized state marker at zero
var (
stats = &generatorStats{start: time.Now()}
Expand Down Expand Up @@ -208,12 +208,12 @@ func journalProgress(db ethdb.KeyValueWriter, marker []byte, stats *generatorSta
// proofResult contains the output of range proving which can be used
// for further processing regardless if it is successful or not.
type proofResult struct {
keys [][]byte // The key set of all elements being iterated, even proving is failed
vals [][]byte // The val set of all elements being iterated, even proving is failed
diskMore bool // Set when the database has extra snapshot states since last iteration
trieMore bool // Set when the trie has extra snapshot states(only meaningful for successful proving)
proofErr error // Indicator whether the given state range is valid or not
tr *trie.Trie // The trie, in case the trie was resolved by the prover (may be nil)
keys [][]byte // The key set of all elements being iterated, even proving is failed
vals [][]byte // The val set of all elements being iterated, even proving is failed
diskMore bool // Set when the database has extra snapshot states since last iteration
trieMore bool // Set when the trie has extra snapshot states(only meaningful for successful proving)
proofErr error // Indicator whether the given state range is valid or not
tr *zktrie.Trie // The trie, in case the trie was resolved by the prover (may be nil)
}

// valid returns the indicator that range proof is successful or not.
Expand Down Expand Up @@ -308,7 +308,7 @@ func (dl *diskLayer) proveRange(stats *generatorStats, root common.Hash, prefix

// The snap state is exhausted, pass the entire key/val set for verification
if origin == nil && !diskMore {
stackTr := trie.NewStackTrie(nil)
stackTr := zktrie.NewStackTrie(nil)
for i, key := range keys {
stackTr.TryUpdate(key, vals[i])
}
Expand All @@ -322,7 +322,7 @@ func (dl *diskLayer) proveRange(stats *generatorStats, root common.Hash, prefix
return &proofResult{keys: keys, vals: vals}, nil
}
// Snap state is chunked, generate edge proofs for verification.
tr, err := trie.New(root, dl.triedb)
tr, err := zktrie.New(root, dl.triedb)
if err != nil {
stats.Log("Trie missing, state snapshotting paused", dl.root, dl.genMarker)
return nil, errMissingTrie
Expand Down Expand Up @@ -360,7 +360,7 @@ func (dl *diskLayer) proveRange(stats *generatorStats, root common.Hash, prefix
}
// Verify the snapshot segment with range prover, ensure that all flat states
// in this range correspond to merkle trie.
cont, err := trie.VerifyRangeProof(root, origin, last, keys, vals, proof)
cont, err := zktrie.VerifyRangeProof(root, origin, last, keys, vals, proof)
return &proofResult{
keys: keys,
vals: vals,
Expand Down Expand Up @@ -433,8 +433,8 @@ func (dl *diskLayer) generateRange(root common.Hash, prefix []byte, kind string,
var snapNodeCache ethdb.KeyValueStore
if len(result.keys) > 0 {
snapNodeCache = memorydb.New()
snapTrieDb := trie.NewDatabase(snapNodeCache)
snapTrie, _ := trie.New(common.Hash{}, snapTrieDb)
snapTrieDb := zktrie.NewDatabase(snapNodeCache)
snapTrie, _ := zktrie.New(common.Hash{}, snapTrieDb)
for i, key := range result.keys {
snapTrie.Update(key, result.vals[i])
}
Expand All @@ -443,7 +443,7 @@ func (dl *diskLayer) generateRange(root common.Hash, prefix []byte, kind string,
}
tr := result.tr
if tr == nil {
tr, err = trie.New(root, dl.triedb)
tr, err = zktrie.New(root, dl.triedb)
if err != nil {
stats.Log("Trie missing, state snapshotting paused", dl.root, dl.genMarker)
return false, nil, errMissingTrie
Expand All @@ -453,7 +453,7 @@ func (dl *diskLayer) generateRange(root common.Hash, prefix []byte, kind string,
var (
trieMore bool
nodeIt = tr.NodeIterator(origin)
iter = trie.NewIterator(nodeIt)
iter = zktrie.NewIterator(nodeIt)
kvkeys, kvvals = result.keys, result.vals

// counters
Expand Down
4 changes: 2 additions & 2 deletions core/state/snapshot/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/scroll-tech/go-ethereum/ethdb"
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/rlp"
"github.com/scroll-tech/go-ethereum/trie"
"github.com/scroll-tech/go-ethereum/zktrie"
)

const journalVersion uint64 = 0
Expand Down Expand Up @@ -127,7 +127,7 @@ func loadAndParseJournal(db ethdb.KeyValueStore, base *diskLayer) (snapshot, jou
}

// loadSnapshot loads a pre-existing state snapshot backed by a key-value store.
func loadSnapshot(diskdb ethdb.KeyValueStore, triedb *trie.Database, cache int, root common.Hash, recovery bool) (snapshot, bool, error) {
func loadSnapshot(diskdb ethdb.KeyValueStore, triedb *zktrie.Database, cache int, root common.Hash, recovery bool) (snapshot, bool, error) {
// If snapshotting is disabled (initial sync in progress), don't do anything,
// wait for the chain to permit us to do something meaningful
if rawdb.ReadSnapshotDisabled(diskdb) {
Expand Down
Loading