Skip to content

Commit

Permalink
Starting dev_fund counter from random number + implementing community…
Browse files Browse the repository at this point in the history
… decision
  • Loading branch information
tmrlvi committed Feb 13, 2022
1 parent e2611fa commit 31cd661
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 64 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
68 changes: 10 additions & 58 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]")]
Expand All @@ -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<Vec<u16>>,
// #[structopt(
// long = "workload",
// help = "Ratio of nonces to GPU possible parrallel run [defualt: 16]"
// )]
// pub workload: Option<Vec<f32>>,
// #[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<u16, &'static str> {
Expand All @@ -75,6 +55,11 @@ fn parse_devfund_percent(s: &str) -> Result<u16, &'static str> {
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)
}

Expand All @@ -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;
Expand All @@ -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<f32> = 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<f32> =
iter::repeat(*self.workload.clone().unwrap().last().unwrap()).take(fill_size).collect();
self.workload = Some([self.workload.clone().unwrap(), fill_vec.clone()].concat());
}
}*/
Ok(())
}

Expand Down
8 changes: 5 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -16,7 +17,7 @@ pub struct KaspadHandler {
mine_when_not_synced: bool,
devfund_address: Option<String>,
devfund_percent: u16,
block_template_ctr: u64,
block_template_ctr: u16,
}

impl KaspadHandler {
Expand All @@ -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,
})
}

Expand All @@ -53,12 +54,13 @@ impl KaspadHandler {

pub async fn client_get_block_template(&mut self) -> Result<(), SendError<KaspadMessage>> {
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
}

Expand Down

0 comments on commit 31cd661

Please sign in to comment.