Skip to content

Commit 41eb3b2

Browse files
committed
Incorporate feedback from dunxen's review.
- Rename the `UnacceptedInboundV1Channel` struct to `InboundChannelRequest`, as it may be used for both V1 and V2 channels. - Similarlly, rename the `unaccepted_inbound_v1_channel_by_id` table to `inbound_channel_request_by_id` - Verify that _no_ channel close event got generated when a request was rejected.
1 parent 96f52f5 commit 41eb3b2

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

lightning/src/ln/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6027,7 +6027,7 @@ pub(super) struct InboundV1Channel<Signer: ChannelSigner> {
60276027
/// A not-yet-accepted inbound (from counterparty) channel using V1
60286028
/// channel establishment. Once accepted, the parameters will be used
60296029
/// to construct a channel.
6030-
pub(super) struct UnacceptedInboundV1Channel {
6030+
pub(super) struct InboundChannelRequest {
60316031
/// The counterparty node id that initiated the channel open.
60326032
pub counterparty_node_id: PublicKey,
60336033
/// The original OpenChannel message.

lightning/src/ln/channelmanager.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::events::{Event, EventHandler, EventsProvider, MessageSendEvent, Messa
4040
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
4141
// construct one themselves.
4242
use crate::ln::{inbound_payment, PaymentHash, PaymentPreimage, PaymentSecret};
43-
use crate::ln::channel::{Channel, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, UnacceptedInboundV1Channel};
43+
use crate::ln::channel::{Channel, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundChannelRequest, InboundV1Channel};
4444
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
4545
#[cfg(any(feature = "_test_utils", test))]
4646
use crate::ln::features::Bolt11InvoiceFeatures;
@@ -638,7 +638,7 @@ pub(super) struct PeerState<Signer: ChannelSigner> {
638638
/// `temporary_channel_id` -> `UnacceptedInboundV1Channel`.
639639
///
640640
/// Holds all unaccepted inbound V1 channels where the peer is the counterparty.
641-
pub(super) unaccepted_inbound_v1_channel_by_id: HashMap<[u8; 32], UnacceptedInboundV1Channel>,
641+
pub(super) inbound_channel_request_by_id: HashMap<[u8; 32], InboundChannelRequest>,
642642
/// The latest `InitFeatures` we heard from the peer.
643643
latest_features: InitFeatures,
644644
/// Messages to send to the peer - pushed to in the same lock that they are generated in (except
@@ -694,7 +694,7 @@ impl <Signer: ChannelSigner> PeerState<Signer> {
694694
self.channel_by_id.len() +
695695
self.outbound_v1_channel_by_id.len() +
696696
self.inbound_v1_channel_by_id.len() +
697-
self.unaccepted_inbound_v1_channel_by_id.len()
697+
self.inbound_channel_request_by_id.len()
698698
}
699699

700700
// Returns a bool indicating if the given `channel_id` matches a channel we have with this peer.
@@ -2564,7 +2564,7 @@ where
25642564
self.finish_force_close_channel(chan.context.force_shutdown(false));
25652565
// Unfunded channel has no update
25662566
(None, chan.context.get_counterparty_node_id())
2567-
} else if let Some(chan) = peer_state.unaccepted_inbound_v1_channel_by_id.remove(channel_id) {
2567+
} else if let Some(chan) = peer_state.inbound_channel_request_by_id.remove(channel_id) {
25682568
log_error!(self.logger, "Force-closing channel {}", log_bytes!(channel_id[..]));
25692569
// N.B. that we don't send any channel close event here: we
25702570
// don't have a user_channel_id, and we never sent any opening
@@ -5190,7 +5190,7 @@ where
51905190

51915191
// Find (and remove) the channel in the unaccepted table. If it's
51925192
// not there, something weird is happening and return an error.
5193-
let mut channel = match peer_state.unaccepted_inbound_v1_channel_by_id.remove(temporary_channel_id) {
5193+
let mut channel = match peer_state.inbound_channel_request_by_id.remove(temporary_channel_id) {
51945194
Some(unaccepted_channel) => {
51955195
let best_block_height = self.best_block.read().unwrap().height();
51965196
InboundV1Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider,
@@ -5279,7 +5279,7 @@ where
52795279
num_unfunded_channels += 1;
52805280
}
52815281
}
5282-
num_unfunded_channels + peer.unaccepted_inbound_v1_channel_by_id.len()
5282+
num_unfunded_channels + peer.inbound_channel_request_by_id.len()
52835283
}
52845284

52855285
fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: &msgs::OpenChannel) -> Result<(), MsgHandleErrInternal> {
@@ -5347,7 +5347,7 @@ where
53475347
push_msat: msg.push_msat,
53485348
channel_type: msg.channel_type.clone().unwrap(),
53495349
}, None));
5350-
peer_state.unaccepted_inbound_v1_channel_by_id.insert(channel_id, UnacceptedInboundV1Channel {
5350+
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
53515351
counterparty_node_id: *counterparty_node_id,
53525352
open_channel_msg: msg.clone(),
53535353
outbound_scid_alias: outbound_scid_alias,
@@ -7293,7 +7293,7 @@ where
72937293
channel_by_id: HashMap::new(),
72947294
outbound_v1_channel_by_id: HashMap::new(),
72957295
inbound_v1_channel_by_id: HashMap::new(),
7296-
unaccepted_inbound_v1_channel_by_id: HashMap::new(),
7296+
inbound_channel_request_by_id: HashMap::new(),
72977297
latest_features: init_msg.features.clone(),
72987298
pending_msg_events: Vec::new(),
72997299
in_flight_monitor_updates: BTreeMap::new(),
@@ -8488,7 +8488,7 @@ where
84888488
channel_by_id,
84898489
outbound_v1_channel_by_id: HashMap::new(),
84908490
inbound_v1_channel_by_id: HashMap::new(),
8491-
unaccepted_inbound_v1_channel_by_id: HashMap::new(),
8491+
inbound_channel_request_by_id: HashMap::new(),
84928492
latest_features: InitFeatures::empty(),
84938493
pending_msg_events: Vec::new(),
84948494
in_flight_monitor_updates: BTreeMap::new(),
@@ -10210,8 +10210,9 @@ mod tests {
1021010210
let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
1021110211
assert!(!open_channel_msg.channel_type.unwrap().supports_anchors_zero_fee_htlc_tx());
1021210212

10213-
// Since we never created a InboundV1Channel object, we cannot generate close event.
10214-
//check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed);
10213+
// Since nodes[1] should not have accepted the channel, it should
10214+
// not have generated any events.
10215+
assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
1021510216
}
1021610217

1021710218
#[test]

lightning/src/ln/functional_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7871,8 +7871,8 @@ fn test_manually_reject_inbound_channel_request() {
78717871
_ => panic!("Unexpected event"),
78727872
}
78737873

7874-
// If the channel was never opened, we cannot generate a closed event.
7875-
//check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed);
7874+
// There should be no more events to process, as the channel was never opened.
7875+
assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
78767876
}
78777877

78787878
#[ignore] // We cannot construct the accept message before creating the IncomingV1Channel object!

0 commit comments

Comments
 (0)