LtbLightning / bdk-rn

Bitcoin Development Kit - React Native Module
MIT License
50 stars 15 forks source link

`wallet.sync()` is scanning 200 addresses #44

Open Czino opened 1 year ago

Czino commented 1 year ago

When syncing, even after after creating a fresh wallet with a stopGap setting of 5, I am logging 200 requests on my electrum server.

Changing the stopGap does not have any influence on these 200 requests. I even set it to 500 but still only see 200 requests.

I cannot find any setting to change the number of initial addresses to be scanned but I would expect it to be much lower (10/25/50)

Tested with BlockchainEsploraConfig and BlockchainElectrumConfig Tested on Android and iOS

Czino commented 1 year ago

So far debugging and finding that stopGap and timeout and mixed up for Esplora

in src/classes/Blockchain.ts:31 stopGap is the 5th argument this.id = await this._bdk.initEsploraBlockchain(url, proxy, concurrency, timeout, stopGap);

android/src/main/java/io/ltbl/bdkrn/BdkRnModule.kt:232 expecting stopGap to be the 4th argument

@ReactMethod
    fun initEsploraBlockchain(
        url: String,
        proxy: String?,
        concurrency: String?,
        stopGap: String?,
        timeOut: String?,
        result: Promise
    )

ios/BdkRnModule.swift:287 expecting stopGap to be the 4th argument

@objc
    func initEsploraBlockchain(_
        url: String,
        proxy: String?,
        concurrency: String?,
        stopGap: String?,
        timeOut: String?,
        resolve: @escaping RCTPromiseResolveBlock,
        reject: @escaping RCTPromiseRejectBlock
    )
Czino commented 1 year ago

After fixing it with https://github.com/LtbLightning/bdk-rn/pull/46, I inspected the stopGap in android and now I receive the same value I passed.

However, bdk-rn is still scanning 200 addresses.

BitcoinZavior commented 1 year ago

Thanks, @Czino will debug and see what could be wrong.

BitcoinZavior commented 1 year ago

@Czino you might also want to check the value for concurrency: String? https://docs.rs/bdk/latest/bdk/blockchain/esplora/struct.EsploraBlockchainConfig.html

Czino commented 1 year ago

@BitcoinZavior yes, I am already using concurrency to speed things up a little

Czino commented 1 year ago

debugging this issue a little, even after forcing stopGap to be 1, still 200 addresses are being scanned

 let _blockchainConfig = BlockchainConfig.esplora(
    config: EsploraConfig(
        baseUrl: baseUrl,
        proxy: proxy.isEmpty ? nil : proxy,
        concurrency: UInt8(truncating: concurrency),
        stopGap: 1,
        timeout: UInt64(truncating: timeout)
    )
)

Looks to me like we need to escalate the issue to bdk-ffi