From 2a3e4064b9978885af0299d39aa48ce7594a7c78 Mon Sep 17 00:00:00 2001 From: antiyro Date: Wed, 27 Mar 2024 17:07:33 +0100 Subject: [PATCH] fix: :zap: fix(latest): Retrieve latest synced block via internal client --- CHANGELOG.md | 1 + crates/client/sync/src/lib.rs | 6 +-- crates/client/sync/src/utils/utility.rs | 56 ------------------------- crates/node/src/commands/run.rs | 12 +----- crates/node/src/service.rs | 3 +- 5 files changed, 7 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f93756776..669c7e0e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ git # Deoxys Changelog ## Next release +- fix(latest): Retrieve latest synced block via internal client - perf(l2 sync): parallelize commitment computation and refactor part of l2 io sync - refactor: rpc methods and removed rpc-core - feat: add an optional TUI dashboard diff --git a/crates/client/sync/src/lib.rs b/crates/client/sync/src/lib.rs index 62e345dab..614780608 100644 --- a/crates/client/sync/src/lib.rs +++ b/crates/client/sync/src/lib.rs @@ -32,20 +32,20 @@ pub mod starknet_sync_worker { pub async fn sync( fetch_config: FetchConfig, sender_config: SenderConfig, - rpc_port: u16, l1_url: Url, client: Arc, + starting_block: u32, ) where C: HeaderBackend + 'static, { - let first_block = utility::get_last_synced_block(rpc_port).await + 1; + let starting_block = starting_block + 1; let _ = tokio::join!( l1::sync(l1_url.clone()), l2::sync( sender_config, fetch_config.clone(), - first_block, + starting_block.into(), DeoxysBackend::bonsai_contract(), DeoxysBackend::bonsai_storage(), DeoxysBackend::bonsai_class(), diff --git a/crates/client/sync/src/utils/utility.rs b/crates/client/sync/src/utils/utility.rs index c8a7c5b09..ad547e659 100644 --- a/crates/client/sync/src/utils/utility.rs +++ b/crates/client/sync/src/utils/utility.rs @@ -47,62 +47,6 @@ pub fn get_config() -> Result { // TODO: secure the auto calls here -/// Returns the block number of the last block (from Substrate). -pub async fn get_last_synced_block(rpc_port: u16) -> u64 { - let client = reqwest::Client::new(); - - let url = format!("http://localhost:{}/", rpc_port); - let request = serde_json::json!({ - "id": 1, - "jsonrpc": "2.0", - "method": "chain_getBlock", - "params": [] - }); - let payload = serde_json::to_vec(&request).unwrap(); - - let response: serde_json::Value = client - .post(&url) - .header(reqwest::header::CONTENT_TYPE, "application/json") - .header(reqwest::header::ACCEPT, "application/json") - .body(payload) - .send() - .await - .unwrap() - .json() - .await - .unwrap(); - - let number_as_hex = response["result"]["block"]["header"]["number"].as_str().unwrap(); - u64::from_str_radix(&number_as_hex[2..], 16).unwrap() -} - -/// Returns the block hash for a given block number (from Substrate). -pub async fn get_block_hash_by_number(rpc_port: u16, block_number: u64) -> Option { - let client = reqwest::Client::new(); - - let url = format!("http://localhost:{}/", rpc_port); - let request = serde_json::json!({ - "id": 1, - "jsonrpc": "2.0", - "method": "chain_getBlockHash", - "params": [block_number] - }); - let payload = serde_json::to_vec(&request).unwrap(); - let response: serde_json::Value = client - .post(&url) - .header(reqwest::header::CONTENT_TYPE, "application/json") - .header(reqwest::header::ACCEPT, "application/json") - .body(payload) - .send() - .await - .unwrap() - .json() - .await - .unwrap(); - - response["result"].as_str().map(String::from) -} - pub async fn get_state_update_at(rpc_port: u16, block_number: u64) -> Result> { let client = reqwest::Client::new(); let url = format!("http://localhost:{}", rpc_port); diff --git a/crates/node/src/commands/run.rs b/crates/node/src/commands/run.rs index 6a58cc62d..9d84d861a 100644 --- a/crates/node/src/commands/run.rs +++ b/crates/node/src/commands/run.rs @@ -174,16 +174,8 @@ pub fn run_node(mut cli: Cli) -> Result<()> { let genesis_block = fetch_apply_genesis_block(fetch_block_config.clone()).await.unwrap(); - service::new_full( - config, - sealing, - cli.run.base.rpc_port.unwrap(), - l1_endpoint, - cache, - fetch_block_config, - genesis_block, - ) - .map_err(sc_cli::Error::Service) + service::new_full(config, sealing, l1_endpoint, cache, fetch_block_config, genesis_block) + .map_err(sc_cli::Error::Service) }) } diff --git a/crates/node/src/service.rs b/crates/node/src/service.rs index c9ce4a10b..91f1ee1e6 100644 --- a/crates/node/src/service.rs +++ b/crates/node/src/service.rs @@ -276,7 +276,6 @@ where pub fn new_full( config: Configuration, sealing: SealingMode, - rpc_port: u16, l1_url: Url, cache_more_things: bool, fetch_config: FetchConfig, @@ -440,7 +439,7 @@ pub fn new_full( task_manager.spawn_essential_handle().spawn( "starknet-sync-worker", Some("madara"), - starknet_sync_worker::sync(fetch_config, sender_config, rpc_port, l1_url, Arc::clone(&client)), + starknet_sync_worker::sync(fetch_config, sender_config, l1_url, Arc::clone(&client), starting_block), ); // manual-seal authorship