Skip to content

Conversation

@wolf31o2
Copy link
Member

@wolf31o2 wolf31o2 commented Nov 28, 2025

Summary by cubic

Fixes transaction metadata decoding in block verification tests by adding a shared helper and using it across all eras. Also replaces interface{} with any for cleaner generics.

  • Bug Fixes

    • Correctly extracts and decodes metadata from tx arrays for Shelley, Allegra, Mary, Alonzo, Babbage, and Conway.
    • Adds clear error messages with era name and index on decode failures.
  • Refactors

    • Introduces decodeTransactionMetadataSet to remove duplicated metadata decoding code.
    • Replaces interface{} with any in test helpers for consistency.

Written for commit bda1e0d. Summary will update automatically on new commits.

Summary by CodeRabbit

  • Tests
    • Refactored test helpers to use more generic data types for improved flexibility in test data handling.
    • Centralized transaction metadata decoding logic to reduce code duplication across test blocks.

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

Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
@wolf31o2 wolf31o2 requested a review from a team as a code owner November 28, 2025 17:38
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 28, 2025

📝 Walkthrough

Walkthrough

This PR refactors test helpers in ledger/verify_block_test.go by updating parameter types from interface{} to any in decodeTxBodyBytes and decodeTxBodies functions. It introduces a centralized metadata decoding helper function and consolidates repetitive metadata decoding logic that was previously inlined separately for each ledger era (Shelley, Allegra, Mary, Alonzo, Babbage, Conway). Transaction entry handling throughout the file is updated to use []any instead of []interface{}, aligning with the new approach.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single test file with straightforward refactoring
  • Type parameter changes (interface{} → any) are syntactic
  • Metadata decoding consolidation follows a clear extraction pattern
  • Verify that the centralized decodeTransactionMetadataSet helper correctly handles all ledger era variants (Shelley through Conway)

Possibly related PRs

  • #1279 — Directly modifies the same test file with related changes to transaction and metadata decoding patterns.

Pre-merge checks and finishing touches

✅ 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 'test: fix decoding transaction metadata' is partially related to the changeset. While metadata decoding is addressed, the main focus is refactoring test helpers to use generic types (interface{} to any) and centralizing metadata decoding logic, not fixing a broken decoding process.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/decode-metadata

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 (2)
ledger/verify_block_test.go (2)

24-61: Generic tx body decoding and []any conversion look correct; consider small safety check

The switch on v.(type) and the move to any/[]any keep behavior identical while modernizing the types; using decodeTxBodyBytes(t, txArray[0]) via []any is sound given any is an alias for interface{} and CBOR decoding will still populate compatible slice elements.

One small optional improvement: guard against malformed CBOR that yields an empty txArray to avoid a potential index panic and get a clearer failure message in tests:

 func decodeTxBodies[T any](t *testing.T, txs []any, label string) []T { t.Helper() bodies := make([]T, len(txs)) for i, tx := range txs { - txArray, ok := tx.([]any) + txArray, ok := tx.([]any) if !ok { t.Fatalf("unexpected %s tx element type %T", label, tx) } + if len(txArray) == 0 { + t.Fatalf("unexpected empty %s tx at index %d", label, i) + } txBodyBytes := decodeTxBodyBytes(t, txArray[0]) if _, err := cbor.Decode(txBodyBytes, &bodies[i]); err != nil { ...

63-95: Centralized metadata decoding mirrors prior per‑era logic; minor redundancies are safe

The new decodeTransactionMetadataSet correctly:

  • Treats each tx as []any and pulls metadata from index 2 only when present.
  • Preserves the uint(txIndex) keying used by common.TransactionMetadataSet.
  • Uses common.DecodeMetadatumRaw(lv.Cbor()), matching the existing decoding semantics.

Two minor nits you can ignore or address later:

  • The intermediate transactionMetadataSet map of *cbor.LazyValue could be skipped by decoding directly in the first loop.
  • The second if lv != nil check before decoding is redundant because you already gate on lv != nil when populating the map.

Neither affects correctness; the helper significantly reduces duplication across eras.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b8ced5 and bda1e0d.

📒 Files selected for processing (1)
  • ledger/verify_block_test.go (10 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
ledger/verify_block_test.go (8)
ledger/common/metadata.go (2)
  • TransactionMetadataSet (38-38)
  • DecodeMetadatumRaw (98-160)
cbor/value.go (1)
  • LazyValue (367-369)
ledger/shelley/shelley.go (1)
  • EraNameShelley (32-32)
ledger/allegra/allegra.go (1)
  • EraNameAllegra (28-28)
ledger/mary/mary.go (1)
  • EraNameMary (31-31)
ledger/alonzo/alonzo.go (1)
  • EraNameAlonzo (34-34)
ledger/babbage/babbage.go (1)
  • EraNameBabbage (34-34)
ledger/conway/conway.go (1)
  • EraNameConway (34-34)
⏰ 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). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
ledger/verify_block_test.go (1)

181-293: Refactored tx decoding & metadata wiring per era is consistent and preserves behavior

  • Changing txs to []any and decoding with cbor.Decode(bodyCborBytes, &txs) aligns with the updated helpers and keeps the decoded structure compatible with decodeTxBodies and decodeTransactionMetadataSet.
  • For each block type (Shelley, Allegra, Mary, Alonzo, Babbage, Conway), the generic decodeTxBodies[...] call uses the correct era‑specific transaction body type, and the corresponding call to decodeTransactionMetadataSet passes the matching EraName* constant, so metadata decoding now follows a single, consistent path.
  • The construction of each concrete block (ShelleyBlock, AllegraBlock, MaryBlock, AlonzoBlock, BabbageBlock, ConwayBlock) still wires TransactionBodies, TransactionWitnessSets, and TransactionMetadataSet together as before; the only real change is that metadata is no longer decoded inline per era.

This refactor looks good and should be behavior‑preserving while making future metadata test updates easier.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@wolf31o2 wolf31o2 merged commit 697f387 into main Nov 29, 2025
12 checks passed
@wolf31o2 wolf31o2 deleted the test/decode-metadata branch November 29, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants