diff --git a/crates/node-interaction/src/lib.rs b/crates/node-interaction/src/lib.rs index 284f932..afba76a 100644 --- a/crates/node-interaction/src/lib.rs +++ b/crates/node-interaction/src/lib.rs @@ -1,5 +1,6 @@ //! This crate implements all node interactions. +use alloy::eips::BlockNumberOrTag; use alloy::primitives::{Address, BlockHash, BlockNumber, BlockTimestamp, ChainId, U256}; use alloy::rpc::types::trace::geth::{DiffMode, GethTrace}; use alloy::rpc::types::{TransactionReceipt, TransactionRequest}; @@ -27,20 +28,20 @@ pub trait EthereumNode { // TODO: This is currently a u128 due to Kitchensink needing more than 64 bits for its gas limit // when we implement the changes to the gas we need to adjust this to be a u64. - /// Returns the gas limit of the last block. - fn block_gas_limit(&self) -> Result; + /// Returns the gas limit of the specified block. + fn block_gas_limit(&self, number: BlockNumberOrTag) -> Result; - /// Returns the coinbase of the last block. - fn block_coinbase(&self) -> Result
; + /// Returns the coinbase of the specified block. + fn block_coinbase(&self, number: BlockNumberOrTag) -> Result
; - /// Returns the difficulty of the last block. - fn block_difficulty(&self) -> Result; + /// Returns the difficulty of the specified block. + fn block_difficulty(&self, number: BlockNumberOrTag) -> Result; - /// Returns the hash of the last block. - fn block_hash(&self) -> Result; + /// Returns the hash of the specified block. + fn block_hash(&self, number: BlockNumberOrTag) -> Result; - /// Returns the timestamp of the last block, - fn block_timestamp(&self) -> Result; + /// Returns the timestamp of the specified block, + fn block_timestamp(&self, number: BlockNumberOrTag) -> Result; /// Returns the number of the last block. fn last_block_number(&self) -> Result; diff --git a/crates/node/src/geth.rs b/crates/node/src/geth.rs index 02abf62..4efd626 100644 --- a/crates/node/src/geth.rs +++ b/crates/node/src/geth.rs @@ -363,12 +363,12 @@ impl EthereumNode for Instance { } #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] - fn block_gas_limit(&self) -> anyhow::Result { + fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result { let provider = self.provider(); BlockingExecutor::execute(async move { provider .await? - .get_block_by_number(BlockNumberOrTag::Latest) + .get_block_by_number(number) .await? .ok_or(anyhow::Error::msg("Blockchain has no blocks")) .map(|block| block.header.gas_limit as _) @@ -376,12 +376,12 @@ impl EthereumNode for Instance { } #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] - fn block_coinbase(&self) -> anyhow::Result
{ + fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result
{ let provider = self.provider(); BlockingExecutor::execute(async move { provider .await? - .get_block_by_number(BlockNumberOrTag::Latest) + .get_block_by_number(number) .await? .ok_or(anyhow::Error::msg("Blockchain has no blocks")) .map(|block| block.header.beneficiary) @@ -389,12 +389,12 @@ impl EthereumNode for Instance { } #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] - fn block_difficulty(&self) -> anyhow::Result { + fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result { let provider = self.provider(); BlockingExecutor::execute(async move { provider .await? - .get_block_by_number(BlockNumberOrTag::Latest) + .get_block_by_number(number) .await? .ok_or(anyhow::Error::msg("Blockchain has no blocks")) .map(|block| block.header.difficulty) @@ -402,12 +402,12 @@ impl EthereumNode for Instance { } #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] - fn block_hash(&self) -> anyhow::Result { + fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result { let provider = self.provider(); BlockingExecutor::execute(async move { provider .await? - .get_block_by_number(BlockNumberOrTag::Latest) + .get_block_by_number(number) .await? .ok_or(anyhow::Error::msg("Blockchain has no blocks")) .map(|block| block.header.hash) @@ -415,12 +415,12 @@ impl EthereumNode for Instance { } #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] - fn block_timestamp(&self) -> anyhow::Result { + fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result { let provider = self.provider(); BlockingExecutor::execute(async move { provider .await? - .get_block_by_number(BlockNumberOrTag::Latest) + .get_block_by_number(number) .await? .ok_or(anyhow::Error::msg("Blockchain has no blocks")) .map(|block| block.header.timestamp) @@ -583,7 +583,7 @@ mod tests { let (node, _temp_dir) = new_node(); // Act - let gas_limit = node.block_gas_limit(); + let gas_limit = node.block_gas_limit(BlockNumberOrTag::Latest); // Assert let gas_limit = gas_limit.expect("Failed to get the gas limit"); @@ -596,7 +596,7 @@ mod tests { let (node, _temp_dir) = new_node(); // Act - let coinbase = node.block_coinbase(); + let coinbase = node.block_coinbase(BlockNumberOrTag::Latest); // Assert let coinbase = coinbase.expect("Failed to get the coinbase"); @@ -609,7 +609,7 @@ mod tests { let (node, _temp_dir) = new_node(); // Act - let block_difficulty = node.block_difficulty(); + let block_difficulty = node.block_difficulty(BlockNumberOrTag::Latest); // Assert let block_difficulty = block_difficulty.expect("Failed to get the block difficulty"); @@ -622,7 +622,7 @@ mod tests { let (node, _temp_dir) = new_node(); // Act - let block_hash = node.block_hash(); + let block_hash = node.block_hash(BlockNumberOrTag::Latest); // Assert let _ = block_hash.expect("Failed to get the block hash"); @@ -634,7 +634,7 @@ mod tests { let (node, _temp_dir) = new_node(); // Act - let block_timestamp = node.block_timestamp(); + let block_timestamp = node.block_timestamp(BlockNumberOrTag::Latest); // Assert let _ = block_timestamp.expect("Failed to get the block timestamp"); diff --git a/crates/node/src/kitchensink.rs b/crates/node/src/kitchensink.rs index b32464a..d003f38 100644 --- a/crates/node/src/kitchensink.rs +++ b/crates/node/src/kitchensink.rs @@ -439,12 +439,12 @@ impl EthereumNode for KitchensinkNode { } #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] - fn block_gas_limit(&self) -> anyhow::Result { + fn block_gas_limit(&self, number: BlockNumberOrTag) -> anyhow::Result { let provider = self.provider(); BlockingExecutor::execute(async move { provider .await? - .get_block_by_number(BlockNumberOrTag::Latest) + .get_block_by_number(number) .await? .ok_or(anyhow::Error::msg("Blockchain has no blocks")) .map(|block| block.header.gas_limit) @@ -452,12 +452,12 @@ impl EthereumNode for KitchensinkNode { } #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] - fn block_coinbase(&self) -> anyhow::Result
{ + fn block_coinbase(&self, number: BlockNumberOrTag) -> anyhow::Result
{ let provider = self.provider(); BlockingExecutor::execute(async move { provider .await? - .get_block_by_number(BlockNumberOrTag::Latest) + .get_block_by_number(number) .await? .ok_or(anyhow::Error::msg("Blockchain has no blocks")) .map(|block| block.header.beneficiary) @@ -465,12 +465,12 @@ impl EthereumNode for KitchensinkNode { } #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] - fn block_difficulty(&self) -> anyhow::Result { + fn block_difficulty(&self, number: BlockNumberOrTag) -> anyhow::Result { let provider = self.provider(); BlockingExecutor::execute(async move { provider .await? - .get_block_by_number(BlockNumberOrTag::Latest) + .get_block_by_number(number) .await? .ok_or(anyhow::Error::msg("Blockchain has no blocks")) .map(|block| block.header.difficulty) @@ -478,12 +478,12 @@ impl EthereumNode for KitchensinkNode { } #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] - fn block_hash(&self) -> anyhow::Result { + fn block_hash(&self, number: BlockNumberOrTag) -> anyhow::Result { let provider = self.provider(); BlockingExecutor::execute(async move { provider .await? - .get_block_by_number(BlockNumberOrTag::Latest) + .get_block_by_number(number) .await? .ok_or(anyhow::Error::msg("Blockchain has no blocks")) .map(|block| block.header.hash) @@ -491,12 +491,12 @@ impl EthereumNode for KitchensinkNode { } #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] - fn block_timestamp(&self) -> anyhow::Result { + fn block_timestamp(&self, number: BlockNumberOrTag) -> anyhow::Result { let provider = self.provider(); BlockingExecutor::execute(async move { provider .await? - .get_block_by_number(BlockNumberOrTag::Latest) + .get_block_by_number(number) .await? .ok_or(anyhow::Error::msg("Blockchain has no blocks")) .map(|block| block.header.timestamp) @@ -1256,7 +1256,7 @@ mod tests { let (node, _temp_dir) = new_node(); // Act - let gas_limit = node.block_gas_limit(); + let gas_limit = node.block_gas_limit(BlockNumberOrTag::Latest); // Assert let gas_limit = gas_limit.expect("Failed to get the gas limit"); @@ -1269,7 +1269,7 @@ mod tests { let (node, _temp_dir) = new_node(); // Act - let coinbase = node.block_coinbase(); + let coinbase = node.block_coinbase(BlockNumberOrTag::Latest); // Assert let coinbase = coinbase.expect("Failed to get the coinbase"); @@ -1282,7 +1282,7 @@ mod tests { let (node, _temp_dir) = new_node(); // Act - let block_difficulty = node.block_difficulty(); + let block_difficulty = node.block_difficulty(BlockNumberOrTag::Latest); // Assert let block_difficulty = block_difficulty.expect("Failed to get the block difficulty"); @@ -1295,7 +1295,7 @@ mod tests { let (node, _temp_dir) = new_node(); // Act - let block_hash = node.block_hash(); + let block_hash = node.block_hash(BlockNumberOrTag::Latest); // Assert let _ = block_hash.expect("Failed to get the block hash"); @@ -1307,7 +1307,7 @@ mod tests { let (node, _temp_dir) = new_node(); // Act - let block_timestamp = node.block_timestamp(); + let block_timestamp = node.block_timestamp(BlockNumberOrTag::Latest); // Assert let _ = block_timestamp.expect("Failed to get the block timestamp");