Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make BPF Loader static #11516

Merged
merged 2 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ serde_derive = "1.0.103"
serde_json = "1.0.56"
solana-account-decoder = { path = "../account-decoder", version = "1.4.0" }
solana-banks-server = { path = "../banks-server", version = "1.4.0" }
solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "1.4.0" }
solana-clap-utils = { path = "../clap-utils", version = "1.4.0" }
solana-client = { path = "../client", version = "1.4.0" }
solana-faucet = { path = "../faucet", version = "1.4.0" }
Expand Down
3 changes: 0 additions & 3 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ pub mod vote_stake_tracker;
pub mod weighted_shuffle;
pub mod window_service;

#[macro_use]
extern crate solana_bpf_loader_program;

#[macro_use]
extern crate log;

Expand Down
7 changes: 0 additions & 7 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,13 +868,6 @@ impl TestValidator {
42,
bootstrap_validator_lamports,
);
genesis_config
.native_instruction_processors
.push(solana_bpf_loader_program!());
genesis_config
.native_instruction_processors
.push(solana_bpf_loader_deprecated_program!());

genesis_config.rent.lamports_per_byte_year = 1;
genesis_config.rent.exemption_threshold = 1.0;
genesis_config.fee_rate_governor = FeeRateGovernor::new(fees, 0);
Expand Down
106 changes: 80 additions & 26 deletions genesis-programs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use solana_sdk::{
clock::Epoch, genesis_config::OperatingMode, inflation::Inflation, pubkey::Pubkey,
};

#[macro_use]
extern crate solana_bpf_loader_program;
#[macro_use]
Expand All @@ -13,6 +9,10 @@ extern crate solana_vest_program;

use log::*;
use solana_runtime::bank::{Bank, EnteredEpochCallback};
use solana_sdk::{
clock::Epoch, entrypoint_native::ProcessInstructionWithContext, genesis_config::OperatingMode,
inflation::Inflation, pubkey::Pubkey,
};

pub fn get_inflation(operating_mode: OperatingMode, epoch: Epoch) -> Option<Inflation> {
match operating_mode {
Expand Down Expand Up @@ -44,22 +44,27 @@ pub fn get_inflation(operating_mode: OperatingMode, epoch: Epoch) -> Option<Infl
}
}

pub fn get_programs(operating_mode: OperatingMode, epoch: Epoch) -> Option<Vec<(String, Pubkey)>> {
enum Program {
Native((String, Pubkey)),
BuiltinLoader((String, Pubkey, ProcessInstructionWithContext)),
}

fn get_programs(operating_mode: OperatingMode, epoch: Epoch) -> Option<Vec<Program>> {
match operating_mode {
OperatingMode::Development => {
if epoch == 0 {
// Programs used for testing
Some(vec![
solana_bpf_loader_program!(),
solana_bpf_loader_deprecated_program!(),
solana_vest_program!(),
solana_budget_program!(),
solana_exchange_program!(),
Program::BuiltinLoader(solana_bpf_loader_program!()),
Program::BuiltinLoader(solana_bpf_loader_deprecated_program!()),
Program::Native(solana_vest_program!()),
Program::Native(solana_budget_program!()),
Program::Native(solana_exchange_program!()),
])
} else if epoch == std::u64::MAX {
// The epoch of std::u64::MAX is a placeholder and is expected
// to be reduced in a future network update.
Some(vec![solana_bpf_loader_program!()])
Some(vec![Program::BuiltinLoader(solana_bpf_loader_program!())])
} else {
None
}
Expand All @@ -68,7 +73,10 @@ pub fn get_programs(operating_mode: OperatingMode, epoch: Epoch) -> Option<Vec<(
if epoch == std::u64::MAX {
// The epoch of std::u64::MAX is a placeholder and is expected
// to be reduced in a future network update.
Some(vec![solana_bpf_loader_program!(), solana_vest_program!()])
Some(vec![
Program::BuiltinLoader(solana_bpf_loader_program!()),
Program::Native(solana_vest_program!()),
])
} else {
None
}
Expand All @@ -77,29 +85,59 @@ pub fn get_programs(operating_mode: OperatingMode, epoch: Epoch) -> Option<Vec<(
if epoch == std::u64::MAX {
// The epoch of std::u64::MAX is a placeholder and is expected
// to be reduced in a future network update.
Some(vec![solana_bpf_loader_program!(), solana_vest_program!()])
Some(vec![
Program::BuiltinLoader(solana_bpf_loader_program!()),
Program::Native(solana_vest_program!()),
])
} else {
None
}
}
}
}

pub fn get_native_programs(
operating_mode: OperatingMode,
epoch: Epoch,
) -> Option<Vec<(String, Pubkey)>> {
match get_programs(operating_mode, epoch) {
Some(programs) => {
let mut native_programs = vec![];
for program in programs {
if let Program::Native((string, key)) = program {
native_programs.push((string, key));
}
}
Some(native_programs)
}
None => None,
}
}

pub fn get_entered_epoch_callback(operating_mode: OperatingMode) -> EnteredEpochCallback {
Box::new(move |bank: &mut Bank| {
info!(
"Entering epoch {} with operating_mode {:?}",
bank.epoch(),
operating_mode
);
if let Some(inflation) = get_inflation(operating_mode, bank.epoch()) {
info!("Entering new epoch with inflation {:?}", inflation);
bank.set_inflation(inflation);
}
if let Some(new_programs) = get_programs(operating_mode, bank.epoch()) {
for (name, program_id) in new_programs.iter() {
info!("Registering {} at {}", name, program_id);
bank.add_native_program(name, program_id);
if let Some(programs) = get_programs(operating_mode, bank.epoch()) {
for program in programs {
match program {
Program::Native((name, program_id)) => {
bank.add_native_program(&name, &program_id);
}
Program::BuiltinLoader((
name,
program_id,
process_instruction_with_context,
)) => {
bank.add_builtin_loader(
&name,
program_id,
process_instruction_with_context,
);
}
}
}
}
if OperatingMode::Stable == operating_mode {
Expand All @@ -118,8 +156,13 @@ mod tests {
#[test]
fn test_id_uniqueness() {
let mut unique = HashSet::new();
let ids = get_programs(OperatingMode::Development, 0).unwrap();
assert!(ids.into_iter().all(move |id| unique.insert(id)));
let programs = get_programs(OperatingMode::Development, 0).unwrap();
for program in programs {
match program {
Program::Native((name, id)) => assert!(unique.insert((name, id))),
Program::BuiltinLoader((name, id, _)) => assert!(unique.insert((name, id))),
}
}
}

#[test]
Expand All @@ -137,7 +180,18 @@ mod tests {
get_programs(OperatingMode::Development, 0).unwrap().len(),
5
);
assert_eq!(get_programs(OperatingMode::Development, 1), None);
assert!(get_programs(OperatingMode::Development, 1).is_none());
}

#[test]
fn test_native_development_programs() {
assert_eq!(
get_native_programs(OperatingMode::Development, 0)
.unwrap()
.len(),
3
);
assert!(get_native_programs(OperatingMode::Development, 1).is_none());
}

#[test]
Expand All @@ -155,7 +209,7 @@ mod tests {

#[test]
fn test_softlaunch_programs() {
assert_eq!(get_programs(OperatingMode::Stable, 1), None);
assert!(get_programs(OperatingMode::Stable, 1).is_none());
assert!(get_programs(OperatingMode::Stable, std::u64::MAX).is_some());
}
}
2 changes: 1 addition & 1 deletion genesis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
);

let native_instruction_processors =
solana_genesis_programs::get_programs(operating_mode, 0).unwrap_or_else(Vec::new);
solana_genesis_programs::get_native_programs(operating_mode, 0).unwrap_or_else(Vec::new);
let inflation = solana_genesis_programs::get_inflation(operating_mode, 0).unwrap();

let mut genesis_config = GenesisConfig {
Expand Down
10 changes: 5 additions & 5 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ pub fn process_blockstore(
}

// Setup bank for slot 0
let bank0 = Arc::new(Bank::new_with_paths(
&genesis_config,
account_paths,
&opts.frozen_accounts,
));
let mut bank0 = Bank::new_with_paths(&genesis_config, account_paths, &opts.frozen_accounts);
let callback =
solana_genesis_programs::get_entered_epoch_callback(genesis_config.operating_mode);
callback(&mut bank0);
let bank0 = Arc::new(bank0);
info!("processing ledger for slot 0...");
let recyclers = VerifyRecyclers::default();
process_bank_0(&bank0, blockstore, &opts, &recyclers)?;
Expand Down
2 changes: 1 addition & 1 deletion local-cluster/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl LocalCluster {
match genesis_config.operating_mode {
OperatingMode::Stable | OperatingMode::Preview => {
genesis_config.native_instruction_processors =
solana_genesis_programs::get_programs(genesis_config.operating_mode, 0)
solana_genesis_programs::get_native_programs(genesis_config.operating_mode, 0)
.unwrap_or_default()
}
_ => (),
Expand Down
1 change: 0 additions & 1 deletion programs/bpf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading