From 526979d589e26433c515a484ed020d584a4aff88 Mon Sep 17 00:00:00 2001 From: Joe C Date: Thu, 4 Apr 2024 18:20:01 -0500 Subject: [PATCH] program-runtime: hoist `MessageProcessor` up to SVM (#586) --- Cargo.lock | 4 +++- program-runtime/Cargo.toml | 3 +-- program-runtime/src/lib.rs | 1 - programs/sbf/Cargo.lock | 2 +- svm/Cargo.toml | 3 +++ svm/src/lib.rs | 1 + {program-runtime => svm}/src/message_processor.rs | 10 ++++------ svm/src/transaction_processor.rs | 2 +- 8 files changed, 14 insertions(+), 12 deletions(-) rename {program-runtime => svm}/src/message_processor.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 6d01f67b9181e4..383740e77e7592 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6702,7 +6702,6 @@ dependencies = [ "enum-iterator", "itertools", "libc", - "libsecp256k1", "log", "num-derive", "num-traits", @@ -7304,9 +7303,12 @@ version = "2.0.0" dependencies = [ "bincode", "itertools", + "libsecp256k1", "log", "percentage", + "rand 0.8.5", "rustc_version 0.4.0", + "serde", "solana-bpf-loader-program", "solana-frozen-abi", "solana-frozen-abi-macro", diff --git a/program-runtime/Cargo.toml b/program-runtime/Cargo.toml index afec7352e1fb70..acf65778af5b72 100644 --- a/program-runtime/Cargo.toml +++ b/program-runtime/Cargo.toml @@ -21,7 +21,6 @@ num-derive = { workspace = true } num-traits = { workspace = true } percentage = { workspace = true } rand = { workspace = true } -serde = { workspace = true, features = ["derive", "rc"] } solana-frozen-abi = { workspace = true } solana-frozen-abi-macro = { workspace = true } solana-measure = { workspace = true } @@ -32,7 +31,7 @@ thiserror = { workspace = true } [dev-dependencies] assert_matches = { workspace = true } -libsecp256k1 = { workspace = true } +serde = { workspace = true } solana-logger = { workspace = true } solana-sdk = { workspace = true, features = ["dev-context-only-utils"] } test-case = { workspace = true } diff --git a/program-runtime/src/lib.rs b/program-runtime/src/lib.rs index 079f214fa236f0..ca44b44cd41aa9 100644 --- a/program-runtime/src/lib.rs +++ b/program-runtime/src/lib.rs @@ -15,7 +15,6 @@ pub mod compute_budget_processor; pub mod invoke_context; pub mod loaded_programs; pub mod log_collector; -pub mod message_processor; pub mod prioritization_fee; pub mod runtime_config; pub mod stable_log; diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 3d383111c3f97c..f6a62d9333b62f 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5446,7 +5446,6 @@ dependencies = [ "percentage", "rand 0.8.5", "rustc_version", - "serde", "solana-frozen-abi", "solana-frozen-abi-macro", "solana-measure", @@ -6351,6 +6350,7 @@ dependencies = [ "log", "percentage", "rustc_version", + "serde", "solana-bpf-loader-program", "solana-frozen-abi", "solana-frozen-abi-macro", diff --git a/svm/Cargo.toml b/svm/Cargo.toml index 21da2f7105bd73..ba5286e984c114 100644 --- a/svm/Cargo.toml +++ b/svm/Cargo.toml @@ -13,6 +13,7 @@ edition = { workspace = true } itertools = { workspace = true } log = { workspace = true } percentage = { workspace = true } +serde = { workspace = true, features = ["derive", "rc"] } solana-bpf-loader-program = { workspace = true } solana-frozen-abi = { workspace = true } solana-frozen-abi-macro = { workspace = true } @@ -29,6 +30,8 @@ name = "solana_svm" [dev-dependencies] bincode = { workspace = true } +libsecp256k1 = { workspace = true } +rand = { workspace = true } solana-logger = { workspace = true } solana-sdk = { workspace = true, features = ["dev-context-only-utils"] } diff --git a/svm/src/lib.rs b/svm/src/lib.rs index d0f679a15c448b..daa66a6fc6f774 100644 --- a/svm/src/lib.rs +++ b/svm/src/lib.rs @@ -4,6 +4,7 @@ pub mod account_loader; pub mod account_overrides; pub mod account_rent_state; +pub mod message_processor; pub mod transaction_account_state_info; pub mod transaction_error_metrics; pub mod transaction_processor; diff --git a/program-runtime/src/message_processor.rs b/svm/src/message_processor.rs similarity index 99% rename from program-runtime/src/message_processor.rs rename to svm/src/message_processor.rs index f3035820ac041c..6e788b9c0f86e0 100644 --- a/program-runtime/src/message_processor.rs +++ b/svm/src/message_processor.rs @@ -1,10 +1,10 @@ use { - crate::{ + serde::{Deserialize, Serialize}, + solana_measure::measure::Measure, + solana_program_runtime::{ invoke_context::InvokeContext, timings::{ExecuteDetailsTimings, ExecuteTimings}, }, - serde::{Deserialize, Serialize}, - solana_measure::measure::Measure, solana_sdk::{ account::WritableAccount, message::SanitizedMessage, @@ -34,7 +34,6 @@ impl MessageProcessor { /// For each instruction it calls the program entrypoint method and verifies that the result of /// the call does not violate the bank's accounting rules. /// The accounts are committed back to the bank only if every instruction succeeds. - #[allow(clippy::too_many_arguments)] pub fn process_message( message: &SanitizedMessage, program_indices: &[Vec], @@ -146,11 +145,10 @@ impl MessageProcessor { mod tests { use { super::*, - crate::{ + solana_program_runtime::{ compute_budget::ComputeBudget, declare_process_instruction, loaded_programs::{LoadedProgram, LoadedProgramsForTxBatch}, - message_processor::MessageProcessor, sysvar_cache::SysvarCache, }, solana_sdk::{ diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index e25c2ccfb24907..cc84347fa0d426 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -4,6 +4,7 @@ use { load_accounts, LoadedTransaction, TransactionCheckResult, TransactionLoadResult, }, account_overrides::AccountOverrides, + message_processor::MessageProcessor, transaction_account_state_info::TransactionAccountStateInfo, transaction_error_metrics::TransactionErrorMetrics, transaction_results::{ @@ -22,7 +23,6 @@ use { ProgramRuntimeEnvironments, DELAY_VISIBILITY_SLOT_OFFSET, }, log_collector::LogCollector, - message_processor::MessageProcessor, runtime_config::RuntimeConfig, sysvar_cache::SysvarCache, timings::{ExecuteDetailsTimings, ExecuteTimingType, ExecuteTimings},