|
| 1 | +use clap::Parser; |
| 2 | +use integration_tests_sv2::mining_device::{self, Secp256k1PublicKey}; |
| 3 | +use tracing::{info, Level}; |
| 4 | +use tracing_subscriber::fmt; |
| 5 | + |
| 6 | +#[derive(Parser, Debug)] |
| 7 | +#[command(version, about, long_about = None)] |
| 8 | +struct Args { |
| 9 | + #[arg( |
| 10 | + short, |
| 11 | + long, |
| 12 | + help = "Pool pub key, when left empty the pool certificate is not checked" |
| 13 | + )] |
| 14 | + pubkey_pool: Option<Secp256k1PublicKey>, |
| 15 | + #[arg( |
| 16 | + short, |
| 17 | + long, |
| 18 | + help = "Sometimes used by the pool to identify the device" |
| 19 | + )] |
| 20 | + id_device: Option<String>, |
| 21 | + #[arg( |
| 22 | + short, |
| 23 | + long, |
| 24 | + help = "Address of the pool in this format ip:port or domain:port" |
| 25 | + )] |
| 26 | + address_pool: String, |
| 27 | + #[arg( |
| 28 | + long, |
| 29 | + help = "This value is used to slow down the cpu miner, it represents the number of micro-seconds that are awaited between hashes", |
| 30 | + default_value = "0" |
| 31 | + )] |
| 32 | + handicap: u32, |
| 33 | + #[arg( |
| 34 | + long, |
| 35 | + help = "User id, used when a new channel is opened, it can be used by the pool to identify the miner" |
| 36 | + )] |
| 37 | + id_user: Option<String>, |
| 38 | + #[arg( |
| 39 | + long, |
| 40 | + help = "This floating point number is used to modify the advertised nominal hashrate when opening a channel with the upstream.\ |
| 41 | + \nIf 0.0 < nominal_hashrate_multiplier < 1.0, the CPU miner will advertise a nominal hashrate that is smaller than its real capacity.\ |
| 42 | + \nIf nominal_hashrate_multiplier > 1.0, the CPU miner will advertise a nominal hashrate that is bigger than its real capacity.\ |
| 43 | + \nIf empty, the CPU miner will simply advertise its real capacity." |
| 44 | + )] |
| 45 | + nominal_hashrate_multiplier: Option<f32>, |
| 46 | + #[arg( |
| 47 | + long, |
| 48 | + help = "Number of nonces to try per mining loop iteration when fast hashing is available (micro-batching)", |
| 49 | + default_value = "32" |
| 50 | + )] |
| 51 | + nonces_per_call: u32, |
| 52 | + #[arg( |
| 53 | + long, |
| 54 | + help = "Number of worker threads to use for mining. Defaults to logical CPUs minus one (leaves one core free)." |
| 55 | + )] |
| 56 | + cores: Option<u32>, |
| 57 | +} |
| 58 | + |
| 59 | +#[tokio::main(flavor = "current_thread")] |
| 60 | +async fn main() { |
| 61 | + let args = Args::parse(); |
| 62 | + fmt().with_max_level(Level::INFO).init(); |
| 63 | + info!("start"); |
| 64 | + |
| 65 | + mining_device::set_nonces_per_call(args.nonces_per_call); |
| 66 | + |
| 67 | + if let Some(n) = args.cores { |
| 68 | + mining_device::set_cores(n); |
| 69 | + } |
| 70 | + |
| 71 | + let used = mining_device::effective_worker_count(); |
| 72 | + let total = mining_device::total_logical_cpus(); |
| 73 | + info!( |
| 74 | + "Using {} worker threads out of {} logical CPUs", |
| 75 | + used, total |
| 76 | + ); |
| 77 | + |
| 78 | + mining_device::connect( |
| 79 | + args.address_pool, |
| 80 | + args.pubkey_pool, |
| 81 | + args.id_device, |
| 82 | + args.id_user, |
| 83 | + args.handicap, |
| 84 | + args.nominal_hashrate_multiplier, |
| 85 | + false, |
| 86 | + ) |
| 87 | + .await; |
| 88 | +} |
0 commit comments