-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
d4697a4
WIP - with TODOs
prestonvanloon 9b20eb9
interface w/ test
prestonvanloon cca4cbd
basic test for broadcast
prestonvanloon 2a134d6
update with master
prestonvanloon e8bfd8a
Add computeStateRoot funciton
prestonvanloon b9236b1
merge master
prestonvanloon b2da996
checkpoint
prestonvanloon d928aac
remove custody challenge
prestonvanloon ea701be
resolve TODO lint issues
prestonvanloon c8201fb
more TODOs
prestonvanloon ac05fb9
revert new line in types.proto
prestonvanloon 3c83b43
broadcaster comment
prestonvanloon 242fbbc
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon 2284add
one of several failure condition tests
prestonvanloon 1e8adb8
Add test cases
prestonvanloon 337d0ba
handle compute state error test case
prestonvanloon 9e56c4c
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon 2398031
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon 18c058e
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon 17f6a0d
Merge branch 'master' into validator-proposer-rewrite
2c24627
Merge branch 'validator-proposer-rewrite' of github.com:prysmaticlabs…
prestonvanloon 388a84e
fix config in validator helpers
prestonvanloon 99c8679
fix tests too
prestonvanloon 7430472
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon 5f5a2f6
fix conflict
prestonvanloon c6f8591
partial PR feedback
prestonvanloon 8b2be2a
remove p2p
prestonvanloon 3d8c5e5
gazelle
prestonvanloon a6e07f5
package comment
prestonvanloon 8bcbd1a
Merge branch 'master' into validator-proposer-rewrite
prestonvanloon 94be890
Merge branch 'master' of github.com:prysmaticlabs/prysm into validato…
prestonvanloon d8666da
Better godoc
prestonvanloon 9969aaf
Merge branch 'validator-proposer-rewrite' of github.com:prysmaticlabs…
prestonvanloon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package client | ||
|
||
// Validator client proposer functions. | ||
|
||
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") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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