From 5e7038a8daba3a9234ec8ac128cdaf6ca5c96139 Mon Sep 17 00:00:00 2001 From: glihm Date: Thu, 31 Oct 2024 13:25:47 -0600 Subject: [PATCH 1/6] fix: ensure we init rpc client with timeout --- Cargo.lock | 15 ++++++++------- Cargo.toml | 2 +- bin/sozo/Cargo.toml | 1 + bin/sozo/src/commands/call.rs | 9 +++++++-- bin/sozo/src/commands/execute.rs | 11 ++++++----- bin/sozo/src/commands/inspect.rs | 3 ++- bin/sozo/src/commands/migrate.rs | 5 +++-- bin/sozo/src/commands/options/starknet.rs | 19 +++++++++++++++++-- bin/sozo/src/utils.rs | 7 +++++-- 9 files changed, 50 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc1f9676ec..026de6f756 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4819,7 +4819,7 @@ dependencies = [ "colored_json", "dojo-test-utils", "futures", - "reqwest 0.12.7", + "reqwest 0.11.27", "rpassword", "serde_json", "starknet 0.12.0", @@ -8174,7 +8174,7 @@ dependencies = [ "metrics", "num-traits 0.2.19", "parking_lot 0.12.3", - "reqwest 0.12.7", + "reqwest 0.11.27", "serde", "serde_json", "starknet 0.12.0", @@ -12392,7 +12392,7 @@ dependencies = [ "katana-provider", "katana-rpc-types", "prover-sdk", - "reqwest 0.12.7", + "reqwest 0.11.27", "saya-provider", "serde", "serde-felt", @@ -13363,6 +13363,7 @@ dependencies = [ "hex", "hex-literal", "itertools 0.12.1", + "jsonrpsee 0.16.3", "katana-rpc-api", "katana-runner", "notify", @@ -13370,7 +13371,7 @@ dependencies = [ "num-integer", "prettytable-rs", "regex", - "reqwest 0.12.7", + "reqwest 0.11.27", "rpassword", "scarb", "scarb-ui", @@ -13455,7 +13456,7 @@ dependencies = [ "anyhow", "console", "dojo-world", - "reqwest 0.12.7", + "reqwest 0.11.27", "scarb", "scarb-ui", "serde", @@ -15073,7 +15074,7 @@ dependencies = [ "katana-runner", "num-traits 0.2.19", "once_cell", - "reqwest 0.12.7", + "reqwest 0.11.27", "scarb", "serde", "serde_json", @@ -16937,7 +16938,7 @@ dependencies = [ "dojo-utils", "dojo-world", "katana-runner", - "reqwest 0.12.7", + "reqwest 0.11.27", "scarb", "sozo-ops", "sozo-scarbext", diff --git a/Cargo.toml b/Cargo.toml index b5a19cedad..55c4eaf734 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -183,7 +183,7 @@ pretty_assertions = "1.2.1" rand = "0.8.5" rayon = "1.8.0" regex = "1.10.3" -reqwest = { version = "0.12.7", features = [ "blocking", "json", "rustls-tls" ], default-features = false } +reqwest = { version = "0.11.27", features = [ "blocking", "json", "rustls-tls" ], default-features = false } rpassword = "7.2.0" rstest = "0.18.2" rstest_reuse = "0.6.0" diff --git a/bin/sozo/Cargo.toml b/bin/sozo/Cargo.toml index a947156a5c..7085948389 100644 --- a/bin/sozo/Cargo.toml +++ b/bin/sozo/Cargo.toml @@ -32,6 +32,7 @@ dojo-world.workspace = true hex = "0.4.3" hex-literal = "0.4.1" itertools.workspace = true +jsonrpsee = { version = "0.16.2", default-features = false } katana-rpc-api.workspace = true notify = "6.0.1" num-bigint = "0.4.3" diff --git a/bin/sozo/src/commands/call.rs b/bin/sozo/src/commands/call.rs index f6661ff740..135e495190 100644 --- a/bin/sozo/src/commands/call.rs +++ b/bin/sozo/src/commands/call.rs @@ -67,8 +67,13 @@ impl CallArgs { }; config.tokio_handle().block_on(async { - let (world_diff, provider, _) = - utils::get_world_diff_and_provider(self.starknet.clone(), self.world, &ws).await?; + let (world_diff, provider, _) = utils::get_world_diff_and_provider( + self.starknet.clone(), + self.world, + Default::default(), + &ws, + ) + .await?; let calldata = if let Some(cd) = self.calldata { calldata_decoder::decode_calldata(&cd)? diff --git a/bin/sozo/src/commands/execute.rs b/bin/sozo/src/commands/execute.rs index d04d026386..5c9acf6f90 100644 --- a/bin/sozo/src/commands/execute.rs +++ b/bin/sozo/src/commands/execute.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use anyhow::{anyhow, Result}; use clap::Args; use dojo_types::naming; -use dojo_utils::Invoker; +use dojo_utils::{Invoker, TxnConfig}; use dojo_world::contracts::naming::ensure_namespace; use scarb::core::Config; use sozo_scarbext::WorkspaceExt; @@ -78,11 +78,14 @@ impl ExecuteArgs { self.starknet.url(profile_config.env.as_ref())?, ); + let txn_config: TxnConfig = self.transaction.into(); + config.tokio_handle().block_on(async { let (world_diff, account, _) = utils::get_world_diff_and_account( self.account, - self.starknet.clone(), + self.starknet, self.world, + txn_config, &ws, ) .await?; @@ -96,8 +99,6 @@ impl ExecuteArgs { } .ok_or_else(|| anyhow!("Contract {descriptor} not found in the world diff."))?; - let tx_config = self.transaction.into(); - trace!( contract=?descriptor, entrypoint=self.entrypoint, @@ -117,7 +118,7 @@ impl ExecuteArgs { selector: snutils::get_selector_from_name(&self.entrypoint)?, }; - let invoker = Invoker::new(&account, tx_config); + let invoker = Invoker::new(&account, txn_config); // TODO: add walnut back, perhaps at the invoker level. let tx_result = invoker.invoke(call).await?; diff --git a/bin/sozo/src/commands/inspect.rs b/bin/sozo/src/commands/inspect.rs index 3d90bf1815..e4ec73d14c 100644 --- a/bin/sozo/src/commands/inspect.rs +++ b/bin/sozo/src/commands/inspect.rs @@ -2,6 +2,7 @@ use anyhow::Result; use clap::Args; use colored::*; use dojo_types::naming; +use dojo_utils::TxnConfig; use dojo_world::diff::{ResourceDiff, WorldDiff, WorldStatus}; use dojo_world::ResourceType; use scarb::core::Config; @@ -37,7 +38,7 @@ impl InspectArgs { config.tokio_handle().block_on(async { let (world_diff, _, _) = - utils::get_world_diff_and_provider(starknet.clone(), world, &ws).await?; + utils::get_world_diff_and_provider(starknet.clone(), world, None, &ws).await?; if let Some(resource) = resource { inspect_resource(&resource, &world_diff); diff --git a/bin/sozo/src/commands/migrate.rs b/bin/sozo/src/commands/migrate.rs index 257aaf977e..a78e919039 100644 --- a/bin/sozo/src/commands/migrate.rs +++ b/bin/sozo/src/commands/migrate.rs @@ -58,7 +58,8 @@ impl MigrateArgs { txn_config.wait = true; let (world_diff, account, rpc_url) = - utils::get_world_diff_and_account(account, starknet, world, &ws).await?; + utils::get_world_diff_and_account(account, starknet, world, txn_config, &ws) + .await?; let world_address = world_diff.world_info.address; @@ -100,7 +101,7 @@ pub struct Banner { /// Prints the migration banner. async fn print_banner(ws: &Workspace<'_>, starknet: &StarknetOptions) -> Result<()> { - let (provider, rpc_url) = starknet.provider(None)?; + let (provider, rpc_url) = starknet.provider(None, None)?; let chain_id = provider.chain_id().await?; let chain_id = parse_cairo_short_string(&chain_id) diff --git a/bin/sozo/src/commands/options/starknet.rs b/bin/sozo/src/commands/options/starknet.rs index 2c60165393..0d50bd6a87 100644 --- a/bin/sozo/src/commands/options/starknet.rs +++ b/bin/sozo/src/commands/options/starknet.rs @@ -1,7 +1,10 @@ +use std::time::Duration; + use anyhow::Result; use clap::Args; use dojo_utils::env::STARKNET_RPC_URL_ENV_VAR; use dojo_world::config::Environment; +use reqwest::ClientBuilder; use starknet::providers::jsonrpc::HttpTransport; use starknet::providers::JsonRpcClient; use tracing::trace; @@ -24,10 +27,22 @@ impl StarknetOptions { pub fn provider( &self, env_metadata: Option<&Environment>, + request_timeout_ms: Option, ) -> Result<(JsonRpcClient, String)> { let url = self.url(env_metadata)?; - trace!(?url, "Creating JsonRpcClient with given RPC URL."); - Ok((JsonRpcClient::new(HttpTransport::new(url.clone())), url.to_string())) + trace!(?url, "Creating JsonRpcClient with given RPC URL and timeout."); + + let client = if let Some(request_timeout_ms) = request_timeout_ms { + ClientBuilder::default() + .timeout(Duration::from_millis(request_timeout_ms)) + .build() + .unwrap() + } else { + ClientBuilder::default().build().unwrap() + }; + + let transport = HttpTransport::new_with_client(url.clone(), client); + Ok((JsonRpcClient::new(transport), url.to_string())) } // We dont check the env var because that would be handled by `clap`. diff --git a/bin/sozo/src/utils.rs b/bin/sozo/src/utils.rs index 254cc80dba..35d562be75 100644 --- a/bin/sozo/src/utils.rs +++ b/bin/sozo/src/utils.rs @@ -3,6 +3,7 @@ use std::str::FromStr; use anyhow::{anyhow, Context, Result}; use camino::Utf8PathBuf; use colored::*; +use dojo_utils::TxnConfig; use dojo_world::config::ProfileConfig; use dojo_world::diff::WorldDiff; use dojo_world::local::WorldLocal; @@ -102,6 +103,7 @@ pub fn is_address(tag_or_address: &str) -> bool { pub async fn get_world_diff_and_provider( starknet: StarknetOptions, world: WorldOptions, + provider_request_timeout_ms: Option, ws: &Workspace<'_>, ) -> Result<(WorldDiff, JsonRpcClient, String)> { let world_local = ws.load_world_local()?; @@ -111,7 +113,7 @@ pub async fn get_world_diff_and_provider( let world_address = get_world_address(&profile_config, &world, &world_local)?; - let (provider, rpc_url) = starknet.provider(env)?; + let (provider, rpc_url) = starknet.provider(env, provider_request_timeout_ms)?; trace!(?provider, "Provider initialized."); let spec_version = provider.spec_version().await?; @@ -143,13 +145,14 @@ pub async fn get_world_diff_and_account( account: AccountOptions, starknet: StarknetOptions, world: WorldOptions, + txn_config: TxnConfig, ws: &Workspace<'_>, ) -> Result<(WorldDiff, SozoAccount>, String)> { let profile_config = ws.load_profile_config()?; let env = profile_config.env.as_ref(); let (world_diff, provider, rpc_url) = - get_world_diff_and_provider(starknet.clone(), world, ws).await?; + get_world_diff_and_provider(starknet.clone(), world, txn_config.timeout_ms, ws).await?; let account = { account From 9d28be8738da0b253cf7123f5a8e59956f84b18a Mon Sep 17 00:00:00 2001 From: glihm Date: Thu, 31 Oct 2024 15:07:42 -0600 Subject: [PATCH 2/6] fix: update prover sdk to compatible version --- Cargo.lock | 11 +++++------ bin/sozo/src/commands/inspect.rs | 1 - crates/saya/core/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 026de6f756..e3be5ad236 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3689,7 +3689,7 @@ dependencies = [ [[package]] name = "common" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/http-prover?rev=24256d5#24256d530e60de5458956a858106cc6be1cbee17" +source = "git+https://github.com/cartridge-gg/http-prover?rev=f239ade#f239ade2f7ed363fbf99c9726b998fe6b0ab887b" dependencies = [ "ed25519-dalek", "serde", @@ -11113,7 +11113,7 @@ dependencies = [ [[package]] name = "prover-sdk" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/http-prover?rev=24256d5#24256d530e60de5458956a858106cc6be1cbee17" +source = "git+https://github.com/cartridge-gg/http-prover?rev=f239ade#f239ade2f7ed363fbf99c9726b998fe6b0ab887b" dependencies = [ "base64 0.22.1", "common", @@ -11121,7 +11121,7 @@ dependencies = [ "futures", "prefix-hex", "rand 0.8.5", - "reqwest 0.12.7", + "reqwest 0.11.27", "reqwest_cookie_store", "serde", "serde_json", @@ -11548,6 +11548,8 @@ dependencies = [ "async-compression", "base64 0.21.7", "bytes", + "cookie 0.17.0", + "cookie_store 0.20.0", "encoding_rs", "futures-core", "futures-util", @@ -11598,7 +11600,6 @@ dependencies = [ "bytes", "cookie 0.18.1", "cookie_store 0.21.0", - "futures-channel", "futures-core", "futures-util", "http 1.1.0", @@ -11628,12 +11629,10 @@ dependencies = [ "tokio", "tokio-native-tls", "tokio-rustls 0.26.0", - "tokio-util", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", - "wasm-streams", "web-sys", "webpki-roots 0.26.6", "windows-registry", diff --git a/bin/sozo/src/commands/inspect.rs b/bin/sozo/src/commands/inspect.rs index e4ec73d14c..102eaa3e60 100644 --- a/bin/sozo/src/commands/inspect.rs +++ b/bin/sozo/src/commands/inspect.rs @@ -2,7 +2,6 @@ use anyhow::Result; use clap::Args; use colored::*; use dojo_types::naming; -use dojo_utils::TxnConfig; use dojo_world::diff::{ResourceDiff, WorldDiff, WorldStatus}; use dojo_world::ResourceType; use scarb::core::Config; diff --git a/crates/saya/core/Cargo.toml b/crates/saya/core/Cargo.toml index 09c71a1eb2..8c2ba0391c 100644 --- a/crates/saya/core/Cargo.toml +++ b/crates/saya/core/Cargo.toml @@ -33,7 +33,7 @@ celestia-types = "0.5.0" cairo-proof-parser = { git = "https://github.com/cartridge-gg/cairo-proof-parser.git", rev = "f175d58" } cairo1-playground = { git = "https://github.com/chudkowsky/cairo1-playground.git", rev = "3fda965" } herodotus_sharp_playground = { git = "https://github.com/chudkowsky/herodotus_sharp_playground.git", rev = "db64bfd" } -prover-sdk = { git = "https://github.com/cartridge-gg/http-prover", rev = "24256d5" } +prover-sdk = { git = "https://github.com/cartridge-gg/http-prover", rev = "f239ade" } reqwest.workspace = true serde-felt = { git = "https://github.com/cartridge-gg/cairo-proof-parser.git", rev = "f175d58" } tempdir = "0.3.7" From ab9be6873784e4be1c08264196c3075204fe32e2 Mon Sep 17 00:00:00 2001 From: glihm Date: Thu, 31 Oct 2024 15:10:50 -0600 Subject: [PATCH 3/6] Update bin/sozo/src/commands/options/starknet.rs Co-authored-by: Ammar Arif --- bin/sozo/src/commands/options/starknet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/sozo/src/commands/options/starknet.rs b/bin/sozo/src/commands/options/starknet.rs index 0d50bd6a87..3cbb2f8d18 100644 --- a/bin/sozo/src/commands/options/starknet.rs +++ b/bin/sozo/src/commands/options/starknet.rs @@ -30,7 +30,7 @@ impl StarknetOptions { request_timeout_ms: Option, ) -> Result<(JsonRpcClient, String)> { let url = self.url(env_metadata)?; - trace!(?url, "Creating JsonRpcClient with given RPC URL and timeout."); + trace!(?url, timeout = ?request_timeout_ms, "Creating JsonRpcClient."); let client = if let Some(request_timeout_ms) = request_timeout_ms { ClientBuilder::default() From b10fd7907a8ae77306013daeb2657a65fc1fcc69 Mon Sep 17 00:00:00 2001 From: glihm Date: Fri, 1 Nov 2024 11:33:30 -0600 Subject: [PATCH 4/6] chore: remove unused dep --- Cargo.lock | 1 - bin/sozo/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3be5ad236..5ef3781efb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13362,7 +13362,6 @@ dependencies = [ "hex", "hex-literal", "itertools 0.12.1", - "jsonrpsee 0.16.3", "katana-rpc-api", "katana-runner", "notify", diff --git a/bin/sozo/Cargo.toml b/bin/sozo/Cargo.toml index 7085948389..a947156a5c 100644 --- a/bin/sozo/Cargo.toml +++ b/bin/sozo/Cargo.toml @@ -32,7 +32,6 @@ dojo-world.workspace = true hex = "0.4.3" hex-literal = "0.4.1" itertools.workspace = true -jsonrpsee = { version = "0.16.2", default-features = false } katana-rpc-api.workspace = true notify = "6.0.1" num-bigint = "0.4.3" From 4faa65022b2914efabfa7c8f5cf01c0bf116ffb3 Mon Sep 17 00:00:00 2001 From: glihm Date: Fri, 1 Nov 2024 14:07:26 -0600 Subject: [PATCH 5/6] fix: internalise request timeout and lower l2 inclusion timeout --- bin/sozo/src/commands/call.rs | 9 ++------- bin/sozo/src/commands/execute.rs | 11 +++-------- bin/sozo/src/commands/inspect.rs | 2 +- bin/sozo/src/commands/migrate.rs | 11 +++++------ bin/sozo/src/commands/options/starknet.rs | 16 ++++++---------- bin/sozo/src/commands/options/transaction.rs | 8 -------- bin/sozo/src/utils.rs | 7 ++----- crates/dojo/utils/src/tx/declarer.rs | 10 +--------- crates/dojo/utils/src/tx/deployer.rs | 11 ++--------- crates/dojo/utils/src/tx/invoker.rs | 20 ++++---------------- crates/dojo/utils/src/tx/mod.rs | 8 ++++---- crates/dojo/utils/src/tx/waiter.rs | 3 ++- crates/sozo/ops/src/account.rs | 19 +++---------------- 13 files changed, 35 insertions(+), 100 deletions(-) diff --git a/bin/sozo/src/commands/call.rs b/bin/sozo/src/commands/call.rs index 135e495190..f6661ff740 100644 --- a/bin/sozo/src/commands/call.rs +++ b/bin/sozo/src/commands/call.rs @@ -67,13 +67,8 @@ impl CallArgs { }; config.tokio_handle().block_on(async { - let (world_diff, provider, _) = utils::get_world_diff_and_provider( - self.starknet.clone(), - self.world, - Default::default(), - &ws, - ) - .await?; + let (world_diff, provider, _) = + utils::get_world_diff_and_provider(self.starknet.clone(), self.world, &ws).await?; let calldata = if let Some(cd) = self.calldata { calldata_decoder::decode_calldata(&cd)? diff --git a/bin/sozo/src/commands/execute.rs b/bin/sozo/src/commands/execute.rs index 5c9acf6f90..904486d72b 100644 --- a/bin/sozo/src/commands/execute.rs +++ b/bin/sozo/src/commands/execute.rs @@ -81,14 +81,9 @@ impl ExecuteArgs { let txn_config: TxnConfig = self.transaction.into(); config.tokio_handle().block_on(async { - let (world_diff, account, _) = utils::get_world_diff_and_account( - self.account, - self.starknet, - self.world, - txn_config, - &ws, - ) - .await?; + let (world_diff, account, _) = + utils::get_world_diff_and_account(self.account, self.starknet, self.world, &ws) + .await?; let contract_address = match &descriptor { ContractDescriptor::Address(address) => Some(*address), diff --git a/bin/sozo/src/commands/inspect.rs b/bin/sozo/src/commands/inspect.rs index 102eaa3e60..3d90bf1815 100644 --- a/bin/sozo/src/commands/inspect.rs +++ b/bin/sozo/src/commands/inspect.rs @@ -37,7 +37,7 @@ impl InspectArgs { config.tokio_handle().block_on(async { let (world_diff, _, _) = - utils::get_world_diff_and_provider(starknet.clone(), world, None, &ws).await?; + utils::get_world_diff_and_provider(starknet.clone(), world, &ws).await?; if let Some(resource) = resource { inspect_resource(&resource, &world_diff); diff --git a/bin/sozo/src/commands/migrate.rs b/bin/sozo/src/commands/migrate.rs index a78e919039..4a1e9ffe2c 100644 --- a/bin/sozo/src/commands/migrate.rs +++ b/bin/sozo/src/commands/migrate.rs @@ -54,15 +54,14 @@ impl MigrateArgs { let mut spinner = MigrationUi::Spinner(Spinner::new(frames, "Evaluating world diff...", None)); - let mut txn_config: TxnConfig = self.transaction.into(); - txn_config.wait = true; - let (world_diff, account, rpc_url) = - utils::get_world_diff_and_account(account, starknet, world, txn_config, &ws) - .await?; + utils::get_world_diff_and_account(account, starknet, world, &ws).await?; let world_address = world_diff.world_info.address; + let mut txn_config: TxnConfig = self.transaction.into(); + txn_config.wait = true; + let migration = Migration::new( world_diff, WorldContract::new(world_address, &account), @@ -101,7 +100,7 @@ pub struct Banner { /// Prints the migration banner. async fn print_banner(ws: &Workspace<'_>, starknet: &StarknetOptions) -> Result<()> { - let (provider, rpc_url) = starknet.provider(None, None)?; + let (provider, rpc_url) = starknet.provider(None)?; let chain_id = provider.chain_id().await?; let chain_id = parse_cairo_short_string(&chain_id) diff --git a/bin/sozo/src/commands/options/starknet.rs b/bin/sozo/src/commands/options/starknet.rs index 3cbb2f8d18..9759fce549 100644 --- a/bin/sozo/src/commands/options/starknet.rs +++ b/bin/sozo/src/commands/options/starknet.rs @@ -21,25 +21,21 @@ pub struct StarknetOptions { } impl StarknetOptions { + const DEFAULT_REQUEST_TIMEOUT_MS: u64 = 20_000; + /// Returns a [`JsonRpcClient`] and the rpc url. /// /// It would be convenient to have the rpc url retrievable from the Provider trait instead. pub fn provider( &self, env_metadata: Option<&Environment>, - request_timeout_ms: Option, ) -> Result<(JsonRpcClient, String)> { let url = self.url(env_metadata)?; - trace!(?url, timeout = ?request_timeout_ms, "Creating JsonRpcClient."); - let client = if let Some(request_timeout_ms) = request_timeout_ms { - ClientBuilder::default() - .timeout(Duration::from_millis(request_timeout_ms)) - .build() - .unwrap() - } else { - ClientBuilder::default().build().unwrap() - }; + let client = ClientBuilder::default() + .timeout(Duration::from_millis(Self::DEFAULT_REQUEST_TIMEOUT_MS)) + .build() + .unwrap(); let transport = HttpTransport::new_with_client(url.clone(), client); Ok((JsonRpcClient::new(transport), url.to_string())) diff --git a/bin/sozo/src/commands/options/transaction.rs b/bin/sozo/src/commands/options/transaction.rs index 9b04a857b5..46920c4066 100644 --- a/bin/sozo/src/commands/options/transaction.rs +++ b/bin/sozo/src/commands/options/transaction.rs @@ -41,12 +41,6 @@ pub struct TransactionOptions { #[arg(help = "Display the link to debug the transaction with Walnut.")] #[arg(global = true)] pub walnut: bool, - - #[arg(long)] - #[arg(help = "The timeout in milliseconds for the transaction wait.")] - #[arg(value_name = "TIMEOUT-MS")] - #[arg(global = true)] - pub timeout: Option, } impl TransactionOptions { @@ -67,7 +61,6 @@ impl TransactionOptions { max_fee_raw: self.max_fee_raw, fee_estimate_multiplier: self.fee_estimate_multiplier, walnut: self.walnut, - timeout_ms: self.timeout, }), } } @@ -81,7 +74,6 @@ impl From for TxnConfig { receipt: value.receipt, max_fee_raw: value.max_fee_raw, walnut: value.walnut, - timeout_ms: value.timeout, } } } diff --git a/bin/sozo/src/utils.rs b/bin/sozo/src/utils.rs index 35d562be75..254cc80dba 100644 --- a/bin/sozo/src/utils.rs +++ b/bin/sozo/src/utils.rs @@ -3,7 +3,6 @@ use std::str::FromStr; use anyhow::{anyhow, Context, Result}; use camino::Utf8PathBuf; use colored::*; -use dojo_utils::TxnConfig; use dojo_world::config::ProfileConfig; use dojo_world::diff::WorldDiff; use dojo_world::local::WorldLocal; @@ -103,7 +102,6 @@ pub fn is_address(tag_or_address: &str) -> bool { pub async fn get_world_diff_and_provider( starknet: StarknetOptions, world: WorldOptions, - provider_request_timeout_ms: Option, ws: &Workspace<'_>, ) -> Result<(WorldDiff, JsonRpcClient, String)> { let world_local = ws.load_world_local()?; @@ -113,7 +111,7 @@ pub async fn get_world_diff_and_provider( let world_address = get_world_address(&profile_config, &world, &world_local)?; - let (provider, rpc_url) = starknet.provider(env, provider_request_timeout_ms)?; + let (provider, rpc_url) = starknet.provider(env)?; trace!(?provider, "Provider initialized."); let spec_version = provider.spec_version().await?; @@ -145,14 +143,13 @@ pub async fn get_world_diff_and_account( account: AccountOptions, starknet: StarknetOptions, world: WorldOptions, - txn_config: TxnConfig, ws: &Workspace<'_>, ) -> Result<(WorldDiff, SozoAccount>, String)> { let profile_config = ws.load_profile_config()?; let env = profile_config.env.as_ref(); let (world_diff, provider, rpc_url) = - get_world_diff_and_provider(starknet.clone(), world, txn_config.timeout_ms, ws).await?; + get_world_diff_and_provider(starknet.clone(), world, ws).await?; let account = { account diff --git a/crates/dojo/utils/src/tx/declarer.rs b/crates/dojo/utils/src/tx/declarer.rs index fed211ff88..c82e94604b 100644 --- a/crates/dojo/utils/src/tx/declarer.rs +++ b/crates/dojo/utils/src/tx/declarer.rs @@ -8,7 +8,6 @@ use std::collections::HashMap; use std::sync::Arc; -use std::time::Duration; use starknet::accounts::ConnectedAccount; use starknet::core::types::{ @@ -103,15 +102,8 @@ where "Declared class." ); - // Since TxnConfig::wait doesn't work for now, we wait for the transaction manually. if txn_config.wait { - let receipt = if let Some(timeout_ms) = txn_config.timeout_ms { - TransactionWaiter::new(transaction_hash, &account.provider()) - .with_timeout(Duration::from_millis(timeout_ms)) - .await? - } else { - TransactionWaiter::new(transaction_hash, &account.provider()).await? - }; + let receipt = TransactionWaiter::new(transaction_hash, &account.provider()).await?; if txn_config.receipt { return Ok(TransactionResult::HashReceipt(transaction_hash, Box::new(receipt))); diff --git a/crates/dojo/utils/src/tx/deployer.rs b/crates/dojo/utils/src/tx/deployer.rs index b3fda1551f..947733f642 100644 --- a/crates/dojo/utils/src/tx/deployer.rs +++ b/crates/dojo/utils/src/tx/deployer.rs @@ -1,7 +1,5 @@ //! The deployer is in charge of deploying contracts to starknet. -use std::time::Duration; - use starknet::accounts::ConnectedAccount; use starknet::core::types::{ BlockId, BlockTag, Call, Felt, InvokeTransactionResult, StarknetError, @@ -74,13 +72,8 @@ where ); if self.txn_config.wait { - let receipt = if let Some(timeout_ms) = self.txn_config.timeout_ms { - TransactionWaiter::new(transaction_hash, &self.account.provider()) - .with_timeout(Duration::from_millis(timeout_ms)) - .await? - } else { - TransactionWaiter::new(transaction_hash, &self.account.provider()).await? - }; + let receipt = + TransactionWaiter::new(transaction_hash, &self.account.provider()).await?; if self.txn_config.receipt { return Ok(TransactionResult::HashReceipt(transaction_hash, Box::new(receipt))); diff --git a/crates/dojo/utils/src/tx/invoker.rs b/crates/dojo/utils/src/tx/invoker.rs index 51f5506f7e..796b051b68 100644 --- a/crates/dojo/utils/src/tx/invoker.rs +++ b/crates/dojo/utils/src/tx/invoker.rs @@ -1,7 +1,5 @@ //! Invoker to invoke contracts. -use std::time::Duration; - use starknet::accounts::ConnectedAccount; use starknet::core::types::Call; use tracing::trace; @@ -61,13 +59,8 @@ where trace!(transaction_hash = format!("{:#066x}", tx.transaction_hash), "Invoke contract."); if self.txn_config.wait { - let receipt = if let Some(timeout_ms) = self.txn_config.timeout_ms { - TransactionWaiter::new(tx.transaction_hash, &self.account.provider()) - .with_timeout(Duration::from_millis(timeout_ms)) - .await? - } else { - TransactionWaiter::new(tx.transaction_hash, &self.account.provider()).await? - }; + let receipt = + TransactionWaiter::new(tx.transaction_hash, &self.account.provider()).await?; if self.txn_config.receipt { return Ok(TransactionResult::HashReceipt(tx.transaction_hash, Box::new(receipt))); @@ -94,13 +87,8 @@ where ); if self.txn_config.wait { - let receipt = if let Some(timeout_ms) = self.txn_config.timeout_ms { - TransactionWaiter::new(tx.transaction_hash, &self.account.provider()) - .with_timeout(Duration::from_millis(timeout_ms)) - .await? - } else { - TransactionWaiter::new(tx.transaction_hash, &self.account.provider()).await? - }; + let receipt = + TransactionWaiter::new(tx.transaction_hash, &self.account.provider()).await?; if self.txn_config.receipt { return Ok(TransactionResult::HashReceipt(tx.transaction_hash, Box::new(receipt))); diff --git a/crates/dojo/utils/src/tx/mod.rs b/crates/dojo/utils/src/tx/mod.rs index 5ddb76b705..df6455048e 100644 --- a/crates/dojo/utils/src/tx/mod.rs +++ b/crates/dojo/utils/src/tx/mod.rs @@ -27,11 +27,14 @@ pub struct TxnConfig { /// The multiplier for how much the actual transaction max fee should be relative to the /// estimated fee. If `None` is provided, the multiplier is set to `1.1`. pub fee_estimate_multiplier: Option, + /// Whether to wait for the transaction to be accepted or reverted on L2. pub wait: bool, + /// Whether to display the transaction receipt. pub receipt: bool, + /// The maximum fee to pay for the transaction. pub max_fee_raw: Option, + /// Whether to use the `walnut` fee estimation strategy. pub walnut: bool, - pub timeout_ms: Option, } #[derive(Debug, Copy, Clone)] @@ -40,11 +43,8 @@ pub enum TxnAction { wait: bool, receipt: bool, max_fee_raw: Option, - /// The multiplier for how much the actual transaction max fee should be relative to the - /// estimated fee. If `None` is provided, the multiplier is set to `1.1`. fee_estimate_multiplier: Option, walnut: bool, - timeout_ms: Option, }, Estimate, Simulate, diff --git a/crates/dojo/utils/src/tx/waiter.rs b/crates/dojo/utils/src/tx/waiter.rs index e02dc55864..d6c9fc28e6 100644 --- a/crates/dojo/utils/src/tx/waiter.rs +++ b/crates/dojo/utils/src/tx/waiter.rs @@ -89,7 +89,8 @@ impl<'a, P> TransactionWaiter<'a, P> where P: Provider + Send, { - const DEFAULT_TIMEOUT: Duration = Duration::from_secs(300); + /// The default timeout for a transaction to be accepted or reverted on L2. + const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30); /// Interval for use with 3rd party provider without burning the API rate limit. const DEFAULT_INTERVAL: Duration = Duration::from_millis(2500); diff --git a/crates/sozo/ops/src/account.rs b/crates/sozo/ops/src/account.rs index 554d8159bb..f8febe249a 100644 --- a/crates/sozo/ops/src/account.rs +++ b/crates/sozo/ops/src/account.rs @@ -256,14 +256,7 @@ pub async fn deploy( }; match txn_action { - TxnAction::Send { - wait, - receipt, - max_fee_raw, - fee_estimate_multiplier, - walnut, - timeout_ms, - } => { + TxnAction::Send { wait, receipt, max_fee_raw, fee_estimate_multiplier, walnut } => { let max_fee = if let Some(max_fee_raw) = max_fee_raw { MaxFeeType::Manual { max_fee: max_fee_raw } } else { @@ -292,14 +285,8 @@ pub async fn deploy( }; let account_deployment = account_deployment.max_fee(max_fee.max_fee()); - let txn_config = TxnConfig { - fee_estimate_multiplier, - wait, - receipt, - max_fee_raw, - walnut, - timeout_ms, - }; + let txn_config = + TxnConfig { fee_estimate_multiplier, wait, receipt, max_fee_raw, walnut }; do_account_deploy( max_fee, txn_config, From 84251fec0e2fde3592567a9d3a2bc48830a407af Mon Sep 17 00:00:00 2001 From: glihm Date: Fri, 1 Nov 2024 14:22:10 -0600 Subject: [PATCH 6/6] fix: add comments and cleanup --- bin/sozo/src/commands/options/starknet.rs | 11 ++++++----- crates/dojo/utils/src/tx/waiter.rs | 3 +++ crates/dojo/world/src/config/namespace_config.rs | 2 +- crates/dojo/world/src/config/profile_config.rs | 6 +++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bin/sozo/src/commands/options/starknet.rs b/bin/sozo/src/commands/options/starknet.rs index 9759fce549..79a70e2371 100644 --- a/bin/sozo/src/commands/options/starknet.rs +++ b/bin/sozo/src/commands/options/starknet.rs @@ -21,7 +21,10 @@ pub struct StarknetOptions { } impl StarknetOptions { - const DEFAULT_REQUEST_TIMEOUT_MS: u64 = 20_000; + /// The default request timeout in milliseconds. This is not the transaction inclusion timeout. + /// Refer to [`dojo_utils::tx::waiter::TransactionWaiter::DEFAULT_TIMEOUT`] for the transaction inclusion + /// timeout. + const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(30); /// Returns a [`JsonRpcClient`] and the rpc url. /// @@ -32,10 +35,8 @@ impl StarknetOptions { ) -> Result<(JsonRpcClient, String)> { let url = self.url(env_metadata)?; - let client = ClientBuilder::default() - .timeout(Duration::from_millis(Self::DEFAULT_REQUEST_TIMEOUT_MS)) - .build() - .unwrap(); + let client = + ClientBuilder::default().timeout(Self::DEFAULT_REQUEST_TIMEOUT).build().unwrap(); let transport = HttpTransport::new_with_client(url.clone(), client); Ok((JsonRpcClient::new(transport), url.to_string())) diff --git a/crates/dojo/utils/src/tx/waiter.rs b/crates/dojo/utils/src/tx/waiter.rs index d6c9fc28e6..c98f168e38 100644 --- a/crates/dojo/utils/src/tx/waiter.rs +++ b/crates/dojo/utils/src/tx/waiter.rs @@ -90,6 +90,9 @@ where P: Provider + Send, { /// The default timeout for a transaction to be accepted or reverted on L2. + /// The inclusion (which can be accepted or reverted) is ~5seconds in ideal cases. + /// We keep some margin for times that could be affected by network congestion or + /// block STM worst cases. const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30); /// Interval for use with 3rd party provider without burning the API rate limit. const DEFAULT_INTERVAL: Duration = Duration::from_millis(2500); diff --git a/crates/dojo/world/src/config/namespace_config.rs b/crates/dojo/world/src/config/namespace_config.rs index 63fe394f0b..a13cf3fe6d 100644 --- a/crates/dojo/world/src/config/namespace_config.rs +++ b/crates/dojo/world/src/config/namespace_config.rs @@ -21,7 +21,7 @@ use serde::{Deserialize, Serialize}; pub struct NamespaceConfig { /// The default namespace to use if none is specified. pub default: String, - /// A mapping + /// A mapping > pub mappings: Option>>, } diff --git a/crates/dojo/world/src/config/profile_config.rs b/crates/dojo/world/src/config/profile_config.rs index 0489125c3d..4297a16d57 100644 --- a/crates/dojo/world/src/config/profile_config.rs +++ b/crates/dojo/world/src/config/profile_config.rs @@ -20,11 +20,11 @@ pub struct ProfileConfig { pub namespace: NamespaceConfig, pub env: Option, pub migration: Option, - /// A mapping of writers to be set on the world. + /// A mapping > of writers to be set on the world. pub writers: Option>>, - /// A mapping of owners to be set on the world. + /// A mapping > of owners to be set on the world. pub owners: Option>>, - /// A mapping of init call arguments to be passed to the contract. + /// A mapping > of init call arguments to be passed to the contract. pub init_call_args: Option>>, }