Fix Bitfield Errors (#2588)

This commit is contained in:
Nishant Das 2019-05-13 21:43:02 +08:00 committed by terence tsao
parent eef35996de
commit e33a6d8aa5
3 changed files with 7 additions and 13 deletions

View File

@ -38,8 +38,6 @@ go_test(
"//shared/bytesutil:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
],
)

View File

@ -227,7 +227,7 @@ func (a *Service) BatchUpdateLatestAttestation(ctx context.Context, attestations
for _, attestation := range attestations {
if err := a.updateAttestation(ctx, headRoot, beaconState, attestation); err != nil {
return err
log.Error(err)
}
}
return nil
@ -309,13 +309,11 @@ func (a *Service) updateAttestation(ctx context.Context, headRoot [32]byte, beac
}
if i >= len(committee) {
log.Errorf("Bitfield points to an invalid index in the committee: bitfield %08b", bitfield)
continue
return fmt.Errorf("bitfield points to an invalid index in the committee: bitfield %08b", bitfield)
}
if int(committee[i]) >= len(beaconState.ValidatorRegistry) {
log.Errorf("Index doesn't exist in validator registry: index %d", committee[i])
continue
return fmt.Errorf("index doesn't exist in validator registry: index %d", committee[i])
}
// If the attestation came from this attester. We use the slot committee to find the

View File

@ -14,9 +14,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/sirupsen/logrus"
logTest "github.com/sirupsen/logrus/hooks/test"
)
func init() {
@ -368,7 +366,6 @@ func TestUpdateLatestAttestation_CacheEnabledAndHit(t *testing.T) {
func TestUpdateLatestAttestation_InvalidIndex(t *testing.T) {
beaconDB := internal.SetupDB(t)
hook := logTest.NewGlobal()
defer internal.TeardownDB(t, beaconDB)
ctx := context.Background()
@ -404,10 +401,11 @@ func TestUpdateLatestAttestation_InvalidIndex(t *testing.T) {
},
}
if err := service.UpdateLatestAttestation(ctx, attestation); err != nil {
t.Fatalf("could not update latest attestation: %v", err)
wanted := "bitfield points to an invalid index in the committee"
if err := service.UpdateLatestAttestation(ctx, attestation); !strings.Contains(err.Error(), wanted) {
t.Errorf("Wanted: %s but got %s", wanted, err)
}
testutil.AssertLogsContain(t, hook, "Bitfield points to an invalid index in the committee")
}
func TestBatchUpdate_FromSync(t *testing.T) {