Skip to content

Commit 2bcba88

Browse files
committed
Include witness weights in FundingNegotiationContext
ChannelManager::splice_channel takes witness weights with the funding inputs. Storing these in FundingNegotiationContext allows us to use them when calculating the change output and include them in a common struct used for initiating a splice-in. In preparation for having ChannelManager::splice_channel take FundingTxContributions, add a weight to the FundingTxContributions::InputsOnly, which supports the splice-in use case.
1 parent df09970 commit 2bcba88

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5978,7 +5978,7 @@ pub(super) struct FundingNegotiationContext {
59785978
pub shared_funding_input: Option<SharedOwnedInput>,
59795979
/// The funding inputs we will be contributing to the channel.
59805980
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled.
5981-
pub our_funding_inputs: Vec<(TxIn, Transaction)>,
5981+
pub our_funding_inputs: Vec<(TxIn, Transaction, Weight)>,
59825982
/// The change output script. This will be used if needed or -- if not set -- generated using
59835983
/// `SignerProvider::get_destination_script`.
59845984
#[allow(dead_code)] // TODO(splicing): Remove once splicing is enabled.
@@ -6050,6 +6050,9 @@ impl FundingNegotiationContext {
60506050
}
60516051
}
60526052

6053+
let funding_inputs =
6054+
self.our_funding_inputs.into_iter().map(|(txin, tx, _)| (txin, tx)).collect();
6055+
60536056
let constructor_args = InteractiveTxConstructorArgs {
60546057
entropy_source,
60556058
holder_node_id,
@@ -6058,7 +6061,7 @@ impl FundingNegotiationContext {
60586061
feerate_sat_per_kw: self.funding_feerate_sat_per_1000_weight,
60596062
is_initiator: self.is_initiator,
60606063
funding_tx_locktime: self.funding_tx_locktime,
6061-
inputs_to_contribute: self.our_funding_inputs,
6064+
inputs_to_contribute: funding_inputs,
60626065
shared_funding_input: self.shared_funding_input,
60636066
shared_funding_output: SharedOwnedOutput::new(
60646067
shared_funding_output,
@@ -10668,9 +10671,8 @@ where
1066810671
err,
1066910672
),
1067010673
})?;
10671-
// Convert inputs
10672-
let mut funding_inputs = Vec::new();
10673-
for (txin, tx, _) in our_funding_inputs.into_iter() {
10674+
10675+
for (txin, tx, _) in our_funding_inputs.iter() {
1067410676
const MESSAGE_TEMPLATE: msgs::TxAddInput = msgs::TxAddInput {
1067510677
channel_id: ChannelId([0; 32]),
1067610678
serial_id: 0,
@@ -10688,8 +10690,6 @@ where
1068810690
),
1068910691
});
1069010692
}
10691-
10692-
funding_inputs.push((txin, tx));
1069310693
}
1069410694

1069510695
let prev_funding_input = self.funding.to_splice_funding_input();
@@ -10699,7 +10699,7 @@ where
1069910699
funding_tx_locktime: LockTime::from_consensus(locktime),
1070010700
funding_feerate_sat_per_1000_weight: funding_feerate_per_kw,
1070110701
shared_funding_input: Some(prev_funding_input),
10702-
our_funding_inputs: funding_inputs,
10702+
our_funding_inputs,
1070310703
change_script,
1070410704
};
1070510705

@@ -12468,7 +12468,7 @@ where
1246812468
pub fn new_outbound<ES: Deref, F: Deref, L: Deref>(
1246912469
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
1247012470
counterparty_node_id: PublicKey, their_features: &InitFeatures, funding_satoshis: u64,
12471-
funding_inputs: Vec<(TxIn, Transaction)>, user_id: u128, config: &UserConfig,
12471+
funding_inputs: Vec<(TxIn, Transaction, Weight)>, user_id: u128, config: &UserConfig,
1247212472
current_chain_height: u32, outbound_scid_alias: u64, funding_confirmation_target: ConfirmationTarget,
1247312473
logger: L,
1247412474
) -> Result<Self, APIError>
@@ -12682,6 +12682,8 @@ where
1268212682
value: Amount::from_sat(funding.get_value_satoshis()),
1268312683
script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
1268412684
};
12685+
let inputs_to_contribute =
12686+
our_funding_inputs.into_iter().map(|(txin, tx, _)| (txin, tx)).collect();
1268512687

1268612688
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
1268712689
InteractiveTxConstructorArgs {
@@ -12692,7 +12694,7 @@ where
1269212694
feerate_sat_per_kw: funding_negotiation_context.funding_feerate_sat_per_1000_weight,
1269312695
funding_tx_locktime: funding_negotiation_context.funding_tx_locktime,
1269412696
is_initiator: false,
12695-
inputs_to_contribute: our_funding_inputs,
12697+
inputs_to_contribute,
1269612698
shared_funding_input: None,
1269712699
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_contribution_sats),
1269812700
outputs_to_contribute: Vec::new(),

lightning/src/ln/dual_funding_tests.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession)
4848
let initiator_funding_inputs: Vec<_> = create_dual_funding_utxos_with_prev_txs(
4949
&nodes[0],
5050
&[session.initiator_input_value_satoshis],
51-
)
52-
.into_iter()
53-
.map(|(txin, tx, _)| (txin, tx))
54-
.collect();
51+
);
5552

5653
// Alice creates a dual-funded channel as initiator.
5754
let funding_satoshis = session.funding_input_sats;

lightning/src/ln/interactivetxs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ pub(super) fn calculate_change_output_value(
20752075

20762076
let mut total_input_satoshis = 0u64;
20772077
let mut our_funding_inputs_weight = 0u64;
2078-
for (txin, tx) in context.our_funding_inputs.iter() {
2078+
for (txin, tx, _) in context.our_funding_inputs.iter() {
20792079
let txid = tx.compute_txid();
20802080
if txin.previous_output.txid != txid {
20812081
return Err(AbortReason::PrevTxOutInvalid);
@@ -3160,9 +3160,10 @@ mod tests {
31603160
sequence: Sequence::ZERO,
31613161
witness: Witness::new(),
31623162
};
3163-
(txin, tx)
3163+
let weight = Weight::ZERO;
3164+
(txin, tx, weight)
31643165
})
3165-
.collect::<Vec<(TxIn, Transaction)>>();
3166+
.collect::<Vec<(TxIn, Transaction, Weight)>>();
31663167
let our_contributed = 110_000;
31673168
let txout = TxOut { value: Amount::from_sat(10_000), script_pubkey: ScriptBuf::new() };
31683169
let outputs = vec![txout];

0 commit comments

Comments
 (0)