mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-11 21:04:11 +00:00
extend rpc api cli and implement debug_traceTransaction stub
This commit is contained in:
parent
f7d858d58b
commit
a2b9167e2b
@ -89,6 +89,9 @@ type
|
|||||||
RpcFlags* {.pure.} = enum
|
RpcFlags* {.pure.} = enum
|
||||||
## RPC flags
|
## RPC flags
|
||||||
Enabled ## RPC enabled
|
Enabled ## RPC enabled
|
||||||
|
Eth ## enable eth_ set of RPC API
|
||||||
|
Shh ## enable shh_ set of RPC API
|
||||||
|
Debug ## enable debug_ set of RPC API
|
||||||
|
|
||||||
RpcConfiguration* = object
|
RpcConfiguration* = object
|
||||||
## JSON-RPC configuration object
|
## JSON-RPC configuration object
|
||||||
@ -155,6 +158,9 @@ type
|
|||||||
net*: NetConfiguration ## Network configuration
|
net*: NetConfiguration ## Network configuration
|
||||||
debug*: DebugConfiguration ## Debug configuration
|
debug*: DebugConfiguration ## Debug configuration
|
||||||
|
|
||||||
|
const
|
||||||
|
defaultRpcApi = {RpcFlags.Eth, RpcFlags.Shh}
|
||||||
|
|
||||||
var nimbusConfig {.threadvar.}: NimbusConfiguration
|
var nimbusConfig {.threadvar.}: NimbusConfiguration
|
||||||
|
|
||||||
proc getConfiguration*(): NimbusConfiguration {.gcsafe.}
|
proc getConfiguration*(): NimbusConfiguration {.gcsafe.}
|
||||||
@ -241,6 +247,18 @@ proc processAddressPortsList(v: string,
|
|||||||
for a in tas6: o.add(a)
|
for a in tas6: o.add(a)
|
||||||
result = Success
|
result = Success
|
||||||
|
|
||||||
|
proc processRpcApiList(v: string, flags: var set[RpcFlags]): ConfigStatus =
|
||||||
|
var list = newSeq[string]()
|
||||||
|
processList(v, list)
|
||||||
|
result = Success
|
||||||
|
for item in list:
|
||||||
|
case item.toLowerAscii()
|
||||||
|
of "eth": flags.incl RpcFlags.Eth
|
||||||
|
of "debug": flags.incl RpcFlags.Debug
|
||||||
|
else:
|
||||||
|
warn "unknown rpc api", name = item
|
||||||
|
result = ErrorIncorrectOption
|
||||||
|
|
||||||
proc processENode(v: string, o: var ENode): ConfigStatus =
|
proc processENode(v: string, o: var ENode): ConfigStatus =
|
||||||
## Convert string to ENode.
|
## Convert string to ENode.
|
||||||
let res = initENode(v, o)
|
let res = initENode(v, o)
|
||||||
@ -314,10 +332,18 @@ proc processRpcArguments(key, value: string): ConfigStatus =
|
|||||||
let config = getConfiguration()
|
let config = getConfiguration()
|
||||||
let skey = key.toLowerAscii()
|
let skey = key.toLowerAscii()
|
||||||
if skey == "rpc":
|
if skey == "rpc":
|
||||||
config.rpc.flags.incl(RpcFlags.Enabled)
|
if RpcFlags.Enabled notin config.rpc.flags:
|
||||||
|
config.rpc.flags.incl(RpcFlags.Enabled)
|
||||||
|
config.rpc.flags.incl(defaultRpcApi)
|
||||||
elif skey == "rpcbind":
|
elif skey == "rpcbind":
|
||||||
config.rpc.binds.setLen(0)
|
config.rpc.binds.setLen(0)
|
||||||
result = processAddressPortsList(value, config.rpc.binds)
|
result = processAddressPortsList(value, config.rpc.binds)
|
||||||
|
elif skey == "rpcapi":
|
||||||
|
if RpcFlags.Enabled in config.rpc.flags:
|
||||||
|
config.rpc.flags.excl(defaultRpcApi)
|
||||||
|
else:
|
||||||
|
config.rpc.flags.incl(RpcFlags.Enabled)
|
||||||
|
result = processRpcApiList(value, config.rpc.flags)
|
||||||
else:
|
else:
|
||||||
result = EmptyOption
|
result = EmptyOption
|
||||||
|
|
||||||
@ -529,6 +555,7 @@ NETWORKING OPTIONS:
|
|||||||
API AND CONSOLE OPTIONS:
|
API AND CONSOLE OPTIONS:
|
||||||
--rpc Enable the HTTP-RPC server
|
--rpc Enable the HTTP-RPC server
|
||||||
--rpcbind:<value> HTTP-RPC server will bind to given comma separated address:port pairs (default: 127.0.0.1:8545)
|
--rpcbind:<value> HTTP-RPC server will bind to given comma separated address:port pairs (default: 127.0.0.1:8545)
|
||||||
|
--rpcapi:<value> Enable specific set of rpc api from comma separated list(eth, debug)
|
||||||
|
|
||||||
LOGGING AND DEBUGGING OPTIONS:
|
LOGGING AND DEBUGGING OPTIONS:
|
||||||
--debug Enable debug mode
|
--debug Enable debug mode
|
||||||
|
@ -12,7 +12,7 @@ import
|
|||||||
asyncdispatch2, json_rpc/rpcserver, eth_keys,
|
asyncdispatch2, json_rpc/rpcserver, eth_keys,
|
||||||
eth_p2p, eth_p2p/rlpx_protocols/[eth_protocol, les_protocol],
|
eth_p2p, eth_p2p/rlpx_protocols/[eth_protocol, les_protocol],
|
||||||
eth_p2p/blockchain_sync,
|
eth_p2p/blockchain_sync,
|
||||||
config, genesis, rpc/[common, p2p], p2p/chain,
|
config, genesis, rpc/[common, p2p, debug, whisper], p2p/chain,
|
||||||
eth_trie/db
|
eth_trie/db
|
||||||
|
|
||||||
const UseSqlite = false
|
const UseSqlite = false
|
||||||
@ -85,9 +85,15 @@ proc start(): NimbusObject =
|
|||||||
|
|
||||||
nimbus.ethNode.chain = newChain(chainDB)
|
nimbus.ethNode.chain = newChain(chainDB)
|
||||||
|
|
||||||
if RpcFlags.Enabled in conf.rpc.flags:
|
if RpcFlags.Eth in conf.rpc.flags:
|
||||||
setupEthRpc(nimbus.ethNode, chainDB, nimbus.rpcServer)
|
setupEthRpc(nimbus.ethNode, chainDB, nimbus.rpcServer)
|
||||||
|
|
||||||
|
if RpcFlags.Shh in conf.rpc.flags:
|
||||||
|
setupWhisperRPC(nimbus.rpcServer)
|
||||||
|
|
||||||
|
if RpcFlags.Debug in conf.rpc.flags:
|
||||||
|
setupDebugRpc(chainDB, nimbus.rpcServer)
|
||||||
|
|
||||||
## Starting servers
|
## Starting servers
|
||||||
nimbus.state = Starting
|
nimbus.state = Starting
|
||||||
if RpcFlags.Enabled in conf.rpc.flags:
|
if RpcFlags.Enabled in conf.rpc.flags:
|
||||||
@ -104,6 +110,8 @@ proc start(): NimbusObject =
|
|||||||
if status != syncSuccess:
|
if status != syncSuccess:
|
||||||
echo "Block sync failed: ", status
|
echo "Block sync failed: ", status
|
||||||
|
|
||||||
|
#runForever()
|
||||||
|
|
||||||
nimbus.state = Running
|
nimbus.state = Running
|
||||||
result = nimbus
|
result = nimbus
|
||||||
|
|
||||||
|
36
nimbus/rpc/debug.nim
Normal file
36
nimbus/rpc/debug.nim
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# Nimbus
|
||||||
|
# Copyright (c) 2018 Status Research & Development GmbH
|
||||||
|
# Licensed under either of
|
||||||
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
|
# at your option.
|
||||||
|
# This file may not be copied, modified, or distributed except according to
|
||||||
|
# those terms.
|
||||||
|
|
||||||
|
import
|
||||||
|
strutils, hexstrings, eth_p2p, options,
|
||||||
|
../db/[db_chain, state_db, storage_types],
|
||||||
|
json_rpc/rpcserver, json, macros, rpc_utils
|
||||||
|
|
||||||
|
type
|
||||||
|
TraceTxOptions = object
|
||||||
|
disableStorage: Option[bool]
|
||||||
|
disableMemory: Option[bool]
|
||||||
|
disableStack: Option[bool]
|
||||||
|
|
||||||
|
proc setupDebugRpc*(chain: BaseChainDB, rpcsrv: RpcServer) =
|
||||||
|
|
||||||
|
rpcsrv.rpc("debug_traceTransaction") do(data: HexDataStr, options: Option[TraceTxOptions]) -> JsonNode:
|
||||||
|
## The traceTransaction debugging method will attempt to run the transaction in the exact
|
||||||
|
## same manner as it was executed on the network. It will replay any transaction that may
|
||||||
|
## have been executed prior to this one before it will finally attempt to execute the
|
||||||
|
## transaction that corresponds to the given hash.
|
||||||
|
##
|
||||||
|
## In addition to the hash of the transaction you may give it a secondary optional argument,
|
||||||
|
## which specifies the options for this specific call. The possible options are:
|
||||||
|
##
|
||||||
|
## * disableStorage: BOOL. Setting this to true will disable storage capture (default = false).
|
||||||
|
## * disableMemory: BOOL. Setting this to true will disable memory capture (default = false).
|
||||||
|
## * disableStack: BOOL. Setting this to true will disable stack capture (default = false).
|
||||||
|
var hashData = strToHash(data.string)
|
||||||
|
|
@ -13,7 +13,7 @@ import
|
|||||||
eth_common, eth_p2p, eth_keys, eth_trie/db, rlp,
|
eth_common, eth_p2p, eth_keys, eth_trie/db, rlp,
|
||||||
../utils/header, ../transaction, ../config, ../vm_state, ../constants,
|
../utils/header, ../transaction, ../config, ../vm_state, ../constants,
|
||||||
../db/[db_chain, state_db, storage_types],
|
../db/[db_chain, state_db, storage_types],
|
||||||
rpc_types
|
rpc_types, rpc_utils
|
||||||
|
|
||||||
#[
|
#[
|
||||||
Note:
|
Note:
|
||||||
@ -28,14 +28,6 @@ import
|
|||||||
proc `%`*(value: Time): JsonNode =
|
proc `%`*(value: Time): JsonNode =
|
||||||
result = %value.toSeconds
|
result = %value.toSeconds
|
||||||
|
|
||||||
func strToAddress(value: string): EthAddress = hexToPaddedByteArray[20](value)
|
|
||||||
|
|
||||||
func toHash(value: array[32, byte]): Hash256 {.inline.} =
|
|
||||||
result.data = value
|
|
||||||
|
|
||||||
func strToHash(value: string): Hash256 {.inline.} =
|
|
||||||
result = hexToPaddedByteArray[32](value).toHash
|
|
||||||
|
|
||||||
template balance(addressDb: AccountStateDb, address: EthAddress): GasInt =
|
template balance(addressDb: AccountStateDb, address: EthAddress): GasInt =
|
||||||
# TODO: Account balance u256 but GasInt is int64?
|
# TODO: Account balance u256 but GasInt is int64?
|
||||||
cast[GasInt](addressDb.get_balance(address).data.lo)
|
cast[GasInt](addressDb.get_balance(address).data.lo)
|
||||||
|
18
nimbus/rpc/rpc_utils.nim
Normal file
18
nimbus/rpc/rpc_utils.nim
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Nimbus
|
||||||
|
# Copyright (c) 2018 Status Research & Development GmbH
|
||||||
|
# Licensed under either of
|
||||||
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
|
# at your option.
|
||||||
|
# This file may not be copied, modified, or distributed except according to
|
||||||
|
# those terms.
|
||||||
|
|
||||||
|
import hexstrings, nimcrypto, eth_common, byteutils
|
||||||
|
|
||||||
|
func strToAddress*(value: string): EthAddress = hexToPaddedByteArray[20](value)
|
||||||
|
|
||||||
|
func toHash*(value: array[32, byte]): Hash256 {.inline.} =
|
||||||
|
result.data = value
|
||||||
|
|
||||||
|
func strToHash*(value: string): Hash256 {.inline.} =
|
||||||
|
result = hexToPaddedByteArray[32](value).toHash
|
Loading…
x
Reference in New Issue
Block a user