mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-03-01 04:10:45 +00:00
avoid loading full block for logs (#2772)
the block body is not needed until a match and parts of the block body are not needed at all.
This commit is contained in:
parent
2c612d4357
commit
fc5ea1c236
@ -163,16 +163,18 @@ proc setupServerAPI*(api: ServerAPIRef, server: RpcServer) =
|
||||
|
||||
proc getLogsForBlock(
|
||||
chain: ForkedChainRef,
|
||||
blk: Block,
|
||||
header: Header,
|
||||
opts: FilterOptions): seq[FilterLog]
|
||||
{.gcsafe, raises: [RlpError].} =
|
||||
if headerBloomFilter(blk.header, opts.address, opts.topics):
|
||||
let receipts = chain.db.getReceipts(blk.header.receiptsRoot)
|
||||
if headerBloomFilter(header, opts.address, opts.topics):
|
||||
let
|
||||
receipts = chain.db.getReceipts(header.receiptsRoot)
|
||||
txs = chain.db.getTransactions(header.txRoot)
|
||||
# Note: this will hit assertion error if number of block transactions
|
||||
# do not match block receipts.
|
||||
# Although this is fine as number of receipts should always match number
|
||||
# of transactions
|
||||
let logs = deriveLogs(blk.header, blk.transactions, receipts)
|
||||
let logs = deriveLogs(header, txs, receipts)
|
||||
let filteredLogs = filterLogs(logs, opts.address, opts.topics)
|
||||
return filteredLogs
|
||||
else:
|
||||
@ -190,9 +192,9 @@ proc setupServerAPI*(api: ServerAPIRef, server: RpcServer) =
|
||||
|
||||
while blockNum <= finish:
|
||||
let
|
||||
blk = chain.blockByNumber(blockNum).valueOr:
|
||||
header = chain.headerByNumber(blockNum).valueOr:
|
||||
return logs
|
||||
filtered = chain.getLogsForBlock(blk, opts)
|
||||
filtered = chain.getLogsForBlock(header, opts)
|
||||
logs.add(filtered)
|
||||
blockNum = blockNum + 1
|
||||
return logs
|
||||
@ -210,9 +212,9 @@ proc setupServerAPI*(api: ServerAPIRef, server: RpcServer) =
|
||||
if filterOptions.blockHash.isSome():
|
||||
let
|
||||
hash = filterOptions.blockHash.expect("blockHash")
|
||||
blk = api.chain.blockByHash(hash).valueOr:
|
||||
header = api.chain.headerByHash(hash).valueOr:
|
||||
raise newException(ValueError, "Block not found")
|
||||
return getLogsForBlock(api.chain, blk, filterOptions)
|
||||
return getLogsForBlock(api.chain, header, filterOptions)
|
||||
else:
|
||||
# TODO: do something smarter with tags. It would be the best if
|
||||
# tag would be an enum (Earliest, Latest, Pending, Number), and all operations
|
||||
|
Loading…
x
Reference in New Issue
Block a user