@@ -9827,30 +9827,35 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
98279827 }
98289828
98299829 /// TODO(dual_funding): Allow contributions, pass intended amount and inputs
9830- #[rustfmt::skip]
98319830 fn do_accept_inbound_channel(
9832- &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool,
9833- user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>
9831+ &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey,
9832+ accept_0conf: bool, user_channel_id: u128,
9833+ config_overrides: Option<ChannelConfigOverrides>,
98349834 ) -> Result<(), APIError> {
9835-
98369835 let mut config = self.config.read().unwrap().clone();
98379836
98389837 // Apply configuration overrides.
98399838 if let Some(overrides) = config_overrides {
98409839 config.apply(&overrides);
98419840 };
98429841
9843- let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(*temporary_channel_id), None);
9842+ let logger = WithContext::from(
9843+ &self.logger,
9844+ Some(*counterparty_node_id),
9845+ Some(*temporary_channel_id),
9846+ None,
9847+ );
98449848 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
98459849
98469850 let peers_without_funded_channels =
9847- self.peers_without_funded_channels(|peer| { peer.total_channel_count() > 0 } );
9851+ self.peers_without_funded_channels(|peer| peer.total_channel_count() > 0);
98489852 let per_peer_state = self.per_peer_state.read().unwrap();
9849- let peer_state_mutex = per_peer_state.get(counterparty_node_id)
9850- .ok_or_else(|| {
9853+ let peer_state_mutex = per_peer_state.get(counterparty_node_id).ok_or_else(|| {
98519854 log_error!(logger, "Can't find peer matching the passed counterparty node_id");
98529855
9853- let err_str = format!("Can't find a peer matching the passed counterparty node_id {counterparty_node_id}");
9856+ let err_str = format!(
9857+ "Can't find a peer matching the passed counterparty node_id {counterparty_node_id}"
9858+ );
98549859 APIError::ChannelUnavailable { err: err_str }
98559860 })?;
98569861 let mut peer_state_lock = peer_state_mutex.lock().unwrap();
@@ -9865,50 +9870,71 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
98659870 Some(unaccepted_channel) => {
98669871 let best_block_height = self.best_block.read().unwrap().height;
98679872 match unaccepted_channel.open_channel_msg {
9868- OpenChannelMessage::V1(open_channel_msg) => {
9869- InboundV1Channel::new(
9870- &self.fee_estimator, &self.entropy_source, &self.signer_provider, *counterparty_node_id,
9871- &self.channel_type_features(), &peer_state.latest_features, &open_channel_msg,
9872- user_channel_id, &config, best_block_height, &self.logger, accept_0conf
9873- ).map_err(|err| MsgHandleErrInternal::from_chan_no_close(err, *temporary_channel_id)
9874- ).map(|mut channel| {
9875- let logger = WithChannelContext::from(&self.logger, &channel.context, None);
9876- let message_send_event = channel.accept_inbound_channel(&&logger).map(|msg| {
9873+ OpenChannelMessage::V1(open_channel_msg) => InboundV1Channel::new(
9874+ &self.fee_estimator,
9875+ &self.entropy_source,
9876+ &self.signer_provider,
9877+ *counterparty_node_id,
9878+ &self.channel_type_features(),
9879+ &peer_state.latest_features,
9880+ &open_channel_msg,
9881+ user_channel_id,
9882+ &config,
9883+ best_block_height,
9884+ &self.logger,
9885+ accept_0conf,
9886+ )
9887+ .map_err(|err| {
9888+ MsgHandleErrInternal::from_chan_no_close(err, *temporary_channel_id)
9889+ })
9890+ .map(|mut channel| {
9891+ let logger = WithChannelContext::from(&self.logger, &channel.context, None);
9892+ let message_send_event =
9893+ channel.accept_inbound_channel(&&logger).map(|msg| {
98779894 MessageSendEvent::SendAcceptChannel {
98789895 node_id: *counterparty_node_id,
98799896 msg,
98809897 }
98819898 });
9882- (*temporary_channel_id, Channel::from(channel), message_send_event)
9883- })
9884- },
9885- OpenChannelMessage::V2(open_channel_msg) => {
9886- PendingV2Channel::new_inbound(
9887- &self.fee_estimator, &self.entropy_source, &self.signer_provider,
9888- self.get_our_node_id(), *counterparty_node_id,
9889- &self.channel_type_features(), &peer_state.latest_features,
9890- &open_channel_msg,
9891- user_channel_id, &config, best_block_height,
9892- &self.logger,
9893- ).map_err(|e| {
9894- let channel_id = open_channel_msg.common_fields.temporary_channel_id;
9895- MsgHandleErrInternal::from_chan_no_close(e, channel_id)
9896- }).map(|channel| {
9897- let message_send_event = MessageSendEvent::SendAcceptChannelV2 {
9898- node_id: channel.context.get_counterparty_node_id(),
9899- msg: channel.accept_inbound_dual_funded_channel()
9900- };
9901- (channel.context.channel_id(), Channel::from(channel), Some(message_send_event))
9902- })
9903- },
9899+ (*temporary_channel_id, Channel::from(channel), message_send_event)
9900+ }),
9901+ OpenChannelMessage::V2(open_channel_msg) => PendingV2Channel::new_inbound(
9902+ &self.fee_estimator,
9903+ &self.entropy_source,
9904+ &self.signer_provider,
9905+ self.get_our_node_id(),
9906+ *counterparty_node_id,
9907+ &self.channel_type_features(),
9908+ &peer_state.latest_features,
9909+ &open_channel_msg,
9910+ user_channel_id,
9911+ &config,
9912+ best_block_height,
9913+ &self.logger,
9914+ )
9915+ .map_err(|e| {
9916+ let channel_id = open_channel_msg.common_fields.temporary_channel_id;
9917+ MsgHandleErrInternal::from_chan_no_close(e, channel_id)
9918+ })
9919+ .map(|channel| {
9920+ let message_send_event = MessageSendEvent::SendAcceptChannelV2 {
9921+ node_id: channel.context.get_counterparty_node_id(),
9922+ msg: channel.accept_inbound_dual_funded_channel(),
9923+ };
9924+ (
9925+ channel.context.channel_id(),
9926+ Channel::from(channel),
9927+ Some(message_send_event),
9928+ )
9929+ }),
99049930 }
99059931 },
99069932 None => {
99079933 let err_str = "No such channel awaiting to be accepted.".to_owned();
99089934 log_error!(logger, "{}", err_str);
99099935
99109936 return Err(APIError::APIMisuseError { err: err_str });
9911- }
9937+ },
99129938 };
99139939
99149940 // We have to match below instead of map_err on the above as in the map_err closure the borrow checker
@@ -9919,13 +9945,19 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
99199945 mem::drop(peer_state_lock);
99209946 mem::drop(per_peer_state);
99219947 // TODO(dunxen): Find/make less icky way to do this.
9922- match handle_error!(self, Result::<(), MsgHandleErrInternal>::Err(err), *counterparty_node_id) {
9923- Ok(_) => unreachable!("`handle_error` only returns Err as we've passed in an Err"),
9948+ match handle_error!(
9949+ self,
9950+ Result::<(), MsgHandleErrInternal>::Err(err),
9951+ *counterparty_node_id
9952+ ) {
9953+ Ok(_) => {
9954+ unreachable!("`handle_error` only returns Err as we've passed in an Err")
9955+ },
99249956 Err(e) => {
99259957 return Err(APIError::ChannelUnavailable { err: e.err });
99269958 },
99279959 }
9928- }
9960+ },
99299961 };
99309962
99319963 if accept_0conf {
@@ -9934,9 +9966,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
99349966 } else if channel.funding().get_channel_type().requires_zero_conf() {
99359967 let send_msg_err_event = MessageSendEvent::HandleError {
99369968 node_id: channel.context().get_counterparty_node_id(),
9937- action: msgs::ErrorAction::SendErrorMessage{
9938- msg: msgs::ErrorMessage { channel_id: *temporary_channel_id, data: "No zero confirmation channels accepted".to_owned(), }
9939- }
9969+ action: msgs::ErrorAction::SendErrorMessage {
9970+ msg: msgs::ErrorMessage {
9971+ channel_id: *temporary_channel_id,
9972+ data: "No zero confirmation channels accepted".to_owned(),
9973+ },
9974+ },
99409975 };
99419976 debug_assert!(peer_state.is_connected);
99429977 peer_state.pending_msg_events.push(send_msg_err_event);
@@ -9951,13 +9986,19 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
99519986 if is_only_peer_channel && peers_without_funded_channels >= MAX_UNFUNDED_CHANNEL_PEERS {
99529987 let send_msg_err_event = MessageSendEvent::HandleError {
99539988 node_id: channel.context().get_counterparty_node_id(),
9954- action: msgs::ErrorAction::SendErrorMessage{
9955- msg: msgs::ErrorMessage { channel_id: *temporary_channel_id, data: "Have too many peers with unfunded channels, not accepting new ones".to_owned(), }
9956- }
9989+ action: msgs::ErrorAction::SendErrorMessage {
9990+ msg: msgs::ErrorMessage {
9991+ channel_id: *temporary_channel_id,
9992+ data:
9993+ "Have too many peers with unfunded channels, not accepting new ones"
9994+ .to_owned(),
9995+ },
9996+ },
99579997 };
99589998 debug_assert!(peer_state.is_connected);
99599999 peer_state.pending_msg_events.push(send_msg_err_event);
9960- let err_str = "Too many peers with unfunded channels, refusing to accept new ones".to_owned();
10000+ let err_str =
10001+ "Too many peers with unfunded channels, refusing to accept new ones".to_owned();
996110002 log_error!(logger, "{}", err_str);
996210003
996310004 return Err(APIError::APIMisuseError { err: err_str });
@@ -13671,7 +13712,6 @@ where
1367113712 provided_init_features(&self.config.read().unwrap())
1367213713 }
1367313714
13674- #[rustfmt::skip]
1367513715 fn peer_disconnected(&self, counterparty_node_id: PublicKey) {
1367613716 let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || {
1367713717 let mut splice_failed_events = Vec::new();
@@ -13779,7 +13819,10 @@ where
1377913819 debug_assert!(peer_state.is_connected, "A disconnected peer cannot disconnect");
1378013820 peer_state.is_connected = false;
1378113821 peer_state.ok_to_remove(true)
13782- } else { debug_assert!(false, "Unconnected peer disconnected"); true }
13822+ } else {
13823+ debug_assert!(false, "Unconnected peer disconnected");
13824+ true
13825+ }
1378313826 };
1378413827 if remove_peer {
1378513828 per_peer_state.remove(&counterparty_node_id);
@@ -13804,11 +13847,16 @@ where
1380413847 });
1380513848 }
1380613849
13807- #[rustfmt::skip]
13808- fn peer_connected(&self, counterparty_node_id: PublicKey, init_msg: &msgs::Init, inbound: bool) -> Result<(), ()> {
13850+ fn peer_connected(
13851+ &self, counterparty_node_id: PublicKey, init_msg: &msgs::Init, inbound: bool,
13852+ ) -> Result<(), ()> {
1380913853 let logger = WithContext::from(&self.logger, Some(counterparty_node_id), None, None);
1381013854 if !init_msg.features.supports_static_remote_key() {
13811- log_debug!(logger, "Peer {} does not support static remote key, disconnecting", log_pubkey!(counterparty_node_id));
13855+ log_debug!(
13856+ logger,
13857+ "Peer {} does not support static remote key, disconnecting",
13858+ log_pubkey!(counterparty_node_id)
13859+ );
1381213860 return Err(());
1381313861 }
1381413862
@@ -13819,8 +13867,10 @@ where
1381913867 // peer immediately (as long as it doesn't have funded channels). If we have a bunch of
1382013868 // unfunded channels taking up space in memory for disconnected peers, we still let new
1382113869 // peers connect, but we'll reject new channels from them.
13822- let connected_peers_without_funded_channels = self.peers_without_funded_channels(|node| node.is_connected);
13823- let inbound_peer_limited = inbound && connected_peers_without_funded_channels >= MAX_NO_CHANNEL_PEERS;
13870+ let connected_peers_without_funded_channels =
13871+ self.peers_without_funded_channels(|node| node.is_connected);
13872+ let inbound_peer_limited =
13873+ inbound && connected_peers_without_funded_channels >= MAX_NO_CHANNEL_PEERS;
1382413874
1382513875 {
1382613876 let mut peer_state_lock = self.per_peer_state.write().unwrap();
@@ -13848,9 +13898,9 @@ where
1384813898 peer_state.latest_features = init_msg.features.clone();
1384913899
1385013900 let best_block_height = self.best_block.read().unwrap().height;
13851- if inbound_peer_limited &&
13852- Self::unfunded_channel_count(&*peer_state, best_block_height) ==
13853- peer_state.channel_by_id.len()
13901+ if inbound_peer_limited
13902+ && Self::unfunded_channel_count(&*peer_state, best_block_height)
13903+ == peer_state.channel_by_id.len()
1385413904 {
1385513905 res = Err(());
1385613906 return NotifyOption::SkipPersistNoEvents;
@@ -13859,7 +13909,10 @@ where
1385913909 debug_assert!(peer_state.pending_msg_events.is_empty());
1386013910 peer_state.pending_msg_events.clear();
1386113911
13862- debug_assert!(!peer_state.is_connected, "A peer shouldn't be connected twice");
13912+ debug_assert!(
13913+ !peer_state.is_connected,
13914+ "A peer shouldn't be connected twice"
13915+ );
1386313916 peer_state.is_connected = true;
1386413917 },
1386513918 }
@@ -13876,27 +13929,26 @@ where
1387613929 if !peer_state.peer_storage.is_empty() {
1387713930 pending_msg_events.push(MessageSendEvent::SendPeerStorageRetrieval {
1387813931 node_id: counterparty_node_id.clone(),
13879- msg: msgs::PeerStorageRetrieval {
13880- data: peer_state.peer_storage.clone()
13881- },
13932+ msg: msgs::PeerStorageRetrieval { data: peer_state.peer_storage.clone() },
1388213933 });
1388313934 }
1388413935
1388513936 for (_, chan) in peer_state.channel_by_id.iter_mut() {
1388613937 let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
1388713938 match chan.peer_connected_get_handshake(self.chain_hash, &&logger) {
13888- ReconnectionMsg::Reestablish(msg) =>
13939+ ReconnectionMsg::Reestablish(msg) => {
1388913940 pending_msg_events.push(MessageSendEvent::SendChannelReestablish {
1389013941 node_id: chan.context().get_counterparty_node_id(),
1389113942 msg,
13892- }),
13893- ReconnectionMsg::Open(OpenChannelMessage::V1(msg)) =>
13894- pending_msg_events.push(MessageSendEvent::SendOpenChannel {
13943+ })
13944+ },
13945+ ReconnectionMsg::Open(OpenChannelMessage::V1(msg)) => pending_msg_events
13946+ .push(MessageSendEvent::SendOpenChannel {
1389513947 node_id: chan.context().get_counterparty_node_id(),
1389613948 msg,
1389713949 }),
13898- ReconnectionMsg::Open(OpenChannelMessage::V2(msg)) =>
13899- pending_msg_events .push(MessageSendEvent::SendOpenChannelV2 {
13950+ ReconnectionMsg::Open(OpenChannelMessage::V2(msg)) => pending_msg_events
13951+ .push(MessageSendEvent::SendOpenChannelV2 {
1390013952 node_id: chan.context().get_counterparty_node_id(),
1390113953 msg,
1390213954 }),
0 commit comments