Skip to content

Validate participant roles in IsValidEpochSetup - #8693

Open
zhangchiqing wants to merge 1 commit into
masterfrom
leo/validate-epoch-setup-participant-roles
Open

Validate participant roles in IsValidEpochSetup#8693
zhangchiqing wants to merge 1 commit into
masterfrom
leo/validate-epoch-setup-participant-roles

Conversation

@zhangchiqing

@zhangchiqing zhangchiqing commented Sep 5, 2026

Copy link
Copy Markdown
Member

Problem

IsValidEpochSetup already checked that an EpochSetup has enough active nodes for each known role, but it never rejected participants whose Role field was not a valid flow.Role. An invalid role (e.g. 0 or 42) would be accepted as long as the real roles were still represented, and later code paths that call Role.String() would panic on the bogus value.

Changes

  • Add a defense-in-depth check that calls Role.Valid() for every participant and rejects the setup with an error if any participant has an invalid role.
  • Add a regression test that mutates a consensus participant to an invalid role and asserts that IsValidEpochSetup returns an error.

Labels: Bug, S-Epochs


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Epoch setup validation now rejects participants with invalid roles.
    • Validation errors identify the invalid role and associated node.

IsValidEpochSetup already checked that an EpochSetup has enough active nodes
for each known role, but it never rejected participants whose Role field was
not a valid flow.Role. An invalid role (e.g. 0 or 42) would be accepted as
long as the real roles were still represented, and later code paths that call
Role.String() would panic on the bogus value.

Add a defense-in-depth check that calls Role.Valid() for every participant
and rejects the setup with an error if any participant has an invalid role.

Also add a regression test that mutates a consensus participant to an invalid
role and asserts that IsValidEpochSetup returns an error.
@zhangchiqing
zhangchiqing requested a review from a team as a code owner September 5, 2026 00:14
@zhangchiqing zhangchiqing added Bug Something isn't working S-Epochs labels Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 59c5a616-69ca-4285-9ce0-47cfe0b375bd

📥 Commits

Reviewing files that changed from the base of the PR and between 2a03353 and 653159e.

📒 Files selected for processing (2)
  • state/protocol/validity.go
  • state/protocol/validity_test.go

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

Epoch setup validation now checks that every participant has a valid role. A test sets a participant role to flow.Role(42) and verifies that validation returns an error.

Changes

Epoch setup validation

Layer / File(s) Summary
Participant role validation
state/protocol/validity.go, state/protocol/validity_test.go
IsValidEpochSetup rejects participants with invalid roles and reports the role and node ID. The validity test covers an invalid consensus participant role.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 65315

Epoch setups with invalid participant roles are now rejected before later role handling can fail, with regression coverage for the invalid-role case. No current merge-blocking risk remains.

Suggested reviewers: alexhentschel, j1010001, janezpodhostnik

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: validating participant roles in IsValidEpochSetup.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch leo/validate-epoch-setup-participant-roles

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working S-Epochs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants