diff --git a/roles/mining-proxy/src/lib/downstream_mining.rs b/roles/mining-proxy/src/lib/downstream_mining.rs index 1b66a97dc7..c8d3732e98 100644 --- a/roles/mining-proxy/src/lib/downstream_mining.rs +++ b/roles/mining-proxy/src/lib/downstream_mining.rs @@ -1,6 +1,11 @@ +use core::convert::TryInto; +use std::sync::Arc; + use async_channel::{Receiver, SendError, Sender}; +use tokio::{net::TcpListener, sync::oneshot::Receiver as TokioReceiver}; +use tracing::{info, warn}; + use codec_sv2::{StandardEitherFrame, StandardSv2Frame}; -use core::convert::TryInto; use network_helpers_sv2::plain_connection_tokio::PlainConnection; use roles_logic_sv2::{ common_messages_sv2::{SetupConnection, SetupConnectionSuccess}, @@ -15,9 +20,6 @@ use roles_logic_sv2::{ routing_logic::MiningProxyRoutingLogic, utils::Mutex, }; -use std::sync::Arc; -use tokio::{net::TcpListener, sync::oneshot::Receiver as TokioReceiver, task}; -use tracing::{error, info}; use super::upstream_mining::{ProxyRemoteSelector, StdFrame as UpstreamFrame, UpstreamMiningNode}; @@ -27,8 +29,8 @@ pub type EitherFrame = StandardEitherFrame; /// 1 to 1 connection with a downstream node that implement the mining (sub)protocol can be either /// a mining device or a downstream proxy. -/// A downstream can only be linked with an upstream at a time. Support multi upstrems for -/// downstream do no make much sense. +/// A downstream can only be linked with an upstream at a time. Support multi upstreams for +/// downstream do not make much sense. #[derive(Debug)] pub struct DownstreamMiningNode { id: u32, @@ -48,12 +50,12 @@ pub enum DownstreamMiningNodeStatus { #[derive(Debug, Clone)] #[allow(clippy::enum_variant_names)] pub enum Channel { - DowntreamHomUpstreamGroup { + DownstreamHomUpstreamGroup { data: CommonDownstreamData, channel_id: u32, group_id: u32, }, - DowntreamHomUpstreamExtended { + DownstreamHomUpstreamExtended { data: CommonDownstreamData, channel_id: u32, }, @@ -94,7 +96,7 @@ impl DownstreamMiningNodeStatus { match self { DownstreamMiningNodeStatus::Initializing => panic!(), DownstreamMiningNodeStatus::Paired(data) => { - let channel = Channel::DowntreamHomUpstreamGroup { + let channel = Channel::DownstreamHomUpstreamGroup { data: *data, channel_id, group_id, @@ -110,7 +112,7 @@ impl DownstreamMiningNodeStatus { match self { DownstreamMiningNodeStatus::Initializing => panic!(), DownstreamMiningNodeStatus::Paired(data) => { - let channel = Channel::DowntreamHomUpstreamExtended { + let channel = Channel::DownstreamHomUpstreamExtended { data: *data, channel_id, }; @@ -277,7 +279,7 @@ impl DownstreamMiningNode { pub fn exit(self_: Arc>) { if let Some(up) = self_.safe_lock(|s| s.upstream.clone()).unwrap() { - super::upstream_mining::UpstreamMiningNode::remove_dowstream(up, &self_); + UpstreamMiningNode::remove_dowstream(up, &self_); }; self_ .safe_lock(|s| { @@ -373,14 +375,14 @@ impl match &self.status { DownstreamMiningNodeStatus::Initializing => todo!(), DownstreamMiningNodeStatus::Paired(_) => todo!(), - DownstreamMiningNodeStatus::ChannelOpened(Channel::DowntreamHomUpstreamGroup { + DownstreamMiningNodeStatus::ChannelOpened(Channel::DownstreamHomUpstreamGroup { .. }) => { let remote = self.upstream.as_ref().unwrap(); let message = Mining::SubmitSharesStandard(m); Ok(SendTo::RelayNewMessageToRemote(remote.clone(), message)) } - DownstreamMiningNodeStatus::ChannelOpened(Channel::DowntreamHomUpstreamExtended { + DownstreamMiningNodeStatus::ChannelOpened(Channel::DownstreamHomUpstreamExtended { .. }) => { // Safe unwrap is channel have been opened it means that the dowsntream is paired @@ -471,7 +473,6 @@ pub async fn listen_for_downstream_mining( } } else { warn!("Received unexpected message from downstream"); - error!("Received unexpected message from downstream"); } } _ = &mut shutdown_rx => { @@ -487,11 +488,11 @@ impl IsDownstream for DownstreamMiningNode { match self.status { DownstreamMiningNodeStatus::Initializing => panic!(), DownstreamMiningNodeStatus::Paired(data) => data, - DownstreamMiningNodeStatus::ChannelOpened(Channel::DowntreamHomUpstreamGroup { + DownstreamMiningNodeStatus::ChannelOpened(Channel::DownstreamHomUpstreamGroup { data, .. }) => data, - DownstreamMiningNodeStatus::ChannelOpened(Channel::DowntreamHomUpstreamExtended { + DownstreamMiningNodeStatus::ChannelOpened(Channel::DownstreamHomUpstreamExtended { data, .. }) => data, diff --git a/roles/mining-proxy/src/lib/upstream_mining.rs b/roles/mining-proxy/src/lib/upstream_mining.rs index 58639f6b5e..5ad012d10e 100644 --- a/roles/mining-proxy/src/lib/upstream_mining.rs +++ b/roles/mining-proxy/src/lib/upstream_mining.rs @@ -1,14 +1,16 @@ #![allow(dead_code)] -use super::EXTRANONCE_RANGE_1_LENGTH; -use roles_logic_sv2::utils::Id; +use core::convert::TryInto; +use std::{collections::HashMap, net::SocketAddr, sync::Arc, time::Duration}; -use super::downstream_mining::{Channel, DownstreamMiningNode, StdFrame as DownstreamFrame}; use async_channel::{Receiver, SendError, Sender}; use async_recursion::async_recursion; +use nohash_hasher::BuildNoHashHasher; +use tokio::{net::TcpStream, task}; +use tracing::{debug, error, info}; + use codec_sv2::{HandshakeRole, Initiator, StandardEitherFrame, StandardSv2Frame}; use network_helpers_sv2::noise_connection_tokio::Connection; -use nohash_hasher::BuildNoHashHasher; use roles_logic_sv2::{ channel_logic::{ channel_factory::{ExtendedChannelKind, OnNewShare, ProxyExtendedChannelFactory, Share}, @@ -26,14 +28,15 @@ use roles_logic_sv2::{ routing_logic::MiningProxyRoutingLogic, selectors::{DownstreamMiningSelector, ProxyDownstreamMiningSelector as Prs}, template_distribution_sv2::SubmitSolution, - utils::{GroupId, Mutex}, + utils::{GroupId, Id, Mutex}, }; -use std::{collections::HashMap, sync::Arc}; -use tokio::{net::TcpStream, task}; -use tracing::error; - use stratum_common::bitcoin::TxOut; +use super::{ + downstream_mining::{Channel, DownstreamMiningNode, StdFrame as DownstreamFrame}, + EXTRANONCE_RANGE_1_LENGTH, +}; + pub type Message = PoolMessages<'static>; pub type StdFrame = StandardSv2Frame; pub type EitherFrame = StandardEitherFrame; @@ -188,10 +191,6 @@ pub struct UpstreamMiningNode { reconnect: bool, } -use core::convert::TryInto; -use std::{net::SocketAddr, time::Duration}; -use tracing::{debug, info}; - /// It assume that endpoint NEVER change flags and version! /// I can open both extended and group channel with upstream. impl UpstreamMiningNode { @@ -471,8 +470,8 @@ impl UpstreamMiningNode { super::downstream_mining::DownstreamMiningNodeStatus::ChannelOpened( channel, ) => match channel { - Channel::DowntreamHomUpstreamGroup { channel_id, .. } => Some(*channel_id), - Channel::DowntreamHomUpstreamExtended { channel_id, .. } => { + Channel::DownstreamHomUpstreamGroup { channel_id, .. } => Some(*channel_id), + Channel::DownstreamHomUpstreamExtended { channel_id, .. } => { Some(*channel_id) } }, @@ -1047,7 +1046,7 @@ impl .ok_or(Error::NoDownstreamsConnected)?; for downstream in downstreams { match downstream.safe_lock(|r| r.get_channel().clone()).unwrap() { - Channel::DowntreamHomUpstreamGroup { + Channel::DownstreamHomUpstreamGroup { channel_id, group_id, .. @@ -1256,9 +1255,10 @@ impl IsMiningUpstream for UpstreamMin #[cfg(test)] mod tests { - use super::*; use std::net::{IpAddr, Ipv4Addr}; + use super::*; + #[test] fn new_upstream_minining_node() { let id = 0;