@@ -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::OurPeerStorage;
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))]
@@ -77,8 +78,8 @@ use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailab
77
78
use crate::onion_message::dns_resolution::HumanReadableName;
78
79
use crate::onion_message::messenger::{Destination, MessageRouter, Responder, ResponseInstruction, MessageSendInstructions};
79
80
use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
80
- use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
81
81
use crate::sign::ecdsa::EcdsaChannelSigner;
82
+ use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
82
83
use crate::util::config::{ChannelConfig, ChannelConfigUpdate, ChannelConfigOverrides, UserConfig};
83
84
use crate::util::wakers::{Future, Notifier};
84
85
use crate::util::scid_utils::fake_scid;
@@ -8341,15 +8342,39 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8341
8342
}
8342
8343
}
8343
8344
8344
- fn internal_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, _msg : msgs::PeerStorageRetrieval) -> Result<(), MsgHandleErrInternal> {
8345
- // TODO: Decrypt and check if have any stale or missing ChannelMonitor.
8345
+ fn internal_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, msg : msgs::PeerStorageRetrieval) -> Result<(), MsgHandleErrInternal> {
8346
+ // TODO: Check if have any stale or missing ChannelMonitor.
8346
8347
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), None, None);
8347
8348
8348
- 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));
8349
+ if msg.data.len() < 16 {
8350
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
8351
+ return Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(
8352
+ "Invalid peer_storage_retrieval message received.".into(),
8353
+ ), ChannelId([0; 32])));
8354
+ }
8355
+
8356
+ let mut res = vec![0; msg.data.len() - 16];
8357
+ let our_peerstorage_encryption_key = self.node_signer.get_peer_storage_key();
8358
+
8359
+ match OurPeerStorage::decrypt_our_peer_storage(&mut res, &msg.data.clone(), our_peerstorage_encryption_key) {
8360
+ Ok(()) => {
8361
+ // Decryption successful, the plaintext is now stored in `res`.
8362
+ }
8363
+ Err(_) => {
8364
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
8365
+
8366
+ return Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(
8367
+ "Invalid peer_storage_retrieval message received.".into(),
8368
+ ), ChannelId([0; 32])));
8369
+ }
8370
+ }
8371
+ let our_peer_storage = <OurPeerStorage as Readable>::read(&mut ::bitcoin::io::Cursor::new(res)).unwrap();
8349
8372
8350
- Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(
8351
- "Invalid peer_storage_retrieval message received.".into(),
8352
- ), ChannelId([0; 32])))
8373
+ if our_peer_storage.get_ser_channels().len() == 0 {
8374
+ log_debug!(logger, "Received a peer storage from peer {} with 0 channels.", log_pubkey!(counterparty_node_id));
8375
+ }
8376
+
8377
+ Ok(())
8353
8378
}
8354
8379
8355
8380
fn internal_peer_storage(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorage) -> Result<(), MsgHandleErrInternal> {
0 commit comments