From 76fc3cdc41ca3978eea6d9edf41d1c3faae5152e Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Fri, 3 Feb 2023 12:57:19 -0600 Subject: [PATCH] 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 --- .../bitcoins/testkit/node/NodeUnitTest.scala | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/testkit/src/main/scala/org/bitcoins/testkit/node/NodeUnitTest.scala b/testkit/src/main/scala/org/bitcoins/testkit/node/NodeUnitTest.scala index b86d69afcc..f915fcc14f 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/node/NodeUnitTest.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/node/NodeUnitTest.scala @@ -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)