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

Validator Proposer Rewrite #1462

Merged
merged 33 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d4697a4
WIP - with TODOs
prestonvanloon Jan 30, 2019
9b20eb9
interface w/ test
prestonvanloon Jan 30, 2019
cca4cbd
basic test for broadcast
prestonvanloon Jan 30, 2019
2a134d6
update with master
prestonvanloon Jan 30, 2019
e8bfd8a
Add computeStateRoot funciton
prestonvanloon Jan 30, 2019
b9236b1
merge master
prestonvanloon Feb 2, 2019
b2da996
checkpoint
prestonvanloon Feb 2, 2019
d928aac
remove custody challenge
prestonvanloon Feb 2, 2019
ea701be
resolve TODO lint issues
prestonvanloon Feb 2, 2019
c8201fb
more TODOs
prestonvanloon Feb 2, 2019
ac05fb9
revert new line in types.proto
prestonvanloon Feb 2, 2019
3c83b43
broadcaster comment
prestonvanloon Feb 2, 2019
242fbbc
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon Feb 2, 2019
2284add
one of several failure condition tests
prestonvanloon Feb 2, 2019
1e8adb8
Add test cases
prestonvanloon Feb 3, 2019
337d0ba
handle compute state error test case
prestonvanloon Feb 3, 2019
9e56c4c
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon Feb 3, 2019
2398031
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon Feb 3, 2019
18c058e
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon Feb 3, 2019
17f6a0d
Merge branch 'master' into validator-proposer-rewrite
Feb 4, 2019
2c24627
Merge branch 'validator-proposer-rewrite' of github.com:prysmaticlabs…
prestonvanloon Feb 4, 2019
388a84e
fix config in validator helpers
prestonvanloon Feb 4, 2019
99c8679
fix tests too
prestonvanloon Feb 4, 2019
7430472
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon Feb 5, 2019
5f5a2f6
fix conflict
prestonvanloon Feb 5, 2019
c6f8591
partial PR feedback
prestonvanloon Feb 5, 2019
8b2be2a
remove p2p
prestonvanloon Feb 5, 2019
3d8c5e5
gazelle
prestonvanloon Feb 5, 2019
a6e07f5
package comment
prestonvanloon Feb 5, 2019
8bcbd1a
Merge branch 'master' into validator-proposer-rewrite
prestonvanloon Feb 5, 2019
94be890
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon Feb 5, 2019
d8666da
Better godoc
prestonvanloon Feb 5, 2019
9969aaf
Merge branch 'validator-proposer-rewrite' of github.com:prysmaticlabs…
prestonvanloon Feb 5, 2019
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
14 changes: 14 additions & 0 deletions beacon-chain/rpc/beacon_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,17 @@ func (bs *BeaconServer) LatestAttestation(req *ptypes.Empty, stream pb.BeaconSer
}
}
}

// Eth1Data fetches the current ETH 1 data which should be used when voting via
// block proposal.
// TODO(1463): Implement this.
func (bs *BeaconServer) Eth1Data(ctx context.Context, _ *ptypes.Empty) (*pb.Eth1DataResponse, error) {
return &pb.Eth1DataResponse{}, nil
}

// PendingDeposits returns a list of pending deposits that are ready for
// inclusion in the next beacon block.
// TODO(1464): Implement this.
func (bs *BeaconServer) PendingDeposits(ctx context.Context, _ *ptypes.Empty) (*pb.PendingDepositsResponse, error) {
return &pb.PendingDepositsResponse{PendingDeposits: []*pbp2p.Deposit{}}, nil
}
586 changes: 509 additions & 77 deletions proto/beacon/rpc/v1/services.pb.go

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions proto/beacon/rpc/v1/services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ service BeaconService {
rpc CanonicalHead(google.protobuf.Empty) returns (ethereum.beacon.p2p.v1.BeaconBlock);
// LatestAttestation streams the latest aggregated attestation to connected validator clients.
rpc LatestAttestation(google.protobuf.Empty) returns (stream ethereum.beacon.p2p.v1.Attestation);
rpc PendingDeposits(google.protobuf.Empty) returns (PendingDepositsResponse);
rpc Eth1Data(google.protobuf.Empty) returns (Eth1DataResponse);
}

service AttesterService {
Expand Down Expand Up @@ -97,3 +99,11 @@ message ValidatorEpochAssignmentsRequest {
message ValidatorEpochAssignmentsResponse {
Assignment assignment = 2;
}

message PendingDepositsResponse {
repeated ethereum.beacon.p2p.v1.Deposit pending_deposits = 1;
}

message Eth1DataResponse {
ethereum.beacon.p2p.v1.Eth1Data eth1_data = 1;
}
1 change: 1 addition & 0 deletions shared/p2p/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
"dial_relay_node.go",
"discovery.go",
"feed.go",
"interfaces.go",
"message.go",
"monitoring.go",
"options.go",
Expand Down
12 changes: 12 additions & 0 deletions shared/p2p/interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package p2p

import (
"github.com/gogo/protobuf/proto"
)

// Broadcaster represents a subset of the p2p.Server. This interface is useful
// for testing or when the calling code only needs access to the broadcast
// method.
type Broadcaster interface {
Broadcast(proto.Message)
}
6 changes: 5 additions & 1 deletion shared/p2p/mock/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ package(default_testonly = True)

go_library(
name = "go_default_library",
srcs = ["feed_mock.go"],
srcs = [
"broadcaster_mock.go",
"feed_mock.go",
],
importpath = "github.com/prysmaticlabs/prysm/shared/p2p/mock",
visibility = ["//visibility:public"],
deps = [
"//shared/event:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
],
)
44 changes: 44 additions & 0 deletions shared/p2p/mock/broadcaster_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions shared/p2p/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

// Ensure that server implements service.
var _ = shared.Service(&Server{})
var _ = Broadcaster(&Server{})

func init() {
logrus.SetLevel(logrus.DebugLevel)
Expand Down
5 changes: 5 additions & 0 deletions validator/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ go_library(
"runner.go",
"service.go",
"validator.go",
"validator_propose.go",
],
importpath = "github.com/prysmaticlabs/prysm/validator/client",
visibility = ["//validator:__subpackages__"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//proto/beacon/rpc/v1:go_default_library",
"//shared/params:go_default_library",
"//shared/slotutil:go_default_library",
"//shared/ssz:go_default_library",
"@com_github_gogo_protobuf//types:go_default_library",
"@com_github_opentracing_opentracing_go//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
Expand All @@ -28,10 +31,12 @@ go_test(
"fake_validator_test.go",
"runner_test.go",
"service_test.go",
"validator_propose_test.go",
"validator_test.go",
],
embed = [":go_default_library"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//proto/beacon/rpc/v1:go_default_library",
"//shared:go_default_library",
"//shared/params:go_default_library",
Expand Down
18 changes: 10 additions & 8 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package client represents the functionality to act as a validator.
package client

import (
Expand All @@ -9,21 +10,30 @@ import (

"github.com/opentracing/opentracing-go"

pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/slotutil"
)

// AttestationPool STUB interface. Final attestation pool pending design.
// TODO(1323): Replace with actual attestation pool.
type AttestationPool interface {
PendingAttestations() []*pbp2p.Attestation
}

// validator
//
// WIP - not done.
type validator struct {
genesisTime uint64
ticker *slotutil.SlotTicker
assignment *pb.Assignment
proposerClient pb.ProposerServiceClient
validatorClient pb.ValidatorServiceClient
beaconClient pb.BeaconServiceClient
pubKey []byte
attestationPool AttestationPool
}

// Done cleans up the validator.
Expand Down Expand Up @@ -128,14 +138,6 @@ func (v *validator) RoleAt(slot uint64) pb.ValidatorRole {
return pb.ValidatorRole_UNKNOWN
}

// ProposeBlock
//
// WIP - not done.
func (v *validator) ProposeBlock(ctx context.Context, slot uint64) {
span, ctx := opentracing.StartSpanFromContext(ctx, "validator.ProposeBlock")
defer span.Finish()
}

// AttestToBlockHead
//
// WIP - not done.
Expand Down
86 changes: 86 additions & 0 deletions validator/client/validator_propose.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package client

// Validator client proposer functions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be a package level godoc comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, these are just the proposer related functions for the validator client. I will add a godoc package comment though


import (
"context"
"fmt"

ptypes "github.com/gogo/protobuf/types"
"github.com/opentracing/opentracing-go"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/ssz"
)

// ProposeBlock A new beacon block for a given slot. This method collects the
// previous beacon block, any pending deposits, and ETH1 data from the beacon
// chain node to construct the new block. The new block is then processed with
// the state root computation, and finally signed by the validator before being
// sent back to the beacon node for broadcasting.
func (v *validator) ProposeBlock(ctx context.Context, slot uint64) {
span, ctx := opentracing.StartSpanFromContext(ctx, "validator.ProposeBlock")
defer span.Finish()

// 1. Fetch data from Beacon Chain node.
// Get current head beacon block.
headBlock, err := v.beaconClient.CanonicalHead(ctx, &ptypes.Empty{})
if err != nil {
log.Errorf("Failed to fetch CanonicalHead: %v", err)
return
}
_ = headBlock // TODO(1461): Actually tree hash the block.
parentTreeHash, err := ssz.TreeHash(false)
if err != nil {
log.Errorf("Failed to hash parent block: %v", err)
return
}

// Get validator ETH1 deposits which have not been included in the beacon
// chain.
pDepResp, err := v.beaconClient.PendingDeposits(ctx, &ptypes.Empty{})
if err != nil {
log.Errorf("Failed to get pending pendings: %v", err)
return
}

// Get ETH1 data.
eth1DataResp, err := v.beaconClient.Eth1Data(ctx, &ptypes.Empty{})
if err != nil {
log.Errorf("Failed to get ETH1 data: %v", err)
return
}

// 2. Construct block.
block := &pbp2p.BeaconBlock{
Slot: slot,
ParentRootHash32: parentTreeHash[:],
RandaoRevealHash32: nil, // TODO(1366): generate randao reveal from BLS
Eth1Data: eth1DataResp.Eth1Data,
Body: &pbp2p.BeaconBlockBody{
Attestations: v.attestationPool.PendingAttestations(),
ProposerSlashings: nil, // TODO(1438): Add after operations pool
AttesterSlashings: nil, // TODO(1438): Add after operations pool
Deposits: pDepResp.PendingDeposits,
Exits: nil, // TODO(1323): Add validator exits
},
}

// 3. Compute state root transition from parent block to the new block.
resp, err := v.proposerClient.ComputeStateRoot(ctx, block)
if err != nil {
log.Errorf("Unable to compute state root: %v", err)
}
block.StateRootHash32 = resp.GetStateRoot()

// 4. Sign the complete block.
// TODO(1366): BLS sign block
block.Signature = nil

// 5. Broadcast to the network via beacon chain node.
blkResp, err := v.proposerClient.ProposeBlock(ctx, block)
if err != nil {
log.WithField("error", err).Error("Failed to propose block")
return
}
log.WithField("hash", fmt.Sprintf("%#x", blkResp.BlockHash)).Info("Proposed new beacon block")
}
Loading