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

[Merged by Bors] - Remove equivocating validators from fork choice #3371

Closed

Conversation

michaelsproul
Copy link
Member

@michaelsproul michaelsproul commented Jul 25, 2022

Issue Addressed

Closes #3241
Closes #3242

Proposed Changes

  • Implement logic to remove equivocating validators from fork choice per Remove equivocating validators from fork choice consideration ethereum/consensus-specs#2845
  • Update tests to v1.2.0-rc.1. The new test which exercises equivocating_indices is passing.
  • Pull in some SSZ abstractions from the tree-states branch that make implementing Vec-compatible encoding for types like BTreeSet and BTreeMap.
  • Implement schema upgrades and downgrades for the database (new schema version is V11).
  • Apply attester slashings from blocks to fork choice

Additional Info

  • This PR doesn't need the BTreeMap impl, but tree-states does, and I don't think there's any harm in keeping it. But I could also be convinced to drop it.

Blocked on #3322.

@michaelsproul michaelsproul added work-in-progress PR is a work-in-progress backwards-incompat Backwards-incompatible API change labels Jul 25, 2022
@michaelsproul michaelsproul force-pushed the rm-equivocating-fork-choice branch from 181fd0f to 960bfbd Compare July 26, 2022 00:57
@michaelsproul michaelsproul added blocked and removed work-in-progress PR is a work-in-progress labels Jul 26, 2022
@michaelsproul michaelsproul changed the base branch from unstable to stable July 26, 2022 02:27
@michaelsproul michaelsproul changed the base branch from stable to unstable July 26, 2022 02:28
@michaelsproul michaelsproul added ready-for-review The code is ready for review consensus An issue/PR that touches consensus code, such as state_processing or block verification. and removed blocked labels Jul 26, 2022
@michaelsproul
Copy link
Member Author

This PR is ready for review!

A few notes for reviewers:

  • There is currently no pruning of the equivocating indices. I think this would require some careful consideration to get right, so I've opened an issue here: Prune fork choice equivocating indices #3373
  • We could consider using a HashMap for the equivocating indices, but I'm hesitant to implement SSZ encode/decode for hashmaps given that it would be non-deterministic. Given that we don't expect this map to become too large (at most ~100K entries), I think the BTree map should be sufficient. Likewise memory usage should be modest: 8 bytes * O(n log n) ~= 4MB.

@michaelsproul michaelsproul added the v2.5.0 Required for Goerli merge release label Jul 26, 2022
Copy link
Member

@realbigsean realbigsean left a comment

Choose a reason for hiding this comment

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

Nice! Looks great, couldn't find any issues. Left one comment that I'm not sure even makes a functional difference so feel free to ignore it.

// anyway. If a validator is slashable at the head but not at justification then it means
// their activation has occurred since justification, and we arguably shouldn't be counting
// their attestations.
let slashed_indices = get_slashable_indices(head_state, slashing)?;
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to use get_slashable_indices modular here and have the is_slashable method do nothing? Seems like it's more in line with what's specified.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think if we wanted to match the spec as closely as possible without actually loading the justified state then we could use get_slashable_indices_modular and check validator.is_slashable_at(head_state.current_justified_checkpoint().epoch). But I suspect that the spec is only written like that because the justified state is easy to access without plumbing the head state through. I've asked about it on the spec PR here: ethereum/consensus-specs#2845 (comment). We can hold off on merging for a bit until we hear back

Copy link
Member Author

Choose a reason for hiding this comment

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

I was wrong 😅

Fixed in this commit, which also enabled a few other simplifications ad0621e.

Copy link
Member

@realbigsean realbigsean left a comment

Choose a reason for hiding this comment

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

Nice the updates look good to me, I'll leave it open in case @paulhauner wants to have a look

Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

Nice stuff, looks good!

Only one comment about SSZ decode in growing Vecs.

//
// We assume that if a max length is provided then the application is able to handle an
// allocation of this size.
let mut values = if max_len.is_some() {
Copy link
Member

Choose a reason for hiding this comment

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

It'll be interesting to see the outcome of losing max-length pre-allocation for VariableLists which contain variable-length items. As an example we'll no longer allocate a list of length 128 for attestations in a block, instead we'll grow it by 1 each attestation. It seems VariableList is used a bit by the networking stack, too.

I'm not certain if this will be a regression or not. I'll keep an eye on the memory stats on our nodes and maybe even do a heaptrack.

Copy link
Member Author

@michaelsproul michaelsproul Jul 28, 2022

Choose a reason for hiding this comment

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

Ooh good point. I kind of hoped the magic of collect and size hints would let us keep the pre-allocation, but it seems it only works if the iterator implements TrustedLen: https://github.com/rust-lang/rust/blob/48316dfea1914d25189fa441e7310449ed76a446/library/alloc/src/vec/spec_extend.rs#L36. And the iterator from process_results doesn't (because it can fail).

It would be quite straight-forward to add a new_with_capacity function to TryFromIter if it turns out we need it

Copy link
Member Author

@michaelsproul michaelsproul Jul 28, 2022

Choose a reason for hiding this comment

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

Or we could just change the TryFromIter implementation for Vec so that it always uses the size_hint

@paulhauner paulhauner added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Jul 28, 2022
@paulhauner
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Jul 28, 2022
## Issue Addressed

Closes #3241
Closes #3242

## Proposed Changes

* [x] Implement logic to remove equivocating validators from fork choice per ethereum/consensus-specs#2845
* [x] Update tests to v1.2.0-rc.1. The new test which exercises `equivocating_indices` is passing.
* [x] Pull in some SSZ abstractions from the `tree-states` branch that make implementing Vec-compatible encoding for types like `BTreeSet` and `BTreeMap`.
* [x] Implement schema upgrades and downgrades for the database (new schema version is V11).
* [x] Apply attester slashings from blocks to fork choice

## Additional Info

* This PR doesn't need the `BTreeMap` impl, but `tree-states` does, and I don't think there's any harm in keeping it. But I could also be convinced to drop it.

Blocked on #3322.
@bors
Copy link

bors bot commented Jul 28, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Jul 28, 2022
## Issue Addressed

Closes #3241
Closes #3242

## Proposed Changes

* [x] Implement logic to remove equivocating validators from fork choice per ethereum/consensus-specs#2845
* [x] Update tests to v1.2.0-rc.1. The new test which exercises `equivocating_indices` is passing.
* [x] Pull in some SSZ abstractions from the `tree-states` branch that make implementing Vec-compatible encoding for types like `BTreeSet` and `BTreeMap`.
* [x] Implement schema upgrades and downgrades for the database (new schema version is V11).
* [x] Apply attester slashings from blocks to fork choice

## Additional Info

* This PR doesn't need the `BTreeMap` impl, but `tree-states` does, and I don't think there's any harm in keeping it. But I could also be convinced to drop it.

Blocked on #3322.
@michaelsproul
Copy link
Member Author

bors r-

@bors
Copy link

bors bot commented Jul 28, 2022

Canceled.

@michaelsproul
Copy link
Member Author

bors r+

bors bot pushed a commit that referenced this pull request Jul 28, 2022
## Issue Addressed

Closes #3241
Closes #3242

## Proposed Changes

* [x] Implement logic to remove equivocating validators from fork choice per ethereum/consensus-specs#2845
* [x] Update tests to v1.2.0-rc.1. The new test which exercises `equivocating_indices` is passing.
* [x] Pull in some SSZ abstractions from the `tree-states` branch that make implementing Vec-compatible encoding for types like `BTreeSet` and `BTreeMap`.
* [x] Implement schema upgrades and downgrades for the database (new schema version is V11).
* [x] Apply attester slashings from blocks to fork choice

## Additional Info

* This PR doesn't need the `BTreeMap` impl, but `tree-states` does, and I don't think there's any harm in keeping it. But I could also be convinced to drop it.

Blocked on #3322.
@bors
Copy link

bors bot commented Jul 28, 2022

Build failed (retrying...):

@paulhauner
Copy link
Member

bors r-

@bors
Copy link

bors bot commented Jul 28, 2022

Canceled.

@paulhauner
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Jul 28, 2022
## Issue Addressed

Closes #3241
Closes #3242

## Proposed Changes

* [x] Implement logic to remove equivocating validators from fork choice per ethereum/consensus-specs#2845
* [x] Update tests to v1.2.0-rc.1. The new test which exercises `equivocating_indices` is passing.
* [x] Pull in some SSZ abstractions from the `tree-states` branch that make implementing Vec-compatible encoding for types like `BTreeSet` and `BTreeMap`.
* [x] Implement schema upgrades and downgrades for the database (new schema version is V11).
* [x] Apply attester slashings from blocks to fork choice

## Additional Info

* This PR doesn't need the `BTreeMap` impl, but `tree-states` does, and I don't think there's any harm in keeping it. But I could also be convinced to drop it.

Blocked on #3322.
@bors
Copy link

bors bot commented Jul 28, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Jul 28, 2022
## Issue Addressed

Closes #3241
Closes #3242

## Proposed Changes

* [x] Implement logic to remove equivocating validators from fork choice per ethereum/consensus-specs#2845
* [x] Update tests to v1.2.0-rc.1. The new test which exercises `equivocating_indices` is passing.
* [x] Pull in some SSZ abstractions from the `tree-states` branch that make implementing Vec-compatible encoding for types like `BTreeSet` and `BTreeMap`.
* [x] Implement schema upgrades and downgrades for the database (new schema version is V11).
* [x] Apply attester slashings from blocks to fork choice

## Additional Info

* This PR doesn't need the `BTreeMap` impl, but `tree-states` does, and I don't think there's any harm in keeping it. But I could also be convinced to drop it.

Blocked on #3322.
@bors
Copy link

bors bot commented Jul 28, 2022

Build failed:

@paulhauner
Copy link
Member

I'll queue this so it runs after the current batch.

bors r+

bors bot pushed a commit that referenced this pull request Jul 28, 2022
## Issue Addressed

Closes #3241
Closes #3242

## Proposed Changes

* [x] Implement logic to remove equivocating validators from fork choice per ethereum/consensus-specs#2845
* [x] Update tests to v1.2.0-rc.1. The new test which exercises `equivocating_indices` is passing.
* [x] Pull in some SSZ abstractions from the `tree-states` branch that make implementing Vec-compatible encoding for types like `BTreeSet` and `BTreeMap`.
* [x] Implement schema upgrades and downgrades for the database (new schema version is V11).
* [x] Apply attester slashings from blocks to fork choice

## Additional Info

* This PR doesn't need the `BTreeMap` impl, but `tree-states` does, and I don't think there's any harm in keeping it. But I could also be convinced to drop it.

Blocked on #3322.
@bors bors bot changed the title Remove equivocating validators from fork choice [Merged by Bors] - Remove equivocating validators from fork choice Jul 28, 2022
@bors bors bot closed this Jul 28, 2022
@michaelsproul michaelsproul deleted the rm-equivocating-fork-choice branch August 3, 2022 03:18
bors bot pushed a commit that referenced this pull request Sep 16, 2022
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
bors bot pushed a commit that referenced this pull request Sep 16, 2022
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
bors bot pushed a commit that referenced this pull request Sep 16, 2022
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
bors bot pushed a commit that referenced this pull request Sep 16, 2022
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
bors bot pushed a commit that referenced this pull request Sep 16, 2022
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: #3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
## Issue Addressed

Fixes a potential regression in memory fragmentation identified by @paulhauner here: sigp#3371 (comment).

## Proposed Changes

Immediately allocate a vector with sufficient size to hold all decoded elements in SSZ decoding. The `size_hint` is derived from the range iterator here:

https://github.com/sigp/lighthouse/blob/2983235650811437b44199f9c94e517e948a1e9b/consensus/ssz/src/decode/impls.rs#L489

## Additional Info

I'd like to test this out on some infra for a substantial duration to see if it affects total fragmentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards-incompat Backwards-incompatible API change consensus An issue/PR that touches consensus code, such as state_processing or block verification. ready-for-merge This PR is ready to merge. v2.5.0 Required for Goerli merge release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants