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

feat: Add proven flag to sent tx wait opts #7950

Merged
merged 1 commit into from
Aug 13, 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
10 changes: 10 additions & 0 deletions yarn-project/aztec.js/src/contract/sent_tx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,15 @@ describe('SentTx', () => {
pxe.getSyncStatus.mockResolvedValue({ blocks: 19, notes: { '0x1': 19, '0x2': 19 } });
await expect(sentTx.wait({ timeout: 1, interval: 0.4 })).rejects.toThrow(/dropped/);
});

it('waits for the tx to be proven', async () => {
const waitOpts = { timeout: 1, interval: 0.4, waitForNotesSync: false, proven: true, provenTimeout: 2 };
pxe.getProvenBlockNumber.mockResolvedValue(10);
await expect(sentTx.wait(waitOpts)).rejects.toThrow(/timeout/i);

pxe.getProvenBlockNumber.mockResolvedValue(20);
const actual = await sentTx.wait(waitOpts);
expect(actual).toEqual(txReceipt);
});
});
});
20 changes: 20 additions & 0 deletions yarn-project/aztec.js/src/contract/sent_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ import { type FieldsOf } from '@aztec/foundation/types';
export type WaitOpts = {
/** The maximum time (in seconds) to wait for the transaction to be mined. Defaults to 60. */
timeout?: number;
/** The maximum time (in seconds) to wait for the transaction to be proven. Defaults to 600. */
provenTimeout?: number;
/** The time interval (in seconds) between retries to fetch the transaction receipt. Defaults to 1. */
interval?: number;
/** Whether to wait for the tx to be proven. */
proven?: boolean;
/**
* Whether to wait for the PXE Service to sync all notes up to the block in which this tx was mined.
* If false, then any queries that depend on state set by this transaction may return stale data. Defaults to true.
Expand All @@ -28,6 +32,7 @@ export type WaitOpts = {

export const DefaultWaitOpts: WaitOpts = {
timeout: 60,
provenTimeout: 600,
interval: 1,
waitForNotesSync: true,
debug: false,
Expand Down Expand Up @@ -78,6 +83,9 @@ export class SentTx {
`Transaction ${await this.getTxHash()} was ${receipt.status}. Reason: ${receipt.error ?? 'unknown'}`,
);
}
if (opts?.proven && receipt.blockNumber !== undefined) {
await this.waitForProven(receipt.blockNumber, opts);
}
if (opts?.debug) {
const txHash = await this.getTxHash();
const tx = (await this.pxe.getTxEffect(txHash))!;
Expand Down Expand Up @@ -144,4 +152,16 @@ export class SentTx {
opts?.interval ?? DefaultWaitOpts.interval,
);
}

protected async waitForProven(minedBlock: number, opts?: WaitOpts) {
return await retryUntil(
async () => {
const provenBlock = await this.pxe.getProvenBlockNumber();
return provenBlock >= minedBlock ? provenBlock : undefined;
},
'isProven',
opts?.provenTimeout ?? DefaultWaitOpts.provenTimeout,
opts?.interval ?? DefaultWaitOpts.interval,
);
}
}
Loading