Skip to content

Commit

Permalink
eth/protocols, trie: revert change on syncbloom method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Jan 12, 2021
1 parent d6971c3 commit 2469e0b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion eth/protocols/eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func handleMessage(backend Backend, peer *Peer) error {
break
}
// Retrieve the requested state entry
if bloom := backend.StateBloom(); bloom != nil && !bloom.Contains(hash) {
if bloom := backend.StateBloom(); bloom != nil && !bloom.Contains(hash[:]) {
// Only lookup the trie node if there's chance that we actually have it
continue
}
Expand Down
6 changes: 3 additions & 3 deletions eth/protocols/snap/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ func (s *Syncer) processBytecodeResponse(res *bytecodeResponse) {
bytes += common.StorageSize(len(code))

rawdb.WriteCode(batch, hash, code)
s.bloom.Add(hash)
s.bloom.Add(hash[:])
}
if err := batch.Write(); err != nil {
log.Crit("Failed to persist bytecodes", "err", err)
Expand Down Expand Up @@ -1710,7 +1710,7 @@ func (s *Syncer) processStorageResponse(res *storageResponse) {
}
// Node is not a boundary, persist to disk
batch.Put(it.Key(), it.Value())
s.bloom.Add(common.BytesToHash(it.Key()))
s.bloom.Add(it.Key())

bytes += common.StorageSize(common.HashLength + len(it.Value()))
nodes++
Expand Down Expand Up @@ -1867,7 +1867,7 @@ func (s *Syncer) forwardAccountTask(task *accountTask) {
}
// Node is neither a boundary, not an incomplete account, persist to disk
batch.Put(it.Key(), it.Value())
s.bloom.Add(common.BytesToHash(it.Key()))
s.bloom.Add(it.Key())

bytes += common.StorageSize(common.HashLength + len(it.Value()))
nodes++
Expand Down
10 changes: 5 additions & 5 deletions trie/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (s *Sync) AddSubTrie(root common.Hash, path []byte, parent common.Hash, cal
if s.membatch.hasNode(root) {
return
}
if s.bloom == nil || s.bloom.Contains(root) {
if s.bloom == nil || s.bloom.Contains(root[:]) {
// Bloom filter says this might be a duplicate, double check.
// If database says yes, then at least the trie node is present
// and we hold the assumption that it's NOT legacy contract code.
Expand Down Expand Up @@ -195,7 +195,7 @@ func (s *Sync) AddCodeEntry(hash common.Hash, path []byte, parent common.Hash) {
if s.membatch.hasCode(hash) {
return
}
if s.bloom == nil || s.bloom.Contains(hash) {
if s.bloom == nil || s.bloom.Contains(hash[:]) {
// Bloom filter says this might be a duplicate, double check.
// If database says yes, the blob is present for sure.
// Note we only check the existence with new code scheme, fast
Expand Down Expand Up @@ -313,11 +313,11 @@ func (s *Sync) Commit(dbw ethdb.Batch) error {
// Dump the membatch into a database dbw
for key, value := range s.membatch.nodes {
rawdb.WriteTrieNode(dbw, key, value)
s.bloom.Add(key)
s.bloom.Add(key[:])
}
for key, value := range s.membatch.codes {
rawdb.WriteCode(dbw, key, value)
s.bloom.Add(key)
s.bloom.Add(key[:])
}
// Drop the membatch data and return
s.membatch = newSyncMemBatch()
Expand Down Expand Up @@ -406,7 +406,7 @@ func (s *Sync) children(req *request, object node) ([]*request, error) {
if s.membatch.hasNode(hash) {
continue
}
if s.bloom == nil || s.bloom.Contains(hash) {
if s.bloom == nil || s.bloom.Contains(node) {
// Bloom filter says this might be a duplicate, double check.
// If database says yes, then at least the trie node is present
// and we hold the assumption that it's NOT legacy contract code.
Expand Down
13 changes: 4 additions & 9 deletions trie/sync_bloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ func (b *SyncBloom) Close() error {
}

// Add inserts a new trie node hash into the bloom filter.
func (b *SyncBloom) Add(hash common.Hash) {
func (b *SyncBloom) Add(hash []byte) {
if atomic.LoadUint32(&b.closed) == 1 {
return
}
b.bloom.AddHash(hashToUint64(hash))
b.bloom.AddHash(binary.BigEndian.Uint64(hash))
bloomAddMeter.Mark(1)
}

Expand All @@ -170,7 +170,7 @@ func (b *SyncBloom) Add(hash common.Hash) {
// - true: the bloom maybe contains hash
//
// While the bloom is being initialized, any query will return true.
func (b *SyncBloom) Contains(hash common.Hash) bool {
func (b *SyncBloom) Contains(hash []byte) bool {
bloomTestMeter.Mark(1)
if atomic.LoadUint32(&b.inited) == 0 {
// We didn't load all the trie nodes from the previous run of Geth yet. As
Expand All @@ -179,14 +179,9 @@ func (b *SyncBloom) Contains(hash common.Hash) bool {
return true
}
// Bloom initialized, check the real one and report any successful misses
maybe := b.bloom.ContainsHash(hashToUint64(hash))
maybe := b.bloom.ContainsHash(binary.BigEndian.Uint64(hash))
if !maybe {
bloomMissMeter.Mark(1)
}
return maybe
}

func hashToUint64(h common.Hash) uint64 {
return uint64(h[7]) | uint64(h[6])<<8 | uint64(h[5])<<16 | uint64(h[4])<<24 |
uint64(h[3])<<32 | uint64(h[2])<<40 | uint64(h[1])<<48 | uint64(h[0])<<56
}

0 comments on commit 2469e0b

Please sign in to comment.