From 8e4bf3566c1a02fe9c191b95790217df34d315c5 Mon Sep 17 00:00:00 2001 From: fi3 Date: Tue, 17 Dec 2024 16:46:48 +0100 Subject: [PATCH] Update roles to use new jd protocol --- .../no-serde-sv2/codec/src/codec/mod.rs | 15 --- .../src/datatypes/non_copy_data_types/mod.rs | 1 + protocols/v2/noise-sv2/src/cipher_state.rs | 14 -- protocols/v2/noise-sv2/src/handshake.rs | 21 +-- protocols/v2/roles-logic-sv2/Cargo.toml | 1 + .../v2/roles-logic-sv2/src/job_dispatcher.rs | 6 - roles/Cargo.lock | 14 +- roles/jd-client/Cargo.toml | 4 +- .../src/lib/job_declarator/message_handler.rs | 16 +-- roles/jd-client/src/lib/job_declarator/mod.rs | 21 ++- roles/jd-server/Cargo.toml | 6 +- .../src/lib/job_declarator/message_handler.rs | 120 +++++++----------- roles/jd-server/src/lib/job_declarator/mod.rs | 14 -- roles/jd-server/src/lib/mempool/mod.rs | 22 +--- roles/mining-proxy/Cargo.toml | 6 +- roles/pool/Cargo.toml | 6 +- roles/roles-utils/network-helpers/Cargo.toml | 6 +- roles/roles-utils/rpc/src/lib.rs | 3 - roles/test-utils/mining-device/Cargo.toml | 6 +- .../tests-integration/tests/common/sniffer.rs | 9 +- roles/translator/Cargo.toml | 4 +- .../tproxy-config-local-jdc-example.toml | 4 +- 22 files changed, 91 insertions(+), 228 deletions(-) diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs index 32a3e0847e..9252519efa 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/codec/mod.rs @@ -65,8 +65,6 @@ mod impls; #[cfg(feature = "with_buffer_pool")] use buffer_sv2::Slice; -use alloc::vec::Vec; - /// The `SizeHint` trait provides a mechanism to return the encoded bytes size of a decodable type. /// /// It defines two methods for retrieving the size of an encoded message: @@ -111,19 +109,6 @@ pub trait Fixed { const SIZE: usize; } -// Not used and will be removed during refactoring -pub trait Variable { - const HEADER_SIZE: usize; - //const ELEMENT_SIZE: usize; - const MAX_SIZE: usize; - - fn inner_size(&self) -> usize; - - // Retrieves the header as a byte vector. This header typically contains information - // about the size or type of the data that follows. - fn get_header(&self) -> Vec; -} - impl SizeHint for T { fn size_hint(_data: &[u8], _offset: usize) -> Result { Ok(Self::SIZE) diff --git a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs index a57222bcc4..57d589b4ec 100644 --- a/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs +++ b/protocols/v2/binary-sv2/no-serde-sv2/codec/src/datatypes/non_copy_data_types/mod.rs @@ -39,6 +39,7 @@ use alloc::vec::Vec; mod inner; mod seq_inner; +#[allow(dead_code)] trait IntoOwned { fn into_owned(self) -> Self; } diff --git a/protocols/v2/noise-sv2/src/cipher_state.rs b/protocols/v2/noise-sv2/src/cipher_state.rs index 7d4414ef39..c741dd9065 100644 --- a/protocols/v2/noise-sv2/src/cipher_state.rs +++ b/protocols/v2/noise-sv2/src/cipher_state.rs @@ -95,20 +95,6 @@ where res } - fn into_aesg(mut self) -> Option> { - #[allow(clippy::clone_on_copy)] - let k = self.get_k().clone()?; - let c = Aes256Gcm::from_key(k); - Some(Cipher::from_cipher(c)) - } - - fn into_chacha(mut self) -> Option> { - #[allow(clippy::clone_on_copy)] - let k = self.get_k().clone()?; - let c = ChaCha20Poly1305::from_key(k); - Some(Cipher::from_cipher(c)) - } - // Encrypts the provided `data` in place using the cipher and AAD (`ad`). // // Performs authenticated encryption on the provided `data` buffer, modifying it in place to diff --git a/protocols/v2/noise-sv2/src/handshake.rs b/protocols/v2/noise-sv2/src/handshake.rs index 38e2ef8445..0ec1ab6643 100644 --- a/protocols/v2/noise-sv2/src/handshake.rs +++ b/protocols/v2/noise-sv2/src/handshake.rs @@ -33,9 +33,8 @@ use crate::{aed_cipher::AeadCipher, cipher_state::CipherState, NOISE_HASHED_PROTOCOL_NAME_CHACHA}; use chacha20poly1305::ChaCha20Poly1305; use secp256k1::{ - ecdh::SharedSecret, hashes::{sha256::Hash as Sha256Hash, Hash}, - rand, Keypair, Secp256k1, SecretKey, XOnlyPublicKey, + rand, Keypair, Secp256k1 }; // Represents the operations needed during a Noise protocol handshake. @@ -166,17 +165,6 @@ pub trait HandshakeOp: CipherState { (out_1, out_2) } - fn hkdf_3( - chaining_key: &[u8; 32], - input_key_material: &[u8], - ) -> ([u8; 32], [u8; 32], [u8; 32]) { - let temp_key = Self::hmac_hash(chaining_key, input_key_material); - let out_1 = Self::hmac_hash(&temp_key, &[0x1]); - let out_2 = Self::hmac_hash(&temp_key, &[&out_1[..], &[0x2][..]].concat()); - let out_3 = Self::hmac_hash(&temp_key, &[&out_2[..], &[0x3][..]].concat()); - (out_1, out_2, out_3) - } - // Mixes the input key material into the current chaining key (`ck`) and initializes the // handshake cipher with an updated encryption key (`k`). // @@ -229,13 +217,6 @@ pub trait HandshakeOp: CipherState { Ok(()) } - fn ecdh(private: &[u8], public: &[u8]) -> [u8; 32] { - let private = SecretKey::from_slice(private).expect("Wrong key"); - let x_public = XOnlyPublicKey::from_slice(public).expect("Wrong key"); - let res = SharedSecret::new(&x_public.public_key(crate::PARITY), &private); - res.secret_bytes() - } - // Initializes the handshake state by setting the initial chaining key (`ck`) and handshake // hash (`h`). // diff --git a/protocols/v2/roles-logic-sv2/Cargo.toml b/protocols/v2/roles-logic-sv2/Cargo.toml index 7593bc76b2..d2390c9519 100644 --- a/protocols/v2/roles-logic-sv2/Cargo.toml +++ b/protocols/v2/roles-logic-sv2/Cargo.toml @@ -44,6 +44,7 @@ with_serde = [ "serde", prop_test = ["template_distribution_sv2/prop_test"] # Code coverage tools may conflict with the nopanic logic, so we can disable it when needed disable_nopanic = [] +cargo-clippy = [] [package.metadata.docs.rs] all-features = true diff --git a/protocols/v2/roles-logic-sv2/src/job_dispatcher.rs b/protocols/v2/roles-logic-sv2/src/job_dispatcher.rs index 780687efe0..c60a600d1c 100644 --- a/protocols/v2/roles-logic-sv2/src/job_dispatcher.rs +++ b/protocols/v2/roles-logic-sv2/src/job_dispatcher.rs @@ -91,12 +91,6 @@ struct DownstreamJob { extended_job_id: u32, } -#[derive(Debug)] -struct ExtendedJobs { - #[allow(dead_code)] - upstream_target: Vec, -} - /// Used by proxies to keep track of standard jobs in the group channel /// created with the sv2 server #[derive(Debug)] diff --git a/roles/Cargo.lock b/roles/Cargo.lock index a8ade1d1af..e032cc29e3 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -381,14 +381,14 @@ checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "binary_codec_sv2" -version = "1.2.0" +version = "2.0.0" dependencies = [ "buffer_sv2", ] [[package]] name = "binary_sv2" -version = "1.2.0" +version = "2.0.0" dependencies = [ "binary_codec_sv2", "derive_codec_sv2", @@ -772,7 +772,7 @@ dependencies = [ [[package]] name = "const_sv2" -version = "2.1.0" +version = "3.0.0" [[package]] name = "convert_case" @@ -835,7 +835,7 @@ dependencies = [ [[package]] name = "derive_codec_sv2" -version = "1.1.0" +version = "2.0.0" dependencies = [ "binary_codec_sv2", ] @@ -1431,7 +1431,7 @@ dependencies = [ [[package]] name = "job_declaration_sv2" -version = "1.0.0" +version = "2.0.0" dependencies = [ "binary_sv2", "const_sv2", @@ -2021,7 +2021,7 @@ dependencies = [ [[package]] name = "roles_logic_sv2" -version = "2.0.0" +version = "3.0.0" dependencies = [ "binary_sv2", "chacha20poly1305", @@ -2239,7 +2239,7 @@ dependencies = [ [[package]] name = "serde_sv2" -version = "1.0.1" +version = "2.0.0" dependencies = [ "buffer_sv2", "serde", diff --git a/roles/jd-client/Cargo.toml b/roles/jd-client/Cargo.toml index 5d138e9b4b..6cc0491057 100644 --- a/roles/jd-client/Cargo.toml +++ b/roles/jd-client/Cargo.toml @@ -19,12 +19,12 @@ path = "src/lib/mod.rs" stratum-common = { version = "1.0.0", path = "../../common" } async-channel = "1.5.1" async-recursion = "0.3.2" -binary_sv2 = { version = "^1.0.0", path = "../../protocols/v2/binary-sv2/binary-sv2" } +binary_sv2 = { version = "^2.0.0", path = "../../protocols/v2/binary-sv2/binary-sv2" } buffer_sv2 = { version = "^1.0.0", path = "../../utils/buffer" } codec_sv2 = { version = "^1.0.1", path = "../../protocols/v2/codec-sv2", features = ["noise_sv2", "with_buffer_pool"] } framing_sv2 = { version = "^2.0.0", path = "../../protocols/v2/framing-sv2" } network_helpers_sv2 = { version = "2.0.0", path = "../roles-utils/network-helpers", features=["with_tokio", "with_buffer_pool"] } -roles_logic_sv2 = { version = "^2.0.0", path = "../../protocols/v2/roles-logic-sv2" } +roles_logic_sv2 = { version = "^3.0.0", path = "../../protocols/v2/roles-logic-sv2" } serde = { version = "1.0.89", default-features = false, features = ["derive", "alloc"] } futures = "0.3.25" tokio = { version = "1", features = ["full"] } diff --git a/roles/jd-client/src/lib/job_declarator/message_handler.rs b/roles/jd-client/src/lib/job_declarator/message_handler.rs index 72d58a9126..21346829af 100644 --- a/roles/jd-client/src/lib/job_declarator/message_handler.rs +++ b/roles/jd-client/src/lib/job_declarator/message_handler.rs @@ -3,8 +3,7 @@ use roles_logic_sv2::{ handlers::{job_declaration::ParseServerJobDeclarationMessages, SendTo_}, job_declaration_sv2::{ AllocateMiningJobTokenSuccess, DeclareMiningJobError, DeclareMiningJobSuccess, - IdentifyTransactions, IdentifyTransactionsSuccess, ProvideMissingTransactions, - ProvideMissingTransactionsSuccess, + ProvideMissingTransactions, ProvideMissingTransactionsSuccess, }, parsers::JobDeclaration, }; @@ -36,19 +35,6 @@ impl ParseServerJobDeclarationMessages for JobDeclarator { Ok(SendTo::None(None)) } - fn handle_identify_transactions( - &mut self, - message: IdentifyTransactions, - ) -> Result { - let message_identify_transactions = IdentifyTransactionsSuccess { - request_id: message.request_id, - tx_data_hashes: Vec::new().into(), - }; - let message_enum = - JobDeclaration::IdentifyTransactionsSuccess(message_identify_transactions); - Ok(SendTo::Respond(message_enum)) - } - fn handle_provide_missing_transactions( &mut self, message: ProvideMissingTransactions, diff --git a/roles/jd-client/src/lib/job_declarator/mod.rs b/roles/jd-client/src/lib/job_declarator/mod.rs index 1c019c85de..da9cabc272 100644 --- a/roles/jd-client/src/lib/job_declarator/mod.rs +++ b/roles/jd-client/src/lib/job_declarator/mod.rs @@ -9,7 +9,7 @@ use roles_logic_sv2::{ mining_sv2::SubmitSharesExtended, parsers::{JobDeclaration, PoolMessages}, template_distribution_sv2::SetNewPrevHash, - utils::{hash_lists_tuple, Mutex}, + utils::Mutex, }; use std::{collections::HashMap, convert::TryInto, str::FromStr}; use stratum_common::bitcoin::{util::psbt::serialize::Deserialize, Transaction}; @@ -240,21 +240,20 @@ impl JobDeclarator { self_mutex: &Arc>, template: NewTemplate<'static>, token: Vec, - tx_list_: Seq064K<'static, B016M<'static>>, + tx_list: Seq064K<'static, B016M<'static>>, excess_data: B064K<'static>, coinbase_pool_output: Vec, ) { let (id, _, sender) = self_mutex .safe_lock(|s| (s.req_ids.next(), s.min_extranonce_size, s.sender.clone())) .unwrap(); - // TODO: create right nonce - let tx_short_hash_nonce = 0; - let mut tx_list: Vec = Vec::new(); - for tx in tx_list_.to_vec() { - //TODO remove unwrap + let mut tx_ids = vec![]; + for tx in tx_list.to_vec() { let tx = Transaction::deserialize(&tx).unwrap(); - tx_list.push(tx); + let id: U256 = tx.txid().to_vec().try_into().unwrap(); + tx_ids.push(id); } + let tx_ids: Seq064K<'static, U256> = Seq064K::from(tx_ids); let declare_job = DeclareMiningJob { request_id: id, mining_job_token: token.try_into().unwrap(), @@ -265,16 +264,14 @@ impl JobDeclarator { coinbase_suffix: self_mutex .safe_lock(|s| s.coinbase_tx_suffix.clone()) .unwrap(), - tx_short_hash_nonce, - tx_short_hash_list: hash_lists_tuple(tx_list.clone(), tx_short_hash_nonce).0, - tx_hash_list_hash: hash_lists_tuple(tx_list.clone(), tx_short_hash_nonce).1, + tx_list: tx_ids, excess_data, // request transaction data }; let last_declare = LastDeclareJob { declare_job: declare_job.clone(), template, coinbase_pool_output, - tx_list: tx_list_.clone(), + tx_list, }; Self::update_last_declare_job_sent(self_mutex, id, last_declare); let frame: StdFrame = diff --git a/roles/jd-server/Cargo.toml b/roles/jd-server/Cargo.toml index 08d566753a..de3afe69e5 100644 --- a/roles/jd-server/Cargo.toml +++ b/roles/jd-server/Cargo.toml @@ -19,14 +19,14 @@ path = "src/lib/mod.rs" [dependencies] stratum-common = { version = "1.0.0", path = "../../common" } async-channel = "1.5.1" -binary_sv2 = { version = "^1.0.0", path = "../../protocols/v2/binary-sv2/binary-sv2" } +binary_sv2 = { version = "^2.0.0", path = "../../protocols/v2/binary-sv2/binary-sv2" } buffer_sv2 = { version = "^1.0.0", path = "../../utils/buffer" } codec_sv2 = { version = "^1.0.1", path = "../../protocols/v2/codec-sv2", features = ["noise_sv2"] } -const_sv2 = { version = "^2.0.0", path = "../../protocols/v2/const-sv2" } +const_sv2 = { version = "^3.0.0", path = "../../protocols/v2/const-sv2" } network_helpers_sv2 = { version = "2.0.0", path = "../roles-utils/network-helpers", features = ["with_tokio"] } noise_sv2 = { version = "1.1.0", path = "../../protocols/v2/noise-sv2" } rand = "0.8.4" -roles_logic_sv2 = { version = "^2.0.0", path = "../../protocols/v2/roles-logic-sv2" } +roles_logic_sv2 = { version = "^3.0.0", path = "../../protocols/v2/roles-logic-sv2" } tokio = { version = "1", features = ["full"] } ext-config = { version = "0.14.0", features = ["toml"], package = "config" } tracing = { version = "0.1" } diff --git a/roles/jd-server/src/lib/job_declarator/message_handler.rs b/roles/jd-server/src/lib/job_declarator/message_handler.rs index cd75e86af7..cb95444ad1 100644 --- a/roles/jd-server/src/lib/job_declarator/message_handler.rs +++ b/roles/jd-server/src/lib/job_declarator/message_handler.rs @@ -1,16 +1,19 @@ -use binary_sv2::ShortTxId; +use binary_sv2::{Deserialize, U256}; use roles_logic_sv2::{ handlers::{job_declaration::ParseClientJobDeclarationMessages, SendTo_}, job_declaration_sv2::{ AllocateMiningJobToken, AllocateMiningJobTokenSuccess, DeclareMiningJob, - DeclareMiningJobError, DeclareMiningJobSuccess, IdentifyTransactionsSuccess, - ProvideMissingTransactions, ProvideMissingTransactionsSuccess, SubmitSolutionJd, + DeclareMiningJobError, DeclareMiningJobSuccess, ProvideMissingTransactions, + ProvideMissingTransactionsSuccess, SubmitSolutionJd, }, parsers::JobDeclaration, utils::Mutex, }; use std::{convert::TryInto, io::Cursor, sync::Arc}; -use stratum_common::bitcoin::{Transaction, Txid}; +use stratum_common::bitcoin::{ + hashes::{sha256d::Hash as Hash256, Hash}, + Transaction, Txid, +}; pub type SendTo = SendTo_, ()>; use crate::mempool::JDsMempool; @@ -73,36 +76,21 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream { // The unknown transactions is a vector that contains the transactions that are not in the // jds mempool, and will be non-empty in the ProvideMissingTransactionsSuccess message let mut known_transactions: Vec = vec![]; - self.tx_hash_list_hash = Some(message.tx_hash_list_hash.clone().into_static()); if self.verify_job(&message) { - let short_hash_list: Vec = message - .tx_short_hash_list - .inner_as_ref() - .iter() - .map(|x| x.to_vec().try_into().unwrap()) - .collect(); - let nonce = message.tx_short_hash_nonce; - // TODO return None when we have a collision handle that case as weel - let short_id_mempool = self - .mempool - .safe_lock(|x| x.to_short_ids(nonce)) - .unwrap() - .unwrap(); - let mut transactions_with_state = - vec![TransactionState::Missing; short_hash_list.len()]; + let hash_list: Vec<&[u8]> = message.tx_list.inner_as_ref().clone(); + let mempool = self.mempool.safe_lock(|x| x.mempool.clone()).unwrap(); + let mut transactions_with_state = vec![TransactionState::Missing; hash_list.len()]; let mut missing_txs: Vec = Vec::new(); - for (i, sid) in short_hash_list.iter().enumerate() { - let sid_: [u8; 6] = sid.to_vec().try_into().unwrap(); - match short_id_mempool.get(&sid_) { - Some(tx_data) => { - transactions_with_state[i] = TransactionState::PresentInMempool(tx_data.id); - known_transactions.push(tx_data.id); - } - None => { - transactions_with_state[i] = TransactionState::Missing; - missing_txs.push(i as u16); - } + for (i, id) in hash_list.iter().enumerate() { + let hash = Hash256::from_slice(id).unwrap(); + let id_ = Txid::from_hash(hash); + if mempool.contains_key(&id_) { + transactions_with_state[i] = TransactionState::PresentInMempool(id_); + known_transactions.push(id_); + } else { + transactions_with_state[i] = TransactionState::Missing; + missing_txs.push(i as u16); } } self.declared_mining_job = ( @@ -118,10 +106,12 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream { .append(&mut known_transactions); if missing_txs.is_empty() { + let mut placeholder = [0_u8; 32]; let message_success = DeclareMiningJobSuccess { request_id: message.request_id, new_mining_job_token: signed_token( - message.tx_hash_list_hash.clone(), + // TODO here we maybe want to have the hash of the concatenated txs + U256::from_bytes(&mut placeholder).unwrap(), &self.public_key.clone(), &self.private_key.clone(), ), @@ -150,13 +140,6 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream { } } - fn handle_identify_transactions_success( - &mut self, - _message: IdentifyTransactionsSuccess, - ) -> Result { - Ok(SendTo::None(None)) - } - fn handle_provide_missing_transactions_success( &mut self, message: ProvideMissingTransactionsSuccess, @@ -201,12 +184,12 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream { TransactionState::Missing => return Err(Error::JDSMissingTransactions), } } - // TODO check it - let tx_hash_list_hash = self.tx_hash_list_hash.clone().unwrap().into_static(); + let mut placeholder = [0_u8; 32]; let message_success = DeclareMiningJobSuccess { request_id: message.request_id, new_mining_job_token: signed_token( - tx_hash_list_hash, + // TODO here we maybe want to have the hash of the concatenated txs + U256::from_bytes(&mut placeholder).unwrap(), &self.public_key.clone(), &self.private_key.clone(), ), @@ -233,57 +216,50 @@ fn clear_declared_mining_job( new_mining_job: &DeclareMiningJob, mempool: Arc>, ) -> Result<(), Error> { - let old_transactions = old_mining_job.tx_short_hash_list.inner_as_ref(); - let new_transactions = new_mining_job.tx_short_hash_list.inner_as_ref(); + let old_transactions = old_mining_job.tx_list.inner_as_ref(); + let new_transactions = new_mining_job.tx_list.inner_as_ref(); if old_transactions.is_empty() { info!("No transactions to remove from mempool"); return Ok(()); } - let nonce = old_mining_job.tx_short_hash_nonce; - let result = mempool .safe_lock(|mempool_| -> Result<(), Error> { - let short_ids_map = mempool_ - .to_short_ids(nonce) - .ok_or(Error::JDSMissingTransactions)?; + let mempool = &mut mempool_.mempool; + let mut to_remove = Vec::new(); - for short_id in old_transactions - .iter() - .filter(|&id| !new_transactions.contains(id)) - { - if let Some(transaction_with_hash) = short_ids_map.get(*short_id) { - let txid = transaction_with_hash.id; - match mempool_.mempool.get_mut(&txid) { - Some(Some((_transaction, counter))) => { + for (id, tx) in mempool { + if new_transactions.contains(&id.as_ref()) { + match tx { + Some((_, counter)) => { if *counter > 1 { *counter -= 1; debug!( - "Fat transaction {:?} counter decremented; job id {:?} dropped", - txid, old_mining_job.request_id + "Transaction {:?} counter decremented; job id {:?} dropped", + id, old_mining_job.mining_job_token ); } else { - mempool_.mempool.remove(&txid); + to_remove.push(*id); debug!( - "Fat transaction {:?} with job id {:?} removed from mempool", - txid, old_mining_job.request_id + "Transaction {:?} with job id {:?} removed from mempool", + id, old_mining_job.mining_job_token ); } } - Some(None) => debug!( - "Thin transaction {:?} with job id {:?} removed from mempool", - txid, old_mining_job.request_id - ), - None => {} + None => { + to_remove.push(*id); + debug!( + "Transaction {:?} with job id {:?} removed from mempool", + id, old_mining_job.request_id + ); + } } - } else { - debug!( - "Transaction with short id {:?} not found in mempool for old jobs", - short_id - ); } } + for id in to_remove { + mempool_.mempool.remove(&id); + } Ok(()) }) .map_err(|e| Error::PoisonLock(e.to_string()))?; diff --git a/roles/jd-server/src/lib/job_declarator/mod.rs b/roles/jd-server/src/lib/job_declarator/mod.rs index 9e775bc927..e21b6092b0 100644 --- a/roles/jd-server/src/lib/job_declarator/mod.rs +++ b/roles/jd-server/src/lib/job_declarator/mod.rs @@ -65,7 +65,6 @@ pub struct JobDeclaratorDownstream { Vec, Vec, ), - tx_hash_list_hash: Option>, add_txs_to_mempool: AddTrasactionsToMempool, } @@ -101,7 +100,6 @@ impl JobDeclaratorDownstream { private_key: config.authority_secret_key, mempool, declared_mining_job: (None, Vec::new(), Vec::new()), - tx_hash_list_hash: None, add_txs_to_mempool: AddTrasactionsToMempool { add_txs_to_mempool_inner, sender_add_txs_to_mempool, @@ -252,12 +250,6 @@ impl JobDeclaratorDownstream { debug!("Send message: DMJS. Updating the JDS mempool."); Self::send_txs_to_mempool(self_mutex.clone()).await; } - JobDeclaration::IdentifyTransactions(_) => { - debug!("Send message: IT"); - } - JobDeclaration::IdentifyTransactionsSuccess(_) => { - error!("Send unexpected message: ITS"); - } JobDeclaration::ProvideMissingTransactions(_) => { debug!("Send message: PMT. Updating the JDS mempool."); Self::send_txs_to_mempool(self_mutex.clone()).await; @@ -361,12 +353,6 @@ impl JobDeclaratorDownstream { Some(JobDeclaration::DeclareMiningJobError(_)) => { error!("JD Server received an unexpected message {:?}", m); } - Some(JobDeclaration::IdentifyTransactions(_)) => { - error!("JD Server received an unexpected message {:?}", m); - } - Some(JobDeclaration::IdentifyTransactionsSuccess(_)) => { - error!("JD Server received an unexpected message {:?}", m); - } Some(JobDeclaration::AllocateMiningJobToken(_)) => { error!("JD Server received an unexpected message {:?}", m); } diff --git a/roles/jd-server/src/lib/mempool/mod.rs b/roles/jd-server/src/lib/mempool/mod.rs index 0541593b46..d7a27d24a6 100644 --- a/roles/jd-server/src/lib/mempool/mod.rs +++ b/roles/jd-server/src/lib/mempool/mod.rs @@ -6,7 +6,7 @@ use bitcoin::blockdata::transaction::Transaction; use hashbrown::HashMap; use roles_logic_sv2::utils::Mutex; use rpc_sv2::{mini_rpc_client, mini_rpc_client::RpcError}; -use std::{convert::TryInto, str::FromStr, sync::Arc}; +use std::{str::FromStr, sync::Arc}; use stratum_common::{bitcoin, bitcoin::hash_types::Txid}; #[derive(Clone, Debug)] @@ -162,24 +162,4 @@ impl JDsMempool { } Ok(()) } - - pub fn to_short_ids(&self, nonce: u64) -> Option> { - let mut ret = HashMap::new(); - for tx in &self.mempool { - let s_id = roles_logic_sv2::utils::get_short_hash(*tx.0, nonce) - .to_vec() - .try_into() - .unwrap(); - let tx_data = TransactionWithHash { - id: *tx.0, - tx: tx.1.clone(), - }; - if ret.insert(s_id, tx_data.clone()).is_none() { - continue; - } else { - return None; - } - } - Some(ret) - } } diff --git a/roles/mining-proxy/Cargo.toml b/roles/mining-proxy/Cargo.toml index 431a1ec850..3e2b494857 100644 --- a/roles/mining-proxy/Cargo.toml +++ b/roles/mining-proxy/Cargo.toml @@ -20,14 +20,14 @@ path = "src/lib/mod.rs" stratum-common = { version = "1.0.0", path = "../../common" } async-channel = "1.8.0" async-recursion = "0.3.2" -binary_sv2 = { version = "^1.0.0", path = "../../protocols/v2/binary-sv2/binary-sv2" } +binary_sv2 = { version = "^2.0.0", path = "../../protocols/v2/binary-sv2/binary-sv2" } buffer_sv2 = { version = "^1.0.0", path = "../../utils/buffer" } codec_sv2 = { version = "^1.0.1", path = "../../protocols/v2/codec-sv2", features = ["noise_sv2", "with_buffer_pool"] } -const_sv2 = { version = "^2.0.0", path = "../../protocols/v2/const-sv2" } +const_sv2 = { version = "^3.0.0", path = "../../protocols/v2/const-sv2" } futures = "0.3.19" network_helpers_sv2 = {version = "2.0.0", path = "../roles-utils/network-helpers", features = ["with_tokio","with_buffer_pool"] } once_cell = "1.12.0" -roles_logic_sv2 = { version = "^2.0.0", path = "../../protocols/v2/roles-logic-sv2" } +roles_logic_sv2 = { version = "^3.0.0", path = "../../protocols/v2/roles-logic-sv2" } serde = { version = "1.0.89", features = ["derive", "alloc"], default-features = false } tokio = { version = "1", features = ["full"] } ext-config = { version = "0.14.0", features = ["toml"], package = "config" } diff --git a/roles/pool/Cargo.toml b/roles/pool/Cargo.toml index 626ddbd25b..ad6dfb6a77 100644 --- a/roles/pool/Cargo.toml +++ b/roles/pool/Cargo.toml @@ -19,14 +19,14 @@ path = "src/lib/mod.rs" [dependencies] stratum-common = { version = "1.0.0", path = "../../common" } async-channel = "1.5.1" -binary_sv2 = { version = "^1.0.0", path = "../../protocols/v2/binary-sv2/binary-sv2" } +binary_sv2 = { version = "^2.0.0", path = "../../protocols/v2/binary-sv2/binary-sv2" } buffer_sv2 = { version = "^1.0.0", path = "../../utils/buffer" } codec_sv2 = { version = "^1.0.1", path = "../../protocols/v2/codec-sv2", features = ["noise_sv2"] } -const_sv2 = { version = "^2.0.0", path = "../../protocols/v2/const-sv2" } +const_sv2 = { version = "^3.0.0", path = "../../protocols/v2/const-sv2" } network_helpers_sv2 = { version = "2.0.0", path = "../roles-utils/network-helpers", features =["with_tokio","with_buffer_pool"] } noise_sv2 = { version = "1.1.0", path = "../../protocols/v2/noise-sv2" } rand = "0.8.4" -roles_logic_sv2 = { version = "^2.0.0", path = "../../protocols/v2/roles-logic-sv2" } +roles_logic_sv2 = { version = "^3.0.0", path = "../../protocols/v2/roles-logic-sv2" } serde = { version = "1.0.89", features = ["derive", "alloc"], default-features = false } tokio = { version = "1", features = ["full"] } ext-config = { version = "0.14.0", features = ["toml"], package = "config" } diff --git a/roles/roles-utils/network-helpers/Cargo.toml b/roles/roles-utils/network-helpers/Cargo.toml index 7c35fc38fd..37d74c41cc 100644 --- a/roles/roles-utils/network-helpers/Cargo.toml +++ b/roles/roles-utils/network-helpers/Cargo.toml @@ -18,9 +18,9 @@ keywords = ["stratum", "mining", "bitcoin", "protocol"] async-std = { version = "1.8.0", optional = true } async-channel = { version = "1.8.0", optional = true } tokio = { version = "1", features = ["full"], optional = true } -binary_sv2 = { version = "^1.0.0", path = "../../../protocols/v2/binary-sv2/binary-sv2", optional = true } +binary_sv2 = { version = "^2.0.0", path = "../../../protocols/v2/binary-sv2/binary-sv2", optional = true } codec_sv2 = { version = "1.0.1", path = "../../../protocols/v2/codec-sv2", features=["noise_sv2"], optional = true } -const_sv2 = {version = "2.0.0", path = "../../../protocols/v2/const-sv2"} +const_sv2 = {version = "3.0.0", path = "../../../protocols/v2/const-sv2"} serde = { version = "1.0.89", features = ["derive"], default-features = false, optional = true } tracing = { version = "0.1" } futures = "0.3.28" @@ -33,4 +33,4 @@ with_serde = ["binary_sv2/with_serde", "serde", "codec_sv2/with_serde"] with_buffer_pool = ["codec_sv2/with_buffer_pool"] [package.metadata.docs.rs] -all-features = true \ No newline at end of file +all-features = true diff --git a/roles/roles-utils/rpc/src/lib.rs b/roles/roles-utils/rpc/src/lib.rs index e3204e86af..eacbc24712 100644 --- a/roles/roles-utils/rpc/src/lib.rs +++ b/roles/roles-utils/rpc/src/lib.rs @@ -4,8 +4,5 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Hash([u8; 32]); -#[derive(Clone, Deserialize)] -pub struct Amount(f64); - #[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct BlockHash(Hash); diff --git a/roles/test-utils/mining-device/Cargo.toml b/roles/test-utils/mining-device/Cargo.toml index b0262677f3..5dc628fe9d 100644 --- a/roles/test-utils/mining-device/Cargo.toml +++ b/roles/test-utils/mining-device/Cargo.toml @@ -22,10 +22,10 @@ path = "src/lib/mod.rs" [dependencies] stratum-common = { version = "1.0.0", path = "../../../common" } codec_sv2 = { version = "^1.0.1", path = "../../../protocols/v2/codec-sv2", features=["noise_sv2"] } -roles_logic_sv2 = { version = "2.0.0", path = "../../../protocols/v2/roles-logic-sv2" } -const_sv2 = { version = "2.0.0", path = "../../../protocols/v2/const-sv2" } +roles_logic_sv2 = { version = "3.0.0", path = "../../../protocols/v2/roles-logic-sv2" } +const_sv2 = { version = "3.0.0", path = "../../../protocols/v2/const-sv2" } async-channel = "1.5.1" -binary_sv2 = { version = "1.0.0", path = "../../../protocols/v2/binary-sv2/binary-sv2" } +binary_sv2 = { version = "2.0.0", path = "../../../protocols/v2/binary-sv2/binary-sv2" } network_helpers_sv2 = { version = "2.0.0", path = "../../roles-utils/network-helpers", features=["tokio"] } buffer_sv2 = { version = "1.0.0", path = "../../../utils/buffer"} async-recursion = "0.3.2" diff --git a/roles/tests-integration/tests/common/sniffer.rs b/roles/tests-integration/tests/common/sniffer.rs index 3cbf739011..092a69359b 100644 --- a/roles/tests-integration/tests/common/sniffer.rs +++ b/roles/tests-integration/tests/common/sniffer.rs @@ -9,8 +9,7 @@ use roles_logic_sv2::{ AnyMessage, CommonMessages, JobDeclaration::{ AllocateMiningJobToken, AllocateMiningJobTokenSuccess, DeclareMiningJob, - DeclareMiningJobError, DeclareMiningJobSuccess, IdentifyTransactions, - IdentifyTransactionsSuccess, ProvideMissingTransactions, + DeclareMiningJobError, DeclareMiningJobSuccess, ProvideMissingTransactions, ProvideMissingTransactionsSuccess, SubmitSolution, }, PoolMessages, @@ -362,12 +361,6 @@ impl Sniffer { DeclareMiningJobSuccess(m) => { AnyMessage::JobDeclaration(DeclareMiningJobSuccess(m.into_static())) } - IdentifyTransactions(m) => { - AnyMessage::JobDeclaration(IdentifyTransactions(m.into_static())) - } - IdentifyTransactionsSuccess(m) => { - AnyMessage::JobDeclaration(IdentifyTransactionsSuccess(m.into_static())) - } ProvideMissingTransactions(m) => { AnyMessage::JobDeclaration(ProvideMissingTransactions(m.into_static())) } diff --git a/roles/translator/Cargo.toml b/roles/translator/Cargo.toml index 834b92a429..aaf179ecbd 100644 --- a/roles/translator/Cargo.toml +++ b/roles/translator/Cargo.toml @@ -24,13 +24,13 @@ stratum-common = { version = "1.0.0", path = "../../common" } async-channel = "1.5.1" async-recursion = "0.3.2" async-std = { version = "1.12.0", features = ["attributes"] } -binary_sv2 = { version = "^1.0.0", path = "../../protocols/v2/binary-sv2/binary-sv2" } +binary_sv2 = { version = "^2.0.0", path = "../../protocols/v2/binary-sv2/binary-sv2" } buffer_sv2 = { version = "^1.0.0", path = "../../utils/buffer" } codec_sv2 = { version = "^1.0.1", path = "../../protocols/v2/codec-sv2", features = ["noise_sv2", "with_buffer_pool"] } framing_sv2 = { version = "^2.0.0", path = "../../protocols/v2/framing-sv2" } network_helpers_sv2 = { version = "2.0.0", path = "../roles-utils/network-helpers", features=["async_std", "with_buffer_pool"] } once_cell = "1.12.0" -roles_logic_sv2 = { version = "^2.0.0", path = "../../protocols/v2/roles-logic-sv2" } +roles_logic_sv2 = { version = "^3.0.0", path = "../../protocols/v2/roles-logic-sv2" } serde = { version = "1.0.89", default-features = false, features = ["derive", "alloc"] } serde_json = { version = "1.0.64", default-features = false, features = ["alloc"] } futures = "0.3.25" diff --git a/roles/translator/config-examples/tproxy-config-local-jdc-example.toml b/roles/translator/config-examples/tproxy-config-local-jdc-example.toml index 1e18457ac2..427945b503 100644 --- a/roles/translator/config-examples/tproxy-config-local-jdc-example.toml +++ b/roles/translator/config-examples/tproxy-config-local-jdc-example.toml @@ -25,7 +25,7 @@ min_extranonce2_size = 5 # 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 +min_individual_miner_hashrate=10_000_000.0 # target number of shares per minute the miner should be sending shares_per_minute = 6.0 @@ -33,4 +33,4 @@ shares_per_minute = 6.0 # 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 +channel_nominal_hashrate = 10_000_000.0