Skip to content

Commit 696d42a

Browse files
RomarQsnowmead
andauthored
backport fix to perm-client-v0.44.1 (#3266)
* Add block range validation to eth_getLogs RPC (#3250) * add basic test * add max block range * validate error in test --------- Co-authored-by: snowmead <[email protected]> Co-authored-by: Michael Assaf <[email protected]> * fix CI * fix CI --------- Co-authored-by: snowmead <[email protected]>
1 parent 183fbfc commit 696d42a

File tree

9 files changed

+78
-28
lines changed

9 files changed

+78
-28
lines changed

.github/workflow-templates/cargo-build/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ runs:
1212
using: "composite"
1313
steps:
1414
- name: Run sccache-cache
15-
uses: mozilla-actions/[email protected].4
15+
uses: mozilla-actions/[email protected].9
1616
- name: Setup Variables
1717
shell: bash
1818
run: |

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ jobs:
493493
with:
494494
ref: ${{ needs.set-tags.outputs.git_ref }}
495495
- name: Run sccache-cache
496-
uses: mozilla-actions/[email protected].7
496+
uses: mozilla-actions/[email protected].9
497497
- name: Setup Variables
498498
shell: bash
499499
run: |

Cargo.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/cli-opt/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub struct RpcConfig {
107107
pub eth_statuses_cache: usize,
108108
pub fee_history_limit: u64,
109109
pub max_past_logs: u32,
110+
pub max_block_range: u32,
110111
pub relay_chain_rpc_urls: Vec<url::Url>,
111112
pub tracing_raw_max_memory_usage: usize,
112113
pub frontier_backend_config: FrontierBackendConfig,

node/cli/src/cli.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ pub struct RunCmd {
295295
#[clap(long, default_value = "10000")]
296296
pub max_past_logs: u32,
297297

298+
/// Maximum block range to query logs from.
299+
#[clap(long, default_value = "1024")]
300+
pub max_block_range: u32,
301+
298302
/// Force using Moonbase native runtime.
299303
#[clap(long = "force-moonbase")]
300304
pub force_moonbase: bool,
@@ -351,6 +355,7 @@ impl RunCmd {
351355
eth_statuses_cache: self.eth_statuses_cache,
352356
fee_history_limit: self.fee_history_limit,
353357
max_past_logs: self.max_past_logs,
358+
max_block_range: self.max_block_range,
354359
relay_chain_rpc_urls: self.base.relay_chain_rpc_urls.clone(),
355360
tracing_raw_max_memory_usage: self.tracing_raw_max_memory_usage,
356361
frontier_backend_config: match self.frontier_backend_type {

node/service/src/lazy_loading/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ where
761761
let sync = sync_service.clone();
762762
let ethapi_cmd = ethapi_cmd.clone();
763763
let max_past_logs = rpc_config.max_past_logs;
764+
let max_block_range = rpc_config.max_block_range;
764765
let overrides = overrides.clone();
765766
let fee_history_cache = fee_history_cache.clone();
766767
let block_data_cache = block_data_cache.clone();
@@ -783,6 +784,7 @@ where
783784
pool: pool.clone(),
784785
is_authority: collator,
785786
max_past_logs,
787+
max_block_range,
786788
fee_history_limit,
787789
fee_history_cache: fee_history_cache.clone(),
788790
network: network.clone(),

node/service/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ where
790790
let backend = backend.clone();
791791
let ethapi_cmd = ethapi_cmd.clone();
792792
let max_past_logs = rpc_config.max_past_logs;
793+
let max_block_range = rpc_config.max_block_range;
793794
let overrides = overrides.clone();
794795
let fee_history_cache = fee_history_cache.clone();
795796
let block_data_cache = block_data_cache.clone();
@@ -831,6 +832,7 @@ where
831832
pool: pool.clone(),
832833
is_authority: collator,
833834
max_past_logs,
835+
max_block_range,
834836
fee_history_limit,
835837
fee_history_cache: fee_history_cache.clone(),
836838
network: network.clone(),
@@ -1538,6 +1540,7 @@ where
15381540
let sync = sync_service.clone();
15391541
let ethapi_cmd = ethapi_cmd.clone();
15401542
let max_past_logs = rpc_config.max_past_logs;
1543+
let max_block_range = rpc_config.max_block_range;
15411544
let overrides = overrides.clone();
15421545
let fee_history_cache = fee_history_cache.clone();
15431546
let block_data_cache = block_data_cache.clone();
@@ -1559,6 +1562,7 @@ where
15591562
pool: pool.clone(),
15601563
is_authority: collator,
15611564
max_past_logs,
1565+
max_block_range,
15621566
fee_history_limit,
15631567
fee_history_cache: fee_history_cache.clone(),
15641568
network: network.clone(),

node/service/src/rpc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ pub struct FullDeps<C, P, A: ChainApi, BE> {
122122
pub command_sink: Option<futures::channel::mpsc::Sender<EngineCommand<Hash>>>,
123123
/// Maximum number of logs in a query.
124124
pub max_past_logs: u32,
125+
/// Maximum block range in a query.
126+
pub max_block_range: u32,
125127
/// Maximum fee history cache size.
126128
pub fee_history_limit: u64,
127129
/// Fee history cache.
@@ -195,6 +197,7 @@ where
195197
frontier_backend,
196198
backend: _,
197199
max_past_logs,
200+
max_block_range,
198201
fee_history_limit,
199202
fee_history_cache,
200203
dev_rpc_data,
@@ -275,6 +278,7 @@ where
275278
filter_pool,
276279
500_usize, // max stored filters
277280
max_past_logs,
281+
max_block_range,
278282
block_data_cache,
279283
)
280284
.into_rpc(),
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { beforeAll, customDevRpcRequest, describeSuite, expect } from "@moonwall/cli";
2+
3+
describeSuite({
4+
id: "T20",
5+
title: "Test eth_getLogs RPC",
6+
foundationMethods: "dev",
7+
testCases: ({ context, it }) => {
8+
beforeAll(async () => {
9+
// This variable needs to be modified if `--max-blocks-range` CLI parameter is changed
10+
// Using the default of 1024
11+
let blocksToCreate = 1025;
12+
for (; blocksToCreate > 0; blocksToCreate--) {
13+
await context.createBlock();
14+
}
15+
});
16+
17+
it({
18+
id: "T01",
19+
title: "Validate eth_getLogs block range limit",
20+
test: async function () {
21+
expect(
22+
async () =>
23+
await customDevRpcRequest("eth_getLogs", [
24+
{
25+
fromBlock: "0x0",
26+
toBlock: "latest",
27+
topics: [],
28+
},
29+
])
30+
).rejects.toThrowError("block range is too wide (maximum 1024)");
31+
},
32+
});
33+
},
34+
});

0 commit comments

Comments
 (0)