Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

evm: PostTxProcessing hook - include the full message data #1027

Merged
merged 3 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking

* (evm) [tharsis#1027](https://github.com/tharsis/ethermint/pull/1027) Change the `PostTxProcessing` hook interface to include the full message data.
* (feemarket) [tharsis#1026](https://github.com/tharsis/ethermint/pull/1026) Fix REST endpoints to use `/ethermint/feemarket/*` instead of `/feemarket/evm/*`.

### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions x/evm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,13 @@ func (suite *EvmTestSuite) TestContractDeploymentRevert() {
// DummyHook implements EvmHooks interface
type DummyHook struct{}

func (dh *DummyHook) PostTxProcessing(ctx sdk.Context, from common.Address, to *common.Address, receipt *ethtypes.Receipt) error {
func (dh *DummyHook) PostTxProcessing(ctx sdk.Context, msg ethtypes.Message, receipt *ethtypes.Receipt) error {
return nil
}

// FailureHook implements EvmHooks interface
type FailureHook struct{}

func (dh *FailureHook) PostTxProcessing(ctx sdk.Context, from common.Address, to *common.Address, receipt *ethtypes.Receipt) error {
func (dh *FailureHook) PostTxProcessing(ctx sdk.Context, msg ethtypes.Message, receipt *ethtypes.Receipt) error {
return errors.New("mock error")
}
5 changes: 2 additions & 3 deletions x/evm/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/tharsis/ethermint/x/evm/types"
)
Expand All @@ -19,9 +18,9 @@ func NewMultiEvmHooks(hooks ...types.EvmHooks) MultiEvmHooks {
}

// PostTxProcessing delegate the call to underlying hooks
func (mh MultiEvmHooks) PostTxProcessing(ctx sdk.Context, from common.Address, to *common.Address, receipt *ethtypes.Receipt) error {
func (mh MultiEvmHooks) PostTxProcessing(ctx sdk.Context, msg ethtypes.Message, receipt *ethtypes.Receipt) error {
for i := range mh {
if err := mh[i].PostTxProcessing(ctx, from, to, receipt); err != nil {
if err := mh[i].PostTxProcessing(ctx, msg, receipt); err != nil {
return sdkerrors.Wrapf(err, "EVM hook %T failed", mh[i])
}
}
Expand Down
6 changes: 3 additions & 3 deletions x/evm/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ type LogRecordHook struct {
Logs []*ethtypes.Log
}

func (dh *LogRecordHook) PostTxProcessing(ctx sdk.Context, from common.Address, to *common.Address, receipt *ethtypes.Receipt) error {
func (dh *LogRecordHook) PostTxProcessing(ctx sdk.Context, msg ethtypes.Message, receipt *ethtypes.Receipt) error {
dh.Logs = receipt.Logs
return nil
}

// FailureHook always fail
type FailureHook struct{}

func (dh FailureHook) PostTxProcessing(ctx sdk.Context, from common.Address, to *common.Address, receipt *ethtypes.Receipt) error {
func (dh FailureHook) PostTxProcessing(ctx sdk.Context, msg ethtypes.Message, receipt *ethtypes.Receipt) error {
return errors.New("post tx processing failed")
}

Expand Down Expand Up @@ -81,7 +81,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
TxHash: txHash,
Logs: logs,
}
result := k.PostTxProcessing(ctx, common.Address{}, nil, receipt)
result := k.PostTxProcessing(ctx, ethtypes.Message{}, receipt)

tc.expFunc(hook, result)
}
Expand Down
4 changes: 2 additions & 2 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ func (k *Keeper) SetHooks(eh types.EvmHooks) *Keeper {
}

// PostTxProcessing delegate the call to the hooks. If no hook has been registered, this function returns with a `nil` error
func (k *Keeper) PostTxProcessing(ctx sdk.Context, from common.Address, to *common.Address, receipt *ethtypes.Receipt) error {
func (k *Keeper) PostTxProcessing(ctx sdk.Context, msg ethtypes.Message, receipt *ethtypes.Receipt) error {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
if k.hooks == nil {
return nil
}
return k.hooks.PostTxProcessing(ctx, from, to, receipt)
return k.hooks.PostTxProcessing(ctx, msg, receipt)
}

// Tracer return a default vm.Tracer based on current keeper state
Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t
}

// Only call hooks if tx executed successfully.
if err = k.PostTxProcessing(tmpCtx, msg.From(), tx.To(), receipt); err != nil {
if err = k.PostTxProcessing(tmpCtx, msg, receipt); err != nil {
// If hooks return error, revert the whole tx.
res.VmError = types.ErrPostTxProcessing.Error()
k.Logger(ctx).Error("tx post processing failed", "error", err)
Expand Down
3 changes: 1 addition & 2 deletions x/evm/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/common"

ethtypes "github.com/ethereum/go-ethereum/core/types"
feemarkettypes "github.com/tharsis/ethermint/x/feemarket/types"
Expand Down Expand Up @@ -53,5 +52,5 @@ type FeeMarketKeeper interface {
// EvmHooks event hooks for evm tx processing
type EvmHooks interface {
// Must be called after tx is processed successfully, if return an error, the whole transaction is reverted.
PostTxProcessing(ctx sdk.Context, from common.Address, to *common.Address, receipt *ethtypes.Receipt) error
PostTxProcessing(ctx sdk.Context, msg ethtypes.Message, receipt *ethtypes.Receipt) error
}