aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-05-13 20:28:01 +0800
committerGitHub <noreply@github.com>2019-05-13 20:28:01 +0800
commit9effd642901e13765dcc1396392ba55a18f66ccf (patch)
tree57355cff7ea6c5efbb5702c6e62ec7b698d4ff15 /core
parent40cdcf8c47ff094775aca08fd5d94051f9cf1dbb (diff)
downloadgo-tangerine-9effd642901e13765dcc1396392ba55a18f66ccf.tar
go-tangerine-9effd642901e13765dcc1396392ba55a18f66ccf.tar.gz
go-tangerine-9effd642901e13765dcc1396392ba55a18f66ccf.tar.bz2
go-tangerine-9effd642901e13765dcc1396392ba55a18f66ccf.tar.lz
go-tangerine-9effd642901e13765dcc1396392ba55a18f66ccf.tar.xz
go-tangerine-9effd642901e13765dcc1396392ba55a18f66ccf.tar.zst
go-tangerine-9effd642901e13765dcc1396392ba55a18f66ccf.zip
core, eth, trie: bloom filter for trie node dedup during fast sync (#19489)
* core, eth, trie: bloom filter for trie node dedup during fast sync * eth/downloader, trie: address review comments * core, ethdb, trie: restart fast-sync bloom construction now and again * eth/downloader: initialize fast sync bloom on startup * eth: reenable eth/62 until we properly remove it
Diffstat (limited to 'core')
-rw-r--r--core/rawdb/table.go7
-rw-r--r--core/state/sync.go4
-rw-r--r--core/state/sync_test.go13
3 files changed, 16 insertions, 8 deletions
diff --git a/core/rawdb/table.go b/core/rawdb/table.go
index e19649dd4..0e50db7c9 100644
--- a/core/rawdb/table.go
+++ b/core/rawdb/table.go
@@ -67,6 +67,13 @@ func (t *table) NewIterator() ethdb.Iterator {
return t.NewIteratorWithPrefix(nil)
}
+// NewIteratorWithStart creates a binary-alphabetical iterator over a subset of
+// database content starting at a particular initial key (or after, if it does
+// not exist).
+func (t *table) NewIteratorWithStart(start []byte) ethdb.Iterator {
+ return t.db.NewIteratorWithStart(start)
+}
+
// NewIteratorWithPrefix creates a binary-alphabetical iterator over a subset
// of database content with a particular key prefix.
func (t *table) NewIteratorWithPrefix(prefix []byte) ethdb.Iterator {
diff --git a/core/state/sync.go b/core/state/sync.go
index 5290411a3..e4a08d293 100644
--- a/core/state/sync.go
+++ b/core/state/sync.go
@@ -26,7 +26,7 @@ import (
)
// NewStateSync create a new state trie download scheduler.
-func NewStateSync(root common.Hash, database ethdb.Reader) *trie.Sync {
+func NewStateSync(root common.Hash, database ethdb.Reader, bloom *trie.SyncBloom) *trie.Sync {
var syncer *trie.Sync
callback := func(leaf []byte, parent common.Hash) error {
var obj Account
@@ -37,6 +37,6 @@ func NewStateSync(root common.Hash, database ethdb.Reader) *trie.Sync {
syncer.AddRawEntry(common.BytesToHash(obj.CodeHash), 64, parent)
return nil
}
- syncer = trie.NewSync(root, database, callback)
+ syncer = trie.NewSync(root, database, callback, bloom)
return syncer
}
diff --git a/core/state/sync_test.go b/core/state/sync_test.go
index ab4718b04..de098dce0 100644
--- a/core/state/sync_test.go
+++ b/core/state/sync_test.go
@@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
+ "github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/trie"
)
@@ -125,7 +126,7 @@ func checkStateConsistency(db ethdb.Database, root common.Hash) error {
// Tests that an empty state is not scheduled for syncing.
func TestEmptyStateSync(t *testing.T) {
empty := common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
- if req := NewStateSync(empty, rawdb.NewMemoryDatabase()).Missing(1); len(req) != 0 {
+ if req := NewStateSync(empty, rawdb.NewMemoryDatabase(), trie.NewSyncBloom(1, memorydb.New())).Missing(1); len(req) != 0 {
t.Errorf("content requested for empty state: %v", req)
}
}
@@ -141,7 +142,7 @@ func testIterativeStateSync(t *testing.T, batch int) {
// Create a destination state and sync with the scheduler
dstDb := rawdb.NewMemoryDatabase()
- sched := NewStateSync(srcRoot, dstDb)
+ sched := NewStateSync(srcRoot, dstDb, trie.NewSyncBloom(1, dstDb))
queue := append([]common.Hash{}, sched.Missing(batch)...)
for len(queue) > 0 {
@@ -173,7 +174,7 @@ func TestIterativeDelayedStateSync(t *testing.T) {
// Create a destination state and sync with the scheduler
dstDb := rawdb.NewMemoryDatabase()
- sched := NewStateSync(srcRoot, dstDb)
+ sched := NewStateSync(srcRoot, dstDb, trie.NewSyncBloom(1, dstDb))
queue := append([]common.Hash{}, sched.Missing(0)...)
for len(queue) > 0 {
@@ -210,7 +211,7 @@ func testIterativeRandomStateSync(t *testing.T, batch int) {
// Create a destination state and sync with the scheduler
dstDb := rawdb.NewMemoryDatabase()
- sched := NewStateSync(srcRoot, dstDb)
+ sched := NewStateSync(srcRoot, dstDb, trie.NewSyncBloom(1, dstDb))
queue := make(map[common.Hash]struct{})
for _, hash := range sched.Missing(batch) {
@@ -250,7 +251,7 @@ func TestIterativeRandomDelayedStateSync(t *testing.T) {
// Create a destination state and sync with the scheduler
dstDb := rawdb.NewMemoryDatabase()
- sched := NewStateSync(srcRoot, dstDb)
+ sched := NewStateSync(srcRoot, dstDb, trie.NewSyncBloom(1, dstDb))
queue := make(map[common.Hash]struct{})
for _, hash := range sched.Missing(0) {
@@ -297,7 +298,7 @@ func TestIncompleteStateSync(t *testing.T) {
// Create a destination state and sync with the scheduler
dstDb := rawdb.NewMemoryDatabase()
- sched := NewStateSync(srcRoot, dstDb)
+ sched := NewStateSync(srcRoot, dstDb, trie.NewSyncBloom(1, dstDb))
added := []common.Hash{}
queue := append([]common.Hash{}, sched.Missing(1)...)