adding attestation (#590)

This commit is contained in:
Nishant Das 2018-09-29 17:09:05 +08:00 committed by GitHub
parent a03baa8055
commit c4ea6b8e13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {