From 3e5113ba0d7c34b16a9acde0e47ec2993f824512 Mon Sep 17 00:00:00 2001 From: peachbits Date: Thu, 8 Aug 2024 00:00:59 -0700 Subject: [PATCH] fixup! Support multiple archive nodes --- src/cosmos/CosmosEngine.ts | 53 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/cosmos/CosmosEngine.ts b/src/cosmos/CosmosEngine.ts index 07cdc6a9f..3778b7a83 100644 --- a/src/cosmos/CosmosEngine.ts +++ b/src/cosmos/CosmosEngine.ts @@ -522,34 +522,32 @@ export class CosmosEngine extends CurrencyEngine< tokenId => this.allTokensMap[tokenId].currencyCode ) ] - - for (const query of txQueryStrings) { - const clientsList: CosmosClients[] = [] - if ( - this.networkInfo.archiveNodes != null && - Date.now() - TWO_WEEKS > this.otherData.archivedTxLastCheckTime - ) { - const sortedArchiveNodes = this.networkInfo.archiveNodes.sort( - (a, b) => - a.blockTimeRangeSeconds.start - b.blockTimeRangeSeconds.start - ) - for (const node of sortedArchiveNodes) { - if ( - node.blockTimeRangeSeconds.end == null || - node.blockTimeRangeSeconds.end > - this.otherData.archivedTxLastCheckTime - ) { - const archiveClients = await createCosmosClients( - this.fetchCors, - rpcWithApiKey(node.endpoint, this.tools.initOptions) - ) - clientsList.push(archiveClients) - } + const clientsList: CosmosClients[] = [] + if ( + this.networkInfo.archiveNodes != null && + Date.now() - TWO_WEEKS > this.otherData.archivedTxLastCheckTime + ) { + const sortedArchiveNodes = this.networkInfo.archiveNodes.sort( + (a, b) => a.blockTimeRangeSeconds.start - b.blockTimeRangeSeconds.start + ) + for (const node of sortedArchiveNodes) { + if ( + node.blockTimeRangeSeconds.end == null || + node.blockTimeRangeSeconds.end > + this.otherData.archivedTxLastCheckTime + ) { + const archiveClients = await createCosmosClients( + this.fetchCors, + rpcWithApiKey(node.endpoint, this.tools.initOptions) + ) + clientsList.push(archiveClients) } } - clientsList.push(this.getClients()) + } + clientsList.push(this.getClients()) - for (const clients of clientsList) { + for (const clients of clientsList) { + for (const query of txQueryStrings) { const { newestTxid, lastTimestamp } = await this.queryTransactionsInner( query, clients @@ -559,7 +557,10 @@ export class CosmosEngine extends CurrencyEngine< this.otherData[query]?.newestTxid !== newestTxid ) { this.otherData[query] = { newestTxid } - this.otherData.archivedTxLastCheckTime = lastTimestamp + this.otherData.archivedTxLastCheckTime = Math.max( + this.otherData.archivedTxLastCheckTime, + lastTimestamp + ) this.walletLocalDataDirty = true } progress += 0.5 / clientsList.length