@@ -52,6 +52,7 @@ use crate::ln::types::ChannelId;
52
52
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
53
53
use crate::ln::channel::{self, Channel, ChannelError, ChannelUpdateStatus, FundedChannel, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, ReconnectionMsg, InboundV1Channel, WithChannelContext};
54
54
use crate::ln::channel::PendingV2Channel;
55
+ use crate::ln::our_peer_storage::EncryptedOurPeerStorage;
55
56
use crate::ln::channel_state::ChannelDetails;
56
57
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
57
58
#[cfg(any(feature = "_test_utils", test))]
@@ -8346,15 +8347,36 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8346
8347
}
8347
8348
}
8348
8349
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.
8351
8352
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);
8352
8358
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
+ };
8354
8366
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(())
8358
8380
}
8359
8381
8360
8382
fn internal_peer_storage(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorage) -> Result<(), MsgHandleErrInternal> {
@@ -16405,7 +16427,7 @@ mod tests {
16405
16427
pub mod bench {
16406
16428
use crate::chain::Listen;
16407
16429
use crate::chain::chainmonitor::{ChainMonitor, Persist};
16408
- use crate::sign::{KeysManager, InMemorySigner};
16430
+ use crate::sign::{KeysManager, InMemorySigner, NodeSigner };
16409
16431
use crate::events::Event;
16410
16432
use crate::ln::channelmanager::{BestBlock, ChainParameters, ChannelManager, PaymentHash, PaymentPreimage, PaymentId, RecipientOnionFields, Retry};
16411
16433
use crate::ln::functional_test_utils::*;
0 commit comments