Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cmd/gouroboros/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,31 @@ func testQuery(f *globalFlags) {
os.Exit(1)
}
fmt.Printf("proposed-protocol-params-updates: %v\n", *proposedUpdates)
case "pool-distr":
// GetPoolDistr without specific pool IDs to get all pools distribution
poolDistr, err := o.LocalStateQuery().Client.GetPoolDistr(nil)
if err != nil {
fmt.Printf(
"ERROR: failure querying pool distribution: %s\n",
err,
)
os.Exit(1)
}
fmt.Printf("pool-distr (raw): %#v\n", poolDistr)

// Build a JSON-friendly view: map pool ID (hex) -> entry
jsonResults := make(map[string]any, len(poolDistr.Results))
for poolID, entry := range poolDistr.Results {
// PoolId is [28]byte; represent as hex for debugging
jsonKey := hex.EncodeToString(poolID[:])
jsonResults[jsonKey] = entry
}
jsonData, err := json.Marshal(jsonResults)
if err != nil {
fmt.Printf("pool-distr (JSON marshaling failed): %s\n", err)
Copy link

@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

} else {
fmt.Printf("pool-distr (JSON): %s\n", string(jsonData))
}
default:
fmt.Printf("ERROR: unknown query: %s\n", queryFlags.flagset.Args()[0])
os.Exit(1)
Expand Down
10 changes: 9 additions & 1 deletion protocol/localstatequery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,18 @@ func (c *Client) GetPoolDistr(poolIds []any) (*PoolDistrResult, error) {
if err != nil {
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

@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

// If no pool IDs specified, use an empty set to query all pools
var params []any
if poolIds == nil {
poolIds = []any{}
}
params = append(params, cbor.Set(poolIds))
query := buildShelleyQuery(
currentEra,
QueryTypeShelleyPoolDistr,
// TODO: add args (#870)
params...,
)
var result PoolDistrResult
if err := c.runQuery(query, &result); err != nil {
Expand Down
12 changes: 10 additions & 2 deletions protocol/localstatequery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,13 @@ type PoolStateResult any
// TODO (#869)
type StakeSnapshotsResult any

// TODO (#870)
type PoolDistrResult any
// PoolDistrResult represents the pool distribution result
// It contains a map of pool IDs to their stake distribution (fraction and VRF hash)
type PoolDistrResult struct {
cbor.StructAsArray
Results map[ledger.PoolId]struct {
cbor.StructAsArray
StakeFraction *cbor.Rat
VrfHash ledger.Blake2b256
}
}