refactor: Improve bitcoind wallet polling logic (#5834)

This commit is contained in:
Chris Stewart 2025-01-03 15:46:48 -06:00 committed by GitHub
parent dee3a1cdee
commit 788b99c184
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 7 deletions

View file

@ -501,7 +501,7 @@ object BitcoindRpcBackendUtil extends BitcoinSLogger {
import system.dispatcher
val atomicPrevCount = new AtomicInteger(prevCount)
val queueSource: Source[Int, SourceQueueWithComplete[Int]] =
Source.queue[Int](100, OverflowStrategy.backpressure)
Source.queue[Int](16, OverflowStrategy.backpressure)
val numParallelism = FutureUtil.getParallelism
val fetchBlocksFlow =

View file

@ -4,21 +4,22 @@ import org.bitcoins.server.util.{BitcoindPollingCancellable}
import scala.concurrent.Future
/** @param syncF
* the future that will be completed when the synchronization with bitcoind
* is complete
/** @param initSyncF
* the future that will be completed when the initial synchronization with
* bitcoind is complete. This Future isn't related to subsequent polling jobs
* after our initial sync between bitcoind and the wallet on startup
* @param pollingCancellable
* You can cancel bitcoind polling by calling
* [[BitcoindPollingCancellabe.cancel()]]
*/
case class BitcoindSyncState(
syncF: Future[Unit],
initSyncF: Future[Unit],
pollingCancellable: BitcoindPollingCancellable
) {
/** Stops syncing and polling bitcoind */
def stop(): Future[Unit] = {
pollingCancellable.cancel()
syncF
initSyncF
}
}

View file

@ -15,7 +15,7 @@ case class BitcoindPollingCancellable(
}
override def isCancelled: Boolean =
blockPollingCancellable.isCancelled && mempoolPollingCancelable.cancel()
blockPollingCancellable.isCancelled && mempoolPollingCancelable.isCancelled
}
object BitcoindPollingCancellabe {