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

Check assert time >= store.time in fork-choice tests #3550

Merged
merged 4 commits into from
Nov 30, 2023
Merged

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Nov 16, 2023

To prevent other future bugs like #3548, this PR adds assert time >= store.time to on_tick.

Note that we have stated " on_tick(store, time) whenever time > store.time where time is the current Unix time" in fork choice specs. This PR is only to make it more explicit.

It will remove some extra on_tick steps from test vectors.

spec.on_tick(store, time)
test_steps.append({'tick': int(time)})
output_store_checks(spec, store, test_steps)
if store.time < time:
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn’t we omit this check and let it fail? in this case it can highlight an error in a test

Copy link
Contributor

@potuz potuz Nov 17, 2023

Choose a reason for hiding this comment

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

This is implementation dependant, time, in particular for spectests is very tricky. Prysm for example modifies genesis time on every tick check and it would be undefined behavior if it went back in time. I advocate for forkchoice tests to only fail on bad output from the API, that is, bad head, bad proposer boost roots, etc .

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I meant that if we’re adding assertion into the spec we can probably let this assertion cause an exception when the test isn’t properly design. Because if you set your time back this is probably something you’re doing wrong when writing the test, something that worth paying attention too instead of quietly omitting the problem

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly this is just ensuring that the tests don't get written in a way that time goes backwards, and that seems fair...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rolfyone is right; it was mainly to avoid righting useless steps in the existing test scripts.

About the failure cases, good point. If we want to cover it, we should add new test cases for on_tick. We do have the test format field to indicate if on_tick step is invalid: https://github.com/ethereum/consensus-specs/tree/dev/tests/formats/fork_choice#on_tick-execution-step

But I hear you @potuz that it could be implementation-dependant...

Do you guys think it is okay to revert the spec change and only make the test script mistake-proofing (avoid making time < store.time call)? I'm trying to find the balance between the abstract FC specs and useful tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes more sense to have an assert store.time < time here so that the test writer sees very quickly that they've done something wrong, instead of it just silently doing nothing

Copy link
Contributor

Choose a reason for hiding this comment

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

An assert in this place looks like a nice alternative to the assert in the on_tick

@@ -623,6 +623,9 @@ def update_latest_messages(store: Store, attesting_indices: Sequence[ValidatorIn

```python
def on_tick(store: Store, time: uint64) -> None:
# Precondition
assert time >= store.time
Copy link
Contributor

@djrtwo djrtwo Nov 28, 2023

Choose a reason for hiding this comment

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

I'm not certain we should add this unless we are going to actively test it. Our guiding principle is that asserts should be triggerable with invalid messages for spec and testing purposes. But this would only really be triggerable if the client's system was broken rather than them getting invalid messages

@hwwhww hwwhww changed the title Check assert time >= store.time in on_tick Check assert time >= store.time in FC tests Nov 29, 2023
@hwwhww hwwhww changed the title Check assert time >= store.time in FC tests Check assert time >= store.time in fork-choice tests Nov 29, 2023
@hwwhww hwwhww mentioned this pull request Nov 29, 2023
4 tasks
@djrtwo djrtwo merged commit 8fa1f8e into dev Nov 30, 2023
@djrtwo djrtwo deleted the on-tick-precondition branch November 30, 2023 13:58
@hwwhww
Copy link
Contributor Author

hwwhww commented Nov 30, 2023

Thank you @mkalinin @djrtwo !

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