skip EndBlocker nonce open/close for scheduler-managed topics (ENGN-8913) - #975
Open
zale144 wants to merge 3 commits into
Conversation
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>
Contributor
There was a problem hiding this comment.
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
3 tasks
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.
Summary
IsTopicSchedulerManaged(true once a topic has allocated any epoch nonce viaStartNewEpoch/ activation).UpdateNoncesOfActiveTopics) and worker-close for scheduler-managed topics; still updateEpochLastEndedand clear stale close-index keys.EmitRewardsunchanged.Notes
Test plan
go test ./x/emissions/keeper/ -run 'TestKeeperTestSuite/TestIsTopicSchedulerManaged|TestKeeperTestSuite/TestUpdateNoncesSkips|TestKeeperTestSuite/TestUpdateNoncesStill|TestKeeperTestSuite/TestEndBlockerWorkerClose|TestKeeperTestSuite/TestStartNewEpoch|TestKeeperTestSuite/TestEpochFSM'Stacked on: #974 (ENGN-8912)
Linear: ENGN-8913
Made with Cursor
Summary by cubic
Skip
EndBlockerworker 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.IsTopicSchedulerManaged(true once any epoch nonce is allocated viaStartNewEpoch/activation) and used it inUpdateNoncesOfActiveTopicsandEndBlocker.UpdateNoncesOfActiveTopicsnow skips nonce opens for scheduler-managed topics but still advancesEpochLastEnded; legacy topics still open nonces by block height.EndBlockernow skips worker-close for scheduler-managed topics and always clears the height index to avoid stale keys.Written for commit 4a494d9. Summary will update on new commits.