Skip to content

Commit 5d228b2

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 7377313 commit 5d228b2

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
@@ -4398,7 +4398,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43984398
self.latest_monitor_update_id += 1;
43994399
Some((self.get_counterparty_node_id(), funding_txo, self.channel_id(), ChannelMonitorUpdate {
44004400
update_id: self.latest_monitor_update_id,
4401-
counterparty_node_id: Some(self.counterparty_node_id),
44024401
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast }],
44034402
channel_id: Some(self.channel_id()),
44044403
}))
@@ -4969,7 +4968,6 @@ impl<SP: Deref> FundedChannel<SP> where
49694968
self.context.latest_monitor_update_id += 1;
49704969
let monitor_update = ChannelMonitorUpdate {
49714970
update_id: self.context.latest_monitor_update_id,
4972-
counterparty_node_id: Some(self.context.counterparty_node_id),
49734971
updates: vec![ChannelMonitorUpdateStep::PaymentPreimage {
49744972
payment_preimage: payment_preimage_arg.clone(),
49754973
payment_info,
@@ -5670,7 +5668,6 @@ impl<SP: Deref> FundedChannel<SP> where
56705668
self.context.latest_monitor_update_id += 1;
56715669
let mut monitor_update = ChannelMonitorUpdate {
56725670
update_id: self.context.latest_monitor_update_id,
5673-
counterparty_node_id: Some(self.context.counterparty_node_id),
56745671
updates: vec![ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo {
56755672
commitment_tx: holder_commitment_tx,
56765673
htlc_outputs: htlcs_and_sigs,
@@ -5764,7 +5761,6 @@ impl<SP: Deref> FundedChannel<SP> where
57645761

57655762
let mut monitor_update = ChannelMonitorUpdate {
57665763
update_id: self.context.latest_monitor_update_id + 1, // We don't increment this yet!
5767-
counterparty_node_id: Some(self.context.counterparty_node_id),
57685764
updates: Vec::new(),
57695765
channel_id: Some(self.context.channel_id()),
57705766
};
@@ -5957,7 +5953,6 @@ impl<SP: Deref> FundedChannel<SP> where
59575953
self.context.latest_monitor_update_id += 1;
59585954
let mut monitor_update = ChannelMonitorUpdate {
59595955
update_id: self.context.latest_monitor_update_id,
5960-
counterparty_node_id: Some(self.context.counterparty_node_id),
59615956
updates: vec![ChannelMonitorUpdateStep::CommitmentSecret {
59625957
idx: self.context.cur_counterparty_commitment_transaction_number + 1,
59635958
secret: msg.per_commitment_secret,
@@ -7229,7 +7224,6 @@ impl<SP: Deref> FundedChannel<SP> where
72297224
self.context.latest_monitor_update_id += 1;
72307225
let monitor_update = ChannelMonitorUpdate {
72317226
update_id: self.context.latest_monitor_update_id,
7232-
counterparty_node_id: Some(self.context.counterparty_node_id),
72337227
updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
72347228
scriptpubkey: self.get_closing_scriptpubkey(),
72357229
}],
@@ -8511,7 +8505,6 @@ impl<SP: Deref> FundedChannel<SP> where
85118505
self.context.latest_monitor_update_id += 1;
85128506
let monitor_update = ChannelMonitorUpdate {
85138507
update_id: self.context.latest_monitor_update_id,
8514-
counterparty_node_id: Some(self.context.counterparty_node_id),
85158508
updates: vec![ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
85168509
commitment_txid: counterparty_commitment_txid,
85178510
htlc_outputs: htlcs.clone(),
@@ -8723,7 +8716,6 @@ impl<SP: Deref> FundedChannel<SP> where
87238716
self.context.latest_monitor_update_id += 1;
87248717
let monitor_update = ChannelMonitorUpdate {
87258718
update_id: self.context.latest_monitor_update_id,
8726-
counterparty_node_id: Some(self.context.counterparty_node_id),
87278719
updates: vec![ChannelMonitorUpdateStep::ShutdownScript {
87288720
scriptpubkey: self.get_closing_scriptpubkey(),
87298721
}],

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)