Skip to content

skip EndBlocker nonce open/close for scheduler-managed topics (ENGN-8913) - #975

Open
zale144 wants to merge 3 commits into
alek/engn-8912-implement-epoch-fsm-transition-side-effectsfrom
alek/engn-8913-cut-over-endblocker-epochnonce-path-to-scheduler-driven
Open

skip EndBlocker nonce open/close for scheduler-managed topics (ENGN-8913)#975
zale144 wants to merge 3 commits into
alek/engn-8912-implement-epoch-fsm-transition-side-effectsfrom
alek/engn-8913-cut-over-endblocker-epochnonce-path-to-scheduler-driven

Conversation

@zale144

@zale144 zale144 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add IsTopicSchedulerManaged (true once a topic has allocated any epoch nonce via StartNewEpoch / activation).
  • Skip EndBlocker worker-nonce open (UpdateNoncesOfActiveTopics) and worker-close for scheduler-managed topics; still update EpochLastEnded and clear stale close-index keys.
  • Leave height-based submission validation, unfulfilled nonce stores, weights, and EmitRewards unchanged.

Notes

Test plan

  • go test ./x/emissions/keeper/ -run 'TestKeeperTestSuite/TestIsTopicSchedulerManaged|TestKeeperTestSuite/TestUpdateNoncesSkips|TestKeeperTestSuite/TestUpdateNoncesStill|TestKeeperTestSuite/TestEndBlockerWorkerClose|TestKeeperTestSuite/TestStartNewEpoch|TestKeeperTestSuite/TestEpochFSM'
  • CI green on this PR

Stacked on: #974 (ENGN-8912)
Linear: ENGN-8913

Made with Cursor


Summary by cubic

Skip EndBlocker worker nonce open/close for scheduler-managed topics so the scheduler FSM owns epoch/nonce lifecycle; legacy topics stay on the height-based path to avoid double-opens and bad closes.

  • Added IsTopicSchedulerManaged (true once any epoch nonce is allocated via StartNewEpoch/activation) and used it in UpdateNoncesOfActiveTopics and EndBlocker.
  • UpdateNoncesOfActiveTopics now skips nonce opens for scheduler-managed topics but still advances EpochLastEnded; legacy topics still open nonces by block height.
  • EndBlocker now skips worker-close for scheduler-managed topics and always clears the height index to avoid stale keys.
  • No changes to submission validation, unfulfilled nonce stores, weight handling, or rewards emission. Aligns with Linear ENGN-8913: EndBlocker no longer owns epoch open/close for migrated topics; wall-clock window enforcement follows in a separate PR.

Written for commit 4a494d9. Summary will update on new commits.

Review in cubic

Topics that have allocated an epoch nonce are owned by the FSM;
UpdateNoncesOfActiveTopics and EndBlocker worker-close skip those
topics so they no longer double-open or steal FSM closes.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cubic analysis

No issues found across 4 files

Linked issue analysis

Linked issue: ENGN-8913: Cut over EndBlocker epoch/nonce path to scheduler-driven epochs

Status Acceptance criteria Notes
Add detection for scheduler-managed topics (IsTopicSchedulerManaged) and mark topics as managed once StartNewEpoch/activation allocates an epoch nonce A new IsTopicSchedulerManaged method was added and tests verify it flips true after StartNewEpoch/activation.
EndBlocker no longer opens worker nonces for scheduler-managed topics (skip in UpdateNoncesOfActiveTopics) UpdateNoncesOfActiveTopics now checks IsTopicSchedulerManaged and skips adding height-keyed worker nonces for managed topics; tests confirm scheduler-managed topics do not get EndBlocker nonces while legacy topics still do.
EndBlocker no longer closes worker nonces for scheduler-managed topics (skip during EndBlocker worker-close handling) EndBlocker now checks IsTopicSchedulerManaged when iterating close-indexed topics and skips closing FSM-owned nonces; test verifies the nonce remains unfulfilled and the skip behavior.
Ensure height index entries are still cleared even when skipping EndBlocker actions (avoid stale keys) EndBlocker continues to call DeleteWorkerWindowBlockHeight regardless of skips, and tests assert the height index is cleared for skipped topics.
Architecture diagram
sequenceDiagram
    participant FS as "Epoch FSM (StartNewEpoch / ActivateTopic)"
    participant EB as "EndBlocker (ABCI)"
    participant UN as "UpdateNoncesOfActiveTopics"
    participant K as "Emissions Keeper"
    participant ST as "KV Store (TopicLastEpochNonce)"
    participant NK as "Nonce Keeper"
    participant TK as "Topic Keeper"

    Note over FS,ST: Topic becomes scheduler-managed once the FSM allocates an epoch nonce
    FS->>K: StartNewEpoch / ActivateTopic(topicId)
    K->>ST: AllocateNextEpochNonce(topicId)
    ST-->>FS: last epoch nonce persisted

    Note over EB,NK: EndBlocker height-based lifecycle guarded by IsTopicSchedulerManaged

    EB->>UN: UpdateNoncesOfActiveTopics(blockHeight, weights)
    loop each active topic
        UN->>K: IsTopicSchedulerManaged(topicId)
        K->>ST: GetTopicLastEpochNonce(topicId)
        ST-->>K: found?
        alt NEW - scheduler-managed (nonce exists)
            K-->>UN: true
            UN->>UN: skip worker nonce open (FSM owns lifecycle)
            UN->>TK: EpochLastEnded still advanced
        else legacy - no epoch nonce
            K-->>UN: false
            UN->>NK: AddWorkerNonce(topicId, blockHeight)
        end
    end

    EB->>NK: GetWorkerWindowTopicIds(blockHeight)
    NK-->>EB: candidate topic IDs at close height
    loop each candidate topic
        EB->>K: IsTopicSchedulerManaged(topicId)
        alt NEW - scheduler-managed
            K-->>EB: true
            EB->>EB: skip worker close nonce stays unfulfilled
        else legacy - close path
            K-->>EB: false
            EB->>NK: close worker nonce window
        end
    end
    EB->>NK: DeleteWorkerWindowBlockHeight(blockHeight) clears stale index for skipped topics too
Loading

Re-trigger cubic

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