Skip to content

Commit 7df40c2

Browse files
committed
Extend begin_interactive_funding_tx_construction() with splicing-specific extra input
2 parents 8367dc6 + fbde31f commit 7df40c2

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,12 +1684,17 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
16841684
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled
16851685
fn begin_interactive_funding_tx_construction<ES: Deref>(
16861686
&mut self, signer_provider: &SP, entropy_source: &ES, holder_node_id: PublicKey,
1687+
prev_funding_input: Option<(TxIn, TransactionU16LenLimited)>,
16871688
) -> Result<Option<InteractiveTxMessageSend>, APIError>
16881689
where ES::Target: EntropySource
16891690
{
16901691
let mut funding_inputs = Vec::new();
16911692
mem::swap(&mut self.dual_funding_context.our_funding_inputs, &mut funding_inputs);
16921693

1694+
if let Some(prev_funding_input) = prev_funding_input {
1695+
funding_inputs.push(prev_funding_input);
1696+
}
1697+
16931698
let funding_inputs_prev_outputs = DualFundingChannelContext::txouts_from_input_prev_txs(&funding_inputs)
16941699
.map_err(|err| APIError::APIMisuseError { err: err.to_string() })?;
16951700

lightning/src/ln/interactivetxs.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,4 +2728,58 @@ mod tests {
27282728
assert_eq!(res.unwrap(), 154);
27292729
}
27302730
}
2731+
2732+
#[test]
2733+
fn test_calculate_change_output_value_splice() {
2734+
let input_prevouts_owned = vec![
2735+
TxOut { value: Amount::from_sat(70_000), script_pubkey: ScriptBuf::new() },
2736+
TxOut { value: Amount::from_sat(60_000), script_pubkey: ScriptBuf::new() },
2737+
];
2738+
let input_prevouts: Vec<&TxOut> = input_prevouts_owned.iter().collect();
2739+
let our_contributed = 110_000;
2740+
let txout = TxOut { value: Amount::from_sat(148_000), script_pubkey: ScriptBuf::new() };
2741+
let outputs = vec![OutputOwned::Shared(SharedOwnedOutput::new(txout, our_contributed))];
2742+
let funding_feerate_sat_per_1000_weight = 3000;
2743+
2744+
let total_inputs: u64 = input_prevouts.iter().map(|o| o.value.to_sat()).sum();
2745+
let gross_change = total_inputs - our_contributed;
2746+
let fees = 1746;
2747+
let common_fees = 126;
2748+
{
2749+
// There is leftover for change
2750+
let res = calculate_change_output_value(
2751+
true,
2752+
our_contributed,
2753+
&input_prevouts,
2754+
&outputs,
2755+
funding_feerate_sat_per_1000_weight,
2756+
300,
2757+
);
2758+
assert_eq!(res.unwrap(), gross_change - fees - common_fees);
2759+
}
2760+
{
2761+
// Very small leftover
2762+
let res = calculate_change_output_value(
2763+
false,
2764+
128_100,
2765+
&input_prevouts,
2766+
&outputs,
2767+
funding_feerate_sat_per_1000_weight,
2768+
300,
2769+
);
2770+
assert!(res.is_none());
2771+
}
2772+
{
2773+
// Small leftover, but not dust
2774+
let res = calculate_change_output_value(
2775+
false,
2776+
128_100,
2777+
&input_prevouts,
2778+
&outputs,
2779+
funding_feerate_sat_per_1000_weight,
2780+
100,
2781+
);
2782+
assert_eq!(res.unwrap(), 154);
2783+
}
2784+
}
27312785
}

0 commit comments

Comments
 (0)