From b4d3659547517b5307bfa7f1b33ecd6e45e91967 Mon Sep 17 00:00:00 2001 From: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Date: Mon, 21 Jun 2021 10:06:30 -0400 Subject: [PATCH] feat: add `txpool` namespace RPC methods (#146) * rpc: add txpool namespace and txpool_content endpoint * fix PublicTxPoolAPI naming typo * Update ethereum/rpc/txpool_api.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update ethereum/rpc/txpool_api.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * rpc: add txpool_inspect method * rpc: add txpool_status method * docs: Update Changelog with TxPool methods * docs: Add txpool namespace methods documentation * fix: removed txpool functions from backend.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> --- CHANGELOG.md | 1 + docs/basics/json_rpc.md | 44 +++++++++++++++++++++++++++++++--- ethereum/rpc/apis.go | 7 ++++++ ethereum/rpc/txpool_api.go | 49 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 ethereum/rpc/txpool_api.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 0954c00e..2deddb59 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 99cfeb2f..6dcc2c0d 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 50d174a2..3c9bf566 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 00000000..37366417 --- /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), + } +}