From f04c02a4904efa594be46d65a82f7a688b1901a0 Mon Sep 17 00:00:00 2001 From: Thomas Nguy Date: Fri, 1 Apr 2022 18:52:10 +0900 Subject: [PATCH 1/2] add log after tx post processing hook add changelog fix tests rename variable minimum change version --- CHANGELOG.md | 4 +++ x/evm/keeper/state_transition.go | 55 ++++++++++++++++---------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef63ba0da1..de73eae5f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (feemarket) [tharsis#1021](https://github.com/tharsis/ethermint/pull/1021) Fix fee market migration. +### Improvements + +* (evm) [tharsis#1025](https://github.com/tharsis/ethermint/pull/1025) Allow to append logs after a post processing hook. + ## [v0.12.1] - 2022-03-29 ### Bug Fixes diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index 310bd33659..fdefe2bd44 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -235,34 +235,34 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t bloomReceipt = ethtypes.BytesToBloom(bloom.Bytes()) } - if !res.Failed() { - cumulativeGasUsed := res.GasUsed - if ctx.BlockGasMeter() != nil { - limit := ctx.BlockGasMeter().Limit() - consumed := ctx.BlockGasMeter().GasConsumed() - cumulativeGasUsed = uint64(math.Min(float64(cumulativeGasUsed+consumed), float64(limit))) - } + cumulativeGasUsed := res.GasUsed + if ctx.BlockGasMeter() != nil { + limit := ctx.BlockGasMeter().Limit() + consumed := ctx.BlockGasMeter().GasConsumed() + cumulativeGasUsed = uint64(math.Min(float64(cumulativeGasUsed+consumed), float64(limit))) + } - var contractAddr common.Address - if msg.To() == nil { - contractAddr = crypto.CreateAddress(msg.From(), msg.Nonce()) - } + var contractAddr common.Address + if msg.To() == nil { + contractAddr = crypto.CreateAddress(msg.From(), msg.Nonce()) + } - receipt := ðtypes.Receipt{ - Type: tx.Type(), - PostState: nil, // TODO: intermediate state root - Status: ethtypes.ReceiptStatusSuccessful, - CumulativeGasUsed: cumulativeGasUsed, - Bloom: bloomReceipt, - Logs: logs, - TxHash: txConfig.TxHash, - ContractAddress: contractAddr, - GasUsed: res.GasUsed, - BlockHash: txConfig.BlockHash, - BlockNumber: big.NewInt(ctx.BlockHeight()), - TransactionIndex: txConfig.TxIndex, - } + receipt := ðtypes.Receipt{ + Type: tx.Type(), + PostState: nil, // TODO: intermediate state root + CumulativeGasUsed: cumulativeGasUsed, + Bloom: bloomReceipt, + Logs: logs, + TxHash: txConfig.TxHash, + ContractAddress: contractAddr, + GasUsed: res.GasUsed, + BlockHash: txConfig.BlockHash, + BlockNumber: big.NewInt(ctx.BlockHeight()), + TransactionIndex: txConfig.TxIndex, + } + if !res.Failed() { + receipt.Status = ethtypes.ReceiptStatusSuccessful // Only call hooks if tx executed successfully. if err = k.PostTxProcessing(tmpCtx, msg, receipt); err != nil { // If hooks return error, revert the whole tx. @@ -282,9 +282,8 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t if len(logs) > 0 { // Update transient block bloom filter - k.SetBlockBloomTransient(ctx, bloom) - - k.SetLogSizeTransient(ctx, uint64(txConfig.LogIndex)+uint64(len(logs))) + k.SetBlockBloomTransient(ctx, receipt.Bloom.Big()) + k.SetLogSizeTransient(ctx, uint64(txConfig.LogIndex)+uint64(len(receipt.Logs))) } k.SetTxIndexTransient(ctx, uint64(txConfig.TxIndex)+1) From 8d751c6b63d6f0df05f7468a2ea883af7b70a961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Tue, 5 Apr 2022 10:25:41 +0200 Subject: [PATCH 2/2] Update x/evm/keeper/state_transition.go --- x/evm/keeper/state_transition.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index fdefe2bd44..8e610a1611 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -280,7 +280,7 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, tx *ethtypes.Transaction) (*t return nil, sdkerrors.Wrapf(err, "failed to refund gas leftover gas to sender %s", msg.From()) } - if len(logs) > 0 { + if len(receipt.Logs) > 0 { // Update transient block bloom filter k.SetBlockBloomTransient(ctx, receipt.Bloom.Big()) k.SetLogSizeTransient(ctx, uint64(txConfig.LogIndex)+uint64(len(receipt.Logs)))