* Addressing leftover comments from #21531 * Add feature flag * Feature gate new vote instruction * add clock & slot hashes sysvar to test
This commit is contained in:
@ -161,18 +161,14 @@ pub enum VoteInstruction {
|
|||||||
///
|
///
|
||||||
/// # Account references
|
/// # Account references
|
||||||
/// 0. `[Write]` Vote account to vote with
|
/// 0. `[Write]` Vote account to vote with
|
||||||
/// 1. `[]` Slot hashes sysvar
|
/// 1. `[SIGNER]` Vote authority
|
||||||
/// 2. `[]` Clock sysvar
|
|
||||||
/// 3. `[SIGNER]` Vote authority
|
|
||||||
UpdateVoteState(VoteStateUpdate),
|
UpdateVoteState(VoteStateUpdate),
|
||||||
|
|
||||||
/// Update the onchain vote state for the signer along with a switching proof.
|
/// Update the onchain vote state for the signer along with a switching proof.
|
||||||
///
|
///
|
||||||
/// # Account references
|
/// # Account references
|
||||||
/// 0. `[Write]` Vote account to vote with
|
/// 0. `[Write]` Vote account to vote with
|
||||||
/// 1. `[]` Slot hashes sysvar
|
/// 1. `[SIGNER]` Vote authority
|
||||||
/// 2. `[]` Clock sysvar
|
|
||||||
/// 3. `[SIGNER]` Vote authority
|
|
||||||
UpdateVoteStateSwitch(VoteStateUpdate, Hash),
|
UpdateVoteStateSwitch(VoteStateUpdate, Hash),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,8 +334,6 @@ pub fn update_vote_state(
|
|||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*vote_pubkey, false),
|
AccountMeta::new(*vote_pubkey, false),
|
||||||
AccountMeta::new_readonly(sysvar::slot_hashes::id(), false),
|
|
||||||
AccountMeta::new_readonly(sysvar::clock::id(), false),
|
|
||||||
AccountMeta::new_readonly(*authorized_voter_pubkey, true),
|
AccountMeta::new_readonly(*authorized_voter_pubkey, true),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -358,8 +352,6 @@ pub fn update_vote_state_switch(
|
|||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*vote_pubkey, false),
|
AccountMeta::new(*vote_pubkey, false),
|
||||||
AccountMeta::new_readonly(sysvar::slot_hashes::id(), false),
|
|
||||||
AccountMeta::new_readonly(sysvar::clock::id(), false),
|
|
||||||
AccountMeta::new_readonly(*authorized_voter_pubkey, true),
|
AccountMeta::new_readonly(*authorized_voter_pubkey, true),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -465,20 +457,23 @@ pub fn process_instruction(
|
|||||||
}
|
}
|
||||||
VoteInstruction::UpdateVoteState(vote_state_update)
|
VoteInstruction::UpdateVoteState(vote_state_update)
|
||||||
| VoteInstruction::UpdateVoteStateSwitch(vote_state_update, _) => {
|
| VoteInstruction::UpdateVoteStateSwitch(vote_state_update, _) => {
|
||||||
inc_new_counter_info!("vote-state-native", 1);
|
if invoke_context
|
||||||
vote_state::process_vote_state_update(
|
.feature_set
|
||||||
me,
|
.is_active(&feature_set::allow_votes_to_directly_update_vote_state::id())
|
||||||
&from_keyed_account::<SlotHashes>(keyed_account_at_index(
|
{
|
||||||
keyed_accounts,
|
inc_new_counter_info!("vote-state-native", 1);
|
||||||
first_instruction_account + 1,
|
let slot_hashes: SlotHashes =
|
||||||
)?)?,
|
invoke_context.get_sysvar(&sysvar::slot_hashes::id())?;
|
||||||
&from_keyed_account::<Clock>(keyed_account_at_index(
|
vote_state::process_vote_state_update(
|
||||||
keyed_accounts,
|
me,
|
||||||
first_instruction_account + 2,
|
slot_hashes.slot_hashes(),
|
||||||
)?)?,
|
&invoke_context.get_sysvar(&sysvar::clock::id())?,
|
||||||
&vote_state_update,
|
vote_state_update,
|
||||||
&signers,
|
&signers,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
Err(InstructionError::InvalidInstructionData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
VoteInstruction::Withdraw(lamports) => {
|
VoteInstruction::Withdraw(lamports) => {
|
||||||
let to = keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?;
|
let to = keyed_account_at_index(keyed_accounts, first_instruction_account + 1)?;
|
||||||
@ -585,12 +580,19 @@ mod tests {
|
|||||||
|
|
||||||
let rent = Rent::default();
|
let rent = Rent::default();
|
||||||
let rent_sysvar = (sysvar::rent::id(), bincode::serialize(&rent).unwrap());
|
let rent_sysvar = (sysvar::rent::id(), bincode::serialize(&rent).unwrap());
|
||||||
|
let clock = Clock::default();
|
||||||
|
let clock_sysvar = (sysvar::clock::id(), bincode::serialize(&clock).unwrap());
|
||||||
|
let slot_hashes = SlotHashes::default();
|
||||||
|
let slot_hashes_sysvar = (
|
||||||
|
sysvar::slot_hashes::id(),
|
||||||
|
bincode::serialize(&slot_hashes).unwrap(),
|
||||||
|
);
|
||||||
solana_program_runtime::invoke_context::mock_process_instruction_with_sysvars(
|
solana_program_runtime::invoke_context::mock_process_instruction_with_sysvars(
|
||||||
&id(),
|
&id(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
&instruction.data,
|
&instruction.data,
|
||||||
&keyed_accounts,
|
&keyed_accounts,
|
||||||
&[rent_sysvar],
|
&[rent_sysvar, clock_sysvar, slot_hashes_sysvar],
|
||||||
super::process_instruction,
|
super::process_instruction,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ pub const INITIAL_LOCKOUT: usize = 2;
|
|||||||
// Maximum number of credits history to keep around
|
// Maximum number of credits history to keep around
|
||||||
pub const MAX_EPOCH_CREDITS_HISTORY: usize = 64;
|
pub const MAX_EPOCH_CREDITS_HISTORY: usize = 64;
|
||||||
|
|
||||||
// Offset of VoteState::pri : Clone + Debug {or_voters, for determining initialization status without deserialization
|
// Offset of VoteState::prior_voters, for determining initialization status without deserialization
|
||||||
const DEFAULT_PRIOR_VOTERS_OFFSET: usize = 82;
|
const DEFAULT_PRIOR_VOTERS_OFFSET: usize = 82;
|
||||||
|
|
||||||
// VoteTransactionClone hack is done so that we can derive clone on the tower that uses the
|
// VoteTransactionClone hack is done so that we can derive clone on the tower that uses the
|
||||||
@ -1156,14 +1156,14 @@ pub fn process_vote_state_update<S: std::hash::BuildHasher>(
|
|||||||
vote_account: &KeyedAccount,
|
vote_account: &KeyedAccount,
|
||||||
slot_hashes: &[SlotHash],
|
slot_hashes: &[SlotHash],
|
||||||
clock: &Clock,
|
clock: &Clock,
|
||||||
vote_state_update: &VoteStateUpdate,
|
vote_state_update: VoteStateUpdate,
|
||||||
signers: &HashSet<Pubkey, S>,
|
signers: &HashSet<Pubkey, S>,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let mut vote_state = verify_and_get_vote_state(vote_account, clock, signers)?;
|
let mut vote_state = verify_and_get_vote_state(vote_account, clock, signers)?;
|
||||||
|
|
||||||
vote_state.check_slots_are_valid(vote_state_update, slot_hashes)?;
|
vote_state.check_slots_are_valid(&vote_state_update, slot_hashes)?;
|
||||||
vote_state.process_new_vote_state(
|
vote_state.process_new_vote_state(
|
||||||
vote_state_update.lockouts.clone(),
|
vote_state_update.lockouts,
|
||||||
vote_state_update.root,
|
vote_state_update.root,
|
||||||
vote_state_update.timestamp,
|
vote_state_update.timestamp,
|
||||||
clock.epoch,
|
clock.epoch,
|
||||||
|
@ -275,6 +275,10 @@ pub mod evict_invalid_stakes_cache_entries {
|
|||||||
solana_sdk::declare_id!("EMX9Q7TVFAmQ9V1CggAkhMzhXSg8ECp7fHrWQX2G1chf");
|
solana_sdk::declare_id!("EMX9Q7TVFAmQ9V1CggAkhMzhXSg8ECp7fHrWQX2G1chf");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod allow_votes_to_directly_update_vote_state {
|
||||||
|
solana_sdk::declare_id!("Ff8b1fBeB86q8cjq47ZhsQLgv5EkHu3G1C99zjUfAzrq");
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// Map of feature identifiers to user-visible description
|
/// Map of feature identifiers to user-visible description
|
||||||
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
||||||
@ -338,6 +342,7 @@ lazy_static! {
|
|||||||
(fixed_memcpy_nonoverlapping_check::id(), "use correct check for nonoverlapping regions in memcpy syscall"),
|
(fixed_memcpy_nonoverlapping_check::id(), "use correct check for nonoverlapping regions in memcpy syscall"),
|
||||||
(reject_non_rent_exempt_vote_withdraws::id(), "fail vote withdraw instructions which leave the account non-rent-exempt"),
|
(reject_non_rent_exempt_vote_withdraws::id(), "fail vote withdraw instructions which leave the account non-rent-exempt"),
|
||||||
(evict_invalid_stakes_cache_entries::id(), "evict invalid stakes cache entries on epoch boundaries"),
|
(evict_invalid_stakes_cache_entries::id(), "evict invalid stakes cache entries on epoch boundaries"),
|
||||||
|
(allow_votes_to_directly_update_vote_state::id(), "enable direct vote state update"),
|
||||||
/*************** ADD NEW FEATURES HERE ***************/
|
/*************** ADD NEW FEATURES HERE ***************/
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
|
Reference in New Issue
Block a user