Don't process block that we can't fetch height for (#4613)

This commit is contained in:
Chris Stewart 2022-08-22 13:21:50 -05:00 committed by GitHub
parent a0eb0824a2
commit 451b525be5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,43 +68,51 @@ private[bitcoins] trait TransactionProcessing extends WalletLogger {
logger.info( logger.info(
s"Processing block=${block.blockHeader.hash.flip.hex} heightOpt=$heightOpt") s"Processing block=${block.blockHeader.hash.flip.hex} heightOpt=$heightOpt")
} }
val resF = for {
isEmpty <- isEmptyF heightF.flatMap {
newWallet <- { case Some(height) =>
if (!isEmpty) { val resF = for {
processBlockCachedUtxos(block) isEmpty <- isEmptyF
} else { newWallet <- {
//do nothing if the wallet is empty as an optimization if (!isEmpty) {
//this is for users first downloading bitcoin-s processBlockCachedUtxos(block)
//and syncing their node } else {
Future.successful(this) //do nothing if the wallet is empty as an optimization
//this is for users first downloading bitcoin-s
//and syncing their node
Future.successful(this)
}
}
} yield newWallet
val f = for {
res <- resF
hash = block.blockHeader.hashBE
_ <- stateDescriptorDAO.updateSyncHeight(hash, height)
_ <- walletConfig.callBacks.executeOnBlockProcessed(block)
} yield {
res
} }
}
} yield newWallet
val f = for { f.onComplete(failure =>
res <- resF signalBlockProcessingCompletion(block.blockHeader.hash, failure))
hash = block.blockHeader.hashBE
height <- heightF f.foreach { _ =>
_ <- stateDescriptorDAO.updateSyncHeight(hash, height.get) val stop = TimeUtil.currentEpochMs
_ <- walletConfig.callBacks.executeOnBlockProcessed(block) logger.info(
} yield { s"Finished processing of block=${block.blockHeader.hash.flip.hex}. It took ${stop - start}ms")
res }
f.failed.foreach(e =>
logger.error(
s"Error processing of block=${block.blockHeader.hash.flip.hex}.",
e))
f
case None =>
logger.warn(
s"Could not find blockheight for blockHash=${block.blockHeader.hashBE.hex}, skipping processing in wallet")
Future.successful(this)
} }
f.onComplete(failure =>
signalBlockProcessingCompletion(block.blockHeader.hash, failure))
f.foreach { _ =>
val stop = TimeUtil.currentEpochMs
logger.info(
s"Finished processing of block=${block.blockHeader.hash.flip.hex}. It took ${stop - start}ms")
}
f.failed.foreach(e =>
logger.error(
s"Error processing of block=${block.blockHeader.hash.flip.hex}.",
e))
f
} }
/** Helper method to process a block. This fetches all of our relevent spending info dbs /** Helper method to process a block. This fetches all of our relevent spending info dbs