From bf250ad3b0a5c4fb8d36c1d7b70b65a5eea2aaf7 Mon Sep 17 00:00:00 2001 From: diegodelrieue Date: Tue, 28 Feb 2023 11:39:27 +0100 Subject: [PATCH 1/3] make wait time dynamic to speed up QA and testing work --- packages/extension/.env.example | 1 + packages/extension/src/background/index.ts | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/extension/.env.example b/packages/extension/.env.example index e6fe74127..c7be16b18 100644 --- a/packages/extension/.env.example +++ b/packages/extension/.env.example @@ -19,3 +19,4 @@ ARGENT_X_STATUS_URL= #ARGENT_SHIELD_NETWORK_ID= #FEATURE_MULTISIG= #FEATURE_VERIFIED_DAPPS= +#WAIT_TIME= \ No newline at end of file diff --git a/packages/extension/src/background/index.ts b/packages/extension/src/background/index.ts index 8d35280b0..2734efdb6 100644 --- a/packages/extension/src/background/index.ts +++ b/packages/extension/src/background/index.ts @@ -55,18 +55,20 @@ browser.alarms.onAlarm.addListener(async (alarm) => { let hasInFlightTransactions = await transactionTracker.update() // the config below will run transaction updates 4x per minute, if there are in-flight transactions - // it will update on second 0, 15, 30 and 45 - const maxRetries = 3 // max 3 retries - const waitTimeInS = 15 // wait 15 seconds between retries - - let runs = 0 - while (hasInFlightTransactions && runs < maxRetries) { + // By default it will update on second 0, 15, 30 and 45 but by updating WAIT_TIME we can change the number of executions + const maxExecutionTimeInMs = 60000 // 1 minute max execution time + const waitTimeInS = parseInt(process.env.WAIT_TIME ?? "15") // use environment variable for wait time, default to 15 seconds + const startTime = Date.now() + + while ( + hasInFlightTransactions && + Date.now() - startTime < maxExecutionTimeInMs + ) { console.info(`~> waiting ${waitTimeInS}s for transaction updates`) await delay(waitTimeInS * 1000) console.info( "~> fetching transaction updates as pending transactions were detected", ) - runs++ hasInFlightTransactions = await transactionTracker.update() } } From 53e8de187bc4f17df10d7359bf2cdd77a74654d1 Mon Sep 17 00:00:00 2001 From: diegodelrieue Date: Tue, 28 Feb 2023 14:40:18 +0100 Subject: [PATCH 2/3] rename env --- packages/extension/.env.example | 2 +- packages/extension/src/background/index.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/extension/.env.example b/packages/extension/.env.example index c7be16b18..076bb73c5 100644 --- a/packages/extension/.env.example +++ b/packages/extension/.env.example @@ -19,4 +19,4 @@ ARGENT_X_STATUS_URL= #ARGENT_SHIELD_NETWORK_ID= #FEATURE_MULTISIG= #FEATURE_VERIFIED_DAPPS= -#WAIT_TIME= \ No newline at end of file +#TRANSACTION_POLLING_INTERVAL= \ No newline at end of file diff --git a/packages/extension/src/background/index.ts b/packages/extension/src/background/index.ts index 2734efdb6..0a7ad730b 100644 --- a/packages/extension/src/background/index.ts +++ b/packages/extension/src/background/index.ts @@ -57,15 +57,19 @@ browser.alarms.onAlarm.addListener(async (alarm) => { // the config below will run transaction updates 4x per minute, if there are in-flight transactions // By default it will update on second 0, 15, 30 and 45 but by updating WAIT_TIME we can change the number of executions const maxExecutionTimeInMs = 60000 // 1 minute max execution time - const waitTimeInS = parseInt(process.env.WAIT_TIME ?? "15") // use environment variable for wait time, default to 15 seconds + const transactionPollingIntervalInS = parseInt( + process.env.TRANSACTION_POLLING_INTERVAL ?? "15", + ) // use environment variable for wait time, default to 15 seconds const startTime = Date.now() while ( hasInFlightTransactions && Date.now() - startTime < maxExecutionTimeInMs ) { - console.info(`~> waiting ${waitTimeInS}s for transaction updates`) - await delay(waitTimeInS * 1000) + console.info( + `~> waiting ${transactionPollingIntervalInS}s for transaction updates`, + ) + await delay(transactionPollingIntervalInS * 1000) console.info( "~> fetching transaction updates as pending transactions were detected", ) From 550e943dbc0d4bcff6ec0c44c0016f798ca2688b Mon Sep 17 00:00:00 2001 From: diegodelrieue Date: Thu, 2 Mar 2023 10:54:29 +0100 Subject: [PATCH 3/3] fix: make remove env variable and make polling time dynamic based on network --- packages/extension/.env.example | 3 +-- packages/extension/src/background/index.ts | 22 +++++++++++++------ .../src/background/transactions/tracking.ts | 8 +++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/extension/.env.example b/packages/extension/.env.example index 076bb73c5..2f6eff566 100644 --- a/packages/extension/.env.example +++ b/packages/extension/.env.example @@ -18,5 +18,4 @@ ARGENT_X_STATUS_URL= #FEATURE_ARGENT_SHIELD= #ARGENT_SHIELD_NETWORK_ID= #FEATURE_MULTISIG= -#FEATURE_VERIFIED_DAPPS= -#TRANSACTION_POLLING_INTERVAL= \ No newline at end of file +#FEATURE_VERIFIED_DAPPS= \ No newline at end of file diff --git a/packages/extension/src/background/index.ts b/packages/extension/src/background/index.ts index 0a7ad730b..03aa11b80 100644 --- a/packages/extension/src/background/index.ts +++ b/packages/extension/src/background/index.ts @@ -39,6 +39,9 @@ import { handleTransactionMessage } from "./transactions/transactionMessaging" import { handleUdcMessaging } from "./udcMessaging" import { Wallet, sessionStore } from "./wallet" +const DEFAULT_POLLING_INTERVAL = 15 +const LOCAL_POLLING_INTERVAL = 5 + browser.alarms.create("core:transactionTracker:history", { periodInMinutes: 5, // fetch history transactions every 5 minutes from voyager }) @@ -52,20 +55,25 @@ browser.alarms.onAlarm.addListener(async (alarm) => { } if (alarm.name === "core:transactionTracker:update") { console.info("~> fetching transaction updates") - let hasInFlightTransactions = await transactionTracker.update() - + let inFlightTransactions = await transactionTracker.update() // the config below will run transaction updates 4x per minute, if there are in-flight transactions // By default it will update on second 0, 15, 30 and 45 but by updating WAIT_TIME we can change the number of executions const maxExecutionTimeInMs = 60000 // 1 minute max execution time - const transactionPollingIntervalInS = parseInt( - process.env.TRANSACTION_POLLING_INTERVAL ?? "15", - ) // use environment variable for wait time, default to 15 seconds + let transactionPollingIntervalInS = DEFAULT_POLLING_INTERVAL const startTime = Date.now() while ( - hasInFlightTransactions && + inFlightTransactions.length > 0 && Date.now() - startTime < maxExecutionTimeInMs ) { + const localTransaction = inFlightTransactions.find( + (tx) => tx.account.networkId === "localhost", + ) + if (localTransaction) { + transactionPollingIntervalInS = LOCAL_POLLING_INTERVAL + } else { + transactionPollingIntervalInS = DEFAULT_POLLING_INTERVAL + } console.info( `~> waiting ${transactionPollingIntervalInS}s for transaction updates`, ) @@ -73,7 +81,7 @@ browser.alarms.onAlarm.addListener(async (alarm) => { console.info( "~> fetching transaction updates as pending transactions were detected", ) - hasInFlightTransactions = await transactionTracker.update() + inFlightTransactions = await transactionTracker.update() } } }) diff --git a/packages/extension/src/background/transactions/tracking.ts b/packages/extension/src/background/transactions/tracking.ts index 69c693e2c..36358e79c 100644 --- a/packages/extension/src/background/transactions/tracking.ts +++ b/packages/extension/src/background/transactions/tracking.ts @@ -1,6 +1,6 @@ import { uniqWith } from "lodash-es" -import { getInFlightTransactions } from "../../shared/transactions" +import { Transaction, getInFlightTransactions } from "../../shared/transactions" import { WalletAccount } from "../../shared/wallet.model" import { accountsEqual } from "../../shared/wallet.service" import { getTransactionsUpdate } from "./sources/onchain" @@ -9,7 +9,7 @@ import { transactionsStore } from "./store" export interface TransactionTracker { loadHistory: (accountsToPopulate: WalletAccount[]) => Promise - update: () => Promise + update: () => Promise } export const transactionTracker: TransactionTracker = { @@ -29,8 +29,6 @@ export const transactionTracker: TransactionTracker = { allTransactions, ) await transactionsStore.push(updatedTransactions) - const hasPendingTransactions = - getInFlightTransactions(allTransactions).length > 0 - return hasPendingTransactions + return getInFlightTransactions(allTransactions) }, }