Skip to content

Commit ef24de4

Browse files
committed
f - DRY
1 parent 74e68b0 commit ef24de4

File tree

1 file changed

+32
-50
lines changed

1 file changed

+32
-50
lines changed

lightning/src/ln/channel.rs

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10847,6 +10847,33 @@ where
1084710847
}
1084810848

1084910849
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
10850+
self.validate_splice_contribution(their_funding_contribution)?;
10851+
10852+
// TODO(splicing): Check that channel balance does not go below the channel reserve
10853+
10854+
let splice_funding = FundingScope::for_splice(
10855+
&self.funding,
10856+
&self.context,
10857+
our_funding_contribution,
10858+
their_funding_contribution,
10859+
msg.funding_pubkey,
10860+
)?;
10861+
10862+
// TODO(splicing): Once splice acceptor can contribute, check that inputs are sufficient,
10863+
// similarly to the check in `splice_channel`.
10864+
10865+
// Note on channel reserve requirement pre-check: as the splice acceptor does not contribute,
10866+
// it can't go below reserve, therefore no pre-check is done here.
10867+
10868+
// TODO(splicing): Early check for reserve requirement
10869+
10870+
Ok(splice_funding)
10871+
}
10872+
10873+
#[cfg(splicing)]
10874+
fn validate_splice_contribution(
10875+
&self, their_funding_contribution: SignedAmount,
10876+
) -> Result<(), ChannelError> {
1085010877
if their_funding_contribution > SignedAmount::MAX_MONEY {
1085110878
return Err(ChannelError::WarnAndDisconnect(format!(
1085210879
"Channel {} cannot be spliced in; their {} contribution exceeds the total bitcoin supply",
@@ -10879,25 +10906,7 @@ where
1087910906
)));
1088010907
}
1088110908

10882-
// TODO(splicing): Check that channel balance does not go below the channel reserve
10883-
10884-
let splice_funding = FundingScope::for_splice(
10885-
&self.funding,
10886-
&self.context,
10887-
our_funding_contribution,
10888-
their_funding_contribution,
10889-
msg.funding_pubkey,
10890-
)?;
10891-
10892-
// TODO(splicing): Once splice acceptor can contribute, check that inputs are sufficient,
10893-
// similarly to the check in `splice_channel`.
10894-
10895-
// Note on channel reserve requirement pre-check: as the splice acceptor does not contribute,
10896-
// it can't go below reserve, therefore no pre-check is done here.
10897-
10898-
// TODO(splicing): Early check for reserve requirement
10899-
10900-
Ok(splice_funding)
10909+
Ok(())
1090110910
}
1090210911

1090310912
/// See also [`validate_splice_init`]
@@ -11013,37 +11022,7 @@ where
1101311022
debug_assert!(our_funding_contribution <= SignedAmount::MAX_MONEY);
1101411023

1101511024
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
11016-
if their_funding_contribution > SignedAmount::MAX_MONEY {
11017-
return Err(ChannelError::WarnAndDisconnect(format!(
11018-
"Channel {} cannot be spliced in; their {} contribution exceeds the total bitcoin supply",
11019-
self.context.channel_id(),
11020-
their_funding_contribution,
11021-
)));
11022-
}
11023-
11024-
if their_funding_contribution < -SignedAmount::MAX_MONEY {
11025-
return Err(ChannelError::WarnAndDisconnect(format!(
11026-
"Channel {} cannot be spliced out; their {} contribution exhausts the total bitcoin supply",
11027-
self.context.channel_id(),
11028-
their_funding_contribution,
11029-
)));
11030-
}
11031-
11032-
let their_channel_balance = Amount::from_sat(self.funding.get_value_satoshis())
11033-
- Amount::from_sat(self.funding.get_value_to_self_msat() / 1000);
11034-
let post_channel_balance = AddSigned::checked_add_signed(
11035-
their_channel_balance.to_sat(),
11036-
their_funding_contribution.to_sat(),
11037-
);
11038-
11039-
if post_channel_balance.is_none() {
11040-
return Err(ChannelError::WarnAndDisconnect(format!(
11041-
"Channel {} cannot be spliced out; their {} contribution exhausts their channel balance: {}",
11042-
self.context.channel_id(),
11043-
their_funding_contribution,
11044-
their_channel_balance,
11045-
)));
11046-
}
11025+
self.validate_splice_contribution(their_funding_contribution)?;
1104711026

1104811027
let splice_funding = FundingScope::for_splice(
1104911028
&self.funding,
@@ -11081,6 +11060,9 @@ where
1108111060
let tx_msg_opt = interactive_tx_constructor.take_initiator_first_message();
1108211061

1108311062
debug_assert!(self.interactive_tx_signing_session.is_none());
11063+
11064+
let pending_splice =
11065+
self.pending_splice.as_mut().expect("pending_splice should still be set");
1108411066
pending_splice.funding_negotiation = Some(FundingNegotiation::ConstructingTransaction(
1108511067
splice_funding,
1108611068
interactive_tx_constructor,

0 commit comments

Comments
 (0)