Skip to content

Commit 50de598

Browse files
committed
f - persist current_holder_commitment_point
1 parent 661214e commit 50de598

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

lightning/src/ln/channel.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10595,6 +10595,15 @@ where
1059510595
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, change_script: Option<ScriptBuf>,
1059610596
funding_feerate_per_kw: u32, locktime: u32,
1059710597
) -> Result<msgs::SpliceInit, APIError> {
10598+
if self.current_holder_commitment_point.is_none() {
10599+
return Err(APIError::APIMisuseError {
10600+
err: format!(
10601+
"Channel {} cannot be spliced, commitment point needs to be advanced once",
10602+
self.context.channel_id(),
10603+
),
10604+
});
10605+
}
10606+
1059810607
// Check if a splice has been initiated already.
1059910608
// Note: only a single outstanding splice is supported (per spec)
1060010609
if self.pending_splice.is_some() {
@@ -10696,6 +10705,13 @@ where
1069610705

1069710706
// TODO(splicing): Add check that we are the quiescence acceptor
1069810707

10708+
if self.current_holder_commitment_point.is_none() {
10709+
return Err(ChannelError::Warn(format!(
10710+
"Channel {} commitment point needs to be advanced once before spliced",
10711+
self.context.channel_id(),
10712+
)));
10713+
}
10714+
1069910715
// Check if a splice has been initiated already.
1070010716
if self.pending_splice.is_some() {
1070110717
return Err(ChannelError::WarnAndDisconnect(format!(
@@ -13214,6 +13230,8 @@ where
1321413230
let is_manual_broadcast = Some(self.context.is_manual_broadcast);
1321513231

1321613232
// `HolderCommitmentPoint::point` will become optional when async signing is implemented.
13233+
let current_holder_commitment_point =
13234+
self.current_holder_commitment_point.map(|p| p.point());
1321713235
let next_holder_commitment_point = Some(self.next_holder_commitment_point.point());
1321813236
let next_holder_commitment_point_next_advance =
1321913237
self.next_holder_commitment_point.next_point();
@@ -13266,6 +13284,7 @@ where
1326613284
(59, self.funding.minimum_depth_override, option), // Added in 0.2
1326713285
(60, self.context.historical_scids, optional_vec), // Added in 0.2
1326813286
(61, fulfill_attribution_data, optional_vec), // Added in 0.2
13287+
(63, current_holder_commitment_point, option), // Added in 0.2
1326913288
});
1327013289

1327113290
Ok(())
@@ -13615,6 +13634,7 @@ where
1361513634
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
1361613635
let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
1361713636

13637+
let mut current_holder_commitment_point_opt: Option<PublicKey> = None;
1361813638
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
1361913639
let mut next_holder_commitment_point_next_advance_opt: Option<PublicKey> = None;
1362013640
let mut is_manual_broadcast = None;
@@ -13668,6 +13688,7 @@ where
1366813688
(59, minimum_depth_override, option), // Added in 0.2
1366913689
(60, historical_scids, optional_vec), // Added in 0.2
1367013690
(61, fulfill_attribution_data, optional_vec), // Added in 0.2
13691+
(63, current_holder_commitment_point_opt, option), // Added in 0.2
1367113692
});
1367213693

1367313694
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -13873,20 +13894,13 @@ where
1387313894
},
1387413895
};
1387513896

13876-
let current_holder_commitment_point = {
13877-
let current_holder_commitment_transaction_number =
13878-
next_holder_commitment_point.transaction_number() + 1;
13879-
let point = holder_signer
13880-
.get_per_commitment_point(current_holder_commitment_transaction_number, &secp_ctx)
13881-
.expect(
13882-
"Must be able to derive the current commitment point upon channel restoration",
13883-
);
13884-
Some(HolderCommitmentPoint {
13885-
transaction_number: current_holder_commitment_transaction_number,
13897+
let current_holder_commitment_point =
13898+
current_holder_commitment_point_opt.map(|point| HolderCommitmentPoint {
13899+
transaction_number: next_holder_commitment_point.transaction_number() + 1,
1388613900
point,
13887-
next_point: Some(next_holder_commitment_point.point()),
13888-
})
13889-
};
13901+
// Not needed since current_holder_commitment_point is never advanced
13902+
next_point: None,
13903+
});
1389013904

1389113905
Ok(FundedChannel {
1389213906
funding: FundingScope {

0 commit comments

Comments
 (0)