From 74242d5f4f6ca1842f92ae76e6e91bc05a159d56 Mon Sep 17 00:00:00 2001 From: Noa Moulin Date: Wed, 17 Apr 2024 13:51:48 +0200 Subject: [PATCH 1/7] deoxys-tui -> tui --- Cargo.toml | 2 +- crates/node/Cargo.toml | 2 +- crates/{deoxys-tui => tui}/.gitignore | 0 crates/{deoxys-tui => tui}/Cargo.lock | 0 crates/{deoxys-tui => tui}/Cargo.toml | 0 crates/{deoxys-tui => tui}/build.rs | 0 crates/{deoxys-tui => tui}/rustfmt.toml | 0 crates/{deoxys-tui => tui}/src/app.rs | 0 crates/{deoxys-tui => tui}/src/deoxys_ui.rs | 0 crates/{deoxys-tui => tui}/src/lib.rs | 0 crates/{deoxys-tui => tui}/src/logging.rs | 0 crates/{deoxys-tui => tui}/src/radar.rs | 0 crates/{deoxys-tui => tui}/src/ui/mod.rs | 0 crates/{deoxys-tui => tui}/src/ui/render.rs | 0 crates/{deoxys-tui => tui}/src/ui/widgets/cpu.rs | 0 crates/{deoxys-tui => tui}/src/ui/widgets/logs.rs | 0 crates/{deoxys-tui => tui}/src/ui/widgets/memory.rs | 0 crates/{deoxys-tui => tui}/src/ui/widgets/mod.rs | 0 crates/{deoxys-tui => tui}/src/ui/widgets/network.rs | 0 crates/{deoxys-tui => tui}/src/ui/widgets/storage.rs | 0 crates/{deoxys-tui => tui}/src/ui/widgets/syncing.rs | 0 crates/{deoxys-tui => tui}/src/ui/widgets/utils.rs | 0 crates/{deoxys-tui => tui}/substrate/mod.rs | 0 crates/{deoxys-tui => tui}/substrate/modifier.sh | 0 24 files changed, 2 insertions(+), 2 deletions(-) rename crates/{deoxys-tui => tui}/.gitignore (100%) rename crates/{deoxys-tui => tui}/Cargo.lock (100%) rename crates/{deoxys-tui => tui}/Cargo.toml (100%) rename crates/{deoxys-tui => tui}/build.rs (100%) rename crates/{deoxys-tui => tui}/rustfmt.toml (100%) rename crates/{deoxys-tui => tui}/src/app.rs (100%) rename crates/{deoxys-tui => tui}/src/deoxys_ui.rs (100%) rename crates/{deoxys-tui => tui}/src/lib.rs (100%) rename crates/{deoxys-tui => tui}/src/logging.rs (100%) rename crates/{deoxys-tui => tui}/src/radar.rs (100%) rename crates/{deoxys-tui => tui}/src/ui/mod.rs (100%) rename crates/{deoxys-tui => tui}/src/ui/render.rs (100%) rename crates/{deoxys-tui => tui}/src/ui/widgets/cpu.rs (100%) rename crates/{deoxys-tui => tui}/src/ui/widgets/logs.rs (100%) rename crates/{deoxys-tui => tui}/src/ui/widgets/memory.rs (100%) rename crates/{deoxys-tui => tui}/src/ui/widgets/mod.rs (100%) rename crates/{deoxys-tui => tui}/src/ui/widgets/network.rs (100%) rename crates/{deoxys-tui => tui}/src/ui/widgets/storage.rs (100%) rename crates/{deoxys-tui => tui}/src/ui/widgets/syncing.rs (100%) rename crates/{deoxys-tui => tui}/src/ui/widgets/utils.rs (100%) rename crates/{deoxys-tui => tui}/substrate/mod.rs (100%) rename crates/{deoxys-tui => tui}/substrate/modifier.sh (100%) diff --git a/Cargo.toml b/Cargo.toml index 0abfc7884..a6c03f60a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -247,7 +247,7 @@ mc-sync = { path = "crates/client/sync" } deoxys-runtime = { path = "crates/runtime" } # TUI Dashboard -deoxys-tui = { path = "crates/deoxys-tui" } +deoxys-tui = { path = "crates/tui" } # Starknet dependencies # Cairo Virtual Machine diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index 600603f29..2db2c0f33 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -99,7 +99,7 @@ mp-types = { workspace = true } try-runtime-cli = { optional = true, git = "https://github.com/massalabs/polkadot-sdk", branch = "release-polkadot-v1.3.0-std" } #Deoxys -deoxys-tui = { optional = true, path = "../deoxys-tui" } +deoxys-tui = { optional = true, path = "../tui" } mc-sync = { workspace = true } parity-scale-codec = { workspace = true, features = ["derive"] } reqwest = { workspace = true } diff --git a/crates/deoxys-tui/.gitignore b/crates/tui/.gitignore similarity index 100% rename from crates/deoxys-tui/.gitignore rename to crates/tui/.gitignore diff --git a/crates/deoxys-tui/Cargo.lock b/crates/tui/Cargo.lock similarity index 100% rename from crates/deoxys-tui/Cargo.lock rename to crates/tui/Cargo.lock diff --git a/crates/deoxys-tui/Cargo.toml b/crates/tui/Cargo.toml similarity index 100% rename from crates/deoxys-tui/Cargo.toml rename to crates/tui/Cargo.toml diff --git a/crates/deoxys-tui/build.rs b/crates/tui/build.rs similarity index 100% rename from crates/deoxys-tui/build.rs rename to crates/tui/build.rs diff --git a/crates/deoxys-tui/rustfmt.toml b/crates/tui/rustfmt.toml similarity index 100% rename from crates/deoxys-tui/rustfmt.toml rename to crates/tui/rustfmt.toml diff --git a/crates/deoxys-tui/src/app.rs b/crates/tui/src/app.rs similarity index 100% rename from crates/deoxys-tui/src/app.rs rename to crates/tui/src/app.rs diff --git a/crates/deoxys-tui/src/deoxys_ui.rs b/crates/tui/src/deoxys_ui.rs similarity index 100% rename from crates/deoxys-tui/src/deoxys_ui.rs rename to crates/tui/src/deoxys_ui.rs diff --git a/crates/deoxys-tui/src/lib.rs b/crates/tui/src/lib.rs similarity index 100% rename from crates/deoxys-tui/src/lib.rs rename to crates/tui/src/lib.rs diff --git a/crates/deoxys-tui/src/logging.rs b/crates/tui/src/logging.rs similarity index 100% rename from crates/deoxys-tui/src/logging.rs rename to crates/tui/src/logging.rs diff --git a/crates/deoxys-tui/src/radar.rs b/crates/tui/src/radar.rs similarity index 100% rename from crates/deoxys-tui/src/radar.rs rename to crates/tui/src/radar.rs diff --git a/crates/deoxys-tui/src/ui/mod.rs b/crates/tui/src/ui/mod.rs similarity index 100% rename from crates/deoxys-tui/src/ui/mod.rs rename to crates/tui/src/ui/mod.rs diff --git a/crates/deoxys-tui/src/ui/render.rs b/crates/tui/src/ui/render.rs similarity index 100% rename from crates/deoxys-tui/src/ui/render.rs rename to crates/tui/src/ui/render.rs diff --git a/crates/deoxys-tui/src/ui/widgets/cpu.rs b/crates/tui/src/ui/widgets/cpu.rs similarity index 100% rename from crates/deoxys-tui/src/ui/widgets/cpu.rs rename to crates/tui/src/ui/widgets/cpu.rs diff --git a/crates/deoxys-tui/src/ui/widgets/logs.rs b/crates/tui/src/ui/widgets/logs.rs similarity index 100% rename from crates/deoxys-tui/src/ui/widgets/logs.rs rename to crates/tui/src/ui/widgets/logs.rs diff --git a/crates/deoxys-tui/src/ui/widgets/memory.rs b/crates/tui/src/ui/widgets/memory.rs similarity index 100% rename from crates/deoxys-tui/src/ui/widgets/memory.rs rename to crates/tui/src/ui/widgets/memory.rs diff --git a/crates/deoxys-tui/src/ui/widgets/mod.rs b/crates/tui/src/ui/widgets/mod.rs similarity index 100% rename from crates/deoxys-tui/src/ui/widgets/mod.rs rename to crates/tui/src/ui/widgets/mod.rs diff --git a/crates/deoxys-tui/src/ui/widgets/network.rs b/crates/tui/src/ui/widgets/network.rs similarity index 100% rename from crates/deoxys-tui/src/ui/widgets/network.rs rename to crates/tui/src/ui/widgets/network.rs diff --git a/crates/deoxys-tui/src/ui/widgets/storage.rs b/crates/tui/src/ui/widgets/storage.rs similarity index 100% rename from crates/deoxys-tui/src/ui/widgets/storage.rs rename to crates/tui/src/ui/widgets/storage.rs diff --git a/crates/deoxys-tui/src/ui/widgets/syncing.rs b/crates/tui/src/ui/widgets/syncing.rs similarity index 100% rename from crates/deoxys-tui/src/ui/widgets/syncing.rs rename to crates/tui/src/ui/widgets/syncing.rs diff --git a/crates/deoxys-tui/src/ui/widgets/utils.rs b/crates/tui/src/ui/widgets/utils.rs similarity index 100% rename from crates/deoxys-tui/src/ui/widgets/utils.rs rename to crates/tui/src/ui/widgets/utils.rs diff --git a/crates/deoxys-tui/substrate/mod.rs b/crates/tui/substrate/mod.rs similarity index 100% rename from crates/deoxys-tui/substrate/mod.rs rename to crates/tui/substrate/mod.rs diff --git a/crates/deoxys-tui/substrate/modifier.sh b/crates/tui/substrate/modifier.sh similarity index 100% rename from crates/deoxys-tui/substrate/modifier.sh rename to crates/tui/substrate/modifier.sh From 5dac659300e22ecc622da46a774669fe7b92fd37 Mon Sep 17 00:00:00 2001 From: Noa Moulin Date: Wed, 17 Apr 2024 16:46:33 +0200 Subject: [PATCH 2/7] refactor get_events --- .../client/rpc/src/methods/read/get_events.rs | 59 +++++-------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/crates/client/rpc/src/methods/read/get_events.rs b/crates/client/rpc/src/methods/read/get_events.rs index c030c6e26..faaa8b4d7 100644 --- a/crates/client/rpc/src/methods/read/get_events.rs +++ b/crates/client/rpc/src/methods/read/get_events.rs @@ -81,19 +81,17 @@ where } let from_block = continuation_token.block_n; - let mut current_block = from_block; - let mut filtered_events: Vec = Vec::new(); - // Iterate on block range: TODO: stop using Cpp-like loops with mutation - while current_block <= to_block { - let emitted_events = if current_block <= latest_block { + for current_block in from_block..=to_block { + let block_filtered_events: Vec = if current_block <= latest_block { starknet.get_block_events(BlockId::Number(current_block))? } else { starknet.get_block_events(BlockId::Tag(BlockTag::Pending))? - }; - - let block_filtered_events: Vec = filter_events_by_params(emitted_events, from_address, &keys); + } + .into_iter() + .filter(|event| event_match_filter(event, from_address, &keys)) + .collect(); if current_block == from_block && (block_filtered_events.len() as u64) < continuation_token.event_n { return Err(StarknetRpcApiError::InvalidContinuationToken.into()); @@ -117,47 +115,18 @@ where return Ok(EventsPage { events: filtered_events, continuation_token: token }); } - - current_block += 1; } - Ok(EventsPage { events: filtered_events, continuation_token: None }) } -/// Helper function to get filter events using address and keys - -/// # Arguments -/// -/// * `events` - A vector of all events -/// * `address` - Address to use to filter the events -/// * `keys` - Keys to use to filter the events. An event is filtered if any key is present -/// * `max_results` - Optional, indicated the max events that need to be filtered -/// -/// # Returns -/// -/// * `(block_events: Vec, continuation_token: usize)` - A tuple of the filtered -/// events and the first index which still hasn't been processed block_id and an instance of Block -fn filter_events_by_params<'a, 'b: 'a>( - events: Vec, - address: Option, - keys: &'a [Vec], -) -> Vec { - let mut filtered_events = vec![]; - - // Iterate on block events. - for event in events { - let match_from_address = address.map_or(true, |addr| addr.0 == event.from_address); - // Based on https://github.com/starkware-libs/papyrus - let match_keys = keys - .iter() - .enumerate() - .all(|(i, keys)| event.keys.len() > i && (keys.is_empty() || keys.contains(&event.keys[i]))); - - if match_from_address && match_keys { - filtered_events.push(event); - } - } - filtered_events +#[inline] +fn event_match_filter(event: &EmittedEvent, address: Option, keys: &Vec>) -> bool { + let match_from_address = address.map_or(true, |addr| addr.0 == event.from_address); + let match_keys = keys + .iter() + .enumerate() + .all(|(i, keys)| event.keys.len() > i && (keys.is_empty() || keys.contains(&event.keys[i]))); + match_from_address && match_keys } fn block_range( From 20bc1b5a19f589522a80d19c0ffc053defc74a1c Mon Sep 17 00:00:00 2001 From: Noa Moulin Date: Fri, 19 Apr 2024 12:14:22 +0200 Subject: [PATCH 3/7] refactor get_events --- crates/client/rpc/src/events/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/client/rpc/src/events/mod.rs b/crates/client/rpc/src/events/mod.rs index bf9e9b4b0..755bb6b41 100644 --- a/crates/client/rpc/src/events/mod.rs +++ b/crates/client/rpc/src/events/mod.rs @@ -61,6 +61,7 @@ where } else { (Some(starknet_block.header().hash::().0), Some(starknet_block.header().block_number)) }; + let emitted_events = tx_hash_and_events .into_iter() .map(|(tx_hash, event)| EmittedEvent { @@ -72,7 +73,6 @@ where transaction_hash: tx_hash.0, }) .collect(); - Ok(emitted_events) } From 63ae78f776ecbb9efd65d029ac9fd9f321aa9655 Mon Sep 17 00:00:00 2001 From: Noa Moulin Date: Fri, 19 Apr 2024 18:07:45 +0200 Subject: [PATCH 4/7] refactor / optimise get_events --- crates/client/rpc/src/lib.rs | 6 +++--- crates/client/rpc/src/methods/read/lib.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/client/rpc/src/lib.rs b/crates/client/rpc/src/lib.rs index 8682db5b5..976a0b440 100644 --- a/crates/client/rpc/src/lib.rs +++ b/crates/client/rpc/src/lib.rs @@ -102,9 +102,9 @@ pub trait StarknetReadRpcApi { #[method(name = "call")] fn call(&self, request: FunctionCall, block_id: BlockId) -> RpcResult>; - // /// Get the chain id - // #[method(name = "chainId")] - // fn chain_id(&self) -> RpcResult; + /// Get the chain id + #[method(name = "chainId")] + fn chain_id(&self) -> RpcResult; /// Get the number of transactions in a block given a block id #[method(name = "getBlockTransactionCount")] diff --git a/crates/client/rpc/src/methods/read/lib.rs b/crates/client/rpc/src/methods/read/lib.rs index 205850a33..c094ffad6 100644 --- a/crates/client/rpc/src/methods/read/lib.rs +++ b/crates/client/rpc/src/methods/read/lib.rs @@ -66,9 +66,9 @@ where call(self, request, block_id) } - // fn chain_id(&self) -> RpcResult { - // chain_id(self) - // } + fn chain_id(&self) -> RpcResult { + self.chain_id() + } fn get_block_transaction_count(&self, block_id: BlockId) -> RpcResult { get_block_transaction_count(self, block_id) From 19bacba511f494a68163b2b08fadd5725c8bed65 Mon Sep 17 00:00:00 2001 From: Noa Moulin Date: Fri, 19 Apr 2024 18:25:05 +0200 Subject: [PATCH 5/7] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c6579f4a..091d03170 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ git # Deoxys Changelog ## Next release +- refactor: optimise get_events RPC - fix: fix implementation `get_storage_at()` for `BlockifierStateAdapter` - fix(sync): Fix end condition of the l2 sync - fix(rpc): fix chain id method for mainnet From 8ca01afd3be360a892b8471d86b0481e91ce556f Mon Sep 17 00:00:00 2001 From: Noa Moulin Date: Fri, 19 Apr 2024 18:37:45 +0200 Subject: [PATCH 6/7] fmt --- crates/client/rpc/src/events/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/client/rpc/src/events/mod.rs b/crates/client/rpc/src/events/mod.rs index 755bb6b41..c3e2b4a23 100644 --- a/crates/client/rpc/src/events/mod.rs +++ b/crates/client/rpc/src/events/mod.rs @@ -61,7 +61,7 @@ where } else { (Some(starknet_block.header().hash::().0), Some(starknet_block.header().block_number)) }; - + let emitted_events = tx_hash_and_events .into_iter() .map(|(tx_hash, event)| EmittedEvent { From 78b316a6affffc7d215677588f594f060aece794 Mon Sep 17 00:00:00 2001 From: Noa Moulin Date: Fri, 19 Apr 2024 19:04:53 +0200 Subject: [PATCH 7/7] clippy --- crates/client/rpc/src/methods/read/get_events.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/client/rpc/src/methods/read/get_events.rs b/crates/client/rpc/src/methods/read/get_events.rs index faaa8b4d7..865480100 100644 --- a/crates/client/rpc/src/methods/read/get_events.rs +++ b/crates/client/rpc/src/methods/read/get_events.rs @@ -120,7 +120,7 @@ where } #[inline] -fn event_match_filter(event: &EmittedEvent, address: Option, keys: &Vec>) -> bool { +fn event_match_filter(event: &EmittedEvent, address: Option, keys: &[Vec]) -> bool { let match_from_address = address.map_or(true, |addr| addr.0 == event.from_address); let match_keys = keys .iter()