Skip to content

Commit 93a822f

Browse files
GitGab19Shourya742plebhash
committed
feat(translator): new modular translator proxy with channel aggregation and failover
Replace existing translator proxy with new implementation featuring: - Aggregated/non-aggregated channel modes (shared vs individual upstream channels) - Stale share rejection with early SV1 share validation - Automatic failover to secondary upstream on connection issues - Improved modularity and extensibility for future features - Integration with newer client-channel APIs from stratum-mining#1724 Co-authored-by: bit-aloo <[email protected]> Co-authored-by: plebhash <[email protected]>
1 parent a73f70c commit 93a822f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+7396
-4199
lines changed

common/Cargo.lock

Lines changed: 1466 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocols/v1/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sv1_api"
3-
version = "2.0.0"
3+
version = "2.1.0"
44
authors = ["The Stratum V2 Developers"]
55
edition = "2021"
66
readme = "README.md"

protocols/v1/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub enum Error<'a> {
3131
/// Errors if server does not recognize the client's `id`.
3232
UnknownID(u64),
3333
InvalidVersionMask(HexU32Be),
34+
/// Errors when an unexpected or unsupported message/method is called.
35+
UnexpectedMessage(String),
3436
}
3537

3638
impl std::fmt::Display for Error<'_> {
@@ -70,6 +72,7 @@ impl std::fmt::Display for Error<'_> {
7072
),
7173
Error::UnknownID(e) => write!(f, "Server did not recognize the client id: `{e}`."),
7274
Error::InvalidVersionMask(e) => write!(f, "First 3 bits of version rolling mask must be 0 and last 13 bits of version rolling mask must be 0. Version rolling mask is: `{:b}`.", e.0),
75+
Error::UnexpectedMessage(method) => write!(f, "Unexpected or unsupported message/method called: `{method}`."),
7376
}
7477
}
7578
}

roles/Cargo.lock

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

roles/jd-client/src/lib/task_manager.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ impl TaskManager {
3333
///
3434
/// # Arguments
3535
/// * `fut` - The future to spawn as a task
36-
#[track_caller]
3736
pub fn spawn<F>(&self, fut: F)
3837
where
3938
F: std::future::Future<Output = ()> + Send + 'static,
4039
{
41-
use tracing::Instrument;
42-
let location = std::panic::Location::caller();
43-
let span = tracing::trace_span!("task", file = location.file(),);
44-
45-
let handle = tokio::spawn(fut.instrument(span));
40+
let handle = tokio::spawn(async move {
41+
fut.await;
42+
});
4643
self.tasks.lock().unwrap().push(handle);
4744
}
4845

roles/roles-utils/network-helpers/src/sv1_connection.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use tokio::{
66
net::TcpStream,
77
};
88
use tokio_util::codec::{FramedRead, LinesCodec};
9+
use tracing::{error, trace, warn};
910

1011
/// Represents a connection between two roles communicating using SV1 protocol.
1112
///
@@ -70,11 +71,11 @@ impl ConnectionSV1 {
7071
tokio::spawn(async move {
7172
tokio::select! {
7273
_ = Self::run_reader(buffer_read_half, sender_incoming.clone()) => {
73-
tracing::info!("Reader task exited. Closing writer sender.");
74+
trace!("Reader task exited. Closing writer sender.");
7475
connection_state.close();
7576
}
7677
_ = Self::run_writer(buffer_write_half, receiver_outgoing.clone()) => {
77-
tracing::info!("Writer task exited.Closing reader sender.");
78+
trace!("Writer task exited. Closing reader sender.");
7879
connection_state.close();
7980
}
8081
}
@@ -96,16 +97,16 @@ impl ConnectionSV1 {
9697
Ok(line) => match serde_json::from_str::<json_rpc::Message>(&line) {
9798
Ok(msg) => {
9899
if sender.send(msg).await.is_err() {
99-
tracing::warn!("Receiver dropped, stopping reader");
100+
warn!("Receiver dropped, stopping reader");
100101
break;
101102
}
102103
}
103104
Err(e) => {
104-
tracing::error!("Failed to deserialize message: {e:?}");
105+
error!("Failed to deserialize message: {e:?}");
105106
}
106107
},
107108
Err(e) => {
108-
tracing::error!("Error reading from stream: {e:?}");
109+
error!("Error reading from stream: {e:?}");
109110
break;
110111
}
111112
}
@@ -121,16 +122,16 @@ impl ConnectionSV1 {
121122
Ok(line) => {
122123
let data = format!("{line}\n");
123124
if writer.write_all(data.as_bytes()).await.is_err() {
124-
tracing::error!("Failed to write to stream");
125+
error!("Failed to write to stream");
125126
break;
126127
}
127128
if writer.flush().await.is_err() {
128-
tracing::error!("Failed to flush writer.");
129+
error!("Failed to flush writer.");
129130
break;
130131
}
131132
}
132133
Err(e) => {
133-
tracing::error!("Failed to serialize message: {e:?}");
134+
error!("Failed to serialize message: {e:?}");
134135
break;
135136
}
136137
}

roles/translator/Cargo.toml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[package]
22
name = "translator_sv2"
3-
version = "1.0.0"
3+
version = "2.0.0"
44
authors = ["The Stratum V2 Developers"]
55
edition = "2021"
6-
description = "Server used to bridge SV1 miners to SV2 pools"
6+
description = "SV1 to SV2 translation proxy"
77
documentation = "https://docs.rs/translator_sv2"
88
readme = "README.md"
99
homepage = "https://stratumprotocol.org"
1010
repository = "https://github.com/stratum-mining/stratum"
1111
license = "MIT OR Apache-2.0"
12-
keywords = ["stratum", "mining", "bitcoin", "protocol"]
12+
keywords = ["stratum", "mining", "bitcoin", "protocol", "translator", "proxy"]
1313

1414
[lib]
1515
name = "translator_sv2"
@@ -20,23 +20,18 @@ name = "translator_sv2"
2020
path = "src/main.rs"
2121

2222
[dependencies]
23-
stratum-common = { path = "../../common", features = ["with_network_helpers"] }
23+
stratum-common = { path = "../../common" }
2424
async-channel = "1.5.1"
25-
async-recursion = "0.3.2"
2625
buffer_sv2 = { path = "../../utils/buffer" }
27-
once_cell = "1.12.0"
26+
network_helpers_sv2 = { path = "../roles-utils/network-helpers", features=["with_buffer_pool", "sv1"] }
27+
stratum_translation = { path = "../roles-utils/stratum-translation" }
2828
serde = { version = "1.0.89", default-features = false, features = ["derive", "alloc"] }
2929
serde_json = { version = "1.0.64", default-features = false, features = ["alloc"] }
30-
futures = "0.3.25"
3130
tokio = { version = "1.44.1", features = ["full"] }
3231
ext-config = { version = "0.14.0", features = ["toml"], package = "config" }
3332
tracing = { version = "0.1" }
3433
v1 = { path = "../../protocols/v1", package="sv1_api" }
35-
error_handling = { path = "../../utils/error-handling" }
3634
key-utils = { path = "../../utils/key-utils" }
37-
tokio-util = { version = "0.7.10", features = ["codec"] }
38-
rand = "0.8.4"
39-
primitive-types = "0.13.1"
4035
clap = { version = "4.5.39", features = ["derive"] }
4136
config_helpers_sv2 = { path = "../roles-utils/config-helpers" }
4237

0 commit comments

Comments
 (0)