Skip to content

Commit fad7430

Browse files
ebadierequiet-node
andauthored
fix: removed nonce precheck buffer (#2919) (#2936)
* 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]>
1 parent 3f668e4 commit fad7430

File tree

6 files changed

+16
-27
lines changed

6 files changed

+16
-27
lines changed

docs/configuration.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ Unless you need to set a non-default value, it is recommended to only populate o
8383
| `MIRROR_NODE_URL_HEADER_X_API_KEY` | "" | Authentication for a `MIRROR_NODE_URL` that requires authentication via the `x-api-key` header. |
8484
| `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. |
8585
| `MIRROR_NODE_AGENT_CACHEABLE_DNS` | "true" | Flag to set if the mirror node agent should cacheable DNS lookups, using better-lookup library. |
86-
| `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. |
8786
| `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. |
8887
| `CONTRACT_QUERY_TIMEOUT_RETRIES` | "3" | Maximum retries for failed contract call query with timeout exceeded error |
8988
| `TIER_1_RATE_LIMIT` | "100" | Maximum restrictive request count limit used for expensive endpoints rate limiting. |

packages/relay/src/lib/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ export default {
149149
WRONG_NONCE: 'WRONG_NONCE',
150150
},
151151

152-
NONCE_PRECHECK_BUFFER: parseInt(process.env.NONCE_PRECHECK_BUFFER || '1'),
153-
154152
PRECHECK_STATUS_ERROR_STATUS_CODES: {
155153
INVALID_CONTRACT_ID: 16,
156154
CONTRACT_DELETED: 66,

packages/relay/src/lib/precheck.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ export class Precheck {
118118
`${requestIdPrefix} Nonce precheck for sendRawTransaction(tx.nonce=${tx.nonce}, accountInfoNonce=${accountInfoNonce})`,
119119
);
120120

121-
// @ts-ignore
122-
if (accountInfoNonce > tx.nonce + constants.NONCE_PRECHECK_BUFFER) {
121+
if (accountInfoNonce > tx.nonce) {
123122
throw predefined.NONCE_TOO_LOW(tx.nonce, accountInfoNonce);
124123
}
125124
}

packages/relay/tests/lib/precheck.spec.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -419,19 +419,6 @@ describe('Precheck', async function () {
419419
}
420420
});
421421

422-
it(`should NOT fail for low nonce, even if Nonce is 1 (default buffer) below account nonce`, async function () {
423-
const tx = {
424-
...defaultTx,
425-
nonce: 2,
426-
};
427-
const signed = await signTransaction(tx);
428-
const parsedTx = ethers.Transaction.from(signed);
429-
430-
mock.onGet(`accounts/${parsedTx.from}${limitOrderPostFix}`).reply(200, mirrorAccount);
431-
432-
await precheck.nonce(parsedTx, mirrorAccount.ethereum_nonce);
433-
});
434-
435422
it(`should not fail for next nonce`, async function () {
436423
const tx = {
437424
...defaultTx,

packages/ws-server/src/controllers/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import { WS_CONSTANTS } from '../utils/constants';
2222
import WsMetricRegistry from '../metrics/wsMetricRegistry';
2323
import ConnectionLimiter from '../metrics/connectionLimiter';
24-
import { predefined, Relay } from '@hashgraph/json-rpc-relay';
2524
import { Validator } from '@hashgraph/json-rpc-server/dist/validator';
2625
import { handleEthSubsribe, handleEthUnsubscribe } from './eth_subscribe';
26+
import { JsonRpcError, predefined, Relay } from '@hashgraph/json-rpc-relay';
2727
import { MirrorNodeClient } from '@hashgraph/json-rpc-relay/dist/lib/clients';
2828
import jsonResp from '@hashgraph/json-rpc-server/dist/koaJsonRpc/lib/RpcResponse';
2929
import { resolveParams, validateJsonRpcRequest, verifySupportedMethod } from '../utils/utils';
@@ -84,7 +84,11 @@ const handleSendingRequestsToRelay = async ({
8484

8585
return jsonResp(request.id, null, txRes);
8686
} catch (error: any) {
87-
throw predefined.INTERNAL_ERROR(JSON.stringify(error.message || error));
87+
if (error instanceof JsonRpcError) {
88+
throw error;
89+
} else {
90+
throw predefined.INTERNAL_ERROR(JSON.stringify(error.message || error));
91+
}
8892
}
8993
};
9094

packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,8 @@ describe('@web-socket-batch-2 eth_sendRawTransaction', async function () {
164164
1000,
165165
);
166166
const expectedNonceTooLowError = predefined.NONCE_TOO_LOW(0, signerNonce);
167-
const errObj = response.result;
168-
expect(errObj.code).to.eq(expectedNonceTooLowError.code);
169-
expect(errObj.message).to.contain(expectedNonceTooLowError.message);
167+
expect(response.error.code).to.eq(expectedNonceTooLowError.code);
168+
expect(response.error.message).to.contain(expectedNonceTooLowError.message);
170169
}
171170
});
172171
});
@@ -221,10 +220,13 @@ describe('@web-socket-batch-2 eth_sendRawTransaction', async function () {
221220
expect(toAccountInfo.evm_address).to.eq(constants.DETERMINISTIC_PROXY_CONTRACT);
222221
expect(receipt.address).to.eq(constants.DETERMINISTIC_PROXY_CONTRACT);
223222
} else {
224-
const errObj = await ethersWsProvider.send(METHOD_NAME, [constants.DETERMINISTIC_DEPLOYER_TRANSACTION]);
225-
const expectedNonceTooLowError = predefined.NONCE_TOO_LOW(0, signerNonce);
226-
expect(errObj.code).to.eq(expectedNonceTooLowError.code);
227-
expect(errObj.message).to.contain(expectedNonceTooLowError.message);
223+
try {
224+
await ethersWsProvider.send(METHOD_NAME, [constants.DETERMINISTIC_DEPLOYER_TRANSACTION]);
225+
} catch (error) {
226+
const expectedNonceTooLowError = predefined.NONCE_TOO_LOW(0, signerNonce);
227+
expect(error.info.error.code).to.eq(expectedNonceTooLowError.code);
228+
expect(error.info.error.message).to.contain(expectedNonceTooLowError.message);
229+
}
228230
}
229231
});
230232
});

0 commit comments

Comments
 (0)