From 91936e4179b655c6f6de41dd03c9c6a0abcb3437 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 7 Jun 2024 09:33:12 +0800 Subject: [PATCH] Problem: pending tx comes after get mined (#1466) --- CHANGELOG.md | 1 + app/app.go | 17 +++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- gomod2nix.toml | 4 ++-- integration_tests/test_mempool.py | 9 +++------ 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5031ca91e0..16f380a8a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ ### Bug Fixes * (rpc) [#1397](https://github.com/crypto-org-chain/cronos/pull/1397) Avoid panic on invalid elasticity_multiplier. +* (rpc) [#1466](https://github.com/crypto-org-chain/cronos/pull/1466) Fix handling of pending transactions related APIs. ### Features diff --git a/app/app.go b/app/app.go index 41448657c1..87b5c0444b 100644 --- a/app/app.go +++ b/app/app.go @@ -288,6 +288,8 @@ type App struct { invCheckPeriod uint + pendingTxListeners []evmapp.PendingTxListener + // keys to access the substores keys map[string]*storetypes.KVStoreKey tkeys map[string]*storetypes.TransientStoreKey @@ -1281,6 +1283,21 @@ func (app *App) AutoCliOpts() autocli.AppOptions { } } +// RegisterPendingTxListener is used by json-rpc server to listen to pending transactions in CheckTx. +func (app *App) RegisterPendingTxListener(listener evmapp.PendingTxListener) { + app.pendingTxListeners = append(app.pendingTxListeners, listener) +} + +func (app *App) CheckTx(req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) { + res, err := app.BaseApp.CheckTx(req) + if err == nil && res.Code == 0 && req.Type == abci.CheckTxType_New { + for _, listener := range app.pendingTxListeners { + listener(req.Tx) + } + } + return res, err +} + // RegisterSwaggerAPI registers swagger route with API Server func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) { root, err := fs.Sub(docs.SwaggerUI, "swagger-ui") diff --git a/go.mod b/go.mod index 28690775c9..914a57a6eb 100644 --- a/go.mod +++ b/go.mod @@ -276,7 +276,7 @@ replace ( github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7 // block-stm branch - github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240502052908-179e436703b3 + github.com/evmos/ethermint => github.com/crypto-org-chain/ethermint v0.6.1-0.20240606130330-6f4031d89f50 // 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 diff --git a/go.sum b/go.sum index d4df6e3a27..bea5a83124 100644 --- a/go.sum +++ b/go.sum @@ -430,8 +430,8 @@ github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240415105151-0108877a3201 github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240415105151-0108877a3201/go.mod h1:lfuLI1f4o+0SGtlHQS4x5qsjRcZZfYqG8bp3k8hM0M8= github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240415105151-0108877a3201 h1:DbCOM19ywdL5K+bOy4h+0MppzcPgI2guHnYCfDNnAcM= github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240415105151-0108877a3201/go.mod h1:CBCU6fsRVz23QGFIQBb1DNX2DztJCf3jWyEkHY2nJQ0= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240502052908-179e436703b3 h1:YYmMJowZyiyioNHYnps5hw3XkV1zcXSC3jy/xzqK2Rg= -github.com/crypto-org-chain/ethermint v0.6.1-0.20240502052908-179e436703b3/go.mod h1:9MVSajfKloRP8h2chP78LhCKx5u9O2pCMBvxrmx6+0s= +github.com/crypto-org-chain/ethermint v0.6.1-0.20240606130330-6f4031d89f50 h1:nrX9G2ETZ0/010sDdduLKd1T2ZxnkfzT70/mRn56Gu0= +github.com/crypto-org-chain/ethermint v0.6.1-0.20240606130330-6f4031d89f50/go.mod h1:9MVSajfKloRP8h2chP78LhCKx5u9O2pCMBvxrmx6+0s= github.com/crypto-org-chain/go-block-stm v0.0.0-20240408011717-9f11af197bde h1:sQIHTJfVt5VTrF7po9eZiFkZiPjlHbFvnXtGCOoBjNM= github.com/crypto-org-chain/go-block-stm v0.0.0-20240408011717-9f11af197bde/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE= github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7 h1:V43F3JFcqG4MUThf9W/DytnPblpR6CcaLBw2Wx6zTgE= diff --git a/gomod2nix.toml b/gomod2nix.toml index 11b79f9ba6..e8c4b52c62 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -262,8 +262,8 @@ schema = 3 hash = "sha256-lE4G5FaRb3MVi9FFVn+WlwsSTOB4SbjmVboKyQ5yB0A=" replaced = "github.com/crypto-org-chain/go-ethereum" [mod."github.com/evmos/ethermint"] - version = "v0.6.1-0.20240502052908-179e436703b3" - hash = "sha256-Qc5A89wi+KCKfFdyvZit5MI4yKDhDvvSjkiYL0EIzNA=" + version = "v0.6.1-0.20240606130330-6f4031d89f50" + hash = "sha256-9AX6l+4AZNWaz4BAUXVCPxFJW3wTdhW3ZyIV38uGXNQ=" replaced = "github.com/crypto-org-chain/ethermint" [mod."github.com/fatih/color"] version = "v1.16.0" diff --git a/integration_tests/test_mempool.py b/integration_tests/test_mempool.py index b565edf1a0..bdd921cab1 100644 --- a/integration_tests/test_mempool.py +++ b/integration_tests/test_mempool.py @@ -61,7 +61,7 @@ def test_mempool(cronos_mempool): print(f"all send tx hash: {sended_hash_set} at {block_num_0}") all_pending = w3.eth.get_filter_changes(filter.filter_id) - assert len(all_pending) == 0 + assert len(all_pending) == 4 block_num_1 = w3.eth.get_block_number() print(f"block_num_1 {block_num_1}") @@ -69,13 +69,10 @@ def test_mempool(cronos_mempool): # check after max 10 blocks for i in range(10): all_pending = w3.eth.get_filter_changes(filter.filter_id) - print(f"all pending tx hash at block {i+block_num_1}: {all_pending}") - for h in all_pending: - sended_hash_set.discard(h) - if len(sended_hash_set) == 0: + if len(all_pending) == 0: break wait_for_new_blocks(cli, 1, sleep=0.1) - assert len(sended_hash_set) == 0 + assert len(all_pending) == 0 def test_blocked_address(cronos_mempool):