Skip to content

Commit

Permalink
start demand branch
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3 authored and UnidenifiedUser committed Apr 13, 2024
1 parent e3f0bac commit dd4a907
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 1,421 deletions.
2 changes: 1 addition & 1 deletion protocols/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 41 additions & 34 deletions roles/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions roles/jd-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ tracing-subscriber = { version = "0.3" }
error_handling = { version = "1.0.0", path = "../../utils/error-handling" }
nohash-hasher = "0.2.0"
key-utils = { version = "^1.0.0", path = "../../utils/key-utils" }
dotenv = "0.15.0"
5 changes: 0 additions & 5 deletions roles/jd-client/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ impl Args {
pub fn from_args() -> Result<Self, String> {
let cli_args = std::env::args();

if cli_args.len() == 1 {
println!("Using default config path: {}", Self::DEFAULT_CONFIG_PATH);
println!("{}\n", Self::HELP_MSG);
}

let config_path = cli_args
.scan(ArgsState::Next, |state, item| {
match std::mem::replace(state, ArgsState::Done) {
Expand Down
1 change: 1 addition & 0 deletions roles/jd-client/src/lib/job_declarator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl JobDeclarator {
) -> Result<Arc<Mutex<Self>>, Error<'static>> {
let stream = tokio::net::TcpStream::connect(address).await?;
let initiator = Initiator::from_raw_k(authority_public_key)?;
let initiator = Initiator::new(None);
let (mut receiver, mut sender, _, _) =
Connection::new(stream, HandshakeRole::Initiator(initiator))
.await
Expand Down
6 changes: 5 additions & 1 deletion roles/jd-client/src/lib/job_declarator/setup_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ impl SetupConnectionHandler {
let vendor = String::new().try_into().unwrap();
let hardware_version = String::new().try_into().unwrap();
let firmware = String::new().try_into().unwrap();
let device_id = String::new().try_into().unwrap();
let address = std::env::var("ADDRESS").unwrap();
let device_id = format!("device_id::SOLO::{}", address)
.to_string()
.try_into()
.unwrap();
let mut setup_connection = SetupConnection {
protocol: Protocol::JobDeclarationProtocol,
min_version: 2,
Expand Down
57 changes: 42 additions & 15 deletions roles/jd-client/src/lib/proxy_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use roles_logic_sv2::{errors::Error, utils::CoinbaseOutput as CoinbaseOutput_};
use serde::Deserialize;
use std::time::Duration;
use stratum_common::bitcoin::TxOut;
use stratum_common::bitcoin::Address;
use std::str::FromStr;

#[derive(Debug, Deserialize, Clone)]
pub struct CoinbaseOutput {
Expand Down Expand Up @@ -41,10 +43,42 @@ pub struct ProxyConfig {
pub upstreams: Vec<Upstream>,
#[serde(deserialize_with = "duration_from_toml")]
pub timeout: Duration,
pub coinbase_outputs: Vec<CoinbaseOutput>,
pub test_only_do_not_send_solution_to_tp: Option<bool>,
}

impl Default for ProxyConfig {
fn default() -> Self {
let downstream_address = std::env::var("LISTEN_ON").unwrap_or_else(|_| "127.0.0.1".to_string());
let address = std::env::var("ADDRESS").unwrap_or("".to_string());
let mut pool_signature = "DEMANDsv2".to_string();
let pool_signature = pool_signature + &address;
Self {
downstream_address,
downstream_port: 34265,
max_supported_version: 2,
min_supported_version: 2,
min_extranonce2_size: 8,
withhold: false,
authority_public_key: "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72".to_string().try_into().unwrap(),
authority_secret_key: "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n".to_string().try_into().unwrap(),
cert_validity_sec: 3600,
tp_address: "127.0.0.1:8442".to_string(),
tp_authority_public_key: None,
retry: 10,
upstreams: vec![
Upstream {
authority_pubkey: "9bQHWXsQ2J9TRFTaxRh3KjoxdyLRfWVEy25YHtKF8y8gotLoCZZ".to_string().try_into().unwrap(),
pool_address: "mining.dmnd.work:2000".to_string(),
jd_address: "mining.dmnd.work:2000".to_string(),
pool_signature,
},
],
timeout: Duration::from_secs(1),
test_only_do_not_send_solution_to_tp: None,
}
}
}

#[derive(Debug, Deserialize, Clone)]
pub struct Upstream {
pub authority_pubkey: Secp256k1PublicKey,
Expand Down Expand Up @@ -82,18 +116,11 @@ where
}
}

pub fn get_coinbase_output(config: &ProxyConfig) -> Result<Vec<TxOut>, Error> {
let mut result = Vec::new();
for coinbase_output_pool in &config.coinbase_outputs {
let coinbase_output: CoinbaseOutput_ = coinbase_output_pool.try_into()?;
let output_script = coinbase_output.try_into()?;
result.push(TxOut {
value: 0,
script_pubkey: output_script,
});
}
match result.is_empty() {
true => Err(Error::EmptyCoinbaseOutputs),
_ => Ok(result),
}
pub fn get_coinbase_output(address: &str) -> Result<Vec<TxOut>, Error> {
let address = Address::from_str(address).unwrap_or_else(|_| panic!("Invalid address: {}", address));
let script = address.script_pubkey();
Ok(vec![TxOut {
value: 0,
script_pubkey: script,
}])
}
Loading

0 comments on commit dd4a907

Please sign in to comment.