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 fetch and display pool distribution for all pools or specified pool IDs, with raw and JSON output.
  • Improvements

    • Pool distribution results now use a well-structured representation for clearer fields and reliable serialization.
    • Queries tolerate missing/empty pool ID input and return the full distribution when none are provided.

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

Signed-off-by: Jenita <jkawan@blinklabs.io>
@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

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds a CLI "pool-distr" subcommand that requests pool distribution without explicit pool IDs, prints the raw response, and prints a JSON-serialized map of pool ID (hex) → entry. Updates the localstate query client GetPoolDistr to ensure poolIds is non-nil (substitutes an empty slice) and to always encode the parameter as a CBOR set tag (an empty set requests all pools). Replaces the previous PoolDistrResult any alias with a concrete exported PoolDistrResult struct (CBOR StructAsArray) that maps ledger.PoolId to entries containing StakeFraction (as *cbor.Rat) and VrfHash (ledger.Blake2b256).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify PoolDistrResult struct fields, CBOR annotations, and array encoding match on-chain serialization expectations.
  • Confirm GetPoolDistr behavior: non-nil poolIds, CBOR set tagging, and that an empty set requests the full distribution.
  • Review the CLI "pool-distr" case: raw output, construction of JSON-friendly map (pool ID hex keys), JSON marshaling, and error handling.
  • Check imports and visibility/compatibility of ledger.PoolId, cbor.Rat, and ledger.Blake2b256.

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR implements a concrete PoolDistrResult struct with CBOR serialization, updates GetPoolDistr to handle nil poolIds, and adds a pool-distr subcommand—all needed for issue #870.
Out of Scope Changes check ✅ Passed All changes (PoolDistrResult struct, GetPoolDistr logic, and pool-distr query command) are directly related to implementing pool distribution result handling per issue #870.
Title check ✅ Passed The title 'feat: implement PoolDistrResult' accurately reflects the main change—adding a concrete PoolDistrResult struct type with CBOR serialization support, which is the primary modification across the codebase.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-implement-pooldistributionresult

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.

Jenita added 2 commits November 17, 2025 18:44
Signed-off-by: Jenita <jkawan@blinklabs.io>
Signed-off-by: Jenita <jkawan@blinklabs.io>
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...,
)

Jenita added 2 commits December 2, 2025 19:52
Signed-off-by: Jenita <jkawan@blinklabs.io>
Signed-off-by: Jenita <jkawan@blinklabs.io>
Copy link
Contributor

@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.

2 issues found across 3 files

Prompt for AI agents (all 2 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="cmd/gouroboros/query.go">

<violation number="1" location="cmd/gouroboros/query.go:339">
P2: JSON marshaling error handling is inconsistent with other cases in this file. Other cases (e.g., `utxos-by-address`, `utxos-by-txin`) call `os.Exit(1)` after JSON marshal failures and use `ERROR:` prefix format. This case silently continues execution.</violation>
</file>

<file name="protocol/localstatequery/client.go">

<violation number="1" location="protocol/localstatequery/client.go:840">
P3: The comment is misleading: &#39;tag=21&#39; refers to the query type, not a CBOR tag. The CBOR set tag is actually 258 (`cbor.CborTagSet`). Consider clarifying: &#39;The query expects format: [queryType=21, CborTagSet(258, poolIds)]&#39; to avoid confusion between query types and CBOR tags.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

}
jsonData, err := json.Marshal(jsonResults)
if err != nil {
fmt.Printf("pool-distr (JSON marshaling failed): %s\n", err)
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 3, 2025

Choose a reason for hiding this comment

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

P2: JSON marshaling error handling is inconsistent with other cases in this file. Other cases (e.g., utxos-by-address, utxos-by-txin) call os.Exit(1) after JSON marshal failures and use ERROR: prefix format. This case silently continues execution.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At cmd/gouroboros/query.go, line 339:

<comment>JSON marshaling error handling is inconsistent with other cases in this file. Other cases (e.g., `utxos-by-address`, `utxos-by-txin`) call `os.Exit(1)` after JSON marshal failures and use `ERROR:` prefix format. This case silently continues execution.</comment>

<file context>
@@ -315,6 +315,31 @@ func testQuery(f *globalFlags) {
+		}
+		jsonData, err := json.Marshal(jsonResults)
+		if err != nil {
+			fmt.Printf(&quot;pool-distr (JSON marshaling failed): %s\n&quot;, err)
+		} else {
+			fmt.Printf(&quot;pool-distr (JSON): %s\n&quot;, string(jsonData))
</file context>
Suggested change
fmt.Printf("pool-distr (JSON marshaling failed): %s\n", err)
fmt.Printf("ERROR: failed to marshal pool-distr JSON: %s\n", err)
os.Exit(1)
Fix with Cubic

return nil, err
}
// GetPoolDistr always requires a pool set parameter according to the Haskell implementation
// The query expects (len=2, tag=21) format: [21, Set(poolIds)]
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 3, 2025

Choose a reason for hiding this comment

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

P3: The comment is misleading: 'tag=21' refers to the query type, not a CBOR tag. The CBOR set tag is actually 258 (cbor.CborTagSet). Consider clarifying: 'The query expects format: [queryType=21, CborTagSet(258, poolIds)]' to avoid confusion between query types and CBOR tags.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At protocol/localstatequery/client.go, line 840:

<comment>The comment is misleading: &#39;tag=21&#39; refers to the query type, not a CBOR tag. The CBOR set tag is actually 258 (`cbor.CborTagSet`). Consider clarifying: &#39;The query expects format: [queryType=21, CborTagSet(258, poolIds)]&#39; to avoid confusion between query types and CBOR tags.</comment>

<file context>
@@ -836,10 +836,19 @@ func (c *Client) GetPoolDistr(poolIds []any) (*PoolDistrResult, error) {
 		return nil, err
 	}
+	// GetPoolDistr always requires a pool set parameter according to the Haskell implementation
+	// The query expects (len=2, tag=21) format: [21, Set(poolIds)]
+	// If no pool IDs specified, use an empty set to query all pools
+	if poolIds == nil {
</file context>
Suggested change
// The query expects (len=2, tag=21) format: [21, Set(poolIds)]
// The query format is: [queryType(21), CborTagSet(258, poolIds)]
Fix with Cubic

Copy link
Contributor

@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 3 files

Signed-off-by: Jenita <jkawan@blinklabs.io>
@wolf31o2 wolf31o2 requested a review from agaffney December 9, 2025 17:15
@wolf31o2 wolf31o2 changed the title feat:added changes to implement poolDistresult feat: implement PoolDistrResult Dec 12, 2025
@wolf31o2 wolf31o2 merged commit 76174df into main Dec 12, 2025
11 checks passed
@wolf31o2 wolf31o2 deleted the feat-implement-pooldistributionresult branch December 12, 2025 03:11
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

4 participants