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 jd-client crate #1549

Open
wants to merge 10 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
12 changes: 12 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,15 @@ 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, Seq0255, Seq064K, B016M, B0255, B064K, U256};

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

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

pub use codec_sv2::{StandardEitherFrame, StandardSv2Frame, Sv2Frame};

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

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

4 changes: 0 additions & 4 deletions roles/jd-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ path = "src/lib/mod.rs"
stratum-common = { path = "../../common" }
async-channel = "1.5.1"
async-recursion = "0.3.2"
binary_sv2 = { path = "../../protocols/v2/binary-sv2" }
buffer_sv2 = { path = "../../utils/buffer" }
codec_sv2 = { path = "../../protocols/v2/codec-sv2", features = ["noise_sv2", "with_buffer_pool"] }
framing_sv2 = { path = "../../protocols/v2/framing-sv2" }
network_helpers_sv2 = { path = "../roles-utils/network-helpers", features=["with_buffer_pool"] }
roles_logic_sv2 = { path = "../../protocols/v2/roles-logic-sv2" }
serde = { version = "1.0.89", default-features = false, features = ["derive", "alloc"] }
Expand Down
13 changes: 5 additions & 8 deletions roles/jd-client/src/lib/downstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ use roles_logic_sv2::{
parsers::{AnyMessage, Mining, MiningDeviceMessages},
template_distribution_sv2::{NewTemplate, SubmitSolution},
utils::Mutex,
HandshakeRole, Responder, Slice, StandardEitherFrame, StandardSv2Frame, Sv2Frame,
};
use tracing::{debug, error, info, warn};

use codec_sv2::{HandshakeRole, Responder, StandardEitherFrame, StandardSv2Frame};
use key_utils::{Secp256k1PublicKey, Secp256k1SecretKey};

use stratum_common::bitcoin::{consensus::Decodable, TxOut};
Expand Down Expand Up @@ -275,7 +275,7 @@ impl DownstreamMiningNode {
) {
match next_message_to_send {
Ok(SendTo::RelaySameMessageToRemote(upstream_mutex)) => {
let sv2_frame: codec_sv2::Sv2Frame<AnyMessage, buffer_sv2::Slice> =
let sv2_frame: Sv2Frame<AnyMessage, Slice> =
incoming.unwrap().map(|payload| payload.try_into().unwrap());
UpstreamMiningNode::send(&upstream_mutex, sv2_frame)
.await
Expand Down Expand Up @@ -305,16 +305,14 @@ impl DownstreamMiningNode {
);
let message = Mining::SubmitSharesExtended(share);
let message: AnyMessage = AnyMessage::Mining(message);
let sv2_frame: codec_sv2::Sv2Frame<AnyMessage, buffer_sv2::Slice> =
message.try_into().unwrap();
let sv2_frame: Sv2Frame<AnyMessage, Slice> = message.try_into().unwrap();
UpstreamMiningNode::send(&upstream_mutex, sv2_frame)
.await
.unwrap();
}
Ok(SendTo::RelayNewMessage(message)) => {
let message: AnyMessage = AnyMessage::Mining(message);
let sv2_frame: codec_sv2::Sv2Frame<AnyMessage, buffer_sv2::Slice> =
message.try_into().unwrap();
let sv2_frame: Sv2Frame<AnyMessage, Slice> = message.try_into().unwrap();
let upstream_mutex = self_mutex.safe_lock(|s| s.status.get_upstream().expect("We should return RelayNewMessage only if we are not in solo mining mode")).unwrap();
UpstreamMiningNode::send(&upstream_mutex, sv2_frame)
.await
Expand All @@ -327,8 +325,7 @@ impl DownstreamMiningNode {
}
Ok(SendTo::Respond(message)) => {
let message = MiningDeviceMessages::Mining(message);
let sv2_frame: codec_sv2::Sv2Frame<MiningDeviceMessages, buffer_sv2::Slice> =
message.try_into().unwrap();
let sv2_frame: Sv2Frame<MiningDeviceMessages, Slice> = message.try_into().unwrap();
Self::send(&self_mutex, sv2_frame).await.unwrap();
}
Ok(SendTo::None(None)) => (),
Expand Down
23 changes: 13 additions & 10 deletions roles/jd-client/src/lib/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use ext_config::ConfigError;
use roles_logic_sv2::mining_sv2::{ExtendedExtranonce, NewExtendedMiningJob, SetCustomMiningJob};
use roles_logic_sv2::{
mining_sv2::{ExtendedExtranonce, NewExtendedMiningJob, SetCustomMiningJob},
BinaryError, FramingError, NoiseError,
};
use std::fmt;

pub type ProxyResult<'a, T> = core::result::Result<T, Error<'a>>;
Expand Down Expand Up @@ -34,11 +37,11 @@ pub enum Error<'a> {
/// Errors on bad `config` TOML deserialize.
BadConfigDeserialize(ConfigError),
/// Errors from `binary_sv2` crate.
BinarySv2(binary_sv2::Error),
BinarySv2(BinaryError),
/// Errors on bad noise handshake.
CodecNoise(codec_sv2::noise_sv2::Error),
CodecNoise(NoiseError),
/// Errors from `framing_sv2` crate.
FramingSv2(framing_sv2::Error),
FramingSv2(FramingError),
/// Errors on bad `TcpStream` connection.
Io(std::io::Error),
/// Errors on bad `String` to `int` conversion.
Expand Down Expand Up @@ -82,20 +85,20 @@ impl fmt::Display for Error<'_> {
}
}

impl From<binary_sv2::Error> for Error<'_> {
fn from(e: binary_sv2::Error) -> Self {
impl<'a> From<BinaryError> for Error<'_> {
fn from(e: BinaryError) -> Self {
Error::BinarySv2(e)
}
}

impl From<codec_sv2::noise_sv2::Error> for Error<'_> {
fn from(e: codec_sv2::noise_sv2::Error) -> Self {
impl From<NoiseError> for Error<'_> {
fn from(e: NoiseError) -> Self {
Error::CodecNoise(e)
}
}

impl From<framing_sv2::Error> for Error<'_> {
fn from(e: framing_sv2::Error) -> Self {
impl From<FramingError> for Error<'_> {
fn from(e: FramingError) -> Self {
Error::FramingSv2(e)
}
}
Expand Down
6 changes: 3 additions & 3 deletions roles/jd-client/src/lib/job_declarator/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use roles_logic_sv2::{
IdentifyTransactions, IdentifyTransactionsSuccess, ProvideMissingTransactions,
ProvideMissingTransactionsSuccess,
},
parsers::JobDeclaration,
parsers::JobDeclaration, Seq064K, B016M,
};
pub type SendTo = SendTo_<JobDeclaration<'static>, ()>;
use roles_logic_sv2::errors::Error;
Expand Down Expand Up @@ -70,14 +70,14 @@ impl ParseServerJobDeclarationMessages for JobDeclarator {
.ok_or(Error::UnknownRequestId(message.request_id))?;

let unknown_tx_position_list: Vec<u16> = message.unknown_tx_position_list.into_inner();
let missing_transactions: Vec<binary_sv2::B016M> = unknown_tx_position_list
let missing_transactions: Vec<B016M> = unknown_tx_position_list
.iter()
.filter_map(|&pos| tx_list.get(pos as usize).cloned())
.collect();
let request_id = message.request_id;
let message_provide_missing_transactions = ProvideMissingTransactionsSuccess {
request_id,
transaction_list: binary_sv2::Seq064K::new(missing_transactions).unwrap(),
transaction_list: Seq064K::new(missing_transactions).unwrap(),
};
let message_enum =
JobDeclaration::ProvideMissingTransactionsSuccess(message_provide_missing_transactions);
Expand Down
4 changes: 2 additions & 2 deletions roles/jd-client/src/lib/job_declarator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub mod message_handler;
use async_channel::{Receiver, Sender};
use binary_sv2::{Seq0255, Seq064K, B016M, B064K, U256};
use codec_sv2::{HandshakeRole, Initiator, StandardEitherFrame, StandardSv2Frame};
use network_helpers_sv2::noise_connection::Connection;
use roles_logic_sv2::{
handlers::SendTo_,
Expand All @@ -10,6 +8,8 @@ use roles_logic_sv2::{
parsers::{AnyMessage, JobDeclaration},
template_distribution_sv2::SetNewPrevHash,
utils::{hash_lists_tuple, Mutex},
HandshakeRole, Initiator, Seq0255, Seq064K, StandardEitherFrame, StandardSv2Frame, B016M,
B064K, U256,
};
use std::{collections::HashMap, convert::TryInto};
use stratum_common::bitcoin::{consensus, Transaction};
Expand Down
2 changes: 1 addition & 1 deletion roles/jd-client/src/lib/job_declarator/setup_connection.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use async_channel::{Receiver, Sender};
use codec_sv2::{StandardEitherFrame, StandardSv2Frame};
use roles_logic_sv2::{
common_messages_sv2::{Protocol, SetupConnection},
handlers::common::{ParseUpstreamCommonMessages, SendTo},
parsers::AnyMessage,
routing_logic::{CommonRoutingLogic, NoRouting},
utils::Mutex,
StandardEitherFrame, StandardSv2Frame,
};
use std::{convert::TryInto, net::SocketAddr, sync::Arc};
pub type Message = AnyMessage<'static>;
Expand Down
2 changes: 1 addition & 1 deletion roles/jd-client/src/lib/template_receiver/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::{job_declarator::JobDeclarator, status, PoolChangerTrigger};
use async_channel::{Receiver, Sender};
use codec_sv2::{HandshakeRole, Initiator, StandardEitherFrame, StandardSv2Frame};
use error_handling::handle_result;
use key_utils::Secp256k1PublicKey;
use network_helpers_sv2::noise_connection::Connection;
Expand All @@ -12,6 +11,7 @@ use roles_logic_sv2::{
CoinbaseOutputDataSize, NewTemplate, RequestTransactionData, SubmitSolution,
},
utils::Mutex,
HandshakeRole, Initiator, StandardEitherFrame, StandardSv2Frame
};
use setup_connection::SetupConnectionHandler;
use std::{convert::TryInto, net::SocketAddr, sync::Arc};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use async_channel::{Receiver, Sender};
use codec_sv2::{StandardEitherFrame, StandardSv2Frame};
use roles_logic_sv2::{
common_messages_sv2::{Protocol, SetupConnection},
handlers::common::{ParseUpstreamCommonMessages, SendTo},
parsers::AnyMessage,
routing_logic::{CommonRoutingLogic, NoRouting},
utils::Mutex,
StandardEitherFrame, StandardSv2Frame
};
use std::{convert::TryInto, net::SocketAddr, sync::Arc};
pub type Message = AnyMessage<'static>;
Expand Down
3 changes: 1 addition & 2 deletions roles/jd-client/src/lib/upstream_sv2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use codec_sv2::{StandardEitherFrame, StandardSv2Frame};
use roles_logic_sv2::parsers::AnyMessage;
use roles_logic_sv2::{parsers::AnyMessage, StandardEitherFrame, StandardSv2Frame};

pub mod upstream;
pub use upstream::Upstream;
Expand Down
19 changes: 9 additions & 10 deletions roles/jd-client/src/lib/upstream_sv2/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ use super::super::{
PoolChangerTrigger,
};
use async_channel::{Receiver, Sender};
use binary_sv2::{Seq0255, U256};
use codec_sv2::{HandshakeRole, Initiator};
use error_handling::handle_result;
use key_utils::Secp256k1PublicKey;
use network_helpers_sv2::noise_connection::Connection;
use roles_logic_sv2::{FramingError, HandshakeRole, Initiator, NoiseError, Seq0255, Slice, Sv2Frame, B0255, U256};
use roles_logic_sv2::{
channel_logic::channel_factory::PoolChannelFactory,
common_messages_sv2::{Protocol, SetupConnection},
Expand Down Expand Up @@ -172,7 +171,7 @@ impl Upstream {
};

let pub_key: Secp256k1PublicKey = authority_public_key;
let initiator = Initiator::from_raw_k(pub_key.into_bytes())?;
let initiator = Initiator::from_raw_k(pub_key.into_bytes()).expect("Unable to create initiator");

info!(
"PROXY SERVER - ACCEPTING FROM UPSTREAM: {}",
Expand Down Expand Up @@ -228,7 +227,7 @@ impl Upstream {
Err(e) => {
error!("Upstream connection closed: {}", e);
return Err(CodecNoise(
codec_sv2::noise_sv2::Error::ExpectedIncomingHandshakeMessage,
NoiseError::ExpectedIncomingHandshakeMessage,
));
}
};
Expand All @@ -237,7 +236,7 @@ impl Upstream {
let message_type = if let Some(header) = incoming.get_header() {
header.msg_type()
} else {
return Err(framing_sv2::Error::ExpectedHandshakeFrame.into());
return Err(FramingError::ExpectedHandshakeFrame.into());
};
// Gets the message payload
let payload = incoming.payload();
Expand All @@ -259,9 +258,9 @@ impl Upstream {
declare_mining_job: DeclareMiningJob<'static>,
set_new_prev_hash: roles_logic_sv2::template_distribution_sv2::SetNewPrevHash<'static>,
merkle_path: Seq0255<'static, U256<'static>>,
signed_token: binary_sv2::B0255<'static>,
signed_token: B0255<'static>,
coinbase_tx_version: u32,
coinbase_prefix: binary_sv2::B0255<'static>,
coinbase_prefix: B0255<'static>,
coinbase_tx_input_n_sequence: u32,
coinbase_tx_value_remaining: u64,
coinbase_tx_outs: Vec<u8>,
Expand Down Expand Up @@ -331,7 +330,7 @@ impl Upstream {
incoming
.get_header()
.ok_or(super::super::error::Error::FramingSv2(
framing_sv2::Error::ExpectedSv2Frame,
FramingError::ExpectedSv2Frame,
));

let message_type = handle_result!(tx_status, message_type).msg_type();
Expand All @@ -358,9 +357,9 @@ impl Upstream {
match next_message_to_send {
// This is a transparent proxy it will only relay messages as received
Ok(SendTo::RelaySameMessageToRemote(downstream_mutex)) => {
let sv2_frame: codec_sv2::Sv2Frame<
let sv2_frame: Sv2Frame<
MiningDeviceMessages,
buffer_sv2::Slice,
Slice,
> = incoming.map(|payload| payload.try_into().unwrap());
Downstream::send(&downstream_mutex, sv2_frame)
.await
Expand Down
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
Loading
Loading