-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Handle re-orgs #81
Open
dr-orlovsky
wants to merge
7
commits into
master
Choose a base branch
from
fix/80
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Handle re-orgs #81
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
937e728
electrum: handle re-org transactions
dr-orlovsky 248eed3
esplora: handle re-org transactions
dr-orlovsky 2bd637d
chore: fix clippy lints
dr-orlovsky aeea5e9
wallet: add cache prune methods
dr-orlovsky da8c0d7
indexers: add prune argument to update, use default create impl
dr-orlovsky 320eedd
indexers: rename publish into broadcast
dr-orlovsky affaa20
indexers: move pruning to the end of calls
dr-orlovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If a TX disappeared from both the chain and the mempool I don't see why we should keep it in the cache. Am I missing something?
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.
Two reasons:
First, someone may re-publish it later. And second, in
data
it may have associated info, like tx or output description, payment purpose etc. If we remove it here, these data will be orphaned.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.
In that case a call to sync will find it, therefore keeping it or dropping it in/from the cache is unrelated to the fact that someone may re-publish it later.
This is an implementation matter, handling a bitcoin reorg where a TX completely disappears should cleanup its associated data. At that point there would be no orphaned data.
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.
They can always be removed later through a specific cleaning procedure.
I assume we both agree that this is an opinion-based API, and my opinion is to keep them in indexers and remove elsewhere.
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.
BTW this may be also very useful in debugging.
Anyway I have added a dedicated cache prune API in a commit on top: aeea5e9
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.
Why do you think it would be useful in debugging? To me it looks like pollution. The cache prune API is not a solution since it deletes all data, both valid and invalid.
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.
Because I need it in a debugging.
Also, this is a very rare case and it won't create any significant amount of pollution in a real-world wallets
Finally, I need my wallet to keep past versions of RBFed transactions for me, and not to remove them until I explicitly ask for ("pruning"). Since the main user of BP wallet library is myself, I will have it this way.
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.
Your solution is still incomplete:
is_unspent
method is not ignoring TXs with aTxStatus::Unknown
status (causing RGB wallets to think the inexistent UTXO is spendable)WalletAddr
balance inWalletCache::addr
is not recalculated to exclude disappeared TXsAlso, in the future there might be more bp-wallet users with necessities different from yours. I propose to change the sync API in a way that it accepts a boolean to specify whether disappeared TXs should be pruned or not during the update. This would be more performant because in highly-used wallets pruning and re-syncing everything from scratch could be very time-expensive.
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.
My argument is that as a creator and maintainer of this library I have a right to decide on opinionated questions (i.e. when there is no clear rational argument and they are a matter of people/users liking or disliking some approaches).
I mean if I need some APIs to be this and this, and somebody needs something else - they can fork or use another library. Since if I merge somebody else opinion and not mine (needing different stuff), I will just fork this library and move somewhere else, which is isomorphic to my original claim and statement ("I will do as I like on the opionated topics in this lib").
At the end of the days this is non-consensus code and library, so it is destined to be opinionated and aligned to specific needs.
I am fine with adding argument to the API call to do update and pruning simultaneously. I will do that alongside fixing two remaining issues you mentioned with balance and
is_unspent
.Just as a note, keeping old transactions adds zero load to the procedure. First, they take no network calls. Second, they are very rare - they are just outdated version of RBFed txes, meaning <10 per normal wallet. Maybe few dozens. So no overload.
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.
No, from what I see, it is not.
Both
is_unspent
andWalletAddr
balance doesn't touchcache.tx
, which contains old transactions, and recomputed from scratch using independent indexer queries. So they DO update.