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

Replace pauseAfterSend by retry policy #254

Merged
merged 1 commit into from
Feb 22, 2025
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
6 changes: 0 additions & 6 deletions xsuite/src/proxy/fsproxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import { hexToBase64 } from "../data/utils";
import { getValuesInOrder, Proxy } from "./proxy";

export class FSProxy extends Proxy {
constructor(...[params]: ConstructorParameters<typeof Proxy>) {
params = typeof params === "string" ? { proxyUrl: params } : params;
params.pauseAfterSend ??= 0;
super(params);
}

async getInitialAddresses() {
const res = await this.fetch("/simulator/initial-wallets");
return {
Expand Down
6 changes: 0 additions & 6 deletions xsuite/src/proxy/lsproxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import { EncodableAccount, eAccountUnfiltered } from "../data/encoding";
import { getSerializableAccount, Proxy } from "./proxy";

export class LSProxy extends Proxy {
constructor(...[params]: ConstructorParameters<typeof Proxy>) {
params = typeof params === "string" ? { proxyUrl: params } : params;
params.pauseAfterSend ??= 0;
super(params);
}

async getAllSerializableAccounts() {
const res = await this.fetch("/admin/get-all-accounts");
return (res.accounts as any[])
Expand Down
68 changes: 33 additions & 35 deletions xsuite/src/proxy/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class Proxy {
headers: HeadersInit;
fetcher?: Fetcher;
blockNonce?: number;
pauseAfterSend?: number; // TODO-MvX: remove this when blockchain fixed

constructor(params: ProxyNewParamsExtended) {
params = typeof params === "string" ? { proxyUrl: params } : params;
Expand All @@ -38,7 +37,6 @@ export class Proxy {
this.headers = params.headers ?? {};
this.fetcher = params.fetcher;
this.blockNonce = params.blockNonce;
this.pauseAfterSend = params.pauseAfterSend ?? 1_000;
}

static new(params: ProxyNewParamsExtended) {
Expand Down Expand Up @@ -103,19 +101,11 @@ export class Proxy {
`Only ${txsHashesSent.length} of ${rawTxs.length} transactions were sent. The other ones were invalid.`,
);
}
// TODO-MvX: remove this when blockchain fixed
if (this.pauseAfterSend) {
await new Promise((r) => setTimeout(r, this.pauseAfterSend));
}
return txsHashesSent;
}

async sendTx(tx: BroadTx) {
const res = await this.fetch("/transaction/send", await broadTxToRawTx(tx));
// TODO-MvX: remove this when blockchain fixed
if (this.pauseAfterSend) {
await new Promise((r) => setTimeout(r, this.pauseAfterSend));
}
return res.txHash as string;
}

Expand Down Expand Up @@ -156,31 +146,40 @@ export class Proxy {
// eslint-disable-next-line no-constant-condition
while (true) {
const txDataStartTime = Date.now();
let txData = await this.getTxData(txHash);
const hash: string = txData.hash;
const explorerUrl = `${this.explorerUrl}/transactions/${hash}`;
txData = { explorerUrl, hash, ...txData };
const error = findErrorInTxData(txData);
if (error) {
return {
type: "fail",
errorCode: error.code,
errorMessage: error.message,
tx: txData,
};
let txData: TxData | undefined;
try {
txData = await this.getTxData(txHash);
} catch (e) {
if (elapsedBlocks >= 1) {
throw e;
}
}
const success = findSuccessInTxData(txData, elapsedBlocks);
if (success) {
const gasUsed: number = txData.gasUsed;
const fee: bigint = BigInt(txData.fee);
return {
type: "success",
explorerUrl,
hash,
gasUsed,
fee,
tx: txData,
};
if (txData) {
const hash: string = txData.hash;
const explorerUrl = `${this.explorerUrl}/transactions/${hash}`;
txData = { explorerUrl, hash, ...txData };
const error = findErrorInTxData(txData);
if (error) {
return {
type: "fail",
errorCode: error.code,
errorMessage: error.message,
tx: txData,
};
}
const success = findSuccessInTxData(txData, elapsedBlocks);
if (success) {
const gasUsed: number = txData.gasUsed;
const fee: bigint = BigInt(txData.fee);
return {
type: "success",
explorerUrl,
hash,
gasUsed,
fee,
tx: txData,
};
}
}
elapsedBlocks += await this.beforeNextTxData(txDataStartTime);
}
Expand Down Expand Up @@ -801,7 +800,6 @@ export type ProxyNewParams = {
headers?: HeadersInit;
fetcher?: Fetcher;
blockNonce?: number;
pauseAfterSend?: number; // TODO-MvX: remove this when blockchain fixed
};

export type ProxyNewRealnetParams = Prettify<
Expand Down