@@ -50,6 +50,7 @@ use crate::ln::types::ChannelId;
50
50
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
51
51
use crate::ln::channel::{self, Channel, ChannelError, ChannelUpdateStatus, FundedChannel, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, ReconnectionMsg, InboundV1Channel, WithChannelContext};
52
52
use crate::ln::channel::PendingV2Channel;
53
+ use crate::ln::our_peer_storage::OurPeerStorage;
53
54
use crate::ln::channel_state::ChannelDetails;
54
55
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
55
56
#[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;
@@ -8288,15 +8289,37 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
8288
8289
}
8289
8290
}
8290
8291
8291
- fn internal_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, _msg : msgs::PeerStorageRetrieval) -> Result<(), MsgHandleErrInternal> {
8292
- // TODO: Decrypt and check if have any stale or missing ChannelMonitor.
8292
+ fn internal_peer_storage_retrieval(&self, counterparty_node_id: PublicKey, msg : msgs::PeerStorageRetrieval) -> Result<(), MsgHandleErrInternal> {
8293
+ // TODO: Check if have any stale or missing ChannelMonitor.
8293
8294
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), None, None);
8294
8295
8295
- 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));
8296
+ if msg.data.len() < 16 {
8297
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
8298
+ return Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(
8299
+ "Invalid peer_storage_retrieval message received.".into(),
8300
+ ), ChannelId([0; 32])));
8301
+ }
8302
+
8303
+ let mut res = vec![0; msg.data.len() - 16];
8304
+ let our_peerstorage_encryption_key = self.node_signer.get_peer_storage_key();
8305
+ let mut cyphertext_with_key = Vec::with_capacity(msg.data.len() + our_peerstorage_encryption_key.len());
8306
+ cyphertext_with_key.extend(msg.data.clone());
8307
+ cyphertext_with_key.extend_from_slice(&our_peerstorage_encryption_key);
8296
8308
8297
- Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(
8298
- "Invalid peer_storage_retrieval message received.".into(),
8299
- ), ChannelId([0; 32])))
8309
+ match OurPeerStorage::decrypt_our_peer_storage(&mut res, cyphertext_with_key.as_slice()) {
8310
+ Ok(()) => {
8311
+ // Decryption successful, the plaintext is now stored in `res`.
8312
+ log_debug!(logger, "Received a peer storage from peer {}", log_pubkey!(counterparty_node_id));
8313
+ }
8314
+ Err(_) => {
8315
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
8316
+
8317
+ return Err(MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(
8318
+ "Invalid peer_storage_retrieval message received.".into(),
8319
+ ), ChannelId([0; 32])));
8320
+ }
8321
+ }
8322
+ Ok(())
8300
8323
}
8301
8324
8302
8325
fn internal_peer_storage(&self, counterparty_node_id: PublicKey, msg: msgs::PeerStorage) -> Result<(), MsgHandleErrInternal> {
0 commit comments