Skip to content

Commit 567442d

Browse files
committed
f - DRY
1 parent 74e68b0 commit 567442d

File tree

1 file changed

+31
-50
lines changed

1 file changed

+31
-50
lines changed

lightning/src/ln/channel.rs

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10847,6 +10847,32 @@ 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+
fn validate_splice_contribution(
10874+
&self, their_funding_contribution: SignedAmount,
10875+
) -> Result<(), ChannelError> {
1085010876
if their_funding_contribution > SignedAmount::MAX_MONEY {
1085110877
return Err(ChannelError::WarnAndDisconnect(format!(
1085210878
"Channel {} cannot be spliced in; their {} contribution exceeds the total bitcoin supply",
@@ -10879,25 +10905,7 @@ where
1087910905
)));
1088010906
}
1088110907

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)
10908+
Ok(())
1090110909
}
1090210910

1090310911
/// See also [`validate_splice_init`]
@@ -11013,37 +11021,7 @@ where
1101311021
debug_assert!(our_funding_contribution <= SignedAmount::MAX_MONEY);
1101411022

1101511023
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-
}
11024+
self.validate_splice_contribution(their_funding_contribution)?;
1104711025

1104811026
let splice_funding = FundingScope::for_splice(
1104911027
&self.funding,
@@ -11081,6 +11059,9 @@ where
1108111059
let tx_msg_opt = interactive_tx_constructor.take_initiator_first_message();
1108211060

1108311061
debug_assert!(self.interactive_tx_signing_session.is_none());
11062+
11063+
let pending_splice =
11064+
self.pending_splice.as_mut().expect("pending_splice should still be set");
1108411065
pending_splice.funding_negotiation = Some(FundingNegotiation::ConstructingTransaction(
1108511066
splice_funding,
1108611067
interactive_tx_constructor,

0 commit comments

Comments
 (0)