diff --git a/x/ccv/consumer/ibc_module.go b/x/ccv/consumer/ibc_module.go index b16457e2fb..db80eed5d8 100644 --- a/x/ccv/consumer/ibc_module.go +++ b/x/ccv/consumer/ibc_module.go @@ -154,6 +154,15 @@ func (am AppModule) OnChanOpenAck( } am.keeper.SetDistributionTransmissionChannel(ctx, resp.ChannelId) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + ccv.EventTypeFeeTransferChannelOpened, + sdk.NewAttribute(sdk.AttributeKeyModule, consumertypes.ModuleName), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, channelID), + sdk.NewAttribute(channeltypes.AttributeKeyPortID, transfertypes.PortID), + ), + ) + return nil } diff --git a/x/ccv/consumer/keeper/distribution.go b/x/ccv/consumer/keeper/distribution.go index 377adadbda..f633cf70ad 100644 --- a/x/ccv/consumer/keeper/distribution.go +++ b/x/ccv/consumer/keeper/distribution.go @@ -1,6 +1,8 @@ package keeper import ( + "strconv" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -89,6 +91,19 @@ func (k Keeper) DistributeToProviderValidatorSet(ctx sdk.Context) error { Height: ctx.BlockHeight(), } + ctx.EventManager().EmitEvent( + sdk.NewEvent( + ccv.EventTypeFeeDistribution, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(ccv.AttributeDistributionCurrentHeight, strconv.Itoa(int(curHeight))), + sdk.NewAttribute(ccv.AttributeDistributionNextHeight, strconv.Itoa(int(curHeight+k.GetBlocksPerDistributionTransmission(ctx)))), + sdk.NewAttribute(ccv.AttributeDistributionFraction, (k.GetConsumerRedistributionFrac(ctx))), + sdk.NewAttribute(ccv.AttributeDistributionTotal, fpTokens.String()), + sdk.NewAttribute(ccv.AttributeDistributionToConsumer, consRedistrTokens.String()), + sdk.NewAttribute(ccv.AttributeDistributionToProvider, remainingTokens.String()), + ), + ) + return k.SetLastTransmissionBlockHeight(ctx, newLtbh) } diff --git a/x/ccv/consumer/keeper/relay.go b/x/ccv/consumer/keeper/relay.go index 83692c7eef..24f185ede1 100644 --- a/x/ccv/consumer/keeper/relay.go +++ b/x/ccv/consumer/keeper/relay.go @@ -3,6 +3,7 @@ package keeper import ( "encoding/binary" "fmt" + "strconv" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -36,6 +37,16 @@ func (k Keeper) OnRecvVSCPacket(ctx sdk.Context, packet channeltypes.Packet, new k.SetProviderChannel(ctx, packet.DestinationChannel) // - send pending slash requests in states k.SendPendingSlashRequests(ctx) + + // emit event on first VSC packet to signal that CCV is working + ctx.EventManager().EmitEvent( + sdk.NewEvent( + ccv.EventTypeChannelEstablished, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, packet.DestinationChannel), + sdk.NewAttribute(channeltypes.AttributeKeyPortID, packet.DestinationPort), + ), + ) } // Set pending changes by accumulating changes from this packet with all prior changes var pendingChanges []abci.ValidatorUpdate @@ -110,6 +121,16 @@ func (k Keeper) SendVSCMaturedPackets(ctx sdk.Context) error { return err } k.DeletePacketMaturityTime(ctx, vscId) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + ccv.EventTypeSendMaturedVSCPacket, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(ccv.AttributeChainID, ctx.ChainID()), + sdk.NewAttribute(ccv.AttributeConsumerHeight, strconv.Itoa(int(ctx.BlockHeight()))), + sdk.NewAttribute(ccv.AttributeValSetUpdateID, strconv.Itoa(int(vscId))), + sdk.NewAttribute(ccv.AttributeTimestamp, strconv.Itoa(int(currentTime))), + ), + ) } else { break } @@ -160,6 +181,18 @@ func (k Keeper) SendSlashPacket(ctx sdk.Context, validator abci.Validator, valse if downtime { k.SetOutstandingDowntime(ctx, consAddr) } + + // if provider channel is not established the emmission + // will instead take place in SendPendingSlashRequests + ctx.EventManager().EmitEvent( + sdk.NewEvent( + ccv.EventTypeSendSlashPacket, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(ccv.AttributeValidatorAddress, sdk.ConsAddress(validator.Address).String()), + sdk.NewAttribute(ccv.AttributeValSetUpdateID, strconv.Itoa(int(valsetUpdateID))), + sdk.NewAttribute(ccv.AttributeInfractionType, infraction.String()), + ), + ) } // SendPendingSlashRequests iterates over the stored pending slash requests in reverse order @@ -197,6 +230,16 @@ func (k Keeper) SendPendingSlashRequests(ctx sdk.Context) { if downtime { k.SetOutstandingDowntime(ctx, sdk.ConsAddress(slashReq.Packet.Validator.Address)) } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + ccv.EventTypeSendSlashPacket, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(ccv.AttributeValidatorAddress, sdk.ConsAddress(slashReq.Packet.Validator.Address).String()), + sdk.NewAttribute(ccv.AttributeValSetUpdateID, strconv.Itoa(int(slashReq.Packet.ValsetUpdateId))), + sdk.NewAttribute(ccv.AttributeInfractionType, slashReq.Packet.Infraction.String()), + ), + ) } } diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index ca740fa11c..f831ad18f1 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -267,7 +267,7 @@ func (k Keeper) SetConsumerChain(ctx sdk.Context, channelID string) error { return sdkerrors.Wrap(channeltypes.ErrTooManyConnectionHops, "must have direct connection to consumer chain") } connectionID := channel.ConnectionHops[0] - _, tmClient, err := k.getUnderlyingClient(ctx, connectionID) + clientID, tmClient, err := k.getUnderlyingClient(ctx, connectionID) if err != nil { return err } @@ -285,6 +285,18 @@ func (k Keeper) SetConsumerChain(ctx sdk.Context, channelID string) error { k.SetInitChainHeight(ctx, chainID, uint64(ctx.BlockHeight())) // - remove init timeout timestamp k.DeleteInitTimeoutTimestamp(ctx, chainID) + + // emit event on successful addition + ctx.EventManager().EmitEvent( + sdk.NewEvent( + ccv.EventTypeChannelEstablished, + sdk.NewAttribute(sdk.AttributeKeyModule, consumertypes.ModuleName), + sdk.NewAttribute(ccv.AttributeChainID, chainID), + sdk.NewAttribute(conntypes.AttributeKeyClientID, clientID), + sdk.NewAttribute(channeltypes.AttributeKeyChannelID, channelID), + sdk.NewAttribute(conntypes.AttributeKeyConnectionID, connectionID), + ), + ) return nil } diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index b235476260..6793294561 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + "strconv" "time" channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" @@ -94,6 +95,20 @@ func (k Keeper) CreateConsumerClient(ctx sdk.Context, chainID string, if lockUbdOnTimeout { k.SetLockUnbondingOnTimeout(ctx, chainID) } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + ccv.EventTypeConsumerClientCreated, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(ccv.AttributeChainID, chainID), + sdk.NewAttribute(clienttypes.AttributeKeyClientID, clientID), + sdk.NewAttribute(ccv.AttributeInitialHeight, 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()), + ), + ) + return nil } diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index 2b7d0debf6..346a08b198 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + "strconv" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -303,6 +304,17 @@ func (k Keeper) HandleSlashPacket(ctx sdk.Context, chainID string, data ccv.Slas } k.slashingKeeper.JailUntil(ctx, consAddr, jailTime) + ctx.EventManager().EmitEvent( + sdk.NewEvent( + ccv.EventTypeExecuteConsumerChainSlash, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(ccv.AttributeValidatorAddress, consAddr.String()), + sdk.NewAttribute(ccv.AttributeInfractionType, data.Infraction.String()), + sdk.NewAttribute(ccv.AttributeInfractionHeight, strconv.Itoa(int(infractionHeight))), + sdk.NewAttribute(ccv.AttributeValSetUpdateID, strconv.Itoa(int(data.ValsetUpdateId))), + ), + ) + return true, nil } diff --git a/x/ccv/types/events.go b/x/ccv/types/events.go index 93ea470d4a..0f6bebc0ef 100644 --- a/x/ccv/types/events.go +++ b/x/ccv/types/events.go @@ -2,11 +2,37 @@ package types // CCV events const ( - EventTypeTimeout = "timeout" - EventTypePacket = "ccv_packet" - EventTypeChannelClose = "channel_closed" + EventTypeTimeout = "timeout" + EventTypePacket = "ccv_packet" + EventTypeChannelEstablished = "channel_established" + EventTypeFeeTransferChannelOpened = "fee_transfer_channel_opened" + EventTypeConsumerClientCreated = "consumer_client_created" + + EventTypeExecuteConsumerChainSlash = "execute_consumer_chain_slash" + EventTypeFeeDistribution = "fee_distribution" + EventTypeSendSlashPacket = "send_slash_packet" + EventTypeSendMaturedVSCPacket = "send_matured_vsc_packet" AttributeKeyAckSuccess = "success" AttributeKeyAck = "acknowledgement" AttributeKeyAckError = "error" + + AttributeChainID = "chain_id" + AttributeValidatorAddress = "validator_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" + + AttributeDistributionCurrentHeight = "current_distribution_height" + AttributeDistributionNextHeight = "next_distribution_height" + AttributeDistributionFraction = "distribution_fraction" + AttributeDistributionTotal = "total" + AttributeDistributionToConsumer = "consumer_amount" + AttributeDistributionToProvider = "provider_amount" )