revert 2 initial committees to 3 (#746)

This commit is contained in:
terence tsao 2018-11-13 07:26:47 -08:00 committed by GitHub
parent 6520c8ffc2
commit 9e096302d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 9 deletions

View File

@ -29,8 +29,9 @@ func InitialShardAndCommitteesForSlots(validators []*pb.ValidatorRecord) ([]*pb.
return nil, err
}
// Initialize with 2 cycles of the same committees.
initialCommittees := make([]*pb.ShardAndCommitteeArray, 0, 2*params.GetConfig().CycleLength)
// Initialize with 3 cycles of the same committees.
initialCommittees := make([]*pb.ShardAndCommitteeArray, 0, 3*params.GetConfig().CycleLength)
initialCommittees = append(initialCommittees, committees...)
initialCommittees = append(initialCommittees, committees...)
initialCommittees = append(initialCommittees, committees...)
return initialCommittees, nil

View File

@ -24,14 +24,14 @@ func TestGetShardAndCommitteesForSlots(t *testing.T) {
if _, err := GetShardAndCommitteesForSlot(state.ShardAndCommitteesForSlots, state.LastStateRecalculationSlot, 1000); err == nil {
t.Error("getShardAndCommitteesForSlot should have failed with invalid slot")
}
committee, err := GetShardAndCommitteesForSlot(state.ShardAndCommitteesForSlots, state.LastStateRecalculationSlot, 1)
committee, err := GetShardAndCommitteesForSlot(state.ShardAndCommitteesForSlots, state.LastStateRecalculationSlot, 0)
if err != nil {
t.Errorf("getShardAndCommitteesForSlot failed: %v", err)
}
if committee.ArrayShardAndCommittee[0].Shard != 1 {
t.Errorf("getShardAndCommitteesForSlot returns Shard should be 1, got: %v", committee.ArrayShardAndCommittee[0].Shard)
}
committee, _ = GetShardAndCommitteesForSlot(state.ShardAndCommitteesForSlots, state.LastStateRecalculationSlot, 2)
committee, _ = GetShardAndCommitteesForSlot(state.ShardAndCommitteesForSlots, state.LastStateRecalculationSlot, 1)
if committee.ArrayShardAndCommittee[0].Shard != 3 {
t.Errorf("getShardAndCommitteesForSlot returns Shard should be 3, got: %v", committee.ArrayShardAndCommittee[0].Shard)
}
@ -77,8 +77,8 @@ func TestInitialShardAndCommiteeForSlots(t *testing.T) {
t.Fatalf("unable to get initial shard committees %v", err)
}
if uint64(len(shardAndCommitteeArray)) != 2*params.GetConfig().CycleLength {
t.Errorf("shard committee slots are not as expected: %d instead of %d", len(shardAndCommitteeArray), 2*params.GetConfig().CycleLength)
if uint64(len(shardAndCommitteeArray)) != 3*params.GetConfig().CycleLength {
t.Errorf("shard committee slots are not as expected: %d instead of %d", len(shardAndCommitteeArray), 3*params.GetConfig().CycleLength)
}
}

View File

@ -51,7 +51,7 @@ func GetShardAndCommitteesForSlot(shardCommittees []*pb.ShardAndCommitteeArray,
var lowerBound uint64
if lastStateRecalc >= cycleLength {
lowerBound = lastStateRecalc - cycleLength + 1
lowerBound = lastStateRecalc - cycleLength
}
upperBound := lastStateRecalc + 2*cycleLength
if slot < lowerBound || slot >= upperBound {

View File

@ -136,8 +136,8 @@ func TestProposerShardAndIndex(t *testing.T) {
if err != nil {
t.Fatalf("ProposerShardAndIndex failed with %v", err)
}
if shard != 0 {
t.Errorf("Invalid shard ID. Wanted 0, got %d", shard)
if shard != 2 {
t.Errorf("Invalid shard ID. Wanted 2, got %d", shard)
}
if index != 0 {
t.Errorf("Invalid proposer index. Wanted 0, got %d", index)