Skip to content

Commit

Permalink
Merge branch 'main' into query-smart-cached-ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
jewei1997 committed Oct 30, 2024
2 parents 0b3d994 + 97346a2 commit 42e7f71
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.
return
}
logs := []*ethtypes.Log{}
// Note: txs with a very large number of WASM events may run out of gas due to
// additional gas consumption from EVM receipt generation and event translation
wasmToEvmEventGasLimit := app.EvmKeeper.GetDeliverTxHookWasmGasLimit(ctx.WithGasMeter(sdk.NewInfiniteGasMeter(1, 1)))
wasmToEvmEventCtx := ctx.WithGasMeter(sdk.NewGasMeterWithMultiplier(ctx, wasmToEvmEventGasLimit))
for _, wasmEvent := range wasmEvents {
contractAddr, found := GetAttributeValue(wasmEvent, wasmtypes.AttributeKeyContractAddr)
if !found {
continue
}
// check if there is a ERC20 pointer to contractAddr
pointerAddr, _, exists := app.EvmKeeper.GetERC20CW20Pointer(wasmToEvmEventCtx, contractAddr)
if exists {
log, eligible := app.translateCW20Event(wasmToEvmEventCtx, wasmEvent, pointerAddr, contractAddr)
Expand Down
5 changes: 3 additions & 2 deletions x/evm/keeper/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/iavl"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -91,12 +92,12 @@ func (k *Keeper) MockReceipt(ctx sdk.Context, txHash common.Hash, receipt *types
}

func (k *Keeper) FlushTransientReceipts(ctx sdk.Context) error {
iter := ctx.TransientStore(k.transientStoreKey).Iterator(nil, nil)
iter := prefix.NewStore(ctx.TransientStore(k.transientStoreKey), types.ReceiptKeyPrefix).Iterator(nil, nil)
defer iter.Close()
var pairs []*iavl.KVPair
var changesets []*proto.NamedChangeSet
for ; iter.Valid(); iter.Next() {
kvPair := &iavl.KVPair{Key: iter.Key(), Value: iter.Value()}
kvPair := &iavl.KVPair{Key: types.ReceiptKey(common.Hash(iter.Key())), Value: iter.Value()}
pairs = append(pairs, kvPair)
}
if len(pairs) == 0 {
Expand Down
5 changes: 5 additions & 0 deletions x/evm/keeper/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package keeper_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/stretchr/testify/require"
Expand All @@ -16,7 +18,10 @@ func TestReceipt(t *testing.T) {
_, err := k.GetReceipt(ctx, txHash)
require.NotNil(t, err)
k.MockReceipt(ctx, txHash, &types.Receipt{TxHashHex: txHash.Hex()})
k.AppendToEvmTxDeferredInfo(ctx, ethtypes.Bloom{}, common.Hash{1}, sdk.NewInt(1)) // make sure this isn't flushed into receipt store
r, err := k.GetReceipt(ctx, txHash)
require.Nil(t, err)
require.Equal(t, txHash.Hex(), r.TxHashHex)
_, err = k.GetReceipt(ctx, common.Hash{1})
require.Equal(t, "not found", err.Error())
}

0 comments on commit 42e7f71

Please sign in to comment.