diff --git a/x/keyshare/keeper/msg_server_send_keyshare.go b/x/keyshare/keeper/msg_server_send_keyshare.go index d6a4d428..f630885c 100644 --- a/x/keyshare/keeper/msg_server_send_keyshare.go +++ b/x/keyshare/keeper/msg_server_send_keyshare.go @@ -5,6 +5,8 @@ import ( "encoding/hex" "fairyring/x/keyshare/types" "fmt" + "github.com/armon/go-metrics" + "github.com/cosmos/cosmos-sdk/telemetry" "strconv" distIBE "github.com/FairBlock/DistributedIBE" @@ -66,6 +68,7 @@ func (k msgServer) SendKeyshare(goCtx context.Context, msg *types.MsgSendKeyshar // Parse the keyshare & commitment then verify it _, _, err := parseKeyShareCommitment(suite, msg.Message, commitments.Commitments[msg.KeyShareIndex-1], uint32(msg.KeyShareIndex), ibeID) if err != nil { + defer telemetry.IncrCounter(1, types.KeyTotalInvalidKeyShareSubmitted) k.Logger(ctx).Error(fmt.Sprintf("Error in parsing & verifying keyshare & commitment: %s", err.Error())) k.Logger(ctx).Error(fmt.Sprintf("KeyShare is: %v | Commitment is: %v | Index: %d", msg.Message, commitments.Commitments, msg.KeyShareIndex)) // Invalid Share, slash validator @@ -143,11 +146,12 @@ func (k msgServer) SendKeyshare(goCtx context.Context, msg *types.MsgSendKeyshar ) // Check if there is an aggregated key exists - _, found = k.GetAggregatedKeyShare(ctx, msg.BlockHeight) + aggrKeyData, found := k.GetAggregatedKeyShare(ctx, msg.BlockHeight) // If there is not enough keyshares to aggregate OR there is already an aggregated key // Only continue the code if there is enough keyshare to aggregate & no aggregated key for current height if int64(len(stateKeyShares)) < expectedThreshold || found { + defer telemetry.IncrCounterWithLabels([]string{types.KeyTotalValidKeyShareSubmitted}, 1, []metrics.Label{telemetry.NewLabel("aggrkey", aggrKeyData.Data)}) return &types.MsgSendKeyshareResponse{ Creator: msg.Creator, Keyshare: msg.Message, @@ -207,6 +211,8 @@ func (k msgServer) SendKeyshare(goCtx context.Context, msg *types.MsgSendKeyshar k.Logger(ctx).Info(fmt.Sprintf("Aggregated Decryption Key for Block %d: %s", msg.BlockHeight, skHex)) + defer telemetry.IncrCounterWithLabels([]string{types.KeyTotalValidKeyShareSubmitted}, 1, []metrics.Label{telemetry.NewLabel("aggrkey", skHex)}) + ctx.EventManager().EmitEvent( sdk.NewEvent(types.KeyShareAggregatedEventType, sdk.NewAttribute(types.KeyShareAggregatedEventBlockHeight, strconv.FormatUint(msg.BlockHeight, 10)), diff --git a/x/keyshare/module.go b/x/keyshare/module.go index 66eb99d6..3cd14e57 100644 --- a/x/keyshare/module.go +++ b/x/keyshare/module.go @@ -6,6 +6,7 @@ import ( "encoding/json" peptypes "fairyring/x/pep/types" "fmt" + "github.com/cosmos/cosmos-sdk/telemetry" "strconv" // this line is used by starport scaffolding # 1 @@ -265,6 +266,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val // After being slashed, his/her last submitted height will be set to the current block // So he/she won't be slashed in the next block instead he/she will be slashed if he didn't submit for N block again. am.keeper.SetLastSubmittedHeight(ctx, eachValidator.Validator, strconv.FormatInt(ctx.BlockHeight(), 10)) + telemetry.IncrCounter(1, types.KeyTotalIdleValSlashed) } return []abci.ValidatorUpdate{} diff --git a/x/keyshare/types/keys.go b/x/keyshare/types/keys.go index 1277c53f..b19d8cf0 100644 --- a/x/keyshare/types/keys.go +++ b/x/keyshare/types/keys.go @@ -85,6 +85,12 @@ const ( QueuedPubKeyCreatedEventPubkey = "queued-pubkey-created-pubkey" ) +const ( + KeyTotalIdleValSlashed = "total_idle_validator_slashed" + KeyTotalValidKeyShareSubmitted = "total_valid_key_share" + KeyTotalInvalidKeyShareSubmitted = "total_invalid_key_share" +) + var ( // PortKey defines the key to store the port ID in store PortKey = KeyPrefix("keyshare-port-") diff --git a/x/pep/keeper/msg_server_submit_encrypted_tx.go b/x/pep/keeper/msg_server_submit_encrypted_tx.go index 0ee64ed2..343e5390 100644 --- a/x/pep/keeper/msg_server_submit_encrypted_tx.go +++ b/x/pep/keeper/msg_server_submit_encrypted_tx.go @@ -4,6 +4,7 @@ import ( "context" "fairyring/x/pep/types" "fmt" + "github.com/cosmos/cosmos-sdk/telemetry" "strconv" sdk "github.com/cosmos/cosmos-sdk/types" @@ -70,5 +71,7 @@ func (k msgServer) SubmitEncryptedTx(goCtx context.Context, msg *types.MsgSubmit ), ) + defer telemetry.IncrCounter(1, types.KeyTotalEncryptedTxSubmitted) + return &types.MsgSubmitEncryptedTxResponse{}, nil } diff --git a/x/pep/module.go b/x/pep/module.go index 129825b9..4cefe03f 100644 --- a/x/pep/module.go +++ b/x/pep/module.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/cosmos/cosmos-sdk/telemetry" cosmosmath "cosmossdk.io/math" @@ -230,7 +231,7 @@ func (am AppModule) processFailedEncryptedTx(ctx sdk.Context, tx types.Encrypted if ctx.GasMeter().GasConsumed() > startConsumedGas { actualGasConsumed = ctx.GasMeter().GasConsumed() - startConsumedGas } - + defer telemetry.IncrCounter(1, types.KeyTotalFailedEncryptedTx) am.handleGasConsumption(ctx, creatorAddr, cosmosmath.NewIntFromUint64(actualGasConsumed), tx.ChargedGas) } @@ -538,6 +539,8 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { sdk.NewAttribute(types.EncryptedTxExecutedEventIndex, strconv.FormatUint(eachTx.Index, 10)), ), ) + + telemetry.IncrCounter(1, types.KeyTotalSuccessEncryptedTx) } am.keeper.RemoveAllEncryptedTxFromHeight(ctx, h) diff --git a/x/pep/types/keys.go b/x/pep/types/keys.go index 15704553..9df6334b 100644 --- a/x/pep/types/keys.go +++ b/x/pep/types/keys.go @@ -62,6 +62,12 @@ const ( KeyShareVerificationReason = "keyshare-verification-reason" ) +const ( + KeyTotalEncryptedTxSubmitted = "total_encrypted_tx_submitted" + KeyTotalSuccessEncryptedTx = "total_success_encrypted_tx" + KeyTotalFailedEncryptedTx = "total_failed_encrypted_tx" +) + func KeyPrefix(p string) []byte { return []byte(p) }