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: stub the RPC server's logger #4534

Merged
merged 1 commit into from
Oct 27, 2023
Merged
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
38 changes: 24 additions & 14 deletions crates/edr_rpc_server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
use std::mem;
use std::net::{SocketAddr, TcpListener};
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
mod config;
mod filter;
mod hardhat_methods;
mod logger;
mod node;

use std::{
mem,
net::{SocketAddr, TcpListener},
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};

use axum::{
extract::{Json, State},
Expand Down Expand Up @@ -37,19 +45,21 @@ use sha3::{Digest, Keccak256};
use tokio::sync::RwLock;
use tracing::{event, Level};

mod hardhat_methods;
mod node;
pub use hardhat_methods::{
reset::{RpcForkConfig, RpcHardhatNetworkConfig},
HardhatMethodInvocation,
use self::{
filter::{new_filter_deadline, Filter},
node::{Node, NodeData, NodeError},
};

mod config;
pub use config::{AccountConfig, Config};
pub use self::{
config::{AccountConfig, Config},
hardhat_methods::{
reset::{RpcForkConfig, RpcHardhatNetworkConfig},
HardhatMethodInvocation,
},
};

mod filter;
use crate::node::{Node, NodeData, NodeError};
use filter::{new_filter_deadline, Filter};
// TODO: Remove this once we are internally using `Logger`
pub use self::logger::Logger;

/// an RPC method with its parameters
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
Expand Down
125 changes: 125 additions & 0 deletions crates/edr_rpc_server/src/logger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
use edr_eth::{
transaction::{SignedTransaction, TransactionRequest},
B256,
};
use edr_evm::{trace::Trace, Bytecode, MineBlockResult, SyncBlock};

use crate::node::NodeError;

/// A logger that handles all the logging of the RPC server.
///
/// The API follows this convention:
/// - `log_*` methods accumulate logs.
/// - `print_*` methods immediately print to stdout.
pub struct Logger {
_is_enabled: bool,
}

impl Logger {
/// Constructs a new instance.
pub fn new(is_enabled: bool) -> Self {
Self {
_is_enabled: is_enabled,
}
}

/// Logs the result of auto-mining a block.
pub fn log_block_from_automine<BlockchainErrorT, StateErrorT>(
_result: MineBlockResult<BlockchainErrorT, StateErrorT>,
_contracts: Vec<Bytecode>,
_transaction_hash_to_highlight: &B256,
) {
}

/// Logs the result of mining a block.
pub fn log_mined_block<BlockchainErrorT, StateErrorT>(
_result: MineBlockResult<BlockchainErrorT, StateErrorT>,
_contracts: Vec<Bytecode>,
) {
}

/// Logs the result of interval mining a block.
pub fn log_interval_mined_block<BlockchainErrorT, StateErrorT>(
_result: MineBlockResult<BlockchainErrorT, StateErrorT>,
_contracts: Vec<Bytecode>,
) {
}

/// Logs an empty hardhat-mined block.
pub fn log_empty_hardhat_mined_block(_block_number: u64, _base_fee_per_gas: Option<u64>) {}

/// Logs a single transaction.
pub fn log_single_transaction<BlockchainErrorT>(
_block: &dyn SyncBlock<Error = BlockchainErrorT>,
_transaction: &SignedTransaction,
_code: &Bytecode,
_gas_used: u64,
_trace: &Trace,
) {
}

/// Logs the currently sent transaction.
pub fn log_currently_sent_transaction<BlockchainErrorT>(
_block: &dyn SyncBlock<Error = BlockchainErrorT>,
_transaction: &SignedTransaction,
_code: &Bytecode,
_gas_used: u64,
_trace: &Trace,
) {
}

/// Logs the trace of an `eth_estimateGas` call.
pub fn log_estimate_gas_trace(
_transaction: &TransactionRequest,
_code: &Bytecode,
_gas_used: u64,
_trace: &Trace,
_console_log_messages: Vec<String>,
) {
}

/// Logs the trace of an `eth_call` call.
pub fn log_call_trace(
_transaction: &TransactionRequest,
_code: &Bytecode,
_trace: &Trace,
_console_log_messages: Vec<String>,
_error: Option<NodeError>,
) {
}

/// Logs a warning about multiple transactions being mined.
pub fn log_multiple_transactions_warning() {}

/// Logs a warning about multiple blocks being mined.
pub fn log_multiple_blocks_warning() {}

/// Logs an empty line.
pub fn log_empty_line() {}

/// Print an error message.
pub fn print_error_message(_message: &str) {}

/// Prints a warning message.
pub fn print_warning_message(_message: &str) {}

/// Prints a failed method.
pub fn print_failed_method(_method: &str) {}

/// Prints a method.
pub fn print_method(_method: &str) {}

/// Prints all accumulated logs.
pub fn print_logs() {}

/// Prints the block number of an interval-mined block.
pub fn print_interval_mined_block_number(
_block_number: u64,
_is_empty: bool,
_base_fee_per_gas: Option<u64>,
) {
}

/// Prints an empty line.
pub fn print_empty_line() {}
}
Loading