@@ -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;
@@ -7467,6 +7469,67 @@ where
7467
7469
self.peer_storage.lock().unwrap().insert(*counterparty_node_id, msg.data.clone());
7468
7470
}
7469
7471
7472
+ fn internal_your_peer_storage(&self, counterparty_node_id: &PublicKey, msg: &msgs::YourPeerStorageMessage) {
7473
+ let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), None, None);
7474
+ let our_peer_storage = self.our_peer_storage.read().unwrap();
7475
+ if msg.data.len() < 16 {
7476
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
7477
+ return;
7478
+ }
7479
+
7480
+ let mut res = vec![0; msg.data.len() - 16];
7481
+
7482
+ match our_peer_storage.decrypt_our_peer_storage(&mut res, msg.data.as_slice(), self.our_peerstorage_encryption_key) {
7483
+ Ok(()) => {
7484
+ // Decryption successful, the plaintext is now stored in `res`
7485
+ log_debug!(logger, "Decryption successful");
7486
+ let our_peer_storage = <OurPeerStorage as Readable>::read(&mut ::std::io::Cursor::new(res)).unwrap();
7487
+
7488
+ for ps_channel in our_peer_storage.get_channels() {
7489
+ if self.chain_monitor.stale_or_missing_channel_monitor(&ps_channel) {
7490
+ let mut keys = self.signer_provider.derive_channel_signer(ps_channel.channel_value_stoshis, ps_channel.channel_keys_id);
7491
+ let channel_parameters = ChannelTransactionParameters{
7492
+ holder_pubkeys:keys.pubkeys().clone(),
7493
+ is_outbound_from_holder: true,
7494
+ holder_selected_contest_delay: 66,
7495
+ counterparty_parameters: Some(CounterpartyChannelTransactionParameters {
7496
+ pubkeys: ChannelPublicKeys {
7497
+ funding_pubkey: PublicKey::from_secret_key(&self.secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
7498
+ revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&self.secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
7499
+ payment_point: PublicKey::from_secret_key(&self.secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
7500
+ delayed_payment_basepoint: ps_channel.counterparty_delayed_payment_base_key,
7501
+ htlc_basepoint: ps_channel.counterparty_htlc_base_key,
7502
+ }, selected_contest_delay: ps_channel.on_counterparty_tx_csv}),
7503
+ funding_outpoint: Some(ps_channel.funding_outpoint),
7504
+ channel_type_features: ChannelTypeFeatures::only_static_remote_key(),
7505
+ };
7506
+ keys.provide_channel_parameters(&channel_parameters);
7507
+ let pubkeys = keys.pubkeys().clone();
7508
+ let funding_redeemscript = make_funding_redeemscript(&pubkeys.funding_pubkey, counterparty_node_id);
7509
+ let funding_txo_script = funding_redeemscript.to_p2wsh();
7510
+ let destination_script = self.signer_provider.get_destination_script(ps_channel.channel_keys_id).unwrap();
7511
+ let monitor = StubChannelMonitor::new_stub(self.secp_ctx.clone(), ps_channel, *self.best_block.read().unwrap(), keys, channel_parameters, funding_txo_script, destination_script);
7512
+ let monitor_res = self.chain_monitor.panic_and_persist_stub_channel(ps_channel.funding_outpoint, monitor);
7513
+
7514
+ match monitor_res {
7515
+ Ok(()) => {
7516
+ log_trace!(logger, "Your node is up-to-date with the peer storage.")
7517
+ }
7518
+ Err(()) => {
7519
+ panic!("Not able to persist StubChannelMonitor.")
7520
+ }
7521
+ }
7522
+ }
7523
+ }
7524
+ }
7525
+ Err(_) => {
7526
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
7527
+ return;
7528
+ }
7529
+ }
7530
+
7531
+ }
7532
+
7470
7533
fn internal_funding_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), MsgHandleErrInternal> {
7471
7534
let best_block = *self.best_block.read().unwrap();
7472
7535
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -10061,6 +10124,8 @@ where
10061
10124
}
10062
10125
10063
10126
fn handle_your_peer_storage(&self, counterparty_node_id: &PublicKey, msg: &msgs::YourPeerStorageMessage) {
10127
+ let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || NotifyOption::SkipPersistNoEvents);
10128
+ self.internal_your_peer_storage(counterparty_node_id, msg);
10064
10129
}
10065
10130
10066
10131
fn handle_channel_ready(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReady) {
0 commit comments