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

View file

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