Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove protocol deps from pool crate #1483

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions protocols/v2/codec-sv2/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ impl<'a, T: Serialize + GetSize + Deserialize<'a>, B: IsBuffer + AeadBuffer> Wit

// Since the frame length is already validated during the handshake process, this
// operation is infallible
#[allow(clippy::useless_conversion)]
// Clippy is wrong here about the `src.into()` conversion. It is necessary to convert the
// `Vec<u8>` into a `B::Slice` to be able to call `from_bytes_unchecked`.
let frame = HandShakeFrame::from_bytes_unchecked(src.into());

frame.into()
Expand Down
2 changes: 1 addition & 1 deletion protocols/v2/roles-logic-sv2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ nohash-hasher = "0.2.0"
siphasher = "1"
primitive-types = "0.13.1"
hex = {package = "hex-conservative", version = "*"}
codec_sv2 = { path = "../../../protocols/v2/codec-sv2", features = ["noise_sv2"] }

[dev-dependencies]
codec_sv2 = { path = "../../../protocols/v2/codec-sv2" }
quickcheck = "1.0.3"
quickcheck_macros = "1"
rand = "0.8.5"
Expand Down
10 changes: 10 additions & 0 deletions protocols/v2/roles-logic-sv2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ pub use errors::Error;
pub use job_declaration_sv2;
pub use mining_sv2;
pub use template_distribution_sv2;

pub use binary_sv2::{Error as BinaryError, B0255, B064K, U256};

pub use codec_sv2::{framing_sv2::Error as FramingError, Error as CodecError};

pub use codec_sv2::{noise_sv2::Error as NoiseError, HandshakeRole, Initiator, Responder};

pub use codec_sv2::{StandardEitherFrame, StandardSv2Frame};

pub use const_sv2::MESSAGE_TYPE_CHANNEL_ENDPOINT_CHANGED;
6 changes: 1 addition & 5 deletions roles/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions roles/pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ path = "src/lib/mod.rs"
[dependencies]
stratum-common = { path = "../../common" }
async-channel = "1.5.1"
binary_sv2 = { path = "../../protocols/v2/binary-sv2" }
buffer_sv2 = { path = "../../utils/buffer" }
codec_sv2 = { path = "../../protocols/v2/codec-sv2", features = ["noise_sv2"] }
const_sv2 = { path = "../../protocols/v2/const-sv2" }
network_helpers_sv2 = { path = "../roles-utils/network-helpers", features =["with_buffer_pool"] }
noise_sv2 = { path = "../../protocols/v2/noise-sv2" }
rand = "0.8.4"
roles_logic_sv2 = { path = "../../protocols/v2/roles-logic-sv2" }
serde = { version = "1.0.89", features = ["derive", "alloc"], default-features = false }
Expand Down
27 changes: 13 additions & 14 deletions roles/pool/src/lib/error.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use roles_logic_sv2::{parsers::Mining, BinaryError, CodecError, FramingError, NoiseError};
use std::{
convert::From,
fmt::Debug,
sync::{MutexGuard, PoisonError},
};

use roles_logic_sv2::parsers::Mining;

#[derive(std::fmt::Debug)]
pub enum PoolError {
Io(std::io::Error),
ChannelSend(Box<dyn std::marker::Send + Debug>),
ChannelRecv(async_channel::RecvError),
BinarySv2(binary_sv2::Error),
Codec(codec_sv2::Error),
Noise(noise_sv2::Error),
BinarySv2(BinaryError),
Codec(CodecError),
Noise(NoiseError),
RolesLogic(roles_logic_sv2::Error),
Framing(codec_sv2::framing_sv2::Error),
Framing(FramingError),
PoisonLock(String),
ComponentShutdown(String),
Custom(String),
Expand Down Expand Up @@ -58,20 +57,20 @@ impl From<async_channel::RecvError> for PoolError {
}
}

impl From<binary_sv2::Error> for PoolError {
fn from(e: binary_sv2::Error) -> PoolError {
impl From<BinaryError> for PoolError {
fn from(e: BinaryError) -> PoolError {
PoolError::BinarySv2(e)
}
}

impl From<codec_sv2::Error> for PoolError {
fn from(e: codec_sv2::Error) -> PoolError {
impl From<CodecError> for PoolError {
fn from(e: CodecError) -> PoolError {
PoolError::Codec(e)
}
}

impl From<noise_sv2::Error> for PoolError {
fn from(e: noise_sv2::Error) -> PoolError {
impl From<NoiseError> for PoolError {
fn from(e: NoiseError) -> PoolError {
PoolError::Noise(e)
}
}
Expand All @@ -93,8 +92,8 @@ impl From<String> for PoolError {
PoolError::Custom(e)
}
}
impl From<codec_sv2::framing_sv2::Error> for PoolError {
fn from(e: codec_sv2::framing_sv2::Error) -> PoolError {
impl From<FramingError> for PoolError {
fn from(e: FramingError) -> PoolError {
PoolError::Framing(e)
}
}
Expand Down
7 changes: 3 additions & 4 deletions roles/pool/src/lib/mining_pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use super::{
status,
};
use async_channel::{Receiver, Sender};
use binary_sv2::U256;
use codec_sv2::{HandshakeRole, Responder, StandardEitherFrame, StandardSv2Frame};
use error_handling::handle_result;
use key_utils::SignatureService;
use network_helpers_sv2::noise_connection::Connection;
Expand All @@ -22,6 +20,7 @@ use roles_logic_sv2::{
routing_logic::MiningRoutingLogic,
template_distribution_sv2::{NewTemplate, SetNewPrevHash, SubmitSolution},
utils::{CoinbaseOutput as CoinbaseOutput_, Mutex},
CodecError, HandshakeRole, Responder, StandardEitherFrame, StandardSv2Frame, U256,
};
use std::{collections::HashMap, convert::TryInto, net::SocketAddr, sync::Arc};
use stratum_common::{
Expand Down Expand Up @@ -137,7 +136,7 @@ impl Downstream {
Ok(received) => {
let received: Result<StdFrame, _> = received
.try_into()
.map_err(|e| PoolError::Codec(codec_sv2::Error::FramingSv2Error(e)));
.map_err(|e| PoolError::Codec(CodecError::FramingSv2Error(e)));
let std_frame = handle_result!(status_tx, received);
handle_result!(
status_tx,
Expand Down Expand Up @@ -562,8 +561,8 @@ impl Pool {

#[cfg(test)]
mod test {
use binary_sv2::{B0255, B064K};
use ext_config::{Config, File, FileFormat};
use roles_logic_sv2::{B0255, B064K};
use std::convert::TryInto;
use tracing::error;

Expand Down
4 changes: 2 additions & 2 deletions roles/pool/src/lib/template_receiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::{
status,
};
use async_channel::{Receiver, Sender};
use codec_sv2::{HandshakeRole, Initiator};
use error_handling::handle_result;
use key_utils::Secp256k1PublicKey;
use network_helpers_sv2::noise_connection::Connection;
Expand All @@ -15,6 +14,7 @@ use roles_logic_sv2::{
CoinbaseOutputDataSize, NewTemplate, SetNewPrevHash, SubmitSolution,
},
utils::Mutex,
CodecError, HandshakeRole, Initiator,
};
use std::{convert::TryInto, net::SocketAddr, sync::Arc};
use tokio::{net::TcpStream, task};
Expand Down Expand Up @@ -114,7 +114,7 @@ impl TemplateRx {
status_tx,
message_from_tp
.try_into()
.map_err(|e| PoolError::Codec(codec_sv2::Error::FramingSv2Error(e)))
.map_err(|e| PoolError::Codec(CodecError::FramingSv2Error(e)))
);
let message_type_res = message_from_tp
.get_header()
Expand Down
5 changes: 3 additions & 2 deletions roles/pool/src/lib/template_receiver/setup_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use roles_logic_sv2::{
parsers::{AnyMessage, CommonMessages},
routing_logic::{CommonRoutingLogic, NoRouting},
utils::Mutex,
CodecError, MESSAGE_TYPE_CHANNEL_ENDPOINT_CHANGED,
};
use std::{convert::TryInto, net::SocketAddr, sync::Arc};

Expand Down Expand Up @@ -52,7 +53,7 @@ impl SetupConnectionHandler {
.recv()
.await?
.try_into()
.map_err(|e| PoolError::Codec(codec_sv2::Error::FramingSv2Error(e)))?;
.map_err(|e| PoolError::Codec(CodecError::FramingSv2Error(e)))?;
let message_type = incoming
.get_header()
.ok_or_else(|| PoolError::Custom(String::from("No header set")))?
Expand Down Expand Up @@ -101,7 +102,7 @@ impl ParseUpstreamCommonMessages<NoRouting> for SetupConnectionHandler {
_: roles_logic_sv2::common_messages_sv2::ChannelEndpointChanged,
) -> Result<roles_logic_sv2::handlers::common::SendTo, Error> {
Err(Error::UnexpectedMessage(
const_sv2::MESSAGE_TYPE_CHANNEL_ENDPOINT_CHANGED,
MESSAGE_TYPE_CHANNEL_ENDPOINT_CHANGED,
))
}
}
Loading