Skip to content

chore: emit event on consensus message creation #1355

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

Merged
merged 2 commits into from
Mar 21, 2025
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
17 changes: 17 additions & 0 deletions util/libwasm/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ func (h router) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contra
if err != nil {
logger.WithError(err).Error("Failed to dispatch message.")
}

// Annoyingly enough, we cannot get the events which have been
// emitted during the dispatch directly without parsing.
evts := make([]sdk.Event, len(ctx.EventManager().Events()))
for i, v := range ctx.EventManager().Events() {
attrs := make([]sdk.Attribute, len(v.Attributes))
for j, k := range v.Attributes {
attrs[j] = sdk.Attribute{
Key: k.Key,
Value: k.Value,
}
}
evts[i] = sdk.NewEvent(fmt.Sprintf("dispatcher_%s", v.Type), attrs...)
}

// Attaching any events emitted during the dispatch to the transaction
a = evts
}()

if msg.Custom != nil {
Expand Down
16 changes: 15 additions & 1 deletion util/libwasm/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (

"cosmossdk.io/log"
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
"github.com/cometbft/cometbft/abci/types"
tmtypes "github.com/cometbft/cometbft/proto/tendermint/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
schedulerbindings "github.com/palomachain/paloma/v2/x/scheduler/bindings/types"
skywaybindings "github.com/palomachain/paloma/v2/x/skyway/bindings/types"
tfbindings "github.com/palomachain/paloma/v2/x/tokenfactory/bindings/types"
Expand All @@ -25,8 +28,19 @@ func (m *MockMessenger[T]) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddr
return args.Get(0).([]sdk.Event), args.Get(1).([][]byte), args.Get(2).([][]*codectypes.Any), args.Error(3)
}

var _ sdk.EventManagerI = (*mockEvtMgr)(nil)

type mockEvtMgr struct{}

func (m *mockEvtMgr) ABCIEvents() []types.Event { return nil }
func (m *mockEvtMgr) EmitEvent(event sdk.Event) {}
func (m *mockEvtMgr) EmitEvents(events sdk.Events) {}
func (m *mockEvtMgr) EmitTypedEvent(tev proto.Message) error { return nil }
func (m *mockEvtMgr) EmitTypedEvents(tevs ...proto.Message) error { return nil }
func (m *mockEvtMgr) Events() sdk.Events { return nil }

func TestDispatchMsg(t *testing.T) {
ctx := sdk.Context{}
ctx := sdk.NewContext(nil, tmtypes.Header{}, false, log.NewNopLogger()).WithEventManager(&mockEvtMgr{})
contractAddr := sdk.AccAddress([]byte("test_address"))
contractIBCPortID := "test_port"

Expand Down
13 changes: 12 additions & 1 deletion x/evm/keeper/smart_contract_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (k Keeper) AddSmartContractExecutionToConsensus(
return 0, err
}

return k.ConsensusKeeper.PutMessageInQueue(
id, err := k.ConsensusKeeper.PutMessageInQueue(
ctx,
consensustypes.Queue(
types.ConsensusTurnstoneMessage,
Expand All @@ -182,6 +182,17 @@ func (k Keeper) AddSmartContractExecutionToConsensus(
RequireGasEstimation: true,
RequireSignatures: true,
})
if err != nil {
return 0, err
}

keeperutil.EmitEvent(k, ctx, "add_consensus_message",
sdk.NewAttribute("msg_id", fmt.Sprint(id)),
sdk.NewAttribute("chain_reference_id", chainReferenceID),
sdk.NewAttribute("assignee", assignee),
sdk.NewAttribute("assignee_remote_addr", remoteAddr),
)
return id, nil
}

func (k Keeper) scheduleCompassHandover(
Expand Down