@@ -7761,6 +7761,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7761
7761
pub(super) struct InboundV1Channel<SP: Deref> where SP::Target: SignerProvider {
7762
7762
pub context: ChannelContext<SP>,
7763
7763
pub unfunded_context: UnfundedChannelContext,
7764
+ pub signer_pending_accept_channel: bool,
7764
7765
}
7765
7766
7766
7767
/// Fetches the [`ChannelTypeFeatures`] that will be used for a channel built from a given
@@ -7847,7 +7848,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
7847
7848
msg.push_msat,
7848
7849
msg.common_fields.clone(),
7849
7850
)?,
7850
- unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 }
7851
+ unfunded_context: UnfundedChannelContext { unfunded_channel_age_ticks: 0 },
7852
+ signer_pending_accept_channel: false,
7851
7853
};
7852
7854
Ok(chan)
7853
7855
}
@@ -7856,7 +7858,9 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
7856
7858
/// should be sent back to the counterparty node.
7857
7859
///
7858
7860
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
7859
- pub fn accept_inbound_channel(&mut self) -> msgs::AcceptChannel {
7861
+ pub fn accept_inbound_channel<L: Deref>(&mut self, logger: &L) -> Option<msgs::AcceptChannel>
7862
+ where L::Target: Logger
7863
+ {
7860
7864
if self.context.is_outbound() {
7861
7865
panic!("Tried to send accept_channel for an outbound channel?");
7862
7866
}
@@ -7870,20 +7874,31 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
7870
7874
panic!("Tried to send an accept_channel for a channel that has already advanced");
7871
7875
}
7872
7876
7873
- self.generate_accept_channel_message()
7877
+ self.generate_accept_channel_message(logger )
7874
7878
}
7875
7879
7876
7880
/// This function is used to explicitly generate a [`msgs::AcceptChannel`] message for an
7877
7881
/// inbound channel. If the intention is to accept an inbound channel, use
7878
7882
/// [`InboundV1Channel::accept_inbound_channel`] instead.
7879
7883
///
7880
7884
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
7881
- fn generate_accept_channel_message(&self) -> msgs::AcceptChannel {
7882
- debug_assert!(self.context.holder_commitment_point.is_available());
7883
- let first_per_commitment_point = self.context.holder_commitment_point.current_point().expect("TODO");
7885
+ fn generate_accept_channel_message<L: Deref>(&mut self, logger: &L) -> Option<msgs::AcceptChannel>
7886
+ where L::Target: Logger
7887
+ {
7888
+ // Note: another option here is to make commitment point a parameter of this function
7889
+ // and make a helper method get_point_for_open_channel to check + set signer_pending_open_channel
7890
+ // and call that right before anytime we call this function, so this function can remain
7891
+ // side-effect free.
7892
+ let first_per_commitment_point = if let Some(point) = self.context.holder_commitment_point.current_point() {
7893
+ point
7894
+ } else {
7895
+ log_trace!(logger, "Unable to generate accept_channel message, waiting for commitment point");
7896
+ self.signer_pending_accept_channel = true;
7897
+ return None;
7898
+ };
7884
7899
let keys = self.context.get_holder_pubkeys();
7885
7900
7886
- msgs::AcceptChannel {
7901
+ Some( msgs::AcceptChannel {
7887
7902
common_fields: msgs::CommonAcceptChannelFields {
7888
7903
temporary_channel_id: self.context.channel_id,
7889
7904
dust_limit_satoshis: self.context.holder_dust_limit_satoshis,
@@ -7907,16 +7922,18 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
7907
7922
channel_reserve_satoshis: self.context.holder_selected_channel_reserve_satoshis,
7908
7923
#[cfg(taproot)]
7909
7924
next_local_nonce: None,
7910
- }
7925
+ })
7911
7926
}
7912
7927
7913
7928
/// Enables the possibility for tests to extract a [`msgs::AcceptChannel`] message for an
7914
7929
/// inbound channel without accepting it.
7915
7930
///
7916
7931
/// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
7917
7932
#[cfg(test)]
7918
- pub fn get_accept_channel_message(&self) -> msgs::AcceptChannel {
7919
- self.generate_accept_channel_message()
7933
+ pub fn get_accept_channel_message<L: Deref>(&mut self, logger: &L) -> Option<msgs::AcceptChannel>
7934
+ where L::Target: Logger
7935
+ {
7936
+ self.generate_accept_channel_message(logger)
7920
7937
}
7921
7938
7922
7939
fn check_funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<CommitmentTransaction, ChannelError> where L::Target: Logger {
@@ -9557,7 +9574,7 @@ mod tests {
9557
9574
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();
9558
9575
9559
9576
// Node B --> Node A: accept channel, explicitly setting B's dust limit.
9560
- let mut accept_channel_msg = node_b_chan.accept_inbound_channel();
9577
+ let mut accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
9561
9578
accept_channel_msg.common_fields.dust_limit_satoshis = 546;
9562
9579
node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap();
9563
9580
node_a_chan.context.holder_dust_limit_satoshis = 1560;
@@ -9689,7 +9706,7 @@ mod tests {
9689
9706
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();
9690
9707
9691
9708
// Node B --> Node A: accept channel
9692
- let accept_channel_msg = node_b_chan.accept_inbound_channel();
9709
+ let accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
9693
9710
node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap();
9694
9711
9695
9712
// Node A --> Node B: funding created
@@ -9876,7 +9893,7 @@ mod tests {
9876
9893
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();
9877
9894
9878
9895
// Node B --> Node A: accept channel, explicitly setting B's dust limit.
9879
- let mut accept_channel_msg = node_b_chan.accept_inbound_channel();
9896
+ let mut accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
9880
9897
accept_channel_msg.common_fields.dust_limit_satoshis = 546;
9881
9898
node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap();
9882
9899
node_a_chan.context.holder_dust_limit_satoshis = 1560;
@@ -9945,11 +9962,11 @@ mod tests {
9945
9962
let mut outbound_chan = OutboundV1Channel::<&TestKeysInterface>::new(
9946
9963
&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &features, 10000000, 100000, 42, &config, 0, 42, None, &&logger
9947
9964
).unwrap();
9948
- let inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
9965
+ let mut inbound_chan = InboundV1Channel::<&TestKeysInterface>::new(
9949
9966
&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config),
9950
9967
&features, &outbound_chan.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap(), 7, &config, 0, &&logger, false
9951
9968
).unwrap();
9952
- outbound_chan.accept_channel(&inbound_chan.get_accept_channel_message(), &config.channel_handshake_limits, &features).unwrap();
9969
+ outbound_chan.accept_channel(&inbound_chan.get_accept_channel_message(&&logger).unwrap( ), &config.channel_handshake_limits, &features).unwrap();
9953
9970
let tx = Transaction { version: Version::ONE, lock_time: LockTime::ZERO, input: Vec::new(), output: vec![TxOut {
9954
9971
value: Amount::from_sat(10000000), script_pubkey: outbound_chan.context.get_funding_redeemscript(),
9955
9972
}]};
@@ -10999,13 +11016,13 @@ mod tests {
10999
11016
11000
11017
let open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
11001
11018
11002
- let channel_b = InboundV1Channel::<&TestKeysInterface>::new(
11019
+ let mut channel_b = InboundV1Channel::<&TestKeysInterface>::new(
11003
11020
&fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
11004
11021
&channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config),
11005
11022
&open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
11006
11023
).unwrap();
11007
11024
11008
- let mut accept_channel_msg = channel_b.get_accept_channel_message();
11025
+ let mut accept_channel_msg = channel_b.get_accept_channel_message(&&logger).unwrap( );
11009
11026
accept_channel_msg.common_fields.channel_type = Some(simple_anchors_channel_type.clone());
11010
11027
11011
11028
let res = channel_a.accept_channel(
@@ -11065,7 +11082,7 @@ mod tests {
11065
11082
true, // Allow node b to send a 0conf channel_ready.
11066
11083
).unwrap();
11067
11084
11068
- let accept_channel_msg = node_b_chan.accept_inbound_channel();
11085
+ let accept_channel_msg = node_b_chan.accept_inbound_channel(&&logger).unwrap( );
11069
11086
node_a_chan.accept_channel(
11070
11087
&accept_channel_msg,
11071
11088
&config.channel_handshake_limits,
0 commit comments