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

use protobufs to define ccv state #332

Merged
merged 9 commits into from
Sep 20, 2022
Merged
5 changes: 5 additions & 0 deletions proto/interchain_security/ccv/consumer/v1/consumer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ message SlashRequest {
interchain_security.ccv.v1.SlashPacketData packet = 1;
cosmos.staking.v1beta1.InfractionType infraction = 2;
}

// SlashRequests is a list of slash requests for CCV consumer module
message SlashRequests {
repeated SlashRequest requests = 1;
}
6 changes: 6 additions & 0 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ message HandshakeMetadata {
string provider_fee_pool_addr = 1;
string version = 2;
}

// SlashAcks contains addesses of consumer chain validators
// successfully slashed on the provider chain
message SlashAcks {
repeated string addresses = 1;
}
10 changes: 10 additions & 0 deletions proto/interchain_security/ccv/v1/ccv.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ message SlashPacketData {
// tell if the slashing is for a downtime or a double-signing infraction
cosmos.staking.v1beta1.InfractionType infraction = 3;
}

// UnbondingOpsIndex defines a list of unbonding operation ids.
message UnbondingOpsIndex {
repeated uint64 ids = 1;
}

// MaturedUnbondingOps defines a list of ids corresponding to ids of matured unbonding operations.
message MaturedUnbondingOps {
repeated uint64 ids = 1;
}
26 changes: 14 additions & 12 deletions x/ccv/consumer/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package keeper

import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -389,36 +387,40 @@ func (k Keeper) GetAllCCValidator(ctx sdk.Context) (validators []types.CrossChai
}

// SetPendingSlashRequests sets the pending slash requests in store
func (k Keeper) SetPendingSlashRequests(ctx sdk.Context, requests []types.SlashRequest) {
func (k Keeper) SetPendingSlashRequests(ctx sdk.Context, requests []*types.SlashRequest) {
store := ctx.KVStore(k.storeKey)
buf := &bytes.Buffer{}
err := json.NewEncoder(buf).Encode(&requests)

sr := types.SlashRequests{
Requests: requests,
}
bz, err := sr.Marshal()
if err != nil {
panic(fmt.Errorf("failed to encode slash request json: %w", err))
}
store.Set([]byte{types.PendingSlashRequestsBytePrefix}, buf.Bytes())
store.Set([]byte{types.PendingSlashRequestsBytePrefix}, bz)
}

// GetPendingSlashRequest returns the pending slash requests in store
func (k Keeper) GetPendingSlashRequests(ctx sdk.Context) (requests []types.SlashRequest) {
func (k Keeper) GetPendingSlashRequests(ctx sdk.Context) []*types.SlashRequest {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte{types.PendingSlashRequestsBytePrefix})
if bz == nil {
return
return []*types.SlashRequest{}
}
buf := bytes.NewBuffer(bz)
err := json.NewDecoder(buf).Decode(&requests)

var sr types.SlashRequests
err := sr.Unmarshal(bz)
if err != nil {
panic(fmt.Errorf("failed to decode slash request json: %w", err))
}

return
return sr.GetRequests()
}

// AppendPendingSlashRequests appends the given slash request to the pending slash requests in store
func (k Keeper) AppendPendingSlashRequests(ctx sdk.Context, req types.SlashRequest) {
requests := k.GetPendingSlashRequests(ctx)
requests = append(requests, req)
requests = append(requests, &req)
k.SetPendingSlashRequests(ctx, requests)
}

Expand Down
4 changes: 2 additions & 2 deletions x/ccv/consumer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ func TestPendingSlashRequests(t *testing.T) {
defer ctrl.Finish()

// prepare test setup by storing 10 pending slash requests
request := []types.SlashRequest{}
request := []*types.SlashRequest{}
for i := 0; i < 10; i++ {
request = append(request, types.SlashRequest{})
request = append(request, &types.SlashRequest{})
consumerKeeper.SetPendingSlashRequests(ctx, request)
}

Expand Down
Loading