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: Do not retry RPC requests on 4xx errors #5634

Merged
merged 3 commits into from
Apr 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ contract StatefulTest {
let _res = context.call_private_function(context.this_address(), selector, [owner.to_field(), value]);
}

#[aztec(private)]
#[aztec(initializer)]
fn wrong_constructor() {
let selector = FunctionSelector::from_signature("not_exists(Field)");
let _res = context.call_public_function(context.this_address(), selector, [42]);
}

#[aztec(public)]
#[aztec(initializer)]
fn public_constructor(owner: AztecAddress, value: Field) {
Expand Down
22 changes: 22 additions & 0 deletions yarn-project/end-to-end/src/e2e_deploy_contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing';
import {
AztecAddress,
type AztecNode,
Expand All @@ -15,8 +16,10 @@ import {
SignerlessWallet,
TxStatus,
type Wallet,
createPXEClient,
getContractClassFromArtifact,
getContractInstanceFromDeployParams,
makeFetch,
} from '@aztec/aztec.js';
import {
broadcastPrivateFunction,
Expand Down Expand Up @@ -157,6 +160,25 @@ describe('e2e_deploy_contract', () => {
}, 90_000);
});

describe('regressions', () => {
beforeAll(async () => {
({ teardown, pxe, logger, wallet, sequencer, aztecNode } = await setup());
}, 100_000);
afterAll(() => teardown());

it('fails properly when trying to deploy a contract with a failing constructor with a pxe client with retries', async () => {
const { PXE_URL } = process.env;
if (!PXE_URL) {
return;
}
const pxeClient = createPXEClient(PXE_URL, makeFetch([1, 2, 3], false));
const [wallet] = await getDeployedTestAccountsWallets(pxeClient);
await expect(
StatefulTestContract.deployWithOpts({ wallet, method: 'wrong_constructor' }).send().deployed(),
).rejects.toThrow(/Unknown function/);
});
});

describe('private initialization', () => {
beforeAll(async () => {
({ teardown, pxe, logger, wallet, sequencer, aztecNode } = await setup());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const log = createDebugLogger('json-rpc:json_rpc_client');
* @param host - The host URL.
* @param method - The RPC method name.
* @param body - The RPC payload.
* @param noRetry - Whether to throw a `NoRetryError` in case the response is not ok and the body contains an error
* @param noRetry - Whether to throw a `NoRetryError` in case the response is a 5xx error and the body contains an error
* message (see `retry` function for more details).
* @returns The parsed JSON response, or throws an error.
*/
Expand Down Expand Up @@ -56,7 +56,7 @@ export async function defaultFetch(
throw new Error(`Failed to parse body as JSON: ${resp.text()}`);
}
if (!resp.ok) {
if (noRetry) {
if (noRetry || (resp.status >= 400 && resp.status < 500)) {
throw new NoRetryError('(JSON-RPC PROPAGATED) ' + responseJson.error.message);
} else {
throw new Error('(JSON-RPC PROPAGATED) ' + responseJson.error.message);
Expand Down
Loading