-
Notifications
You must be signed in to change notification settings - Fork 311
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
Let TxBuilder
avoid previously used UTXOs (UTXO locking)
#849
Comments
We had some offline discussions about how to approach this issue, recapping here: Step 1: create example of how to do it outside of bdk such as by manually keeping a set of used but not broadcast utxos, and then feeding that set to the TxBuilder to exclude the UTXOs when creating new transactions. Step 2: based on experience with 1, create API changes for the Wallet (or TxBuilder?) that will make it possible to automatically manage the set of used but not broadcast UTXOs. |
I think we want to support this in Line 1385 in 7e8f849
The idea is when a tx is cancelled in the future we can mark those utxos as no longer used and return them to the "utxo" pool. See also the necessary feature in There are other cases where you want to reserve utxos that will have to be done via a different method (manual marking) which we can also provide. |
Currently, the proposed solution to this is (for BDK 1.0):
However, as we are replacing the |
It's a little bit harder to say that |
See #913 |
Proposal for UTXO locking featureapproach: to be implemented in the wallet module
pub struct Wallet {
// map of outpoint to expiration height
utxo_locks: HashMap<OutPoint, Option<Height>>,
...
}
/// Populates the the coins map. By default all utxos are unlocked.
pub fn reload_coins(&mut self) {
// for utxo in self.unspent()
// self.utxo_locks.insert(outpoint, None)
}
/// Locks the UTXO at `outpoint` for `n` number of blocks.
pub fn lock_utxo(&mut self, outpoint: OutPoint, n: blocks) { ... }
fn get_available_utxos(&self) -> Vec<(LocalOutput, Weight)> {
self.list_unspent()
.filter(|utxo| !self.is_utxo_locked(utxo.outpoint, self.latest_checkpoint().height()))
.map(|utxo| { ... } )
.collect()
} |
This should be a |
since this is a new feature and shouldn't break existing API I'm assigning it to the 1.1 milestone. |
I want to note that it might be preferable to have the locking status persisted across restarts. Otherwise the user will need to keep track of the locked outpoints on top of |
If the API in #1669 is acceptable then I think we should add this functionality at the Wallet layer and plumb it through to the chain layer only if/when needed. |
Describe the enhancement
When sequentially creating multiple transactions,
TxBuilder
might currently reuse the same UTXOs, potentially exposing us to double-spend ourselves if we want to bring all of these generated transactions on-chain. It would be nice if theTxBuilder
could track the used UTXOs internally, and allow to auto-unlock them after a set amount of time.Use case
This is important for sequentially opening multiple Lightning channels, e.g., in LDK Node.
The text was updated successfully, but these errors were encountered: