Skip to content

feat(jds): validate and bind user_identifier to downstream connections - #839

Draft
nulllpc wants to merge 1 commit into
stratum-mining:mainfrom
nulllpc:npc/authenticate-client-identity
Draft

feat(jds): validate and bind user_identifier to downstream connections#839
nulllpc wants to merge 1 commit into
stratum-mining:mainfrom
nulllpc:npc/authenticate-client-identity

Conversation

@nulllpc

@nulllpc nulllpc commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

This implements the identity tracking requirements for JDS to ensure reliable token allocation and job declaration activity.

  • Bind user_identifier to the Downstream state during AllocateMiningJobToken
  • Reject empty strings or mid-session mismatched identities with a new InvalidUserIdentifier disconnect error to enforce connection consistency
  • Remove raw user_identifier logging in the declaration handler to prevent unnecessary identity leakage
  • Pass the bound user_identity to JobValidationEngine::handle_set_custom_mining_job so upstream pools can authenticate the custom job
  • Add integration tests verifying JDS correctly disconnects downstreams that send empty or mismatched identities, while allowing replayed identities

Solves #779

This implements the identity tracking requirements for JDS to ensure
reliable token allocation and job declaration activity.

- Bind user_identifier to the Downstream state during
  AllocateMiningJobToken
- Reject empty strings or mid-session mismatched identities with a new
  InvalidUserIdentifier disconnect error to enforce connection
  consistency
- Remove raw user_identifier logging in the declaration handler to
  prevent unnecessary identity leakage
- Pass the bound user_identity to
  JobValidationEngine::handle_set_custom_mining_job so upstream pools
  can authenticate the custom job
- Add integration tests verifying JDS correctly disconnects downstreams
  that send empty or mismatched identities, while allowing replayed
  identities
@plebhash
plebhash self-requested a review September 8, 2026 17:09
Comment on lines +9 to +10
//! - `DeclareMiningJob` rejects a coinbase that does not carry exactly one input, without tearing
//! down the IPC connection.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this intentional?

Comment on lines +1619 to +1620
// This test verifies that JDS requires all subsequent token allocations on a single
// connection to use the exact same identity, preventing mid-session identity swapping.

@plebhash plebhash Sep 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm why isn't a JDC allowed to allocate tokens under different indentities?

maybe JDC opened multiple channels with Pool, each with a different user_identity

Comment on lines +1681 to +1682
// This test verifies that JDS accepts subsequent token allocations on a single
// connection as long as they use the exact same (replayed) identity.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm why isn't a JDC allowed to allocate tokens under different indentities?

maybe JDC opened multiple channels with Pool, each with a different user_identity

async fn handle_set_custom_mining_job(
&self,
downstream_id: DownstreamId,
user_identity: Option<String>,

@plebhash plebhash Sep 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this Option?

on Pool, every channel always has a user_identity

async fn handle_set_custom_mining_job(
&self,
downstream_id: DownstreamId,
user_identity: Option<String>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this Option?

on Pool, every channel always has a user_identity

Comment on lines +71 to +72
/// The authenticated user identity bound to this connection via AllocateMiningJobToken.
pub user_identity: SharedLock<Option<String>>,

@plebhash plebhash Sep 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think adding this parameter to Downstream is the right choice

this design seems heavily based around the assumption that every JDC will always have one single Mining Channel with Pool

while that's currently true with SRI Pool, that's not a restriction imposed by spec, and a JDC that opens multiple Channels is theoretically possible

we want to enforce cohesion between token allocation and user_identity... but enforcing 1 single user_identity per Connection seems like a misguided assumption

@plebhash plebhash left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're not yet in the right direction here

we should be touching JDS token_management/mod.rs and adding a new user_identity: String field to AllocatedTokenData and ActiveTokenData

(tbh I think those types deserve a dedicated commit turning them from tuples into structs)

then during the execution of JobDeclarator::handle_set_custom_mining_job we should make sure the channel's user_identity (passed from Pool) matches the one associated with the active token


#779 (comment)

@nulllpc

nulllpc commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @plebhash for the review. I'll refine the PR. I'll turn it into draft for now

@nulllpc
nulllpc marked this pull request as draft September 9, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants