From 116b7699b8e4cba8afca107e893552d6db2fc864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Thu, 18 May 2023 15:18:24 +0000 Subject: [PATCH] Prevents built-ins from being pruned. --- ledger-tool/src/program.rs | 4 ++-- ledger/src/blockstore_processor.rs | 2 +- program-runtime/src/loaded_programs.rs | 4 +++- runtime/benches/bank.rs | 2 +- runtime/src/builtins.rs | 11 ++++++++++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ledger-tool/src/program.rs b/ledger-tool/src/program.rs index 1522c82e2584dd..8488b52d2425db 100644 --- a/ledger-tool/src/program.rs +++ b/ledger-tool/src/program.rs @@ -531,7 +531,7 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) { AccountSharedData::new(0, 0, &loader_id), )); let interpreted = matches.value_of("mode").unwrap() != "jit"; - with_mock_invoke_context!(invoke_context, transaction_context, transaction_accounts,); + with_mock_invoke_context!(invoke_context, transaction_context, transaction_accounts); // Adding `DELAY_VISIBILITY_SLOT_OFFSET` to slots to accommodate for delay visibility of the program let mut loaded_programs = @@ -548,7 +548,7 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) { debug!("Loaded program {}", key); loaded_programs.replenish(key, program); } - invoke_context.programs_loaded_for_tx_batch = &mut loaded_programs; + invoke_context.programs_loaded_for_tx_batch = &loaded_programs; invoke_context .transaction_context diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 167fff4581ec3d..b81212be870272 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -1840,7 +1840,7 @@ pub mod tests { matches::assert_matches, rand::{thread_rng, Rng}, solana_entry::entry::{create_ticks, next_entry, next_entry_mut}, - solana_program_runtime::{declare_process_instruction, loaded_programs::LoadedProgram}, + solana_program_runtime::declare_process_instruction, solana_runtime::{ genesis_utils::{ self, create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs, diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index 59c1b8e8e547b9..0d277852c1a6bf 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -473,7 +473,9 @@ impl LoadedPrograms { .rev() .filter(|entry| { let relation = fork_graph.relationship(entry.deployment_slot, new_root); - if entry.deployment_slot >= new_root { + if matches!(entry.program, LoadedProgramType::Builtin(_)) { + true + } else if entry.deployment_slot >= new_root { matches!(relation, BlockRelation::Equal | BlockRelation::Descendant) } else if !first_ancestor_found && (matches!(relation, BlockRelation::Ancestor) diff --git a/runtime/benches/bank.rs b/runtime/benches/bank.rs index ae52df772db671..ed43f1dae818e0 100644 --- a/runtime/benches/bank.rs +++ b/runtime/benches/bank.rs @@ -5,7 +5,7 @@ extern crate test; use { log::*, - solana_program_runtime::{declare_process_instruction, loaded_programs::LoadedProgram}, + solana_program_runtime::declare_process_instruction, solana_runtime::{ bank::{test_utils::goto_end_of_slot, *}, bank_client::BankClient, diff --git a/runtime/src/builtins.rs b/runtime/src/builtins.rs index f7d5599191fbeb..d692101aaab42f 100644 --- a/runtime/src/builtins.rs +++ b/runtime/src/builtins.rs @@ -27,7 +27,16 @@ impl std::fmt::Debug for BuiltinPrototype { impl solana_frozen_abi::abi_example::AbiExample for BuiltinPrototype { fn example() -> Self { // BuiltinPrototype isn't serializable by definition. - Self::default() + solana_program_runtime::declare_process_instruction!(entrypoint, 0, |_invoke_context| { + // Do nothing + Ok(()) + }); + Self { + feature_id: None, + program_id: Pubkey::default(), + name: "", + entrypoint, + } } }