Skip to content

Commit

Permalink
Fix activation queue sorting (#4409)
Browse files Browse the repository at this point in the history
* Removed old save/process block atts

* Fixed tests

* Proper sorting by eligibility epoch then by indices

* Deleted old colde
  • Loading branch information
terencechain authored and rauljordan committed Jan 5, 2020
1 parent fe22107 commit 4eeefbe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
26 changes: 19 additions & 7 deletions beacon-chain/core/epoch/epoch_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ import (
"github.com/prysmaticlabs/prysm/shared/params"
)

var epochState *pb.BeaconState

// sortableIndices implements the Sort interface to sort newly activated validator indices
// by activation epoch and by index number.
type sortableIndices []uint64

func (s sortableIndices) Len() int { return len(s) }
func (s sortableIndices) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s sortableIndices) Less(i, j int) bool {
if epochState.Validators[s[i]].ActivationEligibilityEpoch == epochState.Validators[s[j]].ActivationEligibilityEpoch {
return s[i] < s[j]
}
return epochState.Validators[s[i]].ActivationEligibilityEpoch < epochState.Validators[s[j]].ActivationEligibilityEpoch
}

// MatchedAttestations is an object that contains the correctly
// voted attestations based on source, target and head criteria.
type MatchedAttestations struct {
Expand Down Expand Up @@ -162,13 +177,9 @@ func ProcessRegistryUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
activationQ = append(activationQ, uint64(idx))
}
}
// Order by the sequence of activation_eligibility_epoch setting and then index
sort.Slice(activationQ, func(i, j int) bool {
return state.Validators[i].ActivationEligibilityEpoch < state.Validators[j].ActivationEligibilityEpoch
})
sort.Slice(activationQ, func(i, j int) bool {
return activationQ[i] < activationQ[j]
})

epochState = state
sort.Sort(sortableIndices(activationQ))

// Only activate just enough validators according to the activation churn limit.
limit := len(activationQ)
Expand All @@ -186,6 +197,7 @@ func ProcessRegistryUpdates(state *pb.BeaconState) (*pb.BeaconState, error) {
if int(churnLimit) < limit {
limit = int(churnLimit)
}

for _, index := range activationQ[:limit] {
validator := state.Validators[index]
validator.ActivationEpoch = helpers.DelayedActivationExitEpoch(currentEpoch)
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/core/epoch/spectest/registry_mainnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import (
)

func TestRegistryUpdatesMainnet(t *testing.T) {
t.Skip("Skip until 4272 merged")
runRegistryUpdatesTests(t, "mainnet")
}
1 change: 0 additions & 1 deletion beacon-chain/core/epoch/spectest/registry_minimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import (
)

func TestRegistryUpdatesMinimal(t *testing.T) {
t.Skip("Skip until 4272 merged")
runRegistryUpdatesTests(t, "minimal")
}

0 comments on commit 4eeefbe

Please sign in to comment.