From f9765e617b661d4164fc17c0a540ebc1ac26a04c Mon Sep 17 00:00:00 2001 From: andri lim Date: Sat, 1 Jun 2024 21:54:02 +0700 Subject: [PATCH] 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 --- nimbus/db/core_db/core_apps_newapi.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/nimbus/db/core_db/core_apps_newapi.nim b/nimbus/db/core_db/core_apps_newapi.nim index 9506138a5..dac5a7476 100644 --- a/nimbus/db/core_db/core_apps_newapi.nim +++ b/nimbus/db/core_db/core_apps_newapi.nim @@ -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: