Skip to content

Commit 2df2e49

Browse files
almk-devAlex | Interchain Labs
authored andcommitted
feature: Add txpool namespace stubs ahead of app-side mempool implementation (#344)
* add txpool implementation stubs * update interface * fix lint --------- Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
1 parent 73eaaf1 commit 2df2e49

File tree

21 files changed

+105
-53
lines changed

21 files changed

+105
-53
lines changed

evmd/eips/eips_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"github.com/ethereum/go-ethereum/common"
99
"github.com/ethereum/go-ethereum/params"
1010

11-
//nolint:revive,ST1001 // dot imports are fine for Ginkgo
11+
//nolint:revive // dot imports are fine for Ginkgo
1212
. "github.com/onsi/ginkgo/v2"
13-
//nolint:revive,ST1001 // dot imports are fine for Ginkgo
13+
//nolint:revive // dot imports are fine for Ginkgo
1414
. "github.com/onsi/gomega"
1515

1616
"github.com/cosmos/evm/evmd/eips/testdata"

evmd/tests/ledger/evmosd_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
"github.com/spf13/cobra"
1313
"github.com/stretchr/testify/suite"
1414

15-
//nolint:revive,ST1001 // dot imports are fine for Ginkgo
15+
//nolint:revive // dot imports are fine for Ginkgo
1616
. "github.com/onsi/ginkgo/v2"
17-
//nolint:revive,ST1001 // dot imports are fine for Ginkgo
17+
//nolint:revive // dot imports are fine for Ginkgo
1818
. "github.com/onsi/gomega"
1919

2020
"github.com/cometbft/cometbft/crypto/tmhash"

evmd/tests/ledger/ledger_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/spf13/cobra"
88

9-
//nolint:revive,ST1001 // dot imports are fine for Ginkgo
9+
//nolint:revive // dot imports are fine for Ginkgo
1010
. "github.com/onsi/ginkgo/v2"
1111

1212
"github.com/cosmos/evm/crypto/hd"

rpc/apis.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,18 @@ func init() {
113113
},
114114
}
115115
},
116-
TxPoolNamespace: func(ctx *server.Context, _ client.Context, _ *rpcclient.WSClient, _ bool, _ types.EVMTxIndexer) []rpc.API {
116+
TxPoolNamespace: func(ctx *server.Context,
117+
clientCtx client.Context,
118+
_ *rpcclient.WSClient,
119+
allowUnprotectedTxs bool,
120+
indexer types.EVMTxIndexer,
121+
) []rpc.API {
122+
evmBackend := backend.NewBackend(ctx, ctx.Logger, clientCtx, allowUnprotectedTxs, indexer)
117123
return []rpc.API{
118124
{
119125
Namespace: TxPoolNamespace,
120126
Version: apiVersion,
121-
Service: txpool.NewPublicAPI(ctx.Logger),
127+
Service: txpool.NewPublicAPI(ctx.Logger, evmBackend),
122128
Public: true,
123129
},
124130
}

rpc/backend/backend.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ type EVMBackend interface {
118118
GetLogsByHeight(height *int64) ([][]*ethtypes.Log, error)
119119
BloomStatus() (uint64, uint64)
120120

121+
// TxPool API
122+
Content() (map[string]map[string]map[string]*rpctypes.RPCTransaction, error)
123+
ContentFrom(address common.Address) (map[string]map[string]map[string]*rpctypes.RPCTransaction, error)
124+
Inspect() (map[string]map[string]map[string]string, error)
125+
Status() (map[string]hexutil.Uint, error)
126+
121127
// Tracing
122128
TraceTransaction(hash common.Hash, config *evmtypes.TraceConfig) (interface{}, error)
123129
TraceBlock(height rpctypes.BlockNumber, config *evmtypes.TraceConfig, block *tmrpctypes.ResultBlock) ([]*evmtypes.TxTraceResult, error)

rpc/backend/tx_pool.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package backend
2+
3+
import (
4+
"github.com/ethereum/go-ethereum/common"
5+
"github.com/ethereum/go-ethereum/common/hexutil"
6+
7+
"github.com/cosmos/evm/rpc/types"
8+
)
9+
10+
// Content returns the transactions contained within the transaction pool
11+
func (b *Backend) Content() (map[string]map[string]map[string]*types.RPCTransaction, error) {
12+
content := map[string]map[string]map[string]*types.RPCTransaction{
13+
"pending": make(map[string]map[string]*types.RPCTransaction),
14+
"queued": make(map[string]map[string]*types.RPCTransaction),
15+
}
16+
return content, nil
17+
}
18+
19+
// ContentFrom returns the transactions contained within the transaction pool
20+
func (b *Backend) ContentFrom(_ common.Address) (map[string]map[string]map[string]*types.RPCTransaction, error) {
21+
content := map[string]map[string]map[string]*types.RPCTransaction{
22+
"pending": make(map[string]map[string]*types.RPCTransaction),
23+
"queued": make(map[string]map[string]*types.RPCTransaction),
24+
}
25+
return content, nil
26+
}
27+
28+
// Inspect returns the content of the transaction pool and flattens it into an easily inspectable list.
29+
func (b *Backend) Inspect() (map[string]map[string]map[string]string, error) {
30+
inspect := map[string]map[string]map[string]string{
31+
"pending": make(map[string]map[string]string),
32+
"queued": make(map[string]map[string]string),
33+
}
34+
return inspect, nil
35+
}
36+
37+
// Status returns the number of pending and queued transaction in the pool.
38+
func (b *Backend) Status() (map[string]hexutil.Uint, error) {
39+
return map[string]hexutil.Uint{
40+
"pending": hexutil.Uint(0),
41+
"queued": hexutil.Uint(0),
42+
}, nil
43+
}

rpc/namespaces/ethereum/debug/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (a *API) BlockProfile(file string, nsec uint) error {
113113

114114
// CpuProfile turns on CPU profiling for nsec seconds and writes
115115
// profile data to file.
116-
func (a *API) CpuProfile(file string, nsec uint) error { //nolint: golint, revive
116+
func (a *API) CpuProfile(file string, nsec uint) error { //nolint: revive
117117
a.logger.Debug("debug_cpuProfile", "file", file, "nsec", nsec)
118118
if err := a.StartCPUProfile(file); err != nil {
119119
return err

rpc/namespaces/ethereum/eth/api.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,13 @@ var _ EthereumAPI = (*PublicAPI)(nil)
114114

115115
// PublicAPI is the eth_ prefixed set of APIs in the Web3 JSON-RPC spec.
116116
type PublicAPI struct {
117-
ctx context.Context
118117
logger log.Logger
119118
backend backend.EVMBackend
120119
}
121120

122121
// NewPublicAPI creates an instance of the public ETH Web3 API.
123122
func NewPublicAPI(logger log.Logger, backend backend.EVMBackend) *PublicAPI {
124123
api := &PublicAPI{
125-
ctx: context.Background(),
126124
logger: logger.With("client", "json-rpc"),
127125
backend: backend,
128126
}
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package txpool
22

33
import (
4+
"github.com/ethereum/go-ethereum/common"
45
"github.com/ethereum/go-ethereum/common/hexutil"
56

7+
"github.com/cosmos/evm/rpc/backend"
68
"github.com/cosmos/evm/rpc/types"
79

810
"cosmossdk.io/log"
@@ -11,41 +13,38 @@ import (
1113
// PublicAPI offers and API for the transaction pool. It only operates on data that is non-confidential.
1214
// NOTE: For more info about the current status of this endpoints see https://github.com/evmos/ethermint/issues/124
1315
type PublicAPI struct {
14-
logger log.Logger
16+
logger log.Logger
17+
backend backend.EVMBackend
1518
}
1619

1720
// NewPublicAPI creates a new tx pool service that gives information about the transaction pool.
18-
func NewPublicAPI(logger log.Logger) *PublicAPI {
21+
func NewPublicAPI(logger log.Logger, backend backend.EVMBackend) *PublicAPI {
1922
return &PublicAPI{
20-
logger: logger.With("module", "txpool"),
23+
logger: logger.With("module", "txpool"),
24+
backend: backend,
2125
}
2226
}
2327

2428
// Content returns the transactions contained within the transaction pool
2529
func (api *PublicAPI) Content() (map[string]map[string]map[string]*types.RPCTransaction, error) {
2630
api.logger.Debug("txpool_content")
27-
content := map[string]map[string]map[string]*types.RPCTransaction{
28-
"pending": make(map[string]map[string]*types.RPCTransaction),
29-
"queued": make(map[string]map[string]*types.RPCTransaction),
30-
}
31-
return content, nil
31+
return api.backend.Content()
32+
}
33+
34+
// ContentFrom returns the transactions contained within the transaction pool
35+
func (api *PublicAPI) ContentFrom(address common.Address) (map[string]map[string]map[string]*types.RPCTransaction, error) {
36+
api.logger.Debug("txpool_contentFrom")
37+
return api.backend.ContentFrom(address)
3238
}
3339

34-
// Inspect returns the content of the transaction pool and flattens it into an
40+
// Inspect returns the content of the transaction pool and flattens it into an easily inspectable list
3541
func (api *PublicAPI) Inspect() (map[string]map[string]map[string]string, error) {
3642
api.logger.Debug("txpool_inspect")
37-
content := map[string]map[string]map[string]string{
38-
"pending": make(map[string]map[string]string),
39-
"queued": make(map[string]map[string]string),
40-
}
41-
return content, nil
43+
return api.backend.Inspect()
4244
}
4345

44-
// Status returns the number of pending and queued transaction in the pool.
45-
func (api *PublicAPI) Status() map[string]hexutil.Uint {
46+
// Status returns the number of pending and queued transaction in the pool
47+
func (api *PublicAPI) Status() (map[string]hexutil.Uint, error) {
4648
api.logger.Debug("txpool_status")
47-
return map[string]hexutil.Uint{
48-
"pending": hexutil.Uint(0),
49-
"queued": hexutil.Uint(0),
50-
}
49+
return api.backend.Status()
5150
}

tests/integration/ante/test_integration.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55

66
"github.com/stretchr/testify/suite"
77

8-
//nolint:revive,ST1001 // dot imports are fine for Ginkgo
8+
//nolint:revive // dot imports are fine for Ginkgo
99
. "github.com/onsi/ginkgo/v2"
10-
//nolint:revive,ST1001 // dot imports are fine for Ginkgo
10+
//nolint:revive // dot imports are fine for Ginkgo
1111
. "github.com/onsi/gomega"
1212

1313
testconstants "github.com/cosmos/evm/testutil/constants"

0 commit comments

Comments
 (0)