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

Additional cork and axelarcork events for easier tracking #322

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions x/axelarcork/keeper/abci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"encoding/hex"
"fmt"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -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())))),
),
},
)
}
}

Expand Down
12 changes: 12 additions & 0 deletions x/axelarcork/types/events.go
Original file line number Diff line number Diff line change
@@ -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
)
22 changes: 19 additions & 3 deletions x/cork/keeper/abci.go
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
9 changes: 9 additions & 0 deletions x/cork/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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(
Expand All @@ -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)),
),
},
)
Expand Down
6 changes: 4 additions & 2 deletions x/cork/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -12,6 +13,7 @@ const (
AttributeKeyCommitPeriodStart = "commit_period_start"
AttributeKeyCommitPeriodEnd = "commit_period_end"
AttributeKeyBlockHeight = "block_height"
AttributeKeyCorkID = "cork_id"

AttributeValueCategory = ModuleName
)
Loading