Skip to content

Commit

Permalink
verkle: store to database (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet authored Jun 1, 2022
1 parent 5bb6607 commit f7f8d18
Showing 1 changed file with 25 additions and 10 deletions.
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
}

0 comments on commit f7f8d18

Please sign in to comment.