Skip to content

Commit

Permalink
feat: add eth_evmSetBlockGasLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Nov 22, 2023
1 parent 1b17910 commit 06cb7f4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/edr_eth/src/remote/cacheable_method_invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand Down
7 changes: 7 additions & 0 deletions crates/edr_eth/src/remote/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions crates/edr_provider/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions crates/edr_provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
}
Expand Down
16 changes: 14 additions & 2 deletions crates/edr_provider/src/requests/eth/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@ pub fn handle_mine_request(
Ok(String::from("0"))
}

pub fn handle_set_automine(data: &mut ProviderData, automine: bool) -> Result<bool, ProviderError> {
pub fn handle_set_automine_request(
data: &mut ProviderData,
automine: bool,
) -> Result<bool, ProviderError> {
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<bool, ProviderError> {
data.set_block_gas_limit(gas_limit)?;

Ok(true)
}

pub fn handle_set_next_block_timestamp_request(
data: &mut ProviderData,
timestamp: U64OrUsize,
) -> Result<String, ProviderError> {
Expand Down

0 comments on commit 06cb7f4

Please sign in to comment.