Skip to content

Commit ffba5f8

Browse files
committed
eth/downloader: fix snap sync of the db on the path scheme
1 parent 8594b43 commit ffba5f8

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

eth/downloader/downloader.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,23 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
468468
if err != nil {
469469
return err
470470
}
471+
if d.blockchain.TrieDB().Scheme() == rawdb.PathScheme && mode == SnapSync {
472+
// Ensure the pivot is above the minimum full block threshold
473+
pivotNumber := uint64(0)
474+
if pivot != nil {
475+
pivotNumber = pivot.Number.Uint64()
476+
}
477+
if pivotNumber < uint64(fsMinFullBlocks) {
478+
block := d.blockchain.CurrentBlock()
479+
if err = d.blockchain.TrieDB().Enable(block.Root); err != nil {
480+
return fmt.Errorf("failed to enable trie db: %v", err)
481+
}
482+
log.Info("Disabling snap sync of the db on the path scheme due to the pivot header being positioned too low",
483+
"pivot", pivotNumber)
484+
<-time.After(3 * time.Second)
485+
return errCanceled
486+
}
487+
}
471488
} else {
472489
// In beacon mode, use the skeleton chain to retrieve the headers from
473490
latest, _, final, err = d.skeleton.Bounds()

eth/handler_eth.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (h *ethHandler) Handle(peer *eth.Peer, packet eth.Packet) error {
6565
return h.handleBlockAnnounces(peer, hashes, numbers)
6666

6767
case *eth.NewBlockPacket:
68-
return h.handleBlockBroadcast(peer, packet.Block, packet.TD)
68+
return h.handleBlockBroadcast(peer, packet)
6969

7070
case *eth.NewPooledTransactionHashesPacket:
7171
return h.txFetcher.Notify(peer.ID(), packet.Types, packet.Sizes, packet.Hashes)
@@ -121,7 +121,10 @@ func (h *ethHandler) handleBlockAnnounces(peer *eth.Peer, hashes []common.Hash,
121121

122122
// handleBlockBroadcast is invoked from a peer's message handler when it transmits a
123123
// block broadcast for the local node to process.
124-
func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, block *types.Block, td *big.Int) error {
124+
func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, packet *eth.NewBlockPacket) error {
125+
block := packet.Block
126+
td := packet.TD
127+
125128
// Schedule the block for import
126129
h.blockFetcher.Enqueue(peer.ID(), block)
127130

0 commit comments

Comments
 (0)