Skip to content

Conversation

@wolf31o2
Copy link
Member

@wolf31o2 wolf31o2 commented Nov 16, 2025

Summary by CodeRabbit

  • Tests

    • Added performance benchmarks for transaction type determination and serialization/deserialization operations across transaction types.
    • Expanded test coverage to measure performance characteristics across multiple transaction formats.
  • Chores

    • Reorganized test data into constants for improved maintainability.

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

coderabbitai bot commented Nov 16, 2025

📝 Walkthrough

Walkthrough

This change introduces performance benchmarking infrastructure for transaction handling across multiple Cardano eras. Two new public constants containing CBOR hexadecimal representations of Byron and Conway transaction samples have been added to replace inline literals in test setup. Six new benchmark functions have been introduced to measure performance of transaction type determination, deserialization, and serialization operations for both Byron and Conway era transactions. The existing test flow is preserved while expanding test coverage to these additional transaction paths. Minor formatting adjustments were made to error handling assertions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify the byronTxCborHex and conwayTxCborHex constants contain valid and distinct CBOR hex representations
  • Confirm all six benchmark functions follow consistent implementation patterns and use the correct constants
  • Check that benchmark function signatures and naming conventions align with Go testing standards
  • Validate that the formatting changes in error assertions maintain correct test behavior

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 accurately describes the main changes: addition of serialization/deserialization and transaction type determination benchmarks for the ledger package.
✨ 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/determine-and-serde-bench

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.

@wolf31o2
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 16, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

24-27: Consider making constants private.

The constants are exported but appear to be used only within this file. Unless they need to be shared with other test files in the ledger_test package, consider making them private (lowercase names) to limit their scope.

 const (
-	byronTxCborHex = "839f8200d8185824825820a12a839c25a01fa5d118167db5acdbd9e38172ae8f00e5ac0a4997ef792a200700ff9f8282d818584283581c6c9982e7f2b6dcc5eaa880e8014568913c8868d9f0f86eb687b2633ca101581e581c010d876783fb2b4d0d17c86df29af8d35356ed3d1827bf4744f06700001a8dc672c11a000f4240ffa0"
-	conwayTxCborHex = "84a500d9010281825820279184037d249e397d97293738370756da559718fcdefae9924834840046b37b01018282583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1a00a9867082583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1b00000001267d7b04021a0002938d031a04e304e70800a100d9010281825820b829480e5d5827d2e1bd7c89176a5ca125c30812e54be7dbdf5c47c835a17f3d5840b13a76e7f2b19cde216fcad55ceeeb489ebab3dcf63ef1539ac4f535dece00411ee55c9b8188ef04b4aa3c72586e4a0ec9b89949367d7270fdddad3b18731403f5f6"
+	byronTxCborHex  = "839f8200d8185824825820a12a839c25a01fa5d118167db5acdbd9e38172ae8f00e5ac0a4997ef792a200700ff9f8282d818584283581c6c9982e7f2b6dcc5eaa880e8014568913c8868d9f0f86eb687b2633ca101581e581c010d876783fb2b4d0d17c86df29af8d35356ed3d1827bf4744f06700001a8dc672c11a000f4240ffa0"
+	conwayTxCborHex = "84a500d9010281825820279184037d249e397d97293738370756da559718fcdefae9924834840046b37b01018282583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1a00a9867082583900923d4b64e1d730a4baf3e6dc433a9686983940f458363f37aad7a1a9568b72f85522e4a17d44a45cd021b9741b55d7cbc635c911625b015e1b00000001267d7b04021a0002938d031a04e304e70800a100d9010281825820b829480e5d5827d2e1bd7c89176a5ca125c30812e54be7dbdf5c47c835a17f3d5840b13a76e7f2b19cde216fcad55ceeeb489ebab3dcf63ef1539ac4f535dece00411ee55c9b8188ef04b4aa3c72586e4a0ec9b89949367d7270fdddad3b18731403f5f6"
 )

67-92: Consider handling hex decode errors for robustness.

All benchmarks ignore errors from hex.DecodeString. While this is common practice when input is known to be valid (validated by the test), explicitly checking these errors would improve consistency and make debugging easier if the constants are ever modified incorrectly.

Example for BenchmarkDetermineTransactionType_Conway:

 func BenchmarkDetermineTransactionType_Conway(b *testing.B) {
-	txCbor, _ := hex.DecodeString(conwayTxCborHex)
+	txCbor, err := hex.DecodeString(conwayTxCborHex)
+	if err != nil {
+		b.Fatalf("failed to decode hex: %s", err)
+	}
 	b.ResetTimer()
 	for i := 0; i < b.N; i++ {
 		_, err := ledger.DetermineTransactionType(txCbor)

Apply similar changes to other benchmark functions.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b93f5f3 and 9c776f0.

📒 Files selected for processing (1)
  • ledger/tx_test.go (3 hunks)
🔇 Additional comments (3)
ledger/tx_test.go (3)

29-65: LGTM!

The refactoring to use constants improves maintainability and DRY principles. The test validates that both transaction hex strings are valid and correctly classified.


94-138: Well-structured benchmarks.

The deserialization and serialization benchmarks are correctly implemented:

  • Setup happens before b.ResetTimer()
  • Serialization benchmarks properly prepare transaction objects outside the timed loop
  • Each benchmark measures a single, focused operation

78-81: LGTM!

The comment provides helpful context about benchmark coverage and clarifies that the Conway type determination benchmark exercises the fallthrough logic across multiple eras.

@wolf31o2 wolf31o2 merged commit fad1241 into main Nov 17, 2025
10 checks passed
@wolf31o2 wolf31o2 deleted the test/determine-and-serde-bench branch November 17, 2025 14:54
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