Skip to content

Feat: (Health check) Check alt_ip if web domain is not accessible #768

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

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

graycraft
Copy link
Member

No description provided.

Copy link

vercel bot commented Apr 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
adamant-im ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 4:23pm

Copy link

github-actions bot commented Apr 20, 2025

Deployed to https://msg-adamant-pr-768.surge.sh 🚀

@graycraft
Copy link
Member Author

@graycraft graycraft marked this pull request as ready for review April 21, 2025 21:08
@graycraft graycraft requested a review from a team as a code owner April 21, 2025 21:08
Comment on lines +63 to +78
/**
* Indicates whether a node with alternative IP is available
*/
altIpAvailable = false
/**
* Indicates whether a node with main URL is available
*/
mainUrlAvailable = true
/**
* Indicates whether node is available.
*/
online = true
/**
* Indicates whether prefer a node with alternative IP or not
*/
preferAltIp = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need preferAltIp? I think we can compute that value based on altIpAvailable and mainUrlAvailable.

mainUrlAvailable altIpAvailable preferAltIp
undefined undefined false
true undefined false
false undefined true
true true false
true false false
false true true
false false false

undefined is a marker that the node's health hasn't been checked yet.

Copy link
Member Author

@graycraft graycraft Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If current logic works as expected, I think we can optimize something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this requires to compare 2 properties mainUrlAvailable and altIpAvailable every time for each network instead of 1 preferAltIp

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skranee @S-FrontendDev what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write unit tests for abstract.node.ts and check all the scenarios? @graycraft

@dvelikiy
Copy link
Collaborator

dvelikiy commented Apr 28, 2025

The logic becomes more complex, it'd be good to write tests for different use-cases.

@adamantmm
Copy link
Member

@S-FrontendDev @bludnic
Please review

Comment on lines +63 to +78
/**
* Indicates whether a node with alternative IP is available
*/
altIpAvailable = false
/**
* Indicates whether a node with main URL is available
*/
mainUrlAvailable = true
/**
* Indicates whether node is available.
*/
online = true
/**
* Indicates whether prefer a node with alternative IP or not
*/
preferAltIp = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write unit tests for abstract.node.ts and check all the scenarios? @graycraft

super(url, 'eth', 'node', NODE_LABELS.EthNode)
}

protected buildClient(): Web3Eth {
return new Web3Eth(new HttpProvider(this.url))
return new Web3Eth(new HttpProvider(this.preferAltIp ? (this.altIp as string) : this.url))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like Web3Eth will always use this.url since buildClient is executed only once. Can you confirm? @graycraft

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is why I added call for this method in the checkHealth below

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be expensive to create a new client on every request. It's better to check if you can use a dynamic URL with the Web3Eth instance. If that's not possible, I'd create two clients during initialization — one for this.url and another for this.altIp.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's reasonable, but more complicated to handle

@adamant-al
Copy link
Member

adamant-al commented May 13, 2025

@graycraft @bludnic
Please update.

@adamant-al
Copy link
Member

@skranee @S-FrontendDev @graycraft
Ps review and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants