diff --git a/CHANGELOG.md b/CHANGELOG.md index 02af17c34..2610b7c32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - [\#790](https://github.com/cosmos/evm/pull/790) fix panic in historical query due to missing EvmCoinInfo. - [\#800](https://github.com/cosmos/evm/pull/800) Fix denom exponent validation in virtual fee deduct in vm module. - [\#817](https://github.com/cosmos/evm/pull/817) Align GetCoinbaseAddress to handle empty proposer address in contexts like CheckTx where proposer doesn't exist. +- [\#814](https://github.com/cosmos/evm/pull/814) Fix duplicated events in post tx processor. - [\#816](https://github.com/cosmos/evm/pull/816) Avoid nil pointer when RPC requests execute before evmCoinInfo initialization in PreBlock with defaultEvmCoinInfo fallback. ## v0.5.0 diff --git a/tests/integration/x/vm/test_state_transition.go b/tests/integration/x/vm/test_state_transition.go index ece42bb74..738a65966 100644 --- a/tests/integration/x/vm/test_state_transition.go +++ b/tests/integration/x/vm/test_state_transition.go @@ -38,6 +38,8 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) +const TestPostProcessingEventType = "test_post_processing_event" + func (s *KeeperTestSuite) TestContextSetConsensusParams() { // set new value of max gas in consensus params maxGas := int64(123456789) @@ -675,6 +677,7 @@ func (s *KeeperTestSuite) TestApplyTransactionWithTxPostProcessing() { keeper.NewMultiEvmHooks( &testHooks{ postProcessing: func(ctx sdk.Context, sender common.Address, msg core.Message, receipt *gethtypes.Receipt) error { + ctx.EventManager().EmitEvent(sdk.NewEvent(TestPostProcessingEventType)) return nil }, }, @@ -706,7 +709,17 @@ func (s *KeeperTestSuite) TestApplyTransactionWithTxPostProcessing() { s.Require().Equal(senderBefore.Sub(sdkmath.NewIntFromBigInt(transferAmt)), senderAfter) s.Require().Equal(recipientBefore.Add(sdkmath.NewIntFromBigInt(transferAmt)), recipientAfter) }, - func(s *KeeperTestSuite) {}, + func(s *KeeperTestSuite) { + // check if the event emitted exactly once + events := s.Network.GetContext().EventManager().Events() + var postProcessingEvents []sdk.Event + for _, event := range events { + if event.Type == TestPostProcessingEventType { + postProcessingEvents = append(postProcessingEvents, event) + } + } + s.Require().Len(postProcessingEvents, 1) + }, }, { "pass - evm tx succeeds, post processing is called but fails, the balance is unchanged", diff --git a/x/vm/keeper/state_transition.go b/x/vm/keeper/state_transition.go index 61a565c51..192f00ad5 100644 --- a/x/vm/keeper/state_transition.go +++ b/x/vm/keeper/state_transition.go @@ -262,8 +262,6 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t return nil, errorsmod.Wrap(err, "failed to extract sender address from ethereum transaction") } - eventsLen := len(tmpCtx.EventManager().Events()) - // Only call PostTxProcessing if there are hooks set, to avoid calling commitFn unnecessarily if !k.HasHooks() { // If there are no hooks, we can commit the state immediately if the tx is successful @@ -297,11 +295,6 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t } else { res.Logs = types.NewLogsFromEth(receipt.Logs) } - - events := tmpCtx.EventManager().Events() - if len(events) > eventsLen { - ctx.EventManager().EmitEvents(events[eventsLen:]) - } } }