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

Revert "Make BPF Loader static (bp #11516) (#11865)" #11871

Merged
merged 1 commit into from
Aug 27, 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: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ serde = "1.0.110"
serde_derive = "1.0.103"
serde_json = "1.0.53"
solana-account-decoder = { path = "../account-decoder", version = "1.2.27" }
solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "1.2.27" }
solana-budget-program = { path = "../programs/budget", version = "1.2.27" }
solana-clap-utils = { path = "../clap-utils", version = "1.2.27" }
solana-client = { path = "../client", version = "1.2.27" }
Expand Down
3 changes: 3 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ pub mod verified_vote_packets;
pub mod weighted_shuffle;
pub mod window_service;

#[macro_use]
extern crate solana_bpf_loader_program;

#[macro_use]
extern crate solana_budget_program;

Expand Down
7 changes: 7 additions & 0 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,13 @@ impl TestValidator {
genesis_config
.native_instruction_processors
.push(solana_budget_program!());
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: 26 additions & 80 deletions genesis-programs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use solana_sdk::{
clock::Epoch, genesis_config::OperatingMode, inflation::Inflation, pubkey::Pubkey,
};

#[macro_use]
extern crate solana_bpf_loader_program;
#[macro_use]
Expand All @@ -9,10 +13,6 @@ 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,27 +44,22 @@ pub fn get_inflation(operating_mode: OperatingMode, epoch: Epoch) -> Option<Infl
}
}

enum Program {
Native((String, Pubkey)),
BuiltinLoader((String, Pubkey, ProcessInstructionWithContext)),
}

fn get_programs(operating_mode: OperatingMode, epoch: Epoch) -> Option<Vec<Program>> {
pub fn get_programs(operating_mode: OperatingMode, epoch: Epoch) -> Option<Vec<(String, Pubkey)>> {
match operating_mode {
OperatingMode::Development => {
if epoch == 0 {
// Programs used for testing
Some(vec![
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!()),
solana_bpf_loader_program!(),
solana_bpf_loader_deprecated_program!(),
solana_vest_program!(),
solana_budget_program!(),
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![Program::BuiltinLoader(solana_bpf_loader_program!())])
Some(vec![solana_bpf_loader_program!()])
} else {
None
}
Expand All @@ -73,10 +68,7 @@ fn get_programs(operating_mode: OperatingMode, epoch: Epoch) -> Option<Vec<Progr
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![
Program::BuiltinLoader(solana_bpf_loader_program!()),
Program::Native(solana_vest_program!()),
])
Some(vec![solana_bpf_loader_program!(), solana_vest_program!()])
} else {
None
}
Expand All @@ -85,59 +77,29 @@ fn get_programs(operating_mode: OperatingMode, epoch: Epoch) -> Option<Vec<Progr
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![
Program::BuiltinLoader(solana_bpf_loader_program!()),
Program::Native(solana_vest_program!()),
])
Some(vec![solana_bpf_loader_program!(), 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(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 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 OperatingMode::Stable == operating_mode {
Expand All @@ -156,13 +118,8 @@ mod tests {
#[test]
fn test_id_uniqueness() {
let mut unique = HashSet::new();
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))),
}
}
let ids = get_programs(OperatingMode::Development, 0).unwrap();
assert!(ids.into_iter().all(move |id| unique.insert(id)));
}

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

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

#[test]
fn test_softlaunch_programs() {
assert!(get_programs(OperatingMode::Stable, 1).is_none());
assert_eq!(get_programs(OperatingMode::Stable, 1), 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_native_programs(operating_mode, 0).unwrap_or_else(Vec::new);
solana_genesis_programs::get_programs(operating_mode, 0).unwrap_or_else(|| vec![]);
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 @@ -300,11 +300,11 @@ pub fn process_blockstore(
}

// Setup bank for slot 0
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);
let bank0 = Arc::new(Bank::new_with_paths(
&genesis_config,
account_paths,
&opts.frozen_accounts,
));
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 @@ -140,7 +140,7 @@ impl LocalCluster {
match genesis_config.operating_mode {
OperatingMode::Stable | OperatingMode::Preview => {
genesis_config.native_instruction_processors =
solana_genesis_programs::get_native_programs(genesis_config.operating_mode, 0)
solana_genesis_programs::get_programs(genesis_config.operating_mode, 0)
.unwrap_or_default()
}
_ => (),
Expand Down
1 change: 1 addition & 0 deletions programs/bpf/Cargo.lock

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

Loading