extend rpc api cli and implement debug_traceTransaction stub

This commit is contained in:
andri lim 2018-11-22 13:40:09 +07:00
parent f7d858d58b
commit a2b9167e2b
5 changed files with 93 additions and 12 deletions

View File

@ -89,6 +89,9 @@ type
RpcFlags* {.pure.} = enum
## RPC flags
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
## JSON-RPC configuration object
@ -155,6 +158,9 @@ type
net*: NetConfiguration ## Network configuration
debug*: DebugConfiguration ## Debug configuration
const
defaultRpcApi = {RpcFlags.Eth, RpcFlags.Shh}
var nimbusConfig {.threadvar.}: NimbusConfiguration
proc getConfiguration*(): NimbusConfiguration {.gcsafe.}
@ -241,6 +247,18 @@ proc processAddressPortsList(v: string,
for a in tas6: o.add(a)
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 =
## Convert string to ENode.
let res = initENode(v, o)
@ -314,10 +332,18 @@ proc processRpcArguments(key, value: string): ConfigStatus =
let config = getConfiguration()
let skey = key.toLowerAscii()
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":
config.rpc.binds.setLen(0)
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:
result = EmptyOption
@ -529,6 +555,7 @@ NETWORKING OPTIONS:
API AND CONSOLE OPTIONS:
--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)
--rpcapi:<value> Enable specific set of rpc api from comma separated list(eth, debug)
LOGGING AND DEBUGGING OPTIONS:
--debug Enable debug mode

View File

@ -12,7 +12,7 @@ import
asyncdispatch2, json_rpc/rpcserver, eth_keys,
eth_p2p, eth_p2p/rlpx_protocols/[eth_protocol, les_protocol],
eth_p2p/blockchain_sync,
config, genesis, rpc/[common, p2p], p2p/chain,
config, genesis, rpc/[common, p2p, debug, whisper], p2p/chain,
eth_trie/db
const UseSqlite = false
@ -85,9 +85,15 @@ proc start(): NimbusObject =
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)
if RpcFlags.Shh in conf.rpc.flags:
setupWhisperRPC(nimbus.rpcServer)
if RpcFlags.Debug in conf.rpc.flags:
setupDebugRpc(chainDB, nimbus.rpcServer)
## Starting servers
nimbus.state = Starting
if RpcFlags.Enabled in conf.rpc.flags:
@ -104,6 +110,8 @@ proc start(): NimbusObject =
if status != syncSuccess:
echo "Block sync failed: ", status
#runForever()
nimbus.state = Running
result = nimbus

36
nimbus/rpc/debug.nim Normal file
View 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)

View File

@ -13,7 +13,7 @@ import
eth_common, eth_p2p, eth_keys, eth_trie/db, rlp,
../utils/header, ../transaction, ../config, ../vm_state, ../constants,
../db/[db_chain, state_db, storage_types],
rpc_types
rpc_types, rpc_utils
#[
Note:
@ -28,14 +28,6 @@ import
proc `%`*(value: Time): JsonNode =
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 =
# TODO: Account balance u256 but GasInt is int64?
cast[GasInt](addressDb.get_balance(address).data.lo)

18
nimbus/rpc/rpc_utils.nim Normal file
View 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