-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP - with TODOs * interface w/ test * basic test for broadcast * Add computeStateRoot funciton * remove custody challenge * resolve TODO lint issues * more TODOs * revert new line in types.proto * broadcaster comment * one of several failure condition tests * Add test cases * handle compute state error test case * fix config in validator helpers * fix tests too * fix conflict * partial PR feedback * remove p2p * gazelle * package comment * Better godoc
- Loading branch information
1 parent
040405b
commit 4add403
Showing
18 changed files
with
1,050 additions
and
107 deletions.
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.