Skip to content

channels_sv2 hardening companion - #826

Draft
plebhash wants to merge 7 commits into
stratum-mining:mainfrom
plebhash:2026-09-02-channels-sv2-hardening
Draft

channels_sv2 hardening companion#826
plebhash wants to merge 7 commits into
stratum-mining:mainfrom
plebhash:2026-09-02-channels-sv2-hardening

Conversation

@plebhash

@plebhash plebhash commented Sep 2, 2026

Copy link
Copy Markdown
Member

companion stratum-mining/stratum#2336

draft due to e1522ca (avoids accidental merging)

but ready for review

… code

channels_sv2 now refuses a zero max_target at the channel boundary:
StandardChannel/ExtendedChannel::new_for_pool return
OpenChannelInvalidMaxTarget and update_channel returns
UpdateChannelInvalidMaxTarget, both carrying the
max-target-out-of-range error code. Route them the way the
invalid-nominal-hashrate variants already are: OpenMiningChannel.Error
on open, UpdateChannel.Error on update. Without this the open path
disconnected the downstream on a well-formed but unattainable request,
and the update path hit its `unreachable!()` arm, so one
UpdateChannel { max_target: 0 } from any downstream took the pool down.

Companion of stratum-mining/stratum #2333.
Downstream (server channels): channels_sv2 now refuses a zero
max_target with OpenChannelInvalidMaxTarget /
UpdateChannelInvalidMaxTarget, carrying the max-target-out-of-range
error code. Route them the way the invalid-nominal-hashrate variants
already are, so the downstream gets OpenMiningChannel.Error /
UpdateChannel.Error instead of a disconnect or a bare
"internal-error".

Upstream (client channel): ExtendedChannel::new and set_target are now
fallible and return InvalidTarget for a zero target, since no share can
meet one and its difficulty is not representable in share accounting.
An upstream advertising such a target is a protocol-level error, so
handle it like a malformed SetExtranoncePrefix: log and fall back.

Companion of stratum-mining/stratum #2333.
channels_sv2's client ExtendedChannel::new and set_target are now
fallible and return InvalidTarget for a zero target, since no share can
meet one and its difficulty is not representable in share accounting.
Every translator channel takes its target from the upstream
(OpenExtendedMiningChannelSuccess.target on open, SetTarget afterwards),
so an error there means the upstream sent something unattainable: log
and fall back, with a new FailedToProcessSetTarget kind next to the
existing FailedToProcess* ones for the SetTarget path. The aggregated
downstream channels copy the aggregated channel's own, already
validated target, so a failure there is an internal inconsistency and
shuts down like the missing-allocator case beside it.

Companion of stratum-mining/stratum #2333.
channels_sv2's client ExtendedJob is now a struct with named fields
instead of a (message, extranonce_prefix, target) tuple. The
aggregated-channel handling read the job message positionally; it
reads job_message now. No behavior change.

Companion of stratum-mining/stratum #2336.
…ling policy

channels_sv2's GroupChannel constructors take version_rolling_allowed
instead of hardcoding it, and ExtendedChannel::on_group_channel_job now
refuses a group job that permits rolling on a channel whose policy
forbids it. The pool opens every extended channel with rolling allowed,
so the group channel is built with the same value.

Companion of stratum-mining/stratum #2336.
…ion-rolling policy

channels_sv2's GroupChannel constructors take version_rolling_allowed
instead of hardcoding it, and ExtendedChannel::on_group_channel_job now
refuses a group job that permits rolling on a channel whose policy
forbids it. The JDC opens every downstream extended channel with rolling
allowed, so the group channel is built with the same value.

Companion of stratum-mining/stratum #2336.
@plebhash
plebhash force-pushed the 2026-09-02-channels-sv2-hardening branch from 4cb31a0 to 1dd6808 Compare September 6, 2026 22:31
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.

1 participant