mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-11 21:04:11 +00:00
rpc fixes and enable kurtosis (#2681)
* fix: rpc can't serve blocks in db * shift db access to forkedchainref * cleanup * kurtosis test fix, should fail + eth_getTransactionReceipt * remove kurtosis not + cleanup * alter CI check to pass * optimize impl * cleanup * fix loop case
This commit is contained in:
parent
56724536a4
commit
e7782fd669
2
.github/workflows/kurtosis.yml
vendored
2
.github/workflows/kurtosis.yml
vendored
@ -266,7 +266,7 @@ jobs:
|
|||||||
echo "Test Result: $test_result"
|
echo "Test Result: $test_result"
|
||||||
echo "$test_status"
|
echo "$test_status"
|
||||||
|
|
||||||
if [ "$test_result" == "success" ]; then
|
if ! [ "$test_result" == "success" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "Failed Test Task Status:"
|
echo "Failed Test Task Status:"
|
||||||
echo "$failed_test_status"
|
echo "$failed_test_status"
|
||||||
|
@ -24,8 +24,8 @@ tx_spammer_params:
|
|||||||
tx_spammer_extra_args: ["--accounts=1", "--txcount=1"]
|
tx_spammer_extra_args: ["--accounts=1", "--txcount=1"]
|
||||||
mev_type: null
|
mev_type: null
|
||||||
assertoor_params:
|
assertoor_params:
|
||||||
image: "ethpandaops/assertoor:latest"
|
image: "ethpandaops/assertoor:master"
|
||||||
run_stability_check: true
|
run_stability_check: false
|
||||||
run_block_proposal_check: true
|
run_block_proposal_check: true
|
||||||
run_transaction_test: true
|
run_transaction_test: true
|
||||||
run_blob_transaction_test: false
|
run_blob_transaction_test: false
|
||||||
|
@ -28,9 +28,9 @@ type
|
|||||||
forkJunction: BlockNumber
|
forkJunction: BlockNumber
|
||||||
hash: Hash256
|
hash: Hash256
|
||||||
|
|
||||||
BlockDesc = object
|
BlockDesc* = object
|
||||||
blk: EthBlock
|
blk*: EthBlock
|
||||||
receipts: seq[Receipt]
|
receipts*: seq[Receipt]
|
||||||
|
|
||||||
BaseDesc = object
|
BaseDesc = object
|
||||||
hash: Hash256
|
hash: Hash256
|
||||||
@ -45,6 +45,7 @@ type
|
|||||||
db: CoreDbRef
|
db: CoreDbRef
|
||||||
com: CommonRef
|
com: CommonRef
|
||||||
blocks: Table[Hash256, BlockDesc]
|
blocks: Table[Hash256, BlockDesc]
|
||||||
|
txRecords: Table[Hash256, (Hash256, uint64)]
|
||||||
baseHash: Hash256
|
baseHash: Hash256
|
||||||
baseHeader: BlockHeader
|
baseHeader: BlockHeader
|
||||||
cursorHash: Hash256
|
cursorHash: Hash256
|
||||||
@ -158,6 +159,9 @@ proc validateBlock(c: ForkedChainRef,
|
|||||||
if updateCursor:
|
if updateCursor:
|
||||||
c.updateCursor(blk, move(res.value))
|
c.updateCursor(blk, move(res.value))
|
||||||
|
|
||||||
|
for i, tx in blk.transactions:
|
||||||
|
c.txRecords[rlpHash(tx)] = (blk.header.blockHash, uint64(i))
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
proc replaySegment(c: ForkedChainRef, target: Hash256) =
|
proc replaySegment(c: ForkedChainRef, target: Hash256) =
|
||||||
@ -218,6 +222,8 @@ proc writeBaggage(c: ForkedChainRef, target: Hash256) =
|
|||||||
c.db.persistWithdrawals(
|
c.db.persistWithdrawals(
|
||||||
header.withdrawalsRoot.expect("WithdrawalsRoot should be verified before"),
|
header.withdrawalsRoot.expect("WithdrawalsRoot should be verified before"),
|
||||||
blk.blk.withdrawals.get)
|
blk.blk.withdrawals.get)
|
||||||
|
for tx in blk.blk.transactions:
|
||||||
|
c.txRecords.del(rlpHash(tx))
|
||||||
prevHash = header.parentHash
|
prevHash = header.parentHash
|
||||||
|
|
||||||
func updateBase(c: ForkedChainRef,
|
func updateBase(c: ForkedChainRef,
|
||||||
@ -405,6 +411,7 @@ proc newForkedChain*(com: CommonRef,
|
|||||||
cursorHeader: baseHeader,
|
cursorHeader: baseHeader,
|
||||||
extraValidation: extraValidation,
|
extraValidation: extraValidation,
|
||||||
baseDistance: baseDistance,
|
baseDistance: baseDistance,
|
||||||
|
txRecords: initTable[Hash256, (Hash256, uint64)]()
|
||||||
)
|
)
|
||||||
|
|
||||||
# update global syncStart
|
# update global syncStart
|
||||||
@ -570,6 +577,12 @@ func latestHash*(c: ForkedChainRef): Hash256 =
|
|||||||
func baseNumber*(c: ForkedChainRef): BlockNumber =
|
func baseNumber*(c: ForkedChainRef): BlockNumber =
|
||||||
c.baseHeader.number
|
c.baseHeader.number
|
||||||
|
|
||||||
|
func txRecords*(c: ForkedChainRef, txHash: Hash256): (Hash256, uint64) =
|
||||||
|
c.txRecords.getOrDefault(txHash, (Hash256.default, 0'u64))
|
||||||
|
|
||||||
|
func memoryBlock*(c: ForkedChainRef, blockHash: Hash256): BlockDesc =
|
||||||
|
c.blocks.getOrDefault(blockHash)
|
||||||
|
|
||||||
proc latestBlock*(c: ForkedChainRef): EthBlock =
|
proc latestBlock*(c: ForkedChainRef): EthBlock =
|
||||||
c.blocks.withValue(c.cursorHash, val) do:
|
c.blocks.withValue(c.cursorHash, val) do:
|
||||||
return val.blk
|
return val.blk
|
||||||
@ -633,7 +646,19 @@ proc blockByHash*(c: ForkedChainRef, blockHash: Hash256): Opt[EthBlock] =
|
|||||||
do:
|
do:
|
||||||
return Opt.none(EthBlock)
|
return Opt.none(EthBlock)
|
||||||
|
|
||||||
func blockByNumber*(c: ForkedChainRef, number: BlockNumber): Result[EthBlock, string] =
|
proc blockByNumber*(c: ForkedChainRef, number: BlockNumber): Result[EthBlock, string] =
|
||||||
|
if number > c.cursorHeader.number:
|
||||||
|
return err("Requested block number not exists: " & $number)
|
||||||
|
|
||||||
|
if number < c.baseHeader.number:
|
||||||
|
var
|
||||||
|
header: Header
|
||||||
|
body: BlockBody
|
||||||
|
if c.db.getBlockHeader(number, header) and c.db.getBlockBody(header, body):
|
||||||
|
return ok(EthBlock.init(move(header), move(body)))
|
||||||
|
else:
|
||||||
|
return err("Failed to get block with number: " & $number)
|
||||||
|
|
||||||
shouldNotKeyError:
|
shouldNotKeyError:
|
||||||
var prevHash = c.cursorHash
|
var prevHash = c.cursorHash
|
||||||
while prevHash != c.baseHash:
|
while prevHash != c.baseHash:
|
||||||
@ -685,4 +710,4 @@ proc isCanonicalAncestor*(c: ForkedChainRef,
|
|||||||
# canonical chain in database should have a marker
|
# canonical chain in database should have a marker
|
||||||
# and the marker is block number
|
# and the marker is block number
|
||||||
var canonHash: common.Hash256
|
var canonHash: common.Hash256
|
||||||
c.db.getBlockHash(blockNumber, canonHash) and canonHash == blockHash
|
c.db.getBlockHash(blockNumber, canonHash) and canonHash == blockHash
|
@ -22,6 +22,7 @@ import
|
|||||||
../transaction/call_evm,
|
../transaction/call_evm,
|
||||||
../evm/evm_errors,
|
../evm/evm_errors,
|
||||||
./rpc_types,
|
./rpc_types,
|
||||||
|
./rpc_utils,
|
||||||
./filters,
|
./filters,
|
||||||
./server_api_helpers
|
./server_api_helpers
|
||||||
|
|
||||||
@ -258,3 +259,48 @@ proc setupServerAPI*(api: ServerAPIRef, server: RpcServer) =
|
|||||||
res = rpcCallEvm(args, header, api.com).valueOr:
|
res = rpcCallEvm(args, header, api.com).valueOr:
|
||||||
raise newException(ValueError, "rpcCallEvm error: " & $error.code)
|
raise newException(ValueError, "rpcCallEvm error: " & $error.code)
|
||||||
res.output
|
res.output
|
||||||
|
|
||||||
|
server.rpc("eth_getTransactionReceipt") do(data: Web3Hash) -> ReceiptObject:
|
||||||
|
## Returns the receipt of a transaction by transaction hash.
|
||||||
|
##
|
||||||
|
## data: Hash of a transaction.
|
||||||
|
## Returns ReceiptObject or nil when no receipt was found.
|
||||||
|
var
|
||||||
|
idx = 0'u64
|
||||||
|
prevGasUsed = GasInt(0)
|
||||||
|
|
||||||
|
let
|
||||||
|
txHash = data.ethHash()
|
||||||
|
(blockhash, txid) = api.chain.txRecords(txHash)
|
||||||
|
|
||||||
|
if blockhash == zeroHash32:
|
||||||
|
# Receipt in database
|
||||||
|
let txDetails = api.chain.db.getTransactionKey(txHash)
|
||||||
|
if txDetails.index < 0:
|
||||||
|
return nil
|
||||||
|
|
||||||
|
let header = api.chain.headerByNumber(txDetails.blockNumber).valueOr:
|
||||||
|
raise newException(ValueError, "Block not found")
|
||||||
|
var tx: Transaction
|
||||||
|
if not api.chain.db.getTransactionByIndex(header.txRoot, uint16(txDetails.index), tx):
|
||||||
|
return nil
|
||||||
|
|
||||||
|
for receipt in api.chain.db.getReceipts(header.receiptsRoot):
|
||||||
|
let gasUsed = receipt.cumulativeGasUsed - prevGasUsed
|
||||||
|
prevGasUsed = receipt.cumulativeGasUsed
|
||||||
|
if idx == txDetails.index:
|
||||||
|
return populateReceipt(receipt, gasUsed, tx, txDetails.index, header)
|
||||||
|
idx.inc
|
||||||
|
else:
|
||||||
|
# Receipt in memory
|
||||||
|
let blkdesc = api.chain.memoryBlock(blockhash)
|
||||||
|
|
||||||
|
while idx <= txid:
|
||||||
|
let receipt = blkdesc.receipts[idx]
|
||||||
|
let gasUsed = receipt.cumulativeGasUsed - prevGasUsed
|
||||||
|
prevGasUsed = receipt.cumulativeGasUsed
|
||||||
|
|
||||||
|
if txid == idx:
|
||||||
|
return populateReceipt(receipt, gasUsed, blkdesc.blk.transactions[txid], txid, blkdesc.blk.header)
|
||||||
|
|
||||||
|
idx.inc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user