Skip to content

Commit 477ec75

Browse files
authored
Merge pull request #22513 from holiman/no_snap_bloom
eth/protocols/snap, eth/downloader: don't use bloom filter in snap sync
2 parents f304290 + 410089a commit 477ec75

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

‎eth/downloader/downloader.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func New(checkpoint uint64, stateDb ethdb.Database, stateBloom *trie.SyncBloom,
240240
headerProcCh: make(chan []*types.Header, 1),
241241
quitCh: make(chan struct{}),
242242
stateCh: make(chan dataPack),
243-
SnapSyncer: snap.NewSyncer(stateDb, stateBloom),
243+
SnapSyncer: snap.NewSyncer(stateDb),
244244
stateSyncStart: make(chan *stateSync),
245245
syncStatsState: stateSyncStats{
246246
processed: rawdb.ReadFastTrieProgress(stateDb),

‎eth/handler.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ func newHandler(config *handlerConfig) (*handler, error) {
177177
// Construct the downloader (long sync) and its backing state bloom if fast
178178
// sync is requested. The downloader is responsible for deallocating the state
179179
// bloom when it's done.
180-
if atomic.LoadUint32(&h.fastSync) == 1 {
180+
// Note: we don't enable it if snap-sync is performed, since it's very heavy
181+
// and the heal-portion of the snap sync is much lighter than fast. What we particularly
182+
// want to avoid, is a 90%-finished (but restarted) snap-sync to begin
183+
// indexing the entire trie
184+
if atomic.LoadUint32(&h.fastSync) == 1 && atomic.LoadUint32(&h.snapSync) == 0 {
181185
h.stateBloom = trie.NewSyncBloom(config.BloomCache, config.Database)
182186
}
183187
h.downloader = downloader.New(h.checkpointNumber, config.Database, h.stateBloom, h.eventMux, h.chain, nil, h.removePeer)

‎eth/protocols/snap/sync.go‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ type SyncPeer interface {
376376
// - The peer delivers a stale response after a previous timeout
377377
// - The peer delivers a refusal to serve the requested state
378378
type Syncer struct {
379-
db ethdb.KeyValueStore // Database to store the trie nodes into (and dedup)
380-
bloom *trie.SyncBloom // Bloom filter to deduplicate nodes for state fixup
379+
db ethdb.KeyValueStore // Database to store the trie nodes into (and dedup)
381380

382381
root common.Hash // Current state trie root being synced
383382
tasks []*accountTask // Current account task set being synced
@@ -446,10 +445,9 @@ type Syncer struct {
446445

447446
// NewSyncer creates a new snapshot syncer to download the Ethereum state over the
448447
// snap protocol.
449-
func NewSyncer(db ethdb.KeyValueStore, bloom *trie.SyncBloom) *Syncer {
448+
func NewSyncer(db ethdb.KeyValueStore) *Syncer {
450449
return &Syncer{
451-
db: db,
452-
bloom: bloom,
450+
db: db,
453451

454452
peers: make(map[string]SyncPeer),
455453
peerJoin: new(event.Feed),
@@ -546,7 +544,7 @@ func (s *Syncer) Sync(root common.Hash, cancel chan struct{}) error {
546544
s.lock.Lock()
547545
s.root = root
548546
s.healer = &healTask{
549-
scheduler: state.NewStateSync(root, s.db, s.bloom),
547+
scheduler: state.NewStateSync(root, s.db, nil),
550548
trieTasks: make(map[common.Hash]trie.SyncPath),
551549
codeTasks: make(map[common.Hash]struct{}),
552550
}
@@ -1660,7 +1658,6 @@ func (s *Syncer) processBytecodeResponse(res *bytecodeResponse) {
16601658
bytes += common.StorageSize(len(code))
16611659

16621660
rawdb.WriteCode(batch, hash, code)
1663-
s.bloom.Add(hash[:])
16641661
}
16651662
if err := batch.Write(); err != nil {
16661663
log.Crit("Failed to persist bytecodes", "err", err)
@@ -1796,7 +1793,6 @@ func (s *Syncer) processStorageResponse(res *storageResponse) {
17961793
}
17971794
// Node is not a boundary, persist to disk
17981795
batch.Put(it.Key(), it.Value())
1799-
s.bloom.Add(it.Key())
18001796

18011797
bytes += common.StorageSize(common.HashLength + len(it.Value()))
18021798
nodes++
@@ -1953,7 +1949,6 @@ func (s *Syncer) forwardAccountTask(task *accountTask) {
19531949
}
19541950
// Node is neither a boundary, not an incomplete account, persist to disk
19551951
batch.Put(it.Key(), it.Value())
1956-
s.bloom.Add(it.Key())
19571952

19581953
bytes += common.StorageSize(common.HashLength + len(it.Value()))
19591954
nodes++

‎eth/protocols/snap/sync_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ func TestSyncBloatedProof(t *testing.T) {
525525

526526
func setupSyncer(peers ...*testPeer) *Syncer {
527527
stateDb := rawdb.NewMemoryDatabase()
528-
syncer := NewSyncer(stateDb, trie.NewSyncBloom(1, stateDb))
528+
syncer := NewSyncer(stateDb)
529529
for _, peer := range peers {
530530
syncer.Register(peer)
531531
peer.remote = syncer

0 commit comments

Comments
 (0)