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

api: Return full consumer info and remove DB object usage in x/btcstkconsumer queries #470

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

### Improvements

- [#470](https://github.com/babylonlabs-io/babylon/pull/470) Return full consumer info and remove DB object
usage in `x/btcstkconsumer` queries
- [#483](https://github.com/babylonlabs-io/babylon/pull/483) Upgrade wasmd and wasmvm to latest
versions (related to security advisories CWA-2025-001 and CWA-2025-002)
- [#464](https://github.com/babylonlabs-io/babylon/pull/464) Update security email. Fix site / repository refs
Expand Down
208 changes: 125 additions & 83 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9829,10 +9829,47 @@ paths:
schema:
type: object
properties:
consumer_ids:
consumer_registers:
type: array
items:
type: string
type: object
properties:
consumer_id:
type: string
title: >-
consumer_id is the ID of the consumer

- for Cosmos SDK chains, the consumer ID will be the IBC
client ID

- for ETH L2 chains, the consumer ID will be the chain
ID of the ETH L2
chain
consumer_name:
type: string
title: consumer_name is the name of the consumer
consumer_description:
type: string
title: >-
consumer_description is a description for the consumer
(can be empty)
cosmos_channel_id:
type: string
title: |-
cosmos_channel_id is the IBC channel ID for the consumer
set only for Cosmos integration
eth_l2_finality_contract_address:
type: string
title: >-
eth_l2_finality_contract_address is the address of the
finality contract

set only for ETH L2 integration
title: >-
ConsumerRegisterResponse contains the information for a
registered consumer

The struct is used in the query responses
title: >-
consumer_ids are IDs of the consumers in ascending
alphabetical order
Expand Down Expand Up @@ -10133,7 +10170,7 @@ paths:
schema:
type: object
properties:
consumers_register:
consumer_registers:
type: array
items:
type: object
Expand All @@ -10157,33 +10194,23 @@ paths:
title: >-
consumer_description is a description for the consumer
(can be empty)
cosmos_consumer_metadata:
type: object
properties:
channel_id:
type: string
title: >-
channel_id defines the IBC channel ID for the
consumer chain
cosmos_channel_id:
type: string
title: |-
cosmos_channel_id is the IBC channel ID for the consumer
set only for Cosmos integration
eth_l2_finality_contract_address:
type: string
title: >-
CosmosConsumerMetadata is the metadata for the Cosmos
integration
eth_l2_consumer_metadata:
type: object
properties:
finality_contract_address:
type: string
title: >-
finality_contract_address is the address of the
finality contract for
eth_l2_finality_contract_address is the address of the
finality contract

the ETH L2 integration
title: >-
ETHL2ConsumerMetadata is the metadata for the ETH L2
integration
set only for ETH L2 integration
title: >-
ConsumerRegister is the registration information of a
consumer
ConsumerRegisterResponse contains the information for a
registered consumer

The struct is used in the query responses
description: >-
QueryConsumersRegistryResponse is response type for the
Query/ConsumersRegistry RPC method.
Expand Down Expand Up @@ -21464,7 +21491,7 @@ definitions:
transition and the time (in both timestamp and block height) of this
transition.
description: RawCheckpointWithMetaResponse wraps the raw checkpoint with metadata.
babylon.btcstkconsumer.v1.ConsumerRegister:
babylon.btcstkconsumer.v1.ConsumerRegisterResponse:
type: object
properties:
consumer_id:
Expand All @@ -21483,41 +21510,23 @@ definitions:
consumer_description:
type: string
title: consumer_description is a description for the consumer (can be empty)
cosmos_consumer_metadata:
type: object
properties:
channel_id:
type: string
title: channel_id defines the IBC channel ID for the consumer chain
title: CosmosConsumerMetadata is the metadata for the Cosmos integration
eth_l2_consumer_metadata:
type: object
properties:
finality_contract_address:
type: string
title: >-
finality_contract_address is the address of the finality contract
for

the ETH L2 integration
title: ETHL2ConsumerMetadata is the metadata for the ETH L2 integration
title: ConsumerRegister is the registration information of a consumer
babylon.btcstkconsumer.v1.CosmosConsumerMetadata:
type: object
properties:
channel_id:
type: string
title: channel_id defines the IBC channel ID for the consumer chain
title: CosmosConsumerMetadata is the metadata for the Cosmos integration
babylon.btcstkconsumer.v1.ETHL2ConsumerMetadata:
type: object
properties:
finality_contract_address:
cosmos_channel_id:
type: string
title: |-
finality_contract_address is the address of the finality contract for
the ETH L2 integration
title: ETHL2ConsumerMetadata is the metadata for the ETH L2 integration
cosmos_channel_id is the IBC channel ID for the consumer
set only for Cosmos integration
eth_l2_finality_contract_address:
type: string
title: >-
eth_l2_finality_contract_address is the address of the finality
contract

set only for ETH L2 integration
title: >-
ConsumerRegisterResponse contains the information for a registered
consumer

The struct is used in the query responses
babylon.btcstkconsumer.v1.FinalityProviderResponse:
type: object
properties:
Expand Down Expand Up @@ -21626,10 +21635,47 @@ definitions:
babylon.btcstkconsumer.v1.QueryConsumerRegistryListResponse:
type: object
properties:
consumer_ids:
consumer_registers:
type: array
items:
type: string
type: object
properties:
consumer_id:
type: string
title: >-
consumer_id is the ID of the consumer

- for Cosmos SDK chains, the consumer ID will be the IBC client
ID

- for ETH L2 chains, the consumer ID will be the chain ID of the
ETH L2
chain
consumer_name:
type: string
title: consumer_name is the name of the consumer
consumer_description:
type: string
title: >-
consumer_description is a description for the consumer (can be
empty)
cosmos_channel_id:
type: string
title: |-
cosmos_channel_id is the IBC channel ID for the consumer
set only for Cosmos integration
eth_l2_finality_contract_address:
type: string
title: >-
eth_l2_finality_contract_address is the address of the finality
contract

set only for ETH L2 integration
title: >-
ConsumerRegisterResponse contains the information for a registered
consumer

The struct is used in the query responses
title: consumer_ids are IDs of the consumers in ascending alphabetical order
pagination:
title: pagination defines the pagination in the response
Expand Down Expand Up @@ -21664,7 +21710,7 @@ definitions:
babylon.btcstkconsumer.v1.QueryConsumersRegistryResponse:
type: object
properties:
consumers_register:
consumer_registers:
type: array
items:
type: object
Expand All @@ -21688,27 +21734,23 @@ definitions:
title: >-
consumer_description is a description for the consumer (can be
empty)
cosmos_consumer_metadata:
type: object
properties:
channel_id:
type: string
title: channel_id defines the IBC channel ID for the consumer chain
cosmos_channel_id:
type: string
title: |-
cosmos_channel_id is the IBC channel ID for the consumer
set only for Cosmos integration
eth_l2_finality_contract_address:
type: string
title: >-
CosmosConsumerMetadata is the metadata for the Cosmos
integration
eth_l2_consumer_metadata:
type: object
properties:
finality_contract_address:
type: string
title: >-
finality_contract_address is the address of the finality
contract for
eth_l2_finality_contract_address is the address of the finality
contract

set only for ETH L2 integration
title: >-
ConsumerRegisterResponse contains the information for a registered
consumer

the ETH L2 integration
title: ETHL2ConsumerMetadata is the metadata for the ETH L2 integration
title: ConsumerRegister is the registration information of a consumer
The struct is used in the query responses
description: >-
QueryConsumersRegistryResponse is response type for the
Query/ConsumersRegistry RPC method.
Expand Down
27 changes: 23 additions & 4 deletions proto/babylon/btcstkconsumer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import "cosmos/staking/v1beta1/staking.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "babylon/btcstaking/v1/btcstaking.proto";
import "babylon/btcstaking/v1/pop.proto";
import "babylon/btcstkconsumer/v1/btcstkconsumer.proto";
import "babylon/btcstkconsumer/v1/params.proto";

option go_package = "github.com/babylonlabs-io/babylon/x/btcstkconsumer/types";
Expand Down Expand Up @@ -65,8 +64,8 @@ message QueryConsumerRegistryListRequest {

// QueryConsumerRegistryListResponse is response type for the Query/ConsumerRegistryList RPC method
message QueryConsumerRegistryListResponse {
// consumer_ids are IDs of the consumers in ascending alphabetical order
repeated string consumer_ids = 1;
// consumer_registers are the registered consumers in ascending alphabetical order
repeated ConsumerRegisterResponse consumer_registers = 1;
// pagination defines the pagination in the response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
Expand All @@ -76,7 +75,7 @@ message QueryConsumersRegistryRequest { repeated string consumer_ids = 1; }

// QueryConsumersRegistryResponse is response type for the Query/ConsumersRegistry RPC method.
message QueryConsumersRegistryResponse {
repeated babylon.btcstkconsumer.v1.ConsumerRegister consumers_register = 1;
repeated ConsumerRegisterResponse consumer_registers = 1;
}

// QueryFinalityProvidersRequest is the request type for the
Expand Down Expand Up @@ -153,3 +152,23 @@ message QueryFinalityProviderConsumerRequest {
message QueryFinalityProviderConsumerResponse {
string consumer_id = 1;
}

// ConsumerRegisterResponse contains the information for a registered consumer
// The struct is used in the query responses
message ConsumerRegisterResponse {
SebastianElvis marked this conversation as resolved.
Show resolved Hide resolved
// consumer_id is the ID of the consumer
// - for Cosmos SDK chains, the consumer ID will be the IBC client ID
// - for ETH L2 chains, the consumer ID will be the chain ID of the ETH L2
// chain
string consumer_id = 1;
// consumer_name is the name of the consumer
string consumer_name = 2;
// consumer_description is a description for the consumer (can be empty)
string consumer_description = 3;
// cosmos_channel_id is the IBC channel ID for the consumer
// set only for Cosmos integration
string cosmos_channel_id = 4;
// eth_l2_finality_contract_address is the address of the finality contract
// set only for ETH L2 integration
string eth_l2_finality_contract_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}
18 changes: 11 additions & 7 deletions x/btcstkconsumer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ func (k Keeper) ConsumerRegistryList(c context.Context, req *types.QueryConsumer

ctx := sdk.UnwrapSDKContext(c)

consumerIDs := []string{}
consumerRegisters := []*types.ConsumerRegisterResponse{}
store := k.consumerRegistryStore(ctx)
pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
consumerID := string(key)
consumerIDs = append(consumerIDs, consumerID)
consumerRegister, err := k.GetConsumerRegister(ctx, consumerID)
if err != nil {
return err
}
consumerRegisters = append(consumerRegisters, consumerRegister.ToResponse())
return nil
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

resp := &types.QueryConsumerRegistryListResponse{
ConsumerIds: consumerIDs,
Pagination: pageRes,
ConsumerRegisters: consumerRegisters,
Pagination: pageRes,
}
return resp, nil
}
Expand All @@ -66,17 +70,17 @@ func (k Keeper) ConsumersRegistry(c context.Context, req *types.QueryConsumersRe
}

ctx := sdk.UnwrapSDKContext(c)
var consumersRegister []*types.ConsumerRegister
consumersRegisters := []*types.ConsumerRegisterResponse{}
for _, consumerID := range req.ConsumerIds {
consumerRegister, err := k.GetConsumerRegister(ctx, consumerID)
if err != nil {
return nil, err
}

consumersRegister = append(consumersRegister, consumerRegister)
consumersRegisters = append(consumersRegisters, consumerRegister.ToResponse())
}

resp := &types.QueryConsumersRegistryResponse{ConsumersRegister: consumersRegister}
resp := &types.QueryConsumersRegistryResponse{ConsumerRegisters: consumersRegisters}
return resp, nil
}

Expand Down
Loading
Loading