From 84659635a33efe41830e93647ef35fee472cf7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=B6ckli?= Date: Fri, 22 Dec 2023 13:31:59 +0100 Subject: [PATCH 1/2] BAARC-86: request highest missing blocks first --- blocktx/store/sql/get_block_gaps.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 { From 359a56203e7d6ccb70d977d437d3a5f1b905aa6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=B6ckli?= Date: Fri, 22 Dec 2023 13:33:19 +0100 Subject: [PATCH 2/2] BAARC-86: limit blocks requested per interval to 5 --- blocktx/peer_handler.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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