Skip to content

Commit 8f42c0f

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 35813da commit 8f42c0f

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
@@ -4386,7 +4386,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43864386
self.latest_monitor_update_id += 1;
43874387
Some((self.get_counterparty_node_id(), funding_txo, self.channel_id(), ChannelMonitorUpdate {
43884388
update_id: self.latest_monitor_update_id,
4389-
counterparty_node_id: Some(self.counterparty_node_id),
43904389
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast }],
43914390
channel_id: Some(self.channel_id()),
43924391
}))
@@ -4957,7 +4956,6 @@ impl<SP: Deref> FundedChannel<SP> where
49574956
self.context.latest_monitor_update_id += 1;
49584957
let monitor_update = ChannelMonitorUpdate {
49594958
update_id: self.context.latest_monitor_update_id,
4960-
counterparty_node_id: Some(self.context.counterparty_node_id),
49614959
updates: vec![ChannelMonitorUpdateStep::PaymentPreimage {
49624960
payment_preimage: payment_preimage_arg.clone(),
49634961
payment_info,
@@ -5665,7 +5663,6 @@ impl<SP: Deref> FundedChannel<SP> where
56655663
self.context.latest_monitor_update_id += 1;
56665664
let mut monitor_update = ChannelMonitorUpdate {
56675665
update_id: self.context.latest_monitor_update_id,
5668-
counterparty_node_id: Some(self.context.counterparty_node_id),
56695666
updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
56705667
commitment_tx: holder_commitment_tx,
56715668
htlc_outputs: htlcs_and_sigs,
@@ -5759,7 +5756,6 @@ impl<SP: Deref> FundedChannel<SP> where
57595756

57605757
let mut monitor_update = ChannelMonitorUpdate {
57615758
update_id: self.context.latest_monitor_update_id + 1, // We don't increment this yet!
5762-
counterparty_node_id: Some(self.context.counterparty_node_id),
57635759
updates: Vec::new(),
57645760
channel_id: Some(self.context.channel_id()),
57655761
};
@@ -5952,7 +5948,6 @@ impl<SP: Deref> FundedChannel<SP> where
59525948
self.context.latest_monitor_update_id += 1;
59535949
let mut monitor_update = ChannelMonitorUpdate {
59545950
update_id: self.context.latest_monitor_update_id,
5955-
counterparty_node_id: Some(self.context.counterparty_node_id),
59565951
updates: vec![ChannelMonitorUpdateStep::CommitmentSecret {
59575952
idx: self.context.cur_counterparty_commitment_transaction_number + 1,
59585953
secret: msg.per_commitment_secret,
@@ -7224,7 +7219,6 @@ impl<SP: Deref> FundedChannel<SP> where
72247219
self.context.latest_monitor_update_id += 1;
72257220
let monitor_update = ChannelMonitorUpdate {
72267221
update_id: self.context.latest_monitor_update_id,
7227-
counterparty_node_id: Some(self.context.counterparty_node_id),
72287222
updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
72297223
scriptpubkey: self.get_closing_scriptpubkey(),
72307224
}],
@@ -8506,7 +8500,6 @@ impl<SP: Deref> FundedChannel<SP> where
85068500
self.context.latest_monitor_update_id += 1;
85078501
let monitor_update = ChannelMonitorUpdate {
85088502
update_id: self.context.latest_monitor_update_id,
8509-
counterparty_node_id: Some(self.context.counterparty_node_id),
85108503
updates: vec![ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
85118504
commitment_txid: counterparty_commitment_txid,
85128505
htlc_outputs: htlcs.clone(),
@@ -8718,7 +8711,6 @@ impl<SP: Deref> FundedChannel<SP> where
87188711
self.context.latest_monitor_update_id += 1;
87198712
let monitor_update = ChannelMonitorUpdate {
87208713
update_id: self.context.latest_monitor_update_id,
8721-
counterparty_node_id: Some(self.context.counterparty_node_id),
87228714
updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
87238715
scriptpubkey: self.get_closing_scriptpubkey(),
87248716
}],

lightning/src/ln/channelmanager.rs

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

72827282
let preimage_update = ChannelMonitorUpdate {
72837283
update_id,
7284-
counterparty_node_id: Some(counterparty_node_id),
72857284
updates: vec![ChannelMonitorUpdateStep::PaymentPreimage {
72867285
payment_preimage,
72877286
payment_info,
@@ -13704,7 +13703,6 @@ where
1370413703
&channel_id);
1370513704
let monitor_update = ChannelMonitorUpdate {
1370613705
update_id: monitor.get_latest_update_id().saturating_add(1),
13707-
counterparty_node_id: Some(counterparty_node_id),
1370813706
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast: true }],
1370913707
channel_id: Some(monitor.channel_id()),
1371013708
};

0 commit comments

Comments
 (0)