Fix rescan to fetch blocks during scan (#2540)

This commit is contained in:
benthecarman 2021-01-22 10:28:53 -06:00 committed by GitHub
parent 7cce23abf7
commit cba90e5c2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -150,12 +150,16 @@ class WalletUnitTest extends BitcoinSWalletTest {
it should "match block filters" in { wallet: Wallet =>
for {
height <- wallet.chainQueryApi.getFilterCount()
matched <- wallet.fetchFiltersInRange(
filtersResponse <- chainQueryApi.getFiltersBetweenHeights(startHeight = 0,
endHeight =
height)
matched <- wallet.findMatches(
filters = filtersResponse,
scripts = Vector(
// this is a random address which is included into the test block
BitcoinAddress("n1RH2x3b3ah4TGQtgrmNAHfmad9wr8U2QY").scriptPubKey),
parallelismLevel = 1
)(heightRange = 0.to(height).toVector)
)
} yield {
assert(
Vector(BlockMatchingResponse(blockHash = testBlockHash,

View file

@ -111,8 +111,6 @@ private[wallet] trait RescanHandling extends WalletLogger {
elements = range.toVector,
f = fetchFiltersInRange(scripts, parallelismLevel),
batchSize = batchSize)
_ <- downloadAndProcessBlocks(matched.map(_.blockHash.flip))
} yield {
logger.info(s"Matched ${matched.length} blocks on rescan")
matched
@ -260,7 +258,7 @@ private[wallet] trait RescanHandling extends WalletLogger {
}
}
private[wallet] def fetchFiltersInRange(
private def fetchFiltersInRange(
scripts: Vector[ScriptPubKey],
parallelismLevel: Int)(
heightRange: Vector[Int]): Future[Vector[BlockMatchingResponse]] = {
@ -271,6 +269,7 @@ private[wallet] trait RescanHandling extends WalletLogger {
startHeight = startHeight,
endHeight = endHeight)
filtered <- findMatches(filtersResponse, scripts, parallelismLevel)
_ <- downloadAndProcessBlocks(filtered.map(_.blockHash.flip))
} yield {
logger.info(
s"Found ${filtered.length} matches from start=$startHeight to end=$endHeight")
@ -278,7 +277,7 @@ private[wallet] trait RescanHandling extends WalletLogger {
}
}
private def findMatches(
private[wallet] def findMatches(
filters: Vector[FilterResponse],
scripts: Vector[ScriptPubKey],
parallelismLevel: Int): Future[Vector[BlockMatchingResponse]] = {