Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Reject close of active vote accounts#22651

Merged
willhickey merged 18 commits intosolana-labs:masterfrom
willhickey:whickey/10461_withdraw_vote_account
Feb 2, 2022
Merged

Reject close of active vote accounts#22651
willhickey merged 18 commits intosolana-labs:masterfrom
willhickey:whickey/10461_withdraw_vote_account

Conversation

@willhickey
Copy link
Copy Markdown
Contributor

@willhickey willhickey commented Jan 21, 2022

Issue 10461

Problem

Withdrawing the rent exempt reserve from a vote account will close the account. This shouldn't be allowed for active vote accounts.

Summary of Changes

Attempted withdraws of the rent exempt reserve check whether the vote account received any credits in the most recent completed epoch. If they did, the withdraw is rejected with an error.

Note: This change is feature gated, and PR 21639 also created a feature in the same function, so the unit test matrix has ballooned and includes a lot of duplicated code. The duplication could be factored out but I choose to leave most of it unrolled to simplify cleanup once both features are activated.

Feature Gate Issue: #24488

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 24, 2022

Codecov Report

Merging #22651 (88b95e3) into master (aea8f0d) will decrease coverage by 0.0%.
The diff coverage is 97.4%.

@@            Coverage Diff            @@
##           master   #22651     +/-   ##
=========================================
- Coverage    81.5%    81.5%   -0.1%     
=========================================
  Files         558      558             
  Lines      149898   150122    +224     
=========================================
+ Hits       122266   122447    +181     
- Misses      27632    27675     +43     

Copy link
Copy Markdown
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

Looking good, just one substantive question from me.

Test duplication lgtm. Will be tons easier to clean when either/both features are removed.

Comment thread programs/vote/src/vote_state/mod.rs Outdated
Comment thread programs/vote/src/vote_state/mod.rs Outdated
Comment thread programs/vote/src/vote_state/mod.rs Outdated
Comment thread programs/vote/src/vote_state/mod.rs Outdated
@willhickey
Copy link
Copy Markdown
Contributor Author

willhickey commented Jan 25, 2022

@CriesofCarrots Thanks for the feedback!

I'm making changes now. Does the checked math rule apply to tests and test helper functions too?

@CriesofCarrots
Copy link
Copy Markdown
Contributor

Does the checked math rule apply to tests and test helper functions too?

Nope, just the program code itself. Feel free to do whatever's easiest or easiest to read for tests

Comment thread programs/vote/src/vote_state/mod.rs Outdated
Comment thread programs/vote/src/vote_state/mod.rs Outdated
Comment thread programs/vote/src/vote_processor.rs Outdated
Comment thread programs/vote/src/vote_processor.rs Outdated
Comment thread programs/vote/src/vote_state/mod.rs Outdated
Comment thread programs/vote/src/vote_state/mod.rs Outdated
Comment thread programs/vote/src/vote_state/mod.rs Outdated
CriesofCarrots
CriesofCarrots previously approved these changes Jan 28, 2022
Copy link
Copy Markdown
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

lgtm! Thanks for all the iterations and polish.
@t-nelson , can you give this a quick sanity check? 🙏

@mergify mergify Bot dismissed CriesofCarrots’s stale review January 28, 2022 16:06

Pull request has been modified.

Copy link
Copy Markdown
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

oh, nit: we should probably update the error msgs. One possibility suggested below; wordsmithing welcome.

Comment thread sdk/program/src/instruction.rs Outdated
Comment thread sdk/program/src/program_error.rs Outdated
willhickey and others added 2 commits January 28, 2022 13:43
Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
t-nelson
t-nelson previously approved these changes Feb 1, 2022
Copy link
Copy Markdown
Contributor

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

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

looks great! I love the test coverage. All I have is one logical simplification suggestion and a comment from Tyera's review.

If vote_state.epoch_credits.is_empty(), it should mean the vote account hasn't received any credits ever.
Yes, the VoteState is what is stored in a Vote account on chain, so part of the accounts state on all validators.
There's probably a small race condition here if (a) a validator has submitted it's first votes which haven't landed yet and (b) empties its vote account, but that shouldn't matter for the protection we're trying to add.

Since stake can't be delegated to a validator that hasn't voted, I don't think the race even exists in any meaningful way

Comment thread programs/vote/src/vote_state/mod.rs Outdated
Co-authored-by: Trent Nelson <trent.a.b.nelson@gmail.com>
@mergify mergify Bot dismissed t-nelson’s stale review February 2, 2022 17:09

Pull request has been modified.

@willhickey
Copy link
Copy Markdown
Contributor Author

@t-nelson I hadn't encountered zip before... thanks for the handy new tool!

Should I backport this to 1.9 or just merge it to master?

@CriesofCarrots
Copy link
Copy Markdown
Contributor

Should I backport this to 1.9 or just merge it to master?

I say v1.9 for sure. @t-nelson, do you foresee any more v1.8 releases? If so, I'd like to have this there too.

@t-nelson
Copy link
Copy Markdown
Contributor

t-nelson commented Feb 2, 2022

Yeah we're definitely going to see more 1.8.x. Let's take it all the way back

Copy link
Copy Markdown
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

:shipit:

@willhickey willhickey merged commit 75563f6 into solana-labs:master Feb 2, 2022
mergify Bot pushed a commit that referenced this pull request Feb 2, 2022
* 10461 Reject close of vote accounts unless it earned no credits in the previous epoch. This is checked by comparing current epoch (from clock sysvar) with the most recent epoch with credits in vote state.

(cherry picked from commit 75563f6)

# Conflicts:
#	programs/vote/src/vote_processor.rs
#	programs/vote/src/vote_state/mod.rs
#	runtime/src/bank.rs
#	sdk/program/src/instruction.rs
#	sdk/program/src/program_error.rs
#	storage-proto/proto/transaction_by_addr.proto
#	storage-proto/src/convert.rs
mergify Bot pushed a commit that referenced this pull request Feb 2, 2022
* 10461 Reject close of vote accounts unless it earned no credits in the previous epoch. This is checked by comparing current epoch (from clock sysvar) with the most recent epoch with credits in vote state.

(cherry picked from commit 75563f6)

# Conflicts:
#	programs/vote/src/vote_processor.rs
#	sdk/src/feature_set.rs
mergify Bot added a commit that referenced this pull request Feb 3, 2022
* Reject close of active vote accounts (#22651)

* 10461 Reject close of vote accounts unless it earned no credits in the previous epoch. This is checked by comparing current epoch (from clock sysvar) with the most recent epoch with credits in vote state.

(cherry picked from commit 75563f6)

# Conflicts:
#	programs/vote/src/vote_processor.rs
#	sdk/src/feature_set.rs

* Resolve merge conflicts

Co-authored-by: Will Hickey <csu_hickey@yahoo.com>
Co-authored-by: Will Hickey <will.hickey@solana.com>
mergify Bot added a commit that referenced this pull request Feb 7, 2022
* Reject close of active vote accounts (#22651)

* 10461 Reject close of vote accounts unless it earned no credits in the previous epoch. This is checked by comparing current epoch (from clock sysvar) with the most recent epoch with credits in vote state.

(cherry picked from commit 75563f6)

# Conflicts:
#	programs/vote/src/vote_processor.rs
#	programs/vote/src/vote_state/mod.rs
#	runtime/src/bank.rs
#	sdk/program/src/instruction.rs
#	sdk/program/src/program_error.rs
#	storage-proto/proto/transaction_by_addr.proto
#	storage-proto/src/convert.rs

* Resolve merge conflicts

* lint

* Clippy cleanup

* Add import to test module

* remove vote processor

* Update test_abi_digest hash

* cleanup

Co-authored-by: Will Hickey <csu_hickey@yahoo.com>
Co-authored-by: Will Hickey <will.hickey@solana.com>
@willhickey willhickey linked an issue Feb 14, 2022 that may be closed by this pull request
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Feb 24, 2022
* 10461 Reject close of vote accounts unless it earned no credits in the previous epoch. This is checked by comparing current epoch (from clock sysvar) with the most recent epoch with credits in vote state.
@jstarry jstarry added the feature-gate Pull Request adds or modifies a runtime feature gate label Jun 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature-gate Pull Request adds or modifies a runtime feature gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Withdrawing from vote account can delete it while still validating

4 participants