diff --git a/docker/hive/Dockerfile b/docker/hive/Dockerfile index 4ed80ced0..4f3f911e7 100644 --- a/docker/hive/Dockerfile +++ b/docker/hive/Dockerfile @@ -53,7 +53,7 @@ FROM mongo:6.0.8 as mongo # Ethereum RPC Server ### Build the Cairo programs artifacts -FROM python:3.9.13 as compiler +FROM python:3.10.13 as compiler # install poetry ENV POETRY_VERSION=1.7.1 ENV PATH="$PATH:/root/.local/bin:/root/.foundry/bin" diff --git a/lib/kakarot b/lib/kakarot index dd7f25b3d..5279fd2f0 160000 --- a/lib/kakarot +++ b/lib/kakarot @@ -1 +1 @@ -Subproject commit dd7f25b3d6e62be120aa55c28a6df2ae16ba2a43 +Subproject commit 5279fd2f0ac1a1e33354f317d89c8f16b0ae504e diff --git a/src/eth_provider/provider.rs b/src/eth_provider/provider.rs index 0ed1f2695..ca508ce96 100644 --- a/src/eth_provider/provider.rs +++ b/src/eth_provider/provider.rs @@ -139,9 +139,8 @@ where SP: starknet::providers::Provider + Send + Sync, { async fn block_number(&self) -> EthProviderResult { - let filter = doc! {}; let sort = doc! { "header.number": -1 }; - let header: Option = self.database.get_one("headers", filter, sort).await?; + let header: Option = self.database.get_one("headers", None, sort).await?; let block_number = match header { None => U64::from(self.starknet_provider.block_number().await.map_err(KakarotError::from)?), // in case the database is empty, use the starknet provider Some(header) => { @@ -632,8 +631,10 @@ impl EthDataProvider where SP: starknet::providers::Provider + Send + Sync, { - pub const fn new(database: Database, starknet_provider: SP, chain_id: u64) -> Self { - Self { database, starknet_provider, chain_id } + pub async fn new(database: Database, starknet_provider: SP) -> Result { + let chain_id = starknet_provider.chain_id().await?; + let chain_id = (FieldElement::from(u64::MAX) & chain_id).try_into().unwrap(); // safe unwrap + Ok(Self { database, starknet_provider, chain_id }) } #[cfg(feature = "testing")] diff --git a/src/main.rs b/src/main.rs index b11b50a0d..7d3e70af5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use kakarot_rpc::eth_rpc::rpc::KakarotRpcModuleBuilder; use kakarot_rpc::eth_rpc::run_server; use mongodb::options::{DatabaseOptions, ReadConcern, WriteConcern}; use starknet::providers::jsonrpc::HttpTransport; -use starknet::providers::{JsonRpcClient, Provider as _, SequencerGatewayProvider}; +use starknet::providers::{JsonRpcClient, SequencerGatewayProvider}; use tracing_subscriber::util::SubscriberInitExt; enum StarknetProvider { @@ -50,16 +50,19 @@ async fn main() -> Result<()> { DatabaseOptions::builder().read_concern(ReadConcern::MAJORITY).write_concern(WriteConcern::MAJORITY).build(), )); - let provider = - JsonRpcClient::new(HttpTransport::new(starknet_config.network.provider_url().expect("Incorrect provider URL"))); - let chain_id = provider.chain_id().await?; - let chain_id: u64 = chain_id.try_into()?; - // Get the deployer nonce and set the value in the DEPLOY_WALLET_NONCE #[cfg(feature = "hive")] { use kakarot_rpc::eth_provider::constant::{CHAIN_ID, DEPLOY_WALLET, DEPLOY_WALLET_NONCE}; use starknet::accounts::ConnectedAccount; + use starknet::providers::Provider as _; + use starknet_crypto::FieldElement; + + let provider = JsonRpcClient::new(HttpTransport::new( + starknet_config.network.provider_url().expect("Incorrect provider URL"), + )); + let chain_id = provider.chain_id().await?; + let chain_id: u64 = (FieldElement::from(u64::MAX) & chain_id).try_into()?; CHAIN_ID.set(chain_id.into()).expect("Failed to set chain id"); @@ -71,12 +74,12 @@ async fn main() -> Result<()> { let kakarot_rpc_module = match starknet_provider { StarknetProvider::JsonRpcClient(starknet_provider) => { let starknet_provider = Arc::new(starknet_provider); - let eth_provider = EthDataProvider::new(db, starknet_provider, chain_id); + let eth_provider = EthDataProvider::new(db, starknet_provider).await?; KakarotRpcModuleBuilder::new(eth_provider).rpc_module() } StarknetProvider::SequencerGatewayProvider(starknet_provider) => { let starknet_provider = Arc::new(starknet_provider); - let eth_provider = EthDataProvider::new(db, starknet_provider, chain_id); + let eth_provider = EthDataProvider::new(db, starknet_provider).await?; KakarotRpcModuleBuilder::new(eth_provider).rpc_module() } }?; diff --git a/src/test_utils/katana/mod.rs b/src/test_utils/katana/mod.rs index e51f80808..684d5968e 100644 --- a/src/test_utils/katana/mod.rs +++ b/src/test_utils/katana/mod.rs @@ -11,7 +11,7 @@ use katana_primitives::genesis::json::GenesisJson; use katana_primitives::genesis::Genesis; use reth_primitives::B256; use starknet::providers::jsonrpc::HttpTransport; -use starknet::providers::{JsonRpcClient, Provider}; +use starknet::providers::JsonRpcClient; use crate::eth_provider::provider::EthDataProvider; use crate::test_utils::eoa::KakarotEOA; @@ -68,9 +68,9 @@ impl Katana { // Create a Kakarot client let database = mock_database().await; - let chain_id = starknet_provider.chain_id().await.unwrap_or_default(); - let chain_id: u64 = chain_id.try_into().unwrap_or_default(); - let eth_provider = Arc::new(EthDataProvider::new(database, starknet_provider, chain_id)); + let eth_provider = Arc::new( + EthDataProvider::new(database, starknet_provider).await.expect("Failed to create EthDataProvider"), + ); let eoa = KakarotEOA::new(pk, eth_provider);