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

Add clippy CI check to workflow #99

Merged
merged 19 commits into from
Jun 17, 2024
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
11 changes: 11 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ env:
CARGO_TERM_COLOR: always

jobs:
# check workspace for warnings & treat them as errors
clippy:
name: clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: dsherret/rust-toolchain-file@v1
- name: Clippy Check
run: cargo clippy --all-targets -- -D warnings

# check if workspace is formatted, and treat unformatted code as errors.
fmt-check:
name: fmt
Expand Down
13 changes: 4 additions & 9 deletions crates/actors/src/account_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ impl ActorName for AccountCacheActor {
}
}

#[derive(Debug, Clone, Error)]
#[derive(Debug, Clone, Error, Default)]
pub enum AccountCacheError {
#[default]
#[error("failed to acquire AccountCacheActor from registry")]
RactorRegistryError,

Expand All @@ -43,12 +44,6 @@ pub enum AccountCacheError {
Custom(String),
}

impl Default for AccountCacheError {
fn default() -> Self {
AccountCacheError::RactorRegistryError
}
}

pub struct AccountCache<S: PersistenceStore> {
inner: AccountCacheInner,
storage: S,
Expand Down Expand Up @@ -263,9 +258,9 @@ impl Actor for AccountCacheActor {
bincode::deserialize(&returned_data)
.typecast()
.log_err(|e| e)
.and_then(|AccountValue { account }| {
.map(|AccountValue { account }| {
tracing::debug!("retrieved account from persistence store for address {hex_address}: {account:?}");
Some(account)
account
})
})
};
Expand Down
11 changes: 3 additions & 8 deletions crates/actors/src/batcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub const ETH_ADDR: Address = Address::eth_addr();
// const BATCH_INTERVAL: u64 = 180;
pub type PendingReceivers = FuturesUnordered<OneshotReceiver<(String, BlobVerificationProof)>>;

#[derive(Debug, Error)]
#[derive(Debug, Error, Default)]
pub enum BatcherError {
#[error(transparent)]
AccountCacheMessage(#[from] MessagingErr<AccountCacheMessage>),
Expand All @@ -86,19 +86,14 @@ pub enum BatcherError {
#[error("{msg}")]
FailedTransaction { msg: String, txn: Box<Transaction> },

#[default]
#[error("failed to acquire BatcherActor from registry")]
RactorRegistryError,

#[error("{0}")]
Custom(String),
}

impl Default for BatcherError {
fn default() -> Self {
BatcherError::RactorRegistryError
}
}

#[derive(Clone, Debug, Default)]
pub struct BatcherActor {
future_pool: UnorderedFuturePool<StaticFuture<Result<(), BatcherError>>>,
Expand Down Expand Up @@ -1719,7 +1714,7 @@ impl Batcher {
//TiKV will accept any key if of type String, OR Vec<u8>
let acc_val = AccountValue { account: data };
// Serialize `Account` data to be stored.
if let Some(val) = bincode::serialize(&acc_val).ok() {
if let Ok(val) = bincode::serialize(&acc_val) {
if PersistenceStore::put(&storage_ref, addr.clone().into(), val)
.await
.is_ok()
Expand Down
13 changes: 4 additions & 9 deletions crates/actors/src/da_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl DaClientActor {
match res {
Ok(blob) => {
if let Ok(blob) = EncodedBlob::from_str(&blob) {
Batch::decode_batch(&blob.data()).map(|batch| {
if let Some(batch) = Batch::decode_batch(&blob.data()) {
let account = batch.get_user_account(address);
if let Err(Some(account)) = tx.send(account.clone()) {
tracing::error!(
Expand All @@ -102,7 +102,7 @@ impl DaClientActor {
tracing::warn!("found account: {}", acct.owner_address().to_full_string());
}
}
});
};
}
}
Err(err) => tracing::error!("Error attempting to retreive account for batcher_header_hash {batch_header_hash} and blob_index {blob_index}: {err:?}"),
Expand All @@ -115,21 +115,16 @@ pub struct DaClient {
client: EigenDaGrpcClient,
}

#[derive(Clone, Debug, Error)]
#[derive(Clone, Debug, Error, Default)]
pub enum DaClientError {
#[default]
#[error("failed to acquire DaClientActor from registry")]
RactorRegistryError,

#[error("{0}")]
Custom(String),
}

impl Default for DaClientError {
fn default() -> Self {
DaClientError::RactorRegistryError
}
}

impl DaClient {
pub fn new(client: EigenDaGrpcClient) -> Self {
Self { client }
Expand Down
6 changes: 2 additions & 4 deletions crates/actors/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ impl EngineActor {
if let Ok(Some(account)) = self.check_cache(address).await {
return account;
}
} else {
if let Ok(Some(account)) = self.check_cache(address).await {
return account;
}
} else if let Ok(Some(account)) = self.check_cache(address).await {
return account;
}

Account::new(account_type, None, *address, None)
Expand Down
14 changes: 8 additions & 6 deletions crates/actors/src/eo_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ impl ActorName for EoClientActor {
}
}

#[derive(Debug, Error)]
impl Default for EoClientActor {
fn default() -> Self {
Self::new()
}
}

#[derive(Debug, Error, Default)]
pub enum EoClientError {
#[default]
#[error("failed to acquire EoClientActor from registry")]
RactorRegistryError,

#[error("{0}")]
Custom(String),
}
impl Default for EoClientError {
fn default() -> Self {
EoClientError::RactorRegistryError
}
}

impl EoClientActor {
pub fn new() -> Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/actors/src/eo_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ impl EoServerActor {
let a_value = a
.params
.iter()
.find(|p| p.name == "bridgeEventId".to_string())
.find(|p| p.name == *"bridgeEventId")
.and_then(|p| p.value.clone().into_uint()?.into());
let b_value = b
.params
.iter()
.find(|p| p.name == "bridgeEventId".to_string())
.find(|p| p.name == *"bridgeEventId")
.and_then(|p| p.value.clone().into_uint()?.into());

a_value.cmp(&b_value)
Expand Down
7 changes: 6 additions & 1 deletion crates/actors/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ impl ActorName for ExecutorActor {
ActorType::Executor.to_string()
}
}
impl Default for ExecutorActor {
fn default() -> Self {
Self::new()
}
}

impl ExecutorActor {
pub fn new() -> Self {
Expand Down Expand Up @@ -439,7 +444,7 @@ impl ExecutorActor {
let manager = {
let state = engine.lock().await;
let manager = state.manager.clone();
if let Err(_) = manager.check_pinned_status(&content_id).await {
if (manager.check_pinned_status(&content_id).await).is_err() {
match state.pin_object(&content_id.clone(), true).await {
Ok(()) => {
tracing::info!("Successfully pinned objects");
Expand Down
2 changes: 1 addition & 1 deletion crates/actors/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn get_actor_ref<M: Sized, E: Default + StdError + Debug>(
.ok_or(E::default())
.typecast()
.log_err(|e| e)
.and_then(|a| Some(a.into()))
.map(|a| a.into())
}

/// Wrapper type for `std::result::Result` with emphasis on `ractor::Actor` friendliness.
Expand Down
14 changes: 7 additions & 7 deletions crates/actors/src/pending_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,11 @@ impl DependencyGraphs {

#[derive(Debug, Clone)]
pub struct PendingTransactionActor;
impl Default for PendingTransactionActor {
fn default() -> Self {
Self::new()
}
}
impl PendingTransactionActor {
pub fn new() -> Self {
Self
Expand All @@ -673,21 +678,16 @@ impl ActorName for PendingTransactionActor {
}
}

#[derive(Debug, Clone, Error)]
#[derive(Debug, Clone, Error, Default)]
pub enum PendingTransactionError {
#[default]
#[error("failed to acquire PendingTransactionActor from registry")]
RactorRegistryError,

#[error("{0}")]
Custom(String),
}

impl Default for PendingTransactionError {
fn default() -> Self {
PendingTransactionError::RactorRegistryError
}
}

#[async_trait]
impl Actor for PendingTransactionActor {
type Msg = PendingTransactionMessage;
Expand Down
10 changes: 3 additions & 7 deletions crates/actors/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use lasr_messages::{
use lasr_types::{Address, RecoverableSignature, Transaction};
use ractor::{concurrency::oneshot, Actor, ActorProcessingErr, ActorRef, RpcReplyPort};
use ractor::{ActorCell, SupervisionEvent};
use std::default;
use std::sync::{Arc, Mutex};
use std::{collections::HashMap, fmt::Display};
use thiserror::*;
Expand All @@ -22,21 +23,16 @@ use tokio::task::JoinHandle;

/// A generic error type to propagate errors from this actor
/// and other actors that interact with it
#[derive(Debug, Clone, Error)]
#[derive(Debug, Clone, Error, Default)]
pub enum SchedulerError {
#[default]
#[error("failed to acquire SchedulerActor from registry")]
RactorRegistryError,

#[error("{0}")]
Custom(String),
}

impl Default for SchedulerError {
fn default() -> Self {
SchedulerError::RactorRegistryError
}
}

pub type MethodResults = Arc<Mutex<FuturesUnordered<Result<(), Box<dyn std::error::Error>>>>>;

pub struct SchedulerState {
Expand Down
9 changes: 2 additions & 7 deletions crates/actors/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,9 @@ impl ActorName for ValidatorActor {
}
}

#[derive(Debug, Error)]
#[derive(Debug, Error, Default)]
pub enum ValidatorError {
#[default]
#[error("failed to acquire ValidatorActor from registry")]
RactorRegistryError,

Expand All @@ -966,12 +967,6 @@ pub enum ValidatorError {
ValidatorCoreError(#[from] ValidatorCoreError),
}

impl Default for ValidatorError {
fn default() -> Self {
ValidatorError::RactorRegistryError
}
}

impl ValidatorActor {
pub fn new() -> Self {
Self {
Expand Down
1 change: 1 addition & 0 deletions crates/actors/tests/account.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(test)]
#![cfg(feature = "mock_storage")]
//! Test coverage for events that make changes to `Account`.

use std::{
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ struct U256Wrapper(pub U256);
impl FromStr for U256Wrapper {
type Err = uint::FromDecStrErr;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.starts_with("0x") {
if let Some(s) = s.strip_prefix("0x") {
Ok(U256Wrapper(
ethereum_types::U256::from_str_radix(&s[2..], 16)
ethereum_types::U256::from_str_radix(s, 16)
.expect("failed to convert hex string to U256")
.into(),
))
Expand Down
Loading
Loading