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

Implement Stream Duties Functionality #5685

Merged
merged 56 commits into from
May 6, 2020
Merged

Implement Stream Duties Functionality #5685

merged 56 commits into from
May 6, 2020

Conversation

rauljordan
Copy link
Contributor

@rauljordan rauljordan commented Apr 29, 2020

What type of PR is this?

Feature

What does this PR do? Why is it needed?

Currently, validators request duties by using an internal ticker on the client side. This makes it impossible for validators to be aware of any chain reorgs that may have occurred. We can solve this problem by using StreamDuties as a server-side stream from the beacon node to connected validators and simply sending over new duties if there was a chain reorg accordingly. This PR is only the server-side implementation.

This PR also introduces the notion of a reorg event in the blockchain service, sending out a statefeed.Reorg event over a StateFeed(). The RPC validator service verifies if this reorg occurred across epoch boundaries, and resends duties accordingly. Thanks for the tip @terencechain.

Which issues(s) does this PR fix?

Fixes #5306

@rauljordan rauljordan self-assigned this Apr 30, 2020
@rauljordan rauljordan added API Api related tasks Ready For Review A pull request ready for code review labels Apr 30, 2020
@rauljordan rauljordan marked this pull request as ready for review April 30, 2020 03:16
@rauljordan rauljordan requested a review from a team as a code owner April 30, 2020 03:16
Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

Goimport, rest looks good

@@ -29,6 +29,8 @@ import (
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/slotutil"

Copy link
Member

Choose a reason for hiding this comment

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

goimport please

@codecov
Copy link

codecov bot commented Apr 30, 2020

Codecov Report

Merging #5685 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #5685   +/-   ##
=======================================
  Coverage   20.47%   20.47%           
=======================================
  Files         239      239           
  Lines       20849    20849           
=======================================
  Hits         4268     4268           
  Misses      15776    15776           
  Partials      805      805           


// Compute the validator duties from the head state's corresponding epoch
// for validators public key / indices requested.
func (vs *Server) duties(ctx context.Context, req *ethpb.DutiesRequest) (*ethpb.DutiesResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we could possibly send nextCommitteeAssignments over the stream. that way validators will know about their assignments ahead of time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to do this in a separate PR to not further complicate the logic and line count, but yep we definitely need to compute next epoch assignments

nisdas
nisdas previously requested changes May 4, 2020
Copy link
Member

@nisdas nisdas left a comment

Choose a reason for hiding this comment

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

Had concerns on how re-orgs are being determined

@@ -108,6 +112,17 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
return errors.Wrap(err, "could not save head root in DB")
}

// A chain re-org occurred, so we fire an event notifying the rest of the services.
if newHeadState.Slot() < currentHeadSlot {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this is fully correct, while this would be one way to determine a re-org the correct way would be to check whether the incoming block is a direct child of the current head. If it's not then we can mark it as a re-org.

You could have re-orgs also when

newHeadState.Slot() > currentHeadSlot 

where the new head isn't a descendant of the current chain head.
cc @terencechain

Copy link
Member

@terencechain terencechain May 4, 2020

Choose a reason for hiding this comment

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

Yeah my bad on this. I was only thinking reorg that affect assignments so it's not complete. Nishant is right. We can have the following:

100 - 101 - 103
   \- 102

Head can change from 101 to 102 to 103. From 102 to 103 it's a reorg but slot isn't right.
Checking the direct child sounds good to me

prestonvanloon
prestonvanloon previously approved these changes May 4, 2020
@prestonvanloon
Copy link
Member

Code LGTM. I didn't review @nisdas point about whether or not this correctly detects reorgs.

// ReorgData is the data alongside a reorg event.
type ReorgData struct {
// NewSlot is the slot of new state after the reorg.
NewSlot uint64
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct ? shouldn't it be new block root instead

Copy link
Member

Choose a reason for hiding this comment

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

This is fine. ReorgData is just to notify downstream service and based on downstream service's need. Currently OldRoot and NewRoot are not needed by the downstream services. They can be added later if its necessary

@rauljordan rauljordan dismissed nisdas’s stale review May 6, 2020 19:09

Resolved offline

// ReorgData is the data alongside a reorg event.
type ReorgData struct {
// NewSlot is the slot of new state after the reorg.
NewSlot uint64
Copy link
Member

Choose a reason for hiding this comment

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

This is fine. ReorgData is just to notify downstream service and based on downstream service's need. Currently OldRoot and NewRoot are not needed by the downstream services. They can be added later if its necessary

@rauljordan rauljordan merged commit d5b1f9f into master May 6, 2020
@rauljordan rauljordan deleted the stream-duties branch May 6, 2020 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Api related tasks Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alert validators in case of beacon chain has a short range reorg
5 participants