From d9dfc16e4af43240fe419099ba7e62be6c852455 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 26 Jan 2023 02:23:08 +0000 Subject: [PATCH] Implement `PartialEq` for `ChannelMonitor` It turns out `#[derive(PartialEq)]` will automatically bound the `PartialEq` implementation by any bounds on the struct also being `PartialEq`. This means to use an auto-derived `ChannelMonitor` `PartialEq` the `EcdsaSigner` used must also be `PartialEq`, but for the use-cases we have today for a `ChannelMonitor` `PartialEq` it doesn't really matter - we use it internally in tests and downstream users wanted similar test-only usage. Fixes #1912. --- lightning/src/chain/channelmonitor.rs | 53 +-------------------- lightning/src/chain/onchaintx.rs | 1 + lightning/src/util/enforcing_trait_impls.rs | 6 +++ 3 files changed, 9 insertions(+), 51 deletions(-) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 34e5aac21..a26866497 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -713,6 +713,7 @@ pub struct ChannelMonitor { inner: Mutex>, } +#[derive(PartialEq)] pub(crate) struct ChannelMonitorImpl { latest_update_id: u64, commitment_transaction_number_obscure_factor: u64, @@ -854,10 +855,7 @@ pub(crate) struct ChannelMonitorImpl { /// Transaction outputs to watch for on-chain spends. pub type TransactionOutputs = (Txid, Vec<(u32, TxOut)>); -#[cfg(any(test, fuzzing, feature = "_test_utils"))] -/// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying -/// object -impl PartialEq for ChannelMonitor { +impl PartialEq for ChannelMonitor where Signer: PartialEq { fn eq(&self, other: &Self) -> bool { let inner = self.inner.lock().unwrap(); let other = other.inner.lock().unwrap(); @@ -865,53 +863,6 @@ impl PartialEq for ChannelMonitor { } } -#[cfg(any(test, fuzzing, feature = "_test_utils"))] -/// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying -/// object -impl PartialEq for ChannelMonitorImpl { - fn eq(&self, other: &Self) -> bool { - if self.latest_update_id != other.latest_update_id || - self.commitment_transaction_number_obscure_factor != other.commitment_transaction_number_obscure_factor || - self.destination_script != other.destination_script || - self.broadcasted_holder_revokable_script != other.broadcasted_holder_revokable_script || - self.counterparty_payment_script != other.counterparty_payment_script || - self.channel_keys_id != other.channel_keys_id || - self.holder_revocation_basepoint != other.holder_revocation_basepoint || - self.funding_info != other.funding_info || - self.current_counterparty_commitment_txid != other.current_counterparty_commitment_txid || - self.prev_counterparty_commitment_txid != other.prev_counterparty_commitment_txid || - self.counterparty_commitment_params != other.counterparty_commitment_params || - self.funding_redeemscript != other.funding_redeemscript || - self.channel_value_satoshis != other.channel_value_satoshis || - self.their_cur_per_commitment_points != other.their_cur_per_commitment_points || - self.on_holder_tx_csv != other.on_holder_tx_csv || - self.commitment_secrets != other.commitment_secrets || - self.counterparty_claimable_outpoints != other.counterparty_claimable_outpoints || - self.counterparty_commitment_txn_on_chain != other.counterparty_commitment_txn_on_chain || - self.counterparty_hash_commitment_number != other.counterparty_hash_commitment_number || - self.prev_holder_signed_commitment_tx != other.prev_holder_signed_commitment_tx || - self.current_counterparty_commitment_number != other.current_counterparty_commitment_number || - self.current_holder_commitment_number != other.current_holder_commitment_number || - self.current_holder_commitment_tx != other.current_holder_commitment_tx || - self.payment_preimages != other.payment_preimages || - self.pending_monitor_events != other.pending_monitor_events || - self.pending_events.len() != other.pending_events.len() || // We trust events to round-trip properly - self.onchain_events_awaiting_threshold_conf != other.onchain_events_awaiting_threshold_conf || - self.outputs_to_watch != other.outputs_to_watch || - self.lockdown_from_offchain != other.lockdown_from_offchain || - self.holder_tx_signed != other.holder_tx_signed || - self.funding_spend_seen != other.funding_spend_seen || - self.funding_spend_confirmed != other.funding_spend_confirmed || - self.confirmed_commitment_tx_counterparty_output != other.confirmed_commitment_tx_counterparty_output || - self.htlcs_resolved_on_chain != other.htlcs_resolved_on_chain - { - false - } else { - true - } - } -} - impl Writeable for ChannelMonitor { fn write(&self, writer: &mut W) -> Result<(), Error> { self.inner.lock().unwrap().write(writer) diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs index 7dcb8ff89..039fb5ff1 100644 --- a/lightning/src/chain/onchaintx.rs +++ b/lightning/src/chain/onchaintx.rs @@ -219,6 +219,7 @@ type PackageID = [u8; 32]; /// OnchainTxHandler receives claiming requests, aggregates them if it's sound, broadcast and /// do RBF bumping if possible. +#[derive(PartialEq)] pub struct OnchainTxHandler { destination_script: Script, holder_commitment: HolderCommitmentTransaction, diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs index c13907bb9..1f7b5221c 100644 --- a/lightning/src/util/enforcing_trait_impls.rs +++ b/lightning/src/util/enforcing_trait_impls.rs @@ -58,6 +58,12 @@ pub struct EnforcingSigner { pub disable_revocation_policy_check: bool, } +impl PartialEq for EnforcingSigner { + fn eq(&self, o: &Self) -> bool { + Arc::ptr_eq(&self.state, &o.state) + } +} + impl EnforcingSigner { /// Construct an EnforcingSigner pub fn new(inner: InMemorySigner) -> Self { -- 2.39.5