Implement call to Node.stop() when shutting down BitcoinSServerMain (#5124)

This commit is contained in:
Chris Stewart 2023-06-29 15:57:46 -05:00 committed by GitHub
parent aff86c7679
commit 5e6caa866f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 10 deletions

View file

@ -1,13 +1,15 @@
package org.bitcoins.server.util
import akka.http.scaladsl.Http
import grizzled.slf4j.Logging
import scala.concurrent.duration.DurationInt
import scala.concurrent.{ExecutionContext, Future}
case class ServerBindings(
httpServer: Http.ServerBinding,
webSocketServerOpt: Option[Http.ServerBinding]) {
webSocketServerOpt: Option[Http.ServerBinding])
extends Logging {
private val terminateTimeout = 5.seconds
@ -22,6 +24,9 @@ case class ServerBindings(
case None =>
Future.unit
}
} yield ()
} yield {
logger.info(s"ServerBindings stopped")
()
}
}
}

View file

@ -31,6 +31,7 @@ import org.bitcoins.dlc.node.config.DLCNodeAppConfig
import org.bitcoins.dlc.wallet._
import org.bitcoins.feeprovider.MempoolSpaceTarget.HourFeeTarget
import org.bitcoins.feeprovider._
import org.bitcoins.node.Node
import org.bitcoins.node.config.NodeAppConfig
import org.bitcoins.node.models.NodeStateDescriptorDAO
import org.bitcoins.rpc.BitcoindException.InWarmUp
@ -130,6 +131,10 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
case None => Future.unit
}
}
_ <- nodeOpt match {
case Some(node) => node.stop()
case None => Future.unit
}
_ <- conf.stop()
_ <- walletLoaderApiOpt match {
case Some(l) => l.stop()
@ -141,11 +146,19 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
}
_ = logger.info(s"Stopped ${nodeConf.nodeType.shortName} node")
} yield {
resetState()
//return empty wallet holder
WalletHolder.empty
}
}
private def resetState(): Unit = {
bitcoindSyncStateOpt = None
nodeOpt = None
walletLoaderApiOpt = None
serverBindingsOpt = None
}
/** Start the bitcoin-s wallet server with a neutrino backend
* @param startedTorConfigF a future that is completed when tor is fully started
* @return
@ -269,6 +282,7 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
_ <- startedTorConfigF
_ <- node.sync()
} yield {
nodeOpt = Some(node)
logger.info(
s"Done starting Main! It took ${System.currentTimeMillis() - start}ms")
()
@ -339,11 +353,13 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
private[this] var bitcoindSyncStateOpt: Option[BitcoindSyncState] = None
private[this] var nodeOpt: Option[Node] = None
/** Start the bitcoin-s wallet server with a bitcoind backend
* @param startedTorConfigF a future that is completed when tor is fully started
* @return
*/
def startBitcoindBackend(
private def startBitcoindBackend(
startedTorConfigF: Future[Unit]): Future[WalletHolder] = {
logger.info(s"startBitcoindBackend()")
val bitcoindF = for {
@ -597,7 +613,7 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
.executeOnTxReceivedCallbacks(tx)
}
val combinedCancellable =
BitcoindPollingCancellabe(blockingPollingCancellable,
BitcoindPollingCancellable(blockingPollingCancellable,
mempoolCancellable)
Future.successful(combinedCancellable)

View file

@ -253,7 +253,10 @@ sealed trait DLCWalletLoaderApi extends Logging with StartStopAsync[Unit] {
_ <- rescanStopF
_ <- walletStopF
_ <- dlcStopF
} yield ()
} yield {
logger.info(s"DLCWalletLoaderApi stopped")
()
}
}
}

View file

@ -1,6 +1,6 @@
package org.bitcoins.server.bitcoind
import org.bitcoins.server.util.BitcoindPollingCancellabe
import org.bitcoins.server.util.{BitcoindPollingCancellable}
import scala.concurrent.Future
@ -9,7 +9,7 @@ import scala.concurrent.Future
*/
case class BitcoindSyncState(
syncF: Future[Unit],
pollingCancellable: BitcoindPollingCancellabe) {
pollingCancellable: BitcoindPollingCancellable) {
/** Stops syncing and polling bitcoind */
def stop(): Future[Unit] = {

View file

@ -3,7 +3,7 @@ package org.bitcoins.server.util
import akka.actor.Cancellable
import grizzled.slf4j.Logging
case class BitcoindPollingCancellabe(
case class BitcoindPollingCancellable(
blockPollingCancellable: Cancellable,
mempoolPollingCancelable: Cancellable)
extends Cancellable
@ -20,7 +20,7 @@ case class BitcoindPollingCancellabe(
object BitcoindPollingCancellabe {
val none: BitcoindPollingCancellabe = BitcoindPollingCancellabe(
val none: BitcoindPollingCancellable = BitcoindPollingCancellable(
Cancellable.alreadyCancelled,
Cancellable.alreadyCancelled)
}