diff --git a/Cargo.lock b/Cargo.lock index 9f0bcd44a0..ace78f9245 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3863,6 +3863,12 @@ dependencies = [ "serde_json", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dotenvy" version = "0.15.7" @@ -11403,6 +11409,7 @@ dependencies = [ "common", "console", "dojo-metrics", + "dotenv", "katana-core", "katana-executor", "katana-primitives", diff --git a/bin/solis/Cargo.toml b/bin/solis/Cargo.toml index 5b8debb1c2..0a0c5a07d9 100644 --- a/bin/solis/Cargo.toml +++ b/bin/solis/Cargo.toml @@ -19,6 +19,7 @@ clap_complete.workspace = true common.workspace = true console.workspace = true dojo-metrics.workspace = true +dotenv = "0.15.0" katana-core.workspace = true katana-executor.workspace = true katana-primitives.workspace = true diff --git a/bin/solis/src/args.rs b/bin/solis/src/args.rs index f2fb8b6b01..cb31691377 100644 --- a/bin/solis/src/args.rs +++ b/bin/solis/src/args.rs @@ -9,7 +9,7 @@ //! and leak detection functionality. See [jemalloc's opt.prof](https://jemalloc.net/jemalloc.3.html#opt.prof) //! documentation for usage details. This is **not recommended on Windows**. See [here](https://rust-lang.github.io/rfcs/1974-global-allocators.html#jemalloc) //! for more info. - +use std::env; use std::net::SocketAddr; use std::path::PathBuf; @@ -230,7 +230,8 @@ impl KatanaArgs { } pub fn server_config(&self) -> ServerConfig { - let mut apis = vec![ApiKind::Starknet, ApiKind::Katana, ApiKind::Torii, ApiKind::Saya, ApiKind::Solis]; + let mut apis = + vec![ApiKind::Starknet, ApiKind::Katana, ApiKind::Torii, ApiKind::Saya, ApiKind::Solis]; // only enable `katana` API in dev mode if self.dev { apis.push(ApiKind::Dev); diff --git a/bin/solis/src/contracts/account.rs b/bin/solis/src/contracts/account.rs index f19a7d9c6c..1b8356bb2f 100644 --- a/bin/solis/src/contracts/account.rs +++ b/bin/solis/src/contracts/account.rs @@ -1,10 +1,8 @@ -use starknet::{ - accounts::{ExecutionEncoding, SingleOwnerAccount}, - core::types::FieldElement, - providers::{jsonrpc::HttpTransport, AnyProvider, JsonRpcClient, Provider}, - signers::{LocalWallet, SigningKey}, -}; - +use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount}; +use starknet::core::types::FieldElement; +use starknet::providers::jsonrpc::HttpTransport; +use starknet::providers::{AnyProvider, JsonRpcClient, Provider}; +use starknet::signers::{LocalWallet, SigningKey}; use url::Url; /// Initializes a new account to interact with Starknet. @@ -25,18 +23,9 @@ pub async fn new_account( AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(rpc_url.clone()))); // TODO: need error instead of expect. - let chain_id = provider - .chain_id() - .await - .expect("couldn't get chain_id from provider"); + let chain_id = provider.chain_id().await.expect("couldn't get chain_id from provider"); let signer = LocalWallet::from(SigningKey::from_secret_scalar(private_key)); - SingleOwnerAccount::new( - provider, - signer, - account_address, - chain_id, - ExecutionEncoding::Legacy, - ) + SingleOwnerAccount::new(provider, signer, account_address, chain_id, ExecutionEncoding::Legacy) } diff --git a/bin/solis/src/contracts/orderbook.rs b/bin/solis/src/contracts/orderbook.rs index 9bc801643b..b20a97a7ed 100644 --- a/bin/solis/src/contracts/orderbook.rs +++ b/bin/solis/src/contracts/orderbook.rs @@ -1,5 +1,6 @@ use cainome::rs::abigen; -use starknet::{accounts::ConnectedAccount, core::types::FieldElement}; +use starknet::accounts::ConnectedAccount; +use starknet::core::types::FieldElement; abigen!(OrderbookContract, "./artifacts/orderbook.abi.json"); diff --git a/bin/solis/src/contracts/starknet_utils.rs b/bin/solis/src/contracts/starknet_utils.rs index 280c9f2e6d..7dfe38ab71 100644 --- a/bin/solis/src/contracts/starknet_utils.rs +++ b/bin/solis/src/contracts/starknet_utils.rs @@ -1,9 +1,7 @@ use cainome::rs::abigen; -use starknet::{ - core::types::FieldElement, - providers::{jsonrpc::HttpTransport, AnyProvider, JsonRpcClient}, -}; - +use starknet::core::types::FieldElement; +use starknet::providers::jsonrpc::HttpTransport; +use starknet::providers::{AnyProvider, JsonRpcClient}; use url::Url; abigen!(StarknetUtils, "./artifacts/starknet_utils.json"); diff --git a/bin/solis/src/hooker.rs b/bin/solis/src/hooker.rs index 4068940884..d39a7e733d 100644 --- a/bin/solis/src/hooker.rs +++ b/bin/solis/src/hooker.rs @@ -1,55 +1,50 @@ //! Solis hooker on Katana transaction lifecycle. -//! -use crate::contracts::starknet_utils::{ExecutionInfo, U256}; +use std::fs::{File, OpenOptions}; +use std::io::{Read, Write}; +use std::path::Path; +use std::sync::Arc; + use async_trait::async_trait; use cainome::cairo_serde::CairoSerde; use cainome::rs::abigen; use katana_core::hooker::{HookerAddresses, KatanaHooker}; use katana_core::sequencer::KatanaSequencer; use katana_executor::ExecutorFactory; - use katana_primitives::chain::ChainId; use katana_primitives::contract::ContractAddress; use katana_primitives::transaction::{ExecutableTx, ExecutableTxWithHash, L1HandlerTx}; use katana_primitives::utils::transaction::compute_l1_message_hash; +use serde_json::{json, Value}; use starknet::accounts::Call; -use starknet::core::types::BroadcastedInvokeTransaction; -use starknet::core::types::FieldElement; +use starknet::core::types::{BroadcastedInvokeTransaction, FieldElement}; use starknet::macros::selector; use starknet::providers::Provider; -use std::sync::Arc; -use std::fs::File; -use std::fs::OpenOptions; -use std::io::Write; -use std::io::Read; -use serde_json::Value; -use std::path::Path; -use serde_json::json; +use crate::contracts::starknet_utils::{ExecutionInfo, U256}; const FILE_PATH_ADDRESSES: &str = "addresses.json"; +use tracing::info; use crate::contracts::orderbook::{OrderV1, RouteType}; use crate::contracts::starknet_utils::StarknetUtilsReader; use crate::CHAIN_ID_SOLIS; -use tracing::info; #[allow(dead_code)] pub enum CancelStatus { - CancelledUser, - CancelledByNewOrder, - CancelledAssetFault, - CancelledOwnership, + User, + ByNewOrder, + AssetFault, + Ownership, } impl CancelStatus { fn to_u32(&self) -> u32 { match self { - CancelStatus::CancelledUser => 1, - CancelStatus::CancelledByNewOrder => 2, - CancelStatus::CancelledAssetFault => 3, - CancelStatus::CancelledOwnership => 4, + CancelStatus::User => 1, + CancelStatus::ByNewOrder => 2, + CancelStatus::AssetFault => 3, + CancelStatus::Ownership => 4, } } } @@ -92,10 +87,7 @@ impl ); // check the current owner of the token. - let owner = sn_utils_reader_nft_address - .ownerOf(&ownership_verifier.token_id) - .call() - .await; + let owner = sn_utils_reader_nft_address.ownerOf(&ownership_verifier.token_id).call().await; if let Ok(owner_address) = owner { if owner_address != ownership_verifier.current_owner { @@ -145,10 +137,8 @@ impl } // check the balance - let balance = sn_utils_reader_erc20_address - .balanceOf(&balance_verifier.offerer) - .call() - .await; + let balance = + sn_utils_reader_erc20_address.balanceOf(&balance_verifier.offerer).call().await; if let Ok(balance) = balance { if balance < balance_verifier.start_amount { tracing::trace!( @@ -179,10 +169,7 @@ impl // ERC721 to ERC20 if order.route == RouteType::Erc721ToErc20 { let token_id = order.token_id.clone().unwrap(); - let n_token_id = U256 { - low: token_id.low, - high: token_id.high, - }; + let n_token_id = U256 { low: token_id.low, high: token_id.high }; let verifier = OwnershipVerifier { token_address: ContractAddress(order.token_address.into()), @@ -197,8 +184,8 @@ impl } // ERC20 to ERC721 : we check the allowance and the offerer balance. - if order.route == RouteType::Erc20ToErc721 { - if !self + if order.route == RouteType::Erc20ToErc721 + && !self .verify_balance(&BalanceVerifier { currency_address: ContractAddress(order.currency_address.into()), offerer: cainome::cairo_serde::ContractAddress(order.offerer.into()), @@ -208,19 +195,19 @@ impl }, }) .await - { - println!("verify balance for starknet before failed"); - return false; - } + { + println!("verify balance for starknet before failed"); + return false; } - return true; + true } } impl SolisHooker { - fn get_addresses_from_file() -> Result<(FieldElement, FieldElement), Box> { + fn get_addresses_from_file() -> Result<(FieldElement, FieldElement), Box> + { let mut file = match File::open(FILE_PATH_ADDRESSES) { Ok(file) => file, Err(_) => return Err("File not found".into()), @@ -264,7 +251,9 @@ impl orderbook_address: FieldElement, sn_executor_address: FieldElement, ) -> Self { - let (orderbook_address, sn_executor_address) = if orderbook_address == FieldElement::ZERO && sn_executor_address == FieldElement::ZERO { + let (orderbook_address, sn_executor_address) = if orderbook_address == FieldElement::ZERO + && sn_executor_address == FieldElement::ZERO + { match Self::get_addresses_from_file() { Ok((orderbook, executor)) => (orderbook, executor), Err(e) => { @@ -276,12 +265,7 @@ impl (orderbook_address, sn_executor_address) }; - Self { - orderbook_address, - sn_utils_reader, - sn_executor_address, - sequencer: None, - } + Self { orderbook_address, sn_utils_reader, sn_executor_address, sequencer: None } } /// Retrieves a reference to the sequencer. @@ -289,9 +273,7 @@ impl pub fn sequencer_ref(&self) -> &Arc> { // The expect is used here as it must always be set by Katana core. // If not set, the merge on Katana may be revised. - self.sequencer - .as_ref() - .expect("Sequencer must be set to get a reference to it") + self.sequencer.as_ref().expect("Sequencer must be set to get a reference to it") } /// Adds a `L1HandlerTransaction` to the transaction pool that is directed to the @@ -301,8 +283,8 @@ impl /// /// In the case of Solis, `L1HandlerTransaction` are sent by Solis for two purposes: /// 1. A message was collected from the L2, and it must be executed. - /// 2. A transaction has been rejected by Solis (asset faults), and the order - /// must then be updated. + /// 2. A transaction has been rejected by Solis (asset faults), and the order must then be + /// updated. /// /// This function is used for the scenario 2. For this reason, the `from_address` /// field is automatically filled up by the sequencer to use the executor address @@ -329,7 +311,7 @@ impl // The calldata always starts with the from_address. let mut calldata: Vec = vec![from_address]; - for p in payload.into_iter() { + for p in payload.iter() { calldata.push(*p); } @@ -369,10 +351,7 @@ impl self.sn_executor_address = addresses.executor_starknet; let path = Path::new(FILE_PATH_ADDRESSES); - let file = OpenOptions::new() - .write(true) - .create(true) - .open(&path); + let file = OpenOptions::new().write(true).create(true).open(path); match file { Ok(mut file) => { @@ -381,7 +360,7 @@ impl "sn_executor_address": format!("{:#x}", self.sn_executor_address) }); - if let Err(e) = writeln!(file, "{}", data.to_string()) { + if let Err(e) = writeln!(file, "{}", data) { eprintln!("Error writing file : {}", e); } } @@ -412,25 +391,19 @@ impl /// Verifies an invoke transaction that is: /// 1. Directed to the orderbook only. - /// 2. With the selector `create_order` only as the fulfill - /// is verified by `verify_message_to_starknet_before_tx`. + /// 2. With the selector `create_order` only as the fulfill is verified by + /// `verify_message_to_starknet_before_tx`. async fn verify_invoke_tx_before_pool( &self, transaction: BroadcastedInvokeTransaction, ) -> bool { - info!( - "HOOKER: verify_invoke_tx_before_pool called with transaction: {:?}", - transaction - ); + info!("HOOKER: verify_invoke_tx_before_pool called with transaction: {:?}", transaction); let calldata = match transaction { BroadcastedInvokeTransaction::V1(v1_transaction) => v1_transaction.calldata, BroadcastedInvokeTransaction::V3(v3_transaction) => v3_transaction.calldata, }; - info!( - "HOOKER: cairo_deserialize called with transaction: {:?}", - calldata - ); + info!("HOOKER: cairo_deserialize called with transaction: {:?}", calldata); let calls = match Vec::::cairo_deserialize(&calldata, 0) { Ok(calls) => calls, @@ -482,7 +455,7 @@ impl let owner_ship_verification = self.verify_ownership(&verifier).await; if !owner_ship_verification { // rollback the status - let status = CancelStatus::CancelledOwnership; + let status = CancelStatus::Ownership; self.add_l1_handler_transaction_for_orderbook( selector!("rollback_status_order"), @@ -503,7 +476,7 @@ impl .await { // rollback the status - let status = CancelStatus::CancelledAssetFault; + let status = CancelStatus::AssetFault; self.add_l1_handler_transaction_for_orderbook( selector!("rollback_status_order"), @@ -536,9 +509,10 @@ impl #[cfg(test)] mod test { - use super::*; use starknet::macros::{felt, selector}; + use super::*; + #[test] fn test_calldata_calls_parsing_new_encoding() { // Calldata for a transaction to starkgate: diff --git a/bin/solis/src/main.rs b/bin/solis/src/main.rs index ce806b1e34..2ddc2ecb5d 100644 --- a/bin/solis/src/main.rs +++ b/bin/solis/src/main.rs @@ -2,7 +2,6 @@ use std::io; use std::net::SocketAddr; use std::sync::Arc; -use crate::hooker::SolisHooker; use clap::{CommandFactory, Parser}; use clap_complete::{generate, Shell}; use console::Style; @@ -23,10 +22,12 @@ use tokio::signal::ctrl_c; use tokio::sync::RwLock as AsyncRwLock; use tracing::info; +use crate::hooker::SolisHooker; + mod args; -mod utils; -mod hooker; mod contracts; +mod hooker; +mod utils; // Chain ID: 'SOLIS' cairo short string. pub const CHAIN_ID_SOLIS: FieldElement = FieldElement::from_mont([ @@ -116,17 +117,19 @@ async fn main() -> Result<(), Box> { let executor_address = FieldElement::ZERO; let orderbook_address = FieldElement::ZERO; - let hooker:Arc + Send + Sync>> = - Arc::new(AsyncRwLock::new(SolisHooker::new( - sn_utils_reader, - orderbook_address, - executor_address, - ))); + let hooker: Arc + Send + Sync>> = Arc::new( + AsyncRwLock::new(SolisHooker::new(sn_utils_reader, orderbook_address, executor_address)), + ); // ** let sequencer = Arc::new( - KatanaSequencer::new(executor_factory, sequencer_config, starknet_config, Some(hooker.clone())) - .await?, + KatanaSequencer::new( + executor_factory, + sequencer_config, + starknet_config, + Some(hooker.clone()), + ) + .await?, ); let NodeHandle { addr, handle, .. } = spawn(Arc::clone(&sequencer), server_config).await?; diff --git a/crates/katana/core/src/hooker.rs b/crates/katana/core/src/hooker.rs index a7724a96bb..64da247d0c 100644 --- a/crates/katana/core/src/hooker.rs +++ b/crates/katana/core/src/hooker.rs @@ -1,14 +1,16 @@ //! This module contains a hooker trait, that is added to katana in order to //! allow external code to react at some precise moment of katana processing. -use crate::sequencer::KatanaSequencer; +use std::sync::Arc; + use async_trait::async_trait; use katana_executor::ExecutorFactory; use starknet::accounts::Call; use starknet::core::types::{BroadcastedInvokeTransaction, FieldElement}; -use std::sync::Arc; use tracing::{error, info}; +use crate::sequencer::KatanaSequencer; + #[derive(Debug, Clone, serde::Deserialize, serde::Serialize, Copy, PartialEq, Eq)] pub struct HookerAddresses { pub orderbook_arkchain: FieldElement, @@ -45,7 +47,7 @@ pub trait KatanaHooker { /// /// * `transaction` - The invoke transaction to be verified. async fn verify_invoke_tx_before_pool(&self, transaction: BroadcastedInvokeTransaction) - -> bool; + -> bool; /// Runs code right before a message to starknet /// is being sent via a direct transaction. @@ -86,6 +88,12 @@ impl DefaultKatanaHooker { } } +impl Default for DefaultKatanaHooker { + fn default() -> Self { + Self::new() + } +} + #[async_trait] impl KatanaHooker for DefaultKatanaHooker { fn set_sequencer(&mut self, sequencer: Arc>) { diff --git a/crates/katana/core/src/lib.rs b/crates/katana/core/src/lib.rs index 099e04b025..f202735ea8 100644 --- a/crates/katana/core/src/lib.rs +++ b/crates/katana/core/src/lib.rs @@ -1,10 +1,10 @@ pub mod backend; pub mod constants; pub mod env; +pub mod hooker; pub mod pool; pub mod sequencer; pub mod service; pub mod utils; -pub mod hooker; pub mod sequencer_error; diff --git a/crates/katana/core/src/sequencer.rs b/crates/katana/core/src/sequencer.rs index cf1815eaed..68b323ed98 100644 --- a/crates/katana/core/src/sequencer.rs +++ b/crates/katana/core/src/sequencer.rs @@ -1,6 +1,3 @@ -use crate::hooker::KatanaHooker; -use tokio::sync::RwLock as AsyncRwLock; - use std::cmp::Ordering; use std::iter::Skip; use std::slice::Iter; @@ -27,11 +24,13 @@ use katana_provider::traits::transaction::{ ReceiptProvider, TransactionProvider, TransactionsProviderExt, }; use starknet::core::types::{BlockTag, EmittedEvent, EventsPage}; +use tokio::sync::RwLock as AsyncRwLock; use tracing::error; use crate::backend::config::StarknetConfig; use crate::backend::contract::StarknetContract; use crate::backend::Backend; +use crate::hooker::KatanaHooker; use crate::pool::TransactionPool; use crate::sequencer_error::SequencerError; use crate::service::block_producer::{BlockProducer, BlockProducerMode, PendingExecutor}; @@ -94,7 +93,10 @@ impl KatanaSequencer { .await .ok(), None => { - error!("Messaging service is enabled but no hooker is provided. Messaging service will not be started."); + error!( + "Messaging service is enabled but no hooker is provided. Messaging \ + service will not be started." + ); None } } @@ -305,13 +307,10 @@ impl KatanaSequencer { let tx @ Some(_) = tx else { return Ok(self.pending_executor().as_ref().and_then(|exec| { - exec.read().transactions().iter().find_map(|tx| { - if tx.0.hash == *hash { - Some(tx.0.clone()) - } else { - None - } - }) + exec.read() + .transactions() + .iter() + .find_map(|tx| if tx.0.hash == *hash { Some(tx.0.clone()) } else { None }) })); }; @@ -519,9 +518,10 @@ fn filter_events_by_params( #[cfg(test)] mod tests { - use super::*; use katana_executor::implementation::noop::NoopExecutorFactory; use katana_provider::traits::block::BlockNumberProvider; + + use super::*; #[tokio::test] async fn init_interval_block_producer_with_correct_block_env() { let executor_factory = NoopExecutorFactory::default(); diff --git a/crates/katana/core/src/service/messaging/mod.rs b/crates/katana/core/src/service/messaging/mod.rs index 259cb483f1..27e317a836 100644 --- a/crates/katana/core/src/service/messaging/mod.rs +++ b/crates/katana/core/src/service/messaging/mod.rs @@ -32,10 +32,12 @@ //! configuration file following the `MessagingConfig` format. An example of this file can be found //! in the messaging contracts. -use crate::hooker::KatanaHooker; use std::sync::Arc; + use tokio::sync::RwLock as AsyncRwLock; +use crate::hooker::KatanaHooker; + mod ethereum; mod service; mod starknet; diff --git a/crates/katana/core/src/service/messaging/service.rs b/crates/katana/core/src/service/messaging/service.rs index 3bed0e18ea..e4854db463 100644 --- a/crates/katana/core/src/service/messaging/service.rs +++ b/crates/katana/core/src/service/messaging/service.rs @@ -1,5 +1,7 @@ -use crate::hooker::KatanaHooker; -use tokio::sync::RwLock as AsyncRwLock; +use std::pin::Pin; +use std::sync::Arc; +use std::task::{Context, Poll}; +use std::time::Duration; use futures::{Future, FutureExt, Stream}; use katana_executor::ExecutorFactory; @@ -8,15 +10,13 @@ use katana_primitives::receipt::MessageToL1; use katana_primitives::transaction::{ExecutableTxWithHash, L1HandlerTx, TxHash}; use katana_provider::traits::block::BlockNumberProvider; use katana_provider::traits::transaction::ReceiptProvider; -use std::pin::Pin; -use std::sync::Arc; -use std::task::{Context, Poll}; -use std::time::Duration; +use tokio::sync::RwLock as AsyncRwLock; use tokio::time::{interval_at, Instant, Interval}; use tracing::{error, info}; use super::{MessagingConfig, Messenger, MessengerMode, MessengerResult, LOG_TARGET}; use crate::backend::Backend; +use crate::hooker::KatanaHooker; use crate::pool::TransactionPool; type MessagingFuture = Pin + Send>>; @@ -149,7 +149,8 @@ impl MessagingService { } Err(e) => { error!(target: LOG_TARGET, error = %e, "Error sending messages from block {}", block_num); - // Even if there's an error, we should move to the next block to avoid infinite retries + // Even if there's an error, we should move to the next block to avoid + // infinite retries Ok(Some((block_num, 0))) // Marking as processed to avoid retries } } @@ -165,7 +166,8 @@ impl MessagingService { } Err(e) => { error!(target: LOG_TARGET, error = %e, "Error sending messages from block {}", block_num); - // Even if there's an error, we should move to the next block to avoid infinite retries + // Even if there's an error, we should move to the next block to avoid + // infinite retries Ok(Some((block_num, 0))) // Marking as processed to avoid retries } } @@ -247,7 +249,8 @@ impl Stream for MessagingService { } Poll::Ready(Err(e)) => { error!(target: LOG_TARGET, block = %pin.send_from_block, error = %e, "Error sending messages for block."); - // Even if there's an error, we should move to the next block to avoid infinite retries + // Even if there's an error, we should move to the next block to avoid infinite + // retries pin.send_from_block += 1; return Poll::Pending; } diff --git a/crates/katana/core/src/service/messaging/starknet.rs b/crates/katana/core/src/service/messaging/starknet.rs index 6375f78227..387714d3e5 100644 --- a/crates/katana/core/src/service/messaging/starknet.rs +++ b/crates/katana/core/src/service/messaging/starknet.rs @@ -1,4 +1,7 @@ -use crate::hooker::KatanaHooker; +use std::collections::HashSet; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::Arc; + use anyhow::Result; use async_trait::async_trait; use katana_primitives::chain::ChainId; @@ -12,14 +15,12 @@ use starknet::macros::{felt, selector}; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::{AnyProvider, JsonRpcClient, Provider}; use starknet::signers::{LocalWallet, SigningKey}; -use std::collections::HashSet; -use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::Arc; use tokio::sync::RwLock as AsyncRwLock; use tracing::{debug, error, info, trace, warn}; use url::Url; use super::{Error, MessagingConfig, Messenger, MessengerResult, LOG_TARGET}; +use crate::hooker::KatanaHooker; const MSG_MAGIC: FieldElement = felt!("0x4d5347"); const EXE_MAGIC: FieldElement = felt!("0x455845"); @@ -108,25 +109,25 @@ impl StarknetMessaging { if let Ok(tx) = l1_handler_tx_from_event(&event, chain_id) { if let Ok((from, to, selector)) = info_from_event(&event) { - let hooker = Arc::clone(&self.hooker); - let is_message_accepted = hooker - .read() - .await - .verify_message_to_appchain(from, to, selector) - .await; + let hooker = Arc::clone(&self.hooker); + let is_message_accepted = hooker + .read() + .await + .verify_message_to_appchain(from, to, selector) + .await; if is_message_accepted { debug!(target: LOG_TARGET, "Event ID: {} accepted, adding to transactions", event_id); l1_handler_txs.push(tx); let mut cache = self.event_cache.write().await; cache.insert(event_id); } else { - debug!( - target: LOG_TARGET, - "Event ID: {} not accepted by hooker, check the contract addresses defined in the hooker: executor address: {:?}, orderbook address: {:?}", - event_id, - from, - to - ); + debug!( + target: LOG_TARGET, + "Event ID: {} not accepted by hooker, check the contract addresses defined in the hooker: executor address: {:?}, orderbook address: {:?}", + event_id, + from, + to + ); } } } @@ -225,8 +226,8 @@ impl Messenger for StarknetM async fn gather_messages( &self, - from_block: u64, - max_blocks: u64, + _from_block: u64, + _max_blocks: u64, chain_id: ChainId, ) -> MessengerResult<(u64, Vec)> { debug!(target: LOG_TARGET, "Gathering messages"); diff --git a/crates/katana/rpc/rpc-api/src/lib.rs b/crates/katana/rpc/rpc-api/src/lib.rs index c56f5cbd27..f568a9e4ce 100644 --- a/crates/katana/rpc/rpc-api/src/lib.rs +++ b/crates/katana/rpc/rpc-api/src/lib.rs @@ -13,5 +13,5 @@ pub enum ApiKind { Torii, Dev, Saya, - Solis + Solis, } diff --git a/crates/katana/rpc/rpc-types/src/error/mod.rs b/crates/katana/rpc/rpc-types/src/error/mod.rs index c68defcea8..82686bf94f 100644 --- a/crates/katana/rpc/rpc-types/src/error/mod.rs +++ b/crates/katana/rpc/rpc-types/src/error/mod.rs @@ -1,5 +1,5 @@ pub mod katana; pub mod saya; +pub mod solis; pub mod starknet; pub mod torii; -pub mod solis; \ No newline at end of file diff --git a/crates/katana/rpc/rpc/src/solis.rs b/crates/katana/rpc/rpc/src/solis.rs index 16d4690674..0c0f4d8dab 100644 --- a/crates/katana/rpc/rpc/src/solis.rs +++ b/crates/katana/rpc/rpc/src/solis.rs @@ -1,13 +1,14 @@ -use base64::decode; use std::sync::Arc; -use crate::config::ServerConfig; +use base64::decode; use jsonrpsee::core::{async_trait, Error as RpcError}; -use katana_rpc_types::error::solis::SolisApiError; use katana_core::hooker::HookerAddresses; use katana_core::sequencer::KatanaSequencer; use katana_executor::ExecutorFactory; use katana_rpc_api::solis::SolisApiServer; +use katana_rpc_types::error::solis::SolisApiError; + +use crate::config::ServerConfig; pub struct SolisApi { sequencer: Arc>, pub rpc_user: String, diff --git a/crates/katana/rpc/rpc/src/starknet.rs b/crates/katana/rpc/rpc/src/starknet.rs index a0fde82e7e..18f0888652 100644 --- a/crates/katana/rpc/rpc/src/starknet.rs +++ b/crates/katana/rpc/rpc/src/starknet.rs @@ -36,7 +36,7 @@ use katana_rpc_types::{ use katana_rpc_types_builder::ReceiptBuilder; use katana_tasks::{BlockingTaskPool, TokioTaskSpawner}; use starknet::core::types::{ - BlockTag, BroadcastedInvokeTransaction, DeclareTransactionTrace, DeployAccountTransactionTrace, ExecuteInvocation, + BlockTag, DeclareTransactionTrace, DeployAccountTransactionTrace, ExecuteInvocation, InvokeTransactionTrace, L1HandlerTransactionTrace, RevertedInvocation, SimulatedTransaction, TransactionExecutionStatus, TransactionStatus, TransactionTrace, }; @@ -675,11 +675,10 @@ impl StarknetApiServer for StarknetApi { &self, invoke_transaction: BroadcastedInvokeTx, ) -> RpcResult { - if let Some(hooker) = &self.inner.sequencer.hooker { let tx = invoke_transaction.0.clone(); if !hooker.read().await.verify_invoke_tx_before_pool(tx).await { - return Err(StarknetApiError::SolisAssetFault.into()); + return Err(StarknetApiError::SolisAssetFault.into()); } } self.on_io_blocking_task(move |this| {