Skip to content

Commit

Permalink
trie: apply fastNodeEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
qianbin committed Dec 18, 2021
1 parent e5132bf commit db9a648
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion trie/database.go
Expand Up @@ -164,7 +164,7 @@ func (n *cachedNode) rlp() []byte {
if node, ok := n.node.(rawNode); ok {
return node
}
blob, err := rlp.EncodeToBytes(n.node)
blob, err := frlp.EncodeToBytes(n.node)
if err != nil {
panic(err)
}
Expand Down
5 changes: 2 additions & 3 deletions trie/hasher.go
Expand Up @@ -20,7 +20,6 @@ import (
"sync"

"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"golang.org/x/crypto/sha3"
)

Expand Down Expand Up @@ -154,7 +153,7 @@ func (h *hasher) hashFullNodeChildren(n *fullNode) (collapsed *fullNode, cached
// If the rlp data is smaller than 32 bytes, `nil` is returned.
func (h *hasher) shortnodeToHash(n *shortNode, force bool) node {
h.tmp.Reset()
if err := rlp.Encode(&h.tmp, n); err != nil {
if err := frlp.Encode(&h.tmp, n); err != nil {
panic("encode error: " + err.Error())
}

Expand All @@ -169,7 +168,7 @@ func (h *hasher) shortnodeToHash(n *shortNode, force bool) node {
func (h *hasher) fullnodeToHash(n *fullNode, force bool) node {
h.tmp.Reset()
// Generate the RLP encoding of the node
if err := n.EncodeRLP(&h.tmp); err != nil {
if err := frlp.Encode(&h.tmp, n); err != nil {
panic("encode error: " + err.Error())
}

Expand Down
3 changes: 1 addition & 2 deletions trie/iterator.go
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
)

// Iterator is a key-value trie iterator that traverses a Trie.
Expand Down Expand Up @@ -210,7 +209,7 @@ func (it *nodeIterator) LeafProof() [][]byte {
// Gather nodes that end up as hash nodes (or the root)
node, hashed := hasher.proofHash(item.node)
if _, ok := hashed.(hashNode); ok || i == 0 {
enc, _ := rlp.EncodeToBytes(node)
enc, _ := frlp.EncodeToBytes(node)
proofs = append(proofs, enc)
}
}
Expand Down
3 changes: 1 addition & 2 deletions trie/proof.go
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
)

// Prove constructs a merkle proof for key. The result contains all encoded nodes
Expand Down Expand Up @@ -79,7 +78,7 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter) e
if hash, ok := hn.(hashNode); ok || i == 0 {
// If the node's database encoding is a hash (or is the
// root node), it becomes a proof element.
enc, _ := rlp.EncodeToBytes(n)
enc, _ := frlp.EncodeToBytes(n)
if !ok {
hash = hasher.hashData(enc)
}
Expand Down

0 comments on commit db9a648

Please sign in to comment.