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

Block: make blockchain mandatory in validation methods #942

Merged
merged 2 commits into from
Nov 10, 2020

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented Nov 6, 2020

This PR:

  • Makes blockchain parameter mandatory in validate methods of Block and BlockHeader
  • Adds validateData method to Block
  • Hoists the extraData check to the constructor of BlockHeader

Rationale:
If you called validate in BlockHeader without a blockchain, the only check which is being done is checking that extraData.length is within the current bounds of the maximum extraData. This can give consumers the false idea that the header is correct, but the method does practically nothing.

Validate is now explicitly used to validate against the parent BlockHeader (or Block). There is an additional function in Block which has the logic which does not need blockchain in case a consumer does have a block but no access to a blockchain. (We cannot do all this in the constructor of the Block, as we need access to Trie here which is async).

Note: hoisting the extraData check to the constructor makes the Ethash test fail, will open an issue for this, looks like this data is invalid (?). See #943

This mandatory blockchain parameter is necessary in #933, this PR simply ensures that we make this parameter mandatory so we can work on this uncle validation logic in the future.

@codecov
Copy link

codecov bot commented Nov 6, 2020

Codecov Report

Merging #942 (6a21940) into master (84aaf81) will increase coverage by 0.72%.
The diff coverage is 22.22%.

Impacted file tree graph

Flag Coverage Δ
block 76.36% <22.22%> (+1.65%) ⬆️
blockchain 78.04% <ø> (ø)
common 92.03% <ø> (ø)
ethash 82.08% <ø> (ø)
tx 88.54% <ø> (+0.17%) ⬆️
vm 87.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@jochem-brouwer jochem-brouwer force-pushed the block-blockchain-validation-mandatory branch from 2a862b6 to 6a21940 Compare November 9, 2020 13:45
@jochem-brouwer
Copy link
Member Author

Rebased this one!

Copy link
Contributor

@ryanio ryanio left a comment

Choose a reason for hiding this comment

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

this lgtm! nice idea for making the mock blockchain

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Thanks, great! 👍

@holgerd77 holgerd77 merged commit f53559c into master Nov 10, 2020
@holgerd77 holgerd77 deleted the block-blockchain-validation-mandatory branch November 10, 2020 08:18
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.

3 participants