From 98a9626ef50d87b9943e284aa2a2467e63ca8df2 Mon Sep 17 00:00:00 2001 From: Akihito Nakano Date: Fri, 15 Jul 2022 07:31:19 +0000 Subject: [PATCH] Bump the MSRV to 1.62 and using `#[derive(Default)]` on enums (#3304) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Issue Addressed N/A ## Proposed Changes Since Rust 1.62, we can use `#[derive(Default)]` on enums. ✨ https://blog.rust-lang.org/2022/06/30/Rust-1.62.0.html#default-enum-variants There are no changes to functionality in this PR, just replaced the `Default` trait implementation with `#[derive(Default)]`. --- .github/workflows/local-testnet.yml | 3 +++ Dockerfile | 2 +- beacon_node/client/src/config.rs | 9 ++------- .../src/peer_manager/peerdb/peer_info.rs | 9 ++------- beacon_node/lighthouse_network/src/types/topics.rs | 9 ++------- crypto/eth2_keystore/src/json_keystore/kdf_module.rs | 9 ++------- lighthouse/Cargo.toml | 2 +- testing/ef_tests/src/bls_setting.rs | 9 ++------- 8 files changed, 15 insertions(+), 37 deletions(-) diff --git a/.github/workflows/local-testnet.yml b/.github/workflows/local-testnet.yml index 13c1af7ab6..b68135e4d8 100644 --- a/.github/workflows/local-testnet.yml +++ b/.github/workflows/local-testnet.yml @@ -18,6 +18,9 @@ jobs: steps: - uses: actions/checkout@v1 + - name: Get latest version of stable Rust + run: rustup update stable + - name: Install ganache run: npm install ganache@latest --global diff --git a/Dockerfile b/Dockerfile index aa2853ce4f..6732c7eaf8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.58.1-bullseye AS builder +FROM rust:1.62.0-bullseye AS builder RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev COPY . lighthouse ARG FEATURES diff --git a/beacon_node/client/src/config.rs b/beacon_node/client/src/config.rs index b13ca8f489..a5d5b37c7a 100644 --- a/beacon_node/client/src/config.rs +++ b/beacon_node/client/src/config.rs @@ -10,7 +10,7 @@ use types::{Graffiti, PublicKeyBytes}; const DEFAULT_FREEZER_DB_DIR: &str = "freezer_db"; /// Defines how the client should initialize the `BeaconChain` and other components. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Default)] pub enum ClientGenesis { /// Creates a genesis state as per the 2019 Canada interop specifications. Interop { @@ -21,6 +21,7 @@ pub enum ClientGenesis { FromStore, /// Connects to an eth1 node and waits until it can create the genesis state from the deposit /// contract. + #[default] DepositContract, /// Loads the genesis state from SSZ-encoded `BeaconState` bytes. /// @@ -38,12 +39,6 @@ pub enum ClientGenesis { }, } -impl Default for ClientGenesis { - fn default() -> Self { - Self::DepositContract - } -} - /// The core configuration of a Lighthouse beacon node. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { diff --git a/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs b/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs index 6273356b8f..555266d0e2 100644 --- a/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs +++ b/beacon_node/lighthouse_network/src/peer_manager/peerdb/peer_info.rs @@ -477,7 +477,7 @@ pub enum ConnectionDirection { } /// Connection Status of the peer. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub enum PeerConnectionStatus { /// The peer is connected. Connected { @@ -507,6 +507,7 @@ pub enum PeerConnectionStatus { since: Instant, }, /// The connection status has not been specified. + #[default] Unknown, } @@ -561,9 +562,3 @@ impl Serialize for PeerConnectionStatus { } } } - -impl Default for PeerConnectionStatus { - fn default() -> Self { - PeerConnectionStatus::Unknown - } -} diff --git a/beacon_node/lighthouse_network/src/types/topics.rs b/beacon_node/lighthouse_network/src/types/topics.rs index 3dd7ad8470..825b1088b2 100644 --- a/beacon_node/lighthouse_network/src/types/topics.rs +++ b/beacon_node/lighthouse_network/src/types/topics.rs @@ -78,18 +78,13 @@ impl std::fmt::Display for GossipKind { } /// The known encoding types for gossipsub messages. -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Default)] pub enum GossipEncoding { /// Messages are encoded with SSZSnappy. + #[default] SSZSnappy, } -impl Default for GossipEncoding { - fn default() -> Self { - GossipEncoding::SSZSnappy - } -} - impl GossipTopic { pub fn new(kind: GossipKind, encoding: GossipEncoding, fork_digest: [u8; 4]) -> Self { GossipTopic { diff --git a/crypto/eth2_keystore/src/json_keystore/kdf_module.rs b/crypto/eth2_keystore/src/json_keystore/kdf_module.rs index a1295e859c..94aeab0682 100644 --- a/crypto/eth2_keystore/src/json_keystore/kdf_module.rs +++ b/crypto/eth2_keystore/src/json_keystore/kdf_module.rs @@ -58,9 +58,10 @@ impl Kdf { } /// PRF for use in `pbkdf2`. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Default)] pub enum Prf { #[serde(rename = "hmac-sha256")] + #[default] HmacSha256, } @@ -73,12 +74,6 @@ impl Prf { } } -impl Default for Prf { - fn default() -> Self { - Prf::HmacSha256 - } -} - /// Parameters for `pbkdf2` key derivation. #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[serde(deny_unknown_fields)] diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index f7742ef0b9..920cfa49c1 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -4,7 +4,7 @@ version = "2.3.2-rc.0" authors = ["Sigma Prime "] edition = "2021" autotests = false -rust-version = "1.58" +rust-version = "1.62" [features] # Writes debugging .ssz files to /tmp during block processing. diff --git a/testing/ef_tests/src/bls_setting.rs b/testing/ef_tests/src/bls_setting.rs index add7d8b7bd..24aaf60080 100644 --- a/testing/ef_tests/src/bls_setting.rs +++ b/testing/ef_tests/src/bls_setting.rs @@ -2,20 +2,15 @@ use self::BlsSetting::*; use crate::error::Error; use serde_repr::Deserialize_repr; -#[derive(Deserialize_repr, Debug, Clone, Copy)] +#[derive(Deserialize_repr, Debug, Clone, Copy, Default)] #[repr(u8)] pub enum BlsSetting { + #[default] Flexible = 0, Required = 1, Ignored = 2, } -impl Default for BlsSetting { - fn default() -> Self { - Flexible - } -} - impl BlsSetting { /// Check the BLS setting and skip the test if it isn't compatible with the crypto config. pub fn check(self) -> Result<(), Error> {