Skip to content

Commit

Permalink
feat: add silent and show-only-contract-logs flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Romsters committed Nov 27, 2024
1 parent 16c4d6d commit 42cecb9
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 102 deletions.
23 changes: 23 additions & 0 deletions SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The `status` options are:
| [`CONFIG`](#config-namespace) | [`config_setShowStorageLogs`](#config_setshowstoragelogs) | `SUPPORTED` | Updates `show_storage_logs` to print storage log reads/writes |
| [`CONFIG`](#config-namespace) | [`config_setShowVmDetails`](#config_setshowvmdetails) | `SUPPORTED` | Updates `show_vm_details` to print more detailed results from vm execution |
| [`CONFIG`](#config-namespace) | [`config_setShowGasDetails`](#config_setshowgasdetails) | `SUPPORTED` | Updates `show_gas_details` to print more details about gas estimation and usage |
| [`CONFIG`](#config-namespace) | [`config_setShowOnlyContractLogs`](#config_setshowonlycontractlogs) | `SUPPORTED` | Updates `show_only_contract_logs` |
| [`CONFIG`](#config-namespace) | [`config_setLogLevel`](#config_setloglevel) | `SUPPORTED` | Sets the logging level for the node and only displays the node logs. |
| [`CONFIG`](#config-namespace) | [`config_setLogging`](#config_setlogging) | `SUPPORTED` | Sets the fine-tuned logging levels for the node and any of its dependencies |
| [`DEBUG`](#debug-namespace) | [`debug_traceCall`](#debug_tracecall) | `SUPPORTED` | Performs a call and returns structured traces of the execution |
Expand Down Expand Up @@ -359,6 +360,28 @@ curl --request POST \
--data '{"jsonrpc": "2.0","id": "1","method": "config_setResolveHashes","params": [true]}'
```

### `config_setShowOnlyContractLogs`

[source](src/node/config_api.rs)

Updates `show_only_contract_logs`
#### Arguments

+ `value: boolean`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{"jsonrpc": "2.0","id": "1","method": "config_setShowOnlyContractLogs","params": [true]}'
```

### `config_setLogLevel`

[source](src/node/config_api.rs)
Expand Down
14 changes: 12 additions & 2 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct Cli {
/// Show call debug information.
pub show_calls: Option<ShowCalls>,

#[arg(long, help_heading = "Debugging Options")]
#[arg(long, default_missing_value = "true", num_args(0..=1), help_heading = "Debugging Options")]
/// Show call output information.
pub show_outputs: Option<bool>,

Expand All @@ -86,11 +86,15 @@ pub struct Cli {
/// Show gas details information.
pub show_gas_details: Option<ShowGasDetails>,

#[arg(long, help_heading = "Debugging Options")]
#[arg(long, default_missing_value = "true", num_args(0..=1), help_heading = "Debugging Options")]
/// If true, the tool will try to resolve ABI and topic names for better readability.
/// May decrease performance.
pub resolve_hashes: Option<bool>,

#[arg(long, default_missing_value = "true", num_args(0..=1), help_heading = "Debugging Options")]
/// If true, the tool will only show contract logs.
pub show_only_contract_logs: Option<bool>,

// Gas Configuration
#[arg(long, help_heading = "Gas Configuration")]
/// Custom L1 gas price (in wei).
Expand Down Expand Up @@ -138,6 +142,10 @@ pub struct Cli {
/// Log file path (default: era_test_node.log).
pub log_file_path: Option<String>,

#[arg(long, default_missing_value = "true", num_args(0..=1), help_heading = "Logging Configuration")]
/// If true, the tool will not print anything on startup.
pub silent: Option<bool>,

// Cache Options
#[arg(long, help_heading = "Cache Options")]
/// Cache type (none, memory, or disk). Default: "disk".
Expand Down Expand Up @@ -312,6 +320,8 @@ impl Cli {
.with_gas_limit_scale(self.limit_scale_factor)
.with_price_scale(self.price_scale_factor)
.with_resolve_hashes(self.resolve_hashes)
.with_show_only_contract_logs(self.show_only_contract_logs)
.with_silent(self.silent)
.with_system_contracts(self.dev_system_contracts)
.with_override_bytecodes_dir(self.override_bytecodes_dir.clone()) // Added
.with_log_level(self.log)
Expand Down
29 changes: 29 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ pub struct TestNodeConfig {
pub show_gas_details: ShowGasDetails,
/// Whether to resolve hash references
pub resolve_hashes: bool,
/// Don’t print anything on startup if true
pub silent: bool,
/// Print only contract logs
pub show_only_contract_logs: bool,
/// Configuration for system contracts
pub system_contracts_options: system_contracts::Options,
/// Directory to override bytecodes
Expand Down Expand Up @@ -124,6 +128,8 @@ impl Default for TestNodeConfig {
show_vm_details: Default::default(),
show_gas_details: Default::default(),
resolve_hashes: false,
show_only_contract_logs: false,
silent: false,
system_contracts_options: Default::default(),
override_bytecodes_dir: None,
use_evm_emulator: false,
Expand Down Expand Up @@ -170,6 +176,11 @@ impl TestNodeConfig {
)
.expect("Failed writing json");
}

if self.silent || self.show_only_contract_logs {
return;
}

let color = CustomColor::new(13, 71, 198);

println!("{}", BANNER.custom_color(color));
Expand Down Expand Up @@ -576,6 +587,24 @@ impl TestNodeConfig {
self
}

/// Enable or disable silent mode
#[must_use]
pub fn with_silent(mut self, silent: Option<bool>) -> Self {
if let Some(silent) = silent {
self.silent = silent;
}
self
}

/// Enable or disable printing only contract logs
#[must_use]
pub fn with_show_only_contract_logs(mut self, show_only_contract_logs: Option<bool>) -> Self {
if let Some(show_only_contract_logs) = show_only_contract_logs {
self.show_only_contract_logs = show_only_contract_logs;
}
self
}

/// Check if resolving hashes is enabled
pub fn is_resolve_hashes_enabled(&self) -> bool {
self.resolve_hashes
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async fn main() -> anyhow::Result<()> {

// Initialize the tracing subscriber

Check warning on line 119 in src/main.rs

View workflow job for this annotation

GitHub Actions / lint

Diff in /home/runner/work/era-test-node/era-test-node/src/main.rs
let observability =
Observability::init(vec!["era_test_node".into()], log_level_filter, log_file)?;
Observability::init(vec!["era_test_node".into()], log_level_filter, log_file, config.silent)?;

// Use `Command::Run` as default.
let command = command.as_ref().unwrap_or(&Command::Run);
Expand Down
10 changes: 10 additions & 0 deletions src/namespaces/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ pub trait ConfigurationApiNamespaceT {
#[rpc(name = "config_setResolveHashes", returns = "bool")]
fn config_set_resolve_hashes(&self, value: bool) -> Result<bool>;

/// Set show_only_contract_logs for the InMemoryNodeInner
///
/// # Parameters
/// - `value`: A bool to update show_only_contract_logs to
///
/// # Returns
/// The updated/current `show_only_contract_logs` value for the InMemoryNodeInner.
#[rpc(name = "config_setShowOnlyContractLogs", returns = "bool")]
fn config_set_show_only_contract_logs(&self, value: bool) -> Result<bool>;

/// Set the logging for the InMemoryNodeInner
///
/// # Parameters
Expand Down
15 changes: 15 additions & 0 deletions src/node/config_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> Configurat
})
}

fn config_set_show_only_contract_logs(&self, value: bool) -> Result<bool> {
self.get_inner()
.write()
.map_err(|err| {
tracing::error!("failed acquiring lock: {:?}", err);
into_jsrpc_error(Web3Error::InternalError(anyhow::Error::msg(
"Failed to acquire write lock for inner node state.",
)))
})
.map(|mut writer| {
writer.config.show_only_contract_logs = value;
writer.config.show_only_contract_logs
})
}

fn config_set_log_level(&self, level: LogLevel) -> Result<bool> {
let Some(observability) = &self.observability else {
return Err(into_jsrpc_error(Web3Error::InternalError(
Expand Down
Loading

0 comments on commit 42cecb9

Please sign in to comment.