Skip to content

Commit

Permalink
Add possibility to define more then one upstream in the JDC
Browse files Browse the repository at this point in the history
  • Loading branch information
UnidenifiedUser committed Sep 19, 2023
1 parent 4acc96b commit 241693a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 38 deletions.
28 changes: 17 additions & 11 deletions roles/jd-client/proxy-config-example.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Local SRI Pool Upstream Connection
upstream_address = "127.0.0.1"
upstream_port = 34254
upstream_authority_pubkey = "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL"

# Local Mining Device Downstream Connection
downstream_address = "0.0.0.0"
downstream_port = 34265

Expand All @@ -18,16 +12,28 @@ min_supported_version = 2
min_extranonce2_size = 8

# Withhold
withhold = false
withhold = true

# Auth keys for open encrypted connection downstream
authority_public_key = "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL"
authority_secret_key = "2Z1FZug7mZNyM63ggkm37r4oKQ29khLjAvEx43rGkFN47RcJ2t"
authority_public_key = "3VANfft6ei6jQq1At7d8nmiZzVhBFS4CiQujdgim1ign"
authority_secret_key = "7qbpUjScc865jyX2kiB4NVJANoC7GA7TAJupdzXWkc62"
cert_validity_sec = 3600

# How many time the JDC try to reinitialize itself after a failure
retry = 10

[jd_config]
jd_address = "127.0.0.1:34264"
#tp_address = "127.0.0.1:8442"
# hosted testnet TP
# tp_address = "89.116.25.191:8442"
# hosted regtest TP
tp_address = "75.119.150.111:8442"

[[upstreams]]
authority_pubkey = "3VANfft6ei6jQq1At7d8nmiZzVhBFS4CiQujdgim1ign"
pool_address = "127.0.0.1:34254"
jd_address = "127.0.0.1:34264"

[[upstreams]]
authority_pubkey = "3VANfft6ei6jQq1At7d8nmiZzVhBFS4CiQujdgim1ign"
pool_address = "127.0.0.1:34254"
jd_address = "127.0.0.1:34264"
26 changes: 16 additions & 10 deletions roles/jd-client/proxy-config.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Local SRI Pool Upstream Connection
upstream_address = "127.0.0.1"
upstream_port = 34254
upstream_authority_pubkey = "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL"

# Local Mining Device Downstream Connection
downstream_address = "0.0.0.0"
downstream_port = 34265

Expand All @@ -21,13 +15,25 @@ min_extranonce2_size = 8
withhold = true

# Auth keys for open encrypted connection downstream
authority_public_key = "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL"
authority_secret_key = "2Z1FZug7mZNyM63ggkm37r4oKQ29khLjAvEx43rGkFN47RcJ2t"
authority_public_key = "3VANfft6ei6jQq1At7d8nmiZzVhBFS4CiQujdgim1ign"
authority_secret_key = "7qbpUjScc865jyX2kiB4NVJANoC7GA7TAJupdzXWkc62"
cert_validity_sec = 3600

# How many time the JDC try to reinitialize itself after a failure
retry = 10

[jd_config]
#tp_address = "127.0.0.1:8442"
# hosted testnet TP
# tp_address = "89.116.25.191:8442"
# hosted regtest TP
tp_address = "75.119.150.111:8442"

[[upstreams]]
authority_pubkey = "3VANfft6ei6jQq1At7d8nmiZzVhBFS4CiQujdgim1ign"
pool_address = "127.0.0.1:34254"
jd_address = "127.0.0.1:34264"

[[upstreams]]
authority_pubkey = "3VANfft6ei6jQq1At7d8nmiZzVhBFS4CiQujdgim1ign"
pool_address = "127.0.0.1:34254"
jd_address = "127.0.0.1:34264"
tp_address = "127.0.0.1:8442"
42 changes: 31 additions & 11 deletions roles/jd-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use crate::status::{State, Status};
use std::sync::atomic::AtomicBool;
use tracing::{error, info};

/// USED to make sure that if a future new_template and a set_new_prev_hash are received together
/// the future new_template is always handled before the set new prev hash.
/// USED to make sure that if a future new_temnplate and a set_new_prev_hash are received together
/// the future new_temnplate is always handled before the set new prev hash.
pub static IS_NEW_TEMPLATE_HANDLED: AtomicBool = AtomicBool::new(true);

/// Process CLI args, if any.
Expand Down Expand Up @@ -194,10 +194,30 @@ async fn initialize_jd(
let proxy_config = process_cli_args().unwrap();

// Format `Upstream` connection address
let mut parts = proxy_config.upstreams[0].pool_address.split(':');
let address = parts.next().unwrap_or_else(|| {
panic!(
"Invalid pool address {}",
proxy_config.upstreams[0].pool_address
)
});
let port = parts
.next()
.and_then(|p| p.parse::<u16>().ok())
.unwrap_or_else(|| {
panic!(
"Invalid pool address {}",
proxy_config.upstreams[0].pool_address
)
});
let upstream_addr = SocketAddr::new(
IpAddr::from_str(&proxy_config.upstream_address)
.expect("Failed to parse upstream address!"),
proxy_config.upstream_port,
IpAddr::from_str(address).unwrap_or_else(|_| {
panic!(
"Invalid pool address {}",
proxy_config.upstreams[0].pool_address
)
}),
port,
);

// When Downstream receive a share that meets bitcoin target it transformit in a
Expand All @@ -214,7 +234,7 @@ async fn initialize_jd(
// Instantiate a new `Upstream` (SV2 Pool)
let upstream = match upstream_sv2::Upstream::new(
upstream_addr,
proxy_config.upstream_authority_pubkey.clone(),
proxy_config.upstreams[0].authority_pubkey.clone(),
0, // TODO
status::Sender::Upstream(tx_status.clone()),
send_channel_factory,
Expand Down Expand Up @@ -272,17 +292,17 @@ async fn initialize_jd(
.unwrap();

// Initialize JD part
let jd_config = proxy_config.jd_config.clone();
let mut parts = jd_config.tp_address.split(':');
let mut parts = proxy_config.tp_address.split(':');
let ip_tp = parts.next().unwrap().to_string();
let port_tp = parts.next().unwrap().parse::<u16>().unwrap();
let mut parts = jd_config.jd_address.split(':');

let mut parts = proxy_config.upstreams[0].jd_address.split(':');
let ip_jd = parts.next().unwrap().to_string();
let port_jd = parts.next().unwrap().parse::<u16>().unwrap();
let jd = JobDeclarator::new(
SocketAddr::new(IpAddr::from_str(ip_jd.as_str()).unwrap(), port_jd),
proxy_config
.upstream_authority_pubkey
proxy_config.upstreams[0]
.authority_pubkey
.clone()
.into_inner()
.as_bytes()
Expand Down
11 changes: 5 additions & 6 deletions roles/jd-client/src/proxy_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use serde::Deserialize;

#[derive(Debug, Deserialize, Clone)]
pub struct ProxyConfig {
pub upstream_address: String,
pub upstream_port: u16,
pub upstream_authority_pubkey: EncodedEd25519PublicKey,
pub downstream_address: String,
pub downstream_port: u16,
pub max_supported_version: u16,
Expand All @@ -14,13 +11,15 @@ pub struct ProxyConfig {
pub withhold: bool,
pub authority_public_key: EncodedEd25519PublicKey,
pub authority_secret_key: EncodedEd25519SecretKey,
pub jd_config: JdConfig,
pub cert_validity_sec: u64,
pub tp_address: String,
pub retry: u32,
pub upstreams: Vec<Upstream>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct JdConfig {
pub struct Upstream {
pub authority_pubkey: EncodedEd25519PublicKey,
pub pool_address: String,
pub jd_address: String,
pub tp_address: String,
}

0 comments on commit 241693a

Please sign in to comment.