From 2894de74104a2e8992de15574072bb6e9cf4c328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Anda=20Estensen?= Date: Wed, 27 Nov 2024 10:01:24 +0100 Subject: [PATCH 1/2] chore(bolt-sidecar): add lints --- bolt-sidecar/Cargo.toml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bolt-sidecar/Cargo.toml b/bolt-sidecar/Cargo.toml index f4c31ad43..a7788a660 100644 --- a/bolt-sidecar/Cargo.toml +++ b/bolt-sidecar/Cargo.toml @@ -33,7 +33,9 @@ alloy = { version = "0.6.4", features = [ "rpc-types-beacon", "rpc-types-engine", ] } -alloy-rpc-types-engine = { version = "0.6.4", default_features = false, features = ["jwt"] } +alloy-rpc-types-engine = { version = "0.6.4", default_features = false, features = [ + "jwt", +] } # reth reth-primitives = { git = "https://github.com/paradigmxyz/reth", version = "1.1.1" } @@ -86,3 +88,12 @@ ignored = ["ethereum_ssz"] [[bin]] name = "bolt-sidecar" path = "bin/sidecar.rs" + +[lints.clippy] +explicit_iter_loop = "warn" +if_not_else = "warn" +manual_let_else = "warn" +match_bool = "warn" +redundant_else = "warn" +unnecessary_self_imports = "warn" +use_self = "warn" From b34b1f1b0b1beca736f273576258b1413007de5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Anda=20Estensen?= Date: Wed, 27 Nov 2024 10:15:43 +0100 Subject: [PATCH 2/2] chore(bolt-sidecar): fix lints --- bolt-sidecar/src/api/builder.rs | 8 +-- bolt-sidecar/src/api/commitments/spec.rs | 22 +++---- bolt-sidecar/src/api/spec.rs | 28 ++++----- bolt-sidecar/src/builder/compat.rs | 2 +- bolt-sidecar/src/builder/payload_builder.rs | 3 +- bolt-sidecar/src/builder/template.rs | 4 +- bolt-sidecar/src/client/constraints_client.rs | 39 +++++-------- bolt-sidecar/src/common.rs | 12 ++-- bolt-sidecar/src/config/chain.rs | 18 +++--- bolt-sidecar/src/config/mod.rs | 2 +- bolt-sidecar/src/driver.rs | 4 +- bolt-sidecar/src/primitives/commitment.rs | 8 +-- bolt-sidecar/src/primitives/mod.rs | 28 ++++----- bolt-sidecar/src/primitives/transaction.rs | 58 +++++++++---------- bolt-sidecar/src/signer/mod.rs | 6 +- bolt-sidecar/src/state/consensus.rs | 2 +- bolt-sidecar/src/state/execution.rs | 46 +++++++-------- 17 files changed, 140 insertions(+), 150 deletions(-) diff --git a/bolt-sidecar/src/api/builder.rs b/bolt-sidecar/src/api/builder.rs index d5eab4e81..96044f5c0 100644 --- a/bolt-sidecar/src/api/builder.rs +++ b/bolt-sidecar/src/api/builder.rs @@ -69,7 +69,7 @@ where } /// Gets the status. Just forwards the request to constraints client and returns the status. - pub async fn status(State(server): State>>) -> StatusCode { + pub async fn status(State(server): State>) -> StatusCode { let start = std::time::Instant::now(); debug!("Received status request"); @@ -92,7 +92,7 @@ where /// /// TODO: intercept this to register Bolt validators on-chain as well. pub async fn register_validators( - State(server): State>>, + State(server): State>, Json(registrations): Json>, ) -> Result { debug!("Received register validators request"); @@ -106,7 +106,7 @@ where /// In case of a builder or relay failure, we return the locally built block header /// and store the actual payload so we can return it later. pub async fn get_header( - State(server): State>>, + State(server): State>, Path(params): Path, ) -> Result>, BuilderApiError> { let start = std::time::Instant::now(); @@ -171,7 +171,7 @@ where /// Gets the payload. If we have a locally built payload, we return it. /// Otherwise, we forward the request to the constraints client. pub async fn get_payload( - State(server): State>>, + State(server): State>, req: Request, ) -> Result, BuilderApiError> { let start = std::time::Instant::now(); diff --git a/bolt-sidecar/src/api/commitments/spec.rs b/bolt-sidecar/src/api/commitments/spec.rs index 49e8fb618..31478abdd 100644 --- a/bolt-sidecar/src/api/commitments/spec.rs +++ b/bolt-sidecar/src/api/commitments/spec.rs @@ -60,48 +60,48 @@ pub enum CommitmentError { impl IntoResponse for CommitmentError { fn into_response(self) -> axum::http::Response { match self { - CommitmentError::Rejected(err) => { + Self::Rejected(err) => { (StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32000, err.to_string()))) .into_response() } - CommitmentError::Duplicate => { + Self::Duplicate => { (StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32001, self.to_string()))) .into_response() } - CommitmentError::Internal => ( + Self::Internal => ( StatusCode::INTERNAL_SERVER_ERROR, Json(JsonResponse::from_error(-32002, self.to_string())), ) .into_response(), - CommitmentError::NoSignature => { + Self::NoSignature => { (StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32003, self.to_string()))) .into_response() } - CommitmentError::InvalidSignature(err) => { + Self::InvalidSignature(err) => { (StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32004, err.to_string()))) .into_response() } - CommitmentError::Signature(err) => { + Self::Signature(err) => { (StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32005, err.to_string()))) .into_response() } - CommitmentError::Consensus(err) => { + Self::Consensus(err) => { (StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32006, err.to_string()))) .into_response() } - CommitmentError::Validation(err) => { + Self::Validation(err) => { (StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32006, err.to_string()))) .into_response() } - CommitmentError::MalformedHeader => { + Self::MalformedHeader => { (StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32007, self.to_string()))) .into_response() } - CommitmentError::UnknownMethod => { + Self::UnknownMethod => { (StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32601, self.to_string()))) .into_response() } - CommitmentError::InvalidJson(err) => ( + Self::InvalidJson(err) => ( StatusCode::BAD_REQUEST, Json(JsonResponse::from_error(-32600, format!("Invalid request: {err}"))), ) diff --git a/bolt-sidecar/src/api/spec.rs b/bolt-sidecar/src/api/spec.rs index d21695715..3f9249e38 100644 --- a/bolt-sidecar/src/api/spec.rs +++ b/bolt-sidecar/src/api/spec.rs @@ -84,50 +84,50 @@ pub enum BuilderApiError { impl IntoResponse for BuilderApiError { fn into_response(self) -> Response { match self { - BuilderApiError::FailedRegisteringValidators(error) => { + Self::FailedRegisteringValidators(error) => { (StatusCode::from_u16(error.code).unwrap(), Json(error)).into_response() } - BuilderApiError::FailedGettingHeader(error) => { + Self::FailedGettingHeader(error) => { (StatusCode::from_u16(error.code).unwrap(), Json(error)).into_response() } - BuilderApiError::FailedGettingPayload(error) => { + Self::FailedGettingPayload(error) => { (StatusCode::from_u16(error.code).unwrap(), Json(error)).into_response() } - BuilderApiError::FailedSubmittingConstraints(error) => { + Self::FailedSubmittingConstraints(error) => { (StatusCode::from_u16(error.code).unwrap(), Json(error)).into_response() } - BuilderApiError::FailedDelegating(error) => { + Self::FailedDelegating(error) => { (StatusCode::from_u16(error.code).unwrap(), Json(error)).into_response() } - BuilderApiError::FailedRevoking(error) => { + Self::FailedRevoking(error) => { (StatusCode::from_u16(error.code).unwrap(), Json(error)).into_response() } - BuilderApiError::AxumError(err) => { + Self::AxumError(err) => { (StatusCode::BAD_REQUEST, err.to_string()).into_response() } - BuilderApiError::JsonError(err) => { + Self::JsonError(err) => { (StatusCode::BAD_REQUEST, err.to_string()).into_response() } - BuilderApiError::FailedToFetchLocalPayload(_) => { + Self::FailedToFetchLocalPayload(_) => { (StatusCode::NO_CONTENT, self.to_string()).into_response() } - BuilderApiError::ReqwestError(_) => ( + Self::ReqwestError(_) => ( StatusCode::INTERNAL_SERVER_ERROR, StatusCode::INTERNAL_SERVER_ERROR.canonical_reason().unwrap(), ) .into_response(), - BuilderApiError::Timeout(_) => ( + Self::Timeout(_) => ( StatusCode::GATEWAY_TIMEOUT, StatusCode::GATEWAY_TIMEOUT.canonical_reason().unwrap(), ) .into_response(), - BuilderApiError::InvalidFork(err) => { + Self::InvalidFork(err) => { (StatusCode::BAD_REQUEST, Json(err)).into_response() } - BuilderApiError::LocalPayloadIntegrity(err) => { + Self::LocalPayloadIntegrity(err) => { (StatusCode::BAD_REQUEST, err.to_string()).into_response() } - BuilderApiError::Generic(err) => { + Self::Generic(err) => { (StatusCode::INTERNAL_SERVER_ERROR, Json(err)).into_response() } } diff --git a/bolt-sidecar/src/builder/compat.rs b/bolt-sidecar/src/builder/compat.rs index 63a946785..e3157728c 100644 --- a/bolt-sidecar/src/builder/compat.rs +++ b/bolt-sidecar/src/builder/compat.rs @@ -46,7 +46,7 @@ pub(crate) fn to_execution_payload_header( List::default(); if let Some(withdrawals) = sealed_block.body.withdrawals.as_ref() { - for w in withdrawals.iter() { + for w in withdrawals { withdrawals_ssz.push(to_consensus_withdrawal(w)); } } diff --git a/bolt-sidecar/src/builder/payload_builder.rs b/bolt-sidecar/src/builder/payload_builder.rs index 09b380708..00e15d6fd 100644 --- a/bolt-sidecar/src/builder/payload_builder.rs +++ b/bolt-sidecar/src/builder/payload_builder.rs @@ -329,9 +329,8 @@ impl EngineHinter { // payload response or an error message that we can't parse. if raw_hint.contains("\"status\":\"VALID\"") { return Ok(EngineApiHint::ValidPayload); - } else { - return Err(BuilderError::InvalidEngineHint(raw_hint)); } + return Err(BuilderError::InvalidEngineHint(raw_hint)); }; trace!("raw hint: {:?}", raw_hint); diff --git a/bolt-sidecar/src/builder/template.rs b/bolt-sidecar/src/builder/template.rs index 9ac7d6407..bf86ed84b 100644 --- a/bolt-sidecar/src/builder/template.rs +++ b/bolt-sidecar/src/builder/template.rs @@ -121,7 +121,7 @@ impl BlockTemplate { /// Adds a list of constraints to the block template and updates the state diff. pub fn add_constraints(&mut self, constraints: SignedConstraints) { - for constraint in constraints.message.transactions.iter() { + for constraint in &constraints.message.transactions { let max_cost = max_transaction_cost(constraint); self.state_diff .diffs @@ -140,7 +140,7 @@ impl BlockTemplate { fn remove_constraints_at_index(&mut self, index: usize) { let constraints = self.signed_constraints_list.remove(index); - for constraint in constraints.message.transactions.iter() { + for constraint in &constraints.message.transactions { self.state_diff .diffs .entry(*constraint.sender().expect("recovered sender")) diff --git a/bolt-sidecar/src/client/constraints_client.rs b/bolt-sidecar/src/client/constraints_client.rs index 9df26cbb9..efefe3b58 100644 --- a/bolt-sidecar/src/client/constraints_client.rs +++ b/bolt-sidecar/src/client/constraints_client.rs @@ -64,18 +64,10 @@ impl ConstraintsClient { if delegatees.is_empty() { if available_pubkeys.contains(&validator_pubkey) { return Some(validator_pubkey); - } else { - return None; - } - } else { - for delegatee in delegatees { - if available_pubkeys.contains(&delegatee) { - return Some(delegatee); - } } + return None; } - - None + delegatees.into_iter().find(|delegatee| available_pubkeys.contains(delegatee)) } /// Finds all delegations for the given validator public key. @@ -137,20 +129,19 @@ impl BuilderApi for ConstraintsClient { // registrations to the relay if self.delegations.is_empty() { return Ok(()); - } else { - let validator_pubkeys = - registrations.iter().map(|r| &r.message.public_key).collect::>(); - - let filtered_delegations = self - .delegations - .iter() - .filter(|d| validator_pubkeys.contains(&d.message.validator_pubkey)) - .cloned() - .collect::>(); - - if let Err(err) = self.delegate(&filtered_delegations).await { - error!(?err, "Failed to propagate delegations during validator registration"); - } + } + let validator_pubkeys = + registrations.iter().map(|r| &r.message.public_key).collect::>(); + + let filtered_delegations = self + .delegations + .iter() + .filter(|d| validator_pubkeys.contains(&d.message.validator_pubkey)) + .cloned() + .collect::>(); + + if let Err(err) = self.delegate(&filtered_delegations).await { + error!(?err, "Failed to propagate delegations during validator registration"); } Ok(()) diff --git a/bolt-sidecar/src/common.rs b/bolt-sidecar/src/common.rs index a37218839..0bfa6dbcc 100644 --- a/bolt-sidecar/src/common.rs +++ b/bolt-sidecar/src/common.rs @@ -118,12 +118,12 @@ impl BlsSecretKeyWrapper { } impl<'de> Deserialize<'de> for BlsSecretKeyWrapper { - fn deserialize(deserializer: D) -> Result + fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { let sk = String::deserialize(deserializer)?; - Ok(BlsSecretKeyWrapper::from(sk.as_str())) + Ok(Self::from(sk.as_str())) } } @@ -131,7 +131,7 @@ impl From<&str> for BlsSecretKeyWrapper { fn from(sk: &str) -> Self { let hex_sk = sk.strip_prefix("0x").unwrap_or(sk); let sk = SecretKey::from_bytes(&hex::decode(hex_sk).expect("valid hex")).expect("valid sk"); - BlsSecretKeyWrapper(sk) + Self(sk) } } @@ -160,12 +160,12 @@ impl EcdsaSecretKeyWrapper { } impl<'de> Deserialize<'de> for EcdsaSecretKeyWrapper { - fn deserialize(deserializer: D) -> Result + fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { let sk = String::deserialize(deserializer)?; - Ok(EcdsaSecretKeyWrapper::from(sk.as_str())) + Ok(Self::from(sk.as_str())) } } @@ -174,7 +174,7 @@ impl From<&str> for EcdsaSecretKeyWrapper { let hex_sk = sk.strip_prefix("0x").unwrap_or(sk); let bytes = hex::decode(hex_sk).expect("valid hex"); let sk = SigningKey::from_slice(&bytes).expect("valid sk"); - EcdsaSecretKeyWrapper(sk) + Self(sk) } } diff --git a/bolt-sidecar/src/config/chain.rs b/bolt-sidecar/src/config/chain.rs index 0a75fc9a1..cd935c932 100644 --- a/bolt-sidecar/src/config/chain.rs +++ b/bolt-sidecar/src/config/chain.rs @@ -100,27 +100,27 @@ impl Chain { /// Get the chain name for the given chain. pub fn name(&self) -> &'static str { match self { - Chain::Mainnet => "mainnet", - Chain::Holesky => "holesky", - Chain::Helder => "helder", - Chain::Kurtosis => "kurtosis", + Self::Mainnet => "mainnet", + Self::Holesky => "holesky", + Self::Helder => "helder", + Self::Kurtosis => "kurtosis", } } /// Get the fork version for the given chain. pub fn fork_version(&self) -> [u8; 4] { match self { - Chain::Mainnet => [0, 0, 0, 0], - Chain::Holesky => [1, 1, 112, 0], - Chain::Helder => [16, 0, 0, 0], - Chain::Kurtosis => [16, 0, 0, 56], + Self::Mainnet => [0, 0, 0, 0], + Self::Holesky => [1, 1, 112, 0], + Self::Helder => [16, 0, 0, 0], + Self::Kurtosis => [16, 0, 0, 56], } } /// Returns the address of the canonical BoltManager contract for a given chain, if present pub const fn manager_address(&self) -> Option
{ match self { - Chain::Holesky => Some(MANAGER_ADDRESS_HOLESKY), + Self::Holesky => Some(MANAGER_ADDRESS_HOLESKY), _ => None, } } diff --git a/bolt-sidecar/src/config/mod.rs b/bolt-sidecar/src/config/mod.rs index 001048358..c349dd577 100644 --- a/bolt-sidecar/src/config/mod.rs +++ b/bolt-sidecar/src/config/mod.rs @@ -118,7 +118,7 @@ impl Opts { pub fn try_parse() -> eyre::Result { read_env_file()?; - Ok(Opts::parse()) + Ok(Self::parse()) } } diff --git a/bolt-sidecar/src/driver.rs b/bolt-sidecar/src/driver.rs index 1badeb106..5839557e0 100644 --- a/bolt-sidecar/src/driver.rs +++ b/bolt-sidecar/src/driver.rs @@ -231,7 +231,7 @@ impl SidecarDriver { let unsafe_skip_consensus_checks = opts.unsafe_disable_consensus_checks; - Ok(SidecarDriver { + Ok(Self { unsafe_skip_consensus_checks, head_tracker, execution, @@ -342,7 +342,7 @@ impl SidecarDriver { // // For more information, check out the constraints API docs: // https://docs.boltprotocol.xyz/technical-docs/api/builder#constraints - for tx in inclusion_request.txs.iter() { + for tx in &inclusion_request.txs { let tx_type = tx.tx_type(); let message = ConstraintsMessage::from_tx(signing_pubkey.clone(), target_slot, tx.clone()); diff --git a/bolt-sidecar/src/primitives/commitment.rs b/bolt-sidecar/src/primitives/commitment.rs index 96c4a48df..b5ffbe540 100644 --- a/bolt-sidecar/src/primitives/commitment.rs +++ b/bolt-sidecar/src/primitives/commitment.rs @@ -52,7 +52,7 @@ impl CommitmentRequest { /// Returns a reference to the inner request if this is an inclusion request, otherwise `None`. pub fn as_inclusion_request(&self) -> Option<&InclusionRequest> { match self { - CommitmentRequest::Inclusion(req) => Some(req), + Self::Inclusion(req) => Some(req), } } @@ -62,7 +62,7 @@ impl CommitmentRequest { signer: &S, ) -> eyre::Result { match self { - CommitmentRequest::Inclusion(req) => { + Self::Inclusion(req) => { req.commit_and_sign(signer).await.map(SignedCommitment::Inclusion) } } @@ -71,7 +71,7 @@ impl CommitmentRequest { /// Returns the signature (if signed). pub fn signature(&self) -> Option<&Signature> { match self { - CommitmentRequest::Inclusion(req) => req.signature.as_ref(), + Self::Inclusion(req) => req.signature.as_ref(), } } } @@ -245,7 +245,7 @@ impl InclusionRequest { impl From for CommitmentRequest { fn from(req: InclusionRequest) -> Self { - CommitmentRequest::Inclusion(req) + Self::Inclusion(req) } } diff --git a/bolt-sidecar/src/primitives/mod.rs b/bolt-sidecar/src/primitives/mod.rs index c7cfe5f4a..60c006d70 100644 --- a/bolt-sidecar/src/primitives/mod.rs +++ b/bolt-sidecar/src/primitives/mod.rs @@ -158,20 +158,20 @@ impl GetPayloadResponse { /// Returns the block hash of the payload pub fn block_hash(&self) -> &Hash32 { match self { - GetPayloadResponse::Capella(payload) => payload.block_hash(), - GetPayloadResponse::Bellatrix(payload) => payload.block_hash(), - GetPayloadResponse::Deneb(payload) => payload.execution_payload.block_hash(), - GetPayloadResponse::Electra(payload) => payload.execution_payload.block_hash(), + Self::Capella(payload) => payload.block_hash(), + Self::Bellatrix(payload) => payload.block_hash(), + Self::Deneb(payload) => payload.execution_payload.block_hash(), + Self::Electra(payload) => payload.execution_payload.block_hash(), } } /// Returns the execution payload pub fn execution_payload(&self) -> &ExecutionPayload { match self { - GetPayloadResponse::Capella(payload) => payload, - GetPayloadResponse::Bellatrix(payload) => payload, - GetPayloadResponse::Deneb(payload) => &payload.execution_payload, - GetPayloadResponse::Electra(payload) => &payload.execution_payload, + Self::Capella(payload) => payload, + Self::Bellatrix(payload) => payload, + Self::Deneb(payload) => &payload.execution_payload, + Self::Electra(payload) => &payload.execution_payload, } } } @@ -179,12 +179,12 @@ impl GetPayloadResponse { impl From for GetPayloadResponse { fn from(payload_and_blobs: PayloadAndBlobs) -> Self { match payload_and_blobs.execution_payload.version() { - Fork::Phase0 => GetPayloadResponse::Capella(payload_and_blobs.execution_payload), - Fork::Altair => GetPayloadResponse::Capella(payload_and_blobs.execution_payload), - Fork::Capella => GetPayloadResponse::Capella(payload_and_blobs.execution_payload), - Fork::Bellatrix => GetPayloadResponse::Bellatrix(payload_and_blobs.execution_payload), - Fork::Deneb => GetPayloadResponse::Deneb(payload_and_blobs), - Fork::Electra => GetPayloadResponse::Electra(payload_and_blobs), + Fork::Phase0 => Self::Capella(payload_and_blobs.execution_payload), + Fork::Altair => Self::Capella(payload_and_blobs.execution_payload), + Fork::Capella => Self::Capella(payload_and_blobs.execution_payload), + Fork::Bellatrix => Self::Bellatrix(payload_and_blobs.execution_payload), + Fork::Deneb => Self::Deneb(payload_and_blobs), + Fork::Electra => Self::Electra(payload_and_blobs), } } } diff --git a/bolt-sidecar/src/primitives/transaction.rs b/bolt-sidecar/src/primitives/transaction.rs index 20e4a48ca..5ced1e7b4 100644 --- a/bolt-sidecar/src/primitives/transaction.rs +++ b/bolt-sidecar/src/primitives/transaction.rs @@ -40,40 +40,40 @@ pub trait TransactionExt { impl TransactionExt for PooledTransactionsElement { fn gas_limit(&self) -> u64 { match self { - PooledTransactionsElement::Legacy { transaction, .. } => transaction.gas_limit, - PooledTransactionsElement::Eip2930 { transaction, .. } => transaction.gas_limit, - PooledTransactionsElement::Eip1559 { transaction, .. } => transaction.gas_limit, - PooledTransactionsElement::BlobTransaction(blob_tx) => blob_tx.transaction.tx.gas_limit, + Self::Legacy { transaction, .. } => transaction.gas_limit, + Self::Eip2930 { transaction, .. } => transaction.gas_limit, + Self::Eip1559 { transaction, .. } => transaction.gas_limit, + Self::BlobTransaction(blob_tx) => blob_tx.transaction.tx.gas_limit, _ => unimplemented!(), } } fn value(&self) -> U256 { match self { - PooledTransactionsElement::Legacy { transaction, .. } => transaction.value, - PooledTransactionsElement::Eip2930 { transaction, .. } => transaction.value, - PooledTransactionsElement::Eip1559 { transaction, .. } => transaction.value, - PooledTransactionsElement::BlobTransaction(blob_tx) => blob_tx.transaction.tx.value, + Self::Legacy { transaction, .. } => transaction.value, + Self::Eip2930 { transaction, .. } => transaction.value, + Self::Eip1559 { transaction, .. } => transaction.value, + Self::BlobTransaction(blob_tx) => blob_tx.transaction.tx.value, _ => unimplemented!(), } } fn tx_type(&self) -> TxType { match self { - PooledTransactionsElement::Legacy { .. } => TxType::Legacy, - PooledTransactionsElement::Eip2930 { .. } => TxType::Eip2930, - PooledTransactionsElement::Eip1559 { .. } => TxType::Eip1559, - PooledTransactionsElement::BlobTransaction(_) => TxType::Eip4844, + Self::Legacy { .. } => TxType::Legacy, + Self::Eip2930 { .. } => TxType::Eip2930, + Self::Eip1559 { .. } => TxType::Eip1559, + Self::BlobTransaction(_) => TxType::Eip4844, _ => unimplemented!(), } } fn tx_kind(&self) -> TxKind { match self { - PooledTransactionsElement::Legacy { transaction, .. } => transaction.to, - PooledTransactionsElement::Eip2930 { transaction, .. } => transaction.to, - PooledTransactionsElement::Eip1559 { transaction, .. } => transaction.to, - PooledTransactionsElement::BlobTransaction(blob_tx) => { + Self::Legacy { transaction, .. } => transaction.to, + Self::Eip2930 { transaction, .. } => transaction.to, + Self::Eip1559 { transaction, .. } => transaction.to, + Self::BlobTransaction(blob_tx) => { TxKind::Call(blob_tx.transaction.tx.to) } _ => unimplemented!(), @@ -82,20 +82,20 @@ impl TransactionExt for PooledTransactionsElement { fn input(&self) -> &Bytes { match self { - PooledTransactionsElement::Legacy { transaction, .. } => &transaction.input, - PooledTransactionsElement::Eip2930 { transaction, .. } => &transaction.input, - PooledTransactionsElement::Eip1559 { transaction, .. } => &transaction.input, - PooledTransactionsElement::BlobTransaction(blob_tx) => &blob_tx.transaction.tx.input, + Self::Legacy { transaction, .. } => &transaction.input, + Self::Eip2930 { transaction, .. } => &transaction.input, + Self::Eip1559 { transaction, .. } => &transaction.input, + Self::BlobTransaction(blob_tx) => &blob_tx.transaction.tx.input, _ => unimplemented!(), } } fn chain_id(&self) -> Option { match self { - PooledTransactionsElement::Legacy { transaction, .. } => transaction.chain_id, - PooledTransactionsElement::Eip2930 { transaction, .. } => Some(transaction.chain_id), - PooledTransactionsElement::Eip1559 { transaction, .. } => Some(transaction.chain_id), - PooledTransactionsElement::BlobTransaction(blob_tx) => { + Self::Legacy { transaction, .. } => transaction.chain_id, + Self::Eip2930 { transaction, .. } => Some(transaction.chain_id), + Self::Eip1559 { transaction, .. } => Some(transaction.chain_id), + Self::BlobTransaction(blob_tx) => { Some(blob_tx.transaction.tx.chain_id) } _ => unimplemented!(), @@ -104,7 +104,7 @@ impl TransactionExt for PooledTransactionsElement { fn blob_sidecar(&self) -> Option<&BlobTransactionSidecar> { match self { - PooledTransactionsElement::BlobTransaction(blob_tx) => { + Self::BlobTransaction(blob_tx) => { Some(&blob_tx.transaction.sidecar) } _ => None, @@ -113,10 +113,10 @@ impl TransactionExt for PooledTransactionsElement { fn size(&self) -> usize { match self { - PooledTransactionsElement::Legacy { transaction, .. } => transaction.size(), - PooledTransactionsElement::Eip2930 { transaction, .. } => transaction.size(), - PooledTransactionsElement::Eip1559 { transaction, .. } => transaction.size(), - PooledTransactionsElement::BlobTransaction(blob_tx) => blob_tx.transaction.tx.size(), + Self::Legacy { transaction, .. } => transaction.size(), + Self::Eip2930 { transaction, .. } => transaction.size(), + Self::Eip1559 { transaction, .. } => transaction.size(), + Self::BlobTransaction(blob_tx) => blob_tx.transaction.tx.size(), _ => unimplemented!(), } } diff --git a/bolt-sidecar/src/signer/mod.rs b/bolt-sidecar/src/signer/mod.rs index 5584addbd..c6663d262 100644 --- a/bolt-sidecar/src/signer/mod.rs +++ b/bolt-sidecar/src/signer/mod.rs @@ -44,9 +44,9 @@ impl SignerBLS { /// Returns all the public keys available for signing. pub fn available_pubkeys(&self) -> HashSet { match self { - SignerBLS::Local(signer) => [signer.pubkey()].into(), - SignerBLS::CommitBoost(signer) => [signer.pubkey()].into(), - SignerBLS::Keystore(signer) => signer.pubkeys(), + Self::Local(signer) => [signer.pubkey()].into(), + Self::CommitBoost(signer) => [signer.pubkey()].into(), + Self::Keystore(signer) => signer.pubkeys(), } } } diff --git a/bolt-sidecar/src/state/consensus.rs b/bolt-sidecar/src/state/consensus.rs index e2d215167..4d5601381 100644 --- a/bolt-sidecar/src/state/consensus.rs +++ b/bolt-sidecar/src/state/consensus.rs @@ -94,7 +94,7 @@ impl ConsensusState { commitment_deadline_duration: Duration, unsafe_lookahead_enabled: bool, ) -> Self { - ConsensusState { + Self { beacon_api_client, epoch: Epoch::default(), latest_slot: Default::default(), diff --git a/bolt-sidecar/src/state/execution.rs b/bolt-sidecar/src/state/execution.rs index 858311d45..f139204d8 100644 --- a/bolt-sidecar/src/state/execution.rs +++ b/bolt-sidecar/src/state/execution.rs @@ -95,30 +95,30 @@ impl ValidationError { /// Returns the tag of the enum as a string, mainly for metrics purposes pub const fn to_tag_str(&self) -> &'static str { match self { - ValidationError::BaseFeeTooLow(_) => "base_fee_too_low", - ValidationError::BlobBaseFeeTooLow(_) => "blob_base_fee_too_low", - ValidationError::BlobValidation(_) => "blob_validation", - ValidationError::MaxBaseFeeCalcOverflow => "max_base_fee_calc_overflow", - ValidationError::NonceTooLow(_, _) => "nonce_too_low", - ValidationError::NonceTooHigh(_, _) => "nonce_too_high", - ValidationError::AccountHasCode => "account_has_code", - ValidationError::GasLimitTooHigh => "gas_limit_too_high", - ValidationError::TransactionSizeTooHigh => "transaction_size_too_high", - ValidationError::MaxPriorityFeePerGasTooHigh => "max_priority_fee_per_gas_too_high", - ValidationError::MaxPriorityFeePerGasTooLow => "max_priority_fee_per_gas_too_low", - ValidationError::InsufficientBalance => "insufficient_balance", - ValidationError::Eip4844Limit => "eip4844_limit", - ValidationError::SlotTooLow(_) => "slot_too_low", - ValidationError::MaxCommitmentsReachedForSlot(_, _) => { + Self::BaseFeeTooLow(_) => "base_fee_too_low", + Self::BlobBaseFeeTooLow(_) => "blob_base_fee_too_low", + Self::BlobValidation(_) => "blob_validation", + Self::MaxBaseFeeCalcOverflow => "max_base_fee_calc_overflow", + Self::NonceTooLow(_, _) => "nonce_too_low", + Self::NonceTooHigh(_, _) => "nonce_too_high", + Self::AccountHasCode => "account_has_code", + Self::GasLimitTooHigh => "gas_limit_too_high", + Self::TransactionSizeTooHigh => "transaction_size_too_high", + Self::MaxPriorityFeePerGasTooHigh => "max_priority_fee_per_gas_too_high", + Self::MaxPriorityFeePerGasTooLow => "max_priority_fee_per_gas_too_low", + Self::InsufficientBalance => "insufficient_balance", + Self::Eip4844Limit => "eip4844_limit", + Self::SlotTooLow(_) => "slot_too_low", + Self::MaxCommitmentsReachedForSlot(_, _) => { "max_commitments_reached_for_slot" } - ValidationError::MaxCommittedGasReachedForSlot(_, _) => { + Self::MaxCommittedGasReachedForSlot(_, _) => { "max_committed_gas_reached_for_slot" } - ValidationError::Signature(_) => "signature", - ValidationError::RecoverSigner => "recover_signer", - ValidationError::ChainIdMismatch => "chain_id_mismatch", - ValidationError::Internal(_) => "internal", + Self::Signature(_) => "signature", + Self::RecoverSigner => "recover_signer", + Self::ChainIdMismatch => "chain_id_mismatch", + Self::Internal(_) => "internal", } } } @@ -316,7 +316,7 @@ impl ExecutionState { // and balance diffs that will be applied to the account state. let mut bundle_nonce_diff_map = HashMap::new(); let mut bundle_balance_diff_map = HashMap::new(); - for tx in req.txs.iter() { + for tx in &req.txs { let sender = tx.sender().expect("Recovered sender"); // From previous preconfirmations requests retrieve @@ -513,10 +513,10 @@ impl ExecutionState { /// transactions by checking the nonce and balance of the account after applying the state /// diffs. fn refresh_templates(&mut self) { - for (address, account_state) in self.account_states.iter_mut() { + for (address, account_state) in &mut self.account_states { trace!(%address, ?account_state, "Refreshing template..."); // Iterate over all block templates and apply the state diff - for (_, template) in self.block_templates.iter_mut() { + for template in self.block_templates.values_mut() { // Retain only signed constraints where transactions are still valid based on the // canonical account states. template.retain(*address, *account_state);