Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
588c38d
add new handlers_sv2 crate with async trait feature
Shourya742 Jul 20, 2025
bebd489
update protocol crates for new handler crate
Shourya742 Jul 20, 2025
00c4019
update the corresponding lock files all dependent workspaces
Shourya742 Jul 20, 2025
18202de
feat: add `External` variant to `HandlerError` for user-defined errors
Shourya742 Jul 22, 2025
9f19be3
handlers refactor
Shourya742 Jul 8, 2025
bfc7dd4
change return type to unit type
Shourya742 Jul 17, 2025
9cb881c
add async traits
Shourya742 Jul 17, 2025
2829667
move new handler code inside handlers-sv2
Shourya742 Jul 17, 2025
5838a84
expose new handlers module via roles-logic-sv2
Shourya742 Jul 20, 2025
25781f0
extend error variant in handler and expose SupportedChannelTypes
Shourya742 Jul 20, 2025
c8b0df1
new tproxy
GitGab19 Jun 16, 2025
2213a02
initial draft
GitGab19 Jun 18, 2025
af7642d
draft n.2
GitGab19 Jun 19, 2025
f9bdde3
fix errors and remove some warnings
Shourya742 Jun 20, 2025
0ad17eb
improved logging
Shourya742 Jun 20, 2025
50d129b
improve downstream and sv1server logging
Shourya742 Jun 20, 2025
8f463cf
Refactor Downstream and ChannelManager for improved message handling
GitGab19 Jun 20, 2025
ea05cf6
uncomplete bootstrap flow
Shourya742 Jun 20, 2025
0523c02
add tproxy end-to-end flow, without submit share
Shourya742 Jun 22, 2025
33146d0
some auxillary change
Shourya742 Jun 22, 2025
f72fe92
add share validation logic
Shourya742 Jun 23, 2025
ee6a8e5
structured the bootstrap steps, fixed extranonce length and removed s…
Shourya742 Jun 23, 2025
94f0c90
store user_identity and hashrate into pending_channels hashmap to get…
GitGab19 Jun 24, 2025
4bb72a9
Refactor SV1 and SV2 modules for improved structure and functionality
GitGab19 Jun 25, 2025
81020f4
Refactor Downstream and SV1Server for enhanced message handling
GitGab19 Jun 25, 2025
45ccf00
Enhance SV1Server and TranslatorSv2 with configuration integration
GitGab19 Jun 25, 2025
ffca016
Update SV1Server to incorporate configurable extranonce size and impr…
GitGab19 Jun 25, 2025
9cbf9a8
Enhance TProxy configuration and error handling
GitGab19 Jun 26, 2025
eaeb560
Refactor Downstream struct to enhance authorization and user identity…
GitGab19 Jun 27, 2025
5033912
Refactor TProxy configuration and channel management for enhanced fle…
GitGab19 Jun 27, 2025
6dd18bf
Refactor ChannelManager for enhanced aggregated mode handling
GitGab19 Jun 29, 2025
538d5d3
add shutdown signalling
Shourya742 Jun 28, 2025
7cd19db
make setup connection method in upstream not take mut
Shourya742 Jun 28, 2025
90f1e28
separate downstream to downstream data and downstream channel manager
Shourya742 Jun 29, 2025
fdfe479
restructure sv1 server to channel specific and data specific structs
Shourya742 Jun 29, 2025
7814fd6
split channel manager struct into data and channel counter part
Shourya742 Jun 29, 2025
58f0779
split upstream structure to channel and data specific counterparts
Shourya742 Jun 29, 2025
686d539
change managers to states
Shourya742 Jun 29, 2025
0cb4a74
add ra-target in gitignore
Shourya742 Jun 29, 2025
9df5244
structure arc around sv1_server and channel_manager and add exit on main
Shourya742 Jun 29, 2025
5431045
club on_upstream_message and on_downstream_message into run channel m…
Shourya742 Jun 30, 2025
9ec07bf
club spawn downstream receiver and sender into run_downstream_tasks
Shourya742 Jun 30, 2025
afeee46
move downstream to its own separate module
Shourya742 Jun 30, 2025
1787352
club upstream and receiver task
Shourya742 Jun 30, 2025
c8a12ae
resolve merge conflicts
Shourya742 Jun 30, 2025
390b7b2
revive tproxy error handling
Shourya742 Jul 1, 2025
8e3392f
add new handle_status result
Shourya742 Jul 1, 2025
7925c20
adapt status with respect to new handle_result
Shourya742 Jul 1, 2025
d81b2fc
adapt downstream to new handle result
Shourya742 Jul 1, 2025
150174a
club reader and writer task in tproxy together
Shourya742 Jul 1, 2025
4c95585
add handle error to upstream and channel_manager and sv1_server
Shourya742 Jul 1, 2025
e03a3c1
improve shutdown handling and disconnection using status
Shourya742 Jul 1, 2025
9e9d305
improve downstream module with better error handling and module struc…
Shourya742 Jul 2, 2025
972bc45
improve error handling in upstream and restructure the upstream modul…
Shourya742 Jul 2, 2025
6d17518
modularize channel manager and improve error handling
Shourya742 Jul 2, 2025
6cf739b
decouple the sv1 server and improve error handling
Shourya742 Jul 2, 2025
005cf19
remove other warnings and trim the setup
Shourya742 Jul 2, 2025
61528f1
remove handle result status macro
Shourya742 Jul 2, 2025
d6c018a
Update tproxy configuration and improve message handling
GitGab19 Jul 2, 2025
816d79f
make sure downstream doesn't close sv1 server channels on its disconn…
Shourya742 Jul 3, 2025
f048f52
modify config to receive group of upstream and make corresponding cha…
Shourya742 Jul 3, 2025
95597bf
add fallback during upstream bootstrap
Shourya742 Jul 3, 2025
250d8d8
add upstream fallback during fully connected normal flow
Shourya742 Jul 3, 2025
e2661b1
remove all downstream info once the upstream changes
Shourya742 Jul 3, 2025
bb00f59
add task manager
Shourya742 Jul 4, 2025
cbab5bf
migrate all spawns to use task_manager
Shourya742 Jul 4, 2025
51ab966
Enhance message handling and logging in SV1 and SV2
GitGab19 Jul 5, 2025
0f81d54
Implement first notify handling in downstream processing
GitGab19 Jul 5, 2025
7cba1bc
Enhance documentation and error handling in Tproxy components
GitGab19 Jul 5, 2025
da26c90
Replace translator with new-tproxy implementation
GitGab19 Jul 5, 2025
1aae7c7
Update integration tests for new translator implementation
GitGab19 Jul 5, 2025
693b12b
Clean up old translator implementation
GitGab19 Jul 5, 2025
d94d0f2
Fix clippy warnings in translator
GitGab19 Jul 5, 2025
f38ecc5
Update translator README for new implementation
GitGab19 Jul 5, 2025
09baa00
Refactor code for clarity and consistency in utils and channel manager
GitGab19 Jul 5, 2025
c474cb1
Refactor whitespace in SV2 translator configuration for improved read…
GitGab19 Jul 5, 2025
92c4323
make translator clippy approved
Shourya742 Jul 6, 2025
60d5ad8
add better logs to status and mod.rs
Shourya742 Jul 6, 2025
580317d
ignore failing IT
Shourya742 Jul 6, 2025
d95d061
change from broadcast sender to receiver in downstream
Shourya742 Jul 6, 2025
2409f3d
Remove unnecessary sleep in job sending process in ChannelManager
GitGab19 Jul 7, 2025
d56dc79
Remove unnecessary ignore directives from integration tests to enable…
GitGab19 Jul 8, 2025
e23c9e9
make new tproxy compliant with new roles logic restructuring
Shourya742 Jul 20, 2025
6098484
adapt new tproxy to new roles-logic structure and migrate upstream to…
Shourya742 Jul 20, 2025
55577f3
migrate channel manager to new handler's async API's
Shourya742 Jul 20, 2025
3827597
update lock files
Shourya742 Jul 20, 2025
0466ee7
add reviewed changes
Shourya742 Jul 21, 2025
e5f3ed5
refactor error handling in handlers
Shourya742 Jul 22, 2025
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: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ cobertura.xml
/test/integration-tests/template-provider
**/template-provider
stratum-message-generator
*.log
*.log
.ra-target
27 changes: 26 additions & 1 deletion common/Cargo.lock

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

3 changes: 2 additions & 1 deletion protocols/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ members = [
"v2/sv2-ffi",
"v2/roles-logic-sv2",
"v2/channels-sv2",
"v2/parsers-sv2",
"v2/parsers-sv2",
"v2/handlers-sv2",
]

[profile.dev]
Expand Down
4 changes: 2 additions & 2 deletions protocols/v2/channels-sv2/src/client/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<'a> ExtendedChannel<'a> {
/// Called when a `NewExtendedMiningJob` message is received from upstream.
pub fn on_new_extended_mining_job(
&mut self,
new_extended_mining_job: NewExtendedMiningJob<'a>,
new_extended_mining_job: NewExtendedMiningJob<'static>,
) {
match new_extended_mining_job.min_ntime.clone().into_inner() {
Some(_min_ntime) => {
Expand Down Expand Up @@ -208,7 +208,7 @@ impl<'a> ExtendedChannel<'a> {
/// The chain tip information is not kept in the channel state.
pub fn on_set_new_prev_hash(
&mut self,
set_new_prev_hash: SetNewPrevHashMp<'a>,
set_new_prev_hash: SetNewPrevHashMp<'static>,
) -> Result<(), ExtendedChannelError> {
match self.future_jobs.remove(&set_new_prev_hash.job_id) {
Some(mut activated_job) => {
Expand Down
21 changes: 21 additions & 0 deletions protocols/v2/handlers-sv2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "handlers_sv2"
version = "0.1.0"
authors = ["The Stratum V2 Developers"]
edition = "2018"
readme = "README.md"
description = "Sv2 Message handlers"
documentation = "https://docs.rs/handlers_sv2"
license = "MIT OR Apache-2.0"
repository = "https://github.com/stratum-mining/stratum"
homepage = "https://stratumprotocol.org"
keywords = ["stratum", "mining", "bitcoin", "protocol"]

[dependencies]
trait-variant = "0.1.2"
parsers_sv2 = { path = "../parsers-sv2", version = "^0.1.0"}
binary_sv2 = { path = "../binary-sv2", version = "^3.0.0" }
common_messages_sv2 = { path = "../subprotocols/common-messages", version = "^5.0.0" }
mining_sv2 = { path = "../subprotocols/mining", version = "^4.0.0" }
template_distribution_sv2 = { path = "../subprotocols/template-distribution", version = "^3.0.0" }
job_declaration_sv2 = { path = "../subprotocols/job-declaration", version = "^4.0.0" }
162 changes: 162 additions & 0 deletions protocols/v2/handlers-sv2/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
use crate::error::HandlerError as Error;
use common_messages_sv2::{
ChannelEndpointChanged, Reconnect, SetupConnectionError, SetupConnectionSuccess, *,
};
use core::convert::TryInto;
use parsers_sv2::CommonMessages;

pub trait ParseCommonMessagesFromUpstreamSync {
fn handle_common_message(&mut self, message_type: u8, payload: &mut [u8]) -> Result<(), Error> {
let parsed: CommonMessages<'_> = (message_type, payload).try_into()?;
self.dispatch_common_message(parsed)
}

fn dispatch_common_message(&mut self, message: CommonMessages<'_>) -> Result<(), Error> {
match message {
CommonMessages::SetupConnectionSuccess(msg) => {
self.handle_setup_connection_success(msg)
}
CommonMessages::SetupConnectionError(msg) => self.handle_setup_connection_error(msg),
CommonMessages::ChannelEndpointChanged(msg) => {
self.handle_channel_endpoint_changed(msg)
}
CommonMessages::Reconnect(msg) => self.handle_reconnect(msg),

CommonMessages::SetupConnection(_) => {
Err(Error::UnexpectedMessage(MESSAGE_TYPE_SETUP_CONNECTION))
}
}
}

fn handle_setup_connection_success(&mut self, msg: SetupConnectionSuccess)
-> Result<(), Error>;

fn handle_setup_connection_error(&mut self, msg: SetupConnectionError) -> Result<(), Error>;

fn handle_channel_endpoint_changed(&mut self, msg: ChannelEndpointChanged)
-> Result<(), Error>;

fn handle_reconnect(&mut self, msg: Reconnect) -> Result<(), Error>;
}

#[trait_variant::make(Send)]
pub trait ParseCommonMessagesFromUpstreamAsync {
async fn handle_common_message(
&mut self,
message_type: u8,
payload: &mut [u8],
) -> Result<(), Error> {
let parsed: Result<CommonMessages<'_>, _> = (message_type, payload).try_into();
async move {
let parsed = parsed?;
self.dispatch_common_message(parsed).await
}
}

async fn dispatch_common_message(&mut self, message: CommonMessages<'_>) -> Result<(), Error> {
async move {
match message {
CommonMessages::SetupConnectionSuccess(msg) => {
self.handle_setup_connection_success(msg).await
}
CommonMessages::SetupConnectionError(msg) => {
self.handle_setup_connection_error(msg).await
}
CommonMessages::ChannelEndpointChanged(msg) => {
self.handle_channel_endpoint_changed(msg).await
}
CommonMessages::Reconnect(msg) => self.handle_reconnect(msg).await,

CommonMessages::SetupConnection(_) => {
Err(Error::UnexpectedMessage(MESSAGE_TYPE_SETUP_CONNECTION))
}
}
}
}

async fn handle_setup_connection_success(
&mut self,
msg: SetupConnectionSuccess,
) -> Result<(), Error>;

async fn handle_setup_connection_error(
&mut self,
msg: SetupConnectionError,
) -> Result<(), Error>;

async fn handle_channel_endpoint_changed(
&mut self,
msg: ChannelEndpointChanged,
) -> Result<(), Error>;

async fn handle_reconnect(&mut self, msg: Reconnect) -> Result<(), Error>;
}

pub trait ParseCommonMessagesFromDownstreamSync
where
Self: Sized,
{
fn handle_common_message(&mut self, message_type: u8, payload: &mut [u8]) -> Result<(), Error> {
let parsed: CommonMessages<'_> = (message_type, payload).try_into()?;
self.dispatch_common_message(parsed)
}

fn dispatch_common_message(&mut self, message: CommonMessages<'_>) -> Result<(), Error> {
match message {
CommonMessages::SetupConnectionSuccess(_) => Err(Error::UnexpectedMessage(
MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS,
)),
CommonMessages::SetupConnectionError(_) => Err(Error::UnexpectedMessage(
MESSAGE_TYPE_SETUP_CONNECTION_ERROR,
)),
CommonMessages::ChannelEndpointChanged(_) => Err(Error::UnexpectedMessage(
MESSAGE_TYPE_CHANNEL_ENDPOINT_CHANGED,
)),
CommonMessages::Reconnect(_) => Err(Error::UnexpectedMessage(MESSAGE_TYPE_RECONNECT)),

CommonMessages::SetupConnection(msg) => self.handle_setup_connection(msg),
}
}

fn handle_setup_connection(&mut self, msg: SetupConnection) -> Result<(), Error>;
}

#[trait_variant::make(Send)]
pub trait ParseCommonMessagesFromDownstreamAsync
where
Self: Sized,
{
async fn handle_common_message(
&mut self,
message_type: u8,
payload: &mut [u8],
) -> Result<(), Error> {
let parsed: Result<CommonMessages<'_>, _> = (message_type, payload).try_into();
async move {
let parsed = parsed?;
self.dispatch_common_message(parsed).await
}
}

async fn dispatch_common_message(&mut self, message: CommonMessages<'_>) -> Result<(), Error> {
async move {
match message {
CommonMessages::SetupConnectionSuccess(_) => Err(Error::UnexpectedMessage(
MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS,
)),
CommonMessages::SetupConnectionError(_) => Err(Error::UnexpectedMessage(
MESSAGE_TYPE_SETUP_CONNECTION_ERROR,
)),
CommonMessages::ChannelEndpointChanged(_) => Err(Error::UnexpectedMessage(
MESSAGE_TYPE_CHANNEL_ENDPOINT_CHANGED,
)),
CommonMessages::Reconnect(_) => {
Err(Error::UnexpectedMessage(MESSAGE_TYPE_RECONNECT))
}
CommonMessages::SetupConnection(msg) => self.handle_setup_connection(msg).await,
}
}
}

async fn handle_setup_connection(&mut self, msg: SetupConnection) -> Result<(), Error>;
}
16 changes: 16 additions & 0 deletions protocols/v2/handlers-sv2/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use parsers_sv2::ParserError;

#[derive(Debug)]
pub enum HandlerError {
UnexpectedMessage(u8),
ParserError(ParserError),
OpenStandardMiningChannelError,
OpenExtendedMiningChannelError,
External(Box<dyn std::error::Error + Send + Sync>),
}

impl From<ParserError> for HandlerError {
fn from(value: ParserError) -> HandlerError {
HandlerError::ParserError(value)
}
}
Loading