Skip to content

feat: sort finalized committee scores#1491

Merged
ctrlc03 merged 3 commits into
mainfrom
feat/sort-node-scores
Mar 28, 2026
Merged

feat: sort finalized committee scores#1491
ctrlc03 merged 3 commits into
mainfrom
feat/sort-node-scores

Conversation

@hmzakhalid

@hmzakhalid hmzakhalid commented Mar 28, 2026

Copy link
Copy Markdown
Collaborator

The CommitteeFinalized event now emits the score as well as the addresses. Nodes sort the list before continuing

Summary by CodeRabbit

  • New Features

    • Committee finalization events now include per-member sortition scores (uint256[]); SDK payload exposes committee + scores.
    • Committee results are now ordered by score when available, so downstream consumers may observe committees sorted by increasing score.
  • Contracts

    • On-chain event ABI updated to emit scores alongside the committee; contract emissions include the scores array.
  • Tests

    • Integration tests updated to compute and publish committee scores.

@hmzakhalid hmzakhalid requested a review from ctrlc03 March 28, 2026 05:35
@vercel

vercel Bot commented Mar 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
crisp Ready Ready Preview, Comment Mar 28, 2026 9:04am
enclave-docs Ready Ready Preview, Comment Mar 28, 2026 9:04am

Request Review

@coderabbitai

coderabbitai Bot commented Mar 28, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

CommitteeFinalized on-chain events and corresponding SDK/Rust types were extended to include a per-member scores array; Rust conversion now populates and sorts committee entries by parsed scores. Solidity interface, implementation, artifacts, tests, and TypeScript types were updated accordingly.

Changes

Cohort / File(s) Summary
Spec & Docs
agent/flow-trace/03_E3_REQUEST_AND_COMMITTEE.md
Documented new event signature CommitteeFinalized(e3Id, committee, scores) and updated published EnclaveEvent::CommitteeFinalized to include scores.
Rust: Event Struct
crates/events/src/enclave_event/committee_finalized.rs
Added pub scores: Vec<String> and pub fn sort_by_score(&mut self) to reorder committee and scores by parsed U256 values.
Rust: EVM Conversion
crates/evm/src/ciphernode_registry_sol.rs
Populate scores from on-chain event in From<CommitteeFinalizedWithChainId> and call sort_by_score() before returning the converted event.
Rust: Tests
crates/tests/tests/integration.rs
Added compute_committee_scores() helper, changed determine_committee() to return scores, and updated tests to publish/consume CommitteeFinalized.scores.
Solidity: Interface
packages/enclave-contracts/contracts/interfaces/ICiphernodeRegistry.sol
Extended event ABI: CommitteeFinalized(uint256 indexed e3Id, address[] committee, uint256[] scores).
Solidity: Implementation
packages/enclave-contracts/contracts/registry/CiphernodeRegistryOwnable.sol
finalizeCommittee() now collects scores from c.scoreOf for selected nodes and emits CommitteeFinalized(e3Id, c.topNodes, scores).
TypeScript SDK Types
packages/enclave-sdk/src/events/types.ts
CommitteeFinalizedData updated: replaced nodes: string[] with committee: string[] and added scores: bigint[].
Artifacts: ABI & Metadata
packages/enclave-contracts/artifacts/.../*.json
ABI artifact for ICiphernodeRegistry updated to include uint256[] scores; several artifact buildInfoId fields refreshed (metadata-only changes).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ryardley

Poem

🐰 Scores hop into the event with grace,
Each address paired in tidy space.
Rust counts and sorts them, neat and bright,
Solidity echoes them into the night,
A tiny hop for committee, a joyous bite.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: sort finalized committee scores' directly and accurately summarizes the main change: adding score sorting functionality to the finalized committee event.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/sort-node-scores

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 and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/enclave-sdk/src/events/types.ts`:
- Around line 100-104: The interface CommitteeFinalizedData has a field named
nodes that doesn't match the ABI-decoded event args (which use committee);
update the interface to rename nodes to committee so the shape matches the ABI
output, i.e. change CommitteeFinalizedData { e3Id: bigint; nodes: string[];
scores: bigint[] } to use committee: string[] instead, ensuring the event
listener that passes the ABI-decoded args will satisfy the type without
remapping.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: be6dac11-5be0-47fb-bf33-dd84ad677056

📥 Commits

Reviewing files that changed from the base of the PR and between 7aa3315 and 64f315e.

📒 Files selected for processing (13)
  • agent/flow-trace/03_E3_REQUEST_AND_COMMITTEE.md
  • crates/events/src/enclave_event/committee_finalized.rs
  • crates/evm/src/ciphernode_registry_sol.rs
  • crates/tests/tests/integration.rs
  • packages/enclave-contracts/artifacts/contracts/Enclave.sol/Enclave.json
  • packages/enclave-contracts/artifacts/contracts/interfaces/IBondingRegistry.sol/IBondingRegistry.json
  • packages/enclave-contracts/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.json
  • packages/enclave-contracts/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.json
  • packages/enclave-contracts/artifacts/contracts/interfaces/ISlashingManager.sol/ISlashingManager.json
  • packages/enclave-contracts/artifacts/contracts/registry/CiphernodeRegistryOwnable.sol/CiphernodeRegistryOwnable.json
  • packages/enclave-contracts/contracts/interfaces/ICiphernodeRegistry.sol
  • packages/enclave-contracts/contracts/registry/CiphernodeRegistryOwnable.sol
  • packages/enclave-sdk/src/events/types.ts

Comment thread packages/enclave-sdk/src/events/types.ts
@vercel vercel Bot temporarily deployed to Preview – enclave-docs March 28, 2026 06:06 Inactive
@vercel vercel Bot temporarily deployed to Preview – crisp March 28, 2026 06:06 Inactive

@ctrlc03 ctrlc03 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks

@ctrlc03 ctrlc03 enabled auto-merge (squash) March 28, 2026 09:02

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
crates/tests/tests/integration.rs (1)

404-416: Make placeholder score semantics explicit to prevent accidental misuse.

Line 412 hardcodes ticket_id=0, so this helper can generate scores that differ from actual winner-ticket scores used in production sortition. Consider renaming it to a clearly test-only placeholder (or accept ticket IDs as input) so it isn’t reused as canonical scoring logic.

Suggested minimal rename to make intent explicit
- fn compute_committee_scores(committee: &[String], e3_id: &E3id, seed: Seed) -> Vec<String> {
+ fn compute_placeholder_committee_scores(
+     committee: &[String],
+     e3_id: &E3id,
+     seed: Seed,
+ ) -> Vec<String> {
- scores: compute_committee_scores(&eth_addrs, &e3_id, seed.clone()),
+ scores: compute_placeholder_committee_scores(&eth_addrs, &e3_id, seed.clone()),
- scores: compute_committee_scores(&eth_addrs, &E3id::new("1234", 1), seed.clone()),
+ scores: compute_placeholder_committee_scores(&eth_addrs, &E3id::new("1234", 1), seed.clone()),
- scores: compute_committee_scores(&eth_addrs, &E3id::new("1234", 2), seed.clone()),
+ scores: compute_placeholder_committee_scores(&eth_addrs, &E3id::new("1234", 2), seed.clone()),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/tests/tests/integration.rs` around lines 404 - 416, The helper
compute_committee_scores currently hardcodes ticket_id=0 which can be mistaken
for production logic; rename it to compute_placeholder_committee_scores (and
update its doc comment to state it uses ticket_id=0 as a test-only placeholder)
and then update all call sites to use the new name so tests remain correct and
the intent is explicit; alternatively, if you prefer extending behavior, change
the signature to accept a ticket_id parameter (e.g., ticket_id: u64) and pass
that through to e3_sortition::hash_to_score wherever compute_committee_scores is
used.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/tests/tests/integration.rs`:
- Around line 404-416: The helper compute_committee_scores currently hardcodes
ticket_id=0 which can be mistaken for production logic; rename it to
compute_placeholder_committee_scores (and update its doc comment to state it
uses ticket_id=0 as a test-only placeholder) and then update all call sites to
use the new name so tests remain correct and the intent is explicit;
alternatively, if you prefer extending behavior, change the signature to accept
a ticket_id parameter (e.g., ticket_id: u64) and pass that through to
e3_sortition::hash_to_score wherever compute_committee_scores is used.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 07ef5b1d-7041-492b-a985-b50332192d59

📥 Commits

Reviewing files that changed from the base of the PR and between 2755196 and dd7896f.

📒 Files selected for processing (1)
  • crates/tests/tests/integration.rs

@ctrlc03 ctrlc03 merged commit a8c3fc8 into main Mar 28, 2026
33 checks passed
@ctrlc03 ctrlc03 deleted the feat/sort-node-scores branch March 28, 2026 09:48
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.

2 participants