trie: prefer nil slices over zero-length slices (#19084)
This commit is contained in:
parent
f1537b774c
commit
514a9472ad
@ -809,7 +809,7 @@ func (db *Database) verifyIntegrity() {
|
|||||||
db.accumulate(child, reachable)
|
db.accumulate(child, reachable)
|
||||||
}
|
}
|
||||||
// Find any unreachable but cached nodes
|
// Find any unreachable but cached nodes
|
||||||
unreachable := []string{}
|
var unreachable []string
|
||||||
for hash, node := range db.dirties {
|
for hash, node := range db.dirties {
|
||||||
if _, ok := reachable[hash]; !ok {
|
if _, ok := reachable[hash]; !ok {
|
||||||
unreachable = append(unreachable, fmt.Sprintf("%x: {Node: %v, Parents: %d, Prev: %x, Next: %x}",
|
unreachable = append(unreachable, fmt.Sprintf("%x: {Node: %v, Parents: %d, Prev: %x, Next: %x}",
|
||||||
|
@ -37,7 +37,7 @@ import (
|
|||||||
func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.Putter) error {
|
func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.Putter) error {
|
||||||
// Collect all nodes on the path to key.
|
// Collect all nodes on the path to key.
|
||||||
key = keybytesToHex(key)
|
key = keybytesToHex(key)
|
||||||
nodes := []node{}
|
var nodes []node
|
||||||
tn := t.root
|
tn := t.root
|
||||||
for len(key) > 0 && tn != nil {
|
for len(key) > 0 && tn != nil {
|
||||||
switch n := tn.(type) {
|
switch n := tn.(type) {
|
||||||
|
@ -157,7 +157,7 @@ func (s *Sync) AddRawEntry(hash common.Hash, depth int, parent common.Hash) {
|
|||||||
|
|
||||||
// Missing retrieves the known missing nodes from the trie for retrieval.
|
// Missing retrieves the known missing nodes from the trie for retrieval.
|
||||||
func (s *Sync) Missing(max int) []common.Hash {
|
func (s *Sync) Missing(max int) []common.Hash {
|
||||||
requests := []common.Hash{}
|
var requests []common.Hash
|
||||||
for !s.queue.Empty() && (max == 0 || len(requests) < max) {
|
for !s.queue.Empty() && (max == 0 || len(requests) < max) {
|
||||||
requests = append(requests, s.queue.PopItem().(common.Hash))
|
requests = append(requests, s.queue.PopItem().(common.Hash))
|
||||||
}
|
}
|
||||||
@ -254,7 +254,7 @@ func (s *Sync) children(req *request, object node) ([]*request, error) {
|
|||||||
node node
|
node node
|
||||||
depth int
|
depth int
|
||||||
}
|
}
|
||||||
children := []child{}
|
var children []child
|
||||||
|
|
||||||
switch node := (object).(type) {
|
switch node := (object).(type) {
|
||||||
case *shortNode:
|
case *shortNode:
|
||||||
|
@ -313,7 +313,7 @@ func TestIncompleteSync(t *testing.T) {
|
|||||||
triedb := NewDatabase(diskdb)
|
triedb := NewDatabase(diskdb)
|
||||||
sched := NewSync(srcTrie.Hash(), diskdb, nil)
|
sched := NewSync(srcTrie.Hash(), diskdb, nil)
|
||||||
|
|
||||||
added := []common.Hash{}
|
var added []common.Hash
|
||||||
queue := append([]common.Hash{}, sched.Missing(1)...)
|
queue := append([]common.Hash{}, sched.Missing(1)...)
|
||||||
for len(queue) > 0 {
|
for len(queue) > 0 {
|
||||||
// Fetch a batch of trie nodes
|
// Fetch a batch of trie nodes
|
||||||
|
Loading…
Reference in New Issue
Block a user