Skip to content

Commit

Permalink
Use single feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Sep 28, 2021
1 parent 16f1b02 commit 935f3f5
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 151 deletions.
2 changes: 1 addition & 1 deletion cli-output/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn format_account_mode(message: &Message, index: usize) -> String {
} else {
"-"
},
if message.is_writable(index, /*demote_program_write_lock_features=*/ true) {
if message.is_writable(index, /*demote_program_write_locks=*/ true) {
"w" // comment for consistent rust fmt (no joking; lol)
} else {
"-"
Expand Down
10 changes: 5 additions & 5 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ impl BankingStage {
feature_set: &Arc<feature_set::FeatureSet>,
cost_tracker: &Arc<RwLock<CostTracker>>,
banking_stage_stats: &BankingStageStats,
demote_program_write_lock_features: bool,
demote_program_write_locks: bool,
votes_only: bool,
) -> (Vec<SanitizedTransaction>, Vec<usize>, Vec<usize>) {
let mut retryable_transaction_packet_indexes: Vec<usize> = vec![];
Expand Down Expand Up @@ -1126,7 +1126,7 @@ impl BankingStage {
.into_iter()
.filter_map(|(tx, tx_index)| {
let result = cost_tracker_readonly
.would_transaction_fit(&tx, demote_program_write_lock_features);
.would_transaction_fit(&tx, demote_program_write_locks);
if result.is_err() {
debug!("transaction {:?} would exceed limit: {:?}", tx, result);
retryable_transaction_packet_indexes.push(tx_index);
Expand Down Expand Up @@ -1208,7 +1208,7 @@ impl BankingStage {
&bank.feature_set,
cost_tracker,
banking_stage_stats,
bank.demote_program_write_lock_features(),
bank.demote_program_write_locks(),
bank.vote_only_bank(),
);
packet_conversion_time.stop();
Expand Down Expand Up @@ -1249,7 +1249,7 @@ impl BankingStage {
cost_tracker
.write()
.unwrap()
.add_transaction_cost(tx, bank.demote_program_write_lock_features());
.add_transaction_cost(tx, bank.demote_program_write_locks());
}
});
cost_tracking_time.stop();
Expand Down Expand Up @@ -1315,7 +1315,7 @@ impl BankingStage {
&bank.feature_set,
cost_tracker,
banking_stage_stats,
bank.demote_program_write_lock_features(),
bank.demote_program_write_locks(),
bank.vote_only_bank(),
);
unprocessed_packet_conversion_time.stop();
Expand Down
12 changes: 5 additions & 7 deletions core/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl CostModel {
pub fn calculate_cost(
&mut self,
transaction: &SanitizedTransaction,
demote_program_write_lock_features: bool,
demote_program_write_locks: bool,
) -> &TransactionCost {
self.transaction_cost.reset();

Expand All @@ -126,7 +126,7 @@ impl CostModel {
// calculate account access cost
let message = transaction.message();
message.account_keys_iter().enumerate().for_each(|(i, k)| {
let is_writable = message.is_writable(i, demote_program_write_lock_features);
let is_writable = message.is_writable(i, demote_program_write_locks);

if is_writable {
self.transaction_cost.writable_accounts.push(*k);
Expand Down Expand Up @@ -357,8 +357,7 @@ mod tests {
.unwrap();

let mut cost_model = CostModel::default();
let tx_cost =
cost_model.calculate_cost(&tx, /*demote_program_write_lock_features=*/ true);
let tx_cost = cost_model.calculate_cost(&tx, /*demote_program_write_locks=*/ true);
assert_eq!(2 + 2, tx_cost.writable_accounts.len());
assert_eq!(signer1.pubkey(), tx_cost.writable_accounts[0]);
assert_eq!(signer2.pubkey(), tx_cost.writable_accounts[1]);
Expand Down Expand Up @@ -400,8 +399,7 @@ mod tests {
cost_model
.upsert_instruction_cost(&system_program::id(), expected_execution_cost)
.unwrap();
let tx_cost =
cost_model.calculate_cost(&tx, /*demote_program_write_lock_features=*/ true);
let tx_cost = cost_model.calculate_cost(&tx, /*demote_program_write_locks=*/ true);
assert_eq!(expected_account_cost, tx_cost.account_access_cost);
assert_eq!(expected_execution_cost, tx_cost.execution_cost);
assert_eq!(2, tx_cost.writable_accounts.len());
Expand Down Expand Up @@ -472,7 +470,7 @@ mod tests {
thread::spawn(move || {
let mut cost_model = cost_model.write().unwrap();
let tx_cost = cost_model
.calculate_cost(&tx, /*demote_program_write_lock_features=*/ true);
.calculate_cost(&tx, /*demote_program_write_locks=*/ true);
assert_eq!(3, tx_cost.writable_accounts.len());
assert_eq!(expected_account_cost, tx_cost.account_access_cost);
})
Expand Down
8 changes: 4 additions & 4 deletions core/src/cost_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ impl CostTracker {
pub fn would_transaction_fit(
&self,
transaction: &SanitizedTransaction,
demote_program_write_lock_features: bool,
demote_program_write_locks: bool,
) -> Result<(), CostModelError> {
let mut cost_model = self.cost_model.write().unwrap();
let tx_cost = cost_model.calculate_cost(transaction, demote_program_write_lock_features);
let tx_cost = cost_model.calculate_cost(transaction, demote_program_write_locks);
self.would_fit(
&tx_cost.writable_accounts,
&(tx_cost.account_access_cost + tx_cost.execution_cost),
Expand All @@ -59,10 +59,10 @@ impl CostTracker {
pub fn add_transaction_cost(
&mut self,
transaction: &SanitizedTransaction,
demote_program_write_lock_features: bool,
demote_program_write_locks: bool,
) {
let mut cost_model = self.cost_model.write().unwrap();
let tx_cost = cost_model.calculate_cost(transaction, demote_program_write_lock_features);
let tx_cost = cost_model.calculate_cost(transaction, demote_program_write_locks);
let cost = tx_cost.account_access_cost + tx_cost.execution_cost;
for account_key in tx_cost.writable_accounts.iter() {
*self
Expand Down
2 changes: 1 addition & 1 deletion ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String>

let tx_cost = cost_model.calculate_cost(
&transaction,
true, // demote_program_write_lock_features
true, // demote_program_write_locks
);
if cost_tracker.try_add(tx_cost).is_err() {
println!(
Expand Down
12 changes: 4 additions & 8 deletions program-runtime/src/instruction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount},
account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
feature_set::{
demote_program_write_locks, do_support_realloc, fix_write_privs,
restore_write_lock_when_upgradeable,
},
feature_set::{demote_program_write_locks, do_support_realloc, fix_write_privs},
ic_msg,
instruction::{Instruction, InstructionError},
message::Message,
Expand Down Expand Up @@ -621,11 +618,10 @@ impl InstructionProcessor {
);
if result.is_ok() {
// Verify the called program has not misbehaved
let demote_program_write_lock_features = invoke_context
.is_feature_active(&demote_program_write_locks::id())
&& invoke_context.is_feature_active(&restore_write_lock_when_upgradeable::id());
let demote_program_write_locks =
invoke_context.is_feature_active(&demote_program_write_locks::id());
let write_privileges: Vec<bool> = (0..message.account_keys.len())
.map(|i| message.is_writable(i, demote_program_write_lock_features))
.map(|i| message.is_writable(i, demote_program_write_locks))
.collect();
result =
invoke_context.verify_and_update(instruction, account_indices, &write_privileges);
Expand Down
11 changes: 5 additions & 6 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use {
compute_budget::ComputeBudget,
entrypoint::{ProgramResult, SUCCESS},
epoch_schedule::EpochSchedule,
feature_set::{demote_program_write_locks, restore_write_lock_when_upgradeable},
feature_set::demote_program_write_locks,
fee_calculator::{FeeCalculator, FeeRateGovernor},
genesis_config::{ClusterType, GenesisConfig},
hash::Hash,
Expand Down Expand Up @@ -262,15 +262,14 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
let message = Message::new(&[instruction.clone()], None);
let program_id_index = message.instructions[0].program_id_index as usize;
let program_id = message.account_keys[program_id_index];
let demote_program_write_lock_features = invoke_context
.is_feature_active(&demote_program_write_locks::id())
&& invoke_context.is_feature_active(&restore_write_lock_when_upgradeable::id());
let demote_program_write_locks =
invoke_context.is_feature_active(&demote_program_write_locks::id());
// TODO don't have the caller's keyed_accounts so can't validate writer or signer escalation or deescalation yet
let caller_privileges = message
.account_keys
.iter()
.enumerate()
.map(|(i, _)| message.is_writable(i, demote_program_write_lock_features))
.map(|(i, _)| message.is_writable(i, demote_program_write_locks))
.collect::<Vec<bool>>();

stable_log::program_invoke(&logger, &program_id, invoke_context.invoke_depth());
Expand All @@ -296,7 +295,7 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
account.set_executable(account_info.executable);
account.set_rent_epoch(account_info.rent_epoch);
}
let account_info = if message.is_writable(i, demote_program_write_lock_features) {
let account_info = if message.is_writable(i, demote_program_write_locks) {
Some(account_info)
} else {
None
Expand Down
11 changes: 5 additions & 6 deletions programs/bpf_loader/src/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use solana_sdk::{
allow_native_ids, blake3_syscall_enabled, check_seed_length,
close_upgradeable_program_accounts, demote_program_write_locks, disable_fees_sysvar,
do_support_realloc, libsecp256k1_0_5_upgrade_enabled, mem_overlap_fix,
restore_write_lock_when_upgradeable, return_data_syscall_enabled,
secp256k1_recover_syscall_enabled, sol_log_data_syscall_enabled,
return_data_syscall_enabled, secp256k1_recover_syscall_enabled,
sol_log_data_syscall_enabled,
},
hash::{Hasher, HASH_BYTES},
ic_msg,
Expand Down Expand Up @@ -2079,9 +2079,8 @@ fn get_translated_accounts<'a, T, F>(
where
F: Fn(&T, &mut dyn InvokeContext) -> Result<CallerAccount<'a>, EbpfError<BpfError>>,
{
let demote_program_write_lock_features = invoke_context
.is_feature_active(&demote_program_write_locks::id())
&& invoke_context.is_feature_active(&restore_write_lock_when_upgradeable::id());
let demote_program_write_locks =
invoke_context.is_feature_active(&demote_program_write_locks::id());
let mut account_indices = Vec::with_capacity(message.account_keys.len());
let mut accounts = Vec::with_capacity(message.account_keys.len());
for (i, account_key) in message.account_keys.iter().enumerate() {
Expand All @@ -2107,7 +2106,7 @@ where
account.set_executable(caller_account.executable);
account.set_rent_epoch(caller_account.rent_epoch);
}
let caller_account = if message.is_writable(i, demote_program_write_lock_features) {
let caller_account = if message.is_writable(i, demote_program_write_locks) {
Some(caller_account)
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/transaction_status_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ impl TransactionStatusService {
})
.expect("FeeCalculator must exist");
let fee = transaction.message().calculate_fee(&fee_calculator);
let tx_account_locks = transaction
.get_account_locks(bank.demote_program_write_lock_features());
let tx_account_locks =
transaction.get_account_locks(bank.demote_program_write_locks());

let inner_instructions = inner_instructions.map(|inner_instructions| {
inner_instructions
Expand Down
Loading

0 comments on commit 935f3f5

Please sign in to comment.