Skip to content

Commit fd92945

Browse files
committed
easier parallelism
1 parent 08a049b commit fd92945

File tree

2 files changed

+7
-61
lines changed

2 files changed

+7
-61
lines changed

cmd/migration-checker/main.go

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import (
55
"encoding/hex"
66
"flag"
77
"fmt"
8-
"os"
9-
"runtime"
108
"sort"
119
"sync"
12-
"sync/atomic"
1310
"time"
1411

1512
"github.com/scroll-tech/go-ethereum/common"
@@ -19,22 +16,18 @@ import (
1916
"github.com/scroll-tech/go-ethereum/trie"
2017
)
2118

22-
var accountsDone atomic.Uint64
23-
var trieCheckers chan struct{}
24-
2519
type dbs struct {
2620
zkDb *leveldb.Database
2721
mptDb *leveldb.Database
2822
}
2923

3024
func main() {
3125
var (
32-
mptDbPath = flag.String("mpt-db", "", "path to the MPT node DB")
33-
zkDbPath = flag.String("zk-db", "", "path to the ZK node DB")
34-
mptRoot = flag.String("mpt-root", "", "root hash of the MPT node")
35-
zkRoot = flag.String("zk-root", "", "root hash of the ZK node")
36-
paranoid = flag.Bool("paranoid", false, "verifies all node contents against their expected hash")
37-
parallelismMultipler = flag.Int("parallelism-multiplier", 4, "multiplier for the number of parallel workers")
26+
mptDbPath = flag.String("mpt-db", "", "path to the MPT node DB")
27+
zkDbPath = flag.String("zk-db", "", "path to the ZK node DB")
28+
mptRoot = flag.String("mpt-root", "", "root hash of the MPT node")
29+
zkRoot = flag.String("zk-root", "", "root hash of the ZK node")
30+
paranoid = flag.Bool("paranoid", false, "verifies all node contents against their expected hash")
3831
)
3932
flag.Parse()
4033

@@ -45,35 +38,10 @@ func main() {
4538

4639
zkRootHash := common.HexToHash(*zkRoot)
4740
mptRootHash := common.HexToHash(*mptRoot)
48-
49-
numTrieCheckers := runtime.GOMAXPROCS(0) * (*parallelismMultipler)
50-
trieCheckers = make(chan struct{}, numTrieCheckers)
51-
for i := 0; i < numTrieCheckers; i++ {
52-
trieCheckers <- struct{}{}
53-
}
54-
55-
done := make(chan struct{})
56-
totalCheckers := len(trieCheckers)
57-
go func() {
58-
for {
59-
select {
60-
case <-done:
61-
return
62-
case <-time.After(time.Minute):
63-
fmt.Println("Active checkers:", totalCheckers-len(trieCheckers))
64-
}
65-
}
66-
}()
67-
defer close(done)
68-
6941
checkTrieEquality(&dbs{
7042
zkDb: zkDb,
7143
mptDb: mptDb,
7244
}, zkRootHash, mptRootHash, "", checkAccountEquality, true, *paranoid)
73-
74-
for i := 0; i < numTrieCheckers; i++ {
75-
<-trieCheckers
76-
}
7745
}
7846

7947
func panicOnError(err error, label, msg string) {
@@ -120,6 +88,7 @@ func checkTrieEquality(dbs *dbs, zkRoot, mptRoot common.Hash, label string, leaf
12088
for index, zkKv := range zkLeafs {
12189
mptKv := mptLeafs[index]
12290
leafChecker(fmt.Sprintf("%s key: %s", label, hex.EncodeToString([]byte(zkKv.key))), dbs, zkKv.value, mptKv.value, paranoid)
91+
fmt.Println("Accounts done:", index+1, "/", len(zkLeafs))
12392
}
12493
}
12594

@@ -146,23 +115,7 @@ func checkAccountEquality(label string, dbs *dbs, zkAccountBytes, mptAccountByte
146115
} else if zkAccount.Root != (common.Hash{}) {
147116
zkRoot := common.BytesToHash(zkAccount.Root[:])
148117
mptRoot := common.BytesToHash(mptAccount.Root[:])
149-
<-trieCheckers
150-
go func() {
151-
defer func() {
152-
if p := recover(); p != nil {
153-
fmt.Println(p)
154-
os.Exit(1)
155-
}
156-
}()
157-
158-
checkTrieEquality(dbs, zkRoot, mptRoot, label, checkStorageEquality, false, paranoid)
159-
accountsDone.Add(1)
160-
fmt.Println("Accounts done:", accountsDone.Load())
161-
trieCheckers <- struct{}{}
162-
}()
163-
} else {
164-
accountsDone.Add(1)
165-
fmt.Println("Accounts done:", accountsDone.Load())
118+
checkTrieEquality(dbs, zkRoot, mptRoot, label, checkStorageEquality, false, paranoid)
166119
}
167120
}
168121

@@ -183,9 +136,6 @@ type kv struct {
183136
func loadMPT(mptTrie *trie.SecureTrie, top bool) chan []kv {
184137
startKey := make([]byte, 32)
185138
workers := 1 << 5
186-
if !top {
187-
workers = 1 << 3
188-
}
189139
step := byte(256 / workers)
190140

191141
mptLeafs := make([]kv, 0, 1000)

trie/zk_trie.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,6 @@ func (t *ZkTrie) countLeaves(root *zkt.Hash, cb func(key, value []byte), depth i
272272
return 1
273273
} else {
274274
parallelismDepth := 5
275-
if !top {
276-
parallelismDepth = 3
277-
}
278-
279275
if depth < parallelismDepth {
280276
count := make(chan uint64)
281277
leftT := t.Copy()

0 commit comments

Comments
 (0)