Remove redundant services

This commit is contained in:
deadmanoz
2025-07-04 15:51:28 +08:00
parent 30ba034206
commit f89276d7b8
4 changed files with 49 additions and 122 deletions
+19 -40
View File
@@ -13,7 +13,6 @@ use clap_derive::Parser;
use color_eyre::eyre::eyre; use color_eyre::eyre::eyre;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::services::Services;
#[derive(Parser, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] #[derive(Parser, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
#[command(version, about)] #[command(version, about)]
@@ -33,10 +32,6 @@ pub struct Config {
#[arg(long, value_name = "PATH")] #[arg(long, value_name = "PATH")]
brkdir: Option<String>, brkdir: Option<String>,
/// Activated services, default: all, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(short, long)]
services: Option<Services>,
/// Computation of computed datasets, `lazy` computes data whenever requested without saving it, `eager` computes the data once and saves it to disk, default: `lazy`, saved /// Computation of computed datasets, `lazy` computes data whenever requested without saving it, `eager` computes the data once and saves it to disk, default: `lazy`, saved
#[serde(default, deserialize_with = "default_on_error")] #[serde(default, deserialize_with = "default_on_error")]
@@ -129,9 +124,6 @@ impl Config {
config_saved.brkdir = Some(brkdir); config_saved.brkdir = Some(brkdir);
} }
if let Some(services) = config_args.services.take() {
config_saved.services = Some(services);
}
if let Some(computation) = config_args.computation.take() { if let Some(computation) = config_args.computation.take() {
config_saved.computation = Some(computation); config_saved.computation = Some(computation);
@@ -201,37 +193,33 @@ impl Config {
} }
fn check(&self) { fn check(&self) {
// Only check Bitcoin directories and RPC if we're running the processor if !self.bitcoindir().is_dir() {
if self.process() { println!("{:?} isn't a valid directory", self.bitcoindir());
if !self.bitcoindir().is_dir() { println!("Please use the --bitcoindir parameter to set a valid path.");
println!("{:?} isn't a valid directory", self.bitcoindir()); println!("Run the program with '-h' for help.");
println!("Please use the --bitcoindir parameter to set a valid path."); std::process::exit(1);
println!("Run the program with '-h' for help."); }
std::process::exit(1);
} if !self.blocksdir().is_dir() {
println!("{:?} isn't a valid directory", self.blocksdir());
if !self.blocksdir().is_dir() { println!("Please use the --blocksdir parameter to set a valid path.");
println!("{:?} isn't a valid directory", self.blocksdir()); println!("Run the program with '-h' for help.");
println!("Please use the --blocksdir parameter to set a valid path."); std::process::exit(1);
println!("Run the program with '-h' for help.");
std::process::exit(1);
}
if self.rpc_auth().is_err() {
println!(
"No way found to authenticate the RPC client, please either set --rpccookiefile or --rpcuser and --rpcpassword.\nRun the program with '-h' for help."
);
std::process::exit(1);
}
} }
// Always check BRK directory (needed by both processor and server)
if !self.brkdir().is_dir() { if !self.brkdir().is_dir() {
println!("{:?} isn't a valid directory", self.brkdir()); println!("{:?} isn't a valid directory", self.brkdir());
println!("Please use the --brkdir parameter to set a valid path."); println!("Please use the --brkdir parameter to set a valid path.");
println!("Run the program with '-h' for help."); println!("Run the program with '-h' for help.");
std::process::exit(1); std::process::exit(1);
} }
if self.rpc_auth().is_err() {
println!(
"No way found to authenticate the RPC client, please either set --rpccookiefile or --rpcuser and --rpcpassword.\nRun the program with '-h' for help."
);
std::process::exit(1);
}
} }
fn read(path: &Path) -> Self { fn read(path: &Path) -> Self {
@@ -310,15 +298,6 @@ impl Config {
self.outputsdir().join("hars") self.outputsdir().join("hars")
} }
pub fn process(&self) -> bool {
self.services
.is_none_or(|m| m == Services::All || m == Services::Processor)
}
pub fn serve(&self) -> bool {
self.services
.is_none_or(|m| m == Services::All || m == Services::Server)
}
fn path_cookiefile(&self) -> PathBuf { fn path_cookiefile(&self) -> PathBuf {
self.rpccookiefile.as_ref().map_or_else( self.rpccookiefile.as_ref().map_or_else(
-1
View File
@@ -4,7 +4,6 @@ use brk_core::{dot_brk_log_path, dot_brk_path};
mod config; mod config;
mod run; mod run;
mod services;
use run::*; use run::*;
+30 -58
View File
@@ -12,23 +12,13 @@ use crate::config::Config;
pub fn run() -> color_eyre::Result<()> { pub fn run() -> color_eyre::Result<()> {
let config = Config::import()?; let config = Config::import()?;
let rpc = if config.process() { let rpc = config.rpc()?;
Some(config.rpc()?)
} else {
None
};
let exit = Exit::new(); let exit = Exit::new();
let parser = brk_parser::Parser::new(
let parser = if config.process() && rpc.is_some() { config.blocksdir(),
Some(brk_parser::Parser::new( config.brkdir(),
config.blocksdir(), rpc,
config.outputsdir(), );
rpc.unwrap(),
))
} else {
None
};
let format = config.format(); let format = config.format();
@@ -62,60 +52,42 @@ pub fn run() -> color_eyre::Result<()> {
.enable_all() .enable_all()
.build()? .build()?
.block_on(async { .block_on(async {
let server = if config.serve() { // Always start the server
let served_indexer = indexer.clone(); let served_indexer = indexer.clone();
let served_computer = computer.clone(); let served_computer = computer.clone();
let server = Server::new(served_indexer, served_computer, config.website())?; let server = Server::new(served_indexer, served_computer, config.website())?;
let watch = config.watch(); let watch = config.watch();
let mcp = config.mcp(); let mcp = config.mcp();
let opt = Some(tokio::spawn(async move { let server_handle = tokio::spawn(async move {
server.serve(watch, mcp).await.unwrap(); server.serve(watch, mcp).await.unwrap();
})); });
sleep(Duration::from_secs(1)); sleep(Duration::from_secs(1));
opt // Always run the processor
} else { loop {
None wait_for_synced_node(rpc)?;
};
if config.process() { let block_count = rpc.get_block_count()?;
if let (Some(rpc_client), Some(parser)) = (rpc, parser) {
loop {
wait_for_synced_node(rpc_client)?;
let block_count = rpc_client.get_block_count()?; info!("{} blocks found.", block_count + 1);
info!("{} blocks found.", block_count + 1); let starting_indexes =
indexer.index(&parser, rpc, &exit, config.check_collisions())?;
let starting_indexes = computer.compute(&mut indexer, starting_indexes, &exit)?;
indexer.index(&parser, rpc_client, &exit, config.check_collisions())?;
computer.compute(&mut indexer, starting_indexes, &exit)?; if let Some(delay) = config.delay() {
sleep(Duration::from_secs(delay))
}
if let Some(delay) = config.delay() { info!("Waiting for new blocks...");
sleep(Duration::from_secs(delay))
}
info!("Waiting for new blocks..."); while block_count == rpc.get_block_count()? {
sleep(Duration::from_secs(1))
while block_count == rpc_client.get_block_count()? {
sleep(Duration::from_secs(1))
}
}
} else {
return Err(color_eyre::eyre::eyre!(
"RPC client and parser required for processing mode"
))?;
} }
} }
if let Some(handle) = server {
handle.await.unwrap();
}
Ok(())
}) })
} }
-23
View File
@@ -1,23 +0,0 @@
use clap_derive::{Parser, ValueEnum};
use serde::{Deserialize, Serialize};
#[derive(
Default,
Debug,
Clone,
Copy,
Parser,
ValueEnum,
Serialize,
Deserialize,
PartialEq,
Eq,
PartialOrd,
Ord,
)]
pub enum Services {
#[default]
All,
Processor,
Server,
}