mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
fixes tracer
This commit is contained in:
parent
890e8e11a4
commit
e3fee70f0a
@ -2,7 +2,7 @@ import
|
|||||||
db/[db_chain, state_db, capturedb], eth_common, utils, json,
|
db/[db_chain, state_db, capturedb], eth_common, utils, json,
|
||||||
constants, vm_state, vm_types, transaction, p2p/executor,
|
constants, vm_state, vm_types, transaction, p2p/executor,
|
||||||
eth_trie/db, nimcrypto, strutils, ranges, ./utils/addresses,
|
eth_trie/db, nimcrypto, strutils, ranges, ./utils/addresses,
|
||||||
sets, chronicles
|
chronicles
|
||||||
|
|
||||||
proc getParentHeader(self: BaseChainDB, header: BlockHeader): BlockHeader =
|
proc getParentHeader(self: BaseChainDB, header: BlockHeader): BlockHeader =
|
||||||
self.getBlockHeader(header.parentHash)
|
self.getBlockHeader(header.parentHash)
|
||||||
@ -30,9 +30,9 @@ proc captureAccount(n: JsonNode, db: AccountStateDB, address: EthAddress, name:
|
|||||||
jaccount["balance"] = %(account.balance.toHex)
|
jaccount["balance"] = %(account.balance.toHex)
|
||||||
|
|
||||||
let code = db.getCode(address)
|
let code = db.getCode(address)
|
||||||
jaccount["codeHash"] = %($account.codeHash)
|
jaccount["codeHash"] = %(($account.codeHash).toLowerAscii)
|
||||||
jaccount["code"] = %(toHex(code.toOpenArray, true))
|
jaccount["code"] = %(toHex(code.toOpenArray, true))
|
||||||
jaccount["storageRoot"] = %($account.storageRoot)
|
jaccount["storageRoot"] = %(($account.storageRoot).toLowerAscii)
|
||||||
|
|
||||||
var storage = newJObject()
|
var storage = newJObject()
|
||||||
for key, value in db.storage(address):
|
for key, value in db.storage(address):
|
||||||
@ -66,8 +66,8 @@ proc traceTransaction*(db: BaseChainDB, header: BlockHeader,
|
|||||||
|
|
||||||
var
|
var
|
||||||
gasUsed: GasInt
|
gasUsed: GasInt
|
||||||
before = newJObject()
|
before = newJArray()
|
||||||
after = newJObject()
|
after = newJArray()
|
||||||
stateDiff = %{"before": before, "after": after}
|
stateDiff = %{"before": before, "after": after}
|
||||||
|
|
||||||
for idx, tx in body.transactions:
|
for idx, tx in body.transactions:
|
||||||
@ -81,10 +81,10 @@ proc traceTransaction*(db: BaseChainDB, header: BlockHeader,
|
|||||||
before.captureAccount(stateDb, header.coinbase, minerName)
|
before.captureAccount(stateDb, header.coinbase, minerName)
|
||||||
|
|
||||||
let txFee = processTransaction(stateDb, tx, sender, vmState)
|
let txFee = processTransaction(stateDb, tx, sender, vmState)
|
||||||
|
stateDb.addBalance(header.coinbase, txFee)
|
||||||
|
|
||||||
if idx == txIndex:
|
if idx == txIndex:
|
||||||
gasUsed = (txFee div tx.gasPrice.u256).truncate(GasInt)
|
gasUsed = (txFee div tx.gasPrice.u256).truncate(GasInt)
|
||||||
vmState.disableTracing()
|
|
||||||
after.captureAccount(stateDb, sender, senderName)
|
after.captureAccount(stateDb, sender, senderName)
|
||||||
after.captureAccount(stateDb, recipient, recipientName)
|
after.captureAccount(stateDb, recipient, recipientName)
|
||||||
after.captureAccount(stateDb, header.coinbase, minerName)
|
after.captureAccount(stateDb, header.coinbase, minerName)
|
||||||
@ -126,21 +126,16 @@ proc dumpBlockState*(db: BaseChainDB, header: BlockHeader, body: BlockBody): Jso
|
|||||||
vmState = newBaseVMState(parent, captureChainDB, {EnableTracing, DisableMemory, DisableStorage})
|
vmState = newBaseVMState(parent, captureChainDB, {EnableTracing, DisableMemory, DisableStorage})
|
||||||
|
|
||||||
var
|
var
|
||||||
before = newJObject()
|
before = newJArray()
|
||||||
after = newJObject()
|
after = newJArray()
|
||||||
stateBefore = newAccountStateDB(captureTrieDB, parent.stateRoot, db.pruneTrie)
|
stateBefore = newAccountStateDB(captureTrieDB, parent.stateRoot, db.pruneTrie)
|
||||||
stateAfter = newAccountStateDB(captureTrieDB, header.stateRoot, db.pruneTrie)
|
stateAfter = newAccountStateDB(captureTrieDB, header.stateRoot, db.pruneTrie)
|
||||||
accountSet = initSet[EthAddress]()
|
|
||||||
|
|
||||||
for tx in body.transactions:
|
for idx, tx in body.transactions:
|
||||||
let sender = tx.getSender
|
let sender = tx.getSender
|
||||||
let recipient = tx.getRecipient
|
let recipient = tx.getRecipient
|
||||||
if sender notin accountSet:
|
before.captureAccount(stateBefore, sender, senderName & $idx)
|
||||||
before.captureAccount(stateBefore, sender, senderName)
|
before.captureAccount(stateBefore, recipient, recipientName & $idx)
|
||||||
accountSet.incl sender
|
|
||||||
if recipient notin accountSet:
|
|
||||||
before.captureAccount(stateBefore, recipient, recipientName)
|
|
||||||
accountSet.incl recipient
|
|
||||||
|
|
||||||
before.captureAccount(stateBefore, header.coinbase, minerName)
|
before.captureAccount(stateBefore, header.coinbase, minerName)
|
||||||
|
|
||||||
@ -149,15 +144,11 @@ proc dumpBlockState*(db: BaseChainDB, header: BlockHeader, body: BlockBody): Jso
|
|||||||
|
|
||||||
discard captureChainDB.processBlock(parent, header, body, vmState)
|
discard captureChainDB.processBlock(parent, header, body, vmState)
|
||||||
|
|
||||||
for tx in body.transactions:
|
for idx, tx in body.transactions:
|
||||||
let sender = tx.getSender
|
let sender = tx.getSender
|
||||||
let recipient = tx.getRecipient
|
let recipient = tx.getRecipient
|
||||||
if sender notin accountSet:
|
after.captureAccount(stateAfter, sender, senderName & $idx)
|
||||||
after.captureAccount(stateAfter, sender, senderName)
|
after.captureAccount(stateAfter, recipient, recipientName & $idx)
|
||||||
accountSet.incl sender
|
|
||||||
if recipient notin accountSet:
|
|
||||||
after.captureAccount(stateAfter, recipient, recipientName)
|
|
||||||
accountSet.incl recipient
|
|
||||||
|
|
||||||
after.captureAccount(stateAfter, header.coinbase, minerName)
|
after.captureAccount(stateAfter, header.coinbase, minerName)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user