From e12706813f09b755ef376f5a25c699b0fc148dc3 Mon Sep 17 00:00:00 2001 From: Gabriele Vernetti Date: Mon, 25 Sep 2023 17:56:20 +0200 Subject: [PATCH] fixes --- roles/pool/pool-config-example.toml | 11 +++++-- roles/pool/src/error.rs | 1 + roles/pool/src/lib/mining_pool/mod.rs | 4 +-- roles/pool/src/main.rs | 32 ++++++++++++++----- test/config/pool-mock-tp-bad-coinbase.toml | 6 ++-- .../test/bad-pool-config-test.json | 2 +- 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/roles/pool/pool-config-example.toml b/roles/pool/pool-config-example.toml index f921da927..48160ec81 100644 --- a/roles/pool/pool-config-example.toml +++ b/roles/pool/pool-config-example.toml @@ -4,9 +4,16 @@ authority_secret_key = "2Z1FZug7mZNyM63ggkm37r4oKQ29khLjAvEx43rGkFN47RcJ2t" cert_validity_sec = 3600 test_only_listen_adress_plain = "0.0.0.0:34250" listen_address = "0.0.0.0:34254" -# list of compressed or uncompressed pubkeys for coinbase payout (only supports 1 item in the array at this point) + +# 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 ! coinbase_outputs = [ - "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0", + { output_script_type = "P2PK", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" }, + #{ output_script_type = "P2PKH", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" }, + #{ output_script_type = "P2SH", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" }, + #{ output_script_type = "P2WSH", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" }, + #{ output_script_type = "P2WPKH", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" }, + #{ output_script_type = "P2TR", output_script_value = "02e13cef1348924c49dd1f708bf38eb79ae4648c16f0301085f37547d1d25e33e0" }, ] # Template Provider config diff --git a/roles/pool/src/error.rs b/roles/pool/src/error.rs index ec5826977..229d461cc 100644 --- a/roles/pool/src/error.rs +++ b/roles/pool/src/error.rs @@ -27,6 +27,7 @@ pub enum PoolError { pub enum OutputScriptError { UnknownScriptType(String), InvalidScript(String), + EmptyCoinbaseOutputs(String) } impl std::fmt::Display for PoolError { diff --git a/roles/pool/src/lib/mining_pool/mod.rs b/roles/pool/src/lib/mining_pool/mod.rs index a4ef7b457..1e9a6ffc2 100644 --- a/roles/pool/src/lib/mining_pool/mod.rs +++ b/roles/pool/src/lib/mining_pool/mod.rs @@ -466,7 +466,7 @@ impl Pool { creator, share_per_min, kind, - pool_coinbase_outputs, + pool_coinbase_outputs.unwrap(), ))); let pool = Arc::new(Mutex::new(Pool { downstreams: HashMap::with_hasher(BuildNoHashHasher::default()), @@ -599,7 +599,7 @@ mod test { let _coinbase_tx_value_remaining: u64 = 5000000000; let _coinbase_tx_outputs_count = 0; let coinbase_tx_locktime = 0; - let coinbase_tx_outputs: Vec = crate::get_coinbase_output(&config); + let coinbase_tx_outputs: Vec = crate::get_coinbase_output(&config).unwrap(); // extranonce len set to max_extranonce_size in `ChannelFactory::new_extended_channel()` let extranonce_len = 32; diff --git a/roles/pool/src/main.rs b/roles/pool/src/main.rs index 1e53f051a..a6a6d13dc 100644 --- a/roles/pool/src/main.rs +++ b/roles/pool/src/main.rs @@ -25,18 +25,23 @@ pub type EitherFrame = StandardEitherFrame; const BLOCK_REWARD: u64 = 625_000_000; -pub fn get_coinbase_output(config: &Configuration) -> Vec { - config +pub fn get_coinbase_output(config: &Configuration) -> Result, OutputScriptError> { + let result = config .coinbase_outputs .iter() .map(|coinbase_output| { - let output_script: Script = coinbase_output.try_into().unwrap(); - TxOut { - value: crate::BLOCK_REWARD, // It's not important here, since it will be updated by NewTemplate from TP + coinbase_output.try_into().map(|output_script| TxOut { + value: crate::BLOCK_REWARD, script_pubkey: output_script, - } + }) }) - .collect() + .collect::, OutputScriptError>>(); + + if result.is_ok() && result.as_ref().unwrap().is_empty() { + Err(OutputScriptError::EmptyCoinbaseOutputs("Empty coinbase outputs".to_string())) + } else { + result + } } impl TryFrom<&CoinbaseOutput> for Script { @@ -230,7 +235,18 @@ async fn main() { let (s_solution, r_solution) = bounded(10); let (s_message_recv_signal, r_message_recv_signal) = bounded(10); info!("Pool INITIALIZING with config: {:?}", &args.config_path); - let coinbase_output_len = get_coinbase_output(&config).len() as u32; + let coinbase_output_result = get_coinbase_output(&config); + let coinbase_output_len; + match coinbase_output_result { + Ok(coinbase_output) => { + coinbase_output_len = coinbase_output.len() as u32; + } + Err(err) => { + error!("Failed to get coinbase output: {:?}", err); + return; + } + } + //let coinbase_output_len = get_coinbase_output(&config).unwrap().len() as u32; let template_rx_res = TemplateRx::connect( config.tp_address.parse().unwrap(), s_new_t, diff --git a/test/config/pool-mock-tp-bad-coinbase.toml b/test/config/pool-mock-tp-bad-coinbase.toml index 401291a38..d39cdee2d 100644 --- a/test/config/pool-mock-tp-bad-coinbase.toml +++ b/test/config/pool-mock-tp-bad-coinbase.toml @@ -6,6 +6,8 @@ authority_public_key = "2di19GHYQnAZJmEpoUeP7C3Eg9TCcksHr23rZCC83dvUiZgiDL" authority_secret_key = "2Z1FZug7mZNyM63ggkm37r4oKQ29khLjAvEx43rGkFN47RcJ2t" cert_validity_sec = 3600 test_only_listen_adress_plain = "0.0.0.0:34250" +# 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 ! coinbase_outputs = [ - "04466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276728176c3c6431f8eeda4538dc37c865e2784f3a9e77d044f33e407797e1278", -] + { output_script_type = "P2PK", output_script_value = "04466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276728176c3c6431f8eeda4538dc37c865e2784f3a9e77d044f33e407797e1278" }, +] \ No newline at end of file diff --git a/test/message-generator/test/bad-pool-config-test.json b/test/message-generator/test/bad-pool-config-test.json index ff7c38cf3..d0fb6817c 100644 --- a/test/message-generator/test/bad-pool-config-test.json +++ b/test/message-generator/test/bad-pool-config-test.json @@ -103,7 +103,7 @@ "WithConditions": { "conditions": [ { - "output_string": "Failed to parse config:", + "output_string": "Failed to get coinbase output:", "output_location": "StdOut", "condition": true }