Post Chainstart Fix (#2158)

* fixed seed and correct epoch

* fix test and add comments
This commit is contained in:
Nishant Das 2019-04-05 11:13:49 +08:00 committed by terence tsao
parent 47e631d4ff
commit 687f797dd8
3 changed files with 31 additions and 36 deletions

View File

@ -307,12 +307,9 @@ func ProcessPrevSlotShardSeed(state *pb.BeaconState) *pb.BeaconState {
func ProcessCurrSlotShardSeed(state *pb.BeaconState) (*pb.BeaconState, error) {
state.CurrentShufflingStartShard = (state.CurrentShufflingStartShard +
helpers.CurrentEpochCommitteeCount(state)) % params.BeaconConfig().ShardCount
seed, err := helpers.GenerateSeed(state, state.CurrentShufflingEpoch)
if err != nil {
return nil, fmt.Errorf("could not update current shuffling seed: %v", err)
}
// TODO(#2072)we have removed the generation of a new seed for the timebeing to get it stable for the testnet.
// this will be handled in Q2.
state.CurrentShufflingEpoch = helpers.NextEpoch(state)
state.CurrentShufflingSeedHash32 = seed[:]
return state, nil
}
@ -337,11 +334,8 @@ func ProcessPartialValidatorRegistry(ctx context.Context, state *pb.BeaconState)
if epochsSinceLastRegistryChange > 1 &&
mathutil.IsPowerOf2(epochsSinceLastRegistryChange) {
state.CurrentShufflingEpoch = helpers.NextEpoch(state)
seed, err := helpers.GenerateSeed(state, state.CurrentShufflingEpoch)
if err != nil {
return nil, fmt.Errorf("could not generate seed: %v", err)
}
state.CurrentShufflingSeedHash32 = seed[:]
// TODO(#2072)we have removed the generation of a new seed for the timebeing to get it stable for the testnet.
// this will be handled in Q2.
}
return state, nil
}

View File

@ -587,11 +587,12 @@ func crosslinkCommittees(state *pb.BeaconState, input *shufflingInput) ([]*Cross
committeesPerSlot := input.committeesPerEpoch / slotsPerEpoch
slotStartShard := (input.startShard + committeesPerSlot*offSet) %
params.BeaconConfig().ShardCount
requestedEpoch := SlotToEpoch(input.slot)
shuffledIndices, err := Shuffling(
bytesutil.ToBytes32(input.seed),
state.ValidatorRegistry,
CurrentEpoch(state))
requestedEpoch)
if err != nil {
return nil, err
}

View File

@ -440,31 +440,31 @@ func TestCommitteeAssignment_CanRetrieve(t *testing.T) {
}{
{
index: 0,
slot: params.BeaconConfig().GenesisSlot + 159,
committee: []uint64{0, 123},
shard: 31,
isProposer: false,
},
{
index: 105,
slot: params.BeaconConfig().GenesisSlot + 185,
committee: []uint64{1, 105},
shard: 57,
slot: params.BeaconConfig().GenesisSlot + 160,
committee: []uint64{0, 50},
shard: 32,
isProposer: true,
},
{
index: 105,
slot: params.BeaconConfig().GenesisSlot + 130,
committee: []uint64{11, 105},
shard: 2,
isProposer: false,
},
{
index: 64,
slot: params.BeaconConfig().GenesisSlot + 176,
committee: []uint64{64, 12},
shard: 48,
slot: params.BeaconConfig().GenesisSlot + 161,
committee: []uint64{110, 64},
shard: 33,
isProposer: true,
},
{
index: 11,
slot: params.BeaconConfig().GenesisSlot + 188,
committee: []uint64{112, 11},
shard: 60,
isProposer: false,
slot: params.BeaconConfig().GenesisSlot + 130,
committee: []uint64{11, 105},
shard: 2,
isProposer: true,
},
}
@ -475,20 +475,20 @@ func TestCommitteeAssignment_CanRetrieve(t *testing.T) {
t.Fatalf("failed to execute NextEpochCommitteeAssignment: %v", err)
}
if shard != tt.shard {
t.Errorf("wanted shard %d, got shard %d",
tt.shard, shard)
t.Errorf("wanted shard %d, got shard %d for validator index %d",
tt.shard, shard, tt.index)
}
if slot != tt.slot {
t.Errorf("wanted slot %d, got slot %d",
tt.slot, slot)
t.Errorf("wanted slot %d, got slot %d for validator index %d",
tt.slot, slot, tt.index)
}
if isProposer != tt.isProposer {
t.Errorf("wanted isProposer %v, got isProposer %v",
tt.isProposer, isProposer)
t.Errorf("wanted isProposer %v, got isProposer %v for validator index %d",
tt.isProposer, isProposer, tt.index)
}
if !reflect.DeepEqual(committee, tt.committee) {
t.Errorf("wanted committee %v, got committee %v",
tt.committee, committee)
t.Errorf("wanted committee %v, got committee %v for validator index %d",
tt.committee, committee, tt.index)
}
}
}