mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-19 05:43:51 +01:00
Don't process block that we can't fetch height for (#4613)
This commit is contained in:
parent
a0eb0824a2
commit
451b525be5
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user