mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Fix Attestation Aggregation Bitfield (#1975)
* fixed setting aggregation bitfield * fix tests * space * travis
This commit is contained in:
parent
700264b3c7
commit
bb46784735
@ -14,6 +14,7 @@ go_library(
|
||||
deps = [
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//proto/beacon/rpc/v1:go_default_library",
|
||||
"//shared/bitutil:go_default_library",
|
||||
"//shared/forkutils:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/keystore:go_default_library",
|
||||
@ -45,6 +46,7 @@ go_test(
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//proto/beacon/rpc/v1:go_default_library",
|
||||
"//shared:go_default_library",
|
||||
"//shared/bitutil:go_default_library",
|
||||
"//shared/keystore:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bitutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@ -93,23 +94,10 @@ func (v *validator) AttestToBlockHead(ctx context.Context, slot uint64) {
|
||||
// of length len(committee)+7 // 8.
|
||||
attestation.CustodyBitfield = make([]byte, (len(resp.Committee)+7)/8)
|
||||
|
||||
// We set the attestation's aggregation bitfield by determining the index in the committee
|
||||
// corresponding to the validator and modifying the bitfield itself.
|
||||
aggregationBitfield := make([]byte, (len(resp.Committee)+7)/8)
|
||||
var indexIntoCommittee uint
|
||||
for i, validator := range resp.Committee {
|
||||
if validator == validatorIndexRes.Index {
|
||||
indexIntoCommittee = uint(i)
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(aggregationBitfield) == 0 {
|
||||
log.Error("Aggregation bitfield is empty so unable to attest to block head")
|
||||
return
|
||||
}
|
||||
aggregationBitfield[indexIntoCommittee/8] |= 1 << (indexIntoCommittee % 8)
|
||||
// Note: calling get_attestation_participants(state, attestation.data, attestation.aggregation_bitfield)
|
||||
// should return a list of length equal to 1, containing validator_index.
|
||||
|
||||
aggregationBitfield := bitutil.SetBitfield(int(validatorIndexRes.Index))
|
||||
attestation.AggregationBitfield = aggregationBitfield
|
||||
|
||||
// TODO(#1366): Use BLS to generate an aggregate signature.
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/golang/mock/gomock"
|
||||
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bitutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
@ -114,7 +115,7 @@ func TestAttestToBlockHead_AttestsCorrectly(t *testing.T) {
|
||||
|
||||
validator, m, finish := setup(t)
|
||||
defer finish()
|
||||
validatorIndex := uint64(5)
|
||||
validatorIndex := uint64(4)
|
||||
committee := []uint64{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10}
|
||||
m.validatorClient.EXPECT().ValidatorIndex(
|
||||
gomock.Any(), // ctx
|
||||
@ -150,10 +151,7 @@ func TestAttestToBlockHead_AttestsCorrectly(t *testing.T) {
|
||||
|
||||
validator.AttestToBlockHead(context.Background(), 30)
|
||||
|
||||
aggregationBitfield := make([]byte, (len(committee)+7)/8)
|
||||
// Validator index is at index 4 in the mocked committee defined in this test.
|
||||
indexIntoCommittee := uint64(4)
|
||||
aggregationBitfield[indexIntoCommittee/8] |= 1 << (indexIntoCommittee % 8)
|
||||
expectedAttestation := &pbp2p.Attestation{
|
||||
Data: &pbp2p.AttestationData{
|
||||
Slot: 30,
|
||||
@ -165,10 +163,11 @@ func TestAttestToBlockHead_AttestsCorrectly(t *testing.T) {
|
||||
CrosslinkDataRootHash32: params.BeaconConfig().ZeroHash[:],
|
||||
JustifiedEpoch: 3,
|
||||
},
|
||||
CustodyBitfield: make([]byte, (len(committee)+7)/8),
|
||||
AggregationBitfield: aggregationBitfield,
|
||||
AggregateSignature: []byte("signed"),
|
||||
CustodyBitfield: make([]byte, (len(committee)+7)/8),
|
||||
AggregateSignature: []byte("signed"),
|
||||
}
|
||||
aggregationBitfield := bitutil.SetBitfield(int(validatorIndex))
|
||||
expectedAttestation.AggregationBitfield = aggregationBitfield
|
||||
if !proto.Equal(generatedAttestation, expectedAttestation) {
|
||||
t.Errorf("Incorrectly attested head, wanted %v, received %v", expectedAttestation, generatedAttestation)
|
||||
}
|
||||
@ -279,38 +278,3 @@ func TestAttestToBlockHead_DoesAttestAfterDelay(t *testing.T) {
|
||||
delay = 0
|
||||
validator.AttestToBlockHead(context.Background(), 0)
|
||||
}
|
||||
|
||||
func TestAttestToBlockHead_EmptyAggregationBitfield(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
validator, m, finish := setup(t)
|
||||
defer finish()
|
||||
|
||||
validatorIndex := uint64(5)
|
||||
committee := []uint64{}
|
||||
m.validatorClient.EXPECT().ValidatorIndex(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.ValidatorIndexRequest{}),
|
||||
).Return(&pb.ValidatorIndexResponse{
|
||||
Index: uint64(validatorIndex),
|
||||
}, nil)
|
||||
m.validatorClient.EXPECT().CommitteeAssignment(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.ValidatorEpochAssignmentsRequest{}),
|
||||
).Return(&pb.CommitteeAssignmentResponse{
|
||||
Shard: 5,
|
||||
Committee: committee,
|
||||
}, nil)
|
||||
m.attesterClient.EXPECT().AttestationDataAtSlot(
|
||||
gomock.Any(), // ctx
|
||||
gomock.AssignableToTypeOf(&pb.AttestationDataRequest{}),
|
||||
).Return(&pb.AttestationDataResponse{
|
||||
BeaconBlockRootHash32: []byte("A"),
|
||||
EpochBoundaryRootHash32: []byte("B"),
|
||||
JustifiedBlockRootHash32: []byte("C"),
|
||||
LatestCrosslink: &pbp2p.Crosslink{CrosslinkDataRootHash32: []byte{'D'}},
|
||||
JustifiedEpoch: 3,
|
||||
}, nil)
|
||||
|
||||
validator.AttestToBlockHead(context.Background(), 30)
|
||||
testutil.AssertLogsContain(t, hook, "Aggregation bitfield is empty so unable to attest to block head")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user