Skip to content

Commit e1d22fa

Browse files
committed
Include input weights together with inputs (not separate param)
1 parent 1cc2f53 commit e1d22fa

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

lightning/src/ln/channel.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8394,10 +8394,11 @@ impl<SP: Deref> FundedChannel<SP> where
83948394
}
83958395

83968396
/// Initiate splicing.
8397-
/// - witness_weight: The witness weight for contributed inputs.
8397+
/// - our_funding_inputs: the inputs we contribute to the new funding transaction.
8398+
/// Includes the witness weight for this input (e.g. P2WPKH_WITNESS_WEIGHT=109 for typical P2WPKH inputs).
83988399
#[cfg(splicing)]
83998400
pub fn splice_channel(&mut self, our_funding_contribution_satoshis: i64,
8400-
our_funding_inputs: Vec<(TxIn, Transaction)>, witness_weight: Weight,
8401+
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>,
84018402
funding_feerate_per_kw: u32, locktime: u32,
84028403
) -> Result<msgs::SpliceInit, ChannelError> {
84038404
// Check if a splice has been initiated already.
@@ -8436,14 +8437,15 @@ impl<SP: Deref> FundedChannel<SP> where
84368437
// Pre-check that inputs are sufficient to cover our contribution.
84378438
// Note: fees are not taken into account here.
84388439
let sum_input: u64 = our_funding_inputs.iter().map(
8439-
|(txin, tx)| tx.output.get(txin.previous_output.vout as usize).map(|tx| tx.value.to_sat()).unwrap_or(0)
8440+
|(txin, tx, _)| tx.output.get(txin.previous_output.vout as usize).map(|tx| tx.value.to_sat()).unwrap_or(0)
84408441
).sum();
84418442

84428443
// The +1 is to include the input of the old funding
84438444
let funding_input_count = our_funding_inputs.len() + 1;
84448445
// Input witness weight, extended with weight for spending old funding
84458446
let total_witness_weight = Weight::from_wu(
8446-
witness_weight.to_wu().saturating_add(FUNDING_TRANSACTION_WITNESS_WEIGHT)
8447+
our_funding_inputs.iter().map(|(_, _, w)| w.to_wu()).sum::<u64>()
8448+
.saturating_add(FUNDING_TRANSACTION_WITNESS_WEIGHT)
84478449
);
84488450
let estimated_fee = estimate_v2_funding_transaction_fee(true, funding_input_count, total_witness_weight, funding_feerate_per_kw);
84498451
let available_input = sum_input.saturating_sub(estimated_fee);
@@ -9904,6 +9906,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
99049906
/// Creates a new dual-funded channel from a remote side's request for one.
99059907
/// Assumes chain_hash has already been checked and corresponds with what we expect!
99069908
/// TODO(dual_funding): Allow contributions, pass intended amount and inputs
9909+
/// TODO(dual_funding): Include witness weight info with the inputs.
99079910
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
99089911
pub fn new_inbound<ES: Deref, F: Deref, L: Deref>(
99099912
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4285,11 +4285,11 @@ where
42854285
/// Note: Currently only splice-in is supported (increase in channel capacity), splice-out is not.
42864286
/// - our_funding_contribution_satoshis: the amount contributed by us to the channel. This will increase our channel balance.
42874287
/// - our_funding_inputs: the funding inputs provided by us. If our contribution is positive, our funding inputs must cover at least that amount.
4288-
/// - witness_weight: The witness weight for contributed inputs.
4288+
/// Includes the witness weight for this input (e.g. P2WPKH_WITNESS_WEIGHT=109 for typical P2WPKH inputs).
42894289
#[cfg(splicing)]
42904290
pub fn splice_channel(
42914291
&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4292-
our_funding_inputs: Vec<(TxIn, Transaction)>, witness_weight: Weight,
4292+
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>,
42934293
funding_feerate_per_kw: u32, locktime: u32,
42944294
) -> Result<(), APIError> {
42954295
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -4304,7 +4304,7 @@ where
43044304
match peer_state.channel_by_id.entry(*channel_id) {
43054305
hash_map::Entry::Occupied(mut chan_phase_entry) => {
43064306
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
4307-
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, witness_weight, funding_feerate_per_kw, locktime)
4307+
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_per_kw, locktime)
43084308
.map_err(|err| APIError::APIMisuseError {
43094309
err: format!(
43104310
"Cannot initiate Splicing, {}, channel ID {}", err, channel_id

lightning/src/ln/dual_funding_tests.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ fn do_test_v2_channel_establishment(
4949
let logger_a = test_utils::TestLogger::with_id("node a".to_owned());
5050

5151
// Create a funding input for the new channel along with its previous transaction.
52-
let (initiator_funding_inputs, total_weight) = create_dual_funding_utxos_with_prev_txs(
52+
let initiator_funding_inputs = create_dual_funding_utxos_with_prev_txs(
5353
&nodes[0],
5454
&[session.initiator_input_value_satoshis],
55-
)
56-
.into_iter()
57-
.map(|(txin, tx)| (txin, TransactionU16LenLimited::new(tx).unwrap()))
58-
.collect();
55+
);
56+
let total_weight =
57+
Weight::from_wu(initiator_funding_inputs.iter().map(|(_, _, w)| w.to_wu()).sum());
58+
let initiator_funding_inputs: Vec<_> = initiator_funding_inputs
59+
.into_iter()
60+
.map(|(txin, tx, _)| (txin, TransactionU16LenLimited::new(tx).unwrap()))
61+
.collect();
5962

6063
// Alice creates a dual-funded channel as initiator.
6164
let funding_feerate = node_cfgs[0]

lightning/src/ln/functional_test_utils.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ fn internal_create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>,
12411241
/// Return the inputs (with prev tx), and the total witness weight for these inputs
12421242
pub fn create_dual_funding_utxos_with_prev_txs(
12431243
node: &Node<'_, '_, '_>, utxo_values_in_satoshis: &[u64],
1244-
) -> (Vec<(TxIn, Transaction)>, Weight) {
1244+
) -> Vec<(TxIn, Transaction, Weight)> {
12451245
// Ensure we have unique transactions per node by using the locktime.
12461246
let tx = Transaction {
12471247
version: TxVersion::TWO,
@@ -1265,11 +1265,13 @@ pub fn create_dual_funding_utxos_with_prev_txs(
12651265
script_sig: ScriptBuf::new(),
12661266
sequence: Sequence::ZERO,
12671267
witness: Witness::new(),
1268-
}, tx.clone()));
1268+
},
1269+
tx.clone(),
1270+
Weight::from_wu(P2WPKH_WITNESS_WEIGHT),
1271+
));
12691272
}
1270-
let total_weight = Weight::from_wu(utxo_values_in_satoshis.len() as u64 * P2WPKH_WITNESS_WEIGHT);
12711273

1272-
(inputs, total_weight)
1274+
inputs
12731275
}
12741276

12751277
pub fn sign_funding_transaction<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>, channel_value: u64, expected_temporary_channel_id: ChannelId) -> Transaction {

lightning/src/ln/functional_tests_splice.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ fn test_v1_splice_in() {
231231

232232
// Create additional inputs
233233
let extra_splice_funding_input_sats = 35_000;
234-
let (funding_inputs, total_weight) = create_dual_funding_utxos_with_prev_txs(
234+
let funding_inputs = create_dual_funding_utxos_with_prev_txs(
235235
&initiator_node,
236236
&[extra_splice_funding_input_sats],
237237
);
@@ -243,7 +243,6 @@ fn test_v1_splice_in() {
243243
&acceptor_node.node.get_our_node_id(),
244244
splice_in_sats as i64,
245245
funding_inputs,
246-
total_weight,
247246
funding_feerate_per_kw,
248247
locktime,
249248
)

0 commit comments

Comments
 (0)