mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
trie: change comments
This commit is contained in:
parent
12bbaaeb58
commit
827456711a
2 changed files with 69 additions and 14 deletions
10
trie/sync.go
10
trie/sync.go
|
|
@ -462,11 +462,9 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
|
||||||
if _, ok := node.Val.(hashNode); ok && s.scheme == rawdb.PathScheme {
|
if _, ok := node.Val.(hashNode); ok && s.scheme == rawdb.PathScheme {
|
||||||
owner, inner := ResolvePath(req.path)
|
owner, inner := ResolvePath(req.path)
|
||||||
for i := 1; i < len(key); i++ {
|
for i := 1; i < len(key); i++ {
|
||||||
// Theoretically, it's necessary to check for the presence before
|
// While checking for a non-existent item in Pebble can be less efficient
|
||||||
// blindly caching deletion commands. However, due to the fact that
|
// without a bloom filter, the relatively low frequency of lookups makes
|
||||||
// Pebble doesn't use a bloom filter to enhance read performance
|
// the performance impact negligible.
|
||||||
// for non-existent items, this check would significantly slow down
|
|
||||||
// overall performance. FIX IT(rjl493456442)
|
|
||||||
var exists bool
|
var exists bool
|
||||||
if owner == (common.Hash{}) {
|
if owner == (common.Hash{}) {
|
||||||
exists = rawdb.ExistsAccountTrieNode(s.database, append(inner, key[:i]...))
|
exists = rawdb.ExistsAccountTrieNode(s.database, append(inner, key[:i]...))
|
||||||
|
|
@ -476,7 +474,7 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
|
||||||
if exists {
|
if exists {
|
||||||
req.deletes = append(req.deletes, key[:i])
|
req.deletes = append(req.deletes, key[:i])
|
||||||
deletionGauge.Inc(1)
|
deletionGauge.Inc(1)
|
||||||
log.Info("Detected dangling node", "owner", owner, "path", append(inner, key[:i]...))
|
log.Debug("Detected dangling node", "owner", owner, "path", append(inner, key[:i]...))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lookupGauge.Inc(int64(len(key) - 1))
|
lookupGauge.Inc(int64(len(key) - 1))
|
||||||
|
|
|
||||||
|
|
@ -732,16 +732,73 @@ func syncWith(t *testing.T, root common.Hash, db ethdb.Database, srcDb *Database
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the syncing target is keeping moving which may overwrite the stale
|
func testSyncMovingTarget(t *testing.T, scheme string) {
|
||||||
// states synced in the last cycle.
|
// Create a random trie to copy
|
||||||
func TestSyncMovingTarget(t *testing.T) {
|
_, srcDb, srcTrie, srcData := makeTestTrie(scheme)
|
||||||
testSyncMovingTarget(t, rawdb.HashScheme, true)
|
|
||||||
testSyncMovingTarget(t, rawdb.HashScheme, false)
|
// Create a destination trie and sync with the scheduler
|
||||||
testSyncMovingTarget(t, rawdb.PathScheme, true)
|
diskdb := rawdb.NewMemoryDatabase()
|
||||||
testSyncMovingTarget(t, rawdb.PathScheme, false)
|
syncWith(t, srcTrie.Hash(), diskdb, srcDb)
|
||||||
|
checkTrieContents(t, diskdb, srcDb.Scheme(), srcTrie.Hash().Bytes(), srcData, false)
|
||||||
|
|
||||||
|
// Push more modifications into the src trie, to see if dest trie can still
|
||||||
|
// sync with it(overwrite stale states)
|
||||||
|
var (
|
||||||
|
preRoot = srcTrie.Hash()
|
||||||
|
diff = make(map[string][]byte)
|
||||||
|
)
|
||||||
|
for i := byte(0); i < 10; i++ {
|
||||||
|
key, val := randBytes(32), randBytes(32)
|
||||||
|
srcTrie.MustUpdate(key, val)
|
||||||
|
diff[string(key)] = val
|
||||||
|
}
|
||||||
|
root, nodes, _ := srcTrie.Commit(false)
|
||||||
|
if err := srcDb.Update(root, preRoot, 0, trienode.NewWithNodeSet(nodes), nil); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if err := srcDb.Commit(root, false); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
preRoot = root
|
||||||
|
srcTrie, _ = NewStateTrie(TrieID(root), srcDb)
|
||||||
|
|
||||||
|
syncWith(t, srcTrie.Hash(), diskdb, srcDb)
|
||||||
|
checkTrieContents(t, diskdb, srcDb.Scheme(), srcTrie.Hash().Bytes(), diff, false)
|
||||||
|
|
||||||
|
// Revert added modifications from the src trie, to see if dest trie can still
|
||||||
|
// sync with it(overwrite reverted states)
|
||||||
|
var reverted = make(map[string][]byte)
|
||||||
|
for k := range diff {
|
||||||
|
srcTrie.MustDelete([]byte(k))
|
||||||
|
reverted[k] = nil
|
||||||
|
}
|
||||||
|
for k := range srcData {
|
||||||
|
val := randBytes(32)
|
||||||
|
srcTrie.MustUpdate([]byte(k), val)
|
||||||
|
reverted[k] = val
|
||||||
|
}
|
||||||
|
root, nodes, _ = srcTrie.Commit(false)
|
||||||
|
if err := srcDb.Update(root, preRoot, 0, trienode.NewWithNodeSet(nodes), nil); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if err := srcDb.Commit(root, false); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
srcTrie, _ = NewStateTrie(TrieID(root), srcDb)
|
||||||
|
|
||||||
|
syncWith(t, srcTrie.Hash(), diskdb, srcDb)
|
||||||
|
checkTrieContents(t, diskdb, srcDb.Scheme(), srcTrie.Hash().Bytes(), reverted, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSyncMovingTarget(t *testing.T, scheme string, tiny bool) {
|
// Tests if state syncer can correctly catch up the pivot move.
|
||||||
|
func TestPivotMove(t *testing.T) {
|
||||||
|
testPivotMove(t, rawdb.HashScheme, true)
|
||||||
|
testPivotMove(t, rawdb.HashScheme, false)
|
||||||
|
testPivotMove(t, rawdb.PathScheme, true)
|
||||||
|
testPivotMove(t, rawdb.PathScheme, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPivotMove(t *testing.T, scheme string, tiny bool) {
|
||||||
var (
|
var (
|
||||||
srcDisk = rawdb.NewMemoryDatabase()
|
srcDisk = rawdb.NewMemoryDatabase()
|
||||||
srcTrieDB = newTestDatabase(srcDisk, scheme)
|
srcTrieDB = newTestDatabase(srcDisk, scheme)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue