From 29bcdf2ca27c26fda475ab544f02258cb92a90d3 Mon Sep 17 00:00:00 2001 From: Viki Val Date: Sun, 3 Mar 2024 17:56:32 -0700 Subject: [PATCH 1/3] Update subsquid.yml --- .github/workflows/subsquid.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/subsquid.yml b/.github/workflows/subsquid.yml index 74e0785..c9d7d53 100644 --- a/.github/workflows/subsquid.yml +++ b/.github/workflows/subsquid.yml @@ -8,10 +8,10 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 20 - name: install @subsquid/cli run: npm install --location=global @subsquid/cli - name: auth subsquid From 02a751b3d1db3b41d69b6352032f5c48bc9b3d14 Mon Sep 17 00:00:00 2001 From: daiagi Date: Thu, 7 Mar 2024 15:44:44 +0900 Subject: [PATCH 2/3] retry delete token, don't panic --- src/mappings/shared/token/tokenAPI.ts | 5 ++-- src/mappings/shared/token/utils.ts | 40 +++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/mappings/shared/token/tokenAPI.ts b/src/mappings/shared/token/tokenAPI.ts index bb041af..11d2c7d 100644 --- a/src/mappings/shared/token/tokenAPI.ts +++ b/src/mappings/shared/token/tokenAPI.ts @@ -3,7 +3,7 @@ import md5 from 'md5' import { Store } from '../../utils/types' import { CollectionEntity as CE, NFTEntity as NE, TokenEntity as TE } from '../../../model' import { debug } from '../../utils/logger' -import { OPERATION, generateTokenId, tokenName } from './utils' +import { OPERATION, attemptDelete, generateTokenId, tokenName } from './utils' export class TokenAPI { constructor(private store: Store) {} @@ -57,8 +57,7 @@ export class TokenAPI { if (updatedCount === 0) { debug(OPERATION, { deleteEmptyToken: `delete empty token ${token.id}` }) - - await emOf(this.store).delete(TE, token.id) + await attemptDelete(this.store, token.id) } } diff --git a/src/mappings/shared/token/utils.ts b/src/mappings/shared/token/utils.ts index 167c844..c590b5a 100644 --- a/src/mappings/shared/token/utils.ts +++ b/src/mappings/shared/token/utils.ts @@ -1,6 +1,8 @@ import md5 from 'md5' -import { NFTEntity as NE } from '../../../model' -import { warn } from '../../utils/logger' +import { emOf } from '@kodadot1/metasquid/entity' +import { Store } from '@subsquid/typeorm-store' +import { NFTEntity as NE, TokenEntity as TE } from '../../../model' +import { warn, debug } from '../../utils/logger' import { CHAIN } from '../../../environment' export const OPERATION = 'TokenEntity' as any @@ -30,3 +32,37 @@ export const tokenName = (nftName: string | undefined | null, collectionId: stri return doNotAlter ? nftName : nftName.replace(/([#_]\d+$)/g, '') } + +const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) + +export const attemptDelete = async (store: Store, tokenId: string, attempt = 1, maxAttempts = 3) => { + try { + // Attempt to delete the token + await emOf(store).delete(TE, tokenId) + debug(OPERATION, { deleteTokenSuccess: `Successfully deleted token ${tokenId}.` }) + } catch (error) { + // Check if the maximum number of attempts has been reached + if (attempt >= maxAttempts) { + // Log final failure after reaching the max attempts + debug(OPERATION, { + finalDeleteTokenFailure: `Failed to delete token ${tokenId} after ${maxAttempts} attempts.`, + error, + }) + } else { + // Calculate wait time for exponential backoff + const waitTime = Math.pow(2, attempt) * 500 + debug(OPERATION, { + retryDeleteToken: `Attempt ${attempt}: Failed to delete token ${tokenId}. Retrying in ${ + waitTime / 1000 + } seconds...`, + error, + }) + + // Wait before retrying + await sleep(waitTime) + + // Recursively try to delete again with incremented attempt count + await attemptDelete(store, tokenId, attempt + 1, maxAttempts) + } + } +} From d1773b142dcf6c3978c6d4984658941111a731e9 Mon Sep 17 00:00:00 2001 From: daiagi Date: Thu, 7 Mar 2024 18:14:44 +0900 Subject: [PATCH 3/3] simple try/catch --- src/mappings/shared/token/tokenAPI.ts | 11 ++++++-- src/mappings/shared/token/utils.ts | 39 ++------------------------- 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/src/mappings/shared/token/tokenAPI.ts b/src/mappings/shared/token/tokenAPI.ts index 11d2c7d..e8b9f70 100644 --- a/src/mappings/shared/token/tokenAPI.ts +++ b/src/mappings/shared/token/tokenAPI.ts @@ -3,7 +3,7 @@ import md5 from 'md5' import { Store } from '../../utils/types' import { CollectionEntity as CE, NFTEntity as NE, TokenEntity as TE } from '../../../model' import { debug } from '../../utils/logger' -import { OPERATION, attemptDelete, generateTokenId, tokenName } from './utils' +import { OPERATION, generateTokenId, tokenName } from './utils' export class TokenAPI { constructor(private store: Store) {} @@ -57,7 +57,14 @@ export class TokenAPI { if (updatedCount === 0) { debug(OPERATION, { deleteEmptyToken: `delete empty token ${token.id}` }) - await attemptDelete(this.store, token.id) + try { + await emOf(this.store).delete(TE, token.id) + } catch (error) { + debug(OPERATION, { + deleteEmptyToken: `Failed to delete token ${token.id}`, + error, + }) + } } } diff --git a/src/mappings/shared/token/utils.ts b/src/mappings/shared/token/utils.ts index c590b5a..615c2ac 100644 --- a/src/mappings/shared/token/utils.ts +++ b/src/mappings/shared/token/utils.ts @@ -1,8 +1,6 @@ import md5 from 'md5' -import { emOf } from '@kodadot1/metasquid/entity' -import { Store } from '@subsquid/typeorm-store' -import { NFTEntity as NE, TokenEntity as TE } from '../../../model' -import { warn, debug } from '../../utils/logger' +import { NFTEntity as NE } from '../../../model' +import { warn } from '../../utils/logger' import { CHAIN } from '../../../environment' export const OPERATION = 'TokenEntity' as any @@ -33,36 +31,3 @@ export const tokenName = (nftName: string | undefined | null, collectionId: stri return doNotAlter ? nftName : nftName.replace(/([#_]\d+$)/g, '') } -const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) - -export const attemptDelete = async (store: Store, tokenId: string, attempt = 1, maxAttempts = 3) => { - try { - // Attempt to delete the token - await emOf(store).delete(TE, tokenId) - debug(OPERATION, { deleteTokenSuccess: `Successfully deleted token ${tokenId}.` }) - } catch (error) { - // Check if the maximum number of attempts has been reached - if (attempt >= maxAttempts) { - // Log final failure after reaching the max attempts - debug(OPERATION, { - finalDeleteTokenFailure: `Failed to delete token ${tokenId} after ${maxAttempts} attempts.`, - error, - }) - } else { - // Calculate wait time for exponential backoff - const waitTime = Math.pow(2, attempt) * 500 - debug(OPERATION, { - retryDeleteToken: `Attempt ${attempt}: Failed to delete token ${tokenId}. Retrying in ${ - waitTime / 1000 - } seconds...`, - error, - }) - - // Wait before retrying - await sleep(waitTime) - - // Recursively try to delete again with incremented attempt count - await attemptDelete(store, tokenId, attempt + 1, maxAttempts) - } - } -}