Skip to content

Commit 0f4e7c9

Browse files
authored
eth: utilize sync bloom for getNodeData (#21445)
* eth/downloader, eth/handler: utilize sync bloom for getNodeData * trie: handle if bloom is nil * trie, downloader: check bloom nilness externally
1 parent 1b5a867 commit 0f4e7c9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

eth/downloader/downloader.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ func (d *Downloader) Synchronising() bool {
283283
return atomic.LoadInt32(&d.synchronising) > 0
284284
}
285285

286+
// SyncBloomContains tests if the syncbloom filter contains the given hash:
287+
// - false: the bloom definitely does not contain hash
288+
// - true: the bloom maybe contains hash
289+
//
290+
// While the bloom is being initialized (or is closed), all queries will return true.
291+
func (d *Downloader) SyncBloomContains(hash []byte) bool {
292+
return d.stateBloom == nil || d.stateBloom.Contains(hash)
293+
}
294+
286295
// RegisterPeer injects a new download peer into the set of block source to be
287296
// used for fetching hashes and blocks from.
288297
func (d *Downloader) RegisterPeer(id string, version int, peer Peer) error {

eth/handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
610610
// Retrieve the requested state entry, stopping if enough was found
611611
// todo now the code and trienode is mixed in the protocol level,
612612
// separate these two types.
613+
if !pm.downloader.SyncBloomContains(hash[:]) {
614+
// Only lookup the trie node if there's chance that we actually have it
615+
continue
616+
}
613617
entry, err := pm.blockchain.TrieNode(hash)
614618
if len(entry) == 0 || err != nil {
615619
// Read the contract code with prefix only to save unnecessary lookups.

0 commit comments

Comments
 (0)