From aa916bb594fbc77c819e82eb2fc269a307376a01 Mon Sep 17 00:00:00 2001 From: Gabriel Comte Date: Fri, 14 Oct 2022 13:24:02 +0200 Subject: [PATCH] Derive Eq for all structs that derive PartialEq --- lightning-background-processor/src/lib.rs | 2 +- lightning-block-sync/src/lib.rs | 4 +- lightning-block-sync/src/poll.rs | 4 +- lightning-invoice/src/lib.rs | 4 +- lightning/src/chain/channelmonitor.rs | 18 ++--- lightning/src/chain/keysinterface.rs | 6 +- lightning/src/chain/mod.rs | 6 +- lightning/src/chain/onchaintx.rs | 4 +- lightning/src/chain/package.rs | 18 ++--- lightning/src/ln/chan_utils.rs | 13 ++-- lightning/src/ln/msgs.rs | 81 ++++++++++++----------- lightning/src/ln/script.rs | 4 +- lightning/src/onion_message/messenger.rs | 2 +- lightning/src/onion_message/packet.rs | 2 +- lightning/src/routing/gossip.rs | 13 ++-- lightning/src/util/chacha20poly1305rfc.rs | 2 +- lightning/src/util/config.rs | 2 +- lightning/src/util/errors.rs | 2 +- lightning/src/util/events.rs | 4 +- lightning/src/util/scid_utils.rs | 2 +- lightning/src/util/ser.rs | 4 +- 21 files changed, 101 insertions(+), 96 deletions(-) diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 055b5ca6..27cd0663 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -609,7 +609,7 @@ mod tests { const EVENT_DEADLINE: u64 = 5 * FRESHNESS_TIMER; - #[derive(Clone, Eq, Hash, PartialEq)] + #[derive(Clone, Hash, PartialEq, Eq)] struct TestDescriptor{} impl SocketDescriptor for TestDescriptor { fn send_data(&mut self, _data: &[u8], _resume_read: bool) -> usize { diff --git a/lightning-block-sync/src/lib.rs b/lightning-block-sync/src/lib.rs index 5d8bc27f..189a68be 100644 --- a/lightning-block-sync/src/lib.rs +++ b/lightning-block-sync/src/lib.rs @@ -98,7 +98,7 @@ pub struct BlockSourceError { } /// The kind of `BlockSourceError`, either persistent or transient. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum BlockSourceErrorKind { /// Indicates an error that won't resolve when retrying a request (e.g., invalid data). Persistent, @@ -139,7 +139,7 @@ impl BlockSourceError { /// A block header and some associated data. This information should be available from most block /// sources (and, notably, is available in Bitcoin Core's RPC and REST interfaces). -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct BlockHeaderData { /// The block header itself. pub header: BlockHeader, diff --git a/lightning-block-sync/src/poll.rs b/lightning-block-sync/src/poll.rs index 2bb2f4a0..d45e900b 100644 --- a/lightning-block-sync/src/poll.rs +++ b/lightning-block-sync/src/poll.rs @@ -29,7 +29,7 @@ pub trait Poll { } /// A chain tip relative to another chain tip in terms of block hash and chainwork. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum ChainTip { /// A chain tip with the same hash as another chain's tip. Common, @@ -102,7 +102,7 @@ impl Validate for BlockData { } /// A block header with validated proof of work and corresponding block hash. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct ValidatedBlockHeader { pub(crate) block_hash: BlockHash, inner: BlockHeaderData, diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 9457d8ae..5aacf539 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -101,7 +101,7 @@ mod sync; /// Errors that indicate what is wrong with the invoice. They have some granularity for debug /// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user. #[allow(missing_docs)] -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone)] pub enum ParseError { Bech32Error(bech32::Error), ParseAmountError(ParseIntError), @@ -129,7 +129,7 @@ pub enum ParseError { /// Indicates that something went wrong while parsing or validating the invoice. Parsing errors /// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors /// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone)] pub enum ParseOrSemanticError { /// The invoice couldn't be decoded ParseError(ParseError), diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 8f8cbdf4..6f28a63e 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -66,7 +66,7 @@ use sync::Mutex; /// much smaller than a full [`ChannelMonitor`]. However, for large single commitment transaction /// updates (e.g. ones during which there are hundreds of HTLCs pending on the commitment /// transaction), a single update may reach upwards of 1 MiB in serialized size. -#[cfg_attr(any(test, fuzzing, feature = "_test_utils"), derive(PartialEq))] +#[cfg_attr(any(test, fuzzing, feature = "_test_utils"), derive(PartialEq, Eq))] #[derive(Clone)] #[must_use] pub struct ChannelMonitorUpdate { @@ -125,7 +125,7 @@ impl Readable for ChannelMonitorUpdate { } /// An event to be processed by the ChannelManager. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub enum MonitorEvent { /// A monitor event containing an HTLCUpdate. HTLCEvent(HTLCUpdate), @@ -170,7 +170,7 @@ impl_writeable_tlv_based_enum_upgradable!(MonitorEvent, /// Simple structure sent back by `chain::Watch` when an HTLC from a forward channel is detected on /// chain. Used to update the corresponding HTLC in the backward channel. Failing to pass the /// preimage claim backward will lead to loss of funds. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub struct HTLCUpdate { pub(crate) payment_hash: PaymentHash, pub(crate) payment_preimage: Option, @@ -236,7 +236,7 @@ pub const ANTI_REORG_DELAY: u32 = 6; pub(crate) const HTLC_FAIL_BACK_BUFFER: u32 = CLTV_CLAIM_BUFFER + LATENCY_GRACE_PERIOD_BLOCKS; // TODO(devrandom) replace this with HolderCommitmentTransaction -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] struct HolderSignedTx { /// txid of the transaction in tx, just used to make comparison faster txid: Txid, @@ -265,7 +265,7 @@ impl_writeable_tlv_based!(HolderSignedTx, { /// We use this to track static counterparty commitment transaction data and to generate any /// justice or 2nd-stage preimage/timeout transactions. -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] struct CounterpartyCommitmentParameters { counterparty_delayed_payment_base_key: PublicKey, counterparty_htlc_base_key: PublicKey, @@ -319,7 +319,7 @@ impl Readable for CounterpartyCommitmentParameters { /// transaction causing it. /// /// Used to determine when the on-chain event can be considered safe from a chain reorganization. -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] struct OnchainEventEntry { txid: Txid, height: u32, @@ -361,7 +361,7 @@ type CommitmentTxCounterpartyOutputInfo = Option<(u32, u64)>; /// Upon discovering of some classes of onchain tx by ChannelMonitor, we may have to take actions on it /// once they mature to enough confirmations (ANTI_REORG_DELAY) -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] enum OnchainEvent { /// An outbound HTLC failing after a transaction is confirmed. Used /// * 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, ); -#[cfg_attr(any(test, fuzzing, feature = "_test_utils"), derive(PartialEq))] +#[cfg_attr(any(test, fuzzing, feature = "_test_utils"), derive(PartialEq, Eq))] #[derive(Clone)] pub(crate) enum ChannelMonitorUpdateStep { LatestHolderCommitmentTXInfo { @@ -619,7 +619,7 @@ pub enum Balance { } /// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY. -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] struct IrrevocablyResolvedHTLC { commitment_tx_output_idx: Option, /// The txid of the transaction which resolved the HTLC, this may be a commitment (if the HTLC diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 73b8a1b9..a89cc602 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -55,7 +55,7 @@ pub struct KeyMaterial(pub [u8; 32]); /// Information about a spendable output to a P2WSH script. See /// SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct DelayedPaymentOutputDescriptor { /// The outpoint which is spendable pub outpoint: OutPoint, @@ -95,7 +95,7 @@ impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, { /// Information about a spendable output to our "payment key". See /// SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct StaticPaymentOutputDescriptor { /// The outpoint which is spendable pub outpoint: OutPoint, @@ -126,7 +126,7 @@ impl_writeable_tlv_based!(StaticPaymentOutputDescriptor, { /// spend on-chain. The information needed to do this is provided in this enum, including the /// outpoint describing which txid and output index is available, the full output which exists at /// that txid/index, and any keys or other information required to sign. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum SpendableOutputDescriptor { /// An output to a script which was provided via KeysInterface directly, either from /// `get_destination_script()` or `get_shutdown_scriptpubkey()`, thus you should already know diff --git a/lightning/src/chain/mod.rs b/lightning/src/chain/mod.rs index c54f9b1d..bb80440d 100644 --- a/lightning/src/chain/mod.rs +++ b/lightning/src/chain/mod.rs @@ -32,7 +32,7 @@ pub(crate) mod onchaintx; pub(crate) mod package; /// The best known block as identified by its hash and height. -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct BestBlock { block_hash: BlockHash, height: u32, @@ -188,7 +188,7 @@ pub trait Confirm { } /// An enum representing the status of a channel monitor update persistence. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ChannelMonitorUpdateStatus { /// The update has been durably persisted and all copies of the relevant [`ChannelMonitor`] /// have been updated. @@ -364,7 +364,7 @@ pub trait Filter { /// /// [`ChannelMonitor`]: channelmonitor::ChannelMonitor /// [`ChannelMonitor::block_connected`]: channelmonitor::ChannelMonitor::block_connected -#[derive(Clone, PartialEq, Hash)] +#[derive(Clone, PartialEq, Eq, Hash)] pub struct WatchedOutput { /// First block where the transaction output may have been spent. pub block_hash: Option, diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs index 0f2edff5..f14c983b 100644 --- a/lightning/src/chain/onchaintx.rs +++ b/lightning/src/chain/onchaintx.rs @@ -46,7 +46,7 @@ const MAX_ALLOC_SIZE: usize = 64*1024; /// transaction causing it. /// /// Used to determine when the on-chain event can be considered safe from a chain reorganization. -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] struct OnchainEventEntry { txid: Txid, height: u32, @@ -65,7 +65,7 @@ impl OnchainEventEntry { /// Upon discovering of some classes of onchain tx by ChannelMonitor, we may have to take actions on it /// once they mature to enough confirmations (ANTI_REORG_DELAY) -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] enum OnchainEvent { /// Outpoint under claim process by our own tx, once this one get enough confirmations, we remove it from /// bump-txn candidate buffer. diff --git a/lightning/src/chain/package.rs b/lightning/src/chain/package.rs index c945d890..bc5e997b 100644 --- a/lightning/src/chain/package.rs +++ b/lightning/src/chain/package.rs @@ -86,7 +86,7 @@ const HIGH_FREQUENCY_BUMP_INTERVAL: u32 = 1; /// /// CSV and pubkeys are used as part of a witnessScript redeeming a balance output, amount is used /// as part of the signature hash and revocation secret to generate a satisfying witness. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub(crate) struct RevokedOutput { per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: PublicKey, @@ -129,7 +129,7 @@ impl_writeable_tlv_based!(RevokedOutput, { /// /// CSV is used as part of a witnessScript redeeming a balance output, amount is used as part /// of the signature hash and revocation secret to generate a satisfying witness. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub(crate) struct RevokedHTLCOutput { per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: PublicKey, @@ -171,7 +171,7 @@ impl_writeable_tlv_based!(RevokedHTLCOutput, { /// witnessScript. /// /// The preimage is used as part of the witness. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub(crate) struct CounterpartyOfferedHTLCOutput { per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: PublicKey, @@ -204,7 +204,7 @@ impl_writeable_tlv_based!(CounterpartyOfferedHTLCOutput, { /// /// HTLCOutputInCommitment (hash, timelock, directon) and pubkeys are used to generate a suitable /// witnessScript. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub(crate) struct CounterpartyReceivedHTLCOutput { per_commitment_point: PublicKey, counterparty_delayed_payment_base_key: PublicKey, @@ -234,7 +234,7 @@ impl_writeable_tlv_based!(CounterpartyReceivedHTLCOutput, { /// /// Either offered or received, the amount is always used as part of the bip143 sighash. /// Preimage is only included as part of the witness in former case. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub(crate) struct HolderHTLCOutput { preimage: Option, amount: u64, @@ -269,7 +269,7 @@ impl_writeable_tlv_based!(HolderHTLCOutput, { /// A struct to describe the channel output on the funding transaction. /// /// witnessScript is used as part of the witness redeeming the funding utxo. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub(crate) struct HolderFundingOutput { funding_redeemscript: Script, } @@ -290,7 +290,7 @@ impl_writeable_tlv_based!(HolderFundingOutput, { /// /// The generic API offers access to an outputs common attributes or allow transformation such as /// finalizing an input claiming the output. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub(crate) enum PackageSolvingData { RevokedOutput(RevokedOutput), RevokedHTLCOutput(RevokedHTLCOutput), @@ -444,7 +444,7 @@ impl_writeable_tlv_based_enum!(PackageSolvingData, ; /// A malleable package might be aggregated with other packages to save on fees. /// A untractable package has been counter-signed and aggregable will break cached counterparty /// signatures. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub(crate) enum PackageMalleability { Malleable, Untractable, @@ -459,7 +459,7 @@ pub(crate) enum PackageMalleability { /// /// As packages are time-sensitive, we fee-bump and rebroadcast them at scheduled intervals. /// Failing to confirm a package translate as a loss of funds for the user. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub struct PackageTemplate { // List of onchain outputs and solving data to generate satisfying witnesses. inputs: Vec<(BitcoinOutPoint, PackageSolvingData)>, diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index df037893..69ca4fb8 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -65,7 +65,7 @@ pub fn htlc_timeout_tx_weight(opt_anchors: bool) -> u64 { if opt_anchors { HTLC_TIMEOUT_ANCHOR_TX_WEIGHT } else { HTLC_TIMEOUT_TX_WEIGHT } } -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] pub(crate) enum HTLCClaim { OfferedTimeout, OfferedPreimage, @@ -208,6 +208,7 @@ pub struct CounterpartyCommitmentSecrets { old_secrets: [([u8; 32], u64); 49], } +impl Eq for CounterpartyCommitmentSecrets {} impl PartialEq for CounterpartyCommitmentSecrets { fn eq(&self, other: &Self) -> bool { 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(secp_ctx: &Secp2 /// channel basepoints via the new function, or they were obtained via /// CommitmentTransaction.trust().keys() because we trusted the source of the /// pre-calculated keys. -#[derive(PartialEq, Clone)] +#[derive(PartialEq, Eq, Clone)] pub struct TxCreationKeys { /// The broadcaster's per-commitment public key which was used to derive the other keys. pub per_commitment_point: PublicKey, @@ -444,7 +445,7 @@ impl_writeable_tlv_based!(TxCreationKeys, { }); /// One counterparty's public keys which do not change over the life of a channel. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub struct ChannelPublicKeys { /// The public key which is used to sign all commitment transactions, as it appears in the /// 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 res } -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] /// Information about an HTLC as it appears in a commitment transaction pub struct HTLCOutputInCommitment { /// Whether the HTLC was "offered" (ie outbound in relation to this commitment transaction). @@ -882,6 +883,7 @@ impl Deref for HolderCommitmentTransaction { fn deref(&self) -> &Self::Target { &self.inner } } +impl Eq for HolderCommitmentTransaction {} impl PartialEq for HolderCommitmentTransaction { // We dont care whether we are signed in equality comparison fn eq(&self, o: &Self) -> bool { @@ -1007,7 +1009,7 @@ impl BuiltCommitmentTransaction { /// /// This class can be used inside a signer implementation to generate a signature given the relevant /// secret key. -#[derive(Clone, Hash, PartialEq)] +#[derive(Clone, Hash, PartialEq, Eq)] pub struct ClosingTransaction { to_holder_value_sat: u64, to_counterparty_value_sat: u64, @@ -1147,6 +1149,7 @@ pub struct CommitmentTransaction { built: BuiltCommitmentTransaction, } +impl Eq for CommitmentTransaction {} impl PartialEq for CommitmentTransaction { fn eq(&self, o: &Self) -> bool { let eq = self.commitment_number == o.commitment_number && diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 4c103e11..6295fb70 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -50,7 +50,7 @@ use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000; /// An error in decoding a message or struct. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum DecodeError { /// A version byte specified something we don't know how to handle. /// Includes unknown realm byte in an OnionHopData packet @@ -73,7 +73,7 @@ pub enum DecodeError { } /// An init message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Init { /// The relevant features which the sender supports pub features: InitFeatures, @@ -85,7 +85,7 @@ pub struct Init { } /// An error message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ErrorMessage { /// The channel ID involved in the error. /// @@ -100,7 +100,7 @@ pub struct ErrorMessage { } /// A warning message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct WarningMessage { /// The channel ID involved in the warning. /// @@ -114,7 +114,7 @@ pub struct WarningMessage { } /// A ping message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Ping { /// The desired response length pub ponglen: u16, @@ -124,7 +124,7 @@ pub struct Ping { } /// A pong message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Pong { /// The pong packet size. /// This field is not sent on the wire. byteslen zeros are sent. @@ -132,7 +132,7 @@ pub struct Pong { } /// An open_channel message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct OpenChannel { /// The genesis hash of the blockchain where the channel is to be opened pub chain_hash: BlockHash, @@ -179,7 +179,7 @@ pub struct OpenChannel { } /// An accept_channel message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct AcceptChannel { /// A temporary channel ID, until the funding outpoint is announced pub temporary_channel_id: [u8; 32], @@ -220,7 +220,7 @@ pub struct AcceptChannel { } /// A funding_created message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct FundingCreated { /// A temporary channel ID, until the funding is established pub temporary_channel_id: [u8; 32], @@ -233,7 +233,7 @@ pub struct FundingCreated { } /// A funding_signed message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct FundingSigned { /// The channel ID pub channel_id: [u8; 32], @@ -242,7 +242,7 @@ pub struct FundingSigned { } /// A channel_ready message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ChannelReady { /// The channel ID pub channel_id: [u8; 32], @@ -254,7 +254,7 @@ pub struct ChannelReady { } /// A shutdown message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Shutdown { /// The channel ID pub channel_id: [u8; 32], @@ -266,7 +266,7 @@ pub struct Shutdown { /// The minimum and maximum fees which the sender is willing to place on the closing transaction. /// This is provided in [`ClosingSigned`] by both sides to indicate the fee range they are willing /// to use. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ClosingSignedFeeRange { /// The minimum absolute fee, in satoshis, which the sender is willing to place on the closing /// transaction. @@ -277,7 +277,7 @@ pub struct ClosingSignedFeeRange { } /// A closing_signed message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ClosingSigned { /// The channel ID pub channel_id: [u8; 32], @@ -291,7 +291,7 @@ pub struct ClosingSigned { } /// An update_add_htlc message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct UpdateAddHTLC { /// The channel ID pub channel_id: [u8; 32], @@ -307,7 +307,7 @@ pub struct UpdateAddHTLC { } /// An onion message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct OnionMessage { /// Used in decrypting the onion packet's payload. pub blinding_point: PublicKey, @@ -315,7 +315,7 @@ pub struct OnionMessage { } /// An update_fulfill_htlc message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct UpdateFulfillHTLC { /// The channel ID pub channel_id: [u8; 32], @@ -326,7 +326,7 @@ pub struct UpdateFulfillHTLC { } /// An update_fail_htlc message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct UpdateFailHTLC { /// The channel ID pub channel_id: [u8; 32], @@ -336,7 +336,7 @@ pub struct UpdateFailHTLC { } /// An update_fail_malformed_htlc message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct UpdateFailMalformedHTLC { /// The channel ID pub channel_id: [u8; 32], @@ -348,7 +348,7 @@ pub struct UpdateFailMalformedHTLC { } /// A commitment_signed message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct CommitmentSigned { /// The channel ID pub channel_id: [u8; 32], @@ -359,7 +359,7 @@ pub struct CommitmentSigned { } /// A revoke_and_ack message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct RevokeAndACK { /// The channel ID pub channel_id: [u8; 32], @@ -370,7 +370,7 @@ pub struct RevokeAndACK { } /// An update_fee message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct UpdateFee { /// The channel ID pub channel_id: [u8; 32], @@ -378,7 +378,7 @@ pub struct UpdateFee { pub feerate_per_kw: u32, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] /// Proof that the sender knows the per-commitment secret of the previous commitment transaction. /// This is used to convince the recipient that the channel is at a certain commitment /// number even if they lost that data due to a local failure. Of course, the peer may lie @@ -392,7 +392,7 @@ pub struct DataLossProtect { } /// A channel_reestablish message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ChannelReestablish { /// The channel ID pub channel_id: [u8; 32], @@ -405,7 +405,7 @@ pub struct ChannelReestablish { } /// An announcement_signatures message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct AnnouncementSignatures { /// The channel ID pub channel_id: [u8; 32], @@ -418,7 +418,7 @@ pub struct AnnouncementSignatures { } /// An address which can be used to connect to a remote peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum NetAddress { /// An IPv4 address/port on which the peer is listening. IPv4 { @@ -573,7 +573,7 @@ impl Readable for NetAddress { /// The unsigned part of a node_announcement -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct UnsignedNodeAnnouncement { /// The advertised features pub features: NodeFeatures, @@ -592,7 +592,7 @@ pub struct UnsignedNodeAnnouncement { pub(crate) excess_address_data: Vec, pub(crate) excess_data: Vec, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] /// A node_announcement message to be sent or received from a peer pub struct NodeAnnouncement { /// The signature by the node key @@ -602,7 +602,7 @@ pub struct NodeAnnouncement { } /// The unsigned part of a channel_announcement -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct UnsignedChannelAnnouncement { /// The advertised channel features pub features: ChannelFeatures, @@ -621,7 +621,7 @@ pub struct UnsignedChannelAnnouncement { pub(crate) excess_data: Vec, } /// A channel_announcement message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ChannelAnnouncement { /// Authentication of the announcement by the first public node pub node_signature_1: Signature, @@ -636,7 +636,7 @@ pub struct ChannelAnnouncement { } /// The unsigned part of a channel_update -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct UnsignedChannelUpdate { /// The genesis hash of the blockchain where the channel is to be opened pub chain_hash: BlockHash, @@ -669,7 +669,7 @@ pub struct UnsignedChannelUpdate { pub excess_data: Vec, } /// A channel_update message to be sent or received from a peer -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ChannelUpdate { /// A signature of the channel update pub signature: Signature, @@ -681,7 +681,7 @@ pub struct ChannelUpdate { /// UTXOs in a range of blocks. The recipient of a query makes a best /// effort to reply to the query using one or more reply_channel_range /// messages. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct QueryChannelRange { /// The genesis hash of the blockchain being queried pub chain_hash: BlockHash, @@ -698,7 +698,7 @@ pub struct QueryChannelRange { /// not be a perfect view of the network. The short_channel_ids in the /// reply are encoded. We only support encoding_type=0 uncompressed /// serialization and do not support encoding_type=1 zlib serialization. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ReplyChannelRange { /// The genesis hash of the blockchain being queried pub chain_hash: BlockHash, @@ -720,7 +720,7 @@ pub struct ReplyChannelRange { /// reply_short_channel_ids_end message. The short_channel_ids sent in /// this query are encoded. We only support encoding_type=0 uncompressed /// serialization and do not support encoding_type=1 zlib serialization. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct QueryShortChannelIds { /// The genesis hash of the blockchain being queried pub chain_hash: BlockHash, @@ -732,7 +732,7 @@ pub struct QueryShortChannelIds { /// query_short_channel_ids message. The query recipient makes a best /// effort to respond based on their local network view which may not be /// a perfect view of the network. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ReplyShortChannelIdsEnd { /// The genesis hash of the blockchain that was queried pub chain_hash: BlockHash, @@ -744,7 +744,7 @@ pub struct ReplyShortChannelIdsEnd { /// A gossip_timestamp_filter message is used by a node to request /// gossip relay for messages in the requested time range when the /// gossip_queries feature has been negotiated. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct GossipTimestampFilter { /// The genesis hash of the blockchain for channel and node information pub chain_hash: BlockHash, @@ -805,7 +805,7 @@ pub struct LightningError { /// Struct used to return values from revoke_and_ack messages, containing a bunch of commitment /// transaction updates if they were pending. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct CommitmentUpdate { /// update_add_htlc messages which should be sent pub update_add_htlcs: Vec, @@ -826,7 +826,7 @@ pub struct CommitmentUpdate { /// OptionalFeild simply gets Present if there are enough bytes to read into it), we have a /// separate enum type for them. /// (C-not exported) due to a free generic in T -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum OptionalField { /// Optional field is included in message Present(T), @@ -1083,6 +1083,7 @@ impl onion_utils::Packet for OnionPacket { } } +impl Eq for OnionPacket { } impl PartialEq for OnionPacket { fn eq(&self, other: &OnionPacket) -> bool { for (i, j) in self.hop_data.iter().zip(other.hop_data.iter()) { @@ -1100,7 +1101,7 @@ impl fmt::Debug for OnionPacket { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub(crate) struct OnionErrorPacket { // This really should be a constant size slice, but the spec lets these things be up to 128KB? // (TODO) We limit it in decode to much lower... diff --git a/lightning/src/ln/script.rs b/lightning/src/ln/script.rs index 09363b6b..7b712589 100644 --- a/lightning/src/ln/script.rs +++ b/lightning/src/ln/script.rs @@ -18,7 +18,7 @@ use io; /// A script pubkey for shutting down a channel as defined by [BOLT #2]. /// /// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub struct ShutdownScript(ShutdownScriptImpl); /// An error occurring when converting from [`Script`] to [`ShutdownScript`]. @@ -30,7 +30,7 @@ pub struct InvalidShutdownScript { pub script: Script } -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] enum ShutdownScriptImpl { /// [`PublicKey`] used to form a P2WPKH script pubkey. Used to support backward-compatible /// serialization. diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index e2409fc4..3677efda 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -114,7 +114,7 @@ impl Destination { /// Errors that may occur when [sending an onion message]. /// /// [sending an onion message]: OnionMessenger::send_onion_message -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum SendError { /// Errored computing onion message packet keys. Secp256k1(secp256k1::Error), diff --git a/lightning/src/onion_message/packet.rs b/lightning/src/onion_message/packet.rs index 1337bdb1..20b1fb0b 100644 --- a/lightning/src/onion_message/packet.rs +++ b/lightning/src/onion_message/packet.rs @@ -27,7 +27,7 @@ use prelude::*; pub(super) const SMALL_PACKET_HOP_DATA_LEN: usize = 1300; pub(super) const BIG_PACKET_HOP_DATA_LEN: usize = 32768; -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub(crate) struct Packet { pub(super) version: u8, pub(super) public_key: PublicKey, diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 19f109f0..022f48fc 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -164,7 +164,7 @@ pub struct ReadOnlyNetworkGraph<'a> { /// return packet by a node along the route. See [BOLT #4] for details. /// /// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum NetworkUpdate { /// An error indicating a `channel_update` messages should be applied via /// [`NetworkGraph::update_channel`]. @@ -626,7 +626,7 @@ where } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] /// Details about one direction of a channel as received within a [`ChannelUpdate`]. pub struct ChannelUpdateInfo { /// When the last update to the channel direction was issued. @@ -709,7 +709,7 @@ impl Readable for ChannelUpdateInfo { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] /// Details about a channel (both directions). /// Received within a channel announcement. pub struct ChannelInfo { @@ -1017,7 +1017,7 @@ impl_writeable_tlv_based!(RoutingFees, { (2, proportional_millionths, required) }); -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] /// Information received in the latest node_announcement from this node. pub struct NodeAnnouncementInfo { /// Protocol features the node announced support for @@ -1053,7 +1053,7 @@ impl_writeable_tlv_based!(NodeAnnouncementInfo, { /// /// Since node aliases are provided by third parties, they are a potential avenue for injection /// attacks. Care must be taken when processing. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct NodeAlias(pub [u8; 32]); impl fmt::Display for NodeAlias { @@ -1094,7 +1094,7 @@ impl Readable for NodeAlias { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] /// Details about a node in the network, known from the network announcement. pub struct NodeInfo { /// All valid channels a node has announced @@ -1247,6 +1247,7 @@ impl fmt::Display for NetworkGraph where L::Target: Logger { } } +impl Eq for NetworkGraph where L::Target: Logger {} impl PartialEq for NetworkGraph where L::Target: Logger { fn eq(&self, other: &Self) -> bool { self.genesis_hash == other.genesis_hash && diff --git a/lightning/src/util/chacha20poly1305rfc.rs b/lightning/src/util/chacha20poly1305rfc.rs index 5fddb57e..3254e8b0 100644 --- a/lightning/src/util/chacha20poly1305rfc.rs +++ b/lightning/src/util/chacha20poly1305rfc.rs @@ -335,7 +335,7 @@ mod tests { use util::ser::{self, FixedLengthReader, LengthReadableArgs, Writeable}; // Used for for testing various lengths of serialization. - #[derive(Debug, PartialEq)] + #[derive(Debug, PartialEq, Eq)] struct TestWriteable { field1: Vec, field2: Vec, diff --git a/lightning/src/util/config.rs b/lightning/src/util/config.rs index b2004df3..f44e43b7 100644 --- a/lightning/src/util/config.rs +++ b/lightning/src/util/config.rs @@ -274,7 +274,7 @@ impl Default for ChannelHandshakeLimits { /// Options which apply on a per-channel basis and may change at runtime or based on negotiation /// with our counterparty. -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct ChannelConfig { /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound /// over the channel. diff --git a/lightning/src/util/errors.rs b/lightning/src/util/errors.rs index ad699354..f00d2ab2 100644 --- a/lightning/src/util/errors.rs +++ b/lightning/src/util/errors.rs @@ -16,7 +16,7 @@ use core::fmt; /// Indicates an error on the client's part (usually some variant of attempting to use too-low or /// too-high values) -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] pub enum APIError { /// Indicates the API was wholly misused (see err for more). Cases where these can be returned /// are documented, but generally indicates some precondition of a function was violated. diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index 8ddd762e..455263ee 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -74,7 +74,7 @@ impl_writeable_tlv_based_enum!(PaymentPurpose, (2, SpontaneousPayment) ); -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] /// The reason the channel was closed. See individual variants more details. pub enum ClosureReason { /// Closure generated from receiving a peer error message. @@ -153,7 +153,7 @@ impl_writeable_tlv_based_enum_upgradable!(ClosureReason, ); /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`]. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum HTLCDestination { /// We tried forwarding to a channel but failed to do so. An example of such an instance is when /// there is insufficient capacity in our outbound channel. diff --git a/lightning/src/util/scid_utils.rs b/lightning/src/util/scid_utils.rs index 676c303b..79ef415c 100644 --- a/lightning/src/util/scid_utils.rs +++ b/lightning/src/util/scid_utils.rs @@ -20,7 +20,7 @@ pub const MAX_SCID_TX_INDEX: u64 = 0x00ffffff; pub const MAX_SCID_VOUT_INDEX: u64 = 0xffff; /// A `short_channel_id` construction error -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum ShortChannelIdError { BlockOverflow, TxIndexOverflow, diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 6ef29073..3de03ea5 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -399,7 +399,7 @@ impl Readable for BigSize { /// In TLV we occasionally send fields which only consist of, or potentially end with, a /// variable-length integer which is simply truncated by skipping high zero bytes. This type /// encapsulates such integers implementing Readable/Writeable for them. -#[cfg_attr(test, derive(PartialEq, Debug))] +#[cfg_attr(test, derive(PartialEq, Eq, Debug))] pub(crate) struct HighZeroBytesDroppedBigSize(pub T); macro_rules! impl_writeable_primitive { @@ -979,7 +979,7 @@ impl Readable for String { /// The character set consists of ASCII alphanumeric characters, hyphens, and periods. /// Its length is guaranteed to be representable by a single byte. /// This serialization is used by BOLT 7 hostnames. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Hostname(String); impl Hostname { /// Returns the length of the hostname. -- 2.30.2