@@ -7917,6 +7917,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7917
7917
pub(super) struct InboundV1Channel<SP: Deref> where SP::Target: SignerProvider {
7918
7918
pub context: ChannelContext<SP>,
7919
7919
pub unfunded_context: UnfundedChannelContext,
7920
+ pub signer_pending_accept_channel: bool,
7920
7921
}
7921
7922
7922
7923
/// Fetches the [`ChannelTypeFeatures`] that will be used for a channel built from a given
@@ -8003,7 +8004,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8003
8004
msg.push_msat,
8004
8005
msg.common_fields.clone(),
8005
8006
)?,
8006
- unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 }
8007
+ unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 },
8008
+ signer_pending_accept_channel: false,
8007
8009
};
8008
8010
Ok(chan)
8009
8011
}
@@ -8012,7 +8014,9 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8012
8014
/// should be sent back to the counterparty node.
8013
8015
///
8014
8016
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
8015
- pub fn accept_inbound_channel(&mut self) -> msgs::AcceptChannel {
8017
+ pub fn accept_inbound_channel<L: Deref>(&mut self, logger: &L) -> Option<msgs::AcceptChannel>
8018
+ where L::Target: Logger
8019
+ {
8016
8020
if self.context.is_outbound() {
8017
8021
panic!("Tried to send accept_channel for an outbound channel?");
8018
8022
}
@@ -8026,20 +8030,36 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8026
8030
panic!("Tried to send an accept_channel for a channel that has already advanced");
8027
8031
}
8028
8032
8029
- self.generate_accept_channel_message()
8033
+ self.generate_accept_channel_message(logger )
8030
8034
}
8031
8035
8032
8036
/// This function is used to explicitly generate a [`msgs::AcceptChannel`] message for an
8033
8037
/// inbound channel. If the intention is to accept an inbound channel, use
8034
8038
/// [`InboundV1Channel::accept_inbound_channel`] instead.
8035
8039
///
8036
8040
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
8037
- fn generate_accept_channel_message(&self) -> msgs::AcceptChannel {
8038
- debug_assert!(self.context.holder_commitment_point.is_available());
8039
- let first_per_commitment_point = self.context.holder_commitment_point.current_point().expect("TODO");
8041
+ fn generate_accept_channel_message<L: Deref>(&mut self, logger: &L) -> Option<msgs::AcceptChannel>
8042
+ where L::Target: Logger
8043
+ {
8044
+ // Note: another option here is to make commitment point a parameter of this function
8045
+ // and make a helper method get_point_for_open_channel to check + set signer_pending_open_channel
8046
+ // and call that right before anytime we call this function, so this function can remain
8047
+ // side-effect free.
8048
+ let first_per_commitment_point = if let Some(point) = self.context.holder_commitment_point.current_point() {
8049
+ point
8050
+ } else {
8051
+ #[cfg(not(async_signing))] {
8052
+ panic!("Failed getting commitment point for accept_channel message");
8053
+ }
8054
+ #[cfg(async_signing)] {
8055
+ log_trace!(logger, "Unable to generate accept_channel message, waiting for commitment point");
8056
+ self.signer_pending_accept_channel = true;
8057
+ return None;
8058
+ }
8059
+ };
8040
8060
let keys = self.context.get_holder_pubkeys();
8041
8061
8042
- msgs::AcceptChannel {
8062
+ Some( msgs::AcceptChannel {
8043
8063
common_fields: msgs::CommonAcceptChannelFields {
8044
8064
temporary_channel_id: self.context.channel_id,
8045
8065
dust_limit_satoshis: self.context.holder_dust_limit_satoshis,
@@ -8063,16 +8083,18 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8063
8083
channel_reserve_satoshis: self.context.holder_selected_channel_reserve_satoshis,
8064
8084
#[cfg(taproot)]
8065
8085
next_local_nonce: None,
8066
- }
8086
+ })
8067
8087
}
8068
8088
8069
8089
/// Enables the possibility for tests to extract a [`msgs::AcceptChannel`] message for an
8070
8090
/// inbound channel without accepting it.
8071
8091
///
8072
8092
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
8073
8093
#[cfg(test)]
8074
- pub fn get_accept_channel_message(&self) -> msgs::AcceptChannel {
8075
- self.generate_accept_channel_message()
8094
+ pub fn get_accept_channel_message<L: Deref>(&mut self, logger: &L) -> Option<msgs::AcceptChannel>
8095
+ where L::Target: Logger
8096
+ {
8097
+ self.generate_accept_channel_message(logger)
8076
8098
}
8077
8099
8078
8100
fn check_funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<CommitmentTransaction, ChannelError> where L::Target: Logger {
@@ -9716,7 +9738,7 @@ mod tests {
9716
9738
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();
9717
9739
9718
9740
// Node B --> Node A: accept channel, explicitly setting B's dust limit.
9719
- let mut accept_channel_msg = node_b_chan.accept_inbound_channel();
9741
+ let mut accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
9720
9742
accept_channel_msg.common_fields.dust_limit_satoshis = 546;
9721
9743
node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap();
9722
9744
node_a_chan.context.holder_dust_limit_satoshis = 1560;
@@ -9848,7 +9870,7 @@ mod tests {
9848
9870
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();
9849
9871
9850
9872
// Node B --> Node A: accept channel
9851
- let accept_channel_msg = node_b_chan.accept_inbound_channel();
9873
+ let accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
9852
9874
node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap();
9853
9875
9854
9876
// Node A --> Node B: funding created
@@ -10035,7 +10057,7 @@ mod tests {
10035
10057
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();
10036
10058
10037
10059
// Node B --> Node A: accept channel, explicitly setting B's dust limit.
10038
- let mut accept_channel_msg = node_b_chan.accept_inbound_channel();
10060
+ let mut accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
10039
10061
accept_channel_msg.common_fields.dust_limit_satoshis = 546;
10040
10062
node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap();
10041
10063
node_a_chan.context.holder_dust_limit_satoshis = 1560;
@@ -10104,11 +10126,11 @@ mod tests {
10104
10126
let mut outbound_chan = OutboundV1Channel::<&TestKeysInterface>::new(
10105
10127
&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &features, 10000000, 100000, 42, &config, 0, 42, None, &&logger
10106
10128
).unwrap();
10107
- let inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
10129
+ let mut inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
10108
10130
&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config),
10109
10131
&features, &outbound_chan.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap(), 7, &config, 0, &&logger, false
10110
10132
).unwrap();
10111
- outbound_chan.accept_channel(&inbound_chan.get_accept_channel_message(), &config.channel_handshake_limits, &features).unwrap();
10133
+ outbound_chan.accept_channel(&inbound_chan.get_accept_channel_message(&&logger).unwrap( ), &config.channel_handshake_limits, &features).unwrap();
10112
10134
let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
10113
10135
value: Amount::from_sat(10000000), script_pubkey: outbound_chan.context.get_funding_redeemscript(),
10114
10136
}]};
@@ -11158,13 +11180,13 @@ mod tests {
11158
11180
11159
11181
let open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
11160
11182
11161
- let channel_b = InboundV1Channel::<&TestKeysInterface>::new(
11183
+ let mut channel_b = InboundV1Channel::<&TestKeysInterface>::new(
11162
11184
&fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
11163
11185
&channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config),
11164
11186
&open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
11165
11187
).unwrap();
11166
11188
11167
- let mut accept_channel_msg = channel_b.get_accept_channel_message();
11189
+ let mut accept_channel_msg = channel_b.get_accept_channel_message(&&logger).unwrap( );
11168
11190
accept_channel_msg.common_fields.channel_type = Some(simple_anchors_channel_type.clone());
11169
11191
11170
11192
let res = channel_a.accept_channel(
@@ -11224,7 +11246,7 @@ mod tests {
11224
11246
true, // Allow node b to send a 0conf channel_ready.
11225
11247
).unwrap();
11226
11248
11227
- let accept_channel_msg = node_b_chan.accept_inbound_channel();
11249
+ let accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
11228
11250
node_a_chan.accept_channel(
11229
11251
&accept_channel_msg,
11230
11252
&config.channel_handshake_limits,
0 commit comments