-
Notifications
You must be signed in to change notification settings - Fork 369
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
Never delete spent utxos from the database #515
Never delete spent utxos from the database #515
Conversation
add_utxo
e995a87
to
11cca43
Compare
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.
Initial Concept ACK. The approach looks good to me.
Would like to see a small tests for list_unspent
also. Ensuring its working as expected will ensure all other application like coinselection, get_balance are working fine too.
This might also be a breaking change for DB APIs as LocalUtxo
struct is modified. So would be better to include in the change log too.
11cca43
to
596c264
Compare
Thanks for the review Raj, and sorry it took so long for me to update! I added the rpc code as well, so this PR is now ready :D I agree with you regarding the test on for utxo in wallet.list_unspent().unwrap() {
// Making sure the TXO we just spent is not returned by list_unspent
assert!(utxo.outpoint != initial_tx.input[0].previous_output, "wallet displays spent txo in unspents");
} but let me know if you prefer it to be tested somewhere else as well :) Edit: Uhm, I did forget to update compact filters code 😭 Nevermind, this is still not ready, sorry... |
754889c
to
9a6e04a
Compare
9a6e04a
to
f3317eb
Compare
add_utxo
add_utxo
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.
Hey @danielabrozzoni , sorry it also took me a long time to get back to it..
made a thorough pass.. tACK f3317eb
The code changes looks good to me.. I have also witnessed problem with esplora before.. Not sure this one is us or something upstream.. For now I think its good to go without it..
Below are just few non-blocking nits I have found.. If you happen to touch this again, feel free toi add them..
1a49912
to
d39f4a4
Compare
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.
ReACK d39f4a4
I know I previously said that we should delete UTXOs once confirmed (to avoid bloating the database), but I'm changing my mind: having them would help me with my work on #549, specifically in the code that tries to figure out if we've already performed the "handshake" with a payment code: I could list the transactions received by the notification address corresponding to that payment code, and if I find a transaction that spends our UTXO (here's where I need to have them even if spent) I know we did. |
Avoid deleting utxos would made the code a bit cleaner 😏 I can modify this PR to never delete utxos, and then in future we can think of how to implement some kind of garbage collector.
Do you think we would ever need a |
I think we've been having a ton of troubles lately because we try to over-optimize, so in this case I would go for the full |
Actually when trying to implement it I noticed that the |
7c4a35a
to
227eede
Compare
add_utxo
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.
ACK 227eede
There are conflicts with |
A `is_spent` field is added to LocalUtxo; when a txo is spent we set this field to true instead of deleting the entire utxo from the database. This allows us to create txs double-spending txs already in blockchain. Listunspent won't return spent utxos, effectively excluding them from the coin selection and balance calculation
227eede
to
f2f0efc
Compare
Re-ACK f2f0efc |
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
- `verify` flag removed from `TransactionDetails`. | |||
- Add `get_internal_address` to allow you to get internal addresses just as you get external addresses. | |||
- added `ensure_addresses_cached` to `Wallet` to let offline wallets load and cache addresses in their database | |||
- Add `is_spent` field to `LocalUtxo`; when we notice that a utxo has been spent we set `is_spent` field to true instead of deleting it from the db. |
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.
post-merge comment: This should probably be called LocalTxo
now since they're not necessarily spent unspent.
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 my opinion it's fine to just call it "utxo", I think it's pretty common to refer to outputs in general as utxos. I think what we gain in terms of "naming consistency", we lose with confusion because "txo" doesn't sound as familiar as "utxo" to people (or at least it doesn't to myself 😅)
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.
Calling something "unspent" when it isn't unspent seems like it crossing a line...
I think they're usually called "txout"s rather than txos thought.
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.
Yeah I like LocalTxout
or LocalTxOut
better. "txo", while correct, is a weird term imho, it's not used that much.
Description
A
is_spent
field is added to LocalUtxo; when a txo is spent we setthis field to true instead of deleting the entire utxo from the
database.
This allows us to create txs double-spending txs already in blockchain.
Listunspent won't return spent in mempool utxos, effectively excluding them from the coin selection and balance calculation
Fixes #414
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features:
CHANGELOG.md