Skip to content

Commit 362ca65

Browse files
committed
Remove counterparty_node_id from ChannelMonitorUpdate
The `counterparty_node_id` in `ChannelMonitorUpdate`s was only tracked to guarantee we could backfill the `ChannelMonitor`'s field once the update is applied. Now that we require the field to already be set at the monitor level, we can remove it from the updates without backwards compatibility concerns as it was written as an odd TLV.
1 parent f0bb900 commit 362ca65

File tree

4 files changed

+4
-28
lines changed

4 files changed

+4
-28
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ where C::Target: chain::Filter,
804804
let monitors = self.monitors.read().unwrap();
805805
match monitors.get(&channel_id) {
806806
None => {
807-
let logger = WithContext::from(&self.logger, update.counterparty_node_id, Some(channel_id), None);
807+
let logger = WithContext::from(&self.logger, None, Some(channel_id), None);
808808
log_error!(logger, "Failed to update channel monitor: no such monitor registered");
809809

810810
// We should never ever trigger this from within ChannelManager. Technically a

lightning/src/chain/channelmonitor.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ use crate::sync::{Mutex, LockTestExt};
7474
#[must_use]
7575
pub struct ChannelMonitorUpdate {
7676
pub(crate) updates: Vec<ChannelMonitorUpdateStep>,
77-
/// Historically, [`ChannelMonitor`]s didn't know their counterparty node id. However,
78-
/// `ChannelManager` really wants to know it so that it can easily look up the corresponding
79-
/// channel. For now, this results in a temporary map in `ChannelManager` to look up channels
80-
/// by only the funding outpoint.
81-
///
82-
/// To eventually remove that, we repeat the counterparty node id here so that we can upgrade
83-
/// `ChannelMonitor`s to become aware of the counterparty node id if they were generated prior
84-
/// to when it was stored directly in them.
85-
pub(crate) counterparty_node_id: Option<PublicKey>,
8677
/// The sequence number of this update. Updates *must* be replayed in-order according to this
8778
/// sequence number (and updates may panic if they are not). The update_id values are strictly
8879
/// increasing and increase by one for each new update, with two exceptions specified below.
@@ -117,7 +108,7 @@ impl Writeable for ChannelMonitorUpdate {
117108
update_step.write(w)?;
118109
}
119110
write_tlv_fields!(w, {
120-
(1, self.counterparty_node_id, option),
111+
// 1 was previously used to store `counterparty_node_id`
121112
(3, self.channel_id, option),
122113
});
123114
Ok(())
@@ -134,13 +125,12 @@ impl Readable for ChannelMonitorUpdate {
134125
updates.push(upd);
135126
}
136127
}
137-
let mut counterparty_node_id = None;
138128
let mut channel_id = None;
139129
read_tlv_fields!(r, {
140-
(1, counterparty_node_id, option),
130+
// 1 was previously used to store `counterparty_node_id`
141131
(3, channel_id, option),
142132
});
143-
Ok(Self { update_id, counterparty_node_id, updates, channel_id })
133+
Ok(Self { update_id, updates, channel_id })
144134
}
145135
}
146136

@@ -3197,10 +3187,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31973187
log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
31983188
}
31993189

3200-
if let Some(counterparty_node_id) = &updates.counterparty_node_id {
3201-
debug_assert_eq!(self.counterparty_node_id, *counterparty_node_id);
3202-
}
3203-
32043190
// ChannelMonitor updates may be applied after force close if we receive a preimage for a
32053191
// broadcasted commitment transaction HTLC output that we'd like to claim on-chain. If this
32063192
// is the case, we no longer have guaranteed access to the monitor's update ID, so we use a

lightning/src/ln/channel.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4528,7 +4528,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
45284528
self.latest_monitor_update_id += 1;
45294529
Some((self.get_counterparty_node_id(), funding_txo, self.channel_id(), ChannelMonitorUpdate {
45304530
update_id: self.latest_monitor_update_id,
4531-
counterparty_node_id: Some(self.counterparty_node_id),
45324531
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast }],
45334532
channel_id: Some(self.channel_id()),
45344533
}))
@@ -5107,7 +5106,6 @@ impl<SP: Deref> FundedChannel<SP> where
51075106
self.context.latest_monitor_update_id += 1;
51085107
let monitor_update = ChannelMonitorUpdate {
51095108
update_id: self.context.latest_monitor_update_id,
5110-
counterparty_node_id: Some(self.context.counterparty_node_id),
51115109
updates: vec![ChannelMonitorUpdateStep::PaymentPreimage {
51125110
payment_preimage: payment_preimage_arg.clone(),
51135111
payment_info,
@@ -5715,7 +5713,6 @@ impl<SP: Deref> FundedChannel<SP> where
57155713
self.context.latest_monitor_update_id += 1;
57165714
let mut monitor_update = ChannelMonitorUpdate {
57175715
update_id: self.context.latest_monitor_update_id,
5718-
counterparty_node_id: Some(self.context.counterparty_node_id),
57195716
updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
57205717
commitment_tx,
57215718
htlc_outputs,
@@ -5797,7 +5794,6 @@ impl<SP: Deref> FundedChannel<SP> where
57975794

57985795
let mut monitor_update = ChannelMonitorUpdate {
57995796
update_id: self.context.latest_monitor_update_id + 1, // We don't increment this yet!
5800-
counterparty_node_id: Some(self.context.counterparty_node_id),
58015797
updates: Vec::new(),
58025798
channel_id: Some(self.context.channel_id()),
58035799
};
@@ -5990,7 +5986,6 @@ impl<SP: Deref> FundedChannel<SP> where
59905986
self.context.latest_monitor_update_id += 1;
59915987
let mut monitor_update = ChannelMonitorUpdate {
59925988
update_id: self.context.latest_monitor_update_id,
5993-
counterparty_node_id: Some(self.context.counterparty_node_id),
59945989
updates: vec![ChannelMonitorUpdateStep::CommitmentSecret {
59955990
idx: self.context.cur_counterparty_commitment_transaction_number + 1,
59965991
secret: msg.per_commitment_secret,
@@ -7262,7 +7257,6 @@ impl<SP: Deref> FundedChannel<SP> where
72627257
self.context.latest_monitor_update_id += 1;
72637258
let monitor_update = ChannelMonitorUpdate {
72647259
update_id: self.context.latest_monitor_update_id,
7265-
counterparty_node_id: Some(self.context.counterparty_node_id),
72667260
updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
72677261
scriptpubkey: self.get_closing_scriptpubkey(),
72687262
}],
@@ -8548,7 +8542,6 @@ impl<SP: Deref> FundedChannel<SP> where
85488542
self.context.latest_monitor_update_id += 1;
85498543
let monitor_update = ChannelMonitorUpdate {
85508544
update_id: self.context.latest_monitor_update_id,
8551-
counterparty_node_id: Some(self.context.counterparty_node_id),
85528545
updates: vec![ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
85538546
commitment_txid: counterparty_commitment_txid,
85548547
htlc_outputs: htlcs.clone(),
@@ -8760,7 +8753,6 @@ impl<SP: Deref> FundedChannel<SP> where
87608753
self.context.latest_monitor_update_id += 1;
87618754
let monitor_update = ChannelMonitorUpdate {
87628755
update_id: self.context.latest_monitor_update_id,
8763-
counterparty_node_id: Some(self.context.counterparty_node_id),
87648756
updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
87658757
scriptpubkey: self.get_closing_scriptpubkey(),
87668758
}],

lightning/src/ln/channelmanager.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7309,7 +7309,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
73097309

73107310
let preimage_update = ChannelMonitorUpdate {
73117311
update_id,
7312-
counterparty_node_id: Some(counterparty_node_id),
73137312
updates: vec![ChannelMonitorUpdateStep::PaymentPreimage {
73147313
payment_preimage,
73157314
payment_info,
@@ -13732,7 +13731,6 @@ where
1373213731
&channel_id);
1373313732
let monitor_update = ChannelMonitorUpdate {
1373413733
update_id: monitor.get_latest_update_id().saturating_add(1),
13735-
counterparty_node_id: Some(counterparty_node_id),
1373613734
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast: true }],
1373713735
channel_id: Some(monitor.channel_id()),
1373813736
};

0 commit comments

Comments
 (0)