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

fix: fixes broken logging and adds structure to logs #411

Merged
merged 17 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
40 changes: 16 additions & 24 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ pub struct Cli {
/// Show call debug information.
pub show_calls: Option<ShowCalls>,

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

Expand Down Expand Up @@ -325,22 +330,7 @@ impl Cli {
pub fn into_test_node_config(self) -> eyre::Result<TestNodeConfig> {
let genesis_balance = U256::from(self.balance as u128 * 10u128.pow(18));

let vm_log_detail = if let Some(output) = self.show_outputs {
if output {
Some(ShowVMDetails::All)
} else {
Some(ShowVMDetails::None)
}
} else if let Some(logs) = self.show_storage_logs {
match logs {
ShowStorageLogs::None => Some(ShowVMDetails::None),
_ => Some(ShowVMDetails::All),
}
} else {
None
};

let config = TestNodeConfig::default()
let mut config = TestNodeConfig::default()
.with_port(self.port)
.with_l1_gas_price(self.l1_gas_price)
.with_l2_gas_price(self.l2_gas_price)
Expand All @@ -349,7 +339,12 @@ impl Cli {
.with_show_event_logs(self.show_event_logs)
.with_disable_console_log(self.disable_console_log)
.with_show_calls(self.show_calls)
.with_vm_log_detail(vm_log_detail)
.with_vm_log_detail(self.show_vm_details)
.with_show_storage_logs(self.show_storage_logs)
.with_show_gas_details(self.show_gas_details)
.with_show_outputs(self.show_outputs)
.with_show_event_logs(self.show_event_logs)
.with_resolve_hashes(self.resolve_hashes)
.with_gas_limit_scale(self.limit_scale_factor)
.with_price_scale(self.price_scale_factor)
.with_resolve_hashes(self.resolve_hashes)
Expand Down Expand Up @@ -396,13 +391,10 @@ impl Cli {
}

if self.debug_mode {
Ok(config
.with_show_calls(Some(ShowCalls::All))
.with_vm_log_detail(Some(ShowVMDetails::All))
.with_resolve_hashes(Some(true)))
} else {
Ok(config)
config = config.with_debug_mode();
}

Ok(config)
}

fn account_generator(&self) -> AccountGenerator {
Expand Down
84 changes: 70 additions & 14 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,15 @@ impl TestNodeConfig {
&self.log_file_path
}

/// Applies the defaults for debug mode.
#[must_use]
pub fn with_debug_mode(mut self) -> Self {
self.show_calls = ShowCalls::User;
self.resolve_hashes = true;
self.show_gas_details = ShowGasDetails::All;
self
}

/// Set the visibility of call logs
#[must_use]
pub fn with_show_calls(mut self, show_calls: Option<ShowCalls>) -> Self {
Expand Down Expand Up @@ -658,6 +667,11 @@ impl TestNodeConfig {
self
}

/// Get the visibility of event logs
pub fn get_show_event_logs(&self) -> bool {
self.show_event_logs
}

// Enable or disable printing of `console.log` invocations to stdout
#[must_use]
pub fn with_disable_console_log(mut self, disable_console_log: Option<bool>) -> Self {
Expand All @@ -672,6 +686,62 @@ impl TestNodeConfig {
self.resolve_hashes
}

/// Set the visibility of storage logs
#[must_use]
pub fn with_show_storage_logs(mut self, show_storage_logs: Option<ShowStorageLogs>) -> Self {
if let Some(show_storage_logs) = show_storage_logs {
self.show_storage_logs = show_storage_logs;
}
self
}

/// Get the visibility of storage logs
pub fn get_show_storage_logs(&self) -> ShowStorageLogs {
self.show_storage_logs
}

/// Set the detail level of VM execution logs
#[must_use]
pub fn with_vm_log_detail(mut self, detail: Option<ShowVMDetails>) -> Self {
if let Some(detail) = detail {
self.show_vm_details = detail;
}
self
}

/// Get the detail level of VM execution logs
pub fn get_vm_log_detail(&self) -> ShowVMDetails {
self.show_vm_details
}

/// Set the visibility of gas usage logs
#[must_use]
pub fn with_show_gas_details(mut self, show_gas_details: Option<ShowGasDetails>) -> Self {
if let Some(show_gas_details) = show_gas_details {
self.show_gas_details = show_gas_details;
}
self
}

/// Get the visibility of gas usage logs
pub fn get_show_gas_details(&self) -> ShowGasDetails {
self.show_gas_details
}

/// Set show outputs
#[must_use]
pub fn with_show_outputs(mut self, show_outputs: Option<bool>) -> Self {
if let Some(show_outputs) = show_outputs {
self.show_outputs = show_outputs;
}
self
}

/// Get show outputs
pub fn get_show_outputs(&self) -> bool {
self.show_outputs
}

/// Set the gas limit scale factor
#[must_use]
pub fn with_gas_limit_scale(mut self, scale: Option<f32>) -> Self {
Expand Down Expand Up @@ -714,20 +784,6 @@ impl TestNodeConfig {
self
}

/// Set the detail level of VM execution logs
#[must_use]
pub fn with_vm_log_detail(mut self, detail: Option<ShowVMDetails>) -> Self {
if let Some(detail) = detail {
self.show_vm_details = detail;
}
self
}

/// Get the detail level of VM execution logs
pub fn get_vm_log_detail(&self) -> ShowVMDetails {
self.show_vm_details
}

/// Sets the balance of the genesis accounts in the genesis block
#[must_use]
pub fn with_genesis_balance<U: Into<U256>>(mut self, balance: U) -> Self {
Expand Down
8 changes: 8 additions & 0 deletions src/console_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ impl Default for ConsoleLogHandler {
}

impl ConsoleLogHandler {
pub fn handle_calls_recursive(&self, calls: &Vec<Call>) {
tracing::info!("");
tracing::info!("==== Console logs: ");

for call in calls {
self.handle_call_recursive(call);
}
}
pub fn handle_call_recursive(&self, current_call: &Call) {
self.handle_call(current_call);
for call in &current_call.calls {
Expand Down
145 changes: 44 additions & 101 deletions src/data/address_map.json
Original file line number Diff line number Diff line change
@@ -1,102 +1,45 @@
[
[
"0x0000000000000000000000000000000000008001",
"bootloader",
"System"
],
[
"0x0000000000000000000000000000000000008002",
"Account Code Storage",
"System"
],
[
"0x0000000000000000000000000000000000008003",
"Nonce Holder",
"System"
],
[
"0x0000000000000000000000000000000000008004",
"Known code storage",
"System"
],
[
"0x0000000000000000000000000000000000008005",
"ImmutableSimulator",
"System"
],
[
"0x0000000000000000000000000000000000008006",
"L2 deployer",
"System"
],
[
"0x0000000000000000000000000000000000008007",
"Force L2 deployer",
"System"
],
[
"0x0000000000000000000000000000000000008008",
"L1 messenger",
"System"
],
[
"0x0000000000000000000000000000000000008009",
"Msg Value System Contract",
"System"
],
[
"0x000000000000000000000000000000000000800a",
"EthToken System Contract",
"System"
],
[
"0x000000000000000000000000000000000000800b",
"System context",
"System"
],
[
"0x000000000000000000000000000000000000800c",
"Bootloader utilities",
"System"
],
[
"0x000000000000000000000000000000000000800d",
"Event writer",
"System"
],
[
"0x000000000000000000000000000000000000800e",
"Compressor",
"System"
],
[
"0x000000000000000000000000000000000000800f",
"ComplexUpgrader",
"System"
],
[
"0x0000000000000000000000000000000000008010",
"Keccak",
"Precompile"
],
[
"0x0000000000000000000000000000000000008011",
"PubdataChunkPublisher",
"System"
],
[
"0x0000000000000000000000000000000000008012",
"CodeOracle",
"System"
],
[
"0x000000000000000000636f6e736f6c652e6c6f67",
"Console log",
"Precompile"
],
[
"0x0000000000000000000000000000000000010000",
"Create2Factory",
"Popular"
]
]
["0x0000000000000000000000000000000000008001", "bootloader", "System"],
[
"0x0000000000000000000000000000000000008002",
"AccountCodeStorage",
"System"
],
["0x0000000000000000000000000000000000008003", "NonceHolder", "System"],
["0x0000000000000000000000000000000000008004", "KnownCodesStorage", "System"],
[
"0x0000000000000000000000000000000000008005",
"ImmutableSimulator",
"System"
],
["0x0000000000000000000000000000000000008006", "ContractDeployer", "System"],
["0x0000000000000000000000000000000000008007", "ForceL2Deployer", "System"],
["0x0000000000000000000000000000000000008008", "L1Messenger", "System"],
["0x0000000000000000000000000000000000008009", "MsgValueSimulator", "System"],
["0x000000000000000000000000000000000000800a", "L2BaseToken", "System"],
["0x000000000000000000000000000000000000800b", "SystemContext", "System"],
[
"0x000000000000000000000000000000000000800c",
"BootloaderUtilities",
"System"
],
["0x000000000000000000000000000000000000800d", "EventWriter", "System"],
["0x000000000000000000000000000000000000800e", "Compressor", "System"],
["0x000000000000000000000000000000000000800f", "ComplexUpgrader", "System"],
["0x0000000000000000000000000000000000008010", "Keccak", "Precompile"],
[
"0x0000000000000000000000000000000000008011",
"PubdataChunkPublisher",
"System"
],
["0x0000000000000000000000000000000000008012", "CodeOracle", "System"],
["0x000000000000000000636f6e736f6c652e6c6f67", "ConsoleLog", "Precompile"],
["0x0000000000000000000000000000000000010000", "Create2Factory", "System"],
["0x0000000000000000000000000000000000000002", "SHA256", "Precompile"],
["0x0000000000000000000000000000000000000001", "ECRecover", "Precompile"],
["0x0000000000000000000000000000000000000006", "EcAdd", "Precompile"],
["0x0000000000000000000000000000000000000007", "EcMul", "Precompile"],
["0x0000000000000000000000000000000000000008", "EcPairing", "Precompile"],
["0xc706EC7dfA5D4Dc87f29f859094165E8290530f5", "GasBoundCaller", "System"],
["0x0000000000000000000000000000000000000100", "P256Verify", "System"]
]
Loading
Loading