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: Handle FinalityProviderSigningInfo object #194

Merged
merged 7 commits into from
Oct 15, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### 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`

### State Machine Breaking

* [#181](https://github.com/babylonlabs-io/babylon/pull/181) Modify BTC heights
Expand Down
21 changes: 18 additions & 3 deletions proto/babylon/finality/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "babylon/finality/v1/params.proto";
import "babylon/finality/v1/finality.proto";
import "google/protobuf/timestamp.proto";
import "amino/amino.proto";

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

Expand Down Expand Up @@ -229,11 +231,24 @@ message QuerySigningInfoRequest {
string fp_btc_pk_hex = 1;
}

// SigningInfoResponse defines the API response containing a finality provider's signing info
// for monitoring their liveness activity.
message SigningInfoResponse {
// fp_btc_pk is the BTC PK of the finality provider that casts this vote
string fp_btc_pk_hex = 1;
samricotta marked this conversation as resolved.
Show resolved Hide resolved
// start_height is the block height at which finality provider become active
int64 start_height = 2;
// missed_blocks_counter defines a counter to avoid unnecessary array reads.
// Note that `Sum(MissedBlocksBitArray)` always equals `MissedBlocksCounter`.
int64 missed_blocks_counter = 3;
// Timestamp until which the validator is jailed due to liveness downtime.
google.protobuf.Timestamp jailed_until = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// QuerySigningInfoResponse is the response type for the Query/SigningInfo RPC
// method
message QuerySigningInfoResponse {
// fp_signing_info is the signing info of requested finality provider BTC public key
FinalityProviderSigningInfo fp_signing_info = 1 [(gogoproto.nullable) = false];
SigningInfoResponse signing_info = 1 [(gogoproto.nullable) = false];
}

// QuerySigningInfosRequest is the request type for the Query/SigningInfos RPC
Expand All @@ -246,6 +261,6 @@ message QuerySigningInfosRequest {
// method
message QuerySigningInfosResponse {
// info is the signing info of all finality providers with signing info
repeated FinalityProviderSigningInfo fp_signing_infos = 1 [(gogoproto.nullable) = false];
repeated SigningInfoResponse signing_infos = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
21 changes: 19 additions & 2 deletions x/finality/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (k Keeper) SigningInfo(ctx context.Context, req *types.QuerySigningInfoRequ
return nil, status.Errorf(codes.NotFound, "SigningInfo not found for the finality provider %s", req.FpBtcPkHex)
}

return &types.QuerySigningInfoResponse{FpSigningInfo: signingInfo}, nil
return &types.QuerySigningInfoResponse{SigningInfo: convertToSigningInfoResponse(signingInfo)}, nil
}

// SigningInfos returns signing-infos of all finality providers.
Expand All @@ -271,5 +271,22 @@ func (k Keeper) SigningInfos(ctx context.Context, req *types.QuerySigningInfosRe
if err != nil {
return nil, err
}
return &types.QuerySigningInfosResponse{FpSigningInfos: signInfos, Pagination: pageRes}, nil
return &types.QuerySigningInfosResponse{SigningInfos: convertToSigningInfosResponse(signInfos), Pagination: pageRes}, nil
}

func convertToSigningInfoResponse(info types.FinalityProviderSigningInfo) types.SigningInfoResponse {
return types.SigningInfoResponse{
FpBtcPkHex: info.FpBtcPk.MarshalHex(),
StartHeight: info.StartHeight,
MissedBlocksCounter: info.MissedBlocksCounter,
JailedUntil: info.JailedUntil,
}
}

func convertToSigningInfosResponse(signInfos []types.FinalityProviderSigningInfo) []types.SigningInfoResponse {
response := make([]types.SigningInfoResponse, len(signInfos))
for i, info := range signInfos {
response[i] = convertToSigningInfoResponse(info)
}
return response
}
15 changes: 7 additions & 8 deletions x/finality/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ func FuzzSigningInfo(f *testing.F) {
req := &types.QuerySigningInfoRequest{FpBtcPkHex: fpPk}
resp, err := fKeeper.SigningInfo(ctx, req)
require.NoError(t, err)
require.Equal(t, fpSigningInfos[fpPk].StartHeight, resp.FpSigningInfo.StartHeight)
require.Equal(t, fpSigningInfos[fpPk].MissedBlocksCounter, resp.FpSigningInfo.MissedBlocksCounter)
require.Equal(t, fpPk, resp.FpSigningInfo.FpBtcPk.MarshalHex())
require.Equal(t, fpSigningInfos[fpPk].StartHeight, resp.SigningInfo.StartHeight)
require.Equal(t, fpSigningInfos[fpPk].MissedBlocksCounter, resp.SigningInfo.MissedBlocksCounter)
require.Equal(t, fpPk, resp.SigningInfo.FpBtcPkHex)
}

// perform a query for signing info of non-exist finality provider
Expand All @@ -428,12 +428,11 @@ func FuzzSigningInfo(f *testing.F) {
}
resp, err := fKeeper.SigningInfos(ctx, req)
require.NoError(t, err)
require.LessOrEqual(t, len(resp.FpSigningInfos), int(limit)) // check if pagination takes effect
require.LessOrEqual(t, len(resp.SigningInfos), int(limit)) // check if pagination takes effect
require.EqualValues(t, resp.Pagination.Total, numSigningInfo) // ensure evidences before startHeight are not included
for _, si := range resp.FpSigningInfos {
require.Equal(t, fpSigningInfos[si.FpBtcPk.MarshalHex()].MissedBlocksCounter, si.MissedBlocksCounter)
require.Equal(t, fpSigningInfos[si.FpBtcPk.MarshalHex()].FpBtcPk.MarshalHex(), si.FpBtcPk.MarshalHex())
require.Equal(t, fpSigningInfos[si.FpBtcPk.MarshalHex()].StartHeight, si.StartHeight)
for _, si := range resp.SigningInfos {
require.Equal(t, fpSigningInfos[si.FpBtcPkHex].MissedBlocksCounter, si.MissedBlocksCounter)
require.Equal(t, fpSigningInfos[si.FpBtcPkHex].StartHeight, si.StartHeight)
}
})
}
Loading
Loading