diff --git a/web3_proxy/src/bin/web3_proxy.rs b/web3_proxy/src/bin/web3_proxy.rs index 8f5e8216..ba43e395 100644 --- a/web3_proxy/src/bin/web3_proxy.rs +++ b/web3_proxy/src/bin/web3_proxy.rs @@ -220,6 +220,7 @@ fn main() -> anyhow::Result<()> { // tokio has code for catching ctrl+c so we use that // this shutdown sender is currently only used in tests, but we might make a /shutdown endpoint or something + // we do not need this receiver. new receivers are made by `shutdown_sender.subscribe()` let (shutdown_sender, _) = broadcast::channel(1); run(shutdown_sender, cli_config, top_config) @@ -228,13 +229,16 @@ fn main() -> anyhow::Result<()> { #[cfg(test)] mod tests { use ethers::{ - prelude::{Block, Http, Provider, TxHash, U256}, + prelude::{Http, Provider, U256}, utils::Anvil, }; use hashbrown::HashMap; use std::env; - use web3_proxy::config::{AppConfig, Web3ConnectionConfig}; + use web3_proxy::{ + config::{AppConfig, Web3ConnectionConfig}, + rpcs::blockchain::ArcBlock, + }; use super::*; @@ -329,12 +333,12 @@ mod tests { let proxy_provider = Provider::::try_from(anvil.endpoint()).unwrap(); let anvil_result = anvil_provider - .request::<_, Option>>("eth_getBlockByNumber", ("latest", true)) + .request::<_, Option>("eth_getBlockByNumber", ("latest", true)) .await .unwrap() .unwrap(); let proxy_result = proxy_provider - .request::<_, Option>>("eth_getBlockByNumber", ("latest", true)) + .request::<_, Option>("eth_getBlockByNumber", ("latest", true)) .await .unwrap() .unwrap(); @@ -349,12 +353,12 @@ mod tests { .unwrap(); let anvil_result = anvil_provider - .request::<_, Option>>("eth_getBlockByNumber", ("latest", true)) + .request::<_, Option>("eth_getBlockByNumber", ("latest", true)) .await .unwrap() .unwrap(); let proxy_result = proxy_provider - .request::<_, Option>>("eth_getBlockByNumber", ("latest", true)) + .request::<_, Option>("eth_getBlockByNumber", ("latest", true)) .await .unwrap() .unwrap(); diff --git a/web3_proxy/src/rpcs/blockchain.rs b/web3_proxy/src/rpcs/blockchain.rs index 3f0ce72e..82ee1eb3 100644 --- a/web3_proxy/src/rpcs/blockchain.rs +++ b/web3_proxy/src/rpcs/blockchain.rs @@ -101,7 +101,7 @@ impl Web3Connections { // block not in cache. we need to ask an rpc for it let get_block_params = (*hash, false); // TODO: if error, retry? - let block: Block = match rpc { + let block: ArcBlock = match rpc { Some(rpc) => { rpc.wait_for_request_handle(authorization, Duration::from_secs(30)) .await? @@ -129,8 +129,6 @@ impl Web3Connections { } }; - let block = Arc::new(block); - // the block was fetched using eth_getBlockByHash, so it should have all fields // TODO: fill in heaviest_chain! if the block is old enough, is this definitely true? self.save_block(&block, false).await?; @@ -201,9 +199,7 @@ impl Web3Connections { let raw_block = response.result.context("no block result")?; - let block: Block = serde_json::from_str(raw_block.get())?; - - let block = Arc::new(block); + let block: ArcBlock = serde_json::from_str(raw_block.get())?; // the block was fetched using eth_getBlockByNumber, so it should have all fields and be on the heaviest chain self.save_block(&block, true).await?; @@ -248,7 +244,7 @@ impl Web3Connections { } /// `connection_heads` is a mapping of rpc_names to head block hashes. - /// self.blockchain_map is a mapping of hashes to the complete Block. + /// self.blockchain_map is a mapping of hashes to the complete ArcBlock. /// TODO: return something? async fn process_block_from_rpc( &self,