From 6ea3654e21ca6728874c466ad895dc7ce17fd1b8 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 5 May 2025 14:01:25 +0200 Subject: [PATCH 1/5] Remove async_trait --- Cargo.toml | 15 +++-- src/evm-block-extractor/Cargo.toml | 1 - src/evm-block-extractor/src/config.rs | 3 +- src/evm-block-extractor/src/database/mod.rs | 55 ++++++++++--------- .../src/database/postgres_db_client.rs | 1 - src/evm-block-extractor/src/rpc.rs | 34 +++++++++--- src/evm-block-extractor/src/server.rs | 4 +- .../src/task/block_extractor.rs | 22 ++++---- .../tests/evm_block_extractor_it.rs | 6 +- .../tests/tests/block_extractor_it.rs | 2 +- .../tests/tests/database_client_it.rs | 4 +- .../tests/tests/server_it.rs | 7 ++- src/evm-log-extractor/Cargo.toml | 1 - .../tests/evm_log_extractor_it.rs | 1 - 14 files changed, 85 insertions(+), 71 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9fd161db..782d5286 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ alloy = { version = "0.15", default-features = false, features = [ "serde", ] } anyhow = "1.0" -async-trait = "0.1" bincode = "1.3" bytes = "1" candid = "0.10" @@ -52,14 +51,14 @@ chrono = { version = "0.4", default-features = false } derive_more = { version = "2", features = ["display", "from", "into"] } env_logger = { version = "0.11.4", default-features = false } futures = { version = "0.3", default-features = false } -ic-canister = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister", tag = "v0.24.x" } -ic-canister-client = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister-client", tag = "v0.24.x" } -ic-exports = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-exports", tag = "v0.24.x" } -ic-log = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-log", tag = "v0.24.x" } -ic-stable-structures = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-stable-structures", tag = "v0.24.x" } +ic-canister = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister", branch = "remove_async_trati" } +ic-canister-client = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister-client", branch = "remove_async_trati" } +ic-exports = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-exports", branch = "remove_async_trati" } +ic-log = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-log", branch = "remove_async_trati" } +ic-stable-structures = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-stable-structures", branch = "remove_async_trati" } itertools = "0.14" jsonrpsee = { version = "0.25", features = ["server", "macros"] } -lightspeed_scheduler = "0.63" +lightspeed_scheduler = "0.64" log = "0.4" num = "0.4" port_check = "0.2" @@ -80,7 +79,7 @@ sqlx = { version = "0.8.1", default-features = false, features = [ "runtime-tokio", ] } tempfile = "3" -testcontainers = { package = "testcontainers-modules", version = "0.11", features = [ +testcontainers = { package = "testcontainers-modules", version = "0.12", features = [ "postgres", ] } thiserror = "2.0" diff --git a/src/evm-block-extractor/Cargo.toml b/src/evm-block-extractor/Cargo.toml index c7e40cb3..8c869c54 100644 --- a/src/evm-block-extractor/Cargo.toml +++ b/src/evm-block-extractor/Cargo.toml @@ -12,7 +12,6 @@ repository.workspace = true [dependencies] alloy = { workspace = true } anyhow = { workspace = true } -async-trait = { workspace = true } chrono = { workspace = true } clap = { workspace = true } did = { workspace = true } diff --git a/src/evm-block-extractor/src/config.rs b/src/evm-block-extractor/src/config.rs index 0da6ac84..b3bb67e9 100644 --- a/src/evm-block-extractor/src/config.rs +++ b/src/evm-block-extractor/src/config.rs @@ -4,7 +4,6 @@ use clap::{Parser, Subcommand}; use sqlx::PgPool; use sqlx::postgres::{PgConnectOptions, PgSslMode}; -use crate::database::DatabaseClient; use crate::database::postgres_db_client::PostgresDbClient; const VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -78,7 +77,7 @@ pub enum Database { impl Database { /// Build a database client based on the database type - pub async fn build_client(self) -> anyhow::Result> { + pub async fn build_client(self) -> anyhow::Result> { match self { Database::Postgres { username, diff --git a/src/evm-block-extractor/src/database/mod.rs b/src/evm-block-extractor/src/database/mod.rs index ab0c213f..a027d0a7 100644 --- a/src/evm-block-extractor/src/database/mod.rs +++ b/src/evm-block-extractor/src/database/mod.rs @@ -35,75 +35,76 @@ const BLOCKCHAIN_BLOCK_INFO_KEY: &str = "blockchain_block_info"; pub type CertifiedBlock = CertifiedResult>; /// A trait for interacting with a blockchain database -#[async_trait::async_trait] pub trait DatabaseClient: Send + Sync { /// Initialize the database - async fn init(&self, block: Option>, reset_database: bool) -> anyhow::Result<()>; + fn init(&self, block: Option>, reset_database: bool) -> impl Future> + Send; /// Delete/clear the tables - async fn clear(&self) -> anyhow::Result<()>; + fn clear(&self) -> impl Future> + Send; /// Returns whether the block hash corresponds to the one in the db - async fn check_if_same_block_hash(&self, block: &Block) -> anyhow::Result { - let block_number = block.number.0.to(); - let block_in_db = self.get_block_by_number(block_number).await?; - Ok(block.hash == block_in_db.hash) + fn check_if_same_block_hash(&self, block: &Block) -> impl Future> + Send { + async { + let block_number = block.number.0.to(); + let block_in_db = self.get_block_by_number(block_number).await?; + Ok(block.hash == block_in_db.hash) + } } /// Get a block from the database - async fn get_block_by_number(&self, block_number: u64) -> anyhow::Result>; + fn get_block_by_number(&self, block_number: u64) -> impl Future>> + Send; /// Get a block from the database - async fn get_full_block_by_number( + fn get_full_block_by_number( &self, block_number: u64, - ) -> anyhow::Result>; + ) -> impl Future>> + Send; /// Insert block data; this includes transactions and the blocks - async fn insert_block_data( + fn insert_block_data( &self, blocks: &[Block], transactions: &[Transaction], - ) -> anyhow::Result<()>; + ) -> impl Future> + Send; /// Insert certified block data - async fn insert_certified_block_data(&self, response: CertifiedBlock) -> anyhow::Result<()>; + fn insert_certified_block_data(&self, response: CertifiedBlock) -> impl Future> + Send; /// Returns certified response for the last block - async fn get_last_certified_block_data(&self) -> anyhow::Result; + fn get_last_certified_block_data(&self) -> impl Future> + Send; /// Get genesis balances - async fn get_genesis_balances(&self) -> anyhow::Result>>; + fn get_genesis_balances(&self) -> impl Future>>> + Send; /// Insert genesis balances - async fn insert_genesis_balances( + fn insert_genesis_balances( &self, genesis_balances: &[AccountBalance], - ) -> anyhow::Result<()>; + ) -> impl Future> + Send; /// Get chain id - async fn get_chain_id(&self) -> anyhow::Result>; + fn get_chain_id(&self) -> impl Future>> + Send; /// Insert chain_id - async fn insert_chain_id(&self, chain_id: u64) -> anyhow::Result<()>; + fn insert_chain_id(&self, chain_id: u64) -> impl Future> + Send; /// Get a transaction from the database - async fn get_transaction(&self, tx_hash: H256) -> anyhow::Result; + fn get_transaction(&self, tx_hash: H256) -> impl Future> + Send; /// Get the latest block number - async fn get_latest_block_number(&self) -> anyhow::Result>; + fn get_latest_block_number(&self) -> impl Future>> + Send; /// Get earliest block number - async fn get_earliest_block_number(&self) -> anyhow::Result; + fn get_earliest_block_number(&self) -> impl Future> + Send; /// Delete latest blocks starting with `start_from`, and related transactions. /// Deleted blocks and transactions will be preserved in 'discarded' table with /// the given 'reason' and timestamp. - async fn discard_blocks_from(&self, start_from: u64, reason: &str) -> anyhow::Result<()>; + fn discard_blocks_from(&self, start_from: u64, reason: &str) -> impl Future> + Send; /// Returns a discarded block by its hash. - async fn get_discarded_block_by_hash(&self, block_hash: H256) - -> anyhow::Result; + fn get_discarded_block_by_hash(&self, block_hash: H256) + -> impl Future> + Send; /// Returns block info from storage. /// @@ -115,10 +116,10 @@ pub trait DatabaseClient: Send + Sync { /// - safe_block_number: u64, /// - finalized_block_number: u64, /// - pending_block_number: u64, - async fn get_block_info(&self) -> anyhow::Result>; + fn get_block_info(&self) -> impl Future>> + Send; /// Stores blockchain block info. - async fn set_block_info(&self, info: BlockchainBlockInfo) -> anyhow::Result<()>; + fn set_block_info(&self, info: BlockchainBlockInfo) -> impl Future> + Send; } /// Discarded block with metadata. diff --git a/src/evm-block-extractor/src/database/postgres_db_client.rs b/src/evm-block-extractor/src/database/postgres_db_client.rs index e048c610..783578db 100644 --- a/src/evm-block-extractor/src/database/postgres_db_client.rs +++ b/src/evm-block-extractor/src/database/postgres_db_client.rs @@ -71,7 +71,6 @@ impl PostgresDbClient { } } -#[async_trait::async_trait] impl DatabaseClient for PostgresDbClient { async fn init(&self, block: Option>, reset_database: bool) -> anyhow::Result<()> { MIGRATOR.run(&self.pool).await?; diff --git a/src/evm-block-extractor/src/rpc.rs b/src/evm-block-extractor/src/rpc.rs index 26804802..bb94099b 100644 --- a/src/evm-block-extractor/src/rpc.rs +++ b/src/evm-block-extractor/src/rpc.rs @@ -11,21 +11,35 @@ use jsonrpsee::types::{ErrorCode, ErrorObject}; use crate::database::{CertifiedBlock, DatabaseClient}; -#[derive(Clone)] -pub struct EthImpl +pub struct EthImpl where + DB: DatabaseClient, C: Client + Send + Sync + 'static, { - pub blockchain: Arc, + pub blockchain: Arc, pub evm_client: Arc>, } -impl EthImpl +impl Clone for EthImpl where + DB: DatabaseClient, + C: Client + Send + Sync + 'static, + { + fn clone(&self) -> Self { + Self { + blockchain: self.blockchain.clone(), + evm_client: self.evm_client.clone(), + } + } +} + +impl EthImpl +where + DB: DatabaseClient, C: Client + Send + Sync + 'static, { pub fn new( - db: Arc, + db: Arc, evm_client: Arc>, ) -> Self { Self { @@ -74,9 +88,10 @@ pub trait IC { ) -> RpcResult; } -#[async_trait::async_trait] -impl ICServer for EthImpl +#[jsonrpsee::core::async_trait] +impl ICServer for EthImpl where + DB: DatabaseClient + Send + Sync + 'static, C: Client + Send + Sync + 'static, { async fn get_genesis_balances(&self) -> RpcResult> { @@ -143,9 +158,10 @@ where } } -#[async_trait::async_trait] -impl EthServer for EthImpl +#[jsonrpsee::core::async_trait] +impl EthServer for EthImpl where + DB: DatabaseClient + Send + Sync + 'static, C: Client + Send + Sync + 'static, { async fn get_block_by_number( diff --git a/src/evm-block-extractor/src/server.rs b/src/evm-block-extractor/src/server.rs index dc70f510..1a4277d2 100644 --- a/src/evm-block-extractor/src/server.rs +++ b/src/evm-block-extractor/src/server.rs @@ -9,9 +9,9 @@ use crate::database::DatabaseClient; use crate::rpc::{EthImpl, EthServer, ICServer}; /// Start the RPC server -pub async fn server_start( +pub async fn server_start( server_address: &str, - db_client: Arc, + db_client: Arc, evm_client: Arc>, ) -> anyhow::Result { info!("Start server"); diff --git a/src/evm-block-extractor/src/task/block_extractor.rs b/src/evm-block-extractor/src/task/block_extractor.rs index 02012759..7b03a65a 100644 --- a/src/evm-block-extractor/src/task/block_extractor.rs +++ b/src/evm-block-extractor/src/task/block_extractor.rs @@ -10,9 +10,9 @@ use crate::config::ExtractorArgs; use crate::database::{AccountBalance, CertifiedBlock, DatabaseClient}; /// Starts the block extractor process -pub async fn start_extractor( +pub async fn start_extractor( config: ExtractorArgs, - db_client: Arc, + db_client: Arc, evm_client: Arc>, ) -> anyhow::Result<()> { let earliest_block = evm_client @@ -44,11 +44,11 @@ pub async fn start_extractor( } /// Extracts blocks from an EVMC and stores them in a database -pub struct BlockExtractor { +pub struct BlockExtractor { client: Arc>, request_time_out_secs: u64, rpc_batch_size: usize, - blockchain: Arc, + blockchain: Arc, } /// Outcome of the block extraction process @@ -60,12 +60,12 @@ pub enum BlockExtractCollectOutcome { BlocksExtracted { from_block: u64, to_block: u64 }, } -impl BlockExtractor { +impl BlockExtractor { pub fn new( client: Arc>, request_time_out_secs: u64, rpc_batch_size: usize, - blockchain: Arc, + blockchain: Arc, ) -> Self { Self { client, @@ -366,13 +366,15 @@ mod tests { use did::keccak; use ethereum_json_rpc_client::reqwest::ReqwestClient; + use crate::database::postgres_db_client::PostgresDbClient; + use super::*; #[test] fn test_validate_chain_without_blocks_in_storage() { let latest_block_in_storage = Option::>::None; let sequence = generate_valid_blocks_sequence(10, did::H256::default()); - BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) + BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) .unwrap(); } @@ -384,7 +386,7 @@ mod tests { let hash = block.hash.clone(); let latest_block_in_storage = Some(block); let sequence = generate_valid_blocks_sequence(10, hash); - BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) + BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) .unwrap(); } @@ -397,7 +399,7 @@ mod tests { let invalid_parent_hash = keccak::keccak_hash(&[1, 2, 3]); let sequence = generate_valid_blocks_sequence(10, invalid_parent_hash); let err = - BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) + BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) .unwrap_err(); assert!(matches!(err, ChainError::InconsistentStorage)) } @@ -415,7 +417,7 @@ mod tests { sequence[5].parent_hash = keccak::keccak_hash(&[1, 2, 3, 4]); let err = - BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) + BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) .unwrap_err(); assert!(matches!(err, ChainError::InconsistentSequence)) } diff --git a/src/evm-block-extractor/tests/evm_block_extractor_it.rs b/src/evm-block-extractor/tests/evm_block_extractor_it.rs index ab8cac8e..91d19091 100644 --- a/src/evm-block-extractor/tests/evm_block_extractor_it.rs +++ b/src/evm-block-extractor/tests/evm_block_extractor_it.rs @@ -1,13 +1,13 @@ use std::sync::Arc; use evm_block_extractor::config::Database; -use evm_block_extractor::database::DatabaseClient; +use evm_block_extractor::database::postgres_db_client::PostgresDbClient; use testcontainers::testcontainers::ContainerAsync; use testcontainers::testcontainers::runners::AsyncRunner; mod tests; -async fn test_with_clients) -> ()>(test: T) { +async fn test_with_clients) -> ()>(test: T) { let _ = env_logger::Builder::new().parse_filters("info").try_init(); println!("----------------------------------"); println!("Running test with PostgresDbClient"); @@ -17,7 +17,7 @@ async fn test_with_clients) -> ()>(test: T) { } async fn new_postgres_db_client() -> ( - Arc, + Arc, ContainerAsync, ) { let node = testcontainers::postgres::Postgres::default() diff --git a/src/evm-block-extractor/tests/tests/block_extractor_it.rs b/src/evm-block-extractor/tests/tests/block_extractor_it.rs index 1092c43e..30d4e6d8 100644 --- a/src/evm-block-extractor/tests/tests/block_extractor_it.rs +++ b/src/evm-block-extractor/tests/tests/block_extractor_it.rs @@ -15,7 +15,7 @@ use did::{ }; use ethereum_json_rpc_client::reqwest::ReqwestClient; use ethereum_json_rpc_client::{CertifiedResult, Client, EthJsonRpcClient, JsonRpcResult}; -use evm_block_extractor::database::AccountBalance; +use evm_block_extractor::database::{AccountBalance, DatabaseClient}; use evm_block_extractor::server; use evm_block_extractor::task::block_extractor::{BlockExtractCollectOutcome, BlockExtractor}; use serde::de::DeserializeOwned; diff --git a/src/evm-block-extractor/tests/tests/database_client_it.rs b/src/evm-block-extractor/tests/tests/database_client_it.rs index ad1e6d93..037ddf3d 100644 --- a/src/evm-block-extractor/tests/tests/database_client_it.rs +++ b/src/evm-block-extractor/tests/tests/database_client_it.rs @@ -1,5 +1,5 @@ use did::{Block, H160, H256, Transaction, U64, U256}; -use evm_block_extractor::database::{AccountBalance, CertifiedBlock, DatabaseClient}; +use evm_block_extractor::database::{postgres_db_client::PostgresDbClient, AccountBalance, CertifiedBlock, DatabaseClient}; use rand::random; use crate::test_with_clients; @@ -715,7 +715,7 @@ async fn test_blockchain_tail_discard_and_get_discarded_entries() { } async fn check_blocks_with_txs_storage_state( - db_client: &dyn DatabaseClient, + db_client: &PostgresDbClient, blocks: &[Block], storage_state: StorageState, ) -> bool { diff --git a/src/evm-block-extractor/tests/tests/server_it.rs b/src/evm-block-extractor/tests/tests/server_it.rs index 60a5ac5e..352d996f 100644 --- a/src/evm-block-extractor/tests/tests/server_it.rs +++ b/src/evm-block-extractor/tests/tests/server_it.rs @@ -10,6 +10,7 @@ use did::rpc::version::Version; use did::{Block, BlockNumber, H160, H256, U64, U256}; use ethereum_json_rpc_client::reqwest::ReqwestClient; use ethereum_json_rpc_client::{Client, EthJsonRpcClient}; +use evm_block_extractor::database::postgres_db_client::PostgresDbClient; use evm_block_extractor::database::{AccountBalance, CertifiedBlock, DatabaseClient}; use evm_block_extractor::rpc::{EthImpl, EthServer, ICServer}; use jsonrpsee::RpcModule; @@ -22,7 +23,7 @@ use crate::tests::block_extractor_it::MockClient; const BLOCK_COUNT: u64 = 10; -async fn with_filled_db) -> ()>(func: Func) { +async fn with_filled_db) -> ()>(func: Func) { test_with_clients(async |db_client| { db_client.init(None, false).await.unwrap(); @@ -346,7 +347,7 @@ async fn test_get_evm_global_state() { } async fn new_server( - db_client: Arc, + db_client: Arc, evm_client: Option>>, ) -> (EthJsonRpcClient, u16, ServerHandle) { let evm_client = evm_client.unwrap_or_else(|| { @@ -355,7 +356,7 @@ async fn new_server( ))) }); - let eth = EthImpl::::new(db_client, evm_client); + let eth = EthImpl::::new(db_client, evm_client); let mut module = RpcModule::new(()); module.merge(EthServer::into_rpc(eth.clone())).unwrap(); module.merge(ICServer::into_rpc(eth)).unwrap(); diff --git a/src/evm-log-extractor/Cargo.toml b/src/evm-log-extractor/Cargo.toml index 21dcf994..111a1c85 100644 --- a/src/evm-log-extractor/Cargo.toml +++ b/src/evm-log-extractor/Cargo.toml @@ -21,7 +21,6 @@ log = { workspace = true } tokio = { workspace = true } [dev-dependencies] -async-trait = { workspace = true } candid = { workspace = true } rand = { workspace = true } serde = { workspace = true } diff --git a/src/evm-log-extractor/tests/evm_log_extractor_it.rs b/src/evm-log-extractor/tests/evm_log_extractor_it.rs index 4ce2e63f..ee225385 100644 --- a/src/evm-log-extractor/tests/evm_log_extractor_it.rs +++ b/src/evm-log-extractor/tests/evm_log_extractor_it.rs @@ -14,7 +14,6 @@ struct MockCanisterClient { max_logs: usize, } -#[async_trait::async_trait] impl CanisterClient for MockCanisterClient { async fn update(&self, _method: &str, _args: T) -> CanisterClientResult where From 322639b732215bba0cc53beb2d4579b335600efb Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 5 May 2025 14:01:37 +0200 Subject: [PATCH 2/5] fmt --- src/evm-block-extractor/src/database/mod.rs | 71 +++++++++++++------ src/evm-block-extractor/src/rpc.rs | 9 +-- .../src/task/block_extractor.rs | 33 +++++---- .../tests/tests/database_client_it.rs | 3 +- 4 files changed, 77 insertions(+), 39 deletions(-) diff --git a/src/evm-block-extractor/src/database/mod.rs b/src/evm-block-extractor/src/database/mod.rs index a027d0a7..f4175b49 100644 --- a/src/evm-block-extractor/src/database/mod.rs +++ b/src/evm-block-extractor/src/database/mod.rs @@ -37,13 +37,20 @@ pub type CertifiedBlock = CertifiedResult>; /// A trait for interacting with a blockchain database pub trait DatabaseClient: Send + Sync { /// Initialize the database - fn init(&self, block: Option>, reset_database: bool) -> impl Future> + Send; + fn init( + &self, + block: Option>, + reset_database: bool, + ) -> impl Future> + Send; /// Delete/clear the tables - fn clear(&self) -> impl Future> + Send; + fn clear(&self) -> impl Future> + Send; /// Returns whether the block hash corresponds to the one in the db - fn check_if_same_block_hash(&self, block: &Block) -> impl Future> + Send { + fn check_if_same_block_hash( + &self, + block: &Block, + ) -> impl Future> + Send { async { let block_number = block.number.0.to(); let block_in_db = self.get_block_by_number(block_number).await?; @@ -52,59 +59,78 @@ pub trait DatabaseClient: Send + Sync { } /// Get a block from the database - fn get_block_by_number(&self, block_number: u64) -> impl Future>> + Send; + fn get_block_by_number( + &self, + block_number: u64, + ) -> impl Future>> + Send; /// Get a block from the database - fn get_full_block_by_number( + fn get_full_block_by_number( &self, block_number: u64, ) -> impl Future>> + Send; /// Insert block data; this includes transactions and the blocks - fn insert_block_data( + fn insert_block_data( &self, blocks: &[Block], transactions: &[Transaction], ) -> impl Future> + Send; /// Insert certified block data - fn insert_certified_block_data(&self, response: CertifiedBlock) -> impl Future> + Send; + fn insert_certified_block_data( + &self, + response: CertifiedBlock, + ) -> impl Future> + Send; /// Returns certified response for the last block - fn get_last_certified_block_data(&self) -> impl Future> + Send; + fn get_last_certified_block_data( + &self, + ) -> impl Future> + Send; /// Get genesis balances - fn get_genesis_balances(&self) -> impl Future>>> + Send; + fn get_genesis_balances( + &self, + ) -> impl Future>>> + Send; /// Insert genesis balances - fn insert_genesis_balances( + fn insert_genesis_balances( &self, genesis_balances: &[AccountBalance], ) -> impl Future> + Send; /// Get chain id - fn get_chain_id(&self) -> impl Future>> + Send; + fn get_chain_id(&self) -> impl Future>> + Send; /// Insert chain_id - fn insert_chain_id(&self, chain_id: u64) -> impl Future> + Send; + fn insert_chain_id(&self, chain_id: u64) -> impl Future> + Send; /// Get a transaction from the database - fn get_transaction(&self, tx_hash: H256) -> impl Future> + Send; + fn get_transaction( + &self, + tx_hash: H256, + ) -> impl Future> + Send; /// Get the latest block number - fn get_latest_block_number(&self) -> impl Future>> + Send; + fn get_latest_block_number(&self) -> impl Future>> + Send; /// Get earliest block number - fn get_earliest_block_number(&self) -> impl Future> + Send; + fn get_earliest_block_number(&self) -> impl Future> + Send; /// Delete latest blocks starting with `start_from`, and related transactions. /// Deleted blocks and transactions will be preserved in 'discarded' table with /// the given 'reason' and timestamp. - fn discard_blocks_from(&self, start_from: u64, reason: &str) -> impl Future> + Send; + fn discard_blocks_from( + &self, + start_from: u64, + reason: &str, + ) -> impl Future> + Send; /// Returns a discarded block by its hash. - fn get_discarded_block_by_hash(&self, block_hash: H256) - -> impl Future> + Send; + fn get_discarded_block_by_hash( + &self, + block_hash: H256, + ) -> impl Future> + Send; /// Returns block info from storage. /// @@ -116,10 +142,15 @@ pub trait DatabaseClient: Send + Sync { /// - safe_block_number: u64, /// - finalized_block_number: u64, /// - pending_block_number: u64, - fn get_block_info(&self) -> impl Future>> + Send; + fn get_block_info( + &self, + ) -> impl Future>> + Send; /// Stores blockchain block info. - fn set_block_info(&self, info: BlockchainBlockInfo) -> impl Future> + Send; + fn set_block_info( + &self, + info: BlockchainBlockInfo, + ) -> impl Future> + Send; } /// Discarded block with metadata. diff --git a/src/evm-block-extractor/src/rpc.rs b/src/evm-block-extractor/src/rpc.rs index bb94099b..e3503a56 100644 --- a/src/evm-block-extractor/src/rpc.rs +++ b/src/evm-block-extractor/src/rpc.rs @@ -20,11 +20,11 @@ where pub evm_client: Arc>, } -impl Clone for EthImpl +impl Clone for EthImpl where DB: DatabaseClient, C: Client + Send + Sync + 'static, - { +{ fn clone(&self) -> Self { Self { blockchain: self.blockchain.clone(), @@ -38,10 +38,7 @@ where DB: DatabaseClient, C: Client + Send + Sync + 'static, { - pub fn new( - db: Arc, - evm_client: Arc>, - ) -> Self { + pub fn new(db: Arc, evm_client: Arc>) -> Self { Self { blockchain: db, evm_client, diff --git a/src/evm-block-extractor/src/task/block_extractor.rs b/src/evm-block-extractor/src/task/block_extractor.rs index 7b03a65a..95d6ad93 100644 --- a/src/evm-block-extractor/src/task/block_extractor.rs +++ b/src/evm-block-extractor/src/task/block_extractor.rs @@ -366,16 +366,18 @@ mod tests { use did::keccak; use ethereum_json_rpc_client::reqwest::ReqwestClient; - use crate::database::postgres_db_client::PostgresDbClient; - use super::*; + use crate::database::postgres_db_client::PostgresDbClient; #[test] fn test_validate_chain_without_blocks_in_storage() { let latest_block_in_storage = Option::>::None; let sequence = generate_valid_blocks_sequence(10, did::H256::default()); - BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) - .unwrap(); + BlockExtractor::::validate_chain( + latest_block_in_storage, + &sequence, + ) + .unwrap(); } #[test] @@ -386,8 +388,11 @@ mod tests { let hash = block.hash.clone(); let latest_block_in_storage = Some(block); let sequence = generate_valid_blocks_sequence(10, hash); - BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) - .unwrap(); + BlockExtractor::::validate_chain( + latest_block_in_storage, + &sequence, + ) + .unwrap(); } #[test] @@ -398,9 +403,11 @@ mod tests { let latest_block_in_storage = Some(block); let invalid_parent_hash = keccak::keccak_hash(&[1, 2, 3]); let sequence = generate_valid_blocks_sequence(10, invalid_parent_hash); - let err = - BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) - .unwrap_err(); + let err = BlockExtractor::::validate_chain( + latest_block_in_storage, + &sequence, + ) + .unwrap_err(); assert!(matches!(err, ChainError::InconsistentStorage)) } @@ -416,9 +423,11 @@ mod tests { // break the sequnce sequence[5].parent_hash = keccak::keccak_hash(&[1, 2, 3, 4]); - let err = - BlockExtractor::::validate_chain(latest_block_in_storage, &sequence) - .unwrap_err(); + let err = BlockExtractor::::validate_chain( + latest_block_in_storage, + &sequence, + ) + .unwrap_err(); assert!(matches!(err, ChainError::InconsistentSequence)) } diff --git a/src/evm-block-extractor/tests/tests/database_client_it.rs b/src/evm-block-extractor/tests/tests/database_client_it.rs index 037ddf3d..8bcde775 100644 --- a/src/evm-block-extractor/tests/tests/database_client_it.rs +++ b/src/evm-block-extractor/tests/tests/database_client_it.rs @@ -1,5 +1,6 @@ use did::{Block, H160, H256, Transaction, U64, U256}; -use evm_block_extractor::database::{postgres_db_client::PostgresDbClient, AccountBalance, CertifiedBlock, DatabaseClient}; +use evm_block_extractor::database::postgres_db_client::PostgresDbClient; +use evm_block_extractor::database::{AccountBalance, CertifiedBlock, DatabaseClient}; use rand::random; use crate::test_with_clients; From 601a0bae3f29612142c41516b73acb47da647457 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 5 May 2025 14:02:25 +0200 Subject: [PATCH 3/5] clippy --- src/evm-block-extractor/tests/tests/database_client_it.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/evm-block-extractor/tests/tests/database_client_it.rs b/src/evm-block-extractor/tests/tests/database_client_it.rs index 8bcde775..30a5fab2 100644 --- a/src/evm-block-extractor/tests/tests/database_client_it.rs +++ b/src/evm-block-extractor/tests/tests/database_client_it.rs @@ -676,7 +676,7 @@ async fn test_blockchain_tail_discard_and_get_discarded_entries() { assert!( check_blocks_with_txs_storage_state( - &*db_client, + &db_client, &blocks[..FIRST_REMOVED_BLOCK as usize - 1], StorageState::Present, ) @@ -685,7 +685,7 @@ async fn test_blockchain_tail_discard_and_get_discarded_entries() { assert!( check_blocks_with_txs_storage_state( - &*db_client, + &db_client, &blocks[FIRST_REMOVED_BLOCK as usize - 1..], StorageState::NotPresent, ) From 66312c9a907a93973c25f41e18b15eadb0e5de43 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 5 May 2025 14:51:42 +0200 Subject: [PATCH 4/5] update resolver --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 782d5286..457e9fca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ members = [ "src/evm-log-extractor", "src/signature-verification-canister-client", ] -resolver = "2" +resolver = "3" [workspace.package] authors = ["Bitfinity Network"] From df720e7fb0af8f15b4158c5b54733b251d73c368 Mon Sep 17 00:00:00 2001 From: Francesco Date: Tue, 6 May 2025 09:43:18 +0200 Subject: [PATCH 5/5] update canister-sdk --- Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 457e9fca..4c1062c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,11 +51,11 @@ chrono = { version = "0.4", default-features = false } derive_more = { version = "2", features = ["display", "from", "into"] } env_logger = { version = "0.11.4", default-features = false } futures = { version = "0.3", default-features = false } -ic-canister = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister", branch = "remove_async_trati" } -ic-canister-client = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister-client", branch = "remove_async_trati" } -ic-exports = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-exports", branch = "remove_async_trati" } -ic-log = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-log", branch = "remove_async_trati" } -ic-stable-structures = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-stable-structures", branch = "remove_async_trati" } +ic-canister = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister", tag = "v0.24.x" } +ic-canister-client = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister-client", tag = "v0.24.x" } +ic-exports = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-exports", tag = "v0.24.x" } +ic-log = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-log", tag = "v0.24.x" } +ic-stable-structures = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-stable-structures", tag = "v0.24.x" } itertools = "0.14" jsonrpsee = { version = "0.25", features = ["server", "macros"] } lightspeed_scheduler = "0.64"