Skip to content

Undoing the mixup between Chain ID and Network ID #777

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

Merged
merged 2 commits into from
Apr 23, 2018

Conversation

carver
Copy link
Collaborator

@carver carver commented Apr 20, 2018

What was wrong?

web3py was returning networkId when asked for chainId.

How was it fixed?

There is no quick/foolproof way to determine the value, and None is valid in all cases, so we just return that.

  • There were incorrect chainId validations in place, remove them
  • Always return None from w3.net.chainId
  • Document

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

- There were validations in place, remove them
- Stop returning the network id instead of the chain ID
- Always return chain id is None until a new method is added to
the json-rpc suite
@@ -15,14 +15,14 @@

@curry
def validate_chain_id(web3, chain_id):
if chain_id == web3.version.network:
if chain_id is None:
Copy link
Contributor

@voith voith Apr 20, 2018

Choose a reason for hiding this comment

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

what?? This is going away?? Just because this middleware needed a web3 instance, I spent the last hour or two trying to figure out https://github.com/voith/web3.py/blob/b3a30a7374cb5f205d7e96a326533dc8394c7a73/web3/utils/formatters.py#L168-L180.
I would have got #756 right the first time if I knew this change was coming.

Also you might want to remove web3 from validate_chain_id(web3, chain_id) as its no longer needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess the clearer thing to do is his to set it to:

if chain_id == web3.net.chainId:

Right now, that's the same thing. But once we get nodes to make chainId available in a standard way, it should start working again.

I'll review #756 today.

@carver carver merged commit bf23248 into ethereum:master Apr 23, 2018
@carver carver deleted the chainid-oops branch April 23, 2018 22:48
False,
marks=pytest.mark.xfail,
Copy link
Contributor

Choose a reason for hiding this comment

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

@carver why did you mark this as xfail?

from web3.auto import w3
transaction = {'to': w3.eth.accounts[0], 'chainId': 9999999, 'from': w3.eth.accounts[1]}
w3.personal.unlockAccount(w3.eth.accounts[1], 'passphrase')
w3.eth.sendTransaction(transaction)

shouldn't the above code give ValidationError for chainId? In fact validation middleware doesn't seem to do what it is expected to do.
I'm not very sure if this is a regression but I'm fixing this in #756.

@@ -33,7 +33,6 @@ def transaction_normalizer(transaction):

def validation_middleware(make_request, web3):
transaction_validator = apply_formatters_to_dict({
'chainId': validate_chain_id(web3),
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that this is the cause for using xfail!
Read the description in the PR. However If validate_chain_id is not needed anymore, why is the code left behind?
Is this something you plan to return back to

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this something you plan to return back to?

Yes. Once we can reliably discover the chainID from the connected node, then we should validate chainID again.

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.

2 participants