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

Attestation Using Head State instead of Latest State #2156

Merged
merged 12 commits into from
Apr 5, 2019

Conversation

terencechain
Copy link
Member

@terencechain terencechain commented Apr 4, 2019

This PR fixes the incorrect AttestationDataResponse from attester server to validator. Attester server was using current state (last processed state) to construct these attestation but it is suppose to use head state.

if err != nil {
return nil, fmt.Errorf("could not tree hash beacon block: %v", err)
}
beaconState, err := as.beaconDB.State(ctx)
headState, err := as.beaconDB.HistoricalStateFromSlot(ctx, head.Slot)
Copy link
Member Author

@terencechain terencechain Apr 4, 2019

Choose a reason for hiding this comment

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

Bug1: Suppose to use head state here instead of last processed state

} else {
epochBoundaryRoot, err = blocks.BlockRoot(beaconState, epochStartSlot)
epochBoundaryRoot, err = blocks.BlockRoot(headState, epochStartSlot)
Copy link
Member Author

Choose a reason for hiding this comment

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

Bug2: Because of 1, it gives us an incorrect epoch boundary root

@@ -87,9 +76,9 @@ func (as *AttesterServer) AttestationDataAtSlot(ctx context.Context, req *pb.Att
// On the server side, this is fetched by calling get_block_root(state, justified_epoch).
// If the last justified boundary slot is the same as state current slot (ex: slot 0),
// we set justified block root to an empty root.
lastJustifiedSlot := helpers.StartSlot(beaconState.JustifiedEpoch)
lastJustifiedSlot := helpers.StartSlot(headState.JustifiedEpoch)
Copy link
Member Author

Choose a reason for hiding this comment

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

Bug3: Because of 1, it gives us an incorrect justified slot

@@ -68,6 +67,9 @@ func (v *validator) AttestToBlockHead(ctx context.Context, slot uint64) {
slot-params.BeaconConfig().GenesisSlot, err)
return
}
// Set the attestation data's slot to head_state.slot where the slot
// is the canonical head of the beacon chain.
attData.Slot = infoRes.Slot
Copy link
Member Author

Choose a reason for hiding this comment

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

Bug4: attestation slot should be the head slot, not the current slot

@@ -68,6 +68,7 @@ message AttestationDataResponse {
uint64 justified_epoch = 3;
bytes justified_block_root_hash32 = 4;
ethereum.beacon.p2p.v1.Crosslink latest_crosslink = 5;
uint64 slot = 6;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Member Author

@terencechain terencechain Apr 4, 2019

Choose a reason for hiding this comment

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

Attester needs to know the head slot and it has no one of knowing unless we include head slot in one of the response

Copy link
Contributor

Choose a reason for hiding this comment

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

can we call this head slot then

@codecov
Copy link

codecov bot commented Apr 4, 2019

Codecov Report

Merging #2156 into master will decrease coverage by 0.63%.
The diff coverage is 71.42%.

@@            Coverage Diff             @@
##           master    #2156      +/-   ##
==========================================
- Coverage   70.17%   69.54%   -0.64%     
==========================================
  Files         116      115       -1     
  Lines        9139     8851     -288     
==========================================
- Hits         6413     6155     -258     
+ Misses       2083     2064      -19     
+ Partials      643      632      -11

if err := s.dht.BootstrapWithConfig(ctx, bcfg); err != nil {
log.Errorf("Failed to bootstrap DHT: %v", err)
}
//if err := s.dht.BootstrapWithConfig(ctx, bcfg); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This disables bootstrap discovery. Please remove.

beaconState, err := as.beaconDB.State(ctx)

// Let head state be the state of head block processed through empty slots up to assigned slot.
headState, err := as.beaconDB.HistoricalStateFromSlot(ctx, head.Slot)
Copy link
Member

Choose a reason for hiding this comment

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

Please use as.beaconDB.State(ctx) and have an assertion that these slots are the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

We also don't need the assertion, from the spec:
Let head_statebe the state ofhead_block processed through any empty slots up to the assigned slot.

What we need, what I added is this:

	for headState.Slot < req.Slot {
		headState, err = state.ExecuteStateTransition(
			ctx, headState, nil /* block */, headRoot, state.DefaultConfig(),
		)
		if err != nil {
			return nil, fmt.Errorf("could not execute head transition: %v", err)
		}
	}

@@ -68,6 +68,7 @@ message AttestationDataResponse {
uint64 justified_epoch = 3;
bytes justified_block_root_hash32 = 4;
ethereum.beacon.p2p.v1.Crosslink latest_crosslink = 5;
uint64 slot = 6;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we call this head slot then

@rauljordan rauljordan merged commit a19f08f into master Apr 5, 2019
@prestonvanloon prestonvanloon deleted the fix-attestation-state branch April 20, 2019 03:07
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.

3 participants