Refactor NodeTestUtil.awaitBestHash() to take a reference to bitcoind (#4973)

* Refactor NodeTestUtil.awaitBestHash() to take a reference to bitcoind

* Empty commit
This commit is contained in:
Chris Stewart 2023-02-05 08:59:09 -06:00 committed by GitHub
parent 1391c9497e
commit 7e346e58fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 14 deletions

View file

@ -224,9 +224,9 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
//as they happen with the 'sendheaders' message
//both our spv node and our bitcoind node _should_ both be at the genesis block (regtest)
//at this point so no actual syncing is happening
val initSyncF = gen1F.flatMap { hashes =>
val initSyncF = gen1F.flatMap { _ =>
for {
_ <- NodeTestUtil.awaitBestHash(hashes.head, node)
_ <- NodeTestUtil.awaitBestHash(node, bitcoind)
} yield ()
}

View file

@ -115,8 +115,7 @@ class NeutrinoNodeWithUncachedBitcoindTest extends NodeUnitTest with CachedTor {
//out of sync by 1 block, h2 ahead
_ = assert(h2 - h1 == 1)
_ <- node.sync()
bestHash <- bitcoinds(1).getBestBlockHash
_ <- NodeTestUtil.awaitBestHash(bestHash, node)
_ <- NodeTestUtil.awaitBestHash(node, bitcoinds(1))
} yield {
succeed
}

View file

@ -166,18 +166,25 @@ abstract class NodeTestUtil extends P2PLogger {
}
/** The future doesn't complete until the nodes best hash is the given hash */
def awaitBestHash(hash: DoubleSha256DigestBE, node: Node)(implicit
def awaitBestHash(node: Node, bitcoind: BitcoindRpcClient)(implicit
system: ActorSystem): Future[Unit] = {
import system.dispatcher
def bestHashF: Future[DoubleSha256DigestBE] = {
def bestBitcoinSHashF: Future[DoubleSha256DigestBE] = {
node.chainApiFromDb().flatMap(_.getBestBlockHash())
}
TestAsyncUtil.retryUntilSatisfiedF(() =>
bestHashF.map { case bestHash =>
bestHash == hash
},
interval = 1.second,
maxTries = syncTries)
def bestBitcoindHashF: Future[DoubleSha256DigestBE] =
bitcoind.getBestBlockHash
TestAsyncUtil.retryUntilSatisfiedF(
() => {
for {
bestBitcoindHash <- bestBitcoindHashF
bestBitcoinSHash <- bestBitcoinSHashF
} yield bestBitcoinSHash == bestBitcoindHash
},
interval = 1.second,
maxTries = syncTries
)
}
/** Awaits header, filter header and filter sync between the neutrino node and rpc client */
@ -185,8 +192,7 @@ abstract class NodeTestUtil extends P2PLogger {
system: ActorSystem): Future[Unit] = {
import system.dispatcher
for {
bitcoindBestHash <- bitcoind.getBestBlockHash
_ <- NodeTestUtil.awaitBestHash(bitcoindBestHash, node)
_ <- NodeTestUtil.awaitBestHash(node, bitcoind)
_ <- NodeTestUtil.awaitCompactFilterHeadersSync(node, bitcoind)
_ <- NodeTestUtil.awaitCompactFiltersSync(node, bitcoind)
} yield ()