Skip to content

Commit

Permalink
chore: finalize stake security
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreithecker committed Jul 3, 2023
1 parent a226267 commit 2985563
Show file tree
Hide file tree
Showing 7 changed files with 723 additions and 220 deletions.
93 changes: 57 additions & 36 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2476,20 +2476,16 @@ paths:
pool_id:
type: string
format: uint64
title: >-
pool_id is the id of the pool for which this proposal is
for
title: pool_id in which the bundle was created
id:
type: string
format: uint64
title: >-
id is a unique identifier for each finalized bundle in a
pool
description: id is is integrated with each valid bundle produced.
storage_id:
type: string
title: >-
storage_id is the id with which the data can be
retrieved from
retrieved from the configured data provider
uploader:
type: string
title: >-
Expand All @@ -2507,17 +2503,20 @@ paths:
title: >-
to_index is the index to which the bundle goes
(exclusive)
to_key:
from_key:
type: string
title: >-
to_key the key of the last data item in the bundle
from_key is the key of the first data item in the bundle
proposal
to_key:
type: string
title: to_key the key of the last data item in the bundle
bundle_summary:
type: string
title: bundle_summary a string summary of the current proposal
description: bundle_summary is a summary of the bundle.
data_hash:
type: string
title: data_hash a sha256 hash of the raw compressed data
description: data_hash is a sha256 hash of the uploaded data.
finalized_at:
description: >-
finalized_at contains details of the block that
Expand All @@ -2532,11 +2531,6 @@ paths:
type: string
format: uint64
description: timestamp ...
from_key:
type: string
title: >-
from_key the key of the first data item in the bundle
proposal
storage_provider_id:
type: string
format: uint64
Expand All @@ -2550,13 +2544,24 @@ paths:
compression_id the id of the compression type with which
the data was compressed
stake_security:
type: string
description: stake_security ...
title: >-
FinalizedBundle represents a bundle proposal where the
majority
description: >-
stake_security defines the amount of stake which was
present in the pool during the finalization of the
bundle.
agreed on its validity
This field was added in schema version 2. Bundles
finalized before that return `null`.
type: object
properties:
valid_vote_power:
type: string
description: valid_vote_power ...
total_vote_power:
type: string
description: total_vote_power ...
title: >-
FinalizedBundle represents the latest version of a valid
bundle of a pool
description: finalized_bundles ...
pagination:
description: pagination defines the pagination in the response.
Expand Down Expand Up @@ -2861,14 +2866,16 @@ paths:
pool_id:
type: string
format: uint64
title: pool_id is the id of the pool for which this proposal is for
title: pool_id in which the bundle was created
id:
type: string
format: uint64
title: id is a unique identifier for each finalized bundle in a pool
description: id is is integrated with each valid bundle produced.
storage_id:
type: string
title: storage_id is the id with which the data can be retrieved from
title: >-
storage_id is the id with which the data can be retrieved from
the configured data provider
uploader:
type: string
title: >-
Expand All @@ -2884,15 +2891,20 @@ paths:
type: string
format: uint64
title: to_index is the index to which the bundle goes (exclusive)
from_key:
type: string
title: >-
from_key is the key of the first data item in the bundle
proposal
to_key:
type: string
title: to_key the key of the last data item in the bundle proposal
title: to_key the key of the last data item in the bundle
bundle_summary:
type: string
title: bundle_summary a string summary of the current proposal
description: bundle_summary is a summary of the bundle.
data_hash:
type: string
title: data_hash a sha256 hash of the raw compressed data
description: data_hash is a sha256 hash of the uploaded data.
finalized_at:
description: >-
finalized_at contains details of the block that finalized this
Expand All @@ -2907,9 +2919,6 @@ paths:
type: string
format: uint64
description: timestamp ...
from_key:
type: string
title: from_key the key of the first data item in the bundle proposal
storage_provider_id:
type: string
format: uint64
Expand All @@ -2923,11 +2932,23 @@ paths:
compression_id the id of the compression type with which the
data was compressed
stake_security:
type: string
description: stake_security ...
title: |-
FinalizedBundle represents a bundle proposal where the majority
agreed on its validity
description: >-
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`.
type: object
properties:
valid_vote_power:
type: string
description: valid_vote_power ...
total_vote_power:
type: string
description: total_vote_power ...
title: >-
FinalizedBundle represents the latest version of a valid bundle of
a pool
default:
description: An unexpected error response.
schema:
Expand Down
10 changes: 9 additions & 1 deletion proto/kyve/bundles/v1beta1/bundles.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ message FinalizedBundle {
// compression_id the id of the compression type with which the data was compressed
uint32 compression_id = 13;
// stake_security
uint64 stake_security = 14;
StakeSecurity stake_security = 14;
}

// FinalizedAt ...
Expand All @@ -103,6 +103,14 @@ message FinalizedAt {
uint64 timestamp = 2;
}

// FinalizedAt ...
message StakeSecurity {
// valid_vote_power ...
uint64 valid_vote_power = 1;
// total_vote_power ...
uint64 total_vote_power = 2;
}

// BundleVersionEntry ...
message BundleVersionEntry {
// height ...
Expand Down
10 changes: 9 additions & 1 deletion proto/kyve/query/v1beta1/bundles.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ message FinalizedBundle {
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`.
string stake_security = 14 [(gogoproto.customtype) = "cosmossdk.io/math.Int"];
StakeSecurity stake_security = 14;
}

// FinalizedAt ...
Expand All @@ -82,6 +82,14 @@ message FinalizedAt {
uint64 timestamp = 2;
}

// StakeSecurity ...
message StakeSecurity {
// valid_vote_power ...
string valid_vote_power = 1 [(gogoproto.customtype) = "cosmossdk.io/math.Int"];
// total_vote_power ...
string total_vote_power = 2 [(gogoproto.customtype) = "cosmossdk.io/math.Int"];
}

// ===========================
// finalized_bundles/{pool_id}
// ===========================
Expand Down
11 changes: 8 additions & 3 deletions x/bundles/keeper/getters_bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ func RawBundleToQueryBundle(rawFinalizedBundle types.FinalizedBundle, versionMap
FromKey: rawFinalizedBundle.FromKey,
StorageProviderId: uint64(rawFinalizedBundle.StorageProviderId),
CompressionId: uint64(rawFinalizedBundle.CompressionId),
StakeSecurity: nil,
StakeSecurity: &queryTypes.StakeSecurity{
ValidVotePower: nil,
TotalVotePower: nil,
},
}
// Check for version 2
if rawFinalizedBundle.FinalizedAt.Height >= versionMap[2] {
stake := cosmossdk_io_math.NewInt(int64(rawFinalizedBundle.StakeSecurity))
finalizedBundle.StakeSecurity = &stake
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
Expand Down
5 changes: 4 additions & 1 deletion x/bundles/keeper/logic_bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ func (k Keeper) finalizeCurrentBundleProposal(ctx sdk.Context, poolId uint64, vo
DataHash: bundleProposal.DataHash,
StorageProviderId: bundleProposal.StorageProviderId,
CompressionId: bundleProposal.CompressionId,
StakeSecurity: uint64(0), // TODO what to store?
StakeSecurity: &types.StakeSecurity{
ValidVotePower: voteDistribution.Valid,
TotalVotePower: voteDistribution.Total,
},
}

k.SetFinalizedBundle(ctx, finalizedBundle)
Expand Down
Loading

0 comments on commit 2985563

Please sign in to comment.