Skip to content

Commit

Permalink
Use modified translator config on start
Browse files Browse the repository at this point in the history
  • Loading branch information
coa-telos committed Sep 18, 2024
1 parent 41e10f9 commit 7c7ec5c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
17 changes: 10 additions & 7 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub struct ConsensusClient {
pub db: Database,
shutdown_tx: mpsc::Sender<()>,
shutdown_rx: mpsc::Receiver<()>,
lib: Option<data::Block>,
}

impl ConsensusClient {
Expand All @@ -82,6 +83,7 @@ impl ConsensusClient {
db,
shutdown_tx,
shutdown_rx,
lib: None,
})
}

Expand Down Expand Up @@ -114,11 +116,7 @@ impl ConsensusClient {
.checked_sub(self.config.evm_start_block)
}

pub async fn run(
mut self,
mut rx: mpsc::Receiver<TelosEVMBlock>,
mut lib: Option<data::Block>,
) -> Result<(), Error> {
pub async fn run(mut self, mut rx: mpsc::Receiver<TelosEVMBlock>) -> Result<(), Error> {
let mut batch = vec![];
loop {
let message = tokio::select! {
Expand Down Expand Up @@ -156,8 +154,13 @@ impl ConsensusClient {
debug!("Block {} delete from the database", latest_start);
}

if lib.as_ref().map(|lib| lib.number < lib_num).unwrap_or(true) {
lib = Some(From::from(Lib(&block)));
if self
.lib
.as_ref()
.map(|lib| lib.number < lib_num)
.unwrap_or(true)
{
self.lib = Some(From::from(Lib(&block)));
self.db.put_lib(From::from(Lib(&block)))?;
debug!("LIB {} put in the database", block.lib_num);
}
Expand Down
17 changes: 10 additions & 7 deletions client/src/main_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::cmp;
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;
Expand All @@ -12,18 +11,22 @@ use tracing::level_filters::LevelFilter;
use tracing::{info, warn};

pub async fn run_client(args: CliArgs, config: AppConfig) -> Result<Shutdown, Error> {
let (client, lib) = build_consensus_client(&args, config.clone()).await?;
let client = build_consensus_client(&args, config).await?;
let client_shutdown = client.shutdown_handle();
let translator = Translator::new((&config).into());
let translator = Translator::new((&client.config).into());

let (block_sender, block_receiver) = mpsc::channel::<TelosEVMBlock>(1000);

info!("Telos consensus client starting, awaiting result...");
let client_handle = tokio::spawn(client.run(block_receiver, lib));
let client_handle = tokio::spawn(client.run(block_receiver));

let translator_shutdown = translator.shutdown_handle();

info!("Telos translator client launching, awaiting result...");
info!(
evm_start_block = translator.config.evm_start_block,
evm_stop_block = ?translator.config.evm_stop_block,
"Telos translator client launching, awaiting result...",
);
let translator_handle = tokio::spawn(translator.launch(Some(block_sender)));

// Run the client and handle the result
Expand All @@ -50,7 +53,7 @@ pub async fn run_client(args: CliArgs, config: AppConfig) -> Result<Shutdown, Er
pub async fn build_consensus_client(
args: &CliArgs,
config: AppConfig,
) -> Result<(ConsensusClient, Option<Block>), Error> {
) -> Result<ConsensusClient, Error> {
let mut client = ConsensusClient::new(args, config).await.map_err(|e| {
warn!("Consensus client creation failed: {}", e);
warn!("Retrying...");
Expand Down Expand Up @@ -98,7 +101,7 @@ pub async fn build_consensus_client(
return Err(Error::RangeAboveMaximum(sync_range));
}
}
Ok((client, lib))
Ok(client)
}

pub fn parse_log_level(s: &str) -> eyre::Result<LevelFilter> {
Expand Down
2 changes: 1 addition & 1 deletion client/tests/ship_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ async fn evm_deploy() {
let translator = Translator::new((&config.clone()).into());
let translator_shutdown = translator.shutdown_handle();

let client_handle = tokio::spawn(client_under_test.run(rx, None));
let client_handle = tokio::spawn(client_under_test.run(rx));
let translator_handle = tokio::spawn(translator.launch(Some(tx)));
client_handle.await.unwrap().unwrap();

Expand Down
2 changes: 1 addition & 1 deletion translator/src/translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct TranslatorConfig {
}

pub struct Translator {
config: TranslatorConfig,
pub config: TranslatorConfig,
shutdown_tx: mpsc::Sender<()>,
shutdown_rx: mpsc::Receiver<()>,
}
Expand Down

0 comments on commit 7c7ec5c

Please sign in to comment.