mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-09 14:34:27 +00:00
trie: bloom-filter based pruning mechanism (#21724)
This commit is contained in:
parent
5b8c267122
commit
dcea73039c
1 changed files with 10 additions and 11 deletions
|
|
@ -35,7 +35,7 @@ var stPool = sync.Pool{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func stackTrieFromPool(db ethdb.KeyValueStore) *StackTrie {
|
func stackTrieFromPool(db ethdb.KeyValueWriter) *StackTrie {
|
||||||
st := stPool.Get().(*StackTrie)
|
st := stPool.Get().(*StackTrie)
|
||||||
st.db = db
|
st.db = db
|
||||||
return st
|
return st
|
||||||
|
|
@ -50,24 +50,23 @@ func returnToPool(st *StackTrie) {
|
||||||
// in order. Once it determines that a subtree will no longer be inserted
|
// in order. Once it determines that a subtree will no longer be inserted
|
||||||
// into, it will hash it and free up the memory it uses.
|
// into, it will hash it and free up the memory it uses.
|
||||||
type StackTrie struct {
|
type StackTrie struct {
|
||||||
nodeType uint8 // node type (as in branch, ext, leaf)
|
nodeType uint8 // node type (as in branch, ext, leaf)
|
||||||
val []byte // value contained by this node if it's a leaf
|
val []byte // value contained by this node if it's a leaf
|
||||||
key []byte // key chunk covered by this (full|ext) node
|
key []byte // key chunk covered by this (full|ext) node
|
||||||
keyOffset int // offset of the key chunk inside a full key
|
keyOffset int // offset of the key chunk inside a full key
|
||||||
children [16]*StackTrie // list of children (for fullnodes and exts)
|
children [16]*StackTrie // list of children (for fullnodes and exts)
|
||||||
|
db ethdb.KeyValueWriter // Pointer to the commit db, can be nil
|
||||||
db ethdb.KeyValueStore // Pointer to the commit db, can be nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStackTrie allocates and initializes an empty trie.
|
// NewStackTrie allocates and initializes an empty trie.
|
||||||
func NewStackTrie(db ethdb.KeyValueStore) *StackTrie {
|
func NewStackTrie(db ethdb.KeyValueWriter) *StackTrie {
|
||||||
return &StackTrie{
|
return &StackTrie{
|
||||||
nodeType: emptyNode,
|
nodeType: emptyNode,
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLeaf(ko int, key, val []byte, db ethdb.KeyValueStore) *StackTrie {
|
func newLeaf(ko int, key, val []byte, db ethdb.KeyValueWriter) *StackTrie {
|
||||||
st := stackTrieFromPool(db)
|
st := stackTrieFromPool(db)
|
||||||
st.nodeType = leafNode
|
st.nodeType = leafNode
|
||||||
st.keyOffset = ko
|
st.keyOffset = ko
|
||||||
|
|
@ -76,7 +75,7 @@ func newLeaf(ko int, key, val []byte, db ethdb.KeyValueStore) *StackTrie {
|
||||||
return st
|
return st
|
||||||
}
|
}
|
||||||
|
|
||||||
func newExt(ko int, key []byte, child *StackTrie, db ethdb.KeyValueStore) *StackTrie {
|
func newExt(ko int, key []byte, child *StackTrie, db ethdb.KeyValueWriter) *StackTrie {
|
||||||
st := stackTrieFromPool(db)
|
st := stackTrieFromPool(db)
|
||||||
st.nodeType = extNode
|
st.nodeType = extNode
|
||||||
st.keyOffset = ko
|
st.keyOffset = ko
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue