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

Logging on startup #60

Merged
merged 3 commits into from
Sep 17, 2024
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
2 changes: 0 additions & 2 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ impl ConsensusClient {
.await
.wrap_err("Failed to get latest valid executor block")?;

debug!("Latest valid executor block is: {latest_valid_executor_block:?}");

Ok(Self {
config,
execution_api,
Expand Down
52 changes: 22 additions & 30 deletions client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,38 @@
extern crate alloc;

use crate::config::{AppConfig, CliArgs};
use crate::main_utils::{parse_log_level, run_client};
use std::fs;

use clap::Parser;
use eyre::{Context, Result};
use reth_primitives::revm_primitives::bitvec::macros::internal::funty::Fundamental;
use tokio_retry::strategy::FixedInterval;
use tokio_retry::Retry;
use telos_consensus_client::{
config::{AppConfig, CliArgs},
main_utils::{parse_log_level, run_client},
};
use tokio_retry::{strategy::FixedInterval, Retry};
use tracing::info;
use tracing_subscriber::fmt;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

mod auth;
mod client;
mod config;
mod data;
mod execution_api_client;
mod json_rpc;
mod main_utils;
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt};

#[tokio::main]
async fn main() {
async fn main() -> Result<()> {
let args = CliArgs::parse();
let config_contents = std::fs::read_to_string(&args.config).unwrap();
let config: AppConfig = toml::from_str(&config_contents).unwrap();
let log_level_filter = parse_log_level(&config.log_level).unwrap();
let config_contents = fs::read_to_string(&args.config)?;
let config: AppConfig = toml::from_str(&config_contents)?;
let log_level_filter = parse_log_level(&config.log_level)?;

tracing_subscriber::registry()
.with(fmt::layer())
.with(log_level_filter)
.init();

let retry_strategy = FixedInterval::from_millis(config.retry_interval.unwrap_or(8000u64))
.take(config.max_retry.unwrap_or(8u8).as_usize());
let retry_interval = config.retry_interval.unwrap_or(8000u64);
let max_retries = config.max_retry.unwrap_or(8u8).as_usize();
let retry_strategy = FixedInterval::from_millis(retry_interval).take(max_retries);

Retry::spawn(retry_strategy, || run_client(args.clone(), config.clone()))
.await
.wrap_err("Stopping consensus client, run failed!")?;

let result = Retry::spawn(retry_strategy, || run_client(args.clone(), config.clone())).await;
match result {
Ok(_) => {
info!("Consensus client Finished!");
}
Err(e) => {
info!("Stopping consensus client, run failed! Error: {:?}", e);
}
}
info!("Consensus client Finished!");
Ok(())
}
22 changes: 19 additions & 3 deletions client/src/main_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::client::Error::{CannotStartConsensusClient, TranslatorShutdown};
use crate::client::{ConsensusClient, Error, Shutdown};
use crate::config::{AppConfig, CliArgs};
use crate::data::Block;
use eyre::eyre;
use telos_translator_rs::block::TelosEVMBlock;
use telos_translator_rs::translator::Translator;
use tokio::sync::mpsc;
Expand Down Expand Up @@ -58,9 +59,17 @@ pub async fn build_consensus_client(
CannotStartConsensusClient(e.to_string())
})?;

// Translator
info!(
"Created client with latest EVM block: {:?}",
client.latest_evm_number()
);

let lib = client.db.get_lib()?;

if let Some(lib_number) = lib.as_ref().map(|lib| lib.number) {
info!("Last stored LIB: {lib_number}");
}

let latest_number = lib
.as_ref()
.map(|lib| lib.number + config.chain_id.block_delta())
Expand All @@ -72,6 +81,13 @@ pub async fn build_consensus_client(
None => None,
};

if let Some(last_checked) = last_checked.as_ref() {
info!(
"Last stored final block: {}, {}",
last_checked.number, last_checked.hash
);
}

if let Some(last_checked) = last_checked {
if client.is_in_start_stop_range(last_checked.number + 1) {
config.evm_start_block = last_checked.number + 1;
Expand All @@ -87,14 +103,14 @@ pub async fn build_consensus_client(
Ok((client, lib))
}

pub fn parse_log_level(s: &str) -> Result<LevelFilter, String> {
pub fn parse_log_level(s: &str) -> eyre::Result<LevelFilter> {
match s.to_lowercase().as_str() {
"off" => Ok(LevelFilter::OFF),
"error" => Ok(LevelFilter::ERROR),
"warn" => Ok(LevelFilter::WARN),
"info" => Ok(LevelFilter::INFO),
"debug" => Ok(LevelFilter::DEBUG),
"trace" => Ok(LevelFilter::TRACE),
_ => Err(format!("Unknown log level: {}", s)),
_ => Err(eyre!("Unknown log level: {s}")),
}
}
Loading