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

Investigate eth_getLogs issue #23

Draft
wants to merge 10 commits into
base: polkadot-v0.9.24
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
849 changes: 433 additions & 416 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ serde_json = "1.0"
clap = { version = "3.1", features = ["derive"] }

ethereum-types = "0.13.1"
sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] }
sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", features = ["wasmtime"] }
sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", features = ["wasmtime"] }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
fc-db = { path = "../db" }
fp-storage = { version = "2.0.0-dev", path = "../../primitives/storage" }
fp-rpc = { version = "3.0.0-dev", path = "../../primitives/rpc" }

[dev-dependencies]
tempfile = "3.3.0"
substrate-test-runtime-client = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-test-runtime-client = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
frontier-template-runtime = { path = "../../template/runtime" }
sp-io = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-block-builder = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sc-block-builder = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
codec = { package = "parity-scale-codec", version = "3.0.0" }
futures = { version = "0.3.1", features = ["compat"] }
sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-db = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sc-client-db = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
14 changes: 7 additions & 7 deletions client/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ repository = "https://github.com/paritytech/frontier/"
async-trait = "0.1"
thiserror = "1.0"

sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }

fc-db = { version = "2.0.0-dev", path = "../db" }
fp-consensus = { version = "2.0.0-dev", path = "../../primitives/consensus" }
Expand Down
10 changes: 5 additions & 5 deletions client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
repository = "https://github.com/paritytech/frontier/"

[dependencies]
parking_lot = "0.12.1"
parking_lot = "0.12.0"

codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] }
sc-client-db = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-database = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-db = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-database = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }

fp-storage = { version = "2.0.0-dev", path = "../../primitives/storage" }

Expand Down
8 changes: 4 additions & 4 deletions client/mapping-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ futures = { version = "0.3.1", features = ["compat"] }
futures-timer = "3.0.1"
log = "0.4.17"

sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }

fc-db = { version = "2.0.0-dev", path = "../db" }
fp-consensus = { version = "2.0.0-dev", path = "../../primitives/consensus" }
Expand Down
42 changes: 21 additions & 21 deletions client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,40 @@ hex = "0.4"
jsonrpsee = { version = "0.13.0", features = ["server", "macros"] }
libsecp256k1 = "0.7"
log = "0.4.17"
lru = "0.7.6"
lru = "0.7.5"
prometheus = { version = "0.13.1", default-features = false }
rand = "0.8"
rlp = "0.5"
rustc-hex = "2.1.0"
tokio = { version = "1.19", features = ["sync"] }
tokio = { version = "1.18.2", features = ["sync"] }

prometheus-endpoint = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-storage = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-io = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-storage = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }

fc-db = { version = "2.0.0-dev", path = "../db" }
fc-rpc-core = { version = "1.1.0-dev", path = "../rpc-core" }
fp-rpc = { version = "3.0.0-dev", path = "../../primitives/rpc" }
fp-storage = { version = "2.0.0-dev", path = "../../primitives/storage" }

[dev-dependencies]
beefy-primitives = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
beefy-primitives = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
frontier-template-runtime = { path = "../../template/runtime" }
sc-block-builder = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-client-db = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-test-runtime-client = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-block-builder = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sc-client-db = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
substrate-test-runtime-client = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
tempfile = "3.3.0"

[features]
Expand Down
19 changes: 17 additions & 2 deletions client/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
use fc_rpc_core::types::*;

use crate::{
eth::{rich_block_build, Eth},
eth::{empty_block_from, rich_block_build, Eth},
frontier_backend_client, internal_err,
};

Expand Down Expand Up @@ -132,7 +132,22 @@ where
base_fee,
)))
}
_ => Ok(None),
_ => {
if let BlockNumber::Num(block_number) = number {
let eth_block = empty_block_from(block_number.into());
let eth_hash =
H256::from_slice(keccak_256(&rlp::encode(&eth_block.header)).as_slice());
Ok(Some(rich_block_build(
eth_block,
Default::default(),
Some(eth_hash),
full,
None,
)))
} else {
Ok(None)
}
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions client/rpc/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ where
let backend = Arc::clone(&self.backend);
let max_past_logs = self.max_past_logs;

log::info!(">>eth_getLogs(1): called with filter: {:?}", filter);

let mut ret: Vec<Log> = Vec::new();
if let Some(hash) = filter.block_hash {
let id = match frontier_backend_client::load_hash::<B>(backend.as_ref(), hash)
Expand Down Expand Up @@ -413,6 +415,8 @@ where
.map(|s| s.unique_saturated_into())
.unwrap_or(client.info().best_number);

log::info!(">>eth_getLogs(2): for range from({:?}) to({:?})", from_number, current_number);

let _ = filter_range_logs(
client.as_ref(),
backend.as_ref(),
Expand Down Expand Up @@ -474,12 +478,15 @@ where
}
}
}
log::info!(">>eth_getLogs(3): schema loaded from cache: {:?}", local_cache);

let cache_keys: Vec<NumberFor<B>> = local_cache.keys().cloned().collect();
let mut default_schema: Option<&EthereumStorageSchema> = None;
if cache_keys.len() == 1 {
// There is only one schema and that's the one we use.
default_schema = local_cache.get(&cache_keys[0]);
}
log::info!(">>eth_getLogs(4): default schema is {:?}", default_schema);

while current_number <= to {
let id = BlockId::Number(current_number);
Expand All @@ -501,6 +508,7 @@ where
default_schema = local_cache.get(&cache_keys[i - 1]);
}
}
log::info!(">>eth_getLogs(5_{}): default schema for current number {:?} is {:?}", current_number, current_number, default_schema);
match default_schema {
Some(schema) => *schema,
// Fallback to DB read. This will happen i.e. when there is no cache
Expand All @@ -512,26 +520,31 @@ where

let block = block_data_cache.current_block(schema, substrate_hash).await;

log::info!(">>eth_getLogs(5_{}): for schema {:?} and block number {:?}, read block {:?}", current_number, schema, id, block);

if let Some(block) = block {
if FilteredParams::address_in_bloom(block.header.logs_bloom, &address_bloom_filter)
&& FilteredParams::topics_in_bloom(block.header.logs_bloom, &topics_bloom_filter)
{
let statuses = block_data_cache
.current_transaction_statuses(schema, substrate_hash)
.await;
log::info!(">>eth_getLogs(5_{}): for schema {:?} and block number {:?}, read block {:?}", current_number, schema, id, block);
if let Some(statuses) = statuses {
filter_block_logs(ret, filter, block, statuses);
}
}
}
// Check for restrictions
if ret.len() as u32 > max_past_logs {
log::info!(">>eth_getLogs(5_{}): Too many results in query!", current_number);
return Err(internal_err(format!(
"query returned more than {} results",
max_past_logs
)));
}
if begin_request.elapsed() > max_duration {
log::info!(">>eth_getLogs(5_{}): Query timeout!", current_number);
return Err(internal_err(format!(
"query timeout of {} seconds exceeded",
max_duration.as_secs()
Expand Down
23 changes: 23 additions & 0 deletions client/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,29 @@ fn rich_block_build(
}
}

fn empty_block_from(number: U256) -> ethereum::BlockV2 {
let ommers = Vec::<ethereum::Header>::new();
let receipts = Vec::<ethereum::ReceiptV2>::new();
let receipts_root = ethereum::util::ordered_trie_root(receipts.iter().map(|r| rlp::encode(r)));
let logs_bloom = ethereum_types::Bloom::default();
let partial_header = ethereum::PartialHeader {
parent_hash: H256::default(),
beneficiary: Default::default(),
state_root: Default::default(),
receipts_root,
logs_bloom,
difficulty: U256::zero(),
number,
gas_limit: U256::from(4_000_000),
gas_used: U256::zero(),
timestamp: Default::default(),
extra_data: Vec::new(),
mix_hash: H256::default(),
nonce: H64::default(),
};
ethereum::Block::new(partial_header, Default::default(), ommers)
}

fn transaction_build(
ethereum_transaction: EthereumTransaction,
block: Option<EthereumBlock>,
Expand Down
10 changes: 5 additions & 5 deletions frame/base-fee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ serde = { version = "1.0.137", optional = true }

codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
scale-info = { version = "2.1.2", default-features = false, features = ["derive"] }
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }

frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }

fp-evm = { version = "3.0.0-dev", path = "../../primitives/evm", default-features = false }

[dev-dependencies]
sp-io = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
sp-io = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }

[features]
default = ["std"]
Expand Down