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

Derive Eq for all structs that derive PartialEq #1763

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lightning-block-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lightning-block-sync/src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lightning-invoice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 9 additions & 9 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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<PaymentPreimage>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<u32>,
/// The txid of the transaction which resolved the HTLC, this may be a commitment (if the HTLC
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/chain/keysinterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<BlockHash>,
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/chain/onchaintx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions lightning/src/chain/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<PaymentPreimage>,
amount: u64,
Expand Down Expand Up @@ -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,
}
Expand All @@ -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),
Expand Down Expand Up @@ -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,
Expand All @@ -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)>,
Expand Down
13 changes: 8 additions & 5 deletions lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -419,7 +420,7 @@ pub fn derive_public_revocation_key<T: secp256k1::Verification>(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,
Expand All @@ -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.
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 &&
Expand Down
Loading