mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 10:46:42 +01:00
Refactor waiting for bitcoind lost blocks into helper method, add context (#4602)
This commit is contained in:
parent
9fd9cf1ee4
commit
b0831f26a7
1 changed files with 23 additions and 13 deletions
|
@ -24,7 +24,7 @@ import org.bitcoins.core.api.node.{
|
|||
NodeApi,
|
||||
NodeType
|
||||
}
|
||||
import org.bitcoins.core.api.wallet.NeutrinoHDWalletApi
|
||||
import org.bitcoins.core.api.wallet.{NeutrinoHDWalletApi, WalletApi}
|
||||
import org.bitcoins.core.util.TimeUtil
|
||||
import org.bitcoins.dlc.node.DLCNode
|
||||
import org.bitcoins.dlc.node.config.DLCNodeAppConfig
|
||||
|
@ -540,18 +540,7 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
|
|||
wallet: NeutrinoHDWalletApi,
|
||||
chainCallbacksOpt: Option[ChainCallbacks]): Future[BitcoindSyncState] = {
|
||||
val f = for {
|
||||
_ <- AsyncUtil.retryUntilSatisfiedF(
|
||||
conditionF = { () =>
|
||||
for {
|
||||
bitcoindHeight <- bitcoind.getBlockCount
|
||||
walletStateOpt <- wallet.getSyncDescriptorOpt()
|
||||
} yield walletStateOpt.forall(bitcoindHeight >= _.height)
|
||||
},
|
||||
// retry for approximately 2 hours
|
||||
mode = Exponential,
|
||||
interval = 1.second,
|
||||
maxTries = 12
|
||||
)
|
||||
_ <- handlePotentialBitcoindLostBlock(bitcoind, wallet)
|
||||
syncF = BitcoindRpcBackendUtil.syncWalletToBitcoind(
|
||||
bitcoind,
|
||||
wallet,
|
||||
|
@ -590,6 +579,27 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
|
|||
f
|
||||
}
|
||||
|
||||
/** Surprisingly on some OSes like umbrel bitcoind can lose blocks during the shutdown process
|
||||
* This means next time we boot up, our wallet will have more blocks than bitcoind!
|
||||
* Eventually bitcoind will synchrnoize with the network. This waits until bitcoind is synced
|
||||
*/
|
||||
private def handlePotentialBitcoindLostBlock(
|
||||
bitcoind: BitcoindRpcClient,
|
||||
wallet: WalletApi): Future[Unit] = {
|
||||
AsyncUtil.retryUntilSatisfiedF(
|
||||
conditionF = { () =>
|
||||
for {
|
||||
bitcoindHeight <- bitcoind.getBlockCount
|
||||
walletStateOpt <- wallet.getSyncDescriptorOpt()
|
||||
} yield walletStateOpt.forall(bitcoindHeight >= _.height)
|
||||
},
|
||||
// retry for approximately 2 hours
|
||||
mode = Exponential,
|
||||
interval = 1.second,
|
||||
maxTries = 12
|
||||
)
|
||||
}
|
||||
|
||||
/** Builds a websocket queue that you can feed elements to.
|
||||
* The Source can be wired up with Directives.handleWebSocketMessages
|
||||
* to create a flow that emits websocket messages
|
||||
|
|
Loading…
Add table
Reference in a new issue