Update outdated spec function names and comments (#4992)

* Update outdated spec function names and comments
* VerifyMerkleBranch
* Remove error handle
* Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into slash-spec-refresh
* Merge branch 'master' into slash-spec-refresh
This commit is contained in:
Ivan Martinez 2020-03-03 13:29:41 -05:00 committed by GitHub
parent cc5fc0af1a
commit ba6b8c9321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 47 additions and 50 deletions

View File

@ -284,7 +284,7 @@ func TestArchiverService_SavesActivatedValidatorChanges(t *testing.T) {
State: headState,
}
prevEpoch := helpers.PrevEpoch(headState)
delayedActEpoch := helpers.DelayedActivationExitEpoch(prevEpoch)
delayedActEpoch := helpers.ActivationExitEpoch(prevEpoch)
val1, err := headState.ValidatorAtIndex(4)
if err != nil {
t.Fatal(err)

View File

@ -1038,7 +1038,7 @@ func verifyDeposit(beaconState *stateTrie.BeaconState, deposit *ethpb.Deposit) e
if err != nil {
return errors.Wrap(err, "could not tree hash deposit data")
}
if ok := trieutil.VerifyMerkleProof(
if ok := trieutil.VerifyMerkleBranch(
receiptRoot,
leaf[:],
int(beaconState.Eth1DepositIndex()),

View File

@ -1783,8 +1783,8 @@ func TestProcessVoluntaryExits_AppliesCorrectStatus(t *testing.T) {
t.Fatalf("Could not process exits: %v", err)
}
newRegistry := newState.Validators()
if newRegistry[0].ExitEpoch != helpers.DelayedActivationExitEpoch(state.Slot()/params.BeaconConfig().SlotsPerEpoch) {
if newRegistry[0].ExitEpoch != helpers.ActivationExitEpoch(state.Slot()/params.BeaconConfig().SlotsPerEpoch) {
t.Errorf("Expected validator exit epoch to be %d, got %d",
helpers.DelayedActivationExitEpoch(state.Slot()/params.BeaconConfig().SlotsPerEpoch), newRegistry[0].ExitEpoch)
helpers.ActivationExitEpoch(state.Slot()/params.BeaconConfig().SlotsPerEpoch), newRegistry[0].ExitEpoch)
}
}

View File

@ -132,7 +132,7 @@ func ProcessRegistryUpdates(state *stateTrie.BeaconState) (*stateTrie.BeaconStat
if err != nil {
return nil, err
}
validator.ActivationEpoch = helpers.DelayedActivationExitEpoch(currentEpoch)
validator.ActivationEpoch = helpers.ActivationExitEpoch(currentEpoch)
if err := state.UpdateValidatorAtIndex(index, validator); err != nil {
return nil, err
}

View File

@ -409,9 +409,9 @@ func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) {
t.Errorf("Could not update registry %d, wanted activation eligibility epoch %d got %d",
i, currentEpoch, validator.ActivationEligibilityEpoch)
}
if i < int(limit) && validator.ActivationEpoch != helpers.DelayedActivationExitEpoch(currentEpoch) {
if i < int(limit) && validator.ActivationEpoch != helpers.ActivationExitEpoch(currentEpoch) {
t.Errorf("Could not update registry %d, validators failed to activate: wanted activation epoch %d, got %d",
i, helpers.DelayedActivationExitEpoch(currentEpoch), validator.ActivationEpoch)
i, helpers.ActivationExitEpoch(currentEpoch), validator.ActivationEpoch)
}
if i >= int(limit) && validator.ActivationEpoch != params.BeaconConfig().FarFutureEpoch {
t.Errorf("Could not update registry %d, validators should not have been activated, wanted activation epoch: %d, got %d",
@ -480,7 +480,7 @@ func TestProcessRegistryUpdates_ValidatorsEjected(t *testing.T) {
func TestProcessRegistryUpdates_CanExits(t *testing.T) {
epoch := uint64(5)
exitEpoch := helpers.DelayedActivationExitEpoch(epoch)
exitEpoch := helpers.ActivationExitEpoch(epoch)
minWithdrawalDelay := params.BeaconConfig().MinValidatorWithdrawabilityDelay
base := &pb.BeaconState{
Slot: epoch * params.BeaconConfig().SlotsPerEpoch,

View File

@ -38,13 +38,10 @@ func checkValidatorActiveStatus(activationEpoch uint64, exitEpoch uint64, epoch
//
// Spec pseudocode definition:
// def is_slashable_validator(validator: Validator, epoch: Epoch) -> bool:
// """
// Check if ``validator`` is slashable.
// """
// return (
// validator.activation_epoch <= epoch < validator.withdrawable_epoch and
// validator.slashed is False
// )
// """
// Check if ``validator`` is slashable.
// """
// return (not validator.slashed) and (validator.activation_epoch <= epoch < validator.withdrawable_epoch)
func IsSlashableValidator(validator *ethpb.Validator, epoch uint64) bool {
active := validator.ActivationEpoch <= epoch
beforeWithdrawable := epoch < validator.WithdrawableEpoch
@ -104,7 +101,7 @@ func ActiveValidatorCount(state *stateTrie.BeaconState, epoch uint64) (uint64, e
return count, nil
}
// DelayedActivationExitEpoch takes in epoch number and returns when
// ActivationExitEpoch takes in epoch number and returns when
// the validator is eligible for activation and exit.
//
// Spec pseudocode definition:
@ -112,8 +109,8 @@ func ActiveValidatorCount(state *stateTrie.BeaconState, epoch uint64) (uint64, e
// """
// Return the epoch during which validator activations and exits initiated in ``epoch`` take effect.
// """
// return Epoch(epoch + 1 + ACTIVATION_EXIT_DELAY)
func DelayedActivationExitEpoch(epoch uint64) uint64 {
// return Epoch(epoch + 1 + MIN_SEED_LOOKAHEAD)
func ActivationExitEpoch(epoch uint64) uint64 {
return epoch + 1 + params.BeaconConfig().MaxSeedLookahead
}
@ -304,7 +301,7 @@ func isEligibileForActivationQueue(activationEligibilityEpoch uint64, effectiveB
// )
func IsEligibleForActivation(state *stateTrie.BeaconState, validator *ethpb.Validator) bool {
finalizedEpoch := state.FinalizedCheckpointEpoch()
return isEligibileForActivation(validator.ActivationEligibilityEpoch, validator.ActivationEpoch, finalizedEpoch)
return isEligibleForActivation(validator.ActivationEligibilityEpoch, validator.ActivationEpoch, finalizedEpoch)
}
// IsEligibleForActivationUsingTrie checks if the validator is eligible for activation.
@ -313,11 +310,11 @@ func IsEligibleForActivationUsingTrie(state *stateTrie.BeaconState, validator *s
if cpt == nil {
return false
}
return isEligibileForActivation(validator.ActivationEligibilityEpoch(), validator.ActivationEpoch(), cpt.Epoch)
return isEligibleForActivation(validator.ActivationEligibilityEpoch(), validator.ActivationEpoch(), cpt.Epoch)
}
// isEligibleForActivation carries out the logic for IsEligibleForActivation*
func isEligibileForActivation(activationEligibilityEpoch uint64, activationEpoch uint64, finalizedEpoch uint64) bool {
func isEligibleForActivation(activationEligibilityEpoch uint64, activationEpoch uint64, finalizedEpoch uint64) bool {
return activationEligibilityEpoch <= finalizedEpoch &&
activationEpoch == params.BeaconConfig().FarFutureEpoch
}

View File

@ -180,7 +180,7 @@ func TestBeaconProposerIndex_OK(t *testing.T) {
func TestDelayedActivationExitEpoch_OK(t *testing.T) {
epoch := uint64(9999)
got := DelayedActivationExitEpoch(epoch)
got := ActivationExitEpoch(epoch)
wanted := epoch + 1 + params.BeaconConfig().MaxSeedLookahead
if wanted != got {
t.Errorf("Wanted: %d, received: %d", wanted, got)

View File

@ -53,7 +53,7 @@ func InitiateValidatorExit(state *stateTrie.BeaconState, idx uint64) (*stateTrie
exitEpochs = append(exitEpochs, val.ExitEpoch)
}
}
exitEpochs = append(exitEpochs, helpers.DelayedActivationExitEpoch(helpers.CurrentEpoch(state)))
exitEpochs = append(exitEpochs, helpers.ActivationExitEpoch(helpers.CurrentEpoch(state)))
// Obtain the exit queue epoch as the maximum number in the exit epochs array.
exitQueueEpoch := uint64(0)
@ -169,7 +169,7 @@ func SlashValidator(state *stateTrie.BeaconState, slashedIdx uint64, whistleBlow
// ActivatedValidatorIndices determines the indices activated during the current epoch.
func ActivatedValidatorIndices(epoch uint64, validators []*ethpb.Validator) []uint64 {
activations := make([]uint64, 0)
delayedActivationEpoch := helpers.DelayedActivationExitEpoch(epoch)
delayedActivationEpoch := helpers.ActivationExitEpoch(epoch)
for i := 0; i < len(validators); i++ {
val := validators[i]
if val.ActivationEpoch == delayedActivationEpoch {

View File

@ -223,16 +223,16 @@ func TestActivatedValidatorIndices(t *testing.T) {
Slot: 0,
Validators: []*ethpb.Validator{
{
ActivationEpoch: helpers.DelayedActivationExitEpoch(0),
ActivationEpoch: helpers.ActivationExitEpoch(0),
},
{
ActivationEpoch: helpers.DelayedActivationExitEpoch(0),
ActivationEpoch: helpers.ActivationExitEpoch(0),
},
{
ActivationEpoch: helpers.DelayedActivationExitEpoch(5),
ActivationEpoch: helpers.ActivationExitEpoch(5),
},
{
ActivationEpoch: helpers.DelayedActivationExitEpoch(0),
ActivationEpoch: helpers.ActivationExitEpoch(0),
},
},
},
@ -243,7 +243,7 @@ func TestActivatedValidatorIndices(t *testing.T) {
Slot: 0,
Validators: []*ethpb.Validator{
{
ActivationEpoch: helpers.DelayedActivationExitEpoch(10),
ActivationEpoch: helpers.ActivationExitEpoch(10),
},
},
},
@ -254,7 +254,7 @@ func TestActivatedValidatorIndices(t *testing.T) {
Slot: 0,
Validators: []*ethpb.Validator{
{
ActivationEpoch: helpers.DelayedActivationExitEpoch(0),
ActivationEpoch: helpers.ActivationExitEpoch(0),
},
},
},

View File

@ -500,7 +500,7 @@ func (bs *Server) GetValidatorQueue(
vals := headState.Validators()
for idx, validator := range vals {
eligibleActivated := validator.ActivationEligibilityEpoch != params.BeaconConfig().FarFutureEpoch
canBeActive := validator.ActivationEpoch >= helpers.DelayedActivationExitEpoch(headState.FinalizedCheckpointEpoch())
canBeActive := validator.ActivationEpoch >= helpers.ActivationExitEpoch(headState.FinalizedCheckpointEpoch())
if eligibleActivated && canBeActive {
activationQ = append(activationQ, uint64(idx))
}

View File

@ -409,7 +409,7 @@ func (is *infostream) calculateActivationTimeForPendingValidators(res []*ethpb.V
for i := uint64(0); i < toProcess; i++ {
validator := validators[sortedIndices[i]]
if index, exists := pendingValidatorsMap[validator.PublicKey()]; exists {
res[index].TransitionTimestamp = is.epochToTimestamp(helpers.DelayedActivationExitEpoch(curEpoch))
res[index].TransitionTimestamp = is.epochToTimestamp(helpers.ActivationExitEpoch(curEpoch))
delete(pendingValidatorsMap, validator.PublicKey())
}
numAttestingValidators++

View File

@ -1121,7 +1121,7 @@ func TestServer_GetValidatorActiveSetChanges(t *testing.T) {
slashed := false
// Mark indices divisible by two as activated.
if i%2 == 0 {
activationEpoch = helpers.DelayedActivationExitEpoch(0)
activationEpoch = helpers.ActivationExitEpoch(0)
} else if i%3 == 0 {
// Mark indices divisible by 3 as slashed.
withdrawableEpoch = params.BeaconConfig().EpochsPerSlashingsVector
@ -1277,19 +1277,19 @@ func TestServer_GetValidatorQueue_PendingActivation(t *testing.T) {
headState, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
Validators: []*ethpb.Validator{
{
ActivationEpoch: helpers.DelayedActivationExitEpoch(0),
ActivationEpoch: helpers.ActivationExitEpoch(0),
ActivationEligibilityEpoch: 3,
PublicKey: pubKey(3),
WithdrawalCredentials: make([]byte, 32),
},
{
ActivationEpoch: helpers.DelayedActivationExitEpoch(0),
ActivationEpoch: helpers.ActivationExitEpoch(0),
ActivationEligibilityEpoch: 2,
PublicKey: pubKey(2),
WithdrawalCredentials: make([]byte, 32),
},
{
ActivationEpoch: helpers.DelayedActivationExitEpoch(0),
ActivationEpoch: helpers.ActivationExitEpoch(0),
ActivationEligibilityEpoch: 1,
PublicKey: pubKey(1),
WithdrawalCredentials: make([]byte, 32),

View File

@ -181,7 +181,7 @@ func TestValidatorStatus_Active(t *testing.T) {
depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, depositTrie.Root())
// Active because activation epoch <= current epoch < exit epoch.
activeEpoch := helpers.DelayedActivationExitEpoch(0)
activeEpoch := helpers.ActivationExitEpoch(0)
block := blk.NewGenesisBlock([]byte{})
if err := db.SaveBlock(ctx, block); err != nil {
@ -251,7 +251,7 @@ func TestValidatorStatus_Exiting(t *testing.T) {
// Initiated exit because validator exit epoch and withdrawable epoch are not FAR_FUTURE_EPOCH
slot := uint64(10000)
epoch := helpers.SlotToEpoch(slot)
exitEpoch := helpers.DelayedActivationExitEpoch(epoch)
exitEpoch := helpers.ActivationExitEpoch(epoch)
withdrawableEpoch := exitEpoch + params.BeaconConfig().MinValidatorWithdrawabilityDelay
block := blk.NewGenesisBlock([]byte{})
if err := db.SaveBlock(ctx, block); err != nil {
@ -752,7 +752,7 @@ func TestDepositBlockSlotAfterGenesisTime(t *testing.T) {
t.Fatalf("Could not get signing root %v", err)
}
activeEpoch := helpers.DelayedActivationExitEpoch(0)
activeEpoch := helpers.ActivationExitEpoch(0)
state, err := stateTrie.InitializeFromProtoUnsafe(&pbp2p.BeaconState{
GenesisTime: uint64(time.Unix(0, 0).Unix()),
@ -831,7 +831,7 @@ func TestDepositBlockSlotBeforeGenesisTime(t *testing.T) {
t.Fatalf("Could not get signing root %v", err)
}
activeEpoch := helpers.DelayedActivationExitEpoch(0)
activeEpoch := helpers.ActivationExitEpoch(0)
state, err := stateTrie.InitializeFromProtoUnsafe(&pbp2p.BeaconState{
GenesisTime: uint64(time.Unix(25000, 0).Unix()),

View File

@ -179,8 +179,8 @@ func (m *SparseMerkleTrie) ToProto() *protodb.SparseMerkleTrie {
return trie
}
// VerifyMerkleProof verifies a Merkle branch against a root of a trie.
func VerifyMerkleProof(root []byte, item []byte, merkleIndex int, proof [][]byte) bool {
// VerifyMerkleBranch verifies a Merkle branch against a root of a trie.
func VerifyMerkleBranch(root []byte, item []byte, merkleIndex int, proof [][]byte) bool {
node := bytesutil.ToBytes32(item)
currentIndex := merkleIndex
for i := 0; i < len(proof); i++ {

View File

@ -129,17 +129,17 @@ func TestMerkleTrie_VerifyMerkleProof(t *testing.T) {
t.Errorf("Received len %d, wanted 33", len(proof))
}
root := m.Root()
if ok := VerifyMerkleProof(root[:], items[0], 0, proof); !ok {
if ok := VerifyMerkleBranch(root[:], items[0], 0, proof); !ok {
t.Error("First Merkle proof did not verify")
}
proof, err = m.MerkleProof(3)
if err != nil {
t.Fatalf("Could not generate Merkle proof: %v", err)
}
if ok := VerifyMerkleProof(root[:], items[3], 3, proof); !ok {
if ok := VerifyMerkleBranch(root[:], items[3], 3, proof); !ok {
t.Error("Second Merkle proof did not verify")
}
if ok := VerifyMerkleProof(root[:], []byte("buzz"), 3, proof); ok {
if ok := VerifyMerkleBranch(root[:], []byte("buzz"), 3, proof); ok {
t.Error("Item not in tree should fail to verify")
}
}
@ -160,7 +160,7 @@ func TestMerkleTrie_VerifyMerkleProof_TrieUpdated(t *testing.T) {
t.Fatalf("Could not generate Merkle proof: %v", err)
}
root := m.Root()
if ok := VerifyMerkleProof(root[:], items[0], 0, proof); !ok {
if ok := VerifyMerkleBranch(root[:], items[0], 0, proof); !ok {
t.Error("First Merkle proof did not verify")
}
@ -171,10 +171,10 @@ func TestMerkleTrie_VerifyMerkleProof_TrieUpdated(t *testing.T) {
t.Fatalf("Could not generate Merkle proof: %v", err)
}
root = m.Root()
if ok := VerifyMerkleProof(root[:], []byte{5}, 3, proof); !ok {
if ok := VerifyMerkleBranch(root[:], []byte{5}, 3, proof); !ok {
t.Error("Second Merkle proof did not verify")
}
if ok := VerifyMerkleProof(root[:], []byte{4}, 3, proof); ok {
if ok := VerifyMerkleBranch(root[:], []byte{4}, 3, proof); ok {
t.Error("Old item should not verify")
}
@ -284,7 +284,7 @@ func BenchmarkVerifyMerkleBranch(b *testing.B) {
root := m.Root()
b.StartTimer()
for i := 0; i < b.N; i++ {
if ok := VerifyMerkleProof(root[:], items[2], 2, proof); !ok {
if ok := VerifyMerkleBranch(root[:], items[2], 2, proof); !ok {
b.Error("Merkle proof did not verify")
}
}

View File

@ -156,7 +156,7 @@ func TestEndtoEndDeposits(t *testing.T) {
if err != nil {
t.Fatalf("Could not generate proof: %v", err)
}
if ok := trieutil.VerifyMerkleProof(
if ok := trieutil.VerifyMerkleBranch(
root[:],
encodedDeposit,
i,