Skip to content

Commit 8e0b29c

Browse files
committed
add start from
1 parent c933b5c commit 8e0b29c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

cmd/migration-checker/main.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func main() {
3636
zkRoot = flag.String("zk-root", "", "root hash of the ZK node")
3737
paranoid = flag.Bool("paranoid", false, "verifies all node contents against their expected hash")
3838
parallelismMultipler = flag.Int("parallelism-multiplier", 4, "multiplier for the number of parallel workers")
39+
startFrom = flag.Int("start-form", 0, "start checking from account at the given index")
3940
)
4041
flag.Parse()
4142

@@ -67,10 +68,16 @@ func main() {
6768
}()
6869
defer close(done)
6970

71+
startFromSafe := *startFrom - len(trieCheckers)
72+
if startFromSafe < 0 {
73+
startFromSafe = 0
74+
}
75+
accountsDone.Add(uint64(startFromSafe))
76+
7077
checkTrieEquality(&dbs{
7178
zkDb: zkDb,
7279
mptDb: mptDb,
73-
}, zkRootHash, mptRootHash, "", checkAccountEquality, true, *paranoid)
80+
}, zkRootHash, mptRootHash, "", checkAccountEquality, true, *paranoid, startFromSafe)
7481

7582
for i := 0; i < numTrieCheckers; i++ {
7683
<-trieCheckers
@@ -86,7 +93,7 @@ func panicOnError(err error, label, msg string) {
8693
func dup(s []byte) []byte {
8794
return append([]byte{}, s...)
8895
}
89-
func checkTrieEquality(dbs *dbs, zkRoot, mptRoot common.Hash, label string, leafChecker func(string, *dbs, []byte, []byte, bool), top, paranoid bool) {
96+
func checkTrieEquality(dbs *dbs, zkRoot, mptRoot common.Hash, label string, leafChecker func(string, *dbs, []byte, []byte, bool), top, paranoid bool, startFrom int) {
9097
done := make(chan struct{})
9198
start := time.Now()
9299
if !top {
@@ -120,8 +127,9 @@ func checkTrieEquality(dbs *dbs, zkRoot, mptRoot common.Hash, label string, leaf
120127
totalAccounts = len(mptLeafs)
121128
}
122129

123-
for index, zkKv := range zkLeafs {
124-
mptKv := mptLeafs[index]
130+
for i := startFrom; i < len(zkLeafs); i++ {
131+
zkKv := zkLeafs[i]
132+
mptKv := mptLeafs[i]
125133
leafChecker(fmt.Sprintf("%s key: %s", label, hex.EncodeToString([]byte(zkKv.key))), dbs, zkKv.value, mptKv.value, paranoid)
126134
}
127135
}
@@ -158,7 +166,7 @@ func checkAccountEquality(label string, dbs *dbs, zkAccountBytes, mptAccountByte
158166
}
159167
}()
160168

161-
checkTrieEquality(dbs, zkRoot, mptRoot, label, checkStorageEquality, false, paranoid)
169+
checkTrieEquality(dbs, zkRoot, mptRoot, label, checkStorageEquality, false, paranoid, 0)
162170
accountsDone.Add(1)
163171
fmt.Println("Accounts done:", accountsDone.Load(), "/", totalAccounts)
164172
trieCheckers <- struct{}{}

0 commit comments

Comments
 (0)