Skip to content

Commit e2298d0

Browse files
committed
fixup
1 parent af8ff1b commit e2298d0

File tree

1 file changed

+23
-47
lines changed

1 file changed

+23
-47
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8230,74 +8230,50 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
82308230
}
82318231
}
82328232

8233-
fn internal_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, _msg: msgs::PeerStorageRetrieval) {
8233+
fn internal_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, _msg: msgs::PeerStorageRetrieval) -> Result<(), MsgHandleErrInternal> {
82348234
// TODO: Decrypt and check if have any stale or missing ChannelMonitor.
8235-
let per_peer_state = self.per_peer_state.read().unwrap();
8236-
let peer_state_mutex = match per_peer_state.get(&counterparty_node_id) {
8237-
Some(peer_state_mutex) => peer_state_mutex,
8238-
None => return,
8239-
};
8240-
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
8241-
let peer_state = &mut *peer_state_lock;
82428235
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), None, None);
82438236

82448237
log_debug!(logger, "Received unexpected peer_storage_retrieval from {}. This is unusual since we do not yet distribute peer storage. Sending a warning.", log_pubkey!(counterparty_node_id));
8245-
peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
8246-
node_id: counterparty_node_id.clone(),
8247-
action: msgs::ErrorAction::SendWarningMessage {
8248-
msg: msgs::WarningMessage {
8249-
channel_id: ChannelId([0; 32]),
8250-
data: "Invalid peer_storage_retrieval message received.".to_owned()
8251-
},
8252-
log_level: Level::Trace,
8253-
}
8254-
});
8238+
8239+
Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(
8240+
format!("Invalid peer_storage_retrieval message received.")
8241+
), ChannelId([0; 32])))
82558242
}
82568243

8257-
fn internal_peer_storage(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorage) {
8244+
fn internal_peer_storage(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorage) -> Result<(), MsgHandleErrInternal> {
82588245
let per_peer_state = self.per_peer_state.read().unwrap();
8259-
let peer_state_mutex = match per_peer_state.get(&counterparty_node_id) {
8260-
Some(peer_state_mutex) => peer_state_mutex,
8261-
None => return,
8262-
};
8246+
let peer_state_mutex = per_peer_state.get(&counterparty_node_id)
8247+
.ok_or_else(|| {
8248+
debug_assert!(false);
8249+
MsgHandleErrInternal::send_err_msg_no_close(format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id), ChannelId([0; 32]))
8250+
})?;
8251+
82638252
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
82648253
let peer_state = &mut *peer_state_lock;
82658254
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), None, None);
82668255

82678256
// Check if we have any channels with the peer (Currently we only provide the service to peers we have a channel with).
82688257
if !peer_state.channel_by_id.values().any(|phase| phase.is_funded()) {
82698258
log_debug!(logger, "Ignoring peer storage request from {} as we don't have any funded channels with them.", log_pubkey!(counterparty_node_id));
8270-
peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
8271-
node_id: counterparty_node_id.clone(),
8272-
action: msgs::ErrorAction::SendWarningMessage {
8273-
msg: msgs::WarningMessage {
8274-
channel_id: ChannelId([0; 32]),
8275-
data: "Ignoring peer_storage message, as peer storage is currently supported only for peers with an active funded channel.".to_owned()
8276-
},
8277-
log_level: Level::Trace,
8278-
}
8279-
});
8280-
return;
8259+
return Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(
8260+
format!("Ignoring peer_storage message, as peer storage is currently supported only for peers with an active funded channel.")
8261+
), ChannelId([0; 32])));
82818262
}
82828263

82838264
#[cfg(not(test))]
82848265
if msg.data.len() > MAX_PEER_STORAGE_SIZE {
82858266
log_debug!(logger, "Sending warning to peer and ignoring peer storage request from {} as its over 1KiB", log_pubkey!(counterparty_node_id));
8286-
peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
8287-
node_id: counterparty_node_id.clone(),
8288-
action: msgs::ErrorAction::SendWarningMessage {
8289-
msg: msgs::WarningMessage {
8290-
channel_id: ChannelId([0; 32]),
8291-
data: format!("Supports only data up to {} bytes in peer storage.", MAX_PEER_STORAGE_SIZE)
8292-
},
8293-
log_level: Level::Trace,
8294-
}
8295-
});
8296-
return;
8267+
8268+
return Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(
8269+
format!("Supports only data up to {} bytes in peer storage.", MAX_PEER_STORAGE_SIZE)
8270+
), ChannelId([0; 32])));
82978271
}
82988272

82998273
log_trace!(logger, "Received peer_storage from {}", log_pubkey!(counterparty_node_id));
83008274
peer_state.peer_storage = msg.data;
8275+
8276+
Ok(())
83018277
}
83028278

83038279
fn internal_funding_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), MsgHandleErrInternal> {
@@ -11498,12 +11474,12 @@ where
1149811474

1149911475
fn handle_peer_storage(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorage) {
1150011476
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || NotifyOption::SkipPersistNoEvents);
11501-
self.internal_peer_storage(counterparty_node_id, msg);
11477+
let _ = handle_error!(self, self.internal_peer_storage(counterparty_node_id, msg), counterparty_node_id);
1150211478
}
1150311479

1150411480
fn handle_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorageRetrieval) {
1150511481
let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || NotifyOption::SkipPersistNoEvents);
11506-
self.internal_peer_storage_retrieval(counterparty_node_id, msg);
11482+
let _ = handle_error!(self, self.internal_peer_storage_retrieval(counterparty_node_id, msg), counterparty_node_id);
1150711483
}
1150811484

1150911485
fn handle_channel_ready(&self, counterparty_node_id: PublicKey, msg: &msgs::ChannelReady) {

0 commit comments

Comments
 (0)