Skip to content

Conversation

@mattfoley8
Copy link
Contributor

No description provided.

@mattfoley8 mattfoley8 self-assigned this May 31, 2023
@mattfoley8 mattfoley8 requested a review from a team as a code owner May 31, 2023 17:07
@mattfoley8 mattfoley8 changed the title Mf/stub out epoch complete hook Snapshot GlobalParams, ValidatorSet, GlobalActiveStake, and LeaderSchedule May 31, 2023
ValidatorPKID PKID
}

func (bav *UtxoView) SnapshotCurrentValidators(snapshotAtEpochNumber uint64) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this but I thought it may be good enough for now. I'm not sure how many validators we are expecting. I load all validators into memory to merge between the database and the UtxoView before snapshotting them. Alternatively, I could copy over all validators in the database one-by-one (without even byte-decoding them), and then just insert or delete any validators in the UtxoView. This would increase the number of db inserts/deletes, but reduce the memory footprint. Happy to make that change if others think it's way better. Also happy to punt on that change until our validator set gets unwieldy to load into memory.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now and can be optimized later.

return validatorEntry, nil
}

func (bav *UtxoView) GetSnapshotTopActiveValidatorsByStake(limit uint64, snapshotAtEpochNumber uint64) ([]*ValidatorEntry, error) {
Copy link
Contributor Author

@mattfoley8 mattfoley8 May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some code duplication between e.g. GetTopActiveValidatorsByStake and GetSnapshotTopActiveValidatorsByStake. Not enough to IMO refactor into one function, but just calling it out. We could have the active (non-snapshot set) default to SnapshotAtEpochNumber = 0 and then reuse the indices + functions. So basically, if we are updating the current active validator set in consensus, we assume the SnapshotAtEpochNumber = 0, that's actually where we would store the current validator set. And any rows in that index where SnapshotAtEpochNumber > 0 are snapshot values. I think there's something nice to having them split apart (more future-proof in case their logic diverges), but I could do a pretty big refactor to combine the current + snapshot ValidatorEntries into a single index, one for by PKID and one for by stake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same could be done for GlobalActiveStakeAmountNanos.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like keeping the snapshotting logic separate

bav._setSnapshotLeaderScheduleValidator(validatorPKID, uint8(index), currentEpochEntry.EpochNumber)
}

// TODO: Jail inactive validators.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll address these in a future PR.

ValidatorPKID PKID
}

func (bav *UtxoView) SnapshotCurrentValidators(snapshotAtEpochNumber uint64) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now and can be optimized later.

return validatorEntry, nil
}

func (bav *UtxoView) GetSnapshotTopActiveValidatorsByStake(limit uint64, snapshotAtEpochNumber uint64) ([]*ValidatorEntry, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like keeping the snapshotting logic separate

@mattfoley8 mattfoley8 changed the base branch from feature/proof-of-stake to mf/consolidate-pos-block-heights June 6, 2023 14:02
Base automatically changed from mf/consolidate-pos-block-heights to mf/pos-merge-20230605 June 6, 2023 17:29
// Validate sufficient epochs have elapsed for validator to be unjailed.
// TODO: Retrieve snapshot ValidatorJailEpochDuration, not current value.
if validatorEntry.JailedAtEpochNumber+bav.GetValidatorJailEpochDuration(0) > currentEpochNumber {
if validatorEntry.JailedAtEpochNumber+validatorJailEpochDuration > currentEpochNumber {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels a little overkill, but should we have an overflow check? probably should have it for stakeLockupEpochDuration as well.

@mattfoley8 mattfoley8 merged commit 3f3e24a into mf/pos-merge-20230605 Jun 8, 2023
@mattfoley8 mattfoley8 deleted the mf/stub-out-epoch-complete-hook branch June 8, 2023 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants