Skip to content

Commit 1289506

Browse files
committed
f include remote_value to account for splice outs by counterparty
1 parent fbdefd1 commit 1289506

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lightning/src/ln/interactivetxs.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct NegotiationContext {
8484
outputs: HashMap<SerialId, TxOut>,
8585
tx_locktime: AbsoluteLockTime,
8686
feerate_sat_per_kw: u32,
87+
to_remote_value: u64,
8788
}
8889

8990
impl NegotiationContext {
@@ -314,7 +315,11 @@ impl NegotiationContext {
314315
for output in self.counterparty_outputs_contributed() {
315316
counterparty_outputs_value = counterparty_outputs_value.saturating_add(output.value);
316317
}
317-
if counterparty_inputs_value < counterparty_outputs_value {
318+
// ...actually the counterparty might be splicing out, so that their balance also contributes
319+
// to the total input value.
320+
if counterparty_inputs_value.saturating_add(self.to_remote_value)
321+
< counterparty_outputs_value
322+
{
318323
return Err(AbortReason::OutputsValueExceedsInputsValue);
319324
}
320325

@@ -549,7 +554,10 @@ macro_rules! define_state_machine_transitions {
549554
}
550555

551556
impl StateMachine {
552-
fn new(feerate_sat_per_kw: u32, is_initiator: bool, tx_locktime: AbsoluteLockTime) -> Self {
557+
fn new(
558+
feerate_sat_per_kw: u32, is_initiator: bool, tx_locktime: AbsoluteLockTime,
559+
to_remote_value: u64,
560+
) -> Self {
553561
let context = NegotiationContext {
554562
tx_locktime,
555563
holder_is_initiator: is_initiator,
@@ -559,6 +567,7 @@ impl StateMachine {
559567
prevtx_outpoints: new_hash_set(),
560568
outputs: new_hash_map(),
561569
feerate_sat_per_kw,
570+
to_remote_value,
562571
};
563572
if is_initiator {
564573
Self::RemoteChange(RemoteChange(context))
@@ -643,12 +652,13 @@ impl InteractiveTxConstructor {
643652
pub fn new<ES: Deref>(
644653
entropy_source: &ES, channel_id: ChannelId, feerate_sat_per_kw: u32, is_initiator: bool,
645654
tx_locktime: AbsoluteLockTime, inputs_to_contribute: Vec<(TxIn, TransactionU16LenLimited)>,
646-
outputs_to_contribute: Vec<TxOut>,
655+
outputs_to_contribute: Vec<TxOut>, to_remote_value: u64,
647656
) -> (Self, Option<InteractiveTxMessageSend>)
648657
where
649658
ES::Target: EntropySource,
650659
{
651-
let state_machine = StateMachine::new(feerate_sat_per_kw, is_initiator, tx_locktime);
660+
let state_machine =
661+
StateMachine::new(feerate_sat_per_kw, is_initiator, tx_locktime, to_remote_value);
652662
let inputs_to_contribute = inputs_to_contribute
653663
.into_iter()
654664
.map(|(input, tx)| {
@@ -813,6 +823,7 @@ mod tests {
813823
tx_locktime,
814824
session.inputs_a,
815825
session.outputs_a,
826+
0,
816827
);
817828
let (mut constructor_b, first_message_b) = InteractiveTxConstructor::new(
818829
&&entropy_source,
@@ -822,6 +833,7 @@ mod tests {
822833
tx_locktime,
823834
session.inputs_b,
824835
session.outputs_b,
836+
0,
825837
);
826838

827839
let handle_message_send =

0 commit comments

Comments
 (0)