Skip to content

Commit d9e6971

Browse files
author
Antoine Riard
committed
Introduce UtxoPool
UtxoPool is an interface to require utxos aiming to use them as bumping input for CPFPs. Implementor must provide an outpoint, its spending witness weight and the available amount. It should be also ready to sign the CPFP. A UTXO may be freed but this call isn't leveraged in the rest of this patchset to prevent mempool rejection on the ground of BIP125.
1 parent e4c8b0b commit d9e6971

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

lightning/src/chain/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
pub mod chaininterface;
1313
pub mod transaction;
1414
pub mod keysinterface;
15+
pub mod utxointerface;

lightning/src/chain/utxointerface.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! Trait which allow others parts of rust-lightning to manage CPFP candidates
2+
//! utxos for increasing feerate of time-sensitive transactions.
3+
4+
5+
use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
6+
use bitcoin::blockdata::transaction::Transaction;
7+
8+
use ln::onchain_utils::BumpingOutput;
9+
10+
/// A trait which sould be implemented to provide fresh CPFP utxo for onchain
11+
/// transactions.
12+
///
13+
/// Implementation MUST provision and bookmarked utxo correctly to ensure LN
14+
/// channel security in case of adversarial counterparty or unfavorable mempool
15+
/// congestion.
16+
//TODO: document better
17+
pub trait UtxoPool: Sync + Send {
18+
/// Allocate a utxo to cover fee required to confirm a pending onchain transaction.
19+
fn allocate_utxo(&self, required_fee: u64) -> Option<(BitcoinOutPoint, BumpingOutput)>;
20+
/// Free a utxo. Call in case of reorg or counterparty claiming the output first.
21+
fn free_utxo(&self, free_utxo: BitcoinOutPoint);
22+
/// Provide a witness for the bumping utxo
23+
fn provide_utxo_witness(&self, cpfp_transaction: &Transaction, utxo_index: u32) -> Result<Vec<Vec<u8>>, ()>;
24+
}

lightning/src/ln/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
pub mod channelmanager;
2222
pub mod channelmonitor;
2323
pub mod msgs;
24+
pub mod onchain_utils;
2425
pub mod peer_handler;
2526
pub mod chan_utils;
2627
pub mod features;
@@ -32,7 +33,6 @@ pub mod peer_channel_encryptor;
3233
pub(crate) mod peer_channel_encryptor;
3334

3435
mod channel;
35-
mod onchain_utils;
3636
mod onion_utils;
3737
mod wire;
3838

lightning/src/ln/onchain_utils.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,40 @@ impl Readable for HolderFundingOutput {
253253
}
254254
}
255255

256+
/// A struct to describe a bumping output with the amount and witness weight. It is used by
257+
/// OnchainTxHandler to build a CPFP transaction to drag a local commitment transaction.
258+
#[derive(Clone, PartialEq)]
259+
pub struct BumpingOutput {
260+
amount: u64,
261+
witness_weight: u64,
262+
}
263+
264+
impl BumpingOutput {
265+
pub(crate) fn new(amount: u64, witness_weight: u64) -> Self {
266+
BumpingOutput {
267+
amount,
268+
witness_weight,
269+
}
270+
}
271+
}
272+
273+
impl Writeable for BumpingOutput {
274+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
275+
self.amount.write(writer)?;
276+
self.witness_weight.write(writer)?;
277+
Ok(())
278+
}
279+
}
280+
281+
impl Readable for BumpingOutput {
282+
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
283+
Ok(BumpingOutput {
284+
amount: Readable::read(reader)?,
285+
witness_weight: Readable::read(reader)?,
286+
})
287+
}
288+
}
289+
256290
/// An enum to describe a claim content which is generated by ChannelMonitor and
257291
/// used by OnchainTxHandler to regenerate feerate-bump transactions to settle claims.
258292
///

0 commit comments

Comments
 (0)