Skip to content

Commit 77b4288

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 d129d21 commit 77b4288

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
@@ -626,7 +626,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
626626
/// spending. Thus, in order to claim them via revocation key, we track all the counterparty
627627
/// commitment transactions which we find on-chain, mapping them to the commitment number which
628628
/// can be used to derive the revocation key and claim the transactions.
629-
counterparty_commitment_txn_on_chain: HashMap<Txid, (u64, Vec<Script>)>,
629+
counterparty_commitment_txn_on_chain: HashMap<Txid, u64>,
630630
/// Cache used to make pruning of payment_preimages faster.
631631
/// Maps payment_hash values to commitment numbers for counterparty transactions for non-revoked
632632
/// counterparty transactions (ie should remain pretty small).
@@ -819,13 +819,9 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
819819
}
820820

821821
writer.write_all(&byte_utils::be64_to_array(self.counterparty_commitment_txn_on_chain.len() as u64))?;
822-
for (ref txid, &(commitment_number, ref txouts)) in self.counterparty_commitment_txn_on_chain.iter() {
822+
for (ref txid, commitment_number) in self.counterparty_commitment_txn_on_chain.iter() {
823823
writer.write_all(&txid[..])?;
824-
writer.write_all(&byte_utils::be48_to_array(commitment_number))?;
825-
(txouts.len() as u64).write(writer)?;
826-
for script in txouts.iter() {
827-
script.write(writer)?;
828-
}
824+
writer.write_all(&byte_utils::be48_to_array(*commitment_number))?;
829825
}
830826

831827
writer.write_all(&byte_utils::be64_to_array(self.counterparty_hash_commitment_number.len() as u64))?;
@@ -1210,12 +1206,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
12101206
/// (C-not exported) because we have no HashMap bindings
12111207
pub fn get_outputs_to_watch(&self) -> &HashMap<Txid, Vec<Script>> {
12121208
#[cfg(any(test, feature = "fuzztarget"))]
1213-
for (txid, &(_, ref outputs)) in self.counterparty_commitment_txn_on_chain.iter() {
1214-
let watched_outputs = self.outputs_to_watch.get(txid).expect("Counterparty commitment txn which have been broadcast should have outputs registered");
1215-
assert_eq!(watched_outputs.len(), outputs.len());
1216-
for (watched, output) in watched_outputs.iter().zip(outputs.iter()) {
1217-
assert_eq!(watched, output);
1218-
}
1209+
for (txid, _) in self.counterparty_commitment_txn_on_chain.iter() {
1210+
self.outputs_to_watch.get(txid).expect("Counterparty commitment txn which have been broadcast should have outputs registered");
12191211
}
12201212
&self.outputs_to_watch
12211213
}
@@ -1321,7 +1313,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13211313
// We're definitely a counterparty commitment transaction!
13221314
log_trace!(logger, "Got broadcast of revoked counterparty commitment transaction, going to generate general spend tx with {} inputs", claimable_outpoints.len());
13231315
watch_outputs.append(&mut tx.output.clone());
1324-
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, (commitment_number, tx.output.iter().map(|output| { output.script_pubkey.clone() }).collect()));
1316+
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, commitment_number);
13251317

13261318
macro_rules! check_htlc_fails {
13271319
($txid: expr, $commitment_tx: expr) => {
@@ -1368,7 +1360,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13681360
// not being generated by the above conditional. Thus, to be safe, we go ahead and
13691361
// insert it here.
13701362
watch_outputs.append(&mut tx.output.clone());
1371-
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, (commitment_number, tx.output.iter().map(|output| { output.script_pubkey.clone() }).collect()));
1363+
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, commitment_number);
13721364

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

@@ -1706,7 +1698,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17061698
claimable_outpoints.append(&mut new_outpoints);
17071699
}
17081700
} else {
1709-
if let Some(&(commitment_number, _)) = self.counterparty_commitment_txn_on_chain.get(&prevout.txid) {
1701+
if let Some(&commitment_number) = self.counterparty_commitment_txn_on_chain.get(&prevout.txid) {
17101702
let (mut new_outpoints, new_outputs_option) = self.check_spend_counterparty_htlc(&tx, commitment_number, height, &logger);
17111703
claimable_outpoints.append(&mut new_outpoints);
17121704
if let Some(new_outputs) = new_outputs_option {
@@ -2198,12 +2190,7 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
21982190
for _ in 0..counterparty_commitment_txn_on_chain_len {
21992191
let txid: Txid = Readable::read(reader)?;
22002192
let commitment_number = <U48 as Readable>::read(reader)?.0;
2201-
let outputs_count = <u64 as Readable>::read(reader)?;
2202-
let mut outputs = Vec::with_capacity(cmp::min(outputs_count as usize, MAX_ALLOC_SIZE / 8));
2203-
for _ in 0..outputs_count {
2204-
outputs.push(Readable::read(reader)?);
2205-
}
2206-
if let Some(_) = counterparty_commitment_txn_on_chain.insert(txid, (commitment_number, outputs)) {
2193+
if let Some(_) = counterparty_commitment_txn_on_chain.insert(txid, commitment_number) {
22072194
return Err(DecodeError::InvalidValue);
22082195
}
22092196
}

0 commit comments

Comments
 (0)