add cli args to RPC scanning binary

This commit is contained in:
Boog900 2023-12-08 15:36:45 +00:00
parent 2c4cc1fb93
commit 92652b26a2
No known key found for this signature in database
GPG key ID: 5401367FB7302004
4 changed files with 76 additions and 39 deletions

View file

@ -15,14 +15,12 @@ members = [
]
[profile.release]
panic = 'abort'
lto = true # Build with LTO
strip = "none" # Keep panic stack traces
codegen-units = 1 # Optimize for binary speed over compile times
opt-level = 3
[profile.dev]
panic = 'abort'
lto = false
strip = "none"
# Not much slower compile times than opt-level 0, but much faster code.

View file

@ -22,7 +22,8 @@ binaries = [
"dep:monero-epee-bin-serde",
"dep:monero-wire",
"dep:bincode",
"dep:dirs"
"dep:dirs",
"dep:clap"
]
[dependencies]
@ -56,6 +57,7 @@ serde = {version = "1", optional = true, features = ["derive"]}
tracing-subscriber = {version = "0.3", optional = true}
bincode = {version = "2.0.0-rc.3", optional = true}
dirs = {version="5.0", optional = true}
clap = { version = "4.4.8", optional = true, features = ["derive"] }
# here to help cargo to pick a version - remove me
syn = "2.0.37"

View file

@ -2,6 +2,7 @@
use std::{ops::Range, path::PathBuf, sync::Arc};
use clap::Parser;
use futures::{
channel::{mpsc, oneshot},
SinkExt, StreamExt,
@ -230,48 +231,84 @@ where
Ok(())
}
#[derive(Parser)]
struct Args {
/// The log level, valid values:
/// "off", "error", "warn", "info", "debug", "trace", or a number 0-5.
#[arg(short, long, default_value = "info")]
log_level: LevelFilter,
/// The network we should scan, valid values:
/// "mainnet", "testnet", "stagenet".
#[arg(short, long, default_value = "mainnet")]
network: String,
/// A list of RPC nodes we should use.
/// Example: http://xmr-node.cakewallet.com:18081
#[arg(long)]
rpc_nodes: Vec<String>,
/// Stops the scanner from including the default list of nodes, this is not
/// recommended unless you have sufficient self defined nodes with `rpc_nodes`
#[arg(long)]
dont_use_default_nodes: bool,
/// The directory/ folder to save the scanning cache in.
/// This will default to your user cache directory.
#[arg(long)]
cache_dir: Option<PathBuf>,
}
#[tokio::main]
async fn main() {
// TODO: take this in as config options:
// - nodes to connect to
// - block batch size (not header)
// - network
// - tracing level
let args = Args::parse();
if args.dont_use_default_nodes & args.rpc_nodes.is_empty() {
panic!("Can't run scanner with no RPC nodes, see `--help` ")
}
tracing_subscriber::fmt()
.with_max_level(LevelFilter::INFO)
.with_max_level(args.log_level)
.init();
let network = Network::Mainnet;
let network = match args.network.as_str() {
"mainnet" => Network::Mainnet,
_ => panic!("Invalid network, scanner currently only supports mainnet"),
};
let mut file_for_cache = dirs::cache_dir().unwrap();
let mut file_for_cache = match args.cache_dir {
Some(dir) => dir,
None => dirs::cache_dir().unwrap(),
};
file_for_cache.push("cuprate_rpc_scanning_cache.bin");
let urls = vec![
"http://xmr-node.cakewallet.com:18081".to_string(),
"https://node.sethforprivacy.com".to_string(),
"http://nodex.monerujo.io:18081".to_string(),
"http://nodes.hashvault.pro:18081".to_string(),
"http://node.c3pool.com:18081".to_string(),
"http://node.trocador.app:18089".to_string(),
"http://xmr.lukas.services:18089".to_string(),
"http://xmr-node-eu.cakewallet.com:18081".to_string(),
"http://38.105.209.54:18089".to_string(),
"http://68.118.241.70:18089".to_string(),
"http://145.239.97.211:18089".to_string(),
//
"http://xmr-node.cakewallet.com:18081".to_string(),
"https://node.sethforprivacy.com".to_string(),
"http://nodex.monerujo.io:18081".to_string(),
"http://nodes.hashvault.pro:18081".to_string(),
"http://node.c3pool.com:18081".to_string(),
"http://node.trocador.app:18089".to_string(),
"http://xmr.lukas.services:18089".to_string(),
"http://xmr-node-eu.cakewallet.com:18081".to_string(),
"http://38.105.209.54:18089".to_string(),
"http://68.118.241.70:18089".to_string(),
"http://145.239.97.211:18089".to_string(),
];
let mut urls = if args.dont_use_default_nodes {
vec![]
} else {
vec![
"http://xmr-node.cakewallet.com:18081".to_string(),
"https://node.sethforprivacy.com".to_string(),
"http://nodex.monerujo.io:18081".to_string(),
"http://nodes.hashvault.pro:18081".to_string(),
"http://node.c3pool.com:18081".to_string(),
"http://node.trocador.app:18089".to_string(),
"http://xmr.lukas.services:18089".to_string(),
"http://xmr-node-eu.cakewallet.com:18081".to_string(),
"http://38.105.209.54:18089".to_string(),
"http://68.118.241.70:18089".to_string(),
"http://145.239.97.211:18089".to_string(),
//
"http://xmr-node.cakewallet.com:18081".to_string(),
"https://node.sethforprivacy.com".to_string(),
"http://nodex.monerujo.io:18081".to_string(),
"http://nodes.hashvault.pro:18081".to_string(),
"http://node.c3pool.com:18081".to_string(),
"http://node.trocador.app:18089".to_string(),
"http://xmr.lukas.services:18089".to_string(),
"http://xmr-node-eu.cakewallet.com:18081".to_string(),
"http://38.105.209.54:18089".to_string(),
"http://68.118.241.70:18089".to_string(),
"http://145.239.97.211:18089".to_string(),
]
};
urls.extend(args.rpc_nodes.into_iter());
let rpc_config = RpcConfig::new(MAX_BLOCKS_IN_RANGE, MAX_BLOCKS_HEADERS_IN_RANGE);
let rpc_config = Arc::new(std::sync::RwLock::new(rpc_config));

View file

@ -130,7 +130,7 @@ where
fn call(&mut self, req: DatabaseRequest) -> Self::Future {
let this = self.rpcs.clone();
let config_mutex = self.config.clone();
let config = config_mutex.read().unwrap();
let config = config_mutex.clone();
let cache = self.cache.clone();
@ -166,7 +166,7 @@ where
DatabaseRequest::BlockBatchInRange,
DatabaseResponse::BlockBatchInRange,
resp_to_ret,
config.max_blocks_per_node,
config.read().unwrap().max_blocks_per_node,
)
.boxed()
}
@ -183,7 +183,7 @@ where
DatabaseRequest::BlockExtendedHeaderInRange,
DatabaseResponse::BlockExtendedHeaderInRange,
resp_to_ret,
config.max_block_headers_per_node,
config.read().unwrap().max_block_headers_per_node,
)
.boxed()
}