-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple Proposer Slots Allowed Per Epoch for Validators #5344
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d8f8449
allow multiple proposer slots
rauljordan c5d48c4
multi propose
rauljordan 5205336
proposer indices to slots map
rauljordan f7f4cc4
remove deprecated comm assign
rauljordan 039fbe8
Apply suggestions from code review
rauljordan e84546e
Merge refs/heads/v0.11 into multiple-props
prylabs-bulldozer[bot] f2e20ce
resolve broken tests, add logic in validator client
rauljordan 1b19efc
Merge branch 'multiple-props' of github.com:prysmaticlabs/prysm into …
rauljordan cc6f895
fix val tests
rauljordan 18a6651
Merge refs/heads/v0.11 into multiple-props
prylabs-bulldozer[bot] 2b941d8
Merge refs/heads/v0.11 into multiple-props
prylabs-bulldozer[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,12 @@ import ( | |
"fmt" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" | ||
"github.com/prysmaticlabs/go-bitfield" | ||
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" | ||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" | ||
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" | ||
"github.com/prysmaticlabs/prysm/shared/attestationutil" | ||
"github.com/prysmaticlabs/prysm/shared/bytesutil" | ||
"github.com/prysmaticlabs/prysm/shared/featureconfig" | ||
|
@@ -191,148 +190,6 @@ func TestVerifyBitfieldLength_OK(t *testing.T) { | |
} | ||
} | ||
|
||
func TestCommitteeAssignment_CanRetrieve(t *testing.T) { | ||
ClearCache() | ||
// Initialize test with 128 validators, each slot and each index gets 2 validators. | ||
validators := make([]*ethpb.Validator, 2*params.BeaconConfig().SlotsPerEpoch) | ||
for i := 0; i < len(validators); i++ { | ||
validators[i] = ðpb.Validator{ | ||
ExitEpoch: params.BeaconConfig().FarFutureEpoch, | ||
} | ||
} | ||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{ | ||
Validators: validators, | ||
Slot: params.BeaconConfig().SlotsPerEpoch, | ||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), | ||
}) | ||
|
||
tests := []struct { | ||
index uint64 | ||
slot uint64 | ||
committee []uint64 | ||
committeeIndex uint64 | ||
isProposer bool | ||
proposerSlot uint64 | ||
}{ | ||
{ | ||
index: 0, | ||
slot: 78, | ||
committee: []uint64{0, 38}, | ||
committeeIndex: 0, | ||
isProposer: false, | ||
}, | ||
{ | ||
index: 1, | ||
slot: 71, | ||
committee: []uint64{1, 4}, | ||
committeeIndex: 0, | ||
isProposer: true, | ||
proposerSlot: 79, | ||
}, | ||
{ | ||
index: 11, | ||
slot: 90, | ||
committee: []uint64{31, 11}, | ||
committeeIndex: 0, | ||
isProposer: false, | ||
}, | ||
} | ||
|
||
for i, tt := range tests { | ||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { | ||
committee, committeeIndex, slot, proposerSlot, err := CommitteeAssignment(state, tt.slot/params.BeaconConfig().SlotsPerEpoch, tt.index) | ||
if err != nil { | ||
t.Fatalf("failed to execute NextEpochCommitteeAssignment: %v", err) | ||
} | ||
if committeeIndex != tt.committeeIndex { | ||
t.Errorf("wanted committeeIndex %d, got committeeIndex %d for validator index %d", | ||
tt.committeeIndex, committeeIndex, tt.index) | ||
} | ||
if slot != tt.slot { | ||
t.Errorf("wanted slot %d, got slot %d for validator index %d", | ||
tt.slot, slot, tt.index) | ||
} | ||
if proposerSlot != tt.proposerSlot { | ||
t.Errorf("wanted proposer slot %d, got proposer slot %d for validator index %d", | ||
tt.proposerSlot, proposerSlot, tt.index) | ||
} | ||
if !reflect.DeepEqual(committee, tt.committee) { | ||
t.Errorf("wanted committee %v, got committee %v for validator index %d", | ||
tt.committee, committee, tt.index) | ||
} | ||
if proposerSlot != tt.proposerSlot { | ||
t.Errorf("wanted proposer slot slot %d, got slot %d for validator index %d", | ||
tt.slot, slot, tt.index) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestCommitteeAssignment_CantFindValidator(t *testing.T) { | ||
ClearCache() | ||
validators := make([]*ethpb.Validator, 1) | ||
for i := 0; i < len(validators); i++ { | ||
validators[i] = ðpb.Validator{ | ||
ExitEpoch: params.BeaconConfig().FarFutureEpoch, | ||
} | ||
} | ||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{ | ||
Validators: validators, | ||
Slot: params.BeaconConfig().SlotsPerEpoch, | ||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), | ||
}) | ||
|
||
index := uint64(10000) | ||
_, _, _, _, err := CommitteeAssignment(state, 1, index) | ||
if err != nil && !strings.Contains(err.Error(), "not found in assignments") { | ||
t.Errorf("Wanted 'not found in assignments', received %v", err) | ||
} | ||
} | ||
|
||
// Test helpers.CommitteeAssignments against the results of helpers.CommitteeAssignment by validator | ||
// index. Warning: this test is a bit slow! | ||
func TestCommitteeAssignments_AgreesWithSpecDefinitionMethod(t *testing.T) { | ||
ClearCache() | ||
// Initialize test with 256 validators, each slot and each index gets 4 validators. | ||
validators := make([]*ethpb.Validator, 4*params.BeaconConfig().SlotsPerEpoch) | ||
for i := 0; i < len(validators); i++ { | ||
validators[i] = ðpb.Validator{ | ||
ExitEpoch: params.BeaconConfig().FarFutureEpoch, | ||
} | ||
} | ||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{ | ||
Validators: validators, | ||
Slot: params.BeaconConfig().SlotsPerEpoch, | ||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), | ||
}) | ||
// Test for 2 epochs. | ||
for epoch := uint64(0); epoch < 2; epoch++ { | ||
state, _ := beaconstate.InitializeFromProto(state.CloneInnerState()) | ||
assignments, proposers, err := CommitteeAssignments(state, epoch) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for i := uint64(0); int(i) < len(validators); i++ { | ||
committee, committeeIndex, slot, proposerSlot, err := CommitteeAssignment(state, epoch, i) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !reflect.DeepEqual(committee, assignments[i].Committee) { | ||
t.Errorf("Computed different committees for validator %d", i) | ||
} | ||
if committeeIndex != assignments[i].CommitteeIndex { | ||
t.Errorf("Computed different committee index for validator %d", i) | ||
} | ||
if slot != assignments[i].AttesterSlot { | ||
t.Errorf("Computed different attesting slot for validator %d", i) | ||
} | ||
if proposerSlot != proposers[i] { | ||
t.Errorf("Computed different proposing slot for validator %d", i) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestCommitteeAssignments_CanRetrieve(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this test be run with more slots per epoch so we could have a validator that gets more then one slot in an epoch to propose for? |
||
// Initialize test with 256 validators, each slot and each index gets 4 validators. | ||
validators := make([]*ethpb.Validator, 4*params.BeaconConfig().SlotsPerEpoch) | ||
|
@@ -395,7 +252,7 @@ func TestCommitteeAssignments_CanRetrieve(t *testing.T) { | |
for i, tt := range tests { | ||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { | ||
ClearCache() | ||
validatorIndexToCommittee, proposerIndexToSlot, err := CommitteeAssignments(state, SlotToEpoch(tt.slot)) | ||
validatorIndexToCommittee, proposerIndexToSlots, err := CommitteeAssignments(state, SlotToEpoch(tt.slot)) | ||
if err != nil { | ||
t.Fatalf("failed to determine CommitteeAssignments: %v", err) | ||
} | ||
|
@@ -408,9 +265,9 @@ func TestCommitteeAssignments_CanRetrieve(t *testing.T) { | |
t.Errorf("wanted slot %d, got slot %d for validator index %d", | ||
tt.slot, cac.AttesterSlot, tt.index) | ||
} | ||
if proposerIndexToSlot[tt.index] != tt.proposerSlot { | ||
if len(proposerIndexToSlots[tt.index]) > 0 && proposerIndexToSlots[tt.index][0] != tt.proposerSlot { | ||
t.Errorf("wanted proposer slot %d, got proposer slot %d for validator index %d", | ||
tt.proposerSlot, proposerIndexToSlot[tt.index], tt.index) | ||
tt.proposerSlot, proposerIndexToSlots[tt.index][0], tt.index) | ||
} | ||
if !reflect.DeepEqual(cac.Committee, tt.committee) { | ||
t.Errorf("wanted committee %v, got committee %v for validator index %d", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove this ? dont we need it for a single validator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecated since several months, it isn't used anywhere in the codebase