add TransactionKey to persistTransactions and add more fat to debug_traceTransaction

This commit is contained in:
andri lim 2018-11-28 09:25:36 +07:00
parent 161d6adbc7
commit 21070d510d
5 changed files with 25 additions and 12 deletions

View File

@ -254,6 +254,7 @@ proc processRpcApiList(v: string, flags: var set[RpcFlags]): ConfigStatus =
for item in list: for item in list:
case item.toLowerAscii() case item.toLowerAscii()
of "eth": flags.incl RpcFlags.Eth of "eth": flags.incl RpcFlags.Eth
of "shh": flags.incl RpcFlags.Shh
of "debug": flags.incl RpcFlags.Debug of "debug": flags.incl RpcFlags.Debug
else: else:
warn "unknown rpc api", name = item warn "unknown rpc api", name = item
@ -555,7 +556,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) --rpcapi:<value> Enable specific set of rpc api from comma separated list(eth, shh, debug)
LOGGING AND DEBUGGING OPTIONS: LOGGING AND DEBUGGING OPTIONS:
--debug Enable debug mode --debug Enable debug mode

View File

@ -100,14 +100,19 @@ iterator findNewAncestors(self: BaseChainDB; header: BlockHeader): BlockHeader =
else: else:
h = self.getBlockHeader(h.parentHash) h = self.getBlockHeader(h.parentHash)
proc addBlockNumberToHashLookup(self: BaseChainDB; header: BlockHeader) = proc addBlockNumberToHashLookup*(self: BaseChainDB; header: BlockHeader) =
self.db.put(blockNumberToHashKey(header.blockNumber).toOpenArray, self.db.put(blockNumberToHashKey(header.blockNumber).toOpenArray,
rlp.encode(header.hash)) rlp.encode(header.hash))
proc persistTransactions*(self: BaseChainDB, transactions: openarray[Transaction]) = proc persistTransactions*(self: BaseChainDB, blockNumber: BlockNumber, transactions: openArray[Transaction]) =
var tr = initHexaryTrie(self.db) var trie = initHexaryTrie(self.db)
for i, t in transactions: for idx, tx in transactions:
tr.put(rlp.encode(i).toRange, rlp.encode(t).toRange) let
encodedTx = rlp.encode(tx).toRange
txHash = keccak256.digest(encodedTx.toOpenArray)
txKey: TransactionKey = (blockNumber, idx)
trie.put(rlp.encode(idx).toRange, encodedTx)
self.db.put(transactionHashToBlockKey(txHash).toOpenArray, rlp.encode(txKey))
iterator getBlockTransactionData(self: BaseChainDB, transactionRoot: Hash256): BytesRange = iterator getBlockTransactionData(self: BaseChainDB, transactionRoot: Hash256): BytesRange =
var transactionDb = initHexaryTrie(self.db, transactionRoot) var transactionDb = initHexaryTrie(self.db, transactionRoot)

View File

@ -110,8 +110,6 @@ 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

View File

@ -163,7 +163,7 @@ method persistBlocks*(c: Chain, headers: openarray[BlockHeader], bodies: openarr
discard c.db.persistHeaderToDb(headers[i]) discard c.db.persistHeaderToDb(headers[i])
assert(c.db.getCanonicalHead().blockHash == headers[i].blockHash) assert(c.db.getCanonicalHead().blockHash == headers[i].blockHash)
c.db.persistTransactions(bodies[i].transactions) c.db.persistTransactions(headers[i].blockNumber, bodies[i].transactions)
transaction.commit() transaction.commit()

View File

@ -10,7 +10,8 @@
import import
strutils, hexstrings, eth_p2p, options, strutils, hexstrings, eth_p2p, options,
../db/[db_chain, state_db, storage_types], ../db/[db_chain, state_db, storage_types],
json_rpc/rpcserver, json, macros, rpc_utils json_rpc/rpcserver, json, macros, rpc_utils,
eth_common
type type
TraceTxOptions = object TraceTxOptions = object
@ -20,6 +21,10 @@ type
proc setupDebugRpc*(chain: BaseChainDB, rpcsrv: RpcServer) = proc setupDebugRpc*(chain: BaseChainDB, rpcsrv: RpcServer) =
proc getBlockBody(hash: Hash256): BlockBody =
if not chain.getBlockBody(hash, result):
raise newException(ValueError, "Error when retrieving block body")
rpcsrv.rpc("debug_traceTransaction") do(data: HexDataStr, options: Option[TraceTxOptions]) -> JsonNode: rpcsrv.rpc("debug_traceTransaction") do(data: HexDataStr, options: Option[TraceTxOptions]) -> JsonNode:
## The traceTransaction debugging method will attempt to run the transaction in the exact ## 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 ## same manner as it was executed on the network. It will replay any transaction that may
@ -32,5 +37,9 @@ proc setupDebugRpc*(chain: BaseChainDB, rpcsrv: RpcServer) =
## * disableStorage: BOOL. Setting this to true will disable storage capture (default = false). ## * disableStorage: BOOL. Setting this to true will disable storage capture (default = false).
## * disableMemory: BOOL. Setting this to true will disable memory 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). ## * disableStack: BOOL. Setting this to true will disable stack capture (default = false).
var hashData = strToHash(data.string) let
txHash = strToHash(data.string)
txDetails = chain.getTransactionKey(txHash)
blockHeader = chain.getBlockHeader(txDetails.blockNumber)
blockHash = chain.getBlockHash(txDetails.blockNumber)
blockBody = getBlockBody(blockHash)