Skip to content

Commit

Permalink
some renaming feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Mar 21, 2024
1 parent 220d342 commit 52972c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion runtime/src/bank/builtins/core_bpf_migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pub(crate) mod error;
mod target_builtin;

pub(crate) enum CoreBpfMigrationTarget {
pub(crate) enum CoreBpfMigrationTargetType {
Builtin,
Stateless,
}
31 changes: 15 additions & 16 deletions runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
super::{error::CoreBpfMigrationError, CoreBpfMigrationTarget},
super::{error::CoreBpfMigrationError, CoreBpfMigrationTargetType},
crate::bank::Bank,
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
Expand All @@ -22,51 +22,50 @@ impl TargetProgramBuiltin {
/// Create a new migration configuration for a built-in program.
pub(crate) fn new_checked(
bank: &Bank,
program_id: &Pubkey,
migration_target: &CoreBpfMigrationTarget,
program_address: &Pubkey,
migration_target: &CoreBpfMigrationTargetType,
) -> Result<Self, CoreBpfMigrationError> {
let program_address = *program_id;
let program_account = match migration_target {
CoreBpfMigrationTarget::Builtin => {
CoreBpfMigrationTargetType::Builtin => {
// The program account should exist.
let program_account = bank
.get_account_with_fixed_root(&program_address)
.ok_or(CoreBpfMigrationError::AccountNotFound(program_address))?;
.get_account_with_fixed_root(program_address)
.ok_or(CoreBpfMigrationError::AccountNotFound(*program_address))?;

// The program account should be owned by the native loader.
if program_account.owner() != &NATIVE_LOADER_ID {
return Err(CoreBpfMigrationError::IncorrectOwner(program_address));
return Err(CoreBpfMigrationError::IncorrectOwner(*program_address));
}

program_account
}
CoreBpfMigrationTarget::Stateless => {
CoreBpfMigrationTargetType::Stateless => {
// The program account should _not_ exist.
if bank.get_account_with_fixed_root(&program_address).is_some() {
return Err(CoreBpfMigrationError::AccountExists(program_address));
if bank.get_account_with_fixed_root(program_address).is_some() {
return Err(CoreBpfMigrationError::AccountExists(*program_address));
}

AccountSharedData::default()
}
};

let program_data_address = get_program_data_address(&program_address);
let program_data_address = get_program_data_address(program_address);

// The program data account should not exist.
if bank
.get_account_with_fixed_root(&program_data_address)
.is_some()
{
return Err(CoreBpfMigrationError::ProgramHasDataAccount(
program_address,
*program_address,
));
}

// The total data size is the size of the program account's data.
let total_data_size = program_account.data().len();

Ok(Self {
program_address,
program_address: *program_address,
program_account,
program_data_address,
total_data_size,
Expand Down Expand Up @@ -125,7 +124,7 @@ mod tests {
Some(feature_set::zk_token_sdk_enabled::id())
)]
fn test_target_program_builtin(program_address: Pubkey, activation_feature: Option<Pubkey>) {
let migration_target = CoreBpfMigrationTarget::Builtin;
let migration_target = CoreBpfMigrationTargetType::Builtin;
let mut bank = create_simple_test_bank(0);

if let Some(feature_id) = activation_feature {
Expand Down Expand Up @@ -204,7 +203,7 @@ mod tests {
#[test_case(solana_sdk::feature::id())]
#[test_case(solana_sdk::native_loader::id())]
fn test_target_program_stateless_builtin(program_address: Pubkey) {
let migration_target = CoreBpfMigrationTarget::Stateless;
let migration_target = CoreBpfMigrationTargetType::Stateless;
let bank = create_simple_test_bank(0);

let program_account = AccountSharedData::default();
Expand Down

0 comments on commit 52972c7

Please sign in to comment.