Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update exposed db objects in x/btcstaking module #202

Merged
merged 5 commits into from
Oct 16, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* Updated related tests in `x/finality/keeper/grpc_query_test.go`.
* [#200](https://github.com/babylonlabs-io/babylon/pull/200) Adjusted handling of `Gauge` in incentive keeper queries to improve API security.
* [#201](https://github.com/babylonlabs-io/babylon/pull/201) Adjusted handling of `ValidatorWithBlsKey` in checkpoint keeper queries to improve API security.
* [#202](https://github.com/babylonlabs-io/babylon/pull/202) Adjusted handling of `FinalityProviderWithMeta` in btcstaking keeper queries to improve API security.

### State Machine Breaking

Expand Down
23 changes: 22 additions & 1 deletion proto/babylon/btcstaking/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,32 @@ message QueryActiveFinalityProvidersAtHeightRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// ActiveFinalityProvidersAtHeightResponse wraps the FinalityProvider with metadata.
message ActiveFinalityProvidersAtHeightResponse {
// btc_pk is the Bitcoin secp256k1 PK of thisfinality provider
// the PK follows encoding in BIP-340 spec
string btc_pk_hex = 1 [ (gogoproto.customtype) = "github.com/babylonlabs-io/babylon/types.BIP340PubKey" ];
// height is the queried Babylon height
uint64 height = 2;
// voting_power is the voting power of this finality provider at the given height
uint64 voting_power = 3;
// slashed_babylon_height indicates the Babylon height when
// the finality provider is slashed.
// if it's 0 then the finality provider is not slashed
uint64 slashed_babylon_height = 4;
// slashed_btc_height indicates the BTC height when
// the finality provider is slashed.
// if it's 0 then the finality provider is not slashed
uint32 slashed_btc_height = 5;
// jailed defines whether the finality provider is detected jailed
bool jailed = 6;
}

// QueryActiveFinalityProvidersAtHeightResponse is the response type for the
// Query/ActiveFinalityProvidersAtHeight RPC method.
message QueryActiveFinalityProvidersAtHeightResponse {
// finality_providers contains all the queried finality providersn.
repeated FinalityProviderWithMeta finality_providers = 1;
repeated ActiveFinalityProvidersAtHeightResponse finality_providers = 1;

// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/configurer/chain/queries_btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (n *NodeConfig) QueryFinalityProviders() []*bstypes.FinalityProviderRespons
return resp.FinalityProviders
}

func (n *NodeConfig) QueryActiveFinalityProvidersAtHeight(height uint64) []*bstypes.FinalityProviderWithMeta {
func (n *NodeConfig) QueryActiveFinalityProvidersAtHeight(height uint64) []*bstypes.ActiveFinalityProvidersAtHeightResponse {
path := fmt.Sprintf("/babylon/btcstaking/v1/finality_providers/%d", height)
bz, err := n.QueryGRPCGateway(path, url.Values{})
require.NoError(n.t, err)
Expand Down
17 changes: 16 additions & 1 deletion x/btcstaking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (k Keeper) ActiveFinalityProvidersAtHeight(ctx context.Context, req *types.
return nil, err
}

return &types.QueryActiveFinalityProvidersAtHeightResponse{FinalityProviders: finalityProvidersWithMeta, Pagination: pageRes}, nil
return &types.QueryActiveFinalityProvidersAtHeightResponse{FinalityProviders: convertToActiveFinalityProvidersAtHeightResponse(finalityProvidersWithMeta), Pagination: pageRes}, nil
}

// ActivatedHeight returns the Babylon height in which the BTC Staking protocol was enabled
Expand Down Expand Up @@ -302,3 +302,18 @@ func (k Keeper) BTCDelegation(ctx context.Context, req *types.QueryBTCDelegation
BtcDelegation: types.NewBTCDelegationResponse(btcDel, status),
}, nil
}

func convertToActiveFinalityProvidersAtHeightResponse(finalityProvidersWithMeta []*types.FinalityProviderWithMeta) []*types.ActiveFinalityProvidersAtHeightResponse {
var activeFinalityProvidersAtHeightResponse []*types.ActiveFinalityProvidersAtHeightResponse
for _, fpWithMeta := range finalityProvidersWithMeta {
activeFinalityProvidersAtHeightResponse = append(activeFinalityProvidersAtHeightResponse, &types.ActiveFinalityProvidersAtHeightResponse{
BtcPkHex: fpWithMeta.BtcPk,
Height: fpWithMeta.Height,
VotingPower: fpWithMeta.VotingPower,
SlashedBabylonHeight: fpWithMeta.SlashedBabylonHeight,
samricotta marked this conversation as resolved.
Show resolved Hide resolved
SlashedBtcHeight: fpWithMeta.SlashedBtcHeight,
Jailed: fpWithMeta.Jailed,
})
}
return activeFinalityProvidersAtHeightResponse
}
4 changes: 2 additions & 2 deletions x/btcstaking/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,10 @@ func FuzzActiveFinalityProvidersAtHeight(f *testing.F) {

for _, fp := range resp.FinalityProviders {
// Check if the pk exists in the map
if _, ok := fpsWithVotingPowerMap[fp.BtcPk.MarshalHex()]; !ok {
if _, ok := fpsWithVotingPowerMap[fp.BtcPkHex.MarshalHex()]; !ok {
t.Fatalf("rpc returned a finality provider that was not created")
}
fpsFound[fp.BtcPk.MarshalHex()] = true
fpsFound[fp.BtcPkHex.MarshalHex()] = true
}

// Construct the next page request
Expand Down
Loading
Loading