From b0136bf1a6d710e647749826d9a19267721c9a13 Mon Sep 17 00:00:00 2001 From: Jenita Date: Mon, 17 Nov 2025 18:37:09 -0600 Subject: [PATCH 1/3] feat:added changes to implement poolDistresult Signed-off-by: Jenita --- cmd/gouroboros/query.go | 18 ++++++++++++++++++ protocol/localstatequery/client.go | 23 ++++++++++++++++++----- protocol/localstatequery/queries.go | 12 ++++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/cmd/gouroboros/query.go b/cmd/gouroboros/query.go index 230a2e6c..99e57a64 100644 --- a/cmd/gouroboros/query.go +++ b/cmd/gouroboros/query.go @@ -315,6 +315,24 @@ 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([]any{}) + if err != nil { + fmt.Printf( + "ERROR: failure querying pool distribution: %s\n", + err, + ) + os.Exit(1) + } + fmt.Printf("pool-distr (raw): %#v\n", poolDistr) + // Also try JSON marshaling to see structure + jsonData, err := json.Marshal(poolDistr) + if err != nil { + fmt.Printf("pool-distr (JSON marshaling failed): %s\n", err) + } 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) diff --git a/protocol/localstatequery/client.go b/protocol/localstatequery/client.go index 1c938362..866834f9 100644 --- a/protocol/localstatequery/client.go +++ b/protocol/localstatequery/client.go @@ -836,11 +836,24 @@ func (c *Client) GetPoolDistr(poolIds []any) (*PoolDistrResult, error) { if err != nil { return nil, err } - query := buildShelleyQuery( - currentEra, - QueryTypeShelleyPoolDistr, - // TODO: add args (#870) - ) + // If no pool IDs specified, query without parameters (get all pools) + // Otherwise, query with specific pool IDs as a CBOR set + var query []any + if len(poolIds) == 0 { + query = buildShelleyQuery( + currentEra, + QueryTypeShelleyPoolDistr, + ) + } else { + query = buildShelleyQuery( + currentEra, + QueryTypeShelleyPoolDistr, + cbor.Tag{ + Number: cbor.CborTagSet, + Content: poolIds, + }, + ) + } var result PoolDistrResult if err := c.runQuery(query, &result); err != nil { return nil, err diff --git a/protocol/localstatequery/queries.go b/protocol/localstatequery/queries.go index a81b2526..02cc057e 100644 --- a/protocol/localstatequery/queries.go +++ b/protocol/localstatequery/queries.go @@ -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 + } +} From 554c1e26cb55d661424741d0ecb7a6b1af7ff8d9 Mon Sep 17 00:00:00 2001 From: Jenita Date: Mon, 17 Nov 2025 18:44:59 -0600 Subject: [PATCH 2/3] feat:added changes to implement poolDistresult Signed-off-by: Jenita --- cmd/gouroboros/query.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/gouroboros/query.go b/cmd/gouroboros/query.go index 99e57a64..04159afa 100644 --- a/cmd/gouroboros/query.go +++ b/cmd/gouroboros/query.go @@ -316,7 +316,6 @@ func testQuery(f *globalFlags) { } 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([]any{}) if err != nil { fmt.Printf( @@ -326,12 +325,18 @@ func testQuery(f *globalFlags) { os.Exit(1) } fmt.Printf("pool-distr (raw): %#v\n", poolDistr) - // Also try JSON marshaling to see structure - jsonData, err := json.Marshal(poolDistr) - if err != nil { - fmt.Printf("pool-distr (JSON marshaling failed): %s\n", err) - } else { - fmt.Printf("pool-distr (JSON): %s\n", string(jsonData)) + // Convert to JSON-serializable format (PoolId keys need to be strings) + if poolDistr != nil && poolDistr.Results != nil { + jsonMap := make(map[string]any) + for poolId, distribution := range poolDistr.Results { + jsonMap[poolId.String()] = distribution + } + jsonData, err := json.Marshal(jsonMap) + if err != nil { + fmt.Printf("pool-distr (JSON marshaling failed): %s\n", err) + } else { + fmt.Printf("pool-distr (JSON): %s\n", string(jsonData)) + } } default: fmt.Printf("ERROR: unknown query: %s\n", queryFlags.flagset.Args()[0]) From 6a763b6a3ab6942a7453d4cae0f0d7119a30d3d2 Mon Sep 17 00:00:00 2001 From: Jenita Date: Mon, 17 Nov 2025 18:47:39 -0600 Subject: [PATCH 3/3] feat:added changes to implement poolDistresult Signed-off-by: Jenita --- cmd/gouroboros/query.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/cmd/gouroboros/query.go b/cmd/gouroboros/query.go index 04159afa..86a73bae 100644 --- a/cmd/gouroboros/query.go +++ b/cmd/gouroboros/query.go @@ -316,7 +316,8 @@ func testQuery(f *globalFlags) { } fmt.Printf("proposed-protocol-params-updates: %v\n", *proposedUpdates) case "pool-distr": - poolDistr, err := o.LocalStateQuery().Client.GetPoolDistr([]any{}) + // 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", @@ -325,18 +326,19 @@ func testQuery(f *globalFlags) { os.Exit(1) } fmt.Printf("pool-distr (raw): %#v\n", poolDistr) - // Convert to JSON-serializable format (PoolId keys need to be strings) - if poolDistr != nil && poolDistr.Results != nil { - jsonMap := make(map[string]any) - for poolId, distribution := range poolDistr.Results { - jsonMap[poolId.String()] = distribution - } - jsonData, err := json.Marshal(jsonMap) - if err != nil { - fmt.Printf("pool-distr (JSON marshaling failed): %s\n", err) - } else { - fmt.Printf("pool-distr (JSON): %s\n", string(jsonData)) - } + + // 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) + } else { + fmt.Printf("pool-distr (JSON): %s\n", string(jsonData)) } default: fmt.Printf("ERROR: unknown query: %s\n", queryFlags.flagset.Args()[0])