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

* x/evm - PostTxProcessing use message as callback input

* Update CHANGELOG.md

* Use core.Message for the PostTxProcessing hook (PR review)
This commit is contained in:
Loredana Cirstea
2022-04-04 20:11:46 +02:00
committed by GitHub
parent 6abe84bde7
commit cc37ed283a
7 changed files with 16 additions and 13 deletions
+3 -3
View File
@@ -3,7 +3,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/tharsis/ethermint/x/evm/types"
)
@@ -19,9 +19,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 core.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])
}
}
+4 -3
View File
@@ -6,6 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/tharsis/ethermint/x/evm/keeper"
@@ -18,7 +19,7 @@ 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 core.Message, receipt *ethtypes.Receipt) error {
dh.Logs = receipt.Logs
return nil
}
@@ -26,7 +27,7 @@ func (dh *LogRecordHook) PostTxProcessing(ctx sdk.Context, from common.Address,
// 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 core.Message, receipt *ethtypes.Receipt) error {
return errors.New("post tx processing failed")
}
@@ -81,7 +82,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)
}
+2 -2
View File
@@ -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 core.Message, receipt *ethtypes.Receipt) error {
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
+1 -1
View File
@@ -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)