Skip to content

feat: support tx replacement #1840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -13,6 +13,7 @@
* [#1824](https://github.com/crypto-org-chain/cronos/pull/1824) Rework on github actions.
* [#1826](https://github.com/crypto-org-chain/cronos/pull/1826) Update linter and tidy up code.
* [#1807](https://github.com/crypto-org-chain/cronos/pull/1807) Update go-ethereum version to [v1.15.11](https://github.com/ethereum/go-ethereum/releases/tag/v1.15.11).
* [#1840](https://github.com/crypto-org-chain/cronos/pull/1840) Tx replacement support.

*Jun 20, 2025*

Expand Down
7 changes: 6 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import (
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
ethparams "github.com/ethereum/go-ethereum/params"
"github.com/evmos/ethermint/ante/cache"
evmenc "github.com/evmos/ethermint/encoding"
"github.com/evmos/ethermint/ethereum/eip712"
evmapp "github.com/evmos/ethermint/evmd"
Expand Down Expand Up @@ -379,12 +380,14 @@ func New(
if maxTxs := cast.ToInt(appOpts.Get(server.FlagMempoolMaxTxs)); maxTxs >= 0 {
// NOTE we use custom transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx
// Setup Mempool and Proposal Handlers
logger.Info("NewPriorityMempool is enabled")
mpool = mempool.NewPriorityMempool(mempool.PriorityNonceMempoolConfig[int64]{
TxPriority: mempool.NewDefaultTxPriority(),
SignerExtractor: evmapp.NewEthSignerExtractionAdapter(mempool.NewDefaultSignerExtractionAdapter()),
MaxTx: maxTxs,
})
} else {
logger.Info("NoOpMempool is enabled")
mpool = mempool.NoOpMempool{}
}
blockProposalHandler := NewProposalHandler(txDecoder, identity, addressCodec)
Expand Down Expand Up @@ -962,6 +965,7 @@ func New(
app.SetEndBlocker(app.EndBlocker)
if err := app.setAnteHandler(txConfig,
cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)),
cast.ToInt(appOpts.Get(server.FlagMempoolMaxTxs)),
cast.ToStringSlice(appOpts.Get(FlagBlockedAddresses)),
); err != nil {
panic(err)
Expand Down Expand Up @@ -1036,7 +1040,7 @@ func New(
}

// use Ethermint's custom AnteHandler
func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64, blacklist []string) error {
func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64, mempoolMaxTxs int, blacklist []string) error {
if len(blacklist) > 0 {
sort.Strings(blacklist)
// hash blacklist concatenated
Expand Down Expand Up @@ -1084,6 +1088,7 @@ func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64, bl
},
ExtraDecorators: []sdk.AnteDecorator{blockAddressDecorator},
PendingTxListener: app.onPendingTx,
AnteCache: cache.NewAnteCache(mempoolMaxTxs),
}

anteHandler, err := evmante.NewAnteHandler(options)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ replace (
// release/v1.15
github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20250812022812-0af6c9899f11
// develop
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20250812033036-79e177241f87
github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20250812061456-67a47478d691
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,8 @@ github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20241217090828-cfbca9fe8254/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM=
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241217090828-cfbca9fe8254 h1:JzLOFRiKsDtLJt5h0M0jkEIPDKvFFyja7VEp7gG6O9U=
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20241217090828-cfbca9fe8254/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w=
github.com/crypto-org-chain/ethermint v0.6.1-0.20250812033036-79e177241f87 h1:HsIhQ7bO7cRnD7BnKPtDpXVBbbD3wU5GdkZDN9qWZeA=
github.com/crypto-org-chain/ethermint v0.6.1-0.20250812033036-79e177241f87/go.mod h1:ZVpL8Targ0Iu5arWFTeyyc6LZiclhaZJZhqu0jPQWDo=
github.com/crypto-org-chain/ethermint v0.6.1-0.20250812061456-67a47478d691 h1:x4EA2lt2KMfkDnw8SI3dpbGUdQuooFAIWNSGBjpX2Hg=
github.com/crypto-org-chain/ethermint v0.6.1-0.20250812061456-67a47478d691/go.mod h1:ZVpL8Targ0Iu5arWFTeyyc6LZiclhaZJZhqu0jPQWDo=
github.com/crypto-org-chain/go-block-stm v0.0.0-20241213061541-7afe924fb4a6 h1:6KPEi8dWkDSBddQb4NAvEXmNnTXymF3yVeTaT4Hz1iU=
github.com/crypto-org-chain/go-block-stm v0.0.0-20241213061541-7afe924fb4a6/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE=
github.com/crypto-org-chain/go-ethereum v1.10.20-0.20250812022812-0af6c9899f11 h1:PxE460wd3qG+nkuy+W90gZO06PumOPaPbXeKOAMxBp8=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ schema = 3
version = "v0.2.2"
hash = "sha256-0MLfSJKdeK3Z7tWAXTdzwB4091dmyxIX38S5SKH5QAw="
[mod."github.com/evmos/ethermint"]
version = "v0.6.1-0.20250812033036-79e177241f87"
hash = "sha256-9qik8unxBcJ7u71770JL+zNbMGdQSCnUsJUXLiX+jpA="
version = "v0.6.1-0.20250812061456-67a47478d691"
hash = "sha256-oaDYuJXlt6N8YSH8Eciv/lQCJVMIO4BDREhrkGWqcDc="
replaced = "github.com/crypto-org-chain/ethermint"
[mod."github.com/fatih/color"]
version = "v1.17.0"
Expand Down
46 changes: 46 additions & 0 deletions integration_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
contract_path,
deploy_contract,
derive_new_account,
get_account_nonce,
get_expedited_params,
get_receipts_by_block,
get_sync_info,
modify_command_in_supervisor_config,
replace_transaction,
send_transaction,
send_txs,
sign_transaction,
Expand Down Expand Up @@ -1028,3 +1030,47 @@ def test_textual(cronos):
sign_mode="textual",
)
assert rsp["code"] == 0, rsp["raw_log"]


def test_tx_replacement(cronos):
w3 = cronos.w3
gas_price = w3.eth.gas_price
nonce = get_account_nonce(w3)
initial_balance = w3.eth.get_balance(ADDRS["community"])
txhash = replace_transaction(
w3,
{
"to": ADDRS["community"],
"value": 1,
"gasPrice": gas_price,
"nonce": nonce,
"from": ADDRS["validator"],
},
{
"to": ADDRS["community"],
"value": 5,
"gasPrice": gas_price * 2,
"nonce": nonce,
"from": ADDRS["validator"],
},
KEYS["validator"],
)["transactionHash"]
tx1 = w3.eth.get_transaction(txhash)
assert tx1["transactionIndex"] == 0
assert w3.eth.get_balance(ADDRS["community"]) == initial_balance + 5

# check that already accepted transaction cannot be replaced
txhash_noreplacemenet = send_transaction(
w3,
{"to": ADDRS["community"], "value": 10, "gasPrice": gas_price},
KEYS["validator"],
)["transactionHash"]
tx2 = w3.eth.get_transaction(txhash_noreplacemenet)
assert tx2["transactionIndex"] == 0

with pytest.raises(ValueError) as exc:
w3.eth.replace_transaction(
txhash_noreplacemenet,
{"to": ADDRS["community"], "value": 15, "gasPrice": gas_price},
)
assert "has already been mined" in str(exc)
12 changes: 12 additions & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,24 @@ def sign_transaction(w3, tx, key=KEYS["validator"]):
return acct.sign_transaction(tx)


def get_account_nonce(w3, key=KEYS["validator"]):
acct = Account.from_key(key)
return w3.eth.get_transaction_count(acct.address)


def send_transaction(w3, tx, key=KEYS["validator"]):
signed = sign_transaction(w3, tx, key)
txhash = w3.eth.send_raw_transaction(signed.rawTransaction)
return w3.eth.wait_for_transaction_receipt(txhash)


def replace_transaction(w3, old_tx, new_tx, key=KEYS["validator"]):
signed = sign_transaction(w3, old_tx, key)
old_tx_hash = w3.eth.send_raw_transaction(signed.rawTransaction)
new_txhash = w3.eth.replace_transaction(old_tx_hash, new_tx)
return w3.eth.wait_for_transaction_receipt(new_txhash)


def cronos_address_from_mnemonics(mnemonics, prefix=CRONOS_ADDRESS_PREFIX):
"return cronos address from mnemonics"
acct = Account.from_mnemonic(mnemonics)
Expand Down
3 changes: 2 additions & 1 deletion nix/testground-cronosd.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ index 678ccc0a..ba64a7fe 100644
ExtraDecorators: []sdk.AnteDecorator{blockAddressDecorator},
PendingTxListener: app.onPendingTx,
+ UnsafeUnorderedTx: true,
}
AnteCache: cache.NewAnteCache(mempoolMaxTxs),
}

anteHandler, err := evmante.NewAnteHandler(options)
Loading