diff --git a/Cargo.lock b/Cargo.lock index 5b3c7a2..98be905 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,7 +62,7 @@ dependencies = [ "getrandom 0.2.15", "once_cell", "version_check", - "zerocopy", + "zerocopy 0.7.35", ] [[package]] @@ -123,7 +123,7 @@ dependencies = [ "auto_impl", "c-kzg", "derive_more", - "rand", + "rand 0.8.5", "serde", "serde_with", ] @@ -182,7 +182,7 @@ dependencies = [ "alloy-primitives", "alloy-rlp", "arbitrary", - "rand", + "rand 0.8.5", "serde", ] @@ -197,7 +197,7 @@ dependencies = [ "arbitrary", "derive_more", "k256", - "rand", + "rand 0.8.5", "serde", "serde_with", ] @@ -323,7 +323,7 @@ dependencies = [ "paste", "proptest", "proptest-derive", - "rand", + "rand 0.8.5", "ruint", "rustc-hash 2.1.0", "serde", @@ -526,7 +526,7 @@ dependencies = [ "ethereum_ssz_derive", "jsonrpsee-types", "jsonwebtoken", - "rand", + "rand 0.8.5", "serde", "strum", ] @@ -630,7 +630,7 @@ dependencies = [ "alloy-signer", "async-trait", "k256", - "rand", + "rand 0.8.5", "thiserror 2.0.11", ] @@ -978,7 +978,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", ] [[package]] @@ -988,7 +988,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" dependencies = [ "num-traits", - "rand", + "rand 0.8.5", ] [[package]] @@ -1338,7 +1338,7 @@ dependencies = [ "once_cell", "pollster", "portable-atomic", - "rand", + "rand 0.8.5", "regress", "rustc-hash 2.1.0", "ryu-js", @@ -1941,7 +1941,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ "generic-array", - "rand_core", + "rand_core 0.6.4", "subtle", "zeroize", ] @@ -1953,7 +1953,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", - "rand_core", + "rand_core 0.6.4", "typenum", ] @@ -2252,7 +2252,7 @@ dependencies = [ "more-asserts", "multiaddr", "parking_lot", - "rand", + "rand 0.8.5", "smallvec", "socket2", "tokio", @@ -2323,7 +2323,7 @@ checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek", "ed25519", - "rand_core", + "rand_core 0.6.4", "serde", "sha2 0.10.8", "subtle", @@ -2349,7 +2349,7 @@ dependencies = [ "generic-array", "group", "pkcs8", - "rand_core", + "rand_core 0.6.4", "sec1", "serdect", "subtle", @@ -2384,7 +2384,7 @@ dependencies = [ "hex", "k256", "log", - "rand", + "rand 0.8.5", "secp256k1", "serde", "sha3", @@ -2519,7 +2519,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ - "rand_core", + "rand_core 0.6.4", "subtle", ] @@ -2548,7 +2548,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" dependencies = [ "byteorder", - "rand", + "rand 0.8.5", "rustc-hex", "static_assertions", ] @@ -2844,7 +2844,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", - "rand_core", + "rand_core 0.6.4", "subtle", ] @@ -2976,7 +2976,7 @@ dependencies = [ "idna", "ipnet", "once_cell", - "rand", + "rand 0.8.5", "serde", "thiserror 2.0.11", "tinyvec", @@ -2998,7 +2998,7 @@ dependencies = [ "moka", "once_cell", "parking_lot", - "rand", + "rand 0.8.5", "resolv-conf", "serde", "smallvec", @@ -3725,7 +3725,7 @@ dependencies = [ "jsonrpsee-types", "parking_lot", "pin-project", - "rand", + "rand 0.8.5", "rustc-hash 2.1.0", "serde", "serde_json", @@ -3985,7 +3985,7 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand", + "rand 0.8.5", "serde", "sha2 0.9.9", "typenum", @@ -4158,7 +4158,7 @@ dependencies = [ "maili-flz", "maili-genesis", "miniz_oxide", - "rand", + "rand 0.8.5", "serde", "thiserror 2.0.11", "tracing", @@ -4287,7 +4287,7 @@ dependencies = [ "hashbrown 0.15.2", "metrics", "quanta", - "rand", + "rand 0.8.5", "rand_xoshiro", "sketches-ddsketch", ] @@ -4933,7 +4933,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" dependencies = [ "phf_shared", - "rand", + "rand 0.8.5", ] [[package]] @@ -5042,7 +5042,7 @@ version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" dependencies = [ - "zerocopy", + "zerocopy 0.7.35", ] [[package]] @@ -5174,8 +5174,8 @@ dependencies = [ "bitflags 2.8.0", "lazy_static", "num-traits", - "rand", - "rand_chacha", + "rand 0.8.5", + "rand_chacha 0.3.1", "rand_xorshift", "regex-syntax 0.8.5", "rusty-fork", @@ -5250,7 +5250,7 @@ checksum = "a2fe5ef3495d7d2e377ff17b1a8ce2ee2ec2a18cde8b6ad6619d65d0701c135d" dependencies = [ "bytes", "getrandom 0.2.15", - "rand", + "rand 0.8.5", "ring", "rustc-hash 2.1.0", "rustls", @@ -5298,11 +5298,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", "serde", ] +[[package]] +name = "rand" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.1", + "zerocopy 0.8.19", +] + [[package]] name = "rand_chacha" version = "0.3.1" @@ -5310,7 +5321,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.1", ] [[package]] @@ -5322,13 +5343,23 @@ dependencies = [ "getrandom 0.2.15", ] +[[package]] +name = "rand_core" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a88e0da7a2c97baa202165137c158d0a2e824ac465d13d81046727b34cb247d3" +dependencies = [ + "getrandom 0.3.1", + "zerocopy 0.8.19", +] + [[package]] name = "rand_xorshift" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -5337,7 +5368,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -5899,7 +5930,7 @@ dependencies = [ "cfg-if", "eyre", "libc", - "rand", + "rand 0.8.5", "reth-fs-util", "secp256k1", "serde", @@ -6113,7 +6144,7 @@ dependencies = [ "generic-array", "itertools 0.13.0", "parking_lot", - "rand", + "rand 0.8.5", "reth-ethereum-forks", "reth-net-banlist", "reth-net-nat", @@ -6140,7 +6171,7 @@ dependencies = [ "futures", "itertools 0.13.0", "metrics", - "rand", + "rand 0.8.5", "reth-chainspec", "reth-ethereum-forks", "reth-metrics", @@ -6226,7 +6257,7 @@ dependencies = [ "generic-array", "hmac 0.12.1", "pin-project", - "rand", + "rand 0.8.5", "reth-network-peers", "secp256k1", "sha2 0.10.8", @@ -6716,7 +6747,7 @@ dependencies = [ "serde_json", "tokio", "tokio-stream", - "tokio-tungstenite 0.26.1", + "tokio-tungstenite 0.26.2", "tracing", "url", ] @@ -6858,7 +6889,7 @@ dependencies = [ "metrics", "parking_lot", "pin-project", - "rand", + "rand 0.8.5", "reth-chainspec", "reth-consensus", "reth-discv4", @@ -7085,7 +7116,7 @@ dependencies = [ "eyre", "futures", "humantime", - "rand", + "rand 0.8.5", "reth-chainspec", "reth-cli-util", "reth-config", @@ -7441,7 +7472,7 @@ dependencies = [ "once_cell", "op-alloy-consensus", "proptest", - "rand", + "rand 0.8.5", "reth-codecs", "reth-primitives", "reth-primitives-traits", @@ -7770,7 +7801,7 @@ dependencies = [ "jsonwebtoken", "parking_lot", "pin-project", - "rand", + "rand 0.8.5", "reth-chainspec", "reth-consensus", "reth-consensus-common", @@ -7958,7 +7989,7 @@ dependencies = [ "jsonrpsee-core", "jsonrpsee-types", "metrics", - "rand", + "rand 0.8.5", "reth-chain-state", "reth-chainspec", "reth-errors", @@ -8239,7 +8270,7 @@ dependencies = [ "futures-util", "metrics", "parking_lot", - "rand", + "rand 0.8.5", "reth-chain-state", "reth-chainspec", "reth-eth-wire-types", @@ -8583,7 +8614,7 @@ dependencies = [ "parity-scale-codec", "primitive-types", "proptest", - "rand", + "rand 0.8.5", "rlp", "ruint-macro", "serde", @@ -8615,7 +8646,7 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" dependencies = [ - "rand", + "rand 0.8.5", ] [[package]] @@ -8852,7 +8883,7 @@ version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" dependencies = [ - "rand", + "rand 0.8.5", "secp256k1-sys", "serde", ] @@ -9163,7 +9194,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ "digest 0.10.7", - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -9257,7 +9288,7 @@ dependencies = [ "http 1.2.0", "httparse", "log", - "rand", + "rand 0.8.5", "sha1", ] @@ -9332,7 +9363,7 @@ dependencies = [ "byteorder", "crunchy", "lazy_static", - "rand", + "rand 0.8.5", "rustc-hex", ] @@ -9705,14 +9736,16 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.26.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4bf6fecd69fcdede0ec680aaf474cdab988f9de6bc73d3758f0160e3b7025a" +checksum = "7a9daff607c6d2bf6c16fd681ccb7eecc83e4e2cdc1ca067ffaadfca5de7f084" dependencies = [ "futures-util", "log", + "native-tls", "tokio", - "tungstenite 0.26.1", + "tokio-native-tls", + "tungstenite 0.26.2", ] [[package]] @@ -9776,7 +9809,7 @@ dependencies = [ "indexmap 1.9.3", "pin-project", "pin-project-lite", - "rand", + "rand 0.8.5", "slab", "tokio", "tokio-util", @@ -9981,7 +10014,7 @@ dependencies = [ "http 1.2.0", "httparse", "log", - "rand", + "rand 0.8.5", "rustls", "rustls-pki-types", "sha1", @@ -9991,17 +10024,17 @@ dependencies = [ [[package]] name = "tungstenite" -version = "0.26.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413083a99c579593656008130e29255e54dcaae495be556cc26888f211648c24" +checksum = "4793cb5e56680ecbb1d843515b23b6de9a75eb04b66643e256a396d43be33c13" dependencies = [ - "byteorder", "bytes", "data-encoding", "http 1.2.0", "httparse", "log", - "rand", + "native-tls", + "rand 0.9.0", "sha1", "thiserror 2.0.11", "utf-8", @@ -10792,7 +10825,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "byteorder", - "zerocopy-derive", + "zerocopy-derive 0.7.35", +] + +[[package]] +name = "zerocopy" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8207f485579465f62ae51a983e42c906736a17efd2de48b021e64f1bbd8e98c7" +dependencies = [ + "zerocopy-derive 0.8.19", ] [[package]] @@ -10806,6 +10848,17 @@ dependencies = [ "syn 2.0.98", ] +[[package]] +name = "zerocopy-derive" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dbe1304a711c6eb4cf1ed333aa0d9b344685e71f6f00c3b176072213bd3783e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.98", +] + [[package]] name = "zerofrom" version = "0.1.5" diff --git a/Cargo.toml b/Cargo.toml index ec6c6e5..d3f4a1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,8 +28,8 @@ tokio-stream = "0.1" futures = "0.3" futures-util = "0.3" reqwest = { version = "0.11", features = ["json", "stream"] } -tokio-tungstenite = "0.26.1" url = "2.5" +tokio-tungstenite = { version = "0.26.2", features = ["native-tls"] } # TODO: Pinning dependencies to work around deposit-transaction being removed and Reth 1.1.5 not being updated, see: # https://github.com/alloy-rs/op-alloy/pull/383/files. This can be removed in the future diff --git a/src/cache.rs b/src/cache.rs index cbd944d..c4da7d3 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,5 +1,4 @@ use serde::{de::DeserializeOwned, Serialize}; -use serde_json; use std::collections::HashMap; use std::sync::{Arc, RwLock}; use std::time::{Duration, Instant}; diff --git a/src/flashblocks.rs b/src/flashblocks.rs index dac76ae..f095a1c 100644 --- a/src/flashblocks.rs +++ b/src/flashblocks.rs @@ -1,5 +1,5 @@ use crate::cache::Cache; -use alloy_primitives::B256; +use alloy_primitives::{map::foldhash::HashMap, Address, B256, U256}; use futures_util::StreamExt; use op_alloy_rpc_types_engine::OpExecutionPayloadEnvelopeV3; use reth::core::primitives::SignedTransaction; @@ -7,7 +7,7 @@ use reth_optimism_primitives::{OpBlock, OpReceipt}; use serde::{Deserialize, Serialize}; use std::sync::Arc; use tokio::sync::mpsc; -use tokio_tungstenite::{connect_async, tungstenite::Message}; +use tokio_tungstenite::{connect_async, tungstenite::protocol::Message}; use tracing::{error, info}; use url::Url; @@ -26,6 +26,7 @@ enum ActorMessage { response: OpExecutionPayloadEnvelopeV3, receipts: Vec, tx_hashes: Vec, + //new_account_balances: HashMap, }, } @@ -48,28 +49,96 @@ impl FlashblocksClient { pub fn init(&mut self, ws_url: String) -> Result<(), Box> { let url = Url::parse(&ws_url)?; + println!("trying to connect to {:?}", url); let sender = self.sender.clone(); + let cache_clone = self.cache.clone(); + + // Take ownership of mailbox for the actor loop + let mut mailbox = std::mem::replace(&mut self.mailbox, mpsc::channel(1).1); - // Spawn WebSocket handler + // Spawn WebSocket handler with integrated actor loop tokio::spawn(async move { loop { - match connect_websocket(&url, sender.clone()).await { - Ok(()) => break, + match connect_async(url.as_str()).await { + Ok((ws_stream, _)) => { + println!("WebSocket connected!"); + let (_write, mut read) = ws_stream.split(); + + // Handle incoming messages + while let Some(msg) = read.next().await { + match msg { + Ok(Message::Text(text)) => { + let message: serde_json::Value = + match serde_json::from_str(&text) { + Ok(m) => m, + Err(e) => { + error!("failed to parse message: {}", e); + continue; + } + }; + let payload: OpExecutionPayloadEnvelopeV3 = + match serde_json::from_value(message["response"].clone()) { + Ok(p) => p, + Err(e) => { + error!("failed to parse payload: {}", e); + continue; + } + }; + let receipts: Vec = + match serde_json::from_value(message["receipts"].clone()) { + Ok(r) => r, + Err(e) => { + error!("failed to parse receipts: {}", e); + continue; + } + }; + let tx_hashes: Vec = match serde_json::from_value( + message["tx_hashes"].clone(), + ) { + Ok(h) => h, + Err(e) => { + error!("failed to parse tx_hashes: {}", e); + continue; + } + }; + // let new_account_balances: HashMap = match serde_json::from_value(message["new_account_balances"].clone()) { + // Ok(b) => b, + // Err(e) => { + // error!("failed to parse account balances: {}", e); + // continue; + // } + // }; + + let _ = sender + .send(ActorMessage::BestPayload { + response: payload, + receipts, + tx_hashes, + //new_account_balances, + }) + .await; + } + Ok(Message::Close(_)) => break, + Err(e) => { + error!("Error receiving message: {}", e); + break; + } + _ => {} // Handle other message types if needed + } + } + } Err(e) => { error!( - message = "Flashbots WebSocket connection error, retrying in 5 seconds", + message = "WebSocket connection error, retrying in 5 seconds", error = %e ); tokio::time::sleep(std::time::Duration::from_secs(5)).await; + continue; } } } }); - // Take ownership of mailbox and state for the actor loop - let mut mailbox = std::mem::replace(&mut self.mailbox, mpsc::channel(1).1); - - let cache_clone = self.cache.clone(); // Spawn actor's event loop tokio::spawn(async move { while let Some(message) = mailbox.recv().await { @@ -78,24 +147,24 @@ impl FlashblocksClient { response, receipts, tx_hashes, + // new_account_balances, } => { - // add logic to add to cache here let execution_payload = response.execution_payload; let block: OpBlock = execution_payload .try_into_block() .expect("failed to convert execution payload to block"); - // store the block in cache + cache_clone .set(&format!("pending"), &block, Some(10)) .expect("failed to set block in cache"); println!("block number {:?}", block.number); - // store all receipts in cache + // Store receipts cache_clone .set(&format!("pending_receipts"), &receipts, Some(10)) .expect("failed to set receipts in cache"); - // store each OpTransactctionSigned in cache + // Store transactions for tx in block.body.transactions { let tx_hash = *tx.tx_hash(); cache_clone @@ -104,13 +173,21 @@ impl FlashblocksClient { println!("stored tx {:?}", tx_hash); } - // iterate over tx_hashes and receipts, and store them in cache + // Store tx receipts for (tx_hash, receipt) in tx_hashes.iter().zip(receipts.iter()) { cache_clone .set(&format!("receipt:{:?}", tx_hash), &receipt, Some(10)) .expect("failed to set receipt in cache"); println!("stored receipt {:?}", tx_hash); } + + // Store account balances + // for (address, balance) in new_account_balances.iter() { + // cache_clone + // .set(&format!("{:?}", address), &balance, Some(10)) + // .expect("failed to set account balance in cache"); + // println!("stored account balance {:?}", address); + // } } } } @@ -119,45 +196,3 @@ impl FlashblocksClient { Ok(()) } } - -async fn connect_websocket( - url: &Url, - sender: mpsc::Sender, -) -> Result<(), Box> { - let (ws_stream, _) = connect_async(url.as_str()).await?; - let (_write, mut read) = ws_stream.split(); - - info!(message = "Flashbots WebSocket connected", url = %url); - - while let Some(msg) = read.next().await { - match msg { - Ok(Message::Text(text)) => { - // extract payload, receipts, and tx_hashes from the message - let message: serde_json::Value = serde_json::from_str(&text)?; - let payload: OpExecutionPayloadEnvelopeV3 = - serde_json::from_value(message["response"].clone())?; - let receipts: Vec = serde_json::from_value(message["receipts"].clone())?; - let tx_hashes: Vec = serde_json::from_value(message["tx_hashes"].clone())?; - - let _ = sender - .send(ActorMessage::BestPayload { - response: payload, - receipts, - tx_hashes, - }) - .await; - } - Ok(Message::Close(_)) => { - info!(message = "Received close frame"); - break; - } - Err(e) => { - error!(message = "WebSocket error", error = %e); - return Err(e.into()); - } - _ => {} // Ignore other message types - } - } - - Ok(()) -} diff --git a/src/rpc.rs b/src/rpc.rs index e873b50..c07b703 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -73,7 +73,7 @@ impl EthApiExt { let converted_txs = transactions_with_senders .enumerate() .map(|(idx, (tx, sender))| { - let signed_tx_ec_recovered = Recovered::new_unchecked(tx.clone(), sender.clone()); + let signed_tx_ec_recovered = Recovered::new_unchecked(tx.clone(), sender); let tx_info = TransactionInfo { hash: Some(*tx.tx_hash()), block_hash: None, @@ -85,12 +85,12 @@ impl EthApiExt { }) .collect(); - return RpcBlock:: { + RpcBlock:: { header: Header::from_consensus(header.seal_slow(), None, None), transactions: BlockTransactions::Full(converted_txs), uncles: Vec::new(), withdrawals: None, - }; + } } pub fn transform_tx( @@ -179,7 +179,7 @@ impl EthApiExt { reth_optimism_evm::extract_l1_info(&block.body).expect("failed to extract l1 info"); let meta = TransactionMeta { - tx_hash: tx_hash, + tx_hash, index: 0, // placeholder block_hash: B256::default(), // placeholder block_number: block.number, @@ -262,14 +262,15 @@ where ) -> RpcResult { let block_id = block_number.unwrap_or_default(); if block_id.is_pending() { - info!("pending tag, delegating to flashblocks"); - todo!() - } else { - info!("non pending block, using standard flow"); - EthState::balance(&self.eth_api, address, block_number) - .await - .map_err(Into::into) + if let Some(balance) = self.cache.get::(&format!("{:?}", address)) { + return Ok(balance); + } + // If pending not found, use standard flow below } + + EthState::balance(&self.eth_api, address, block_number) + .await + .map_err(Into::into) } }