Skip to content

Commit

Permalink
Award one credit per dequeued vote when processing VoteStateUpdate in… (
Browse files Browse the repository at this point in the history
#25743)

* Award one credit per dequeued vote when processing VoteStateUpdate instruction,
to match vote rewards of Vote instruction.

* Update feature pubkey to one owned by cc (ashwin)

Co-authored-by: Ashwin Sekar <[email protected]>
  • Loading branch information
bji and AshwinSekar authored Jun 6, 2022
1 parent 7c93504 commit cbb0f07
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 38 deletions.
2 changes: 1 addition & 1 deletion program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ impl ProgramTestContext {

let epoch = bank.epoch();
for _ in 0..number_of_credits {
vote_state.increment_credits(epoch);
vote_state.increment_credits(epoch, 1);
}
let versioned = VoteStateVersions::new_current(vote_state);
VoteState::to(&versioned, &mut vote_account).unwrap();
Expand Down
15 changes: 9 additions & 6 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6554,7 +6554,7 @@ mod tests {
// Instruction will fail
let mut reference_vote_state = VoteState::default();
for epoch in 0..MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION / 2 {
reference_vote_state.increment_credits(epoch as Epoch);
reference_vote_state.increment_credits(epoch as Epoch, 1);
}
reference_vote_account
.borrow_mut()
Expand All @@ -6574,7 +6574,7 @@ mod tests {
// Instruction will fail
let mut reference_vote_state = VoteState::default();
for epoch in 0..=current_epoch {
reference_vote_state.increment_credits(epoch);
reference_vote_state.increment_credits(epoch, 1);
}
assert_eq!(
reference_vote_state.epoch_credits[current_epoch as usize - 2].0,
Expand Down Expand Up @@ -6604,7 +6604,7 @@ mod tests {
// Instruction will succeed
let mut reference_vote_state = VoteState::default();
for epoch in 0..=current_epoch {
reference_vote_state.increment_credits(epoch);
reference_vote_state.increment_credits(epoch, 1);
}
reference_vote_account
.borrow_mut()
Expand Down Expand Up @@ -6633,7 +6633,7 @@ mod tests {

let mut vote_state = VoteState::default();
for epoch in 0..MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION / 2 {
vote_state.increment_credits(epoch as Epoch);
vote_state.increment_credits(epoch as Epoch, 1);
}
vote_account
.serialize_data(&VoteStateVersions::new_current(vote_state))
Expand Down Expand Up @@ -6687,8 +6687,10 @@ mod tests {
// `MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION` ago.
// Instruction will succeed
let mut vote_state = VoteState::default();
vote_state
.increment_credits(current_epoch - MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION as Epoch);
vote_state.increment_credits(
current_epoch - MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION as Epoch,
1,
);
vote_account
.serialize_data(&VoteStateVersions::new_current(vote_state))
.unwrap();
Expand All @@ -6706,6 +6708,7 @@ mod tests {
let mut vote_state = VoteState::default();
vote_state.increment_credits(
current_epoch - (MINIMUM_DELINQUENT_EPOCHS_FOR_DEACTIVATION - 1) as Epoch,
1,
);
vote_account
.serialize_data(&VoteStateVersions::new_current(vote_state))
Expand Down
14 changes: 7 additions & 7 deletions programs/stake/src/stake_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2373,8 +2373,8 @@ mod tests {
);

// put 2 credits in at epoch 0
vote_state.increment_credits(0);
vote_state.increment_credits(0);
vote_state.increment_credits(0, 1);
vote_state.increment_credits(0, 1);

// this one should be able to collect exactly 2
assert_eq!(
Expand Down Expand Up @@ -2435,7 +2435,7 @@ mod tests {
// put 193,536,000 credits in at epoch 0, typical for a 14-day epoch
// this loop takes a few seconds...
for _ in 0..epoch_slots {
vote_state.increment_credits(0);
vote_state.increment_credits(0, 1);
}

// no overflow on points
Expand Down Expand Up @@ -2476,8 +2476,8 @@ mod tests {
);

// put 2 credits in at epoch 0
vote_state.increment_credits(0);
vote_state.increment_credits(0);
vote_state.increment_credits(0, 1);
vote_state.increment_credits(0, 1);

// this one should be able to collect exactly 2
assert_eq!(
Expand Down Expand Up @@ -2523,7 +2523,7 @@ mod tests {
);

// put 1 credit in epoch 1
vote_state.increment_credits(1);
vote_state.increment_credits(1, 1);

stake.credits_observed = 2;
// this one should be able to collect the one just added
Expand All @@ -2548,7 +2548,7 @@ mod tests {
);

// put 1 credit in epoch 2
vote_state.increment_credits(2);
vote_state.increment_credits(2, 1);
// this one should be able to collect 2 now
assert_eq!(
Some(CalculatedStakeRewards {
Expand Down
1 change: 1 addition & 0 deletions programs/vote/src/vote_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn process_instruction(
&clock,
vote_state_update,
&signers,
&invoke_context.feature_set,
)
} else {
Err(InstructionError::InvalidInstructionData)
Expand Down
Loading

0 comments on commit cbb0f07

Please sign in to comment.