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
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
29f4148
add test for stream duties
rauljordan Apr 29, 2020
ed807b0
rem gomock
rauljordan Apr 29, 2020
4efab4e
Merge branch 'master' into stream-duties
rauljordan Apr 29, 2020
99a848d
context cancelation test
rauljordan Apr 29, 2020
08f37d5
use interface for epoch ticker in duties
rauljordan Apr 29, 2020
bb5e60d
fix build
rauljordan Apr 30, 2020
3be7452
compute duties on first call
rauljordan Apr 30, 2020
aa9ea93
pass tests for streams
rauljordan Apr 30, 2020
d893fd7
gaz
rauljordan Apr 30, 2020
a04d738
ss stream duties
rauljordan Apr 30, 2020
6a3392d
Merge branch 'master' into stream-duties
rauljordan Apr 30, 2020
31d0bc1
ensure only stream across epoch-wide reorgs
rauljordan Apr 30, 2020
ac55332
regen mock for validator
rauljordan Apr 30, 2020
3784dc2
Update beacon-chain/blockchain/head.go
rauljordan Apr 30, 2020
89cdb94
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] Apr 30, 2020
6247c91
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] Apr 30, 2020
9a26622
Update beacon-chain/rpc/validator/server.go
rauljordan Apr 30, 2020
467233d
Merge branch 'master' into stream-duties
rauljordan Apr 30, 2020
86ab8a2
update workspac
rauljordan Apr 30, 2020
21262d1
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] Apr 30, 2020
1585c14
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] Apr 30, 2020
78bc89f
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 1, 2020
645fdfd
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 1, 2020
f616897
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 1, 2020
6161be4
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 1, 2020
33a3bc1
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 1, 2020
069c307
pregenesis check
rauljordan May 1, 2020
7a40233
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 1, 2020
9029d63
tests pass
rauljordan May 1, 2020
04f35d0
build fix
rauljordan May 1, 2020
a8358e7
Revert "tests pass"
rauljordan May 1, 2020
9f7b659
ethereumapis
rauljordan May 1, 2020
947c34a
gaz
rauljordan May 1, 2020
419e08b
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 1, 2020
d791233
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 1, 2020
90337c8
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 2, 2020
70e91ed
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 2, 2020
320c257
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 2, 2020
a8082d7
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 4, 2020
90e9074
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 4, 2020
4cd6783
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 4, 2020
58e688e
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 4, 2020
8929e3e
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 4, 2020
e03aa1d
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 4, 2020
dfc7e36
Update beacon-chain/rpc/validator/assignments.go
prestonvanloon May 4, 2020
daeddb8
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 4, 2020
c1dd9c4
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 5, 2020
23c7cf1
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 5, 2020
670dde7
fix confs
rauljordan May 6, 2020
21305e7
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 6, 2020
0ca6512
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 6, 2020
1b8cf21
Merge refs/heads/master into stream-duties
prylabs-bulldozer[bot] May 6, 2020
f21c9a5
test for reorg
rauljordan May 6, 2020
06121d7
Merge branch 'stream-duties' of github.com:prysmaticlabs/prysm into s…
rauljordan May 6, 2020
92cd704
fix up required tests
rauljordan May 6, 2020
68a9e33
fmt
rauljordan May 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ go_repository(

go_repository(
name = "com_github_prysmaticlabs_ethereumapis",
commit = "ba9042096e9fc49606279513d3e24e5e8cdbd5a0",
commit = "df460bd3d84be4ff3df0658395c7dc9d2a7e7b3d",
importpath = "github.com/prysmaticlabs/ethereumapis",
)

Expand Down
15 changes: 15 additions & 0 deletions beacon-chain/blockchain/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
Expand Down Expand Up @@ -100,6 +102,8 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
return errors.New("cannot save nil head state")
}

currentHeadSlot := s.headSlot()

// Cache the new head info.
s.setHead(headRoot, newHeadBlock, newHeadState)

Expand All @@ -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

s.stateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.Reorg,
Data: &statefeed.ReorgData{
NewSlot: newHeadState.Slot(),
OldSlot: currentHeadSlot,
},
})
}

return nil
}

Expand Down
13 changes: 12 additions & 1 deletion beacon-chain/core/feed/state/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ const (
Initialized
// Synced is sent when the beacon node has completed syncing and is ready to participate in the network.
Synced
// Reorg is an event sent when the new head state's slot after a block
// transition is lower than its previous head state slot value.
Reorg
)

// BlockProcessedData is the data sent with BlockProcessed events.
type BlockProcessedData struct {
// Slot is the slot of the processed block.
Slot uint64
// BlockRoot is the hash of the processed block.
// BlockRoot of the processed block.
BlockRoot [32]byte
// Verified is true if the block's BLS contents have been verified.
Verified bool
Expand All @@ -45,3 +48,11 @@ type InitializedData struct {
// GenesisValidatorsRoot represents ssz.HashTreeRoot(state.validators).
GenesisValidatorsRoot []byte
}

// 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

// OldSlot is the slot of the head state before the reorg.
OldSlot uint64
}
1 change: 1 addition & 0 deletions beacon-chain/rpc/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/rpc/testing",
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"@com_github_gogo_protobuf//types:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
"@org_golang_google_grpc//metadata:go_default_library",
Expand Down
Loading