@@ -536,15 +536,15 @@ pub(super) struct Channel<Signer: Sign> {
536
536
#[ cfg( not( test) ) ]
537
537
closing_fee_limits : Option < ( u64 , u64 ) > ,
538
538
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
540
540
/// `funding_created` function is executed successfully. The reason for this flag is that
541
541
/// when the util::config::UserConfig.manually_accept_inbound_channels is set to true,
542
542
/// 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
544
544
/// called during that process.
545
545
/// A counterparty node could theoretically send a `FundingCreated` message before the node
546
546
/// 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.
548
548
inbound_awaiting_accept : bool ,
549
549
550
550
/// The hash of the block in which the funding transaction was included.
@@ -4526,7 +4526,11 @@ impl<Signer: Sign> Channel<Signer> {
4526
4526
self . inbound_awaiting_accept
4527
4527
}
4528
4528
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 {
4530
4534
if self . is_outbound ( ) {
4531
4535
panic ! ( "Tried to send accept_channel for an outbound channel?" ) ;
4532
4536
}
@@ -4536,9 +4540,22 @@ impl<Signer: Sign> Channel<Signer> {
4536
4540
if self . cur_holder_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER {
4537
4541
panic ! ( "Tried to send an accept_channel for a channel that has already advanced" ) ;
4538
4542
}
4543
+ if !self . inbound_awaiting_accept {
4544
+ panic ! ( "The inbound channel has already been accepted" ) ;
4545
+ }
4539
4546
4540
4547
self . inbound_awaiting_accept = false ;
4541
4548
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
+ /// [`Channel::accept_inbound_channel`]: crate::ln::channel::Channel::accept_inbound_channel
4558
+ pub fn get_accept_channel_message ( & self ) -> msgs:: AcceptChannel {
4542
4559
let first_per_commitment_point = self . holder_signer . get_per_commitment_point ( self . cur_holder_commitment_transaction_number , & self . secp_ctx ) ;
4543
4560
let keys = self . get_holder_pubkeys ( ) ;
4544
4561
@@ -6079,7 +6096,7 @@ mod tests {
6079
6096
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 ( ) ;
6080
6097
6081
6098
// Node B --> Node A: accept channel, explicitly setting B's dust limit.
6082
- let mut accept_channel_msg = node_b_chan. get_accept_channel ( ) ;
6099
+ let mut accept_channel_msg = node_b_chan. accept_inbound_channel ( ) ;
6083
6100
accept_channel_msg. dust_limit_satoshis = 546 ;
6084
6101
node_a_chan. accept_channel ( & accept_channel_msg, & config, & InitFeatures :: known ( ) ) . unwrap ( ) ;
6085
6102
node_a_chan. holder_dust_limit_satoshis = 1560 ;
@@ -6197,7 +6214,7 @@ mod tests {
6197
6214
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 ( ) ;
6198
6215
6199
6216
// Node B --> Node A: accept channel
6200
- let accept_channel_msg = node_b_chan. get_accept_channel ( ) ;
6217
+ let accept_channel_msg = node_b_chan. accept_inbound_channel ( ) ;
6201
6218
node_a_chan. accept_channel ( & accept_channel_msg, & config, & InitFeatures :: known ( ) ) . unwrap ( ) ;
6202
6219
6203
6220
// Node A --> Node B: funding created
0 commit comments