Skip to content
Merged
11 changes: 11 additions & 0 deletions mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"sync"

"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/holiman/uint256"

Expand Down Expand Up @@ -424,6 +425,16 @@ func (m *ExperimentalEVMMempool) HasEventBus() bool {
return m.eventBus != nil
}

// Has returns true if the transaction with the given hash is already in the mempool.
// This checks tx pool for EVM transactions, which iterates through all pools (currently only legacypool)
func (m *ExperimentalEVMMempool) Has(hash common.Hash) bool {
m.mtx.Lock()
defer m.mtx.Unlock()

// Check the tx pool
return m.txPool.Has(hash)
}

// Close unsubscribes from the CometBFT event bus and shuts down the mempool.
func (m *ExperimentalEVMMempool) Close() error {
var errs []error
Expand Down
7 changes: 7 additions & 0 deletions rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"google.golang.org/grpc/status"

"github.com/cosmos/evm/mempool"
"github.com/cosmos/evm/mempool/txpool"
rpctypes "github.com/cosmos/evm/rpc/types"
evmtypes "github.com/cosmos/evm/x/vm/types"

Expand Down Expand Up @@ -148,6 +149,12 @@ func (b *Backend) SendRawTransaction(data hexutil.Bytes) (common.Hash, error) {

txHash := ethereumTx.AsTransaction().Hash()

// Check if transaction is already in the mempool before broadcasting
// This is important for user-submitted transactions via JSON-RPC to provide proper error feedback
if b.Mempool != nil && b.Mempool.Has(txHash) {
return txHash, txpool.ErrAlreadyKnown
}

syncCtx := b.ClientCtx.WithBroadcastMode(flags.BroadcastSync)
rsp, err := syncCtx.BroadcastTx(txBytes)
if rsp != nil && rsp.Code != 0 {
Expand Down
20 changes: 10 additions & 10 deletions tests/systemtests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
package systemtests

import (
"testing"

"github.com/cosmos/evm/tests/systemtests/accountabstraction"
"github.com/cosmos/evm/tests/systemtests/chainupgrade"
"github.com/cosmos/evm/tests/systemtests/eip712"
"testing"

"github.com/cosmos/evm/tests/systemtests/mempool"
"github.com/cosmos/evm/tests/systemtests/suite"

Expand All @@ -19,7 +19,7 @@ func TestMain(m *testing.M) {
}

/*
* Mempool Tests
* Mempool Tests
*/
func TestMempoolTxsOrdering(t *testing.T) {
suite.RunWithSharedSuite(t, mempool.RunTxsOrdering)
Expand All @@ -41,8 +41,8 @@ func TestMempoolMixedTxsReplacementLegacyAndDynamicFee(t *testing.T) {
suite.RunWithSharedSuite(t, mempool.RunMixedTxsReplacementLegacyAndDynamicFee)
}

func TestMempoolTxRebroadcasting(t *testing.T) {
suite.RunWithSharedSuite(t, mempool.RunTxRebroadcasting)
func TestMempoolTxBroadcasting(t *testing.T) {
suite.RunWithSharedSuite(t, mempool.RunTxBroadcasting)
}

func TestMinimumGasPricesZero(t *testing.T) {
Expand All @@ -53,9 +53,9 @@ func TestMempoolCosmosTxsCompatibility(t *testing.T) {
suite.RunWithSharedSuite(t, mempool.RunCosmosTxsCompatibility)
}

/*
* EIP-712 Tests
*/
// /*
// * EIP-712 Tests
// */
func TestEIP712BankSend(t *testing.T) {
suite.RunWithSharedSuite(t, eip712.RunEIP712BankSend)
}
Expand All @@ -69,14 +69,14 @@ func TestEIP712MultipleBankSends(t *testing.T) {
}

/*
* Account Abstraction Tests
* Account Abstraction Tests
*/
func TestAccountAbstractionEIP7702(t *testing.T) {
suite.RunWithSharedSuite(t, accountabstraction.RunEIP7702)
}

/*
* Chain Upgrade Tests
* Chain Upgrade Tests
*/
func TestChainUpgrade(t *testing.T) {
suite.RunWithSharedSuite(t, chainupgrade.RunChainUpgrade)
Expand Down
Loading
Loading