Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PartialEq for ChannelMonitor #1986

Merged
merged 3 commits into from
Jan 26, 2023

Conversation

TheBlueMatt
Copy link
Collaborator

It turns out #[derive(PartialEq)] will automatically bound the
PartialEq implementation by any bounds on the struct also being
PartialEq, which I only found out today. 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.

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 lightningdevkit#1912.
`ChannelMonitor` indirectly already has a context - the
`OnchainTxHandler` has one. This makes it trivial to remove the
existing one, so we do so for a free memory usage reduction.
@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2023

Codecov Report

Base: 90.83% // Head: 91.30% // Increases project coverage by +0.46% 🎉

Coverage data is based on head (53bc6db) compared to base (abbd295).
Patch coverage: 100.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1986      +/-   ##
==========================================
+ Coverage   90.83%   91.30%   +0.46%     
==========================================
  Files          99       99              
  Lines       51761    54507    +2746     
  Branches    51761    54507    +2746     
==========================================
+ Hits        47018    49768    +2750     
+ Misses       4743     4739       -4     
Impacted Files Coverage Δ
lightning/src/chain/channelmonitor.rs 91.12% <100.00%> (+0.04%) ⬆️
lightning/src/chain/onchaintx.rs 95.74% <100.00%> (+0.34%) ⬆️
lightning/src/routing/router.rs 91.15% <100.00%> (ø)
lightning/src/util/enforcing_trait_impls.rs 83.33% <100.00%> (+0.40%) ⬆️
lightning/src/util/events.rs 30.50% <100.00%> (ø)
lightning/src/ln/payment_tests.rs 97.99% <0.00%> (-0.74%) ⬇️
lightning/src/ln/functional_tests.rs 97.10% <0.00%> (+0.04%) ⬆️
lightning/src/ln/msgs.rs 86.22% <0.00%> (+0.21%) ⬆️
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TheBlueMatt TheBlueMatt added this to the 0.0.114 milestone Jan 26, 2023
Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -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)
Copy link
Contributor

@dunxen dunxen Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's interesting when I checked out this function and went down a bit of a rabbit hole and found out that currently for dyn Trait raw pointers, Rust also checks for equality of vtables which has caused what most would naturally consider false negatives as it was unexpected from the docs: rust-lang/rust#106447

We're at least good for EnforcementState structs though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh! Yea, that's surprising. I mean indeed doesn't impact us here (it snot even a dyn trait), but still.

@TheBlueMatt TheBlueMatt merged commit 21ae60b into lightningdevkit:main Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose ChannelMonitor Eq
4 participants