Skip to content

Commit

Permalink
SIMD 0072: Add SignalSupportForStagedFeatures processor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Dec 9, 2024
1 parent 4b0502f commit a46bc23
Show file tree
Hide file tree
Showing 4 changed files with 529 additions and 37 deletions.
31 changes: 16 additions & 15 deletions program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use {
pubkey::Pubkey,
system_instruction, system_program,
sysvar::Sysvar,
vote::state::VoteStateVersions,
},
};

Expand Down Expand Up @@ -154,22 +153,24 @@ fn process_signal_support_for_staged_features(
// the provided vote account.
// Also validates vote account state.
{
let vote_data = vote_account_info.try_borrow_data()?;
let vote_state_versioned = bincode::deserialize::<VoteStateVersions>(&vote_data)
.map_err(|_| ProgramError::InvalidAccountData)?;

if vote_state_versioned.is_uninitialized() {
return Err(ProgramError::UninitializedAccount);
if !vote_account_info
.owner
.eq(&solana_program::vote::program::id())
{
return Err(ProgramError::InvalidAccountOwner);
}

match vote_state_versioned
.convert_to_current()
.get_authorized_voter(clock.epoch)
{
Some(authorized) if authorized.eq(authorized_voter_info.key) => (),
_ => {
return Err(ProgramError::IncorrectAuthority);
}
// Authorized voter pubkey is at offset 36. Don't deserialize the whole
// vote account.
let vote_data = vote_account_info.try_borrow_data()?;
let vote_state_authorized_voter = vote_data
.get(36..68)
.and_then(|slice| slice.try_into().ok())
.map(Pubkey::new_from_array)
.ok_or(ProgramError::InvalidAccountData)?;

if !vote_state_authorized_voter.eq(authorized_voter_info.key) {
return Err(ProgramError::IncorrectAuthority);
}
}

Expand Down
42 changes: 39 additions & 3 deletions program/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

use {
mollusk_svm::Mollusk,
solana_feature_gate_program::state::StagedFeatures,
solana_feature_gate_program::state::{FeatureBitMask, StagedFeatures, ValidatorSupportSignal},
solana_sdk::{
account::{Account, AccountSharedData},
clock::Clock,
feature::Feature,
pubkey::Pubkey,
rent::Rent,
vote::state::{VoteInit, VoteState, VoteStateVersions},
},
};

Expand Down Expand Up @@ -47,10 +49,11 @@ pub fn active_feature_account() -> AccountSharedData {
})
}

pub fn staged_features_account(feature_ids: &[Pubkey]) -> AccountSharedData {
pub fn staged_features_account(feature_ids: &[(Pubkey, u64)]) -> AccountSharedData {
let mut stage = StagedFeatures::default();
for (i, id) in feature_ids.iter().enumerate() {
for (i, (id, stake_support)) in feature_ids.iter().enumerate() {
stage.features[i].feature_id = *id;
stage.features[i].stake_support = *stake_support;
}
AccountSharedData::from(Account {
lamports: 100_000_000,
Expand All @@ -59,3 +62,36 @@ pub fn staged_features_account(feature_ids: &[Pubkey]) -> AccountSharedData {
..Account::default()
})
}

pub fn support_signal_account(signals: &[(u64, FeatureBitMask)]) -> AccountSharedData {
let mut support_signals = ValidatorSupportSignal::default();
for (slot, mask) in signals {
support_signals.store_signal(*slot, *mask);
}
AccountSharedData::from(Account {
lamports: 100_000_000,
data: bytemuck::bytes_of(&support_signals).to_vec(),
owner: solana_feature_gate_program::id(),
..Account::default()
})
}

pub fn vote_account(authorized_voter: &Pubkey, clock: &Clock, _stake: u64) -> AccountSharedData {
let data = {
let vote_init = VoteInit {
node_pubkey: Pubkey::new_unique(),
authorized_voter: *authorized_voter,
authorized_withdrawer: *authorized_voter,
commission: 0,
};
let vote_state = VoteState::new(&vote_init, clock);
let state = VoteStateVersions::new_current(vote_state);
bincode::serialize(&state).unwrap()
};
AccountSharedData::from(Account {
lamports: 100_000_000,
data,
owner: solana_program::vote::program::id(),
..Account::default()
})
}
Loading

0 comments on commit a46bc23

Please sign in to comment.