Skip to content

Commit

Permalink
Fmt after rust-bitcoin migration to v.0.32.5
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGab19 committed Feb 17, 2025
1 parent 2aef93d commit 0b98b29
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 68 deletions.
17 changes: 7 additions & 10 deletions protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,18 @@ use mining_sv2::{
SubmitSharesStandard, Target,
};

use hex::DisplayHex;
use nohash_hasher::BuildNoHashHasher;
use std::{collections::HashMap, convert::TryInto, sync::Arc};
use template_distribution_sv2::{NewTemplate, SetNewPrevHash as SetNewPrevHashFromTp};
use hex::DisplayHex;

use tracing::{debug, error, info, trace, warn};

use stratum_common::{
bitcoin::{
block::{Header, Version},
CompactTarget,
hash_types,
hashes::sha256d::Hash,
TxOut,
},
use stratum_common::bitcoin::{
block::{Header, Version},
hash_types,
hashes::sha256d::Hash,
CompactTarget, TxOut,
};

/// A stripped type of `SetCustomMiningJob` without the (`channel_id, `request_id` and `token`)
Expand Down Expand Up @@ -1826,8 +1823,8 @@ impl ExtendedChannelKind {
mod test {
use super::*;
use binary_sv2::{Seq0255, B064K, U256};
use stratum_common::bitcoin::{Amount, PublicKey, Target, TxOut, WPubkeyHash};
use mining_sv2::OpenStandardMiningChannel;
use stratum_common::bitcoin::{Amount, PublicKey, Target, TxOut, WPubkeyHash};

const BLOCK_REWARD: u64 = 2_000_000_000;

Expand Down
6 changes: 3 additions & 3 deletions protocols/v2/roles-logic-sv2/src/job_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ use binary_sv2::B064K;
use mining_sv2::NewExtendedMiningJob;
use nohash_hasher::BuildNoHashHasher;
use std::{collections::HashMap, convert::TryInto};
use template_distribution_sv2::{NewTemplate, SetNewPrevHash};
use tracing::debug;
use stratum_common::{
bitcoin,
bitcoin::{
absolute::LockTime,
Amount,
blockdata::{
transaction::{OutPoint, Transaction, TxIn, TxOut, Version},
witness::Witness,
},
consensus,
consensus::Decodable,
Amount,
},
};
use template_distribution_sv2::{NewTemplate, SetNewPrevHash};
use tracing::debug;

#[derive(Debug)]
pub struct JobsCreators {
Expand Down
15 changes: 7 additions & 8 deletions protocols/v2/roles-logic-sv2/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ use std::{
use binary_sv2::{Seq064K, ShortTxId, U256};
use bitcoin::Block;
use job_declaration_sv2::{DeclareMiningJob, SubmitSolutionJd};
use primitive_types::U256 as U256Primitive;
use siphasher::sip::SipHasher24;
use stratum_common::{
bitcoin,
bitcoin::{
blockdata::block::{Header, Version},
consensus,
hash_types::{BlockHash, TxMerkleNode},
hashes::{sha256, sha256d::Hash as DHash, Hash},
secp256k1::{All, Secp256k1},
CompactTarget, consensus, PublicKey, ScriptBuf, Transaction, XOnlyPublicKey,
ScriptHash, WScriptHash,
CompactTarget, PublicKey, ScriptBuf, ScriptHash, Transaction, WScriptHash, XOnlyPublicKey,
},
};
use primitive_types::U256 as U256Primitive;
use tracing::error;

use crate::errors::Error;
Expand Down Expand Up @@ -403,8 +403,7 @@ pub fn hash_rate_to_target(

let mut h_times_s_array = [0u8; 32];
h_times_s_array[16..].copy_from_slice(&h_times_s.to_be_bytes());
let numerator =
two_to_256_minus_one - U256Primitive::from_big_endian(h_times_s_array.as_ref());
let numerator = two_to_256_minus_one - U256Primitive::from_big_endian(h_times_s_array.as_ref());

let mut target = numerator.div(denominator).to_big_endian();
target.reverse();
Expand Down Expand Up @@ -461,7 +460,8 @@ pub fn hash_rate_from_target(target: U256<'static>, share_per_min: f64) -> Resul
return Err(Error::HashrateError(InputError::DivisionByZero));
}
let shares_occurrency_frequence = from_u128_to_u256(shares_occurrency_frequence);
let target_plus_one = U256Primitive::from_big_endian(target_arr.as_ref()) + U256Primitive::one();
let target_plus_one =
U256Primitive::from_big_endian(target_arr.as_ref()) + U256Primitive::one();
let denominator = shares_occurrency_frequence
.mul(target_plus_one)
.div(U256Primitive::from(100));
Expand Down Expand Up @@ -971,8 +971,7 @@ mod tests {
use binary_sv2::{Seq0255, B064K, U256};
use rand::Rng;
use serde::Deserialize;
use std::convert::TryInto;
use std::num::ParseIntError;
use std::{convert::TryInto, num::ParseIntError};

fn decode_hex(s: &str) -> Result<Vec<u8>, ParseIntError> {
(0..s.len())
Expand Down
2 changes: 1 addition & 1 deletion roles/jd-client/src/lib/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ext_config::ConfigError;
use std::fmt;
use roles_logic_sv2::mining_sv2::{ExtendedExtranonce, NewExtendedMiningJob, SetCustomMiningJob};
use std::fmt;

pub type ProxyResult<'a, T> = core::result::Result<T, Error<'a>>;

Expand Down
16 changes: 9 additions & 7 deletions roles/jd-server/src/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ pub mod job_declarator;
pub mod mempool;
pub mod status;
use async_channel::{bounded, unbounded, Receiver, Sender};
use codec_sv2::{StandardEitherFrame, StandardSv2Frame};
use error_handling::handle_result;
use job_declarator::JobDeclarator;
use mempool::error::JdsMempoolError;
use roles_logic_sv2::utils::Mutex;
use std::{ops::Sub, sync::Arc};
use tokio::{select, task};
use tracing::{error, info, warn};
use codec_sv2::{StandardEitherFrame, StandardSv2Frame};
use key_utils::{Secp256k1PublicKey, Secp256k1SecretKey};
use mempool::error::JdsMempoolError;
use roles_logic_sv2::{
errors::Error, parsers::PoolMessages as JdsMessages, utils::CoinbaseOutput as CoinbaseOutput_,
errors::Error,
parsers::PoolMessages as JdsMessages,
utils::{CoinbaseOutput as CoinbaseOutput_, Mutex},
};
use serde::Deserialize;
use std::{
convert::{TryFrom, TryInto},
ops::Sub,
sync::Arc,
time::Duration,
};
use stratum_common::bitcoin::{Amount, ScriptBuf, TxOut};
use tokio::{select, task};
use tracing::{error, info, warn};

pub type Message = JdsMessages<'static>;
pub type StdFrame = StandardSv2Frame<Message>;
Expand Down
2 changes: 1 addition & 1 deletion roles/pool/src/lib/mining_pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ mod test {

use stratum_common::{
bitcoin,
bitcoin::{absolute::LockTime, consensus, Transaction, transaction::Version, Witness},
bitcoin::{absolute::LockTime, consensus, transaction::Version, Transaction, Witness},
};

use super::Configuration;
Expand Down
7 changes: 3 additions & 4 deletions roles/test-utils/mining-device-sv1/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
use std::{convert::TryInto, net::SocketAddr, ops::Div};
use crate::{job::Job, miner::Miner};
use async_channel::{bounded, Receiver, Sender};
use num_bigint::BigUint;
use num_traits::FromPrimitive;
use primitive_types::U256;
use roles_logic_sv2::utils::Mutex;
use std::{sync::Arc, time};
use std::{convert::TryInto, net::SocketAddr, ops::Div, sync::Arc, time};
use tokio::{
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
net::TcpStream,
task,
};
use tracing::{error, info, warn};
use primitive_types::U256;
use v1::{
client_to_server,
error::Error,
json_rpc, server_to_client,
utils::{Extranonce, HexU32Be},
ClientStatus, IsClient,
};
use crate::{job::Job, miner::Miner};

/// Represents the Mining Device client which is connected to a Upstream node (either a SV1 Pool
/// server or a SV1 <-> SV2 Translator Proxy server).
Expand Down
9 changes: 7 additions & 2 deletions roles/test-utils/mining-device-sv1/src/miner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use crate::job::Job;
use std::convert::TryInto;
use stratum_common::bitcoin::{blockdata::block::{Header,Version}, hash_types::{BlockHash, TxMerkleNode}, hashes::{sha256d::Hash as DHash, Hash}, CompactTarget};
use primitive_types::U256;
use std::convert::TryInto;
use stratum_common::bitcoin::{
blockdata::block::{Header, Version},
hash_types::{BlockHash, TxMerkleNode},
hashes::{sha256d::Hash as DHash, Hash},
CompactTarget,
};
use tracing::info;

/// A mock representation of a Mining Device that produces block header hashes to be submitted by
Expand Down
34 changes: 17 additions & 17 deletions roles/test-utils/mining-device/src/lib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
#![allow(clippy::option_map_unit_fn)]
use key_utils::Secp256k1PublicKey;
use network_helpers_sv2::noise_connection::Connection;
use roles_logic_sv2::utils::Id;
use std::{
net::{SocketAddr, ToSocketAddrs},
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
thread::available_parallelism,
time::Duration,
};
use tokio::net::TcpStream;
use async_channel::{Receiver, Sender};
use binary_sv2::u256_from_int;
use codec_sv2::{Initiator, StandardEitherFrame, StandardSv2Frame};
use key_utils::Secp256k1PublicKey;
use network_helpers_sv2::noise_connection::Connection;
use primitive_types::U256;
use rand::{thread_rng, Rng};
use roles_logic_sv2::{
common_messages_sv2::{Protocol, SetupConnection, SetupConnectionSuccess},
Expand All @@ -28,11 +18,21 @@ use roles_logic_sv2::{
parsers::{Mining, MiningDeviceMessages},
routing_logic::{CommonRoutingLogic, MiningRoutingLogic, NoRouting},
selectors::NullDownstreamMiningSelector,
utils::Mutex,
utils::{Id, Mutex},
};
use std::time::Instant;
use stratum_common::bitcoin::{blockdata::block::Header, hash_types::BlockHash, hashes::Hash, CompactTarget};
use primitive_types::U256;
use std::{
net::{SocketAddr, ToSocketAddrs},
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
thread::available_parallelism,
time::{Duration, Instant},
};
use stratum_common::bitcoin::{
blockdata::block::Header, hash_types::BlockHash, hashes::Hash, CompactTarget,
};
use tokio::net::TcpStream;
use tracing::{error, info};

pub async fn connect(
Expand Down
2 changes: 1 addition & 1 deletion roles/translator/src/lib/downstream_sv1/diff_management.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{Downstream, DownstreamMessages, SetDownstreamTarget};

use super::super::error::{Error, ProxyResult};
use primitive_types::U256;
use roles_logic_sv2::utils::Mutex;
use std::{ops::Div, sync::Arc};
use v1::json_rpc;
use primitive_types::U256;

impl Downstream {
/// initializes the timestamp and resets the number of submits for a connection.
Expand Down
29 changes: 15 additions & 14 deletions roles/translator/src/lib/proxy/bridge.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
use super::super::{
downstream_sv1::{DownstreamMessages, SetDownstreamTarget, SubmitShareWithChannelId},
error::{
Error::{self, PoisonLock},
ProxyResult,
},
status,
};
use async_channel::{Receiver, Sender};
use error_handling::handle_result;
use roles_logic_sv2::{
channel_logic::channel_factory::{ExtendedChannelKind, ProxyExtendedChannelFactory, Share},
channel_logic::channel_factory::{
ExtendedChannelKind, OnNewShare, ProxyExtendedChannelFactory, Share,
},
mining_sv2::{
ExtendedExtranonce, NewExtendedMiningJob, SetNewPrevHash, SubmitSharesExtended, Target,
},
parsers::Mining,
utils::{GroupId, Mutex},
Error as RolesLogicError,
};
use std::sync::Arc;
use tokio::{sync::broadcast, task::AbortHandle};
use v1::{client_to_server::Submit, server_to_client, utils::HexU32Be};
use super::super::{
downstream_sv1::{DownstreamMessages, SetDownstreamTarget, SubmitShareWithChannelId},
error::{
Error::{self, PoisonLock},
ProxyResult,
},
status,
};
use error_handling::handle_result;
use roles_logic_sv2::{channel_logic::channel_factory::OnNewShare, Error as RolesLogicError};
use tracing::{debug, error, info, warn};
use v1::{client_to_server::Submit, server_to_client, utils::HexU32Be};

/// Bridge between the SV2 `Upstream` and SV1 `Downstream` responsible for the following messaging
/// translation:
Expand Down Expand Up @@ -534,8 +536,7 @@ pub struct OpenSv1Downstream {
mod test {
use super::*;
use async_channel::bounded;
use stratum_common::bitcoin::{consensus, transaction::Version};
use stratum_common::bitcoin::absolute::LockTime;
use stratum_common::bitcoin::{absolute::LockTime, consensus, transaction::Version};

pub mod test_utils {
use super::*;
Expand Down

0 comments on commit 0b98b29

Please sign in to comment.