diff --git a/roles/Cargo.lock b/roles/Cargo.lock index ea0dcfa1cb..0f08200696 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -1401,13 +1401,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" dependencies = [ + "hermit-abi 0.3.9", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1481,16 +1482,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi 0.3.9", - "libc", -] - [[package]] name = "object" version = "0.32.2" @@ -2105,6 +2096,20 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "tests-integration" +version = "0.1.0" +dependencies = [ + "async-channel 1.9.0", + "async-std", + "jd_client", + "jd_server", + "key-utils", + "pool_sv2", + "tokio", + "translator_sv2", +] + [[package]] name = "thread_local" version = "1.1.8" @@ -2117,28 +2122,27 @@ dependencies = [ [[package]] name = "tokio" -version = "1.38.0" +version = "1.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2 0.5.7", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", diff --git a/roles/jd-client/config-examples/integration-tests.toml b/roles/jd-client/config-examples/integration-tests.toml deleted file mode 100644 index bea6693fc5..0000000000 --- a/roles/jd-client/config-examples/integration-tests.toml +++ /dev/null @@ -1,70 +0,0 @@ -# SRI JDC config -downstream_address = "127.0.0.1" -downstream_port = 34265 - -# Version support -max_supported_version = 2 -min_supported_version = 2 - -# Minimum extranonce2 size for downstream -# Max value: 16 (leaves 0 bytes for search space splitting of downstreams) -# Max value for CGminer: 8 -# Min value: 2 -min_extranonce2_size = 8 - -# Withhold -withhold = false - -# Auth keys for open encrypted connection downstream -authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" -authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n" -cert_validity_sec = 3600 - -# How many time the JDC try to reinitialize itself after a failure -retry = 10 - -# Template Provider config -# Local TP (this is pointing to localhost so you must run a TP locally for this configuration to work) -# tp_address = "127.0.0.1:8442" -# Hosted testnet TP -tp_address = "75.119.150.111:8442" -tp_authority_public_key = "9azQdassggC7L3YMVcZyRJmK7qrFDj5MZNHb4LkaUrJRUhct92W" - -# Solo Mining config -# List of coinbase outputs used to build the coinbase tx in case of Solo Mining (as last-resort solution of the pools fallback system) -# ! Put your Extended Public Key or Script as output_script_value ! -# ! Right now only one output is supported, so comment all the ones you don't need ! -# For P2PK, P2PKH, P2WPKH, P2TR a public key is needed. For P2SH and P2WSH, a redeem script is needed. -coinbase_outputs = [ - #{ output_script_type = "P2PK", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" }, - #{ output_script_type = "P2PKH", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" }, - #{ output_script_type = "P2SH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" }, - #{ output_script_type = "P2WSH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" }, - { output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" }, - #{ output_script_type = "P2TR", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" }, -] - -[timeout] -unit = "secs" -value = 1 - -# List of upstreams (JDS) used as backup endpoints -# In case of shares refused by the JDS, the fallback system will propose the same job to the next upstream in this list -[[upstreams]] -# authority_pubkey = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" -# pool_address = "75.119.150.111:34254" - -# ** Modified Here -authority_pubkey = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" -pool_address = "127.0.0.1:34254" - -jd_address = "127.0.0.1:34264" -# Pool signature (string to be included in coinbase tx) -pool_signature = "Stratum v2 SRI Pool" - -# [[upstreams]] -# authority_pubkey = "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL" -# pool_address = "127.0.0.1:34254" -# jd_address = "127.0.0.1:34264" -# Pool signature (string to be included in coinbase tx) -# pool_signature = "Stratum v2 SRI Pool" diff --git a/roles/jd-client/src/lib/mod.rs b/roles/jd-client/src/lib/mod.rs index ddb284f993..1a6b06d052 100644 --- a/roles/jd-client/src/lib/mod.rs +++ b/roles/jd-client/src/lib/mod.rs @@ -7,8 +7,6 @@ pub mod template_receiver; pub mod upstream_sv2; pub use proxy_config::ProxyConfig; -#[allow(unused_imports)] -pub use toml; use std::{sync::atomic::AtomicBool, time::Duration}; diff --git a/roles/jd-client/src/lib/proxy_config.rs b/roles/jd-client/src/lib/proxy_config.rs index 89c97a7beb..687a5c5283 100644 --- a/roles/jd-client/src/lib/proxy_config.rs +++ b/roles/jd-client/src/lib/proxy_config.rs @@ -10,6 +10,15 @@ pub struct CoinbaseOutput { output_script_value: String, } +impl CoinbaseOutput { + pub fn new(output_script_type: String, output_script_value: String) -> Self { + Self { + output_script_type, + output_script_value, + } + } +} + impl TryFrom<&CoinbaseOutput> for CoinbaseOutput_ { type Error = Error; @@ -45,6 +54,46 @@ pub struct ProxyConfig { pub test_only_do_not_send_solution_to_tp: Option, } +impl ProxyConfig { + pub fn new( + downstream_address: String, + downstream_port: u16, + max_supported_version: u16, + min_supported_version: u16, + min_extranonce2_size: u16, + withhold: bool, + authority_public_key: Secp256k1PublicKey, + authority_secret_key: Secp256k1SecretKey, + cert_validity_sec: u64, + tp_address: String, + tp_authority_public_key: Option, + retry: u32, + upstreams: Vec, + timeout: Duration, + coinbase_outputs: Vec, + ) -> Self { + Self { + downstream_address, + downstream_port, + max_supported_version, + min_supported_version, + min_extranonce2_size, + withhold, + authority_public_key, + authority_secret_key, + cert_validity_sec, + tp_address, + tp_authority_public_key, + retry, + upstreams, + timeout, + coinbase_outputs, + test_only_do_not_send_solution_to_tp: None, + } + + } +} + #[derive(Debug, Deserialize, Clone)] pub struct Upstream { pub authority_pubkey: Secp256k1PublicKey, diff --git a/roles/jd-server/config-examples/jds-config-hosted-example.toml b/roles/jd-server/config-examples/jds-config-hosted-example.toml index 328cffd520..9a4a5b1cab 100644 --- a/roles/jd-server/config-examples/jds-config-hosted-example.toml +++ b/roles/jd-server/config-examples/jds-config-hosted-example.toml @@ -1,28 +1,11 @@ -# SRI Pool config authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n" cert_validity_sec = 3600 - -# List of coinbase outputs used to build the coinbase tx -# ! Right now only one output is supported, so comment all the ones you don't need ! -# For P2PK, P2PKH, P2WPKH, P2TR a public key is needed. For P2SH and P2WSH, a redeem script is needed. -coinbase_outputs = [ - #{ output_script_type = "P2PK", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" }, - #{ output_script_type = "P2PKH", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" }, - #{ output_script_type = "P2SH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" }, - #{ output_script_type = "P2WSH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" }, - { output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" }, - #{ output_script_type = "P2TR", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" }, -] - -# SRI Pool JD config listen_jd_address = "0.0.0.0:34264" -# RPC config for mempool (it can be also the same TP if correctly configured) core_rpc_url = "http://75.119.150.111" core_rpc_port = 48332 core_rpc_user = "username" core_rpc_pass = "password" -# Time interval used for JDS mempool update -[mempool_update_interval] -unit = "secs" -value = 1 +coinbase_outputs = [ + { output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" }, +] diff --git a/roles/jd-server/src/lib/mod.rs b/roles/jd-server/src/lib/mod.rs index 60f9477948..126f99eadf 100644 --- a/roles/jd-server/src/lib/mod.rs +++ b/roles/jd-server/src/lib/mod.rs @@ -234,6 +234,15 @@ pub struct CoinbaseOutput { output_script_value: String, } +impl CoinbaseOutput { + pub fn new(output_script_type: String, output_script_value: String) -> Self { + Self { + output_script_type, + output_script_value, + } + } +} + #[derive(Debug, Deserialize, Clone)] pub struct Configuration { pub listen_jd_address: String, @@ -249,6 +258,34 @@ pub struct Configuration { pub mempool_update_interval: Duration, } +impl Configuration { + pub fn new( + listen_jd_address: String, + authority_public_key: Secp256k1PublicKey, + authority_secret_key: Secp256k1SecretKey, + cert_validity_sec: u64, + coinbase_outputs: Vec, + core_rpc_url: String, + core_rpc_port: u16, + core_rpc_user: String, + core_rpc_pass: String, + mempool_update_interval: Duration, + ) -> Self { + Self { + listen_jd_address, + authority_public_key, + authority_secret_key, + cert_validity_sec, + coinbase_outputs, + core_rpc_url, + core_rpc_port, + core_rpc_user, + core_rpc_pass, + mempool_update_interval, + } + } +} + fn duration_from_toml<'de, D>(deserializer: D) -> Result where D: serde::Deserializer<'de>, diff --git a/roles/pool/config-examples/integration-tests.toml b/roles/pool/config-examples/integration-tests.toml deleted file mode 100644 index 84d5c54ad1..0000000000 --- a/roles/pool/config-examples/integration-tests.toml +++ /dev/null @@ -1,28 +0,0 @@ -# SRI Pool config -authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" -authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n" -cert_validity_sec = 3600 -test_only_listen_adress_plain = "0.0.0.0:34250" -listen_address = "0.0.0.0:34254" - -# List of coinbase outputs used to build the coinbase tx -# ! Right now only one output is supported, so comment all the ones you don't need ! -# For P2PK, P2PKH, P2WPKH, P2TR a public key is needed. For P2SH and P2WSH, a redeem script is needed. -coinbase_outputs = [ - #{ output_script_type = "P2PK", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" }, - #{ output_script_type = "P2PKH", output_script_value = "0372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354f086" }, - #{ output_script_type = "P2SH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" }, - #{ output_script_type = "P2WSH", output_script_value = "00142ef89234bc95136eb9e6fee9d32722ebd8c1f0ab" }, - { output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" }, - #{ output_script_type = "P2TR", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" }, -] - -# Pool signature (string to be included in coinbase tx) -pool_signature = "Stratum v2 SRI Pool" - -# Template Provider config -# Local TP (this is pointing to localhost so you must run a TP locally for this configuration to work) -# tp_address = "127.0.0.1:8442" - -tp_address = "75.119.150.111:8442" -tp_authority_public_key = "9azQdassggC7L3YMVcZyRJmK7qrFDj5MZNHb4LkaUrJRUhct92W" diff --git a/roles/pool/src/lib/mining_pool/mod.rs b/roles/pool/src/lib/mining_pool/mod.rs index 4b9d10b188..409f1b3eb3 100644 --- a/roles/pool/src/lib/mining_pool/mod.rs +++ b/roles/pool/src/lib/mining_pool/mod.rs @@ -66,6 +66,15 @@ pub struct CoinbaseOutput { output_script_value: String, } +impl CoinbaseOutput { + pub fn new(output_script_type: String, output_script_value: String) -> Self { + Self { + output_script_type, + output_script_value, + } + } +} + impl TryFrom<&CoinbaseOutput> for CoinbaseOutput_ { type Error = Error; @@ -96,6 +105,34 @@ pub struct Configuration { pub test_only_listen_adress_plain: String, } +impl Configuration { + pub fn new( + listen_address: String, + tp_address: String, + tp_authority_public_key: Option, + authority_public_key: Secp256k1PublicKey, + authority_secret_key: Secp256k1SecretKey, + cert_validity_sec: u64, + coinbase_outputs: Vec, + pool_signature: String, + #[cfg(feature = "test_only_allow_unencrypted")] + test_only_listen_adress_plain: String, + ) -> Self { + Self { + listen_address, + tp_address, + tp_authority_public_key, + authority_public_key, + authority_secret_key, + cert_validity_sec, + coinbase_outputs, + pool_signature, + #[cfg(feature = "test_only_allow_unencrypted")] + test_only_listen_adress_plain, + } + } +} + #[derive(Debug)] pub struct Downstream { // Either group or channel id diff --git a/roles/tests-integration/Cargo.toml b/roles/tests-integration/Cargo.toml index b5132aa8c3..ff139b324b 100644 --- a/roles/tests-integration/Cargo.toml +++ b/roles/tests-integration/Cargo.toml @@ -13,6 +13,7 @@ jd_server = { version = "0.1.1", path = "../jd-server" } pool_sv2 = { version = "0.1.1", path = "../pool" } async-channel = "1.5.1" async-std = { version = "1.8.0" } +key-utils = { version = "1.1.0", path = "../../utils/key-utils" } [[test]] name = "jd_client_integration" diff --git a/roles/tests-integration/tests/jd_client_integration.rs b/roles/tests-integration/tests/jd_client_integration.rs index 2d664b92d7..aa5d55bc2c 100644 --- a/roles/tests-integration/tests/jd_client_integration.rs +++ b/roles/tests-integration/tests/jd_client_integration.rs @@ -1,34 +1,111 @@ use async_channel::unbounded; use async_std::net::TcpStream; -use jd_client::{toml, JobDeclaratorClient, Mutex}; +use jd_client::{proxy_config::Upstream, JobDeclaratorClient, Mutex}; +use key_utils::{Secp256k1PublicKey, Secp256k1SecretKey}; use translator_sv2::TranslatorSv2; -use pool_sv2::{mining_pool, PoolSv2}; +use pool_sv2::{mining_pool::{self}, PoolSv2}; use std::sync::Arc; async fn start_pool_sv2() { - let config_path = "../pool/config-examples/integration-tests.toml"; - let config = std::fs::read_to_string(config_path).unwrap(); - let config = - toml::from_str::(&config).expect("Failed to parse config"); + use pool_sv2::mining_pool::CoinbaseOutput; + let authority_public_key = Secp256k1PublicKey::try_from("9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72".to_string()).expect("failed"); + let authority_secret_key = + Secp256k1SecretKey::try_from("mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n".to_string()).expect("failed"); + let cert_validity_sec = 3600; + let listen_address = "0.0.0.0:34254".to_string(); + let coinbase_outputs = vec![CoinbaseOutput::new("P2WPKH".to_string(), "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075".to_string())]; + let pool_signature = "Stratum v2 SRI Pool".to_string(); + let tp_address = "75.119.150.111:8442".to_string(); + let tp_authority_public_key = + Secp256k1PublicKey::try_from("9azQdassggC7L3YMVcZyRJmK7qrFDj5MZNHb4LkaUrJRUhct92W".to_string()).expect("failed"); + let config = mining_pool::Configuration::new( + listen_address, + tp_address, + Some(tp_authority_public_key), + authority_public_key, + authority_secret_key, + cert_validity_sec, + coinbase_outputs, + pool_signature, + ); PoolSv2::start(config).await; } async fn start_jd_client() -> (JobDeclaratorClient, jd_client::ProxyConfig) { - let config_path = "../jd-client/config-examples/integration-tests.toml"; - let config = std::fs::read_to_string(config_path).unwrap(); - let config = toml::from_str::(&config).expect("Failed to parse config"); + let downstream_address = "127.0.0.1".to_string(); + let downstream_port = 34265; + let max_supported_version = 2; + let min_supported_version = 2; + let min_extranonce2_size = 8; + let withhold = false; + let authority_pubkey = Secp256k1PublicKey::try_from("9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72".to_string()).expect("failed"); + let authority_secret_key = + Secp256k1SecretKey::try_from("mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n".to_string()).expect("failed"); + let cert_validity_sec = 3600; + let retry = 10; + let tp_address = "75.119.150.111:8442".to_string(); + let tp_authority_public_key = Secp256k1PublicKey::try_from("9azQdassggC7L3YMVcZyRJmK7qrFDj5MZNHb4LkaUrJRUhct92W".to_string()).expect("failed"); + let pool_address = "127.0.0.1:34254".to_string(); + let jd_address = "127.0.0.1:34264".to_string(); + let pool_signature = "Stratum v2 SRI Pool".to_string(); + use jd_client::proxy_config::CoinbaseOutput; + let coinbase_outputs: CoinbaseOutput = CoinbaseOutput::new( + "P2WPKH".to_string() , + "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075".to_string() + ); + let upstreams = vec![Upstream { + authority_pubkey, + pool_address, + jd_address, + pool_signature, + }]; + let config = jd_client::ProxyConfig::new( + downstream_address, + downstream_port, + max_supported_version, + min_supported_version, + min_extranonce2_size, + withhold, + authority_pubkey, + authority_secret_key, + cert_validity_sec, + tp_address, + Some(tp_authority_public_key), + retry, + upstreams, + std::time::Duration::from_secs(300), + vec![coinbase_outputs], + ); let task_collector = Arc::new(Mutex::new(Vec::new())); let client = JobDeclaratorClient::new(config.clone(), task_collector); (client, config) } -async fn init_jd_server() { - let config_path = "../jd-server/config-examples/jds-config-hosted-example.toml"; - let config = std::fs::read_to_string(config_path).unwrap(); - let config = toml::from_str::(&config).expect("Failed to parse config"); +async fn start_jd_server() { + let authority_public_key = Secp256k1PublicKey::try_from("9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72".to_string()).expect("failed"); + let authority_secret_key = Secp256k1SecretKey::try_from("mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n".to_string()).expect("failed"); + let cert_validity_sec = 3600; + let listen_jd_address = "0.0.0.0:34264".to_string(); + let core_rpc_url = "http://75.119.150.111".to_string(); + let core_rpc_port = 48332; + let core_rpc_user = "username".to_string(); + let core_rpc_pass = "password".to_string(); + let coinbase_outputs = vec![jd_server::CoinbaseOutput::new("P2WPKH".to_string(), "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075".to_string())]; + let config = jd_server::Configuration::new( + listen_jd_address, + authority_public_key, + authority_secret_key, + cert_validity_sec, + coinbase_outputs, + core_rpc_url, + core_rpc_port, + core_rpc_user, + core_rpc_pass, + std::time::Duration::from_secs(5) + ); jd_server::start_jd_server(config).await; } @@ -43,10 +120,58 @@ async fn connect_to_jd_client(address: String) -> Result { } } +async fn start_translator(jd_client_address: String) -> TranslatorSv2 { + let stream = connect_to_jd_client(jd_client_address).await; + let translator_v2 = TranslatorSv2::new(stream.unwrap()); + let upstream_address = "127.0.0.1".to_string(); + let upstream_port = 34265; + let upstream_authority_pubkey = + Secp256k1PublicKey::try_from("9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72".to_string()).expect("failed"); + let downstream_address = "0.0.0.0".to_string(); + let downstream_port = 34255; + let max_supported_version = 2; + let min_supported_version = 2; + let min_extranonce2_size = 8; + // # [downstream_difficulty_config] + let min_individual_miner_hashrate=10_000_000_000_000.0; + let shares_per_minute = 6.0; + // # [upstream_difficulty_config] + let channel_diff_update_interval = 60; + let channel_nominal_hashrate = 10_000_000_000_000.0; + 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( + channel_diff_update_interval, + channel_nominal_hashrate, + 0, + false + ); + let config = translator_sv2::proxy_config::ProxyConfig::new( + upstream_address, + upstream_port, + upstream_authority_pubkey, + downstream_address, + downstream_port, + max_supported_version, + min_supported_version, + min_extranonce2_size, + downstream_difficulty_config, + upstream_difficulty_config + ); + + let (tx_status, _rx_status) = unbounded(); + translator_v2.start(config, tx_status).await; + translator_v2 +} + // Test that the Job Declarator Client and the Translator SV2 can communicate with each other #[tokio::test] async fn test_jd_client_translator_sv2_pool_sv2_integration() { - init_jd_server().await; + start_jd_server().await; start_pool_sv2().await; let (jd_client, jd_client_config) = start_jd_client().await; let (tx_status, _rx_status) = unbounded(); @@ -60,14 +185,7 @@ async fn test_jd_client_translator_sv2_pool_sv2_integration() { .clone() .initialize_jd(tx_status, upstream.clone()) .await; - let stream = connect_to_jd_client(address.clone()).await; - let translator_v2 = TranslatorSv2::new(stream.unwrap()); - let translator_config = "../translator/config-examples/integration-tests.toml"; - let translator_config = std::fs::read_to_string(translator_config).unwrap(); - let translator_config = - toml::from_str::(&translator_config).unwrap(); - let (tx_status, _rx_status) = unbounded(); - translator_v2.start(translator_config, tx_status).await; - let upstream_address = translator_v2.upstream_address().unwrap(); + let translator_sv2 = start_translator(address.clone()).await; + let upstream_address = translator_sv2.upstream_address().unwrap(); assert_eq!(jd_client.downstream_address(), upstream_address); } diff --git a/roles/translator/config-examples/integration-tests.toml b/roles/translator/config-examples/integration-tests.toml deleted file mode 100644 index 5fe4a8eebd..0000000000 --- a/roles/translator/config-examples/integration-tests.toml +++ /dev/null @@ -1,36 +0,0 @@ -# Braiins Pool Upstream Connection -# upstream_authority_pubkey = "u95GEReVMjK6k5YqiSFNqqTnKU4ypU2Wm8awa6tmbmDmk1bWt" -# upstream_address = "18.196.32.109" -# upstream_port = 3336 - -# Local SRI JDC Upstream Connection -upstream_address = "127.0.0.1" -upstream_port = 34265 -upstream_authority_pubkey = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" - -# Local Mining Device Downstream Connection -downstream_address = "0.0.0.0" -downstream_port = 34255 - -# Version support -max_supported_version = 2 -min_supported_version = 2 - -# Minimum extranonce2 size for downstream -# Max value: 16 (leaves 0 bytes for search space splitting of downstreams) -# Max value for CGminer: 8 -# Min value: 2 -min_extranonce2_size = 8 - -# Difficulty params -[downstream_difficulty_config] -# hashes/s of the weakest miner that will be connecting (e.g.: 10 Th/s = 10_000_000_000_000.0) -min_individual_miner_hashrate=10_000_000_000_000.0 -# target number of shares per minute the miner should be sending -shares_per_minute = 6.0 - -[upstream_difficulty_config] -# interval in seconds to elapse before updating channel hashrate with the pool -channel_diff_update_interval = 60 -# estimated accumulated hashrate of all downstream miners (e.g.: 10 Th/s = 10_000_000_000_000.0) -channel_nominal_hashrate = 10_000_000_000_000.0 diff --git a/roles/translator/src/lib/proxy_config.rs b/roles/translator/src/lib/proxy_config.rs index d0a8357261..5da64f60f8 100644 --- a/roles/translator/src/lib/proxy_config.rs +++ b/roles/translator/src/lib/proxy_config.rs @@ -15,6 +15,34 @@ pub struct ProxyConfig { pub upstream_difficulty_config: UpstreamDifficultyConfig, } +impl ProxyConfig { + pub fn new( + upstream_address: String, + upstream_port: u16, + upstream_authority_pubkey: Secp256k1PublicKey, + downstream_address: String, + downstream_port: u16, + max_supported_version: u16, + min_supported_version: u16, + min_extranonce2_size: u16, + downstream_difficulty_config: DownstreamDifficultyConfig, + upstream_difficulty_config: UpstreamDifficultyConfig, + ) -> Self { + Self { + upstream_address, + upstream_port, + upstream_authority_pubkey, + downstream_address, + downstream_port, + max_supported_version, + min_supported_version, + min_extranonce2_size, + downstream_difficulty_config, + upstream_difficulty_config, + } + } +} + #[derive(Debug, Deserialize, Clone)] pub struct DownstreamDifficultyConfig { pub min_individual_miner_hashrate: f32, @@ -25,6 +53,21 @@ pub struct DownstreamDifficultyConfig { pub timestamp_of_last_update: u64, } +impl DownstreamDifficultyConfig { + pub fn new( + min_individual_miner_hashrate: f32, + shares_per_minute: f32, + submits_since_last_update: u32, + timestamp_of_last_update: u64, + ) -> Self { + Self { + min_individual_miner_hashrate, + shares_per_minute, + submits_since_last_update, + timestamp_of_last_update, + } + } +} impl PartialEq for DownstreamDifficultyConfig { fn eq(&self, other: &Self) -> bool { other.min_individual_miner_hashrate.round() as u32 @@ -41,3 +84,19 @@ pub struct UpstreamDifficultyConfig { #[serde(default = "bool::default")] pub should_aggregate: bool, } + +impl UpstreamDifficultyConfig { + pub fn new( + channel_diff_update_interval: u32, + channel_nominal_hashrate: f32, + timestamp_of_last_update: u64, + should_aggregate: bool, + ) -> Self { + Self { + channel_diff_update_interval, + channel_nominal_hashrate, + timestamp_of_last_update, + should_aggregate, + } + } +}