Skip to content

Commit

Permalink
fix: removed nonce precheck buffer (#2919) (#2936)
Browse files Browse the repository at this point in the history
* fix: removed nonce precheck buffer



* fix: unwrapped INTERAL_ERROR if error is an instance of JsonRpcError for the WS object



---------

Signed-off-by: Logan Nguyen <[email protected]>
Co-authored-by: Logan Nguyen <[email protected]>
  • Loading branch information
ebadiere and quiet-node authored Sep 3, 2024
1 parent 3f668e4 commit fad7430
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 27 deletions.
1 change: 0 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ Unless you need to set a non-default value, it is recommended to only populate o
| `MIRROR_NODE_URL_HEADER_X_API_KEY` | "" | Authentication for a `MIRROR_NODE_URL` that requires authentication via the `x-api-key` header. |
| `MIRROR_NODE_REQUEST_RETRY_COUNT` | "10" | Maximun amount of retries to repeat on `GetContractResults` `contracts/results/)` requests when fetching contract results after eth_sendRawTransaction submission. \*Note that this in addition and multiplies the configured Axios retries values. |
| `MIRROR_NODE_AGENT_CACHEABLE_DNS` | "true" | Flag to set if the mirror node agent should cacheable DNS lookups, using better-lookup library. |
| `NONCE_PRECHECK_BUFFER` | "1" | The additional buffer range to allow during a relay precheck of nonce. This supports slight fluctuations in network nonce calculations. By default is set to 1. |
| `SDK_REQUEST_TIMEOUT` | "10000" | The complete timeout for running the SDK `execute()` method. This controls the GRPC channel timeout config when querying with network nodes. |
| `CONTRACT_QUERY_TIMEOUT_RETRIES` | "3" | Maximum retries for failed contract call query with timeout exceeded error |
| `TIER_1_RATE_LIMIT` | "100" | Maximum restrictive request count limit used for expensive endpoints rate limiting. |
Expand Down
2 changes: 0 additions & 2 deletions packages/relay/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ export default {
WRONG_NONCE: 'WRONG_NONCE',
},

NONCE_PRECHECK_BUFFER: parseInt(process.env.NONCE_PRECHECK_BUFFER || '1'),

PRECHECK_STATUS_ERROR_STATUS_CODES: {
INVALID_CONTRACT_ID: 16,
CONTRACT_DELETED: 66,
Expand Down
3 changes: 1 addition & 2 deletions packages/relay/src/lib/precheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ export class Precheck {
`${requestIdPrefix} Nonce precheck for sendRawTransaction(tx.nonce=${tx.nonce}, accountInfoNonce=${accountInfoNonce})`,
);

// @ts-ignore
if (accountInfoNonce > tx.nonce + constants.NONCE_PRECHECK_BUFFER) {
if (accountInfoNonce > tx.nonce) {
throw predefined.NONCE_TOO_LOW(tx.nonce, accountInfoNonce);
}
}
Expand Down
13 changes: 0 additions & 13 deletions packages/relay/tests/lib/precheck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,6 @@ describe('Precheck', async function () {
}
});

it(`should NOT fail for low nonce, even if Nonce is 1 (default buffer) below account nonce`, async function () {
const tx = {
...defaultTx,
nonce: 2,
};
const signed = await signTransaction(tx);
const parsedTx = ethers.Transaction.from(signed);

mock.onGet(`accounts/${parsedTx.from}${limitOrderPostFix}`).reply(200, mirrorAccount);

await precheck.nonce(parsedTx, mirrorAccount.ethereum_nonce);
});

it(`should not fail for next nonce`, async function () {
const tx = {
...defaultTx,
Expand Down
8 changes: 6 additions & 2 deletions packages/ws-server/src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import { WS_CONSTANTS } from '../utils/constants';
import WsMetricRegistry from '../metrics/wsMetricRegistry';
import ConnectionLimiter from '../metrics/connectionLimiter';
import { predefined, Relay } from '@hashgraph/json-rpc-relay';
import { Validator } from '@hashgraph/json-rpc-server/dist/validator';
import { handleEthSubsribe, handleEthUnsubscribe } from './eth_subscribe';
import { JsonRpcError, predefined, Relay } from '@hashgraph/json-rpc-relay';
import { MirrorNodeClient } from '@hashgraph/json-rpc-relay/dist/lib/clients';
import jsonResp from '@hashgraph/json-rpc-server/dist/koaJsonRpc/lib/RpcResponse';
import { resolveParams, validateJsonRpcRequest, verifySupportedMethod } from '../utils/utils';
Expand Down Expand Up @@ -84,7 +84,11 @@ const handleSendingRequestsToRelay = async ({

return jsonResp(request.id, null, txRes);
} catch (error: any) {
throw predefined.INTERNAL_ERROR(JSON.stringify(error.message || error));
if (error instanceof JsonRpcError) {
throw error;
} else {
throw predefined.INTERNAL_ERROR(JSON.stringify(error.message || error));
}
}
};

Expand Down
16 changes: 9 additions & 7 deletions packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ describe('@web-socket-batch-2 eth_sendRawTransaction', async function () {
1000,
);
const expectedNonceTooLowError = predefined.NONCE_TOO_LOW(0, signerNonce);
const errObj = response.result;
expect(errObj.code).to.eq(expectedNonceTooLowError.code);
expect(errObj.message).to.contain(expectedNonceTooLowError.message);
expect(response.error.code).to.eq(expectedNonceTooLowError.code);
expect(response.error.message).to.contain(expectedNonceTooLowError.message);
}
});
});
Expand Down Expand Up @@ -221,10 +220,13 @@ describe('@web-socket-batch-2 eth_sendRawTransaction', async function () {
expect(toAccountInfo.evm_address).to.eq(constants.DETERMINISTIC_PROXY_CONTRACT);
expect(receipt.address).to.eq(constants.DETERMINISTIC_PROXY_CONTRACT);
} else {
const errObj = await ethersWsProvider.send(METHOD_NAME, [constants.DETERMINISTIC_DEPLOYER_TRANSACTION]);
const expectedNonceTooLowError = predefined.NONCE_TOO_LOW(0, signerNonce);
expect(errObj.code).to.eq(expectedNonceTooLowError.code);
expect(errObj.message).to.contain(expectedNonceTooLowError.message);
try {
await ethersWsProvider.send(METHOD_NAME, [constants.DETERMINISTIC_DEPLOYER_TRANSACTION]);
} catch (error) {
const expectedNonceTooLowError = predefined.NONCE_TOO_LOW(0, signerNonce);
expect(error.info.error.code).to.eq(expectedNonceTooLowError.code);
expect(error.info.error.message).to.contain(expectedNonceTooLowError.message);
}
}
});
});
Expand Down

0 comments on commit fad7430

Please sign in to comment.