Skip to content

Commit

Permalink
Stop using txpool inspect for geth
Browse files Browse the repository at this point in the history
Fix #4976

Instead use web3.eth.getTransactionCount(address, "pending") which now
works as intended since
ethereum/go-ethereum#2880 has been fixed
  • Loading branch information
LefterisJP authored and rakanalh committed Sep 25, 2019
1 parent 8bc95bf commit 8db4ad2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/overview_and_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ We will provide you with the necessary cli arguments step by step. Full example

Run the Ethereum client and let it sync::

geth --syncmode fast --rpc --rpcapi eth,net,web3,txpool
geth --syncmode fast --rpc --rpcapi eth,net,web3

.. note::
When you want to use a testnet add the ``--testnet`` or ``--rinkeby`` flags or set the network id with ``--networkid`` directly.
Expand Down
2 changes: 1 addition & 1 deletion docs/private_net_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ With the ``genesis.json`` you can initialize a blockchain.
(env) $ pwd
<snip>/priv_chain
(env) $ geth --datadir blkchain1 init genesis.json
(env) $ geth --rpc --datadir blkchain1 --networkid 4321 --rpcapi "eth,net,web3,txpool" console
(env) $ geth --rpc --datadir blkchain1 --networkid 4321 --rpcapi "eth,net,web3" console
<snip>
> personal.newAccount()
"0xd4de892c06cf4a0557c7d515f79fd20b8356d6cf"
Expand Down
42 changes: 4 additions & 38 deletions raiden/network/rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,23 @@ def geth_assert_rpc_interfaces(web3: Web3):
except ValueError:
raise EthNodeInterfaceError(
"The underlying geth node does not have the web3 rpc interface "
"enabled. Please run it with --rpcapi eth,net,web3,txpool"
"enabled. Please run it with --rpcapi eth,net,web3"
)

try:
web3.eth.blockNumber
except ValueError:
raise EthNodeInterfaceError(
"The underlying geth node does not have the eth rpc interface "
"enabled. Please run it with --rpcapi eth,net,web3,txpool"
"enabled. Please run it with --rpcapi eth,net,web3"
)

try:
web3.net.version
except ValueError:
raise EthNodeInterfaceError(
"The underlying geth node does not have the net rpc interface "
"enabled. Please run it with --rpcapi eth,net,web3,txpool"
)

try:
web3.txpool.inspect
except ValueError:
raise EthNodeInterfaceError(
"The underlying geth node does not have the txpool rpc interface "
"enabled. Please run it with --rpcapi eth,net,web3,txpool"
"enabled. Please run it with --rpcapi eth,net,web3"
)


Expand Down Expand Up @@ -134,33 +126,7 @@ def parity_discover_next_available_nonce(web3: Web3, address: AddressHex) -> Non

def geth_discover_next_available_nonce(web3: Web3, address: AddressHex) -> Nonce:
"""Returns the next available nonce for `address`."""

# The nonces of the mempool transactions are considered used, and it's
# assumed these transactions are different from the ones currently pending
# in the client. This is a simplification, otherwise it would be necessary
# to filter the local pending transactions based on the mempool.
pool = web3.txpool.inspect or {}

# pool is roughly:
#
# {'queued': {'account1': {nonce1: ... nonce2: ...}, 'account2': ...}, 'pending': ...}
#
# Pending refers to the current block and if it contains transactions from
# the user, these will be the younger transactions. Because this needs the
# largest nonce, queued is checked first.

address = to_checksum_address(address)
queued = pool.get("queued", {}).get(address)
if queued:
return Nonce(max(int(k) for k in queued.keys()) + 1)

pending = pool.get("pending", {}).get(address)
if pending:
return Nonce(max(int(k) for k in pending.keys()) + 1)

# The first valid nonce is 0, therefore the count is already the next
# available nonce
return web3.eth.getTransactionCount(address, "latest")
return web3.eth.getTransactionCount(address, "pending")


def check_address_has_code(
Expand Down
2 changes: 1 addition & 1 deletion raiden/tests/utils/eth_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def geth_to_cmd(node: Dict, datadir: str, chain_id: ChainID, verbosity: str) ->
[
"--rpc",
"--rpcapi",
"eth,net,web3,personal,txpool",
"eth,net,web3,personal",
"--rpcaddr",
"127.0.0.1",
"--networkid",
Expand Down
2 changes: 1 addition & 1 deletion raiden/ui/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def check_ethereum_client_is_supported(web3: Web3) -> None:
except ValueError:
raise EthNodeInterfaceError(
"The underlying ethereum node does not have the web3 rpc interface "
"enabled. Please run it with --rpcapi eth,net,web3,txpool for geth "
"enabled. Please run it with --rpcapi eth,net,web3 for geth "
"and --jsonrpc-apis=eth,net,web3,parity for parity."
)

Expand Down

0 comments on commit 8db4ad2

Please sign in to comment.