From e1c8fd02a66ae3841af857940343129356463511 Mon Sep 17 00:00:00 2001 From: Logan Nguyen Date: Fri, 20 Dec 2024 15:51:00 -0600 Subject: [PATCH] fix: added null check to root hash builder Signed-off-by: Logan Nguyen Revert "fix: added null check to root hash builder" This reverts commit d2653053e52520deb706e363309becf100f7d158. Reapply "fix: added null check to root hash builder" This reverts commit d6b1da8e2361295ffaa1f1fa56c7c99c3d42c9e7. --- .../relay/src/lib/clients/mirrorNodeClient.ts | 9 ++++++--- packages/relay/src/receiptsRootUtils.ts | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/relay/src/lib/clients/mirrorNodeClient.ts b/packages/relay/src/lib/clients/mirrorNodeClient.ts index 997ba76891..bb0990ae8d 100644 --- a/packages/relay/src/lib/clients/mirrorNodeClient.ts +++ b/packages/relay/src/lib/clients/mirrorNodeClient.ts @@ -1,8 +1,8 @@ -/* - +/*- * * Hedera JSON RPC Relay * - * Copyright (C) 2022-2024 Hedera Hashgraph, LLC + * Copyright (C) 2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -620,7 +620,10 @@ export class MirrorNodeClient { requestDetails, ); - await this.cacheService.set(cachedLabel, block, MirrorNodeClient.GET_BLOCK_ENDPOINT, requestDetails); + if (block) { + await this.cacheService.set(cachedLabel, block, MirrorNodeClient.GET_BLOCK_ENDPOINT, requestDetails); + } + return block; } diff --git a/packages/relay/src/receiptsRootUtils.ts b/packages/relay/src/receiptsRootUtils.ts index c9603de699..727eef4ba8 100644 --- a/packages/relay/src/receiptsRootUtils.ts +++ b/packages/relay/src/receiptsRootUtils.ts @@ -21,8 +21,9 @@ import { RLP } from '@ethereumjs/rlp'; import { Trie } from '@ethereumjs/trie'; import { bytesToInt, concatBytes, hexToBytes, intToBytes, intToHex } from '@ethereumjs/util'; -import { EthImpl } from './lib/eth'; + import { prepend0x } from './formatters'; +import { EthImpl } from './lib/eth'; import { Log } from './lib/model'; import { LogsBloomUtils } from './logsBloomUtils'; @@ -93,16 +94,25 @@ export class ReceiptsRootUtils { public static buildReceiptRootHashes(txHashes: string[], contractResults: any[], logs: Log[]): IReceiptRootHash[] { const receipts: IReceiptRootHash[] = []; - for (let i in txHashes) { + for (const i in txHashes) { const txHash: string = txHashes[i]; const logsPerTx: Log[] = logs.filter((log) => log.transactionHash == txHash); const crPerTx: any[] = contractResults.filter((cr) => cr.hash == txHash); + + let transactionIndex: any = null; + if (crPerTx.length && crPerTx[0].transaction_index != null) { + transactionIndex = intToHex(crPerTx[0].transaction_index); + } else if (logsPerTx.length) { + transactionIndex = logsPerTx[0].transactionIndex; + } + receipts.push({ - transactionIndex: crPerTx.length ? intToHex(crPerTx[0].transaction_index) : logsPerTx[0].transactionIndex, + transactionIndex, type: crPerTx.length && crPerTx[0].type ? intToHex(crPerTx[0].type) : null, root: crPerTx.length ? crPerTx[0].root : EthImpl.zeroHex32Byte, status: crPerTx.length ? crPerTx[0].status : EthImpl.oneHex, - cumulativeGasUsed: crPerTx.length ? intToHex(crPerTx[0].block_gas_used) : EthImpl.zeroHex, + cumulativeGasUsed: + crPerTx.length && crPerTx[0].block_gas_used ? intToHex(crPerTx[0].block_gas_used) : EthImpl.zeroHex, logsBloom: crPerTx.length ? crPerTx[0].bloom : LogsBloomUtils.buildLogsBloom(logs[0].address, logsPerTx[0].topics),