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 object IndexedBlock in x/finality module #209

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ generalized unbonding handler
* [#202](https://github.com/babylonlabs-io/babylon/pull/202) Adjusted handling of `FinalityProviderWithMeta` in btcstaking keeper queries to improve API security.
* [#203](https://github.com/babylonlabs-io/babylon/pull/203) Adjusted handling of `RewardGauge` in incentive keeper queries to improve API security.
* [#208](https://github.com/babylonlabs-io/babylon/pull/208) Adjusted handling of `Evidence` in finality keeper queries to improve API security.
* [#209](https://github.com/babylonlabs-io/babylon/pull/209) Adjusted handling of `IndexedBlock` in finality keeper queries to improve API security.

### State Machine Breaking

Expand Down
15 changes: 13 additions & 2 deletions proto/babylon/finality/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,22 @@ message QueryBlockRequest {
uint64 height = 1;
}

// IndexedBlockResponse is the necessary metadata and finalization status of a block
message IndexedBlockResponse {
// height is the height of the block
uint64 height = 1;
// app_hash is the AppHash of the block
bytes app_hash = 2;
// finalized indicates whether the IndexedBlock is finalised by 2/3
// finality providers or not
bool finalized = 3;
}

// QueryBlockResponse is the response type for the
// Query/Block RPC method.
message QueryBlockResponse {
// block is the Babylon at the given height
IndexedBlock block = 1;
IndexedBlockResponse block = 1;
}

// QueryListBlocksRequest is the request type for the
Expand All @@ -167,7 +178,7 @@ message QueryListBlocksRequest {
// Query/ListBlocks RPC method.
message QueryListBlocksResponse {
// blocks is the list of blocks at the given status
repeated IndexedBlock blocks = 1;
repeated IndexedBlockResponse blocks = 1;

// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
Expand Down
20 changes: 18 additions & 2 deletions test/e2e/configurer/chain/queries_btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (n *NodeConfig) QueryListBlocks(status ftypes.QueriedBlockStatus) []*ftypes
err = util.Cdc.UnmarshalJSON(bz, &resp)
require.NoError(n.t, err)

return resp.Blocks
return convertToIndexedBlockList(resp.Blocks)
}

func (n *NodeConfig) QueryIndexedBlock(height uint64) *ftypes.IndexedBlock {
Expand All @@ -182,5 +182,21 @@ func (n *NodeConfig) QueryIndexedBlock(height uint64) *ftypes.IndexedBlock {
err = util.Cdc.UnmarshalJSON(bz, &resp)
require.NoError(n.t, err)

return resp.Block
return convertToIndexedBlock(resp.Block)
}

func convertToIndexedBlock(br *ftypes.IndexedBlockResponse) *ftypes.IndexedBlock {
return &ftypes.IndexedBlock{
Height: br.Height,
AppHash: br.AppHash,
Finalized: br.Finalized,
}
}

func convertToIndexedBlockList(brs []*ftypes.IndexedBlockResponse) []*ftypes.IndexedBlock {
var ibs []*ftypes.IndexedBlock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allocate the size in advance

for _, indexedBlock := range brs {
ibs = append(ibs, convertToIndexedBlock(indexedBlock))
}
return ibs
}
20 changes: 18 additions & 2 deletions x/finality/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (k Keeper) Block(ctx context.Context, req *types.QueryBlockRequest) (*types
return nil, err
}

return &types.QueryBlockResponse{Block: b}, nil
return &types.QueryBlockResponse{Block: convertToIndexedBlockResponse(b)}, nil
}

// ListBlocks returns a list of blocks at the given finalisation status
Expand Down Expand Up @@ -129,7 +129,7 @@ func (k Keeper) ListBlocks(ctx context.Context, req *types.QueryListBlocksReques
}

resp := &types.QueryListBlocksResponse{
Blocks: ibs,
Blocks: convertToIndexedBlockResponseList(ibs),
Pagination: pageRes,
}
return resp, nil
Expand Down Expand Up @@ -291,6 +291,22 @@ func convertToSigningInfosResponse(signInfos []types.FinalityProviderSigningInfo
return response
}

func convertToIndexedBlockResponse(ib *types.IndexedBlock) *types.IndexedBlockResponse {
return &types.IndexedBlockResponse{
Height: ib.Height,
AppHash: ib.AppHash,
Finalized: ib.Finalized,
}
}

func convertToIndexedBlockResponseList(ibs []*types.IndexedBlock) []*types.IndexedBlockResponse {
var blockResponses []*types.IndexedBlockResponse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

for _, ib := range ibs {
blockResponses = append(blockResponses, convertToIndexedBlockResponse(ib))
}
return blockResponses
}

func convertToEvidenceResponse(evidence *types.Evidence) *types.EvidenceResponse {
return &types.EvidenceResponse{
FpBtcPkHex: evidence.FpBtcPk.MarshalHex(),
Expand Down
Loading
Loading