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