Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve sv2 cpuminer #819

Merged
merged 6 commits into from
Apr 6, 2024
Merged

Improve sv2 cpuminer #819

merged 6 commits into from
Apr 6, 2024

Conversation

Fi3
Copy link
Collaborator

@Fi3 Fi3 commented Mar 28, 2024

Add a nicer user interface to the sv2 cpuminer with help messages. Add noise to the cpuminer.

This is the output of cargo run -- --help

Usage: mining-device [OPTIONS] --address-pool <ADDRESS_POOL>

Options:
  -p, --pubkey-pool <PUBKEY_POOL>    Pool pub key, when left empty the pool certificate is not checked
  -i, --id-device <ID_DEVICE>        Sometimes used by the pool to identify the device
  -a, --address-pool <ADDRESS_POOL>  Address of the pool in this format ip:port or domain:port
      --handicap <HANDICAP>          This value is used to slow down the cpu miner, it rapresents the number of micro-seconds that are awaited between one hashes, default is 0 [default: 0]
  -h, --help                         Print help
  -V, --version                      Print version

@plebhash
Copy link
Collaborator

I see this is using clap for CLI, while all other roles crates do not.
Was there any specific reason not to use clap there? Would it be desirable to use clap on roles implementations?

For context, see #813 and #814

@@ -143,7 +226,7 @@ pub struct Device {
fn open_channel() -> OpenStandardMiningChannel<'static> {
let user_identity = "ABC".to_string().try_into().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ABC could be made into a CLI arg?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep I will do

@@ -209,7 +308,7 @@ impl Device {

loop {
let mut incoming: StdFrame = receiver.recv().await.unwrap().try_into().unwrap();
let message_type = incoming.get_header().unwrap().msg_type();
let message_type = dbg!(incoming.get_header().unwrap().msg_type());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this dbg! is supposed to be here?

@lorbax
Copy link
Collaborator

lorbax commented Mar 30, 2024

I reviewed the code and LGTM.
This PR basically introduces two things: noise encrypted connections and command line arguments (with the aid of clap library). The first is easy to test, because it just works.
For testing the second, I launched the pool with local TP and I launched the mining_device (where the pool-pubkey is retrieved from pool's config)

cargo run -- --pubkey-pool 9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72 --address-pool 127.0.0.2:34254

I also tested the --address option, by launching the pool listening on a different address listen_address = "127.0.0.2:34254" and the mining device

 cargo run -- --pubkey-pool 9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72 --address-pool 127.0.0.2:34254

which works as expected.
Similarly, all the other options works (-V and --help), in particular --id-user

2024-03-30T18:04:59.209254Z  INFO roles_logic_sv2::handlers::mining: Received OpenStandardMiningChannel from: pippo with id: 10

@Sjors
Copy link
Collaborator

Sjors commented Apr 2, 2024

Thanks for opening this! Added to my test list...

@Fi3 Fi3 force-pushed the ImproveCpuMiner branch 2 times, most recently from ec44dae to b570b22 Compare April 5, 2024 09:49
fi3 added 3 commits April 5, 2024 11:58
Add a nicer user interface to the sv2 cpuminer with help messages.
Add noise to the cpuminer.
@Sjors
Copy link
Collaborator

Sjors commented Apr 5, 2024

I was able to mine a block!

Followup suggestions (feel free to merge this first, if it's holding back other things):

Use all CPU threads (currently only uses 1).

Rather than --handicap I would prefer being able to set a difficulty target, like the --nbits argument for Bitcoin Core's signet miner: https://github.com/bitcoin/bitcoin/blob/master/contrib/signet/README.md (this even messes with the timestamps to achieve the desired difficulty adjustments)

Perhaps simpler:

  • a way to set the max hash rate
  • optionally have it wait for x (default 10) minutes before mining the next block

However that can wait for a followup.

let id: u32 = 10;
println!("MINING DEVICE: send open channel with request id {}", id);
info!("Misuring pc hashrate");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Measuring

@Sjors
Copy link
Collaborator

Sjors commented Apr 5, 2024

For the second block (on a custom signet) I'm getting errors:

2024-04-05T11:02:30.047785Z  INFO roles_logic_sv2::handlers::template_distribution: Received NewTemplate with id: 2, is future: true
2024-04-05T11:02:30.047829Z  INFO roles_logic_sv2::handlers::template_distribution: Received SetNewPrevHash for template: 2
2024-04-05T11:05:21.072403Z ERROR roles_logic_sv2::channel_logic::channel_factory: Share does not meet any target: Standard((SubmitSharesStandard { channel_id: 1, sequence_number: 2, job_id: 2, nonce: 360646192, ntime: 1712315010, version: 536870912 }, 0))
2024-04-05T11:08:48.166951Z ERROR roles_logic_sv2::channel_logic::channel_factory: Share does not meet any target: Standard((SubmitSharesStandard { channel_id: 1, sequence_number: 3, job_id: 2, nonce: 789285428, ntime: 1712315010, version: 536870912 }, 0))

@Fi3 Fi3 merged commit 8092742 into stratum-mining:dev Apr 6, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants