mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Handle idx panic (#1492)
* fix panic on empty first committee * fix issue in validator server too
This commit is contained in:
@@ -64,6 +64,10 @@ func BeaconProposerIdx(state *pb.BeaconState, slot uint64) (uint64, error) {
|
||||
}
|
||||
firstCommittee := committeeArray[0].Committee
|
||||
|
||||
if len(firstCommittee) == 0 {
|
||||
return 0, fmt.Errorf("empty first committee at slot %d", slot)
|
||||
}
|
||||
|
||||
return firstCommittee[slot%uint64(len(firstCommittee))], nil
|
||||
}
|
||||
|
||||
|
||||
@@ -274,6 +274,14 @@ func TestBeaconProposerIdx(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeaconProposerIdx_returnsErrorWithEmptyCommittee(t *testing.T) {
|
||||
_, err := BeaconProposerIdx(&pb.BeaconState{}, 0)
|
||||
expected := "empty first committee at slot 0"
|
||||
if err.Error() != expected {
|
||||
t.Errorf("Unexpected error. got=%v want=%s", err, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttestingValidatorIndices_Ok(t *testing.T) {
|
||||
if params.BeaconConfig().EpochLength != 64 {
|
||||
t.Errorf("EpochLength should be 64 for these tests to pass")
|
||||
|
||||
@@ -58,20 +58,22 @@ func (vs *ValidatorServer) ValidatorEpochAssignments(
|
||||
var attesterSlot uint64
|
||||
var proposerSlot uint64
|
||||
|
||||
for i := req.EpochStart; i < req.EpochStart+params.BeaconConfig().EpochLength; i++ {
|
||||
crossLinkCommittees, err := v.CrosslinkCommitteesAtSlot(beaconState, i)
|
||||
for slot := req.EpochStart; slot < req.EpochStart+params.BeaconConfig().EpochLength; slot++ {
|
||||
crossLinkCommittees, err := v.CrosslinkCommitteesAtSlot(beaconState, slot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get crosslink committees at slot %d: %v", i, err)
|
||||
return nil, err
|
||||
}
|
||||
proposerIndex, err := v.BeaconProposerIdx(beaconState, slot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
firstCommittee := crossLinkCommittees[0].Committee
|
||||
proposerIndex := firstCommittee[i%uint64(len(firstCommittee))]
|
||||
if proposerIndex == validatorIndex {
|
||||
proposerSlot = i
|
||||
proposerSlot = slot
|
||||
}
|
||||
for _, committee := range crossLinkCommittees {
|
||||
for _, idx := range committee.Committee {
|
||||
if idx == validatorIndex {
|
||||
attesterSlot = i
|
||||
attesterSlot = slot
|
||||
shard = committee.Shard
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user