diff --git a/CHANGELOG.md b/CHANGELOG.md index 0954c00ee4..2deddb594d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (evm) [tharsis#66](https://github.com/tharsis/ethermint/issues/66) Support legacy transaction types for signing. * (evm) [tharsis#24](https://github.com/tharsis/ethermint/pull/24) Implement metrics for `MsgEthereumTx`, state transtitions, `BeginBlock` and `EndBlock`. * (deps) [\#602](https://github.com/cosmos/ethermint/pull/856) Bump tendermint version to [v0.39.3](https://github.com/tendermint/tendermint/releases/tag/v0.39.3) +* (rpc) [#124](https://github.com/tharsis/ethermint/issues/124) Implement `txpool_content`, `txpool_inspect` and `txpool_status` RPC methods ### Bug Fixes diff --git a/docs/basics/json_rpc.md b/docs/basics/json_rpc.md index 99cfeb2fe7..6dcc2c0d45 100644 --- a/docs/basics/json_rpc.md +++ b/docs/basics/json_rpc.md @@ -144,9 +144,9 @@ Check the JSON-RPC methods and namespaces supported on Ethermint. {synopsis} | `miner_start` | Miner | | | | `miner_stop` | Miner | | | | `miner_setEtherbase` | Miner | | | -| `txpool_content` | TXPool | | | -| `txpool_inspect` | TXPool | | | -| `txpool_status` | TXPool | | | +| `txpool_content` | TXPool | ✔ | | +| `txpool_inspect` | TXPool | ✔ | | +| `txpool_status` | TXPool | ✔ | | :::tip @@ -693,6 +693,44 @@ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"topics" {"jsonrpc":"2.0","id":1,"result":[]} ``` +## TxPool Methods + +### txpool_content + +Returns a list of the exact details of all the transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only. + +```json +// Request +curl -X POST --data '{"jsonrpc":"2.0","method":"txpool_content","params":[],"id":1}' -H "Content-Type: application/json" http://localhost:8545 + +// Result +{"jsonrpc":"2.0","id":1,"result":{"pending":{},"queued":{}} +``` + +### txpool_inspect + +Returns a list on text format to summarize all the transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only. This is a method specifically tailored to developers to quickly see the transactions in the pool and find any potential issues. + +```json +// Request +curl -X POST --data '{"jsonrpc":"2.0","method":"txpool_inspect","params":[],"id":1}' -H "Content-Type: application/json" http://localhost:8545 + +// Result +{"jsonrpc":"2.0","id":1,"result":{"pending":{},"queued":{}} +``` + +### txpool_status + +Returns the number of transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only. + +```json +// Request +curl -X POST --data '{"jsonrpc":"2.0","method":"txpool_status","params":[],"id":1}' -H "Content-Type: application/json" http://localhost:8545 + +// Result +{"jsonrpc":"2.0","id":1,"result":{"pending":"0x0","queued":"0x0"}} +``` + ## WebSocket Methods Read about websockets in [events](./../quickstart/events.md) {hide} diff --git a/ethereum/rpc/apis.go b/ethereum/rpc/apis.go index 50d174a24a..3c9bf5666c 100644 --- a/ethereum/rpc/apis.go +++ b/ethereum/rpc/apis.go @@ -16,6 +16,7 @@ const ( EthNamespace = "eth" PersonalNamespace = "personal" NetNamespace = "net" + TxPoolNamespace = "txpool" apiVersion = "1.0" ) @@ -57,5 +58,11 @@ func GetRPCAPIs(clientCtx client.Context, tmWSClient *rpcclient.WSClient) []rpc. Service: NewPersonalAPI(ethAPI), Public: true, }, + { + Namespace: TxPoolNamespace, + Version: apiVersion, + Service: NewPublicTxPoolAPI(), + Public: true, + }, } } diff --git a/ethereum/rpc/txpool_api.go b/ethereum/rpc/txpool_api.go new file mode 100644 index 0000000000..3736641753 --- /dev/null +++ b/ethereum/rpc/txpool_api.go @@ -0,0 +1,49 @@ +package rpc + +import ( + "github.com/cosmos/ethermint/ethereum/rpc/types" + "github.com/ethereum/go-ethereum/common/hexutil" + log "github.com/xlab/suplog" +) + +// PublicTxPoolAPI offers and API for the transaction pool. It only operates on data that is non-confidential. +// NOTE: For more info about the current status of this endpoints see https://github.com/tharsis/ethermint/issues/124 +type PublicTxPoolAPI struct { + logger log.Logger +} + +// NewPublicTxPoolAPI creates a new tx pool service that gives information about the transaction pool. +func NewPublicTxPoolAPI() *PublicTxPoolAPI { + return &PublicTxPoolAPI{ + logger: log.WithField("module", "txpool"), + } +} + +// Content returns the transactions contained within the transaction pool +func (api *PublicTxPoolAPI) Content() (map[string]map[string]map[string]*types.RPCTransaction, error) { + api.logger.Debug("txpool_content") + content := map[string]map[string]map[string]*types.RPCTransaction{ + "pending": make(map[string]map[string]*types.RPCTransaction), + "queued": make(map[string]map[string]*types.RPCTransaction), + } + return content, nil +} + +// Inspect returns the content of the transaction pool and flattens it into an +func (api *PublicTxPoolAPI) Inspect() (map[string]map[string]map[string]string, error) { + api.logger.Debug("txpool_inspect") + content := map[string]map[string]map[string]string{ + "pending": make(map[string]map[string]string), + "queued": make(map[string]map[string]string), + } + return content, nil +} + +// Status returns the number of pending and queued transaction in the pool. +func (api *PublicTxPoolAPI) Status() map[string]hexutil.Uint { + api.logger.Debug("txpool_status") + return map[string]hexutil.Uint{ + "pending": hexutil.Uint(0), + "queued": hexutil.Uint(0), + } +}