From defc01a5420e496a857bd3acd60c2d2fc4fca5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Baranx?= Date: Fri, 29 Mar 2024 12:28:17 +0700 Subject: [PATCH 1/4] Sozo call command (#1704) * typo * sozo: add call command add `sozo call` command to be able to directly call view functions without using `starkli`. * add sozo call tests * fix fmt * add block-id option to call command --- bin/sozo/src/args.rs | 3 + bin/sozo/src/commands/call.rs | 56 +++++++++ bin/sozo/src/commands/execute.rs | 2 +- bin/sozo/src/commands/mod.rs | 2 + bin/sozo/src/utils.rs | 44 +++++++ crates/dojo-test-utils/src/sequencer.rs | 4 + crates/sozo/ops/src/call.rs | 39 +++++++ crates/sozo/ops/src/lib.rs | 1 + crates/sozo/ops/src/tests/call.rs | 147 ++++++++++++++++++++++++ crates/sozo/ops/src/tests/mod.rs | 1 + crates/sozo/ops/src/tests/utils.rs | 71 +++++++++++- crates/sozo/ops/src/utils.rs | 64 ++++++++++- 12 files changed, 429 insertions(+), 5 deletions(-) create mode 100644 bin/sozo/src/commands/call.rs create mode 100644 crates/sozo/ops/src/call.rs create mode 100644 crates/sozo/ops/src/tests/call.rs diff --git a/bin/sozo/src/args.rs b/bin/sozo/src/args.rs index 4a065764a9..4dbc54003d 100644 --- a/bin/sozo/src/args.rs +++ b/bin/sozo/src/args.rs @@ -9,6 +9,7 @@ use tracing_log::AsTrace; use crate::commands::auth::AuthArgs; use crate::commands::build::BuildArgs; +use crate::commands::call::CallArgs; use crate::commands::clean::CleanArgs; use crate::commands::completions::CompletionsArgs; use crate::commands::dev::DevArgs; @@ -79,6 +80,8 @@ pub enum Commands { Test(TestArgs), #[command(about = "Execute a world's system")] Execute(ExecuteArgs), + #[command(about = "Call a world's system")] + Call(CallArgs), #[command(about = "Interact with a worlds models")] Model(ModelArgs), #[command(about = "Register new models")] diff --git a/bin/sozo/src/commands/call.rs b/bin/sozo/src/commands/call.rs new file mode 100644 index 0000000000..109f8af41c --- /dev/null +++ b/bin/sozo/src/commands/call.rs @@ -0,0 +1,56 @@ +use anyhow::Result; +use clap::Args; +use scarb::core::Config; +use starknet::core::types::FieldElement; + +use super::options::starknet::StarknetOptions; +use super::options::world::WorldOptions; +use crate::utils; + +#[derive(Debug, Args)] +#[command(about = "Call a system with the given calldata.")] +pub struct CallArgs { + #[arg(help = "The address or the fully qualified name of the contract to call.")] + pub contract: String, + + #[arg(help = "The name of the entrypoint to call.")] + pub entrypoint: String, + + #[arg(short, long)] + #[arg(value_delimiter = ',')] + #[arg(help = "The calldata to be passed to the entrypoint. Comma separated values e.g., \ + 0x12345,0x69420.")] + pub calldata: Vec, + + #[arg(short, long)] + #[arg(help = "The block ID (could be a hash, a number, 'pending' or 'latest')")] + pub block_id: Option, + + #[command(flatten)] + pub starknet: StarknetOptions, + + #[command(flatten)] + pub world: WorldOptions, +} + +impl CallArgs { + pub fn run(self, config: &Config) -> Result<()> { + let env_metadata = utils::load_metadata_from_config(config)?; + + config.tokio_handle().block_on(async { + let world_reader = + utils::world_reader_from_env_metadata(self.world, self.starknet, &env_metadata) + .await + .unwrap(); + + sozo_ops::call::call( + world_reader, + self.contract, + self.entrypoint, + self.calldata, + self.block_id, + ) + .await + }) + } +} diff --git a/bin/sozo/src/commands/execute.rs b/bin/sozo/src/commands/execute.rs index a777dd19b0..663290ad85 100644 --- a/bin/sozo/src/commands/execute.rs +++ b/bin/sozo/src/commands/execute.rs @@ -22,7 +22,7 @@ pub struct ExecuteArgs { #[arg(short, long)] #[arg(value_delimiter = ',')] - #[arg(help = "The calldata to be passed to the system. Comma seperated values e.g., \ + #[arg(help = "The calldata to be passed to the system. Comma separated values e.g., \ 0x12345,0x69420.")] pub calldata: Vec, diff --git a/bin/sozo/src/commands/mod.rs b/bin/sozo/src/commands/mod.rs index fce588da4f..d0f563bce4 100644 --- a/bin/sozo/src/commands/mod.rs +++ b/bin/sozo/src/commands/mod.rs @@ -5,6 +5,7 @@ use crate::args::Commands; pub(crate) mod auth; pub(crate) mod build; +pub(crate) mod call; pub(crate) mod clean; pub(crate) mod completions; pub(crate) mod dev; @@ -27,6 +28,7 @@ pub fn run(command: Commands, config: &Config) -> Result<()> { Commands::Dev(args) => args.run(config), Commands::Auth(args) => args.run(config), Commands::Execute(args) => args.run(config), + Commands::Call(args) => args.run(config), Commands::Model(args) => args.run(config), Commands::Register(args) => args.run(config), Commands::Events(args) => args.run(config), diff --git a/bin/sozo/src/utils.rs b/bin/sozo/src/utils.rs index 76d6de797b..8bd219e5b7 100644 --- a/bin/sozo/src/utils.rs +++ b/bin/sozo/src/utils.rs @@ -1,5 +1,6 @@ use anyhow::Error; use dojo_world::contracts::world::WorldContract; +use dojo_world::contracts::WorldContractReader; use dojo_world::metadata::{dojo_metadata_from_workspace, Environment}; use scarb::core::Config; use starknet::accounts::SingleOwnerAccount; @@ -11,6 +12,15 @@ use crate::commands::options::account::AccountOptions; use crate::commands::options::starknet::StarknetOptions; use crate::commands::options::world::WorldOptions; +/// Load metadata from the Scarb configuration. +/// +/// # Arguments +/// +/// * `config` - Scarb project configuration. +/// +/// # Returns +/// +/// A [`Environment`] on success. pub fn load_metadata_from_config(config: &Config) -> Result, Error> { let env_metadata = if config.manifest_path().exists() { let ws = scarb::ops::read_workspace(config.manifest_path(), config)?; @@ -23,6 +33,18 @@ pub fn load_metadata_from_config(config: &Config) -> Result, Ok(env_metadata) } +/// Build a world contract from the provided environment. +/// +/// # Arguments +/// +/// * `world` - The world options such as the world address, +/// * `account` - The account options, +/// * `starknet` - The Starknet options such as the RPC url, +/// * `env_metadata` - Optional environment coming from Scarb configuration. +/// +/// # Returns +/// +/// A [`WorldContract`] on success. pub async fn world_from_env_metadata( world: WorldOptions, account: AccountOptions, @@ -35,3 +57,25 @@ pub async fn world_from_env_metadata( let account = account.account(provider, env_metadata.as_ref()).await?; Ok(WorldContract::new(world_address, account)) } + +/// Build a world contract reader from the provided environment. +/// +/// # Arguments +/// +/// * `world` - The world options such as the world address, +/// * `starknet` - The Starknet options such as the RPC url, +/// * `env_metadata` - Optional environment coming from Scarb configuration. +/// +/// # Returns +/// +/// A [`WorldContractReader`] on success. +pub async fn world_reader_from_env_metadata( + world: WorldOptions, + starknet: StarknetOptions, + env_metadata: &Option, +) -> Result>, Error> { + let world_address = world.address(env_metadata.as_ref())?; + let provider = starknet.provider(env_metadata.as_ref())?; + + Ok(WorldContractReader::new(world_address, provider)) +} diff --git a/crates/dojo-test-utils/src/sequencer.rs b/crates/dojo-test-utils/src/sequencer.rs index ba61129898..8a72922a06 100644 --- a/crates/dojo-test-utils/src/sequencer.rs +++ b/crates/dojo-test-utils/src/sequencer.rs @@ -101,6 +101,10 @@ impl TestSequencer { ) } + pub fn provider(&self) -> JsonRpcClient { + JsonRpcClient::new(HttpTransport::new(self.url.clone())) + } + pub fn account_at_index( &self, index: usize, diff --git a/crates/sozo/ops/src/call.rs b/crates/sozo/ops/src/call.rs new file mode 100644 index 0000000000..14bb487b5b --- /dev/null +++ b/crates/sozo/ops/src/call.rs @@ -0,0 +1,39 @@ +use anyhow::{Context, Result}; +use dojo_world::contracts::WorldContractReader; +use starknet::core::types::{BlockId, BlockTag, FieldElement, FunctionCall}; +use starknet::core::utils::get_selector_from_name; +use starknet::providers::Provider; + +use crate::utils::{get_contract_address_from_reader, parse_block_id}; + +pub async fn call( + world_reader: WorldContractReader

, + contract: String, + entrypoint: String, + calldata: Vec, + block_id: Option, +) -> Result<()> { + let contract_address = get_contract_address_from_reader(&world_reader, contract).await?; + let block_id = if let Some(block_id) = block_id { + parse_block_id(block_id)? + } else { + BlockId::Tag(BlockTag::Pending) + }; + + let output = world_reader + .provider() + .call( + FunctionCall { + contract_address, + entry_point_selector: get_selector_from_name(&entrypoint)?, + calldata, + }, + block_id, + ) + .await + .with_context(|| format!("Failed to call {entrypoint}"))?; + + println!("[ {} ]", output.iter().map(|o| format!("0x{:x}", o)).collect::>().join(" ")); + + Ok(()) +} diff --git a/crates/sozo/ops/src/lib.rs b/crates/sozo/ops/src/lib.rs index 2ba2bf238e..3d1b69ce11 100644 --- a/crates/sozo/ops/src/lib.rs +++ b/crates/sozo/ops/src/lib.rs @@ -1,4 +1,5 @@ pub mod auth; +pub mod call; pub mod events; pub mod execute; pub mod migration; diff --git a/crates/sozo/ops/src/tests/call.rs b/crates/sozo/ops/src/tests/call.rs new file mode 100644 index 0000000000..331215c03f --- /dev/null +++ b/crates/sozo/ops/src/tests/call.rs @@ -0,0 +1,147 @@ +use dojo_test_utils::sequencer::{ + get_default_test_starknet_config, SequencerConfig, TestSequencer, +}; +use dojo_world::contracts::WorldContractReader; +use starknet::accounts::SingleOwnerAccount; +use starknet::providers::jsonrpc::HttpTransport; +use starknet::providers::JsonRpcClient; +use starknet::signers::LocalWallet; +use starknet_crypto::FieldElement; + +use super::setup; +use crate::{call, utils}; + +const CONTRACT_NAME: &str = "dojo_examples::actions::actions"; +const ENTRYPOINT: &str = "tile_terrain"; + +#[tokio::test] +async fn call_with_bad_address() { + let sequencer = + TestSequencer::start(SequencerConfig::default(), get_default_test_starknet_config()).await; + + let world = setup::setup(&sequencer).await.unwrap(); + let provider = sequencer.provider(); + let world_reader = WorldContractReader::new(world.address, provider); + + assert!( + call::call( + world_reader, + "0xBadCoffeeBadCode".to_string(), + ENTRYPOINT.to_string(), + vec![FieldElement::ZERO, FieldElement::ZERO], + None + ) + .await + .is_err() + ); +} + +#[tokio::test] +async fn call_with_bad_name() { + let sequencer = + TestSequencer::start(SequencerConfig::default(), get_default_test_starknet_config()).await; + + let world = setup::setup(&sequencer).await.unwrap(); + let provider = sequencer.provider(); + let world_reader = WorldContractReader::new(world.address, provider); + + assert!( + call::call( + world_reader, + "BadName".to_string(), + ENTRYPOINT.to_string(), + vec![FieldElement::ZERO, FieldElement::ZERO], + None + ) + .await + .is_err() + ); +} + +#[tokio::test] +async fn call_with_bad_entrypoint() { + let sequencer = + TestSequencer::start(SequencerConfig::default(), get_default_test_starknet_config()).await; + + let world = setup::setup(&sequencer).await.unwrap(); + let provider = sequencer.provider(); + let world_reader = WorldContractReader::new(world.address, provider); + + assert!( + call::call( + world_reader, + CONTRACT_NAME.to_string(), + "BadEntryPoint".to_string(), + vec![FieldElement::ZERO, FieldElement::ZERO], + None + ) + .await + .is_err() + ); +} + +#[tokio::test] +async fn call_with_bad_calldata() { + let sequencer = + TestSequencer::start(SequencerConfig::default(), get_default_test_starknet_config()).await; + + let world = setup::setup(&sequencer).await.unwrap(); + let provider = sequencer.provider(); + let world_reader = WorldContractReader::new(world.address, provider); + + assert!( + call::call(world_reader, CONTRACT_NAME.to_string(), ENTRYPOINT.to_string(), vec![], None) + .await + .is_err() + ); +} + +#[tokio::test] +async fn call_with_contract_name() { + let sequencer = + TestSequencer::start(SequencerConfig::default(), get_default_test_starknet_config()).await; + + let world = setup::setup(&sequencer).await.unwrap(); + let provider = sequencer.provider(); + let world_reader = WorldContractReader::new(world.address, provider); + + assert!( + call::call( + world_reader, + CONTRACT_NAME.to_string(), + ENTRYPOINT.to_string(), + vec![FieldElement::ZERO, FieldElement::ZERO], + None, + ) + .await + .is_ok() + ); +} + +#[tokio::test] +async fn call_with_contract_address() { + let sequencer = + TestSequencer::start(SequencerConfig::default(), get_default_test_starknet_config()).await; + + let world = setup::setup(&sequencer).await.unwrap(); + let provider = sequencer.provider(); + let world_reader = WorldContractReader::new(world.address, provider); + + let contract_address = utils::get_contract_address::< + SingleOwnerAccount, LocalWallet>, + >(&world, CONTRACT_NAME.to_string()) + .await + .unwrap(); + + assert!( + call::call( + world_reader, + format!("{:#x}", contract_address), + ENTRYPOINT.to_string(), + vec![FieldElement::ZERO, FieldElement::ZERO], + None, + ) + .await + .is_ok() + ); +} diff --git a/crates/sozo/ops/src/tests/mod.rs b/crates/sozo/ops/src/tests/mod.rs index 1cc5eab8d1..25bdba5697 100644 --- a/crates/sozo/ops/src/tests/mod.rs +++ b/crates/sozo/ops/src/tests/mod.rs @@ -1,3 +1,4 @@ pub mod auth; +pub mod call; pub mod setup; pub mod utils; diff --git a/crates/sozo/ops/src/tests/utils.rs b/crates/sozo/ops/src/tests/utils.rs index 92d22fb0b6..71859f079e 100644 --- a/crates/sozo/ops/src/tests/utils.rs +++ b/crates/sozo/ops/src/tests/utils.rs @@ -2,7 +2,9 @@ use dojo_test_utils::sequencer::{ get_default_test_starknet_config, SequencerConfig, TestSequencer, }; use dojo_world::contracts::world::WorldContract; -use starknet::core::types::FieldElement; +use dojo_world::contracts::WorldContractReader; +use starknet::accounts::ConnectedAccount; +use starknet::core::types::{BlockId, BlockTag, FieldElement}; use super::setup; use crate::utils; @@ -34,3 +36,70 @@ async fn get_contract_address_from_string() { assert_eq!(contract_address, FieldElement::from_hex_be("0x1234").unwrap()); } + +#[tokio::test(flavor = "multi_thread")] +async fn get_contract_address_from_world_with_world_reader() { + let sequencer = + TestSequencer::start(SequencerConfig::default(), get_default_test_starknet_config()).await; + + let world = setup::setup(&sequencer).await.unwrap(); + let account = sequencer.account(); + let provider = account.provider(); + let world_reader = WorldContractReader::new(world.address, provider); + + let contract_address = + utils::get_contract_address_from_reader(&world_reader, ACTION_CONTRACT_NAME.to_string()) + .await + .unwrap(); + + assert!(contract_address != FieldElement::ZERO); +} + +#[tokio::test(flavor = "multi_thread")] +async fn get_contract_address_from_string_with_world_reader() { + let sequencer = + TestSequencer::start(SequencerConfig::default(), get_default_test_starknet_config()).await; + + let provider = sequencer.provider(); + let world_reader = WorldContractReader::new(FieldElement::ZERO, provider); + + let contract_address = + utils::get_contract_address_from_reader(&world_reader, "0x1234".to_string()).await.unwrap(); + + assert_eq!(contract_address, FieldElement::from_hex_be("0x1234").unwrap()); +} + +#[test] +fn parse_block_id_bad_hash() { + assert!(utils::parse_block_id("0xBadHash".to_string()).is_err()); +} + +#[test] +fn parse_block_id_bad_string() { + assert!(utils::parse_block_id("BadString".to_string()).is_err()); +} + +#[test] +fn parse_block_id_hash() { + assert!( + utils::parse_block_id("0x1234".to_string()).unwrap() + == BlockId::Hash(FieldElement::from_hex_be("0x1234").unwrap()) + ); +} + +#[test] +fn parse_block_id_pending() { + assert!( + utils::parse_block_id("pending".to_string()).unwrap() == BlockId::Tag(BlockTag::Pending) + ); +} + +#[test] +fn parse_block_id_latest() { + assert!(utils::parse_block_id("latest".to_string()).unwrap() == BlockId::Tag(BlockTag::Latest)); +} + +#[test] +fn parse_block_id_number() { + assert!(utils::parse_block_id("42".to_string()).unwrap() == BlockId::Number(42)); +} diff --git a/crates/sozo/ops/src/utils.rs b/crates/sozo/ops/src/utils.rs index 673a9a9a29..00735e59a4 100644 --- a/crates/sozo/ops/src/utils.rs +++ b/crates/sozo/ops/src/utils.rs @@ -1,9 +1,11 @@ -use anyhow::Result; -use dojo_world::contracts::world::WorldContract; +use anyhow::{anyhow, Result}; +use dojo_world::contracts::world::{WorldContract, WorldContractReader}; use dojo_world::migration::strategy::generate_salt; use dojo_world::utils::{execution_status_from_maybe_pending_receipt, TransactionWaiter}; use starknet::accounts::ConnectedAccount; -use starknet::core::types::{ExecutionResult, FieldElement, InvokeTransactionResult}; +use starknet::core::types::{ + BlockId, BlockTag, ExecutionResult, FieldElement, InvokeTransactionResult, +}; use starknet::providers::Provider; /// Retrieves a contract address from it's name @@ -35,6 +37,35 @@ pub async fn get_contract_address( } } +/// Retrieves a contract address from its name +/// using a world contract reader, or parses a hex string into +/// a [`FieldElement`]. +/// +/// # Arguments +/// +/// * `world_reader` - The world contract reader. +/// * `name_or_address` - A string with a contract name or a hexadecimal address. +/// +/// # Returns +/// +/// A [`FieldElement`] with the address of the contract on success. +pub async fn get_contract_address_from_reader( + world_reader: &WorldContractReader

, + name_or_address: String, +) -> Result { + if name_or_address.starts_with("0x") { + FieldElement::from_hex_be(&name_or_address).map_err(anyhow::Error::from) + } else { + let contract_class_hash = world_reader.base().call().await?; + Ok(starknet::core::utils::get_contract_address( + generate_salt(&name_or_address), + contract_class_hash.into(), + &[], + world_reader.address, + )) + } +} + /// Handles a transaction result configuring a /// [`TransactionWaiter`] if required. /// @@ -76,3 +107,30 @@ where Ok(()) } + +/// Parses a string into a [`BlockId`]. +/// +/// # Arguments +/// +/// * `block_str` - a string representing a block ID. It could be a +/// block hash starting with 0x, a block number, 'pending' or 'latest'. +/// +/// # Returns +/// +/// The parsed [`BlockId`] on success. +pub fn parse_block_id(block_str: String) -> Result { + if block_str.starts_with("0x") { + let hash = FieldElement::from_hex_be(&block_str) + .map_err(|_| anyhow!("Unable to parse block hash: {}", block_str))?; + Ok(BlockId::Hash(hash)) + } else if block_str.eq("pending") { + Ok(BlockId::Tag(BlockTag::Pending)) + } else if block_str.eq("latest") { + Ok(BlockId::Tag(BlockTag::Latest)) + } else { + match block_str.parse::() { + Ok(n) => Ok(BlockId::Number(n)), + Err(_) => Err(anyhow!("Unable to parse block ID: {}", block_str)), + } + } +} From 8d66222e8212585bdeb28fbd0f1b1acf88991043 Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Fri, 29 Mar 2024 14:19:29 +0800 Subject: [PATCH 2/4] Bump rust to `1.76.0` (#1720) * bump rust to `1.76.0` * wip * clippy * update rust ver in ci * upate dockerfile rust ver * update ci image --- .devcontainer/Dockerfile | 2 +- .github/workflows/ci.yml | 18 ++--- .github/workflows/release.yml | 2 +- crates/benches/src/main.rs | 2 +- crates/dojo-types/src/packing.rs | 4 +- .../core/src/service/messaging/service.rs | 16 ++--- .../primitives/src/utils/transaction.rs | 68 +++++++++---------- crates/katana/rpc/rpc/src/lib.rs | 2 + crates/torii/graphql/src/tests/models_test.rs | 1 + rust-toolchain.toml | 2 +- 10 files changed, 59 insertions(+), 58 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 441c7e91b5..6ab5bec682 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -23,7 +23,7 @@ ENV LLVM_SYS_170_PREFIX=/usr/lib/llvm-17 ENV TABLEGEN_170_PREFIX=/usr/lib/llvm-17 # To allow independent workflow of the container, the rust-toolchain is explicitely given. -RUN echo "1.74.0" > rust_toolchain_version +RUN echo "1.76.0" > rust_toolchain_version # Install cargo-binstall RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9414adf04..a6c68c6bb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,13 +8,13 @@ on: env: CARGO_TERM_COLOR: always - RUST_VERSION: 1.74.0 + RUST_VERSION: 1.76.0 jobs: test: runs-on: ubuntu-latest-16-cores container: - image: nondeterministickari/dojo-dev:cc6554da + image: ghcr.io/dojoengine/dojo-dev:a884990 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -31,7 +31,7 @@ jobs: ensure-wasm: runs-on: ubuntu-latest container: - image: nondeterministickari/dojo-dev:cc6554da + image: ghcr.io/dojoengine/dojo-dev:a884990 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -66,7 +66,7 @@ jobs: dojo-core-test: runs-on: ubuntu-latest container: - image: nondeterministickari/dojo-dev:cc6554da + image: ghcr.io/dojoengine/dojo-dev:a884990 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -75,7 +75,7 @@ jobs: dojo-spawn-and-move-example-test: runs-on: ubuntu-latest container: - image: nondeterministickari/dojo-dev:cc6554da + image: ghcr.io/dojoengine/dojo-dev:a884990 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -84,7 +84,7 @@ jobs: dojo-world-bindings-check: runs-on: ubuntu-latest container: - image: nondeterministickari/dojo-dev:cc6554da + image: ghcr.io/dojoengine/dojo-dev:a884990 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -93,7 +93,7 @@ jobs: clippy: runs-on: ubuntu-latest container: - image: nondeterministickari/dojo-dev:cc6554da + image: ghcr.io/dojoengine/dojo-dev:a884990 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -102,7 +102,7 @@ jobs: fmt: runs-on: ubuntu-latest container: - image: nondeterministickari/dojo-dev:cc6554da + image: ghcr.io/dojoengine/dojo-dev:a884990 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -111,7 +111,7 @@ jobs: docs: runs-on: ubuntu-latest container: - image: nondeterministickari/dojo-dev:cc6554da + image: ghcr.io/dojoengine/dojo-dev:a884990 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5fd3f3870b..70c88bd2c0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,7 +8,7 @@ on: env: CARGO_TERM_COLOR: always - RUST_VERSION: 1.74.0 + RUST_VERSION: 1.76.0 REGISTRY_IMAGE: ghcr.io/${{ github.repository }} jobs: diff --git a/crates/benches/src/main.rs b/crates/benches/src/main.rs index 62330c14e4..8fe3434388 100644 --- a/crates/benches/src/main.rs +++ b/crates/benches/src/main.rs @@ -36,7 +36,7 @@ fn main() { } } - let mut pairs = map.into_iter().map(|(name, runs)| (name, runs)).collect::>(); + let mut pairs = map.into_iter().collect::>(); pairs.sort_by_key(|(key, _)| key.clone()); for (name, mut runs) in pairs { diff --git a/crates/dojo-types/src/packing.rs b/crates/dojo-types/src/packing.rs index c011a63511..acba62efd1 100644 --- a/crates/dojo-types/src/packing.rs +++ b/crates/dojo-types/src/packing.rs @@ -205,7 +205,7 @@ mod tests { #[test] fn parse_simple_with_invalid_value() { - let data = &vec![FieldElement::default()]; - assert!(matches!(super::parse_simple(data), Err(ParseError::InvalidSchema))); + let data = [FieldElement::default()]; + assert!(matches!(super::parse_simple(&data), Err(ParseError::InvalidSchema))); } } diff --git a/crates/katana/core/src/service/messaging/service.rs b/crates/katana/core/src/service/messaging/service.rs index ea0d124904..64730c0641 100644 --- a/crates/katana/core/src/service/messaging/service.rs +++ b/crates/katana/core/src/service/messaging/service.rs @@ -131,20 +131,18 @@ impl MessagingService { } else { match messenger.as_ref() { MessengerMode::Ethereum(inner) => { - let hashes = inner - .send_messages(&messages) - .await - .map(|hashes| hashes.iter().map(|h| format!("{h:#x}")).collect())?; + let hashes = inner.send_messages(&messages).await.map(|hashes| { + hashes.iter().map(|h| format!("{h:#x}")).collect::>() + })?; trace_msg_to_l1_sent(&messages, &hashes); Ok(Some((block_num, hashes.len()))) } #[cfg(feature = "starknet-messaging")] MessengerMode::Starknet(inner) => { - let hashes = inner - .send_messages(&messages) - .await - .map(|hashes| hashes.iter().map(|h| format!("{h:#x}")).collect())?; + let hashes = inner.send_messages(&messages).await.map(|hashes| { + hashes.iter().map(|h| format!("{h:#x}")).collect::>() + })?; trace_msg_to_l1_sent(&messages, &hashes); Ok(Some((block_num, hashes.len()))) } @@ -251,7 +249,7 @@ fn interval_from_seconds(secs: u64) -> Interval { interval } -fn trace_msg_to_l1_sent(messages: &Vec, hashes: &Vec) { +fn trace_msg_to_l1_sent(messages: &[MessageToL1], hashes: &[String]) { assert_eq!(messages.len(), hashes.len()); #[cfg(feature = "starknet-messaging")] diff --git a/crates/katana/primitives/src/utils/transaction.rs b/crates/katana/primitives/src/utils/transaction.rs index 7bada6be65..f9922f268d 100644 --- a/crates/katana/primitives/src/utils/transaction.rs +++ b/crates/katana/primitives/src/utils/transaction.rs @@ -274,6 +274,40 @@ pub fn compute_l1_message_hash( H256::from_slice(msg.hash().as_bytes()) } +fn encode_gas_bound(name: &[u8], bound: &ResourceBounds) -> FieldElement { + let mut buffer = [0u8; 32]; + let (remainder, max_price) = buffer.split_at_mut(128 / 8); + let (gas_kind, max_amount) = remainder.split_at_mut(64 / 8); + + let padding = gas_kind.len() - name.len(); + gas_kind[padding..].copy_from_slice(name); + max_amount.copy_from_slice(&bound.max_amount.to_be_bytes()); + max_price.copy_from_slice(&bound.max_price_per_unit.to_be_bytes()); + + FieldElement::from_bytes_be(&buffer).expect("Packed resource should fit into felt") +} + +fn hash_fee_fields( + tip: u64, + l1_gas_bounds: &ResourceBounds, + l2_gas_bounds: &ResourceBounds, +) -> FieldElement { + poseidon_hash_many(&[ + tip.into(), + encode_gas_bound(b"L1_GAS", l1_gas_bounds), + encode_gas_bound(b"L2_GAS", l2_gas_bounds), + ]) +} + +fn encode_da_mode( + nonce_da_mode: &DataAvailabilityMode, + fee_da_mode: &DataAvailabilityMode, +) -> FieldElement { + let nonce = (*nonce_da_mode as u64) << 32; + let fee = *fee_da_mode as u64; + FieldElement::from(nonce + fee) +} + #[cfg(test)] mod tests { use starknet::core::chain_id; @@ -334,37 +368,3 @@ mod tests { ); } } - -fn encode_gas_bound(name: &[u8], bound: &ResourceBounds) -> FieldElement { - let mut buffer = [0u8; 32]; - let (remainder, max_price) = buffer.split_at_mut(128 / 8); - let (gas_kind, max_amount) = remainder.split_at_mut(64 / 8); - - let padding = gas_kind.len() - name.len(); - gas_kind[padding..].copy_from_slice(name); - max_amount.copy_from_slice(&bound.max_amount.to_be_bytes()); - max_price.copy_from_slice(&bound.max_price_per_unit.to_be_bytes()); - - FieldElement::from_bytes_be(&buffer).expect("Packed resource should fit into felt") -} - -fn hash_fee_fields( - tip: u64, - l1_gas_bounds: &ResourceBounds, - l2_gas_bounds: &ResourceBounds, -) -> FieldElement { - poseidon_hash_many(&[ - tip.into(), - encode_gas_bound(b"L1_GAS", l1_gas_bounds), - encode_gas_bound(b"L2_GAS", l2_gas_bounds), - ]) -} - -fn encode_da_mode( - nonce_da_mode: &DataAvailabilityMode, - fee_da_mode: &DataAvailabilityMode, -) -> FieldElement { - let nonce = (*nonce_da_mode as u64) << 32; - let fee = *fee_da_mode as u64; - FieldElement::from(nonce + fee) -} diff --git a/crates/katana/rpc/rpc/src/lib.rs b/crates/katana/rpc/rpc/src/lib.rs index d5974b69d8..22bc8111d7 100644 --- a/crates/katana/rpc/rpc/src/lib.rs +++ b/crates/katana/rpc/rpc/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::blocks_in_conditions)] + pub mod config; pub mod dev; pub mod katana; diff --git a/crates/torii/graphql/src/tests/models_test.rs b/crates/torii/graphql/src/tests/models_test.rs index ff3e825ec5..c5d18c8466 100644 --- a/crates/torii/graphql/src/tests/models_test.rs +++ b/crates/torii/graphql/src/tests/models_test.rs @@ -151,6 +151,7 @@ mod tests { // End to end test spins up a test sequencer and deploys types-test project, this takes a while // to run so combine all related tests into one + #[allow(clippy::get_first)] #[tokio::test(flavor = "multi_thread")] async fn models_test() -> Result<()> { let pool = spinup_types_test().await?; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 639f4f17d9..624eb0ea63 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.74.0" +channel = "1.76.0" From 3de11db06c240aa78ad74a1f23e78ec071ceb45c Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Fri, 29 Mar 2024 02:58:00 -0400 Subject: [PATCH 3/4] Update devcontainer image hash: 8d66222 (#1727) Co-authored-by: kariy --- .devcontainer/devcontainer.json | 2 +- .github/workflows/bench.yml | 2 +- .github/workflows/ci.yml | 16 ++++++++-------- .github/workflows/release-dispatch.yml | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 25ed6cbf30..9245e8f8d6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ // https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/rust { "name": "Rust", - "image": "ghcr.io/dojoengine/dojo-dev:5340720", + "image": "ghcr.io/dojoengine/dojo-dev:8d66222", "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index 3edc299449..40bfd5918f 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -14,7 +14,7 @@ jobs: build: runs-on: ubuntu-latest container: - image: ghcr.io/dojoengine/dojo-dev:5340720 + image: ghcr.io/dojoengine/dojo-dev:8d66222 steps: - uses: actions/checkout@v3 - run: git config --global --add safe.directory "$GITHUB_WORKSPACE" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6c68c6bb8..4421507c96 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: test: runs-on: ubuntu-latest-16-cores container: - image: ghcr.io/dojoengine/dojo-dev:a884990 + image: ghcr.io/dojoengine/dojo-dev:8d66222 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -31,7 +31,7 @@ jobs: ensure-wasm: runs-on: ubuntu-latest container: - image: ghcr.io/dojoengine/dojo-dev:a884990 + image: ghcr.io/dojoengine/dojo-dev:8d66222 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -66,7 +66,7 @@ jobs: dojo-core-test: runs-on: ubuntu-latest container: - image: ghcr.io/dojoengine/dojo-dev:a884990 + image: ghcr.io/dojoengine/dojo-dev:8d66222 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -75,7 +75,7 @@ jobs: dojo-spawn-and-move-example-test: runs-on: ubuntu-latest container: - image: ghcr.io/dojoengine/dojo-dev:a884990 + image: ghcr.io/dojoengine/dojo-dev:8d66222 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -84,7 +84,7 @@ jobs: dojo-world-bindings-check: runs-on: ubuntu-latest container: - image: ghcr.io/dojoengine/dojo-dev:a884990 + image: ghcr.io/dojoengine/dojo-dev:8d66222 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -93,7 +93,7 @@ jobs: clippy: runs-on: ubuntu-latest container: - image: ghcr.io/dojoengine/dojo-dev:a884990 + image: ghcr.io/dojoengine/dojo-dev:8d66222 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -102,7 +102,7 @@ jobs: fmt: runs-on: ubuntu-latest container: - image: ghcr.io/dojoengine/dojo-dev:a884990 + image: ghcr.io/dojoengine/dojo-dev:8d66222 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 @@ -111,7 +111,7 @@ jobs: docs: runs-on: ubuntu-latest container: - image: ghcr.io/dojoengine/dojo-dev:a884990 + image: ghcr.io/dojoengine/dojo-dev:8d66222 steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/release-dispatch.yml b/.github/workflows/release-dispatch.yml index fc9364f192..0e3faa3d13 100644 --- a/.github/workflows/release-dispatch.yml +++ b/.github/workflows/release-dispatch.yml @@ -14,7 +14,7 @@ jobs: contents: write runs-on: ubuntu-latest container: - image: ghcr.io/dojoengine/dojo-dev:5340720 + image: ghcr.io/dojoengine/dojo-dev:8d66222 steps: # Workaround described here: https://github.com/actions/checkout/issues/760 - uses: actions/checkout@v3 From 48e72610428b7d0c9340fd21ee363a4638883c56 Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Fri, 29 Mar 2024 15:29:46 +0800 Subject: [PATCH 4/4] Re-export `reth-metrics-derive` crate from `dojo-metrics` (#1719) ref #1369 - re-export [reth-metrics-derive](https://github.com/paradigmxyz/reth/tree/v0.2.0-beta.4/crates/metrics/metrics-derive) crate from dojo-metrics - rename metrics -> dojo-metrics crate - re-export core metrics stuff from dojo-metrics --- this PR relies on #1720 bcs reth's MSRV is 1.76.0, otherwise can't build reth-metrics-derive. --- Cargo.lock | 247 ++++++++++------------ Cargo.toml | 6 +- bin/katana/Cargo.toml | 5 +- bin/katana/src/main.rs | 2 +- bin/torii/Cargo.toml | 7 +- bin/torii/src/main.rs | 2 +- crates/metrics/Cargo.toml | 9 +- crates/metrics/src/lib.rs | 6 + crates/metrics/src/prometheus_exporter.rs | 71 ++++--- crates/torii/server/Cargo.toml | 5 +- 10 files changed, 169 insertions(+), 191 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36c66dfb88..011de0d2c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -598,7 +598,7 @@ dependencies = [ "proc-macro2", "quote", "strum 0.25.0", - "syn 2.0.49", + "syn 2.0.55", "thiserror", ] @@ -705,7 +705,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -753,7 +753,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -770,7 +770,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -841,7 +841,7 @@ checksum = "823b8bb275161044e2ac7a25879cb3e2480cb403e3943022c7c769c599b756aa" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -1027,7 +1027,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -1399,7 +1399,7 @@ dependencies = [ "quote", "serde_json", "starknet 0.8.0", - "syn 2.0.49", + "syn 2.0.55", "thiserror", ] @@ -1412,7 +1412,7 @@ dependencies = [ "quote", "serde_json", "starknet 0.9.0", - "syn 2.0.49", + "syn 2.0.55", "thiserror", ] @@ -1428,7 +1428,7 @@ dependencies = [ "quote", "serde_json", "starknet 0.8.0", - "syn 2.0.49", + "syn 2.0.55", "thiserror", ] @@ -1444,7 +1444,7 @@ dependencies = [ "quote", "serde_json", "starknet 0.9.0", - "syn 2.0.49", + "syn 2.0.55", "thiserror", ] @@ -1461,7 +1461,7 @@ dependencies = [ "quote", "serde_json", "starknet 0.9.0", - "syn 2.0.49", + "syn 2.0.55", "thiserror", ] @@ -1697,7 +1697,7 @@ checksum = "fef002aac874d76492eb9577dab663f9a84fe4584b4215c7ebfda7d025fcadae" dependencies = [ "cairo-lang-debug", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -2430,7 +2430,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -2850,7 +2850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30d2b3721e861707777e3195b0158f950ae6dc4a27e4d02ff9f67e3eb3de199e" dependencies = [ "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -2897,7 +2897,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -2958,7 +2958,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -2980,7 +2980,7 @@ checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be" dependencies = [ "darling_core 0.20.6", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -3084,34 +3084,13 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "derive_builder" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" -dependencies = [ - "derive_builder_macro 0.12.0", -] - [[package]] name = "derive_builder" version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7" dependencies = [ - "derive_builder_macro 0.20.0", -] - -[[package]] -name = "derive_builder_core" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" -dependencies = [ - "darling 0.14.4", - "proc-macro2", - "quote", - "syn 1.0.109", + "derive_builder_macro", ] [[package]] @@ -3123,17 +3102,7 @@ dependencies = [ "darling 0.20.6", "proc-macro2", "quote", - "syn 2.0.49", -] - -[[package]] -name = "derive_builder_macro" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" -dependencies = [ - "derive_builder_core 0.12.0", - "syn 1.0.109", + "syn 2.0.55", ] [[package]] @@ -3142,8 +3111,8 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" dependencies = [ - "derive_builder_core 0.20.0", - "syn 2.0.49", + "derive_builder_core", + "syn 2.0.55", ] [[package]] @@ -3280,7 +3249,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -3384,6 +3353,24 @@ dependencies = [ "tower-lsp", ] +[[package]] +name = "dojo-metrics" +version = "0.6.0-alpha.9" +dependencies = [ + "anyhow", + "hyper", + "jemalloc-ctl", + "jemallocator", + "metrics", + "metrics-exporter-prometheus", + "metrics-process", + "metrics-util", + "reth-metrics-derive", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "dojo-test-utils" version = "0.6.0-alpha.9" @@ -3649,7 +3636,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -3661,7 +3648,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -3849,7 +3836,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "syn 2.0.49", + "syn 2.0.55", "toml 0.8.10", "walkdir", ] @@ -3867,7 +3854,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -3893,7 +3880,7 @@ dependencies = [ "serde", "serde_json", "strum 0.25.0", - "syn 2.0.49", + "syn 2.0.55", "tempfile", "thiserror", "tiny-keccak", @@ -4404,7 +4391,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -4496,7 +4483,7 @@ checksum = "d4cf186fea4af17825116f72932fe52cce9a13bae39ff63b4dc0cfdb3fb4bde1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -4941,7 +4928,7 @@ checksum = "d75e7ab728059f595f6ddc1ad8771b8d6a231971ae493d9d5948ecad366ee8bb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -6672,13 +6659,12 @@ dependencies = [ "clap_complete", "common", "console", + "dojo-metrics", "katana-core", "katana-executor", "katana-primitives", "katana-rpc", "katana-rpc-api", - "metrics 0.6.0-alpha.9", - "metrics-process", "serde_json", "shellexpand", "starknet_api", @@ -6703,7 +6689,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -7505,7 +7491,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -7834,23 +7820,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "metrics" -version = "0.6.0-alpha.9" -dependencies = [ - "anyhow", - "hyper", - "jemalloc-ctl", - "jemallocator", - "metrics 0.21.1", - "metrics-exporter-prometheus", - "metrics-process", - "metrics-util", - "thiserror", - "tokio", - "tracing", -] - [[package]] name = "metrics" version = "0.21.1" @@ -7862,16 +7831,6 @@ dependencies = [ "portable-atomic", ] -[[package]] -name = "metrics" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b9e10a211c839210fd7f99954bda26e5f8e26ec686ad68da6a32df7c80e782" -dependencies = [ - "ahash 0.8.8", - "portable-atomic", -] - [[package]] name = "metrics-exporter-prometheus" version = "0.12.2" @@ -7882,7 +7841,7 @@ dependencies = [ "hyper", "indexmap 1.9.3", "ipnet", - "metrics 0.21.1", + "metrics", "metrics-util", "quanta", "thiserror", @@ -7898,18 +7857,18 @@ checksum = "38b4faf00617defe497754acde3024865bc143d44a86799b24e191ecff91354f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] name = "metrics-process" -version = "1.2.0" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ab55aa892047d9fa19d390afc5318492f956de3ec88a098adb4c0e663b4914" +checksum = "6aa2a67e2580fbeba4d5a96e659945981e700a383b4cea1432e0cfc18f58c5da" dependencies = [ "libproc", "mach2", - "metrics 0.22.0", + "metrics", "once_cell", "procfs", "rlimit", @@ -7927,7 +7886,7 @@ dependencies = [ "crossbeam-utils", "hashbrown 0.13.1", "indexmap 1.9.3", - "metrics 0.21.1", + "metrics", "num_cpus", "ordered-float 3.9.2", "quanta", @@ -8513,7 +8472,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -8624,7 +8583,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -8939,7 +8898,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -9003,7 +8962,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -9047,7 +9006,7 @@ checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -9276,7 +9235,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -9347,9 +9306,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -9407,7 +9366,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -9489,7 +9448,7 @@ dependencies = [ "prost 0.12.3", "prost-types 0.12.3", "regex", - "syn 2.0.49", + "syn 2.0.55", "tempfile", "which 4.4.2", ] @@ -9517,7 +9476,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -9937,6 +9896,18 @@ dependencies = [ "libc", ] +[[package]] +name = "reth-metrics-derive" +version = "0.2.0-beta.4" +source = "git+https://github.com/paradigmxyz/reth.git?tag=v0.2.0-beta.4#c04dbe6e9bd05be5da3a5d541adbf76166c14a08" +dependencies = [ + "once_cell", + "proc-macro2", + "quote", + "regex", + "syn 2.0.55", +] + [[package]] name = "rfc6979" version = "0.4.0" @@ -10062,7 +10033,7 @@ dependencies = [ "regex", "relative-path", "rustc_version 0.4.0", - "syn 2.0.49", + "syn 2.0.55", "unicode-ident", ] @@ -10075,7 +10046,7 @@ dependencies = [ "quote", "rand", "rustc_version 0.4.0", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -10152,7 +10123,7 @@ name = "runner-macro" version = "0.6.0-alpha.9" dependencies = [ "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -10504,7 +10475,7 @@ dependencies = [ "create-output-dir", "data-encoding", "deno_task_shell", - "derive_builder 0.20.0", + "derive_builder", "directories", "dunce", "fs4", @@ -10590,7 +10561,7 @@ version = "1.11.1" source = "git+https://github.com/software-mansion/scarb?tag=v2.5.4#28dee92c87e97bacefb2a300e7a102455936eeca" dependencies = [ "camino", - "derive_builder 0.12.0", + "derive_builder", "semver 1.0.22", "serde", "serde_json", @@ -10817,7 +10788,7 @@ checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -10862,7 +10833,7 @@ checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -10911,7 +10882,7 @@ dependencies = [ "darling 0.20.6", "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -10946,7 +10917,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -11829,7 +11800,7 @@ checksum = "af6527b845423542c8a16e060ea1bc43f67229848e7cd4c4d80be994a84220ce" dependencies = [ "starknet-curve 0.4.1", "starknet-ff", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -11872,7 +11843,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c5d2964612f0ccd0a700279e33cfc98d6db04f64645ff834f3b7ec422142d7a" dependencies = [ "starknet-core 0.9.0", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -12140,7 +12111,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -12225,9 +12196,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.49" +version = "2.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915aea9e586f80826ee59f8453c1101f9d1c4b3964cd2460185ee8e299ada496" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" dependencies = [ "proc-macro2", "quote", @@ -12346,7 +12317,7 @@ checksum = "7ba277e77219e9eea169e8508942db1bf5d8a41ff2db9b20aab5a5aadc9fa25d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -12366,7 +12337,7 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -12503,7 +12474,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -12730,7 +12701,7 @@ dependencies = [ "proc-macro2", "prost-build 0.12.3", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -12802,6 +12773,7 @@ dependencies = [ "clap", "common", "ctrlc", + "dojo-metrics", "dojo-types", "dojo-world", "either", @@ -12812,8 +12784,6 @@ dependencies = [ "hyper-reverse-proxy", "indexmap 1.9.3", "lazy_static", - "metrics 0.6.0-alpha.9", - "metrics-process", "scarb", "serde", "serde_json", @@ -13027,6 +12997,7 @@ dependencies = [ "chrono", "clap", "ctrlc", + "dojo-metrics", "dojo-types", "dojo-world", "either", @@ -13037,8 +13008,6 @@ dependencies = [ "hyper-reverse-proxy", "indexmap 1.9.3", "lazy_static", - "metrics 0.6.0-alpha.9", - "metrics-process", "scarb", "serde", "serde_json", @@ -13146,7 +13115,7 @@ checksum = "84fd902d4e0b9a4b27f2f440108dc034e1758628a9b702f8ec61ad66355422fa" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -13175,7 +13144,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -13324,7 +13293,7 @@ checksum = "563b3b88238ec95680aef36bdece66896eaa7ce3c0f1b4f39d38fb2435261352" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -13653,7 +13622,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", "wasm-bindgen-shared", ] @@ -13687,7 +13656,7 @@ checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -13720,7 +13689,7 @@ checksum = "a5211b7550606857312bba1d978a8ec75692eae187becc5e680444fffc5e6f89" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -14513,7 +14482,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] @@ -14533,7 +14502,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.49", + "syn 2.0.55", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9106840bb0..26bae6c455 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ lto = "fat" common = { path = "crates/common" } # metrics -metrics = { path = "crates/metrics" } +dojo-metrics = { path = "crates/metrics" } # dojo-lang dojo-bindgen = { path = "crates/dojo-bindgen" } @@ -139,12 +139,13 @@ indoc = "1.0.7" itertools = "0.10.3" jsonrpsee = { version = "0.16.2", default-features = false } lazy_static = "1.4.0" -metrics-process = "1.0.9" +metrics = "0.21.1" num-traits = { version = "0.2", default-features = false } once_cell = "1.0" parking_lot = "0.12.1" pretty_assertions = "1.2.1" rayon = "1.8.0" +regex = "1.10.3" salsa = "0.16.1" scarb = { git = "https://github.com/software-mansion/scarb", tag = "v2.5.4" } scarb-ui = { git = "https://github.com/software-mansion/scarb", tag = "v2.5.4" } @@ -166,7 +167,6 @@ tokio = { version = "1.32.0", features = [ "full" ] } toml = "0.7.4" tracing = "0.1.34" tracing-subscriber = { version = "0.3.16", features = [ "env-filter", "json" ] } -regex = "1.10.3" url = { version = "2.4.0", features = [ "serde" ] } rstest = "0.18.2" diff --git a/bin/katana/Cargo.toml b/bin/katana/Cargo.toml index 774a438211..e268ad2f02 100644 --- a/bin/katana/Cargo.toml +++ b/bin/katana/Cargo.toml @@ -13,13 +13,12 @@ clap.workspace = true clap_complete.workspace = true common.workspace = true console.workspace = true +dojo-metrics.workspace = true katana-core.workspace = true katana-executor.workspace = true katana-primitives.workspace = true katana-rpc-api.workspace = true katana-rpc.workspace = true -metrics-process.workspace = true -metrics.workspace = true serde_json.workspace = true shellexpand = "3.1.0" starknet_api.workspace = true @@ -37,6 +36,6 @@ default = [ "blockifier", "jemalloc", "messaging" ] blockifier = [ "katana-executor/blockifier" ] sir = [ "katana-executor/sir" ] -jemalloc = [ "metrics/jemalloc" ] +jemalloc = [ "dojo-metrics/jemalloc" ] messaging = [ "katana-core/messaging" ] starknet-messaging = [ "katana-core/starknet-messaging", "messaging" ] diff --git a/bin/katana/src/main.rs b/bin/katana/src/main.rs index 0c62ce949a..e9028dfbe0 100644 --- a/bin/katana/src/main.rs +++ b/bin/katana/src/main.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use clap::{CommandFactory, Parser}; use clap_complete::{generate, Shell}; use console::Style; +use dojo_metrics::{metrics_process, prometheus_exporter}; use katana_core::constants::MAX_RECURSION_DEPTH; use katana_core::env::get_default_vm_resource_fee_cost; use katana_core::sequencer::KatanaSequencer; @@ -15,7 +16,6 @@ use katana_primitives::env::{CfgEnv, FeeTokenAddressses}; use katana_primitives::genesis::allocation::GenesisAccountAlloc; use katana_primitives::genesis::Genesis; use katana_rpc::{spawn, NodeHandle}; -use metrics::prometheus_exporter; use tokio::signal::ctrl_c; use tracing::info; diff --git a/bin/torii/Cargo.toml b/bin/torii/Cargo.toml index eb01a20f41..9c21d160b9 100644 --- a/bin/torii/Cargo.toml +++ b/bin/torii/Cargo.toml @@ -14,6 +14,7 @@ chrono.workspace = true clap.workspace = true common.workspace = true ctrlc = { version = "3.4", features = [ "termination" ] } +dojo-metrics.workspace = true dojo-types.workspace = true dojo-world.workspace = true either = "1.9.0" @@ -24,8 +25,6 @@ hyper-reverse-proxy = { git = "https://github.com/tarrencev/hyper-reverse-proxy" hyper.workspace = true indexmap = "1.9.3" lazy_static.workspace = true -metrics-process.workspace = true -metrics.workspace = true scarb.workspace = true serde.workspace = true serde_json.workspace = true @@ -38,13 +37,13 @@ tokio.workspace = true torii-core.workspace = true torii-graphql.workspace = true torii-grpc = { workspace = true, features = [ "server" ] } +torii-relay.workspace = true torii-server.workspace = true tower = "0.4.13" tower-http = "0.4.4" tracing-subscriber.workspace = true tracing.workspace = true url.workspace = true -torii-relay.workspace = true webbrowser = "0.8" [dev-dependencies] @@ -52,5 +51,5 @@ camino.workspace = true [features] default = [ "jemalloc", "sqlite" ] -jemalloc = [ "metrics/jemalloc" ] +jemalloc = [ "dojo-metrics/jemalloc" ] sqlite = [ "sqlx/sqlite" ] diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index f5cf30b273..d726863483 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -16,8 +16,8 @@ use std::sync::Arc; use clap::Parser; use common::parse::{parse_socket_address, parse_url}; +use dojo_metrics::{metrics_process, prometheus_exporter}; use dojo_world::contracts::world::WorldContractReader; -use metrics::prometheus_exporter; use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions}; use sqlx::SqlitePool; use starknet::core::types::FieldElement; diff --git a/crates/metrics/Cargo.toml b/crates/metrics/Cargo.toml index d351b39341..92fda92b98 100644 --- a/crates/metrics/Cargo.toml +++ b/crates/metrics/Cargo.toml @@ -1,22 +1,23 @@ [package] edition.workspace = true -name = "metrics" +name = "dojo-metrics" version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] anyhow.workspace = true -hyper.workspace = true +hyper = { workspace = true, features = [ "http1", "http2", "server", "tcp" ] } thiserror.workspace = true tokio.workspace = true tracing.workspace = true # Metrics -metrics = "0.21.1" metrics-exporter-prometheus = "0.12.1" -metrics-process.workspace = true +metrics-process = "=1.0.14" metrics-util = "0.15.0" +metrics.workspace = true +reth-metrics-derive = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.2.0-beta.4" } [target.'cfg(not(windows))'.dependencies] jemalloc-ctl = { version = "0.5.0", optional = true } diff --git a/crates/metrics/src/lib.rs b/crates/metrics/src/lib.rs index 2b3519af15..4a3a43cea9 100644 --- a/crates/metrics/src/lib.rs +++ b/crates/metrics/src/lib.rs @@ -2,6 +2,12 @@ pub mod prometheus_exporter; #[cfg(all(feature = "jemalloc", unix))] use jemallocator as _; +/// Re-export the metrics crate +pub use metrics; +/// Re-export the metrics-process crate +pub use metrics_process; +/// Re-export the metrics derive macro +pub use reth_metrics_derive::Metrics; // We use jemalloc for performance reasons #[cfg(all(feature = "jemalloc", unix))] diff --git a/crates/metrics/src/prometheus_exporter.rs b/crates/metrics/src/prometheus_exporter.rs index 82206da51e..27242bdcda 100644 --- a/crates/metrics/src/prometheus_exporter.rs +++ b/crates/metrics/src/prometheus_exporter.rs @@ -1,9 +1,11 @@ //! Prometheus exporter //! Adapted from Paradigm's [`reth`](https://github.com/paradigmxyz/reth/blob/c1d7d2bde398bcf410c7e2df13fd7151fc2a58b9/bin/reth/src/prometheus_exporter.rs) + use std::convert::Infallible; use std::net::SocketAddr; use std::sync::Arc; +use anyhow::{Context, Result}; use hyper::service::{make_service_fn, service_fn}; use hyper::{Body, Request, Response, Server}; use metrics::{describe_gauge, gauge}; @@ -14,34 +16,55 @@ pub(crate) trait Hook: Fn() + Send + Sync {} impl Hook for T {} /// Installs Prometheus as the metrics recorder. -pub fn install_recorder(prefix: &str) -> anyhow::Result { +/// +/// ## Arguments +/// * `prefix` - Apply a prefix to all metrics keys. +pub fn install_recorder(prefix: &str) -> Result { let recorder = PrometheusBuilder::new().build_recorder(); let handle = recorder.handle(); - // Build metrics stack + // Build metrics stack and install the recorder Stack::new(recorder) .push(PrefixLayer::new(prefix)) .install() - .map_err(|e| anyhow::anyhow!("Couldn't set metrics recorder: {}", e))?; + .context("Couldn't set metrics recorder")?; Ok(handle) } +/// Serves Prometheus metrics over HTTP with database and process metrics. +pub async fn serve( + listen_addr: SocketAddr, + handle: PrometheusHandle, + process: metrics_process::Collector, +) -> Result<()> { + // Clone `process` to move it into the hook and use the original `process` for describe below. + let cloned_process = process.clone(); + let hooks: Vec>> = + vec![Box::new(move || cloned_process.collect()), Box::new(collect_memory_stats)]; + serve_with_hooks(listen_addr, handle, hooks).await?; + + process.describe(); + describe_memory_stats(); + + Ok(()) +} + /// Serves Prometheus metrics over HTTP with hooks. /// /// The hooks are called every time the metrics are requested at the given endpoint, and can be used /// to record values for pull-style metrics, i.e. metrics that are not automatically updated. -pub(crate) async fn serve_with_hooks( +async fn serve_with_hooks( listen_addr: SocketAddr, handle: PrometheusHandle, hooks: impl IntoIterator, -) -> anyhow::Result<()> { +) -> Result<()> { let hooks: Vec<_> = hooks.into_iter().collect(); // Start endpoint start_endpoint(listen_addr, handle, Arc::new(move || hooks.iter().for_each(|hook| hook()))) .await - .map_err(|e| anyhow::anyhow!("Could not start Prometheus endpoint: {}", e))?; + .context("Could not start Prometheus endpoint")?; Ok(()) } @@ -51,7 +74,7 @@ async fn start_endpoint( listen_addr: SocketAddr, handle: PrometheusHandle, hook: Arc, -) -> anyhow::Result<()> { +) -> Result<()> { let make_svc = make_service_fn(move |_| { let handle = handle.clone(); let hook = Arc::clone(&hook); @@ -64,7 +87,7 @@ async fn start_endpoint( } }); let server = Server::try_bind(&listen_addr) - .map_err(|e| anyhow::anyhow!("Could not bind to address: {}", e))? + .context(format!("Could not bind to address: {listen_addr}"))? .serve(make_svc); tokio::spawn(async move { server.await.expect("Metrics endpoint crashed") }); @@ -72,67 +95,49 @@ async fn start_endpoint( Ok(()) } -/// Serves Prometheus metrics over HTTP with database and process metrics. -pub async fn serve( - listen_addr: SocketAddr, - handle: PrometheusHandle, - process: metrics_process::Collector, -) -> anyhow::Result<()> { - // Clone `process` to move it into the hook and use the original `process` for describe below. - let cloned_process = process.clone(); - let hooks: Vec>> = - vec![Box::new(move || cloned_process.collect()), Box::new(collect_memory_stats)]; - serve_with_hooks(listen_addr, handle, hooks).await?; - - process.describe(); - describe_memory_stats(); - - Ok(()) -} - #[cfg(all(feature = "jemalloc", unix))] fn collect_memory_stats() { use jemalloc_ctl::{epoch, stats}; if epoch::advance() - .map_err(|error| tracing::error!(?error, "Failed to advance jemalloc epoch")) + .map_err(|error| tracing::error!(%error, "Failed to advance jemalloc epoch")) .is_err() { return; } if let Ok(value) = stats::active::read() - .map_err(|error| tracing::error!(?error, "Failed to read jemalloc.stats.active")) + .map_err(|error| tracing::error!(%error, "Failed to read jemalloc.stats.active")) { gauge!("jemalloc.active", value as f64); } if let Ok(value) = stats::allocated::read() - .map_err(|error| tracing::error!(?error, "Failed to read jemalloc.stats.allocated")) + .map_err(|error| tracing::error!(%error, "Failed to read jemalloc.stats.allocated")) { gauge!("jemalloc.allocated", value as f64); } if let Ok(value) = stats::mapped::read() - .map_err(|error| tracing::error!(?error, "Failed to read jemalloc.stats.mapped")) + .map_err(|error| tracing::error!(%error, "Failed to read jemalloc.stats.mapped")) { gauge!("jemalloc.mapped", value as f64); } if let Ok(value) = stats::metadata::read() - .map_err(|error| tracing::error!(?error, "Failed to read jemalloc.stats.metadata")) + .map_err(|error| tracing::error!(%error, "Failed to read jemalloc.stats.metadata")) { gauge!("jemalloc.metadata", value as f64); } if let Ok(value) = stats::resident::read() - .map_err(|error| tracing::error!(?error, "Failed to read jemalloc.stats.resident")) + .map_err(|error| tracing::error!(%error, "Failed to read jemalloc.stats.resident")) { gauge!("jemalloc.resident", value as f64); } if let Ok(value) = stats::retained::read() - .map_err(|error| tracing::error!(?error, "Failed to read jemalloc.stats.retained")) + .map_err(|error| tracing::error!(%error, "Failed to read jemalloc.stats.retained")) { gauge!("jemalloc.retained", value as f64); } diff --git a/crates/torii/server/Cargo.toml b/crates/torii/server/Cargo.toml index 314bfc6bfb..6e447748c4 100644 --- a/crates/torii/server/Cargo.toml +++ b/crates/torii/server/Cargo.toml @@ -13,6 +13,7 @@ camino.workspace = true chrono.workspace = true clap.workspace = true ctrlc = { version = "3.4", features = [ "termination" ] } +dojo-metrics.workspace = true dojo-types = { path = "../../dojo-types" } dojo-world = { path = "../../dojo-world" } either = "1.9.0" @@ -23,8 +24,6 @@ hyper-reverse-proxy = { git = "https://github.com/tarrencev/hyper-reverse-proxy" hyper.workspace = true indexmap = "1.9.3" lazy_static.workspace = true -metrics = { path = "../../metrics" } -metrics-process.workspace = true scarb.workspace = true serde.workspace = true serde_json.workspace = true @@ -48,5 +47,5 @@ camino.workspace = true [features] default = [ "jemalloc", "sqlite" ] -jemalloc = [ "metrics/jemalloc" ] +jemalloc = [ "dojo-metrics/jemalloc" ] sqlite = [ "sqlx/sqlite" ]