Skip to content

Commit

Permalink
feat: update ProxyConfig in roles to JDCConfig, and update the refere…
Browse files Browse the repository at this point in the history
…nces
  • Loading branch information
devworlds committed Dec 21, 2024
1 parent e8d76d6 commit f010f11
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 86 deletions.
2 changes: 1 addition & 1 deletion INTEROPERABILITY-TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Once the pool role is running you can start up the Translation Proxy. The transl

If this successfully starts up you'll see these messages as part of the output:
```
2023-01-11T21:29:05.468529Z INFO translator: PC: ProxyConfig { upstream_address: "127.0.0.1", upstream_port: 34254, upstream_authority_pubkey: "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL", downstream_address: "0.0.0.0", downstream_port: 34255, max_supported_version: 2, min_supported_version: 2, min_extranonce2_size: 16 }
2023-01-11T21:29:05.468529Z INFO translator: PC: JDCConfig { upstream_address: "127.0.0.1", upstream_port: 34254, upstream_authority_pubkey: "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL", downstream_address: "0.0.0.0", downstream_port: 34255, max_supported_version: 2, min_supported_version: 2, min_extranonce2_size: 16 }
2023-01-11T21:29:05.469467Z INFO translator::upstream_sv2::upstream: PROXY SERVER - ACCEPTING FROM UPSTREAM: 127.0.0.1:34254
2023-01-11T21:29:05.477542Z INFO translator::upstream_sv2::upstream: Up: Sending: SetupConnection { protocol: MiningProtocol, min_version: 2, max_version: 2, flags: 14, endpoint_host: Owned([48, 46, 48, 46, 48, 46, 48]), endpoint_port: 50, vendor: Owned([]), hardware_version: Owned([]), firmware: Owned([]), device_id: Owned([]) }
2023-01-11T21:29:05.479122Z DEBUG translator::upstream_sv2::upstream: Up: Handling SetupConnectionSuccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl TryFrom<&CoinbaseOutput> for CoinbaseOutput_ {
}

#[derive(Debug, Deserialize, Clone)]
pub struct ProxyConfig {
pub struct JDCConfig {
pub downstream_address: String,
pub downstream_port: u16,
pub max_supported_version: u16,
Expand Down Expand Up @@ -116,7 +116,7 @@ impl ProtocolConfig {
}
}

impl ProxyConfig {
impl JDCConfig {
pub fn new(
listening_address: std::net::SocketAddr,
protocol_config: ProtocolConfig,
Expand Down Expand Up @@ -200,7 +200,7 @@ where
}
}

pub fn get_coinbase_output(config: &ProxyConfig) -> Result<Vec<TxOut>, Error> {
pub fn get_coinbase_output(config: &JDCConfig) -> Result<Vec<TxOut>, Error> {

Check warning on line 203 in roles/jd-client/src/lib/jdc_config.rs

View check run for this annotation

Codecov / codecov/patch

roles/jd-client/src/lib/jdc_config.rs#L203

Added line #L203 was not covered by tests
let mut result = Vec::new();
for coinbase_output_pool in &config.coinbase_outputs {
let coinbase_output: CoinbaseOutput_ = coinbase_output_pool.try_into()?;
Expand Down
4 changes: 2 additions & 2 deletions roles/jd-client/src/lib/job_declarator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub type StdFrame = StandardSv2Frame<Message>;
mod setup_connection;
use setup_connection::SetupConnectionHandler;

use super::{error::Error, proxy_config::ProxyConfig, upstream_sv2::Upstream};
use super::{error::Error, jdc_config::JDCConfig, upstream_sv2::Upstream};

#[derive(Debug, Clone)]
pub struct LastDeclareJob {
Expand Down Expand Up @@ -79,7 +79,7 @@ impl JobDeclarator {
pub async fn new(
address: SocketAddr,
authority_public_key: [u8; 32],
config: ProxyConfig,
config: JDCConfig,
up: Arc<Mutex<Upstream>>,
task_collector: Arc<Mutex<Vec<AbortHandle>>>,
) -> Result<Arc<Mutex<Self>>, Error<'static>> {
Expand Down
64 changes: 32 additions & 32 deletions roles/jd-client/src/lib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
pub mod downstream;
pub mod error;
pub mod jdc_config;
pub mod job_declarator;
pub mod proxy_config;
pub mod status;
pub mod template_receiver;
pub mod upstream_sv2;

use std::{sync::atomic::AtomicBool, time::Duration};

use jdc_config::JDCConfig;
use job_declarator::JobDeclarator;
use proxy_config::ProxyConfig;
use template_receiver::TemplateRx;

use async_channel::{bounded, unbounded};
Expand Down Expand Up @@ -56,11 +56,11 @@ pub static IS_NEW_TEMPLATE_HANDLED: AtomicBool = AtomicBool::new(true);
/// in the market.
pub struct JobDeclaratorClient {
/// Configuration of the proxy server [`JobDeclaratorClient`] is connected to.
config: ProxyConfig,
config: JDCConfig,
}

impl JobDeclaratorClient {
pub fn new(config: ProxyConfig) -> Self {
pub fn new(config: JDCConfig) -> Self {
Self { config }
}

Expand All @@ -73,12 +73,12 @@ impl JobDeclaratorClient {

let task_collector = Arc::new(Mutex::new(vec![]));

let proxy_config = &self.config;
let jdc_config = &self.config;

loop {
let task_collector = task_collector.clone();
let tx_status = tx_status.clone();
if let Some(upstream) = proxy_config.upstreams.get(upstream_index) {
if let Some(upstream) = jdc_config.upstreams.get(upstream_index) {
self.initialize_jd(tx_status.clone(), task_collector.clone(), upstream.clone())
.await;
} else {
Expand Down Expand Up @@ -159,29 +159,29 @@ impl JobDeclaratorClient {
tx_status: async_channel::Sender<status::Status<'static>>,
task_collector: Arc<Mutex<Vec<AbortHandle>>>,
) {
let proxy_config = &self.config;
let timeout = proxy_config.timeout;
let miner_tx_out = proxy_config::get_coinbase_output(proxy_config).unwrap();
let jdc_config = &self.config;
let timeout = jdc_config.timeout;
let miner_tx_out = jdc_config::get_coinbase_output(jdc_config).unwrap();

// When Downstream receive a share that meets bitcoin target it transformit in a
// SubmitSolution and send it to the TemplateReceiver
let (send_solution, recv_solution) = bounded(10);

// Format `Downstream` connection address
let downstream_addr = SocketAddr::new(
IpAddr::from_str(&proxy_config.downstream_address).unwrap(),
proxy_config.downstream_port,
IpAddr::from_str(&jdc_config.downstream_address).unwrap(),
jdc_config.downstream_port,
);

// Wait for downstream to connect
let downstream = downstream::listen_for_downstream_mining(
downstream_addr,
None,
send_solution,
proxy_config.withhold,
proxy_config.authority_public_key,
proxy_config.authority_secret_key,
proxy_config.cert_validity_sec,
jdc_config.withhold,
jdc_config.authority_public_key,
jdc_config.authority_secret_key,
jdc_config.cert_validity_sec,
task_collector.clone(),
status::Sender::Downstream(tx_status.clone()),
miner_tx_out.clone(),
Expand All @@ -191,7 +191,7 @@ impl JobDeclaratorClient {
.unwrap();

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

Expand All @@ -204,7 +204,7 @@ impl JobDeclaratorClient {
task_collector,
Arc::new(Mutex::new(PoolChangerTrigger::new(timeout))),
miner_tx_out.clone(),
proxy_config.tp_authority_public_key,
jdc_config.tp_authority_public_key,
false,
)
.await;
Expand All @@ -214,11 +214,11 @@ impl JobDeclaratorClient {
&self,
tx_status: async_channel::Sender<status::Status<'static>>,
task_collector: Arc<Mutex<Vec<AbortHandle>>>,
upstream_config: proxy_config::Upstream,
upstream_config: jdc_config::Upstream,
) {
let proxy_config = &self.config;
let timeout = proxy_config.timeout;
let test_only_do_not_send_solution_to_tp = proxy_config
let jdc_config = &self.config;
let timeout = jdc_config.timeout;
let test_only_do_not_send_solution_to_tp = jdc_config
.test_only_do_not_send_solution_to_tp
.unwrap_or(false);

Expand Down Expand Up @@ -263,8 +263,8 @@ impl JobDeclaratorClient {

match upstream_sv2::Upstream::setup_connection(
upstream.clone(),
proxy_config.min_supported_version,
proxy_config.max_supported_version,
jdc_config.min_supported_version,
jdc_config.max_supported_version,
)
.await
{
Expand All @@ -283,12 +283,12 @@ impl JobDeclaratorClient {

// Format `Downstream` connection address
let downstream_addr = SocketAddr::new(
IpAddr::from_str(&proxy_config.downstream_address).unwrap(),
proxy_config.downstream_port,
IpAddr::from_str(&jdc_config.downstream_address).unwrap(),
jdc_config.downstream_port,
);

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

Expand All @@ -298,7 +298,7 @@ impl JobDeclaratorClient {
let jd = match JobDeclarator::new(
SocketAddr::new(IpAddr::from_str(ip_jd.as_str()).unwrap(), port_jd),
upstream_config.authority_pubkey.into_bytes(),
proxy_config.clone(),
jdc_config.clone(),
upstream.clone(),
task_collector.clone(),
)
Expand All @@ -320,10 +320,10 @@ impl JobDeclaratorClient {
downstream_addr,
Some(upstream),
send_solution,
proxy_config.withhold,
proxy_config.authority_public_key,
proxy_config.authority_secret_key,
proxy_config.cert_validity_sec,
jdc_config.withhold,
jdc_config.authority_public_key,
jdc_config.authority_secret_key,
jdc_config.cert_validity_sec,
task_collector.clone(),
status::Sender::Downstream(tx_status.clone()),
vec![],
Expand All @@ -341,7 +341,7 @@ impl JobDeclaratorClient {
task_collector,
Arc::new(Mutex::new(PoolChangerTrigger::new(timeout))),
vec![],
proxy_config.tp_authority_public_key,
jdc_config.tp_authority_public_key,
test_only_do_not_send_solution_to_tp,
)
.await;
Expand Down
12 changes: 6 additions & 6 deletions roles/jd-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod lib;

use lib::{
error::{Error, ProxyResult},
proxy_config::ProxyConfig,
jdc_config::JDCConfig,
status, JobDeclaratorClient,
};

Expand All @@ -14,7 +14,7 @@ use tracing::error;

/// Process CLI args and load configuration.
#[allow(clippy::result_large_err)]
fn process_cli_args<'a>() -> ProxyResult<'a, ProxyConfig> {
fn process_cli_args<'a>() -> ProxyResult<'a, JDCConfig> {

Check warning on line 17 in roles/jd-client/src/main.rs

View check run for this annotation

Codecov / codecov/patch

roles/jd-client/src/main.rs#L17

Added line #L17 was not covered by tests
// Parse CLI arguments
let args = Args::from_args().map_err(|help| {
error!("{}", help);
Expand All @@ -31,8 +31,8 @@ fn process_cli_args<'a>() -> ProxyResult<'a, ProxyConfig> {
.add_source(File::new(config_path, FileFormat::Toml))
.build()?;

// Deserialize settings into ProxyConfig
let config = settings.try_deserialize::<ProxyConfig>()?;
// Deserialize settings into JDCConfig
let config = settings.try_deserialize::<JDCConfig>()?;

Check warning on line 35 in roles/jd-client/src/main.rs

View check run for this annotation

Codecov / codecov/patch

roles/jd-client/src/main.rs#L35

Added line #L35 was not covered by tests
Ok(config)
}

Expand Down Expand Up @@ -91,14 +91,14 @@ fn process_cli_args<'a>() -> ProxyResult<'a, ProxyConfig> {
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let proxy_config = match process_cli_args() {
let jdc_config = match process_cli_args() {
Ok(p) => p,
Err(e) => {
error!("Job Declarator Client Config error: {}", e);
return;
}
};

let jdc = JobDeclaratorClient::new(proxy_config);
let jdc = JobDeclaratorClient::new(jdc_config);
jdc.start().await;
}
27 changes: 13 additions & 14 deletions roles/tests-integration/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ pub async fn start_jdc(
tp_address: SocketAddr,
jds_address: SocketAddr,
) -> SocketAddr {
use jd_client::proxy_config::{
CoinbaseOutput, PoolConfig, ProtocolConfig, ProxyConfig, TPConfig, Upstream,
use jd_client::jdc_config::{
CoinbaseOutput, JDCConfig, PoolConfig, ProtocolConfig, TPConfig, Upstream,
};
let jdc_address = get_available_address();
let max_supported_version = 2;
Expand Down Expand Up @@ -335,7 +335,7 @@ pub async fn start_jdc(
min_extranonce2_size,
coinbase_outputs,
);
let jd_client_proxy = ProxyConfig::new(
let jd_client_proxy = JDCConfig::new(
jdc_address,
protocol_config,
withhold,
Expand Down Expand Up @@ -402,33 +402,32 @@ pub async fn start_sv2_translator(upstream: SocketAddr) -> SocketAddr {
let shares_per_minute = 60.0;
let channel_diff_update_interval = 60;
let channel_nominal_hashrate = hashrate;
let downstream_difficulty_config =
translator_sv2::proxy_config::DownstreamDifficultyConfig::new(
min_individual_miner_hashrate,
shares_per_minute,
0,
0,
);
let upstream_difficulty_config = translator_sv2::proxy_config::UpstreamDifficultyConfig::new(
let downstream_difficulty_config = translator_sv2::jdc_config::DownstreamDifficultyConfig::new(
min_individual_miner_hashrate,
shares_per_minute,
0,
0,
);
let upstream_difficulty_config = translator_sv2::jdc_config::UpstreamDifficultyConfig::new(
channel_diff_update_interval,
channel_nominal_hashrate,
0,
false,
);
let upstream_conf = translator_sv2::proxy_config::UpstreamConfig::new(
let upstream_conf = translator_sv2::jdc_config::UpstreamConfig::new(
upstream_address,
upstream_port,
upstream_authority_pubkey,
upstream_difficulty_config,
);
let downstream_conf = translator_sv2::proxy_config::DownstreamConfig::new(
let downstream_conf = translator_sv2::jdc_config::DownstreamConfig::new(
listening_address.ip().to_string(),
listening_port,
downstream_difficulty_config,
);

let config =
translator_sv2::proxy_config::ProxyConfig::new(upstream_conf, downstream_conf, 2, 2, 8);
translator_sv2::jdc_config::JDCConfig::new(upstream_conf, downstream_conf, 2, 2, 8);
let translator_v2 = translator_sv2::TranslatorSv2::new(config);
tokio::spawn(async move {
translator_v2.start().await;
Expand Down
2 changes: 1 addition & 1 deletion roles/translator/src/lib/downstream_sv1/diff_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl Downstream {

#[cfg(test)]
mod test {
use crate::proxy_config::{DownstreamDifficultyConfig, UpstreamDifficultyConfig};
use crate::jdc_config::{DownstreamDifficultyConfig, UpstreamDifficultyConfig};
use async_channel::unbounded;
use binary_sv2::U256;
use rand::{thread_rng, Rng};
Expand Down
2 changes: 1 addition & 1 deletion roles/translator/src/lib/downstream_sv1/downstream.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
downstream_sv1,
error::ProxyResult,
proxy_config::{DownstreamDifficultyConfig, UpstreamDifficultyConfig},
jdc_config::{DownstreamDifficultyConfig, UpstreamDifficultyConfig},
status,
};
use async_channel::{bounded, Receiver, Sender};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use key_utils::Secp256k1PublicKey;
use serde::Deserialize;

#[derive(Debug, Deserialize, Clone)]
pub struct ProxyConfig {
pub struct JDCConfig {
pub upstream_address: String,
pub upstream_port: u16,
pub upstream_authority_pubkey: Secp256k1PublicKey,
Expand Down Expand Up @@ -54,7 +54,7 @@ impl DownstreamConfig {
}
}

impl ProxyConfig {
impl JDCConfig {
pub fn new(
upstream: UpstreamConfig,
downstream: DownstreamConfig,
Expand Down
Loading

0 comments on commit f010f11

Please sign in to comment.