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:
Advaita Saha 2024-10-04 13:29:38 +05:30 committed by GitHub
parent 56724536a4
commit e7782fd669
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 79 additions and 8 deletions

View File

@ -266,7 +266,7 @@ jobs:
echo "Test Result: $test_result"
echo "$test_status"
if [ "$test_result" == "success" ]; then
if ! [ "$test_result" == "success" ]; then
echo ""
echo "Failed Test Task Status:"
echo "$failed_test_status"

View File

@ -24,8 +24,8 @@ tx_spammer_params:
tx_spammer_extra_args: ["--accounts=1", "--txcount=1"]
mev_type: null
assertoor_params:
image: "ethpandaops/assertoor:latest"
run_stability_check: true
image: "ethpandaops/assertoor:master"
run_stability_check: false
run_block_proposal_check: true
run_transaction_test: true
run_blob_transaction_test: false

View File

@ -28,9 +28,9 @@ type
forkJunction: BlockNumber
hash: Hash256
BlockDesc = object
blk: EthBlock
receipts: seq[Receipt]
BlockDesc* = object
blk*: EthBlock
receipts*: seq[Receipt]
BaseDesc = object
hash: Hash256
@ -45,6 +45,7 @@ type
db: CoreDbRef
com: CommonRef
blocks: Table[Hash256, BlockDesc]
txRecords: Table[Hash256, (Hash256, uint64)]
baseHash: Hash256
baseHeader: BlockHeader
cursorHash: Hash256
@ -158,6 +159,9 @@ proc validateBlock(c: ForkedChainRef,
if updateCursor:
c.updateCursor(blk, move(res.value))
for i, tx in blk.transactions:
c.txRecords[rlpHash(tx)] = (blk.header.blockHash, uint64(i))
ok()
proc replaySegment(c: ForkedChainRef, target: Hash256) =
@ -218,6 +222,8 @@ proc writeBaggage(c: ForkedChainRef, target: Hash256) =
c.db.persistWithdrawals(
header.withdrawalsRoot.expect("WithdrawalsRoot should be verified before"),
blk.blk.withdrawals.get)
for tx in blk.blk.transactions:
c.txRecords.del(rlpHash(tx))
prevHash = header.parentHash
func updateBase(c: ForkedChainRef,
@ -405,6 +411,7 @@ proc newForkedChain*(com: CommonRef,
cursorHeader: baseHeader,
extraValidation: extraValidation,
baseDistance: baseDistance,
txRecords: initTable[Hash256, (Hash256, uint64)]()
)
# update global syncStart
@ -570,6 +577,12 @@ func latestHash*(c: ForkedChainRef): Hash256 =
func baseNumber*(c: ForkedChainRef): BlockNumber =
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 =
c.blocks.withValue(c.cursorHash, val) do:
return val.blk
@ -633,7 +646,19 @@ proc blockByHash*(c: ForkedChainRef, blockHash: Hash256): Opt[EthBlock] =
do:
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:
var prevHash = c.cursorHash
while prevHash != c.baseHash:

View File

@ -22,6 +22,7 @@ import
../transaction/call_evm,
../evm/evm_errors,
./rpc_types,
./rpc_utils,
./filters,
./server_api_helpers
@ -258,3 +259,48 @@ proc setupServerAPI*(api: ServerAPIRef, server: RpcServer) =
res = rpcCallEvm(args, header, api.com).valueOr:
raise newException(ValueError, "rpcCallEvm error: " & $error.code)
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