Skip to content

Commit

Permalink
chore: update exposed db objects in x/incentive module (#200)
Browse files Browse the repository at this point in the history
## Summary

Part closes: babylonlabs-io/pm#72

Currently some of the objects in the babylon apis are exposed and need
to be handled correctly seen in
babylonlabs-io/pm#72

This PR handles the exposed objects in `x/incentive`
  • Loading branch information
samricotta authored Oct 16, 2024
1 parent 35610ce commit 1c00726
Show file tree
Hide file tree
Showing 6 changed files with 469 additions and 63 deletions.
11 changes: 5 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### API Breaking

* [#194](https://github.com/babylonlabs-io/babylon/pull/194) Adjusted handling of `FinalityProviderSigningInfo` in finality keeper queries to improve API security
* Modified `QuerySigningInfosResponse` to remove direct exposure of sensitive fields
* Updated related tests in `x/finality/keeper/grpc_query_test.go`
* [#201](https://github.com/babylonlabs-io/babylon/pull/201) Adjusted handling of `ValidatorWithBlsKey` in checkpoint keeper queries to improve API security
* Modified `QueryBlsPublicKeyListResponse` to remove direct exposure of sensitive fields
* Updated related tests in `x/checkpointing/keeper/grpc_query_bls.go`
* [#194](https://github.com/babylonlabs-io/babylon/pull/194) Adjusted handling of `FinalityProviderSigningInfo` in finality keeper queries to improve API security.
* Modified `QuerySigningInfosResponse` to remove direct exposure of sensitive fields.
* 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.

### State Machine Breaking

Expand Down
27 changes: 24 additions & 3 deletions proto/babylon/incentive/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "babylon/incentive/params.proto";
import "babylon/incentive/incentive.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/babylonlabs-io/babylon/x/incentive/types";

Expand Down Expand Up @@ -56,10 +57,30 @@ message QueryBTCStakingGaugeRequest {
uint64 height = 1;
}

message BTCStakingGaugeResponse {
// coins that have been in the gauge
// can have multiple coin denoms
repeated cosmos.base.v1beta1.Coin coins = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

}

message BTCTimestampingGaugeResponse {
// coins that have been in the gauge
// can have multiple coin denoms
repeated cosmos.base.v1beta1.Coin coins = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

}

// QueryBTCStakingGaugeResponse is response type for the Query/BTCStakingGauge RPC method.
message QueryBTCStakingGaugeResponse {
// gauge is the BTC staking gauge at the queried height
Gauge gauge = 1;
BTCStakingGaugeResponse gauge = 1;
}

// QueryBTCTimestampingGaugeRequest is request type for the Query/BTCTimestampingGauge RPC method.
Expand All @@ -71,5 +92,5 @@ message QueryBTCTimestampingGaugeRequest {
// QueryBTCTimestampingGaugeResponse is response type for the Query/BTCTimestampingGauge RPC method.
message QueryBTCTimestampingGaugeResponse {
// gauge is the BTC timestamping gauge at the queried epoch
Gauge gauge = 1;
}
BTCTimestampingGaugeResponse gauge = 1;
}
2 changes: 1 addition & 1 deletion test/e2e/btc_timestamping_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (s *BTCTimestampingTestSuite) Test6InterceptFeeCollector() {
// at the 1st block of an epoch, the gauge does not exist since incentive's BeginBlock
// at this block accumulates rewards for BTC timestamping gauge for the previous block
// need to wait for a block to ensure the gauge is created
var btcTimestampingGauge *itypes.Gauge
var btcTimestampingGauge *itypes.BTCTimestampingGaugeResponse
s.Eventually(func() bool {
btcTimestampingGauge, err = nonValidatorNode.QueryBTCTimestampingGauge(curEpoch)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/configurer/chain/queries_incentive.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
)

func (n *NodeConfig) QueryBTCStakingGauge(height uint64) (*incentivetypes.Gauge, error) {
func (n *NodeConfig) QueryBTCStakingGauge(height uint64) (*incentivetypes.BTCStakingGaugeResponse, error) {
path := fmt.Sprintf("/babylon/incentive/btc_staking_gauge/%d", height)
bz, err := n.QueryGRPCGateway(path, url.Values{})
if err != nil {
Expand Down Expand Up @@ -52,7 +52,7 @@ func (n *NodeConfig) QueryRewardGauge(sAddr sdk.AccAddress) (map[string]*incenti
return resp.RewardGauges, nil
}

func (n *NodeConfig) QueryBTCTimestampingGauge(epoch uint64) (*incentivetypes.Gauge, error) {
func (n *NodeConfig) QueryBTCTimestampingGauge(epoch uint64) (*incentivetypes.BTCTimestampingGaugeResponse, error) {
path := fmt.Sprintf("/babylon/incentive/btc_timestamping_gauge/%d", epoch)
bz, err := n.QueryGRPCGateway(path, url.Values{})
if err != nil {
Expand Down
16 changes: 14 additions & 2 deletions x/incentive/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (k Keeper) BTCStakingGauge(goCtx context.Context, req *types.QueryBTCStakin
return nil, types.ErrBTCStakingGaugeNotFound
}

return &types.QueryBTCStakingGaugeResponse{Gauge: gauge}, nil
return &types.QueryBTCStakingGaugeResponse{Gauge: convertGaugeToBTCStakingResponse(*gauge)}, nil
}

func (k Keeper) BTCTimestampingGauge(goCtx context.Context, req *types.QueryBTCTimestampingGaugeRequest) (*types.QueryBTCTimestampingGaugeResponse, error) {
Expand All @@ -69,5 +69,17 @@ func (k Keeper) BTCTimestampingGauge(goCtx context.Context, req *types.QueryBTCT
return nil, types.ErrBTCTimestampingGaugeNotFound
}

return &types.QueryBTCTimestampingGaugeResponse{Gauge: gauge}, nil
return &types.QueryBTCTimestampingGaugeResponse{Gauge: convertGaugeToBTCTimestampingResponse(*gauge)}, nil
}

func convertGaugeToBTCStakingResponse(gauge types.Gauge) *types.BTCStakingGaugeResponse {
return &types.BTCStakingGaugeResponse{
Coins: gauge.Coins,
}
}

func convertGaugeToBTCTimestampingResponse(gauge types.Gauge) *types.BTCTimestampingGaugeResponse {
return &types.BTCTimestampingGaugeResponse{
Coins: gauge.Coins,
}
}
Loading

0 comments on commit 1c00726

Please sign in to comment.