-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Refactor Vote Program Account setup #2992
Refactor Vote Program Account setup #2992
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2992 +/- ##
========================================
- Coverage 76.9% 76.8% -0.1%
========================================
Files 130 130
Lines 19888 19976 +88
========================================
+ Hits 15294 15350 +56
- Misses 4594 4626 +32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This program is so important and pretty trick to debug. It needs loads of tests! See neighboring file programs/native/rewards/tests/rewards.rs
for how to do that easily.
/// identified by keys[0] for voting | ||
RegisterAccount, | ||
/// Initialize the VoteState for this "vote account" | ||
/// * Transaction::keys[0] - the staker id that is also assumed to be the delegate by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment needs some work. While the transaction containing this instruction may have two accounts, this instruction should only point to the second one (the vote account). The transaction would be a SystemInstruction::CreateAccount
and VoteInstruction::InitializeAccount
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@garious, I will need both accounts being passed in to the VoteProgram. To assign the staker as the delegate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fairly certain you don't. Should be the same pattern as here: https://github.com/solana-labs/solana/blob/master/programs/native/rewards_api/src/rewards_transaction.rs#L49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@garious, maybe I'm missing something. I need to assign the "staker" as the delegate by default. I cannot do that if I don't have the staker's pubkey (provided by accounts[0] right now). I suppose I could take it as an argument to Initialize?
sdk/src/vote_transaction.rs
Outdated
@@ -50,11 +55,29 @@ impl VoteTransaction { | |||
vec![system_program::id(), vote_program::id()], | |||
vec![ | |||
Instruction::new(0, &create_tx, vec![0, 1]), | |||
Instruction::new(1, &VoteInstruction::RegisterAccount, vec![0, 1]), | |||
Instruction::new(1, &VoteInstruction::InitAccount, vec![0, 1]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per previous comments, this can be vec![1]
.
1fc132c
to
ea0767c
Compare
@garious, I was able to address most of your comments. |
Can you rebase and merge? |
7efcda5
to
e035123
Compare
Summary of Changes
new_account()
intofund_vote_account()
,initialize_account()
, anddelegate_account()
.staker account
from therewards account
Fixes #2513
Hopeful alternative to #2973