diff --git a/beacon-chain/casper/sharding.go b/beacon-chain/casper/sharding.go index 3f206c580..94f77ff00 100644 --- a/beacon-chain/casper/sharding.go +++ b/beacon-chain/casper/sharding.go @@ -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 diff --git a/beacon-chain/casper/sharding_test.go b/beacon-chain/casper/sharding_test.go index 6f58b78c0..ef51b5477 100644 --- a/beacon-chain/casper/sharding_test.go +++ b/beacon-chain/casper/sharding_test.go @@ -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) } } diff --git a/beacon-chain/casper/validator.go b/beacon-chain/casper/validator.go index ba2b7608d..8b02b6c1d 100644 --- a/beacon-chain/casper/validator.go +++ b/beacon-chain/casper/validator.go @@ -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 { diff --git a/beacon-chain/casper/validator_test.go b/beacon-chain/casper/validator_test.go index b9378d18e..8b4b61f11 100644 --- a/beacon-chain/casper/validator_test.go +++ b/beacon-chain/casper/validator_test.go @@ -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)