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

tree insertion + flush to db #36

Merged
Merged
Changes from all commits
Commits
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
35 changes: 25 additions & 10 deletions cmd/geth/converkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,6 @@ func convertToVerkle(ctx *cli.Context) error {
log.Info("Traversing state", "accounts", accounts, "at", accHash.String(), "elapsed", common.PrettyDuration(time.Since(start)))
lastReport = time.Now()
}
if accounts == 17696139 {
log.Info("Traversing state", "accounts", accounts, "at", accHash.String(), "elapsed", common.PrettyDuration(time.Since(start)))
lastReport = time.Now()
break
}
accounts += 1

// Get the loader-routines started
Expand Down Expand Up @@ -555,6 +550,29 @@ func doInsertion(ctx *cli.Context) error {
}()
defer close(abortCh)

convdb, err := rawdb.NewLevelDBDatabase("verkle", 128, 128, "", false)
if err != nil {
panic(err)
}

flushCh := make(chan verkle.VerkleNode)
saveverkle := func(node verkle.VerkleNode) {
flushCh <- node
}
go func() {
for node := range flushCh {
comm := node.ComputeCommitment()
s, err := node.Serialize()
if err != nil {
panic(err)
}
commB := comm.Bytes()
if err := convdb.Put(commB[:], s); err != nil {
panic(err)
}
}
}()

for elem := range itemCh {

if time.Since(lastReport) > time.Second*8 {
Expand All @@ -564,16 +582,13 @@ func doInsertion(ctx *cli.Context) error {
var st = make([]byte, 31)
copy(st, elem.stem[:])
leaf := verkle.NewLeafNode(st, elem.values)
if err := root.(*verkle.InternalNode).InsertStemOrdered(st, leaf, nil); err != nil {
if err := root.(*verkle.InternalNode).InsertStemOrdered(st, leaf, saveverkle); err != nil {
log.Warn("Error during insert", "stem", fmt.Sprintf("%x", elem.stem), err, err)
return err
}
count++
if count == 100_000 {
log.Info("aborting early here, time for lunch")
break
}
}
close(flushCh)
log.Info("Insertion done", "elems", count, "root commitment", fmt.Sprintf("%x", root.ComputeCommitment().Bytes()), "elapsed", common.PrettyDuration(time.Since(start)))
return nil
}