Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds fork-transaction-hash and rename network to fork-url #431

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ pub struct ForkArgs {
/// - http://XXX:YY
#[arg(
long,
help = "Network to fork from (e.g., mainnet, sepolia-testnet, etc.)."
alias = "network",
help = "Network to fork from (e.g., http://XXX:YY, mainnet, sepolia-testnet)."
)]
pub network: String,
pub fork_url: String,
// Fork at a given L2 miniblock height.
// If not set - will use the current finalized block from the network.
#[arg(
Expand All @@ -230,6 +231,17 @@ pub struct ForkArgs {
alias = "fork-at"
)]
pub fork_block_number: Option<u64>,

/// Fetch state from a specific transaction hash over a remote endpoint.
///
/// See --fork-url.
#[arg(
long,
requires = "fork_url",
value_name = "TRANSACTION",
conflicts_with = "fork_block_number"
)]
pub fork_transaction_hash: Option<H256>,
}

#[derive(Debug, Parser, Clone)]
Expand All @@ -243,9 +255,10 @@ pub struct ReplayArgs {
/// - http://XXX:YY
#[arg(
long,
help = "Network to fork from (e.g., mainnet, sepolia-testnet, etc.)."
alias = "network",
help = "Network to fork from (e.g., http://XXX:YY, mainnet, sepolia-testnet)."
)]
pub network: String,
pub fork_url: String,
/// Transaction hash to replay.
#[arg(help = "Transaction hash to replay.")]
pub tx: H256,
Expand Down
64 changes: 43 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,33 +157,55 @@ async fn main() -> anyhow::Result<()> {
}
}
Command::Fork(fork) => {
match ForkDetails::from_network(
&fork.network,
fork.fork_block_number,
&config.cache_config,
)
.await
{
Ok(fd) => {
// Update the config here
config = config
.with_l1_gas_price(Some(fd.l1_gas_price))
.with_l2_gas_price(Some(fd.l2_fair_gas_price))
.with_l1_pubdata_price(Some(fd.fair_pubdata_price))
.with_price_scale(Some(fd.estimate_gas_price_scale_factor))
.with_gas_limit_scale(Some(fd.estimate_gas_scale_factor))
.with_chain_id(Some(fd.chain_id.as_u64() as u32));
Some(fd)
if let Some(tx_hash) = fork.fork_transaction_hash {
// If fork_transaction_hash is provided, use from_network_tx
match ForkDetails::from_network_tx(&fork.fork_url, tx_hash, &config.cache_config)
.await
{
Ok(fd) => {
config = config
.with_l1_gas_price(Some(fd.l1_gas_price))
.with_l2_gas_price(Some(fd.l2_fair_gas_price))
.with_l1_pubdata_price(Some(fd.fair_pubdata_price))
.with_price_scale(Some(fd.estimate_gas_price_scale_factor))
.with_gas_limit_scale(Some(fd.estimate_gas_scale_factor))
.with_chain_id(Some(fd.chain_id.as_u64() as u32));
Some(fd)
}
Err(error) => {
tracing::error!("cannot fork from transaction: {:?}", error);
return Err(anyhow!(error));
}
}
Err(error) => {
tracing::error!("cannot fork: {:?}", error);
return Err(anyhow!(error));
} else {
// Otherwise, use from_network
match ForkDetails::from_network(
&fork.fork_url,
fork.fork_block_number,
&config.cache_config,
)
.await
{
Ok(fd) => {
config = config
.with_l1_gas_price(Some(fd.l1_gas_price))
.with_l2_gas_price(Some(fd.l2_fair_gas_price))
.with_l1_pubdata_price(Some(fd.fair_pubdata_price))
.with_price_scale(Some(fd.estimate_gas_price_scale_factor))
.with_gas_limit_scale(Some(fd.estimate_gas_scale_factor))
.with_chain_id(Some(fd.chain_id.as_u64() as u32));
Some(fd)
}
Err(error) => {
tracing::error!("cannot fork: {:?}", error);
return Err(anyhow!(error));
itegulov marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Command::ReplayTx(replay_tx) => {
match ForkDetails::from_network_tx(
&replay_tx.network,
&replay_tx.fork_url,
replay_tx.tx,
&config.cache_config,
)
Expand Down