Skip to content

Commit 61e940f

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 1771fae commit 61e940f

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

@@ -3194,10 +3184,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31943184
log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
31953185
}
31963186

3197-
if let Some(counterparty_node_id) = &updates.counterparty_node_id {
3198-
debug_assert_eq!(self.counterparty_node_id, *counterparty_node_id);
3199-
}
3200-
32013187
// ChannelMonitor updates may be applied after force close if we receive a preimage for a
32023188
// broadcasted commitment transaction HTLC output that we'd like to claim on-chain. If this
32033189
// 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
@@ -4385,7 +4385,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43854385
self.latest_monitor_update_id += 1;
43864386
Some((self.get_counterparty_node_id(), funding_txo, self.channel_id(), ChannelMonitorUpdate {
43874387
update_id: self.latest_monitor_update_id,
4388-
counterparty_node_id: Some(self.counterparty_node_id),
43894388
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast }],
43904389
channel_id: Some(self.channel_id()),
43914390
}))
@@ -4956,7 +4955,6 @@ impl<SP: Deref> FundedChannel<SP> where
49564955
self.context.latest_monitor_update_id += 1;
49574956
let monitor_update = ChannelMonitorUpdate {
49584957
update_id: self.context.latest_monitor_update_id,
4959-
counterparty_node_id: Some(self.context.counterparty_node_id),
49604958
updates: vec![ChannelMonitorUpdateStep::PaymentPreimage {
49614959
payment_preimage: payment_preimage_arg.clone(),
49624960
payment_info,
@@ -5664,7 +5662,6 @@ impl<SP: Deref> FundedChannel<SP> where
56645662
self.context.latest_monitor_update_id += 1;
56655663
let mut monitor_update = ChannelMonitorUpdate {
56665664
update_id: self.context.latest_monitor_update_id,
5667-
counterparty_node_id: Some(self.context.counterparty_node_id),
56685665
updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
56695666
commitment_tx: holder_commitment_tx,
56705667
htlc_outputs: htlcs_and_sigs,
@@ -5758,7 +5755,6 @@ impl<SP: Deref> FundedChannel<SP> where
57585755

57595756
let mut monitor_update = ChannelMonitorUpdate {
57605757
update_id: self.context.latest_monitor_update_id + 1, // We don't increment this yet!
5761-
counterparty_node_id: Some(self.context.counterparty_node_id),
57625758
updates: Vec::new(),
57635759
channel_id: Some(self.context.channel_id()),
57645760
};
@@ -5951,7 +5947,6 @@ impl<SP: Deref> FundedChannel<SP> where
59515947
self.context.latest_monitor_update_id += 1;
59525948
let mut monitor_update = ChannelMonitorUpdate {
59535949
update_id: self.context.latest_monitor_update_id,
5954-
counterparty_node_id: Some(self.context.counterparty_node_id),
59555950
updates: vec![ChannelMonitorUpdateStep::CommitmentSecret {
59565951
idx: self.context.cur_counterparty_commitment_transaction_number + 1,
59575952
secret: msg.per_commitment_secret,
@@ -7223,7 +7218,6 @@ impl<SP: Deref> FundedChannel<SP> where
72237218
self.context.latest_monitor_update_id += 1;
72247219
let monitor_update = ChannelMonitorUpdate {
72257220
update_id: self.context.latest_monitor_update_id,
7226-
counterparty_node_id: Some(self.context.counterparty_node_id),
72277221
updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
72287222
scriptpubkey: self.get_closing_scriptpubkey(),
72297223
}],
@@ -8505,7 +8499,6 @@ impl<SP: Deref> FundedChannel<SP> where
85058499
self.context.latest_monitor_update_id += 1;
85068500
let monitor_update = ChannelMonitorUpdate {
85078501
update_id: self.context.latest_monitor_update_id,
8508-
counterparty_node_id: Some(self.context.counterparty_node_id),
85098502
updates: vec![ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
85108503
commitment_txid: counterparty_commitment_txid,
85118504
htlc_outputs: htlcs.clone(),
@@ -8717,7 +8710,6 @@ impl<SP: Deref> FundedChannel<SP> where
87178710
self.context.latest_monitor_update_id += 1;
87188711
let monitor_update = ChannelMonitorUpdate {
87198712
update_id: self.context.latest_monitor_update_id,
8720-
counterparty_node_id: Some(self.context.counterparty_node_id),
87218713
updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
87228714
scriptpubkey: self.get_closing_scriptpubkey(),
87238715
}],

lightning/src/ln/channelmanager.rs

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

72787278
let preimage_update = ChannelMonitorUpdate {
72797279
update_id,
7280-
counterparty_node_id: Some(counterparty_node_id),
72817280
updates: vec![ChannelMonitorUpdateStep::PaymentPreimage {
72827281
payment_preimage,
72837282
payment_info,
@@ -13700,7 +13699,6 @@ where
1370013699
&channel_id);
1370113700
let monitor_update = ChannelMonitorUpdate {
1370213701
update_id: monitor.get_latest_update_id().saturating_add(1),
13703-
counterparty_node_id: Some(counterparty_node_id),
1370413702
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast: true }],
1370513703
channel_id: Some(monitor.channel_id()),
1370613704
};

0 commit comments

Comments
 (0)