Skip to content

Commit

Permalink
Fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyasantoss committed Jul 23, 2024
1 parent e31beba commit 165d0dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
33 changes: 17 additions & 16 deletions roles/mining-proxy/src/lib/downstream_mining.rs
Original file line number Diff line number Diff line change
@@ -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::{error, 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},
Expand All @@ -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};

Expand All @@ -27,8 +29,8 @@ pub type EitherFrame = StandardEitherFrame<Message>;

/// 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,
Expand All @@ -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,
},
Expand Down Expand Up @@ -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,
Expand All @@ -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,
};
Expand Down Expand Up @@ -277,7 +279,7 @@ impl DownstreamMiningNode {

pub fn exit(self_: Arc<Mutex<Self>>) {
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| {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -470,7 +472,6 @@ pub async fn listen_for_downstream_mining(
DownstreamMiningNode::start(node, setup_msg).await;
}
} else {
warn!("Received unexpected message from downstream");
error!("Received unexpected message from downstream");
}
}
Expand All @@ -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,
Expand Down
34 changes: 17 additions & 17 deletions roles/mining-proxy/src/lib/upstream_mining.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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<Message>;
pub type EitherFrame = StandardEitherFrame<Message>;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
},
Expand Down Expand Up @@ -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,
..
Expand Down Expand Up @@ -1256,9 +1255,10 @@ impl IsMiningUpstream<DownstreamMiningNode, ProxyRemoteSelector> for UpstreamMin

#[cfg(test)]
mod tests {
use super::*;
use std::net::{IpAddr, Ipv4Addr};

use super::*;

#[test]
fn new_upstream_minining_node() {
let id = 0;
Expand Down

0 comments on commit 165d0dd

Please sign in to comment.