Skip to content

Commit e61f3a2

Browse files
authored
Merge pull request #1763 from gcomte/feature/derive-eq
Derive Eq for all structs that derive PartialEq
2 parents 1caf1ab + aa916bb commit e61f3a2

File tree

21 files changed

+101
-96
lines changed

21 files changed

+101
-96
lines changed

lightning-background-processor/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ mod tests {
609609

610610
const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER;
611611

612-
#[derive(Clone, Eq, Hash, PartialEq)]
612+
#[derive(Clone, Hash, PartialEq, Eq)]
613613
struct TestDescriptor{}
614614
impl SocketDescriptor for TestDescriptor {
615615
fn send_data(&mut self, _data: &[u8], _resume_read: bool) -> usize {

lightning-block-sync/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub struct BlockSourceError {
9898
}
9999

100100
/// The kind of `BlockSourceError`, either persistent or transient.
101-
#[derive(Clone, Copy, Debug, PartialEq)]
101+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
102102
pub enum BlockSourceErrorKind {
103103
/// Indicates an error that won't resolve when retrying a request (e.g., invalid data).
104104
Persistent,
@@ -139,7 +139,7 @@ impl BlockSourceError {
139139

140140
/// A block header and some associated data. This information should be available from most block
141141
/// sources (and, notably, is available in Bitcoin Core's RPC and REST interfaces).
142-
#[derive(Clone, Copy, Debug, PartialEq)]
142+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
143143
pub struct BlockHeaderData {
144144
/// The block header itself.
145145
pub header: BlockHeader,

lightning-block-sync/src/poll.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait Poll {
2929
}
3030

3131
/// A chain tip relative to another chain tip in terms of block hash and chainwork.
32-
#[derive(Clone, Debug, PartialEq)]
32+
#[derive(Clone, Debug, PartialEq, Eq)]
3333
pub enum ChainTip {
3434
/// A chain tip with the same hash as another chain's tip.
3535
Common,
@@ -102,7 +102,7 @@ impl Validate for BlockData {
102102
}
103103

104104
/// A block header with validated proof of work and corresponding block hash.
105-
#[derive(Clone, Copy, Debug, PartialEq)]
105+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
106106
pub struct ValidatedBlockHeader {
107107
pub(crate) block_hash: BlockHash,
108108
inner: BlockHeaderData,

lightning-invoice/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ mod sync;
101101
/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
102102
/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
103103
#[allow(missing_docs)]
104-
#[derive(PartialEq, Debug, Clone)]
104+
#[derive(PartialEq, Eq, Debug, Clone)]
105105
pub enum ParseError {
106106
Bech32Error(bech32::Error),
107107
ParseAmountError(ParseIntError),
@@ -129,7 +129,7 @@ pub enum ParseError {
129129
/// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
130130
/// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
131131
/// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
132-
#[derive(PartialEq, Debug, Clone)]
132+
#[derive(PartialEq, Eq, Debug, Clone)]
133133
pub enum ParseOrSemanticError {
134134
/// The invoice couldn't be decoded
135135
ParseError(ParseError),

lightning/src/chain/channelmonitor.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use sync::Mutex;
6666
/// much smaller than a full [`ChannelMonitor`]. However, for large single commitment transaction
6767
/// updates (e.g. ones during which there are hundreds of HTLCs pending on the commitment
6868
/// transaction), a single update may reach upwards of 1 MiB in serialized size.
69-
#[cfg_attr(any(test, fuzzing, feature = "_test_utils"), derive(PartialEq))]
69+
#[cfg_attr(any(test, fuzzing, feature = "_test_utils"), derive(PartialEq, Eq))]
7070
#[derive(Clone)]
7171
#[must_use]
7272
pub struct ChannelMonitorUpdate {
@@ -125,7 +125,7 @@ impl Readable for ChannelMonitorUpdate {
125125
}
126126

127127
/// An event to be processed by the ChannelManager.
128-
#[derive(Clone, PartialEq)]
128+
#[derive(Clone, PartialEq, Eq)]
129129
pub enum MonitorEvent {
130130
/// A monitor event containing an HTLCUpdate.
131131
HTLCEvent(HTLCUpdate),
@@ -170,7 +170,7 @@ impl_writeable_tlv_based_enum_upgradable!(MonitorEvent,
170170
/// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on
171171
/// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the
172172
/// preimage claim backward will lead to loss of funds.
173-
#[derive(Clone, PartialEq)]
173+
#[derive(Clone, PartialEq, Eq)]
174174
pub struct HTLCUpdate {
175175
pub(crate) payment_hash: PaymentHash,
176176
pub(crate) payment_preimage: Option<PaymentPreimage>,
@@ -236,7 +236,7 @@ pub const ANTI_REORG_DELAY: u32 = 6;
236236
pub(crate) const HTLC_FAIL_BACK_BUFFER: u32 = CLTV_CLAIM_BUFFER + LATENCY_GRACE_PERIOD_BLOCKS;
237237

238238
// TODO(devrandom) replace this with HolderCommitmentTransaction
239-
#[derive(Clone, PartialEq)]
239+
#[derive(Clone, PartialEq, Eq)]
240240
struct HolderSignedTx {
241241
/// txid of the transaction in tx, just used to make comparison faster
242242
txid: Txid,
@@ -265,7 +265,7 @@ impl_writeable_tlv_based!(HolderSignedTx, {
265265

266266
/// We use this to track static counterparty commitment transaction data and to generate any
267267
/// justice or 2nd-stage preimage/timeout transactions.
268-
#[derive(PartialEq)]
268+
#[derive(PartialEq, Eq)]
269269
struct CounterpartyCommitmentParameters {
270270
counterparty_delayed_payment_base_key: PublicKey,
271271
counterparty_htlc_base_key: PublicKey,
@@ -319,7 +319,7 @@ impl Readable for CounterpartyCommitmentParameters {
319319
/// transaction causing it.
320320
///
321321
/// Used to determine when the on-chain event can be considered safe from a chain reorganization.
322-
#[derive(PartialEq)]
322+
#[derive(PartialEq, Eq)]
323323
struct OnchainEventEntry {
324324
txid: Txid,
325325
height: u32,
@@ -361,7 +361,7 @@ type CommitmentTxCounterpartyOutputInfo = Option<(u32, u64)>;
361361

362362
/// Upon discovering of some classes of onchain tx by ChannelMonitor, we may have to take actions on it
363363
/// once they mature to enough confirmations (ANTI_REORG_DELAY)
364-
#[derive(PartialEq)]
364+
#[derive(PartialEq, Eq)]
365365
enum OnchainEvent {
366366
/// An outbound HTLC failing after a transaction is confirmed. Used
367367
/// * when an outbound HTLC output is spent by us after the HTLC timed out
@@ -471,7 +471,7 @@ impl_writeable_tlv_based_enum_upgradable!(OnchainEvent,
471471

472472
);
473473

474-
#[cfg_attr(any(test, fuzzing, feature = "_test_utils"), derive(PartialEq))]
474+
#[cfg_attr(any(test, fuzzing, feature = "_test_utils"), derive(PartialEq, Eq))]
475475
#[derive(Clone)]
476476
pub(crate) enum ChannelMonitorUpdateStep {
477477
LatestHolderCommitmentTXInfo {
@@ -619,7 +619,7 @@ pub enum Balance {
619619
}
620620

621621
/// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY.
622-
#[derive(PartialEq)]
622+
#[derive(PartialEq, Eq)]
623623
struct IrrevocablyResolvedHTLC {
624624
commitment_tx_output_idx: Option<u32>,
625625
/// The txid of the transaction which resolved the HTLC, this may be a commitment (if the HTLC

lightning/src/chain/keysinterface.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub struct KeyMaterial(pub [u8; 32]);
5555

5656
/// Information about a spendable output to a P2WSH script. See
5757
/// SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this.
58-
#[derive(Clone, Debug, PartialEq)]
58+
#[derive(Clone, Debug, PartialEq, Eq)]
5959
pub struct DelayedPaymentOutputDescriptor {
6060
/// The outpoint which is spendable
6161
pub outpoint: OutPoint,
@@ -95,7 +95,7 @@ impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, {
9595

9696
/// Information about a spendable output to our "payment key". See
9797
/// SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this.
98-
#[derive(Clone, Debug, PartialEq)]
98+
#[derive(Clone, Debug, PartialEq, Eq)]
9999
pub struct StaticPaymentOutputDescriptor {
100100
/// The outpoint which is spendable
101101
pub outpoint: OutPoint,
@@ -126,7 +126,7 @@ impl_writeable_tlv_based!(StaticPaymentOutputDescriptor, {
126126
/// spend on-chain. The information needed to do this is provided in this enum, including the
127127
/// outpoint describing which txid and output index is available, the full output which exists at
128128
/// that txid/index, and any keys or other information required to sign.
129-
#[derive(Clone, Debug, PartialEq)]
129+
#[derive(Clone, Debug, PartialEq, Eq)]
130130
pub enum SpendableOutputDescriptor {
131131
/// An output to a script which was provided via KeysInterface directly, either from
132132
/// `get_destination_script()` or `get_shutdown_scriptpubkey()`, thus you should already know

lightning/src/chain/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) mod onchaintx;
3232
pub(crate) mod package;
3333

3434
/// The best known block as identified by its hash and height.
35-
#[derive(Clone, Copy, PartialEq)]
35+
#[derive(Clone, Copy, PartialEq, Eq)]
3636
pub struct BestBlock {
3737
block_hash: BlockHash,
3838
height: u32,
@@ -188,7 +188,7 @@ pub trait Confirm {
188188
}
189189

190190
/// An enum representing the status of a channel monitor update persistence.
191-
#[derive(Clone, Copy, Debug, PartialEq)]
191+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
192192
pub enum ChannelMonitorUpdateStatus {
193193
/// The update has been durably persisted and all copies of the relevant [`ChannelMonitor`]
194194
/// have been updated.
@@ -364,7 +364,7 @@ pub trait Filter {
364364
///
365365
/// [`ChannelMonitor`]: channelmonitor::ChannelMonitor
366366
/// [`ChannelMonitor::block_connected`]: channelmonitor::ChannelMonitor::block_connected
367-
#[derive(Clone, PartialEq, Hash)]
367+
#[derive(Clone, PartialEq, Eq, Hash)]
368368
pub struct WatchedOutput {
369369
/// First block where the transaction output may have been spent.
370370
pub block_hash: Option<BlockHash>,

lightning/src/chain/onchaintx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const MAX_ALLOC_SIZE: usize = 64*1024;
4646
/// transaction causing it.
4747
///
4848
/// Used to determine when the on-chain event can be considered safe from a chain reorganization.
49-
#[derive(PartialEq)]
49+
#[derive(PartialEq, Eq)]
5050
struct OnchainEventEntry {
5151
txid: Txid,
5252
height: u32,
@@ -65,7 +65,7 @@ impl OnchainEventEntry {
6565

6666
/// Upon discovering of some classes of onchain tx by ChannelMonitor, we may have to take actions on it
6767
/// once they mature to enough confirmations (ANTI_REORG_DELAY)
68-
#[derive(PartialEq)]
68+
#[derive(PartialEq, Eq)]
6969
enum OnchainEvent {
7070
/// Outpoint under claim process by our own tx, once this one get enough confirmations, we remove it from
7171
/// bump-txn candidate buffer.

lightning/src/chain/package.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const HIGH_FREQUENCY_BUMP_INTERVAL: u32 = 1;
8686
///
8787
/// CSV and pubkeys are used as part of a witnessScript redeeming a balance output, amount is used
8888
/// as part of the signature hash and revocation secret to generate a satisfying witness.
89-
#[derive(Clone, PartialEq)]
89+
#[derive(Clone, PartialEq, Eq)]
9090
pub(crate) struct RevokedOutput {
9191
per_commitment_point: PublicKey,
9292
counterparty_delayed_payment_base_key: PublicKey,
@@ -129,7 +129,7 @@ impl_writeable_tlv_based!(RevokedOutput, {
129129
///
130130
/// CSV is used as part of a witnessScript redeeming a balance output, amount is used as part
131131
/// of the signature hash and revocation secret to generate a satisfying witness.
132-
#[derive(Clone, PartialEq)]
132+
#[derive(Clone, PartialEq, Eq)]
133133
pub(crate) struct RevokedHTLCOutput {
134134
per_commitment_point: PublicKey,
135135
counterparty_delayed_payment_base_key: PublicKey,
@@ -171,7 +171,7 @@ impl_writeable_tlv_based!(RevokedHTLCOutput, {
171171
/// witnessScript.
172172
///
173173
/// The preimage is used as part of the witness.
174-
#[derive(Clone, PartialEq)]
174+
#[derive(Clone, PartialEq, Eq)]
175175
pub(crate) struct CounterpartyOfferedHTLCOutput {
176176
per_commitment_point: PublicKey,
177177
counterparty_delayed_payment_base_key: PublicKey,
@@ -204,7 +204,7 @@ impl_writeable_tlv_based!(CounterpartyOfferedHTLCOutput, {
204204
///
205205
/// HTLCOutputInCommitment (hash, timelock, directon) and pubkeys are used to generate a suitable
206206
/// witnessScript.
207-
#[derive(Clone, PartialEq)]
207+
#[derive(Clone, PartialEq, Eq)]
208208
pub(crate) struct CounterpartyReceivedHTLCOutput {
209209
per_commitment_point: PublicKey,
210210
counterparty_delayed_payment_base_key: PublicKey,
@@ -234,7 +234,7 @@ impl_writeable_tlv_based!(CounterpartyReceivedHTLCOutput, {
234234
///
235235
/// Either offered or received, the amount is always used as part of the bip143 sighash.
236236
/// Preimage is only included as part of the witness in former case.
237-
#[derive(Clone, PartialEq)]
237+
#[derive(Clone, PartialEq, Eq)]
238238
pub(crate) struct HolderHTLCOutput {
239239
preimage: Option<PaymentPreimage>,
240240
amount: u64,
@@ -269,7 +269,7 @@ impl_writeable_tlv_based!(HolderHTLCOutput, {
269269
/// A struct to describe the channel output on the funding transaction.
270270
///
271271
/// witnessScript is used as part of the witness redeeming the funding utxo.
272-
#[derive(Clone, PartialEq)]
272+
#[derive(Clone, PartialEq, Eq)]
273273
pub(crate) struct HolderFundingOutput {
274274
funding_redeemscript: Script,
275275
}
@@ -290,7 +290,7 @@ impl_writeable_tlv_based!(HolderFundingOutput, {
290290
///
291291
/// The generic API offers access to an outputs common attributes or allow transformation such as
292292
/// finalizing an input claiming the output.
293-
#[derive(Clone, PartialEq)]
293+
#[derive(Clone, PartialEq, Eq)]
294294
pub(crate) enum PackageSolvingData {
295295
RevokedOutput(RevokedOutput),
296296
RevokedHTLCOutput(RevokedHTLCOutput),
@@ -444,7 +444,7 @@ impl_writeable_tlv_based_enum!(PackageSolvingData, ;
444444
/// A malleable package might be aggregated with other packages to save on fees.
445445
/// A untractable package has been counter-signed and aggregable will break cached counterparty
446446
/// signatures.
447-
#[derive(Clone, PartialEq)]
447+
#[derive(Clone, PartialEq, Eq)]
448448
pub(crate) enum PackageMalleability {
449449
Malleable,
450450
Untractable,
@@ -459,7 +459,7 @@ pub(crate) enum PackageMalleability {
459459
///
460460
/// As packages are time-sensitive, we fee-bump and rebroadcast them at scheduled intervals.
461461
/// Failing to confirm a package translate as a loss of funds for the user.
462-
#[derive(Clone, PartialEq)]
462+
#[derive(Clone, PartialEq, Eq)]
463463
pub struct PackageTemplate {
464464
// List of onchain outputs and solving data to generate satisfying witnesses.
465465
inputs: Vec<(BitcoinOutPoint, PackageSolvingData)>,

lightning/src/ln/chan_utils.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn htlc_timeout_tx_weight(opt_anchors: bool) -> u64 {
6565
if opt_anchors { HTLC_TIMEOUT_ANCHOR_TX_WEIGHT } else { HTLC_TIMEOUT_TX_WEIGHT }
6666
}
6767

68-
#[derive(PartialEq)]
68+
#[derive(PartialEq, Eq)]
6969
pub(crate) enum HTLCClaim {
7070
OfferedTimeout,
7171
OfferedPreimage,
@@ -208,6 +208,7 @@ pub struct CounterpartyCommitmentSecrets {
208208
old_secrets: [([u8; 32], u64); 49],
209209
}
210210

211+
impl Eq for CounterpartyCommitmentSecrets {}
211212
impl PartialEq for CounterpartyCommitmentSecrets {
212213
fn eq(&self, other: &Self) -> bool {
213214
for (&(ref secret, ref idx), &(ref o_secret, ref o_idx)) in self.old_secrets.iter().zip(other.old_secrets.iter()) {
@@ -419,7 +420,7 @@ pub fn derive_public_revocation_key<T: secp256k1::Verification>(secp_ctx: &Secp2
419420
/// channel basepoints via the new function, or they were obtained via
420421
/// CommitmentTransaction.trust().keys() because we trusted the source of the
421422
/// pre-calculated keys.
422-
#[derive(PartialEq, Clone)]
423+
#[derive(PartialEq, Eq, Clone)]
423424
pub struct TxCreationKeys {
424425
/// The broadcaster's per-commitment public key which was used to derive the other keys.
425426
pub per_commitment_point: PublicKey,
@@ -444,7 +445,7 @@ impl_writeable_tlv_based!(TxCreationKeys, {
444445
});
445446

446447
/// One counterparty's public keys which do not change over the life of a channel.
447-
#[derive(Clone, PartialEq)]
448+
#[derive(Clone, PartialEq, Eq)]
448449
pub struct ChannelPublicKeys {
449450
/// The public key which is used to sign all commitment transactions, as it appears in the
450451
/// on-chain channel lock-in 2-of-2 multisig output.
@@ -525,7 +526,7 @@ pub fn get_revokeable_redeemscript(revocation_key: &PublicKey, contest_delay: u1
525526
res
526527
}
527528

528-
#[derive(Clone, PartialEq)]
529+
#[derive(Clone, PartialEq, Eq)]
529530
/// Information about an HTLC as it appears in a commitment transaction
530531
pub struct HTLCOutputInCommitment {
531532
/// Whether the HTLC was "offered" (ie outbound in relation to this commitment transaction).
@@ -882,6 +883,7 @@ impl Deref for HolderCommitmentTransaction {
882883
fn deref(&self) -> &Self::Target { &self.inner }
883884
}
884885

886+
impl Eq for HolderCommitmentTransaction {}
885887
impl PartialEq for HolderCommitmentTransaction {
886888
// We dont care whether we are signed in equality comparison
887889
fn eq(&self, o: &Self) -> bool {
@@ -1007,7 +1009,7 @@ impl BuiltCommitmentTransaction {
10071009
///
10081010
/// This class can be used inside a signer implementation to generate a signature given the relevant
10091011
/// secret key.
1010-
#[derive(Clone, Hash, PartialEq)]
1012+
#[derive(Clone, Hash, PartialEq, Eq)]
10111013
pub struct ClosingTransaction {
10121014
to_holder_value_sat: u64,
10131015
to_counterparty_value_sat: u64,
@@ -1147,6 +1149,7 @@ pub struct CommitmentTransaction {
11471149
built: BuiltCommitmentTransaction,
11481150
}
11491151

1152+
impl Eq for CommitmentTransaction {}
11501153
impl PartialEq for CommitmentTransaction {
11511154
fn eq(&self, o: &Self) -> bool {
11521155
let eq = self.commitment_number == o.commitment_number &&

0 commit comments

Comments
 (0)