diff --git a/src/blocks/ticket.rs b/src/blocks/ticket.rs index 8510ce71fe0a..faad69dc19fa 100644 --- a/src/blocks/ticket.rs +++ b/src/blocks/ticket.rs @@ -8,6 +8,7 @@ use get_size2::GetSize; /// A Ticket is a marker of a tick of the blockchain's clock. It is the source /// of randomness for proofs of storage and leader election. It is generated /// by the miner of a block using a `VRF` and a `VDF`. +#[cfg_attr(test, derive(derive_more::Constructor))] #[derive( Clone, Debug, @@ -27,14 +28,6 @@ pub struct Ticket { pub vrfproof: VRFProof, } -impl Ticket { - #[cfg(test)] - /// Ticket constructor - pub fn new(vrfproof: VRFProof) -> Self { - Self { vrfproof } - } -} - #[cfg(test)] impl quickcheck::Arbitrary for Ticket { fn arbitrary(g: &mut quickcheck::Gen) -> Self { diff --git a/src/blocks/vrf_proof.rs b/src/blocks/vrf_proof.rs index 70e38b62d756..fbb2549d0836 100644 --- a/src/blocks/vrf_proof.rs +++ b/src/blocks/vrf_proof.rs @@ -6,17 +6,14 @@ use get_size2::GetSize; use serde::{Deserialize, Serialize}; /// The output from running a VRF proof. -#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))] +#[cfg_attr( + test, + derive(derive_quickcheck_arbitrary::Arbitrary, derive_more::Constructor) +)] #[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Default, Serialize, Deserialize, Hash)] pub struct VRFProof(#[serde(with = "serde_byte_array")] pub Vec); impl VRFProof { - /// Creates a `VRFProof` from a raw vector. - #[cfg(test)] - pub fn new(output: Vec) -> Self { - Self(output) - } - /// Returns reference to underlying proof bytes. pub fn as_bytes(&self) -> &[u8] { &self.0 diff --git a/src/chain/snapshot_format.rs b/src/chain/snapshot_format.rs index a44b0732d12a..996f0e28c99e 100644 --- a/src/chain/snapshot_format.rs +++ b/src/chain/snapshot_format.rs @@ -43,7 +43,7 @@ impl<'de> Deserialize<'de> for FilecoinSnapshotVersion { } /// Defined in -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, derive_more::Constructor)] #[serde(rename_all = "PascalCase")] pub struct FilecoinSnapshotMetadata { /// Snapshot version @@ -55,18 +55,6 @@ pub struct FilecoinSnapshotMetadata { } impl FilecoinSnapshotMetadata { - pub fn new( - version: FilecoinSnapshotVersion, - head_tipset_key: NonEmpty, - f3_data: Option, - ) -> Self { - Self { - version, - head_tipset_key, - f3_data, - } - } - pub fn new_v2(head_tipset_key: NonEmpty, f3_data: Option) -> Self { Self::new(FilecoinSnapshotVersion::V2, head_tipset_key, f3_data) } diff --git a/src/chain_sync/metrics.rs b/src/chain_sync/metrics.rs index 24ade583fbf2..dadd95ecd95f 100644 --- a/src/chain_sync/metrics.rs +++ b/src/chain_sync/metrics.rs @@ -45,15 +45,9 @@ pub static INVALID_TIPSET_TOTAL: LazyLock = LazyLock::new(|| { metric }); -#[derive(Clone, Debug, Hash, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, derive_more::Constructor)] pub struct Libp2pMessageKindLabel(&'static str); -impl Libp2pMessageKindLabel { - pub const fn new(kind: &'static str) -> Self { - Self(kind) - } -} - impl EncodeLabelSet for Libp2pMessageKindLabel { fn encode(&self, mut encoder: LabelSetEncoder) -> Result<(), std::fmt::Error> { let mut label_encoder = encoder.encode_label(); diff --git a/src/chain_sync/network_context.rs b/src/chain_sync/network_context.rs index ae78c1404ce7..8366a76f8d9a 100644 --- a/src/chain_sync/network_context.rs +++ b/src/chain_sync/network_context.rs @@ -47,6 +47,7 @@ const MAX_CONCURRENT_CHAIN_EXCHANGE_REQUESTS: usize = 2; /// Context used in chain sync to handle network requests. /// This contains the peer manager, P2P service interface, and [`Blockstore`] /// required to make network requests. +#[derive(derive_more::Constructor)] pub struct SyncNetworkContext { /// Channel to send network messages through P2P service network_send: flume::Sender, @@ -118,18 +119,6 @@ impl SyncNetworkContext where DB: Blockstore, { - pub fn new( - network_send: flume::Sender, - peer_manager: Arc, - db: Arc, - ) -> Self { - Self { - network_send, - peer_manager, - db, - } - } - /// Returns a reference to the peer manager of the network context. pub fn peer_manager(&self) -> &PeerManager { self.peer_manager.as_ref() diff --git a/src/db/blockstore_with_read_cache.rs b/src/db/blockstore_with_read_cache.rs index ee4b933ea369..e9b830f3d8c5 100644 --- a/src/db/blockstore_with_read_cache.rs +++ b/src/db/blockstore_with_read_cache.rs @@ -72,6 +72,7 @@ impl BlockstoreReadCacheStats for DefaultBlockstoreReadCacheStats { } } +#[derive(derive_more::Constructor)] pub struct BlockstoreWithReadCache< DB: Blockstore, CACHE: BlockstoreReadCache, @@ -85,14 +86,6 @@ pub struct BlockstoreWithReadCache< impl BlockstoreWithReadCache { - pub fn new(db: DB, cache: CACHE, stats: Option) -> Self { - Self { - inner: db, - cache, - stats, - } - } - pub fn stats(&self) -> Option<&STATS> { self.stats.as_ref() } diff --git a/src/fil_cns/mod.rs b/src/fil_cns/mod.rs index 17e20a5020a0..c84247960423 100644 --- a/src/fil_cns/mod.rs +++ b/src/fil_cns/mod.rs @@ -57,6 +57,7 @@ pub enum FilecoinConsensusError { ForestEncoding(#[from] ForestEncodingError), } +#[derive(derive_more::Constructor)] pub struct FilecoinConsensus { /// `Drand` randomness beacon /// @@ -67,10 +68,6 @@ pub struct FilecoinConsensus { } impl FilecoinConsensus { - pub fn new(beacon: Arc) -> Self { - Self { beacon } - } - pub async fn validate_block( &self, state_manager: Arc>, diff --git a/src/key_management/keystore.rs b/src/key_management/keystore.rs index 990bd3681b67..bc35ae411869 100644 --- a/src/key_management/keystore.rs +++ b/src/key_management/keystore.rs @@ -41,7 +41,7 @@ type SaltByteArray = [u8; RECOMMENDED_SALT_LEN]; /// `KeyInfo` structure, this contains the type of key (stored as a string) and /// the private key. Note how the private key is stored as a byte vector #[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))] -#[derive(Clone, PartialEq, Debug, Eq, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Debug, Eq, Serialize, Deserialize, derive_more::Constructor)] pub struct KeyInfo { key_type: SignatureType, // Vec is used because The private keys for BLS and SECP256K1 are not of the same type @@ -55,14 +55,6 @@ pub struct PersistentKeyInfo { } impl KeyInfo { - /// Return a new `KeyInfo` given the key type and private key - pub fn new(key_type: SignatureType, private_key: Vec) -> Self { - KeyInfo { - key_type, - private_key, - } - } - /// Return a reference to the key's signature type pub fn key_type(&self) -> &SignatureType { &self.key_type diff --git a/src/message_pool/msgpool/provider.rs b/src/message_pool/msgpool/provider.rs index d925d61988d2..a685810344dc 100644 --- a/src/message_pool/msgpool/provider.rs +++ b/src/message_pool/msgpool/provider.rs @@ -62,20 +62,12 @@ pub trait Provider { /// This is the default Provider implementation that will be used for the /// `mpool` RPC. +#[derive(derive_more::Constructor)] pub struct MpoolRpcProvider { subscriber: Publisher, sm: Arc>, } -impl MpoolRpcProvider -where - DB: Blockstore, -{ - pub fn new(subscriber: Publisher, sm: Arc>) -> Self { - MpoolRpcProvider { subscriber, sm } - } -} - #[async_trait] impl Provider for MpoolRpcProvider where diff --git a/src/metrics/mod.rs b/src/metrics/mod.rs index 6fdc5f2a06ad..e48098aa97d6 100644 --- a/src/metrics/mod.rs +++ b/src/metrics/mod.rs @@ -169,17 +169,11 @@ pub struct RpcMethodLabel { pub method: String, } -#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet, derive_more::Constructor)] pub struct KindLabel { kind: &'static str, } -impl KindLabel { - pub const fn new(kind: &'static str) -> Self { - Self { kind } - } -} - pub mod values { use super::KindLabel; diff --git a/src/networks/metrics.rs b/src/networks/metrics.rs index a033a705eb5e..41bd781fb694 100644 --- a/src/networks/metrics.rs +++ b/src/networks/metrics.rs @@ -13,7 +13,7 @@ use prometheus_client::{ use super::calculate_expected_epoch; use crate::{networks::ChainConfig, shim::clock::ChainEpoch}; -#[derive(Educe)] +#[derive(Educe, derive_more::Constructor)] #[educe(Debug)] pub struct NetworkHeightCollector where @@ -25,23 +25,6 @@ where get_chain_head_height: Arc, } -impl NetworkHeightCollector -where - F: Fn() -> ChainEpoch, -{ - pub fn new( - block_delay_secs: u32, - genesis_timestamp: u64, - get_chain_head_height: Arc, - ) -> Self { - Self { - block_delay_secs, - genesis_timestamp, - get_chain_head_height, - } - } -} - impl Collector for NetworkHeightCollector where F: Fn() -> ChainEpoch + Send + Sync + 'static, @@ -82,7 +65,7 @@ where } } -#[derive(Educe)] +#[derive(Educe, derive_more::Constructor)] #[educe(Debug)] pub struct NetworkVersionCollector where @@ -96,24 +79,6 @@ where get_chain_head_actor_version: Arc, } -impl NetworkVersionCollector -where - F1: Fn() -> ChainEpoch, - F2: Fn() -> u64, -{ - pub fn new( - chain_config: Arc, - get_chain_head_height: Arc, - get_chain_head_actor_version: Arc, - ) -> Self { - Self { - chain_config, - get_chain_head_height, - get_chain_head_actor_version, - } - } -} - impl Collector for NetworkVersionCollector where F1: Fn() -> ChainEpoch + Send + Sync + 'static, diff --git a/src/rpc/methods/eth/pubsub.rs b/src/rpc/methods/eth/pubsub.rs index 7c4d2bef3fd1..d69cb082e006 100644 --- a/src/rpc/methods/eth/pubsub.rs +++ b/src/rpc/methods/eth/pubsub.rs @@ -69,16 +69,11 @@ use jsonrpsee::core::{SubscriptionError, SubscriptionResult}; use std::sync::Arc; use tokio::sync::broadcast::{Receiver as Subscriber, error::RecvError}; +#[derive(derive_more::Constructor)] pub struct EthPubSub { ctx: Arc>, } -impl EthPubSub { - pub fn new(ctx: Arc>) -> Self { - Self { ctx } - } -} - #[async_trait::async_trait] impl EthPubSubApiServer for EthPubSub where diff --git a/src/rpc/types/mod.rs b/src/rpc/types/mod.rs index 8c5180062ffb..60ee00609b90 100644 --- a/src/rpc/types/mod.rs +++ b/src/rpc/types/mod.rs @@ -377,7 +377,9 @@ pub struct CirculatingSupply { lotus_json_with_self!(CirculatingSupply); -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] +#[derive( + Debug, Clone, Serialize, Deserialize, PartialEq, Eq, JsonSchema, derive_more::Constructor, +)] #[serde(rename_all = "PascalCase")] pub struct MinerSectors { live: u64, @@ -386,16 +388,6 @@ pub struct MinerSectors { } lotus_json_with_self!(MinerSectors); -impl MinerSectors { - pub fn new(live: u64, active: u64, faulty: u64) -> Self { - Self { - live, - active, - faulty, - } - } -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)] #[serde(rename_all = "PascalCase")] pub struct MinerPartitions { diff --git a/src/shim/crypto.rs b/src/shim/crypto.rs index df2e626ae413..c0ea0e6c81cf 100644 --- a/src/shim/crypto.rs +++ b/src/shim/crypto.rs @@ -23,7 +23,7 @@ use schemars::JsonSchema; use std::borrow::Cow; /// A cryptographic signature, represented in bytes, of any key protocol. -#[derive(Clone, Debug, PartialEq, Eq, Hash, GetSize)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, GetSize, derive_more::Constructor)] #[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))] pub struct Signature { pub sig_type: SignatureType, @@ -70,10 +70,6 @@ impl<'de> de::Deserialize<'de> for Signature { } impl Signature { - pub fn new(sig_type: SignatureType, bytes: Vec) -> Self { - Signature { sig_type, bytes } - } - /// Creates a BLS Signature given the raw bytes. pub fn new_bls(bytes: Vec) -> Self { Self { diff --git a/src/state_manager/chain_rand.rs b/src/state_manager/chain_rand.rs index 13a192d357e2..e2015e12d300 100644 --- a/src/state_manager/chain_rand.rs +++ b/src/state_manager/chain_rand.rs @@ -16,6 +16,7 @@ use byteorder::{BigEndian, WriteBytesExt}; use fvm_ipld_blockstore::Blockstore; /// Allows for deriving the randomness from a particular tipset. +#[derive(derive_more::Constructor)] pub struct ChainRand { chain_config: Arc, tipset: Tipset, @@ -38,20 +39,6 @@ impl ChainRand where DB: Blockstore, { - pub fn new( - chain_config: Arc, - tipset: Tipset, - chain_index: Arc>>, - beacon: Arc, - ) -> Self { - Self { - chain_config, - tipset, - chain_index, - beacon, - } - } - /// Gets 32 bytes of randomness for `ChainRand` parameterized by the /// `DomainSeparationTag`, `ChainEpoch`, Entropy from the ticket chain. pub fn get_chain_randomness( diff --git a/src/utils/version/mod.rs b/src/utils/version/mod.rs index cef28945b042..6ab2ac1fe84d 100644 --- a/src/utils/version/mod.rs +++ b/src/utils/version/mod.rs @@ -21,17 +21,11 @@ pub static FOREST_VERSION_STRING: LazyLock = pub static FOREST_VERSION: LazyLock = LazyLock::new(|| semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Invalid version")); -#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet, derive_more::Constructor)] pub struct VersionLabel { version: &'static str, } -impl VersionLabel { - pub const fn new(version: &'static str) -> Self { - Self { version } - } -} - #[derive(Debug)] pub struct ForestVersionCollector { version: Family,