mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 10:46:42 +01:00
Fix bug where we just need to awaitSyncAndIBD()
rather than attempt to sync()
(#5158)
* Fix bug where we just ned to awaitAllSync() rather than attempt to sync() * Use awaitSyncAndIBD, mv awaitSyncAndIBD to NodeTestUtil * Replace more NodeUnitTest.syncNeutrinoNode() with NodeTestUtil.awaitSyncAndIBD * Replace more NodeUnitTest.syncNeutrinoNode() with NodeTestUtil.awaitSyncAndIBD
This commit is contained in:
parent
1ccc6a9230
commit
2032b16620
4 changed files with 34 additions and 38 deletions
|
@ -10,11 +10,7 @@ import org.bitcoins.node.models.{PeerDAO, PeerDb}
|
||||||
import org.bitcoins.server.BitcoinSAppConfig
|
import org.bitcoins.server.BitcoinSAppConfig
|
||||||
import org.bitcoins.testkit.BitcoinSTestAppConfig
|
import org.bitcoins.testkit.BitcoinSTestAppConfig
|
||||||
import org.bitcoins.testkit.node.fixture.NeutrinoNodeConnectedWithBitcoinds
|
import org.bitcoins.testkit.node.fixture.NeutrinoNodeConnectedWithBitcoinds
|
||||||
import org.bitcoins.testkit.node.{
|
import org.bitcoins.testkit.node.{NodeTestUtil, NodeTestWithCachedBitcoindPair}
|
||||||
NodeTestUtil,
|
|
||||||
NodeTestWithCachedBitcoindPair,
|
|
||||||
NodeUnitTest
|
|
||||||
}
|
|
||||||
import org.bitcoins.testkit.util.{AkkaUtil, TorUtil}
|
import org.bitcoins.testkit.util.{AkkaUtil, TorUtil}
|
||||||
import org.scalatest.{Assertion, FutureOutcome, Outcome}
|
import org.scalatest.{Assertion, FutureOutcome, Outcome}
|
||||||
|
|
||||||
|
@ -69,7 +65,7 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_ <- connAndInit
|
_ <- connAndInit
|
||||||
_ <- NodeUnitTest.syncNeutrinoNode(node, bitcoinds.head)
|
_ <- NodeTestUtil.awaitSyncAndIBD(node, bitcoinds.head)
|
||||||
} yield {
|
} yield {
|
||||||
succeed
|
succeed
|
||||||
}
|
}
|
||||||
|
@ -187,10 +183,10 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
|
||||||
.retryUntilSatisfied(peers.size == 2,
|
.retryUntilSatisfied(peers.size == 2,
|
||||||
interval = 1.second,
|
interval = 1.second,
|
||||||
maxTries = 30)
|
maxTries = 30)
|
||||||
_ <- NodeUnitTest.syncNeutrinoNode(node, bitcoind)
|
|
||||||
_ <- Future
|
_ <- Future
|
||||||
.sequence(peers.map(peerManager.isConnected))
|
.sequence(peers.map(peerManager.isConnected))
|
||||||
.flatMap(p => assert(p.forall(_ == true)))
|
.flatMap(p => assert(p.forall(_ == true)))
|
||||||
|
_ <- NodeTestUtil.awaitSyncAndIBD(node, bitcoind)
|
||||||
res <- Future
|
res <- Future
|
||||||
.sequence(peers.map(peerManager.isConnected))
|
.sequence(peers.map(peerManager.isConnected))
|
||||||
.flatMap(p => assert(p.forall(_ == true)))
|
.flatMap(p => assert(p.forall(_ == true)))
|
||||||
|
@ -221,7 +217,7 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
|
||||||
//itself out of IBD. bitcoind will not sendheaders
|
//itself out of IBD. bitcoind will not sendheaders
|
||||||
//when it believes itself, or it's peer is in IBD
|
//when it believes itself, or it's peer is in IBD
|
||||||
val gen1F = for {
|
val gen1F = for {
|
||||||
_ <- NodeUnitTest.syncNeutrinoNode(node, bitcoind)
|
_ <- NodeTestUtil.awaitSyncAndIBD(node, bitcoind)
|
||||||
x <- bitcoind.generate(1)
|
x <- bitcoind.generate(1)
|
||||||
} yield x
|
} yield x
|
||||||
|
|
||||||
|
@ -269,7 +265,7 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
|
||||||
val bitcoind = nodeConnectedWithBitcoind.bitcoinds(0)
|
val bitcoind = nodeConnectedWithBitcoind.bitcoinds(0)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_ <- NodeUnitTest.syncNeutrinoNode(node, bitcoind)
|
_ <- NodeTestUtil.awaitSyncAndIBD(node, bitcoind)
|
||||||
_ <- AkkaUtil.nonBlockingSleep(3.seconds)
|
_ <- AkkaUtil.nonBlockingSleep(3.seconds)
|
||||||
//have to generate the block headers independent of one another
|
//have to generate the block headers independent of one another
|
||||||
//rather than just calling generateToAddress(2,junkAddress)
|
//rather than just calling generateToAddress(2,junkAddress)
|
||||||
|
@ -291,7 +287,7 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
|
||||||
val bitcoind = nodeConnectedWithBitcoind.bitcoinds(0)
|
val bitcoind = nodeConnectedWithBitcoind.bitcoinds(0)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_ <- NodeUnitTest.syncNeutrinoNode(node, bitcoind)
|
_ <- NodeTestUtil.awaitSyncAndIBD(node, bitcoind)
|
||||||
_ <- node.stop()
|
_ <- node.stop()
|
||||||
//drop all compact filter headers / filters
|
//drop all compact filter headers / filters
|
||||||
_ <- CompactFilterHeaderDAO()(executionContext, node.chainConfig)
|
_ <- CompactFilterHeaderDAO()(executionContext, node.chainConfig)
|
||||||
|
|
|
@ -958,8 +958,8 @@ case class PeerManager(
|
||||||
val chainApi: ChainApi = ChainHandler.fromDatabase()
|
val chainApi: ChainApi = ChainHandler.fromDatabase()
|
||||||
val headerF = chainApi.getBestBlockHeader()
|
val headerF = chainApi.getBestBlockHeader()
|
||||||
for {
|
for {
|
||||||
_ <- getHeaderSyncHelper(syncPeerOpt)
|
|
||||||
_ <- chainApi.setSyncing(true)
|
_ <- chainApi.setSyncing(true)
|
||||||
|
_ <- getHeaderSyncHelper(syncPeerOpt)
|
||||||
cancellable = createFilterSyncJob(chainApi, syncPeerOpt)
|
cancellable = createFilterSyncJob(chainApi, syncPeerOpt)
|
||||||
_ = {
|
_ = {
|
||||||
syncFilterCancellableOpt = Some(cancellable)
|
syncFilterCancellableOpt = Some(cancellable)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.bitcoins.testkit.node
|
package org.bitcoins.testkit.node
|
||||||
|
|
||||||
import akka.actor.ActorSystem
|
import akka.actor.ActorSystem
|
||||||
|
import org.bitcoins.asyncutil.AsyncUtil
|
||||||
import org.bitcoins.core.api.node.Peer
|
import org.bitcoins.core.api.node.Peer
|
||||||
import org.bitcoins.core.api.tor.Socks5ProxyParams
|
import org.bitcoins.core.api.tor.Socks5ProxyParams
|
||||||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||||
|
@ -178,6 +179,31 @@ abstract class NodeTestUtil extends P2PLogger {
|
||||||
} yield ()
|
} yield ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def awaitSyncAndIBD(node: NeutrinoNode, bitcoind: BitcoindRpcClient)(implicit
|
||||||
|
system: ActorSystem): Future[Unit] = {
|
||||||
|
import system.dispatcher
|
||||||
|
|
||||||
|
for {
|
||||||
|
_ <- NodeTestUtil.awaitSync(node, bitcoind)
|
||||||
|
_ <- AsyncUtil.retryUntilSatisfiedF(
|
||||||
|
() => {
|
||||||
|
val chainApi = node.chainApiFromDb()
|
||||||
|
val syncingF = chainApi.flatMap(_.isSyncing())
|
||||||
|
val isIBDF = chainApi.flatMap(_.isIBD())
|
||||||
|
for {
|
||||||
|
syncing <- syncingF
|
||||||
|
isIBD <- isIBDF
|
||||||
|
} yield {
|
||||||
|
!syncing && !isIBD
|
||||||
|
}
|
||||||
|
},
|
||||||
|
interval = 1.second,
|
||||||
|
maxTries = 5
|
||||||
|
)
|
||||||
|
} yield ()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** get our neutrino node's uri from a test bitcoind instance to send rpc commands for our node.
|
/** get our neutrino node's uri from a test bitcoind instance to send rpc commands for our node.
|
||||||
* The peer must be initialized by the node.
|
* The peer must be initialized by the node.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.scalatest.FutureOutcome
|
||||||
|
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import scala.concurrent.duration.DurationInt
|
|
||||||
import scala.concurrent.{ExecutionContext, Future}
|
import scala.concurrent.{ExecutionContext, Future}
|
||||||
|
|
||||||
trait NodeUnitTest extends BaseNodeTest {
|
trait NodeUnitTest extends BaseNodeTest {
|
||||||
|
@ -470,7 +469,7 @@ object NodeUnitTest extends P2PLogger {
|
||||||
//do nothing as we are already syncing
|
//do nothing as we are already syncing
|
||||||
logger.info(
|
logger.info(
|
||||||
s"Node is already syncing, skipping initiating a new sync.")
|
s"Node is already syncing, skipping initiating a new sync.")
|
||||||
awaitSyncAndIBD(node, bitcoind).map(_ => node)
|
NodeTestUtil.awaitSyncAndIBD(node, bitcoind).map(_ => node)
|
||||||
} else {
|
} else {
|
||||||
neutrinoNodeSyncHelper(node, bitcoind)
|
neutrinoNodeSyncHelper(node, bitcoind)
|
||||||
}
|
}
|
||||||
|
@ -494,31 +493,6 @@ object NodeUnitTest extends P2PLogger {
|
||||||
} yield node
|
} yield node
|
||||||
}
|
}
|
||||||
|
|
||||||
private def awaitSyncAndIBD(node: NeutrinoNode, bitcoind: BitcoindRpcClient)(
|
|
||||||
implicit system: ActorSystem): Future[Unit] = {
|
|
||||||
import system.dispatcher
|
|
||||||
|
|
||||||
for {
|
|
||||||
_ <- NodeTestUtil.awaitSync(node, bitcoind)
|
|
||||||
_ <- AsyncUtil.retryUntilSatisfiedF(
|
|
||||||
() => {
|
|
||||||
val chainApi = node.chainApiFromDb()
|
|
||||||
val syncingF = chainApi.flatMap(_.isSyncing())
|
|
||||||
val isIBDF = chainApi.flatMap(_.isIBD())
|
|
||||||
for {
|
|
||||||
syncing <- syncingF
|
|
||||||
isIBD <- isIBDF
|
|
||||||
} yield {
|
|
||||||
!syncing && !isIBD
|
|
||||||
}
|
|
||||||
},
|
|
||||||
interval = 1.second,
|
|
||||||
maxTries = 5
|
|
||||||
)
|
|
||||||
} yield ()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This is needed for postgres, we do not drop tables in between individual tests with postgres
|
/** This is needed for postgres, we do not drop tables in between individual tests with postgres
|
||||||
* rather an entire test suite shares the same postgres database.
|
* rather an entire test suite shares the same postgres database.
|
||||||
* therefore, we need to clean the database after each test, so that migrations can be applied during
|
* therefore, we need to clean the database after each test, so that migrations can be applied during
|
||||||
|
|
Loading…
Add table
Reference in a new issue