Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add below-threshold validator set #1576

Closed
wants to merge 15 commits into from

Conversation

brentstone
Copy link
Collaborator

@brentstone brentstone commented Jun 15, 2023

Based on v0.17.4.

Closes #1128.

This PR implements a third validator set in addition to the consensus and below-capacity sets: the below-threshold set. All validators with stake below the validator_stake_threshold parameter are placed into this set, which is unordered, unlike the other two validator sets. Smaller amounts of data are needed to be kept in storage for validators in this set.

@brentstone brentstone force-pushed the brent/add-below-threshold-validators branch 5 times, most recently from 396d5ce to 06b5ee5 Compare June 17, 2023 01:10
@brentstone
Copy link
Collaborator Author

Several unit tests break because arb_genesis_validators generates genesis validators whose staked tokens are all below the validator_stake_threshold. Some hackier ways of solving this is to make the validator_stake_threshold 0 or 1 namnam or to just lower the threshold to some value where it is less likely to arbitrarily generate a set of validators all of whose stake is below this number.

The more rigorous solution is to modify arb_genesis_validators to take a PosParams as input. Then if the generated validators all have stake less than validator_stake_threshold, we can generate one additional genesis validator with random stake that is assured to be at least as large as this.

@tzemanovic

@brentstone brentstone marked this pull request as ready for review June 17, 2023 02:18
@karbyshev karbyshev self-requested a review June 19, 2023 15:25
);
return None;
}
// TODO: maybe debug_assert that the new stake is >= threshold?
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 we need to be careful with removing this check. We can do it, but we should probably enforce that the validator_stake_threshold and tm_votes_per_token * u64::from(validator_stake_threshold) are non-zero

Copy link
Member

Choose a reason for hiding this comment

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

same with if prev_tm_voting_power == 0 ... for below capacity

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

enforce with debug_asserts or by returning None values?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maybe smth like

if params.validator_stake_threshold == token::Amount::default() && *prev_tm_voting_power == 0 && *new_tm_voting_power == 0
                {
                    tracing::info!(
                        "skipping validator update, {address} is in consensus \
                         set but without voting power"
                    );
                    return None;
                }

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ALSO, do we still need this Lazy type wrapped around prev_tm_voting_power and new_tm_voting_power?

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 we could enforce in the paramaters PosParams::validate that validator_stake_threshold and tm_votes_per_token * u64::from(validator_stake_threshold) are non-zero - only thing is that we're currently not using this function but we should probably fix that anyway. We could use it for genesis parameters validation and for on-chain parameters change, which is only allowed via governance.

If we enforce these invariants on the params then we can remove the check in here as we couldn't have a validator with 0 TM voting to enter the consensus set. That being said, what you've done LGTM and I don't think we need to change this immediately.

I think we should keep Lazy as the first condition if matches!(prev_state, Some(ValidatorState::Consensus)) might short-circuit in which case we don't need to compute these.

@brentstone brentstone force-pushed the brent/add-below-threshold-validators branch 2 times, most recently from 77f8a5f to 865d7ce Compare June 21, 2023 04:51
brentstone added a commit that referenced this pull request Jun 21, 2023
@brentstone brentstone force-pushed the brent/add-below-threshold-validators branch from 865d7ce to 0df7872 Compare June 21, 2023 05:47
@brentstone
Copy link
Collaborator Author

pls update wasm

tzemanovic
tzemanovic previously approved these changes Jun 21, 2023
@tzemanovic
Copy link
Member

I'll squash the fixup commits and add this to draft

@tzemanovic tzemanovic force-pushed the brent/add-below-threshold-validators branch from 3100bfc to 6926d60 Compare June 21, 2023 08:43
tzemanovic added a commit that referenced this pull request Jun 21, 2023
* brent/add-below-threshold-validators:
  [ci] wasm checksums update
  changelog: add #1576
  fix pos unit tests
  pos/tests: improve `arb_genesis_validators` to consider a stake threshold
  pos/lib: refactor `validator_set_update_tendermint`
  removing below-threshold validators from storage
  WIP fixing other pos unit tests
  fix wasm tx tests
  pos/tests: fix broken unit tests
  pos/lib: update `validator_set_update_tendermint`
  pos/state_machine: update test with new validator set
  pos/lib: fix `init_genesis`
  remove outdated comments
  pos/lib: update logic in `update_validator_set`
  beginning changes
@tzemanovic tzemanovic mentioned this pull request Jun 21, 2023
@brentstone brentstone force-pushed the brent/add-below-threshold-validators branch from 9c488fb to 6926d60 Compare June 29, 2023 10:11
brentstone added a commit that referenced this pull request Jul 3, 2023
brentstone added a commit that referenced this pull request Jul 3, 2023
* origin/brent/add-below-threshold-validators:
  [ci] wasm checksums update
  changelog: add #1576
  fix pos unit tests
  pos/tests: improve `arb_genesis_validators` to consider a stake threshold
  pos/lib: refactor `validator_set_update_tendermint`
  removing below-threshold validators from storage
  WIP fixing other pos unit tests
  fix wasm tx tests
  pos/tests: fix broken unit tests
  pos/lib: update `validator_set_update_tendermint`
  pos/state_machine: update test with new validator set
  pos/lib: fix `init_genesis`
  remove outdated comments
  pos/lib: update logic in `update_validator_set`
  beginning changes
@brentstone
Copy link
Collaborator Author

Merged in v0.18.0.

@brentstone brentstone closed this Jul 4, 2023
@brentstone brentstone deleted the brent/add-below-threshold-validators branch December 28, 2023 00:52
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.

PoS: add below_threshold validator sub-set
2 participants