From 9c8b8edfe5f3328080ffa1ac372e26b13c302f4a Mon Sep 17 00:00:00 2001 From: segfaultdoctor <17258903+segfaultdoc@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:07:48 -0800 Subject: [PATCH] wip --- Cargo.lock | 4 -- bundle-execution/Cargo.toml | 10 ++-- bundle-execution/src/lib.rs | 2 - .../unprocessed_transaction_storage.rs | 6 +- programs/sbf/Cargo.lock | 4 -- .../src/bundle_processor.rs | 55 ++++++++++++++++++- svm/src/lib.rs | 1 + 7 files changed, 64 insertions(+), 18 deletions(-) rename bundle-execution/src/bundle_execution.rs => svm/src/bundle_processor.rs (96%) diff --git a/Cargo.lock b/Cargo.lock index 49d0c85a53..9a512e5691 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6502,14 +6502,10 @@ dependencies = [ "log", "serde", "solana-accounts-db", - "solana-ledger", "solana-logger", "solana-measure", - "solana-poh", "solana-program-runtime", - "solana-runtime", "solana-sdk", - "solana-svm", "solana-timings", "solana-transaction-status", "thiserror 1.0.69", diff --git a/bundle-execution/Cargo.toml b/bundle-execution/Cargo.toml index d5621517e5..14dfc83bb1 100644 --- a/bundle-execution/Cargo.toml +++ b/bundle-execution/Cargo.toml @@ -16,14 +16,14 @@ itertools = { workspace = true } log = { workspace = true } serde = { workspace = true } solana-accounts-db = { workspace = true } -solana-ledger = { workspace = true } +#solana-ledger = { workspace = true } solana-logger = { workspace = true } solana-measure = { workspace = true } -solana-poh = { workspace = true } +#solana-poh = { workspace = true } solana-program-runtime = { workspace = true } -solana-runtime = { workspace = true } +#solana-runtime = { workspace = true } solana-sdk = { workspace = true } -solana-svm = { workspace = true } +#solana-svm = { workspace = true } solana-timings = { workspace = true } solana-transaction-status = { workspace = true } thiserror = { workspace = true } @@ -31,7 +31,7 @@ thiserror = { workspace = true } [dev-dependencies] assert_matches = { workspace = true } solana-logger = { workspace = true } -solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } +#solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } [lib] crate-type = ["lib"] diff --git a/bundle-execution/src/lib.rs b/bundle-execution/src/lib.rs index a93e0d3d17..fa50b4c5e8 100644 --- a/bundle-execution/src/lib.rs +++ b/bundle-execution/src/lib.rs @@ -7,8 +7,6 @@ use { thiserror::Error, }; -pub mod bundle_execution; - #[derive(Error, Debug, Clone, Serialize, Deserialize, PartialEq)] pub enum TipError { #[error("account is missing from bank: {0}")] diff --git a/core/src/banking_stage/unprocessed_transaction_storage.rs b/core/src/banking_stage/unprocessed_transaction_storage.rs index 41f14419b6..cb65324797 100644 --- a/core/src/banking_stage/unprocessed_transaction_storage.rs +++ b/core/src/banking_stage/unprocessed_transaction_storage.rs @@ -22,7 +22,6 @@ use { itertools::Itertools, min_max_heap::MinMaxHeap, solana_accounts_db::account_locks::validate_account_locks, - solana_bundle::{bundle_execution::LoadAndExecuteBundleError, BundleExecutionError}, solana_measure::measure_us, solana_runtime::bank::Bank, solana_sdk::{ @@ -34,7 +33,10 @@ use { saturating_add_assign, transaction::SanitizedTransaction, }, - solana_svm::transaction_error_metrics::TransactionErrorMetrics, + solana_svm::{ + bundle_processor::{BundleExecutionError, LoadAndExecuteBundleError}, + transaction_error_metrics::TransactionErrorMetrics, + }, std::{ collections::{HashMap, HashSet, VecDeque}, sync::{atomic::Ordering, Arc}, diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index c0c6b7e208..d85ffe9fe9 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5289,14 +5289,10 @@ dependencies = [ "log", "serde", "solana-accounts-db", - "solana-ledger", "solana-logger", "solana-measure", - "solana-poh", "solana-program-runtime", - "solana-runtime", "solana-sdk", - "solana-svm", "solana-timings", "solana-transaction-status", "thiserror", diff --git a/bundle-execution/src/bundle_execution.rs b/svm/src/bundle_processor.rs similarity index 96% rename from bundle-execution/src/bundle_execution.rs rename to svm/src/bundle_processor.rs index d97803e537..232b129ebd 100644 --- a/bundle-execution/src/bundle_execution.rs +++ b/svm/src/bundle_processor.rs @@ -1,8 +1,11 @@ use { + anchor_lang::error::Error, itertools::izip, log::*, + serde::{Deserialize, Serialize}, solana_ledger::token_balances::collect_token_balances, solana_measure::{measure::Measure, measure_us}, + solana_poh::poh_recorder::PohRecorderError, solana_runtime::{ account_saver::collect_accounts_to_store, bank::{Bank, LoadAndExecuteTransactionsOutput, TransactionBalances}, @@ -38,6 +41,56 @@ use { thiserror::Error, }; +#[derive(Error, Debug, Clone, Serialize, Deserialize, PartialEq)] +pub enum TipError { + #[error("account is missing from bank: {0}")] + AccountMissing(Pubkey), + + #[error("Anchor error: {0}")] + AnchorError(String), + + #[error("Lock error")] + LockError, + + #[error("Error executing initialize programs")] + InitializeProgramsError, + + #[error("Error cranking tip programs")] + CrankTipError, +} + +impl From for TipError { + fn from(anchor_err: Error) -> Self { + match anchor_err { + Error::AnchorError(e) => Self::AnchorError(e.error_msg), + Error::ProgramError(e) => Self::AnchorError(e.to_string()), + } + } +} + +pub type BundleExecutionResult = Result; + +#[derive(Error, Debug, Clone)] +pub enum BundleExecutionError { + #[error("The bank has hit the max allotted time for processing transactions")] + BankProcessingTimeLimitReached, + + #[error("The bundle exceeds the cost model")] + ExceedsCostModel, + + #[error("Runtime error while executing the bundle: {0}")] + TransactionFailure(#[from] LoadAndExecuteBundleError), + + #[error("Error locking bundle because a transaction is malformed")] + LockError, + + #[error("PoH record error: {0}")] + PohRecordError(#[from] PohRecorderError), + + #[error("Tip payment error {0}")] + TipError(#[from] TipError), +} + #[derive(Clone, Default)] pub struct BundleExecutionMetrics { pub num_retries: u64, @@ -551,7 +604,7 @@ fn get_account_transactions( #[cfg(test)] mod tests { use { - crate::bundle_execution::{load_and_execute_bundle, LoadAndExecuteBundleError}, + crate::bundle_processor::{load_and_execute_bundle, LoadAndExecuteBundleError}, assert_matches::assert_matches, solana_ledger::genesis_utils::create_genesis_config, solana_runtime::{bank::Bank, bank_forks::BankForks, genesis_utils::GenesisConfigInfo}, diff --git a/svm/src/lib.rs b/svm/src/lib.rs index 7a42e3ce4b..abdd8865d9 100644 --- a/svm/src/lib.rs +++ b/svm/src/lib.rs @@ -3,6 +3,7 @@ pub mod account_loader; pub mod account_overrides; +pub mod bundle_processor; pub mod message_processor; pub mod nonce_info; pub mod program_loader;