Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/Add retry and set submittx to submit and wait #282

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/chains/xrpl/xrpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -505,15 +508,28 @@ export class XRPL implements XRPLish {

async getTransaction(txHash: string): Promise<TxResponse> {
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() {
Expand Down
7 changes: 5 additions & 2 deletions src/connectors/xrpl/xrpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -568,7 +571,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 };
}
Expand Down
Loading