Fix bug where we were executing block callbacks when we hadn't seen a block header (#5455)

* Fix bug where we were executing block callbacks when we hadn't seen a block header

* reduce log to DEBUG
This commit is contained in:
Chris Stewart 2024-03-05 13:47:03 -06:00 committed by GitHub
parent 238948e185
commit 898d2b44ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 6 deletions

View File

@ -100,6 +100,8 @@ class DataMessageHandlerTest extends NodeTestWithCachedBitcoindNewest {
nodeCallbacks = NodeCallbacks.onBlockReceived(callback)
_ = node.nodeAppConfig.addCallbacks(nodeCallbacks)
hash <- bitcoind.generateToAddress(blocks = 1, junkAddress).map(_.head)
_ <- NodeTestUtil.awaitAllSync(node, bitcoind)
_ <- node.downloadBlocks(Vector(hash.flip))
result = Await.result(resultP.future, 30.seconds)
} yield assert(result.blockHeader.hashBE == hash)
}

View File

@ -310,11 +310,7 @@ case class DataMessageHandler(
HeadersMessage(CompactSizeUInt.one, Vector(block.blockHeader))
val newDmhF = handleDataPayload(payload = headersMessage,
peerData = peerData)
newDmhF.flatMap { dmh =>
appConfig.callBacks
.executeOnBlockReceivedCallbacks(block)
.map(_ => dmh)
}
newDmhF
} else {
logger.info(
s"Received block=${block.blockHeader.hash.flip.hex} state=$state")
@ -508,7 +504,7 @@ case class DataMessageHandler(
stopBlockHash: DoubleSha256DigestBE,
startHeightOpt: Option[Int],
syncNodeState: SyncNodeState): Future[Option[NodeState.FilterSync]] = {
logger.info(s"Beginning to sync filters to stopBlockHashBE=$stopBlockHash")
logger.debug(s"Beginning to sync filters to stopBlockHashBE=$stopBlockHash")
val fs = syncNodeState match {
case x @ (_: HeaderSync | _: FilterHeaderSync) =>