diff --git a/go.mod b/go.mod index 8483e0a097..9d761c3937 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tidwall/gjson v1.17.0 golang.org/x/crypto v0.11.0 // indirect - golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb + golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.11.0 // indirect google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect diff --git a/x/ccv/consumer/ibc_module.go b/x/ccv/consumer/ibc_module.go index 93b8096092..99f0141e64 100644 --- a/x/ccv/consumer/ibc_module.go +++ b/x/ccv/consumer/ibc_module.go @@ -176,7 +176,7 @@ func (am AppModule) OnChanOpenAck( ctx.EventManager().EmitEvent( sdk.NewEvent( - types.EventTypeFeeTransferChannelOpened, + consumertypes.EventTypeFeeTransferChannelOpened, sdk.NewAttribute(sdk.AttributeKeyModule, consumertypes.ModuleName), sdk.NewAttribute(channeltypes.AttributeKeyChannelID, channelID), sdk.NewAttribute(channeltypes.AttributeKeyPortID, transfertypes.PortID), diff --git a/x/ccv/consumer/keeper/distribution.go b/x/ccv/consumer/keeper/distribution.go index a2c19b495d..92171244ad 100644 --- a/x/ccv/consumer/keeper/distribution.go +++ b/x/ccv/consumer/keeper/distribution.go @@ -161,13 +161,13 @@ func (k Keeper) SendRewardsToProvider(ctx sdk.Context) error { currentHeight := ctx.BlockHeight() ctx.EventManager().EmitEvent( sdk.NewEvent( - ccv.EventTypeFeeDistribution, + types.EventTypeFeeDistribution, sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(ccv.AttributeDistributionCurrentHeight, strconv.Itoa(int(currentHeight))), - sdk.NewAttribute(ccv.AttributeDistributionNextHeight, strconv.Itoa(int(currentHeight+k.GetBlocksPerDistributionTransmission(ctx)))), - sdk.NewAttribute(ccv.AttributeDistributionFraction, (k.GetConsumerRedistributionFrac(ctx))), - sdk.NewAttribute(ccv.AttributeDistributionTotal, allBalances.String()), - sdk.NewAttribute(ccv.AttributeDistributionToProvider, sentCoins.String()), + sdk.NewAttribute(types.AttributeDistributionCurrentHeight, strconv.Itoa(int(currentHeight))), + sdk.NewAttribute(types.AttributeDistributionNextHeight, strconv.Itoa(int(currentHeight+k.GetBlocksPerDistributionTransmission(ctx)))), + sdk.NewAttribute(types.AttributeDistributionFraction, (k.GetConsumerRedistributionFrac(ctx))), + sdk.NewAttribute(types.AttributeDistributionTotal, allBalances.String()), + sdk.NewAttribute(types.AttributeDistributionToProvider, sentCoins.String()), ), ) diff --git a/x/ccv/consumer/keeper/relay.go b/x/ccv/consumer/keeper/relay.go index 060aadff20..3afeb33188 100644 --- a/x/ccv/consumer/keeper/relay.go +++ b/x/ccv/consumer/keeper/relay.go @@ -115,12 +115,12 @@ func (k Keeper) QueueVSCMaturedPackets(ctx sdk.Context) { ctx.EventManager().EmitEvent( sdk.NewEvent( - ccv.EventTypeVSCMatured, + types.EventTypeVSCMatured, sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), sdk.NewAttribute(ccv.AttributeChainID, ctx.ChainID()), - sdk.NewAttribute(ccv.AttributeConsumerHeight, strconv.Itoa(int(ctx.BlockHeight()))), + sdk.NewAttribute(types.AttributeConsumerHeight, strconv.Itoa(int(ctx.BlockHeight()))), sdk.NewAttribute(ccv.AttributeValSetUpdateID, strconv.Itoa(int(maturityTime.VscId))), - sdk.NewAttribute(ccv.AttributeTimestamp, ctx.BlockTime().String()), + sdk.NewAttribute(types.AttributeTimestamp, ctx.BlockTime().String()), ), ) } @@ -162,7 +162,7 @@ func (k Keeper) QueueSlashPacket(ctx sdk.Context, validator abci.Validator, vals ctx.EventManager().EmitEvent( sdk.NewEvent( - ccv.EventTypeConsumerSlashRequest, + types.EventTypeConsumerSlashRequest, sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), sdk.NewAttribute(ccv.AttributeValidatorAddress, sdk.ConsAddress(validator.Address).String()), sdk.NewAttribute(ccv.AttributeValSetUpdateID, strconv.Itoa(int(valsetUpdateID))), diff --git a/x/ccv/consumer/types/events.go b/x/ccv/consumer/types/events.go new file mode 100644 index 0000000000..ccc2616416 --- /dev/null +++ b/x/ccv/consumer/types/events.go @@ -0,0 +1,18 @@ +package types + +const ( + AttributeConsumerHeight = "consumer_height" + AttributeTimestamp = "timestamp" + + EventTypeFeeDistribution = "fee_distribution" + EventTypeVSCMatured = "vsc_matured" + EventTypeConsumerSlashRequest = "consumer_slash_request" + EventTypeFeeTransferChannelOpened = "fee_transfer_channel_opened" + + AttributeDistributionCurrentHeight = "current_distribution_height" + //#nosec G101 -- (false positive) this is not a hardcoded credential + AttributeDistributionNextHeight = "next_distribution_height" + AttributeDistributionFraction = "distribution_fraction" + AttributeDistributionTotal = "total" + AttributeDistributionToProvider = "provider_amount" +) diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index e9bb1d1bd0..d4470ec0aa 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -299,7 +299,7 @@ func (k Keeper) VerifyConsumerChain(ctx sdk.Context, channelID string, connectio return errorsmod.Wrapf(ccv.ErrClientNotFound, "cannot find client for consumer chain %s", tmClient.ChainId) } if ccvClientId != clientID { - return errorsmod.Wrapf(ccv.ErrInvalidConsumerClient, "CCV channel must be built on top of CCV client. expected %s, got %s", ccvClientId, clientID) + return errorsmod.Wrapf(types.ErrInvalidConsumerClient, "CCV channel must be built on top of CCV client. expected %s, got %s", ccvClientId, clientID) } // Verify that there isn't already a CCV channel for the consumer chain diff --git a/x/ccv/provider/keeper/msg_server.go b/x/ccv/provider/keeper/msg_server.go index 2aa0fed46c..fecbdc8c36 100644 --- a/x/ccv/provider/keeper/msg_server.go +++ b/x/ccv/provider/keeper/msg_server.go @@ -12,7 +12,6 @@ import ( tmprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" - ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) type msgServer struct { @@ -100,9 +99,9 @@ func (k msgServer) AssignConsumerKey(goCtx context.Context, msg *types.MsgAssign ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( - ccvtypes.EventTypeAssignConsumerKey, - sdk.NewAttribute(ccvtypes.AttributeProviderValidatorAddress, msg.ProviderAddr), - sdk.NewAttribute(ccvtypes.AttributeConsumerConsensusPubKey, consumerTMPublicKey.String()), + types.EventTypeAssignConsumerKey, + sdk.NewAttribute(types.AttributeProviderValidatorAddress, msg.ProviderAddr), + sdk.NewAttribute(types.AttributeConsumerConsensusPubKey, consumerTMPublicKey.String()), ), }) diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index 8fae41fd62..20bf812395 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -56,7 +56,7 @@ func (k Keeper) CreateConsumerClient(ctx sdk.Context, prop *types.ConsumerAdditi chainID := prop.ChainId // check that a client for this chain does not exist if _, found := k.GetConsumerClientId(ctx, chainID); found { - return errorsmod.Wrap(ccv.ErrDuplicateConsumerChain, + return errorsmod.Wrap(types.ErrDuplicateConsumerChain, fmt.Sprintf("cannot create client for existent consumer chain: %s", chainID)) } @@ -108,14 +108,14 @@ func (k Keeper) CreateConsumerClient(ctx sdk.Context, prop *types.ConsumerAdditi ctx.EventManager().EmitEvent( sdk.NewEvent( - ccv.EventTypeConsumerClientCreated, + types.EventTypeConsumerClientCreated, sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), sdk.NewAttribute(ccv.AttributeChainID, chainID), sdk.NewAttribute(clienttypes.AttributeKeyClientID, clientID), - sdk.NewAttribute(ccv.AttributeInitialHeight, prop.InitialHeight.String()), - sdk.NewAttribute(ccv.AttributeInitializationTimeout, strconv.Itoa(int(ts.UnixNano()))), - sdk.NewAttribute(ccv.AttributeTrustingPeriod, clientState.TrustingPeriod.String()), - sdk.NewAttribute(ccv.AttributeUnbondingPeriod, clientState.UnbondingPeriod.String()), + sdk.NewAttribute(types.AttributeInitialHeight, prop.InitialHeight.String()), + sdk.NewAttribute(types.AttributeInitializationTimeout, strconv.Itoa(int(ts.UnixNano()))), + sdk.NewAttribute(types.AttributeTrustingPeriod, clientState.TrustingPeriod.String()), + sdk.NewAttribute(types.AttributeUnbondingPeriod, clientState.UnbondingPeriod.String()), ), ) @@ -155,7 +155,7 @@ func (k Keeper) HandleConsumerRemovalProposal(ctx sdk.Context, p *types.Consumer func (k Keeper) StopConsumerChain(ctx sdk.Context, chainID string, closeChan bool) (err error) { // check that a client for chainID exists if _, found := k.GetConsumerClientId(ctx, chainID); !found { - return errorsmod.Wrap(ccv.ErrConsumerChainNotFound, + return errorsmod.Wrap(types.ErrConsumerChainNotFound, fmt.Sprintf("cannot stop non-existent consumer chain: %s", chainID)) } @@ -612,8 +612,8 @@ func (k Keeper) HandleConsumerRewardDenomProposal(ctx sdk.Context, p *types.Chan } k.SetConsumerRewardDenom(ctx, denomToAdd) ctx.EventManager().EmitEvent(sdk.NewEvent( - ccv.EventTypeAddConsumerRewardDenom, - sdk.NewAttribute(ccv.AttributeConsumerRewardDenom, denomToAdd), + types.EventTypeAddConsumerRewardDenom, + sdk.NewAttribute(types.AttributeConsumerRewardDenom, denomToAdd), )) } for _, denomToRemove := range p.DenomsToRemove { @@ -624,8 +624,8 @@ func (k Keeper) HandleConsumerRewardDenomProposal(ctx sdk.Context, p *types.Chan } k.DeleteConsumerRewardDenom(ctx, denomToRemove) ctx.EventManager().EmitEvent(sdk.NewEvent( - ccv.EventTypeRemoveConsumerRewardDenom, - sdk.NewAttribute(ccv.AttributeConsumerRewardDenom, denomToRemove), + types.EventTypeRemoveConsumerRewardDenom, + sdk.NewAttribute(types.AttributeConsumerRewardDenom, denomToRemove), )) } return nil diff --git a/x/ccv/provider/keeper/proposal_test.go b/x/ccv/provider/keeper/proposal_test.go index e9468d860f..0992b14553 100644 --- a/x/ccv/provider/keeper/proposal_test.go +++ b/x/ccv/provider/keeper/proposal_test.go @@ -231,6 +231,7 @@ func TestPendingConsumerAdditionPropDeletion(t *testing.T) { defer ctrl.Finish() for _, tc := range testCases { + tc := tc providerKeeper.SetPendingConsumerAdditionProp(ctx, &tc.ConsumerAdditionProposal) } @@ -580,6 +581,7 @@ func TestPendingConsumerRemovalPropDeletion(t *testing.T) { defer ctrl.Finish() for _, tc := range testCases { + tc := tc providerKeeper.SetPendingConsumerRemovalProp(ctx, &tc.ConsumerRemovalProposal) } diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index 63ea8dd9d5..0cbce718a7 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -426,11 +426,11 @@ func (k Keeper) HandleSlashPacket(ctx sdk.Context, chainID string, data ccv.Slas ctx.EventManager().EmitEvent( sdk.NewEvent( - ccv.EventTypeExecuteConsumerChainSlash, + providertypes.EventTypeExecuteConsumerChainSlash, sdk.NewAttribute(sdk.AttributeKeyModule, providertypes.ModuleName), sdk.NewAttribute(ccv.AttributeValidatorAddress, providerConsAddr.String()), sdk.NewAttribute(ccv.AttributeInfractionType, data.Infraction.String()), - sdk.NewAttribute(ccv.AttributeInfractionHeight, strconv.Itoa(int(infractionHeight))), + sdk.NewAttribute(providertypes.AttributeInfractionHeight, strconv.Itoa(int(infractionHeight))), sdk.NewAttribute(ccv.AttributeValSetUpdateID, strconv.Itoa(int(data.ValsetUpdateId))), ), ) @@ -452,7 +452,7 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) { "chainID", initTimeoutTimestamp.ChainId) err := k.StopConsumerChain(ctx, initTimeoutTimestamp.ChainId, false) if err != nil { - if ccv.ErrConsumerChainNotFound.Is(err) { + if providertypes.ErrConsumerChainNotFound.Is(err) { // consumer chain not found continue } @@ -479,7 +479,7 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) { ) err := k.StopConsumerChain(ctx, channelToChain.ChainId, true) if err != nil { - if ccv.ErrConsumerChainNotFound.Is(err) { + if providertypes.ErrConsumerChainNotFound.Is(err) { // consumer chain not found continue } diff --git a/x/ccv/provider/types/errors.go b/x/ccv/provider/types/errors.go index 12fbfbe9c2..66d7a9a3b8 100644 --- a/x/ccv/provider/types/errors.go +++ b/x/ccv/provider/types/errors.go @@ -21,4 +21,7 @@ var ( ErrInvalidProviderAddress = errorsmod.Register(ModuleName, 13, "invalid provider address") ErrInvalidConsumerRewardDenom = errorsmod.Register(ModuleName, 14, "invalid consumer reward denom") ErrInvalidDepositorAddress = errorsmod.Register(ModuleName, 15, "invalid depositor address") + ErrInvalidConsumerClient = errorsmod.Register(ModuleName, 16, "ccv channel is not built on correct client") + ErrDuplicateConsumerChain = errorsmod.Register(ModuleName, 17, "consumer chain already exists") + ErrConsumerChainNotFound = errorsmod.Register(ModuleName, 18, "consumer chain not found") ) diff --git a/x/ccv/provider/types/events.go b/x/ccv/provider/types/events.go new file mode 100644 index 0000000000..58d686020f --- /dev/null +++ b/x/ccv/provider/types/events.go @@ -0,0 +1,18 @@ +package types + +// Provider events +const ( + EventTypeConsumerClientCreated = "consumer_client_created" + EventTypeAssignConsumerKey = "assign_consumer_key" + EventTypeAddConsumerRewardDenom = "add_consumer_reward_denom" + EventTypeRemoveConsumerRewardDenom = "remove_consumer_reward_denom" + EventTypeExecuteConsumerChainSlash = "execute_consumer_chain_slash" + AttributeInfractionHeight = "infraction_height" + AttributeInitialHeight = "initial_height" + AttributeInitializationTimeout = "initialization_timeout" + AttributeTrustingPeriod = "trusting_period" + AttributeUnbondingPeriod = "unbonding_period" + AttributeProviderValidatorAddress = "provider_validator_address" + AttributeConsumerConsensusPubKey = "consumer_consensus_pub_key" + AttributeConsumerRewardDenom = "consumer_reward_denom" +) diff --git a/x/ccv/types/codec.go b/x/ccv/types/codec.go index d2815ae9b7..3db65608b2 100644 --- a/x/ccv/types/codec.go +++ b/x/ccv/types/codec.go @@ -5,31 +5,12 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" ) -// RegisterLegacyAminoCodec registers the necessary x/ibc transfer interfaces and concrete types -// on the provided LegacyAmino codec. These types are used for Amino JSON serialization. -func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { -} - -// RegisterInterfaces register the ibc transfer module interfaces to protobuf -// Any. -func RegisterInterfaces(registry codectypes.InterfaceRegistry) { -} - -var ( - amino = codec.NewLegacyAmino() - - // ModuleCdc references the global x/ibc-transfer module codec. Note, the codec - // should ONLY be used in certain instances of tests and for JSON encoding. - // - // The actual codec used for serialization should be provided to x/ibc transfer and - // defined at the application level. - ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) - - // AminoCdc is a amino codec created to support amino json compatible msgs. - AminoCdc = codec.NewAminoCodec(amino) -) +// ModuleCdc references the global x/ibc-transfer module codec. Note, the codec +// should ONLY be used in certain instances of tests and for JSON encoding. +// +// The actual codec used for serialization should be provided to x/ibc transfer and +// defined at the application level. +var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) func init() { - RegisterLegacyAminoCodec(amino) - amino.Seal() } diff --git a/x/ccv/types/errors.go b/x/ccv/types/errors.go index 79c0e1e31c..b719e60479 100644 --- a/x/ccv/types/errors.go +++ b/x/ccv/types/errors.go @@ -6,23 +6,14 @@ import ( // CCV sentinel errors var ( - ErrInvalidPacketData = errorsmod.Register(ModuleName, 2, "invalid CCV packet data") - ErrInvalidPacketTimeout = errorsmod.Register(ModuleName, 3, "invalid packet timeout") - ErrInvalidVersion = errorsmod.Register(ModuleName, 4, "invalid CCV version") - ErrInvalidChannelFlow = errorsmod.Register(ModuleName, 5, "invalid message sent to channel end") - ErrInvalidConsumerChain = errorsmod.Register(ModuleName, 6, "invalid consumer chain") - ErrInvalidProviderChain = errorsmod.Register(ModuleName, 7, "invalid provider chain") - ErrInvalidStatus = errorsmod.Register(ModuleName, 8, "invalid channel status") - ErrInvalidGenesis = errorsmod.Register(ModuleName, 9, "invalid genesis state") - ErrDuplicateChannel = errorsmod.Register(ModuleName, 10, "CCV channel already exists") - ErrInvalidVSCMaturedId = errorsmod.Register(ModuleName, 11, "invalid vscId for VSC packet") - ErrInvalidVSCMaturedTime = errorsmod.Register(ModuleName, 12, "invalid maturity time for VSC packet") - ErrInvalidConsumerState = errorsmod.Register(ModuleName, 13, "provider chain has invalid state for consumer chain") - ErrInvalidConsumerClient = errorsmod.Register(ModuleName, 14, "ccv channel is not built on correct client") - ErrInvalidProposal = errorsmod.Register(ModuleName, 15, "invalid proposal") - ErrInvalidHandshakeMetadata = errorsmod.Register(ModuleName, 16, "invalid provider handshake metadata") - ErrChannelNotFound = errorsmod.Register(ModuleName, 17, "channel not found") - ErrClientNotFound = errorsmod.Register(ModuleName, 18, "client not found") - ErrDuplicateConsumerChain = errorsmod.Register(ModuleName, 19, "consumer chain already exists") - ErrConsumerChainNotFound = errorsmod.Register(ModuleName, 20, "consumer chain not found") + ErrInvalidPacketData = errorsmod.Register(ModuleName, 1, "invalid CCV packet data") + ErrInvalidVersion = errorsmod.Register(ModuleName, 2, "invalid CCV version") + ErrInvalidChannelFlow = errorsmod.Register(ModuleName, 3, "invalid message sent to channel end") + ErrInvalidGenesis = errorsmod.Register(ModuleName, 4, "invalid genesis state") + ErrDuplicateChannel = errorsmod.Register(ModuleName, 5, "CCV channel already exists") + ErrInvalidVSCMaturedId = errorsmod.Register(ModuleName, 6, "invalid vscId for VSC packet") + ErrInvalidVSCMaturedTime = errorsmod.Register(ModuleName, 7, "invalid maturity time for VSC packet") + ErrInvalidHandshakeMetadata = errorsmod.Register(ModuleName, 8, "invalid provider handshake metadata") + ErrChannelNotFound = errorsmod.Register(ModuleName, 9, "channel not found") + ErrClientNotFound = errorsmod.Register(ModuleName, 10, "client not found") ) diff --git a/x/ccv/types/events.go b/x/ccv/types/events.go index 82462f6530..7c7343021e 100644 --- a/x/ccv/types/events.go +++ b/x/ccv/types/events.go @@ -2,45 +2,17 @@ package types // CCV events const ( - EventTypeTimeout = "timeout" - EventTypePacket = "ccv_packet" - EventTypeChannelEstablished = "channel_established" - EventTypeFeeTransferChannelOpened = "fee_transfer_channel_opened" - EventTypeConsumerClientCreated = "consumer_client_created" - EventTypeAssignConsumerKey = "assign_consumer_key" - EventTypeAddConsumerRewardDenom = "add_consumer_reward_denom" - EventTypeRemoveConsumerRewardDenom = "remove_consumer_reward_denom" - - EventTypeExecuteConsumerChainSlash = "execute_consumer_chain_slash" - EventTypeFeeDistribution = "fee_distribution" - EventTypeConsumerSlashRequest = "consumer_slash_request" - EventTypeVSCMatured = "vsc_matured" + EventTypeTimeout = "timeout" + EventTypePacket = "ccv_packet" + EventTypeChannelEstablished = "channel_established" AttributeKeyAckSuccess = "success" AttributeKeyAck = "acknowledgement" AttributeKeyAckError = "error" - AttributeChainID = "chain_id" - AttributeValidatorAddress = "validator_address" - AttributeValidatorConsumerAddress = "validator_consumer_address" - AttributeInfractionType = "infraction_type" - AttributeInfractionHeight = "infraction_height" - AttributeConsumerHeight = "consumer_height" - AttributeValSetUpdateID = "valset_update_id" - AttributeTimestamp = "timestamp" - AttributeInitialHeight = "initial_height" - AttributeInitializationTimeout = "initialization_timeout" - AttributeTrustingPeriod = "trusting_period" - AttributeUnbondingPeriod = "unbonding_period" - AttributeProviderValidatorAddress = "provider_validator_address" - AttributeConsumerConsensusPubKey = "consumer_consensus_pub_key" - - AttributeDistributionCurrentHeight = "current_distribution_height" - //#nosec G101 -- (false positive) this is not a hardcoded credential - AttributeDistributionNextHeight = "next_distribution_height" - AttributeDistributionFraction = "distribution_fraction" - AttributeDistributionTotal = "total" - AttributeDistributionToProvider = "provider_amount" + AttributeChainID = "chain_id" + AttributeValidatorAddress = "validator_address" + AttributeInfractionType = "infraction_type" - AttributeConsumerRewardDenom = "consumer_reward_denom" + AttributeValSetUpdateID = "valset_update_id" )