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>
This commit is contained in:
crypto-facs 2021-06-21 10:06:30 -04:00 committed by GitHub
parent 8a2a8d377f
commit b4d3659547
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 98 additions and 3 deletions

View File

@ -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

View File

@ -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}

View File

@ -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,
},
}
}

View File

@ -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),
}
}