Skip to content

Commit

Permalink
Add walnut flag to sozo execute and migrate apply commands (#2333)
Browse files Browse the repository at this point in the history
* feat: add sierra to cairo debug information

* Add walnut flag to sozo execute command

* Pass rpc url to handle_transaction_result

* Add walnut flag to sozo migrate apply command

* Move walnut_debug_transaction to walnut crate

* Cargo fmt

* Keep only one global walnut flag

* Add comments

* Add walnut flag to sozo execute command

* Pass rpc url to handle_transaction_result

* Add walnut flag to sozo migrate apply command

* Move walnut_debug_transaction to walnut crate

* Cargo fmt

* Keep only one global walnut flag

* Add comments

* Resolve conflicts

* Fix lint errors

* Put the walnut crate under the /sozo dir

* Add constants with API and app URLs

* Warn where we fail silently

* Remove unnecessary comments

* Check Walnut API key before migration

* Add doc comments

* Disable walnut flag in auto_authorize

* chore; use debug for pending tx log (#2383)

Update engine.rs

* refactor(katana-rpc): `getEvents` include pending block  (#2375)

* refactor(katana): move predeployedAccounts under DevApi and remove KatanaApi (#2310)

fix: move predeployedAccounts under DevApi and remove KatanaApi

* remove world and indexers table in favour of contracts

commit-id:98359f5f

* opt(torii): batch query execution in sync_range

commit-id:72f22f88

* refactor(torii): make select block cancel safe

commit-id:8fbc8e6d

* opt(torii): use hashmap instead of vector of event processors

commit-id:7303cc72

* opt(torii): fetch receipts along with blocks instead of fetching them individually

commit-id:b6db4cb5

* opt(torii): avoid re-processing of transactions in certain case

fix: #2355

commit-id:a510b985

* wip

* chore(dojo-world): enable manifest feature on `migration` feature

* fmt

* refactor: move walnut config into WalnutDebugger

* fix: ensure only WalnutDebugger is exposed

* fix: restore default dojo_dev.toml

* dont print in library code

* use concrete error types in walnut/verification

* use concrete types again

* remove unecessary util function

* use json method instead

* fix: fix test

---------

Co-authored-by: glihm <[email protected]>
Co-authored-by: Larko <[email protected]>
Co-authored-by: Ammar Arif <[email protected]>
Co-authored-by: lambda-0x <[email protected]>
  • Loading branch information
5 people authored Sep 8, 2024
1 parent 4d34bc5 commit 76458a3
Show file tree
Hide file tree
Showing 31 changed files with 581 additions and 40 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ members = [
"crates/saya/core",
"crates/saya/provider",
"crates/sozo/signers",
"crates/sozo/walnut",
"crates/torii/client",
"crates/torii/server",
"crates/torii/types-test",
Expand Down Expand Up @@ -111,6 +112,7 @@ saya-provider = { path = "crates/saya/provider" }
# sozo
sozo-ops = { path = "crates/sozo/ops" }
sozo-signers = { path = "crates/sozo/signers" }
sozo-walnut = { path = "crates/sozo/walnut" }

anyhow = "1.0.80"
assert_fs = "1.1"
Expand Down Expand Up @@ -207,6 +209,7 @@ tower-http = "0.4.4"
tracing = "0.1.34"
tracing-subscriber = { version = "0.3.16", features = [ "env-filter", "json" ] }
url = { version = "2.4.0", features = [ "serde" ] }
walkdir = "2.5.0"

# server
hyper = "0.14.27"
Expand Down
1 change: 1 addition & 0 deletions bin/sozo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ serde.workspace = true
serde_json.workspace = true
smol_str.workspace = true
sozo-ops.workspace = true
sozo-walnut.workspace = true
starknet.workspace = true
starknet-crypto.workspace = true
thiserror.workspace = true
Expand Down
47 changes: 38 additions & 9 deletions bin/sozo/src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use dojo_world::metadata::get_default_namespace_from_ws;
use scarb::core::Config;
use scarb_ui::Ui;
use sozo_ops::auth;
use sozo_walnut::WalnutDebugger;
use tracing::trace;

use super::options::account::AccountOptions;
Expand Down Expand Up @@ -149,24 +150,41 @@ pub async fn grant(
) -> Result<()> {
trace!(?kind, ?world, ?starknet, ?account, ?transaction, "Executing Grant command.");
let world =
utils::world_from_env_metadata(world, account, starknet, &env_metadata, config).await?;
utils::world_from_env_metadata(world, account, &starknet, &env_metadata, config).await?;

let walnut_debugger =
WalnutDebugger::new_from_flag(transaction.walnut, starknet.url(env_metadata.as_ref())?);

match kind {
AuthKind::Writer { models_contracts } => {
trace!(
contracts=?models_contracts,
"Granting Writer permissions."
);
auth::grant_writer(ui, &world, &models_contracts, transaction.into(), default_namespace)
.await
auth::grant_writer(
ui,
&world,
&models_contracts,
&transaction.into(),
default_namespace,
&walnut_debugger,
)
.await
}
AuthKind::Owner { owners_resources } => {
trace!(
resources=?owners_resources,
"Granting Owner permissions."
);
auth::grant_owner(ui, &world, &owners_resources, transaction.into(), default_namespace)
.await
auth::grant_owner(
ui,
&world,
&owners_resources,
&transaction.into(),
default_namespace,
&walnut_debugger,
)
.await
}
}
}
Expand All @@ -185,7 +203,10 @@ pub async fn revoke(
) -> Result<()> {
trace!(?kind, ?world, ?starknet, ?account, ?transaction, "Executing Revoke command.");
let world =
utils::world_from_env_metadata(world, account, starknet, &env_metadata, config).await?;
utils::world_from_env_metadata(world, account, &starknet, &env_metadata, config).await?;

let walnut_debugger =
WalnutDebugger::new_from_flag(transaction.walnut, starknet.url(env_metadata.as_ref())?);

match kind {
AuthKind::Writer { models_contracts } => {
Expand All @@ -197,8 +218,9 @@ pub async fn revoke(
ui,
&world,
&models_contracts,
transaction.into(),
&transaction.into(),
default_namespace,
&walnut_debugger,
)
.await
}
Expand All @@ -207,8 +229,15 @@ pub async fn revoke(
resources=?owners_resources,
"Revoking Owner permissions."
);
auth::revoke_owner(ui, &world, &owners_resources, transaction.into(), default_namespace)
.await
auth::revoke_owner(
ui,
&world,
&owners_resources,
&transaction.into(),
default_namespace,
&walnut_debugger,
)
.await
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion bin/sozo/src/commands/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use dojo_world::contracts::naming::ensure_namespace;
use dojo_world::metadata::get_default_namespace_from_ws;
use scarb::core::Config;
use sozo_ops::execute;
use sozo_walnut::WalnutDebugger;
use tracing::trace;

use super::calldata_decoder;
Expand Down Expand Up @@ -61,11 +62,16 @@ impl ExecuteArgs {
ensure_namespace(&self.tag_or_address, &default_namespace)
};

let walnut_debugger = WalnutDebugger::new_from_flag(
self.transaction.walnut,
self.starknet.url(env_metadata.as_ref())?,
);

config.tokio_handle().block_on(async {
let world = utils::world_from_env_metadata(
self.world,
self.account,
self.starknet,
&self.starknet,
&env_metadata,
config,
)
Expand Down Expand Up @@ -93,6 +99,7 @@ impl ExecuteArgs {
calldata,
&world,
&tx_config,
&walnut_debugger,
)
.await
})
Expand Down
11 changes: 9 additions & 2 deletions bin/sozo/src/commands/options/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ pub struct TransactionOptions {
)]
#[arg(global = true)]
pub receipt: bool,

#[arg(long)]
#[arg(help = "Display the link to debug the transaction with Walnut.")]
#[arg(global = true)]
pub walnut: bool,
}

impl TransactionOptions {
Expand All @@ -52,10 +57,11 @@ impl TransactionOptions {
(true, false) => Ok(TxnAction::Estimate),
(false, true) => Ok(TxnAction::Simulate),
(false, false) => Ok(TxnAction::Send {
wait: self.wait,
wait: self.wait || self.walnut,
receipt: self.receipt,
max_fee_raw: self.max_fee_raw,
fee_estimate_multiplier: self.fee_estimate_multiplier,
walnut: self.walnut,
}),
}
}
Expand All @@ -71,9 +77,10 @@ impl From<TransactionOptions> for TxnConfig {
);
Self {
fee_estimate_multiplier: value.fee_estimate_multiplier,
wait: value.wait,
wait: value.wait || value.walnut,
receipt: value.receipt,
max_fee_raw: value.max_fee_raw,
walnut: value.walnut,
}
}
}
9 changes: 7 additions & 2 deletions bin/sozo/src/commands/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::{Args, Subcommand};
use dojo_world::contracts::WorldContractReader;
use scarb::core::Config;
use sozo_ops::register;
use sozo_walnut::WalnutDebugger;
use starknet::accounts::ConnectedAccount;
use starknet::core::types::{BlockId, BlockTag, Felt};
use tracing::trace;
Expand Down Expand Up @@ -58,9 +59,12 @@ impl RegisterArgs {
let world_address = world.world_address.unwrap_or_default();
trace!(?world_address, "Using world address.");

let walnut_debugger =
WalnutDebugger::new_from_flag(transaction.walnut, starknet.url(env_metadata.as_ref())?);

config.tokio_handle().block_on(async {
let world =
utils::world_from_env_metadata(world, account, starknet, &env_metadata, config)
utils::world_from_env_metadata(world, account, &starknet, &env_metadata, config)
.await?;
let provider = world.account.provider();
let mut world_reader = WorldContractReader::new(world_address, &provider);
Expand All @@ -69,10 +73,11 @@ impl RegisterArgs {
register::model_register(
models,
&world,
transaction.into(),
&transaction.into(),
world_reader,
world_address,
config,
&walnut_debugger,
)
.await
})
Expand Down
4 changes: 2 additions & 2 deletions bin/sozo/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn load_metadata_from_config(config: &Config) -> Result<Option<Environment>,
pub async fn world_from_env_metadata(
world: WorldOptions,
account: AccountOptions,
starknet: StarknetOptions,
starknet: &StarknetOptions,
env_metadata: &Option<Environment>,
config: &Config,
) -> Result<WorldContract<SozoAccount<JsonRpcClient<HttpTransport>>>, Error> {
Expand All @@ -64,7 +64,7 @@ pub async fn world_from_env_metadata(
.account(
provider,
WorldAddressOrName::Address(world_address),
&starknet,
starknet,
env_metadata,
config,
)
Expand Down
1 change: 0 additions & 1 deletion crates/dojo-lang/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ impl Compiler for DojoCompiler {

for (decl, contract_class, debug_info) in izip!(contracts, classes, debug_info_classes) {
let contract_name = decl.submodule_id.name(db.upcast_mut());

// note that the qualified path is in snake case while
// the `full_path()` method of StructId uses the original struct name case.
// (see in `get_dojo_model_artifacts`)
Expand Down
2 changes: 2 additions & 0 deletions crates/dojo-utils/src/tx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct TxnConfig {
pub wait: bool,
pub receipt: bool,
pub max_fee_raw: Option<Felt>,
pub walnut: bool,
}

#[derive(Debug, Copy, Clone)]
Expand All @@ -29,6 +30,7 @@ pub enum TxnAction {
/// 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<f64>,
walnut: bool,
},
Estimate,
Simulate,
Expand Down
4 changes: 2 additions & 2 deletions crates/dojo-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ scarb = { workspace = true, optional = true }
tokio = { version = "1.32.0", features = [ "time" ], default-features = false, optional = true }
toml.workspace = true
url = { workspace = true, optional = true }
walkdir = "2.5.0"
walkdir.workspace = true

[dev-dependencies]
assert_fs.workspace = true
Expand All @@ -52,4 +52,4 @@ tokio.workspace = true
contracts = [ "dep:dojo-types", "dep:http", "dep:num-traits" ]
manifest = [ "contracts", "dep:dojo-types", "dep:scarb", "dep:url" ]
metadata = [ "dep:ipfs-api-backend-hyper", "dep:scarb", "dep:url" ]
migration = [ "dep:dojo-utils", "dep:scarb", "dep:tokio" ]
migration = [ "dep:dojo-utils", "dep:scarb", "dep:tokio", "manifest" ]
1 change: 1 addition & 0 deletions crates/sozo/ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ tokio.workspace = true
toml.workspace = true
tracing.workspace = true
url.workspace = true
sozo-walnut.workspace = true

dojo-test-utils = { workspace = true, features = [ "build-examples" ], optional = true }
katana-runner = { workspace = true, optional = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/sozo/ops/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub async fn deploy(
};

match txn_action {
TxnAction::Send { wait, receipt, max_fee_raw, fee_estimate_multiplier } => {
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 {
Expand Down Expand Up @@ -277,7 +277,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 };
let txn_config =
TxnConfig { fee_estimate_multiplier, wait, receipt, max_fee_raw, walnut };
do_account_deploy(
max_fee,
txn_config,
Expand Down
Loading

0 comments on commit 76458a3

Please sign in to comment.