Skip to content

Commit d9dfc16

Browse files
committed
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.
1 parent b536d01 commit d9dfc16

File tree

3 files changed

+9
-51
lines changed

3 files changed

+9
-51
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ pub struct ChannelMonitor<Signer: WriteableEcdsaChannelSigner> {
713713
inner: Mutex<ChannelMonitorImpl<Signer>>,
714714
}
715715

716+
#[derive(PartialEq)]
716717
pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
717718
latest_update_id: u64,
718719
commitment_transaction_number_obscure_factor: u64,
@@ -854,64 +855,14 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
854855
/// Transaction outputs to watch for on-chain spends.
855856
pub type TransactionOutputs = (Txid, Vec<(u32, TxOut)>);
856857

857-
#[cfg(any(test, fuzzing, feature = "_test_utils"))]
858-
/// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying
859-
/// object
860-
impl<Signer: WriteableEcdsaChannelSigner> PartialEq for ChannelMonitor<Signer> {
858+
impl<Signer: WriteableEcdsaChannelSigner> PartialEq for ChannelMonitor<Signer> where Signer: PartialEq {
861859
fn eq(&self, other: &Self) -> bool {
862860
let inner = self.inner.lock().unwrap();
863861
let other = other.inner.lock().unwrap();
864862
inner.eq(&other)
865863
}
866864
}
867865

868-
#[cfg(any(test, fuzzing, feature = "_test_utils"))]
869-
/// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying
870-
/// object
871-
impl<Signer: WriteableEcdsaChannelSigner> PartialEq for ChannelMonitorImpl<Signer> {
872-
fn eq(&self, other: &Self) -> bool {
873-
if self.latest_update_id != other.latest_update_id ||
874-
self.commitment_transaction_number_obscure_factor != other.commitment_transaction_number_obscure_factor ||
875-
self.destination_script != other.destination_script ||
876-
self.broadcasted_holder_revokable_script != other.broadcasted_holder_revokable_script ||
877-
self.counterparty_payment_script != other.counterparty_payment_script ||
878-
self.channel_keys_id != other.channel_keys_id ||
879-
self.holder_revocation_basepoint != other.holder_revocation_basepoint ||
880-
self.funding_info != other.funding_info ||
881-
self.current_counterparty_commitment_txid != other.current_counterparty_commitment_txid ||
882-
self.prev_counterparty_commitment_txid != other.prev_counterparty_commitment_txid ||
883-
self.counterparty_commitment_params != other.counterparty_commitment_params ||
884-
self.funding_redeemscript != other.funding_redeemscript ||
885-
self.channel_value_satoshis != other.channel_value_satoshis ||
886-
self.their_cur_per_commitment_points != other.their_cur_per_commitment_points ||
887-
self.on_holder_tx_csv != other.on_holder_tx_csv ||
888-
self.commitment_secrets != other.commitment_secrets ||
889-
self.counterparty_claimable_outpoints != other.counterparty_claimable_outpoints ||
890-
self.counterparty_commitment_txn_on_chain != other.counterparty_commitment_txn_on_chain ||
891-
self.counterparty_hash_commitment_number != other.counterparty_hash_commitment_number ||
892-
self.prev_holder_signed_commitment_tx != other.prev_holder_signed_commitment_tx ||
893-
self.current_counterparty_commitment_number != other.current_counterparty_commitment_number ||
894-
self.current_holder_commitment_number != other.current_holder_commitment_number ||
895-
self.current_holder_commitment_tx != other.current_holder_commitment_tx ||
896-
self.payment_preimages != other.payment_preimages ||
897-
self.pending_monitor_events != other.pending_monitor_events ||
898-
self.pending_events.len() != other.pending_events.len() || // We trust events to round-trip properly
899-
self.onchain_events_awaiting_threshold_conf != other.onchain_events_awaiting_threshold_conf ||
900-
self.outputs_to_watch != other.outputs_to_watch ||
901-
self.lockdown_from_offchain != other.lockdown_from_offchain ||
902-
self.holder_tx_signed != other.holder_tx_signed ||
903-
self.funding_spend_seen != other.funding_spend_seen ||
904-
self.funding_spend_confirmed != other.funding_spend_confirmed ||
905-
self.confirmed_commitment_tx_counterparty_output != other.confirmed_commitment_tx_counterparty_output ||
906-
self.htlcs_resolved_on_chain != other.htlcs_resolved_on_chain
907-
{
908-
false
909-
} else {
910-
true
911-
}
912-
}
913-
}
914-
915866
impl<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitor<Signer> {
916867
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
917868
self.inner.lock().unwrap().write(writer)

lightning/src/chain/onchaintx.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ type PackageID = [u8; 32];
219219

220220
/// OnchainTxHandler receives claiming requests, aggregates them if it's sound, broadcast and
221221
/// do RBF bumping if possible.
222+
#[derive(PartialEq)]
222223
pub struct OnchainTxHandler<ChannelSigner: WriteableEcdsaChannelSigner> {
223224
destination_script: Script,
224225
holder_commitment: HolderCommitmentTransaction,

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ pub struct EnforcingSigner {
5858
pub disable_revocation_policy_check: bool,
5959
}
6060

61+
impl PartialEq for EnforcingSigner {
62+
fn eq(&self, o: &Self) -> bool {
63+
Arc::ptr_eq(&self.state, &o.state)
64+
}
65+
}
66+
6167
impl EnforcingSigner {
6268
/// Construct an EnforcingSigner
6369
pub fn new(inner: InMemorySigner) -> Self {

0 commit comments

Comments
 (0)