@@ -536,15 +536,15 @@ pub(super) struct Channel<Signer: Sign> {
536536 #[ cfg( not( test) ) ]
537537 closing_fee_limits : Option < ( u64 , u64 ) > ,
538538
539- /// Flag that ensures that the `get_accept_channel ` function must be called before the
539+ /// Flag that ensures that the `accept_inbound_channel ` function must be called before the
540540 /// `funding_created` function is executed successfully. The reason for this flag is that
541541 /// when the util::config::UserConfig.manually_accept_inbound_channels is set to true,
542542 /// inbound channels are required to be manually accepted by the node operator before the
543- /// `SendAcceptChannel` message is created and sent out. The `get_accept_channel ` function is
543+ /// `SendAcceptChannel` message is created and sent out. The `accept_inbound_channel ` function is
544544 /// called during that process.
545545 /// A counterparty node could theoretically send a `FundingCreated` message before the node
546546 /// operator has accepted the inbound channel. That would would execute the `funding_created`
547- /// function before the `get_accept_channel ` function, and should therefore be rejected.
547+ /// function before the `accept_inbound_channel ` function, and should therefore be rejected.
548548 inbound_awaiting_accept : bool ,
549549
550550 /// The hash of the block in which the funding transaction was included.
@@ -4526,7 +4526,11 @@ impl<Signer: Sign> Channel<Signer> {
45264526 self . inbound_awaiting_accept
45274527 }
45284528
4529- pub fn get_accept_channel ( & mut self ) -> msgs:: AcceptChannel {
4529+ /// Marks an inbound channel as accepted and generates a [`msgs::AcceptChannel`] message which
4530+ /// should be sent back to the counterparty node.
4531+ ///
4532+ /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
4533+ pub fn accept_inbound_channel ( & mut self ) -> msgs:: AcceptChannel {
45304534 if self . is_outbound ( ) {
45314535 panic ! ( "Tried to send accept_channel for an outbound channel?" ) ;
45324536 }
@@ -4536,9 +4540,21 @@ impl<Signer: Sign> Channel<Signer> {
45364540 if self . cur_holder_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER {
45374541 panic ! ( "Tried to send an accept_channel for a channel that has already advanced" ) ;
45384542 }
4543+ if !self . inbound_awaiting_accept {
4544+ panic ! ( "The inbound channel has already been accepted" ) ;
4545+ }
45394546
45404547 self . inbound_awaiting_accept = false ;
45414548
4549+ return self . get_accept_channel_message ( ) ;
4550+ }
4551+
4552+ /// This function is used to explicitly generate a [`msgs::AcceptChannel`] message for an
4553+ /// inbound channel. If the intention is to accept an inbound channel, you should use the
4554+ /// [`Channel::accept_inbound_channel`] function instead.
4555+ ///
4556+ /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel
4557+ pub fn get_accept_channel_message ( & self ) -> msgs:: AcceptChannel {
45424558 let first_per_commitment_point = self . holder_signer . get_per_commitment_point ( self . cur_holder_commitment_transaction_number , & self . secp_ctx ) ;
45434559 let keys = self . get_holder_pubkeys ( ) ;
45444560
@@ -6079,7 +6095,7 @@ mod tests {
60796095 let mut node_b_chan = Channel :: < EnforcingSigner > :: new_from_req ( & & feeest, & & keys_provider, node_b_node_id, & InitFeatures :: known ( ) , & open_channel_msg, 7 , & config, 0 , & & logger) . unwrap ( ) ;
60806096
60816097 // Node B --> Node A: accept channel, explicitly setting B's dust limit.
6082- let mut accept_channel_msg = node_b_chan. get_accept_channel ( ) ;
6098+ let mut accept_channel_msg = node_b_chan. accept_inbound_channel ( ) ;
60836099 accept_channel_msg. dust_limit_satoshis = 546 ;
60846100 node_a_chan. accept_channel ( & accept_channel_msg, & config, & InitFeatures :: known ( ) ) . unwrap ( ) ;
60856101 node_a_chan. holder_dust_limit_satoshis = 1560 ;
@@ -6197,7 +6213,7 @@ mod tests {
61976213 let mut node_b_chan = Channel :: < EnforcingSigner > :: new_from_req ( & & feeest, & & keys_provider, node_b_node_id, & InitFeatures :: known ( ) , & open_channel_msg, 7 , & config, 0 , & & logger) . unwrap ( ) ;
61986214
61996215 // Node B --> Node A: accept channel
6200- let accept_channel_msg = node_b_chan. get_accept_channel ( ) ;
6216+ let accept_channel_msg = node_b_chan. accept_inbound_channel ( ) ;
62016217 node_a_chan. accept_channel ( & accept_channel_msg, & config, & InitFeatures :: known ( ) ) . unwrap ( ) ;
62026218
62036219 // Node A --> Node B: funding created
0 commit comments