Skip to content
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

Merged
merged 4 commits into from
Aug 25, 2023
Merged

Conversation

petreze
Copy link
Contributor

@petreze petreze commented Aug 23, 2023

Description:
This PR improves the node selection of the SDK

Related issue(s):

Fixes #1813

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@petreze petreze requested a review from rokn August 23, 2023 08:39
Comment on lines 244 to 249
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--;
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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
}

Copy link
Contributor Author

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

@petreze petreze requested a review from rokn August 24, 2023 11:13
@sonarcloud
Copy link

sonarcloud bot commented Aug 25, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 3 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@petreze petreze merged commit 4a106ad into develop Aug 25, 2023
@petreze petreze deleted the fix/node-selection-improvement branch August 25, 2023 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

INVALID_NODE_ACCOUNT returned when submitting a signed transaction from different client objects
2 participants