@@ -7851,6 +7851,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7851
7851
pub(super) struct InboundV1Channel<SP: Deref> where SP::Target: SignerProvider {
7852
7852
pub context: ChannelContext<SP>,
7853
7853
pub unfunded_context: UnfundedChannelContext,
7854
+ pub signer_pending_accept_channel: bool,
7854
7855
}
7855
7856
7856
7857
/// Fetches the [`ChannelTypeFeatures`] that will be used for a channel built from a given
@@ -7937,7 +7938,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
7937
7938
msg.push_msat,
7938
7939
msg.common_fields.clone(),
7939
7940
)?,
7940
- unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 }
7941
+ unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 },
7942
+ signer_pending_accept_channel: false,
7941
7943
};
7942
7944
Ok(chan)
7943
7945
}
@@ -7946,7 +7948,9 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
7946
7948
/// should be sent back to the counterparty node.
7947
7949
///
7948
7950
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
7949
- pub fn accept_inbound_channel(&mut self) -> msgs::AcceptChannel {
7951
+ pub fn accept_inbound_channel<L: Deref>(&mut self, logger: &L) -> Option<msgs::AcceptChannel>
7952
+ where L::Target: Logger
7953
+ {
7950
7954
if self.context.is_outbound() {
7951
7955
panic!("Tried to send accept_channel for an outbound channel?");
7952
7956
}
@@ -7960,20 +7964,36 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
7960
7964
panic!("Tried to send an accept_channel for a channel that has already advanced");
7961
7965
}
7962
7966
7963
- self.generate_accept_channel_message()
7967
+ self.generate_accept_channel_message(logger )
7964
7968
}
7965
7969
7966
7970
/// This function is used to explicitly generate a [`msgs::AcceptChannel`] message for an
7967
7971
/// inbound channel. If the intention is to accept an inbound channel, use
7968
7972
/// [`InboundV1Channel::accept_inbound_channel`] instead.
7969
7973
///
7970
7974
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
7971
- fn generate_accept_channel_message(&self) -> msgs::AcceptChannel {
7972
- debug_assert!(self.context.holder_commitment_point.is_available());
7973
- let first_per_commitment_point = self.context.holder_commitment_point.current_point().expect("TODO");
7975
+ fn generate_accept_channel_message<L: Deref>(&mut self, logger: &L) -> Option<msgs::AcceptChannel>
7976
+ where L::Target: Logger
7977
+ {
7978
+ // Note: another option here is to make commitment point a parameter of this function
7979
+ // and make a helper method get_point_for_open_channel to check + set signer_pending_open_channel
7980
+ // and call that right before anytime we call this function, so this function can remain
7981
+ // side-effect free.
7982
+ let first_per_commitment_point = if let Some(point) = self.context.holder_commitment_point.current_point() {
7983
+ point
7984
+ } else {
7985
+ #[cfg(not(async_signing))] {
7986
+ panic!("Failed getting commitment point for accept_channel message");
7987
+ }
7988
+ #[cfg(async_signing)] {
7989
+ log_trace!(logger, "Unable to generate accept_channel message, waiting for commitment point");
7990
+ self.signer_pending_accept_channel = true;
7991
+ return None;
7992
+ }
7993
+ };
7974
7994
let keys = self.context.get_holder_pubkeys();
7975
7995
7976
- msgs::AcceptChannel {
7996
+ Some( msgs::AcceptChannel {
7977
7997
common_fields: msgs::CommonAcceptChannelFields {
7978
7998
temporary_channel_id: self.context.channel_id,
7979
7999
dust_limit_satoshis: self.context.holder_dust_limit_satoshis,
@@ -7997,16 +8017,18 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
7997
8017
channel_reserve_satoshis: self.context.holder_selected_channel_reserve_satoshis,
7998
8018
#[cfg(taproot)]
7999
8019
next_local_nonce: None,
8000
- }
8020
+ })
8001
8021
}
8002
8022
8003
8023
/// Enables the possibility for tests to extract a [`msgs::AcceptChannel`] message for an
8004
8024
/// inbound channel without accepting it.
8005
8025
///
8006
8026
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
8007
8027
#[cfg(test)]
8008
- pub fn get_accept_channel_message(&self) -> msgs::AcceptChannel {
8009
- self.generate_accept_channel_message()
8028
+ pub fn get_accept_channel_message<L: Deref>(&mut self, logger: &L) -> Option<msgs::AcceptChannel>
8029
+ where L::Target: Logger
8030
+ {
8031
+ self.generate_accept_channel_message(logger)
8010
8032
}
8011
8033
8012
8034
fn check_funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<CommitmentTransaction, ChannelError> where L::Target: Logger {
@@ -9649,7 +9671,7 @@ mod tests {
9649
9671
let mut node_b_chan = InboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false).unwrap();
9650
9672
9651
9673
// Node B --> Node A: accept channel, explicitly setting B's dust limit.
9652
- let mut accept_channel_msg = node_b_chan.accept_inbound_channel();
9674
+ let mut accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
9653
9675
accept_channel_msg.common_fields.dust_limit_satoshis = 546;
9654
9676
node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap();
9655
9677
node_a_chan.context.holder_dust_limit_satoshis = 1560;
@@ -9781,7 +9803,7 @@ mod tests {
9781
9803
let mut node_b_chan = InboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false).unwrap();
9782
9804
9783
9805
// Node B --> Node A: accept channel
9784
- let accept_channel_msg = node_b_chan.accept_inbound_channel();
9806
+ let accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
9785
9807
node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap();
9786
9808
9787
9809
// Node A --> Node B: funding created
@@ -9968,7 +9990,7 @@ mod tests {
9968
9990
let mut node_b_chan = InboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false).unwrap();
9969
9991
9970
9992
// Node B --> Node A: accept channel, explicitly setting B's dust limit.
9971
- let mut accept_channel_msg = node_b_chan.accept_inbound_channel();
9993
+ let mut accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
9972
9994
accept_channel_msg.common_fields.dust_limit_satoshis = 546;
9973
9995
node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap();
9974
9996
node_a_chan.context.holder_dust_limit_satoshis = 1560;
@@ -10037,11 +10059,11 @@ mod tests {
10037
10059
let mut outbound_chan = OutboundV1Channel::<&TestKeysInterface>::new(
10038
10060
&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &features, 10000000, 100000, 42, &config, 0, 42, None, &&logger
10039
10061
).unwrap();
10040
- let inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
10062
+ let mut inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
10041
10063
&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config),
10042
10064
&features, &outbound_chan.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap(), 7, &config, 0, &&logger, false
10043
10065
).unwrap();
10044
- outbound_chan.accept_channel(&inbound_chan.get_accept_channel_message(), &config.channel_handshake_limits, &features).unwrap();
10066
+ outbound_chan.accept_channel(&inbound_chan.get_accept_channel_message(&&logger).unwrap( ), &config.channel_handshake_limits, &features).unwrap();
10045
10067
let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
10046
10068
value: Amount::from_sat(10000000), script_pubkey: outbound_chan.context.get_funding_redeemscript(),
10047
10069
}]};
@@ -11091,13 +11113,13 @@ mod tests {
11091
11113
11092
11114
let open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
11093
11115
11094
- let channel_b = InboundV1Channel::<&TestKeysInterface>::new(
11116
+ let mut channel_b = InboundV1Channel::<&TestKeysInterface>::new(
11095
11117
&fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
11096
11118
&channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config),
11097
11119
&open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
11098
11120
).unwrap();
11099
11121
11100
- let mut accept_channel_msg = channel_b.get_accept_channel_message();
11122
+ let mut accept_channel_msg = channel_b.get_accept_channel_message(&&logger).unwrap( );
11101
11123
accept_channel_msg.common_fields.channel_type = Some(simple_anchors_channel_type.clone());
11102
11124
11103
11125
let res = channel_a.accept_channel(
@@ -11157,7 +11179,7 @@ mod tests {
11157
11179
true, // Allow node b to send a 0conf channel_ready.
11158
11180
).unwrap();
11159
11181
11160
- let accept_channel_msg = node_b_chan.accept_inbound_channel();
11182
+ let accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
11161
11183
node_a_chan.accept_channel(
11162
11184
&accept_channel_msg,
11163
11185
&config.channel_handshake_limits,
0 commit comments