Remove WalletSync.sync() -> WalletSync.syncFullBlocks() (#2522)

This commit is contained in:
Chris Stewart 2021-01-15 17:05:11 -06:00 committed by GitHub
parent a1a2524b56
commit f3e81d027d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 14 deletions

View file

@ -168,13 +168,16 @@ abstract class SyncUtil extends BitcoinSLogger {
node.NodeChainQueryApi(nodeApi, chainQuery)
}
def syncWallet(wallet: Wallet, bitcoind: BitcoindRpcClient)(implicit
/** Syncs a wallet against bitcoind by retrieving full blocks and then calling
* [[Wallet.processBlock()]]
*/
def syncWalletFullBlocks(wallet: Wallet, bitcoind: BitcoindRpcClient)(implicit
ec: ExecutionContext): Future[Wallet] = {
WalletSync.sync(
WalletSync.syncFullBlocks(
wallet = wallet,
getBlockHeaderFunc = SyncUtil.getBlockHeaderFunc(bitcoind),
getBestBlockHashFunc = SyncUtil.getBestBlockHashFunc(bitcoind),
getBlock = SyncUtil.getBlockFunc(bitcoind)
getBlockFunc = SyncUtil.getBlockFunc(bitcoind)
)
}
}

View file

@ -274,8 +274,8 @@ trait BitcoinSWalletTest extends BitcoinSFixture with EmbeddedPg {
bitcoind = bitcoind,
bip39PasswordOpt = bip39PasswordOpt)
fundedWallet <- fundWalletWithBitcoind(walletWithBitcoind)
_ <-
SyncUtil.syncWallet(wallet = fundedWallet.wallet, bitcoind = bitcoind)
_ <- SyncUtil.syncWalletFullBlocks(wallet = fundedWallet.wallet,
bitcoind = bitcoind)
_ <- BitcoinSWalletTest.awaitWalletBalances(fundedWallet)
} yield fundedWallet
}
@ -294,8 +294,8 @@ trait BitcoinSWalletTest extends BitcoinSFixture with EmbeddedPg {
.map(_.asInstanceOf[BitcoindV19RpcClient])
wallet <- createWalletWithBitcoindCallbacks(bitcoind, bip39PasswordOpt)
fundedWallet <- fundWalletWithBitcoind(wallet)
_ <-
SyncUtil.syncWallet(wallet = fundedWallet.wallet, bitcoind = bitcoind)
_ <- SyncUtil.syncWalletFullBlocks(wallet = fundedWallet.wallet,
bitcoind = bitcoind)
_ <- BitcoinSWalletTest.awaitWalletBalances(fundedWallet)
} yield {
WalletWithBitcoindV19(fundedWallet.wallet, bitcoind)

View file

@ -22,10 +22,10 @@ class WalletSyncTest extends BitcoinSWalletTest {
val getBlockHeaderFunc = SyncUtil.getBlockHeaderFunc(bitcoind)
val getBlockFunc = SyncUtil.getBlockFunc(bitcoind)
val syncedWalletF = WalletSync.sync(wallet,
getBlockHeaderFunc,
getBestBlockHashFunc,
getBlockFunc)
val syncedWalletF = WalletSync.syncFullBlocks(wallet,
getBlockHeaderFunc,
getBestBlockHashFunc,
getBlockFunc)
val bitcoindBestHeaderF = bitcoind.getBestBlockHeader()
for {

View file

@ -9,11 +9,17 @@ import scala.concurrent.{ExecutionContext, Future}
trait WalletSync extends BitcoinSLogger {
def sync(
/** Synchronizes the bitcoin-s' wallet by retrieving each block and then calling
* [[Wallet.processBlock()]] on the block retrieved
*
* WARNING: This should not be used on resource constrained devices
* as fetching full blocks will use a lot of bandwidth on live networks
*/
def syncFullBlocks(
wallet: Wallet,
getBlockHeaderFunc: DoubleSha256DigestBE => Future[BlockHeader],
getBestBlockHashFunc: () => Future[DoubleSha256DigestBE],
getBlock: DoubleSha256DigestBE => Future[Block])(implicit
getBlockFunc: DoubleSha256DigestBE => Future[Block])(implicit
ec: ExecutionContext): Future[Wallet] = {
val bestBlockHashF = getBestBlockHashFunc()
val bestBlockHeaderF = for {
@ -26,7 +32,7 @@ trait WalletSync extends BitcoinSLogger {
blocksToSync <- getBlocksToSync(wallet = wallet,
currentTipBlockHashBE = bestHeader.hashBE,
accum = Vector.empty,
getBlock = getBlock)
getBlock = getBlockFunc)
} yield blocksToSync
val syncedWalletF = for {