From 9d4cd72a5d23980706737c582f19272c1f5a1edc Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Fri, 18 Jun 2021 09:39:36 -0400 Subject: [PATCH 1/9] rpc: add txpool namespace and txpool_content endpoint --- ethereum/rpc/apis.go | 7 +++++++ ethereum/rpc/backend.go | 12 ++++++++++++ ethereum/rpc/txpool_api.go | 25 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 ethereum/rpc/txpool_api.go diff --git a/ethereum/rpc/apis.go b/ethereum/rpc/apis.go index 50d174a24a..9b922897db 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(backend), + Public: true, + }, } } diff --git a/ethereum/rpc/backend.go b/ethereum/rpc/backend.go index 8c91607f50..71c4bf5671 100644 --- a/ethereum/rpc/backend.go +++ b/ethereum/rpc/backend.go @@ -36,6 +36,9 @@ type Backend interface { // Used by pending transaction filter PendingTransactions() ([]*types.RPCTransaction, error) + // Used by txpool content + TxPoolContent() (map[string]map[string]map[string]*types.RPCTransaction, error) + // Used by log filter GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error) BloomStatus() (uint64, uint64) @@ -274,6 +277,15 @@ func (e *EVMBackend) PendingTransactions() ([]*types.RPCTransaction, error) { return []*types.RPCTransaction{}, nil } +// TxPoolContent returns the transactions contained within the transaction pool +func (e *EVMBackend) TxPoolContent() (map[string]map[string]map[string]*types.RPCTransaction, error) { + 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 +} + // GetLogs returns all the logs from all the ethereum transactions in a block. func (e *EVMBackend) GetLogs(blockHash common.Hash) ([][]*ethtypes.Log, error) { // NOTE: we query the state in case the tx result logs are not persisted after an upgrade. diff --git a/ethereum/rpc/txpool_api.go b/ethereum/rpc/txpool_api.go new file mode 100644 index 0000000000..2ed6cd7aba --- /dev/null +++ b/ethereum/rpc/txpool_api.go @@ -0,0 +1,25 @@ +package rpc + +import ( + "github.com/cosmos/ethermint/ethereum/rpc/types" + log "github.com/xlab/suplog" +) + +type PublicTxPoolApi struct { + logger log.Logger + backend Backend +} + +func NewPublicTxPoolApi(backend Backend) *PublicTxPoolApi { + return &PublicTxPoolApi{ + logger: log.WithField("module", "txpool"), + backend: backend, + } +} + +// Content returns the transactions contained within the transaction pool +// NOTE: For more info about the current status of this endpoint https://github.com/tharsis/ethermint/issues/124 +func (api *PublicTxPoolApi) Content() (map[string]map[string]map[string]*types.RPCTransaction, error) { + api.logger.Debug("txpool_content") + return api.backend.TxPoolContent() +} From a624127ca17a8cd1249bffdd8e406abbaa1f50cf Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Fri, 18 Jun 2021 11:32:36 -0400 Subject: [PATCH 2/9] fix PublicTxPoolAPI naming typo --- ethereum/rpc/apis.go | 2 +- ethereum/rpc/txpool_api.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ethereum/rpc/apis.go b/ethereum/rpc/apis.go index 9b922897db..4c8fd399b7 100644 --- a/ethereum/rpc/apis.go +++ b/ethereum/rpc/apis.go @@ -61,7 +61,7 @@ func GetRPCAPIs(clientCtx client.Context, tmWSClient *rpcclient.WSClient) []rpc. { Namespace: TxPoolNamespace, Version: apiVersion, - Service: NewPublicTxPoolApi(backend), + Service: NewPublicTxPoolAPI(backend), Public: true, }, } diff --git a/ethereum/rpc/txpool_api.go b/ethereum/rpc/txpool_api.go index 2ed6cd7aba..a4aab570ee 100644 --- a/ethereum/rpc/txpool_api.go +++ b/ethereum/rpc/txpool_api.go @@ -5,13 +5,13 @@ import ( log "github.com/xlab/suplog" ) -type PublicTxPoolApi struct { +type PublicTxPoolAPI struct { logger log.Logger backend Backend } -func NewPublicTxPoolApi(backend Backend) *PublicTxPoolApi { - return &PublicTxPoolApi{ +func NewPublicTxPoolAPI(backend Backend) *PublicTxPoolAPI { + return &PublicTxPoolAPI{ logger: log.WithField("module", "txpool"), backend: backend, } @@ -19,7 +19,7 @@ func NewPublicTxPoolApi(backend Backend) *PublicTxPoolApi { // Content returns the transactions contained within the transaction pool // NOTE: For more info about the current status of this endpoint https://github.com/tharsis/ethermint/issues/124 -func (api *PublicTxPoolApi) Content() (map[string]map[string]map[string]*types.RPCTransaction, error) { +func (api *PublicTxPoolAPI) Content() (map[string]map[string]map[string]*types.RPCTransaction, error) { api.logger.Debug("txpool_content") return api.backend.TxPoolContent() } From ba341ed871df80296ce2f183b56977ec815bb220 Mon Sep 17 00:00:00 2001 From: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Date: Sun, 20 Jun 2021 16:42:39 -0400 Subject: [PATCH 3/9] Update ethereum/rpc/txpool_api.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> --- ethereum/rpc/txpool_api.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ethereum/rpc/txpool_api.go b/ethereum/rpc/txpool_api.go index a4aab570ee..f9d42295df 100644 --- a/ethereum/rpc/txpool_api.go +++ b/ethereum/rpc/txpool_api.go @@ -5,6 +5,7 @@ import ( log "github.com/xlab/suplog" ) +// PublicTxPoolAPI offers and API for the transaction pool. It only operates on data that is non-confidential. type PublicTxPoolAPI struct { logger log.Logger backend Backend From a3874348262cec7233443a2fbab91cddcef08e23 Mon Sep 17 00:00:00 2001 From: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Date: Sun, 20 Jun 2021 16:42:43 -0400 Subject: [PATCH 4/9] Update ethereum/rpc/txpool_api.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> --- ethereum/rpc/txpool_api.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ethereum/rpc/txpool_api.go b/ethereum/rpc/txpool_api.go index f9d42295df..ecde0887d2 100644 --- a/ethereum/rpc/txpool_api.go +++ b/ethereum/rpc/txpool_api.go @@ -11,6 +11,7 @@ type PublicTxPoolAPI struct { backend Backend } +// NewPublicTxPoolAPI creates a new tx pool service that gives information about the transaction pool. func NewPublicTxPoolAPI(backend Backend) *PublicTxPoolAPI { return &PublicTxPoolAPI{ logger: log.WithField("module", "txpool"), From e10a287aa1d38d44c7892df666e2847d4c73adef Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Sun, 20 Jun 2021 17:11:09 -0400 Subject: [PATCH 5/9] rpc: add txpool_inspect method --- ethereum/rpc/backend.go | 11 +++++++++++ ethereum/rpc/txpool_api.go | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ethereum/rpc/backend.go b/ethereum/rpc/backend.go index 71c4bf5671..a11b616d14 100644 --- a/ethereum/rpc/backend.go +++ b/ethereum/rpc/backend.go @@ -38,6 +38,7 @@ type Backend interface { // Used by txpool content TxPoolContent() (map[string]map[string]map[string]*types.RPCTransaction, error) + TxPoolInspect() (map[string]map[string]map[string]string, error) // Used by log filter GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error) @@ -286,6 +287,16 @@ func (e *EVMBackend) TxPoolContent() (map[string]map[string]map[string]*types.RP return content, nil } +// TxPoolInspect retrieves the content of the transaction pool and flattens it into an +// easily inspectable list. +func (e *EVMBackend) TxPoolInspect() (map[string]map[string]map[string]string, error) { + 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 +} + // GetLogs returns all the logs from all the ethereum transactions in a block. func (e *EVMBackend) GetLogs(blockHash common.Hash) ([][]*ethtypes.Log, error) { // NOTE: we query the state in case the tx result logs are not persisted after an upgrade. diff --git a/ethereum/rpc/txpool_api.go b/ethereum/rpc/txpool_api.go index ecde0887d2..025c446403 100644 --- a/ethereum/rpc/txpool_api.go +++ b/ethereum/rpc/txpool_api.go @@ -6,6 +6,7 @@ import ( ) // 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 backend Backend @@ -20,8 +21,13 @@ func NewPublicTxPoolAPI(backend Backend) *PublicTxPoolAPI { } // Content returns the transactions contained within the transaction pool -// NOTE: For more info about the current status of this endpoint https://github.com/tharsis/ethermint/issues/124 func (api *PublicTxPoolAPI) Content() (map[string]map[string]map[string]*types.RPCTransaction, error) { api.logger.Debug("txpool_content") return api.backend.TxPoolContent() } + +// 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") + return api.backend.TxPoolInspect() +} From 1aa873065a01e6dc5274f7fdbba3d8fde08c6e7a Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Sun, 20 Jun 2021 17:20:47 -0400 Subject: [PATCH 6/9] rpc: add txpool_status method --- ethereum/rpc/backend.go | 11 ++++++++++- ethereum/rpc/txpool_api.go | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ethereum/rpc/backend.go b/ethereum/rpc/backend.go index a11b616d14..ebdd8ec1ac 100644 --- a/ethereum/rpc/backend.go +++ b/ethereum/rpc/backend.go @@ -36,9 +36,10 @@ type Backend interface { // Used by pending transaction filter PendingTransactions() ([]*types.RPCTransaction, error) - // Used by txpool content + // Used by txpool methods TxPoolContent() (map[string]map[string]map[string]*types.RPCTransaction, error) TxPoolInspect() (map[string]map[string]map[string]string, error) + TxPoolStatus() map[string]hexutil.Uint // Used by log filter GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error) @@ -297,6 +298,14 @@ func (e *EVMBackend) TxPoolInspect() (map[string]map[string]map[string]string, e return content, nil } +// TxPoolStatus returns the number of pending and queued transaction in the pool. +func (e *EVMBackend) TxPoolStatus() map[string]hexutil.Uint { + return map[string]hexutil.Uint{ + "pending": hexutil.Uint(0), + "queued": hexutil.Uint(0), + } +} + // GetLogs returns all the logs from all the ethereum transactions in a block. func (e *EVMBackend) GetLogs(blockHash common.Hash) ([][]*ethtypes.Log, error) { // NOTE: we query the state in case the tx result logs are not persisted after an upgrade. diff --git a/ethereum/rpc/txpool_api.go b/ethereum/rpc/txpool_api.go index 025c446403..1442e65b9c 100644 --- a/ethereum/rpc/txpool_api.go +++ b/ethereum/rpc/txpool_api.go @@ -2,6 +2,7 @@ package rpc import ( "github.com/cosmos/ethermint/ethereum/rpc/types" + "github.com/ethereum/go-ethereum/common/hexutil" log "github.com/xlab/suplog" ) @@ -31,3 +32,9 @@ func (api *PublicTxPoolAPI) Inspect() (map[string]map[string]map[string]string, api.logger.Debug("txpool_inspect") return api.backend.TxPoolInspect() } + +// 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 api.backend.TxPoolStatus() +} From e592b3c3d973477e4103abdc4a07f4b7eaa00be6 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Mon, 21 Jun 2021 08:11:12 -0400 Subject: [PATCH 7/9] docs: Update Changelog with TxPool methods --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From 7d6c7ed7f344d20450ae1bc448948c9436ee371f Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Mon, 21 Jun 2021 09:42:00 -0400 Subject: [PATCH 8/9] docs: Add txpool namespace methods documentation --- docs/basics/json_rpc.md | 44 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) 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} From acd394f8a45a2f749ba7026763c7d5a33310ffc3 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Mon, 21 Jun 2021 09:46:24 -0400 Subject: [PATCH 9/9] fix: removed txpool functions from backend.go --- ethereum/rpc/apis.go | 2 +- ethereum/rpc/backend.go | 32 -------------------------------- ethereum/rpc/txpool_api.go | 25 +++++++++++++++++-------- 3 files changed, 18 insertions(+), 41 deletions(-) diff --git a/ethereum/rpc/apis.go b/ethereum/rpc/apis.go index 4c8fd399b7..3c9bf5666c 100644 --- a/ethereum/rpc/apis.go +++ b/ethereum/rpc/apis.go @@ -61,7 +61,7 @@ func GetRPCAPIs(clientCtx client.Context, tmWSClient *rpcclient.WSClient) []rpc. { Namespace: TxPoolNamespace, Version: apiVersion, - Service: NewPublicTxPoolAPI(backend), + Service: NewPublicTxPoolAPI(), Public: true, }, } diff --git a/ethereum/rpc/backend.go b/ethereum/rpc/backend.go index ebdd8ec1ac..8c91607f50 100644 --- a/ethereum/rpc/backend.go +++ b/ethereum/rpc/backend.go @@ -36,11 +36,6 @@ type Backend interface { // Used by pending transaction filter PendingTransactions() ([]*types.RPCTransaction, error) - // Used by txpool methods - TxPoolContent() (map[string]map[string]map[string]*types.RPCTransaction, error) - TxPoolInspect() (map[string]map[string]map[string]string, error) - TxPoolStatus() map[string]hexutil.Uint - // Used by log filter GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, error) BloomStatus() (uint64, uint64) @@ -279,33 +274,6 @@ func (e *EVMBackend) PendingTransactions() ([]*types.RPCTransaction, error) { return []*types.RPCTransaction{}, nil } -// TxPoolContent returns the transactions contained within the transaction pool -func (e *EVMBackend) TxPoolContent() (map[string]map[string]map[string]*types.RPCTransaction, error) { - 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 -} - -// TxPoolInspect retrieves the content of the transaction pool and flattens it into an -// easily inspectable list. -func (e *EVMBackend) TxPoolInspect() (map[string]map[string]map[string]string, error) { - 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 -} - -// TxPoolStatus returns the number of pending and queued transaction in the pool. -func (e *EVMBackend) TxPoolStatus() map[string]hexutil.Uint { - return map[string]hexutil.Uint{ - "pending": hexutil.Uint(0), - "queued": hexutil.Uint(0), - } -} - // GetLogs returns all the logs from all the ethereum transactions in a block. func (e *EVMBackend) GetLogs(blockHash common.Hash) ([][]*ethtypes.Log, error) { // NOTE: we query the state in case the tx result logs are not persisted after an upgrade. diff --git a/ethereum/rpc/txpool_api.go b/ethereum/rpc/txpool_api.go index 1442e65b9c..3736641753 100644 --- a/ethereum/rpc/txpool_api.go +++ b/ethereum/rpc/txpool_api.go @@ -9,32 +9,41 @@ import ( // 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 - backend Backend + logger log.Logger } // NewPublicTxPoolAPI creates a new tx pool service that gives information about the transaction pool. -func NewPublicTxPoolAPI(backend Backend) *PublicTxPoolAPI { +func NewPublicTxPoolAPI() *PublicTxPoolAPI { return &PublicTxPoolAPI{ - logger: log.WithField("module", "txpool"), - backend: backend, + 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") - return api.backend.TxPoolContent() + 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") - return api.backend.TxPoolInspect() + 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 api.backend.TxPoolStatus() + return map[string]hexutil.Uint{ + "pending": hexutil.Uint(0), + "queued": hexutil.Uint(0), + } }