Refactor to not throw an exception is node is already syncing (#4970)

* Refactor to not throw an exception is node is already syncing

* Refactor method name
This commit is contained in:
Chris Stewart 2023-02-03 12:57:19 -06:00 committed by GitHub
parent 3bc89c680f
commit 76fc3cdc41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -513,9 +513,25 @@ object NodeUnitTest extends P2PLogger {
import system.dispatcher
for {
syncing <- node.chainApiFromDb().flatMap(_.isSyncing())
_ = require(
!syncing,
s"Cannot start syncing neutrino node when previous sync is ongoing")
newNode <- {
if (syncing) {
//do nothing as we are already syncing
logger.info(
s"Node is already syncing, skipping initiating a new sync.")
Future.successful(node)
} else {
neutrinoNodeSyncHelper(node, bitcoind)
}
}
} yield newNode
}
private def neutrinoNodeSyncHelper(
node: NeutrinoNode,
bitcoind: BitcoindRpcClient)(implicit
system: ActorSystem): Future[NeutrinoNode] = {
import system.dispatcher
for {
_ <- node.sync()
syncing <- node.chainApiFromDb().flatMap(_.isSyncing())
_ = require(syncing)