From 95ef497e7b2fa21e3a3bb8e1f6d2642729af1b5e Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 25 Sep 2021 11:26:54 +1000 Subject: [PATCH] Fix clippy lints --- Cargo.lock | 1 + beacon_node/execution_layer/Cargo.toml | 1 + beacon_node/execution_layer/src/engine_api.rs | 4 +- .../execution_layer/src/engine_api/http.rs | 39 ++++++++++++++++--- beacon_node/execution_layer/src/lib.rs | 8 ---- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eee1147c84..74ae8d1720 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2072,6 +2072,7 @@ dependencies = [ "eth1", "eth2_serde_utils 0.1.0", "futures", + "hex", "reqwest", "sensitive_url", "serde", diff --git a/beacon_node/execution_layer/Cargo.toml b/beacon_node/execution_layer/Cargo.toml index 9e80a553ed..d04f7a7296 100644 --- a/beacon_node/execution_layer/Cargo.toml +++ b/beacon_node/execution_layer/Cargo.toml @@ -21,3 +21,4 @@ warp = { git = "https://github.com/paulhauner/warp ", branch = "cors-wildcard" } environment = { path = "../../lighthouse/environment" } bytes = "1.1.0" task_executor = { path = "../../common/task_executor" } +hex = "0.4.2" diff --git a/beacon_node/execution_layer/src/engine_api.rs b/beacon_node/execution_layer/src/engine_api.rs index 2892d62412..b1fd72deea 100644 --- a/beacon_node/execution_layer/src/engine_api.rs +++ b/beacon_node/execution_layer/src/engine_api.rs @@ -16,8 +16,8 @@ pub enum Error { JsonRpc(RpcError), Json(serde_json::Error), ServerMessage(String), - Eip155Error, - NoResultOrError, + Eip155Failure, + NoErrorOrResult, IsSyncing, } diff --git a/beacon_node/execution_layer/src/engine_api/http.rs b/beacon_node/execution_layer/src/engine_api/http.rs index c7674a882c..8c7cec59f6 100644 --- a/beacon_node/execution_layer/src/engine_api/http.rs +++ b/beacon_node/execution_layer/src/engine_api/http.rs @@ -7,7 +7,7 @@ use sensitive_url::SensitiveUrl; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde_json::json; use std::time::Duration; -use types::{execution_payload::serde_logs_bloom, EthSpec, FixedVector, Transaction, VariableList}; +use types::{EthSpec, FixedVector, Transaction, Unsigned, VariableList}; const STATIC_ID: u32 = 1; const JSONRPC_VERSION: &str = "2.0"; @@ -51,7 +51,7 @@ impl HttpJsonRpc { ) -> Result { let body = JsonRequestBody { jsonrpc: JSONRPC_VERSION, - method: method, + method, params, id: STATIC_ID, }; @@ -72,12 +72,12 @@ impl HttpJsonRpc { (Some(result), None) => serde_json::from_value(result).map_err(Into::into), (_, Some(error)) => { if error.contains(EIP155_ERROR_STR) { - Err(Error::Eip155Error) + Err(Error::Eip155Failure) } else { Err(Error::ServerMessage(error)) } } - (None, None) => Err(Error::NoResultOrError), + (None, None) => Err(Error::NoErrorOrResult), } } } @@ -300,6 +300,35 @@ struct JsonForkChoiceUpdatedRequest { finalized_block_hash: Hash256, } +// Serializes the `logs_bloom` field. +pub mod serde_logs_bloom { + use super::*; + use eth2_serde_utils::hex::PrefixedHexVisitor; + use serde::{Deserializer, Serializer}; + + pub fn serialize(bytes: &FixedVector, serializer: S) -> Result + where + S: Serializer, + U: Unsigned, + { + let mut hex_string: String = "0x".to_string(); + hex_string.push_str(&hex::encode(&bytes[..])); + + serializer.serialize_str(&hex_string) + } + + pub fn deserialize<'de, D, U>(deserializer: D) -> Result, D::Error> + where + D: Deserializer<'de>, + U: Unsigned, + { + let vec = deserializer.deserialize_string(PrefixedHexVisitor)?; + + FixedVector::new(vec) + .map_err(|e| serde::de::Error::custom(format!("invalid logs bloom: {:?}", e))) + } +} + #[cfg(test)] mod test { use super::*; @@ -414,7 +443,7 @@ mod test { coinbase: Address::repeat_byte(1), state_root: Hash256::repeat_byte(1), receipt_root: Hash256::repeat_byte(0), - logs_bloom: vec![01; 256].into(), + logs_bloom: vec![1; 256].into(), random: Hash256::repeat_byte(1), block_number: 0, gas_limit: 1, diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index 4c5fe547a8..44935ccc17 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -68,11 +68,3 @@ impl ExecutionLayer { .map_err(Error::EngineErrors) } } - -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -}