diff --git a/blocktx/peer_handler.go b/blocktx/peer_handler.go index e80175f52..073c9b860 100644 --- a/blocktx/peer_handler.go +++ b/blocktx/peer_handler.go @@ -26,7 +26,10 @@ import ( "github.com/ordishs/gocore" ) -const transactionStoringBatchsizeDefault = 65536 // power of 2 for easier memory allocation +const ( + transactionStoringBatchsizeDefault = 65536 // power of 2 for easier memory allocation + maxRequestBlocks = 5 +) func init() { // override the default wire block handler with our own that streams and stores only the transaction ids @@ -394,7 +397,11 @@ func (bs *PeerHandler) FillGaps(peer p2p.PeerI) error { return nil } - for _, gaps := range blockHeightGaps { + for i, gaps := range blockHeightGaps { + if i+1 > maxRequestBlocks { + break + } + _, found := bs.announcedCache.Get(*gaps.Hash) if found { return nil diff --git a/blocktx/store/sql/get_block_gaps.go b/blocktx/store/sql/get_block_gaps.go index d8c2a8a44..00f53574c 100644 --- a/blocktx/store/sql/get_block_gaps.go +++ b/blocktx/store/sql/get_block_gaps.go @@ -26,7 +26,8 @@ func (s *SQL) GetBlockGaps(ctx context.Context) ([]*store.BlockGap, error) { )) AS block_heights) AS bl LEFT JOIN blocks blks ON blks.height = bl.block_heights WHERE blks.height IS NULL - ) AS missing_blocks ON blocks.height = missing_blocks.missing_block_height + 1;` + ) AS missing_blocks ON blocks.height = missing_blocks.missing_block_height + 1 + ORDER BY missing_blocks.missing_block_height DESC;` rows, err := s.db.QueryContext(ctx, q) if err != nil {