Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove hardfork restriction on eth_getLogs #5087

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/friendly-steaks-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/edr": patch
---

Fixed eth_getLogs RPC request for pre-Merge hardforks
2 changes: 1 addition & 1 deletion crates/edr_eth/src/remote/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum OneOrMore<T> {
}

/// for specifying the inputs to `eth_newFilter` and `eth_getLogs`
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LogFilterOptions {
/// beginning of a range of blocks
Expand Down
9 changes: 1 addition & 8 deletions crates/edr_provider/src/requests/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use edr_eth::{
filter::{FilteredEvents, LogFilterOptions, LogOutput, OneOrMore, SubscriptionType},
BlockSpec, BlockTag, Eip1898BlockSpec,
},
SpecId, U256,
U256,
};
use edr_evm::HashSet;

Expand Down Expand Up @@ -41,13 +41,6 @@ pub fn handle_get_logs_request<LoggerErrorT: Debug>(
validate_post_merge_block_tags(data.spec_id(), to_block)?;
}

if data.spec_id() < SpecId::MERGE {
return Err(ProviderError::InvalidInput(
"eth_getLogs is disabled. It only works with the Berlin hardfork or a later one."
.into(),
));
}

let filter = validate_filter_criteria::<true, LoggerErrorT>(data, filter_options)?;
data.logs(filter)
.map(|logs| logs.iter().map(LogOutput::from).collect())
Expand Down
55 changes: 55 additions & 0 deletions crates/edr_provider/tests/issue_361.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use edr_eth::{
remote::{filter::LogFilterOptions, BlockSpec},
transaction::EthTransactionRequest,
AccountInfo, Address, SpecId,
};
use edr_evm::KECCAK_EMPTY;
use edr_provider::{
test_utils::{create_test_config_with_fork, one_ether},
MethodInvocation, NoopLogger, Provider, ProviderRequest,
};
use tokio::runtime;

#[tokio::test(flavor = "multi_thread")]
async fn issue_361() -> anyhow::Result<()> {
let logger = Box::new(NoopLogger);
let subscriber = Box::new(|_event| {});

let mut config = create_test_config_with_fork(None);
config.hardfork = SpecId::MUIR_GLACIER;

let impersonated_account = Address::random();
config.genesis_accounts.insert(
impersonated_account,
AccountInfo {
balance: one_ether(),
nonce: 0,
code: None,
code_hash: KECCAK_EMPTY,
},
);

let provider = Provider::new(runtime::Handle::current(), logger, subscriber, config)?;

provider.handle_request(ProviderRequest::Single(
MethodInvocation::ImpersonateAccount(impersonated_account.into()),
))?;

provider.handle_request(ProviderRequest::Single(MethodInvocation::SendTransaction(
EthTransactionRequest {
from: impersonated_account,
to: Some(Address::random()),
..EthTransactionRequest::default()
},
)))?;

provider.handle_request(ProviderRequest::Single(MethodInvocation::GetLogs(
LogFilterOptions {
from_block: Some(BlockSpec::Number(0)),
to_block: Some(BlockSpec::latest()),
..LogFilterOptions::default()
},
)))?;

Ok(())
}
Loading