Skip to content
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
9 changes: 1 addition & 8 deletions src/blocks/ticket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
11 changes: 4 additions & 7 deletions src/blocks/vrf_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>);

impl VRFProof {
/// Creates a `VRFProof` from a raw vector.
#[cfg(test)]
pub fn new(output: Vec<u8>) -> Self {
Self(output)
}

/// Returns reference to underlying proof bytes.
pub fn as_bytes(&self) -> &[u8] {
&self.0
Expand Down
14 changes: 1 addition & 13 deletions src/chain/snapshot_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'de> Deserialize<'de> for FilecoinSnapshotVersion {
}

/// Defined in <https://github.com/filecoin-project/FIPs/blob/98e33b9fa306959aa0131519eb4cc155522b2081/FRCs/frc-0108.md#snapshotmetadata>
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, derive_more::Constructor)]
#[serde(rename_all = "PascalCase")]
pub struct FilecoinSnapshotMetadata {
/// Snapshot version
Expand All @@ -55,18 +55,6 @@ pub struct FilecoinSnapshotMetadata {
}

impl FilecoinSnapshotMetadata {
pub fn new(
version: FilecoinSnapshotVersion,
head_tipset_key: NonEmpty<Cid>,
f3_data: Option<Cid>,
) -> Self {
Self {
version,
head_tipset_key,
f3_data,
}
}

pub fn new_v2(head_tipset_key: NonEmpty<Cid>, f3_data: Option<Cid>) -> Self {
Self::new(FilecoinSnapshotVersion::V2, head_tipset_key, f3_data)
}
Expand Down
8 changes: 1 addition & 7 deletions src/chain_sync/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,9 @@ pub static INVALID_TIPSET_TOTAL: LazyLock<Counter> = 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();
Expand Down
13 changes: 1 addition & 12 deletions src/chain_sync/network_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DB> {
/// Channel to send network messages through P2P service
network_send: flume::Sender<NetworkMessage>,
Expand Down Expand Up @@ -118,18 +119,6 @@ impl<DB> SyncNetworkContext<DB>
where
DB: Blockstore,
{
pub fn new(
network_send: flume::Sender<NetworkMessage>,
peer_manager: Arc<PeerManager>,
db: Arc<DB>,
) -> 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()
Expand Down
9 changes: 1 addition & 8 deletions src/db/blockstore_with_read_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl BlockstoreReadCacheStats for DefaultBlockstoreReadCacheStats {
}
}

#[derive(derive_more::Constructor)]
pub struct BlockstoreWithReadCache<
DB: Blockstore,
CACHE: BlockstoreReadCache,
Expand All @@ -85,14 +86,6 @@ pub struct BlockstoreWithReadCache<
impl<DB: Blockstore, CACHE: BlockstoreReadCache, STATS: BlockstoreReadCacheStats>
BlockstoreWithReadCache<DB, CACHE, STATS>
{
pub fn new(db: DB, cache: CACHE, stats: Option<STATS>) -> Self {
Self {
inner: db,
cache,
stats,
}
}

pub fn stats(&self) -> Option<&STATS> {
self.stats.as_ref()
}
Expand Down
5 changes: 1 addition & 4 deletions src/fil_cns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub enum FilecoinConsensusError {
ForestEncoding(#[from] ForestEncodingError),
}

#[derive(derive_more::Constructor)]
pub struct FilecoinConsensus {
/// `Drand` randomness beacon
///
Expand All @@ -67,10 +68,6 @@ pub struct FilecoinConsensus {
}

impl FilecoinConsensus {
pub fn new(beacon: Arc<BeaconSchedule>) -> Self {
Self { beacon }
}

pub async fn validate_block<DB: Blockstore + Sync + Send + 'static>(
&self,
state_manager: Arc<StateManager<DB>>,
Expand Down
10 changes: 1 addition & 9 deletions src/key_management/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> is used because The private keys for BLS and SECP256K1 are not of the same type
Expand All @@ -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<u8>) -> Self {
KeyInfo {
key_type,
private_key,
}
}

/// Return a reference to the key's signature type
pub fn key_type(&self) -> &SignatureType {
&self.key_type
Expand Down
10 changes: 1 addition & 9 deletions src/message_pool/msgpool/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DB> {
subscriber: Publisher<HeadChange>,
sm: Arc<StateManager<DB>>,
}

impl<DB> MpoolRpcProvider<DB>
where
DB: Blockstore,
{
pub fn new(subscriber: Publisher<HeadChange>, sm: Arc<StateManager<DB>>) -> Self {
MpoolRpcProvider { subscriber, sm }
}
}

#[async_trait]
impl<DB> Provider for MpoolRpcProvider<DB>
where
Expand Down
8 changes: 1 addition & 7 deletions src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
39 changes: 2 additions & 37 deletions src/networks/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F>
where
Expand All @@ -25,23 +25,6 @@ where
get_chain_head_height: Arc<F>,
}

impl<F> NetworkHeightCollector<F>
where
F: Fn() -> ChainEpoch,
{
pub fn new(
block_delay_secs: u32,
genesis_timestamp: u64,
get_chain_head_height: Arc<F>,
) -> Self {
Self {
block_delay_secs,
genesis_timestamp,
get_chain_head_height,
}
}
}

impl<F> Collector for NetworkHeightCollector<F>
where
F: Fn() -> ChainEpoch + Send + Sync + 'static,
Expand Down Expand Up @@ -82,7 +65,7 @@ where
}
}

#[derive(Educe)]
#[derive(Educe, derive_more::Constructor)]
#[educe(Debug)]
pub struct NetworkVersionCollector<F1, F2>
where
Expand All @@ -96,24 +79,6 @@ where
get_chain_head_actor_version: Arc<F2>,
}

impl<F1, F2> NetworkVersionCollector<F1, F2>
where
F1: Fn() -> ChainEpoch,
F2: Fn() -> u64,
{
pub fn new(
chain_config: Arc<ChainConfig>,
get_chain_head_height: Arc<F1>,
get_chain_head_actor_version: Arc<F2>,
) -> Self {
Self {
chain_config,
get_chain_head_height,
get_chain_head_actor_version,
}
}
}

impl<F1, F2> Collector for NetworkVersionCollector<F1, F2>
where
F1: Fn() -> ChainEpoch + Send + Sync + 'static,
Expand Down
7 changes: 1 addition & 6 deletions src/rpc/methods/eth/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DB> {
ctx: Arc<RPCState<DB>>,
}

impl<DB> EthPubSub<DB> {
pub fn new(ctx: Arc<RPCState<DB>>) -> Self {
Self { ctx }
}
}

#[async_trait::async_trait]
impl<DB> EthPubSubApiServer for EthPubSub<DB>
where
Expand Down
14 changes: 3 additions & 11 deletions src/rpc/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions src/shim/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -70,10 +70,6 @@ impl<'de> de::Deserialize<'de> for Signature {
}

impl Signature {
pub fn new(sig_type: SignatureType, bytes: Vec<u8>) -> Self {
Signature { sig_type, bytes }
}

/// Creates a BLS Signature given the raw bytes.
pub fn new_bls(bytes: Vec<u8>) -> Self {
Self {
Expand Down
15 changes: 1 addition & 14 deletions src/state_manager/chain_rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DB> {
chain_config: Arc<ChainConfig>,
tipset: Tipset,
Expand All @@ -38,20 +39,6 @@ impl<DB> ChainRand<DB>
where
DB: Blockstore,
{
pub fn new(
chain_config: Arc<ChainConfig>,
tipset: Tipset,
chain_index: Arc<ChainIndex<Arc<DB>>>,
beacon: Arc<BeaconSchedule>,
) -> 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(
Expand Down
Loading
Loading