Skip to content

Commit

Permalink
verkle: add logging for proof time and size
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Aug 28, 2023
1 parent 97e6090 commit 5f011ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/state/access_witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package state

import (
"fmt"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/utils"
Expand Down Expand Up @@ -273,10 +275,12 @@ func (aw *AccessWitness) touchAddress(addr []byte, treeIndex uint256.Int, subInd
}

func (aw *AccessWitness) GenerateProofAndSerialize() (*verkle.VerkleProof, verkle.StateDiff, error) {
start := time.Now()
// Signal that we are done sending chunks to load the tree.
aw.treeLoaderQuit <- struct{}{}
// Wait for the background loader to finish loading pending keys.
<-aw.treeLoaderClosed
log.Debug("Waiting for the tree loader to finish took %s", time.Since(start))

// If the background loader encountered an error, return it.
if aw.treeLoaderErr != nil {
Expand All @@ -288,6 +292,7 @@ func (aw *AccessWitness) GenerateProofAndSerialize() (*verkle.VerkleProof, verkl
if err != nil {
return nil, nil, fmt.Errorf("generating the witness proof failed: %s", err)
}

return proof, stateDiff, nil
}

Expand Down
12 changes: 11 additions & 1 deletion trie/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ package trie
import (
"bytes"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/trie/trienode"
"github.com/ethereum/go-ethereum/trie/utils"
"github.com/gballet/go-verkle"
Expand Down Expand Up @@ -325,16 +328,23 @@ func (trie *VerkleTrie) IsVerkle() bool {
}

func (trie *VerkleTrie) ProveAndSerialize(keys [][]byte, kv map[string][]byte) (*verkle.VerkleProof, verkle.StateDiff, error) {
// TODO: remove verbose logging.
startProofGen := time.Now()
proof, _, _, _, err := verkle.MakeVerkleMultiProof(trie.root, keys)
if err != nil {
return nil, nil, err
}

startProofSerialization := time.Now()
p, kvps, err := verkle.SerializeProof(proof)
if err != nil {
return nil, nil, err
}

proofJson, err := json.Marshal(proof)
if err != nil {
return nil, nil, err
}
log.Debug("Generating the proof", "number of keys", len(keys), "building proof", startProofSerialization.Sub(startProofGen), "serializing proof", time.Since(startProofSerialization), "json encoded size", common.StorageSize(len(proofJson)))
return p, kvps, nil
}

Expand Down

0 comments on commit 5f011ab

Please sign in to comment.