Skip to content

Commit 0ffbdbd

Browse files
committed
Drop now-unused Vec of outpoints in remote-commitment-tx-tracking
This nearly fully reverts 6f08779, removing the extra data storage that it added.
1 parent 4e983e8 commit 0ffbdbd

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
631631
/// spending. Thus, in order to claim them via revocation key, we track all the counterparty
632632
/// commitment transactions which we find on-chain, mapping them to the commitment number which
633633
/// can be used to derive the revocation key and claim the transactions.
634-
counterparty_commitment_txn_on_chain: HashMap<Txid, (u64, Vec<Script>)>,
634+
counterparty_commitment_txn_on_chain: HashMap<Txid, u64>,
635635
/// Cache used to make pruning of payment_preimages faster.
636636
/// Maps payment_hash values to commitment numbers for counterparty transactions for non-revoked
637637
/// counterparty transactions (ie should remain pretty small).
@@ -824,13 +824,9 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
824824
}
825825

826826
writer.write_all(&byte_utils::be64_to_array(self.counterparty_commitment_txn_on_chain.len() as u64))?;
827-
for (ref txid, &(commitment_number, ref txouts)) in self.counterparty_commitment_txn_on_chain.iter() {
827+
for (ref txid, commitment_number) in self.counterparty_commitment_txn_on_chain.iter() {
828828
writer.write_all(&txid[..])?;
829-
writer.write_all(&byte_utils::be48_to_array(commitment_number))?;
830-
(txouts.len() as u64).write(writer)?;
831-
for script in txouts.iter() {
832-
script.write(writer)?;
833-
}
829+
writer.write_all(&byte_utils::be48_to_array(*commitment_number))?;
834830
}
835831

836832
writer.write_all(&byte_utils::be64_to_array(self.counterparty_hash_commitment_number.len() as u64))?;
@@ -1215,12 +1211,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
12151211
/// (C-not exported) because we have no HashMap bindings
12161212
pub fn get_outputs_to_watch(&self) -> &HashMap<Txid, Vec<Script>> {
12171213
#[cfg(any(test, feature = "fuzztarget"))]
1218-
for (txid, &(_, ref outputs)) in self.counterparty_commitment_txn_on_chain.iter() {
1219-
let watched_outputs = self.outputs_to_watch.get(txid).expect("Counterparty commitment txn which have been broadcast should have outputs registered");
1220-
assert_eq!(watched_outputs.len(), outputs.len());
1221-
for (watched, output) in watched_outputs.iter().zip(outputs.iter()) {
1222-
assert_eq!(watched, output);
1223-
}
1214+
for (txid, _) in self.counterparty_commitment_txn_on_chain.iter() {
1215+
self.outputs_to_watch.get(txid).expect("Counterparty commitment txn which have been broadcast should have outputs registered");
12241216
}
12251217
&self.outputs_to_watch
12261218
}
@@ -1326,7 +1318,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13261318
// We're definitely a counterparty commitment transaction!
13271319
log_trace!(logger, "Got broadcast of revoked counterparty commitment transaction, going to generate general spend tx with {} inputs", claimable_outpoints.len());
13281320
watch_outputs.append(&mut tx.output.clone());
1329-
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, (commitment_number, tx.output.iter().map(|output| { output.script_pubkey.clone() }).collect()));
1321+
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, commitment_number);
13301322

13311323
macro_rules! check_htlc_fails {
13321324
($txid: expr, $commitment_tx: expr) => {
@@ -1373,7 +1365,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13731365
// not being generated by the above conditional. Thus, to be safe, we go ahead and
13741366
// insert it here.
13751367
watch_outputs.append(&mut tx.output.clone());
1376-
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, (commitment_number, tx.output.iter().map(|output| { output.script_pubkey.clone() }).collect()));
1368+
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, commitment_number);
13771369

13781370
log_trace!(logger, "Got broadcast of non-revoked counterparty commitment transaction {}", commitment_txid);
13791371

@@ -1711,7 +1703,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17111703
claimable_outpoints.append(&mut new_outpoints);
17121704
}
17131705
} else {
1714-
if let Some(&(commitment_number, _)) = self.counterparty_commitment_txn_on_chain.get(&prevout.txid) {
1706+
if let Some(&commitment_number) = self.counterparty_commitment_txn_on_chain.get(&prevout.txid) {
17151707
let (mut new_outpoints, new_outputs_option) = self.check_spend_counterparty_htlc(&tx, commitment_number, height, &logger);
17161708
claimable_outpoints.append(&mut new_outpoints);
17171709
if let Some(new_outputs) = new_outputs_option {
@@ -2203,12 +2195,7 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
22032195
for _ in 0..counterparty_commitment_txn_on_chain_len {
22042196
let txid: Txid = Readable::read(reader)?;
22052197
let commitment_number = <U48 as Readable>::read(reader)?.0;
2206-
let outputs_count = <u64 as Readable>::read(reader)?;
2207-
let mut outputs = Vec::with_capacity(cmp::min(outputs_count as usize, MAX_ALLOC_SIZE / 8));
2208-
for _ in 0..outputs_count {
2209-
outputs.push(Readable::read(reader)?);
2210-
}
2211-
if let Some(_) = counterparty_commitment_txn_on_chain.insert(txid, (commitment_number, outputs)) {
2198+
if let Some(_) = counterparty_commitment_txn_on_chain.insert(txid, commitment_number) {
22122199
return Err(DecodeError::InvalidValue);
22132200
}
22142201
}

0 commit comments

Comments
 (0)