@@ -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;
@@ -7429,6 +7431,58 @@ where
7429
7431
self.peer_storage.lock().unwrap().insert(*counterparty_node_id, msg.data.clone());
7430
7432
}
7431
7433
7434
+ fn internal_your_peer_storage(&self, counterparty_node_id: &PublicKey, msg: &msgs::YourPeerStorageMessage) {
7435
+ let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), None, None);
7436
+ let our_peer_storage = self.our_peer_storage.read().unwrap();
7437
+ if msg.data.len() < 16 {
7438
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
7439
+ return;
7440
+ }
7441
+
7442
+ let mut res = vec![0; msg.data.len() - 16];
7443
+
7444
+ match our_peer_storage.decrypt_our_peer_storage(&mut res, msg.data.as_slice(), self.our_peerstorage_encryption_key) {
7445
+ Ok(()) => {
7446
+ // Decryption successful, the plaintext is now stored in `res`
7447
+ log_debug!(logger, "Decryption successful");
7448
+ let our_peer_storage = <OurPeerStorage as Readable>::read(&mut ::std::io::Cursor::new(res)).unwrap();
7449
+
7450
+ for ps_channel in &our_peer_storage.channels {
7451
+ let mut keys = self.signer_provider.derive_channel_signer(ps_channel.channel_value_stoshis, ps_channel.channel_keys_id);
7452
+ let channel_parameters = ChannelTransactionParameters{
7453
+ holder_pubkeys:keys.pubkeys().clone(),
7454
+ is_outbound_from_holder: true,
7455
+ holder_selected_contest_delay: 66,
7456
+ counterparty_parameters: Some(CounterpartyChannelTransactionParameters {
7457
+ pubkeys: ChannelPublicKeys {
7458
+ funding_pubkey: PublicKey::from_secret_key(&self.secp_ctx, &SecretKey::from_slice(&[44; 32]).unwrap()),
7459
+ revocation_basepoint: RevocationBasepoint::from(PublicKey::from_secret_key(&self.secp_ctx, &SecretKey::from_slice(&[45; 32]).unwrap())),
7460
+ payment_point: PublicKey::from_secret_key(&self.secp_ctx, &SecretKey::from_slice(&[46; 32]).unwrap()),
7461
+ delayed_payment_basepoint: ps_channel.counterparty_delayed_payment_base_key,
7462
+ htlc_basepoint: ps_channel.counterparty_htlc_base_key,
7463
+ }, selected_contest_delay: ps_channel.on_counterparty_tx_csv}),
7464
+ funding_outpoint: Some(ps_channel.funding_outpoint),
7465
+ channel_type_features: ChannelTypeFeatures::only_static_remote_key(),
7466
+ };
7467
+ keys.provide_channel_parameters(&channel_parameters);
7468
+ let pubkeys = keys.pubkeys().clone();
7469
+ let funding_redeemscript = make_funding_redeemscript(&pubkeys.funding_pubkey, counterparty_node_id);
7470
+ let funding_txo_script = funding_redeemscript.to_p2wsh();
7471
+ let monitor = StubChannelMonitor::new_stub(self.secp_ctx.clone(), ps_channel, *self.best_block.read().unwrap(), keys, channel_parameters, funding_txo_script);
7472
+ let monitor_res = self.chain_monitor.watch_dummy(ps_channel.funding_outpoint, monitor);
7473
+ if let Ok(_persist_state) = monitor_res {
7474
+ log_trace!(logger, "Dummy channel persisted!");
7475
+ }
7476
+ }
7477
+ }
7478
+ Err(_) => {
7479
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
7480
+ return;
7481
+ }
7482
+ }
7483
+
7484
+ }
7485
+
7432
7486
fn internal_funding_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), MsgHandleErrInternal> {
7433
7487
let best_block = *self.best_block.read().unwrap();
7434
7488
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -10023,6 +10077,8 @@ where
10023
10077
}
10024
10078
10025
10079
fn handle_your_peer_storage(&self, counterparty_node_id: &PublicKey, msg: &msgs::YourPeerStorageMessage) {
10080
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
10081
+ self.internal_your_peer_storage(counterparty_node_id, msg);
10026
10082
}
10027
10083
10028
10084
fn handle_channel_ready(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReady) {
0 commit comments