-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add chain_id
setter to avoid eth_chainId
requests
#2207
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
Conversation
@@ -469,7 +470,14 @@ def blockNumber(self) -> BlockNumber: | |||
|
|||
@property | |||
def chain_id(self) -> int: | |||
return self._chain_id() | |||
if self._default_chain_id is None: | |||
return self._chain_id() |
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.
Would it make sense to set _default_chain_id
here before returning the value?
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.
Yes, it totally would! (That's what I meant with: "As a further improvement, it may be beneficial to cache the result of the first eth_chainId request.")
But that would also change the current behavior and I don't know if that's something that is wanted.
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.
Thanks @medariox! I assume this fixes the chain_id issue where it's requesting the chainId even though it shouldn't? Do you mind adding a test for that?
Sorry for the late reply. I'll try to add some meaningful tests next week. |
If I understand this code correctly, I think I lean towards no, because as it stands right now, when we call And btw if you're seeing Timeout failures on integration tests, feel free to ignore. Those are just flaky. |
I tend to agree with you. I was thinking about the possibility because as long as the endpoint (chain provider) is not changed, there should be no way to get a different result. That's my current understanding of it, but I may be wrong and I don't want to risk breaking anything. 😅 |
The patch seems quite interesting, what is the status? :) |
@BoboTiG |
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.
Thanks @medariox! This looks great! Sorry it took me so long to circle back. I moved the newsfragment to be a feature instead of misc and pulled in the most recent master. I'll also cherry-pick this onto our v5 branch.
We were talking about this internally - does anyone have a use case where you wouldn't use the
Does anyone have any opinions? |
What was wrong?
Every time the
chain_id
property is called, aneth_chainId
request is triggered.How was it fixed?
By manually specifying the
chain_id
, the request can be avoided.As a further improvement, it may be beneficial to cache the result of the first
eth_chainId
request.The current change is intentionally conservative: there is no behavioral change if the setter is not used.
Todo:
Cute Animal Picture