mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-23 09:18:29 +00:00
some cleanup
This commit is contained in:
parent
9db4e9296a
commit
a6bf970b1b
@ -149,6 +149,10 @@ proc getBlockBody*(self: BaseChainDB, blockHash: Hash256, output: var BlockBody)
|
||||
else:
|
||||
result = false
|
||||
|
||||
proc getBlockBody*(self: BaseChainDB, hash: Hash256): BlockBody =
|
||||
if not self.getBlockBody(hash, result):
|
||||
raise newException(ValueError, "Error when retrieving block body")
|
||||
|
||||
proc getTransactionKey*(self: BaseChainDB, transactionHash: Hash256): tuple[blockNumber: BlockNumber, index: int] {.inline.} =
|
||||
let
|
||||
tx = self.db.get(transactionHashToBlockKey(transactionHash).toOpenArray).toRange
|
||||
|
@ -1,41 +1,6 @@
|
||||
import ../db/[db_chain, state_db], eth_common, chronicles, ../vm_state, ../vm_types, ../transaction, ranges,
|
||||
../vm/[computation, interpreter_dispatch, message, interpreter/vm_forks], ../constants, stint, nimcrypto,
|
||||
../vm_state_transactions, sugar, ../utils, eth_trie/db, ../tracer, ./executor, json,
|
||||
eth_bloom, strutils
|
||||
|
||||
type
|
||||
# TODO: these types need to be removed
|
||||
# once eth_bloom and eth_common sync'ed
|
||||
Bloom = eth_common.BloomFilter
|
||||
LogsBloom = eth_bloom.BloomFilter
|
||||
|
||||
# TODO: move these three receipt procs below somewhere else more appropriate
|
||||
func logsBloom(logs: openArray[Log]): LogsBloom =
|
||||
for log in logs:
|
||||
result.incl log.address
|
||||
for topic in log.topics:
|
||||
result.incl topic
|
||||
|
||||
func createBloom*(receipts: openArray[Receipt]): Bloom =
|
||||
var bloom: LogsBloom
|
||||
for receipt in receipts:
|
||||
bloom.value = bloom.value or logsBloom(receipt.logs).value
|
||||
result = bloom.value.toByteArrayBE
|
||||
|
||||
proc makeReceipt(vmState: BaseVMState, stateRoot: Hash256, cumulativeGasUsed: GasInt, fork = FkFrontier): Receipt =
|
||||
if fork < FkByzantium:
|
||||
# TODO: which one: vmState.blockHeader.stateRoot or stateDb.rootHash?
|
||||
# currently, vmState.blockHeader.stateRoot vs stateDb.rootHash can be different
|
||||
# need to wait #188 solved
|
||||
result.stateRootOrStatus = hashOrStatus(stateRoot)
|
||||
else:
|
||||
# TODO: post byzantium fork use status instead of rootHash
|
||||
let vmStatus = true # success or failure
|
||||
result.stateRootOrStatus = hashOrStatus(vmStatus)
|
||||
|
||||
result.cumulativeGasUsed = cumulativeGasUsed
|
||||
result.logs = vmState.getAndClearLogEntries()
|
||||
result.bloom = logsBloom(result.logs).value.toByteArrayBE
|
||||
../vm/[computation, interpreter_dispatch, message], ../constants, stint, nimcrypto,
|
||||
../vm_state_transactions, sugar, ../utils, eth_trie/db, ../tracer, ./executor
|
||||
|
||||
type
|
||||
Chain* = ref object of AbstractChainDB
|
||||
|
@ -1,8 +1,8 @@
|
||||
import ../db/[db_chain, state_db], ../transaction, eth_common,
|
||||
../vm_state, ../vm_types, ../vm_state_transactions, ranges,
|
||||
chronicles, ../vm/[computation, interpreter_dispatch, message],
|
||||
../rpc/hexstrings, byteutils, nimcrypto,
|
||||
../utils, ../constants
|
||||
import eth_common, ranges, chronicles,
|
||||
../db/[db_chain, state_db],
|
||||
../utils, ../constants, ../transaction,
|
||||
../vm_state, ../vm_types, ../vm_state_transactions,
|
||||
../vm/[computation, interpreter_dispatch, message]
|
||||
|
||||
proc processTransaction*(db: var AccountStateDB, t: Transaction, sender: EthAddress, vmState: BaseVMState): UInt256 =
|
||||
## Process the transaction, write the results to db.
|
||||
@ -68,6 +68,39 @@ proc processTransaction*(db: var AccountStateDB, t: Transaction, sender: EthAddr
|
||||
db.addBalance(sender, refund)
|
||||
return gasUsed.u256 * t.gasPrice.u256
|
||||
|
||||
type
|
||||
# TODO: these types need to be removed
|
||||
# once eth_bloom and eth_common sync'ed
|
||||
Bloom = eth_common.BloomFilter
|
||||
LogsBloom = eth_bloom.BloomFilter
|
||||
|
||||
# TODO: move these three receipt procs below somewhere else more appropriate
|
||||
func logsBloom(logs: openArray[Log]): LogsBloom =
|
||||
for log in logs:
|
||||
result.incl log.address
|
||||
for topic in log.topics:
|
||||
result.incl topic
|
||||
|
||||
func createBloom*(receipts: openArray[Receipt]): Bloom =
|
||||
var bloom: LogsBloom
|
||||
for receipt in receipts:
|
||||
bloom.value = bloom.value or logsBloom(receipt.logs).value
|
||||
result = bloom.value.toByteArrayBE
|
||||
|
||||
proc makeReceipt(vmState: BaseVMState, stateRoot: Hash256, cumulativeGasUsed: GasInt, fork = FkFrontier): Receipt =
|
||||
if fork < FkByzantium:
|
||||
# TODO: which one: vmState.blockHeader.stateRoot or stateDb.rootHash?
|
||||
# currently, vmState.blockHeader.stateRoot vs stateDb.rootHash can be different
|
||||
# need to wait #188 solved
|
||||
result.stateRootOrStatus = hashOrStatus(stateRoot)
|
||||
else:
|
||||
# TODO: post byzantium fork use status instead of rootHash
|
||||
let vmStatus = true # success or failure
|
||||
result.stateRootOrStatus = hashOrStatus(vmStatus)
|
||||
|
||||
result.cumulativeGasUsed = cumulativeGasUsed
|
||||
result.logs = vmState.getAndClearLogEntries()
|
||||
result.bloom = logsBloom(result.logs).value.toByteArrayBE
|
||||
|
||||
proc processBlock*(chainDB: BaseChainDB, head, header: BlockHeader, body: BlockBody, vmState: BaseVMState): bool =
|
||||
let blockReward = 5.u256 * pow(10.u256, 18) # 5 ETH
|
||||
|
@ -8,10 +8,10 @@
|
||||
# those terms.
|
||||
|
||||
import
|
||||
strutils, hexstrings, eth_p2p, options,
|
||||
../db/[db_chain, state_db, storage_types],
|
||||
json_rpc/rpcserver, json, macros, rpc_utils,
|
||||
eth_common, ../tracer, ../vm_state, ../vm_types
|
||||
strutils, json, options,
|
||||
json_rpc/rpcserver, rpc_utils, eth_common,
|
||||
hexstrings, ../tracer, ../vm_state, ../vm_types,
|
||||
../db/[db_chain, storage_types]
|
||||
|
||||
type
|
||||
TraceOptions = object
|
||||
@ -33,10 +33,6 @@ proc traceOptionsToFlags(options: Option[TraceOptions]): set[TracerFlags] =
|
||||
|
||||
proc setupDebugRpc*(chainDB: BaseChainDB, rpcsrv: RpcServer) =
|
||||
|
||||
proc getBlockBody(hash: Hash256): BlockBody =
|
||||
if not chainDB.getBlockBody(hash, result):
|
||||
raise newException(ValueError, "Error when retrieving block body")
|
||||
|
||||
rpcsrv.rpc("debug_traceTransaction") do(data: EthHashStr, options: Option[TraceOptions]) -> 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
|
||||
@ -55,7 +51,7 @@ proc setupDebugRpc*(chainDB: BaseChainDB, rpcsrv: RpcServer) =
|
||||
txDetails = chainDB.getTransactionKey(txHash)
|
||||
blockHeader = chainDB.getBlockHeader(txDetails.blockNumber)
|
||||
blockHash = chainDB.getBlockHash(txDetails.blockNumber)
|
||||
blockBody = getBlockBody(blockHash)
|
||||
blockBody = chainDB.getBlockBody(blockHash)
|
||||
flags = traceOptionsToFlags(options)
|
||||
|
||||
traceTransaction(chainDB, blockHeader, blockBody, txDetails.index, flags)
|
||||
@ -69,7 +65,7 @@ proc setupDebugRpc*(chainDB: BaseChainDB, rpcsrv: RpcServer) =
|
||||
let
|
||||
header = chainDB.headerFromTag(quantityTag)
|
||||
blockHash = chainDB.getBlockHash(header.blockNumber)
|
||||
body = getBlockBody(blockHash)
|
||||
body = chainDB.getBlockBody(blockHash)
|
||||
|
||||
dumpBlockState(chainDB, header, body)
|
||||
|
||||
@ -82,7 +78,7 @@ proc setupDebugRpc*(chainDB: BaseChainDB, rpcsrv: RpcServer) =
|
||||
h = data.toHash
|
||||
header = chainDB.getBlockHeader(h)
|
||||
blockHash = chainDB.getBlockHash(header.blockNumber)
|
||||
body = getBlockBody(blockHash)
|
||||
body = chainDB.getBlockBody(blockHash)
|
||||
|
||||
dumpBlockState(chainDB, header, body)
|
||||
|
||||
@ -96,7 +92,7 @@ proc setupDebugRpc*(chainDB: BaseChainDB, rpcsrv: RpcServer) =
|
||||
let
|
||||
header = chainDB.headerFromTag(quantityTag)
|
||||
blockHash = chainDB.getBlockHash(header.blockNumber)
|
||||
body = getBlockBody(blockHash)
|
||||
body = chainDB.getBlockBody(blockHash)
|
||||
flags = traceOptionsToFlags(options)
|
||||
|
||||
traceBlock(chainDB, header, body, flags)
|
||||
@ -111,7 +107,7 @@ proc setupDebugRpc*(chainDB: BaseChainDB, rpcsrv: RpcServer) =
|
||||
h = data.toHash
|
||||
header = chainDB.getBlockHeader(h)
|
||||
blockHash = chainDB.getBlockHash(header.blockNumber)
|
||||
body = getBlockBody(blockHash)
|
||||
body = chainDB.getBlockBody(blockHash)
|
||||
flags = traceOptionsToFlags(options)
|
||||
|
||||
traceBlock(chainDB, header, body, flags)
|
||||
|
@ -6,25 +6,15 @@
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import
|
||||
unittest, json, os, tables, strutils, times, strformat,
|
||||
eth_common, byteutils, nimcrypto, rlp,
|
||||
eth_trie/[hexary, db, defs]
|
||||
|
||||
import
|
||||
./test_helpers,
|
||||
../nimbus/db/[storage_types, db_chain, state_db, capturedb],
|
||||
../nimbus/[transaction, rpc/hexstrings],
|
||||
../nimbus/[tracer, vm_types, utils]
|
||||
unittest, json, os, tables, strformat,
|
||||
eth_common, byteutils, eth_trie/db,
|
||||
./test_helpers, ../nimbus/db/db_chain, ../nimbus/[tracer, vm_types]
|
||||
|
||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus)
|
||||
|
||||
suite "tracer json tests":
|
||||
jsonTest("TracerTests", testFixture)
|
||||
|
||||
proc getBlockBody(chainDB: BaseChainDB, hash: Hash256): BlockBody =
|
||||
if not chainDB.getBlockBody(hash, result):
|
||||
raise newException(ValueError, "Error when retrieving block body")
|
||||
|
||||
# use tracerTestGen.nim to generate additional test data
|
||||
|
||||
proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus) =
|
||||
|
@ -1,14 +1,7 @@
|
||||
import
|
||||
json, eth_common,
|
||||
stint, strutils, times, byteutils, nimcrypto,
|
||||
chronicles, options, os, rlp
|
||||
|
||||
import
|
||||
eth_trie/[hexary, db, defs],
|
||||
../nimbus/db/[storage_types, db_chain, state_db, capturedb],
|
||||
../nimbus/[genesis, utils, config],
|
||||
../nimbus/[p2p/chain, transaction, rpc/hexstrings],
|
||||
../nimbus/[tracer, vm_types]
|
||||
json, os, eth_common, stint, chronicles,
|
||||
eth_trie/[db], ../nimbus/db/[db_chain, capturedb],
|
||||
../nimbus/[tracer, vm_types, config]
|
||||
|
||||
const backEnd {.strdefine.} = "lmdb"
|
||||
|
||||
@ -19,10 +12,6 @@ elif backEnd == "rocksdb":
|
||||
else:
|
||||
import ../nimbus/db/backends/lmdb_backend
|
||||
|
||||
proc getBlockBody(chainDB: BaseChainDB, hash: Hash256): BlockBody =
|
||||
if not chainDB.getBlockBody(hash, result):
|
||||
raise newException(ValueError, "Error when retrieving block body")
|
||||
|
||||
proc dumpTest(chainDB: BaseChainDB, blockNumber: int) =
|
||||
var
|
||||
memoryDB = newMemoryDB()
|
||||
|
Loading…
x
Reference in New Issue
Block a user