]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Implement `PartialEq` for `ChannelMonitor`
authorMatt Corallo <git@bluematt.me>
Thu, 26 Jan 2023 02:23:08 +0000 (02:23 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 26 Jan 2023 02:23:08 +0000 (02:23 +0000)
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
lightning/src/chain/onchaintx.rs
lightning/src/util/enforcing_trait_impls.rs

index 34e5aac214c177453a5f7171bb39c1a2245b6a21..a26866497fcc1df9d405aac495414c02cdfd969d 100644 (file)
@@ -713,6 +713,7 @@ pub struct ChannelMonitor<Signer: WriteableEcdsaChannelSigner> {
        inner: Mutex<ChannelMonitorImpl<Signer>>,
 }
 
+#[derive(PartialEq)]
 pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
        latest_update_id: u64,
        commitment_transaction_number_obscure_factor: u64,
@@ -854,10 +855,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
 /// 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<Signer: WriteableEcdsaChannelSigner> PartialEq for ChannelMonitor<Signer> {
+impl<Signer: WriteableEcdsaChannelSigner> PartialEq for ChannelMonitor<Signer> 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<Signer: WriteableEcdsaChannelSigner> PartialEq for ChannelMonitor<Signer> {
        }
 }
 
-#[cfg(any(test, fuzzing, feature = "_test_utils"))]
-/// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying
-/// object
-impl<Signer: WriteableEcdsaChannelSigner> PartialEq for ChannelMonitorImpl<Signer> {
-       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<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitor<Signer> {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
                self.inner.lock().unwrap().write(writer)
index 7dcb8ff89821e873bae17c20cfcb19e71df95004..039fb5ff13a04eb1fd843d061bbd992a0f394935 100644 (file)
@@ -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<ChannelSigner: WriteableEcdsaChannelSigner> {
        destination_script: Script,
        holder_commitment: HolderCommitmentTransaction,
index c13907bb9e4a4b5b8c299c588ef1d0c64fc44a47..1f7b5221c8f781e337ae4a3a61b460ab21391829 100644 (file)
@@ -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 {