mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
trie,triedb: store old node length
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
fbac246f39
commit
94134263b5
3 changed files with 17 additions and 10 deletions
|
|
@ -31,6 +31,8 @@ import (
|
|||
type Node struct {
|
||||
Hash common.Hash // Node hash, empty for deleted node
|
||||
Blob []byte // Encoded node blob, nil for the deleted node
|
||||
|
||||
length int // The length of the original value of the node
|
||||
}
|
||||
|
||||
// Size returns the total memory size used by this node.
|
||||
|
|
@ -43,13 +45,18 @@ func (n *Node) IsDeleted() bool {
|
|||
return len(n.Blob) == 0
|
||||
}
|
||||
|
||||
// OriginLen returns the length of the original value of the node.
|
||||
func (n *Node) OriginLen() int {
|
||||
return n.length
|
||||
}
|
||||
|
||||
// New constructs a node with provided node information.
|
||||
func New(hash common.Hash, blob []byte) *Node {
|
||||
return &Node{Hash: hash, Blob: blob}
|
||||
func New(hash common.Hash, blob []byte, length int) *Node {
|
||||
return &Node{Hash: hash, Blob: blob, length: length}
|
||||
}
|
||||
|
||||
// NewDeleted constructs a node which is deleted.
|
||||
func NewDeleted() *Node { return New(common.Hash{}, nil) }
|
||||
func NewDeleted(length int) *Node { return New(common.Hash{}, nil, length) }
|
||||
|
||||
// NodeWithPrev is a wrapper over Node by tracking the original value of node.
|
||||
type NodeWithPrev struct {
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ func benchmarkSearch(b *testing.B, depth int, total int) {
|
|||
var (
|
||||
path = testrand.Bytes(32)
|
||||
blob = testrand.Bytes(100)
|
||||
node = trienode.New(crypto.Keccak256Hash(blob), blob)
|
||||
node = trienode.New(crypto.Keccak256Hash(blob), blob, 0)
|
||||
)
|
||||
nodes[common.Hash{}][string(path)] = node
|
||||
if npath == nil && depth == index {
|
||||
|
|
@ -114,7 +114,7 @@ func BenchmarkPersist(b *testing.B) {
|
|||
var (
|
||||
path = testrand.Bytes(32)
|
||||
blob = testrand.Bytes(100)
|
||||
node = trienode.New(crypto.Keccak256Hash(blob), blob)
|
||||
node = trienode.New(crypto.Keccak256Hash(blob), blob, 0)
|
||||
)
|
||||
nodes[common.Hash{}][string(path)] = node
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ func BenchmarkJournal(b *testing.B) {
|
|||
var (
|
||||
path = testrand.Bytes(32)
|
||||
blob = testrand.Bytes(100)
|
||||
node = trienode.New(crypto.Keccak256Hash(blob), blob)
|
||||
node = trienode.New(crypto.Keccak256Hash(blob), blob, 0)
|
||||
)
|
||||
nodes[common.Hash{}][string(path)] = node
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,9 +251,9 @@ func (s *nodeSet) decode(r *rlp.Stream) error {
|
|||
// Account nodes
|
||||
for _, n := range entry.Nodes {
|
||||
if len(n.Blob) > 0 {
|
||||
s.accountNodes[string(n.Path)] = trienode.New(crypto.Keccak256Hash(n.Blob), n.Blob)
|
||||
s.accountNodes[string(n.Path)] = trienode.New(crypto.Keccak256Hash(n.Blob), n.Blob, 0)
|
||||
} else {
|
||||
s.accountNodes[string(n.Path)] = trienode.NewDeleted()
|
||||
s.accountNodes[string(n.Path)] = trienode.NewDeleted(0)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -261,9 +261,9 @@ func (s *nodeSet) decode(r *rlp.Stream) error {
|
|||
subset := make(map[string]*trienode.Node)
|
||||
for _, n := range entry.Nodes {
|
||||
if len(n.Blob) > 0 {
|
||||
subset[string(n.Path)] = trienode.New(crypto.Keccak256Hash(n.Blob), n.Blob)
|
||||
subset[string(n.Path)] = trienode.New(crypto.Keccak256Hash(n.Blob), n.Blob, 0)
|
||||
} else {
|
||||
subset[string(n.Path)] = trienode.NewDeleted()
|
||||
subset[string(n.Path)] = trienode.NewDeleted(0)
|
||||
}
|
||||
}
|
||||
s.storageNodes[entry.Owner] = subset
|
||||
|
|
|
|||
Loading…
Reference in a new issue