Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Eagle941 committed Jul 17, 2024
1 parent e30528e commit aa19eb6
Show file tree
Hide file tree
Showing 33 changed files with 3,520 additions and 3,442 deletions.
3,835 changes: 889 additions & 2,946 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
]

[workspace.package]
# Edition 2021 is chosen to support async.
edition = "2021"
# Version chosen only because 1.78.0 is the stable version when writing this Cargo.toml
# If this version is changed, amend the version set in `build.yml`
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In the future, this tool is likely to evolve to support:
## How to Use

```bash
cargo run --release -- --db-path <PATHFINDER_DB> --start-block <BLOCK_NUM> --end-block <BLOCK_NUM>
cargo run --release -- --rpc-url <STARKNET_JSONRPC_ENDPOINT> --start-block <BLOCK_NUM> --end-block <BLOCK_NUM>
```

`PATHFINDER_DB` is the path of the Pathfinder sqlite database. The Pathfinder
Expand All @@ -42,7 +42,7 @@ This tool makes use of `tracing` library for log purposes. For this reason set
## Example

```bash
cargo run -- --db-path ../pathfinder/mainnet.sqlite --start-block 632917 --end-block 632917 --svg-out "histogram.svg"
cargo run --release -- --rpc-url https://starknet-mainnet.public.blastapi.io/rpc/v0_7 --start-block 632917 --end-block 632917 --svg-out "histogram.svg"
```

The command above replays all transactions of block
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tracing-subscriber = { version = "0.3.17", features = [
"ansi",
] }
exitcode = "1.1.2"
url = "2.5.2"
anyhow.workspace = true
tracing.workspace = true
itertools.workspace = true
8 changes: 6 additions & 2 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
use std::path::PathBuf;

use clap::Parser;
use url::Url;

/// This is the struct of the command line arguments accepted by
/// `starknet-replay`.
#[derive(Clone, Parser, Debug)]
pub struct Args {
/// The path of the Pathfinder database file.
#[arg(long)]
pub db_path: PathBuf,
pub rpc_url: Url,

/// The starting block to replay transactions.
#[arg(long)]
Expand Down Expand Up @@ -38,7 +41,8 @@ pub struct Args {
#[arg(long)]
pub trace_out: Option<PathBuf>,

/// Set to overwrite `svg_out` and/or `txt_out` if it already exists.
/// Set to overwrite `svg_out`, `txt_out`, `trace_out` if they already
/// exists.
#[arg(long)]
pub overwrite: bool,
}
17 changes: 12 additions & 5 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
//! transactions within those blocks. This is only the CLI front-end. All the
//! logic is contained in the library [`starknet_replay`].

#![warn(clippy::all, clippy::cargo, clippy::pedantic)]
#![warn(
clippy::all,
clippy::cargo,
clippy::pedantic,
clippy::missing_docs_in_private_items,
clippy::unwrap_used
)]
#![allow(clippy::multiple_crate_versions)] // Due to duplicate dependencies in pathfinder

use std::path::PathBuf;
Expand All @@ -18,7 +24,7 @@ use starknet_replay::profiler::analysis::extract_libfuncs_weight;
use starknet_replay::profiler::report::write_to_file;
use starknet_replay::runner::replay_range::ReplayRange;
use starknet_replay::runner::run_replay;
use starknet_replay::storage::pathfinder::PathfinderStorage;
use starknet_replay::storage::rpc::RpcStorage;

use crate::args::Args;

Expand All @@ -28,6 +34,7 @@ mod args;
// a huge number of allocations. We get roughly two times better execution
// performance by using jemalloc (compared to the Linux glibc allocator).
// TODO: review in other operating systems. Issue #21
/// Custom allocator for efficiency in Linux.
#[global_allocator]
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;

Expand Down Expand Up @@ -90,7 +97,7 @@ fn check_file(path: &Option<PathBuf>, overwrite: bool) -> anyhow::Result<()> {
/// replay.
/// - Any error during execution of the replayer..
fn run(args: Args) -> anyhow::Result<()> {
let database_path = args.db_path;
let rpc_url = args.rpc_url;
let start_block = args.start_block;
let end_block = args.end_block;
let svg_path = args.svg_out;
Expand All @@ -102,14 +109,14 @@ fn run(args: Args) -> anyhow::Result<()> {
check_file(&txt_out, overwrite)?;
check_file(&trace_out, overwrite)?;

let storage = PathfinderStorage::new(database_path)?;
let storage = RpcStorage::new(rpc_url)?;

let replay_range = ReplayRange::new(start_block, end_block)?;

tracing::info!(%start_block, %end_block, "Re-executing blocks");
let start_time = std::time::Instant::now();

let visited_pcs = run_replay(&replay_range, &trace_out, &storage.clone())?;
let visited_pcs = run_replay(&replay_range, &trace_out, &storage)?;

let elapsed = start_time.elapsed();
tracing::info!(?elapsed, "Finished");
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allow-unwrap-in-tests = true
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Ensure this is matching `Cargo.toml`.
edition = "2021"

# Better readability
format_code_in_doc_comments = true
wrap_comments = true
Expand Down
23 changes: 16 additions & 7 deletions starknet-replay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,38 @@ cairo-lang-compiler = "2.6.0"
cairo-lang-sierra = "2.6.0"
cairo-lang-utils = "2.6.0"
cairo-lang-sierra-generator = "2.6.0"
# Some changes are required to `eqlabs/pathfinder` and to
# `starkware-libs/blockifier`. These changes are in the branch `extract_libfunc`
# of Reilabs fork and need to be merged in main branch.
# Some changes are required to `starkware-libs/blockifier`. These changes are
# in the branch `extract_libfunc` of Reilabs fork and need to be merged
# in main branch.
# Hardcoding the commit hash for the time being.
pathfinder-common = { git = "https:/reilabs/pathfinder.git", rev = "fdeb5b0d1747d6396e5b0774140026a3b1beae2f" }
pathfinder-executor = { git = "https:/reilabs/pathfinder.git", rev = "fdeb5b0d1747d6396e5b0774140026a3b1beae2f" }
pathfinder-rpc = { git = "https:/reilabs/pathfinder.git", rev = "fdeb5b0d1747d6396e5b0774140026a3b1beae2f" }
pathfinder-storage = { git = "https:/reilabs/pathfinder.git", rev = "fdeb5b0d1747d6396e5b0774140026a3b1beae2f" }
blockifier = { git = "https:/reilabs/blockifier.git", rev = "fdb86caf85435cb42ae363c7b04b5620bc80c24a" }
# `plotters` is using the latest (as of 30-May-2024) commit on the branch
# `next-release-devel` because it contains the fix for bug #551 related to
# anchoring of labels when rotated. Issue #26.
plotters = { git = "https:/plotters-rs/plotters.git", rev = "a7a3f8989af20931dd9e7e1f204d5254de3a8053" }
flate2 = "1.0.25"
rayon = "1.8.0"
starknet_api = "0.10.0"
starknet = "0.5.0"
serde = "1.0.192"
serde_json = "1.0.105"
serde_with = "3.0.0"
smol_str = { version = "0.2.0", features = ["serde"] }
thiserror = "1.0.61"
jsonrpc = { version = "0.18.0", features = ["minreq_http"] }
url = "2.5.2"
hex = "0.4.3"
once_cell = "1.17.1"
anyhow.workspace = true
tracing.workspace = true
itertools.workspace = true

[dependencies.minreq]
version = "2.11.2"
features = ["https"]

[dev-dependencies]
indoc = "2.0.5"
rand = "0.8.4"
rand_chacha = "0.3.1"
test-log = { version = "0.2.16", features = ["trace"] }
Loading

0 comments on commit aa19eb6

Please sign in to comment.