-
Notifications
You must be signed in to change notification settings - Fork 326
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
Make RpcBlockchain
import more efficient
#740
Conversation
aed0c9c
to
4dce1e6
Compare
`RpcImportParams` keeps track of the scriptPubKey derivation index to start from for the next call to `importdescripts`/`importmulti`, thus avoiding re-importing into Bitcoin Core.
4dce1e6
to
5319816
Compare
The idea of paging makes good sense, but is there a reason to not save the next derivation index in the existing wallet DB as we do with other sync related data? |
Thanks for the comment @notmandatory . The "next derivation index" in this context means the index after the last imported into Bitcoin Core. Ideally, we should be able to obtain this information easily from Bitcoin Core itself, but the RPC interface does not allow it. This is different to how "next derivation index" should be interpreted in The ideal would be to have the two "next derivation index" concepts in sync. This would be possible if "user-get-new-address" and "import-new-address-into-bitcoin-core" could be performed atomically. Another solution would be to mark "imported-into-bitcoin-core" addresses in the So in essence, I did this hack because: restrictive RPC interface in Core + restrictive "bounds" of the current BDK "model". |
@@ -66,6 +68,8 @@ pub struct RpcBlockchain { | |||
capabilities: HashSet<Capability>, | |||
/// Sync parameters. | |||
sync_params: RpcSyncParams, | |||
/// Import parameters. | |||
import_params: RefCell<RpcImportParams>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be safe I would replace this with an Arc<RpcImportParams>
. Then you can use Arc::make_mut()
whenever you want to replace it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work as the WalletSync
is NOT &mut self
. We can do Arc<Mutex<RpcImportParams>>
? But I think this is too much. I feel like the user can just handle thread-safety elsewhere?
I think #372 would fix the same issue this PR tries to tackle, because it would allow us to save in the database which addresses have already been imported. It's been blocked all this time because we haven't figured out a good way to do database migrations, but maybe it's time we get back to it. Also, a suggestion: maybe you don't remember, but the old rpc implementation used the label of a fixed address as a "storage section" to save essentially the |
I'm putting this on the list to discuss tomorrow, but since it looks like it requires more discussion will probably have to remove it from the 0.23.0 feature freeze. |
* Add `RpcSyncParams::page_size` that restricts req/resp array count for various RPC calls. * Add `pagenated_import` function.
ff398ec
to
83edbf0
Compare
@afilini I am currently unconvinced that the previous model is a good idea. It will cause problems if a different Even with what I have in the PR, and if the user does not persist
It does sound like this would fix the issue, but I think #372 would be more elegant with "birthdays" of scriptPubKeys. So database will store birthdays of scriptPubKeys and "last-sync" for each different "blockchain". This way we can compare which scriptPubKeys we need to import, without having to do a map of which scriptPubKey has been synced to which "blockchains". |
BDK Chain will replace the need for this |
Fixes #715
Description
Introduces
RpcImportParams
that keeps track of next derivation index to start import from for next sync. This avoids re-importing scripts/descriptors into Bitcoin Core for every sync cycle. However, the user will be responsible for persisting theRpcImportParams
structure; theRpcBlockchain::get_import_parameters
andRpcBlockchain::replace_import_parameters
functions can be used for this purpose.Also add pagination for importing scripts/descriptors.
Also had to make
clippy
happy by derivingEq
for various structures.Notes to the reviewers
Refer to: #715 (comment)
Changelog notice
RpcImportParams
to make sync more efficientRpcSyncParams::page_size
to restrict request/response array size of RPC callsChecklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features:
Bugfixes:
* [ ] This pull request breaks the existing API* [ ] I've added tests to reproduce the issue which are now passing(This is a performance bug fix)