Skip to content

Commit

Permalink
Merge pull request #282 from hummingbot/fix/xrpl-add-retry-and-wait-f…
Browse files Browse the repository at this point in the history
…or-submit

Fix/Add retry and set submittx to submit and wait
  • Loading branch information
fengtality authored Feb 19, 2024
2 parents 6cda2dd + 0930e3c commit b8d9764
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
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

0 comments on commit b8d9764

Please sign in to comment.