Skip to content

Commit eb6a39d

Browse files
committed
Remove funding outpoint from MonitorEvent enum
1 parent ab7e4e4 commit eb6a39d

File tree

4 files changed

+19
-28
lines changed

4 files changed

+19
-28
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ where C::Target: chain::Filter,
301301
monitor_state.channel_perm_failed.store(true, Ordering::Release);
302302
let mut pending_monitor_events = self.pending_monitor_events.lock().unwrap();
303303
let events = pending_monitor_events.entry(*funding_outpoint).or_insert(Vec::new());
304-
events.push(MonitorEvent::UpdateFailed(*funding_outpoint));
304+
events.push(MonitorEvent::UpdateFailed);
305305
drop(pending_monitor_events);
306306
},
307307
Err(ChannelMonitorUpdateErr::TemporaryFailure) => {
@@ -461,7 +461,6 @@ where C::Target: chain::Filter,
461461
let mut pending_monitor_events = self.pending_monitor_events.lock().unwrap();
462462
let events = pending_monitor_events.entry(funding_txo).or_insert(Vec::new());
463463
events.push(MonitorEvent::UpdateCompleted {
464-
funding_txo,
465464
monitor_update_id: monitor_data.monitor.get_latest_update_id(),
466465
});
467466
drop(pending_monitor_events);
@@ -485,7 +484,6 @@ where C::Target: chain::Filter,
485484
let mut pending_monitor_events = self.pending_monitor_events.lock().unwrap();
486485
let events = pending_monitor_events.entry(funding_txo).or_insert(Vec::new());
487486
events.push(MonitorEvent::UpdateCompleted {
488-
funding_txo,
489487
monitor_update_id,
490488
});
491489
}

lightning/src/chain/channelmonitor.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,13 @@ pub enum MonitorEvent {
122122
HTLCEvent(HTLCUpdate),
123123

124124
/// A monitor event that the Channel's commitment transaction was confirmed.
125-
CommitmentTxConfirmed(OutPoint),
125+
CommitmentTxConfirmed,
126126

127127
/// Indicates a [`ChannelMonitor`] update has completed. See
128128
/// [`ChannelMonitorUpdateErr::TemporaryFailure`] for more information on how this is used.
129129
///
130130
/// [`ChannelMonitorUpdateErr::TemporaryFailure`]: super::ChannelMonitorUpdateErr::TemporaryFailure
131131
UpdateCompleted {
132-
/// The funding outpoint of the [`ChannelMonitor`] that was updated
133-
funding_txo: OutPoint,
134132
/// The Update ID from [`ChannelMonitorUpdate::update_id`] which was applied or
135133
/// [`ChannelMonitor::get_latest_update_id`].
136134
///
@@ -143,19 +141,18 @@ pub enum MonitorEvent {
143141
/// [`ChannelMonitorUpdateErr::PermanentFailure`] for more information on how this is used.
144142
///
145143
/// [`ChannelMonitorUpdateErr::PermanentFailure`]: super::ChannelMonitorUpdateErr::PermanentFailure
146-
UpdateFailed(OutPoint),
144+
UpdateFailed,
147145
}
148146
impl_writeable_tlv_based_enum_upgradable!(MonitorEvent,
149147
// Note that UpdateCompleted and UpdateFailed are currently never serialized to disk as they are
150148
// generated only in ChainMonitor
151-
(0, UpdateCompleted) => {
152-
(0, funding_txo, required),
153-
(2, monitor_update_id, required),
149+
(1, UpdateCompleted) => {
150+
(0, monitor_update_id, required),
154151
},
152+
(3, CommitmentTxConfirmed) => {},
153+
(5, UpdateFailed) => {},
155154
;
156155
(2, HTLCEvent),
157-
(4, CommitmentTxConfirmed),
158-
(6, UpdateFailed),
159156
);
160157

161158
/// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
@@ -166,14 +163,12 @@ pub struct HTLCUpdate {
166163
pub(crate) payment_hash: PaymentHash,
167164
pub(crate) payment_preimage: Option<PaymentPreimage>,
168165
pub(crate) source: HTLCSource,
169-
pub(crate) sink_channel_id: Option<[u8; 32]>,
170166
pub(crate) onchain_value_satoshis: Option<u64>,
171167
}
172168
impl_writeable_tlv_based!(HTLCUpdate, {
173169
(0, payment_hash, required),
174170
(1, onchain_value_satoshis, option),
175171
(2, source, required),
176-
(3, sink_channel_id, option),
177172
(4, payment_preimage, option),
178173
});
179174

@@ -903,7 +898,7 @@ impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
903898

904899
writer.write_all(&(self.pending_monitor_events.iter().filter(|ev| match ev {
905900
MonitorEvent::HTLCEvent(_) => true,
906-
MonitorEvent::CommitmentTxConfirmed(_) => true,
901+
MonitorEvent::CommitmentTxConfirmed => true,
907902
_ => false,
908903
}).count() as u64).to_be_bytes())?;
909904
for event in self.pending_monitor_events.iter() {
@@ -912,7 +907,7 @@ impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
912907
0u8.write(writer)?;
913908
upd.write(writer)?;
914909
},
915-
MonitorEvent::CommitmentTxConfirmed(_) => 1u8.write(writer)?,
910+
MonitorEvent::CommitmentTxConfirmed => 1u8.write(writer)?,
916911
_ => {}, // Covered in the TLV writes below
917912
}
918913
}
@@ -1893,7 +1888,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18931888
log_info!(logger, "Broadcasting local {}", log_tx!(tx));
18941889
broadcaster.broadcast_transaction(tx);
18951890
}
1896-
self.pending_monitor_events.push(MonitorEvent::CommitmentTxConfirmed(self.funding_info.0));
1891+
self.pending_monitor_events.push(MonitorEvent::CommitmentTxConfirmed);
18971892
}
18981893

18991894
pub fn update_monitor<B: Deref, F: Deref, L: Deref>(&mut self, updates: &ChannelMonitorUpdate, broadcaster: &B, fee_estimator: &F, logger: &L) -> Result<(), ()>
@@ -2483,7 +2478,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
24832478
let funding_outp = HolderFundingOutput::build(self.funding_redeemscript.clone());
24842479
let commitment_package = PackageTemplate::build_package(self.funding_info.0.txid.clone(), self.funding_info.0.index as u32, PackageSolvingData::HolderFundingOutput(funding_outp), self.best_block.height(), false, self.best_block.height());
24852480
claimable_outpoints.push(commitment_package);
2486-
self.pending_monitor_events.push(MonitorEvent::CommitmentTxConfirmed(self.funding_info.0));
2481+
self.pending_monitor_events.push(MonitorEvent::CommitmentTxConfirmed);
24872482
let commitment_tx = self.onchain_tx_handler.get_fully_signed_holder_tx(&self.funding_redeemscript);
24882483
self.holder_tx_signed = true;
24892484
// Because we're broadcasting a commitment transaction, we should construct the package
@@ -2547,7 +2542,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
25472542
payment_preimage: None,
25482543
source: source.clone(),
25492544
onchain_value_satoshis,
2550-
sink_channel_id: Some(self.funding_info.0.to_channel_id()),
25512545
}));
25522546
if let Some(idx) = input_idx {
25532547
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC { input_idx: idx, payment_preimage: None });
@@ -2887,7 +2881,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
28872881
payment_preimage: Some(payment_preimage),
28882882
payment_hash,
28892883
onchain_value_satoshis: Some(amount_msat / 1000),
2890-
sink_channel_id: Some(self.funding_info.0.to_channel_id()),
28912884
}));
28922885
}
28932886
} else if offered_preimage_claim {
@@ -2909,7 +2902,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
29092902
payment_preimage: Some(payment_preimage),
29102903
payment_hash,
29112904
onchain_value_satoshis: Some(amount_msat / 1000),
2912-
sink_channel_id: Some(self.funding_info.0.to_channel_id()),
29132905
}));
29142906
}
29152907
} else {
@@ -3195,7 +3187,7 @@ impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
31953187
for _ in 0..pending_monitor_events_len {
31963188
let ev = match <u8 as Readable>::read(reader)? {
31973189
0 => MonitorEvent::HTLCEvent(Readable::read(reader)?),
3198-
1 => MonitorEvent::CommitmentTxConfirmed(funding_info.0),
3190+
1 => MonitorEvent::CommitmentTxConfirmed,
31993191
_ => return Err(DecodeError::InvalidValue)
32003192
};
32013193
pending_monitor_events.as_mut().unwrap().push(ev);

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,7 +4044,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
40444044

40454045
let mut pending_events = self.pending_events.lock().unwrap();
40464046
let source_channel_id = Some(prev_outpoint.to_channel_id());
4047-
// let sink_channel_id = Some(funding_txo.to_channel_id());
40484047
let sink_channel_id = Some(sink_channel_id);
40494048

40504049
pending_events.push(events::Event::PaymentForwarded {
@@ -4836,21 +4835,21 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48364835
self.fail_htlc_backwards_internal(self.channel_state.lock().unwrap(), htlc_update.source, &htlc_update.payment_hash, HTLCFailReason::Reason { failure_code: 0x4000 | 8, data: Vec::new() });
48374836
}
48384837
},
4839-
MonitorEvent::CommitmentTxConfirmed(funding_outpoint) |
4840-
MonitorEvent::UpdateFailed(funding_outpoint) => {
4838+
MonitorEvent::CommitmentTxConfirmed |
4839+
MonitorEvent::UpdateFailed => {
48414840
let mut channel_lock = self.channel_state.lock().unwrap();
48424841
let channel_state = &mut *channel_lock;
48434842
let by_id = &mut channel_state.by_id;
48444843
let pending_msg_events = &mut channel_state.pending_msg_events;
4845-
if let hash_map::Entry::Occupied(chan_entry) = by_id.entry(funding_outpoint.to_channel_id()) {
4844+
if let hash_map::Entry::Occupied(chan_entry) = by_id.entry(funding_txo.to_channel_id()) {
48464845
let mut chan = remove_channel!(self, channel_state, chan_entry);
48474846
failed_channels.push(chan.force_shutdown(false));
48484847
if let Ok(update) = self.get_channel_update_for_broadcast(&chan) {
48494848
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
48504849
msg: update
48514850
});
48524851
}
4853-
let reason = if let MonitorEvent::UpdateFailed(_) = monitor_event {
4852+
let reason = if let MonitorEvent::UpdateFailed = monitor_event {
48544853
ClosureReason::ProcessingError { err: "Failed to persist ChannelMonitor update during chain sync".to_string() }
48554854
} else {
48564855
ClosureReason::CommitmentTxConfirmed
@@ -4864,7 +4863,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
48644863
});
48654864
}
48664865
},
4867-
MonitorEvent::UpdateCompleted { funding_txo, monitor_update_id } => {
4866+
MonitorEvent::UpdateCompleted { monitor_update_id } => {
48684867
self.channel_monitor_updated(&funding_txo, monitor_update_id);
48694868
},
48704869
}

lightning/src/util/events.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ pub enum Event {
346346
/// The channel between the source node and us. Optional because versions prior to 0.0.107
347347
/// do not serialize this field.
348348
source_channel_id: Option<[u8; 32]>,
349+
/// The channel between the destination node and us. Optional because versions prior to 0.0.107
350+
/// do not serialize this field.
349351
sink_channel_id: Option<[u8; 32]>,
350352
/// The fee, in milli-satoshis, which was earned as a result of the payment.
351353
///

0 commit comments

Comments
 (0)