Skip to content

Commit

Permalink
Added confirmOrChallenge value exist check in the appliedReceipt
Browse files Browse the repository at this point in the history
  • Loading branch information
jairajdev committed Apr 16, 2024
1 parent 86e1b0c commit b1995a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Data/Collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/shardeum/verifyAppReceiptData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
) {
Expand Down

0 comments on commit b1995a6

Please sign in to comment.