Skip to content

Commit

Permalink
clean up uses of activated vote_state_add_vote_latency feature (sol…
Browse files Browse the repository at this point in the history
…ana-labs#2469)

clean up uses of activated vote_state_add_vote_latency feature
  • Loading branch information
jstarry authored Aug 7, 2024
1 parent 83bb29e commit 9db1d9c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 142 deletions.
10 changes: 2 additions & 8 deletions cli/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use {
solana_rpc_client_api::config::RpcGetVoteAccountsConfig,
solana_rpc_client_nonce_utils::blockhash_query::BlockhashQuery,
solana_sdk::{
account::Account, commitment_config::CommitmentConfig, feature, message::Message,
account::Account, commitment_config::CommitmentConfig, message::Message,
native_token::lamports_to_sol, pubkey::Pubkey, system_instruction::SystemError,
transaction::Transaction,
},
Expand Down Expand Up @@ -819,13 +819,7 @@ pub fn process_create_vote_account(

let fee_payer = config.signers[fee_payer];
let nonce_authority = config.signers[nonce_authority];

let is_feature_active = (!sign_only)
.then(solana_sdk::feature_set::vote_state_add_vote_latency::id)
.and_then(|feature_address| rpc_client.get_account(&feature_address).ok())
.and_then(|account| feature::from_account(&account))
.map_or(false, |feature| feature.activated_at.is_some());
let space = VoteStateVersions::vote_state_size_of(is_feature_active) as u64;
let space = VoteStateVersions::vote_state_size_of(true) as u64;

let build_message = |lamports| {
let vote_init = VoteInit {
Expand Down
16 changes: 1 addition & 15 deletions local-cluster/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use {
clock::{Slot, DEFAULT_DEV_SLOTS_PER_EPOCH, DEFAULT_TICKS_PER_SLOT, MAX_PROCESSING_AGE},
commitment_config::CommitmentConfig,
epoch_schedule::EpochSchedule,
feature_set,
genesis_config::{ClusterType, GenesisConfig},
message::Message,
poh_config::PohConfig,
Expand Down Expand Up @@ -778,18 +777,6 @@ impl LocalCluster {
== 0
{
// 1) Create vote account
// Unlike the bootstrap validator we have to check if the new vote state is being used
// as the cluster is already running, and using the wrong account size will cause the
// InitializeAccount tx to fail
let use_current_vote_state = client
.rpc_client()
.poll_get_balance_with_commitment(
&feature_set::vote_state_add_vote_latency::id(),
CommitmentConfig::processed(),
)
.unwrap_or(0)
> 0;

let instructions = vote_instruction::create_account_with_config(
&from_account.pubkey(),
&vote_account_pubkey,
Expand All @@ -801,8 +788,7 @@ impl LocalCluster {
},
amount,
vote_instruction::CreateVoteAccountConfig {
space: vote_state::VoteStateVersions::vote_state_size_of(use_current_vote_state)
as u64,
space: vote_state::VoteStateVersions::vote_state_size_of(true) as u64,
..vote_instruction::CreateVoteAccountConfig::default()
},
);
Expand Down
76 changes: 5 additions & 71 deletions programs/vote/src/vote_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ fn process_authorize_with_seed_instruction(
authorization_type,
&expected_authority_keys,
&clock,
invoke_context.get_feature_set(),
)
}

Expand Down Expand Up @@ -75,25 +74,12 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context|
}
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 2)?;
vote_state::initialize_account(
&mut me,
&vote_init,
&signers,
&clock,
invoke_context.get_feature_set(),
)
vote_state::initialize_account(&mut me, &vote_init, &signers, &clock)
}
VoteInstruction::Authorize(voter_pubkey, vote_authorize) => {
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 1)?;
vote_state::authorize(
&mut me,
&voter_pubkey,
vote_authorize,
&signers,
&clock,
invoke_context.get_feature_set(),
)
vote_state::authorize(&mut me, &voter_pubkey, vote_authorize, &signers, &clock)
}
VoteInstruction::AuthorizeWithSeed(args) => {
instruction_context.check_number_of_instruction_accounts(3)?;
Expand Down Expand Up @@ -132,12 +118,7 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context|
let node_pubkey = transaction_context.get_key_of_account_at_index(
instruction_context.get_index_of_instruction_account_in_transaction(1)?,
)?;
vote_state::update_validator_identity(
&mut me,
node_pubkey,
&signers,
invoke_context.get_feature_set(),
)
vote_state::update_validator_identity(&mut me, node_pubkey, &signers)
}
VoteInstruction::UpdateCommission(commission) => {
let sysvar_cache = invoke_context.get_sysvar_cache();
Expand Down Expand Up @@ -228,7 +209,6 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context|
&signers,
&rent_sysvar,
&clock_sysvar,
invoke_context.get_feature_set(),
)
}
VoteInstruction::AuthorizeChecked(vote_authorize) => {
Expand All @@ -241,14 +221,7 @@ declare_process_instruction!(Entrypoint, DEFAULT_COMPUTE_UNITS, |invoke_context|
}
let clock =
get_sysvar_with_account_check::clock(invoke_context, instruction_context, 1)?;
vote_state::authorize(
&mut me,
voter_pubkey,
vote_authorize,
&signers,
&clock,
invoke_context.get_feature_set(),
)
vote_state::authorize(&mut me, voter_pubkey, vote_authorize, &signers, &clock)
}
}
});
Expand All @@ -275,7 +248,6 @@ mod tests {
solana_sdk::{
account::{self, Account, AccountSharedData, ReadableAccount},
account_utils::StateMut,
feature_set::FeatureSet,
hash::Hash,
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
Expand Down Expand Up @@ -322,27 +294,6 @@ mod tests {
)
}

fn process_instruction_disabled_features(
instruction_data: &[u8],
transaction_accounts: Vec<(Pubkey, AccountSharedData)>,
instruction_accounts: Vec<AccountMeta>,
expected_result: Result<(), InstructionError>,
) -> Vec<AccountSharedData> {
mock_process_instruction(
&id(),
Vec::new(),
instruction_data,
transaction_accounts,
instruction_accounts,
expected_result,
Entrypoint::vm,
|invoke_context| {
invoke_context.mock_set_feature_set(std::sync::Arc::new(FeatureSet::default()));
},
|_invoke_context| {},
)
}

fn process_instruction_as_one_arg(
instruction: &Instruction,
expected_result: Result<(), InstructionError>,
Expand Down Expand Up @@ -1796,15 +1747,7 @@ mod tests {
(sysvar::rent::id(), create_default_rent_account()),
];

// should succeed when vote_state_add_vote_latency is disabled
process_instruction_disabled_features(
&instructions[1].data,
transaction_accounts.clone(),
instructions[1].accounts.clone(),
Ok(()),
);

// should fail, if vote_state_add_vote_latency is enabled
// should fail, since VoteState1_14_11 isn't supported anymore
process_instruction(
&instructions[1].data,
transaction_accounts,
Expand Down Expand Up @@ -1845,15 +1788,6 @@ mod tests {
(sysvar::rent::id(), create_default_rent_account()),
];

// should fail, if vote_state_add_vote_latency is disabled
process_instruction_disabled_features(
&instructions[1].data,
transaction_accounts.clone(),
instructions[1].accounts.clone(),
Err(InstructionError::InvalidAccountData),
);

// succeeds, since vote_state_add_vote_latency is enabled
process_instruction(
&instructions[1].data,
transaction_accounts,
Expand Down
Loading

0 comments on commit 9db1d9c

Please sign in to comment.