From 1c9a498484dfc0d81ce5e215f61d7ff7134818c2 Mon Sep 17 00:00:00 2001 From: mlguys Date: Sun, 18 Feb 2024 23:22:15 +0700 Subject: [PATCH 1/2] add retry and set submittx to submit and wait --- src/chains/xrpl/xrpl.ts | 32 ++++++++++++++++++++++++-------- src/connectors/xrpl/xrpl.ts | 2 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/chains/xrpl/xrpl.ts b/src/chains/xrpl/xrpl.ts index 408915b7b2..9a3463c7d0 100644 --- a/src/chains/xrpl/xrpl.ts +++ b/src/chains/xrpl/xrpl.ts @@ -21,7 +21,7 @@ import { rootPath } from '../../paths'; import { TokenListType, walletPath, MarketListType } from '../../services/base'; import { ConfigManagerCertPassphrase } from '../../services/config-manager-cert-passphrase'; import { getXRPLConfig } from './xrpl.config'; -// import { logger } from '../../services/logger'; +import { logger } from '../../services/logger'; import { TransactionResponseStatusCode, TokenBalance } from './xrpl.requests'; import { XRPLOrderStorage } from './xrpl.order-storage'; import { OrderTracker } from './xrpl.order-tracker'; @@ -54,6 +54,9 @@ export type Fee = { openLedger: string; }; +const MAX_POLL_RETRY = 5; +const POLL_RETRY_INTERVAL = 300; + export class XRPL implements XRPLish { private static _instances: { [name: string]: XRPL }; public rpcUrl; @@ -505,15 +508,28 @@ export class XRPL implements XRPLish { async getTransaction(txHash: string): Promise { await this.ensureConnection(); - const tx_resp = await this._client.request({ - command: 'tx', - transaction: txHash, - binary: false, - }); + let retryCount = 0; + let result: any = undefined; + while (retryCount < MAX_POLL_RETRY && result === undefined) { + try { + const tx_resp = await this._client.request({ + command: 'tx', + transaction: txHash, + binary: false, + }); - const result = tx_resp; + result = tx_resp; + } catch (error) { + retryCount++; + if (retryCount >= 5) { + throw new Error(`Transaction ${txHash} not found, error: ` + String(error)); + } + logger.info(`Transaction ${txHash} not found, retrying ${retryCount}/${MAX_POLL_RETRY}...`); + await new Promise(resolve => setTimeout(resolve, POLL_RETRY_INTERVAL)); // Add delay + } + } - return result; + return result as TxResponse; } async close() { diff --git a/src/connectors/xrpl/xrpl.ts b/src/connectors/xrpl/xrpl.ts index c1b574ad8f..bff3bb3f23 100644 --- a/src/connectors/xrpl/xrpl.ts +++ b/src/connectors/xrpl/xrpl.ts @@ -568,7 +568,7 @@ export class XRPLCLOB implements CLOBish { const prepared = await this._client.autofill(offer); const signed = wallet.sign(prepared); await this._xrpl.ensureConnection(); - await this._client.submit(signed.tx_blob); + await this._client.submitAndWait(signed.tx_blob); this._isSubmittingTxn = false; return { prepared, signed }; } From 527d8a559dc27017e69677b41e9e99ab17c39419 Mon Sep 17 00:00:00 2001 From: mlguys Date: Sun, 18 Feb 2024 23:56:13 +0700 Subject: [PATCH 2/2] Increase batch for fetching markets --- src/connectors/xrpl/xrpl.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/connectors/xrpl/xrpl.ts b/src/connectors/xrpl/xrpl.ts index bff3bb3f23..75c3de54dd 100644 --- a/src/connectors/xrpl/xrpl.ts +++ b/src/connectors/xrpl/xrpl.ts @@ -44,6 +44,7 @@ import LRUCache from 'lru-cache'; import { getXRPLConfig } from '../../chains/xrpl/xrpl.config'; import { isUndefined } from 'mathjs'; import { convertStringToHex } from './xrpl.utils'; +import { logger } from '../../services/logger'; // const XRP_FACTOR = 1000000; const ORDERBOOK_LIMIT = 50; @@ -145,7 +146,9 @@ export class XRPLCLOB implements CLOBish { loadedMarkets.push(processedMarket); }; - await promiseAllInBatches(getMarket, markets, 1, 1); + logger.info(`Fetching markets for ${this.chain} ${this.network}`); + + await promiseAllInBatches(getMarket, markets, 15, 300); return loadedMarkets; }