Skip to content

Commit 0e41bba

Browse files
committed
Give OnchainEvent::HTLCUpdate individual fields instead of a pair
1 parent 77bdc32 commit 0e41bba

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ enum OnchainEvent {
351351
/// inbound HTLC in backward channel. Note, in case of preimage, we pass info to upstream without delay as we can
352352
/// only win from it, so it's never an OnchainEvent
353353
HTLCUpdate {
354-
htlc_update: (HTLCSource, PaymentHash),
354+
source: HTLCSource,
355+
payment_hash: PaymentHash,
355356
},
356357
MaturingOutput {
357358
descriptor: SpendableOutputDescriptor,
@@ -818,10 +819,10 @@ impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
818819
entry.txid.write(writer)?;
819820
writer.write_all(&byte_utils::be32_to_array(entry.height))?;
820821
match entry.event {
821-
OnchainEvent::HTLCUpdate { ref htlc_update } => {
822+
OnchainEvent::HTLCUpdate { ref source, ref payment_hash } => {
822823
0u8.write(writer)?;
823-
htlc_update.0.write(writer)?;
824-
htlc_update.1.write(writer)?;
824+
source.write(writer)?;
825+
payment_hash.write(writer)?;
825826
},
826827
OnchainEvent::MaturingOutput { ref descriptor } => {
827828
1u8.write(writer)?;
@@ -1609,17 +1610,18 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16091610
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| {
16101611
if entry.height != height { return true; }
16111612
match entry.event {
1612-
OnchainEvent::HTLCUpdate { ref htlc_update } => {
1613-
htlc_update.0 != **source
1614-
},
1615-
_ => true,
1613+
OnchainEvent::HTLCUpdate { source: ref update_source, .. } => {
1614+
*update_source != **source
1615+
},
1616+
_ => true,
16161617
}
16171618
});
16181619
let entry = OnchainEventEntry {
16191620
txid: *$txid,
16201621
height,
16211622
event: OnchainEvent::HTLCUpdate {
1622-
htlc_update: ((**source).clone(), htlc.payment_hash.clone())
1623+
source: (**source).clone(),
1624+
payment_hash: htlc.payment_hash.clone(),
16231625
},
16241626
};
16251627
log_info!(logger, "Failing HTLC with payment_hash {} from {} counterparty commitment tx due to broadcast of revoked counterparty commitment transaction, waiting for confirmation (at height {})", log_bytes!(htlc.payment_hash.0), $commitment_tx, entry.confirmation_threshold());
@@ -1675,17 +1677,18 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16751677
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| {
16761678
if entry.height != height { return true; }
16771679
match entry.event {
1678-
OnchainEvent::HTLCUpdate { ref htlc_update } => {
1679-
htlc_update.0 != **source
1680-
},
1681-
_ => true,
1680+
OnchainEvent::HTLCUpdate { source: ref update_source, .. } => {
1681+
*update_source != **source
1682+
},
1683+
_ => true,
16821684
}
16831685
});
16841686
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
16851687
txid: *$txid,
16861688
height,
16871689
event: OnchainEvent::HTLCUpdate {
1688-
htlc_update: ((**source).clone(), htlc.payment_hash.clone())
1690+
source: (**source).clone(),
1691+
payment_hash: htlc.payment_hash.clone(),
16891692
},
16901693
});
16911694
}
@@ -1829,16 +1832,16 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18291832
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| {
18301833
if entry.height != height { return true; }
18311834
match entry.event {
1832-
OnchainEvent::HTLCUpdate { ref htlc_update } => {
1833-
htlc_update.0 != $source
1834-
},
1835-
_ => true,
1835+
OnchainEvent::HTLCUpdate { source: ref update_source, .. } => {
1836+
*update_source != $source
1837+
},
1838+
_ => true,
18361839
}
18371840
});
18381841
let entry = OnchainEventEntry {
18391842
txid: commitment_txid,
18401843
height,
1841-
event: OnchainEvent::HTLCUpdate { htlc_update: ($source, $payment_hash) },
1844+
event: OnchainEvent::HTLCUpdate { source: $source, payment_hash: $payment_hash },
18421845
};
18431846
log_trace!(logger, "Failing HTLC with payment_hash {} from {} holder commitment tx due to broadcast of transaction, waiting confirmation (at height{})", log_bytes!($payment_hash.0), $commitment_tx, entry.confirmation_threshold());
18441847
self.onchain_events_awaiting_threshold_conf.push(entry);
@@ -2109,7 +2112,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
21092112
let unmatured_htlcs: Vec<_> = self.onchain_events_awaiting_threshold_conf
21102113
.iter()
21112114
.filter_map(|entry| match &entry.event {
2112-
OnchainEvent::HTLCUpdate { htlc_update } => Some(htlc_update.0.clone()),
2115+
OnchainEvent::HTLCUpdate { source, .. } => Some(source),
21132116
OnchainEvent::MaturingOutput { .. } => None,
21142117
})
21152118
.collect();
@@ -2119,28 +2122,28 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
21192122
// Produce actionable events from on-chain events having reached their threshold.
21202123
for entry in onchain_events_reaching_threshold_conf.drain(..) {
21212124
match entry.event {
2122-
OnchainEvent::HTLCUpdate { htlc_update } => {
2125+
OnchainEvent::HTLCUpdate { ref source, payment_hash } => {
21232126
// Check for duplicate HTLC resolutions.
21242127
#[cfg(debug_assertions)]
21252128
{
21262129
debug_assert!(
2127-
unmatured_htlcs.iter().find(|&htlc| htlc == &htlc_update.0).is_none(),
2130+
unmatured_htlcs.iter().find(|&htlc| htlc == &source).is_none(),
21282131
"An unmature HTLC transaction conflicts with a maturing one; failed to \
21292132
call either transaction_unconfirmed for the conflicting transaction \
21302133
or block_disconnected for a block containing it.");
21312134
debug_assert!(
2132-
matured_htlcs.iter().find(|&htlc| htlc == &htlc_update.0).is_none(),
2135+
matured_htlcs.iter().find(|&htlc| htlc == source).is_none(),
21332136
"A matured HTLC transaction conflicts with a maturing one; failed to \
21342137
call either transaction_unconfirmed for the conflicting transaction \
21352138
or block_disconnected for a block containing it.");
2136-
matured_htlcs.push(htlc_update.0.clone());
2139+
matured_htlcs.push(source.clone());
21372140
}
21382141

2139-
log_trace!(logger, "HTLC {} failure update has got enough confirmations to be passed upstream", log_bytes!((htlc_update.1).0));
2142+
log_trace!(logger, "HTLC {} failure update has got enough confirmations to be passed upstream", log_bytes!(payment_hash.0));
21402143
self.pending_monitor_events.push(MonitorEvent::HTLCEvent(HTLCUpdate {
2141-
payment_hash: htlc_update.1,
2144+
payment_hash: payment_hash,
21422145
payment_preimage: None,
2143-
source: htlc_update.0,
2146+
source: source.clone(),
21442147
}));
21452148
},
21462149
OnchainEvent::MaturingOutput { descriptor } => {
@@ -2437,16 +2440,16 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
24372440
self.onchain_events_awaiting_threshold_conf.retain(|ref entry| {
24382441
if entry.height != height { return true; }
24392442
match entry.event {
2440-
OnchainEvent::HTLCUpdate { ref htlc_update } => {
2441-
htlc_update.0 != source
2442-
},
2443-
_ => true,
2443+
OnchainEvent::HTLCUpdate { source: ref htlc_source, .. } => {
2444+
*htlc_source != source
2445+
},
2446+
_ => true,
24442447
}
24452448
});
24462449
let entry = OnchainEventEntry {
24472450
txid: tx.txid(),
24482451
height,
2449-
event: OnchainEvent::HTLCUpdate { htlc_update: (source, payment_hash) },
2452+
event: OnchainEvent::HTLCUpdate { source: source, payment_hash: payment_hash },
24502453
};
24512454
log_info!(logger, "Failing HTLC with payment_hash {} timeout by a spend tx, waiting for confirmation (at height{})", log_bytes!(payment_hash.0), entry.confirmation_threshold());
24522455
self.onchain_events_awaiting_threshold_conf.push(entry);
@@ -2808,7 +2811,8 @@ impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
28082811
let htlc_source = Readable::read(reader)?;
28092812
let hash = Readable::read(reader)?;
28102813
OnchainEvent::HTLCUpdate {
2811-
htlc_update: (htlc_source, hash)
2814+
source: htlc_source,
2815+
payment_hash: hash,
28122816
}
28132817
},
28142818
1 => {

0 commit comments

Comments
 (0)