Skip to content

Commit

Permalink
Merge pull request #228 from bitcoin-sv/fix/blocktx-fill-gaps
Browse files Browse the repository at this point in the history
Fix/blocktx fill gaps
  • Loading branch information
boecklim authored Dec 22, 2023
2 parents 027c017 + 359a562 commit c814f5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions blocktx/peer_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion blocktx/store/sql/get_block_gaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c814f5b

Please sign in to comment.