diff --git a/beacon-chain/core/epoch/epoch_processing.go b/beacon-chain/core/epoch/epoch_processing.go index d7f27912f..d648b6e4c 100644 --- a/beacon-chain/core/epoch/epoch_processing.go +++ b/beacon-chain/core/epoch/epoch_processing.go @@ -260,18 +260,18 @@ func ProcessPrevSlotShardSeed(state *pb.BeaconState) *pb.BeaconState { } // ProcessCurrSlotShardSeed sets the current shuffling information in the beacon state. -// Set state.current_shuffling_epoch = next_epoch // Set state.current_shuffling_start_shard = (state.current_shuffling_start_shard + // get_current_epoch_committee_count(state)) % SHARD_COUNT +// Set state.current_shuffling_epoch = next_epoch // Set state.current_shuffling_seed = generate_seed(state, state.current_shuffling_epoch) func ProcessCurrSlotShardSeed(state *pb.BeaconState) (*pb.BeaconState, error) { - state.CurrentShufflingEpoch = helpers.NextEpoch(state) 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) } + state.CurrentShufflingEpoch = helpers.NextEpoch(state) state.CurrentShufflingSeedHash32 = seed[:] return state, nil } diff --git a/beacon-chain/core/helpers/committee.go b/beacon-chain/core/helpers/committee.go index af9716648..8b18ebca8 100644 --- a/beacon-chain/core/helpers/committee.go +++ b/beacon-chain/core/helpers/committee.go @@ -144,18 +144,22 @@ func NextEpochCommitteeCount(state *pb.BeaconState) uint64 { // shuffling_epoch = state.previous_shuffling_epoch // shuffling_start_shard = state.previous_shuffling_start_shard // elif epoch == next_epoch: -// current_committees_per_epoch = get_current_epoch_committee_count(state) -// committees_per_epoch = get_next_epoch_committee_count(state) -// shuffling_epoch = next_epoch // // epochs_since_last_registry_update = current_epoch - state.validator_registry_update_epoch // if registry_change: +// committees_per_epoch = get_next_epoch_committee_count(state) +// shuffling_epoch = next_epoch // seed = generate_seed(state, next_epoch) +// current_committees_per_epoch = get_current_epoch_committee_count(state) // shuffling_start_shard = (state.current_epoch_start_shard + current_committees_per_epoch) % SHARD_COUNT // elif epochs_since_last_registry_update > 1 and is_power_of_two(epochs_since_last_registry_update): +// committees_per_epoch = get_next_epoch_committee_count(state) +// shuffling_epoch = next_epoch // seed = generate_seed(state, next_epoch) // shuffling_start_shard = state.current_epoch_start_shard // else: +// committees_per_epoch = get_current_epoch_committee_count(state) +// shuffling_epoch = state.current_shuffling_epoch // seed = state.current_epoch_seed // shuffling_start_shard = state.current_epoch_start_shard // @@ -200,7 +204,7 @@ func CrosslinkCommitteesAtSlot( } if wantedEpoch == currentEpoch { - committeesPerEpoch = PrevEpochCommitteeCount(state) + committeesPerEpoch = CurrentEpochCommitteeCount(state) seed = bytesutil.ToBytes32(state.CurrentShufflingSeedHash32) shufflingEpoch = state.CurrentShufflingEpoch shufflingStartShard = state.CurrentShufflingStartShard @@ -210,13 +214,13 @@ func CrosslinkCommitteesAtSlot( shufflingEpoch = state.PreviousShufflingEpoch shufflingStartShard = state.PreviousShufflingStartShard } else if wantedEpoch == nextEpoch { - currentCommitteesPerEpoch := CurrentEpochCommitteeCount(state) - committeesPerEpoch = NextEpochCommitteeCount(state) - shufflingEpoch = nextEpoch epochsSinceLastRegistryUpdate := currentEpoch - state.ValidatorRegistryUpdateEpoch if registryChange { + committeesPerEpoch = NextEpochCommitteeCount(state) + shufflingEpoch = nextEpoch seed, err = GenerateSeed(state, nextEpoch) + currentCommitteesPerEpoch := CurrentEpochCommitteeCount(state) if err != nil { return nil, fmt.Errorf("could not generate seed: %v", err) } @@ -224,12 +228,16 @@ func CrosslinkCommitteesAtSlot( params.BeaconConfig().ShardCount } else if epochsSinceLastRegistryUpdate > 1 && mathutil.IsPowerOf2(epochsSinceLastRegistryUpdate) { + committeesPerEpoch = NextEpochCommitteeCount(state) + shufflingEpoch = nextEpoch seed, err = GenerateSeed(state, nextEpoch) if err != nil { return nil, fmt.Errorf("could not generate seed: %v", err) } shufflingStartShard = state.CurrentShufflingStartShard } else { + committeesPerEpoch = CurrentEpochCommitteeCount(state) + shufflingEpoch = state.CurrentShufflingEpoch seed = bytesutil.ToBytes32(state.CurrentShufflingSeedHash32) shufflingStartShard = state.CurrentShufflingStartShard } diff --git a/beacon-chain/core/helpers/committee_test.go b/beacon-chain/core/helpers/committee_test.go index 8c90e8cf8..9b7087167 100644 --- a/beacon-chain/core/helpers/committee_test.go +++ b/beacon-chain/core/helpers/committee_test.go @@ -382,29 +382,29 @@ func TestNextEpochCommitteeAssignment_OK(t *testing.T) { }{ { index: 0, - slot: params.BeaconConfig().GenesisSlot + 179, - committee: []uint64{0, 100}, - shard: 51, + slot: params.BeaconConfig().GenesisSlot + 146, + committee: []uint64{105, 0}, + shard: 18, isProposer: false, }, { index: 105, - slot: params.BeaconConfig().GenesisSlot + 138, - committee: []uint64{55, 105}, - shard: 10, - isProposer: false, + slot: params.BeaconConfig().GenesisSlot + 146, + committee: []uint64{105, 0}, + shard: 18, + isProposer: true, }, { index: 64, - slot: params.BeaconConfig().GenesisSlot + 176, - committee: []uint64{126, 64}, - shard: 48, + slot: params.BeaconConfig().GenesisSlot + 139, + committee: []uint64{64, 52}, + shard: 11, isProposer: false, }, { index: 11, slot: params.BeaconConfig().GenesisSlot + 130, - committee: []uint64{11, 14}, + committee: []uint64{11, 121}, shard: 2, isProposer: true, },