Skip to content

Commit

Permalink
Update CpuMiner use tokio rather then async_std
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3 committed Jun 19, 2024
1 parent f7d8378 commit 2efa74b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions roles/Cargo.lock

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

4 changes: 2 additions & 2 deletions roles/test-utils/mining-device/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ codec_sv2 = { version = "^1.0.1", path = "../../../protocols/v2/codec-sv2", feat
roles_logic_sv2 = { version = "1.0.0", path = "../../../protocols/v2/roles-logic-sv2" }
const_sv2 = { version = "1.0.0", path = "../../../protocols/v2/const-sv2" }
async-channel = "1.5.1"
async-std={version = "1.8.0", features = ["attributes"]}
binary_sv2 = { version = "1.0.0", path = "../../../protocols/v2/binary-sv2/binary-sv2" }
network_helpers_sv2 = { version = "2.0.0", path = "../../roles-utils/network-helpers", features=["async_std"] }
network_helpers_sv2 = { version = "2.0.0", path = "../../roles-utils/network-helpers", features=["tokio"] }
buffer_sv2 = { version = "1.0.0", path = "../../../utils/buffer"}
async-recursion = "0.3.2"
rand = "0.8.4"
Expand All @@ -24,3 +23,4 @@ clap = { version = "^4.5.4", features = ["derive"] }
tracing = { version = "0.1" }
tracing-subscriber = "0.3"
sha2 = "0.10.6"
tokio = "^1.36.0"
24 changes: 13 additions & 11 deletions roles/test-utils/mining-device/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use async_std::net::TcpStream;
use key_utils::Secp256k1PublicKey;
use network_helpers_sv2::Connection;
use network_helpers_sv2::noise_connection_tokio::Connection;
use roles_logic_sv2::utils::Id;
use std::{net::SocketAddr, sync::Arc, thread::sleep, time::Duration};
use std::{
net::{SocketAddr, ToSocketAddrs},
sync::Arc,
thread::sleep,
time::Duration,
};
use tokio::net::TcpStream;

use async_std::net::ToSocketAddrs;
use clap::Parser;
use rand::{thread_rng, Rng};
use std::time::Instant;
Expand Down Expand Up @@ -57,14 +61,12 @@ async fn connect(
let address = address
.clone()
.to_socket_addrs()
.await
.expect("Invalid pool address, use one of this formats: ip:port, domain:port")
.next()
.expect("Invalid pool address, use one of this formats: ip:port, domain:port");
info!("Connecting to pool at {}", address);
let socket = loop {
let pool =
async_std::future::timeout(Duration::from_secs(5), TcpStream::connect(address)).await;
let pool = tokio::time::timeout(Duration::from_secs(5), TcpStream::connect(address)).await;
match pool {
Ok(result) => match result {
Ok(socket) => break socket,
Expand All @@ -85,15 +87,15 @@ async fn connect(
info!("Pool tcp connection established at {}", address);
let address = socket.peer_addr().unwrap();
let initiator = Initiator::new(pub_key.map(|e| e.0));
let (receiver, sender): (Receiver<EitherFrame>, Sender<EitherFrame>) =
Connection::new(socket, codec_sv2::HandshakeRole::Initiator(initiator), 10)
let (receiver, sender, _, _): (Receiver<EitherFrame>, Sender<EitherFrame>, _, _) =
Connection::new(socket, codec_sv2::HandshakeRole::Initiator(initiator))
.await
.unwrap();
info!("Pool noise connection established at {}", address);
Device::start(receiver, sender, address, device_id, user_id, handicap).await
}

#[async_std::main]
#[tokio::main]
async fn main() {
let args = Args::parse();
tracing_subscriber::fmt::init();
Expand Down Expand Up @@ -303,7 +305,7 @@ impl Device {
.unwrap();
});

async_std::task::spawn(async move {
tokio::task::spawn(async move {
let recv = share_recv.clone();
loop {
let (nonce, job_id, version, ntime) = recv.recv().await.unwrap();
Expand Down

0 comments on commit 2efa74b

Please sign in to comment.