diff --git a/x/axelarcork/keeper/abci.go b/x/axelarcork/keeper/abci.go index d5fb43eb..73f24f24 100644 --- a/x/axelarcork/keeper/abci.go +++ b/x/axelarcork/keeper/abci.go @@ -1,6 +1,7 @@ package keeper import ( + "encoding/hex" "fmt" "github.com/ethereum/go-ethereum/common" @@ -33,6 +34,18 @@ func (k Keeper) EndBlocker(ctx sdk.Context) { "chain id", config.Id) for _, c := range winningScheduledVotes { k.SetWinningAxelarCork(ctx, config.Id, uint64(ctx.BlockHeight()), c) + + ctx.EventManager().EmitEvents( + sdk.Events{ + sdk.NewEvent( + types.EventTypeAxelarCorkApproved, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(types.AttributeKeyCork, c.String()), + sdk.NewAttribute(types.AttributeKeyBlockHeight, fmt.Sprintf("%d", ctx.BlockHeight())), + sdk.NewAttribute(types.AttributeKeyCorkID, hex.EncodeToString(c.IDHash(uint64(ctx.BlockHeight())))), + ), + }, + ) } } diff --git a/x/axelarcork/types/events.go b/x/axelarcork/types/events.go new file mode 100644 index 00000000..d0e67457 --- /dev/null +++ b/x/axelarcork/types/events.go @@ -0,0 +1,12 @@ +package types + +// axelarcork module event types +const ( + EventTypeAxelarCorkApproved = "axelar_cork_approved" + + AttributeKeyCork = "cork" + AttributeKeyBlockHeight = "block_height" + AttributeKeyCorkID = "cork_id" + + AttributeValueCategory = ModuleName +) diff --git a/x/cork/keeper/abci.go b/x/cork/keeper/abci.go index c7ff943d..014b5833 100644 --- a/x/cork/keeper/abci.go +++ b/x/cork/keeper/abci.go @@ -1,34 +1,50 @@ package keeper import ( + "encoding/hex" "fmt" "github.com/ethereum/go-ethereum/common" sdk "github.com/cosmos/cosmos-sdk/types" gravitytypes "github.com/peggyjv/gravity-bridge/module/v5/x/gravity/types" - types "github.com/peggyjv/sommelier/v8/x/cork/types/v2" + "github.com/peggyjv/sommelier/v8/x/cork/types" + v2types "github.com/peggyjv/sommelier/v8/x/cork/types/v2" ) // BeginBlocker is called at the beginning of every block func (k Keeper) BeginBlocker(ctx sdk.Context) {} -func (k Keeper) submitContractCall(ctx sdk.Context, cork types.Cork) { +func (k Keeper) submitContractCall(ctx sdk.Context, cork v2types.Cork) { k.Logger(ctx).Info("setting outgoing tx for contract call", "address", cork.TargetContractAddress, "encoded contract call", cork.EncodedContractCall) // increment invalidation nonce invalidationNonce := k.IncrementInvalidationNonce(ctx) + invalidationScope := cork.InvalidationScope() // submit contract call to bridge k.gravityKeeper.CreateContractCallTx( ctx, invalidationNonce, - cork.InvalidationScope(), + invalidationScope, common.HexToAddress(cork.TargetContractAddress), cork.EncodedContractCall, []gravitytypes.ERC20Token{}, // tokens are always zero []gravitytypes.ERC20Token{}, ) + + ctx.EventManager().EmitEvents( + sdk.Events{ + sdk.NewEvent(types.EventTypeSubmittedContractCall, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + sdk.NewAttribute(types.AttributeKeyCork, cork.String()), + sdk.NewAttribute(types.AttributeKeyBlockHeight, fmt.Sprintf("%d", ctx.BlockHeight())), + sdk.NewAttribute(types.AttributeKeyCorkID, hex.EncodeToString(cork.IDHash(uint64(ctx.BlockHeight())))), + sdk.NewAttribute(gravitytypes.AttributeKeyContractCallInvalidationScope, fmt.Sprint(invalidationScope)), + sdk.NewAttribute(gravitytypes.AttributeKeyContractCallInvalidationNonce, fmt.Sprint(invalidationNonce)), + ), + }, + ) } // EndBlocker defines the oracle logic that executes at the end of every block: diff --git a/x/cork/keeper/msg_server.go b/x/cork/keeper/msg_server.go index 3f6dac2a..58df9504 100644 --- a/x/cork/keeper/msg_server.go +++ b/x/cork/keeper/msg_server.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/ethereum/go-ethereum/common" + gravitytypes "github.com/peggyjv/gravity-bridge/module/v5/x/gravity/types" corktypes "github.com/peggyjv/sommelier/v8/x/cork/types" types "github.com/peggyjv/sommelier/v8/x/cork/types/v2" ) @@ -42,6 +43,10 @@ func (k Keeper) ScheduleCork(c context.Context, msg *types.MsgScheduleCorkReques corkID := k.SetScheduledCork(ctx, msg.BlockHeight, validatorAddr, *msg.Cork) k.IncrementValidatorCorkCount(ctx, validatorAddr) + invalidationScope := msg.Cork.InvalidationScope() + // If the vote succeeds, the current invalidation nonce will be incremented + invalidationNonce := k.GetLatestInvalidationNonce(ctx) + 1 + ctx.EventManager().EmitEvents( sdk.Events{ sdk.NewEvent( @@ -50,10 +55,14 @@ func (k Keeper) ScheduleCork(c context.Context, msg *types.MsgScheduleCorkReques ), sdk.NewEvent( corktypes.EventTypeCork, + sdk.NewAttribute(sdk.AttributeKeyModule, corktypes.AttributeValueCategory), sdk.NewAttribute(corktypes.AttributeKeySigner, signer.String()), sdk.NewAttribute(corktypes.AttributeKeyValidator, validatorAddr.String()), sdk.NewAttribute(corktypes.AttributeKeyCork, msg.Cork.String()), sdk.NewAttribute(corktypes.AttributeKeyBlockHeight, fmt.Sprintf("%d", msg.BlockHeight)), + sdk.NewAttribute(corktypes.AttributeKeyCorkID, hex.EncodeToString(corkID)), + sdk.NewAttribute(gravitytypes.AttributeKeyContractCallInvalidationScope, fmt.Sprint(invalidationScope)), + sdk.NewAttribute(gravitytypes.AttributeKeyContractCallInvalidationNonce, fmt.Sprint(invalidationNonce)), ), }, ) diff --git a/x/cork/types/events.go b/x/cork/types/events.go index 901e9c2b..40ea874f 100644 --- a/x/cork/types/events.go +++ b/x/cork/types/events.go @@ -2,8 +2,9 @@ package types // cork module event types const ( - EventTypeCork = "cork" - EventTypeCommitPeriod = "commit_period" + EventTypeCork = "cork" + EventTypeCommitPeriod = "commit_period" + EventTypeSubmittedContractCall = "submitted_contract_call" AttributeKeySigner = "signer" AttributeKeyValidator = "validator" @@ -12,6 +13,7 @@ const ( AttributeKeyCommitPeriodStart = "commit_period_start" AttributeKeyCommitPeriodEnd = "commit_period_end" AttributeKeyBlockHeight = "block_height" + AttributeKeyCorkID = "cork_id" AttributeValueCategory = ModuleName )