Bump compute budget for neon evm (#17700)

This commit is contained in:
Jack May
2021-07-08 10:43:34 -07:00
committed by GitHub
parent c853da7424
commit 2867584985
6 changed files with 29 additions and 7 deletions

View File

@ -30,7 +30,7 @@ use solana_sdk::{
bpf_loader, bpf_loader_deprecated, bpf_loader, bpf_loader_deprecated,
bpf_loader_upgradeable::{self, UpgradeableLoaderState}, bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::Clock, clock::Clock,
entrypoint::SUCCESS, entrypoint::{HEAP_LENGTH, SUCCESS},
feature_set::{add_missing_program_error_mappings, upgradeable_close_instruction}, feature_set::{add_missing_program_error_mappings, upgradeable_close_instruction},
ic_logger_msg, ic_msg, ic_logger_msg, ic_msg,
instruction::InstructionError, instruction::InstructionError,
@ -142,10 +142,6 @@ fn check_loader_id(id: &Pubkey) -> bool {
|| bpf_loader_upgradeable::check_id(id) || 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 /// Create the BPF virtual machine
pub fn create_vm<'a>( pub fn create_vm<'a>(
loader_id: &'a Pubkey, loader_id: &'a Pubkey,
@ -153,7 +149,11 @@ pub fn create_vm<'a>(
parameter_bytes: &mut [u8], parameter_bytes: &mut [u8],
invoke_context: &'a mut dyn InvokeContext, invoke_context: &'a mut dyn InvokeContext,
) -> Result<EbpfVm<'a, BpfError, ThisInstructionMeter>, EbpfError<BpfError>> { ) -> 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 heap_region = MemoryRegion::new_from_slice(heap.as_slice(), MM_HEAP_START, 0, true);
let mut vm = EbpfVm::new(program, parameter_bytes, &[heap_region])?; let mut vm = EbpfVm::new(program, parameter_bytes, &[heap_region])?;
syscalls::bind_syscall_context_objects(loader_id, &mut vm, invoke_context, heap)?; syscalls::bind_syscall_context_objects(loader_id, &mut vm, invoke_context, heap)?;

View File

@ -27,6 +27,7 @@ pub mod loader_utils;
pub mod log_collector; pub mod log_collector;
pub mod message_processor; pub mod message_processor;
mod native_loader; mod native_loader;
pub mod neon_evm_program;
pub mod non_circulating_supply; pub mod non_circulating_supply;
mod pubkey_bins; mod pubkey_bins;
mod read_only_accounts_cache; mod read_only_accounts_cache;

View File

@ -9,7 +9,9 @@ use solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount}, account::{AccountSharedData, ReadableAccount, WritableAccount},
account_utils::StateMut, account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState}, 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, ic_logger_msg, ic_msg,
instruction::{CompiledInstruction, Instruction, InstructionError}, instruction::{CompiledInstruction, Instruction, InstructionError},
keyed_account::{create_keyed_accounts_unified, keyed_account_at_index, KeyedAccount}, keyed_account::{create_keyed_accounts_unified, keyed_account_at_index, KeyedAccount},
@ -1151,6 +1153,16 @@ impl MessageProcessor {
} }
let program_id = instruction.program_id(&message.account_keys); 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( let mut invoke_context = ThisInvokeContext::new(
program_id, program_id,
rent_collector.rent, rent_collector.rent,

View File

@ -0,0 +1 @@
solana_sdk::declare_id!("NeonEVM111111111111111111111111111111111111");

View File

@ -163,6 +163,10 @@ pub mod updated_verify_policy {
solana_sdk::declare_id!("k15tVxtkgsmo7dy6iJ56N5hBCxuQAtqRgYwoTDuwbia"); solana_sdk::declare_id!("k15tVxtkgsmo7dy6iJ56N5hBCxuQAtqRgYwoTDuwbia");
} }
pub mod neon_evm_compute_budget {
solana_sdk::declare_id!("GLrVvDPkQi5PMYUrsYWT9doZhSHr1BVZXqj5DbFps3rS");
}
lazy_static! { lazy_static! {
/// Map of feature identifiers to user-visible description /// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [ pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
@ -203,6 +207,7 @@ lazy_static! {
(deterministic_shred_seed_enabled::id(), "deterministic shred seed"), (deterministic_shred_seed_enabled::id(), "deterministic shred seed"),
(vote_stake_checked_instructions::id(), "vote/state program checked instructions #18345"), (vote_stake_checked_instructions::id(), "vote/state program checked instructions #18345"),
(updated_verify_policy::id(), "Update verify policy"), (updated_verify_policy::id(), "Update verify policy"),
(neon_evm_compute_budget::id(), "bump neon_evm's compute budget"),
/*************** ADD NEW FEATURES HERE ***************/ /*************** ADD NEW FEATURES HERE ***************/
] ]
.iter() .iter()

View File

@ -181,6 +181,8 @@ pub struct BpfComputeBudget {
pub sysvar_base_cost: u64, pub sysvar_base_cost: u64,
/// Number of compute units consumed to call secp256k1_recover /// Number of compute units consumed to call secp256k1_recover
pub secp256k1_recover_cost: u64, pub secp256k1_recover_cost: u64,
/// Optional program heap region size, if `None` then loader default
pub heap_size: Option<usize>,
} }
impl Default for BpfComputeBudget { impl Default for BpfComputeBudget {
fn default() -> Self { fn default() -> Self {
@ -205,6 +207,7 @@ impl BpfComputeBudget {
cpi_bytes_per_unit: 250, // ~50MB at 200,000 units cpi_bytes_per_unit: 250, // ~50MB at 200,000 units
sysvar_base_cost: 100, sysvar_base_cost: 100,
secp256k1_recover_cost: 25_000, secp256k1_recover_cost: 25_000,
heap_size: None,
} }
} }
} }