Skip to content

Commit 161be79

Browse files
committed
Include input weights together with inputs (not separate param)
1 parent 09237f7 commit 161be79

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

lightning/src/ln/channel.rs

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

82218221
/// Initiate splicing.
8222-
/// - witness_weight: The witness weight for contributed inputs.
8222+
/// - our_funding_inputs: the inputs we contribute to the new funding transaction.
8223+
/// Includes the witness weight for this input (e.g. P2WPKH_WITNESS_WEIGHT=109 for typical P2WPKH inputs).
82238224
#[cfg(splicing)]
82248225
pub fn splice_channel(&mut self, our_funding_contribution_satoshis: i64,
8225-
our_funding_inputs: Vec<(TxIn, Transaction)>, witness_weight: Weight,
8226+
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>,
82268227
funding_feerate_per_kw: u32, locktime: u32,
82278228
) -> Result<msgs::SpliceInit, ChannelError> {
82288229
// Check if a splice has been initiated already.
@@ -8261,14 +8262,15 @@ impl<SP: Deref> FundedChannel<SP> where
82618262
// Pre-check that inputs are sufficient to cover our contribution.
82628263
// Note: fees are not taken into account here.
82638264
let sum_input: u64 = our_funding_inputs.iter().map(
8264-
|(txin, tx)| tx.output.get(txin.previous_output.vout as usize).map(|tx| tx.value.to_sat()).unwrap_or(0)
8265+
|(txin, tx, _)| tx.output.get(txin.previous_output.vout as usize).map(|tx| tx.value.to_sat()).unwrap_or(0)
82658266
).sum();
82668267

82678268
// The +1 is to include the input of the old funding
82688269
let funding_input_count = our_funding_inputs.len() + 1;
82698270
// Input witness weight, extended with weight for spending old funding
82708271
let total_witness_weight = Weight::from_wu(
8271-
witness_weight.to_wu().saturating_add(FUNDING_TRANSACTION_WITNESS_WEIGHT)
8272+
our_funding_inputs.iter().map(|(_, _, w)| w.to_wu()).sum::<u64>()
8273+
.saturating_add(FUNDING_TRANSACTION_WITNESS_WEIGHT)
82728274
);
82738275
let estimated_fee = estimate_funding_transaction_fee(true, funding_input_count, total_witness_weight, funding_feerate_per_kw);
82748276
let available_input = sum_input.saturating_sub(estimated_fee);
@@ -9504,6 +9506,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
95049506

95059507
/// Creates a new dual-funded channel from a remote side's request for one.
95069508
/// Assumes chain_hash has already been checked and corresponds with what we expect!
9509+
/// TODO(dual_funding): Include witness weight info with the inputs.
95079510
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
95089511
pub fn new_inbound<ES: Deref, F: Deref, L: Deref>(
95099512
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
@@ -4238,11 +4238,11 @@ where
42384238
/// Note: Currently only splice-in is supported (increase in channel capacity), splice-out is not.
42394239
/// - our_funding_contribution_satoshis: the amount contributed by us to the channel. This will increase our channel balance.
42404240
/// - our_funding_inputs: the funding inputs provided by us. If our contribution is positive, our funding inputs must cover at least that amount.
4241-
/// - witness_weight: The witness weight for contributed inputs.
4241+
/// Includes the witness weight for this input (e.g. P2WPKH_WITNESS_WEIGHT=109 for typical P2WPKH inputs).
42424242
#[cfg(splicing)]
42434243
pub fn splice_channel(
42444244
&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4245-
our_funding_inputs: Vec<(TxIn, Transaction)>, witness_weight: Weight,
4245+
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>,
42464246
funding_feerate_per_kw: u32, locktime: u32,
42474247
) -> Result<(), APIError> {
42484248
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -4257,7 +4257,7 @@ where
42574257
match peer_state.channel_by_id.entry(*channel_id) {
42584258
hash_map::Entry::Occupied(mut chan_phase_entry) => {
42594259
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
4260-
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, witness_weight, funding_feerate_per_kw, locktime)
4260+
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_per_kw, locktime)
42614261
.map_err(|err| APIError::APIMisuseError {
42624262
err: format!(
42634263
"Cannot initiate Splicing, {}, channel ID {}", err, channel_id

lightning/src/ln/dual_funding_tests.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use {
2626
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete},
2727
crate::ln::types::ChannelId,
2828
crate::prelude::*,
29-
crate::sign::{ChannelSigner as _, P2WPKH_WITNESS_WEIGHT},
29+
crate::sign::ChannelSigner as _,
3030
crate::util::ser::TransactionU16LenLimited,
3131
crate::util::test_utils,
3232
bitcoin::Weight,
@@ -51,12 +51,13 @@ fn do_test_v2_channel_establishment(
5151
let logger_a = test_utils::TestLogger::with_id("node a".to_owned());
5252

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

6263
// Alice creates a dual-funded channel as initiator.

lightning/src/ln/functional_test_utils.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ fn internal_create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>,
12501250
/// Return the inputs (with prev tx), and the total witness weight for these inputs
12511251
pub fn create_dual_funding_utxos_with_prev_txs(
12521252
node: &Node<'_, '_, '_>, utxo_values_in_satoshis: &[u64],
1253-
) -> (Vec<(TxIn, Transaction)>, Weight) {
1253+
) -> Vec<(TxIn, Transaction, Weight)> {
12541254
// Ensure we have unique transactions per node by using the locktime.
12551255
let tx = Transaction {
12561256
version: TxVersion::TWO,
@@ -1274,11 +1274,13 @@ pub fn create_dual_funding_utxos_with_prev_txs(
12741274
script_sig: ScriptBuf::new(),
12751275
sequence: Sequence::ZERO,
12761276
witness: Witness::new(),
1277-
}, tx.clone()));
1277+
},
1278+
tx.clone(),
1279+
Weight::from_wu(P2WPKH_WITNESS_WEIGHT),
1280+
));
12781281
}
1279-
let total_weight = Weight::from_wu(utxo_values_in_satoshis.len() as u64 * P2WPKH_WITNESS_WEIGHT);
12801282

1281-
(inputs, total_weight)
1283+
inputs
12821284
}
12831285

12841286
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)