mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
Fix committee assignment bugs (#1740)
* moved processiing logs to block chain service layer * fix-committee-start-shard-bug * typo * fixed test
This commit is contained in:
parent
f7ac2b1820
commit
79252f1e96
@ -260,18 +260,18 @@ func ProcessPrevSlotShardSeed(state *pb.BeaconState) *pb.BeaconState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ProcessCurrSlotShardSeed sets the current shuffling information in the beacon state.
|
// 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 +
|
// Set state.current_shuffling_start_shard = (state.current_shuffling_start_shard +
|
||||||
// get_current_epoch_committee_count(state)) % SHARD_COUNT
|
// 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)
|
// Set state.current_shuffling_seed = generate_seed(state, state.current_shuffling_epoch)
|
||||||
func ProcessCurrSlotShardSeed(state *pb.BeaconState) (*pb.BeaconState, error) {
|
func ProcessCurrSlotShardSeed(state *pb.BeaconState) (*pb.BeaconState, error) {
|
||||||
state.CurrentShufflingEpoch = helpers.NextEpoch(state)
|
|
||||||
state.CurrentShufflingStartShard = (state.CurrentShufflingStartShard +
|
state.CurrentShufflingStartShard = (state.CurrentShufflingStartShard +
|
||||||
helpers.CurrentEpochCommitteeCount(state)) % params.BeaconConfig().ShardCount
|
helpers.CurrentEpochCommitteeCount(state)) % params.BeaconConfig().ShardCount
|
||||||
seed, err := helpers.GenerateSeed(state, state.CurrentShufflingEpoch)
|
seed, err := helpers.GenerateSeed(state, state.CurrentShufflingEpoch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not update current shuffling seed: %v", err)
|
return nil, fmt.Errorf("could not update current shuffling seed: %v", err)
|
||||||
}
|
}
|
||||||
|
state.CurrentShufflingEpoch = helpers.NextEpoch(state)
|
||||||
state.CurrentShufflingSeedHash32 = seed[:]
|
state.CurrentShufflingSeedHash32 = seed[:]
|
||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
@ -144,18 +144,22 @@ func NextEpochCommitteeCount(state *pb.BeaconState) uint64 {
|
|||||||
// shuffling_epoch = state.previous_shuffling_epoch
|
// shuffling_epoch = state.previous_shuffling_epoch
|
||||||
// shuffling_start_shard = state.previous_shuffling_start_shard
|
// shuffling_start_shard = state.previous_shuffling_start_shard
|
||||||
// elif epoch == next_epoch:
|
// 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
|
// epochs_since_last_registry_update = current_epoch - state.validator_registry_update_epoch
|
||||||
// if registry_change:
|
// if registry_change:
|
||||||
|
// committees_per_epoch = get_next_epoch_committee_count(state)
|
||||||
|
// shuffling_epoch = next_epoch
|
||||||
// seed = generate_seed(state, 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
|
// 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):
|
// 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)
|
// seed = generate_seed(state, next_epoch)
|
||||||
// shuffling_start_shard = state.current_epoch_start_shard
|
// shuffling_start_shard = state.current_epoch_start_shard
|
||||||
// else:
|
// else:
|
||||||
|
// committees_per_epoch = get_current_epoch_committee_count(state)
|
||||||
|
// shuffling_epoch = state.current_shuffling_epoch
|
||||||
// seed = state.current_epoch_seed
|
// seed = state.current_epoch_seed
|
||||||
// shuffling_start_shard = state.current_epoch_start_shard
|
// shuffling_start_shard = state.current_epoch_start_shard
|
||||||
//
|
//
|
||||||
@ -200,7 +204,7 @@ func CrosslinkCommitteesAtSlot(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if wantedEpoch == currentEpoch {
|
if wantedEpoch == currentEpoch {
|
||||||
committeesPerEpoch = PrevEpochCommitteeCount(state)
|
committeesPerEpoch = CurrentEpochCommitteeCount(state)
|
||||||
seed = bytesutil.ToBytes32(state.CurrentShufflingSeedHash32)
|
seed = bytesutil.ToBytes32(state.CurrentShufflingSeedHash32)
|
||||||
shufflingEpoch = state.CurrentShufflingEpoch
|
shufflingEpoch = state.CurrentShufflingEpoch
|
||||||
shufflingStartShard = state.CurrentShufflingStartShard
|
shufflingStartShard = state.CurrentShufflingStartShard
|
||||||
@ -210,13 +214,13 @@ func CrosslinkCommitteesAtSlot(
|
|||||||
shufflingEpoch = state.PreviousShufflingEpoch
|
shufflingEpoch = state.PreviousShufflingEpoch
|
||||||
shufflingStartShard = state.PreviousShufflingStartShard
|
shufflingStartShard = state.PreviousShufflingStartShard
|
||||||
} else if wantedEpoch == nextEpoch {
|
} else if wantedEpoch == nextEpoch {
|
||||||
currentCommitteesPerEpoch := CurrentEpochCommitteeCount(state)
|
|
||||||
committeesPerEpoch = NextEpochCommitteeCount(state)
|
|
||||||
shufflingEpoch = nextEpoch
|
|
||||||
|
|
||||||
epochsSinceLastRegistryUpdate := currentEpoch - state.ValidatorRegistryUpdateEpoch
|
epochsSinceLastRegistryUpdate := currentEpoch - state.ValidatorRegistryUpdateEpoch
|
||||||
if registryChange {
|
if registryChange {
|
||||||
|
committeesPerEpoch = NextEpochCommitteeCount(state)
|
||||||
|
shufflingEpoch = nextEpoch
|
||||||
seed, err = GenerateSeed(state, nextEpoch)
|
seed, err = GenerateSeed(state, nextEpoch)
|
||||||
|
currentCommitteesPerEpoch := CurrentEpochCommitteeCount(state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not generate seed: %v", err)
|
return nil, fmt.Errorf("could not generate seed: %v", err)
|
||||||
}
|
}
|
||||||
@ -224,12 +228,16 @@ func CrosslinkCommitteesAtSlot(
|
|||||||
params.BeaconConfig().ShardCount
|
params.BeaconConfig().ShardCount
|
||||||
} else if epochsSinceLastRegistryUpdate > 1 &&
|
} else if epochsSinceLastRegistryUpdate > 1 &&
|
||||||
mathutil.IsPowerOf2(epochsSinceLastRegistryUpdate) {
|
mathutil.IsPowerOf2(epochsSinceLastRegistryUpdate) {
|
||||||
|
committeesPerEpoch = NextEpochCommitteeCount(state)
|
||||||
|
shufflingEpoch = nextEpoch
|
||||||
seed, err = GenerateSeed(state, nextEpoch)
|
seed, err = GenerateSeed(state, nextEpoch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not generate seed: %v", err)
|
return nil, fmt.Errorf("could not generate seed: %v", err)
|
||||||
}
|
}
|
||||||
shufflingStartShard = state.CurrentShufflingStartShard
|
shufflingStartShard = state.CurrentShufflingStartShard
|
||||||
} else {
|
} else {
|
||||||
|
committeesPerEpoch = CurrentEpochCommitteeCount(state)
|
||||||
|
shufflingEpoch = state.CurrentShufflingEpoch
|
||||||
seed = bytesutil.ToBytes32(state.CurrentShufflingSeedHash32)
|
seed = bytesutil.ToBytes32(state.CurrentShufflingSeedHash32)
|
||||||
shufflingStartShard = state.CurrentShufflingStartShard
|
shufflingStartShard = state.CurrentShufflingStartShard
|
||||||
}
|
}
|
||||||
|
@ -382,29 +382,29 @@ func TestNextEpochCommitteeAssignment_OK(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
index: 0,
|
index: 0,
|
||||||
slot: params.BeaconConfig().GenesisSlot + 179,
|
slot: params.BeaconConfig().GenesisSlot + 146,
|
||||||
committee: []uint64{0, 100},
|
committee: []uint64{105, 0},
|
||||||
shard: 51,
|
shard: 18,
|
||||||
isProposer: false,
|
isProposer: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
index: 105,
|
index: 105,
|
||||||
slot: params.BeaconConfig().GenesisSlot + 138,
|
slot: params.BeaconConfig().GenesisSlot + 146,
|
||||||
committee: []uint64{55, 105},
|
committee: []uint64{105, 0},
|
||||||
shard: 10,
|
shard: 18,
|
||||||
isProposer: false,
|
isProposer: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
index: 64,
|
index: 64,
|
||||||
slot: params.BeaconConfig().GenesisSlot + 176,
|
slot: params.BeaconConfig().GenesisSlot + 139,
|
||||||
committee: []uint64{126, 64},
|
committee: []uint64{64, 52},
|
||||||
shard: 48,
|
shard: 11,
|
||||||
isProposer: false,
|
isProposer: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
index: 11,
|
index: 11,
|
||||||
slot: params.BeaconConfig().GenesisSlot + 130,
|
slot: params.BeaconConfig().GenesisSlot + 130,
|
||||||
committee: []uint64{11, 14},
|
committee: []uint64{11, 121},
|
||||||
shard: 2,
|
shard: 2,
|
||||||
isProposer: true,
|
isProposer: true,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user