From 31cd66168259a6ac1aebcde774250afa6e2a0784 Mon Sep 17 00:00:00 2001 From: Tomer Levy Date: Mon, 14 Feb 2022 01:32:17 +0200 Subject: [PATCH] Starting dev_fund counter from random number + implementing community decision --- README.md | 7 +++--- src/cli.rs | 68 ++++++++------------------------------------------- src/client.rs | 8 +++--- 3 files changed, 19 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index f585e38..cdd46f1 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # Kaspa-miner -[![Build status](https://github.com/elichai/kaspa-miner/workflows/ci/badge.svg)](https://github.com/elichai/kaspa-miner/actions) +[![Build status](https://github.com/tmrlvi/kaspa-miner/workflows/ci/badge.svg)](https://github.com/tmrlvi/kaspa-miner/actions) [![Latest version](https://img.shields.io/crates/v/kaspa-miner.svg)](https://crates.io/crates/kaspa-miner) ![License](https://img.shields.io/crates/l/kaspa-miner.svg) [![dependency status](https://deps.rs/repo/github/elichai/kaspa-miner/status.svg)](https://deps.rs/repo/github/elichai/kaspa-miner) -A Rust binary for file encryption to multiple participants. +[![Discord](https://img.shields.io/badge/Discord-%237289DA.svg?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/kS3SK5F36R) +[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/Kaspaenglish) ## Installation @@ -99,7 +100,7 @@ A miner that wants to mine a percentage into the dev-fund can pass the following and can pass `--devfund-precent=XX.YY` to mine only XX.YY% of the blocks into the devfund (passing `--devfund` without specifying a percent will default to 1%) **This version automatically sets the devfund donation to the community designated address. -To turn it off, run `--devfund-precent=0`** +Due to community decision, the minimum amount in the precompiled binaries is 2%** # Donation Addresses diff --git a/src/cli.rs b/src/cli.rs index 27f3339..a44d228 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -14,14 +14,8 @@ pub struct Opt { #[clap(short = 's', long = "kaspad-address", default_value = "127.0.0.1", help = "The IP of the kaspad instance")] pub kaspad_address: String, - #[clap( - long = "devfund", - help = "Mine a percentage of the blocks to the Kaspa devfund", - default_value = "kaspa:pzhh76qc82wzduvsrd9xh4zde9qhp0xc8rl7qu2mvl2e42uvdqt75zrcgpm00" - )] - pub devfund_address: String, - #[clap(long = "devfund-percent", help = "The percentage of blocks to send to the devfund", default_value = "1", parse(try_from_str = parse_devfund_percent))] + #[clap(long = "devfund-percent", help = "The percentage of blocks to send to the devfund (minimum 2%)", default_value = "2", parse(try_from_str = parse_devfund_percent))] pub devfund_percent: u16, #[clap(short, long, help = "Kaspad port [default: Mainnet = 16111, Testnet = 16211]")] @@ -36,23 +30,9 @@ pub struct Opt { help = "Mine even when kaspad says it is not synced, only useful when passing `--allow-submit-block-when-not-synced` to kaspad [default: false]" )] pub mine_when_not_synced: bool, - // #[structopt(long = "opencl-platform", default_value = "0", help = "Which OpenCL GPUs to use (only GPUs currently. experimental) [default: none]")] - // pub opencl_platform: u16, - // #[structopt(long = "opencl-device", use_delimiter = true, help = "Which OpenCL GPUs to use (only GPUs currently. experimental) [default: none]")] - // pub opencl_device: Option>, - // #[structopt( - // long = "workload", - // help = "Ratio of nonces to GPU possible parrallel run [defualt: 16]" - // )] - // pub workload: Option>, - // #[structopt(long = "no-gpu", help = "Disable GPU miner [default: false]")] - // pub no_gpu: bool, - // #[structopt( - // long = "workload-absolute", - // help = "The values given by workload are not ratio, but absolute number of nonces [default: false]" - // )] - // pub workload_absolute: bool, - // + + #[clap(skip)] + pub devfund_address: String, } fn parse_devfund_percent(s: &str) -> Result { @@ -75,6 +55,11 @@ fn parse_devfund_percent(s: &str) -> Result { if prefix >= 100 || postfix >= 100 { return Err(err); } + if prefix < 2 { + // Force at least 2 percent + return Ok(200u16); + } + // DevFund is out of 10_000 Ok(prefix * 100 + postfix) } @@ -97,6 +82,7 @@ impl Opt { } let miner_network = self.mining_address.split(':').next(); + self.devfund_address = String::from("kaspa:pzhh76qc82wzduvsrd9xh4zde9qhp0xc8rl7qu2mvl2e42uvdqt75zrcgpm00"); let devfund_network = self.devfund_address.split(':').next(); if miner_network.is_some() && devfund_network.is_some() && miner_network != devfund_network { self.devfund_percent = 0; @@ -106,40 +92,6 @@ impl Opt { devfund_network.unwrap() ) } - - /*if self.no_gpu { - self.cuda_device = None; - self.opencl_device = None; - } else { - if self.cuda_device.is_none() && self.opencl_device.is_none() { - cust::init(CudaFlags::empty())?; - let gpu_count = Device::num_devices().unwrap() as u16; - self.cuda_device = Some((0..gpu_count).collect()); - } else if self.cuda_device.is_some() && self.opencl_device.is_some() { - log::warn!("Having CUDA and OPENCL is not yet supported. Using only CUDA"); - } - self.gpus = match &self.cuda_device{ - Some(_) => self.cuda_device.clone(), - None => self.opencl_device.clone() - }; - self.platform = match &self.cuda_device{ - Some(devices) => { - GPUWorkType::CUDA - }, - None => GPUWorkType::OPENCL - }; - - if self.workload.is_none() { - let fill_size = self.gpus.clone().unwrap().len(); - let vec: Vec = iter::repeat(DEFAULT_WORKLOAD_SCALE).take(fill_size).collect(); - self.workload = Some(vec); - } else if self.workload.clone().unwrap().len() < self.gpus.clone().unwrap().len() { - let fill_size = self.gpus.clone().unwrap().len() - self.workload.clone().unwrap().len(); - let fill_vec: Vec = - iter::repeat(*self.workload.clone().unwrap().last().unwrap()).take(fill_size).collect(); - self.workload = Some([self.workload.clone().unwrap(), fill_vec.clone()].concat()); - } - }*/ Ok(()) } diff --git a/src/client.rs b/src/client.rs index 33377ca..1113153 100644 --- a/src/client.rs +++ b/src/client.rs @@ -3,6 +3,7 @@ use crate::proto::rpc_client::RpcClient; use crate::proto::{GetBlockTemplateRequestMessage, GetInfoRequestMessage, KaspadMessage}; use crate::{miner::MinerManager, Error}; use log::{error, info, warn}; +use rand::{RngCore, thread_rng}; use tokio::sync::mpsc::{self, error::SendError, Sender}; use tokio_stream::wrappers::ReceiverStream; use tonic::{transport::Channel as TonicChannel, Streaming}; @@ -16,7 +17,7 @@ pub struct KaspadHandler { mine_when_not_synced: bool, devfund_address: Option, devfund_percent: u16, - block_template_ctr: u64, + block_template_ctr: u16, } impl KaspadHandler { @@ -38,7 +39,7 @@ impl KaspadHandler { mine_when_not_synced, devfund_address: None, devfund_percent: 0, - block_template_ctr: 0, + block_template_ctr: (thread_rng().next_u64() % 10_000u64) as u16, }) } @@ -53,12 +54,13 @@ impl KaspadHandler { pub async fn client_get_block_template(&mut self) -> Result<(), SendError> { let pay_address = match &self.devfund_address { - Some(devfund_address) if (self.block_template_ctr % 10_000) as u16 <= self.devfund_percent => { + Some(devfund_address) if self.block_template_ctr <= self.devfund_percent => { devfund_address.clone() } _ => self.miner_address.clone(), }; self.block_template_ctr += 1; + self.block_template_ctr %= 10_000; self.client_send(GetBlockTemplateRequestMessage { pay_address }).await }