@@ -40,13 +40,14 @@ use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12OfferContext, Bolt1
40
40
use crate::chain;
41
41
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
42
42
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
43
- use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, WithChannelMonitor, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY, MonitorEvent, CLOSED_CHANNEL_UPDATE_ID };
43
+ use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, MonitorEvent, WithChannelMonitor, ANTI_REORG_DELAY, CLOSED_CHANNEL_UPDATE_ID, CLTV_CLAIM_BUFFER, HTLC_FAIL_BACK_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, STUB_CHANNEL_UPDATE_IDENTIFIER };
44
44
use crate::chain::transaction::{OutPoint, TransactionData};
45
45
use crate::events;
46
46
use crate::events::{Event, EventHandler, EventsProvider, MessageSendEvent, MessageSendEventsProvider, ClosureReason, HTLCDestination, PaymentFailureReason, ReplayEvent};
47
47
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
48
48
// construct one themselves.
49
49
use crate::ln::inbound_payment;
50
+ use crate::ln::our_peer_storage::OurPeerStorage;
50
51
use crate::ln::types::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
51
52
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
52
53
use crate::ln::channel_state::ChannelDetails;
@@ -76,8 +77,8 @@ use crate::offers::static_invoice::StaticInvoice;
76
77
use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
77
78
use crate::onion_message::messenger::{Destination, MessageRouter, Responder, ResponseInstruction, MessageSendInstructions};
78
79
use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
79
- use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
80
80
use crate::sign::ecdsa::EcdsaChannelSigner;
81
+ use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
81
82
use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
82
83
use crate::util::wakers::{Future, Notifier};
83
84
use crate::util::scid_utils::fake_scid;
@@ -7913,6 +7914,61 @@ where
7913
7914
peer_state.peer_storage = msg.data.clone();
7914
7915
}
7915
7916
7917
+ fn internal_your_peer_storage(&self, counterparty_node_id: &PublicKey, msg: &msgs::YourPeerStorageMessage) {
7918
+ let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), None, None);
7919
+ if msg.data.len() < 16 {
7920
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
7921
+ return;
7922
+ }
7923
+
7924
+ let mut res = vec![0; msg.data.len() - 16];
7925
+ let our_peerstorage_encryption_key = self.node_signer.get_peer_storage_key();
7926
+ let mut cyphertext_with_key = Vec::with_capacity(msg.data.len() + our_peerstorage_encryption_key.len());
7927
+ cyphertext_with_key.extend(msg.data.clone());
7928
+ cyphertext_with_key.extend_from_slice(&our_peerstorage_encryption_key);
7929
+
7930
+ match OurPeerStorage::decrypt_our_peer_storage(&mut res, cyphertext_with_key.as_slice()) {
7931
+ Ok(()) => {
7932
+ // Decryption successful, the plaintext is now stored in `res`.
7933
+ log_debug!(logger, "Received a peer storage from peer {}", log_pubkey!(counterparty_node_id));
7934
+ }
7935
+ Err(_) => {
7936
+ log_debug!(logger, "Invalid YourPeerStorage received from {}", log_pubkey!(counterparty_node_id));
7937
+ return;
7938
+ }
7939
+ }
7940
+
7941
+ let our_peer_storage = <OurPeerStorage as Readable>::read(&mut ::bitcoin::io::Cursor::new(res)).unwrap();
7942
+ let per_peer_state = self.per_peer_state.read().unwrap();
7943
+
7944
+ for ((node_id, channel_id), min_seen_secret) in our_peer_storage.get_cid_and_min_seen_secret().unwrap() {
7945
+ let peer_state_mutex = match per_peer_state.get(&node_id) {
7946
+ Some(mutex) => mutex,
7947
+ None => {
7948
+ log_debug!(logger, "Not able to find peer_state for the counterparty {}, channelId {}", log_pubkey!(node_id), channel_id);
7949
+ continue;
7950
+ }
7951
+ };
7952
+
7953
+ let peer_state_lock = peer_state_mutex.lock().unwrap();
7954
+ let peer_state = &*peer_state_lock;
7955
+
7956
+ match peer_state.channel_by_id.get(&channel_id) {
7957
+ Some(ChannelPhase::Funded(chan)) => {
7958
+ if chan.context.get_commitment_secret().get_min_seen_secret() > min_seen_secret {
7959
+ panic!("Lost channel state for channel {}.
7960
+ Received peer storage with a more recent state than what our node had.
7961
+ Use the FundRecoverer to initiate a force close and sweep the funds.", channel_id);
7962
+ }
7963
+ },
7964
+ Some(_) => {}
7965
+ None => {
7966
+ continue;
7967
+ }
7968
+ }
7969
+ }
7970
+ }
7971
+
7916
7972
fn internal_funding_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingSigned) -> Result<(), MsgHandleErrInternal> {
7917
7973
let best_block = *self.best_block.read().unwrap();
7918
7974
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -12339,6 +12395,10 @@ where
12339
12395
funding_txo_to_channel_id.insert(funding_txo, channel.context.channel_id());
12340
12396
funding_txo_set.insert(funding_txo.clone());
12341
12397
if let Some(ref mut monitor) = args.channel_monitors.get_mut(&funding_txo) {
12398
+ if monitor.get_latest_update_id() == STUB_CHANNEL_UPDATE_IDENTIFIER {
12399
+ panic!("ChannelMonitor for {} is stale and recovered from Peer Storage, it is not safe to run the node in normal mode.", monitor.channel_id());
12400
+ }
12401
+
12342
12402
if channel.get_cur_holder_commitment_transaction_number() > monitor.get_cur_holder_commitment_number() ||
12343
12403
channel.get_revoked_counterparty_commitment_transaction_number() > monitor.get_min_seen_secret() ||
12344
12404
channel.get_cur_counterparty_commitment_transaction_number() > monitor.get_cur_counterparty_commitment_number() ||
0 commit comments