diff --git a/common/src/errors.rs b/common/src/errors.rs index 3f275ba..b5b8e52 100644 --- a/common/src/errors.rs +++ b/common/src/errors.rs @@ -15,13 +15,17 @@ impl BlockNotFoundError { } #[derive(Debug, Error)] -#[error("rpc error: {message}")] +#[error("rpc error on method: {method}, message: {message}")] pub struct RpcError { + method: String, message: String, } impl RpcError { - pub fn new(message: String) -> Self { - Self { message } + pub fn new(method: &str, err: E) -> Self { + Self { + method: method.to_string(), + message: err.to_string(), + } } } diff --git a/config/src/networks.rs b/config/src/networks.rs index 060e6a2..2c8a022 100644 --- a/config/src/networks.rs +++ b/config/src/networks.rs @@ -18,7 +18,7 @@ pub struct BaseConfig { pub fn mainnet() -> BaseConfig { BaseConfig { checkpoint: hex_str_to_bytes( - "0x5ca31c7c795d8f2de2e844718cdb08835639c644365427b9f20f82083e7dac9a", + "0xb0fe0394e2ed1a96b758b67fad1942371db5f7070502d10937fa65dacfc2ea4b", ) .unwrap(), rpc_port: 8545, diff --git a/consensus/src/rpc/nimbus_rpc.rs b/consensus/src/rpc/nimbus_rpc.rs index 4594f5e..9ea968c 100644 --- a/consensus/src/rpc/nimbus_rpc.rs +++ b/consensus/src/rpc/nimbus_rpc.rs @@ -20,56 +20,56 @@ impl Rpc for NimbusRpc { async fn get_bootstrap(&self, block_root: &Vec) -> Result { let root_hex = hex::encode(block_root); let req = format!( - "{}/eth/v0/beacon/light_client/bootstrap/0x{}", + "{}/eth/v1/beacon/light_client/bootstrap/0x{}", self.rpc, root_hex ); let res = reqwest::get(req) .await - .map_err(|e| RpcError::new(e.to_string()))? + .map_err(|e| RpcError::new("bootstrap", e))? .json::() .await - .map_err(|e| RpcError::new(e.to_string()))?; + .map_err(|e| RpcError::new("bootstrap", e))?; - Ok(res.data.v) + Ok(res.data) } async fn get_updates(&self, period: u64) -> Result> { let req = format!( - "{}/eth/v0/beacon/light_client/updates?start_period={}&count=1000", + "{}/eth/v1/beacon/light_client/updates?start_period={}&count=1000", self.rpc, period ); let res = reqwest::get(req) .await - .map_err(|e| RpcError::new(e.to_string()))? + .map_err(|e| RpcError::new("updates", e))? .json::() .await - .map_err(|e| RpcError::new(e.to_string()))?; + .map_err(|e| RpcError::new("updates", e))?; - Ok(res.data) + Ok(res.iter().map(|d| d.data.clone()).collect()) } async fn get_finality_update(&self) -> Result { - let req = format!("{}/eth/v0/beacon/light_client/finality_update", self.rpc); + let req = format!("{}/eth/v1/beacon/light_client/finality_update", self.rpc); let res = reqwest::get(req) .await - .map_err(|e| RpcError::new(e.to_string()))? + .map_err(|e| RpcError::new("finality_update", e))? .json::() .await - .map_err(|e| RpcError::new(e.to_string()))?; + .map_err(|e| RpcError::new("finality_update", e))?; Ok(res.data) } async fn get_optimistic_update(&self) -> Result { - let req = format!("{}/eth/v0/beacon/light_client/optimistic_update", self.rpc); + let req = format!("{}/eth/v1/beacon/light_client/optimistic_update", self.rpc); let res = reqwest::get(req) .await - .map_err(|e| RpcError::new(e.to_string()))? + .map_err(|e| RpcError::new("optimistic_update", e))? .json::() .await - .map_err(|e| RpcError::new(e.to_string()))?; + .map_err(|e| RpcError::new("optimistic_update", e))?; Ok(res.data) } @@ -78,10 +78,10 @@ impl Rpc for NimbusRpc { let req = format!("{}/eth/v2/beacon/blocks/{}", self.rpc, slot); let res = reqwest::get(req) .await - .map_err(|e| RpcError::new(e.to_string()))? + .map_err(|e| RpcError::new("blocks", e))? .json::() .await - .map_err(|e| RpcError::new(e.to_string()))?; + .map_err(|e| RpcError::new("blocks", e))?; Ok(res.data.message) } @@ -97,9 +97,11 @@ struct BeaconBlockData { message: BeaconBlock, } +type UpdateResponse = Vec; + #[derive(serde::Deserialize, Debug)] -struct UpdateResponse { - data: Vec, +struct UpdateData { + data: Update, } #[derive(serde::Deserialize, Debug)] @@ -114,10 +116,5 @@ struct OptimisticUpdateResponse { #[derive(serde::Deserialize, Debug)] struct BootstrapResponse { - data: BootstrapData, -} - -#[derive(serde::Deserialize, Debug)] -struct BootstrapData { - v: Bootstrap, + data: Bootstrap, } diff --git a/execution/src/rpc/http_rpc.rs b/execution/src/rpc/http_rpc.rs index a825a5b..5ccfa3c 100644 --- a/execution/src/rpc/http_rpc.rs +++ b/execution/src/rpc/http_rpc.rs @@ -53,7 +53,7 @@ impl Rpc for HttpRpc { .provider .get_proof(*address, slots.to_vec(), block) .await - .map_err(|e| RpcError::new(e.to_string()))?; + .map_err(|e| RpcError::new("get_proof", e))?; Ok(proof_response) } @@ -78,7 +78,7 @@ impl Rpc for HttpRpc { .provider .create_access_list(&tx, block) .await - .map_err(|e| RpcError::new(e.to_string()))?; + .map_err(|e| RpcError::new("create_access_list", e))?; Ok(list.access_list) } @@ -89,7 +89,7 @@ impl Rpc for HttpRpc { .provider .get_code(*address, block) .await - .map_err(|e| RpcError::new(e.to_string()))?; + .map_err(|e| RpcError::new("get_code", e))?; Ok(code.to_vec()) } @@ -100,7 +100,7 @@ impl Rpc for HttpRpc { .provider .send_raw_transaction(bytes) .await - .map_err(|e| RpcError::new(e.to_string()))?; + .map_err(|e| RpcError::new("send_raw_transaction", e))?; Ok(tx.tx_hash()) } @@ -110,12 +110,16 @@ impl Rpc for HttpRpc { .provider .get_transaction_receipt(*tx_hash) .await - .map_err(|e| RpcError::new(e.to_string()))?; + .map_err(|e| RpcError::new("get_transaction_receipt", e))?; Ok(receipt) } async fn get_transaction(&self, tx_hash: &H256) -> Result> { - Ok(self.provider.get_transaction(*tx_hash).await?) + Ok(self + .provider + .get_transaction(*tx_hash) + .await + .map_err(|e| RpcError::new("get_transaction", e))?) } }