mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-05-02 03:02:54 -04:00
adding attestation (#590)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
@@ -212,12 +213,34 @@ func (s *Service) ProposeBlock(ctx context.Context, req *pb.ProposeRequest) (*pb
|
||||
} else {
|
||||
powChainHash = s.powChainService.LatestBlockHash()
|
||||
}
|
||||
data := &pbp2p.BeaconBlock{
|
||||
SlotNumber: req.GetSlotNumber(),
|
||||
PowChainRef: powChainHash[:],
|
||||
ParentHash: req.GetParentHash(),
|
||||
Timestamp: req.GetTimestamp(),
|
||||
|
||||
//TODO(#589) The attestation should be aggregated in the validator client side not in the beacon node.
|
||||
parentSlot := req.GetSlotNumber() - 1
|
||||
cState := s.chainService.CurrentCrystallizedState()
|
||||
|
||||
_, prevProposerIndex, err := casper.ProposerShardAndIndex(
|
||||
cState.ShardAndCommitteesForSlots(),
|
||||
cState.LastStateRecalc(),
|
||||
parentSlot,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get index of previous proposer: %v", err)
|
||||
}
|
||||
|
||||
proposerBitfield := uint64(math.Pow(2, (7 - float64(prevProposerIndex))))
|
||||
attestation := &pbp2p.AggregatedAttestation{
|
||||
AttesterBitfield: []byte{byte(proposerBitfield)},
|
||||
}
|
||||
|
||||
data := &pbp2p.BeaconBlock{
|
||||
SlotNumber: req.GetSlotNumber(),
|
||||
PowChainRef: powChainHash[:],
|
||||
ParentHash: req.GetParentHash(),
|
||||
Timestamp: req.GetTimestamp(),
|
||||
Attestations: []*pbp2p.AggregatedAttestation{attestation},
|
||||
}
|
||||
|
||||
block := types.NewBlock(data)
|
||||
h, err := block.Hash()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user