Skip to content

Commit

Permalink
fix(evm)!: set event status to completed when msg is queued for routi…
Browse files Browse the repository at this point in the history
…ng in the nexus module (axelarnetwork#2084)
  • Loading branch information
fish-sammy authored Jan 23, 2024
1 parent e080596 commit 007ebb2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 56 deletions.
6 changes: 0 additions & 6 deletions x/evm/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,6 @@ func handleMessages(ctx sdk.Context, bk types.BaseKeeper, n types.Nexus, m types
continue
}

if srcCk, err := bk.ForChain(ctx, msg.GetSourceChain()); err == nil {
eventID := types.NewEventID(types.Hash(common.BytesToHash(msg.SourceTxID)), msg.SourceTxIndex)

funcs.MustNoErr(srcCk.SetEventCompleted(ctx, eventID))
}

funcs.MustNoErr(n.SetMessageExecuted(ctx, msg.ID))
}
}
Expand Down
48 changes: 0 additions & 48 deletions x/evm/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ func TestHandleGeneralMessages(t *testing.T) {
multisigKeeper *mock.MultisigKeeperMock
ck1 *mock.ChainKeeperMock
ck2 *mock.ChainKeeperMock
ck3 *mock.ChainKeeperMock
)
chain1 := nexus.ChainName(rand.Str(5))
chain2 := nexus.ChainName(rand.Str(5))
Expand Down Expand Up @@ -380,53 +379,6 @@ func TestHandleGeneralMessages(t *testing.T) {
assert.Len(t, ck2.EnqueueCommandCalls(), int(ck2.GetParams(ctx).EndBlockerLimit))
}).
Run(t)

givenGeneralMessagesEnqueued.
When("some associated EVM event exists", func() {
srcChain := nexustestutils.RandomChain()
srcChain.Module = types.ModuleName

ck1.GetParamsFunc = func(ctx sdk.Context) types.Params {
return types.Params{EndBlockerLimit: 45}
}
ck2.GetParamsFunc = func(ctx sdk.Context) types.Params {
return types.Params{EndBlockerLimit: 40}
}
ck3 = &mock.ChainKeeperMock{}

bk.ForChainFunc = func(_ sdk.Context, chain nexus.ChainName) (types.ChainKeeper, error) {
switch chain {
case chain1:
return ck1, nil
case chain2:
return ck2, nil
case srcChain.Name:
return ck3, nil
default:
return nil, errors.New("not found")
}
}

n.GetProcessingMessagesFunc = func(_ sdk.Context, chain nexus.ChainName, limit int64) []nexus.GeneralMessage {
destChain := nexus.Chain{Name: chain, Module: types.ModuleName}
sender := nexus.CrossChainAddress{Chain: srcChain, Address: evmTestUtils.RandomAddress().Hex()}
receiver := nexus.CrossChainAddress{Chain: destChain, Address: evmTestUtils.RandomAddress().Hex()}

msg := nexus.NewGeneralMessage(evmTestUtils.RandomHash().Hex(), sender, receiver, evmTestUtils.RandomHash().Bytes(), evmTestUtils.RandomHash().Bytes()[:], uint64(rand.I64Between(0, 10000)), nil)

return []nexus.GeneralMessage{msg}
}
}).
Then("should handle", func(t *testing.T) {
ck3.SetEventCompletedFunc = func(ctx sdk.Context, eventID types.EventID) error { return nil }

handleMessages(ctx, bk, n, multisigKeeper)

assert.Len(t, ck1.EnqueueCommandCalls(), 1)
assert.Len(t, ck2.EnqueueCommandCalls(), 1)
assert.Len(t, ck3.SetEventCompletedCalls(), 2)
}).
Run(t)
}

func TestHandleContractCall(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions x/evm/keeper/vote_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (v voteHandler) handleEvent(ctx sdk.Context, ck types.ChainKeeper, event ty
// which bypassed nexus routing
switch event.GetEvent().(type) {
case *types.Event_ContractCall:
if err := v.handleContractCall(ctx, event); err != nil {
if err := v.handleContractCall(ctx, ck, event); err != nil {
return err
}
default:
Expand All @@ -219,14 +219,15 @@ func (v voteHandler) handleEvent(ctx sdk.Context, ck types.ChainKeeper, event ty
return nil
}

func (v voteHandler) handleContractCall(ctx sdk.Context, event types.Event) error {
func (v voteHandler) handleContractCall(ctx sdk.Context, ck types.ChainKeeper, event types.Event) error {
msg := mustToGeneralMessage(ctx, v.nexus, event)

if err := v.nexus.SetNewMessage(ctx, msg); err != nil {
return err
}

funcs.MustNoErr(v.nexus.EnqueueRouteMessage(ctx, msg.ID))
funcs.MustNoErr(ck.SetEventCompleted(ctx, event.GetID()))

return nil
}
Expand Down
4 changes: 4 additions & 0 deletions x/evm/keeper/vote_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,15 @@ func TestHandleResult(t *testing.T) {
}).
When("succeeded to route the general messages", func() {
nexusK.EnqueueRouteMessageFunc = func(_ sdk.Context, _ string) error { return nil }
chaink.SetEventCompletedFunc = func(sdk.Context, types.EventID) error { return nil }
}).
Then("should route the general messages", func(t *testing.T) {
nexusK.SetNewMessageFunc = func(_ sdk.Context, _ nexus.GeneralMessage) error { return nil }

assert.NoError(t, handler.HandleResult(ctx, result))
assert.Len(t, nexusK.SetNewMessageCalls(), 5)
assert.Len(t, nexusK.EnqueueRouteMessageCalls(), 5)
assert.Len(t, chaink.SetEventCompletedCalls(), 5)
}),

When("event is contract call and is sent to a known chain", func() {
Expand Down Expand Up @@ -387,13 +389,15 @@ func TestHandleResult(t *testing.T) {
}).
When("succeeded to route the general messages", func() {
nexusK.EnqueueRouteMessageFunc = func(_ sdk.Context, _ string) error { return nil }
chaink.SetEventCompletedFunc = func(sdk.Context, types.EventID) error { return nil }
}).
Then("should set as approved general messages", func(t *testing.T) {
nexusK.SetNewMessageFunc = func(_ sdk.Context, _ nexus.GeneralMessage) error { return nil }

assert.NoError(t, handler.HandleResult(ctx, result))
assert.Len(t, nexusK.SetNewMessageCalls(), 5)
assert.Len(t, nexusK.EnqueueRouteMessageCalls(), 5)
assert.Len(t, chaink.SetEventCompletedCalls(), 5)

for _, call := range nexusK.SetNewMessageCalls() {
assert.Equal(t, wasm.ModuleName, call.M.Recipient.Chain.Module)
Expand Down

0 comments on commit 007ebb2

Please sign in to comment.