Skip to content

Commit

Permalink
Implement Comprehensive Dojo Storage Benchmarking with Katana (starkw…
Browse files Browse the repository at this point in the history
…are-libs#1148)

* added rust crate and dojo contract for benches

* fetching fee for tx

* used cli methods in benches

* a simple test

* dependency cleanup

* partial

* emit macro bench

* bench get and set macros

* added a list of katana prefunded accounts

* new components authorization

* contract cleanup

* prefunded keypair system

* nicer transaction sequence api

* first attempt on raw api usage

* new contract version

* working on starknet api

* estimating gas usage instead of executiong

* migration of everything to the new api

* exposed async api as well

* removed old attempt

* fixes after merge

* added character struct

* character init test

* update benchmark

* using tracing to log gas usage

* logging to file

* script and program for running benches

* sorting tests by name

* double set test

* a bit cleaner api

* a few more benches

* more character benches

* last fixes

* doubled performance

* cargo fmt

* cargo clippy --fix

* add macro_use

* fix missing trait

* remove unused extern crate

* clippy

---------

Co-authored-by: Mateusz Zając <matzayon@gmail.com>
  • Loading branch information
neotheprogramist and Mateusz Zając authored Nov 30, 2023
1 parent d7e9788 commit f4c9a4c
Show file tree
Hide file tree
Showing 26 changed files with 1,295 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dojo.iml
.DS_Store
.env
data
crates/benches/gas_usage.txt
144 changes: 144 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"crates/sozo",
"crates/torii/client",
"crates/torii/server",
"crates/benches",
]

[workspace.package]
Expand Down
19 changes: 19 additions & 0 deletions crates/benches/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "benches"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
proptest = "1.3.1"
reqwest = { version="0.11.18", features=["blocking", "json"] }
clap_builder = "4.4.6"

sozo = { path = "../sozo" }
starknet.workspace = true
anyhow.workspace = true
hex.workspace = true
lazy_static.workspace = true
futures.workspace = true
tokio.workspace = true
51 changes: 51 additions & 0 deletions crates/benches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This crate is dedicated for benchmarking purposes

## Quick start

```bash
katana
bash scripts/cargo_bench.sh
```

## Prerequisites

- `cargo` - for test case generation and runtime
- `katana` - as a local RPC server
- `sozo` - for contract compilation and deployment

## Requirements for running

While benchmarks are running a Katana instance has to be online either remotely or locally...

```bash
katana
```

...contracts have to be built and deployed...

```bash
sozo --manifest-path crates/benches/contracts/Scarb.toml build
sozo --manifest-path crates/benches/contracts/Scarb.toml migrate
```

...and actions authorized.

```bash
crates/benches/contracts/scripts/default_auth.sh
```

Then tests can be run with

```bash
cargo test bench -- --ignored
```

Benchmarks are ignored by default because they need a while to complete and need a running Katana. Their names should start with bench.

## Running with compiled `sozo`

While during testing release version of the tool worked better, Sozo can be run from source with

```bash
cargo run -r --bin sozo -- --manifest-path crates/benches/contracts/Scarb.toml build
```
5 changes: 5 additions & 0 deletions crates/benches/contracts/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cairo1.languageServerPath": "$HOME/.dojo/bin/dojo-language-server",
"cairo1.enableLanguageServer": true,
"cairo1.enableScarb": false
}
21 changes: 21 additions & 0 deletions crates/benches/contracts/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "benches"
version = "0.3.2"
dependencies = [
"dojo",
]

[[package]]
name = "dojo"
version = "0.3.2"
source = "git+https://github.com/dojoengine/dojo#0a772af3ec677705042630723c55b421f4fe084d"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_plugin"
version = "0.3.2"
21 changes: 21 additions & 0 deletions crates/benches/contracts/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
cairo-version = "2.2.0"
name = "benches"
version = "0.3.2"

[cairo]
sierra-replace-ids = true

[dependencies]
dojo = { git = "https://github.com/dojoengine/dojo", version = "0.3.2" }

[[target.dojo]]

[tool.dojo]
initializer_class_hash = "0xbeef"

[tool.dojo.env]
rpc_url = "http://localhost:5050/"
# Default account for katana with seed = 0
account_address = "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973"
private_key = "0x1800000000300000180000000000030000000000003006001800006600"
Loading

0 comments on commit f4c9a4c

Please sign in to comment.