-
Notifications
You must be signed in to change notification settings - Fork 330
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
Applied unconfirmed transactions need to be pruned after some time #1666
Comments
To get the result you want, I think you could have a parameter to canonical txs/UTXOs/balance listing which asks it to ignore the effect of transactions that have a Any valid transaction that is broadcast could reappear at any time. If the app no longer wants the transaction to exist then they should probably double spend it explicitly or otherwise rebroadcast. I think it's undesirable to "prune" this transaction from any data structure. There's no need to forget about it to get the right answer for any query you want to make about the data. If the user has not explicitly asked for a tx to be canceled it should be fine to spend its utxos if we also broadcast the tx before broadcasting the child. Maybe in the future the transaction creation pipeline can just give you a "package" of transactions that should be broadcast which contains parents that may have dropped from the mempool. |
Yes, at which point it would simply get synced again / applied again after having been pruned.
I disagree. The expected flow here is that the user simply creates, signs, and broadcasts transactions. If these then appear in the mempool and are applied via As a lot of these behaviors depend on internals and BDK has the best insight into what's going on, it's really the concern of the on-chain wallet and hence BDK needs to handle this by default in a sane and safe way that wouldn't lead to more and more funds becoming unspendable over time. FWIW, on the call yesterday there even seems to be confusion around whether any API exists that would allow the user to create a conflicting transaction even if they explicitly specified the UTXOs (which users should never be required to do if they simply want to send some funds and leave everything else to BDK's coin selection algorithms, IMO). |
Closing this for now as it may in part get completed by UTXO locking (i.e. is already tracked by #849) |
Even though the issue is closed I wanted to better understand what you are disagreeing with. The user has to decide the fate of their transactions. And I claim each unconfirmed tx is either in a state of:
We have to consider the state when creating a new tx: in (1,2) we want to treat the tx as canonical regardless of whether it has been seen in the mempool recently or not and therefore it's UTXOs can be candidate inputs. In (2), if it hasn't been seen for a while this will mean we want the user to broadcast it again along with the new child tx. I don't think there is a fifth state we have to model where the user is thinking "I broadcasted this tx but you know I don't really care if it gets confirmed. If it hasn't been seen for a while I kinda want to prune it so I might inadvertently double spend it with my next tx...or I might not..whatever". There are several ways in which these three tx states are not modeled correctly in BDK so there definitely is a design bug but it seems we are not in agreement to the nature of it. I think states (2) and (4) are easy to express, YMWV with (3) and (1) doesn't exist. |
I think I generally agree with you analysis. However, I still think BDK could do a better job API-wise to smooth out the 'default' user experience. In contrast to Core's UX, the BDK wallet doesn't necessarily presuppose to be operated by a human, i.e., be it in a mobile app or on a server, BDK can't really design the API around the assumption that there always is an operator that will monitor the wallet state and take action in particular circumstances. In this case, I'd argue that BDK should try to find an API/UX that by default allows 'naive' users that only make simple transactions "to do the right thing" by default. For example, BDK should auto-lock UTXOs it creates transactions to disallow double-spending itself when creating transactions without doing a syncing step in-between. However, there might be circumstances where we're positive that we failed to broadcast such a transaction, in which case it might make sense to allow explictly unlocking it again. Apart from that, BDK could offer logic to track, rebroadcast, and RBF-until-confirmed previously created transactions. In general, as a user I expect all tracking and handling of transactions required for the simplest default use cases to happen in BDK / Btw. note that when I opened this issue there was generally a lot of confusion as we had just discussed this in the BDK call and none of the attendees could clarify the currently implemented behavior, e.g., whether the state of unconfirmed transactions is persisted across restarts, how |
Describe the bug
In the last BDK Lib call we discussed that likely
Wallet::apply_unconfirmed_txs
won't ever forget the applied transactions. This is a bug as there is no guarantee that transactions might not eventually be dropped from the mempool, which would leave the wallet with unspendable UTXOs/funds, at least until the wallet is restarted and the state is lost.Expected behavior
We need a way (read:
prune_applied_transactions
API or similar) to prune the applied transactions, preferable after a configurable threshold after the last seen, or after some number of blocks. Incidentally this would likely also resolve #849, as locking UTXOs prior to broadcast and locking UTXOs based on the ephemeral mempool state is more or less the same thing.Additional context
We also discussed in the call that the difference between
apply_unconfirmed_txs
andinsert_tx
is unclear, as @stevenroose previously wondered in #1642 (comment)The text was updated successfully, but these errors were encountered: