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] - Ensure doppelganger detects attestations in blocks #2495

Closed
wants to merge 7 commits into from

Conversation

paulhauner
Copy link
Member

@paulhauner paulhauner commented Aug 4, 2021

Issue Addressed

NA

Proposed Changes

When testing our (not-yet-released) Doppelganger implementation, I noticed that we aren't detecting attestations included in blocks (only those on the gossip network).

This is because during block processing we only update the observed_attestations cache with each attestation, but not the observed_attesters cache. This is the correct behaviour when we consider the p2p spec:

[IGNORE] There has been no other valid attestation seen on an attestation subnet that has an identical attestation.data.target.epoch and participating validator index.

We're doing the right thing here and still allowing attestations on gossip that we've seen in a block. However, this doesn't work so nicely for Doppelganger.

To resolve this, I've taken the following steps:

  • Add a observed_block_attesters cache.
  • Rename observed_attesters to observed_gossip_attesters.

TODO

  • Add a test to ensure a validator that's been seen in a block attestation (but not a gossip attestation) returns true for BeaconChain::validator_seen_at_epoch.
  • Add a test to ensure observed_block_attesters isn't polluted via gossip attestations and vice versa.

@paulhauner paulhauner added work-in-progress PR is a work-in-progress v1.5.0 For inclusion in v1.5.0 release labels Aug 4, 2021
@paulhauner paulhauner requested a review from realbigsean August 4, 2021 08:41
@paulhauner paulhauner changed the title Ensure doppelganger detects attestations in blocks. Ensure doppelganger detects attestations in blocks Aug 4, 2021
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.

Generally wondering if we are OK with creating and populating the new cache even when doppelganger is disabled?

@@ -2305,6 +2311,23 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Err(e) => Err(BlockError::BeaconChainError(e.into())),
}?;

if attestation_target_epoch + OBSERVED_ATTESTERS_MAX_CAPACITY >= current_epoch {
Copy link
Member

Choose a reason for hiding this comment

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

I think OBSERVED_ATTESTERS_EPOCH_CAPACITY would be a little clearer, to distinguish this from the total number of attesters in the cache

Copy link
Member

Choose a reason for hiding this comment

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

Also the cache's lowest_permissible_epoch (which it prunes based on) is based off of the target_epoch - (MAX_CAPACITY - 1) so this check might have too wide a range.

{
debug!(
self.log,
"Failed register observed block attester";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Failed register observed block attester";
"Failed to register observed block attester";

@paulhauner
Copy link
Member Author

All comments addressed, thanks for the review @realbigsean.

I'll wait for your approval before merging this one :)

@paulhauner paulhauner added ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels Aug 6, 2021
@paulhauner paulhauner marked this pull request as ready for review August 6, 2021 04:21
paulhauner added a commit that referenced this pull request Aug 6, 2021
commit db48997
Author: Paul Hauner <[email protected]>
Date:   Wed Aug 4 14:21:39 2021 +1000

    Add observed_block_attesters

commit a8da027
Author: Paul Hauner <[email protected]>
Date:   Wed Aug 4 14:03:49 2021 +1000

    Rename observed_attesters to observed_gossip_attesters
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.

Looks good to me!

@paulhauner
Copy link
Member Author

bors r+

bors bot pushed a commit that referenced this pull request Aug 9, 2021
## Issue Addressed

NA

## Proposed Changes

When testing our (not-yet-released) Doppelganger implementation, I noticed that we aren't detecting attestations included in blocks (only those on the gossip network).

This is because during [block processing](https://github.com/sigp/lighthouse/blob/e8c0d1f19b2736efb83c67a247e0022da5eaa7bb/beacon_node/beacon_chain/src/beacon_chain.rs#L2168) we only update the `observed_attestations` cache with each attestation, but not the `observed_attesters` cache. This is the correct behaviour when we consider the [p2p spec](https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/p2p-interface.md):

> [IGNORE] There has been no other valid attestation seen on an attestation subnet that has an identical attestation.data.target.epoch and participating validator index.

We're doing the right thing here and still allowing attestations on gossip that we've seen in a block. However, this doesn't work so nicely for Doppelganger.

To resolve this, I've taken the following steps:

- Add a `observed_block_attesters` cache.
- Rename `observed_attesters` to `observed_gossip_attesters`.

## TODO

- [x] Add a test to ensure a validator that's been seen in a block attestation (but not a gossip attestation) returns `true` for `BeaconChain::validator_seen_at_epoch`.
- [x] Add a test to ensure `observed_block_attesters` isn't polluted via gossip attestations and vice versa. 


Co-authored-by: realbigsean <[email protected]>
@paulhauner paulhauner added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Aug 9, 2021
@bors bors bot changed the title Ensure doppelganger detects attestations in blocks [Merged by Bors] - Ensure doppelganger detects attestations in blocks Aug 9, 2021
@bors bors bot closed this Aug 9, 2021
pawanjay176 pushed a commit to pawanjay176/lighthouse that referenced this pull request Aug 27, 2021
## Issue Addressed

NA

## Proposed Changes

When testing our (not-yet-released) Doppelganger implementation, I noticed that we aren't detecting attestations included in blocks (only those on the gossip network).

This is because during [block processing](https://github.com/sigp/lighthouse/blob/e8c0d1f19b2736efb83c67a247e0022da5eaa7bb/beacon_node/beacon_chain/src/beacon_chain.rs#L2168) we only update the `observed_attestations` cache with each attestation, but not the `observed_attesters` cache. This is the correct behaviour when we consider the [p2p spec](https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/p2p-interface.md):

> [IGNORE] There has been no other valid attestation seen on an attestation subnet that has an identical attestation.data.target.epoch and participating validator index.

We're doing the right thing here and still allowing attestations on gossip that we've seen in a block. However, this doesn't work so nicely for Doppelganger.

To resolve this, I've taken the following steps:

- Add a `observed_block_attesters` cache.
- Rename `observed_attesters` to `observed_gossip_attesters`.

## TODO

- [x] Add a test to ensure a validator that's been seen in a block attestation (but not a gossip attestation) returns `true` for `BeaconChain::validator_seen_at_epoch`.
- [x] Add a test to ensure `observed_block_attesters` isn't polluted via gossip attestations and vice versa. 


Co-authored-by: realbigsean <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge This PR is ready to merge. v1.5.0 For inclusion in v1.5.0 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants