mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
core, trie: fix some dereferencing issues
This commit is contained in:
parent
80eb5be015
commit
e0657554cc
2 changed files with 15 additions and 13 deletions
|
|
@ -856,7 +856,7 @@ func (bc *BlockChain) WriteBlockAndState(block *types.Block, receipts []*types.R
|
||||||
bc.triedb.Dereference(header.Root, common.Hash{})
|
bc.triedb.Dereference(header.Root, common.Hash{})
|
||||||
|
|
||||||
if current%10000 == 0 {
|
if current%10000 == 0 {
|
||||||
log.Debug("Current trie pruning state", "size", bc.triedb.Size(), "elapsed", bc.procTime)
|
log.Warn("Current trie pruning state", "size", bc.triedb.Size(), "elapsed", bc.procTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := WriteBlockReceipts(batch, block.Hash(), block.NumberU64(), receipts); err != nil {
|
if err := WriteBlockReceipts(batch, block.Hash(), block.NumberU64(), receipts); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ type Database struct {
|
||||||
|
|
||||||
nodes map[common.Hash][]byte // Cached data blocks of the trie nodes
|
nodes map[common.Hash][]byte // Cached data blocks of the trie nodes
|
||||||
parents map[common.Hash]int // Number of live nodes referencing a given one
|
parents map[common.Hash]int // Number of live nodes referencing a given one
|
||||||
children map[common.Hash]map[common.Hash]struct{} // Set of children referenced by given nodes
|
children map[common.Hash]map[common.Hash]int // Set of children referenced by given nodes
|
||||||
|
|
||||||
preimages map[common.Hash][]byte // Preimages of nodes from the secure trie
|
preimages map[common.Hash][]byte // Preimages of nodes from the secure trie
|
||||||
seckeybuf [secureKeyLength]byte // Ephemeral buffer for calculating preimage keys
|
seckeybuf [secureKeyLength]byte // Ephemeral buffer for calculating preimage keys
|
||||||
|
|
@ -71,10 +71,10 @@ func NewDatabase(diskdb ethdb.Database) *Database {
|
||||||
diskdb: diskdb,
|
diskdb: diskdb,
|
||||||
nodes: make(map[common.Hash][]byte),
|
nodes: make(map[common.Hash][]byte),
|
||||||
parents: make(map[common.Hash]int),
|
parents: make(map[common.Hash]int),
|
||||||
children: make(map[common.Hash]map[common.Hash]struct{}),
|
children: make(map[common.Hash]map[common.Hash]int),
|
||||||
preimages: make(map[common.Hash][]byte),
|
preimages: make(map[common.Hash][]byte),
|
||||||
}
|
}
|
||||||
db.children[common.Hash{}] = make(map[common.Hash]struct{})
|
db.children[common.Hash{}] = make(map[common.Hash]int)
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ func (db *Database) insert(hash common.Hash, blob []byte) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
db.nodes[hash] = common.CopyBytes(blob)
|
db.nodes[hash] = common.CopyBytes(blob)
|
||||||
db.children[hash] = make(map[common.Hash]struct{})
|
db.children[hash] = make(map[common.Hash]int)
|
||||||
|
|
||||||
db.size += common.StorageSize(common.HashLength + len(blob))
|
db.size += common.StorageSize(common.HashLength + len(blob))
|
||||||
}
|
}
|
||||||
|
|
@ -203,7 +203,7 @@ func (db *Database) reference(child common.Hash, parent common.Hash) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
db.parents[child]++
|
db.parents[child]++
|
||||||
db.children[parent][child] = struct{}{}
|
db.children[parent][child]++
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dereference removes an existing reference from a parent node to a child node.
|
// Dereference removes an existing reference from a parent node to a child node.
|
||||||
|
|
@ -226,13 +226,15 @@ func (db *Database) dereference(child common.Hash, parent common.Hash) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
db.children[parent][child]--
|
||||||
|
if db.children[parent][child] == 0 {
|
||||||
delete(db.children[parent], child)
|
delete(db.children[parent], child)
|
||||||
db.parents[child]--
|
}
|
||||||
|
|
||||||
// If there are no more references to the child, delete it and cascade
|
// If there are no more references to the child, delete it and cascade
|
||||||
|
db.parents[child]--
|
||||||
if db.parents[child] == 0 {
|
if db.parents[child] == 0 {
|
||||||
for child := range db.children[child] {
|
for hash := range db.children[child] {
|
||||||
db.dereference(child, child)
|
db.dereference(hash, child)
|
||||||
}
|
}
|
||||||
delete(db.nodes, child)
|
delete(db.nodes, child)
|
||||||
delete(db.parents, child)
|
delete(db.parents, child)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue