Skip to content

Commit f6d25ff

Browse files
committed
Merge branch 'main' into EPROD-1192-upgrade-to-ic-cdk-0-18
2 parents 8237fc8 + 6c06fbf commit f6d25ff

18 files changed

Lines changed: 205 additions & 84 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ members = [
1010
"src/evm-log-extractor",
1111
"src/signature-verification-canister-client",
1212
]
13-
resolver = "2"
13+
resolver = "3"
1414

1515
[workspace.package]
1616
authors = ["Bitfinity Network"]
@@ -22,7 +22,7 @@ homepage = "https://github.com/bitfinity-network/bitfinity-evm-sdk"
2222
include = ["src/**/*", "LICENSE", "README.md"]
2323
license = "MIT"
2424
repository = "https://github.com/bitfinity-network/bitfinity-evm-sdk"
25-
version = "0.51.0"
25+
version = "0.53.0"
2626

2727
[workspace.dependencies]
2828
did = { path = "src/did" }
@@ -34,7 +34,7 @@ evm-canister-client = { path = "src/evm-canister-client" }
3434
evm-log-extractor = { path = "src/evm-log-extractor" }
3535
signature-verification-canister-client = { path = "src/signature-verification-canister-client" }
3636

37-
alloy = { version = "0.15", default-features = false, features = [
37+
alloy = { version = "1", default-features = false, features = [
3838
"consensus",
3939
"k256",
4040
"eips",
@@ -43,7 +43,6 @@ alloy = { version = "0.15", default-features = false, features = [
4343
"serde",
4444
] }
4545
anyhow = "1"
46-
async-trait = "0.1"
4746
bincode = "1.3"
4847
bytes = "1"
4948
candid = "0.10"
@@ -54,13 +53,12 @@ env_logger = { version = "0.11.4", default-features = false }
5453
futures = { version = "0.3", default-features = false }
5554
ic-canister = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister", branch = "EPROD-1192-upgrade-to-ic-cdk-0-18" }
5655
ic-canister-client = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister-client", branch = "EPROD-1192-upgrade-to-ic-cdk-0-18" }
57-
ic-cdk = "0.18"
5856
ic-exports = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-exports", branch = "EPROD-1192-upgrade-to-ic-cdk-0-18" }
5957
ic-log = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-log", branch = "EPROD-1192-upgrade-to-ic-cdk-0-18" }
6058
ic-stable-structures = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-stable-structures", branch = "EPROD-1192-upgrade-to-ic-cdk-0-18" }
6159
itertools = "0.14"
6260
jsonrpsee = { version = "0.25", features = ["server", "macros"] }
63-
lightspeed_scheduler = "0.63"
61+
lightspeed_scheduler = "0.64"
6462
log = "0.4"
6563
num = "0.4"
6664
port_check = "0.2"
@@ -81,7 +79,7 @@ sqlx = { version = "0.8", default-features = false, features = [
8179
"runtime-tokio",
8280
] }
8381
tempfile = "3"
84-
testcontainers = { package = "testcontainers-modules", version = "0.11", features = [
82+
testcontainers = { package = "testcontainers-modules", version = "0.12", features = [
8583
"postgres",
8684
] }
8785
thiserror = "2.0"

src/did/src/ic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ pub struct BlockchainBlockInfo {
116116

117117
/// Strategy for confirming a block.
118118
/// When a block is confirmed, it becomes `safe`.
119-
#[derive(Debug, Clone, CandidType, Serialize, Deserialize, PartialEq, Eq)]
119+
#[derive(Debug, Default, Clone, CandidType, Serialize, Deserialize, PartialEq, Eq)]
120120
pub enum BlockConfirmationStrategy {
121121
/// The block does not require any particular confirmation,
122122
/// it is always considered safe.
123+
#[default]
123124
None,
124125

125126
/// The block requires a proof of work to be considered safe.

src/did/src/init.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ic_log::LogSettings;
55
use serde::{Deserialize, Serialize};
66

77
use crate::permission::Permission;
8-
use crate::{H160, U256};
8+
use crate::{BlockConfirmationStrategy, H160, U256};
99

1010
/// These are the arguments which are taken by the evm canister init fn
1111
#[derive(Debug, Clone, CandidType, Deserialize)]
@@ -27,6 +27,8 @@ pub struct EvmCanisterInitData {
2727
pub genesis_accounts: Vec<(H160, Option<U256>)>,
2828
/// Coinbase address
2929
pub coinbase: H160,
30+
/// Block confirmation strategy
31+
pub block_confirmation_strategy: BlockConfirmationStrategy,
3032
}
3133

3234
impl Default for EvmCanisterInitData {
@@ -42,6 +44,7 @@ impl Default for EvmCanisterInitData {
4244
owner: Principal::management_canister(),
4345
genesis_accounts: vec![],
4446
coinbase: Default::default(),
47+
block_confirmation_strategy: BlockConfirmationStrategy::default(),
4548
}
4649
}
4750
}

src/eth-signer/src/transaction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl TransactionBuilder<'_, '_> {
8989
mod test {
9090

9191
use alloy::consensus::TxEnvelope;
92+
use alloy::consensus::transaction::SignerRecoverable;
9293
use alloy::signers::k256::ecdsa::signature::hazmat::PrehashVerifier;
9394
use alloy::signers::utils::secret_key_to_address;
9495

src/evm-block-extractor/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ repository.workspace = true
1212
[dependencies]
1313
alloy = { workspace = true }
1414
anyhow = { workspace = true }
15-
async-trait = { workspace = true }
1615
chrono = { workspace = true }
1716
clap = { workspace = true }
1817
did = { workspace = true }

src/evm-block-extractor/src/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use clap::{Parser, Subcommand};
44
use sqlx::PgPool;
55
use sqlx::postgres::{PgConnectOptions, PgSslMode};
66

7-
use crate::database::DatabaseClient;
87
use crate::database::postgres_db_client::PostgresDbClient;
98

109
const VERSION: &str = env!("CARGO_PKG_VERSION");
@@ -78,7 +77,7 @@ pub enum Database {
7877

7978
impl Database {
8079
/// Build a database client based on the database type
81-
pub async fn build_client(self) -> anyhow::Result<Arc<dyn DatabaseClient>> {
80+
pub async fn build_client(self) -> anyhow::Result<Arc<PostgresDbClient>> {
8281
match self {
8382
Database::Postgres {
8483
username,

src/evm-block-extractor/src/database/mod.rs

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,75 +35,102 @@ const BLOCKCHAIN_BLOCK_INFO_KEY: &str = "blockchain_block_info";
3535
pub type CertifiedBlock = CertifiedResult<Block<H256>>;
3636

3737
/// A trait for interacting with a blockchain database
38-
#[async_trait::async_trait]
3938
pub trait DatabaseClient: Send + Sync {
4039
/// Initialize the database
41-
async fn init(&self, block: Option<Block<H256>>, reset_database: bool) -> anyhow::Result<()>;
40+
fn init(
41+
&self,
42+
block: Option<Block<H256>>,
43+
reset_database: bool,
44+
) -> impl Future<Output = anyhow::Result<()>> + Send;
4245

4346
/// Delete/clear the tables
44-
async fn clear(&self) -> anyhow::Result<()>;
47+
fn clear(&self) -> impl Future<Output = anyhow::Result<()>> + Send;
4548

4649
/// Returns whether the block hash corresponds to the one in the db
47-
async fn check_if_same_block_hash(&self, block: &Block<H256>) -> anyhow::Result<bool> {
48-
let block_number = block.number.0.to();
49-
let block_in_db = self.get_block_by_number(block_number).await?;
50-
Ok(block.hash == block_in_db.hash)
50+
fn check_if_same_block_hash(
51+
&self,
52+
block: &Block<H256>,
53+
) -> impl Future<Output = anyhow::Result<bool>> + Send {
54+
async {
55+
let block_number = block.number.0.to();
56+
let block_in_db = self.get_block_by_number(block_number).await?;
57+
Ok(block.hash == block_in_db.hash)
58+
}
5159
}
5260

5361
/// Get a block from the database
54-
async fn get_block_by_number(&self, block_number: u64) -> anyhow::Result<Block<H256>>;
62+
fn get_block_by_number(
63+
&self,
64+
block_number: u64,
65+
) -> impl Future<Output = anyhow::Result<Block<H256>>> + Send;
5566

5667
/// Get a block from the database
57-
async fn get_full_block_by_number(
68+
fn get_full_block_by_number(
5869
&self,
5970
block_number: u64,
60-
) -> anyhow::Result<Block<Transaction>>;
71+
) -> impl Future<Output = anyhow::Result<Block<Transaction>>> + Send;
6172

6273
/// Insert block data; this includes transactions and the blocks
63-
async fn insert_block_data(
74+
fn insert_block_data(
6475
&self,
6576
blocks: &[Block<H256>],
6677
transactions: &[Transaction],
67-
) -> anyhow::Result<()>;
78+
) -> impl Future<Output = anyhow::Result<()>> + Send;
6879

6980
/// Insert certified block data
70-
async fn insert_certified_block_data(&self, response: CertifiedBlock) -> anyhow::Result<()>;
81+
fn insert_certified_block_data(
82+
&self,
83+
response: CertifiedBlock,
84+
) -> impl Future<Output = anyhow::Result<()>> + Send;
7185

7286
/// Returns certified response for the last block
73-
async fn get_last_certified_block_data(&self) -> anyhow::Result<CertifiedBlock>;
87+
fn get_last_certified_block_data(
88+
&self,
89+
) -> impl Future<Output = anyhow::Result<CertifiedBlock>> + Send;
7490

7591
/// Get genesis balances
76-
async fn get_genesis_balances(&self) -> anyhow::Result<Option<Vec<AccountBalance>>>;
92+
fn get_genesis_balances(
93+
&self,
94+
) -> impl Future<Output = anyhow::Result<Option<Vec<AccountBalance>>>> + Send;
7795

7896
/// Insert genesis balances
79-
async fn insert_genesis_balances(
97+
fn insert_genesis_balances(
8098
&self,
8199
genesis_balances: &[AccountBalance],
82-
) -> anyhow::Result<()>;
100+
) -> impl Future<Output = anyhow::Result<()>> + Send;
83101

84102
/// Get chain id
85-
async fn get_chain_id(&self) -> anyhow::Result<Option<u64>>;
103+
fn get_chain_id(&self) -> impl Future<Output = anyhow::Result<Option<u64>>> + Send;
86104

87105
/// Insert chain_id
88-
async fn insert_chain_id(&self, chain_id: u64) -> anyhow::Result<()>;
106+
fn insert_chain_id(&self, chain_id: u64) -> impl Future<Output = anyhow::Result<()>> + Send;
89107

90108
/// Get a transaction from the database
91-
async fn get_transaction(&self, tx_hash: H256) -> anyhow::Result<Transaction>;
109+
fn get_transaction(
110+
&self,
111+
tx_hash: H256,
112+
) -> impl Future<Output = anyhow::Result<Transaction>> + Send;
92113

93114
/// Get the latest block number
94-
async fn get_latest_block_number(&self) -> anyhow::Result<Option<u64>>;
115+
fn get_latest_block_number(&self) -> impl Future<Output = anyhow::Result<Option<u64>>> + Send;
95116

96117
/// Get earliest block number
97-
async fn get_earliest_block_number(&self) -> anyhow::Result<u64>;
118+
fn get_earliest_block_number(&self) -> impl Future<Output = anyhow::Result<u64>> + Send;
98119

99120
/// Delete latest blocks starting with `start_from`, and related transactions.
100121
/// Deleted blocks and transactions will be preserved in 'discarded' table with
101122
/// the given 'reason' and timestamp.
102-
async fn discard_blocks_from(&self, start_from: u64, reason: &str) -> anyhow::Result<()>;
123+
fn discard_blocks_from(
124+
&self,
125+
start_from: u64,
126+
reason: &str,
127+
) -> impl Future<Output = anyhow::Result<()>> + Send;
103128

104129
/// Returns a discarded block by its hash.
105-
async fn get_discarded_block_by_hash(&self, block_hash: H256)
106-
-> anyhow::Result<DiscardedBlock>;
130+
fn get_discarded_block_by_hash(
131+
&self,
132+
block_hash: H256,
133+
) -> impl Future<Output = anyhow::Result<DiscardedBlock>> + Send;
107134

108135
/// Returns block info from storage.
109136
///
@@ -115,10 +142,15 @@ pub trait DatabaseClient: Send + Sync {
115142
/// - safe_block_number: u64,
116143
/// - finalized_block_number: u64,
117144
/// - pending_block_number: u64,
118-
async fn get_block_info(&self) -> anyhow::Result<Option<BlockchainBlockInfo>>;
145+
fn get_block_info(
146+
&self,
147+
) -> impl Future<Output = anyhow::Result<Option<BlockchainBlockInfo>>> + Send;
119148

120149
/// Stores blockchain block info.
121-
async fn set_block_info(&self, info: BlockchainBlockInfo) -> anyhow::Result<()>;
150+
fn set_block_info(
151+
&self,
152+
info: BlockchainBlockInfo,
153+
) -> impl Future<Output = anyhow::Result<()>> + Send;
122154
}
123155

124156
/// Discarded block with metadata.

src/evm-block-extractor/src/database/postgres_db_client.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ impl PostgresDbClient {
7171
}
7272
}
7373

74-
#[async_trait::async_trait]
7574
impl DatabaseClient for PostgresDbClient {
7675
async fn init(&self, block: Option<Block<H256>>, reset_database: bool) -> anyhow::Result<()> {
7776
MIGRATOR.run(&self.pool).await?;

src/evm-block-extractor/src/rpc.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,34 @@ use jsonrpsee::types::{ErrorCode, ErrorObject};
1111

1212
use crate::database::{CertifiedBlock, DatabaseClient};
1313

14-
#[derive(Clone)]
15-
pub struct EthImpl<C>
14+
pub struct EthImpl<C, DB>
1615
where
16+
DB: DatabaseClient,
1717
C: Client + Send + Sync + 'static,
1818
{
19-
pub blockchain: Arc<dyn DatabaseClient + 'static>,
19+
pub blockchain: Arc<DB>,
2020
pub evm_client: Arc<EthJsonRpcClient<C>>,
2121
}
2222

23-
impl<C> EthImpl<C>
23+
impl<C, DB> Clone for EthImpl<C, DB>
2424
where
25+
DB: DatabaseClient,
2526
C: Client + Send + Sync + 'static,
2627
{
27-
pub fn new(
28-
db: Arc<dyn DatabaseClient + 'static>,
29-
evm_client: Arc<EthJsonRpcClient<C>>,
30-
) -> Self {
28+
fn clone(&self) -> Self {
29+
Self {
30+
blockchain: self.blockchain.clone(),
31+
evm_client: self.evm_client.clone(),
32+
}
33+
}
34+
}
35+
36+
impl<C, DB> EthImpl<C, DB>
37+
where
38+
DB: DatabaseClient,
39+
C: Client + Send + Sync + 'static,
40+
{
41+
pub fn new(db: Arc<DB>, evm_client: Arc<EthJsonRpcClient<C>>) -> Self {
3142
Self {
3243
blockchain: db,
3344
evm_client,
@@ -74,9 +85,10 @@ pub trait IC {
7485
) -> RpcResult<BlockConfirmationResult>;
7586
}
7687

77-
#[async_trait::async_trait]
78-
impl<C> ICServer for EthImpl<C>
88+
#[jsonrpsee::core::async_trait]
89+
impl<C, DB> ICServer for EthImpl<C, DB>
7990
where
91+
DB: DatabaseClient + Send + Sync + 'static,
8092
C: Client + Send + Sync + 'static,
8193
{
8294
async fn get_genesis_balances(&self) -> RpcResult<Vec<(Address, U256)>> {
@@ -143,9 +155,10 @@ where
143155
}
144156
}
145157

146-
#[async_trait::async_trait]
147-
impl<C> EthServer for EthImpl<C>
158+
#[jsonrpsee::core::async_trait]
159+
impl<C, DB> EthServer for EthImpl<C, DB>
148160
where
161+
DB: DatabaseClient + Send + Sync + 'static,
149162
C: Client + Send + Sync + 'static,
150163
{
151164
async fn get_block_by_number(

src/evm-block-extractor/src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::database::DatabaseClient;
99
use crate::rpc::{EthImpl, EthServer, ICServer};
1010

1111
/// Start the RPC server
12-
pub async fn server_start(
12+
pub async fn server_start<DB: DatabaseClient + Send + Sync + 'static>(
1313
server_address: &str,
14-
db_client: Arc<dyn DatabaseClient>,
14+
db_client: Arc<DB>,
1515
evm_client: Arc<EthJsonRpcClient<impl Client + 'static>>,
1616
) -> anyhow::Result<ServerHandle> {
1717
info!("Start server");

0 commit comments

Comments
 (0)