channels_sv2: fix chain-tip transition correctness gaps in the job state machine - #2255
Merged
plebhash merged 4 commits intoAug 7, 2026
Merged
Conversation
plebhash
force-pushed
the
2026-08-03-fix-chain-tip-transitions
branch
from
August 7, 2026 00:11
b64326a to
2298b53
Compare
`JobStore::activate_future_job` returns `false` and no-ops when the `template_id` matches no queued future job. The server-side `GroupChannel` discarded that `bool`, unconditionally advanced its `chain_tip` and returned `Ok(())`, despite its own doc comment promising an error. The result was silent state corruption: subsequent group jobs were built against a tip whose job had never been activated. Propagate the activation result as `GroupChannelError::TemplateIdNotFound`, before the chain tip is touched, so the error path leaves channel state untouched. This mirrors what `server/standard.rs` and `server/extended.rs` already do.
… update `ExtendedChannel::on_chain_tip_update` is the JDC entry point for chain tip updates. It cleared future jobs and rotated past jobs into stale, but never transitioned `active_job`. A share arriving in the window before the next `SetCustomMiningJobSuccess` therefore passed the `is_active_job` check in `validate_share`, bypassed the stale early-return, and was re-hashed against the NEW tip's `prev_hash` while using the OLD job's coinbase and merkle path, yielding phantom `Valid` and `BlockFound` results credited for work unrelated to the current tip. Demote the previously active job into `past_jobs` before the past -> stale rotation, so it ends up in `stale_jobs` and late shares for it are correctly rejected as stale.
… a job The client-side `GroupChannel` promoted the future job matching the `SetNewPrevHash` `job_id` to `active_job` as-is, keeping `min_ntime` as `None`. As a result `is_future()` kept returning `true` on the active job and consumers dispatching on `min_ntime` misclassified it. Call `set_no_future(set_new_prev_hash.min_ntime)` before promoting, as `client/standard.rs` and `client/extended.rs` already do on activation.
Both client channels overwrote `active_job` with the activated future job. The job that was active under the previous prev hash was never inserted into `past_jobs`, so the past -> stale rotation right below could not see it: it landed in neither `past_jobs` nor `stale_jobs` and was simply dropped. As a result, a late share for the just-retired job fell through to the `else` branch of `validate_share` and was rejected as `InvalidJobId` instead of `Stale`. The server side already gets this right, since `JobStore::activate_future_job` moves the current active job into `past_jobs` before activating and then marks past jobs as stale. Capture the previous job via `Option::replace` and insert it into `past_jobs`. This happens after the `JobIdNotFound` early-return, so a failed activation does not corrupt channel state.
plebhash
force-pushed
the
2026-08-03-fix-chain-tip-transitions
branch
from
August 7, 2026 15:41
2298b53 to
a302aee
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
close #2254
close https://github.com/project-loupe/audit-stratum/issues/13
close https://github.com/project-loupe/audit-stratum/issues/15
close https://github.com/project-loupe/audit-stratum/issues/29