@@ -52,6 +52,7 @@ use crate::ln::types::ChannelId;
5252use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
5353use crate::ln::channel::{self, Channel, ChannelError, ChannelUpdateStatus, FundedChannel, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, ReconnectionMsg, InboundV1Channel, WithChannelContext};
5454use crate::ln::channel::PendingV2Channel;
55+ use crate::ln::our_peer_storage::EncryptedOurPeerStorage;
5556use crate::ln::channel_state::ChannelDetails;
5657use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
5758#[cfg(any(feature = "_test_utils", test))]
@@ -8346,15 +8347,36 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
83468347 }
83478348 }
83488349
8349- fn internal_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, _msg : msgs::PeerStorageRetrieval) -> Result<(), MsgHandleErrInternal> {
8350- // TODO: Decrypt and check if have any stale or missing ChannelMonitor.
8350+ fn internal_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, msg : msgs::PeerStorageRetrieval) -> Result<(), MsgHandleErrInternal> {
8351+ // TODO: Check if have any stale or missing ChannelMonitor.
83518352 let logger = WithContext::from(&self.logger, Some(counterparty_node_id), None, None);
8353+ let err = MsgHandleErrInternal::from_chan_no_close(
8354+ ChannelError::Ignore("Invalid PeerStorageRetrieval message received.".into()),
8355+ ChannelId([0; 32]),
8356+ );
8357+ let err_str = format!("Invalid PeerStorage received from {}", counterparty_node_id);
83528358
8353- 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));
8359+ let encrypted_ops = match EncryptedOurPeerStorage::new(msg.data) {
8360+ Ok(encrypted_ops) => encrypted_ops,
8361+ Err(_) => {
8362+ log_debug!(logger, "{}", err_str);
8363+ return Err(err);
8364+ }
8365+ };
83548366
8355- Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(
8356- "Invalid peer_storage_retrieval message received.".into(),
8357- ), ChannelId([0; 32])))
8367+ let decrypted_data = match encrypted_ops.decrypt(&self.node_signer.get_peer_storage_key()) {
8368+ Ok(decrypted_ops) => decrypted_ops.into_vec(),
8369+ Err(_) => {
8370+ log_debug!(logger, "{}", err_str);
8371+ return Err(err);
8372+ }
8373+ };
8374+
8375+ if decrypted_data.is_empty() {
8376+ log_debug!(logger, "Received a peer storage from peer {} with 0 channels.", log_pubkey!(counterparty_node_id));
8377+ }
8378+
8379+ Ok(())
83588380 }
83598381
83608382 fn internal_peer_storage(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorage) -> Result<(), MsgHandleErrInternal> {
@@ -16405,7 +16427,7 @@ mod tests {
1640516427pub mod bench {
1640616428 use crate::chain::Listen;
1640716429 use crate::chain::chainmonitor::{ChainMonitor, Persist};
16408- use crate::sign::{KeysManager, InMemorySigner};
16430+ use crate::sign::{KeysManager, InMemorySigner, NodeSigner };
1640916431 use crate::events::Event;
1641016432 use crate::ln::channelmanager::{BestBlock, ChainParameters, ChannelManager, PaymentHash, PaymentPreimage, PaymentId, RecipientOnionFields, Retry};
1641116433 use crate::ln::functional_test_utils::*;
0 commit comments