Skip to content

Commit

Permalink
feat: config file (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeapoz authored Jul 3, 2024
1 parent 6c5d552 commit a0827eb
Show file tree
Hide file tree
Showing 21 changed files with 809 additions and 524 deletions.
54 changes: 37 additions & 17 deletions Cargo.lock

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

16 changes: 13 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository = "https://github.com/matter-labs/zksync-era"
license = "MIT OR Apache-2.0"
keywords = ["blockchain", "zksync"]
categories = ["cryptography"]
publish = false # We don't want to publish our binaries.
publish = false # We don't want to publish our binaries.

[dependencies]
zkevm_opcode_defs = { git = "https://github.com/matter-labs/era-zkevm_opcode_defs.git", branch = "v1.5.0" }
Expand All @@ -19,7 +19,10 @@ zksync_contracts = { git = "https://github.com/matter-labs/zksync-era.git", rev
zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_utils = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_state = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
zksync_web3_decl = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea", features = [ "server", "client" ] }
zksync_web3_decl = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea", features = [
"server",
"client",
] }
sha3 = "0.10.6"


Expand All @@ -39,7 +42,13 @@ clap = { version = "4.2.4", features = ["derive"] }
reqwest = { version = "0.11", features = ["blocking"] }
serde = { version = "1.0", features = ["derive"] }
tracing = { version = "0.1.26", features = ["log"] }
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter", "time", "json", "local-time"] }
tracing-subscriber = { version = "0.3", features = [
"fmt",
"env-filter",
"time",
"json",
"local-time",
] }
colored = "2.0"
lazy_static = "1.4"
eyre = "0.6"
Expand All @@ -52,6 +61,7 @@ rustc-hash = "1.1.0"
indexmap = "2.0.1"
chrono = { version = "0.4.31", default-features = false }
time = "0.3.30"
toml = "0.8.13"

[dev-dependencies]
httptest = "0.15.4"
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ Please note that `era-test-node` is still in its **alpha** stage. Some features
era_test_node run
```

## 🔧 Configuring

The test node can optionally be configured via a TOML configuration file placed
at `$HOME/.era_test_node/config.toml` or supplied as a path via the `--config` CLI-argument. To start configuring the test node:

1. Create the configuration directory:
```bash
mkdir $HOME/.era_test_node
```

2. Copy the example configuration file:
```bash
cp example/config.toml $HOME/.era_test_node
```

For all options that can be configured,
please refer to [examples/config.toml](examples/config.toml)

## 🧑‍💻 Running Locally

1. Compile Rust project and start the node:
Expand Down
49 changes: 49 additions & 0 deletions examples/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[node]
# Port to listen on.
port = 8011

# Show call debug information. Possible values: None, User, System, All.
show_calls = "None"
# Show call output.
show_outputs = false
# Show storage log information. Possible values: None, Read, Write, Paid, All.
show_storage_logs = "None"
# Show VM details information. Possible values: None, All,
show_vm_details = "None"
# Show gas details information. Possible values: None, All.
show_gas_details = "None"

# If true, the tool will try to contact openchain to resolve the ABI & topic names.
# It will make debug log more readable, but will decrease the performance.
resolve_hashes = false

# Specifies the option for the system contracts (use compiled built-in with or without signature verification, or load locally).
# Possible values: BuiltIn, BuiltInNoVerify, Local.
system_contracts_options = "BuiltIn"

# Note: gas configuration functions as overrides. If provided, the node will use
# these instead of setting them to network-appropriate values.
# [gas]
# L1 gas price.
# l1_gas_price = 10
# L2 gas price.
# l2_gas_price = 25_000_000

# [gas.estimation]
# L1 gas price scale factor for gas estimation.
# price_scale_factor = 1.5
# The factor by which to scale the gasLimit.
# limit_scale_factor = 1.3

[log]
# Log filter level. Possible values: trace, debug, info, warn, error.
level = "info"
# Log file path.
file_path = "era_test_node.log"

[cache]
# Cache type, can be one of `none`, `memory`, or `disk`
# The disk variant can further be configured via:
# - dir: Cache directory location.
# - reset: If true, will reset the local cache.
disk = { dir = ".cache", reset = false }
18 changes: 2 additions & 16 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use zksync_basic_types::H256;
use zksync_types::api::{Block, BridgeAddresses, Transaction, TransactionVariant};
use zksync_types::Transaction as RawTransaction;

use crate::config::cache::CacheConfig;

/// Caches full blocks by their hashes
const CACHE_TYPE_BLOCKS_FULL: &str = "blocks_full";
/// Caches minimal blocks by their hashes
Expand All @@ -24,22 +26,6 @@ const CACHE_TYPE_KEY_VALUE: &str = "key_value";
/// Caching key for bridge addresses
const CACHE_KEY_BRIDGE_ADDRESSES: &str = "bridge_addresses";

/// Cache configuration. Can be one of:
///
/// None : Caching is disabled
/// Memory : Caching is provided in-memory and not persisted across runs
/// Disk : Caching is persisted on disk in the provided directory and can be reset
#[derive(Default, Debug, Clone)]
pub enum CacheConfig {
#[default]
None,
Memory,
Disk {
dir: String,
reset: bool,
},
}

/// A general purpose cache.
#[derive(Default, Debug, Clone)]
pub(crate) struct Cache {
Expand Down
Loading

0 comments on commit a0827eb

Please sign in to comment.