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

add event emissions to provider and consumer #427

Merged
merged 12 commits into from
Nov 11, 2022
9 changes: 9 additions & 0 deletions x/ccv/consumer/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions x/ccv/consumer/keeper/distribution.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand Down Expand Up @@ -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)
}

Expand Down
43 changes: 43 additions & 0 deletions x/ccv/consumer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()),
mpoke marked this conversation as resolved.
Show resolved Hide resolved
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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()),
),
)
}
}

Expand Down
14 changes: 13 additions & 1 deletion x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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(
mpoke marked this conversation as resolved.
Show resolved Hide resolved
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
}

Expand Down
15 changes: 15 additions & 0 deletions x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"
"strconv"
"time"

channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 12 additions & 0 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"
"strconv"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -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
}

Expand Down
32 changes: 29 additions & 3 deletions x/ccv/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)