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

update mining-device-sv1 to tracing #1294

Open
wants to merge 7 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
242 changes: 119 additions & 123 deletions roles/Cargo.lock

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions roles/jd-client/src/lib/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub enum Error<'a> {
Infallible(std::convert::Infallible),
}

impl<'a> fmt::Display for Error<'a> {
impl fmt::Display for Error<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use Error::*;
match self {
Expand All @@ -86,55 +86,55 @@ impl<'a> fmt::Display for Error<'a> {
}
}

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

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

impl<'a> From<framing_sv2::Error> for Error<'a> {
impl From<framing_sv2::Error> for Error<'_> {
fn from(e: framing_sv2::Error) -> Self {
Error::FramingSv2(e)
}
}

impl<'a> From<std::io::Error> for Error<'a> {
impl From<std::io::Error> for Error<'_> {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}

impl<'a> From<std::num::ParseIntError> for Error<'a> {
impl From<std::num::ParseIntError> for Error<'_> {
fn from(e: std::num::ParseIntError) -> Self {
Error::ParseInt(e)
}
}

impl<'a> From<roles_logic_sv2::errors::Error> for Error<'a> {
impl From<roles_logic_sv2::errors::Error> for Error<'_> {
fn from(e: roles_logic_sv2::errors::Error) -> Self {
Error::RolesSv2Logic(e)
}
}

impl<'a> From<ConfigError> for Error<'a> {
impl From<ConfigError> for Error<'_> {
fn from(e: ConfigError) -> Self {
Error::BadConfigDeserialize(e)
}
}

impl<'a> From<async_channel::RecvError> for Error<'a> {
impl From<async_channel::RecvError> for Error<'_> {
fn from(e: async_channel::RecvError) -> Self {
Error::ChannelErrorReceiver(e)
}
}

impl<'a> From<tokio::sync::broadcast::error::RecvError> for Error<'a> {
impl From<tokio::sync::broadcast::error::RecvError> for Error<'_> {
fn from(e: tokio::sync::broadcast::error::RecvError) -> Self {
Error::TokioChannelErrorRecv(e)
}
Expand Down Expand Up @@ -176,7 +176,7 @@ impl<'a> From<async_channel::SendError<roles_logic_sv2::mining_sv2::SetNewPrevHa
}
}

impl<'a> From<async_channel::SendError<(ExtendedExtranonce, u32)>> for Error<'a> {
impl From<async_channel::SendError<(ExtendedExtranonce, u32)>> for Error<'_> {
fn from(e: async_channel::SendError<(ExtendedExtranonce, u32)>) -> Self {
Error::ChannelErrorSender(ChannelSendError::Extranonce(e))
}
Expand Down Expand Up @@ -212,13 +212,13 @@ impl<'a>
}
}

impl<'a> From<ParseLengthError> for Error<'a> {
impl From<ParseLengthError> for Error<'_> {
fn from(e: ParseLengthError) -> Self {
Error::Uint256Conversion(e)
}
}

impl<'a> From<std::convert::Infallible> for Error<'a> {
impl From<std::convert::Infallible> for Error<'_> {
fn from(e: std::convert::Infallible) -> Self {
Error::Infallible(e)
}
Expand Down
2 changes: 1 addition & 1 deletion roles/jd-client/src/lib/job_declarator/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
None
}
})
.ok_or_else(|| Error::UnknownRequestId(message.request_id))?;
.ok_or(Error::UnknownRequestId(message.request_id))?;

Check warning on line 70 in roles/jd-client/src/lib/job_declarator/message_handler.rs

View check run for this annotation

Codecov / codecov/patch

roles/jd-client/src/lib/job_declarator/message_handler.rs#L70

Added line #L70 was not covered by tests

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
Expand Down
2 changes: 2 additions & 0 deletions roles/test-utils/mining-device-sv1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ serde_json = { version = "1.0.64", default-features = false, features = ["alloc"
v1 = { path="../../../protocols/v1", package="sv1_api" }
num-bigint = "0.4.3"
num-traits = "0.2.15"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
5 changes: 3 additions & 2 deletions roles/test-utils/mining-device-sv1/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use num_bigint::BigUint;
use num_traits::FromPrimitive;
use roles_logic_sv2::utils::Mutex;
use std::{sync::Arc, time};
use tracing::info;

use stratum_common::bitcoin::util::uint::Uint256;
use v1::{
Expand Down Expand Up @@ -234,7 +235,7 @@ impl Client {
) {
// If we have a line (1 line represents 1 sv1 incoming message), then handle that message
if let Ok(line) = incoming_message {
println!(
info!(
"CLIENT {} - Received: {}",
self_.safe_lock(|s| s.client_id).unwrap(),
line
Expand All @@ -254,7 +255,7 @@ impl Client {
/// Send SV1 messages to the receiver_outgoing which writes to the socket (aka Upstream node)
async fn send_message(sender: Sender<String>, msg: json_rpc::Message) {
let msg = format!("{}\n", serde_json::to_string(&msg).unwrap());
println!(" - Send: {}", &msg);
info!(" - Send: {}", &msg);
sender.send(msg).await.unwrap();
}

Expand Down
1 change: 1 addition & 0 deletions roles/test-utils/mining-device-sv1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub(crate) use client::Client;

#[async_std::main]
async fn main() {
tracing_subscriber::fmt().init();
const ADDR: &str = "127.0.0.1:34255";
Client::connect(
80,
Expand Down
3 changes: 2 additions & 1 deletion roles/test-utils/mining-device-sv1/src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
hashes::{sha256d::Hash as DHash, Hash},
util::uint::Uint256,
};
use tracing::info;

/// A mock representation of a Mining Device that produces block header hashes to be submitted by
/// the `Client` to the Upstream node (either a SV1 Pool server or a SV1 <-> SV2 Translator Proxy
Expand Down Expand Up @@ -75,7 +76,7 @@
hash.reverse();
let hash = Uint256::from_be_bytes(hash);
if hash < *self.target.as_ref().ok_or(())? {
println!(
info!(

Check warning on line 79 in roles/test-utils/mining-device-sv1/src/miner.rs

View check run for this annotation

Codecov / codecov/patch

roles/test-utils/mining-device-sv1/src/miner.rs#L79

Added line #L79 was not covered by tests
"Found share with nonce: {}, for target: {:?}, hash: {:?}",
header.nonce, self.target, hash
);
Expand Down
36 changes: 18 additions & 18 deletions roles/translator/src/lib/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub enum Error<'a> {
Sv1MessageTooLong,
}

impl<'a> fmt::Display for Error<'a> {
impl fmt::Display for Error<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use Error::*;
match self {
Expand Down Expand Up @@ -118,49 +118,49 @@ impl<'a> fmt::Display for Error<'a> {
}
}

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

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

impl<'a> From<framing_sv2::Error> for Error<'a> {
impl From<framing_sv2::Error> for Error<'_> {
fn from(e: framing_sv2::Error) -> Self {
Error::FramingSv2(e)
}
}

impl<'a> From<std::io::Error> for Error<'a> {
impl From<std::io::Error> for Error<'_> {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}

impl<'a> From<std::num::ParseIntError> for Error<'a> {
impl From<std::num::ParseIntError> for Error<'_> {
fn from(e: std::num::ParseIntError) -> Self {
Error::ParseInt(e)
}
}

impl<'a> From<roles_logic_sv2::errors::Error> for Error<'a> {
impl From<roles_logic_sv2::errors::Error> for Error<'_> {
fn from(e: roles_logic_sv2::errors::Error) -> Self {
Error::RolesSv2Logic(e)
}
}

impl<'a> From<serde_json::Error> for Error<'a> {
impl From<serde_json::Error> for Error<'_> {
fn from(e: serde_json::Error) -> Self {
Error::BadSerdeJson(e)
}
}

impl<'a> From<ConfigError> for Error<'a> {
impl From<ConfigError> for Error<'_> {
fn from(e: ConfigError) -> Self {
Error::BadConfigDeserialize(e)
}
Expand All @@ -172,20 +172,20 @@ impl<'a> From<v1::error::Error<'a>> for Error<'a> {
}
}

impl<'a> From<async_channel::RecvError> for Error<'a> {
impl From<async_channel::RecvError> for Error<'_> {
fn from(e: async_channel::RecvError) -> Self {
Error::ChannelErrorReceiver(e)
}
}

impl<'a> From<tokio::sync::broadcast::error::RecvError> for Error<'a> {
impl From<tokio::sync::broadcast::error::RecvError> for Error<'_> {
fn from(e: tokio::sync::broadcast::error::RecvError) -> Self {
Error::TokioChannelErrorRecv(e)
}
}

//*** LOCK ERRORS ***
impl<'a, T> From<PoisonError<T>> for Error<'a> {
impl<T> From<PoisonError<T>> for Error<'_> {
fn from(_e: PoisonError<T>) -> Self {
Error::PoisonLock
}
Expand Down Expand Up @@ -216,13 +216,13 @@ impl<'a> From<tokio::sync::broadcast::error::SendError<Notify<'a>>> for Error<'a
}
}

impl<'a> From<async_channel::SendError<v1::Message>> for Error<'a> {
impl From<async_channel::SendError<v1::Message>> for Error<'_> {
fn from(e: async_channel::SendError<v1::Message>) -> Self {
Error::ChannelErrorSender(ChannelSendError::V1Message(e))
}
}

impl<'a> From<async_channel::SendError<(ExtendedExtranonce, u32)>> for Error<'a> {
impl From<async_channel::SendError<(ExtendedExtranonce, u32)>> for Error<'_> {
fn from(e: async_channel::SendError<(ExtendedExtranonce, u32)>) -> Self {
Error::ChannelErrorSender(ChannelSendError::Extranonce(e))
}
Expand Down Expand Up @@ -258,25 +258,25 @@ impl<'a>
}
}

impl<'a> From<Vec<u8>> for Error<'a> {
impl From<Vec<u8>> for Error<'_> {
fn from(e: Vec<u8>) -> Self {
Error::VecToSlice32(e)
}
}

impl<'a> From<ParseLengthError> for Error<'a> {
impl From<ParseLengthError> for Error<'_> {
fn from(e: ParseLengthError) -> Self {
Error::Uint256Conversion(e)
}
}

impl<'a> From<SetDifficulty> for Error<'a> {
impl From<SetDifficulty> for Error<'_> {
fn from(e: SetDifficulty) -> Self {
Error::SetDifficultyToMessage(e)
}
}

impl<'a> From<std::convert::Infallible> for Error<'a> {
impl From<std::convert::Infallible> for Error<'_> {
fn from(e: std::convert::Infallible) -> Self {
Error::Infallible(e)
}
Expand Down
Loading