fix: logs handling
This commit is contained in:
@@ -24,7 +24,7 @@ services:
|
|||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
environment:
|
environment:
|
||||||
RUST_LOG: "protocol_testing=info"
|
RUST_LOG: "${RUST_LOG:-protocol_testing=info}"
|
||||||
DATABASE_URL: postgres://postgres:mypassword@db:5432/tycho_indexer_0
|
DATABASE_URL: postgres://postgres:mypassword@db:5432/tycho_indexer_0
|
||||||
RPC_URL: "${RPC_URL}"
|
RPC_URL: "${RPC_URL}"
|
||||||
SUBSTREAMS_API_TOKEN: "${SUBSTREAMS_API_TOKEN}"
|
SUBSTREAMS_API_TOKEN: "${SUBSTREAMS_API_TOKEN}"
|
||||||
|
|||||||
@@ -32,10 +32,6 @@ struct Args {
|
|||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
match_test: Option<String>,
|
match_test: Option<String>,
|
||||||
|
|
||||||
/// Enable tycho logs
|
|
||||||
#[arg(long, default_value_t = false)]
|
|
||||||
tycho_logs: bool,
|
|
||||||
|
|
||||||
/// Postgres database URL for the Tycho indexer
|
/// Postgres database URL for the Tycho indexer
|
||||||
#[arg(long, default_value = "postgres://postgres:mypassword@localhost:5431/tycho_indexer_0")]
|
#[arg(long, default_value = "postgres://postgres:mypassword@localhost:5431/tycho_indexer_0")]
|
||||||
db_url: String,
|
db_url: String,
|
||||||
@@ -94,7 +90,6 @@ fn main() -> miette::Result<()> {
|
|||||||
args.root_path()?,
|
args.root_path()?,
|
||||||
args.package,
|
args.package,
|
||||||
args.match_test,
|
args.match_test,
|
||||||
args.tycho_logs,
|
|
||||||
args.db_url,
|
args.db_url,
|
||||||
args.vm_traces,
|
args.vm_traces,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub struct TestRunner {
|
pub struct TestRunner {
|
||||||
tycho_logs: bool,
|
|
||||||
db_url: String,
|
db_url: String,
|
||||||
vm_traces: bool,
|
vm_traces: bool,
|
||||||
substreams_path: PathBuf,
|
substreams_path: PathBuf,
|
||||||
@@ -55,7 +54,6 @@ impl TestRunner {
|
|||||||
root_path: PathBuf,
|
root_path: PathBuf,
|
||||||
protocol: String,
|
protocol: String,
|
||||||
match_test: Option<String>,
|
match_test: Option<String>,
|
||||||
tycho_logs: bool,
|
|
||||||
db_url: String,
|
db_url: String,
|
||||||
vm_traces: bool,
|
vm_traces: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -65,14 +63,7 @@ impl TestRunner {
|
|||||||
let evm_path = root_path.join("evm");
|
let evm_path = root_path.join("evm");
|
||||||
let adapter_contract_builder =
|
let adapter_contract_builder =
|
||||||
AdapterContractBuilder::new(evm_path.to_string_lossy().to_string());
|
AdapterContractBuilder::new(evm_path.to_string_lossy().to_string());
|
||||||
Self {
|
Self { db_url, vm_traces, substreams_path, adapter_contract_builder, match_test }
|
||||||
tycho_logs,
|
|
||||||
db_url,
|
|
||||||
vm_traces,
|
|
||||||
substreams_path,
|
|
||||||
adapter_contract_builder,
|
|
||||||
match_test,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_tests(&self) -> miette::Result<()> {
|
pub fn run_tests(&self) -> miette::Result<()> {
|
||||||
@@ -191,8 +182,7 @@ impl TestRunner {
|
|||||||
let spkg_path =
|
let spkg_path =
|
||||||
build_spkg(&substreams_yaml_path, test.start_block).wrap_err("Failed to build spkg")?;
|
build_spkg(&substreams_yaml_path, test.start_block).wrap_err("Failed to build spkg")?;
|
||||||
|
|
||||||
let tycho_runner =
|
let tycho_runner = TychoRunner::new(self.db_url.clone(), initialized_accounts);
|
||||||
TychoRunner::new(self.db_url.clone(), initialized_accounts, self.tycho_logs);
|
|
||||||
|
|
||||||
tycho_runner
|
tycho_runner
|
||||||
.run_tycho(
|
.run_tycho(
|
||||||
|
|||||||
@@ -6,23 +6,21 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use dotenv::dotenv;
|
|
||||||
use miette::{IntoDiagnostic, WrapErr};
|
use miette::{IntoDiagnostic, WrapErr};
|
||||||
use tracing::debug;
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::config::ProtocolComponentWithTestConfig;
|
use crate::config::ProtocolComponentWithTestConfig;
|
||||||
|
|
||||||
pub struct TychoRunner {
|
pub struct TychoRunner {
|
||||||
db_url: String,
|
db_url: String,
|
||||||
initialized_accounts: Vec<String>,
|
initialized_accounts: Vec<String>,
|
||||||
with_binary_logs: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Currently Tycho-Indexer cannot be run as a lib. We need to expose the entrypoints to allow
|
// TODO: Currently Tycho-Indexer cannot be run as a lib. We need to expose the entrypoints to allow
|
||||||
// running it as a lib
|
// running it as a lib
|
||||||
impl TychoRunner {
|
impl TychoRunner {
|
||||||
pub fn new(db_url: String, initialized_accounts: Vec<String>, with_binary_logs: bool) -> Self {
|
pub fn new(db_url: String, initialized_accounts: Vec<String>) -> Self {
|
||||||
Self { db_url, initialized_accounts, with_binary_logs }
|
Self { db_url, initialized_accounts }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_tycho(
|
pub fn run_tycho(
|
||||||
@@ -33,8 +31,7 @@ impl TychoRunner {
|
|||||||
protocol_type_names: &[String],
|
protocol_type_names: &[String],
|
||||||
protocol_system: &str,
|
protocol_system: &str,
|
||||||
) -> miette::Result<()> {
|
) -> miette::Result<()> {
|
||||||
// Expects a .env present in the same folder as package root (where Cargo.toml is)
|
info!("Running Tycho indexer from block {start_block} to {end_block}...");
|
||||||
dotenv().ok();
|
|
||||||
|
|
||||||
let mut cmd = Command::new("tycho-indexer");
|
let mut cmd = Command::new("tycho-indexer");
|
||||||
cmd.env("RUST_LOG", std::env::var("RUST_LOG").unwrap_or("tycho_indexer=info".to_string()))
|
cmd.env("RUST_LOG", std::env::var("RUST_LOG").unwrap_or("tycho_indexer=info".to_string()))
|
||||||
@@ -79,9 +76,7 @@ impl TychoRunner {
|
|||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.wrap_err("Error running Tycho indexer")?;
|
.wrap_err("Error running Tycho indexer")?;
|
||||||
|
|
||||||
if self.with_binary_logs {
|
Self::handle_process_output(&mut process);
|
||||||
Self::handle_process_output(&mut process);
|
|
||||||
}
|
|
||||||
|
|
||||||
let status = process
|
let status = process
|
||||||
.wait()
|
.wait()
|
||||||
@@ -110,7 +105,6 @@ impl TychoRunner {
|
|||||||
{
|
{
|
||||||
let (tx, rx): (Sender<bool>, Receiver<bool>) = mpsc::channel();
|
let (tx, rx): (Sender<bool>, Receiver<bool>) = mpsc::channel();
|
||||||
let db_url = self.db_url.clone();
|
let db_url = self.db_url.clone();
|
||||||
let with_binary_logs = self.with_binary_logs;
|
|
||||||
|
|
||||||
// Start the RPC server in a separate thread
|
// Start the RPC server in a separate thread
|
||||||
let rpc_thread = thread::spawn(move || {
|
let rpc_thread = thread::spawn(move || {
|
||||||
@@ -126,9 +120,7 @@ impl TychoRunner {
|
|||||||
.spawn()
|
.spawn()
|
||||||
.expect("Failed to start RPC server");
|
.expect("Failed to start RPC server");
|
||||||
|
|
||||||
if with_binary_logs {
|
Self::handle_process_output(&mut cmd);
|
||||||
Self::handle_process_output(&mut cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
match rx.recv() {
|
match rx.recv() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ pub fn build_spkg(yaml_file_path: &PathBuf, initial_block: u64) -> miette::Resul
|
|||||||
// Restore the original YAML from backup
|
// Restore the original YAML from backup
|
||||||
fs::copy(&backup_file_path, yaml_file_path).into_diagnostic()?;
|
fs::copy(&backup_file_path, yaml_file_path).into_diagnostic()?;
|
||||||
fs::remove_file(&backup_file_path).into_diagnostic()?;
|
fs::remove_file(&backup_file_path).into_diagnostic()?;
|
||||||
|
info!("Spkg built successfully: {}", spkg_name);
|
||||||
|
|
||||||
Ok(spkg_name)
|
Ok(spkg_name)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user