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

Improve governance voting logic #3120

Merged
merged 9 commits into from
May 9, 2024

Conversation

Fraccaman
Copy link
Member

@Fraccaman Fraccaman commented Apr 24, 2024

Describe your changes

Closes #2523.

Summary of changes w.r.t the delegation validators and governance voting:

  • client:
    • if voter is validator, client will return error if validator is inactive or jailed in the current epoch
    • if delegator, client just ensures it has delegations. Does not filter based on the bond validator's state
  • wasm tx:
    • fetches the delegation validators in the current epoch, passes them into vote_proposal, which writes a vote key to storage for each. Does not filter based on the bond validator's state
  • gov VP: is_valid_vote_key does not filter based on the bond validator's state.

Almost no filtering is done in when a vote tx is submitted and vote keys are written into a storage for a proposal. This is because the state of a validator at the tally epoch, which is the voting end epoch, cannot necessarily be known at the epoch of vote submission. We should allow, for example, a delegator to submit a vote for a bond to an inactive validator, which may be active by the time the tally epoch comes around.

Ultimately in compute_proposal_votes, a vote will only be counted if the validator is active at the end epoch - in consensus, below-capacity, or below-threshold. We rely on this step to do the proper filtering.

Filtering is performed, however, by preventing a delegator with no delegations from submitting a valid vote tx and by preventing a validator that is currently jailed or inactive from submitting a valid vote tx.

Indicate on which release or other PRs this topic is based on

v0.34.0

Checklist before merging to draft

  • I have added a changelog
  • Git history is in acceptable state

@Fraccaman Fraccaman requested a review from grarco April 25, 2024 09:48
@Fraccaman Fraccaman marked this pull request as ready for review April 25, 2024 09:48
@grarco
Copy link
Collaborator

grarco commented Apr 29, 2024

There's a failing unit test and I left a minor comment. Overall it looks good to me but I'd like a second opinion from @brentstone especially for the query and sdk files

@grarco grarco requested a review from brentstone April 29, 2024 13:57
@brentstone brentstone force-pushed the fraccaman/improve-governance-voting-logic branch 3 times, most recently from be235ac to 9d0a862 Compare April 30, 2024 02:48
Copy link

codecov bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 59.83607% with 49 lines in your changes are missing coverage. Please review.

Project coverage is 59.46%. Comparing base (9d4de02) to head (48aba22).
Report is 2 commits behind head on main.

Files Patch % Lines
crates/sdk/src/tx.rs 0.00% 25 Missing ⚠️
crates/proof_of_stake/src/storage.rs 0.00% 11 Missing ⚠️
...rates/apps/src/lib/node/ledger/shell/governance.rs 0.00% 8 Missing ⚠️
crates/sdk/src/queries/vp/pos.rs 0.00% 3 Missing ⚠️
crates/light_sdk/src/transaction/governance.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3120      +/-   ##
==========================================
+ Coverage   59.40%   59.46%   +0.05%     
==========================================
  Files         298      298              
  Lines       92326    92332       +6     
==========================================
+ Hits        54849    54904      +55     
+ Misses      37477    37428      -49     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brentstone
Copy link
Collaborator

@Fraccaman @grarco I fixed up the logic in here and also summarized the changes in the PR description. Lmk your thoughts

@brentstone brentstone force-pushed the fraccaman/improve-governance-voting-logic branch from d27cd42 to 48aba22 Compare May 2, 2024 01:48
@brentstone brentstone requested a review from grarco May 2, 2024 01:48
brentstone added a commit that referenced this pull request May 2, 2024
* fraccaman/improve-governance-voting-logic:
  better documentation of proposal periods
  keep validator state longer in storage
  wasm tx: pass current delegations instead of those at proposal start
  clean up client code
  bug fix: ensure votes only to explicit active validators are counted
  revert find_delegation_validators -> no state
  should gov VP have any delegations logic? turn off
  wip
  added changelog
Comment on lines +306 to +363
// Not sure, since ultimately whether the vote counts or not is
// determined by the validator state at the end epoch, which likely has
// not occurred yet during VP execution

// // Check the target validator of the bond used to vote
// let delegations_targets = find_delegation_validators(
// &self.ctx.pre(),
// voter,
// &pre_voting_end_epoch,
// )
// .unwrap_or_default();

// if delegations_targets.is_empty() {
// return Err(native_vp::Error::new_alloc(format!(
// "No delegations found for {voter}"
// ))
// .into());
// }

// if !delegations_targets.contains(validator) {
// return Err(native_vp::Error::new_alloc(format!(
// "The vote key is not valid due to {voter} not having \
// delegations to {validator}"
// ))
// .into());
// }

// let validator_state = read_validator_state(&self.ctx.pre(),
// validator, &pre_voting_end_epoch)?; if !matches!
// (validator_state, ValidatorState::Consensus |
// ValidatorState::BelowCapacity | ValidatorState::BelowThreshold) {
// if validator_state.is_none() {
// return Err(native_vp::Error::new_alloc(format!(
// "The vote key is invalid because the validator
// {validator} is not in \ the active set (jailed
// or inactive)" ))
// .into());
// } else {
// return Err(native_vp::Error::new_alloc(format!(
// "The vote key is invalid because the validator
// {validator} is not in \ the active set (jailed
// or inactive)" ))
// .into());
// }

// }

// // this is safe as we check above that validator is part of the
// hashmap if !matches!(
// delegations_targets.get(validator).unwrap(),
// ValidatorState::Consensus
// ) {
// return Err(native_vp::Error::new_alloc(format!(
// "The vote key is not valid due to {validator} being not in \
// the active set"
// ))
// .into());
// }
Copy link
Member Author

Choose a reason for hiding this comment

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

remove this comment

brentstone added a commit that referenced this pull request May 8, 2024
* origin/fraccaman/improve-governance-voting-logic:
  better documentation of proposal periods
  keep validator state longer in storage
  wasm tx: pass current delegations instead of those at proposal start
  clean up client code
  bug fix: ensure votes only to explicit active validators are counted
  revert find_delegation_validators -> no state
  should gov VP have any delegations logic? turn off
  wip
  added changelog
@brentstone brentstone merged commit f9db22f into main May 9, 2024
16 of 19 checks passed
@brentstone brentstone deleted the fraccaman/improve-governance-voting-logic branch May 9, 2024 03:53
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.

VoteTx should fetch all the voter delegations on wasm
3 participants