Skip to content

Commit

Permalink
chain: use neutrino filters to speed up bitcoind seed recovery
Browse files Browse the repository at this point in the history
In this commit, we use neutrino filters to speed up bitcoind seed
recovery. We use the recently created `maybeShouldFetchBlock` function
to check the filters to see if we need to fetch a block at all. This
saves us from fetching, decoding, then scanning the block contents if we
know nothing is present in them.

At this point, we can also further consolidate the `FilterBlocks`
methods between the two backends, as they're now identical.
  • Loading branch information
Roasbeef committed Sep 22, 2023
1 parent bb4ca79 commit 6c9113e
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions chain/bitcoind_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,12 +968,38 @@ func (c *BitcoindClient) FilterBlocks(

blockFilterer := NewBlockFilterer(c.chainConn.cfg.ChainParams, req)

// Iterate over the requested blocks, fetching each from the rpc client.
// Each block will scanned using the reverse addresses indexes generated
// above, breaking out early if any addresses are found.
// Construct the watchlist using the addresses and outpoints contained
// in the filter blocks request.
watchList, err := buildFilterBlocksWatchList(req)
if err != nil {
return nil, err
}

// Iterate over the requested blocks, fetching each from the rpc
// client. Each block will scanned using the reverse addresses indexes
// generated above, breaking out early if any addresses are found.
for i, block := range req.Blocks {
// TODO(conner): add prefetching, since we already know we'll be
// fetching *every* block
shouldFetchBlock, err := maybeShouldFetchBlock(
c.chainConn.client, block, watchList,
)
if err != nil {
return nil, err
}

// If the filter concluded that there're no matches in this
// block, then we don't need to fetch it, as there're no false
// negatives.
if !shouldFetchBlock {
log.Infof("Skipping block height=%d hash=%v, no "+
"filter match", block.Height, block.Hash)
continue
}

log.Infof("Fetching block height=%d hash=%v",
block.Height, block.Hash)

// TODO(conner): add prefetching, since we already know we'll
// be fetching *every* block
rawBlock, err := c.GetBlock(&block.Hash)
if err != nil {
return nil, err
Expand Down

0 comments on commit 6c9113e

Please sign in to comment.