Skip to content

Commit 02e73b8

Browse files
committed
Drop unused CounterpartyCommitmentTransaction::per_htlc HashMap
1 parent 562a677 commit 02e73b8

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,11 @@ struct CounterpartyCommitmentTransaction {
297297
counterparty_delayed_payment_base_key: PublicKey,
298298
counterparty_htlc_base_key: PublicKey,
299299
on_counterparty_tx_csv: u16,
300-
per_htlc: HashMap<Txid, Vec<HTLCOutputInCommitment>>
301300
}
302301

303302
impl Writeable for CounterpartyCommitmentTransaction {
304303
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
305-
w.write_all(&byte_utils::be64_to_array(self.per_htlc.len() as u64))?;
306-
for (ref txid, ref htlcs) in self.per_htlc.iter() {
307-
w.write_all(&txid[..])?;
308-
w.write_all(&byte_utils::be64_to_array(htlcs.len() as u64))?;
309-
for &ref htlc in htlcs.iter() {
310-
htlc.write(w)?;
311-
}
312-
}
304+
w.write_all(&byte_utils::be64_to_array(0))?;
313305
write_tlv_fields!(w, {
314306
(0, self.counterparty_delayed_payment_base_key, required),
315307
(2, self.counterparty_htlc_base_key, required),
@@ -321,20 +313,17 @@ impl Writeable for CounterpartyCommitmentTransaction {
321313
impl Readable for CounterpartyCommitmentTransaction {
322314
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
323315
let counterparty_commitment_transaction = {
316+
// Versions prior to 0.0.100 had some per-HTLC state stored here, which is no longer
317+
// used. Read it for compatibility.
324318
let per_htlc_len: u64 = Readable::read(r)?;
325-
let mut per_htlc = HashMap::with_capacity(cmp::min(per_htlc_len as usize, MAX_ALLOC_SIZE / 64));
326319
for _ in 0..per_htlc_len {
327-
let txid: Txid = Readable::read(r)?;
320+
let _txid: Txid = Readable::read(r)?;
328321
let htlcs_count: u64 = Readable::read(r)?;
329-
let mut htlcs = Vec::with_capacity(cmp::min(htlcs_count as usize, MAX_ALLOC_SIZE / 32));
330322
for _ in 0..htlcs_count {
331-
let htlc = Readable::read(r)?;
332-
htlcs.push(htlc);
333-
}
334-
if let Some(_) = per_htlc.insert(txid, htlcs) {
335-
return Err(DecodeError::InvalidValue);
323+
let _htlc: HTLCOutputInCommitment = Readable::read(r)?;
336324
}
337325
}
326+
338327
let mut counterparty_delayed_payment_base_key = OptionDeserWrapper(None);
339328
let mut counterparty_htlc_base_key = OptionDeserWrapper(None);
340329
let mut on_counterparty_tx_csv: u16 = 0;
@@ -347,7 +336,6 @@ impl Readable for CounterpartyCommitmentTransaction {
347336
counterparty_delayed_payment_base_key: counterparty_delayed_payment_base_key.0.unwrap(),
348337
counterparty_htlc_base_key: counterparty_htlc_base_key.0.unwrap(),
349338
on_counterparty_tx_csv,
350-
per_htlc,
351339
}
352340
};
353341
Ok(counterparty_commitment_transaction)
@@ -855,7 +843,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
855843
let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
856844
let counterparty_delayed_payment_base_key = counterparty_channel_parameters.pubkeys.delayed_payment_basepoint;
857845
let counterparty_htlc_base_key = counterparty_channel_parameters.pubkeys.htlc_basepoint;
858-
let counterparty_tx_cache = CounterpartyCommitmentTransaction { counterparty_delayed_payment_base_key, counterparty_htlc_base_key, on_counterparty_tx_csv, per_htlc: HashMap::new() };
846+
let counterparty_tx_cache = CounterpartyCommitmentTransaction { counterparty_delayed_payment_base_key, counterparty_htlc_base_key, on_counterparty_tx_csv };
859847

860848
let channel_keys_id = keys.channel_keys_id();
861849
let holder_revocation_basepoint = keys.pubkeys().revocation_basepoint;
@@ -1407,7 +1395,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
14071395
htlcs.push(htlc.0);
14081396
}
14091397
}
1410-
self.counterparty_tx_cache.per_htlc.insert(txid, htlcs);
14111398
}
14121399

14131400
/// Informs this monitor of the latest holder (ie broadcastable) commitment transaction. The

0 commit comments

Comments
 (0)