Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Bump compute budget for neon evm #17700

Merged
merged 1 commit into from
Jul 8, 2021
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
12 changes: 6 additions & 6 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use solana_sdk::{
bpf_loader, bpf_loader_deprecated,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::Clock,
entrypoint::SUCCESS,
entrypoint::{HEAP_LENGTH, SUCCESS},
feature_set::{add_missing_program_error_mappings, upgradeable_close_instruction},
ic_logger_msg, ic_msg,
instruction::InstructionError,
Expand Down Expand Up @@ -142,18 +142,18 @@ fn check_loader_id(id: &Pubkey) -> bool {
|| bpf_loader_upgradeable::check_id(id)
}

/// Default program heap size, allocators
/// are expected to enforce this
const DEFAULT_HEAP_SIZE: usize = 32 * 1024;

/// Create the BPF virtual machine
pub fn create_vm<'a>(
loader_id: &'a Pubkey,
program: &'a dyn Executable<BpfError, ThisInstructionMeter>,
parameter_bytes: &mut [u8],
invoke_context: &'a mut dyn InvokeContext,
) -> Result<EbpfVm<'a, BpfError, ThisInstructionMeter>, EbpfError<BpfError>> {
let heap = AlignedMemory::new_with_size(DEFAULT_HEAP_SIZE, HOST_ALIGN);
let bpf_compute_budget = invoke_context.get_bpf_compute_budget();
let heap = AlignedMemory::new_with_size(
bpf_compute_budget.heap_size.unwrap_or(HEAP_LENGTH),
HOST_ALIGN,
);
let heap_region = MemoryRegion::new_from_slice(heap.as_slice(), MM_HEAP_START, 0, true);
let mut vm = EbpfVm::new(program, parameter_bytes, &[heap_region])?;
syscalls::bind_syscall_context_objects(loader_id, &mut vm, invoke_context, heap)?;
Expand Down
1 change: 1 addition & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod loader_utils;
pub mod log_collector;
pub mod message_processor;
mod native_loader;
pub mod neon_evm_program;
pub mod non_circulating_supply;
mod pubkey_bins;
mod read_only_accounts_cache;
Expand Down
14 changes: 13 additions & 1 deletion runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount},
account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
feature_set::{instructions_sysvar_enabled, updated_verify_policy, FeatureSet},
feature_set::{
instructions_sysvar_enabled, neon_evm_compute_budget, updated_verify_policy, FeatureSet,
},
ic_logger_msg, ic_msg,
instruction::{CompiledInstruction, Instruction, InstructionError},
keyed_account::{create_keyed_accounts_unified, keyed_account_at_index, KeyedAccount},
Expand Down Expand Up @@ -1151,6 +1153,16 @@ impl MessageProcessor {
}

let program_id = instruction.program_id(&message.account_keys);

let mut bpf_compute_budget = bpf_compute_budget;
if feature_set.is_active(&neon_evm_compute_budget::id())
&& *program_id == crate::neon_evm_program::id()
{
// Bump the compute budget for neon_evm
bpf_compute_budget.max_units = 500_000;
bpf_compute_budget.heap_size = Some(256 * 1024);
}

let mut invoke_context = ThisInvokeContext::new(
program_id,
rent_collector.rent,
Expand Down
1 change: 1 addition & 0 deletions runtime/src/neon_evm_program.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
solana_sdk::declare_id!("NeonEVM111111111111111111111111111111111111");
5 changes: 5 additions & 0 deletions sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ pub mod updated_verify_policy {
solana_sdk::declare_id!("k15tVxtkgsmo7dy6iJ56N5hBCxuQAtqRgYwoTDuwbia");
}

pub mod neon_evm_compute_budget {
solana_sdk::declare_id!("GLrVvDPkQi5PMYUrsYWT9doZhSHr1BVZXqj5DbFps3rS");
}

lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
Expand Down Expand Up @@ -203,6 +207,7 @@ lazy_static! {
(deterministic_shred_seed_enabled::id(), "deterministic shred seed"),
(vote_stake_checked_instructions::id(), "vote/state program checked instructions #18345"),
(updated_verify_policy::id(), "Update verify policy"),
(neon_evm_compute_budget::id(), "bump neon_evm's compute budget"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/process_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ pub struct BpfComputeBudget {
pub sysvar_base_cost: u64,
/// Number of compute units consumed to call secp256k1_recover
pub secp256k1_recover_cost: u64,
/// Optional program heap region size, if `None` then loader default
pub heap_size: Option<usize>,
}
impl Default for BpfComputeBudget {
fn default() -> Self {
Expand All @@ -205,6 +207,7 @@ impl BpfComputeBudget {
cpi_bytes_per_unit: 250, // ~50MB at 200,000 units
sysvar_base_cost: 100,
secp256k1_recover_cost: 25_000,
heap_size: None,
}
}
}
Expand Down