Skip to content

Conversation

@jeluard
Copy link
Contributor

@jeluard jeluard commented Dec 30, 2025

Summary by CodeRabbit

Release Notes

  • Refactor

    • Simplified voting threshold and tally calculations across governance systems by removing version-dependent branching logic.
    • Streamlined account and delegation management workflows by eliminating conditional version checks.
    • Reduced parameter complexity in governance ratification and DRep management functions.
  • Tests

    • Removed version-specific test scenarios and historical behavior comparisons.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: jeluard <jeluard@users.noreply.github.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 30, 2025

Walkthrough

This PR strips out protocol_version parameters and v9-specific conditional logic across governance ratification and ledger store modules, simplifying function signatures for voting thresholds, tally calculations, and account/drep management. The core control flows remain intact—thresholds still get computed and compared—but the version gating that previously branched on protocol versions is now gone.

Changes

Cohort / File(s) Summary
Governance Ratification – Voting Logic
crates/amaru-ledger/src/governance/ratification/ratification.rs, constitutional_committee.rs, dreps.rs, stake_pools.rs
Removed protocol_version parameter from voting_threshold() and tally() function signatures. Eliminated v9-specific conditional logic in constitutional committee threshold checks and stake pool tally fallback behavior. Updated all call sites to pass simplified argument lists. Removed related test cases comparing v9 vs v10 behavior.
Transaction Rules Cleanup
crates/amaru-ledger/src/rules/transaction/certificates.rs
Removed PROTOCOL_VERSION_9 import and simplified valid_until calculation for RegDRepCert by eliminating the protocol version conditional.
Ledger Store – Account Management
crates/amaru-stores/src/rocksdb/ledger/columns/accounts.rs
Removed entire reset_delegation() function and v9-specific delegation reset logic. Simplified add() signature to drop protocol_version parameter and remove return of past delegations; now returns Result<(), StoreError> instead of delegation history.
Ledger Store – DRep Management
crates/amaru-stores/src/rocksdb/ledger/columns/dreps.rs, mod.rs
Removed protocol_version parameter from remove() function and eliminated delegation-reset branching logic. Cleaned up imports (PROTOCOL_VERSION_9, protocol version-related delegates). Updated call sites in rocksdb/mod.rs to pass simplified arguments.
Test Scaffolding & Documentation
crates/amaru-plutus/src/script_context/v3.rs
Removed commented-out test case reference for certificates_v9.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • abailly
  • rkuhn

Poem

🎬 Like cutting a scene from a director's cut,
Protocol Nine fades to the vault—
Clean parameters, cleaner thresholds,
No more version-branching faults! 🎮✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: remove protocol v9 specifics' clearly and accurately summarizes the main objective of the pull request—removing protocol version 9 dependencies across multiple modules.
✨ Finishing touches
  • 📝 Generate docstrings

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
crates/amaru-ledger/src/governance/ratification/stake_pools.rs (1)

119-121: Comment could use a refresh, cobber!

The comment mentions "Starting from v10" but there's no actual version check in the code anymore. Since this PR removes v9 specifics, the comment could be simplified to just describe the behavior without the version reference. Something like "If no explicit vote, the fallback is given to the DRep..." would be clearer now that we're always on v10+. Just a bit of polish to keep things crisp! 🎯

🔎 Proposed comment update
-                    // Starting from v10, the fallback is given to the DRep chosen by the pool's
-                    // reward account (?!), if any. If there's no drep, then the vote is considered
-                    // to be "no" by default.
+                    // If no explicit vote, the fallback is given to the DRep chosen by the pool's
+                    // reward account, if any. If there's no DRep, then the vote is considered
+                    // to be "no" by default.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4227440 and 07c3548.

📒 Files selected for processing (9)
  • crates/amaru-ledger/src/governance/ratification.rs
  • crates/amaru-ledger/src/governance/ratification/constitutional_committee.rs
  • crates/amaru-ledger/src/governance/ratification/dreps.rs
  • crates/amaru-ledger/src/governance/ratification/stake_pools.rs
  • crates/amaru-ledger/src/rules/transaction/certificates.rs
  • crates/amaru-plutus/src/script_context/v3.rs
  • crates/amaru-stores/src/rocksdb/ledger/columns/accounts.rs
  • crates/amaru-stores/src/rocksdb/ledger/columns/dreps.rs
  • crates/amaru-stores/src/rocksdb/mod.rs
💤 Files with no reviewable changes (1)
  • crates/amaru-plutus/src/script_context/v3.rs
🧰 Additional context used
🧠 Learnings (10)
📚 Learning: 2025-08-20T13:02:25.763Z
Learnt from: jeluard
Repo: pragma-org/amaru PR: 387
File: crates/amaru-stores/src/lib.rs:40-40
Timestamp: 2025-08-20T13:02:25.763Z
Learning: In the amaru-stores crate, amaru_slot_arithmetic types like Epoch and EraHistory are used throughout the main crate code in modules like in_memory/mod.rs, rocksdb/consensus.rs, and rocksdb/ledger/columns/, not just in tests. This means amaru-slot-arithmetic should be a regular dependency, not a dev-dependency.

Applied to files:

  • crates/amaru-ledger/src/rules/transaction/certificates.rs
  • crates/amaru-stores/src/rocksdb/ledger/columns/dreps.rs
  • crates/amaru-stores/src/rocksdb/ledger/columns/accounts.rs
  • crates/amaru-stores/src/rocksdb/mod.rs
📚 Learning: 2025-09-29T16:44:14.807Z
Learnt from: rkuhn
Repo: pragma-org/amaru PR: 471
File: crates/amaru-network/src/protocol.rs:94-106
Timestamp: 2025-09-29T16:44:14.807Z
Learning: In the amaru-network crate protocol.rs file, the correct Cardano mini-protocol ID assignments are: PROTO_N2N_KEEP_ALIVE = 8 and PROTO_N2N_PEER_SHARE = 10, as verified against the network specification by the maintainer.

Applied to files:

  • crates/amaru-ledger/src/rules/transaction/certificates.rs
📚 Learning: 2025-12-16T21:32:37.668Z
Learnt from: rkuhn
Repo: pragma-org/amaru PR: 584
File: crates/amaru-network/src/handshake/tests.rs:40-47
Timestamp: 2025-12-16T21:32:37.668Z
Learning: In Rust, shadowing a binding with a new let does not drop the previous binding until the end of the scope. All shadowed bindings in a scope are dropped in reverse-declaration order when the scope ends. Therefore, multiple let _guard = register_*() calls will keep all guards alive until the end of the function (or the surrounding scope). When reviewing code, be mindful that resources tied to shadowed bindings persist longer than the most recent binding; to release early, constrain the lifetime in an inner block or explicitly drop guards when appropriate.

Applied to files:

  • crates/amaru-ledger/src/rules/transaction/certificates.rs
  • crates/amaru-ledger/src/governance/ratification/dreps.rs
  • crates/amaru-stores/src/rocksdb/ledger/columns/dreps.rs
  • crates/amaru-ledger/src/governance/ratification/constitutional_committee.rs
  • crates/amaru-ledger/src/governance/ratification.rs
  • crates/amaru-stores/src/rocksdb/ledger/columns/accounts.rs
  • crates/amaru-ledger/src/governance/ratification/stake_pools.rs
  • crates/amaru-stores/src/rocksdb/mod.rs
📚 Learning: 2025-05-21T18:58:48.631Z
Learnt from: abailly
Repo: pragma-org/amaru PR: 228
File: crates/amaru-stores/src/rocksdb/consensus.rs:89-128
Timestamp: 2025-05-21T18:58:48.631Z
Learning: The InMemConsensusStore implementation in crates/amaru-stores/src/rocksdb/consensus.rs will be fleshed out incrementally on a by-need basis, driven by test requirements rather than implementing all functionality upfront.

Applied to files:

  • crates/amaru-stores/src/rocksdb/ledger/columns/dreps.rs
  • crates/amaru-stores/src/rocksdb/ledger/columns/accounts.rs
  • crates/amaru-stores/src/rocksdb/mod.rs
📚 Learning: 2025-01-21T15:32:17.911Z
Learnt from: jeluard
Repo: pragma-org/amaru PR: 69
File: crates/amaru/src/ledger/state/diff_epoch_reg.rs:112-117
Timestamp: 2025-01-21T15:32:17.911Z
Learning: When suggesting code changes in Rust, always verify that the types align correctly, especially when dealing with references and Options. The `Fold::Registered` variant in `diff_epoch_reg.rs` expects a reference `&'a V`, so unwrapping an `Option<&V>` requires only a single `.expect()`.

Applied to files:

  • crates/amaru-ledger/src/governance/ratification/constitutional_committee.rs
📚 Learning: 2025-04-20T17:57:23.233Z
Learnt from: rkuhn
Repo: pragma-org/amaru PR: 149
File: crates/amaru/src/stages/consensus/chain_forward/test_infra.rs:272-285
Timestamp: 2025-04-20T17:57:23.233Z
Learning: In test infrastructure code, rkuhn prefers explicit panics (using .unwrap() or similar) over returning Result types, as test failures should be immediate and obvious.

Applied to files:

  • crates/amaru-ledger/src/governance/ratification/constitutional_committee.rs
📚 Learning: 2025-08-18T08:10:32.640Z
Learnt from: KtorZ
Repo: pragma-org/amaru PR: 374
File: crates/amaru-stores/src/in_memory/mod.rs:427-433
Timestamp: 2025-08-18T08:10:32.640Z
Learning: The MemoryStore in crates/amaru-stores/src/in_memory/mod.rs is planned for a major revamp, so unimplemented methods like set_proposals_roots and set_constitution are intentionally left as placeholders until the revamp is complete.

Applied to files:

  • crates/amaru-stores/src/rocksdb/ledger/columns/accounts.rs
  • crates/amaru-stores/src/rocksdb/mod.rs
📚 Learning: 2025-08-18T08:10:35.849Z
Learnt from: KtorZ
Repo: pragma-org/amaru PR: 374
File: crates/amaru-stores/src/in_memory/mod.rs:431-433
Timestamp: 2025-08-18T08:10:35.849Z
Learning: The MemoryStore in crates/amaru-stores/src/in_memory/mod.rs is planned for a major revamp soon, so unimplemented methods like set_constitution, set_proposals_roots are intentionally left aside until the revamp is complete.

Applied to files:

  • crates/amaru-stores/src/rocksdb/ledger/columns/accounts.rs
  • crates/amaru-stores/src/rocksdb/mod.rs
📚 Learning: 2025-08-19T09:54:04.412Z
Learnt from: KtorZ
Repo: pragma-org/amaru PR: 374
File: crates/amaru-ledger/src/summary/stake_distribution.rs:219-225
Timestamp: 2025-08-19T09:54:04.412Z
Learning: In stake distribution calculations for governance voting, pool deposit refunds are intentionally handled asymmetrically: DRep voting stake includes the refund (`dreps_voting_stake += account.lovelace + drep_deposits + refund`) while Pool voting stake does not include the refund (`let delta = account.lovelace + pool_deposits`). This behavior matches the Haskell Cardano ledger reference implementation and is by design, not a bug.

Applied to files:

  • crates/amaru-ledger/src/governance/ratification/stake_pools.rs
📚 Learning: 2025-02-03T11:15:22.640Z
Learnt from: abailly
Repo: pragma-org/amaru PR: 75
File: crates/amaru/src/consensus/mod.rs:164-165
Timestamp: 2025-02-03T11:15:22.640Z
Learning: In the Amaru project, chain selection operations (roll_forward and rollback) should use separate result types to leverage the type system for preventing impossible states, rather than using runtime checks or panics.

Applied to files:

  • crates/amaru-stores/src/rocksdb/mod.rs
🧬 Code graph analysis (5)
crates/amaru-ledger/src/governance/ratification/dreps.rs (1)
crates/amaru-kernel/src/vote.rs (1)
  • any_vote_ref (28-30)
crates/amaru-stores/src/rocksdb/ledger/columns/dreps.rs (1)
crates/amaru-stores/src/rocksdb/common.rs (2)
  • as_key (25-27)
  • as_value (30-32)
crates/amaru-ledger/src/governance/ratification/constitutional_committee.rs (1)
crates/amaru-ledger/src/summary/mod.rs (1)
  • into_safe_ratio (129-134)
crates/amaru-ledger/src/governance/ratification/stake_pools.rs (2)
crates/amaru-kernel/src/lib.rs (1)
  • expect_stake_credential (551-554)
crates/amaru-ledger/src/governance/ratification/dreps.rs (1)
  • any_tally (293-311)
crates/amaru-stores/src/rocksdb/mod.rs (4)
crates/amaru-ledger/src/state.rs (1)
  • protocol_parameters (230-232)
crates/amaru-ledger/src/store.rs (1)
  • protocol_parameters (166-166)
crates/amaru-stores/src/in_memory/mod.rs (2)
  • protocol_parameters (101-103)
  • protocol_parameters (367-369)
crates/amaru-stores/src/in_memory/ledger/columns/accounts.rs (1)
  • add (23-50)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: End-to-end snapshot tests (preview, 2, 680, true, 10.5.3)
  • GitHub Check: End-to-end snapshot tests (preprod, 1, 182, 10.5.3)
  • GitHub Check: Build aarch64/linux
  • GitHub Check: Build aarch64/macos
  • GitHub Check: Build riscv32
  • GitHub Check: Build wasm32
  • GitHub Check: Test coverage
  • GitHub Check: Build x86_64/linux
  • GitHub Check: Build x86_64/windows
  • GitHub Check: Test the CLI
  • GitHub Check: Benches
  • GitHub Check: Analyze (rust)
🔇 Additional comments (16)
crates/amaru-ledger/src/rules/transaction/certificates.rs (2)

24-25: Crikey, clean removal of the v9 baggage, mate!

Removing PROTOCOL_VERSION_9 from the imports is spot on for this PR's mission. The code doesn't reference it anywhere below, so we're all sorted here.


215-217: The slot_to_epoch usage here is spot on—no double-dip needed!

Your eyes picked up on something real, but it turns out the API's designed exactly this way. The slot_to_epoch function signature takes two parameters—slot and tip—so passing pointer.slot() twice isn't a mishap; it's the intended pattern. You'll see this same pattern throughout the codebase (rocksdb, praos, state, even the test suites), so the code here is bang on.

The removal of the protocol version conditional is also intentional—the git history confirms this is part of cleaning up protocol v9 specifics. The refactor stands up solid.

crates/amaru-ledger/src/governance/ratification/dreps.rs (2)

33-37: Clean signature simplification, mate!

The removal of the protocol_version parameter is spot on. The function signature is now more straightforward, and since the AI summary mentions that version gating has been removed from the function body, this is a solid cleanup. No drama here! 🎬


231-234: Test imports cleaned up nicely!

Good to see the test imports aligned with the new reality. Removing the protocol version constants and keeping things tidy. This is cleaner than a fresh pair of Dunlop Volleys! 👟

crates/amaru-ledger/src/governance/ratification/constitutional_committee.rs (2)

122-127: Voting threshold signature looking fresh!

Nice work stripping out the protocol_version parameter. The method signature is cleaner than a freshly wiped hard drive after a zombie apocalypse (looking at you, The Last of Us). 🧟


137-146: Committee size check is proper!

The active member count check looks good without the version branching. The warning message at lines 138-142 is a beaut for debugging when the committee's running short-staffed. This is cleaner than a Melbourne café's pour-over setup! ☕

crates/amaru-ledger/src/governance/ratification.rs (1)

474-474: Tally call simplified beautifully!

The updated stake_pools::tally call is as clean as a whistle. Dropping the protocol_version parameter keeps things tidy and aligns perfectly with the changes in stake_pools.rs. This is smoother than butter on a hot pavlova! 🍰

crates/amaru-ledger/src/governance/ratification/stake_pools.rs (2)

97-101: Tally signature is mint!

The simplified tally function signature is looking sharp. Removing the protocol_version parameter streamlines the API nicely. This is as clean as a fresh fade from your local barber! 💈


324-341: Test helper updated like a boss!

The any_tally helper is now returning a cleaner tuple without the protocol_version. The prop_map at lines 337-339 is straightforward and matches the new signature perfectly. This is tighter than a drum solo in a Rush song! 🥁

crates/amaru-stores/src/rocksdb/ledger/columns/dreps.rs (2)

15-16: G'day! Import cleanup looks crisp as.

The removal of PROTOCOL_VERSION_9, ProtocolVersion, dreps_delegations, and accounts from the imports aligns perfectly with the PR's mission to strip out v9-specific bits. Clean as a whistle, mate.


152-175: Refactoring checks out, mate.

The simplified dreps::remove signature is all good—all the call sites in both RocksDB and in-memory implementations have been updated to the new 2-parameter version. The delegation reset logic hasn't been orphaned somewhere collecting digital dust either; it looks like it's been cleanly separated into the dreps_delegations module, which handles that tracking independently. No downstream code is expecting those delegation resets to happen through dreps::remove anymore, so you're not breaking anything downstream.

crates/amaru-stores/src/rocksdb/ledger/columns/accounts.rs (2)

15-23: Bonza import cleanup!

Stripped out DRep, CertificatePointer, PROTOCOL_VERSION_9, and ProtocolVersion - the imports are now lean and mean, matching the simplified logic below. No complaints here, champion.


31-74: Function signature overhaul is solid, but let's check for stragglers.

Right, so the add function's been streamlined beautifully:

  • Dropped the protocol_version parameter ✓
  • Changed return from Result<Vec<...>, StoreError> to Result<(), StoreError>
  • The _drep underscore prefix on line 35 is textbook Rust - tells the compiler "yeah nah, not using this value" ✓

The logic itself looks sound - it's updating or creating account rows without tracking previous delegations anymore. Much simpler, like going from a complicated flat white order to just asking for a coffee.

This is indeed a breaking API change, but the good news: both implementations (rocksdb and in_memory) have been updated consistently, and all call sites use the ? operator without capturing the return value. No code's actually expecting that old Vec back, so you're all sweet here.

crates/amaru-stores/src/rocksdb/mod.rs (3)

19-20: Import changes track with the rest of the PR.

The imports still pull in ProtocolParameters but dropped the PROTOCOL_VERSION_9 constant. Makes sense - we're keeping the parameters but ditching the version-specific branching logic. Sweet as.


781-781: Updated call to accounts::add matches the new signature perfectly.

Line 781 now calls accounts::add(&self.db, add.accounts)? without the protocol_version parameter, which syncs up nicely with the signature change we saw in accounts.rs. The return value is no longer captured, which is exactly what we'd expect since it now returns ().


796-796: All dreps::remove and accounts::add call sites have been properly updated—no stragglers with the old protocol_version signature.

The search came up clean, mate. Both accounts::add and dreps::remove are showing up with the correct 2-parameter signatures across the board:

  • rocksdb/mod.rs lines 781 and 796: correct signatures ✓
  • in_memory/mod.rs lines 704 and 714: correct signatures ✓

And no sneaky protocol_version references lurking about either. You've nailed it—like landing a perfect headshot in a no-scoping competition. All the function calls have been consistently refactored across both implementations.

@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

❌ Patch coverage is 64.28571% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...amaru-ledger/src/rules/transaction/certificates.rs 0.00% 3 Missing ⚠️
crates/amaru-ledger/src/governance/ratification.rs 0.00% 1 Missing ⚠️
...overnance/ratification/constitutional_committee.rs 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
.../amaru-ledger/src/governance/ratification/dreps.rs 96.89% <ø> (+1.80%) ⬆️
...-ledger/src/governance/ratification/stake_pools.rs 98.73% <100.00%> (+0.98%) ⬆️
crates/amaru-plutus/src/script_context/v3.rs 40.69% <ø> (ø)
...maru-stores/src/rocksdb/ledger/columns/accounts.rs 78.57% <100.00%> (+11.90%) ⬆️
...s/amaru-stores/src/rocksdb/ledger/columns/dreps.rs 51.16% <ø> (-2.61%) ⬇️
crates/amaru-stores/src/rocksdb/mod.rs 73.17% <100.00%> (-0.15%) ⬇️
crates/amaru-ledger/src/governance/ratification.rs 6.18% <0.00%> (+0.16%) ⬆️
...overnance/ratification/constitutional_committee.rs 88.14% <0.00%> (-7.48%) ⬇️
...amaru-ledger/src/rules/transaction/certificates.rs 6.74% <0.00%> (+0.07%) ⬆️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yHSJ
Copy link
Contributor

yHSJ commented Jan 5, 2026

This looks good to me, but I want to make sure we don't merge this until we update documentation and makefile commands to start from protocol version 10 blocks.

@jeluard
Copy link
Contributor Author

jeluard commented Jan 6, 2026

Right, we need new snapshots before those changes can be applied.

@jeluard jeluard marked this pull request as draft January 6, 2026 10:22
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.

3 participants