Skip to content

Commit

Permalink
chore: use separate type for QueryFinalizedBundle (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler authored Jun 7, 2024
1 parent 9e581bb commit 59bb116
Show file tree
Hide file tree
Showing 6 changed files with 769 additions and 107 deletions.
6 changes: 3 additions & 3 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3050,9 +3050,9 @@ paths:
title: >-
StakeSecurity represents the relative security of a finalized
bundle
title: >-
FinalizedBundle represents the latest version of a valid bundle of
a pool
description: >-
QueryFinalizedBundleResponse is the response type for the
Query/Staker RPC method.
default:
description: An unexpected error response.
schema:
Expand Down
33 changes: 30 additions & 3 deletions proto/kyve/query/v1beta1/bundles.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ service QueryBundles {
}

// FinalizedBundle ...
rpc FinalizedBundleQuery(QueryFinalizedBundleRequest) returns (FinalizedBundle) {
rpc FinalizedBundleQuery(QueryFinalizedBundleRequest) returns (QueryFinalizedBundleResponse) {
option (google.api.http).get = "/kyve/v1/bundles/{pool_id}/{id}";
}

Expand Down Expand Up @@ -128,8 +128,35 @@ message QueryFinalizedBundleRequest {

// QueryFinalizedBundleResponse is the response type for the Query/Staker RPC method.
message QueryFinalizedBundleResponse {
// finalized_bundles ...
FinalizedBundle finalized_bundles = 1 [(gogoproto.nullable) = false];
// pool_id in which the bundle was created
uint64 pool_id = 1;
// id is is integrated with each valid bundle produced.
uint64 id = 2;
// storage_id is the id with which the data can be retrieved from the configured data provider
string storage_id = 3;
// uploader is the address of the staker who submitted this bundle
string uploader = 4;
// from_index is the index from where the bundle starts (inclusive)
uint64 from_index = 5;
// to_index is the index to which the bundle goes (exclusive)
uint64 to_index = 6;
// from_key is the key of the first data item in the bundle proposal
string from_key = 11;
// to_key the key of the last data item in the bundle
string to_key = 7;
// bundle_summary is a summary of the bundle.
string bundle_summary = 8;
// data_hash is a sha256 hash of the uploaded data.
string data_hash = 9;
// finalized_at contains details of the block that finalized this bundle.
FinalizedAt finalized_at = 10;
// storage_provider_id the id of the storage provider where the bundle is stored
uint64 storage_provider_id = 12;
// compression_id the id of the compression type with which the data was compressed
uint64 compression_id = 13;
// stake_security defines the amount of stake which was present in the pool during the finalization of the bundle.
// This field was added in schema version 2. Bundles finalized before that return `null`.
StakeSecurity stake_security = 14;
}

// ===============================
Expand Down
2 changes: 1 addition & 1 deletion testutil/integration/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (suite *KeeperTestSuite) VerifyStakersGenesisImportExport() {
// bundles module checks
// =====================

func checkFinalizedBundle(queryBundle querytypes.FinalizedBundle, rawBundle bundlesTypes.FinalizedBundle) {
func checkFinalizedBundle(queryBundle querytypes.QueryFinalizedBundleResponse, rawBundle bundlesTypes.FinalizedBundle) {
Expect(queryBundle.Id).To(Equal(rawBundle.Id))
Expect(queryBundle.PoolId).To(Equal(rawBundle.PoolId))
Expect(queryBundle.StorageId).To(Equal(rawBundle.StorageId))
Expand Down
37 changes: 37 additions & 0 deletions x/bundles/keeper/getters_bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,43 @@ func RawBundleToQueryBundle(rawFinalizedBundle types.FinalizedBundle, versionMap
return finalizedBundle
}

func RawBundleToQueryBundleResponse(rawFinalizedBundle types.FinalizedBundle, versionMap map[int32]uint64) (queryBundle queryTypes.QueryFinalizedBundleResponse) {
finalizedHeight := cosmossdk_io_math.NewInt(int64(rawFinalizedBundle.FinalizedAt.Height))

finalizedBundle := queryTypes.QueryFinalizedBundleResponse{
PoolId: rawFinalizedBundle.PoolId,
Id: rawFinalizedBundle.Id,
StorageId: rawFinalizedBundle.StorageId,
Uploader: rawFinalizedBundle.Uploader,
FromIndex: rawFinalizedBundle.FromIndex,
ToIndex: rawFinalizedBundle.ToIndex,
ToKey: rawFinalizedBundle.ToKey,
BundleSummary: rawFinalizedBundle.BundleSummary,
DataHash: rawFinalizedBundle.DataHash,
FinalizedAt: &queryTypes.FinalizedAt{
Height: &finalizedHeight,
Timestamp: time.Unix(int64(rawFinalizedBundle.FinalizedAt.Timestamp), 0).Format(time.RFC3339),
},
FromKey: rawFinalizedBundle.FromKey,
StorageProviderId: uint64(rawFinalizedBundle.StorageProviderId),
CompressionId: uint64(rawFinalizedBundle.CompressionId),
StakeSecurity: &queryTypes.StakeSecurity{
ValidVotePower: nil,
TotalVotePower: nil,
},
}

// Check for version 2
if rawFinalizedBundle.FinalizedAt.Height >= versionMap[2] {
validPower := cosmossdk_io_math.NewInt(int64(rawFinalizedBundle.StakeSecurity.ValidVotePower))
totalPower := cosmossdk_io_math.NewInt(int64(rawFinalizedBundle.StakeSecurity.TotalVotePower))
finalizedBundle.StakeSecurity.ValidVotePower = &validPower
finalizedBundle.StakeSecurity.TotalVotePower = &totalPower
}

return finalizedBundle
}

// GetPaginatedFinalizedBundleQuery parses a paginated request and builds a valid response out of the
// raw finalized bundles. It uses the fact that the ID of a bundle increases incrementally (starting with 0)
// and allows therefore for efficient queries using `offset`.
Expand Down
4 changes: 2 additions & 2 deletions x/query/keeper/grpc_query_finalized_bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (k Keeper) FinalizedBundlesQuery(c context.Context, req *types.QueryFinaliz
}
}

func (k Keeper) FinalizedBundleQuery(c context.Context, req *types.QueryFinalizedBundleRequest) (*types.FinalizedBundle, error) {
func (k Keeper) FinalizedBundleQuery(c context.Context, req *types.QueryFinalizedBundleRequest) (*types.QueryFinalizedBundleResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
Expand All @@ -48,6 +48,6 @@ func (k Keeper) FinalizedBundleQuery(c context.Context, req *types.QueryFinalize
}

versionMap := k.bundleKeeper.GetBundleVersionMap(ctx).GetMap()
response := bundlesKeeper.RawBundleToQueryBundle(finalizedBundle, versionMap)
response := bundlesKeeper.RawBundleToQueryBundleResponse(finalizedBundle, versionMap)
return &response, nil
}
Loading

0 comments on commit 59bb116

Please sign in to comment.