Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/block_view_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func DBGetValidatorByPKIDWithTxn(txn *badger.Txn, snap *Snapshot, pkid *PKID) (*
return validatorEntry, nil
}

func DBGetTopActiveValidatorsByStake(
func DBGetTopActiveValidatorsByStakeAmount(
handle *badger.DB,
snap *Snapshot,
limit uint64,
Expand Down Expand Up @@ -630,20 +630,20 @@ func DBGetTopActiveValidatorsByStake(
handle, key, int(limit), nil, true, canSkipValidatorInBadgerSeek,
)
if err != nil {
return nil, errors.Wrapf(err, "DBGetTopActiveValidatorsByStake: problem retrieving top validators: ")
return nil, errors.Wrapf(err, "DBGetTopActiveValidatorsByStakeAmount: problem retrieving top validators: ")
}

// For each key found, parse the ValidatorPKID from the key,
// then retrieve the ValidatorEntry by the ValidatorPKID.
for _, keyFound := range keysFound {
validatorPKID, err := GetValidatorPKIDFromDBKeyForValidatorByStatusAndStakeAmount(keyFound)
if err != nil {
return nil, errors.Wrapf(err, "DBGetTopActiveValidatorsByStake: problem reading ValidatorPKID: ")
return nil, errors.Wrapf(err, "DBGetTopActiveValidatorsByStakeAmount: problem reading ValidatorPKID: ")
}
// Retrieve ValidatorEntry by PKID.
validatorEntry, err := DBGetValidatorByPKID(handle, snap, validatorPKID)
if err != nil {
return nil, errors.Wrapf(err, "DBGetTopActiveValidatorsByStake: problem retrieving validator by PKID: ")
return nil, errors.Wrapf(err, "DBGetTopActiveValidatorsByStakeAmount: problem retrieving validator by PKID: ")
}
validatorEntries = append(validatorEntries, validatorEntry)
}
Expand Down Expand Up @@ -1759,7 +1759,7 @@ func (bav *UtxoView) GetValidatorByPublicKey(validatorPublicKey *PublicKey) (*Va
return validatorEntry, nil
}

func (bav *UtxoView) GetTopActiveValidatorsByStake(limit uint64) ([]*ValidatorEntry, error) {
func (bav *UtxoView) GetTopActiveValidatorsByStakeAmount(limit uint64) ([]*ValidatorEntry, error) {
// Validate limit param.
if limit == uint64(0) {
return []*ValidatorEntry{}, nil
Expand All @@ -1777,9 +1777,9 @@ func (bav *UtxoView) GetTopActiveValidatorsByStake(limit uint64) ([]*ValidatorEn
// Pull top N active ValidatorEntries from the database (not present in the UtxoView).
// Note that we will skip validators that are present in the view because we pass
// utxoViewValidatorEntries to the function.
dbValidatorEntries, err := DBGetTopActiveValidatorsByStake(bav.Handle, bav.Snapshot, limit, utxoViewValidatorEntries)
dbValidatorEntries, err := DBGetTopActiveValidatorsByStakeAmount(bav.Handle, bav.Snapshot, limit, utxoViewValidatorEntries)
if err != nil {
return nil, errors.Wrapf(err, "UtxoView.GetTopActiveValidatorsByStake: error retrieving entries from db: ")
return nil, errors.Wrapf(err, "UtxoView.GetTopActiveValidatorsByStakeAmount: error retrieving entries from db: ")
}
// Cache top N active ValidatorEntries from the db in the UtxoView.
for _, validatorEntry := range dbValidatorEntries {
Expand Down
34 changes: 17 additions & 17 deletions lib/block_view_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func _testValidatorRegistration(t *testing.T, flushToDB bool) {
{
// Query: retrieve top active ValidatorEntries by stake.
// Should be empty since m0's TotalStakeAmountNanos is zero.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(1)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(1)
require.NoError(t, err)
require.Empty(t, validatorEntries)
}
Expand Down Expand Up @@ -275,7 +275,7 @@ func _testValidatorRegistration(t *testing.T, flushToDB bool) {
}
{
// Query: retrieve top active ValidatorEntries by stake
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(1)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(1)
require.NoError(t, err)
require.Empty(t, validatorEntries)
}
Expand Down Expand Up @@ -661,12 +661,12 @@ func TestValidatorRegistrationWithDerivedKey(t *testing.T) {
_executeAllTestRollbackAndFlush(testMeta)
}

func TestGetTopActiveValidatorsByStake(t *testing.T) {
_testGetTopActiveValidatorsByStake(t, false)
_testGetTopActiveValidatorsByStake(t, true)
func TestGetTopActiveValidatorsByStakeAmount(t *testing.T) {
_testGetTopActiveValidatorsByStakeAmount(t, false)
_testGetTopActiveValidatorsByStakeAmount(t, true)
}

func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
func _testGetTopActiveValidatorsByStakeAmount(t *testing.T, flushToDB bool) {
var validatorEntries []*ValidatorEntry
var err error

Expand Down Expand Up @@ -741,7 +741,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
require.NoError(t, err)

// Verify top validators is empty since m0's TotalStakeAmountNanos is zero.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Empty(t, validatorEntries)
}
Expand All @@ -757,7 +757,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
require.NoError(t, err)

// Verify top validators is empty since both validators' TotalStakeAmountNanos are zero.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Empty(t, validatorEntries)
}
Expand All @@ -773,7 +773,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
require.NoError(t, err)

// Verify top validators is empty since all three validators' TotalStakeAmountNanos are zero.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Empty(t, validatorEntries)
}
Expand Down Expand Up @@ -803,7 +803,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
require.NoError(t, err)

// Verify top validators.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Len(t, validatorEntries, 3)
require.Equal(t, validatorEntries[0].ValidatorPKID, m2PKID)
Expand All @@ -822,7 +822,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
_, err = _submitUnstakeTxn(testMeta, m3Pub, m3Priv, unstakeMetadata, nil, flushToDB)

// Verify top validators.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Len(t, validatorEntries, 3)
require.Equal(t, validatorEntries[0].ValidatorPKID, m2PKID)
Expand All @@ -841,7 +841,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
_, err = _submitUnstakeTxn(testMeta, m3Pub, m3Priv, unstakeMetadata, nil, flushToDB)

// Verify top validators.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Len(t, validatorEntries, 2)
require.Equal(t, validatorEntries[0].ValidatorPKID, m2PKID)
Expand All @@ -855,7 +855,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
require.NoError(t, err)

// Verify top validators.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Len(t, validatorEntries, 1)
require.Equal(t, validatorEntries[0].ValidatorPKID, m0PKID)
Expand All @@ -871,7 +871,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
require.NoError(t, err)

// Verify top validators.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Len(t, validatorEntries, 2)
require.Equal(t, validatorEntries[0].ValidatorPKID, m1PKID)
Expand All @@ -889,7 +889,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
require.NoError(t, err)

// Verify top validators.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Len(t, validatorEntries, 2)
require.Equal(t, validatorEntries[0].ValidatorPKID, m1PKID)
Expand All @@ -899,7 +899,7 @@ func _testGetTopActiveValidatorsByStake(t *testing.T, flushToDB bool) {
}
{
// Verify top validators with LIMIT.
validatorEntries, err = utxoView().GetTopActiveValidatorsByStake(1)
validatorEntries, err = utxoView().GetTopActiveValidatorsByStakeAmount(1)
require.NoError(t, err)
require.Len(t, validatorEntries, 1)
require.Equal(t, validatorEntries[0].ValidatorPKID, m1PKID)
Expand Down Expand Up @@ -1081,7 +1081,7 @@ func TestGetTopActiveValidatorsByStakeMergingDbAndUtxoView(t *testing.T) {
)

// Fetch TopActiveValidatorsByStake merging ValidatorEntries from the db and UtxoView.
validatorEntries, err := utxoView.GetTopActiveValidatorsByStake(6)
validatorEntries, err := utxoView.GetTopActiveValidatorsByStakeAmount(6)
require.NoError(t, err)
require.Len(t, validatorEntries, 3)
require.Equal(t, validatorEntries[0].ValidatorPKID, m2PKID)
Expand Down
2 changes: 1 addition & 1 deletion lib/pos_epoch_complete_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (bav *UtxoView) RunEpochCompleteHook(blockHeight uint64) error {
bav._setSnapshotGlobalParamsEntry(bav.GlobalParamsEntry, currentEpochEntry.EpochNumber)

// Snapshot the current top n active validators as the current validator set.
validatorSet, err := bav.GetTopActiveValidatorsByStake(currentGlobalParamsEntry.ValidatorSetMaxNumValidators)
validatorSet, err := bav.GetTopActiveValidatorsByStakeAmount(currentGlobalParamsEntry.ValidatorSetMaxNumValidators)
if err != nil {
return errors.Wrapf(err, "RunEpochCompleteHook: error retrieving top ValidatorEntries: ")
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pos_epoch_complete_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestRunEpochCompleteHook(t *testing.T) {
_registerAndStake(m5Pub, m5Priv, 600)
_registerAndStake(m6Pub, m6Priv, 700)

validatorEntries, err := utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err := utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Len(t, validatorEntries, 7)

Expand Down Expand Up @@ -484,7 +484,7 @@ func TestRunEpochCompleteHook(t *testing.T) {
}

getNumCurrentActiveValidators := func() int {
validatorEntries, err := utxoView().GetTopActiveValidatorsByStake(10)
validatorEntries, err := utxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
return len(validatorEntries)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/pos_leader_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (bav *UtxoView) GenerateLeaderSchedule() ([]*PKID, error) {
currentGlobalParamsEntry := bav.GetCurrentGlobalParamsEntry()

// Retrieve top, active validators ordered by stake.
validatorEntries, err := bav.GetTopActiveValidatorsByStake(currentGlobalParamsEntry.LeaderScheduleMaxNumValidators)
validatorEntries, err := bav.GetTopActiveValidatorsByStakeAmount(currentGlobalParamsEntry.LeaderScheduleMaxNumValidators)
if err != nil {
return nil, errors.Wrapf(err, "UtxoView.GenerateLeaderSchedule: error retrieving top ValidatorEntries: ")
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pos_leader_schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ func TestGenerateLeaderSchedule(t *testing.T) {
registerValidator(m6Pub, m6Priv, 700)
}
{
// Verify GetTopActiveValidatorsByStake.
validatorEntries, err := newUtxoView().GetTopActiveValidatorsByStake(10)
// Verify GetTopActiveValidatorsByStakeAmount.
validatorEntries, err := newUtxoView().GetTopActiveValidatorsByStakeAmount(10)
require.NoError(t, err)
require.Len(t, validatorEntries, 7)
require.True(t, validatorEntries[0].ValidatorPKID.Eq(m6PKID))
Expand Down