-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WalletSync
issues with RpcBlockchain
and CompactFiltersBlockchain
#677
Comments
evanlinjin
changed the title
Potential
Jul 21, 2022
WalletSync
issues with RpcBlockchain
and CompactFiltersBlockchain
WalletSync
issues with RpcBlockchain
and CompactFiltersBlockchain
6 tasks
afilini
added a commit
that referenced
this issue
Jul 21, 2022
…not cached 5c940c3 Fix wallet sync not finding coins of addresses which are not cached (志宇) Pull request description: Fixes #521 Fixes #451 ^ However, only for electrum-based `Blockchain` implementations. For RPC and Compact Block Filters, syncing works differently, and so are the bugs - I have created a separate ticket for this (#677). ### Description Previously, electrum-based blockchain implementations only synced for `scriptPubKey`s that are already cached in `Database`. This PR introduces a feedback mechanism, that uses `stop_gap` and the difference between "current index" and "last active index" to determine whether we need to cache more `scriptPubKeys`. The `WalletSync::wallet_setup` trait now may return an `Error::MissingCachedScripts` error which contains the number of extra `scriptPubKey`s to cache, in order to satisfy `stop_gap` for the next call. `Wallet::sync` now calls `WalletSync` in a loop, caching in-between subsequent calls (if needed). #### Notes to reviewers 1. The caveat to this solution is that it is not the most efficient. Every call to `WalletSync::wallet_setup` starts polling the Electrum-based server for `scriptPubKey`s starting from index 0. However, I feel like this solution is the least "destructive" to the API of `Blockchain`. Also, once the `bdk_core` sync logic is integration, we can select specific ranges of `scriptPubKey`s to sync. 2. Also note that this PR only fixes the issue for electrum-based `Blockchain` implementations (currently `blockchain::electrum` and `blockchain::esplora` only). 3. Another thing to note is that, although `Database` assumes 1-2 keychains, the current `WalletSync` "feedback" only returns one number (which is interpreted as the larger "missing count" of the two keychains). This is done for simplicity, and because we are planning to only have one keychain per database in the future. https://github.com/bitcoindevkit/bdk/blob/f0c876e7bf38566c0d224cbe421ee312ffc06660/src/blockchain/mod.rs#L157-L161 4. Please have a read of #672 (comment) for additional context. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### Bugfixes: * [x] This pull request breaks the existing API * [x] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: afilini: ACK 5c940c3 Tree-SHA512: aee917ed4821438fc0675241432a7994603a09a77d5a72e96bad863e7cdd55a9bc6fbd931ce096fef1153905cf1b786e1d8d932dc19032d549480bcda7c75d1b
This comment was marked as resolved.
This comment was marked as resolved.
I was wrong. Transactions are fetched later via multiple calls with |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The bug
After looking through the codebase for
RpcBlockchain
, it looks as ifimportdescriptors
would only be called on the first sync, or not at all if there were already more than 100scriptPubKey
s cached before the first sync attempt. In other words, the Bitcoin Core wallet would only be aware of 100scriptPubKey
s or none at all.The
CompactFiltersBlockchain
implementation may have similar issues to the electrum-basedBlockchain
implementations (fixed in #672), where owned outputs can be missed when compiling data from raw transactions (whenscriptPubKey
s are under-cached), and subsequent syncs will not rediscover these missed outputs.Note that these deductions are not tested, but mere assumptions from scanning over the codebase.
Tests to write
I recommend writing the following tests (to confirm the existence of these bugs):
After caching greater-than-100
scriptPubKey
s before doing initialWallet::sync
, we should be able to detect correct balance and owned UTXO set (assuming that all txs interact with ownedscriptPubKey
s with derivation index less-than-100).Given a positive integer that is greater-than-0 (
x
), after doing the initialWallet::sync
, create a self-send transaction, sending fromscriptPubKey
at derivation index 99 to derivation index 99+x
. Cache at-leastx
morescriptPubKey
s and re-sync.Wallet
should have the correct balance and output-set.Additional context
Feel free to look at PR #672 (which fixes #521 and #451 for electrum-based blockchains). However, note that the sync logic differs from RPC and Compact Block Filters, so the fix will be different.
If I have understood the codebase correctly, and these bugs exist, it will be good to have a fix ASAP since these are critical problems.
The text was updated successfully, but these errors were encountered: