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

Update default l1 gas price value, add CLI arg #26

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ struct Cli {
#[arg(long)]
/// If true, will load the locally compiled system contracts (useful when doing changes to system contracts or bootloader)
dev_use_local_contracts: bool,

#[arg(long)]
/// Whether to override the l1 gas price.
/// If not set - fork or default value(`1 gwei`) will be used.
override_l1_gas_price: Option<u64>,
Copy link
Collaborator

@MexicanAce MexicanAce Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid having another CLI argument in favor of a new RPC endpoint in the CONFIG namespace? e.g. config_setL1GasPrice(gasPrice: u64)

The idea would be to have the test node configuration editable without restarting the node.

Example (Would go in https://github.com/matter-labs/era-test-node/blob/main/src/configuration_api.rs):

#[rpc(name = "config_setL1GasPrice", returns = "u64")]
fn config_set_l1_gas_price(&self, gas_price: u64) -> Result<u64>;

// ...

fn config_set_l1_gas_price(&self, gas_price: u64) -> Result<u64> {
    let mut inner = self.node.write().unwrap(); // We're cleaning up `.unwrap()` use, just leaving here for simplicity
    inner.l1_gas_price = gas_price;
    Ok(inner.l1_gas_price)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have not seen it, but sounds good. Will take a look, thanks

}

#[derive(Debug, Parser, Clone, clap::ValueEnum, PartialEq, Eq)]
Expand Down Expand Up @@ -170,10 +175,11 @@ struct ForkArgs {
/// - http://XXX:YY
network: String,
#[arg(long)]
// Fork at a given L2 miniblock height.
// If not set - will use the current finalized block from the network.
/// Fork at a given L2 miniblock height.
/// If not set - will use the current finalized block from the network.
fork_at: Option<u64>,
}

#[derive(Debug, Parser)]
struct ReplayArgs {
/// Whether to fork from existing network.
Expand Down Expand Up @@ -228,6 +234,7 @@ async fn main() -> anyhow::Result<()> {

let node = InMemoryNode::new(
fork_details,
opt.override_l1_gas_price,
opt.show_calls,
opt.resolve_hashes,
opt.dev_use_local_contracts,
Expand Down
14 changes: 10 additions & 4 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,19 @@ fn contract_address_from_tx_result(execution_result: &VmTxExecutionResult) -> Op
impl InMemoryNode {
pub fn new(
fork: Option<ForkDetails>,
override_l1_gas_price: Option<u64>,
show_calls: ShowCalls,
resolve_hashes: bool,
dev_use_local_contracts: bool,
) -> Self {
let mut l1_gas_price = fork
.as_ref()
.map(|f| f.l1_gas_price)
.unwrap_or(1_000_000_000); // 1 gwei
if let Some(override_l1_gas_price) = override_l1_gas_price {
l1_gas_price = override_l1_gas_price;
}

InMemoryNode {
inner: Arc::new(RwLock::new(InMemoryNodeInner {
current_timestamp: fork
Expand All @@ -210,10 +219,7 @@ impl InMemoryNode {
.unwrap_or(NON_FORK_FIRST_BLOCK_TIMESTAMP),
current_batch: fork.as_ref().map(|f| f.l1_block.0 + 1).unwrap_or(1),
current_miniblock: fork.as_ref().map(|f| f.l2_miniblock + 1).unwrap_or(1),
l1_gas_price: fork
.as_ref()
.map(|f| f.l1_gas_price)
.unwrap_or(50_000_000_000),
l1_gas_price,
tx_results: Default::default(),
blocks: Default::default(),
fork_storage: ForkStorage::new(fork, dev_use_local_contracts),
Expand Down