Early exit from some of CoreDbRef functions if nothing to do (#2259)

* Early exit from some of CoreDbRef functions if nothing to do

* More exits

* persistReceipts early exit if nothing to do
This commit is contained in:
andri lim 2024-06-01 21:54:02 +07:00 committed by GitHub
parent 1565c57ae6
commit f9765e617b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 0 deletions

View File

@ -122,6 +122,9 @@ iterator getBlockTransactionData*(
transactionRoot: Hash256;
): Blob =
block body:
if transactionRoot == EMPTY_ROOT_HASH:
break body
let
ctx = db.ctx
col = ctx.newColumn(CtTxs, transactionRoot).valueOr:
@ -170,6 +173,9 @@ iterator getWithdrawalsData*(
withdrawalsRoot: Hash256;
): Blob =
block body:
if withdrawalsRoot == EMPTY_ROOT_HASH:
break body
let
ctx = db.ctx
col = ctx.newColumn(CtWithdrawals, withdrawalsRoot).valueOr:
@ -198,6 +204,9 @@ iterator getReceipts*(
): Receipt
{.gcsafe, raises: [RlpError].} =
block body:
if receiptRoot == EMPTY_ROOT_HASH:
break body
let
ctx = db.ctx
col = ctx.newColumn(CtReceipts, receiptRoot).valueOr:
@ -562,6 +571,10 @@ proc persistTransactions*(
): Hash256 =
const
info = "persistTransactions()"
if transactions.len == 0:
return EMPTY_ROOT_HASH
let
mpt = db.ctx.getMpt(CtTxs)
kvt = db.newKvt()
@ -690,6 +703,9 @@ proc persistWithdrawals*(
withdrawals: openArray[Withdrawal];
): Hash256 =
const info = "persistWithdrawals()"
if withdrawals.len == 0:
return EMPTY_ROOT_HASH
let mpt = db.ctx.getMpt(CtWithdrawals)
for idx, wd in withdrawals:
mpt.merge(rlp.encode(idx), rlp.encode(wd)).isOkOr:
@ -836,6 +852,9 @@ proc persistReceipts*(
receipts: openArray[Receipt];
): Hash256 =
const info = "persistReceipts()"
if receipts.len == 0:
return EMPTY_ROOT_HASH
let mpt = db.ctx.getMpt(CtReceipts)
for idx, rec in receipts:
mpt.merge(rlp.encode(idx), rlp.encode(rec)).isOkOr: