-
Notifications
You must be signed in to change notification settings - Fork 148
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 node selection improvement #1815
Conversation
Signed-off-by: Petar Tonev <[email protected]>
Signed-off-by: Petar Tonev <[email protected]>
Signed-off-by: Petar Tonev <[email protected]>
src/client/ManagedNetwork.js
Outdated
let node = this.getNode(); | ||
if ( | ||
!keys.has(node.getKey()) || | ||
!nodeAddresses.has(node.address._address) | ||
) { | ||
if (!keys.has(node.getKey())) { | ||
keys.add(node.getKey()); | ||
nodeAddresses.add(node.address._address); | ||
nodes.push(node); | ||
} else { | ||
i--; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we even need this? in Go we are just assigning the first count
nodes for the transaction. Even if we don't want this and we want random nodes there are better more deterministic ways to get them. For example filling an array with all healthy nodes and picking and removing 1 by 1 out of it in a random fashion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do this check to ensure that we don't add the same node twice or more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but we can do this with a deterministic approach, always getting count
nodes. I understand it's just the way it was till now, but if we are changing this we could as well just do this a bit better. Something like:
const healthy = // copy the healthy nodes array
const chosenNodes = []
for (let i = 0; i < count; i++) {
const idx = Math.floor(Math.random() * healthy.length);
// add to the chosen nodes
// remove from healthy array copy
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The process is improved with the latest commit
Signed-off-by: Petar Tonev <[email protected]>
SonarCloud Quality Gate failed. 0 Bugs No Coverage information Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
Description:
This PR improves the node selection of the SDK
Related issue(s):
Fixes #1813
Notes for reviewer:
Checklist