@@ -1251,6 +1251,7 @@ pub(crate) struct ShutdownResult {
1251
1251
#[derive(Debug, Copy, Clone)]
1252
1252
struct HolderCommitmentPoint {
1253
1253
next_transaction_number: u64,
1254
+ current_point: Option<PublicKey>,
1254
1255
next_point: PublicKey,
1255
1256
pending_next_point: Option<PublicKey>,
1256
1257
}
@@ -1262,6 +1263,7 @@ impl HolderCommitmentPoint {
1262
1263
{
1263
1264
Some(HolderCommitmentPoint {
1264
1265
next_transaction_number: INITIAL_COMMITMENT_NUMBER,
1266
+ current_point: None,
1265
1267
next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?,
1266
1268
pending_next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok(),
1267
1269
})
@@ -1271,6 +1273,14 @@ impl HolderCommitmentPoint {
1271
1273
self.pending_next_point.is_some()
1272
1274
}
1273
1275
1276
+ pub fn current_transaction_number(&self) -> u64 {
1277
+ self.next_transaction_number + 1
1278
+ }
1279
+
1280
+ pub fn current_point(&self) -> Option<PublicKey> {
1281
+ self.current_point
1282
+ }
1283
+
1274
1284
pub fn next_transaction_number(&self) -> u64 {
1275
1285
self.next_transaction_number
1276
1286
}
@@ -1328,6 +1338,7 @@ impl HolderCommitmentPoint {
1328
1338
if let Some(next_point) = self.pending_next_point {
1329
1339
*self = Self {
1330
1340
next_transaction_number: self.next_transaction_number - 1,
1341
+ current_point: Some(self.next_point),
1331
1342
next_point,
1332
1343
pending_next_point: None,
1333
1344
};
@@ -9591,7 +9602,7 @@ where
9591
9602
}
9592
9603
9593
9604
pub fn get_cur_holder_commitment_transaction_number(&self) -> u64 {
9594
- self.holder_commitment_point.next_transaction_number() + 1
9605
+ self.holder_commitment_point.current_transaction_number()
9595
9606
}
9596
9607
9597
9608
pub fn get_cur_counterparty_commitment_transaction_number(&self) -> u64 {
@@ -10582,6 +10593,15 @@ where
10582
10593
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, change_script: Option<ScriptBuf>,
10583
10594
funding_feerate_per_kw: u32, locktime: u32,
10584
10595
) -> Result<msgs::SpliceInit, APIError> {
10596
+ if self.holder_commitment_point.current_point().is_none() {
10597
+ return Err(APIError::APIMisuseError {
10598
+ err: format!(
10599
+ "Channel {} cannot be spliced, commitment point needs to be advanced once",
10600
+ self.context.channel_id(),
10601
+ ),
10602
+ });
10603
+ }
10604
+
10585
10605
// Check if a splice has been initiated already.
10586
10606
// Note: only a single outstanding splice is supported (per spec)
10587
10607
if self.pending_splice.is_some() {
@@ -10683,6 +10703,13 @@ where
10683
10703
10684
10704
// TODO(splicing): Add check that we are the quiescence acceptor
10685
10705
10706
+ if self.holder_commitment_point.current_point().is_none() {
10707
+ return Err(ChannelError::Warn(format!(
10708
+ "Channel {} commitment point needs to be advanced once before spliced",
10709
+ self.context.channel_id(),
10710
+ )));
10711
+ }
10712
+
10686
10713
// Check if a splice has been initiated already.
10687
10714
if self.pending_splice.is_some() {
10688
10715
return Err(ChannelError::WarnAndDisconnect(format!(
@@ -13198,6 +13225,7 @@ where
13198
13225
}
13199
13226
let is_manual_broadcast = Some(self.context.is_manual_broadcast);
13200
13227
13228
+ let holder_commitment_point_current = self.holder_commitment_point.current_point();
13201
13229
// `HolderCommitmentPoint::next_point` will become optional when async signing is implemented.
13202
13230
let holder_commitment_point_next = Some(self.holder_commitment_point.next_point());
13203
13231
let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point;
@@ -13250,6 +13278,7 @@ where
13250
13278
(59, self.funding.minimum_depth_override, option), // Added in 0.2
13251
13279
(60, self.context.historical_scids, optional_vec), // Added in 0.2
13252
13280
(61, fulfill_attribution_data, optional_vec), // Added in 0.2
13281
+ (63, holder_commitment_point_current, option), // Added in 0.2
13253
13282
});
13254
13283
13255
13284
Ok(())
@@ -13599,6 +13628,7 @@ where
13599
13628
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
13600
13629
let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
13601
13630
13631
+ let mut holder_commitment_point_current_opt: Option<PublicKey> = None;
13602
13632
let mut holder_commitment_point_next_opt: Option<PublicKey> = None;
13603
13633
let mut holder_commitment_point_pending_next_opt: Option<PublicKey> = None;
13604
13634
let mut is_manual_broadcast = None;
@@ -13652,6 +13682,7 @@ where
13652
13682
(59, minimum_depth_override, option), // Added in 0.2
13653
13683
(60, historical_scids, optional_vec), // Added in 0.2
13654
13684
(61, fulfill_attribution_data, optional_vec), // Added in 0.2
13685
+ (63, holder_commitment_point_current_opt, option), // Added in 0.2
13655
13686
});
13656
13687
13657
13688
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -13833,6 +13864,7 @@ where
13833
13864
match (holder_commitment_point_next_opt, holder_commitment_point_pending_next_opt) {
13834
13865
(Some(next_point), pending_next_point) => HolderCommitmentPoint {
13835
13866
next_transaction_number: holder_commitment_next_transaction_number,
13867
+ current_point: None,
13836
13868
next_point,
13837
13869
pending_next_point,
13838
13870
},
@@ -13852,6 +13884,7 @@ where
13852
13884
);
13853
13885
HolderCommitmentPoint {
13854
13886
next_transaction_number: holder_commitment_next_transaction_number,
13887
+ current_point: holder_commitment_point_current_opt,
13855
13888
next_point,
13856
13889
pending_next_point: Some(pending_next_point),
13857
13890
}
0 commit comments