Skip to content

Conversation

@jkawan
Copy link
Contributor

@jkawan jkawan commented Nov 18, 2025

Closes #870

While running the query against the cardano node, I keep getting one of the following
root@7ebe79e76ec2:/code# go run ./cmd/gouroboros/ -network devnet -network-magic 42 -socket /ipc/node.socket query pool-distr
ERROR: peer closed the connection while reading header: EOF
exit status 1
root@7ebe79e76ec2:/code# go run ./cmd/gouroboros/ -network devnet -network-magic 42 -socket /ipc/node.socket query pool-distr
ERROR: failure querying pool distribution: protocol is shutting down
exit status 1

Summary by CodeRabbit

  • New Features

    • Added a "pool-distr" command to query pool distribution for all pools or for specific pool IDs.
  • Improvements

    • Results now use a structured representation and include JSON output for easier consumption.
    • Query behavior adapts when no pool IDs are provided, returning full distribution without requiring parameters.

@jkawan jkawan requested a review from a team as a code owner November 18, 2025 00:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 18, 2025

📝 Walkthrough

Walkthrough

Adds a new "pool-distr" CLI subcommand that requests pool distribution and prints both raw and JSON-serialized outputs. Updates the local state query client GetPoolDistr to build two query forms: no-parameter Shelley pool distribution when poolIds is empty, or a CBOR set-tagged query when poolIds are provided. Replaces the prior PoolDistrResult any alias with a concrete PoolDistrResult struct (CBOR-tagged) that maps ledger.PoolId to entries containing StakeFraction and VrfHash.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the new PoolDistrResult struct fields and CBOR annotations for correct types and serialization.
  • Verify GetPoolDistr query construction branches correctly for empty vs non-empty poolIds (CBOR set encoding).
  • Check the CLI "pool-distr" subcommand error handling and JSON marshaling/printing.
  • Inspect any ledger type imports/aliases (ledger.PoolId, cbor.Rat, Blake2b256) for correct usage and visibility.

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title mentions 'poolDistresult' but uses informal phrasing ('added changes to implement') and lacks clarity about the actual implementation scope. Revise title to be more concise and professional, e.g., 'Implement PoolDistrResult type with pool distribution query support' to better reflect the multi-file changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR implements PoolDistrResult struct with CBOR serialization, updates GetPoolDistr to handle empty/non-empty poolIds, and adds pool-distr query subcommand, addressing the core requirement from issue #870.
Out of Scope Changes check ✅ Passed All changes (PoolDistrResult struct definition, GetPoolDistr conditional logic, and pool-distr subcommand) are directly related to implementing pool distribution result handling as specified in issue #870.
✨ 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 feat-implement-pooldistributionresult

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0136bf and 6a763b6.

📒 Files selected for processing (1)
  • cmd/gouroboros/query.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/gouroboros/query.go

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: 1

🧹 Nitpick comments (1)
protocol/localstatequery/client.go (1)

839-856: Query construction for GetPoolDistr looks correct; consider tightening parameter type

The conditional construction—no params for “all pools” and a CborTagSet when poolIds is non-empty—matches the pattern used in GetStakePoolParams and should be acceptable from a CBOR perspective.

Two follow-ups worth considering:

  • Use a stronger type for poolIds (e.g., []ledger.PoolId) instead of []any for consistency with GetStakePoolParams and to prevent accidental misuse.
  • Double-check against the local-state-query CDDL/spec that the “no params” form for QueryTypeShelleyPoolDistr is indeed the correct way to request all pools.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd01888 and b0136bf.

📒 Files selected for processing (3)
  • cmd/gouroboros/query.go (1 hunks)
  • protocol/localstatequery/client.go (1 hunks)
  • protocol/localstatequery/queries.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
protocol/localstatequery/client.go (3)
protocol/localstatequery/queries.go (1)
  • QueryTypeShelleyPoolDistr (64-64)
cbor/cbor.go (1)
  • Tag (40-40)
cbor/tags.go (1)
  • CborTagSet (31-31)
protocol/localstatequery/queries.go (3)
cbor/cbor.go (1)
  • StructAsArray (45-48)
ledger/common/common.go (2)
  • PoolId (449-449)
  • Blake2b256 (41-41)
cbor/tags.go (1)
  • Rat (94-96)
cmd/gouroboros/query.go (2)
protocol/localstatequery/localstatequery.go (1)
  • LocalStateQuery (116-119)
protocol/localstatequery/client.go (1)
  • Client (30-43)
🪛 GitHub Actions: golangci-lint
cmd/gouroboros/query.go

[error] 330-330: encoding/json.Marshal for unsupported type github.com/blinklabs-io/gouroboros/ledger.PoolId as map key found (errchkjson)

🪛 GitHub Check: lint
cmd/gouroboros/query.go

[failure] 330-330:
encoding/json.Marshal for unsupported type github.com/blinklabs-io/gouroboros/ledger.PoolId as map key found (errchkjson)

⏰ 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 (1)
protocol/localstatequery/queries.go (1)

725-734: PoolDistrResult structure is consistent with existing CBOR result types

The layout mirrors StakeDistributionResult (StructAsArray + map[ledger.PoolId]{StakeFraction, VrfHash}), which is appropriate for decoding the pool distribution response. No issues from a type/CBOR-shape perspective.

cbor.Tag{
Number: cbor.CborTagSet,
Content: poolIds,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

We have the cbor.Set type that handles this

QueryTypeShelleyPoolDistr,
)
} else {
query = buildShelleyQuery(
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of building the query twice, it's a bit cleaner to build the params dynamically. Something like this:

var params []any
if len(poolIds) > 0 {
  params = append(params, cbor.Set(poolIds))
}
query := buildShelleyQuery(
  currentEra,
  QueryTypeShelleyPoolDistr,
  params...,
)

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.

Implement PoolDistrResult

3 participants