2022-11-26 14:59:19 +00:00
|
|
|
# Nimbus
|
2024-02-16 09:08:07 +00:00
|
|
|
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
2022-11-26 14:59:19 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2022-03-21 09:19:19 +00:00
|
|
|
import
|
2024-02-16 09:08:07 +00:00
|
|
|
std/[options, json],
|
2022-12-06 05:55:40 +00:00
|
|
|
../common/common,
|
2022-12-02 04:35:41 +00:00
|
|
|
stew/byteutils,
|
2024-06-17 07:56:39 +00:00
|
|
|
../evm/state,
|
|
|
|
../evm/types,
|
2023-12-12 19:12:56 +00:00
|
|
|
../db/ledger,
|
2023-10-19 06:02:12 +00:00
|
|
|
./utils,
|
|
|
|
./state_dump
|
2022-03-21 09:19:19 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
proc `$`(bloom: Bloom): string =
|
2022-03-21 09:19:19 +00:00
|
|
|
bloom.toHex
|
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
proc `$`(nonce: Bytes8): string =
|
2022-03-21 09:19:19 +00:00
|
|
|
nonce.toHex
|
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
proc `$`(data: seq[byte]): string =
|
2023-07-09 01:46:18 +00:00
|
|
|
if data.len == 0:
|
|
|
|
return "zero length"
|
2022-03-23 14:05:57 +00:00
|
|
|
data.toHex
|
2022-09-28 06:09:33 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
proc debug*(h: Header): string =
|
2024-06-14 07:31:08 +00:00
|
|
|
result.add "parentHash : " & $h.parentHash & "\n"
|
|
|
|
result.add "ommersHash : " & $h.ommersHash & "\n"
|
|
|
|
result.add "coinbase : " & $h.coinbase & "\n"
|
|
|
|
result.add "stateRoot : " & $h.stateRoot & "\n"
|
|
|
|
result.add "txRoot : " & $h.txRoot & "\n"
|
|
|
|
result.add "receiptsRoot : " & $h.receiptsRoot & "\n"
|
|
|
|
result.add "logsBloom : " & $h.logsBloom & "\n"
|
|
|
|
result.add "difficulty : " & $h.difficulty & "\n"
|
|
|
|
result.add "blockNumber : " & $h.number & "\n"
|
|
|
|
result.add "gasLimit : " & $h.gasLimit & "\n"
|
|
|
|
result.add "gasUsed : " & $h.gasUsed & "\n"
|
|
|
|
result.add "timestamp : " & $h.timestamp & "\n"
|
|
|
|
result.add "extraData : " & $h.extraData & "\n"
|
|
|
|
result.add "mixHash : " & $h.mixHash & "\n"
|
|
|
|
result.add "nonce : " & $h.nonce & "\n"
|
|
|
|
result.add "baseFeePerGas.isSome: " & $h.baseFeePerGas.isSome & "\n"
|
|
|
|
if h.baseFeePerGas.isSome:
|
|
|
|
result.add "baseFeePerGas : " & $h.baseFeePerGas.get() & "\n"
|
2022-11-26 14:59:19 +00:00
|
|
|
if h.withdrawalsRoot.isSome:
|
|
|
|
result.add "withdrawalsRoot: " & $h.withdrawalsRoot.get() & "\n"
|
2023-08-04 12:43:30 +00:00
|
|
|
if h.blobGasUsed.isSome:
|
|
|
|
result.add "blobGasUsed : " & $h.blobGasUsed.get() & "\n"
|
|
|
|
if h.excessBlobGas.isSome:
|
|
|
|
result.add "excessBlobGas : " & $h.excessBlobGas.get() & "\n"
|
2023-10-19 00:50:07 +00:00
|
|
|
if h.parentBeaconBlockRoot.isSome:
|
|
|
|
result.add "beaconRoot : " & $h.parentBeaconBlockRoot.get() & "\n"
|
2024-10-26 11:10:54 +00:00
|
|
|
if h.requestsHash.isSome:
|
|
|
|
result.add "requestsHash : " & $h.requestsHash.get() & "\n"
|
2022-11-26 14:59:19 +00:00
|
|
|
result.add "blockHash : " & $blockHash(h) & "\n"
|
2022-12-02 04:35:41 +00:00
|
|
|
|
2023-03-17 13:20:52 +00:00
|
|
|
proc dumpAccounts*(vmState: BaseVMState): JsonNode =
|
2023-10-19 06:02:12 +00:00
|
|
|
%dumpAccounts(vmState.stateDB)
|
2023-03-17 13:20:52 +00:00
|
|
|
|
2023-12-12 19:12:56 +00:00
|
|
|
proc debugAccounts*(stateDB: LedgerRef, addresses: openArray[string]): string =
|
2024-10-16 06:51:38 +00:00
|
|
|
var accountList = newSeq[Address]()
|
2023-10-18 23:55:50 +00:00
|
|
|
for address in addresses:
|
2024-10-16 06:51:38 +00:00
|
|
|
accountList.add Address.fromHex(address)
|
2023-10-18 23:55:50 +00:00
|
|
|
|
2023-10-19 06:02:12 +00:00
|
|
|
(%dumpAccounts(stateDB, accountList)).pretty
|
2023-10-18 23:55:50 +00:00
|
|
|
|
2022-12-02 04:35:41 +00:00
|
|
|
proc debugAccounts*(vmState: BaseVMState): string =
|
2024-10-16 06:51:38 +00:00
|
|
|
var accountList = newSeq[Address]()
|
2022-12-02 04:35:41 +00:00
|
|
|
for address in vmState.stateDB.addresses:
|
|
|
|
accountList.add address
|
|
|
|
|
|
|
|
let res = %{
|
|
|
|
"rootHash": %($vmState.readOnlyStateDB.rootHash),
|
2023-10-19 06:02:12 +00:00
|
|
|
"accounts": %dumpAccounts(vmState.stateDB, accountList),
|
2022-12-02 04:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res.pretty
|
2022-12-06 05:55:40 +00:00
|
|
|
|
|
|
|
proc debug*(vms: BaseVMState): string =
|
2024-10-08 02:37:36 +00:00
|
|
|
result.add "proofOfStake : " & $vms.proofOfStake() & "\n"
|
2022-12-07 16:11:03 +00:00
|
|
|
result.add "parent : " & $vms.parent.blockHash & "\n"
|
2023-10-18 02:16:11 +00:00
|
|
|
result.add "timestamp : " & $vms.blockCtx.timestamp & "\n"
|
2023-09-24 15:25:41 +00:00
|
|
|
result.add "gasLimit : " & $vms.blockCtx.gasLimit & "\n"
|
2024-06-14 07:31:08 +00:00
|
|
|
result.add "baseFeePerGas : " & $vms.blockCtx.baseFeePerGas & "\n"
|
2023-09-24 15:25:41 +00:00
|
|
|
result.add "prevRandao : " & $vms.blockCtx.prevRandao & "\n"
|
|
|
|
result.add "blockDifficulty : " & $vms.blockCtx.difficulty & "\n"
|
|
|
|
result.add "coinbase : " & $vms.blockCtx.coinbase & "\n"
|
|
|
|
result.add "excessBlobGas : " & $vms.blockCtx.excessBlobGas & "\n"
|
2022-12-07 16:11:03 +00:00
|
|
|
result.add "flags : " & $vms.flags & "\n"
|
|
|
|
result.add "receipts.len : " & $vms.receipts.len & "\n"
|
|
|
|
result.add "stateDB.root : " & $vms.stateDB.rootHash & "\n"
|
|
|
|
result.add "cumulativeGasUsed: " & $vms.cumulativeGasUsed & "\n"
|
2023-10-01 07:24:15 +00:00
|
|
|
result.add "tx.origin : " & $vms.txCtx.origin & "\n"
|
|
|
|
result.add "tx.gasPrice : " & $vms.txCtx.gasPrice & "\n"
|
|
|
|
result.add "tx.blobHash.len : " & $vms.txCtx.versionedHashes.len & "\n"
|
|
|
|
result.add "tx.blobBaseFee : " & $vms.txCtx.blobBaseFee & "\n"
|
2022-12-07 16:11:03 +00:00
|
|
|
result.add "fork : " & $vms.fork & "\n"
|
|
|
|
|
|
|
|
proc `$`(x: ChainId): string =
|
|
|
|
$int(x)
|
|
|
|
|
|
|
|
proc `$`(acl: AccessList): string =
|
2023-07-09 01:46:18 +00:00
|
|
|
if acl.len == 0:
|
|
|
|
return "zero length"
|
|
|
|
|
2022-12-07 16:11:03 +00:00
|
|
|
if acl.len > 0:
|
|
|
|
result.add "\n"
|
|
|
|
|
|
|
|
for ap in acl:
|
|
|
|
result.add " * " & $ap.address & "\n"
|
|
|
|
for i, k in ap.storageKeys:
|
|
|
|
result.add " - " & k.toHex
|
|
|
|
if i < ap.storageKeys.len-1:
|
|
|
|
result.add "\n"
|
|
|
|
|
|
|
|
proc debug*(tx: Transaction): string =
|
|
|
|
result.add "txType : " & $tx.txType & "\n"
|
|
|
|
result.add "chainId : " & $tx.chainId & "\n"
|
|
|
|
result.add "nonce : " & $tx.nonce & "\n"
|
|
|
|
result.add "gasPrice : " & $tx.gasPrice & "\n"
|
2024-06-14 07:31:08 +00:00
|
|
|
result.add "maxPriorityFee: " & $tx.maxPriorityFeePerGas & "\n"
|
|
|
|
result.add "maxFee : " & $tx.maxFeePerGas & "\n"
|
2022-12-07 16:11:03 +00:00
|
|
|
result.add "gasLimit : " & $tx.gasLimit & "\n"
|
|
|
|
result.add "to : " & $tx.to & "\n"
|
|
|
|
result.add "value : " & $tx.value & "\n"
|
|
|
|
result.add "payload : " & $tx.payload & "\n"
|
|
|
|
result.add "accessList : " & $tx.accessList & "\n"
|
2023-10-05 03:04:12 +00:00
|
|
|
result.add "maxFeePerBlobGas: " & $tx.maxFeePerBlobGas & "\n"
|
|
|
|
result.add "versionedHashes.len: " & $tx.versionedHashes.len & "\n"
|
2024-05-15 03:07:59 +00:00
|
|
|
result.add "V : " & $tx.V & "\n"
|
|
|
|
result.add "R : " & $tx.R & "\n"
|
|
|
|
result.add "S : " & $tx.S & "\n"
|
2023-10-18 23:55:50 +00:00
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
proc debug*(tx: PooledTransaction): string =
|
|
|
|
result.add debug(tx.tx)
|
2023-10-05 03:04:12 +00:00
|
|
|
if tx.networkPayload.isNil:
|
2023-10-18 23:55:50 +00:00
|
|
|
result.add "networkPaylod : nil\n"
|
2023-10-05 03:04:12 +00:00
|
|
|
else:
|
|
|
|
result.add "networkPaylod : \n"
|
|
|
|
result.add " - blobs : " & $tx.networkPayload.blobs.len & "\n"
|
|
|
|
result.add " - commitments : " & $tx.networkPayload.commitments.len & "\n"
|
|
|
|
result.add " - proofs : " & $tx.networkPayload.proofs.len & "\n"
|
2023-10-18 23:55:50 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
proc debugSum*(h: Header): string =
|
2023-09-28 06:20:12 +00:00
|
|
|
result.add "txRoot : " & $h.txRoot & "\n"
|
|
|
|
result.add "ommersHash : " & $h.ommersHash & "\n"
|
|
|
|
if h.withdrawalsRoot.isSome:
|
|
|
|
result.add "withdrawalsRoot: " & $h.withdrawalsRoot.get() & "\n"
|
|
|
|
result.add "sumHash : " & $sumHash(h) & "\n"
|
|
|
|
|
|
|
|
proc debugSum*(body: BlockBody): string =
|
2024-10-16 01:34:12 +00:00
|
|
|
let ommersHash = keccak256(rlp.encode(body.uncles))
|
2023-09-28 06:20:12 +00:00
|
|
|
let txRoot = calcTxRoot(body.transactions)
|
|
|
|
let wdRoot = if body.withdrawals.isSome:
|
|
|
|
calcWithdrawalsRoot(body.withdrawals.get)
|
|
|
|
else: EMPTY_ROOT_HASH
|
|
|
|
let numwd = if body.withdrawals.isSome:
|
|
|
|
$body.withdrawals.get().len
|
|
|
|
else:
|
|
|
|
"none"
|
|
|
|
result.add "txRoot : " & $txRoot & "\n"
|
|
|
|
result.add "ommersHash : " & $ommersHash & "\n"
|
|
|
|
if body.withdrawals.isSome:
|
|
|
|
result.add "wdRoot : " & $wdRoot & "\n"
|
|
|
|
result.add "num tx : " & $body.transactions.len & "\n"
|
|
|
|
result.add "num uncles : " & $body.uncles.len & "\n"
|
|
|
|
result.add "num wd : " & numwd & "\n"
|
|
|
|
result.add "sumHash : " & $sumHash(body) & "\n"
|