From b1995a60e34fa66c753583517ad3dbc789affcc4 Mon Sep 17 00:00:00 2001 From: jairajdev Date: Tue, 16 Apr 2024 23:36:21 +0545 Subject: [PATCH] Added confirmOrChallenge value exist check in the appliedReceipt --- src/Data/Collector.ts | 16 +++++++++++++--- src/shardeum/verifyAppReceiptData.ts | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Data/Collector.ts b/src/Data/Collector.ts index 52228219..78ea3a4f 100644 --- a/src/Data/Collector.ts +++ b/src/Data/Collector.ts @@ -518,8 +518,13 @@ export const storeReceiptData = async ( if (verifyData) { const existingReceipt = await Receipt.queryReceiptByReceiptId(txId) - if (existingReceipt && receipt.appliedReceipt.confirmOrChallenge.message === 'challenge') { - // If the existing receipt is confirmed, but the new receipt is challenged, then skip the new receipt + if ( + existingReceipt && + receipt.appliedReceipt && + receipt.appliedReceipt.confirmOrChallenge && + receipt.appliedReceipt.confirmOrChallenge.message === 'challenge' + ) { + // If the existing receipt is confirmed, and the new receipt is challenged, then skip saving the new receipt if (existingReceipt.appliedReceipt.confirmOrChallenge.message === 'confirm') { Logger.mainLogger.error( `Existing receipt is confirmed, but new receipt is challenged ${txId}, ${receipt.cycle}, ${timestamp}` @@ -608,7 +613,12 @@ export const storeReceiptData = async ( ) txDataList.push({ txId, timestamp }) // If the receipt is a challenge, then skip updating its accounts data or transaction data - if (appliedReceipt.confirmOrChallenge.message === 'challenge') continue + if ( + appliedReceipt && + appliedReceipt.confirmOrChallenge && + appliedReceipt.confirmOrChallenge.message === 'challenge' + ) + continue for (const account of accounts) { const accObj: Account.AccountCopy = { accountId: account.accountId, diff --git a/src/shardeum/verifyAppReceiptData.ts b/src/shardeum/verifyAppReceiptData.ts index e82bf0d4..9c5371d9 100644 --- a/src/shardeum/verifyAppReceiptData.ts +++ b/src/shardeum/verifyAppReceiptData.ts @@ -36,6 +36,10 @@ export const verifyAppReceiptData = async ( // If the existing receipt is challenged and the new receipt is confirmed, overwrite the existing receipt let skipAppReceiptCheck = false if ( + existingReceipt.appliedReceipt && + existingReceipt.appliedReceipt.confirmOrChallenge && + receipt.appliedReceipt && + receipt.appliedReceipt.confirmOrChallenge && existingReceipt.appliedReceipt.confirmOrChallenge.message === 'challenge' && receipt.appliedReceipt.confirmOrChallenge.message === 'confirm' ) {