Skip to content

Commit 58d1988

Browse files
committed
core, eth, les, trie: remove the sync bloom, used by fast sync
1 parent 5e78fc0 commit 58d1988

18 files changed

+49
-329
lines changed

core/state/sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
// NewStateSync create a new state trie download scheduler.
30-
func NewStateSync(root common.Hash, database ethdb.KeyValueReader, bloom *trie.SyncBloom, onLeaf func(paths [][]byte, leaf []byte) error) *trie.Sync {
30+
func NewStateSync(root common.Hash, database ethdb.KeyValueReader, onLeaf func(paths [][]byte, leaf []byte) error) *trie.Sync {
3131
// Register the storage slot callback if the external callback is specified.
3232
var onSlot func(paths [][]byte, hexpath []byte, leaf []byte, parent common.Hash) error
3333
if onLeaf != nil {
@@ -52,6 +52,6 @@ func NewStateSync(root common.Hash, database ethdb.KeyValueReader, bloom *trie.S
5252
syncer.AddCodeEntry(common.BytesToHash(obj.CodeHash), hexpath, parent)
5353
return nil
5454
}
55-
syncer = trie.NewSync(root, database, onAccount, bloom)
55+
syncer = trie.NewSync(root, database, onAccount)
5656
return syncer
5757
}

core/state/sync_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/ethereum/go-ethereum/core/types"
2727
"github.com/ethereum/go-ethereum/crypto"
2828
"github.com/ethereum/go-ethereum/ethdb"
29-
"github.com/ethereum/go-ethereum/ethdb/memorydb"
3029
"github.com/ethereum/go-ethereum/rlp"
3130
"github.com/ethereum/go-ethereum/trie"
3231
)
@@ -134,7 +133,7 @@ func checkStateConsistency(db ethdb.Database, root common.Hash) error {
134133
// Tests that an empty state is not scheduled for syncing.
135134
func TestEmptyStateSync(t *testing.T) {
136135
empty := common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
137-
sync := NewStateSync(empty, rawdb.NewMemoryDatabase(), trie.NewSyncBloom(1, memorydb.New()), nil)
136+
sync := NewStateSync(empty, rawdb.NewMemoryDatabase(), nil)
138137
if nodes, paths, codes := sync.Missing(1); len(nodes) != 0 || len(paths) != 0 || len(codes) != 0 {
139138
t.Errorf(" content requested for empty state: %v, %v, %v", nodes, paths, codes)
140139
}
@@ -171,7 +170,7 @@ func testIterativeStateSync(t *testing.T, count int, commit bool, bypath bool) {
171170

172171
// Create a destination state and sync with the scheduler
173172
dstDb := rawdb.NewMemoryDatabase()
174-
sched := NewStateSync(srcRoot, dstDb, trie.NewSyncBloom(1, dstDb), nil)
173+
sched := NewStateSync(srcRoot, dstDb, nil)
175174

176175
nodes, paths, codes := sched.Missing(count)
177176
var (
@@ -250,7 +249,7 @@ func TestIterativeDelayedStateSync(t *testing.T) {
250249

251250
// Create a destination state and sync with the scheduler
252251
dstDb := rawdb.NewMemoryDatabase()
253-
sched := NewStateSync(srcRoot, dstDb, trie.NewSyncBloom(1, dstDb), nil)
252+
sched := NewStateSync(srcRoot, dstDb, nil)
254253

255254
nodes, _, codes := sched.Missing(0)
256255
queue := append(append([]common.Hash{}, nodes...), codes...)
@@ -298,7 +297,7 @@ func testIterativeRandomStateSync(t *testing.T, count int) {
298297

299298
// Create a destination state and sync with the scheduler
300299
dstDb := rawdb.NewMemoryDatabase()
301-
sched := NewStateSync(srcRoot, dstDb, trie.NewSyncBloom(1, dstDb), nil)
300+
sched := NewStateSync(srcRoot, dstDb, nil)
302301

303302
queue := make(map[common.Hash]struct{})
304303
nodes, _, codes := sched.Missing(count)
@@ -348,7 +347,7 @@ func TestIterativeRandomDelayedStateSync(t *testing.T) {
348347

349348
// Create a destination state and sync with the scheduler
350349
dstDb := rawdb.NewMemoryDatabase()
351-
sched := NewStateSync(srcRoot, dstDb, trie.NewSyncBloom(1, dstDb), nil)
350+
sched := NewStateSync(srcRoot, dstDb, nil)
352351

353352
queue := make(map[common.Hash]struct{})
354353
nodes, _, codes := sched.Missing(0)
@@ -415,7 +414,7 @@ func TestIncompleteStateSync(t *testing.T) {
415414

416415
// Create a destination state and sync with the scheduler
417416
dstDb := rawdb.NewMemoryDatabase()
418-
sched := NewStateSync(srcRoot, dstDb, trie.NewSyncBloom(1, dstDb), nil)
417+
sched := NewStateSync(srcRoot, dstDb, nil)
419418

420419
var added []common.Hash
421420

eth/downloader/downloader.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"github.com/ethereum/go-ethereum/event"
3737
"github.com/ethereum/go-ethereum/log"
3838
"github.com/ethereum/go-ethereum/params"
39-
"github.com/ethereum/go-ethereum/trie"
4039
)
4140

4241
var (
@@ -101,8 +100,7 @@ type Downloader struct {
101100
queue *queue // Scheduler for selecting the hashes to download
102101
peers *peerSet // Set of active peers from which download can proceed
103102

104-
stateDB ethdb.Database // Database to state sync into (and deduplicate via)
105-
stateBloom *trie.SyncBloom // Bloom filter for snap trie node and contract code existence checks
103+
stateDB ethdb.Database // Database to state sync into (and deduplicate via)
106104

107105
// Statistics
108106
syncStatsChainOrigin uint64 // Origin block number where syncing started at
@@ -203,13 +201,12 @@ type BlockChain interface {
203201
}
204202

205203
// New creates a new downloader to fetch hashes and blocks from remote peers.
206-
func New(checkpoint uint64, stateDb ethdb.Database, stateBloom *trie.SyncBloom, mux *event.TypeMux, chain BlockChain, lightchain LightChain, dropPeer peerDropFn) *Downloader {
204+
func New(checkpoint uint64, stateDb ethdb.Database, mux *event.TypeMux, chain BlockChain, lightchain LightChain, dropPeer peerDropFn) *Downloader {
207205
if lightchain == nil {
208206
lightchain = chain
209207
}
210208
dl := &Downloader{
211209
stateDB: stateDb,
212-
stateBloom: stateBloom,
213210
mux: mux,
214211
checkpoint: checkpoint,
215212
queue: newQueue(blockCacheMaxItems, blockCacheInitialItems),
@@ -365,12 +362,6 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode
365362
if atomic.CompareAndSwapInt32(&d.notified, 0, 1) {
366363
log.Info("Block synchronisation started")
367364
}
368-
// If we are already full syncing, but have a snap-sync bloom filter laying
369-
// around, make sure it doesn't use memory any more. This is a special case
370-
// when the user attempts to snap sync a new empty network.
371-
if mode == FullSync && d.stateBloom != nil {
372-
d.stateBloom.Close()
373-
}
374365
// If snap sync was requested, create the snap scheduler and switch to snap
375366
// sync mode. Long term we could drop snap sync or merge the two together,
376367
// but until snap becomes prevalent, we should support both. TODO(karalabe).
@@ -612,9 +603,6 @@ func (d *Downloader) Terminate() {
612603
default:
613604
close(d.quitCh)
614605
}
615-
if d.stateBloom != nil {
616-
d.stateBloom.Close()
617-
}
618606
d.quitLock.Unlock()
619607

620608
// Cancel any pending download requests
@@ -1599,15 +1587,6 @@ func (d *Downloader) commitPivotBlock(result *fetchResult) error {
15991587
return err
16001588
}
16011589
atomic.StoreInt32(&d.committed, 1)
1602-
1603-
// If we had a bloom filter for the state sync, deallocate it now. Note, we only
1604-
// deallocate internally, but keep the empty wrapper. This ensures that if we do
1605-
// a rollback after committing the pivot and restarting snap sync, we don't end
1606-
// up using a nil bloom. Empty bloom is fine, it just returns that it does not
1607-
// have the info we need, so reach down to the database instead.
1608-
if d.stateBloom != nil {
1609-
d.stateBloom.Close()
1610-
}
16111590
return nil
16121591
}
16131592

eth/downloader/downloader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func newTester() *downloadTester {
7575
chain: chain,
7676
peers: make(map[string]*downloadTesterPeer),
7777
}
78-
tester.downloader = New(0, db, trie.NewSyncBloom(1, db), new(event.TypeMux), tester.chain, nil, tester.dropPeer)
78+
tester.downloader = New(0, db, new(event.TypeMux), tester.chain, nil, tester.dropPeer)
7979
return tester
8080
}
8181

eth/handler.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import (
3939
"github.com/ethereum/go-ethereum/log"
4040
"github.com/ethereum/go-ethereum/p2p"
4141
"github.com/ethereum/go-ethereum/params"
42-
"github.com/ethereum/go-ethereum/trie"
4342
)
4443

4544
const (
@@ -106,7 +105,6 @@ type handler struct {
106105
maxPeers int
107106

108107
downloader *downloader.Downloader
109-
stateBloom *trie.SyncBloom
110108
blockFetcher *fetcher.BlockFetcher
111109
txFetcher *fetcher.TxFetcher
112110
peers *peerSet
@@ -176,14 +174,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
176174
// Construct the downloader (long sync) and its backing state bloom if snap
177175
// sync is requested. The downloader is responsible for deallocating the state
178176
// bloom when it's done.
179-
// Note: we don't enable it if snap-sync is performed, since it's very heavy
180-
// and the heal-portion of the snap sync is much lighter than snap. What we particularly
181-
// want to avoid, is a 90%-finished (but restarted) snap-sync to begin
182-
// indexing the entire trie
183-
if atomic.LoadUint32(&h.snapSync) == 1 && atomic.LoadUint32(&h.snapSync) == 0 {
184-
h.stateBloom = trie.NewSyncBloom(config.BloomCache, config.Database)
185-
}
186-
h.downloader = downloader.New(h.checkpointNumber, config.Database, h.stateBloom, h.eventMux, h.chain, nil, h.removePeer)
177+
h.downloader = downloader.New(h.checkpointNumber, config.Database, h.eventMux, h.chain, nil, h.removePeer)
187178

188179
// Construct the fetcher (short sync)
189180
validator := func(header *types.Header) error {

eth/handler_eth.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ import (
2727
"github.com/ethereum/go-ethereum/core/types"
2828
"github.com/ethereum/go-ethereum/eth/protocols/eth"
2929
"github.com/ethereum/go-ethereum/p2p/enode"
30-
"github.com/ethereum/go-ethereum/trie"
3130
)
3231

3332
// ethHandler implements the eth.Backend interface to handle the various network
3433
// packets that are sent as replies or broadcasts.
3534
type ethHandler handler
3635

37-
func (h *ethHandler) Chain() *core.BlockChain { return h.chain }
38-
func (h *ethHandler) StateBloom() *trie.SyncBloom { return h.stateBloom }
39-
func (h *ethHandler) TxPool() eth.TxPool { return h.txpool }
36+
func (h *ethHandler) Chain() *core.BlockChain { return h.chain }
37+
func (h *ethHandler) TxPool() eth.TxPool { return h.txpool }
4038

4139
// RunPeer is invoked when a peer joins on the `eth` protocol.
4240
func (h *ethHandler) RunPeer(peer *eth.Peer, hand eth.Handler) error {

eth/handler_eth_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"github.com/ethereum/go-ethereum/p2p"
3939
"github.com/ethereum/go-ethereum/p2p/enode"
4040
"github.com/ethereum/go-ethereum/params"
41-
"github.com/ethereum/go-ethereum/trie"
4241
)
4342

4443
// testEthHandler is a mock event handler to listen for inbound network requests
@@ -50,7 +49,6 @@ type testEthHandler struct {
5049
}
5150

5251
func (h *testEthHandler) Chain() *core.BlockChain { panic("no backing chain") }
53-
func (h *testEthHandler) StateBloom() *trie.SyncBloom { panic("no backing state bloom") }
5452
func (h *testEthHandler) TxPool() eth.TxPool { panic("no backing tx pool") }
5553
func (h *testEthHandler) AcceptTxs() bool { return true }
5654
func (h *testEthHandler) RunPeer(*eth.Peer, eth.Handler) error { panic("not used in tests") }

eth/protocols/eth/handler.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/ethereum/go-ethereum/p2p/enode"
3030
"github.com/ethereum/go-ethereum/p2p/enr"
3131
"github.com/ethereum/go-ethereum/params"
32-
"github.com/ethereum/go-ethereum/trie"
3332
)
3433

3534
const (
@@ -69,9 +68,6 @@ type Backend interface {
6968
// Chain retrieves the blockchain object to serve data.
7069
Chain() *core.BlockChain
7170

72-
// StateBloom retrieves the bloom filter - if any - for state trie nodes.
73-
StateBloom() *trie.SyncBloom
74-
7571
// TxPool retrieves the transaction pool object to serve data.
7672
TxPool() TxPool
7773

eth/protocols/eth/handler_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"github.com/ethereum/go-ethereum/p2p"
3535
"github.com/ethereum/go-ethereum/p2p/enode"
3636
"github.com/ethereum/go-ethereum/params"
37-
"github.com/ethereum/go-ethereum/trie"
3837
)
3938

4039
var (
@@ -91,9 +90,8 @@ func (b *testBackend) close() {
9190
b.chain.Stop()
9291
}
9392

94-
func (b *testBackend) Chain() *core.BlockChain { return b.chain }
95-
func (b *testBackend) StateBloom() *trie.SyncBloom { return nil }
96-
func (b *testBackend) TxPool() TxPool { return b.txpool }
93+
func (b *testBackend) Chain() *core.BlockChain { return b.chain }
94+
func (b *testBackend) TxPool() TxPool { return b.txpool }
9795

9896
func (b *testBackend) RunPeer(peer *Peer, handler Handler) error {
9997
// Normally the backend would do peer mainentance and handshakes. All that

eth/protocols/eth/handlers.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ func handleGetNodeData66(backend Backend, msg Decoder, peer *Peer) error {
164164
if err := msg.Decode(&query); err != nil {
165165
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
166166
}
167-
response := ServiceGetNodeDataQuery(backend.Chain(), backend.StateBloom(), query.GetNodeDataPacket)
167+
response := ServiceGetNodeDataQuery(backend.Chain(), query.GetNodeDataPacket)
168168
return peer.ReplyNodeData(query.RequestId, response)
169169
}
170170

171171
// ServiceGetNodeDataQuery assembles the response to a node data query. It is
172172
// exposed to allow external packages to test protocol behavior.
173-
func ServiceGetNodeDataQuery(chain *core.BlockChain, bloom *trie.SyncBloom, query GetNodeDataPacket) [][]byte {
173+
func ServiceGetNodeDataQuery(chain *core.BlockChain, query GetNodeDataPacket) [][]byte {
174174
// Gather state data until the fetch or network limits is reached
175175
var (
176176
bytes int
@@ -182,10 +182,6 @@ func ServiceGetNodeDataQuery(chain *core.BlockChain, bloom *trie.SyncBloom, quer
182182
break
183183
}
184184
// Retrieve the requested state entry
185-
if bloom != nil && !bloom.Contains(hash[:]) {
186-
// Only lookup the trie node if there's chance that we actually have it
187-
continue
188-
}
189185
entry, err := chain.TrieNode(hash)
190186
if len(entry) == 0 || err != nil {
191187
// Read the contract code with prefix only to save unnecessary lookups.

0 commit comments

Comments
 (0)