@@ -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.
@@ -7643,28 +7649,31 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7643
7649
let holder_signer = signer_provider.derive_channel_signer(channel_value_satoshis, channel_keys_id);
7644
7650
let pubkeys = holder_signer.pubkeys().clone();
7645
7651
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 }
7652
+ let context = ChannelContext::new_for_outbound_channel(
7653
+ fee_estimator,
7654
+ entropy_source,
7655
+ signer_provider,
7656
+ counterparty_node_id,
7657
+ their_features,
7658
+ channel_value_satoshis,
7659
+ push_msat,
7660
+ user_id,
7661
+ config,
7662
+ current_chain_height,
7663
+ outbound_scid_alias,
7664
+ temporary_channel_id,
7665
+ holder_selected_channel_reserve_satoshis,
7666
+ channel_keys_id,
7667
+ holder_signer,
7668
+ pubkeys,
7669
+ logger,
7670
+ )?;
7671
+ let unfunded_context = UnfundedChannelContext {
7672
+ unfunded_channel_age_ticks: 0,
7673
+ holder_commitment_point: HolderCommitmentPoint::new(&context.holder_signer, &context.secp_ctx),
7667
7674
};
7675
+
7676
+ let chan = Self { context, unfunded_context };
7668
7677
Ok(chan)
7669
7678
}
7670
7679
@@ -8020,29 +8029,31 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8020
8029
htlc_basepoint: HtlcBasepoint::from(msg.common_fields.htlc_basepoint)
8021
8030
};
8022
8031
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 }
8032
+ let context = ChannelContext::new_for_inbound_channel(
8033
+ fee_estimator,
8034
+ entropy_source ,
8035
+ signer_provider ,
8036
+ counterparty_node_id ,
8037
+ their_features ,
8038
+ user_id ,
8039
+ config ,
8040
+ current_chain_height ,
8041
+ &&logger ,
8042
+ is_0conf ,
8043
+ 0 ,
8044
+ counterparty_pubkeys ,
8045
+ channel_type,
8046
+ holder_selected_channel_reserve_satoshis ,
8047
+ msg.channel_reserve_satoshis ,
8048
+ msg.push_msat ,
8049
+ msg.common_fields.clone() ,
8050
+ )?;
8051
+ let unfunded_context = UnfundedChannelContext {
8052
+ unfunded_channel_age_ticks: 0 ,
8053
+ holder_commitment_point: HolderCommitmentPoint::new(&context.holder_signer, &context.secp_ctx),
8045
8054
};
8055
+
8056
+ let chan = Self { context, unfunded_context };
8046
8057
Ok(chan)
8047
8058
}
8048
8059
0 commit comments