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

[Merge] implement ExecutionPayload timestamp validation in BlockValidator #4730

Merged
merged 6 commits into from
Dec 6, 2021

Conversation

tbenr
Copy link
Contributor

@tbenr tbenr commented Dec 1, 2021

PR Description

implements the validation in BlockValidator and migrate BlockValidatorTest to use StorageSystem and ChainUpdater

Fixed Issue(s)

fixes #4669

Documentation

  • I thought about documentation and added the documentation label to this PR if updates are required.

Changelog

  • I thought about adding a changelog entry, and added one if I deemed necessary.

Comment on lines 280 to 288
SignedBeaconBlock block = spy(signedBlockAndState.getBlock());
BeaconBlock beaconBlock = spy(block.getMessage());
BeaconBlockBody beaconBlockBody = spy(beaconBlock.getBody());
doReturn(beaconBlock).when(block).getMessage();
doReturn(beaconBlockBody).when(beaconBlock).getBody();

doReturn(Optional.of(specContext.getDataStructureUtil().randomExecutionPayload()))
.when(beaconBlockBody)
.getOptionalExecutionPayload();
Copy link
Contributor

Choose a reason for hiding this comment

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

Using spies to make this work feels pretty ugly. We generally shouldn't need to mock/spy data structure objects like blocks.
I think we'd ideally use the generateBlockAtSlot(nextSlot, <BlockOptions>) method and add the ability to specify a specific ExecutionPayload for the created block. Might need to also specify the resulting state root since you won't actually be able to apply the block.

I know it's a bunch more work here but it gives us the test utilities we need to do more tests like this which I think is a pretty big win.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I spent some time on that (i implemented the setExecutionPayload) but block processor kicks in even if you are just generating a new block without applying it ant it gets rejected.. so appeared to me that we need a way to skip validations to be able to build "wrong" chains.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the test. Have a look if the approach makes sense to you.

@tbenr tbenr force-pushed the gossip_block_validation_conditions branch from 2494138 to 2061ee4 Compare December 3, 2021 09:42
Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

LGTM.

.getMessage()
.getBody()
.getOptionalExecutionPayload()
.orElseThrow();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think this is right because to parse the block we'd have to get a payload and we're just checking if it's the default payload or not. But I think it would be clearer if instead of .orElseThrow we just returned reject("Missing execution payload") if it's not present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, will never happen but going to change it

… to generate invalid blocks.

apply suggestions in timestamp validation
apply suggestions in SpecContext assumptions helpers
improve a ValidatorDataProvider test
@tbenr tbenr force-pushed the gossip_block_validation_conditions branch from 4873256 to 6a07b11 Compare December 6, 2021 08:26
@tbenr tbenr merged commit 8c51458 into Consensys:master Dec 6, 2021
@tbenr tbenr deleted the gossip_block_validation_conditions branch December 6, 2021 12:41
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.

[Merge] Update merge gossip block validation conditions
2 participants