@@ -54,6 +54,8 @@ use crate::ln::features::Bolt11InvoiceFeatures;
54
54
use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
55
55
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails};
56
56
use crate::ln::msgs;
57
+ use crate::ln::channel_keys::RevocationBasepoint;
58
+ use crate::ln::chan_utils::{make_funding_redeemscript, ChannelTransactionParameters, CounterpartyChannelTransactionParameters, ChannelPublicKeys};
57
59
use crate::ln::onion_utils;
58
60
use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING};
59
61
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
@@ -70,8 +72,8 @@ use crate::offers::refund::{Refund, RefundBuilder};
70
72
use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
71
73
use crate::onion_message::messenger::{new_pending_onion_message, Destination, MessageRouter, PendingOnionMessage, Responder, ResponseInstruction};
72
74
use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
73
- use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
74
75
use crate::sign::ecdsa::EcdsaChannelSigner;
76
+ use crate::sign::{EntropySource, ChannelSigner, NodeSigner, Recipient, SignerProvider};
75
77
use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
76
78
use crate::util::wakers::{Future, Notifier};
77
79
use crate::util::scid_utils::fake_scid;
@@ -7466,6 +7468,58 @@ where
7466
7468
self.peer_storage.lock().unwrap().insert(*counterparty_node_id, msg.data.clone());
7467
7469
}
7468
7470
7471
+ fn internal_your_peer_storage(&self, counterparty_node_id: &PublicKey, msg: &msgs::YourPeerStorageMessage) {
7472
+ let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), None, None);
7473
+ let our_peer_storage = self.our_peer_storage.read().unwrap();
7474
+ if msg.data.len() < 16 {
7475
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
7476
+ return;
7477
+ }
7478
+
7479
+ let mut res = vec![0; msg.data.len() - 16];
7480
+
7481
+ match our_peer_storage.decrypt_our_peer_storage(&mut res, msg.data.as_slice(), self.our_peerstorage_encryption_key) {
7482
+ Ok(()) => {
7483
+ // Decryption successful, the plaintext is now stored in `res`
7484
+ log_debug!(logger, "Decryption successful");
7485
+ let our_peer_storage = <OurPeerStorage as Readable>::read(&mut ::std::io::Cursor::new(res)).unwrap();
7486
+
7487
+ for ps_channel in &our_peer_storage.channels {
7488
+ let mut keys = self.signer_provider.derive_channel_signer(ps_channel.channel_value_stoshis, ps_channel.channel_keys_id);
7489
+ let channel_parameters = ChannelTransactionParameters{
7490
+ holder_pubkeys:keys.pubkeys().clone(),
7491
+ is_outbound_from_holder: true,
7492
+ holder_selected_contest_delay: 66,
7493
+ counterparty_parameters: Some(CounterpartyChannelTransactionParameters {
7494
+ pubkeys: ChannelPublicKeys {
7495
+ funding_pubkey: PublicKey::from_secret_key(&self.secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
7496
+ revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&self.secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
7497
+ payment_point: PublicKey::from_secret_key(&self.secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
7498
+ delayed_payment_basepoint: ps_channel.counterparty_delayed_payment_base_key,
7499
+ htlc_basepoint: ps_channel.counterparty_htlc_base_key,
7500
+ }, selected_contest_delay: ps_channel.on_counterparty_tx_csv}),
7501
+ funding_outpoint: Some(ps_channel.funding_outpoint),
7502
+ channel_type_features: ChannelTypeFeatures::only_static_remote_key(),
7503
+ };
7504
+ keys.provide_channel_parameters(&channel_parameters);
7505
+ let pubkeys = keys.pubkeys().clone();
7506
+ let funding_redeemscript = make_funding_redeemscript(&pubkeys.funding_pubkey, counterparty_node_id);
7507
+ let funding_txo_script = funding_redeemscript.to_p2wsh();
7508
+ let monitor = StubChannelMonitor::new_stub(self.secp_ctx.clone(), ps_channel, *self.best_block.read().unwrap(), keys, channel_parameters, funding_txo_script);
7509
+ let monitor_res = self.chain_monitor.watch_dummy(ps_channel.funding_outpoint, monitor);
7510
+ if let Ok(_persist_state) = monitor_res {
7511
+ log_trace!(logger, "Dummy channel persisted!");
7512
+ }
7513
+ }
7514
+ }
7515
+ Err(_) => {
7516
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
7517
+ return;
7518
+ }
7519
+ }
7520
+
7521
+ }
7522
+
7469
7523
fn internal_funding_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), MsgHandleErrInternal> {
7470
7524
let best_block = *self.best_block.read().unwrap();
7471
7525
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -10060,6 +10114,8 @@ where
10060
10114
}
10061
10115
10062
10116
fn handle_your_peer_storage(&self, counterparty_node_id: &PublicKey, msg: &msgs::YourPeerStorageMessage) {
10117
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
10118
+ self.internal_your_peer_storage(counterparty_node_id, msg);
10063
10119
}
10064
10120
10065
10121
fn handle_channel_ready(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReady) {
0 commit comments