From 06cb7f4f21deb2f88ef19511d0c12e2f25dec25b Mon Sep 17 00:00:00 2001 From: Wodann Date: Wed, 22 Nov 2023 08:02:12 +0000 Subject: [PATCH] feat: add eth_evmSetBlockGasLimit --- .../src/remote/cacheable_method_invocation.rs | 1 + crates/edr_eth/src/remote/methods.rs | 7 +++++++ crates/edr_provider/src/data.rs | 7 +++++++ crates/edr_provider/src/lib.rs | 7 +++++-- crates/edr_provider/src/requests/eth/evm.rs | 16 ++++++++++++++-- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/crates/edr_eth/src/remote/cacheable_method_invocation.rs b/crates/edr_eth/src/remote/cacheable_method_invocation.rs index eda831fae1..a0b6833125 100644 --- a/crates/edr_eth/src/remote/cacheable_method_invocation.rs +++ b/crates/edr_eth/src/remote/cacheable_method_invocation.rs @@ -267,6 +267,7 @@ impl<'a> TryFrom<&'a MethodInvocation> for CacheableMethodInvocation<'a> { | MethodInvocation::EvmIncreaseTime(_) | MethodInvocation::EvmMine(_) | MethodInvocation::EvmSetAutomine(_) + | MethodInvocation::EvmSetBlockGasLimit(_) | MethodInvocation::EvmSetIntervalMining(_) | MethodInvocation::EvmSetNextBlockTimestamp(_) | MethodInvocation::EvmSnapshot() => { diff --git a/crates/edr_eth/src/remote/methods.rs b/crates/edr_eth/src/remote/methods.rs index 131d48b58d..131743559b 100644 --- a/crates/edr_eth/src/remote/methods.rs +++ b/crates/edr_eth/src/remote/methods.rs @@ -311,6 +311,13 @@ pub enum MethodInvocation { deserialize_with = "sequence_to_single" )] EvmSetAutomine(bool), + /// evm_setBlockGasLimit + #[serde( + rename = "evm_setBlockGasLimit", + serialize_with = "single_to_sequence", + deserialize_with = "sequence_to_single" + )] + EvmSetBlockGasLimit(#[serde(with = "crate::serde::u64")] u64), /// evm_setIntervalMining #[serde( rename = "evm_setIntervalMining", diff --git a/crates/edr_provider/src/data.rs b/crates/edr_provider/src/data.rs index 8427099b28..46431cd34d 100644 --- a/crates/edr_provider/src/data.rs +++ b/crates/edr_provider/src/data.rs @@ -423,6 +423,13 @@ impl ProviderData { Ok(()) } + /// Sets the gas limit used for mining new blocks. + pub fn set_block_gas_limit(&mut self, gas_limit: u64) -> Result<(), ProviderError> { + self.mem_pool + .set_block_gas_limit(&self.state, gas_limit) + .map_err(ProviderError::State) + } + pub fn set_code(&mut self, address: Address, code: Bytes) -> Result<(), ProviderError> { let default_code = code.clone(); self.state.modify_account( diff --git a/crates/edr_provider/src/lib.rs b/crates/edr_provider/src/lib.rs index a95d93602e..6e90e58c9a 100644 --- a/crates/edr_provider/src/lib.rs +++ b/crates/edr_provider/src/lib.rs @@ -199,11 +199,14 @@ fn handle_eth_request( eth::handle_mine_request(data, timestamp).and_then(to_json) } EthRequest::EvmSetAutomine(enabled) => { - eth::handle_set_automine(data, enabled).and_then(to_json) + eth::handle_set_automine_request(data, enabled).and_then(to_json) + } + EthRequest::EvmSetBlockGasLimit(gas_limit) => { + eth::handle_set_block_gas_limit_request(data, gas_limit).and_then(to_json) } EthRequest::EvmSetIntervalMining(_) => Err(ProviderError::Unimplemented("".to_string())), EthRequest::EvmSetNextBlockTimestamp(timestamp) => { - eth::handle_set_next_block_timestamp(data, timestamp).and_then(to_json) + eth::handle_set_next_block_timestamp_request(data, timestamp).and_then(to_json) } EthRequest::EvmSnapshot() => Err(ProviderError::Unimplemented("".to_string())), } diff --git a/crates/edr_provider/src/requests/eth/evm.rs b/crates/edr_provider/src/requests/eth/evm.rs index aca13cb930..038028ac6b 100644 --- a/crates/edr_provider/src/requests/eth/evm.rs +++ b/crates/edr_provider/src/requests/eth/evm.rs @@ -25,13 +25,25 @@ pub fn handle_mine_request( Ok(String::from("0")) } -pub fn handle_set_automine(data: &mut ProviderData, automine: bool) -> Result { +pub fn handle_set_automine_request( + data: &mut ProviderData, + automine: bool, +) -> Result { data.set_auto_mining(automine); Ok(true) } -pub fn handle_set_next_block_timestamp( +pub fn handle_set_block_gas_limit_request( + data: &mut ProviderData, + gas_limit: u64, +) -> Result { + data.set_block_gas_limit(gas_limit)?; + + Ok(true) +} + +pub fn handle_set_next_block_timestamp_request( data: &mut ProviderData, timestamp: U64OrUsize, ) -> Result {