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] - Update state before producing attestation #1596

Closed
wants to merge 2 commits into from

Conversation

pawanjay176
Copy link
Member

@pawanjay176 pawanjay176 commented Sep 7, 2020

Issue Addressed

Partly addresses #1547

Proposed Changes

This fix addresses the missing attestations at slot 0 of an epoch (also sometimes slot 1 when slot 0 was skipped).
There are 2 cases:

  1. BN receives the block for the attestation slot after 4 seconds (1/3rd of the slot).
  2. No block is proposed for this slot.

In both cases, when we produce the attestation, we pass the head state to the
produce_unaggregated_attestation_for_block function here

pub fn produce_unaggregated_attestation_for_block(
&self,
slot: Slot,
index: CommitteeIndex,
beacon_block_root: Hash256,
mut state: Cow<BeaconState<T::EthSpec>>,

Since we don't advance the state in this function, we set attestation.data.source = state.current_justified_checkpoint which is atleast 2 epochs lower than current_epoch(wall clock epoch).
This attestation is invalid and cannot be included in a block because of this assert from the spec:

if data.target.epoch == get_current_epoch(state):
        assert data.source == state.current_justified_checkpoint
        state.current_epoch_attestations.append(pending_attestation)

https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#attestations

This PR changes the produce_unaggregated_attestation_for_block function to ensure that it advances the state before producing the attestation at the new epoch.

Running this on my node, have missed 0 attestations across all 8 of my validators in a 100 epoch period 🎉
To compare, I was missing ~14 attestations across all 8 validators in the same 100 epoch period before the fix.

Will report missed attestations if any after running for another 100 epochs tomorrow.

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

Great fix!

I'll try it on my node too

beacon_node/beacon_chain/src/beacon_chain.rs Show resolved Hide resolved
@pawanjay176
Copy link
Member Author

Update: no missed attestations after running for 100 more epochs!

Copy link
Member

@AgeManning AgeManning left a comment

Choose a reason for hiding this comment

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

I really want this bad boy!

So i'm just going to add an approval here!

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.

Great work! Like @michaelsproul (I assume) I have actually reviewed this and approve it.

bors r+

bors bot pushed a commit that referenced this pull request Sep 8, 2020
## Issue Addressed

Partly addresses #1547 

## Proposed Changes

This fix addresses the missing attestations at slot 0 of an epoch (also sometimes slot 1 when slot 0 was skipped).
There are 2 cases:
1. BN receives the block for the attestation slot after 4 seconds (1/3rd of the slot).
2. No block is proposed for this slot.

In both cases, when we produce the attestation, we pass the head state to the 
`produce_unaggregated_attestation_for_block` function here
https://github.com/sigp/lighthouse/blob/9833eca02485ef06abef4144f071ea3b79002f30/beacon_node/beacon_chain/src/beacon_chain.rs#L845-L850

Since we don't advance the state in this function, we set `attestation.data.source = state.current_justified_checkpoint` which is atleast 2 epochs lower than current_epoch(wall clock epoch). 
This attestation is invalid and cannot be included in a block because of this assert from the spec:
```python
if data.target.epoch == get_current_epoch(state):
        assert data.source == state.current_justified_checkpoint
        state.current_epoch_attestations.append(pending_attestation)
```
https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#attestations

This PR changes the `produce_unaggregated_attestation_for_block` function to ensure that it advances the state before producing the attestation at the new epoch.

Running this on my node, have missed 0 attestations across all 8 of my validators in a 100 epoch period 🎉 
To compare, I was missing ~14 attestations across all 8 validators in the same 100 epoch period before the fix. 

Will report missed attestations if any after running for another 100 epochs tomorrow.
@bors bors bot changed the title Update state before producing attestation [Merged by Bors] - Update state before producing attestation Sep 8, 2020
@bors bors bot closed this Sep 8, 2020
@pawanjay176 pawanjay176 deleted the fix-attestations branch September 8, 2020 12:18
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.

4 participants