Skip to content

Commit

Permalink
Add option to use native trace in stylus replay
Browse files Browse the repository at this point in the history
  • Loading branch information
gligneul committed Aug 20, 2024
1 parent f73265e commit 48a1704
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
24 changes: 10 additions & 14 deletions replay/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,8 @@ enum Subcommands {

#[derive(Args, Clone, Debug)]
struct ReplayArgs {
/// RPC endpoint.
#[arg(short, long, default_value = "http://localhost:8547")]
endpoint: String,
/// Tx to replay.
#[arg(short, long)]
tx: TxHash,
/// Project path.
#[arg(short, long, default_value = ".")]
project: PathBuf,
#[command(flatten)]
trace: TraceArgs,
/// Whether to use stable Rust. Note that nightly is needed to expand macros.
#[arg(short, long)]
stable_rust: bool,
Expand All @@ -76,6 +69,9 @@ struct TraceArgs {
/// Project path.
#[arg(short, long, default_value = ".")]
project: PathBuf,
/// If set, use the native tracer instead of the JavaScript one. Notice the native tracer might not be available in the node.
#[arg(short, long, default_value_t = false)]
use_native_tracer: bool,
}

fn main() -> Result<()> {
Expand Down Expand Up @@ -106,7 +102,7 @@ async fn main_impl(args: Opts) -> Result<()> {

async fn trace(args: TraceArgs) -> Result<()> {
let provider = sys::new_provider(&args.endpoint)?;
let trace = Trace::new(provider, args.tx).await?;
let trace = Trace::new(provider, args.tx, args.use_native_tracer).await?;
println!("{}", trace.json);
Ok(())
}
Expand Down Expand Up @@ -144,11 +140,11 @@ async fn replay(args: ReplayArgs) -> Result<()> {
bail!("failed to exec gdb {:?}", err);
}

let provider = sys::new_provider(&args.endpoint)?;
let trace = Trace::new(provider, args.tx).await?;
let provider = sys::new_provider(&args.trace.endpoint)?;
let trace = Trace::new(provider, args.trace.tx, args.trace.use_native_tracer).await?;

build_so(&args.project)?;
let so = find_so(&args.project)?;
build_so(&args.trace.project)?;
let so = find_so(&args.trace.project)?;

// TODO: don't assume the contract is top-level
let args_len = trace.tx.input.len();
Expand Down
12 changes: 10 additions & 2 deletions replay/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ pub struct Trace {
}

impl Trace {
pub async fn new<T: JsonRpcClient>(provider: Provider<T>, tx: TxHash) -> Result<Self> {
pub async fn new<T: JsonRpcClient>(
provider: Provider<T>,
tx: TxHash,
use_native_tracer: bool,
) -> Result<Self> {
let hash = tx.0.into();

let Some(receipt) = provider.get_transaction_receipt(hash).await? else {
Expand All @@ -33,7 +37,11 @@ impl Trace {
bail!("failed to get tx data: {}", hash)
};

let query = include_str!("query.js");
let query = if use_native_tracer {
"stylusTracer"
} else {
include_str!("query.js")
};
let tracer = GethDebugTracingOptions {
tracer: Some(GethDebugTracerType::JsTracer(query.to_owned())),
..GethDebugTracingOptions::default()
Expand Down

0 comments on commit 48a1704

Please sign in to comment.