Repository navigation
Add custom sync methods - #1012
Conversation
ceefaac to
2e9dc1a
Compare
2e9dc1a to
831fca7
Compare
ebff0bf to
5d88586
Compare
| if spk_index.get_descriptor(keychain).is_none() { | ||
| return Err(SpkIndexError::KeychainNotFound { keychain }); | ||
| } | ||
| if spk_index.last_revealed_index(keychain).is_none() { |
There was a problem hiding this comment.
Could we only error when the combined selection is empty? Example: externalCount = 5, internalCount = 5 currently fails when external addresses are revealed but no change addresses are.
There was a problem hiding this comment.
And maybe we could cover this with tests where only external addresses are revealed, and vice versa?
There was a problem hiding this comment.
As per comment above I'm removing this method entirely.
| fetchPrevTxouts = true | ||
| ) | ||
|
|
||
| assertEquals(7, counter.inspected, "Only the 5 external and 2 internal scripts should be synced") |
There was a problem hiding this comment.
Could we also assert which scripts were synced because checking only the count would also pass if we accidentally selected the first scripts instead of the last I think
There was a problem hiding this comment.
Yeah good idea. I added a custom SyncScriptInspector that records the scripts as they are being synced by the client, so we can then check.
| BdkSyncRequest::builder() | ||
| .chain_tip(chain_tip) | ||
| .spks_with_indexes(spks) | ||
| .expected_spk_txids(expected_spk_txids) |
There was a problem hiding this comment.
Might want to add a rust test checking that the custom request preserves the wallets chain tip and expected transaction IDs for the selected scripts to possibly would help catch regressions in the metadata needed for eviction tracking? Non-blocking
There was a problem hiding this comment.
This one at the Rust layer (which doesn't use/see regtest) requires building custom transactions and whatnot, and I propose we leave it out. Let me know if you'd rather I add it.
| /// an unrevealed index would be misleading: the wallet's indexer does not track it, so the | ||
| /// outputs of any transaction found there would not be recognized as the wallet's own. |
There was a problem hiding this comment.
Can we keep the “every index must have been revealed” requirement and drop the explanation about outputs not being recognized?
There was a problem hiding this comment.
Done. Thanks
| external_indices: Option<Vec<u32>>, | ||
| internal_indices: Option<Vec<u32>>, |
There was a problem hiding this comment.
non blocking: what do you think about these using plain lists defaulting to empty and the count arguments default to zero, just since None has the same meaning, or is there a better reason we need the optional types?
There was a problem hiding this comment.
Nah I agree with you, let's just use plain lists, and they can be made default empty lists, so that's even simpler to use!
| continue; | ||
| } | ||
| if spk_index.get_descriptor(keychain).is_none() { | ||
| return Err(SpkIndexError::KeychainNotFound { keychain }); |
There was a problem hiding this comment.
Is rejecting the internal keychain intentional for single keychain wallets? Upstream methods like reveal_next_address map Internal to External in that case so this behaves differently is all.
There was a problem hiding this comment.
I removed this helper method from the PR. We can easily add it later, and the first one (start_sync_with_spk_indices) is the one that really counts and provides strong value for users. This is more like syntactic sugar, and I think we need to cut the code surface here.
|
concept looking good, added some comments/questions. in original description we can update |
b16fb8e to
52311fe
Compare
52311fe to
f0d4935
Compare
This PR introduces two new methods:
Wallet::start_sync_with_spk_indices(external_indices, internal_indices)start_sync_with_last_revealed_spks(external_count, internal_count)Note that when using these methods, invalid inputs can be provided, and so the methods actually return a Result (for example if you give an index you haven't revealed yet or if you ask for indices on a keychain the wallet doesn't have). This required a new error that doesn't exist upstream:
SpkIndexError.Why adding methods to the wallet instead of exposing the whole builder?
I looked at exposing
SyncRequest::builder()to the bindings instead because that could potentially be the most flexible option, but it turned out to be super clumsy:chain_tiptakes aCheckPoint, which the bindings do not expose. A request built without a tip produces no chain update, so confirmed transactions cannot be connected to the local chain and show up as unconfirmed. Exposing the CheckPoint is not impossible, but it's a linked list of unknown size so it ends up being a lot more than we probably want, especially that you don't actually need it, you just need to pass it to your builder!expected_spk_txidsis weird to compute. It's a reimplementation of internal bookkeeping that every caller would write, and keep in step with upstream if the definition of "relevant spk" changes. Getting it wrong, or skipping it, fails silently, and a dropped or replaced transaction just stays pending forever. No error, no missing-argument complaint. Also, the wallet already has the answer, so having each app recompute it is wasted effort.Keeping the entry point on
Walletmeans both are always filled in. The cost is that we own two methods upstream doesn't have.Notes on API shape
There is a bit of bikeshedding to be done if you want to around certain choices I made:
None, so you can call a sync for the last 3 addresses on your external keychain like so:But for that you'll get an error (can't construct an empty
SyncRequest)3.
Noneis a bit different than an empty list, and if you try to sync an empty list on an internal keychain but you have a single-keychain wallet you get an error.Documentation
There are no direct upstream equivalent to these methods.
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingchangelog:*labelNew Features: