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

Start incrementing jsonrpc message id from random number #5371

Merged
merged 4 commits into from
Aug 25, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,4 @@ Released with 1.0.0-beta.37 code base.

### Fixed
- Browser builds support polyfills (#5031) (#5053) (#4659) (#4767)
- Start incrementing jsonrpc.id from random number (#5327)
14 changes: 11 additions & 3 deletions packages/web3-core-requestmanager/src/jsonrpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

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

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

// advance message ID
Jsonrpc.messageId++;
if(Jsonrpc.messageId === Number.MAX_SAFE_INTEGER) {
// if the maximum safe integer has been reached, restart from a random number
Jsonrpc.messageId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)
}
else {
// advance message ID
Jsonrpc.messageId++;
}

return {
jsonrpc: '2.0',
Expand Down