Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 0d38050

Browse files
Start incrementing jsonrpc message id from random number (#5371)
* start incrementing jsonrpc.id from random number
1 parent fce653d commit 0d38050

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,4 @@ Released with 1.0.0-beta.37 code base.
592592

593593
### Fixed
594594
- Browser builds support polyfills (#5031) (#5053) (#4659) (#4767)
595+
- Start incrementing jsonrpc.id from random number (#5327)

packages/web3-core-requestmanager/src/jsonrpc.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
// Initialize Jsonrpc as a simple object with utility functions.
2828
var Jsonrpc = {
29-
messageId: 0
29+
// This is the starting counter for the Jsonrpc.id.
30+
// Pick a random number between 0 and the maximum safe integer
31+
messageId: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)
3032
};
3133

3234
/**
@@ -42,8 +44,14 @@ Jsonrpc.toPayload = function (method, params) {
4244
throw new Error('JSONRPC method should be specified for params: "'+ JSON.stringify(params) +'"!');
4345
}
4446

45-
// advance message ID
46-
Jsonrpc.messageId++;
47+
if(Jsonrpc.messageId === Number.MAX_SAFE_INTEGER) {
48+
// if the maximum safe integer has been reached, restart from a random number
49+
Jsonrpc.messageId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)
50+
}
51+
else {
52+
// advance message ID
53+
Jsonrpc.messageId++;
54+
}
4755

4856
return {
4957
jsonrpc: '2.0',

0 commit comments

Comments
 (0)