Skip to content

Conversation

@wolf31o2
Copy link
Member

@wolf31o2 wolf31o2 commented Nov 4, 2025

Summary by CodeRabbit

  • Refactor
    • Updated pool state lookup mechanism to use stricter type parameters instead of generic byte arrays, improving type safety across ledger implementations. Consolidated API consistency across multiple ledger rules.

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

coderabbitai bot commented Nov 4, 2025

📝 Walkthrough

Walkthrough

This pull request refactors the PoolCurrentState method signature to use a typed PoolKeyHash parameter instead of a raw []byte. The interface definition in ledger/common/state.go is updated accordingly. The mock implementation in internal/test/ledger/ledger.go is modified to handle hashing internally via Blake2b224(poolKeyHash).Bytes(). All call sites across five rule files (alonzo, babbage, conway, mary, shelley) are updated to pass the Blake2b224 hash object directly instead of calling .Bytes() on it.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Interface signature change: Single method contract update in ledger/common/state.go from []byte to PoolKeyHash
  • Homogeneous call site updates: Five identical modifications across rules files (alonzo, babbage, conway, mary, shelley) following the same pattern—removing .Bytes() call
  • Mock implementation logic: Verify the hashing logic in internal/test/ledger/ledger.go correctly implements the type conversion and comparison

Areas requiring extra attention:

  • Verify all implementations of the PoolState interface have been updated to match the new signature
  • Confirm the mock's Blake2b224 hashing logic correctly handles the PoolKeyHash input type
  • Ensure no other call sites to PoolCurrentState exist outside the five updated files

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 clearly and specifically describes the main change: refactoring the ledger code to use the typed PoolKeyHash instead of []byte for the PoolCurrentState method signature and all call sites.
✨ 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 refactor/ls-pkh

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)
internal/test/ledger/ledger.go (1)

66-81: LGTM! Mock implementation updated correctly.

The signature change and comparison logic are correct. Both cert.Operator and poolKeyHash are properly compared as PoolKeyHash values.

The comparison could be simplified since PoolKeyHash is a fixed-size array (directly comparable):

 func (ls MockLedgerState) PoolCurrentState(
 	poolKeyHash common.PoolKeyHash,
 ) (*common.PoolRegistrationCertificate, *uint64, error) {
 	for _, cert := range ls.MockPoolRegistration {
-		if string(
-			common.Blake2b224(cert.Operator).Bytes(),
-		) == string(
-			common.Blake2b224(poolKeyHash).Bytes(),
-		) {
+		if cert.Operator == poolKeyHash {
 			// pretend latest registration is current; no retirement support in mock
 			c := cert
 			return &c, nil, nil
 		}
 	}
 	return nil, nil, nil
 }

This eliminates redundant type conversions and byte comparisons.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6dfab7d and bb958e2.

📒 Files selected for processing (7)
  • internal/test/ledger/ledger.go (1 hunks)
  • ledger/alonzo/rules.go (1 hunks)
  • ledger/babbage/rules.go (1 hunks)
  • ledger/common/state.go (1 hunks)
  • ledger/conway/rules.go (1 hunks)
  • ledger/mary/rules.go (1 hunks)
  • ledger/shelley/rules.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (7)
ledger/common/state.go (1)
ledger/common/certs.go (1)
  • PoolKeyHash (331-331)
ledger/conway/rules.go (2)
ledger/common/common.go (1)
  • Blake2b224 (74-74)
ledger/compat.go (1)
  • Blake2b224 (26-26)
internal/test/ledger/ledger.go (2)
ledger/common/certs.go (2)
  • PoolKeyHash (331-331)
  • PoolRegistrationCertificate (430-443)
ledger/common/common.go (1)
  • Blake2b224 (74-74)
ledger/mary/rules.go (1)
ledger/common/common.go (1)
  • Blake2b224 (74-74)
ledger/babbage/rules.go (2)
ledger/common/common.go (1)
  • Blake2b224 (74-74)
ledger/compat.go (1)
  • Blake2b224 (26-26)
ledger/shelley/rules.go (1)
ledger/common/common.go (1)
  • Blake2b224 (74-74)
ledger/alonzo/rules.go (1)
ledger/common/common.go (1)
  • Blake2b224 (74-74)
⏰ 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). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (6)
ledger/common/state.go (1)

38-38: LGTM! Improved type safety with PoolKeyHash.

The interface signature change from []byte to PoolKeyHash enhances type safety and makes the API more explicit about what kind of data is expected.

ledger/shelley/rules.go (1)

199-199: LGTM! Call site updated correctly.

The call now passes Blake2b224(tmpCert.Operator) directly as a PoolKeyHash, correctly matching the updated interface signature.

ledger/conway/rules.go (1)

275-275: LGTM! Consistent with interface change.

The call site correctly passes the PoolKeyHash directly, aligning with the updated interface signature.

ledger/mary/rules.go (1)

178-178: LGTM! Updated consistently.

The change correctly passes the PoolKeyHash directly to PoolCurrentState.

ledger/alonzo/rules.go (1)

292-292: LGTM! Call site properly updated.

The PoolCurrentState call correctly passes the PoolKeyHash directly, matching the new interface.

ledger/babbage/rules.go (1)

278-278: LGTM! Correctly updated.

The change aligns with the new PoolCurrentState signature by passing the PoolKeyHash directly.

@wolf31o2 wolf31o2 merged commit 55c1e3d into main Nov 5, 2025
10 checks passed
@wolf31o2 wolf31o2 deleted the refactor/ls-pkh branch November 5, 2025 14:42
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