mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-11 07:24:27 +00:00
trie: rename NodeFlag to nodeFlag (#1049)
This commit is contained in:
parent
5dd41a6765
commit
5b071d1b0d
4 changed files with 15 additions and 15 deletions
|
|
@ -233,7 +233,7 @@ func expandNode(hash hashNode, n node) node {
|
||||||
return &shortNode{
|
return &shortNode{
|
||||||
Key: compactToHex(n.Key),
|
Key: compactToHex(n.Key),
|
||||||
Val: expandNode(nil, n.Val),
|
Val: expandNode(nil, n.Val),
|
||||||
flags: NodeFlag{
|
flags: nodeFlag{
|
||||||
hash: hash,
|
hash: hash,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -241,7 +241,7 @@ func expandNode(hash hashNode, n node) node {
|
||||||
case rawFullNode:
|
case rawFullNode:
|
||||||
// Full nodes need child expansion
|
// Full nodes need child expansion
|
||||||
node := &fullNode{
|
node := &fullNode{
|
||||||
flags: NodeFlag{
|
flags: nodeFlag{
|
||||||
hash: hash,
|
hash: hash,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
trie/node.go
12
trie/node.go
|
|
@ -36,12 +36,12 @@ type node interface {
|
||||||
type (
|
type (
|
||||||
fullNode struct {
|
fullNode struct {
|
||||||
Children [17]node // Actual trie Node data to encode/decode (needs custom encoder)
|
Children [17]node // Actual trie Node data to encode/decode (needs custom encoder)
|
||||||
flags NodeFlag
|
flags nodeFlag
|
||||||
}
|
}
|
||||||
shortNode struct {
|
shortNode struct {
|
||||||
Key []byte
|
Key []byte
|
||||||
Val node
|
Val node
|
||||||
flags NodeFlag
|
flags nodeFlag
|
||||||
}
|
}
|
||||||
hashNode []byte
|
hashNode []byte
|
||||||
valueNode []byte
|
valueNode []byte
|
||||||
|
|
@ -61,8 +61,8 @@ func (n *fullNode) EncodeRLP(w io.Writer) error {
|
||||||
func (n *fullNode) copy() *fullNode { copy := *n; return © }
|
func (n *fullNode) copy() *fullNode { copy := *n; return © }
|
||||||
func (n *shortNode) copy() *shortNode { copy := *n; return © }
|
func (n *shortNode) copy() *shortNode { copy := *n; return © }
|
||||||
|
|
||||||
// NodeFlag contains caching-related metadata about a Node.
|
// nodeFlag contains caching-related metadata about a Node.
|
||||||
type NodeFlag struct {
|
type nodeFlag struct {
|
||||||
hash hashNode // cached hash of the Node (may be nil)
|
hash hashNode // cached hash of the Node (may be nil)
|
||||||
dirty bool // whether the Node has changes that must be written to the database
|
dirty bool // whether the Node has changes that must be written to the database
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +133,7 @@ func decodeShort(hash, elems []byte) (node, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
flag := NodeFlag{hash: hash}
|
flag := nodeFlag{hash: hash}
|
||||||
key := compactToHex(kbuf)
|
key := compactToHex(kbuf)
|
||||||
if hasTerm(key) {
|
if hasTerm(key) {
|
||||||
// value Node
|
// value Node
|
||||||
|
|
@ -151,7 +151,7 @@ func decodeShort(hash, elems []byte) (node, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeFull(hash, elems []byte) (*fullNode, error) {
|
func decodeFull(hash, elems []byte) (*fullNode, error) {
|
||||||
n := &fullNode{flags: NodeFlag{hash: hash}}
|
n := &fullNode{flags: nodeFlag{hash: hash}}
|
||||||
for i := 0; i < 16; i++ {
|
for i := 0; i < 16; i++ {
|
||||||
cld, rest, err := decodeRef(elems)
|
cld, rest, err := decodeRef(elems)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ findFork:
|
||||||
if len(right)-pos < len(rn.Key) || !bytes.Equal(rn.Key, right[pos:pos+len(rn.Key)]) {
|
if len(right)-pos < len(rn.Key) || !bytes.Equal(rn.Key, right[pos:pos+len(rn.Key)]) {
|
||||||
return errors.New("invalid edge path")
|
return errors.New("invalid edge path")
|
||||||
}
|
}
|
||||||
rn.flags = NodeFlag{dirty: true}
|
rn.flags = nodeFlag{dirty: true}
|
||||||
// Special case, the non-existent proof points to the same path
|
// Special case, the non-existent proof points to the same path
|
||||||
// as the existent proof, but the path of existent proof is longer.
|
// as the existent proof, but the path of existent proof is longer.
|
||||||
// In this case, the fork point is this shortnode.
|
// In this case, the fork point is this shortnode.
|
||||||
|
|
@ -251,7 +251,7 @@ findFork:
|
||||||
if rightnode == nil {
|
if rightnode == nil {
|
||||||
return errors.New("invalid edge path")
|
return errors.New("invalid edge path")
|
||||||
}
|
}
|
||||||
rn.flags = NodeFlag{dirty: true}
|
rn.flags = nodeFlag{dirty: true}
|
||||||
if leftnode != rightnode {
|
if leftnode != rightnode {
|
||||||
break findFork
|
break findFork
|
||||||
}
|
}
|
||||||
|
|
@ -305,12 +305,12 @@ func unset(parent node, child node, key []byte, pos int, removeLeft bool) error
|
||||||
for i := 0; i < int(key[pos]); i++ {
|
for i := 0; i < int(key[pos]); i++ {
|
||||||
cld.Children[i] = nil
|
cld.Children[i] = nil
|
||||||
}
|
}
|
||||||
cld.flags = NodeFlag{dirty: true}
|
cld.flags = nodeFlag{dirty: true}
|
||||||
} else {
|
} else {
|
||||||
for i := key[pos] + 1; i < 16; i++ {
|
for i := key[pos] + 1; i < 16; i++ {
|
||||||
cld.Children[i] = nil
|
cld.Children[i] = nil
|
||||||
}
|
}
|
||||||
cld.flags = NodeFlag{dirty: true}
|
cld.flags = nodeFlag{dirty: true}
|
||||||
}
|
}
|
||||||
return unset(cld, cld.Children[key[pos]], key, pos+1, removeLeft)
|
return unset(cld, cld.Children[key[pos]], key, pos+1, removeLeft)
|
||||||
case *shortNode:
|
case *shortNode:
|
||||||
|
|
@ -337,7 +337,7 @@ func unset(parent node, child node, key []byte, pos int, removeLeft bool) error
|
||||||
fn.Children[key[pos-1]] = nil
|
fn.Children[key[pos-1]] = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cld.flags = NodeFlag{dirty: true}
|
cld.flags = nodeFlag{dirty: true}
|
||||||
return unset(cld, cld.Val, key, pos+len(cld.Key), removeLeft)
|
return unset(cld, cld.Val, key, pos+len(cld.Key), removeLeft)
|
||||||
case nil:
|
case nil:
|
||||||
// If the Node is nil, it's a child of the fork point
|
// If the Node is nil, it's a child of the fork point
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,8 @@ type Trie struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newFlag returns the Cache flag value for a newly created Node.
|
// newFlag returns the Cache flag value for a newly created Node.
|
||||||
func (t *Trie) newFlag() NodeFlag {
|
func (t *Trie) newFlag() nodeFlag {
|
||||||
return NodeFlag{dirty: true}
|
return nodeFlag{dirty: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a trie with an existing root Node from Db.
|
// New creates a trie with an existing root Node from Db.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue