Skip to content

Commit 5155450

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 57802e7 commit 5155450

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

@@ -3191,10 +3181,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31913181
log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
31923182
}
31933183

3194-
if let Some(counterparty_node_id) = &updates.counterparty_node_id {
3195-
debug_assert_eq!(self.counterparty_node_id, *counterparty_node_id);
3196-
}
3197-
31983184
// ChannelMonitor updates may be applied after force close if we receive a preimage for a
31993185
// broadcasted commitment transaction HTLC output that we'd like to claim on-chain. If this
32003186
// 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
@@ -4404,7 +4404,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
44044404
self.latest_monitor_update_id += 1;
44054405
Some((self.get_counterparty_node_id(), funding_txo, self.channel_id(), ChannelMonitorUpdate {
44064406
update_id: self.latest_monitor_update_id,
4407-
counterparty_node_id: Some(self.counterparty_node_id),
44084407
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast }],
44094408
channel_id: Some(self.channel_id()),
44104409
}))
@@ -4975,7 +4974,6 @@ impl<SP: Deref> FundedChannel<SP> where
49754974
self.context.latest_monitor_update_id += 1;
49764975
let monitor_update = ChannelMonitorUpdate {
49774976
update_id: self.context.latest_monitor_update_id,
4978-
counterparty_node_id: Some(self.context.counterparty_node_id),
49794977
updates: vec![ChannelMonitorUpdateStep::PaymentPreimage {
49804978
payment_preimage: payment_preimage_arg.clone(),
49814979
payment_info,
@@ -5666,7 +5664,6 @@ impl<SP: Deref> FundedChannel<SP> where
56665664
self.context.latest_monitor_update_id += 1;
56675665
let mut monitor_update = ChannelMonitorUpdate {
56685666
update_id: self.context.latest_monitor_update_id,
5669-
counterparty_node_id: Some(self.context.counterparty_node_id),
56705667
updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
56715668
commitment_tx: holder_commitment_tx,
56725669
htlc_outputs: htlcs_and_sigs,
@@ -5760,7 +5757,6 @@ impl<SP: Deref> FundedChannel<SP> where
57605757

57615758
let mut monitor_update = ChannelMonitorUpdate {
57625759
update_id: self.context.latest_monitor_update_id + 1, // We don't increment this yet!
5763-
counterparty_node_id: Some(self.context.counterparty_node_id),
57645760
updates: Vec::new(),
57655761
channel_id: Some(self.context.channel_id()),
57665762
};
@@ -5953,7 +5949,6 @@ impl<SP: Deref> FundedChannel<SP> where
59535949
self.context.latest_monitor_update_id += 1;
59545950
let mut monitor_update = ChannelMonitorUpdate {
59555951
update_id: self.context.latest_monitor_update_id,
5956-
counterparty_node_id: Some(self.context.counterparty_node_id),
59575952
updates: vec![ChannelMonitorUpdateStep::CommitmentSecret {
59585953
idx: self.context.cur_counterparty_commitment_transaction_number + 1,
59595954
secret: msg.per_commitment_secret,
@@ -7225,7 +7220,6 @@ impl<SP: Deref> FundedChannel<SP> where
72257220
self.context.latest_monitor_update_id += 1;
72267221
let monitor_update = ChannelMonitorUpdate {
72277222
update_id: self.context.latest_monitor_update_id,
7228-
counterparty_node_id: Some(self.context.counterparty_node_id),
72297223
updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
72307224
scriptpubkey: self.get_closing_scriptpubkey(),
72317225
}],
@@ -8507,7 +8501,6 @@ impl<SP: Deref> FundedChannel<SP> where
85078501
self.context.latest_monitor_update_id += 1;
85088502
let monitor_update = ChannelMonitorUpdate {
85098503
update_id: self.context.latest_monitor_update_id,
8510-
counterparty_node_id: Some(self.context.counterparty_node_id),
85118504
updates: vec![ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
85128505
commitment_txid: counterparty_commitment_txid,
85138506
htlc_outputs: htlcs.clone(),
@@ -8719,7 +8712,6 @@ impl<SP: Deref> FundedChannel<SP> where
87198712
self.context.latest_monitor_update_id += 1;
87208713
let monitor_update = ChannelMonitorUpdate {
87218714
update_id: self.context.latest_monitor_update_id,
8722-
counterparty_node_id: Some(self.context.counterparty_node_id),
87238715
updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
87248716
scriptpubkey: self.get_closing_scriptpubkey(),
87258717
}],

lightning/src/ln/channelmanager.rs

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

72957295
let preimage_update = ChannelMonitorUpdate {
72967296
update_id,
7297-
counterparty_node_id: Some(counterparty_node_id),
72987297
updates: vec![ChannelMonitorUpdateStep::PaymentPreimage {
72997298
payment_preimage,
73007299
payment_info,
@@ -13717,7 +13716,6 @@ where
1371713716
&channel_id);
1371813717
let monitor_update = ChannelMonitorUpdate {
1371913718
update_id: monitor.get_latest_update_id().saturating_add(1),
13720-
counterparty_node_id: Some(counterparty_node_id),
1372113719
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast: true }],
1372213720
channel_id: Some(monitor.channel_id()),
1372313721
};

0 commit comments

Comments
 (0)