Skip to content

Commit b5a1835

Browse files
committed
Move FundingTxInput::sequence to Utxo
A forthcoming commit will change CoinSelection to include FundingTxInput instead of Utxo, though the former will probably be renamed. This is so CoinSelectionSource can be used when funding a splice. Further updating WalletSource to use FundingTxInput is not desirable, however, as it would result in looking up each confirmed UTXOs previous transaction even if it is not selected. See Wallet's implementation of CoinSelectionSource, which delegates to WalletSource for listing all confirmed UTXOs. This commit moves FundingTxInput::sequence to Utxo, and thus the responsibility for setting it to WalletSource implementations. Doing so will allow Wallet's CoinSelectionSource implementation to delegate looking up previous transactions to WalletSource without having to explicitly set the sequence on any FundingTxInput.
1 parent f3eb94e commit b5a1835

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

lightning/src/events/bump_transaction/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,15 @@ pub struct Utxo {
282282
/// with their lengths included, required to satisfy the output's script. The weight consumed by
283283
/// the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`].
284284
pub satisfaction_weight: u64,
285+
/// The sequence number to use in the [`TxIn`] when spending the UTXO.
286+
pub sequence: Sequence,
285287
}
286288

287289
impl_writeable_tlv_based!(Utxo, {
288290
(1, outpoint, required),
289291
(3, output, required),
290292
(5, satisfaction_weight, required),
293+
(7, sequence, (default_value, Sequence::ENABLE_RBF_NO_LOCKTIME)),
291294
});
292295

293296
impl Utxo {
@@ -302,6 +305,7 @@ impl Utxo {
302305
outpoint,
303306
output: TxOut { value, script_pubkey: ScriptBuf::new_p2pkh(pubkey_hash) },
304307
satisfaction_weight: script_sig_size * WITNESS_SCALE_FACTOR as u64 + 1, /* empty witness */
308+
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
305309
}
306310
}
307311

@@ -321,6 +325,7 @@ impl Utxo {
321325
},
322326
satisfaction_weight: script_sig_size * WITNESS_SCALE_FACTOR as u64
323327
+ P2WPKH_WITNESS_WEIGHT,
328+
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
324329
}
325330
}
326331

@@ -330,6 +335,7 @@ impl Utxo {
330335
outpoint,
331336
output: TxOut { value, script_pubkey: ScriptBuf::new_p2wpkh(pubkey_hash) },
332337
satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT + P2WPKH_WITNESS_WEIGHT,
338+
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
333339
}
334340
}
335341
}
@@ -728,7 +734,7 @@ where
728734
tx.input.push(TxIn {
729735
previous_output: utxo.outpoint,
730736
script_sig: ScriptBuf::new(),
731-
sequence: Sequence::ZERO,
737+
sequence: utxo.sequence,
732738
witness: Witness::new(),
733739
});
734740
}
@@ -1354,6 +1360,7 @@ mod tests {
13541360
script_pubkey: ScriptBuf::new(),
13551361
},
13561362
satisfaction_weight: 5, // Just the script_sig and witness lengths
1363+
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
13571364
}],
13581365
change_output: None,
13591366
},

lightning/src/ln/funding.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ pub struct FundingTxInput {
108108
/// [`TxOut`]: bitcoin::TxOut
109109
pub(super) utxo: Utxo,
110110

111-
/// The sequence number to use in the [`TxIn`].
112-
///
113-
/// [`TxIn`]: bitcoin::TxIn
114-
pub(super) sequence: Sequence,
115-
116111
/// The transaction containing the unspent [`TxOut`] referenced by [`utxo`].
117112
///
118113
/// [`TxOut`]: bitcoin::TxOut
@@ -122,7 +117,7 @@ pub struct FundingTxInput {
122117

123118
impl_writeable_tlv_based!(FundingTxInput, {
124119
(1, utxo, required),
125-
(3, sequence, required),
120+
(3, _sequence, (legacy, Sequence, |input: &FundingTxInput| Some(input.utxo.sequence))),
126121
(5, prevtx, required),
127122
});
128123

@@ -140,8 +135,8 @@ impl FundingTxInput {
140135
.ok_or(())?
141136
.clone(),
142137
satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT + witness_weight.to_wu(),
138+
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
143139
},
144-
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
145140
prevtx,
146141
})
147142
}
@@ -234,14 +229,14 @@ impl FundingTxInput {
234229
///
235230
/// [`TxIn`]: bitcoin::TxIn
236231
pub fn sequence(&self) -> Sequence {
237-
self.sequence
232+
self.utxo.sequence
238233
}
239234

240235
/// Sets the sequence number to use in the [`TxIn`].
241236
///
242237
/// [`TxIn`]: bitcoin::TxIn
243238
pub fn set_sequence(&mut self, sequence: Sequence) {
244-
self.sequence = sequence;
239+
self.utxo.sequence = sequence;
245240
}
246241

247242
/// Converts the [`FundingTxInput`] into a [`Utxo`] for coin selection.

lightning/src/ln/interactivetxs.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,9 +2061,13 @@ impl InteractiveTxConstructor {
20612061

20622062
let mut inputs_to_contribute: Vec<(SerialId, InputOwned)> = inputs_to_contribute
20632063
.into_iter()
2064-
.map(|FundingTxInput { utxo, sequence, prevtx: prev_tx }| {
2064+
.map(|FundingTxInput { utxo, prevtx: prev_tx }| {
20652065
let serial_id = generate_holder_serial_id(entropy_source, is_initiator);
2066-
let txin = TxIn { previous_output: utxo.outpoint, sequence, ..Default::default() };
2066+
let txin = TxIn {
2067+
previous_output: utxo.outpoint,
2068+
sequence: utxo.sequence,
2069+
..Default::default()
2070+
};
20672071
let prev_output = utxo.output;
20682072
let input = InputOwned::Single(SingleOwnedInput {
20692073
input: txin,

lightning/src/util/anchor_channel_reserves.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ where
330330
#[cfg(test)]
331331
mod test {
332332
use super::*;
333-
use bitcoin::{OutPoint, ScriptBuf, TxOut, Txid};
333+
use bitcoin::{OutPoint, ScriptBuf, Sequence, TxOut, Txid};
334334
use std::str::FromStr;
335335

336336
#[test]
@@ -358,6 +358,7 @@ mod test {
358358
},
359359
output: TxOut { value: amount, script_pubkey: ScriptBuf::new() },
360360
satisfaction_weight: 1 * 4 + (1 + 1 + 72 + 1 + 33),
361+
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME,
361362
}
362363
}
363364

0 commit comments

Comments
 (0)