Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Jan 25, 2024
1 parent 087a9fe commit 29a96e0
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 22 deletions.
28 changes: 18 additions & 10 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import "cosmos/evidence/v1beta1/evidence.proto";
import "cosmos/base/v1beta1/coin.proto";

//
// Note any type defined in this file is ONLY used internally to the provider CCV module.
// These schemas can change with proper consideration of compatibility or migration.
//
// Note any type defined in this file is ONLY used internally to the provider
// CCV module. These schemas can change with proper consideration of
// compatibility or migration.
//

// ConsumerAdditionProposal is a governance proposal on the provider chain to
// spawn a new consumer chain. If it passes, then all validators on the provider
Expand Down Expand Up @@ -83,6 +84,11 @@ message ConsumerAdditionProposal {
// chain. it is most relevant for chains performing a sovereign to consumer
// changeover in order to maintan the existing ibc transfer channel
string distribution_transmission_channel = 14;

// TODO: add comments
bool is_top_N = 15;

uint32 top_N = 16;
}

// ConsumerRemovalProposal is a governance proposal on the provider chain to
Expand All @@ -104,15 +110,16 @@ message ConsumerRemovalProposal {

// EquivocationProposal is a governance proposal on the provider chain to
// punish a validator for equivocation on a consumer chain.
//
// This type is only used internally to the consumer CCV module.
//
// This type is only used internally to the consumer CCV module.
// WARNING: This message is deprecated now that equivocations can be submitted
// and verified automatically on the provider. (see SubmitConsumerDoubleVoting in proto/interchain-security/ccv/provider/v1/tx.proto).
// and verified automatically on the provider. (see SubmitConsumerDoubleVoting
// in proto/interchain-security/ccv/provider/v1/tx.proto).
message EquivocationProposal {
option deprecated = true;
// the title of the proposal
string title = 1;
// the description of the proposal
// the description of the proposal
string description = 2;
// the list of equivocations that will be processed
repeated cosmos.evidence.v1beta1.Equivocation equivocations = 3;
Expand Down Expand Up @@ -191,7 +198,7 @@ message Params {
}

// SlashAcks contains cons addresses of consumer chain validators
// successfully slashed on the provider chain.
// successfully slashed on the provider chain.
message SlashAcks { repeated string addresses = 1; }

// ConsumerAdditionProposals holds pending governance proposals on the provider
Expand Down Expand Up @@ -253,11 +260,12 @@ message ValidatorSetChangePackets {
// unbonding operations.
message MaturedUnbondingOps { repeated uint64 ids = 1; }

// ExportedVscSendTimestamps is VscSendTimestamp with chainID info for exporting to genesis
// ExportedVscSendTimestamps is VscSendTimestamp with chainID info for exporting
// to genesis
message ExportedVscSendTimestamp {
string chain_id = 1;
repeated VscSendTimestamp vsc_send_timestamps = 2
[ (gogoproto.nullable) = false ];
[ (gogoproto.nullable) = false ];
}

//
Expand Down
48 changes: 36 additions & 12 deletions proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import "google/protobuf/any.proto";
import "ibc/lightclients/tendermint/v1/tendermint.proto";
import "tendermint/types/evidence.proto";


// Msg defines the Msg service.
service Msg {
rpc AssignConsumerKey(MsgAssignConsumerKey) returns (MsgAssignConsumerKeyResponse);
rpc SubmitConsumerMisbehaviour(MsgSubmitConsumerMisbehaviour) returns (MsgSubmitConsumerMisbehaviourResponse);
rpc SubmitConsumerDoubleVoting(MsgSubmitConsumerDoubleVoting) returns (MsgSubmitConsumerDoubleVotingResponse);
rpc AssignConsumerKey(MsgAssignConsumerKey)
returns (MsgAssignConsumerKeyResponse);
rpc SubmitConsumerMisbehaviour(MsgSubmitConsumerMisbehaviour)
returns (MsgSubmitConsumerMisbehaviourResponse);
rpc SubmitConsumerDoubleVoting(MsgSubmitConsumerDoubleVoting)
returns (MsgSubmitConsumerDoubleVotingResponse);
rpc OptIn(MsgOptIn) returns (MsgOptInResponse);
rpc OptOut(MsgOptOut) returns (MsgOptOutResponse);
}

message MsgAssignConsumerKey {
Expand All @@ -32,32 +36,52 @@ message MsgAssignConsumerKey {

message MsgAssignConsumerKeyResponse {}


// MsgSubmitConsumerMisbehaviour defines a message that reports a light client attack,
// also known as a misbehaviour, observed on a consumer chain
// MsgSubmitConsumerMisbehaviour defines a message that reports a light client
// attack, also known as a misbehaviour, observed on a consumer chain
message MsgSubmitConsumerMisbehaviour {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
string submitter = 1;
// The Misbehaviour of the consumer chain wrapping
// two conflicting IBC headers
// The Misbehaviour of the consumer chain wrapping
// two conflicting IBC headers
ibc.lightclients.tendermint.v1.Misbehaviour misbehaviour = 2;
}

message MsgSubmitConsumerMisbehaviourResponse {}


// MsgSubmitConsumerDoubleVoting defines a message that reports
// MsgSubmitConsumerDoubleVoting defines a message that reports
// a double signing infraction observed on a consumer chain
message MsgSubmitConsumerDoubleVoting {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
string submitter = 1;
// The equivocation of the consumer chain wrapping
// The equivocation of the consumer chain wrapping
// an evidence of a validator that signed two conflicting votes
tendermint.types.DuplicateVoteEvidence duplicate_vote_evidence = 2;
// The light client header of the infraction block
ibc.lightclients.tendermint.v1.Header infraction_block_header = 3;
}

message MsgSubmitConsumerDoubleVotingResponse {}

message MsgOptIn {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
// the chain id of the consumer chain to opt in to
string chain_id = 1;
// the validator address on the provider
string provider_addr = 2 [ (gogoproto.moretags) = "yaml:\"address\"" ];
}

message MsgOptInResponse {}

message MsgOptOut {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
// the chain id of the consumer chain to opt out from
string chain_id = 1;
// the validator address on the provider
string provider_addr = 2 [ (gogoproto.moretags) = "yaml:\"address\"" ];
}

message MsgOptOutResponse {}
6 changes: 6 additions & 0 deletions x/ccv/provider/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func NewHandler(k *keeper.Keeper) sdk.Handler {
case *types.MsgSubmitConsumerDoubleVoting:
res, err := msgServer.SubmitConsumerDoubleVoting(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgOptIn:
res, err := msgServer.OptIn(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgOptOut:
res, err := msgServer.OptOut(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
default:
return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
}
Expand Down
31 changes: 31 additions & 0 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,3 +1136,34 @@ func (k Keeper) GetAllRegisteredAndProposedChainIDs(ctx sdk.Context) []string {

return allConsumerChains
}

func (k Keeper) SetTopN(ctx sdk.Context, chainID string, isTopN bool, topN uint8) {
store := ctx.KVStore(k.storeKey)
var value byte
if isTopN {
value = 0
} else {
value = 0
}
store.Set(types.TopNKey(chainID), []byte{value, topN})
}

// or an erorr if not found
func (k Keeper) IsTopN(ctx sdk.Context, chainID string) (bool, bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.TopNKey(chainID))
if bz == nil || len(bz) < 1 {
return false, false
}
return bz[0] == 1, true
}

// func (k Keeper) GetTopN(ctx sdk.Context, chainID string) (uint8, error)
func (k Keeper) GetTopN(ctx sdk.Context, chainID string) (uint8, bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.TopNKey(chainID))
if bz == nil || len(bz) < 2 {
return 0, false
}
return bz[1], true
}
36 changes: 36 additions & 0 deletions x/ccv/provider/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,39 @@ func (k msgServer) SubmitConsumerDoubleVoting(goCtx context.Context, msg *types.

return &types.MsgSubmitConsumerDoubleVotingResponse{}, nil
}

func (k msgServer) OptIn(goCtx context.Context, msg *types.MsgOptIn) (*types.MsgOptInResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
if err := k.Keeper.HandleOptIn(ctx, *msg); err != nil {
return nil, err
}

// add some outpout
//ctx.EventManager().EmitEvents(sdk.Events{
// sdk.NewEvent(
// ccvtypes.EventTypeSubmitConsumerMisbehaviour,
// sdk.NewAttribute(ccvtypes.AttributeConsumerMisbehaviour, msg.Misbehaviour.String()),
//
// ),
//})

return &types.MsgOptInResponse{}, nil
}

func (k msgServer) OptOut(goCtx context.Context, msg *types.MsgOptOut) (*types.MsgOptOutResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
if err := k.Keeper.HandleOptOut(ctx, *msg); err != nil {
return nil, err
}

// add some outpout
//ctx.EventManager().EmitEvents(sdk.Events{
// sdk.NewEvent(
// ccvtypes.EventTypeSubmitConsumerMisbehaviour,
// sdk.NewAttribute(ccvtypes.AttributeConsumerMisbehaviour, msg.Misbehaviour.String()),
//
// ),
//})

return &types.MsgOptOutResponse{}, nil
}
22 changes: 22 additions & 0 deletions x/ccv/provider/keeper/partial_set_security.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
)

// HandleOptIn TODO
func (k Keeper) HandleOptIn(ctx sdk.Context, msg types.MsgOptIn) error {
logger := k.Logger(ctx)
logger.Info("something ..")

return nil
}

// HandleOptOut TODO
func (k Keeper) HandleOptOut(ctx sdk.Context, msg types.MsgOptOut) error {
logger := k.Logger(ctx)
logger.Info("something ..")

return nil
}
2 changes: 2 additions & 0 deletions x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ func (k Keeper) BeginBlockInit(ctx sdk.Context) {
// write cache
writeFn()

k.SetTopN(ctx, prop.ChainId, prop.IsTop_N, uint8(prop.Top_N))

k.Logger(ctx).Info("executed consumer addition proposal",
"chainID", prop.ChainId,
"title", prop.Title,
Expand Down
8 changes: 8 additions & 0 deletions x/ccv/provider/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ const (
// ProposedConsumerChainByteKey is the byte prefix storing the consumer chainId in consumerAddition gov proposal submitted before voting finishes
ProposedConsumerChainByteKey

// TopNChainBytePrefix is the byte prefix for storing the mapping from a chain ID to PSS info
TopNChainBytePrefix

// NOTE: DO NOT ADD NEW BYTE PREFIXES HERE WITHOUT ADDING THEM TO getAllKeyPrefixes() IN keys_test.go
)

Expand Down Expand Up @@ -517,6 +520,11 @@ func ParseProposedConsumerChainKey(prefix byte, bz []byte) (uint64, error) {
return proposalID, nil
}

// TopNKey ??? TODO
func TopNKey(chainID string) []byte {
return append([]byte{TopNChainBytePrefix}, []byte(chainID)...)
}

//
// End of generic helpers section
//
1 change: 1 addition & 0 deletions x/ccv/provider/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func getAllKeyPrefixes() []byte {
providertypes.VSCMaturedHandledThisBlockBytePrefix,
providertypes.EquivocationEvidenceMinHeightBytePrefix,
providertypes.ProposedConsumerChainByteKey,
providertypes.TopNChainBytePrefix,
}
}

Expand Down
Loading

0 comments on commit 29a96e0

Please sign in to comment.