repository: enforce valid epoch status transitions#759
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds database-level enforcement for epoch status state-machine transitions and updates repository logic/tests to respect the new constraints, improving crash-recovery safety and data integrity across epoch processing.
Changes:
- Introduce a Postgres trigger (
enforce_epoch_status_transition) to validate epoch status transitions and require proof fields when enteringCLAIM_COMPUTED. - Make
CreateEpochsAndInputsupserts preserve non-OPENepochs (crash-recovery guard) and tightenStoreClaimAndProofsto only advance epochs fromINPUTS_PROCESSED. - Update integration/repository tests with a helper to advance epochs through valid transitions.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/validator/validator_test.go | Adjusts validator integration tests to move epochs through CLOSED -> INPUTS_PROCESSED before storing claims. |
| internal/repository/repotest/epoch_test_cases.go | Adds new test coverage for upsert guarding and DB-trigger transition enforcement. |
| internal/repository/repotest/claimer_test_cases.go | Switches tests to use AdvanceEpochStatus helper for valid transitions. |
| internal/repository/repotest/bulk_test_cases.go | Updates bulk-operation tests to satisfy new preconditions for StoreClaimAndProofs. |
| internal/repository/repotest/builders.go | Introduces AdvanceEpochStatus helper and dummy-proof setup for tests. |
| internal/repository/postgres/schema/migrations/000001_create_initial_schema.up.sql | Adds epoch-status transition trigger and required-proof-field checks. |
| internal/repository/postgres/schema/migrations/000001_create_initial_schema.down.sql | Adds rollback steps for the new trigger/function. |
| internal/repository/postgres/epoch.go | Adds guarded upsert behavior (only mutate epoch fields when existing row is OPEN). |
| internal/repository/postgres/bulk.go | Enforces INPUTS_PROCESSED precondition when updating epoch claim/status to CLAIM_COMPUTED. |
| internal/evmreader/output.go | Adds explanatory comments around marking apps inoperable on output mismatch. |
| internal/evmreader/input.go | Adds explanatory comments around marking apps inoperable on invalid epoch length. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
internal/repository/postgres/schema/migrations/000001_create_initial_schema.down.sql
Show resolved
Hide resolved
internal/repository/postgres/schema/migrations/000001_create_initial_schema.up.sql
Show resolved
Hide resolved
6f39291 to
0485be3
Compare
mpolitzer
reviewed
Mar 15, 2026
internal/repository/postgres/schema/migrations/000001_create_initial_schema.up.sql
Show resolved
Hide resolved
0485be3 to
f5a9d87
Compare
mpolitzer
previously approved these changes
Mar 16, 2026
mpolitzer
approved these changes
Mar 16, 2026
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.
No description provided.