@@ -954,18 +954,17 @@ enum HolderCommitmentPoint {
954
954
}
955
955
956
956
impl HolderCommitmentPoint {
957
- pub fn new<SP: Deref>(signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>) -> Self
957
+ pub fn new<SP: Deref>(signer: &ChannelSignerType<SP>, secp_ctx: &Secp256k1<secp256k1::All>) -> Option< Self>
958
958
where SP::Target: SignerProvider
959
959
{
960
- HolderCommitmentPoint::Available {
961
- transaction_number: INITIAL_COMMITMENT_NUMBER,
962
- // TODO(async_signing): remove this expect with the Uninitialized variant
963
- current: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx)
964
- .expect("Signer must be able to provide initial commitment point"),
965
- // TODO(async_signing): remove this expect with the Uninitialized variant
966
- next: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx)
967
- .expect("Signer must be able to provide second commitment point"),
968
- }
960
+ let current = signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?;
961
+ let next = signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok();
962
+ let point = if let Some(next) = next {
963
+ HolderCommitmentPoint::Available { transaction_number: INITIAL_COMMITMENT_NUMBER, current, next }
964
+ } else {
965
+ HolderCommitmentPoint::PendingNext { transaction_number: INITIAL_COMMITMENT_NUMBER, current }
966
+ };
967
+ Some(point)
969
968
}
970
969
971
970
pub fn is_available(&self) -> bool {
@@ -1163,6 +1162,8 @@ pub(super) struct UnfundedChannelContext {
1163
1162
/// This is so that we don't keep channels around that haven't progressed to a funded state
1164
1163
/// in a timely manner.
1165
1164
unfunded_channel_age_ticks: usize,
1165
+ /// Tracks the commitment number and commitment point before the channel is funded.
1166
+ holder_commitment_point: Option<HolderCommitmentPoint>,
1166
1167
}
1167
1168
1168
1169
impl UnfundedChannelContext {
@@ -1174,6 +1175,11 @@ impl UnfundedChannelContext {
1174
1175
self.unfunded_channel_age_ticks += 1;
1175
1176
self.unfunded_channel_age_ticks >= UNFUNDED_CHANNEL_AGE_LIMIT_TICKS
1176
1177
}
1178
+
1179
+ fn transaction_number(&self) -> u64 {
1180
+ self.holder_commitment_point.as_ref().map(|point| point.transaction_number())
1181
+ .unwrap_or(INITIAL_COMMITMENT_NUMBER)
1182
+ }
1177
1183
}
1178
1184
1179
1185
/// Contains everything about the channel including state, and various flags.
@@ -1685,7 +1691,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1685
1691
let value_to_self_msat = our_funding_satoshis * 1000 + msg_push_msat;
1686
1692
1687
1693
let holder_signer = ChannelSignerType::Ecdsa(holder_signer);
1688
- let holder_commitment_point = HolderCommitmentPoint::new(&holder_signer, &secp_ctx);
1694
+ // Unwrap here since it gets removed in the next commit
1695
+ let holder_commitment_point = HolderCommitmentPoint::new(&holder_signer, &secp_ctx).unwrap();
1689
1696
1690
1697
// TODO(dual_funding): Checks for `funding_feerate_sat_per_1000_weight`?
1691
1698
@@ -1921,7 +1928,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1921
1928
let temporary_channel_id = temporary_channel_id.unwrap_or_else(|| ChannelId::temporary_from_entropy_source(entropy_source));
1922
1929
1923
1930
let holder_signer = ChannelSignerType::Ecdsa(holder_signer);
1924
- let holder_commitment_point = HolderCommitmentPoint::new(&holder_signer, &secp_ctx);
1931
+ // Unwrap here since it gets removed in the next commit
1932
+ let holder_commitment_point = HolderCommitmentPoint::new(&holder_signer, &secp_ctx).unwrap();
1925
1933
1926
1934
Ok(Self {
1927
1935
user_id,
@@ -7643,28 +7651,31 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7643
7651
let holder_signer = signer_provider.derive_channel_signer(channel_value_satoshis, channel_keys_id);
7644
7652
let pubkeys = holder_signer.pubkeys().clone();
7645
7653
7646
- let chan = Self {
7647
- context: ChannelContext::new_for_outbound_channel(
7648
- fee_estimator,
7649
- entropy_source,
7650
- signer_provider,
7651
- counterparty_node_id,
7652
- their_features,
7653
- channel_value_satoshis,
7654
- push_msat,
7655
- user_id,
7656
- config,
7657
- current_chain_height,
7658
- outbound_scid_alias,
7659
- temporary_channel_id,
7660
- holder_selected_channel_reserve_satoshis,
7661
- channel_keys_id,
7662
- holder_signer,
7663
- pubkeys,
7664
- logger,
7665
- )?,
7666
- unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 }
7654
+ let context = ChannelContext::new_for_outbound_channel(
7655
+ fee_estimator,
7656
+ entropy_source,
7657
+ signer_provider,
7658
+ counterparty_node_id,
7659
+ their_features,
7660
+ channel_value_satoshis,
7661
+ push_msat,
7662
+ user_id,
7663
+ config,
7664
+ current_chain_height,
7665
+ outbound_scid_alias,
7666
+ temporary_channel_id,
7667
+ holder_selected_channel_reserve_satoshis,
7668
+ channel_keys_id,
7669
+ holder_signer,
7670
+ pubkeys,
7671
+ logger,
7672
+ )?;
7673
+ let unfunded_context = UnfundedChannelContext {
7674
+ unfunded_channel_age_ticks: 0,
7675
+ holder_commitment_point: HolderCommitmentPoint::new(&context.holder_signer, &context.secp_ctx),
7667
7676
};
7677
+
7678
+ let chan = Self { context, unfunded_context };
7668
7679
Ok(chan)
7669
7680
}
7670
7681
@@ -8020,29 +8031,31 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8020
8031
htlc_basepoint: HtlcBasepoint::from(msg.common_fields.htlc_basepoint)
8021
8032
};
8022
8033
8023
- let chan = Self {
8024
- context: ChannelContext::new_for_inbound_channel(
8025
- fee_estimator ,
8026
- entropy_source ,
8027
- signer_provider ,
8028
- counterparty_node_id ,
8029
- their_features ,
8030
- user_id ,
8031
- config ,
8032
- current_chain_height ,
8033
- &&logger ,
8034
- is_0conf ,
8035
- 0 ,
8036
-
8037
- counterparty_pubkeys ,
8038
- channel_type ,
8039
- holder_selected_channel_reserve_satoshis ,
8040
- msg.channel_reserve_satoshis ,
8041
- msg.push_msat,
8042
- msg.common_fields.clone(),
8043
- )? ,
8044
- unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 }
8034
+ let context = ChannelContext::new_for_inbound_channel(
8035
+ fee_estimator,
8036
+ entropy_source ,
8037
+ signer_provider ,
8038
+ counterparty_node_id ,
8039
+ their_features ,
8040
+ user_id ,
8041
+ config ,
8042
+ current_chain_height ,
8043
+ &&logger ,
8044
+ is_0conf ,
8045
+ 0 ,
8046
+ counterparty_pubkeys ,
8047
+ channel_type,
8048
+ holder_selected_channel_reserve_satoshis ,
8049
+ msg.channel_reserve_satoshis ,
8050
+ msg.push_msat ,
8051
+ msg.common_fields.clone() ,
8052
+ )?;
8053
+ let unfunded_context = UnfundedChannelContext {
8054
+ unfunded_channel_age_ticks: 0 ,
8055
+ holder_commitment_point: HolderCommitmentPoint::new(&context.holder_signer, &context.secp_ctx),
8045
8056
};
8057
+
8058
+ let chan = Self { context, unfunded_context };
8046
8059
Ok(chan)
8047
8060
}
8048
8061
0 commit comments