Skip to content

Commit d3467b4

Browse files
authored
Merge pull request #408 from plebhash/2026-04-04-reintroduce-mining-device-bin
reintroduce `mining_device` bin
2 parents 0994512 + 59b543c commit d3467b4

4 files changed

Lines changed: 116 additions & 0 deletions

File tree

integration-tests/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ tokio-util = { version = "0.7", default-features = false }
2626
tracing = { version = "0.1.41", default-features = false }
2727
tracing-subscriber = { version = "0.3.19", default-features = false }
2828
hex = "0.4.3"
29+
clap = { version = "^4.5.4", features = ["derive"] }
2930

3031
# Direct dependencies kept only for the embedded `mining_device` module.
3132
# Remove this block when removing:
@@ -48,6 +49,11 @@ num_cpus = "1"
4849
[lib]
4950
path = "lib/mod.rs"
5051

52+
# Binary target preserved from the former standalone `mining_device` crate.
53+
[[bin]]
54+
name = "mining_device"
55+
path = "bin/mining_device.rs"
56+
5157
# Bench targets preserved from the former standalone `mining_device` crate.
5258
# Remove these entries when the embedded `mining_device` module is deprecated.
5359
[[bench]]

integration-tests/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ Note: during the execution of the tests, the `template-provider` directory holds
3333
binaries (Bitcoin Core and sv2-tp), while test data directories are created in the system temp
3434
directory.
3535

36+
## Standalone `mining_device` Binary
37+
38+
The embedded `integration_tests_sv2::mining_device` module also exposes a standalone executable
39+
binary again.
40+
41+
To build it:
42+
43+
```bash
44+
cargo build --manifest-path=integration-tests/Cargo.toml --release --bin mining_device
45+
```
46+
47+
The executable will be available at `integration-tests/target/release/mining_device`.
48+
49+
To run it directly through Cargo:
50+
51+
```bash
52+
cargo run --manifest-path=integration-tests/Cargo.toml --release --bin mining_device -- \
53+
--address-pool 127.0.0.1:3333 \
54+
--id-device test
55+
```
56+
3657
## Writing Custom Integration Tests
3758

3859
- To write your own integration tests using this library, you can install the library as follows:
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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

Comments
 (0)