Skip to content

fix: Allow non-Alonzo era when missing total collateral#776

Open
caike wants to merge 1 commit intotxpipe:mainfrom
caike:fix/allow-non-alonzo-eras-total-collateral-compute
Open

fix: Allow non-Alonzo era when missing total collateral#776
caike wants to merge 1 commit intotxpipe:mainfrom
caike:fix/allow-non-alonzo-eras-total-collateral-compute

Conversation

@caike
Copy link
Contributor

@caike caike commented Oct 29, 2025

This field is optional according to the CDDL.

Fixes #775

Summary by CodeRabbit

  • Improvements
    • Collateral value computation now applies across more transaction eras, improving compatibility with newer and legacy transactions.
    • Relaxed era-specific checks allow collateral to be computed even when explicit collateral fields are absent, preserving existing calculation behavior.
  • Documentation
    • Clarified that collateral computation is era-agnostic.

@caike caike requested a review from scarmuega as a code owner October 29, 2025 20:34
@coderabbitai
Copy link

coderabbitai bot commented Oct 29, 2025

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ca709261-f5ef-46d4-83b6-6d5d12e9023d

📥 Commits

Reviewing files that changed from the base of the PR and between 2cc2523 and 700a64c.

📒 Files selected for processing (1)
  • crates/cardano/src/roll/epochs.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/cardano/src/roll/epochs.rs

📝 Walkthrough

Walkthrough

compute_collateral_value in crates/cardano/src/roll/epochs.rs was made era-agnostic: the Alonzo-only assertion was removed, imports adjusted to multi-era types, and a note added that it may be used for Alonzo, Babbage, or Conway transactions when total_collateral is unset. Internal collateral math is unchanged.

Changes

Cohort / File(s) Summary
Collateral era relaxation
crates/cardano/src/roll/epochs.rs
Removed Era from pallas::ledger::traverse import, dropped debug_assert!(tx.era() == Era::Alonzo), documented that compute_collateral_value is callable for Alonzo/Babbage/Conway txs when total_collateral is absent; core input-sum/output-subtract logic unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰
I hopped through eras, light and spry,
Removed a check with a curious eye.
Collateral counted, inputs and returns,
Now Babbage and Conway join Alonzo's turns.
Thump-thump — the ledger hums nearby.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. 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 PR title directly matches the main change: allowing non-Alonzo era transactions when total_collateral is missing, which is the core fix.
Linked Issues check ✅ Passed The code change directly addresses issue #775 by removing the Era::Alonzo assertion and documenting that compute_collateral_value works for any era when total_collateral is absent.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the total_collateral handling issue; only import path updates and assertion removal related to the fix are present.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can customize the tone of the review comments and chat replies.

Configure the tone_instructions setting to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

@caike caike changed the title Allow non-Alonzo era when missing total collateral fix: Allow non-Alonzo era when missing total collateral Oct 29, 2025
Copy link

@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 (2)
crates/cardano/src/roll/epochs.rs (2)

202-207: Consider updating the HACK comment to mention Babbage transactions.

The HACK comment (lines 202-205) mentions that "Alonzo txs don't even have the total collateral field," but based on issue #775, Babbage transactions can also have missing total_collateral fields. The new note (lines 206-207) correctly indicates the function works for multiple eras, but the HACK comment could be updated for clarity.

Apply this diff to clarify that multiple eras can have missing total_collateral:

 // HACK: There are txs that don't have an explicit value for total collateral
-// and Alonzo txs don't even have the total collateral field. This is why we
-// need to compute it by looking at collateral inputs and collateral return.
+// (Alonzo era), or the field exists but is not set (Babbage, Conway). This is
+// why we need to compute it by looking at collateral inputs and collateral return.
 // Pallas hides this from us by providing the "consumes" / "produces" facade.

245-245: Consider making the log message more generic.

The log message says "alonzo-style collateral computed," but this code path now executes for Babbage and Conway transactions as well when total_collateral is missing. While "alonzo-style" refers to the computation method, a more generic message would better reflect the multi-era support.

Apply this diff to make the message clearer:

-        tracing::debug!(tx=%tx.hash(), fee, "alonzo-style collateral computed");
+        tracing::debug!(tx=%tx.hash(), fee, "collateral computed from inputs/outputs");
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20973cc and 5a47282.

📒 Files selected for processing (1)
  • crates/cardano/src/roll/epochs.rs (2 hunks)
⏰ 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). (4)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Test (macos-14)
  • GitHub Check: Test (macos-13)
  • GitHub Check: Test (ubuntu-latest)
🔇 Additional comments (2)
crates/cardano/src/roll/epochs.rs (2)

208-232: LGTM! The collateral computation logic is correct.

The function correctly computes collateral value for invalid transactions across multiple eras by:

  • Summing collateral inputs via tx.consumes()
  • Subtracting collateral return via tx.produces()
  • The debug_assert!(!tx.is_valid()) on line 212 appropriately ensures this is only called for invalid transactions

The removal of the era-specific assertion (mentioned in the AI summary) allows this to work for Alonzo, Babbage, and Conway transactions when total_collateral is not set, which correctly addresses issue #775.


8-8: Era removal is safe and will not cause compilation issues.

The only direct reference to Era in the file is at line 267, which uses the fully qualified path pallas::ledger::traverse::Era::Shelley. All other "Era" mentions are part of imported Multi-Era type names (MultiEraBlock, MultiEraTx, etc.), so the import removal will not affect them.

@scarmuega scarmuega force-pushed the main branch 2 times, most recently from 295b558 to 09d0b81 Compare January 28, 2026 07:14
@scarmuega
Copy link
Member

@caike this looks reasonable. I just need your help fixing the merge conflicts to go ahead with the merge.

@caike caike force-pushed the fix/allow-non-alonzo-eras-total-collateral-compute branch from 5a47282 to 2cc2523 Compare February 2, 2026 22:13
@caike
Copy link
Contributor Author

caike commented Feb 2, 2026

merge conflicts fixed @scarmuega

This field is optional according to the CDDL.

Remove unused import
@caike caike force-pushed the fix/allow-non-alonzo-eras-total-collateral-compute branch from 2cc2523 to 700a64c Compare March 12, 2026 19:00
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.

Error syncing from upstream relay in debug mode on preview

2 participants