mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 02:39:18 +01:00
Handle the case where our block headers are synced already (#2021)
This commit is contained in:
parent
c9e5aa9c3b
commit
841230e35c
2 changed files with 30 additions and 3 deletions
|
@ -392,6 +392,20 @@ class ChainHandlerTest extends ChainDbUnitTest {
|
|||
|
||||
}
|
||||
|
||||
it must "return None for ChainHandler.nextBlockHeaderBatchRange if we are synced" in {
|
||||
chainHandler: ChainHandler =>
|
||||
val genesisHeader =
|
||||
chainHandler.chainConfig.chain.genesisBlock.blockHeader
|
||||
val assert1F = for {
|
||||
rangeOpt <-
|
||||
chainHandler.nextBlockHeaderBatchRange(genesisHeader.hashBE, 1)
|
||||
count <- chainHandler.getBlockCount()
|
||||
} yield {
|
||||
assert(rangeOpt.isEmpty)
|
||||
}
|
||||
assert1F
|
||||
}
|
||||
|
||||
it must "generate a range for a block filter header query" in {
|
||||
chainHandler: ChainHandler =>
|
||||
for {
|
||||
|
|
|
@ -199,9 +199,22 @@ case class ChainHandler(
|
|||
|
||||
for {
|
||||
chains <- chainsF
|
||||
} yield getBestChainAtHeight(startHeight = startHeight,
|
||||
batchSize = batchSize,
|
||||
blockchains = chains)
|
||||
} yield {
|
||||
val nextBlockHeaderOpt = getBestChainAtHeight(startHeight = startHeight,
|
||||
batchSize = batchSize,
|
||||
blockchains = chains)
|
||||
(nextBlockHeaderOpt, prevBlockHeaderOpt) match {
|
||||
case (Some(next), Some(prev)) =>
|
||||
//this means we are synced, so return None
|
||||
if (next.stopBlockHash == prev.hash) {
|
||||
None
|
||||
} else {
|
||||
nextBlockHeaderOpt
|
||||
}
|
||||
case (Some(_), None) | (None, Some(_)) | (None, None) =>
|
||||
nextBlockHeaderOpt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Given a vector of blockchains, this method finds the chain with the most chain work
|
||||
|
|
Loading…
Add table
Reference in a new issue