Skip to content

Commit

Permalink
Clippy (#100)
Browse files Browse the repository at this point in the history
- Added clippy warning for `unwrap_used`, `expect_used`, `todo`
- Fixed typos, added error handling and remove unused code

---------

Co-authored-by: Pablo Deymonnaz <[email protected]>
  • Loading branch information
TomasArrachea and pablodeymo authored Sep 5, 2024
1 parent 77b8903 commit 2be5f67
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 22 deletions.
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ rust.unreachable_pub = "warn"
rust.unused_must_use = "deny"
rust.rust_2018_idioms = { level = "deny", priority = -1 }
rustdoc.all = "warn"
clippy.unwrap_used = "warn"
clippy.expect_used = "warn"
clippy.todo = "warn"

[workspace.dependencies]
ark-bn254 = "0.4.0"
Expand Down Expand Up @@ -111,11 +114,13 @@ tracing-subscriber = { version = "0.3", features = ["json"] }
url = "2.5.2"

#misc
rust-bls-bn254 = {git = "https://github.com/Layr-Labs/rust-bls-bn254.git", rev = "be3ef87", features = ["std"] }
rust-bls-bn254 = { git = "https://github.com/Layr-Labs/rust-bls-bn254.git", rev = "be3ef87", features = [
"std",
] }
uuid = { version = "1.10.0", features = ["v4"] }


#misc
#misc
parking_lot = "0.12"

#alloy
Expand All @@ -130,7 +135,8 @@ alloy-network = { version = "0.1", default-features = false }
alloy-node-bindings = { version = "0.1", default-features = false }
alloy-primitives = "0.7.2"
alloy-provider = { version = "0.1", default-features = false, features = [
"reqwest", "ws"
"reqwest",
"ws",
] }
alloy-pubsub = { version = "0.1", default-features = false }
alloy-rlp = "0.3.4"
Expand Down
2 changes: 2 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
msrv = "1.79"
allow-unwrap-in-tests = true
allow-expect-in-tests = true
10 changes: 9 additions & 1 deletion crates/chainio/clients/avsregistry/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub enum AvsRegistryError {
GetAvsRegistry,

/// Pubey registration msg hash
#[error("Failed to regiser pub key message hash")]
#[error("Failed to register pub key message hash")]
PubKeyRegistrationMessageHash,

/// Failed to calculate operator avs registration digest hash
Expand Down Expand Up @@ -149,6 +149,14 @@ pub enum AvsRegistryError {
/// Invalid Quorum Numbers
#[error("Invalid number of quorum numbers")]
InvalidQuorumNums,

/// Invalid Private Key
#[error("Invalid private key")]
InvalidPrivateKey,

/// Invalid Signature
#[error("Invalid signature")]
InvalidSignature,
}

impl From<ElContractsError> for AvsRegistryError {
Expand Down
5 changes: 3 additions & 2 deletions crates/chainio/clients/avsregistry/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ impl AvsRegistryChainWriter {
socket: String,
) -> Result<TxHash, AvsRegistryError> {
let provider = get_signer(self.signer.clone(), &self.provider);
let wallet = PrivateKeySigner::from_str(&self.signer).expect("failed to generate wallet ");
let wallet = PrivateKeySigner::from_str(&self.signer)
.map_err(|_| AvsRegistryError::InvalidPrivateKey)?;

// tracing info
info!(avs_service_manager = %self.service_manager_addr, operator= %wallet.address(),quorum_numbers = ?quorum_numbers,"quorum_numbers,registering operator with the AVS's registry coordinator");
Expand Down Expand Up @@ -186,7 +187,7 @@ impl AvsRegistryChainWriter {
let operator_signature = wallet
.sign_hash(&msg_to_sign)
.await
.expect("failed to sign message");
.map_err(|_| AvsRegistryError::InvalidSignature)?;

let operator_signature_with_salt_and_expiry = SignatureWithSaltAndExpiry {
signature: operator_signature.as_bytes().into(),
Expand Down
6 changes: 2 additions & 4 deletions examples/avsregistry-read/examples/get_operator_from_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use eyre::Result;
use std::str::FromStr;

#[tokio::main]
#[allow(clippy::expect_used)]
async fn main() -> Result<()> {
let holesky_provider = "https://holesky.drpc.org";

Expand All @@ -21,10 +22,7 @@ async fn main() -> Result<()> {
let operator_id =
FixedBytes::from_str("0xb31102e4cf235efcb84545cb656b039782755994835365d1cd11764ccb4f2fdd")
.expect("invalid operator id ");
let operator_address = avs_registry
.get_operator_from_id(*operator_id)
.await
.unwrap();
let operator_address = avs_registry.get_operator_from_id(*operator_id).await?;

println!("operator address is :{:?}", operator_address);
Ok(())
Expand Down
3 changes: 2 additions & 1 deletion examples/avsregistry-read/examples/get_operator_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use eigen_testing_utils::m2_holesky_constants::{OPERATOR_STATE_RETRIEVER, REGIST
use eyre::Result;

#[tokio::main]
#[allow(clippy::expect_used)]
async fn main() -> Result<()> {
let holesky_provider = "https://holesky.drpc.org";
let avs_registry = AvsRegistryChainReader::new(
Expand All @@ -18,7 +19,7 @@ async fn main() -> Result<()> {
.expect("failed to build avs registry chain reader");

let operator: Address = address!("1D79000206BAFfaE662fFCdba1C2a6176d14dF48");
let operator_id = avs_registry.get_operator_id(operator).await.unwrap();
let operator_id = avs_registry.get_operator_id(operator).await?;

println!("operator id is :{:?}", operator_id);
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use eyre::Result;
use std::str::FromStr;

#[tokio::main]
#[allow(clippy::expect_used)]
async fn main() -> Result<()> {
let holesky_provider = "https://holesky.drpc.org";
let avs_registry = AvsRegistryChainReader::new(
Expand All @@ -24,8 +25,7 @@ async fn main() -> Result<()> {
)
.expect("wrong operator id"),
)
.await
.unwrap();
.await?;

println!("operator state at current block is {:?}", operators_state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use eigen_testing_utils::m2_holesky_constants::{OPERATOR_STATE_RETRIEVER, REGIST
use eyre::Result;

#[tokio::main]
#[allow(clippy::expect_used)]
async fn main() -> Result<()> {
let holesky_provider = "https://holesky.drpc.org";
let avs_registry = AvsRegistryChainReader::new(
Expand All @@ -22,8 +23,7 @@ async fn main() -> Result<()> {
block_num,
Bytes::from_hex("0x00").expect("failed to generate bytes"),
)
.await
.unwrap();
.await?;

println!(
"operator state at block : {:?} is {:?}",
Expand Down
3 changes: 2 additions & 1 deletion examples/avsregistry-read/examples/get_quorum_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use eigen_testing_utils::m2_holesky_constants::{OPERATOR_STATE_RETRIEVER, REGIST
use eyre::Result;

#[tokio::main]
#[allow(clippy::expect_used)]
async fn main() -> Result<()> {
let holesky_provider = "https://holesky.drpc.org";
let avs_registry = AvsRegistryChainReader::new(
Expand All @@ -16,7 +17,7 @@ async fn main() -> Result<()> {
.await
.expect("failed to build avs registry chain reader");

let quorum_count = avs_registry.get_quorum_count().await.unwrap();
let quorum_count = avs_registry.get_quorum_count().await?;

println!("quorum count is :{:?}", quorum_count);
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use eigen_testing_utils::m2_holesky_constants::{OPERATOR_STATE_RETRIEVER, REGIST
use eyre::Result;

#[tokio::main]
#[allow(clippy::expect_used)]
async fn main() -> Result<()> {
let holesky_provider = "https://holesky.drpc.org";
let avs_registry = AvsRegistryChainReader::new(
Expand All @@ -23,8 +24,7 @@ async fn main() -> Result<()> {
to_block,
holesky_provider.to_string(),
)
.await
.unwrap();
.await?;

println!(
"operator state from block: {:?} to block: {:?} is {:?}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ lazy_static! {
static ref SIGNATURE_EXPIRY: U256 = U256::from(86400);
}
#[tokio::main]
#[allow(clippy::expect_used)]
async fn main() -> Result<()> {
let holesky_provider = "https://ethereum-holesky.blockpi.network/v1/rpc/public";
let pvt_key = "bead471191bea97fc3aeac36c9d74c895e8a6242602e144e43152f96219e96e8";
Expand All @@ -39,8 +40,7 @@ async fn main() -> Result<()> {
// Create a new key pair instance using the secret key
let bls_key_pair = BlsKeyPair::new(
"12248929636257230549931416853095037629726205319386239410403476017439825112537".to_string(),
)
.unwrap();
)?;

let digest_hash: FixedBytes<32> = FixedBytes::from([
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
Expand Down Expand Up @@ -104,7 +104,6 @@ async fn main() -> Result<()> {
quorum_nums,
"65.109.158.181:33078;31078".to_string(), // socket
)
.await
.unwrap();
.await?;
Ok(())
}
1 change: 1 addition & 0 deletions testing/testing-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ pub mod mainnet_constants;
pub mod m2_holesky_constants;

/// Anvil constants
#[allow(clippy::unwrap_used)]
pub mod anvil_constants;

0 comments on commit 2be5f67

Please sign in to comment.