From 45bdf729f6f572119e9ab9a6d8a5eb974fbcea3b Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Mon, 10 Mar 2025 11:47:03 +0700 Subject: [PATCH 001/199] test: add realloc ix to flexi counter --- .../programs/flexi-counter/src/instruction.rs | 43 ++++++++++++++++ .../programs/flexi-counter/src/processor.rs | 49 +++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/test-integration/programs/flexi-counter/src/instruction.rs b/test-integration/programs/flexi-counter/src/instruction.rs index c0f1cebdb..7e061ea39 100644 --- a/test-integration/programs/flexi-counter/src/instruction.rs +++ b/test-integration/programs/flexi-counter/src/instruction.rs @@ -17,6 +17,8 @@ pub struct DelegateArgs { pub commit_frequency_ms: u32, } +pub const MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE: u16 = 10_240; + /// The counter has both mul and add instructions in order to facilitate tests where /// order matters. For example in the case of the following operations: /// +4, *2 @@ -32,6 +34,25 @@ pub enum FlexiCounterInstruction { /// 2. `[]` The system program account. Init { label: String, bump: u8 }, + /// Increases the size of the FlexiCounter to reach the given bytes. + /// Max increase is [MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE] per instruction + /// which means this instruction needs to be called multiple times to reach + /// the desired size. + /// + /// NOTE: that the account needs to be funded for the full desired account size + /// via an airdrop after [FlexiCounterInstruction::Init]. + /// + /// Accounts: + /// 0. `[signer]` The payer that created and is resizing the account. + /// 1. `[write]` The counter PDA account whose size we are increasing. + /// 2. `[]` The system program account. + Realloc { + /// The target size we try to resize to. + bytes: u64, + /// The count of invocations of realloc that this instruction represents. + invocation_count: u16, + }, + /// Updates the FlexiCounter by adding the count to it. /// /// Accounts: @@ -94,6 +115,28 @@ pub fn create_init_ix(payer: Pubkey, label: String) -> Instruction { ) } +pub fn create_realloc_ix( + payer: Pubkey, + bytes: u64, + invocation_count: u16, +) -> Instruction { + let program_id = &crate::id(); + let (pda, _) = FlexiCounter::pda(&payer); + let accounts = vec![ + AccountMeta::new(payer, true), + AccountMeta::new(pda, false), + AccountMeta::new_readonly(system_program::id(), false), + ]; + Instruction::new_with_borsh( + *program_id, + &FlexiCounterInstruction::Realloc { + bytes, + invocation_count, + }, + accounts, + ) +} + pub fn create_add_ix(payer: Pubkey, count: u8) -> Instruction { let program_id = &crate::id(); let (pda, _) = FlexiCounter::pda(&payer); diff --git a/test-integration/programs/flexi-counter/src/processor.rs b/test-integration/programs/flexi-counter/src/processor.rs index 1807ba7ec..9d43b371d 100644 --- a/test-integration/programs/flexi-counter/src/processor.rs +++ b/test-integration/programs/flexi-counter/src/processor.rs @@ -17,6 +17,7 @@ use solana_program::{ sysvar::Sysvar, }; +use crate::instruction::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE; use crate::{ instruction::{DelegateArgs, FlexiCounterInstruction}, state::FlexiCounter, @@ -42,6 +43,10 @@ pub fn process( use FlexiCounterInstruction::*; match ix { Init { label, bump } => process_init(program_id, accounts, label, bump), + Realloc { + bytes, + invocation_count, + } => process_realloc(accounts, bytes, invocation_count), Add { count } => process_add(accounts, count), Mul { multiplier } => process_mul(accounts, multiplier), Delegate(args) => process_delegate(accounts, &args), @@ -98,6 +103,50 @@ fn process_init( Ok(()) } +fn process_realloc( + accounts: &[AccountInfo], + bytes: u64, + invocation_count: u16, +) -> ProgramResult { + msg!("Instruction: Realloc {}", invocation_count); + + let account_info_iter = &mut accounts.iter(); + let payer_info = next_account_info(account_info_iter)?; + let counter_pda_info = next_account_info(account_info_iter)?; + + let (counter_pda, _) = FlexiCounter::pda(payer_info.key); + assert_keys_equal(counter_pda_info.key, &counter_pda, || { + format!( + "Invalid Counter PDA {}, should be {}", + counter_pda_info.key, counter_pda + ) + })?; + + let current_size = counter_pda_info.data.borrow().len() as u64; + if current_size >= bytes { + msg!( + "Counter account already has {} bytes, no need to realloc", + counter_pda_info.data.borrow().len() + ); + return Ok(()); + } + + let next_alloc_size = std::cmp::min( + bytes, + current_size + MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64, + ); + + msg!( + "Allocating from {} to {} of desired {} bytes.", + current_size, + next_alloc_size, + bytes + ); + + counter_pda_info.realloc(next_alloc_size as usize, true)?; + Ok(()) +} + fn process_add(accounts: &[AccountInfo], count: u8) -> ProgramResult { msg!("Add {}", count); From 2e618824d32b99a58b753a51a0bd52f5a05cb56d Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 7 May 2025 11:14:00 +0700 Subject: [PATCH 002/199] chore: resort workspace depencencies --- Cargo.toml | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5f33534cc..b1de08288 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,15 +58,12 @@ bincode = "1.3.3" bs58 = "0.4.0" byteorder = "1.5.0" cargo-lock = "10.0.0" -expiring-hashmap = { path = "./utils/expiring-hashmap" } conjunto-transwise = { git = "https://github.com/magicblock-labs/conjunto.git", rev = "bf82b45" } console-subscriber = "0.2.0" -isocountry = "0.3.2" crossbeam-channel = "0.5.11" enum-iterator = "1.5.0" env_logger = "0.11.2" -magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "eba7644", default-features = false} -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } +expiring-hashmap = { path = "./utils/expiring-hashmap" } fd-lock = "4.0.2" fs_extra = "1.3.0" futures-util = "0.3.30" @@ -76,6 +73,7 @@ hostname = "0.4.0" http-body-util = "0.1.2" hyper = "1.4.1" hyper-util = "0.1.9" +isocountry = "0.3.2" itertools = "0.14" jsonrpc-core = "18.0.0" jsonrpc-core-client = "18.0.0" @@ -87,21 +85,7 @@ lazy_static = "1.4.0" libc = "0.2.153" libloading = "0.7.4" log = "0.4.20" -num_cpus = "1.16.0" -num-derive = "0.4" -num-format = "0.4.4" -num-traits = "0.2" -paste = "1.0" -prometheus = "0.13.4" -# Needs to match https://crates.io/crates/solana-storage-bigtable/2.1.13/dependencies -prost = "0.11.9" -rand = "0.8.5" -rayon = "1.10.0" -rustc_version = "0.4" -semver = "1.0.22" -serde = "1.0.217" -serde_derive = "1.0" -serde_json = "1.0" +magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "eba7644", default-features = false } magicblock-account-cloner = { path = "./magicblock-account-cloner" } magicblock-account-dumper = { path = "./magicblock-account-dumper" } magicblock-account-fetcher = { path = "./magicblock-account-fetcher" } @@ -113,6 +97,7 @@ magicblock-api = { path = "./magicblock-api" } magicblock-bank = { path = "./magicblock-bank" } magicblock-config = { path = "./magicblock-config" } magicblock-core = { path = "./magicblock-core" } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" } magicblock-ledger = { path = "./magicblock-ledger" } magicblock-metrics = { path = "./magicblock-metrics" } @@ -125,7 +110,22 @@ magicblock-rpc = { path = "./magicblock-rpc" } magicblock-tokens = { path = "./magicblock-tokens" } magicblock-transaction-status = { path = "./magicblock-transaction-status" } magicblock-version = { path = "./magicblock-version" } +num-derive = "0.4" +num-format = "0.4.4" +num-traits = "0.2" +num_cpus = "1.16.0" +paste = "1.0" +prometheus = "0.13.4" +# Needs to match https://crates.io/crates/solana-storage-bigtable/2.1.13/dependencies +prost = "0.11.9" protobuf-src = "1.1" +rand = "0.8.5" +rayon = "1.10.0" +rustc_version = "0.4" +semver = "1.0.22" +serde = "1.0.217" +serde_derive = "1.0" +serde_json = "1.0" solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "7bdfefc" } solana-accounts-db = { version = "2.2" } solana-account-decoder = { version = "2.2" } @@ -150,7 +150,7 @@ solana-rpc = "2.2" solana-rpc-client = { version = "2.2" } solana-rpc-client-api = { version = "2.2" } solana-sdk = { version = "2.2" } -solana-svm = { version = "2.2", features = [ "dev-context-only-utils" ] } +solana-svm = { version = "2.2", features = ["dev-context-only-utils"] } solana-svm-transaction = { version = "2.2" } solana-storage-proto = { path = "storage-proto" } solana-system-program = { version = "2.2" } @@ -164,11 +164,11 @@ tempfile = "3.10.1" test-tools = { path = "./test-tools" } test-tools-core = { path = "./test-tools-core" } thiserror = "1.0.57" -toml = "0.8.13" # Update solana-tokio patch below when updating this version tokio = "1.0" tokio-stream = "0.1.15" tokio-util = "0.7.10" +toml = "0.8.13" # Tonic version 11 conflicts with lower level deps of solana and 0.9.x is the last # version that allows prost 0.11.x to be used tonic = "0.9.2" @@ -181,5 +181,5 @@ vergen = "8.3.1" # some solana dependencies have solana-storage-proto as dependency # we need to patch them with our version, because they use protobuf-src v1.1.0 # and we use protobuf-src v2.1.1. Otherwise compilation fails -solana-storage-proto = { path = "./storage-proto" } solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "7bdfefc" } +solana-storage-proto = { path = "./storage-proto" } From 6806acf2a049dcdf94bbd5d1ae3df54c515f64f8 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 7 May 2025 11:32:53 +0700 Subject: [PATCH 003/199] chore: retire old remote scheduled commits processor and add new one --- Cargo.lock | 144 ++++++++- Cargo.toml | 1 + magicblock-accounts/Cargo.toml | 1 + magicblock-accounts/src/accounts_manager.rs | 17 +- magicblock-accounts/src/lib.rs | 1 + .../old_remote_scheduled_commits_processor.rs | 300 +++++++++++++++++ .../src/remote_scheduled_commits_processor.rs | 301 +----------------- 7 files changed, 465 insertions(+), 300 deletions(-) create mode 100644 magicblock-accounts/src/old_remote_scheduled_commits_processor.rs diff --git a/Cargo.lock b/Cargo.lock index 3ee589a48..fa5a174cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -747,7 +747,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "115e54d64eb62cdebad391c19efc9dce4981c690c85a33a12199d99bb9546fee" dependencies = [ "borsh-derive 0.10.4", - "hashbrown 0.12.3", + "hashbrown 0.13.2", ] [[package]] @@ -1185,7 +1185,7 @@ dependencies = [ "conjunto-addresses", "conjunto-core", "conjunto-providers", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", "serde", "solana-rpc-client", "solana-rpc-client-api", @@ -1859,6 +1859,18 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + [[package]] name = "fast-math" version = "0.1.1" @@ -1955,6 +1967,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -2350,6 +2368,18 @@ name = "hashbrown" version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.2", +] [[package]] name = "hdrhistogram" @@ -3359,6 +3389,17 @@ dependencies = [ "libsecp256k1-core", ] +[[package]] +name = "libsqlite3-sys" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbb8270bb4060bd76c6e96f20c52d80620f1d82a3470885694e41e0f81ef6fe7" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "libz-sys" version = "1.1.20" @@ -3559,8 +3600,9 @@ dependencies = [ "magicblock-account-updates", "magicblock-accounts-api", "magicblock-bank", + "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3687,6 +3729,44 @@ dependencies = [ "test-tools-core", ] +[[package]] +name = "magicblock-committor-program" +version = "0.0.0" +dependencies = [ + "borsh 1.5.5", + "borsh-derive 1.5.5", + "log", + "paste", + "solana-account", + "solana-program", + "solana-pubkey", + "thiserror 2.0.12", +] + +[[package]] +name = "magicblock-committor-service" +version = "0.0.0" +dependencies = [ + "base64 0.22.1", + "bincode", + "borsh 1.5.5", + "log", + "magicblock-committor-program", + "magicblock-delegation-program 1.0.0", + "magicblock-rpc-client", + "magicblock-table-mania", + "rusqlite", + "solana-account", + "solana-pubkey", + "solana-rpc-client", + "solana-rpc-client-api", + "solana-sdk", + "solana-transaction-status-client-types", + "thiserror 2.0.12", + "tokio", + "tokio-util 0.7.13", +] + [[package]] name = "magicblock-config" version = "0.1.1" @@ -3710,6 +3790,21 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "magicblock-delegation-program" +version = "1.0.0" +dependencies = [ + "bincode", + "borsh 1.5.5", + "bytemuck", + "num_enum", + "paste", + "solana-curve25519", + "solana-program", + "solana-security-txt", + "thiserror 1.0.69", +] + [[package]] name = "magicblock-delegation-program" version = "1.0.0" @@ -3924,6 +4019,35 @@ dependencies = [ "tokio", ] +[[package]] +name = "magicblock-rpc-client" +version = "0.0.0" +dependencies = [ + "log", + "solana-rpc-client", + "solana-rpc-client-api", + "solana-sdk", + "solana-transaction-status-client-types", + "thiserror 2.0.12", + "tokio", +] + +[[package]] +name = "magicblock-table-mania" +version = "0.0.0" +dependencies = [ + "ed25519-dalek", + "log", + "magicblock-rpc-client", + "sha3", + "solana-pubkey", + "solana-rpc-client", + "solana-rpc-client-api", + "solana-sdk", + "thiserror 2.0.12", + "tokio", +] + [[package]] name = "magicblock-tokens" version = "0.1.1" @@ -5420,6 +5544,20 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rusqlite" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e34486da88d8e051c7c0e23c3f15fd806ea8546260aa2fec247e97242ec143" +dependencies = [ + "bitflags 2.9.0", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "smallvec", +] + [[package]] name = "rustc-demangle" version = "0.1.24" diff --git a/Cargo.toml b/Cargo.toml index b1de08288..cf4c8db36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,6 +95,7 @@ magicblock-accounts-api = { path = "./magicblock-accounts-api" } magicblock-accounts-db = { path = "./magicblock-accounts-db" } magicblock-api = { path = "./magicblock-api" } magicblock-bank = { path = "./magicblock-bank" } +magicblock-committor-service = { path = "../comittor/magicblock-committor-service" } magicblock-config = { path = "./magicblock-config" } magicblock-core = { path = "./magicblock-core" } magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } diff --git a/magicblock-accounts/Cargo.toml b/magicblock-accounts/Cargo.toml index b4fe0a0d8..f91cdf0a5 100644 --- a/magicblock-accounts/Cargo.toml +++ b/magicblock-accounts/Cargo.toml @@ -19,6 +19,7 @@ magicblock-account-dumper = { workspace = true } magicblock-account-cloner = { workspace = true } magicblock-accounts-api = { workspace = true } magicblock-bank = { workspace = true } +magicblock-committor-service = { workspace = true } magicblock-core = { workspace = true } magicblock-metrics = { workspace = true } magicblock-mutator = { workspace = true } diff --git a/magicblock-accounts/src/accounts_manager.rs b/magicblock-accounts/src/accounts_manager.rs index 5cd836522..93d75ec12 100644 --- a/magicblock-accounts/src/accounts_manager.rs +++ b/magicblock-accounts/src/accounts_manager.rs @@ -13,8 +13,8 @@ use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair}; use crate::{ config::AccountsConfig, errors::AccountsResult, + old_remote_scheduled_commits_processor::OldRemoteScheduledCommitsProcessor, remote_account_committer::RemoteAccountCommitter, - remote_scheduled_commits_processor::RemoteScheduledCommitsProcessor, utils::try_rpc_cluster_from_cluster, ExternalAccountsManager, }; @@ -24,7 +24,7 @@ pub type AccountsManager = ExternalAccountsManager< RemoteAccountCommitter, TransactionAccountsExtractorImpl, TransactionAccountsValidatorImpl, - RemoteScheduledCommitsProcessor, + OldRemoteScheduledCommitsProcessor, >; impl AccountsManager { @@ -49,12 +49,13 @@ impl AccountsManager { config.commit_compute_unit_price, ); - let scheduled_commits_processor = RemoteScheduledCommitsProcessor::new( - remote_cluster, - bank.clone(), - cloned_accounts.clone(), - transaction_status_sender.clone(), - ); + let scheduled_commits_processor = + OldRemoteScheduledCommitsProcessor::new( + remote_cluster, + bank.clone(), + cloned_accounts.clone(), + transaction_status_sender.clone(), + ); Ok(Self { internal_account_provider, diff --git a/magicblock-accounts/src/lib.rs b/magicblock-accounts/src/lib.rs index ec28920c7..a4e48da4d 100644 --- a/magicblock-accounts/src/lib.rs +++ b/magicblock-accounts/src/lib.rs @@ -2,6 +2,7 @@ mod accounts_manager; mod config; pub mod errors; mod external_accounts_manager; +mod old_remote_scheduled_commits_processor; mod remote_account_committer; mod remote_scheduled_commits_processor; mod traits; diff --git a/magicblock-accounts/src/old_remote_scheduled_commits_processor.rs b/magicblock-accounts/src/old_remote_scheduled_commits_processor.rs new file mode 100644 index 000000000..d42eb9037 --- /dev/null +++ b/magicblock-accounts/src/old_remote_scheduled_commits_processor.rs @@ -0,0 +1,300 @@ +use std::{collections::HashSet, sync::Arc}; + +use async_trait::async_trait; +use conjunto_transwise::AccountChainSnapshot; +use log::*; +use magicblock_account_cloner::{ + AccountClonerOutput, AccountClonerOutput::Cloned, CloneOutputMap, +}; +use magicblock_accounts_api::InternalAccountProvider; +use magicblock_bank::bank::Bank; +use magicblock_core::debug_panic; +use magicblock_metrics::metrics; +use magicblock_mutator::Cluster; +use magicblock_processor::execute_transaction::execute_legacy_transaction; +use magicblock_program::{ + register_scheduled_commit_sent, FeePayerAccount, SentCommit, + TransactionScheduler, +}; +use magicblock_transaction_status::TransactionStatusSender; +use solana_sdk::{pubkey::Pubkey, signature::Signature}; + +use crate::{ + errors::{AccountsError, AccountsResult}, + remote_account_committer::update_account_commit_metrics, + AccountCommittee, AccountCommitter, ScheduledCommitsProcessor, + SendableCommitAccountsPayload, +}; + +pub struct OldRemoteScheduledCommitsProcessor { + #[allow(unused)] + cluster: Cluster, + bank: Arc, + transaction_status_sender: Option, + transaction_scheduler: TransactionScheduler, + cloned_accounts: CloneOutputMap, +} + +#[async_trait] +impl ScheduledCommitsProcessor for OldRemoteScheduledCommitsProcessor { + async fn process( + &self, + committer: &Arc, + account_provider: &IAP, + ) -> AccountsResult<()> + where + AC: AccountCommitter, + IAP: InternalAccountProvider, + { + let scheduled_commits = + self.transaction_scheduler.take_scheduled_commits(); + + if scheduled_commits.is_empty() { + return Ok(()); + } + + let mut sendable_payloads_queue = vec![]; + for commit in scheduled_commits { + info!("Processing commit: {:?}", commit); + + // Determine which accounts are available and can be committed + let mut committees = vec![]; + let all_pubkeys: HashSet = HashSet::from_iter( + commit + .accounts + .iter() + .map(|ca| ca.pubkey) + .collect::>(), + ); + let mut feepayers = HashSet::new(); + + for committed_account in commit.accounts { + let mut commitment_pubkey = committed_account.pubkey; + let mut commitment_pubkey_owner = committed_account.owner; + if let Some(Cloned { + account_chain_snapshot, + .. + }) = Self::fetch_cloned_account( + &committed_account.pubkey, + &self.cloned_accounts, + ) { + // If the account is a FeePayer, we committed the mapped delegated account + if account_chain_snapshot.chain_state.is_feepayer() { + commitment_pubkey = + AccountChainSnapshot::ephemeral_balance_pda( + &committed_account.pubkey, + ); + commitment_pubkey_owner = + AccountChainSnapshot::ephemeral_balance_pda_owner(); + feepayers.insert(FeePayerAccount { + pubkey: committed_account.pubkey, + delegated_pda: commitment_pubkey, + }); + } else if account_chain_snapshot + .chain_state + .is_undelegated() + { + error!("Scheduled commit account '{}' is undelegated. This is not supported.", committed_account.pubkey); + } + } + + match account_provider.get_account(&committed_account.pubkey) { + Some(account_data) => { + committees.push(AccountCommittee { + pubkey: commitment_pubkey, + owner: commitment_pubkey_owner, + account_data, + slot: commit.slot, + undelegation_requested: commit.request_undelegation, + }); + } + None => { + error!( + "Scheduled commmit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", + committed_account.pubkey + ); + } + } + } + + let payloads = vec![ + committer + .create_commit_accounts_transaction(committees) + .await?, + ]; + + // Determine which payloads are a noop since all accounts are up to date + // and which require a commit to chain + let mut included_pubkeys = HashSet::new(); + let sendable_payloads = payloads + .into_iter() + .filter_map(|payload| { + if let Some(transaction) = payload.transaction { + included_pubkeys.extend( + payload + .committees + .iter() + .map(|(pubkey, _)| *pubkey), + ); + Some(SendableCommitAccountsPayload { + transaction, + committees: payload.committees, + }) + } else { + None + } + }) + .collect::>(); + + // Tally up the pubkeys that will not be committed since the account + // was not available as determined when creating sendable payloads + let excluded_pubkeys = all_pubkeys + .into_iter() + .filter(|pubkey| { + !included_pubkeys.contains(pubkey) + && !included_pubkeys.contains( + &AccountChainSnapshot::ephemeral_balance_pda( + pubkey, + ), + ) + }) + .collect::>(); + + // Extract signatures of all transactions that we will execute on + // chain in order to realize the commits needed + let signatures = sendable_payloads + .iter() + .map(|payload| payload.get_signature()) + .collect::>(); + + // Record that we are about to send the commit to chain including all + // information (mainly signatures) needed to track its outcome on chain + let sent_commit = SentCommit { + commit_id: commit.id, + slot: commit.slot, + blockhash: commit.blockhash, + payer: commit.payer, + chain_signatures: signatures, + included_pubkeys: included_pubkeys.into_iter().collect(), + excluded_pubkeys, + feepayers, + requested_undelegation: commit.request_undelegation, + }; + register_scheduled_commit_sent(sent_commit); + let signature = execute_legacy_transaction( + commit.commit_sent_transaction, + &self.bank, + self.transaction_status_sender.as_ref(), + ) + .map_err(Box::new)?; + + // In the case that no account needs to be committed we record that in + // our ledger and are done + if sendable_payloads.is_empty() { + debug!( + "Signaled no commit needed with internal signature: {:?}", + signature + ); + continue; + } else { + debug!( + "Signaled commit with internal signature: {:?}", + signature + ); + } + + // Queue up the actual commit + sendable_payloads_queue.extend(sendable_payloads); + } + + self.process_accounts_commits_in_background( + committer, + sendable_payloads_queue, + ); + + Ok(()) + } + + fn scheduled_commits_len(&self) -> usize { + self.transaction_scheduler.scheduled_commits_len() + } + + fn clear_scheduled_commits(&self) { + self.transaction_scheduler.clear_scheduled_commits(); + } +} + +impl OldRemoteScheduledCommitsProcessor { + pub(crate) fn new( + cluster: Cluster, + bank: Arc, + cloned_accounts: CloneOutputMap, + transaction_status_sender: Option, + ) -> Self { + Self { + cluster, + bank, + transaction_status_sender, + cloned_accounts, + transaction_scheduler: TransactionScheduler::default(), + } + } + + fn process_accounts_commits_in_background( + &self, + committer: &Arc, + sendable_payloads_queue: Vec, + ) { + // We process the queue on a separate task in order to not block + // the validator (slot advance) itself + // NOTE: @@ we have to be careful here and ensure that the validator does not + // shutdown before this task is done + // We will need some tracking machinery which is overkill until we get to the + // point where we do allow validator shutdown + let committer = committer.clone(); + tokio::task::spawn(async move { + let pending_commits = match committer + .send_commit_transactions(sendable_payloads_queue) + .await + { + Ok(pending) => pending, + Err(AccountsError::FailedToSendCommitTransaction( + err, + commit_and_undelegate_accounts, + commit_only_accounts, + )) => { + update_account_commit_metrics( + &commit_and_undelegate_accounts, + &commit_only_accounts, + metrics::Outcome::Error, + None, + ); + debug_panic!( + "Failed to send commit transactions: {:?}", + err + ); + return; + } + Err(err) => { + debug_panic!( + "Failed to send commit transactions, received invalid err: {:?}", + err + ); + return; + } + }; + + committer.confirm_pending_commits(pending_commits).await; + }); + } + + fn fetch_cloned_account( + pubkey: &Pubkey, + cloned_accounts: &CloneOutputMap, + ) -> Option { + cloned_accounts + .read() + .expect("RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned") + .get(pubkey).cloned() + } +} diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 91d7cc6d6..5c5fc0dde 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -1,300 +1,23 @@ -use std::{collections::HashSet, sync::Arc}; +use std::sync::Arc; -use async_trait::async_trait; -use conjunto_transwise::AccountChainSnapshot; -use log::*; -use magicblock_account_cloner::{ - AccountClonerOutput, AccountClonerOutput::Cloned, CloneOutputMap, -}; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_bank::bank::Bank; -use magicblock_core::debug_panic; -use magicblock_metrics::metrics; -use magicblock_mutator::Cluster; -use magicblock_processor::execute_transaction::execute_legacy_transaction; -use magicblock_program::{ - register_scheduled_commit_sent, FeePayerAccount, SentCommit, - TransactionScheduler, -}; -use magicblock_transaction_status::TransactionStatusSender; -use solana_sdk::{pubkey::Pubkey, signature::Signature}; +use magicblock_committor_service::CommittorService; -use crate::{ - errors::{AccountsError, AccountsResult}, - remote_account_committer::update_account_commit_metrics, - AccountCommittee, AccountCommitter, ScheduledCommitsProcessor, - SendableCommitAccountsPayload, -}; +use crate::errors::AccountsResult; -pub struct RemoteScheduledCommitsProcessor { - #[allow(unused)] - cluster: Cluster, - bank: Arc, - transaction_status_sender: Option, - transaction_scheduler: TransactionScheduler, - cloned_accounts: CloneOutputMap, -} - -#[async_trait] -impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { - async fn process( - &self, - committer: &Arc, - account_provider: &IAP, - ) -> AccountsResult<()> - where - AC: AccountCommitter, - IAP: InternalAccountProvider, - { - let scheduled_commits = - self.transaction_scheduler.take_scheduled_commits(); - - if scheduled_commits.is_empty() { - return Ok(()); - } - - let mut sendable_payloads_queue = vec![]; - for commit in scheduled_commits { - info!("Processing commit: {:?}", commit); - - // Determine which accounts are available and can be committed - let mut committees = vec![]; - let all_pubkeys: HashSet = HashSet::from_iter( - commit - .accounts - .iter() - .map(|ca| ca.pubkey) - .collect::>(), - ); - let mut feepayers = HashSet::new(); - - for committed_account in commit.accounts { - let mut commitment_pubkey = committed_account.pubkey; - let mut commitment_pubkey_owner = committed_account.owner; - if let Some(Cloned { - account_chain_snapshot, - .. - }) = Self::fetch_cloned_account( - &committed_account.pubkey, - &self.cloned_accounts, - ) { - // If the account is a FeePayer, we committed the mapped delegated account - if account_chain_snapshot.chain_state.is_feepayer() { - commitment_pubkey = - AccountChainSnapshot::ephemeral_balance_pda( - &committed_account.pubkey, - ); - commitment_pubkey_owner = - AccountChainSnapshot::ephemeral_balance_pda_owner(); - feepayers.insert(FeePayerAccount { - pubkey: committed_account.pubkey, - delegated_pda: commitment_pubkey, - }); - } else if account_chain_snapshot - .chain_state - .is_undelegated() - { - error!("Scheduled commit account '{}' is undelegated. This is not supported.", committed_account.pubkey); - } - } - - match account_provider.get_account(&committed_account.pubkey) { - Some(account_data) => { - committees.push(AccountCommittee { - pubkey: commitment_pubkey, - owner: commitment_pubkey_owner, - account_data, - slot: commit.slot, - undelegation_requested: commit.request_undelegation, - }); - } - None => { - error!( - "Scheduled commmit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", - committed_account.pubkey - ); - } - } - } - - let payloads = vec![ - committer - .create_commit_accounts_transaction(committees) - .await?, - ]; - - // Determine which payloads are a noop since all accounts are up to date - // and which require a commit to chain - let mut included_pubkeys = HashSet::new(); - let sendable_payloads = payloads - .into_iter() - .filter_map(|payload| { - if let Some(transaction) = payload.transaction { - included_pubkeys.extend( - payload - .committees - .iter() - .map(|(pubkey, _)| *pubkey), - ); - Some(SendableCommitAccountsPayload { - transaction, - committees: payload.committees, - }) - } else { - None - } - }) - .collect::>(); - - // Tally up the pubkeys that will not be committed since the account - // was not available as determined when creating sendable payloads - let excluded_pubkeys = all_pubkeys - .into_iter() - .filter(|pubkey| { - !included_pubkeys.contains(pubkey) - && !included_pubkeys.contains( - &AccountChainSnapshot::ephemeral_balance_pda( - pubkey, - ), - ) - }) - .collect::>(); - - // Extract signatures of all transactions that we will execute on - // chain in order to realize the commits needed - let signatures = sendable_payloads - .iter() - .map(|payload| payload.get_signature()) - .collect::>(); - - // Record that we are about to send the commit to chain including all - // information (mainly signatures) needed to track its outcome on chain - let sent_commit = SentCommit { - commit_id: commit.id, - slot: commit.slot, - blockhash: commit.blockhash, - payer: commit.payer, - chain_signatures: signatures, - included_pubkeys: included_pubkeys.into_iter().collect(), - excluded_pubkeys, - feepayers, - requested_undelegation: commit.request_undelegation, - }; - register_scheduled_commit_sent(sent_commit); - let signature = execute_legacy_transaction( - commit.commit_sent_transaction, - &self.bank, - self.transaction_status_sender.as_ref(), - ) - .map_err(Box::new)?; - - // In the case that no account needs to be committed we record that in - // our ledger and are done - if sendable_payloads.is_empty() { - debug!( - "Signaled no commit needed with internal signature: {:?}", - signature - ); - continue; - } else { - debug!( - "Signaled commit with internal signature: {:?}", - signature - ); - } - - // Queue up the actual commit - sendable_payloads_queue.extend(sendable_payloads); - } - - self.process_accounts_commits_in_background( - committer, - sendable_payloads_queue, - ); - - Ok(()) - } - - fn scheduled_commits_len(&self) -> usize { - self.transaction_scheduler.scheduled_commits_len() - } - - fn clear_scheduled_commits(&self) { - self.transaction_scheduler.clear_scheduled_commits(); - } +struct RemoteScheduledCommitsProcessor { + committer_service: Arc, } impl RemoteScheduledCommitsProcessor { - pub(crate) fn new( - cluster: Cluster, - bank: Arc, - cloned_accounts: CloneOutputMap, - transaction_status_sender: Option, - ) -> Self { - Self { - cluster, - bank, - transaction_status_sender, - cloned_accounts, - transaction_scheduler: TransactionScheduler::default(), - } - } - - fn process_accounts_commits_in_background( - &self, - committer: &Arc, - sendable_payloads_queue: Vec, - ) { - // We process the queue on a separate task in order to not block - // the validator (slot advance) itself - // NOTE: @@ we have to be careful here and ensure that the validator does not - // shutdown before this task is done - // We will need some tracking machinery which is overkill until we get to the - // point where we do allow validator shutdown - let committer = committer.clone(); - tokio::task::spawn(async move { - let pending_commits = match committer - .send_commit_transactions(sendable_payloads_queue) - .await - { - Ok(pending) => pending, - Err(AccountsError::FailedToSendCommitTransaction( - err, - commit_and_undelegate_accounts, - commit_only_accounts, - )) => { - update_account_commit_metrics( - &commit_and_undelegate_accounts, - &commit_only_accounts, - metrics::Outcome::Error, - None, - ); - debug_panic!( - "Failed to send commit transactions: {:?}", - err - ); - return; - } - Err(err) => { - debug_panic!( - "Failed to send commit transactions, received invalid err: {:?}", - err - ); - return; - } - }; - - committer.confirm_pending_commits(pending_commits).await; - }); + pub fn new(committer_service: Arc) -> Self { + Self { committer_service } } - fn fetch_cloned_account( - pubkey: &Pubkey, - cloned_accounts: &CloneOutputMap, - ) -> Option { - cloned_accounts - .read() - .expect("RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned") - .get(pubkey).cloned() + async fn process(&self, account_provider: &IAP) -> AccountsResult<()> + where + IAP: InternalAccountProvider, + { + todo!() } } From 8cdc141b47a8aba1c4f082407e9bb57e9241d80f Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 7 May 2025 16:24:41 +0700 Subject: [PATCH 004/199] feat: initial impl of commits processor based on committor service --- magicblock-accounts/src/errors.rs | 12 + .../src/remote_scheduled_commits_processor.rs | 247 +++++++++++++++++- .../process_scheduled_commit_sent.rs | 2 +- 3 files changed, 253 insertions(+), 8 deletions(-) diff --git a/magicblock-accounts/src/errors.rs b/magicblock-accounts/src/errors.rs index fb34ebffa..c7c18b2b3 100644 --- a/magicblock-accounts/src/errors.rs +++ b/magicblock-accounts/src/errors.rs @@ -3,6 +3,7 @@ use std::collections::HashSet; use magicblock_account_cloner::{ AccountClonerError, AccountClonerUnclonableReason, }; +use magicblock_committor_service::ChangesetMeta; use solana_sdk::pubkey::Pubkey; use thiserror::Error; @@ -19,6 +20,14 @@ pub enum AccountsError { #[error("TransactionError")] TransactionError(#[from] Box), + #[error("CommittorSerivceError")] + CommittorSerivceError( + #[from] Box, + ), + + #[error("TokioOneshotRecvError")] + TokioOneshotRecvError(#[from] Box), + #[error("AccountClonerError")] AccountClonerError(#[from] AccountClonerError), @@ -48,4 +57,7 @@ pub enum AccountsError { #[error("Too many committees: {0}")] TooManyCommittees(usize), + + #[error("FailedToObtainReqidForCommittedChangeset {0:?}'")] + FailedToObtainReqidForCommittedChangeset(Box), } diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 5c5fc0dde..ad5dd2b00 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -1,23 +1,256 @@ -use std::sync::Arc; +use conjunto_transwise::AccountChainSnapshot; +use log::*; +use magicblock_bank::bank::Bank; +use magicblock_processor::execute_transaction::execute_legacy_transaction; +use magicblock_transaction_status::TransactionStatusSender; +use solana_sdk::{account::ReadableAccount, transaction::Transaction}; +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, +}; +use magicblock_account_cloner::{ + AccountClonerOutput, AccountClonerOutput::Cloned, CloneOutputMap, +}; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::CommittorService; +use magicblock_committor_service::{ + persist::BundleSignatureRow, ChangedAccount, Changeset, ChangesetMeta, + CommittorService, +}; +use magicblock_program::{ + register_scheduled_commit_sent, FeePayerAccount, Pubkey, SentCommit, + TransactionScheduler, +}; -use crate::errors::AccountsResult; +use crate::{errors::AccountsResult, AccountCommittee}; struct RemoteScheduledCommitsProcessor { - committer_service: Arc, + committor_service: Arc, + transaction_scheduler: TransactionScheduler, + cloned_accounts: CloneOutputMap, + bank: Arc, + transaction_status_sender: Arc, } impl RemoteScheduledCommitsProcessor { - pub fn new(committer_service: Arc) -> Self { - Self { committer_service } + pub fn new( + committer_service: Arc, + bank: Arc, + cloned_accounts: CloneOutputMap, + transaction_status_sender: Arc, + ) -> Self { + Self { + committor_service: committer_service, + bank, + transaction_status_sender, + cloned_accounts, + transaction_scheduler: TransactionScheduler::default(), + } } async fn process(&self, account_provider: &IAP) -> AccountsResult<()> where IAP: InternalAccountProvider, { - todo!() + let scheduled_commits = + self.transaction_scheduler.take_scheduled_commits(); + + if scheduled_commits.is_empty() { + return Ok(()); + } + + let mut changeset = Changeset::default(); + // SAFETY: we only get here if the scheduled commits are not empty + let max_slot = scheduled_commits + .iter() + .map(|commit| commit.slot) + .max() + .unwrap(); + + changeset.slot = max_slot; + + let mut sent_commits = HashMap::new(); + for commit in scheduled_commits { + // Determine which accounts are available and can be committed + let mut committees = vec![]; + let mut feepayers = HashSet::new(); + let mut excluded_pubkeys = vec![]; + for committed_account in commit.accounts { + let mut committee_pubkey = committed_account.pubkey; + let mut committee_owner = committed_account.owner; + if let Some(Cloned { + account_chain_snapshot, + .. + }) = Self::fetch_cloned_account( + &committed_account.pubkey, + &self.cloned_accounts, + ) { + // If the account is a FeePayer, we commit the mapped delegated account + if account_chain_snapshot.chain_state.is_feepayer() { + committee_pubkey = + AccountChainSnapshot::ephemeral_balance_pda( + &committed_account.pubkey, + ); + committee_owner = + AccountChainSnapshot::ephemeral_balance_pda_owner(); + feepayers.insert(FeePayerAccount { + pubkey: committed_account.pubkey, + delegated_pda: committee_pubkey, + }); + } else if account_chain_snapshot + .chain_state + .is_undelegated() + { + error!("Scheduled commit account '{}' is undelegated. This is not supported.", committed_account.pubkey); + excluded_pubkeys.push(committed_account.pubkey); + continue; + } + } + + match account_provider.get_account(&committed_account.pubkey) { + Some(account_data) => { + committees.push(( + commit.id, + AccountCommittee { + pubkey: committee_pubkey, + owner: committee_owner, + account_data, + slot: commit.slot, + undelegation_requested: commit + .request_undelegation, + }, + )); + } + None => { + error!( + "Scheduled commmit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", + committed_account.pubkey + ); + excluded_pubkeys.push(committed_account.pubkey); + continue; + } + } + } + + // Collect all SentCommit info available at this stage + // We add the chain_signatures after we sent off the changeset + let sent_commit = SentCommit { + commit_id: commit.id, + payer: commit.payer, + blockhash: commit.blockhash, + included_pubkeys: committees + .iter() + .map(|(_, committee)| committee.pubkey) + .collect(), + excluded_pubkeys, + feepayers, + requested_undelegation: commit.request_undelegation, + ..Default::default() + }; + sent_commits.insert( + commit.id, + (commit.commit_sent_transaction, sent_commit), + ); + + // Add the committee to the changeset + for (bundle_id, committee) in committees { + changeset.add( + committee.pubkey, + ChangedAccount::Full { + lamports: committee.account_data.lamports(), + data: committee.account_data.data().to_vec(), + owner: committee.owner, + bundle_id, + }, + ); + } + } + + self.process_changeset(changeset, sent_commits); + + Ok(()) + } + + fn fetch_cloned_account( + pubkey: &Pubkey, + cloned_accounts: &CloneOutputMap, + ) -> Option { + cloned_accounts + .read() + .expect("RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned") + .get(pubkey).cloned() + } + + fn process_changeset( + &self, + changeset: Changeset, + mut sent_commits: HashMap, + ) { + // We process the changeset on a separate task in order to not block + // the validator (slot advance) itself + let committor_service = self.committor_service.clone(); + let bank = self.bank.clone(); + let transaction_status_sender = self.transaction_status_sender.clone(); + + tokio::task::spawn(async move { + // Create one sent commit transaction per bundle in our validator + let changeset_metadata = ChangesetMeta::from(&changeset); + for bundle_id in changeset_metadata + .accounts + .iter() + .map(|account| account.bundle_id) + .collect::>() + { + match committor_service + .get_bundle_signatures(bundle_id) + .await + // TODO: @@@ + .unwrap() + .unwrap() + { + Some(BundleSignatureRow { + processed_signature, + finalized_signature, + bundle_id, + .. + }) => { + let mut chain_signatures = vec![processed_signature]; + if let Some(finalized_signature) = finalized_signature { + chain_signatures.push(finalized_signature); + } + if let Some(( + commit_sent_transaction, + mut sent_commit, + )) = sent_commits.remove(&bundle_id) + { + sent_commit.chain_signatures = chain_signatures; + register_scheduled_commit_sent(sent_commit); + match execute_legacy_transaction( + commit_sent_transaction, + &bank, + Some(&transaction_status_sender) + ) { + Ok(signature) => debug!( + "Signaled sent commit with internal signature: {:?}", + signature + ), + Err(err) => { + error!("Failed to signal sent commit via transaction: {}", err); + } + } + } else { + error!( + "BUG: Failed to get sent commit for bundle id {} that should have been added", + bundle_id + ); + } + } + None => error!( + "Failed to get bundle signatures for bundle id {}", + bundle_id + ), + } + } + }); } } diff --git a/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs b/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs index 09eaf38e5..58d76040f 100644 --- a/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs +++ b/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs @@ -17,7 +17,7 @@ use crate::{ FeePayerAccount, }; -#[derive(Debug, Clone)] +#[derive(Default, Debug, Clone)] pub struct SentCommit { pub commit_id: u64, pub slot: Slot, From c0d08a4862a5516d2ca1de19e7e70877aa230598 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 7 May 2025 16:56:42 +0700 Subject: [PATCH 005/199] feat: initializing committor service at startup --- Cargo.lock | 1 + magicblock-accounts/src/accounts_manager.rs | 19 +++---- .../src/external_accounts_manager.rs | 2 +- magicblock-accounts/src/lib.rs | 2 +- .../src/remote_scheduled_commits_processor.rs | 53 ++++++++++++------- magicblock-accounts/src/traits.rs | 5 +- .../stubs/scheduled_commits_processor_stub.rs | 9 +--- magicblock-api/Cargo.toml | 1 + magicblock-api/src/errors.rs | 5 ++ magicblock-api/src/magic_validator.rs | 15 ++++++ 10 files changed, 71 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa5a174cd..d4cae3237 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3665,6 +3665,7 @@ dependencies = [ "magicblock-accounts-api", "magicblock-accounts-db", "magicblock-bank", + "magicblock-committor-service", "magicblock-config", "magicblock-core", "magicblock-geyser-plugin", diff --git a/magicblock-accounts/src/accounts_manager.rs b/magicblock-accounts/src/accounts_manager.rs index 93d75ec12..f1728fe8c 100644 --- a/magicblock-accounts/src/accounts_manager.rs +++ b/magicblock-accounts/src/accounts_manager.rs @@ -7,14 +7,15 @@ use conjunto_transwise::{ use magicblock_account_cloner::{CloneOutputMap, RemoteAccountClonerClient}; use magicblock_accounts_api::BankAccountProvider; use magicblock_bank::bank::Bank; +use magicblock_committor_service::CommittorService; use magicblock_transaction_status::TransactionStatusSender; use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair}; use crate::{ config::AccountsConfig, errors::AccountsResult, - old_remote_scheduled_commits_processor::OldRemoteScheduledCommitsProcessor, remote_account_committer::RemoteAccountCommitter, + remote_scheduled_commits_processor::RemoteScheduledCommitsProcessor, utils::try_rpc_cluster_from_cluster, ExternalAccountsManager, }; @@ -24,11 +25,12 @@ pub type AccountsManager = ExternalAccountsManager< RemoteAccountCommitter, TransactionAccountsExtractorImpl, TransactionAccountsValidatorImpl, - OldRemoteScheduledCommitsProcessor, + RemoteScheduledCommitsProcessor, >; impl AccountsManager { pub fn try_new( + committer_service: Arc, bank: &Arc, cloned_accounts: &CloneOutputMap, remote_account_cloner_client: RemoteAccountClonerClient, @@ -49,13 +51,12 @@ impl AccountsManager { config.commit_compute_unit_price, ); - let scheduled_commits_processor = - OldRemoteScheduledCommitsProcessor::new( - remote_cluster, - bank.clone(), - cloned_accounts.clone(), - transaction_status_sender.clone(), - ); + let scheduled_commits_processor = RemoteScheduledCommitsProcessor::new( + committer_service, + bank.clone(), + cloned_accounts.clone(), + transaction_status_sender.clone(), + ); Ok(Self { internal_account_provider, diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index a19a51ea5..ef47f9c50 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -404,7 +404,7 @@ where pub async fn process_scheduled_commits(&self) -> AccountsResult<()> { self.scheduled_commits_processor - .process(&self.account_committer, &self.internal_account_provider) + .process(&self.internal_account_provider) .await } diff --git a/magicblock-accounts/src/lib.rs b/magicblock-accounts/src/lib.rs index a4e48da4d..6b2eda27e 100644 --- a/magicblock-accounts/src/lib.rs +++ b/magicblock-accounts/src/lib.rs @@ -2,7 +2,7 @@ mod accounts_manager; mod config; pub mod errors; mod external_accounts_manager; -mod old_remote_scheduled_commits_processor; +// mod old_remote_scheduled_commits_processor; mod remote_account_committer; mod remote_scheduled_commits_processor; mod traits; diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index ad5dd2b00..0311ae650 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -1,3 +1,4 @@ +use async_trait::async_trait; use conjunto_transwise::AccountChainSnapshot; use log::*; use magicblock_bank::bank::Bank; @@ -22,32 +23,20 @@ use magicblock_program::{ TransactionScheduler, }; -use crate::{errors::AccountsResult, AccountCommittee}; +use crate::{ + errors::AccountsResult, AccountCommittee, ScheduledCommitsProcessor, +}; -struct RemoteScheduledCommitsProcessor { +pub struct RemoteScheduledCommitsProcessor { committor_service: Arc, transaction_scheduler: TransactionScheduler, cloned_accounts: CloneOutputMap, bank: Arc, - transaction_status_sender: Arc, + transaction_status_sender: Option, } -impl RemoteScheduledCommitsProcessor { - pub fn new( - committer_service: Arc, - bank: Arc, - cloned_accounts: CloneOutputMap, - transaction_status_sender: Arc, - ) -> Self { - Self { - committor_service: committer_service, - bank, - transaction_status_sender, - cloned_accounts, - transaction_scheduler: TransactionScheduler::default(), - } - } - +#[async_trait] +impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { async fn process(&self, account_provider: &IAP) -> AccountsResult<()> where IAP: InternalAccountProvider, @@ -171,6 +160,30 @@ impl RemoteScheduledCommitsProcessor { Ok(()) } + fn scheduled_commits_len(&self) -> usize { + self.transaction_scheduler.scheduled_commits_len() + } + + fn clear_scheduled_commits(&self) { + self.transaction_scheduler.clear_scheduled_commits(); + } +} + +impl RemoteScheduledCommitsProcessor { + pub fn new( + committer_service: Arc, + bank: Arc, + cloned_accounts: CloneOutputMap, + transaction_status_sender: Option, + ) -> Self { + Self { + committor_service: committer_service, + bank, + transaction_status_sender, + cloned_accounts, + transaction_scheduler: TransactionScheduler::default(), + } + } fn fetch_cloned_account( pubkey: &Pubkey, cloned_accounts: &CloneOutputMap, @@ -228,7 +241,7 @@ impl RemoteScheduledCommitsProcessor { match execute_legacy_transaction( commit_sent_transaction, &bank, - Some(&transaction_status_sender) + transaction_status_sender.as_ref() ) { Ok(signature) => debug!( "Signaled sent commit with internal signature: {:?}", diff --git a/magicblock-accounts/src/traits.rs b/magicblock-accounts/src/traits.rs index 965d801f9..34808bc1f 100644 --- a/magicblock-accounts/src/traits.rs +++ b/magicblock-accounts/src/traits.rs @@ -1,4 +1,4 @@ -use std::{collections::HashSet, sync::Arc}; +use std::collections::HashSet; use async_trait::async_trait; use magicblock_accounts_api::InternalAccountProvider; @@ -14,9 +14,8 @@ use crate::errors::AccountsResult; #[async_trait] pub trait ScheduledCommitsProcessor { /// Processes all commits that were scheduled and accepted - async fn process( + async fn process( &self, - committer: &Arc, account_provider: &IAP, ) -> AccountsResult<()>; diff --git a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs index 893988b4b..abce96809 100644 --- a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs +++ b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs @@ -1,9 +1,5 @@ -use std::sync::Arc; - use async_trait::async_trait; -use magicblock_accounts::{ - errors::AccountsResult, AccountCommitter, ScheduledCommitsProcessor, -}; +use magicblock_accounts::{errors::AccountsResult, ScheduledCommitsProcessor}; use magicblock_accounts_api::InternalAccountProvider; #[derive(Default)] @@ -11,9 +7,8 @@ pub struct ScheduledCommitsProcessorStub {} #[async_trait] impl ScheduledCommitsProcessor for ScheduledCommitsProcessorStub { - async fn process( + async fn process( &self, - _committer: &Arc, _account_provider: &IAP, ) -> AccountsResult<()> { Ok(()) diff --git a/magicblock-api/Cargo.toml b/magicblock-api/Cargo.toml index 88bde102d..5687eb0ff 100644 --- a/magicblock-api/Cargo.toml +++ b/magicblock-api/Cargo.toml @@ -23,6 +23,7 @@ magicblock-accounts = { workspace = true } magicblock-accounts-api = { workspace = true } magicblock-accounts-db = { workspace = true } magicblock-bank = { workspace = true } +magicblock-committor-service = { workspace = true } magicblock-config = { workspace = true } magicblock-core = { workspace = true } magicblock-geyser-plugin = { workspace = true } diff --git a/magicblock-api/src/errors.rs b/magicblock-api/src/errors.rs index ee6c08fa3..13bc81b27 100644 --- a/magicblock-api/src/errors.rs +++ b/magicblock-api/src/errors.rs @@ -26,6 +26,11 @@ pub enum ApiError { #[error("Ledger error: {0}")] LedgerError(#[from] magicblock_ledger::errors::LedgerError), + #[error("CommittorSerivceError")] + CommittorSerivceError( + #[from] magicblock_committor_service::error::CommittorServiceError, + ), + #[error("Failed to load programs into bank: {0}")] FailedToLoadProgramsIntoBank(String), diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 268430e91..39b130a89 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -37,6 +37,7 @@ use magicblock_bank::{ program_loader::load_programs_into_bank, transaction_logs::TransactionLogCollectorFilter, }; +use magicblock_committor_service::{config::ChainConfig, CommittorService}; use magicblock_config::{EphemeralConfig, LifecycleMode, ProgramConfig}; use magicblock_geyser_plugin::rpc::GeyserRpcService; use magicblock_ledger::{ @@ -316,7 +317,19 @@ impl MagicValidator { identity_keypair.pubkey(), ); + let committor_service = Arc::new(CommittorService::try_start( + identity_keypair.insecure_clone(), + // TODO: @@@ config or inside ledger dir + "/tmp/committor_service.sqlite", + &ChainConfig { + rpc_uri: remote_rpc_config.url().to_string(), + commitment: remote_rpc_config + .commitment() + .unwrap_or(CommitmentLevel::Confirmed), + }, + )?); let accounts_manager = Self::init_accounts_manager( + committor_service, &bank, &remote_account_cloner_worker.get_last_clone_output(), RemoteAccountClonerClient::new(&remote_account_cloner_worker), @@ -406,6 +419,7 @@ impl MagicValidator { } fn init_accounts_manager( + committer_service: Arc, bank: &Arc, cloned_accounts: &CloneOutputMap, remote_account_cloner_client: RemoteAccountClonerClient, @@ -418,6 +432,7 @@ impl MagicValidator { "Failed to derive accounts config from provided magicblock config", ); let accounts_manager = AccountsManager::try_new( + committer_service, bank, cloned_accounts, remote_account_cloner_client, From 9eed6089005e13a6b14ef33ae02c25e7c744cef2 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 8 May 2025 08:59:09 +0700 Subject: [PATCH 006/199] test: logging signature of failed init_committees tx --- .../schedulecommit/client/src/schedule_commit_context.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test-integration/schedulecommit/client/src/schedule_commit_context.rs b/test-integration/schedulecommit/client/src/schedule_commit_context.rs index 5926e6a31..d287d53d4 100644 --- a/test-integration/schedulecommit/client/src/schedule_commit_context.rs +++ b/test-integration/schedulecommit/client/src/schedule_commit_context.rs @@ -6,7 +6,7 @@ use program_schedulecommit::api::{ delegate_account_cpi_instruction, init_account_instruction, init_payer_escrow, pda_and_bump, }; -use solana_rpc_client::rpc_client::RpcClient; +use solana_rpc_client::rpc_client::{RpcClient, SerializableTransaction}; use solana_rpc_client_api::config::RpcSendTransactionConfig; #[allow(unused_imports)] use solana_sdk::signer::SeedDerivable; @@ -124,7 +124,12 @@ impl ScheduleCommitTestContext { ..Default::default() }, ) - .with_context(|| "Failed to initialize committees") + .with_context(|| { + format!( + "Failed to initialize committees. Transaction signature: {}", + tx.get_signature() + ) + }) } pub fn escrow_lamports_for_payer(&self) -> Result { From dae8ea881dc1303f020573eec35255b219394388 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 9 May 2025 13:52:31 +0700 Subject: [PATCH 007/199] test: adapt to expect two signatures when finalizing --- .../test-scenarios/tests/01_commits.rs | 2 +- .../tests/02_commit_and_undelegate.rs | 4 ++-- .../tests/03_commits_fee_payer.rs | 2 +- .../test-scenarios/tests/utils/mod.rs | 20 ++++++++++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs b/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs index 725ee8955..2cbf0b6d8 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs @@ -61,7 +61,7 @@ fn test_committing_two_accounts() { info!("{} '{:?}'", sig, res); let res = verify::fetch_and_verify_commit_result_from_logs(&ctx, *sig); - assert_two_committees_were_committed(&ctx, &res); + assert_two_committees_were_committed(&ctx, &res, true); assert_two_committees_synchronized_count(&ctx, &res, 1); }); } diff --git a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs index fc506ca4a..bd9f3f8d8 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs @@ -171,7 +171,7 @@ fn test_committing_and_undelegating_one_account() { let res = verify::fetch_and_verify_commit_result_from_logs(&ctx, sig); - assert_one_committee_was_committed(&ctx, &res); + assert_one_committee_was_committed(&ctx, &res, true); assert_one_committee_synchronized_count(&ctx, &res, 1); assert_one_committee_account_was_undelegated_on_chain(&ctx); @@ -186,7 +186,7 @@ fn test_committing_and_undelegating_two_accounts_success() { let res = verify::fetch_and_verify_commit_result_from_logs(&ctx, sig); - assert_two_committees_were_committed(&ctx, &res); + assert_two_committees_were_committed(&ctx, &res, true); assert_two_committees_synchronized_count(&ctx, &res, 1); assert_two_committee_accounts_were_undelegated_on_chain(&ctx); diff --git a/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs b/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs index 2874aaf07..2325584eb 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs @@ -121,7 +121,7 @@ fn test_committing_fee_payer_escrowing_lamports() { assert!(res.is_ok()); let res = verify::fetch_and_verify_commit_result_from_logs(&ctx, *sig); - assert_two_committees_were_committed(&ctx, &res); + assert_two_committees_were_committed(&ctx, &res, true); assert_two_committees_synchronized_count(&ctx, &res, 1); // The fee payer should have been committed diff --git a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs index dc1870299..a807dd65b 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs @@ -52,6 +52,7 @@ fn get_context_with_delegated_committees_impl( pub fn assert_one_committee_was_committed( ctx: &ScheduleCommitTestContext, res: &ScheduledCommitResult, + finalize: bool, ) { let pda = ctx.committees[0].1; @@ -61,13 +62,20 @@ pub fn assert_one_committee_was_committed( let commit = res.included.get(&pda); assert!(commit.is_some(), "should have committed pda"); - assert_eq!(res.sigs.len(), 1, "should have 1 on chain sig"); + let sig_len = if finalize { 2 } else { 1 }; + assert_eq!( + res.sigs.len(), + sig_len, + "should have {} on chain sig", + sig_len + ); } #[allow(dead_code)] // used in 02_commit_and_undelegate.rs pub fn assert_two_committees_were_committed( ctx: &ScheduleCommitTestContext, res: &ScheduledCommitResult, + finalize: bool, ) { let pda1 = ctx.committees[0].1; let pda2 = ctx.committees[1].1; @@ -80,7 +88,13 @@ pub fn assert_two_committees_were_committed( assert!(commit1.is_some(), "should have committed pda1"); assert!(commit2.is_some(), "should have committed pda2"); - assert_eq!(res.sigs.len(), 1, "should have 1 on chain sig"); + let sig_len = if finalize { 2 } else { 1 }; + assert_eq!( + res.sigs.len(), + sig_len, + "should have {} on chain sig", + sig_len + ); } #[allow(dead_code)] @@ -92,7 +106,7 @@ pub fn assert_feepayer_was_committed( assert_eq!(res.feepayers.len(), 1, "includes 1 payer"); - let commit_payer = res.feepayers.iter().filter(|(p, _)| p == &payer).next(); + let commit_payer = res.feepayers.iter().find(|(p, _)| p == &payer); assert!(commit_payer.is_some(), "should have committed payer"); assert_eq!(res.sigs.len(), 1, "should have 1 on chain sig"); From 80e6777b0ff5ad0592b51067fd785904bfee3aca Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 9 May 2025 15:42:37 +0700 Subject: [PATCH 008/199] feat: ensure ephemeral validator is funded on chain --- magicblock-api/src/magic_validator.rs | 102 ++++++++++++++++++++------ 1 file changed, 80 insertions(+), 22 deletions(-) diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 39b130a89..7c02063e0 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -13,8 +13,9 @@ use std::{ use conjunto_transwise::RpcProviderConfig; use log::*; use magicblock_account_cloner::{ - standard_blacklisted_accounts, CloneOutputMap, RemoteAccountClonerClient, - RemoteAccountClonerWorker, ValidatorCollectionMode, + map_committor_request_result, standard_blacklisted_accounts, + CloneOutputMap, RemoteAccountClonerClient, RemoteAccountClonerWorker, + ValidatorCollectionMode, }; use magicblock_account_dumper::AccountDumperBank; use magicblock_account_fetcher::{ @@ -70,9 +71,14 @@ use solana_geyser_plugin_manager::{ geyser_plugin_manager::GeyserPluginManager, slot_status_notifier::SlotStatusNotifierImpl, }; +use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ - clock::Slot, commitment_config::CommitmentLevel, - genesis_config::GenesisConfig, pubkey::Pubkey, signature::Keypair, + clock::Slot, + commitment_config::{CommitmentConfig, CommitmentLevel}, + genesis_config::GenesisConfig, + native_token::LAMPORTS_PER_SOL, + pubkey::Pubkey, + signature::Keypair, signer::Signer, }; use tempfile::TempDir; @@ -148,6 +154,7 @@ pub struct MagicValidator { >, remote_account_cloner_handle: Option>, accounts_manager: Arc, + committor_service: Arc, transaction_listener: GeyserTransactionNotifyListener, rpc_service: JsonRpcService, _metrics: Option<(MetricsService, tokio::task::JoinHandle<()>)>, @@ -300,11 +307,24 @@ impl MagicValidator { &faucet_keypair.pubkey(), ); + let committor_service = Arc::new(CommittorService::try_start( + identity_keypair.insecure_clone(), + // TODO: @@@ config or inside ledger dir + "/tmp/committor_service.sqlite", + &ChainConfig { + rpc_uri: remote_rpc_config.url().to_string(), + commitment: remote_rpc_config + .commitment() + .unwrap_or(CommitmentLevel::Confirmed), + }, + )?); + let remote_account_cloner_worker = RemoteAccountClonerWorker::new( bank_account_provider, remote_account_fetcher_client, remote_account_updates_client, account_dumper_bank, + committor_service.clone(), accounts_config.allowed_program_ids, blacklisted_accounts, accounts_config.payer_init_lamports, @@ -317,19 +337,8 @@ impl MagicValidator { identity_keypair.pubkey(), ); - let committor_service = Arc::new(CommittorService::try_start( - identity_keypair.insecure_clone(), - // TODO: @@@ config or inside ledger dir - "/tmp/committor_service.sqlite", - &ChainConfig { - rpc_uri: remote_rpc_config.url().to_string(), - commitment: remote_rpc_config - .commitment() - .unwrap_or(CommitmentLevel::Confirmed), - }, - )?); let accounts_manager = Self::init_accounts_manager( - committor_service, + committor_service.clone(), &bank, &remote_account_cloner_worker.get_last_clone_output(), RemoteAccountClonerClient::new(&remote_account_cloner_worker), @@ -373,6 +382,7 @@ impl MagicValidator { remote_account_cloner_handle: None, pubsub_handle: Default::default(), pubsub_close_handle: Default::default(), + committor_service, sample_performance_service: None, pubsub_config, token, @@ -635,12 +645,53 @@ impl MagicValidator { }) } + async fn ensure_validator_funded_on_chain(&self) -> ApiResult<()> { + // TODO: @@@ configurable? + const MIN_BALANCE_SOL: u64 = 5; + // TODO: @@ duplicate code getting remote_rpc_config + let accounts_config = try_convert_accounts_config( + &self.config.accounts, + ) + .expect( + "Failed to derive accounts config from provided magicblock config", + ); + let remote_rpc_config = RpcProviderConfig::new( + try_rpc_cluster_from_cluster(&accounts_config.remote_cluster)?, + Some(CommitmentLevel::Confirmed), + ); + + let validator_pubkey = self.bank().get_identity(); + + let lamports = RpcClient::new_with_commitment( + remote_rpc_config.url().to_string(), + CommitmentConfig { + commitment: remote_rpc_config + .commitment() + .unwrap_or(CommitmentLevel::Confirmed), + }, + ) + .get_balance(&validator_pubkey) + .await + .map_err(|err| { + ApiError::FailedToObtainValidatorOnChainBalance( + validator_pubkey, + err.to_string(), + ) + })?; + if lamports < MIN_BALANCE_SOL * LAMPORTS_PER_SOL { + Err(ApiError::ValidatorInsufficientlyFunded( + validator_pubkey, + MIN_BALANCE_SOL, + )) + } else { + Ok(()) + } + } + pub async fn start(&mut self) -> ApiResult<()> { - if let Some(ref fdqn) = self.config.validator.fdqn { - if matches!( - self.config.accounts.lifecycle, - LifecycleMode::Ephemeral - ) { + if matches!(self.config.accounts.lifecycle, LifecycleMode::Ephemeral) { + self.ensure_validator_funded_on_chain().await?; + if let Some(ref fdqn) = self.config.validator.fdqn { self.register_validator_on_chain(fdqn).await?; } } @@ -664,9 +715,9 @@ impl MagicValidator { self.token.clone(), )); + self.start_remote_account_cloner_worker().await?; self.start_remote_account_fetcher_worker(); self.start_remote_account_updates_worker(); - self.start_remote_account_cloner_worker().await?; self.ledger_truncator.start(); @@ -746,6 +797,13 @@ impl MagicValidator { if let Some(mut remote_account_cloner_worker) = self.remote_account_cloner_worker.take() { + debug!("Reserving common pubkeys for committor service"); + map_committor_request_result( + self.committor_service.reserve_common_pubkeys(), + ) + .await?; + info!("RESERVED"); + if !self.config.ledger.reset { remote_account_cloner_worker.hydrate().await?; info!("Validator hydration complete (bank hydrate, replay, account clone)"); From 3078a1cfc0e0beeabcf153bec88732228d0e6f5c Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 9 May 2025 16:59:03 +0700 Subject: [PATCH 009/199] test: add single account commit test --- .../test-scenarios/tests/01_commits.rs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs b/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs index 2cbf0b6d8..8264bde12 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs @@ -10,12 +10,64 @@ use solana_rpc_client_api::config::RpcSendTransactionConfig; use solana_sdk::{signer::Signer, transaction::Transaction}; use test_tools_core::init_logger; use utils::{ + assert_one_committee_synchronized_count, + assert_one_committee_was_committed, assert_two_committees_synchronized_count, assert_two_committees_were_committed, get_context_with_delegated_committees, }; mod utils; +#[test] +fn test_committing_one_account() { + run_test!({ + let ctx = get_context_with_delegated_committees(1); + + let ScheduleCommitTestContextFields { + payer, + committees, + commitment, + ephem_client, + ephem_blockhash, + .. + } = ctx.fields(); + + let ix = schedule_commit_cpi_instruction( + payer.pubkey(), + pubkey_from_magic_program(magic_program::id()), + pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + &committees + .iter() + .map(|(player, _)| player.pubkey()) + .collect::>(), + &committees.iter().map(|(_, pda)| *pda).collect::>(), + ); + + let tx = Transaction::new_signed_with_payer( + &[ix], + Some(&payer.pubkey()), + &[&payer], + *ephem_blockhash, + ); + + let sig = tx.get_signature(); + let res = ephem_client + .send_and_confirm_transaction_with_spinner_and_config( + &tx, + *commitment, + RpcSendTransactionConfig { + skip_preflight: true, + ..Default::default() + }, + ); + info!("{} '{:?}'", sig, res); + + let res = verify::fetch_and_verify_commit_result_from_logs(&ctx, *sig); + assert_one_committee_was_committed(&ctx, &res, true); + assert_one_committee_synchronized_count(&ctx, &res, 1); + }); +} + #[test] fn test_committing_two_accounts() { run_test!({ From 8391124b2c3fc26f109be411e24f7eb34a530729 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 9 May 2025 16:59:59 +0700 Subject: [PATCH 010/199] test: warn when we have issues fetching a transaction --- .../test-tools/src/integration_test_context.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test-integration/test-tools/src/integration_test_context.rs b/test-integration/test-tools/src/integration_test_context.rs index 7d8d882e5..22245254b 100644 --- a/test-integration/test-tools/src/integration_test_context.rs +++ b/test-integration/test-tools/src/integration_test_context.rs @@ -1,3 +1,4 @@ +use log::*; use std::{str::FromStr, thread::sleep, time::Duration}; use anyhow::{Context, Result}; @@ -115,17 +116,18 @@ impl IntegrationTestContext { // Fetch Logs // ----------------- pub fn fetch_ephemeral_logs(&self, sig: Signature) -> Option> { - self.fetch_logs(sig, self.ephem_client.as_ref()) + self.fetch_logs(sig, self.ephem_client.as_ref(), "ephemeral") } pub fn fetch_chain_logs(&self, sig: Signature) -> Option> { - self.fetch_logs(sig, self.chain_client.as_ref()) + self.fetch_logs(sig, self.chain_client.as_ref(), "chain") } fn fetch_logs( &self, sig: Signature, rpc_client: Option<&RpcClient>, + label: &str, ) -> Option> { let rpc_client = rpc_client.or(self.chain_client.as_ref())?; @@ -140,7 +142,11 @@ impl IntegrationTestContext { }, ) { Ok(status) => status, - Err(_) => { + Err(err) => { + warn!( + "Failed to fetch transaction from {}: {:?}", + label, err + ); sleep(Duration::from_millis(400)); continue; } From e5aa347bce730a88dc049c663af0334582ddc501 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 9 May 2025 17:00:32 +0700 Subject: [PATCH 011/199] fix: adding change for validator fund check --- magicblock-api/src/errors.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/magicblock-api/src/errors.rs b/magicblock-api/src/errors.rs index 13bc81b27..6cebbf8d0 100644 --- a/magicblock-api/src/errors.rs +++ b/magicblock-api/src/errors.rs @@ -1,4 +1,5 @@ use magicblock_accounts_db::error::AccountsDbError; +use magicblock_program::Pubkey; use thiserror::Error; pub type ApiResult = std::result::Result; @@ -26,6 +27,12 @@ pub enum ApiError { #[error("Ledger error: {0}")] LedgerError(#[from] magicblock_ledger::errors::LedgerError), + #[error("Failed to obtain balance for validator '{0}' from chain. ({1})")] + FailedToObtainValidatorOnChainBalance(Pubkey, String), + + #[error("Validator '{0}' is insufficiently funded on chain. Minimum is ({1} SOL)")] + ValidatorInsufficientlyFunded(Pubkey, u64), + #[error("CommittorSerivceError")] CommittorSerivceError( #[from] magicblock_committor_service::error::CommittorServiceError, From be98740562f884d8968a6386a94386313a35ac19 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 9 May 2025 17:01:50 +0700 Subject: [PATCH 012/199] feat: fully integrating committor service --- .../src/account_cloner.rs | 20 +++++++++++++++- .../src/remote_account_cloner_worker.rs | 24 +++++++++++++++---- .../src/remote_scheduled_commits_processor.rs | 23 +++++++++++++++++- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/magicblock-account-cloner/src/account_cloner.rs b/magicblock-account-cloner/src/account_cloner.rs index 60ed7d4d5..03e476cab 100644 --- a/magicblock-account-cloner/src/account_cloner.rs +++ b/magicblock-account-cloner/src/account_cloner.rs @@ -8,10 +8,11 @@ use futures_util::future::BoxFuture; use magicblock_account_dumper::AccountDumperError; use magicblock_account_fetcher::AccountFetcherError; use magicblock_account_updates::AccountUpdatesError; +use magicblock_committor_service::error::CommittorServiceResult; use magicblock_core::magic_program; use solana_sdk::{clock::Slot, pubkey::Pubkey, signature::Signature}; use thiserror::Error; -use tokio::sync::oneshot::Sender; +use tokio::sync::oneshot::{self, Sender}; #[derive(Debug, Clone, Error)] pub enum AccountClonerError { @@ -30,6 +31,9 @@ pub enum AccountClonerError { #[error(transparent)] AccountDumperError(#[from] AccountDumperError), + #[error("CommittorSerivceError {0}")] + CommittorSerivceError(String), + #[error("ProgramDataDoesNotExist")] ProgramDataDoesNotExist, @@ -66,6 +70,20 @@ pub enum AccountClonerUnclonableReason { DelegatedAccountsNotClonedWhileHydrating, } +pub async fn map_committor_request_result( + res: oneshot::Receiver>, +) -> AccountClonerResult { + res.await + .map_err(|err| { + // Send request error + AccountClonerError::CommittorSerivceError(format!("{:?}", err)) + })? + .map_err(|err| { + // Commit error + AccountClonerError::CommittorSerivceError(format!("{:?}", err)) + }) +} + #[derive(Debug, Clone)] pub struct AccountClonerPermissions { pub allow_cloning_refresh: bool, diff --git a/magicblock-account-cloner/src/remote_account_cloner_worker.rs b/magicblock-account-cloner/src/remote_account_cloner_worker.rs index 048def464..094de1bbe 100644 --- a/magicblock-account-cloner/src/remote_account_cloner_worker.rs +++ b/magicblock-account-cloner/src/remote_account_cloner_worker.rs @@ -18,6 +18,7 @@ use magicblock_account_dumper::AccountDumper; use magicblock_account_fetcher::AccountFetcher; use magicblock_account_updates::AccountUpdates; use magicblock_accounts_api::InternalAccountProvider; +use magicblock_committor_service::CommittorService; use magicblock_metrics::metrics; use magicblock_mutator::idl::{get_pubkey_anchor_idl, get_pubkey_shank_idl}; use solana_sdk::{ @@ -34,8 +35,8 @@ use tokio::{ use tokio_util::sync::CancellationToken; use crate::{ - AccountClonerError, AccountClonerListeners, AccountClonerOutput, - AccountClonerPermissions, AccountClonerResult, + map_committor_request_result, AccountClonerError, AccountClonerListeners, + AccountClonerOutput, AccountClonerPermissions, AccountClonerResult, AccountClonerUnclonableReason, CloneOutputMap, }; @@ -99,6 +100,7 @@ pub struct RemoteAccountClonerWorker { account_fetcher: AFE, account_updates: AUP, account_dumper: ADU, + committer_service: Arc, allowed_program_ids: Option>, blacklisted_accounts: HashSet, payer_init_lamports: Option, @@ -125,6 +127,7 @@ where account_fetcher: AFE, account_updates: AUP, account_dumper: ADU, + committer_service: Arc, allowed_program_ids: Option>, blacklisted_accounts: HashSet, payer_init_lamports: Option, @@ -141,6 +144,7 @@ where account_updates, account_dumper, allowed_program_ids, + committer_service, blacklisted_accounts, payer_init_lamports, validator_charges_fees, @@ -640,7 +644,7 @@ where }); } - self.do_clone_delegated_account( + let sig = self.do_clone_delegated_account( pubkey, // TODO(GabrielePicco): Avoid cloning &Account { @@ -648,7 +652,19 @@ where ..account.clone() }, delegation_record, - )? + )?; + + // Allow the committer service to reserve pubkeys in lookup tables + // that could be needed when we commit this account + map_committor_request_result( + self.committer_service.reserve_pubkeys_for_committee( + *pubkey, + delegation_record.owner, + ), + ) + .await?; + + sig } }; // Return the result diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 0311ae650..c47bf8ba1 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -4,6 +4,7 @@ use log::*; use magicblock_bank::bank::Bank; use magicblock_processor::execute_transaction::execute_legacy_transaction; use magicblock_transaction_status::TransactionStatusSender; +use solana_sdk::hash::Hash; use solana_sdk::{account::ReadableAccount, transaction::Transaction}; use std::{ collections::{HashMap, HashSet}, @@ -55,6 +56,12 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { .map(|commit| commit.slot) .max() .unwrap(); + // Safety we just obtained the max slot from the scheduled commits + let ephemereal_blockhash = scheduled_commits + .iter() + .find(|commit| commit.slot == max_slot) + .map(|commit| commit.blockhash) + .unwrap(); changeset.slot = max_slot; @@ -155,7 +162,7 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { } } - self.process_changeset(changeset, sent_commits); + self.process_changeset(changeset, sent_commits, ephemereal_blockhash); Ok(()) } @@ -198,6 +205,7 @@ impl RemoteScheduledCommitsProcessor { &self, changeset: Changeset, mut sent_commits: HashMap, + ephemeral_blockhash: Hash, ) { // We process the changeset on a separate task in order to not block // the validator (slot advance) itself @@ -208,6 +216,19 @@ impl RemoteScheduledCommitsProcessor { tokio::task::spawn(async move { // Create one sent commit transaction per bundle in our validator let changeset_metadata = ChangesetMeta::from(&changeset); + debug!( + "Committing changeset with {} accounts", + changeset_metadata.accounts.len() + ); + committor_service + .commit_changeset(changeset, ephemeral_blockhash, true) + .await + // TODO: @@@ + .unwrap(); + debug!( + "Committed changeset with {} accounts", + changeset_metadata.accounts.len() + ); for bundle_id in changeset_metadata .accounts .iter() From 5ce7a2030a1dfd6175678167abb17c0f0af3d473 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Mon, 12 May 2025 09:40:52 +0545 Subject: [PATCH 013/199] chore: update ix tests cargo --- test-integration/Cargo.lock | 213 ++++++++++++++++++++++++++++++------ test-integration/Cargo.toml | 7 +- 2 files changed, 182 insertions(+), 38 deletions(-) diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 141590f57..f479b90c0 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1122,6 +1122,7 @@ dependencies = [ [[package]] name = "conjunto-addresses" version = "0.0.0" +source = "git+https://github.com/magicblock-labs/conjunto.git?rev=bf82b45#bf82b453af9f0b25a81056378d6bcdf06ef53b53" dependencies = [ "paste", "solana-sdk", @@ -1130,6 +1131,7 @@ dependencies = [ [[package]] name = "conjunto-core" version = "0.0.0" +source = "git+https://github.com/magicblock-labs/conjunto.git?rev=bf82b45#bf82b453af9f0b25a81056378d6bcdf06ef53b53" dependencies = [ "async-trait", "serde", @@ -1141,13 +1143,14 @@ dependencies = [ [[package]] name = "conjunto-lockbox" version = "0.0.0" +source = "git+https://github.com/magicblock-labs/conjunto.git?rev=bf82b45#bf82b453af9f0b25a81056378d6bcdf06ef53b53" dependencies = [ "async-trait", "bytemuck", "conjunto-addresses", "conjunto-core", "conjunto-providers", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", "serde", "solana-rpc-client", "solana-rpc-client-api", @@ -1158,6 +1161,7 @@ dependencies = [ [[package]] name = "conjunto-providers" version = "0.0.0" +source = "git+https://github.com/magicblock-labs/conjunto.git?rev=bf82b45#bf82b453af9f0b25a81056378d6bcdf06ef53b53" dependencies = [ "async-trait", "conjunto-addresses", @@ -1172,6 +1176,7 @@ dependencies = [ [[package]] name = "conjunto-transwise" version = "0.0.0" +source = "git+https://github.com/magicblock-labs/conjunto.git?rev=bf82b45#bf82b453af9f0b25a81056378d6bcdf06ef53b53" dependencies = [ "async-trait", "conjunto-core", @@ -1741,28 +1746,29 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk" -version = "0.2.4" +version = "0.2.5" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=c1fcb91#c1fcb917504751ab513c471e4381321d7d40bb91" dependencies = [ "borsh 0.10.4", "ephemeral-rollups-sdk-attribute-commit", "ephemeral-rollups-sdk-attribute-delegate", "ephemeral-rollups-sdk-attribute-ephemeral", - "paste", "solana-program", ] [[package]] name = "ephemeral-rollups-sdk-attribute-commit" -version = "0.2.4" +version = "0.2.5" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=c1fcb91#c1fcb917504751ab513c471e4381321d7d40bb91" dependencies = [ - "proc-macro2", "quote", "syn 1.0.109", ] [[package]] name = "ephemeral-rollups-sdk-attribute-delegate" -version = "0.2.4" +version = "0.2.5" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=c1fcb91#c1fcb917504751ab513c471e4381321d7d40bb91" dependencies = [ "proc-macro2", "quote", @@ -1771,7 +1777,8 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-ephemeral" -version = "0.2.4" +version = "0.2.5" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=c1fcb91#c1fcb917504751ab513c471e4381321d7d40bb91" dependencies = [ "proc-macro2", "quote", @@ -1823,7 +1830,7 @@ dependencies = [ [[package]] name = "expiring-hashmap" -version = "0.1.0" +version = "0.1.1" [[package]] name = "fake-simd" @@ -1831,6 +1838,18 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + [[package]] name = "fast-math" version = "0.1.1" @@ -2159,7 +2178,7 @@ dependencies = [ [[package]] name = "geyser-grpc-proto" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "bincode", @@ -2319,6 +2338,15 @@ dependencies = [ "foldhash", ] +[[package]] +name = "hashlink" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +dependencies = [ + "hashbrown 0.15.2", +] + [[package]] name = "headers" version = "0.3.9" @@ -2906,8 +2934,10 @@ version = "0.0.0" dependencies = [ "anyhow", "borsh 1.5.7", + "log", "magicblock-config", "magicblock-core", + "magicblock-delegation-program 1.0.0", "rayon", "serde", "solana-rpc-client", @@ -3296,6 +3326,17 @@ dependencies = [ "libsecp256k1-core", ] +[[package]] +name = "libsqlite3-sys" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbb8270bb4060bd76c6e96f20c52d80620f1d82a3470885694e41e0f81ef6fe7" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "libz-sys" version = "1.1.22" @@ -3416,7 +3457,7 @@ dependencies = [ [[package]] name = "magicblock-account-cloner" -version = "0.1.0" +version = "0.1.1" dependencies = [ "conjunto-transwise", "futures-util", @@ -3425,6 +3466,7 @@ dependencies = [ "magicblock-account-fetcher", "magicblock-account-updates", "magicblock-accounts-api", + "magicblock-committor-service", "magicblock-core", "magicblock-metrics", "magicblock-mutator", @@ -3436,7 +3478,7 @@ dependencies = [ [[package]] name = "magicblock-account-dumper" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bincode", "magicblock-bank", @@ -3449,7 +3491,7 @@ dependencies = [ [[package]] name = "magicblock-account-fetcher" -version = "0.1.0" +version = "0.1.1" dependencies = [ "async-trait", "conjunto-transwise", @@ -3464,7 +3506,7 @@ dependencies = [ [[package]] name = "magicblock-account-updates" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bincode", "conjunto-transwise", @@ -3482,7 +3524,7 @@ dependencies = [ [[package]] name = "magicblock-accounts" -version = "0.1.0" +version = "0.1.1" dependencies = [ "async-trait", "conjunto-transwise", @@ -3494,8 +3536,9 @@ dependencies = [ "magicblock-account-updates", "magicblock-accounts-api", "magicblock-bank", + "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3511,7 +3554,7 @@ dependencies = [ [[package]] name = "magicblock-accounts-api" -version = "0.1.0" +version = "0.1.1" dependencies = [ "magicblock-bank", "solana-sdk", @@ -3519,7 +3562,7 @@ dependencies = [ [[package]] name = "magicblock-accounts-db" -version = "0.1.0" +version = "0.1.1" dependencies = [ "lmdb-rkv", "log", @@ -3535,7 +3578,7 @@ dependencies = [ [[package]] name = "magicblock-api" -version = "0.1.0" +version = "0.1.1" dependencies = [ "agave-geyser-plugin-interface", "anyhow", @@ -3555,6 +3598,7 @@ dependencies = [ "magicblock-accounts-api", "magicblock-accounts-db", "magicblock-bank", + "magicblock-committor-service", "magicblock-config", "magicblock-core", "magicblock-geyser-plugin", @@ -3580,7 +3624,7 @@ dependencies = [ [[package]] name = "magicblock-bank" -version = "0.1.0" +version = "0.1.1" dependencies = [ "agave-geyser-plugin-interface", "bincode", @@ -3613,9 +3657,47 @@ dependencies = [ "tempfile", ] +[[package]] +name = "magicblock-committor-program" +version = "0.0.0" +dependencies = [ + "borsh 1.5.7", + "borsh-derive 1.5.7", + "log", + "paste", + "solana-account", + "solana-program", + "solana-pubkey", + "thiserror 2.0.11", +] + +[[package]] +name = "magicblock-committor-service" +version = "0.0.0" +dependencies = [ + "base64 0.22.1", + "bincode", + "borsh 1.5.7", + "log", + "magicblock-committor-program", + "magicblock-delegation-program 1.0.0", + "magicblock-rpc-client", + "magicblock-table-mania", + "rusqlite", + "solana-account", + "solana-pubkey", + "solana-rpc-client", + "solana-rpc-client-api", + "solana-sdk", + "solana-transaction-status-client-types", + "thiserror 2.0.11", + "tokio", + "tokio-util 0.7.13", +] + [[package]] name = "magicblock-config" -version = "0.1.0" +version = "0.1.1" dependencies = [ "isocountry", "magicblock-accounts-db", @@ -3630,7 +3712,7 @@ dependencies = [ [[package]] name = "magicblock-core" -version = "0.1.0" +version = "0.1.1" dependencies = [ "solana-sdk", ] @@ -3650,9 +3732,25 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "magicblock-delegation-program" +version = "1.0.0" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c#4af7f1cefe0915f0760ed5c38b25b7d41c31a474" +dependencies = [ + "bincode", + "borsh 1.5.7", + "bytemuck", + "num_enum", + "paste", + "solana-curve25519", + "solana-program", + "solana-security-txt", + "thiserror 1.0.69", +] + [[package]] name = "magicblock-geyser-plugin" -version = "0.1.0" +version = "0.1.1" dependencies = [ "agave-geyser-plugin-interface", "anyhow", @@ -3679,7 +3777,7 @@ dependencies = [ [[package]] name = "magicblock-ledger" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bincode", "byteorder", @@ -3698,7 +3796,7 @@ dependencies = [ "solana-measure", "solana-metrics", "solana-sdk", - "solana-storage-proto 0.1.0", + "solana-storage-proto 0.1.1", "solana-svm", "solana-timings", "solana-transaction-status", @@ -3709,7 +3807,7 @@ dependencies = [ [[package]] name = "magicblock-metrics" -version = "0.1.0" +version = "0.1.1" dependencies = [ "http-body-util", "hyper 1.6.0", @@ -3723,7 +3821,7 @@ dependencies = [ [[package]] name = "magicblock-mutator" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bincode", "log", @@ -3736,7 +3834,7 @@ dependencies = [ [[package]] name = "magicblock-perf-service" -version = "0.1.0" +version = "0.1.1" dependencies = [ "log", "magicblock-bank", @@ -3745,7 +3843,7 @@ dependencies = [ [[package]] name = "magicblock-processor" -version = "0.1.0" +version = "0.1.1" dependencies = [ "lazy_static", "log", @@ -3766,7 +3864,7 @@ dependencies = [ [[package]] name = "magicblock-program" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bincode", "lazy_static", @@ -3783,7 +3881,7 @@ dependencies = [ [[package]] name = "magicblock-pubsub" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bincode", "geyser-grpc-proto", @@ -3805,7 +3903,7 @@ dependencies = [ [[package]] name = "magicblock-rpc" -version = "0.1.0" +version = "0.1.1" dependencies = [ "base64 0.21.7", "bincode", @@ -3838,9 +3936,38 @@ dependencies = [ "tokio", ] +[[package]] +name = "magicblock-rpc-client" +version = "0.0.0" +dependencies = [ + "log", + "solana-rpc-client", + "solana-rpc-client-api", + "solana-sdk", + "solana-transaction-status-client-types", + "thiserror 2.0.11", + "tokio", +] + +[[package]] +name = "magicblock-table-mania" +version = "0.0.0" +dependencies = [ + "ed25519-dalek", + "log", + "magicblock-rpc-client", + "sha3", + "solana-pubkey", + "solana-rpc-client", + "solana-rpc-client-api", + "solana-sdk", + "thiserror 2.0.11", + "tokio", +] + [[package]] name = "magicblock-tokens" -version = "0.1.0" +version = "0.1.1" dependencies = [ "log", "magicblock-bank", @@ -3855,7 +3982,7 @@ dependencies = [ [[package]] name = "magicblock-transaction-status" -version = "0.1.0" +version = "0.1.1" dependencies = [ "crossbeam-channel", "log", @@ -3867,7 +3994,7 @@ dependencies = [ [[package]] name = "magicblock-version" -version = "0.1.0" +version = "0.1.1" dependencies = [ "rustc_version", "semver", @@ -5314,6 +5441,20 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "rusqlite" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e34486da88d8e051c7c0e23c3f15fd806ea8546260aa2fec247e97242ec143" +dependencies = [ + "bitflags 2.8.0", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "smallvec", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -8590,7 +8731,7 @@ dependencies = [ [[package]] name = "solana-storage-proto" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bincode", "bs58 0.4.0", @@ -9957,7 +10098,7 @@ dependencies = [ [[package]] name = "test-tools-core" -version = "0.1.0" +version = "0.1.1" dependencies = [ "env_logger 0.11.6", "log", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index df1f0458a..7edd25794 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -28,10 +28,13 @@ ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-ro integration-test-tools = { path = "test-tools" } log = "0.4.20" magicblock-api = { path = "../magicblock-api" } -magicblock-accounts-db = { path = "../magicblock-accounts-db", features = [ "dev-tools" ] } -magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "eba7644", default-features = false} +magicblock-accounts-db = { path = "../magicblock-accounts-db", features = [ + "dev-tools", +] } +magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "eba7644", default-features = false } magicblock-config = { path = "../magicblock-config" } magicblock-core = { path = "../magicblock-core" } +magicblock-delegation-program = { path = "../../delegation-program" } program-flexi-counter = { path = "./programs/flexi-counter" } program-schedulecommit = { path = "programs/schedulecommit" } program-schedulecommit-security = { path = "programs/schedulecommit-security" } From b54cd3b2dbd08cfa5ec2aa6948260d9c289ec575 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Mon, 12 May 2025 09:41:53 +0545 Subject: [PATCH 014/199] chore: comment with requirements for schedule commit tests --- .../schedulecommit/test-scenarios/tests/01_commits.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs b/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs index 8264bde12..46533b1f2 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs @@ -18,6 +18,15 @@ use utils::{ }; mod utils; +// NOTE: This and all other schedule commit tests depend on the following accounts +// loaded in the mainnet cluster, i.e. the solana-test-validator: +// +// validator: tEsT3eV6RFCWs1BZ7AXTzasHqTtMnMLCB2tjQ42TDXD +// protocol fees vault: 7JrkjmZPprHwtuvtuGTXp9hwfGYFAQLnLeFM52kqAgXg +// validator fees vault: DUH8h7rYjdTPYyBUEGAUwZv9ffz5wiM45GdYWYzogXjp +// delegation program: DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh +// committor program: corabpNrkBEqbTZP7xfJgSWTdBmVdLf1PARWXZbcMcS + #[test] fn test_committing_one_account() { run_test!({ From dc2da585e3d52b2a4147da28ffb605d542bf4b29 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Tue, 13 May 2025 13:31:04 +0545 Subject: [PATCH 015/199] chore: improve test logs --- .../schedulecommit/test-scenarios/tests/utils/mod.rs | 5 +++-- test-integration/test-tools/Cargo.toml | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs index a807dd65b..14833eacd 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs @@ -215,9 +215,10 @@ pub fn assert_account_was_undelegated_on_chain( let owner = ctx.fetch_chain_account_owner(pda).unwrap(); assert_ne!( owner, DELEGATION_PROGRAM_ID, - "not owned by delegation program" + "{} not owned by delegation program", + pda ); - assert_eq!(owner, new_owner, "new owner"); + assert_eq!(owner, new_owner, "{} has new owner", pda); } #[allow(dead_code)] // used in 02_commit_and_undelegate.rs diff --git a/test-integration/test-tools/Cargo.toml b/test-integration/test-tools/Cargo.toml index 1fbaa830d..50c3719ac 100644 --- a/test-integration/test-tools/Cargo.toml +++ b/test-integration/test-tools/Cargo.toml @@ -6,6 +6,7 @@ edition.workspace = true [dependencies] anyhow = { workspace = true } borsh = { workspace = true } +log = { workspace = true } rayon = { workspace = true } serde = { workspace = true } magicblock-core = { workspace = true } From 560fd6b78b7dde9c5ce6f4380a4adeea73356686 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Tue, 13 May 2025 19:51:31 +0545 Subject: [PATCH 016/199] chore: include compute unit price when initializing committor --- magicblock-api/src/magic_validator.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 7c02063e0..1bd6e42a8 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -38,7 +38,9 @@ use magicblock_bank::{ program_loader::load_programs_into_bank, transaction_logs::TransactionLogCollectorFilter, }; -use magicblock_committor_service::{config::ChainConfig, CommittorService}; +use magicblock_committor_service::{ + config::ChainConfig, CommittorService, ComputeBudgetConfig, +}; use magicblock_config::{EphemeralConfig, LifecycleMode, ProgramConfig}; use magicblock_geyser_plugin::rpc::GeyserRpcService; use magicblock_ledger::{ @@ -311,11 +313,14 @@ impl MagicValidator { identity_keypair.insecure_clone(), // TODO: @@@ config or inside ledger dir "/tmp/committor_service.sqlite", - &ChainConfig { + ChainConfig { rpc_uri: remote_rpc_config.url().to_string(), commitment: remote_rpc_config .commitment() .unwrap_or(CommitmentLevel::Confirmed), + compute_budget_config: ComputeBudgetConfig::new( + accounts_config.commit_compute_unit_price, + ), }, )?); From b3445c13f01f6e78096d7b0451bbaecc6306ea50 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Tue, 13 May 2025 19:52:19 +0545 Subject: [PATCH 017/199] fix: mark accounts to be undelegated --- magicblock-accounts/src/remote_scheduled_commits_processor.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index c47bf8ba1..44d1cd5fe 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -159,6 +159,9 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { bundle_id, }, ); + if committee.undelegation_requested { + changeset.request_undelegation(committee.pubkey); + } } } From 24bb27aee9999f852af18d0cf9cf01fba4f90df1 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 14 May 2025 09:58:01 +0545 Subject: [PATCH 018/199] chore: properly handle some unwraps --- .../src/remote_scheduled_commits_processor.rs | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 44d1cd5fe..f2102e28e 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -131,7 +131,9 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { // Collect all SentCommit info available at this stage // We add the chain_signatures after we sent off the changeset let sent_commit = SentCommit { + chain_signatures: vec![], commit_id: commit.id, + slot: commit.slot, payer: commit.payer, blockhash: commit.blockhash, included_pubkeys: committees @@ -141,7 +143,6 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { excluded_pubkeys, feepayers, requested_undelegation: commit.request_undelegation, - ..Default::default() }; sent_commits.insert( commit.id, @@ -223,28 +224,51 @@ impl RemoteScheduledCommitsProcessor { "Committing changeset with {} accounts", changeset_metadata.accounts.len() ); - committor_service + match committor_service .commit_changeset(changeset, ephemeral_blockhash, true) .await - // TODO: @@@ - .unwrap(); - debug!( - "Committed changeset with {} accounts", - changeset_metadata.accounts.len() - ); + { + Ok(Some(reqid)) => { + debug!( + "Committed changeset with {} accounts via reqid {}", + changeset_metadata.accounts.len(), + reqid + ); + } + Ok(None) => { + debug!( + "Committed changeset with {} accounts, but did not get a reqid", + changeset_metadata.accounts.len() + ); + } + Err(err) => { + error!( + "Tried to commit changeset with {} accounts but failed to send request ({:#?})", + changeset_metadata.accounts.len(),err + ); + } + } for bundle_id in changeset_metadata .accounts .iter() .map(|account| account.bundle_id) .collect::>() { - match committor_service + let bundle_signatures = match committor_service .get_bundle_signatures(bundle_id) .await - // TODO: @@@ - .unwrap() - .unwrap() { + Ok(Ok(sig)) => sig, + Ok(Err(err)) => { + error!("Encountered error while getting bundle signatures for {}: {:?}", bundle_id, err); + continue; + } + Err(err) => { + error!("Encountered error while getting bundle signatures for {}: {:?}", bundle_id, err); + continue; + } + }; + match bundle_signatures { Some(BundleSignatureRow { processed_signature, finalized_signature, From cc389e78ddb2f9a1b02bfe0f044024d0caeaa504 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 14 May 2025 10:08:23 +0545 Subject: [PATCH 019/199] test: general improvements + fixes - at this point schedule commit tests pass with maximum concurrency --- .../test-scenarios/tests/03_commits_fee_payer.rs | 2 +- .../test-scenarios/tests/utils/mod.rs | 9 ++++++++- .../test-tools/src/integration_test_context.rs | 14 ++++++++------ .../test-tools/src/scheduled_commits.rs | 6 +++--- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs b/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs index 2325584eb..f04c8bd71 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs @@ -125,6 +125,6 @@ fn test_committing_fee_payer_escrowing_lamports() { assert_two_committees_synchronized_count(&ctx, &res, 1); // The fee payer should have been committed - assert_feepayer_was_committed(&ctx, &res); + assert_feepayer_was_committed(&ctx, &res, true); }); } diff --git a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs index 14833eacd..13ac51715 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs @@ -101,6 +101,7 @@ pub fn assert_two_committees_were_committed( pub fn assert_feepayer_was_committed( ctx: &ScheduleCommitTestContext, res: &ScheduledCommitResult, + finalize: bool, ) { let payer = ctx.payer.pubkey(); @@ -109,7 +110,13 @@ pub fn assert_feepayer_was_committed( let commit_payer = res.feepayers.iter().find(|(p, _)| p == &payer); assert!(commit_payer.is_some(), "should have committed payer"); - assert_eq!(res.sigs.len(), 1, "should have 1 on chain sig"); + let sig_len = if finalize { 2 } else { 1 }; + assert_eq!( + res.sigs.len(), + sig_len, + "should have {} on chain sig", + sig_len + ); } #[allow(dead_code)] // used in 02_commit_and_undelegate.rs diff --git a/test-integration/test-tools/src/integration_test_context.rs b/test-integration/test-tools/src/integration_test_context.rs index 22245254b..4afd9ccc8 100644 --- a/test-integration/test-tools/src/integration_test_context.rs +++ b/test-integration/test-tools/src/integration_test_context.rs @@ -131,9 +131,9 @@ impl IntegrationTestContext { ) -> Option> { let rpc_client = rpc_client.or(self.chain_client.as_ref())?; - // Try this up to 10 times since devnet here returns the version response instead of + // Try this up to 50 times since devnet here returns the version response instead of // the EncodedConfirmedTransactionWithStatusMeta at times - for _ in 0..10 { + for idx in 1..=50 { let status = match rpc_client.get_transaction_with_config( &sig, RpcTransactionConfig { @@ -143,10 +143,12 @@ impl IntegrationTestContext { ) { Ok(status) => status, Err(err) => { - warn!( - "Failed to fetch transaction from {}: {:?}", - label, err - ); + if idx % 10 == 0 { + warn!( + "Failed to fetch transaction from {}: {:?}", + label, err + ); + } sleep(Duration::from_millis(400)); continue; } diff --git a/test-integration/test-tools/src/scheduled_commits.rs b/test-integration/test-tools/src/scheduled_commits.rs index 5f9e723b3..e4c11ef3e 100644 --- a/test-integration/test-tools/src/scheduled_commits.rs +++ b/test-integration/test-tools/src/scheduled_commits.rs @@ -214,9 +214,9 @@ impl IntegrationTestContext { let ephem_account = T::try_from_slice(&ephem_data) .with_context(|| { format!( - "Failed to deserialize ephemeral account data for {:?}", - pubkey - ) + "Failed to deserialize ephemeral account data for {:?}", + pubkey + ) })?; committed_accounts.insert(pubkey, ephem_account); }; From f7304cf59ede839a791556a22f935ca47dc5d6ef Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 14 May 2025 11:02:56 +0545 Subject: [PATCH 020/199] chore: use trait for committor service and create stub to use in tests --- magicblock-account-cloner/Cargo.toml | 1 + .../src/remote_account_cloner_client.rs | 6 ++- .../src/remote_account_cloner_worker.rs | 15 +++--- magicblock-accounts/src/accounts_manager.rs | 3 -- .../src/external_accounts_manager.rs | 8 +++- .../src/remote_scheduled_commits_processor.rs | 30 +++++++----- magicblock-accounts/src/traits.rs | 6 ++- .../tests/stubs/changeset_committor_stub.rs | 47 +++++++++++++++++++ magicblock-accounts/tests/stubs/mod.rs | 1 + .../stubs/scheduled_commits_processor_stub.rs | 6 ++- magicblock-api/src/magic_validator.rs | 5 +- magicblock-api/src/tickers.rs | 8 +++- 12 files changed, 103 insertions(+), 33 deletions(-) create mode 100644 magicblock-accounts/tests/stubs/changeset_committor_stub.rs diff --git a/magicblock-account-cloner/Cargo.toml b/magicblock-account-cloner/Cargo.toml index c6767cc03..5bfc72ea2 100644 --- a/magicblock-account-cloner/Cargo.toml +++ b/magicblock-account-cloner/Cargo.toml @@ -16,6 +16,7 @@ magicblock-account-updates = { workspace = true } magicblock-account-dumper = { workspace = true } magicblock-accounts-api = { workspace = true } magicblock-core = { workspace = true } +magicblock-committor-service = { workspace = true } magicblock-metrics = { workspace = true } magicblock-mutator = { workspace = true } solana-sdk = { workspace = true } diff --git a/magicblock-account-cloner/src/remote_account_cloner_client.rs b/magicblock-account-cloner/src/remote_account_cloner_client.rs index 76f9f893c..d3070022b 100644 --- a/magicblock-account-cloner/src/remote_account_cloner_client.rs +++ b/magicblock-account-cloner/src/remote_account_cloner_client.rs @@ -11,6 +11,7 @@ use magicblock_account_dumper::AccountDumper; use magicblock_account_fetcher::AccountFetcher; use magicblock_account_updates::AccountUpdates; use magicblock_accounts_api::InternalAccountProvider; +use magicblock_committor_service::ChangesetCommittor; use solana_sdk::pubkey::Pubkey; use tokio::sync::{mpsc::UnboundedSender, oneshot::channel}; @@ -25,14 +26,15 @@ pub struct RemoteAccountClonerClient { } impl RemoteAccountClonerClient { - pub fn new( - worker: &RemoteAccountClonerWorker, + pub fn new( + worker: &RemoteAccountClonerWorker, ) -> Self where IAP: InternalAccountProvider, AFE: AccountFetcher, AUP: AccountUpdates, ADU: AccountDumper, + CC: ChangesetCommittor, { Self { clone_request_sender: worker.get_clone_request_sender(), diff --git a/magicblock-account-cloner/src/remote_account_cloner_worker.rs b/magicblock-account-cloner/src/remote_account_cloner_worker.rs index 094de1bbe..90e1d4adf 100644 --- a/magicblock-account-cloner/src/remote_account_cloner_worker.rs +++ b/magicblock-account-cloner/src/remote_account_cloner_worker.rs @@ -18,7 +18,7 @@ use magicblock_account_dumper::AccountDumper; use magicblock_account_fetcher::AccountFetcher; use magicblock_account_updates::AccountUpdates; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::CommittorService; +use magicblock_committor_service::ChangesetCommittor; use magicblock_metrics::metrics; use magicblock_mutator::idl::{get_pubkey_anchor_idl, get_pubkey_shank_idl}; use solana_sdk::{ @@ -95,12 +95,12 @@ impl ValidatorStage { } } -pub struct RemoteAccountClonerWorker { +pub struct RemoteAccountClonerWorker { internal_account_provider: IAP, account_fetcher: AFE, account_updates: AUP, account_dumper: ADU, - committer_service: Arc, + changeset_committor: Arc, allowed_program_ids: Option>, blacklisted_accounts: HashSet, payer_init_lamports: Option, @@ -114,12 +114,13 @@ pub struct RemoteAccountClonerWorker { validator_identity: Pubkey, } -impl RemoteAccountClonerWorker +impl RemoteAccountClonerWorker where IAP: InternalAccountProvider, AFE: AccountFetcher, AUP: AccountUpdates, ADU: AccountDumper, + CC: ChangesetCommittor, { #[allow(clippy::too_many_arguments)] pub fn new( @@ -127,7 +128,7 @@ where account_fetcher: AFE, account_updates: AUP, account_dumper: ADU, - committer_service: Arc, + changeset_committor: Arc, allowed_program_ids: Option>, blacklisted_accounts: HashSet, payer_init_lamports: Option, @@ -143,8 +144,8 @@ where account_fetcher, account_updates, account_dumper, + changeset_committor, allowed_program_ids, - committer_service, blacklisted_accounts, payer_init_lamports, validator_charges_fees, @@ -657,7 +658,7 @@ where // Allow the committer service to reserve pubkeys in lookup tables // that could be needed when we commit this account map_committor_request_result( - self.committer_service.reserve_pubkeys_for_committee( + self.changeset_committor.reserve_pubkeys_for_committee( *pubkey, delegation_record.owner, ), diff --git a/magicblock-accounts/src/accounts_manager.rs b/magicblock-accounts/src/accounts_manager.rs index f1728fe8c..90957e98f 100644 --- a/magicblock-accounts/src/accounts_manager.rs +++ b/magicblock-accounts/src/accounts_manager.rs @@ -7,7 +7,6 @@ use conjunto_transwise::{ use magicblock_account_cloner::{CloneOutputMap, RemoteAccountClonerClient}; use magicblock_accounts_api::BankAccountProvider; use magicblock_bank::bank::Bank; -use magicblock_committor_service::CommittorService; use magicblock_transaction_status::TransactionStatusSender; use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair}; @@ -30,7 +29,6 @@ pub type AccountsManager = ExternalAccountsManager< impl AccountsManager { pub fn try_new( - committer_service: Arc, bank: &Arc, cloned_accounts: &CloneOutputMap, remote_account_cloner_client: RemoteAccountClonerClient, @@ -52,7 +50,6 @@ impl AccountsManager { ); let scheduled_commits_processor = RemoteScheduledCommitsProcessor::new( - committer_service, bank.clone(), cloned_accounts.clone(), transaction_status_sender.clone(), diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index ef47f9c50..6b09bf8c8 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -16,6 +16,7 @@ use futures_util::future::{try_join, try_join_all}; use log::*; use magicblock_account_cloner::{AccountCloner, AccountClonerOutput}; use magicblock_accounts_api::InternalAccountProvider; +use magicblock_committor_service::ChangesetCommittor; use magicblock_core::magic_program; use solana_sdk::{ account::{AccountSharedData, ReadableAccount}, @@ -402,9 +403,12 @@ where .map(|x| x.last_committed_at()) } - pub async fn process_scheduled_commits(&self) -> AccountsResult<()> { + pub async fn process_scheduled_commits( + &self, + changeset_committor: &Arc, + ) -> AccountsResult<()> { self.scheduled_commits_processor - .process(&self.internal_account_provider) + .process(&self.internal_account_provider, changeset_committor) .await } diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index f2102e28e..002a44d42 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -16,8 +16,8 @@ use magicblock_account_cloner::{ }; use magicblock_accounts_api::InternalAccountProvider; use magicblock_committor_service::{ - persist::BundleSignatureRow, ChangedAccount, Changeset, ChangesetMeta, - CommittorService, + persist::BundleSignatureRow, ChangedAccount, Changeset, ChangesetCommittor, + ChangesetMeta, }; use magicblock_program::{ register_scheduled_commit_sent, FeePayerAccount, Pubkey, SentCommit, @@ -29,7 +29,6 @@ use crate::{ }; pub struct RemoteScheduledCommitsProcessor { - committor_service: Arc, transaction_scheduler: TransactionScheduler, cloned_accounts: CloneOutputMap, bank: Arc, @@ -38,9 +37,14 @@ pub struct RemoteScheduledCommitsProcessor { #[async_trait] impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { - async fn process(&self, account_provider: &IAP) -> AccountsResult<()> + async fn process( + &self, + account_provider: &IAP, + changeset_committor: &Arc, + ) -> AccountsResult<()> where IAP: InternalAccountProvider, + CC: ChangesetCommittor, { let scheduled_commits = self.transaction_scheduler.take_scheduled_commits(); @@ -166,7 +170,12 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { } } - self.process_changeset(changeset, sent_commits, ephemereal_blockhash); + self.process_changeset( + changeset_committor, + changeset, + sent_commits, + ephemereal_blockhash, + ); Ok(()) } @@ -182,13 +191,11 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { impl RemoteScheduledCommitsProcessor { pub fn new( - committer_service: Arc, bank: Arc, cloned_accounts: CloneOutputMap, transaction_status_sender: Option, ) -> Self { Self { - committor_service: committer_service, bank, transaction_status_sender, cloned_accounts, @@ -205,15 +212,16 @@ impl RemoteScheduledCommitsProcessor { .get(pubkey).cloned() } - fn process_changeset( + fn process_changeset( &self, + changeset_committor: &Arc, changeset: Changeset, mut sent_commits: HashMap, ephemeral_blockhash: Hash, ) { // We process the changeset on a separate task in order to not block // the validator (slot advance) itself - let committor_service = self.committor_service.clone(); + let changeset_committor = changeset_committor.clone(); let bank = self.bank.clone(); let transaction_status_sender = self.transaction_status_sender.clone(); @@ -224,7 +232,7 @@ impl RemoteScheduledCommitsProcessor { "Committing changeset with {} accounts", changeset_metadata.accounts.len() ); - match committor_service + match changeset_committor .commit_changeset(changeset, ephemeral_blockhash, true) .await { @@ -254,7 +262,7 @@ impl RemoteScheduledCommitsProcessor { .map(|account| account.bundle_id) .collect::>() { - let bundle_signatures = match committor_service + let bundle_signatures = match changeset_committor .get_bundle_signatures(bundle_id) .await { diff --git a/magicblock-accounts/src/traits.rs b/magicblock-accounts/src/traits.rs index 34808bc1f..94699bf37 100644 --- a/magicblock-accounts/src/traits.rs +++ b/magicblock-accounts/src/traits.rs @@ -1,7 +1,8 @@ -use std::collections::HashSet; +use std::{collections::HashSet, sync::Arc}; use async_trait::async_trait; use magicblock_accounts_api::InternalAccountProvider; +use magicblock_committor_service::ChangesetCommittor; use magicblock_metrics::metrics::HistogramTimer; use solana_rpc_client::rpc_client::SerializableTransaction; use solana_sdk::{ @@ -14,9 +15,10 @@ use crate::errors::AccountsResult; #[async_trait] pub trait ScheduledCommitsProcessor { /// Processes all commits that were scheduled and accepted - async fn process( + async fn process( &self, account_provider: &IAP, + changeset_committor: &Arc, ) -> AccountsResult<()>; /// Returns the number of commits that were scheduled and accepted diff --git a/magicblock-accounts/tests/stubs/changeset_committor_stub.rs b/magicblock-accounts/tests/stubs/changeset_committor_stub.rs new file mode 100644 index 000000000..e6752c9d1 --- /dev/null +++ b/magicblock-accounts/tests/stubs/changeset_committor_stub.rs @@ -0,0 +1,47 @@ +use magicblock_committor_service::ChangesetCommittor; + +#[derive(Default)] +pub struct ChangesetCommittorStub {} + +impl ChangesetCommittor for ChangesetCommittorStub { + fn commit_changeset( + &self, + _changeset: magicblock_committor_service::Changeset, + _ephemeral_blockhash: solana_sdk::hash::Hash, + _finalize: bool, + ) -> tokio::sync::oneshot::Receiver> { + unimplemented!("Not called during tests") + } + + fn get_commit_statuses( + &self, + _reqid: String, + ) -> tokio::sync::oneshot::Receiver< + magicblock_committor_service::error::CommittorServiceResult< + Vec, + >, + > { + unimplemented!("Not called during tests") + } + + fn get_bundle_signatures( + &self, + _bundle_id: u64, + ) -> tokio::sync::oneshot::Receiver< + magicblock_committor_service::error::CommittorServiceResult< + Option, + >, + > { + unimplemented!("Not called during tests") + } + + fn reserve_pubkeys_for_committee( + &self, + _committee: magicblock_program::Pubkey, + _owner: magicblock_program::Pubkey, + ) -> tokio::sync::oneshot::Receiver< + magicblock_committor_service::error::CommittorServiceResult<()>, + > { + unimplemented!("Not called during tests") + } +} diff --git a/magicblock-accounts/tests/stubs/mod.rs b/magicblock-accounts/tests/stubs/mod.rs index 5d245cb19..797bab0b3 100644 --- a/magicblock-accounts/tests/stubs/mod.rs +++ b/magicblock-accounts/tests/stubs/mod.rs @@ -1,2 +1,3 @@ pub mod account_committer_stub; +pub mod changeset_committor_stub; pub mod scheduled_commits_processor_stub; diff --git a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs index abce96809..9fe51cb37 100644 --- a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs +++ b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs @@ -1,15 +1,19 @@ +use std::sync::Arc; + use async_trait::async_trait; use magicblock_accounts::{errors::AccountsResult, ScheduledCommitsProcessor}; use magicblock_accounts_api::InternalAccountProvider; +use magicblock_committor_service::ChangesetCommittor; #[derive(Default)] pub struct ScheduledCommitsProcessorStub {} #[async_trait] impl ScheduledCommitsProcessor for ScheduledCommitsProcessorStub { - async fn process( + async fn process( &self, _account_provider: &IAP, + _changeset_committor: &Arc, ) -> AccountsResult<()> { Ok(()) } diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 1bd6e42a8..f308a4baa 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -152,6 +152,7 @@ pub struct MagicValidator { RemoteAccountFetcherClient, RemoteAccountUpdatesClient, AccountDumperBank, + CommittorService, >, >, remote_account_cloner_handle: Option>, @@ -343,7 +344,6 @@ impl MagicValidator { ); let accounts_manager = Self::init_accounts_manager( - committor_service.clone(), &bank, &remote_account_cloner_worker.get_last_clone_output(), RemoteAccountClonerClient::new(&remote_account_cloner_worker), @@ -434,7 +434,6 @@ impl MagicValidator { } fn init_accounts_manager( - committer_service: Arc, bank: &Arc, cloned_accounts: &CloneOutputMap, remote_account_cloner_client: RemoteAccountClonerClient, @@ -447,7 +446,6 @@ impl MagicValidator { "Failed to derive accounts config from provided magicblock config", ); let accounts_manager = AccountsManager::try_new( - committer_service, bank, cloned_accounts, remote_account_cloner_client, @@ -708,6 +706,7 @@ impl MagicValidator { self.slot_ticker = Some(init_slot_ticker( &self.bank, &self.accounts_manager, + &self.committor_service, Some(self.transaction_status_sender.clone()), self.ledger.clone(), Duration::from_millis(self.config.validator.millis_per_slot), diff --git a/magicblock-api/src/tickers.rs b/magicblock-api/src/tickers.rs index 3dd9e6902..51a5f6299 100644 --- a/magicblock-api/src/tickers.rs +++ b/magicblock-api/src/tickers.rs @@ -9,6 +9,7 @@ use std::{ use log::*; use magicblock_accounts::AccountsManager; use magicblock_bank::bank::Bank; +use magicblock_committor_service::CommittorService; use magicblock_core::magic_program; use magicblock_ledger::Ledger; use magicblock_metrics::metrics; @@ -25,6 +26,7 @@ use crate::slot::advance_slot_and_update_ledger; pub fn init_slot_ticker( bank: &Arc, accounts_manager: &Arc, + committor_service: &Arc, transaction_status_sender: Option, ledger: Arc, tick_duration: Duration, @@ -32,6 +34,7 @@ pub fn init_slot_ticker( ) -> tokio::task::JoinHandle<()> { let bank = bank.clone(); let accounts_manager = accounts_manager.clone(); + let committor_service = committor_service.clone(); let log = tick_duration >= Duration::from_secs(5); tokio::task::spawn(async move { while !exit.load(Ordering::Relaxed) { @@ -62,8 +65,9 @@ pub fn init_slot_ticker( // 2. Process those scheduled commits // TODO: fix the possible delay here // https://github.com/magicblock-labs/magicblock-validator/issues/104 - if let Err(err) = - accounts_manager.process_scheduled_commits().await + if let Err(err) = accounts_manager + .process_scheduled_commits(&committor_service) + .await { error!( "Failed to process scheduled commits: {:?}", From 04b01163c842d871833ed822f439e162b79a06d9 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 14 May 2025 12:03:07 +0545 Subject: [PATCH 021/199] chore: update ensure accounts tests to use stub --- magicblock-accounts/tests/ensure_accounts.rs | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/magicblock-accounts/tests/ensure_accounts.rs b/magicblock-accounts/tests/ensure_accounts.rs index ee9526d3c..cd13be55d 100644 --- a/magicblock-accounts/tests/ensure_accounts.rs +++ b/magicblock-accounts/tests/ensure_accounts.rs @@ -19,6 +19,7 @@ use magicblock_accounts_api::InternalAccountProviderStub; use solana_sdk::pubkey::Pubkey; use stubs::{ account_committer_stub::AccountCommitterStub, + changeset_committor_stub::ChangesetCommittorStub, scheduled_commits_processor_stub::ScheduledCommitsProcessorStub, }; use test_tools_core::init_logger; @@ -41,6 +42,7 @@ fn setup_with_lifecycle( account_fetcher: AccountFetcherStub, account_updates: AccountUpdatesStub, account_dumper: AccountDumperStub, + changeset_committor_stub: Arc, lifecycle: LifecycleMode, ) -> (StubbedAccountsManager, CancellationToken, JoinHandle<()>) { let cancellation_token = CancellationToken::new(); @@ -50,6 +52,7 @@ fn setup_with_lifecycle( account_fetcher, account_updates, account_dumper, + changeset_committor_stub, None, HashSet::new(), Some(1_000_000_000), @@ -90,12 +93,14 @@ fn setup_ephem( account_fetcher: AccountFetcherStub, account_updates: AccountUpdatesStub, account_dumper: AccountDumperStub, + changeset_committor_stub: Arc, ) -> (StubbedAccountsManager, CancellationToken, JoinHandle<()>) { setup_with_lifecycle( internal_account_provider, account_fetcher, account_updates, account_dumper, + changeset_committor_stub, LifecycleMode::Ephemeral, ) } @@ -108,12 +113,14 @@ async fn test_ensure_readonly_account_not_tracked_nor_in_our_validator() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // Account should be fetchable but not delegated @@ -152,12 +159,14 @@ async fn test_ensure_readonly_account_not_tracked_but_in_our_validator() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // Account should be already in the bank @@ -194,12 +203,14 @@ async fn test_ensure_readonly_account_cloned_but_not_in_our_validator() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // Pre-clone the account @@ -246,12 +257,14 @@ async fn test_ensure_readonly_account_cloned_but_has_been_updated_on_chain() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // Pre-clone account @@ -304,12 +317,14 @@ async fn test_ensure_readonly_account_cloned_and_no_recent_update_on_chain() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // Pre-clone the account @@ -359,12 +374,14 @@ async fn test_ensure_readonly_account_in_our_validator_and_unseen_writable() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // One already loaded, and one properly delegated @@ -407,6 +424,7 @@ async fn test_ensure_one_delegated_and_one_feepayer_account_writable() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); // Note: since we use a writable new account, we need to allow it as part of the configuration // We can't use an ephemeral's configuration, that forbids new accounts to be writable @@ -415,6 +433,7 @@ async fn test_ensure_one_delegated_and_one_feepayer_account_writable() { account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), LifecycleMode::Replica, ); @@ -459,12 +478,14 @@ async fn test_ensure_multiple_accounts_coming_in_over_time() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // Multiple delegated and undelegated accounts fetchable @@ -606,12 +627,14 @@ async fn test_ensure_accounts_seen_as_readonly_can_be_used_as_writable_later() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // A delegated account @@ -698,12 +721,14 @@ async fn test_ensure_accounts_already_known_can_be_reused_as_writable_later() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // Account already loaded in the bank, but is a delegated on-chain @@ -770,12 +795,14 @@ async fn test_ensure_accounts_already_ensured_needs_reclone_after_updates() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // Pre-clone account @@ -855,12 +882,14 @@ async fn test_ensure_accounts_already_cloned_can_be_reused_without_updates() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor_stub = Arc::new(ChangesetCommittorStub::default()); let (manager, cancel, handle) = setup_ephem( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor_stub.clone(), ); // Pre-clone the account From d770b950d12fee66c6c9a5252bdd2ea1691883bf Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 14 May 2025 16:53:12 +0545 Subject: [PATCH 022/199] chore: re-enable account cloner and ensure accounts tests --- Cargo.lock | 3 + magicblock-account-cloner/Cargo.toml | 3 + .../tests/remote_account_cloner.rs | 55 ++++++++++++++++++- magicblock-accounts/Cargo.toml | 3 + magicblock-accounts/tests/ensure_accounts.rs | 6 +- .../tests/stubs/changeset_committor_stub.rs | 47 ---------------- magicblock-accounts/tests/stubs/mod.rs | 1 - 7 files changed, 67 insertions(+), 51 deletions(-) delete mode 100644 magicblock-accounts/tests/stubs/changeset_committor_stub.rs diff --git a/Cargo.lock b/Cargo.lock index d4cae3237..4d7ca7f95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3529,6 +3529,7 @@ dependencies = [ "magicblock-account-fetcher", "magicblock-account-updates", "magicblock-accounts-api", + "magicblock-committor-service", "magicblock-core", "magicblock-metrics", "magicblock-mutator", @@ -3763,6 +3764,7 @@ dependencies = [ "solana-rpc-client-api", "solana-sdk", "solana-transaction-status-client-types", + "static_assertions", "thiserror 2.0.12", "tokio", "tokio-util 0.7.13", @@ -4040,6 +4042,7 @@ dependencies = [ "ed25519-dalek", "log", "magicblock-rpc-client", + "rand 0.8.5", "sha3", "solana-pubkey", "solana-rpc-client", diff --git a/magicblock-account-cloner/Cargo.toml b/magicblock-account-cloner/Cargo.toml index 5bfc72ea2..d412aa0fe 100644 --- a/magicblock-account-cloner/Cargo.toml +++ b/magicblock-account-cloner/Cargo.toml @@ -25,3 +25,6 @@ tokio-util = { workspace = true } thiserror = { workspace = true } [dev-dependencies] +magicblock-committor-service = { workspace = true, features = [ + "dev-context-only-utils", +] } diff --git a/magicblock-account-cloner/tests/remote_account_cloner.rs b/magicblock-account-cloner/tests/remote_account_cloner.rs index a8cab3d7b..f266683de 100644 --- a/magicblock-account-cloner/tests/remote_account_cloner.rs +++ b/magicblock-account-cloner/tests/remote_account_cloner.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::{collections::HashSet, sync::Arc}; use magicblock_account_cloner::{ standard_blacklisted_accounts, AccountCloner, AccountClonerError, @@ -10,6 +10,7 @@ use magicblock_account_dumper::AccountDumperStub; use magicblock_account_fetcher::AccountFetcherStub; use magicblock_account_updates::AccountUpdatesStub; use magicblock_accounts_api::InternalAccountProviderStub; +use magicblock_committor_service::stubs::ChangesetCommittorStub; use magicblock_mutator::idl::{get_pubkey_anchor_idl, get_pubkey_shank_idl}; use solana_sdk::{ bpf_loader_upgradeable::get_program_data_address, @@ -26,6 +27,7 @@ fn setup_custom( account_fetcher: AccountFetcherStub, account_updates: AccountUpdatesStub, account_dumper: AccountDumperStub, + changeset_committor: Arc, allowed_program_ids: Option>, blacklisted_accounts: HashSet, permissions: AccountClonerPermissions, @@ -42,6 +44,7 @@ fn setup_custom( account_fetcher, account_updates, account_dumper, + changeset_committor, allowed_program_ids, blacklisted_accounts, payer_init_lamports, @@ -69,6 +72,7 @@ fn setup_replica( account_fetcher: AccountFetcherStub, account_updates: AccountUpdatesStub, account_dumper: AccountDumperStub, + changeset_committor: Arc, allowed_program_ids: Option>, ) -> ( RemoteAccountClonerClient, @@ -80,6 +84,7 @@ fn setup_replica( account_fetcher, account_updates, account_dumper, + changeset_committor, allowed_program_ids, standard_blacklisted_accounts( &Pubkey::new_unique(), @@ -100,6 +105,7 @@ fn setup_programs_replica( account_fetcher: AccountFetcherStub, account_updates: AccountUpdatesStub, account_dumper: AccountDumperStub, + changeset_committor: Arc, allowed_program_ids: Option>, ) -> ( RemoteAccountClonerClient, @@ -111,6 +117,7 @@ fn setup_programs_replica( account_fetcher, account_updates, account_dumper, + changeset_committor, allowed_program_ids, standard_blacklisted_accounts( &Pubkey::new_unique(), @@ -131,6 +138,7 @@ fn setup_ephemeral( account_fetcher: AccountFetcherStub, account_updates: AccountUpdatesStub, account_dumper: AccountDumperStub, + changeset_committor: Arc, allowed_program_ids: Option>, ) -> ( RemoteAccountClonerClient, @@ -142,6 +150,7 @@ fn setup_ephemeral( account_fetcher, account_updates, account_dumper, + changeset_committor, allowed_program_ids, standard_blacklisted_accounts( &Pubkey::new_unique(), @@ -162,6 +171,7 @@ fn setup_offline( account_fetcher: AccountFetcherStub, account_updates: AccountUpdatesStub, account_dumper: AccountDumperStub, + changeset_committor: Arc, allowed_program_ids: Option>, ) -> ( RemoteAccountClonerClient, @@ -173,6 +183,7 @@ fn setup_offline( account_fetcher, account_updates, account_dumper, + changeset_committor, allowed_program_ids, standard_blacklisted_accounts( &Pubkey::new_unique(), @@ -195,12 +206,14 @@ async fn test_clone_allow_feepayer_account_when_ephemeral() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -226,12 +239,14 @@ async fn test_clone_allow_undelegated_account_when_ephemeral() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -259,12 +274,14 @@ async fn test_clone_fails_stale_undelegated_account_when_ephemeral() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -293,12 +310,14 @@ async fn test_clone_allow_delegated_account_when_ephemeral() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -324,12 +343,14 @@ async fn test_clone_allow_program_accounts_when_ephemeral() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -376,6 +397,7 @@ async fn test_clone_program_accounts_when_ephemeral_with_whitelist() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); let mut allowed_program_ids = HashSet::new(); allowed_program_ids.insert(allowed_program_id); // Create account cloner worker and client @@ -384,6 +406,7 @@ async fn test_clone_program_accounts_when_ephemeral_with_whitelist() { account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), Some(allowed_program_ids), ); // Account(s) involved @@ -451,12 +474,14 @@ async fn test_clone_refuse_already_written_in_bank() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -487,12 +512,14 @@ async fn test_clone_refuse_blacklisted_account() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -522,12 +549,15 @@ async fn test_clone_refuse_feepayer_account_when_programs_replica() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); + // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_programs_replica( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -559,12 +589,14 @@ async fn test_clone_refuse_undelegated_account_when_programs_replica() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_programs_replica( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -597,12 +629,14 @@ async fn test_clone_refuse_delegated_account_when_programs_replica() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_programs_replica( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -634,12 +668,14 @@ async fn test_clone_allow_program_accounts_when_programs_replica() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_programs_replica( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -683,12 +719,14 @@ async fn test_clone_allow_undelegated_account_when_replica() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_replica( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -716,12 +754,14 @@ async fn test_clone_allow_feepayer_account_when_replica() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_replica( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -747,12 +787,14 @@ async fn test_clone_refuse_any_account_when_offline() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_offline( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -828,12 +870,14 @@ async fn test_clone_will_not_fetch_the_same_thing_multiple_times() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -878,12 +922,15 @@ async fn test_clone_properly_cached_undelegated_account_when_ephemeral() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); + // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -931,12 +978,14 @@ async fn test_clone_properly_cached_program() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -1005,12 +1054,14 @@ async fn test_clone_properly_cached_delegated_account_that_changes_state() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved @@ -1096,12 +1147,14 @@ async fn test_clone_properly_upgrading_downgrading_when_created_and_deleted() { let account_fetcher = AccountFetcherStub::default(); let account_updates = AccountUpdatesStub::default(); let account_dumper = AccountDumperStub::default(); + let changeset_committor = Arc::new(ChangesetCommittorStub::default()); // Create account cloner worker and client let (cloner, cancellation_token, worker_handle) = setup_ephemeral( internal_account_provider.clone(), account_fetcher.clone(), account_updates.clone(), account_dumper.clone(), + changeset_committor.clone(), None, ); // Account(s) involved diff --git a/magicblock-accounts/Cargo.toml b/magicblock-accounts/Cargo.toml index f91cdf0a5..61505240f 100644 --- a/magicblock-accounts/Cargo.toml +++ b/magicblock-accounts/Cargo.toml @@ -34,5 +34,8 @@ thiserror = { workspace = true } url = { workspace = true } [dev-dependencies] +magicblock-committor-service = { workspace = true, features = [ + "dev-context-only-utils", +] } test-tools-core = { workspace = true } tokio-util = { workspace = true } diff --git a/magicblock-accounts/tests/ensure_accounts.rs b/magicblock-accounts/tests/ensure_accounts.rs index cd13be55d..7c497f78b 100644 --- a/magicblock-accounts/tests/ensure_accounts.rs +++ b/magicblock-accounts/tests/ensure_accounts.rs @@ -1,3 +1,4 @@ +use log::*; use std::{collections::HashSet, sync::Arc}; use conjunto_transwise::{ @@ -16,10 +17,10 @@ use magicblock_accounts::{ errors::AccountsError, ExternalAccountsManager, LifecycleMode, }; use magicblock_accounts_api::InternalAccountProviderStub; +use magicblock_committor_service::stubs::ChangesetCommittorStub; use solana_sdk::pubkey::Pubkey; use stubs::{ account_committer_stub::AccountCommitterStub, - changeset_committor_stub::ChangesetCommittorStub, scheduled_commits_processor_stub::ScheduledCommitsProcessorStub, }; use test_tools_core::init_logger; @@ -654,7 +655,8 @@ async fn test_ensure_accounts_seen_as_readonly_can_be_used_as_writable_later() { }, "tx-sig".to_string(), ) - .await; + .await + .inspect_err(|e| error!("Error: {:?}", e)); assert!(result.is_ok()); // Check proper behaviour diff --git a/magicblock-accounts/tests/stubs/changeset_committor_stub.rs b/magicblock-accounts/tests/stubs/changeset_committor_stub.rs deleted file mode 100644 index e6752c9d1..000000000 --- a/magicblock-accounts/tests/stubs/changeset_committor_stub.rs +++ /dev/null @@ -1,47 +0,0 @@ -use magicblock_committor_service::ChangesetCommittor; - -#[derive(Default)] -pub struct ChangesetCommittorStub {} - -impl ChangesetCommittor for ChangesetCommittorStub { - fn commit_changeset( - &self, - _changeset: magicblock_committor_service::Changeset, - _ephemeral_blockhash: solana_sdk::hash::Hash, - _finalize: bool, - ) -> tokio::sync::oneshot::Receiver> { - unimplemented!("Not called during tests") - } - - fn get_commit_statuses( - &self, - _reqid: String, - ) -> tokio::sync::oneshot::Receiver< - magicblock_committor_service::error::CommittorServiceResult< - Vec, - >, - > { - unimplemented!("Not called during tests") - } - - fn get_bundle_signatures( - &self, - _bundle_id: u64, - ) -> tokio::sync::oneshot::Receiver< - magicblock_committor_service::error::CommittorServiceResult< - Option, - >, - > { - unimplemented!("Not called during tests") - } - - fn reserve_pubkeys_for_committee( - &self, - _committee: magicblock_program::Pubkey, - _owner: magicblock_program::Pubkey, - ) -> tokio::sync::oneshot::Receiver< - magicblock_committor_service::error::CommittorServiceResult<()>, - > { - unimplemented!("Not called during tests") - } -} diff --git a/magicblock-accounts/tests/stubs/mod.rs b/magicblock-accounts/tests/stubs/mod.rs index 797bab0b3..5d245cb19 100644 --- a/magicblock-accounts/tests/stubs/mod.rs +++ b/magicblock-accounts/tests/stubs/mod.rs @@ -1,3 +1,2 @@ pub mod account_committer_stub; -pub mod changeset_committor_stub; pub mod scheduled_commits_processor_stub; From 88dd40bbb3dc2560d27c034f3471e5a077eb42b3 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 14 May 2025 18:07:25 +0545 Subject: [PATCH 023/199] chore: move committor repo crates into magicblock monorepo - https://github.com/magicblock-labs/committor/tree/73f6a93d43995991fcc684b8853041f43fc19fa2 --- Cargo.lock | 244 +++- Cargo.toml | 20 +- magicblock-committor-program/Cargo.toml | 30 + magicblock-committor-program/src/consts.rs | 43 + magicblock-committor-program/src/error.rs | 34 + .../src/instruction.rs | 386 +++++++ .../src/instruction_chunks.rs | 53 + magicblock-committor-program/src/lib.rs | 29 + magicblock-committor-program/src/pdas.rs | 107 ++ magicblock-committor-program/src/processor.rs | 397 +++++++ .../src/state/changeset.rs | 498 ++++++++ .../src/state/changeset_chunks.rs | 165 +++ .../src/state/chunks.rs | 235 ++++ magicblock-committor-program/src/state/mod.rs | 3 + .../src/utils/account.rs | 26 + .../src/utils/asserts.rs | 60 + magicblock-committor-program/src/utils/mod.rs | 15 + .../tests/prog_init_write_and_close.rs | 346 ++++++ .../tests/prog_security.rs | 10 + magicblock-committor-service/Cargo.toml | 47 + .../src/bundle_strategy.rs | 205 ++++ magicblock-committor-service/src/bundles.rs | 273 +++++ .../src/commit/commit_using_args.rs | 299 +++++ .../src/commit/commit_using_buffer.rs | 1028 +++++++++++++++++ .../src/commit/committor_processor.rs | 560 +++++++++ .../src/commit/common.rs | 204 ++++ .../src/commit/mod.rs | 6 + .../src/commit/process_buffers.rs | 239 ++++ .../src/commit_info.rs | 177 +++ .../src/commit_stage.rs | 340 ++++++ .../src/commit_strategy.rs | 635 ++++++++++ .../src/compute_budget.rs | 218 ++++ magicblock-committor-service/src/config.rs | 42 + magicblock-committor-service/src/consts.rs | 15 + magicblock-committor-service/src/error.rs | 127 ++ magicblock-committor-service/src/finalize.rs | 66 ++ magicblock-committor-service/src/lib.rs | 35 + .../src/persist/commit_persister.rs | 254 ++++ .../src/persist/db.rs | 965 ++++++++++++++++ .../src/persist/error.rs | 38 + .../src/persist/mod.rs | 11 + .../src/persist/types/commit_status.rs | 269 +++++ .../src/persist/types/commit_strategy.rs | 54 + .../src/persist/types/commit_type.rs | 28 + .../src/persist/types/mod.rs | 7 + .../src/persist/utils.rs | 58 + .../src/pubkeys_provider.rs | 75 ++ magicblock-committor-service/src/service.rs | 367 ++++++ .../src/stubs/changeset_committor_stub.rs | 140 +++ magicblock-committor-service/src/stubs/mod.rs | 2 + .../src/transactions.rs | 778 +++++++++++++ magicblock-committor-service/src/types.rs | 57 + .../src/undelegate.rs | 103 ++ .../todo-tests/ix_commit_local.rs | 886 ++++++++++++++ .../todo-tests/utils/instructions.rs | 50 + .../todo-tests/utils/mod.rs | 51 + .../todo-tests/utils/transactions.rs | 58 + magicblock-rpc-client/Cargo.toml | 21 + magicblock-rpc-client/src/lib.rs | 512 ++++++++ magicblock-table-mania/Cargo.toml | 33 + magicblock-table-mania/src/derive_keypair.rs | 60 + magicblock-table-mania/src/error.rs | 27 + magicblock-table-mania/src/find_tables.rs | 47 + magicblock-table-mania/src/lib.rs | 10 + magicblock-table-mania/src/lookup_table.rs | 535 +++++++++ magicblock-table-mania/src/lookup_table_rc.rs | 708 ++++++++++++ magicblock-table-mania/src/manager.rs | 702 +++++++++++ .../tests/ix_lookup_table.rs | 163 +++ .../tests/ix_release_pubkeys.rs | 106 ++ .../tests/ix_reserve_pubkeys.rs | 132 +++ magicblock-table-mania/tests/utils/mod.rs | 116 ++ 71 files changed, 14612 insertions(+), 28 deletions(-) create mode 100644 magicblock-committor-program/Cargo.toml create mode 100644 magicblock-committor-program/src/consts.rs create mode 100644 magicblock-committor-program/src/error.rs create mode 100644 magicblock-committor-program/src/instruction.rs create mode 100644 magicblock-committor-program/src/instruction_chunks.rs create mode 100644 magicblock-committor-program/src/lib.rs create mode 100644 magicblock-committor-program/src/pdas.rs create mode 100644 magicblock-committor-program/src/processor.rs create mode 100644 magicblock-committor-program/src/state/changeset.rs create mode 100644 magicblock-committor-program/src/state/changeset_chunks.rs create mode 100644 magicblock-committor-program/src/state/chunks.rs create mode 100644 magicblock-committor-program/src/state/mod.rs create mode 100644 magicblock-committor-program/src/utils/account.rs create mode 100644 magicblock-committor-program/src/utils/asserts.rs create mode 100644 magicblock-committor-program/src/utils/mod.rs create mode 100644 magicblock-committor-program/tests/prog_init_write_and_close.rs create mode 100644 magicblock-committor-program/tests/prog_security.rs create mode 100644 magicblock-committor-service/Cargo.toml create mode 100644 magicblock-committor-service/src/bundle_strategy.rs create mode 100644 magicblock-committor-service/src/bundles.rs create mode 100644 magicblock-committor-service/src/commit/commit_using_args.rs create mode 100644 magicblock-committor-service/src/commit/commit_using_buffer.rs create mode 100644 magicblock-committor-service/src/commit/committor_processor.rs create mode 100644 magicblock-committor-service/src/commit/common.rs create mode 100644 magicblock-committor-service/src/commit/mod.rs create mode 100644 magicblock-committor-service/src/commit/process_buffers.rs create mode 100644 magicblock-committor-service/src/commit_info.rs create mode 100644 magicblock-committor-service/src/commit_stage.rs create mode 100644 magicblock-committor-service/src/commit_strategy.rs create mode 100644 magicblock-committor-service/src/compute_budget.rs create mode 100644 magicblock-committor-service/src/config.rs create mode 100644 magicblock-committor-service/src/consts.rs create mode 100644 magicblock-committor-service/src/error.rs create mode 100644 magicblock-committor-service/src/finalize.rs create mode 100644 magicblock-committor-service/src/lib.rs create mode 100644 magicblock-committor-service/src/persist/commit_persister.rs create mode 100644 magicblock-committor-service/src/persist/db.rs create mode 100644 magicblock-committor-service/src/persist/error.rs create mode 100644 magicblock-committor-service/src/persist/mod.rs create mode 100644 magicblock-committor-service/src/persist/types/commit_status.rs create mode 100644 magicblock-committor-service/src/persist/types/commit_strategy.rs create mode 100644 magicblock-committor-service/src/persist/types/commit_type.rs create mode 100644 magicblock-committor-service/src/persist/types/mod.rs create mode 100644 magicblock-committor-service/src/persist/utils.rs create mode 100644 magicblock-committor-service/src/pubkeys_provider.rs create mode 100644 magicblock-committor-service/src/service.rs create mode 100644 magicblock-committor-service/src/stubs/changeset_committor_stub.rs create mode 100644 magicblock-committor-service/src/stubs/mod.rs create mode 100644 magicblock-committor-service/src/transactions.rs create mode 100644 magicblock-committor-service/src/types.rs create mode 100644 magicblock-committor-service/src/undelegate.rs create mode 100644 magicblock-committor-service/todo-tests/ix_commit_local.rs create mode 100644 magicblock-committor-service/todo-tests/utils/instructions.rs create mode 100644 magicblock-committor-service/todo-tests/utils/mod.rs create mode 100644 magicblock-committor-service/todo-tests/utils/transactions.rs create mode 100644 magicblock-rpc-client/Cargo.toml create mode 100644 magicblock-rpc-client/src/lib.rs create mode 100644 magicblock-table-mania/Cargo.toml create mode 100644 magicblock-table-mania/src/derive_keypair.rs create mode 100644 magicblock-table-mania/src/error.rs create mode 100644 magicblock-table-mania/src/find_tables.rs create mode 100644 magicblock-table-mania/src/lib.rs create mode 100644 magicblock-table-mania/src/lookup_table.rs create mode 100644 magicblock-table-mania/src/lookup_table_rc.rs create mode 100644 magicblock-table-mania/src/manager.rs create mode 100644 magicblock-table-mania/tests/ix_lookup_table.rs create mode 100644 magicblock-table-mania/tests/ix_release_pubkeys.rs create mode 100644 magicblock-table-mania/tests/ix_reserve_pubkeys.rs create mode 100644 magicblock-table-mania/tests/utils/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 4d7ca7f95..c7baa0bd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1185,7 +1185,7 @@ dependencies = [ "conjunto-addresses", "conjunto-core", "conjunto-providers", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", + "magicblock-delegation-program", "serde", "solana-rpc-client", "solana-rpc-client-api", @@ -1729,6 +1729,18 @@ dependencies = [ "sha2 0.10.8", ] +[[package]] +name = "educe" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0042ff8246a363dbe77d2ceedb073339e85a804b9a47636c6e016a9a32c05f" +dependencies = [ + "enum-ordinalize", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "either" version = "1.13.0" @@ -1770,6 +1782,19 @@ dependencies = [ "syn 2.0.95", ] +[[package]] +name = "enum-ordinalize" +version = "3.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bf1fa3f06bbff1ea5b1a9c7b14aa992a39657db60a2759457328d7e058f49ee" +dependencies = [ + "num-bigint 0.4.6", + "num-traits", + "proc-macro2", + "quote", + "syn 2.0.95", +] + [[package]] name = "env_filter" version = "0.1.3" @@ -3603,7 +3628,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", + "magicblock-delegation-program", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3733,7 +3758,7 @@ dependencies = [ [[package]] name = "magicblock-committor-program" -version = "0.0.0" +version = "0.1.1" dependencies = [ "borsh 1.5.5", "borsh-derive 1.5.5", @@ -3741,20 +3766,25 @@ dependencies = [ "paste", "solana-account", "solana-program", + "solana-program-test", "solana-pubkey", - "thiserror 2.0.12", + "solana-sdk", + "thiserror 1.0.69", + "tokio", ] [[package]] name = "magicblock-committor-service" -version = "0.0.0" +version = "0.1.1" dependencies = [ - "base64 0.22.1", + "base64 0.21.7", "bincode", "borsh 1.5.5", + "env_logger 0.11.6", + "lazy_static", "log", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program", "magicblock-rpc-client", "magicblock-table-mania", "rusqlite", @@ -3765,7 +3795,7 @@ dependencies = [ "solana-sdk", "solana-transaction-status-client-types", "static_assertions", - "thiserror 2.0.12", + "thiserror 1.0.69", "tokio", "tokio-util 0.7.13", ] @@ -3793,21 +3823,6 @@ dependencies = [ "solana-sdk", ] -[[package]] -name = "magicblock-delegation-program" -version = "1.0.0" -dependencies = [ - "bincode", - "borsh 1.5.5", - "bytemuck", - "num_enum", - "paste", - "solana-curve25519", - "solana-program", - "solana-security-txt", - "thiserror 1.0.69", -] - [[package]] name = "magicblock-delegation-program" version = "1.0.0" @@ -4024,31 +4039,34 @@ dependencies = [ [[package]] name = "magicblock-rpc-client" -version = "0.0.0" +version = "0.1.1" dependencies = [ + "env_logger 0.11.6", "log", "solana-rpc-client", "solana-rpc-client-api", "solana-sdk", "solana-transaction-status-client-types", - "thiserror 2.0.12", + "thiserror 1.0.69", "tokio", ] [[package]] name = "magicblock-table-mania" -version = "0.0.0" +version = "0.1.1" dependencies = [ "ed25519-dalek", + "env_logger 0.11.6", "log", "magicblock-rpc-client", + "paste", "rand 0.8.5", "sha3", "solana-pubkey", "solana-rpc-client", "solana-rpc-client-api", "solana-sdk", - "thiserror 2.0.12", + "thiserror 1.0.69", "tokio", ] @@ -4613,6 +4631,25 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "opentelemetry" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6105e89802af13fdf48c49d7646d3b533a70e536d818aae7e78ba0433d01acb8" +dependencies = [ + "async-trait", + "crossbeam-channel", + "futures-channel", + "futures-executor", + "futures-util", + "js-sys", + "lazy_static", + "percent-encoding 2.3.1", + "pin-project", + "rand 0.8.5", + "thiserror 1.0.69", +] + [[package]] name = "parity-ws" version = "0.11.1" @@ -6327,6 +6364,57 @@ dependencies = [ "parking_lot 0.12.3", ] +[[package]] +name = "solana-banks-client" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01364483db3a7ad3546695df73eeec869fdb7399e8734b9a4d9ec5426d4bc932" +dependencies = [ + "borsh 1.5.5", + "futures 0.3.31", + "solana-banks-interface", + "solana-program", + "solana-sdk", + "tarpc", + "thiserror 2.0.12", + "tokio", + "tokio-serde", +] + +[[package]] +name = "solana-banks-interface" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d185017c022a9bc7b9b4709fdb15d4a3a4875548bb53d95d49f696476497879" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk", + "tarpc", +] + +[[package]] +name = "solana-banks-server" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f72a966c0ebb198a16db924b4377f1b04dc8040afe0815ccee29cf852b4a0cc" +dependencies = [ + "bincode", + "crossbeam-channel", + "futures 0.3.31", + "solana-banks-interface", + "solana-client", + "solana-feature-set", + "solana-runtime", + "solana-runtime-transaction", + "solana-sdk", + "solana-send-transaction-service", + "solana-svm", + "tarpc", + "tokio", + "tokio-serde", +] + [[package]] name = "solana-big-mod-exp" version = "2.2.1" @@ -7935,6 +8023,43 @@ dependencies = [ "thiserror 2.0.12", ] +[[package]] +name = "solana-program-test" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02f25b19e0f8ef1f4e30f9aa5d986238edfd68bb35ef66131d8992cb941286f0" +dependencies = [ + "assert_matches", + "async-trait", + "base64 0.22.1", + "bincode", + "chrono-humanize", + "crossbeam-channel", + "log", + "serde", + "solana-accounts-db", + "solana-banks-client", + "solana-banks-interface", + "solana-banks-server", + "solana-bpf-loader-program", + "solana-compute-budget", + "solana-feature-set", + "solana-inline-spl", + "solana-instruction", + "solana-log-collector", + "solana-logger", + "solana-program-runtime", + "solana-runtime", + "solana-sbpf", + "solana-sdk", + "solana-sdk-ids", + "solana-svm", + "solana-timings", + "solana-vote-program", + "thiserror 2.0.12", + "tokio", +] + [[package]] name = "solana-pubkey" version = "2.2.1" @@ -10094,6 +10219,41 @@ dependencies = [ "xattr", ] +[[package]] +name = "tarpc" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38a012bed6fb9681d3bf71ffaa4f88f3b4b9ed3198cda6e4c8462d24d4bb80" +dependencies = [ + "anyhow", + "fnv", + "futures 0.3.31", + "humantime", + "opentelemetry", + "pin-project", + "rand 0.8.5", + "serde", + "static_assertions", + "tarpc-plugins", + "thiserror 1.0.69", + "tokio", + "tokio-serde", + "tokio-util 0.6.10", + "tracing", + "tracing-opentelemetry", +] + +[[package]] +name = "tarpc-plugins" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee42b4e559f17bce0385ebf511a7beb67d5cc33c12c96b7f4e9789919d9c10f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "task-local-extensions" version = "0.1.4" @@ -10370,6 +10530,22 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-serde" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "911a61637386b789af998ee23f50aa30d5fd7edcec8d6d3dedae5e5815205466" +dependencies = [ + "bincode", + "bytes 1.10.1", + "educe", + "futures-core", + "futures-sink", + "pin-project", + "serde", + "serde_json", +] + [[package]] name = "tokio-stream" version = "0.1.17" @@ -10407,6 +10583,7 @@ dependencies = [ "futures-sink", "log", "pin-project-lite", + "slab", "tokio", ] @@ -10618,6 +10795,19 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-opentelemetry" +version = "0.17.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbbe89715c1dbbb790059e2565353978564924ee85017b5fff365c872ff6721f" +dependencies = [ + "once_cell", + "opentelemetry", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "tracing-subscriber" version = "0.3.19" diff --git a/Cargo.toml b/Cargo.toml index cf4c8db36..ffc2e12af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,8 @@ members = [ "magicblock-accounts-db", "magicblock-api", "magicblock-bank", + "magicblock-committor-program", + "magicblock-committor-service", "magicblock-config", "magicblock-core", "magicblock-geyser-plugin", @@ -25,6 +27,8 @@ members = [ "magicblock-processor", "magicblock-pubsub", "magicblock-rpc", + "magicblock-rpc-client", + "magicblock-table-mania", "magicblock-tokens", "magicblock-transaction-status", "magicblock-version", @@ -55,12 +59,15 @@ assert_matches = "1.5.0" async-trait = "0.1.77" base64 = "0.21.7" bincode = "1.3.3" +borsh = { version = "1.5.1", features = ["derive", "unstable__schema"] } +borsh-derive = "1.5.1" bs58 = "0.4.0" byteorder = "1.5.0" cargo-lock = "10.0.0" conjunto-transwise = { git = "https://github.com/magicblock-labs/conjunto.git", rev = "bf82b45" } console-subscriber = "0.2.0" crossbeam-channel = "0.5.11" +ed25519-dalek = "1.0.1" enum-iterator = "1.5.0" env_logger = "0.11.2" expiring-hashmap = { path = "./utils/expiring-hashmap" } @@ -95,7 +102,10 @@ magicblock-accounts-api = { path = "./magicblock-accounts-api" } magicblock-accounts-db = { path = "./magicblock-accounts-db" } magicblock-api = { path = "./magicblock-api" } magicblock-bank = { path = "./magicblock-bank" } -magicblock-committor-service = { path = "../comittor/magicblock-committor-service" } +magicblock-committor-service = { path = "./magicblock-committor-service" } +magicblock-committor-program = { path = "./magicblock-committor-program", features = [ + "no-entrypoint", +] } magicblock-config = { path = "./magicblock-config" } magicblock-core = { path = "./magicblock-core" } magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } @@ -108,6 +118,8 @@ magicblock-processor = { path = "./magicblock-processor" } magicblock-program = { path = "./programs/magicblock" } magicblock-pubsub = { path = "./magicblock-pubsub" } magicblock-rpc = { path = "./magicblock-rpc" } +magicblock-rpc-client = { path = "./magicblock-rpc-client" } +magicblock-table-mania = { path = "./magicblock-table-mania" } magicblock-tokens = { path = "./magicblock-tokens" } magicblock-transaction-status = { path = "./magicblock-transaction-status" } magicblock-version = { path = "./magicblock-version" } @@ -123,10 +135,12 @@ protobuf-src = "1.1" rand = "0.8.5" rayon = "1.10.0" rustc_version = "0.4" +rusqlite = { version = "0.34.0", features = ["bundled"] } # bundled sqlite 3.44 semver = "1.0.22" serde = "1.0.217" serde_derive = "1.0" serde_json = "1.0" +sha3 = "0.10.8" solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "7bdfefc" } solana-accounts-db = { version = "2.2" } solana-account-decoder = { version = "2.2" } @@ -143,7 +157,9 @@ solana-log-collector = { version = "2.2" } solana-measure = { version = "2.2" } solana-metrics = { version = "2.2" } solana-perf = { version = "2.2" } +solana-program = "2.2" solana-program-runtime = { version = "2.2" } +solana-program-test = "2.2" solana-pubkey = { version = "2.2" } solana-rayon-threadlimit = { version = "2.2" } solana-pubsub-client = { version = "2.2" } @@ -157,8 +173,10 @@ solana-storage-proto = { path = "storage-proto" } solana-system-program = { version = "2.2" } solana-timings = "2.2" solana-transaction-status = { version = "2.2" } +solana-transaction-status-client-types = "2.2" spl-token = "=7.0" spl-token-2022 = "=6.0" +static_assertions = "1.1.0" strum = "0.24" strum_macros = "0.24" tempfile = "3.10.1" diff --git a/magicblock-committor-program/Cargo.toml b/magicblock-committor-program/Cargo.toml new file mode 100644 index 000000000..2b17f5b3f --- /dev/null +++ b/magicblock-committor-program/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "magicblock-committor-program" +version.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true +license.workspace = true +edition.workspace = true + +[dependencies] +borsh = { workspace = true } +borsh-derive = { workspace = true } +log = { workspace = true } +paste = { workspace = true } +solana-account = { workspace = true } +solana-program = { workspace = true } +solana-pubkey = { workspace = true } +thiserror = { workspace = true } + +[dev-dependencies] +solana-program-test = { workspace = true } +solana-sdk = { workspace = true } +tokio = { workspace = true } + +[lib] +crate-type = ["cdylib", "lib"] + +[features] +no-entrypoint = [] +default = [] diff --git a/magicblock-committor-program/src/consts.rs b/magicblock-committor-program/src/consts.rs new file mode 100644 index 000000000..4af1f467f --- /dev/null +++ b/magicblock-committor-program/src/consts.rs @@ -0,0 +1,43 @@ +/// Max bytest that can be allocated as part of the one instruction. +/// For buffers that are larger than that ReallocBuffer needs to be +/// invoked 1 or more times after Init completed. +pub const MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE: u16 = 10_240; + +/// The maximum number of instructions that can be added to a single transaction. +/// See: https://github.com/solana-labs/solana/issues/33863 +pub const MAX_INSTRUCTION_TRACE_LENGTH: u8 = 64; + +/// We ran into max transaction size exceeded if we included more than +/// the below amount of instructions in a single transaction. +/// (VersionedTransaction too large: xxxx bytes (max: encoded/raw 1644/1232)) +/// Thus the [MAX_INSTRUCTION_TRACE_LENGTH] is not the upper limit, but we're +/// capped by the size of each instruction. (see [crate::instruction_chunks::chunk_realloc_ixs]) +pub const MAX_INSTRUCTION_LENGTH: u8 = 11; + +/// This size is based on exploration of the Write instruction of the BPFUpgradableLoader program +/// +/// It includes the following accounts: +/// +/// - account +/// - authority +/// +/// The write instruction: +/// +/// ```rust +/// pub enum UpgradeableLoaderInstruction { +/// Write { +/// /// Offset at which to write the given bytes. +/// offset: u32, +/// /// Serialized program data +/// bytes: Vec, +/// } +/// } +/// ``` +/// +/// The instruction data size total I measured was 1028 bytes +/// The bytes hold 1012 bytes(see tools/sh/deploy-ix-bytesize) +/// which leaves 16 bytes for: +/// - offset: 4 bytes +/// - instruction discriminator: 1 byte aligned to 4 bytes +/// - both accounts repeated in instruction: 2x 4 bytes 8 bytes +pub const MAX_INSTRUCTION_DATA_SIZE: u16 = 1028; diff --git a/magicblock-committor-program/src/error.rs b/magicblock-committor-program/src/error.rs new file mode 100644 index 000000000..35e7156d3 --- /dev/null +++ b/magicblock-committor-program/src/error.rs @@ -0,0 +1,34 @@ +use solana_program::msg; +use solana_program::program_error::ProgramError; +use thiserror::Error; + +pub type CommittorResult = std::result::Result; + +#[derive(Error, Debug, Clone)] +pub enum CommittorError { + #[error("Unable to serialize change set: {0}")] + UnableToSerializeChangeSet(String), + + #[error("Pubkey error")] + PubkeyError(#[from] solana_pubkey::PubkeyError), + + #[error("Offset ({0}) must be multiple of chunk size ({1})")] + OffsetMustBeMultipleOfChunkSize(usize, u16), + + #[error("Chunk of size {0} cannot be stored at offset {1} in buffer of size ({2})")] + OffsetChunkOutOfRange(usize, u32, usize), +} + +impl From for ProgramError { + fn from(e: CommittorError) -> Self { + msg!("Error: {:?}", e); + use CommittorError::*; + let n = match e { + UnableToSerializeChangeSet(_) => 0x69000, + PubkeyError(_) => 0x69001, + OffsetMustBeMultipleOfChunkSize(_, _) => 0x69002, + OffsetChunkOutOfRange(_, _, _) => 0x69003, + }; + ProgramError::Custom(n) + } +} diff --git a/magicblock-committor-program/src/instruction.rs b/magicblock-committor-program/src/instruction.rs new file mode 100644 index 000000000..8ce2e7c78 --- /dev/null +++ b/magicblock-committor-program/src/instruction.rs @@ -0,0 +1,386 @@ +use borsh::{BorshDeserialize, BorshSerialize}; +use solana_program::hash::Hash; +use solana_program::hash::HASH_BYTES; +use solana_program::instruction::{AccountMeta, Instruction}; +use solana_program::system_program; +use solana_pubkey::Pubkey; + +use crate::{consts, pdas}; + +#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)] +pub enum CommittorInstruction { + /// Initializes the buffer and [Chunks] accounts which will be used to + /// [CommittorInstruction::Write] and then [CommittorInstruction::Commit]. + /// + /// Accounts: + /// 0. `[signer]` The validator authority. + /// 1. `[writable]` The PDA holding the [Chunks] data which track the + /// committed chunks. + /// 2. `[writable]` The PDA buffer account into which we accumulate the data to commit. + /// 3. `[]` The system program to facilitate creation of accounts + Init { + /// The on chain address of the account we are committing + /// This is part of the seeds used to derive the buffer and chunk account PDAs. + pubkey: Pubkey, + /// The size that the buffer account needs to have in order to track commits + chunks_account_size: u64, + /// The size that the buffer account needs to have in order to hold all commits + buffer_account_size: u64, + /// The ephemeral blockhash of the changeset we are writing, + /// needed to properly derive the seeds of the PDAs. + blockhash: Hash, + /// The bump to use when deriving seeds and PDA for the [Chunks] account. + chunks_bump: u8, + /// The bump to use when deriving seeds and PDA for the buffer account. + buffer_bump: u8, + /// The number of chunks that the [Chunks] account will track. + chunk_count: usize, + /// The size of each chunk that the [Chunks] account will track. + chunk_size: u16, + }, + /// Accounts: + /// 0. `[signer]` The validator authority. + /// 1. `[writable]` The PDA buffer account into which we accumulate the data to commit. + ReallocBuffer { + /// The on chain address of the account we are committing + /// This is part of the seeds used to derive the buffer and chunk account PDAs. + pubkey: Pubkey, + /// The size that the buffer account needs to have in order to hold all commits + buffer_account_size: u64, + /// The ephemeral blockhash of the changeset we are writing, + /// needed to properly derive the seeds of the PDAs. + blockhash: Hash, + /// The bump to use when deriving seeds and PDA for the buffer account. + buffer_bump: u8, + /// The count of invocations of realloc buffer that this instruction represents. + invocation_count: u16, + }, + /// Writes a chunk of data into the buffer account and updates the [Chunks] to + /// show that the chunk has been written. + /// + /// Accounts: + /// 0. `[signer]` The validator authority. + /// 1. `[writable]` The PDA holding the [Chunks] data which track the + /// committed chunks. + /// 2. `[writable]` The PDA buffer account into which we accumulate the data to commit. + Write { + /// The on chain address of the account we are committing + /// This is part of the seeds used to derive the buffer and chunk account PDAs. + pubkey: Pubkey, + /// The ephemeral blockhash of the changeset we are writing, + /// needed to properly derive the seeds of the PDAs. + blockhash: Hash, + /// The bump to use when deriving seeds and PDA for the [Chunks] account. + chunks_bump: u8, + /// The bump to use when deriving seeds and PDA for the buffer account. + buffer_bump: u8, + /// Offset in the buffer account where to write the data. + offset: u32, + /// The data to write into the buffer account. + data_chunk: Vec, + }, + /// This instruction closes the buffer account and the [Chunks] account. + /// + /// It is called by the validator after the instruction that processes the + /// change set stored in the buffer account and applies the commits to the + /// relevant accounts. + /// Ideally it runs in the same transaction as the 'processs' instruction. + /// + /// The lamports gained due to closing both accounts are transferred to the + /// validator authority. + /// + /// Accounts: + /// 0. `[signer]` The validator authority. + /// 1. `[writable]` The PDA holding the [Chunks] data which tracked the + /// committed chunks and we are now closing. + /// 2. `[writable]` The PDA buffer account we are closing. + Close { + /// The on chain address of the account we committed. + /// This is part of the seeds used to derive the buffer and chunk account PDAs. + pubkey: Pubkey, + /// The ephemeral blockhash of the changeset we are writing, + /// needed to properly derive the seeds of the PDAs. + blockhash: Hash, + /// The bump to use when deriving seeds and PDA for the [Chunks] account. + chunks_bump: u8, + /// The bump to use when deriving seeds and PDA for the buffer account. + buffer_bump: u8, + }, +} + +pub const IX_INIT_SIZE: u16 = + // pubkey: Pubkey, + 32 + + // chunks_account_size: u64, + 8 + + // buffer_account_size: u64, + 8 + + // blockhash: Hash, + HASH_BYTES as u16 + + // chunks_bump: u8, + 8 + + // buffer_bump: u8, + 8 + + // chunk_count: usize, + 8 + + // chunk_size: u16, + 2 + + // byte align + 6; + +pub const IX_REALLOC_SIZE: u16 = + // pubkey: Pubkey, + 32 + + // buffer_account_size: u64, + 8 + + // blockhash: Hash, + HASH_BYTES as u16 + + // buffer_bump: u8, + 8 + + // invocation_count: u16, + 2 + + // byte align + 6; + +pub const IX_WRITE_SIZE_WITHOUT_CHUNKS: u16 = + // pubkey: Pubkey, + 32+ + // blockhash: Hash, + HASH_BYTES as u16 + + // chunks_bump: u8, + 8 + + // buffer_bump: u8, + 8 + + // offset: u32 + 32; + +pub const IX_CLOSE_SIZE: u16 = + // pubkey: Pubkey, + 32 + + // blockhash: Hash, + HASH_BYTES as u16 + + // chunks_bump: u8, + 8 + + // buffer_bump: u8, + 8; + +// ----------------- +// create_init_ix +// ----------------- +pub struct CreateInitIxArgs { + /// The validator authority + pub authority: Pubkey, + /// On chain address of the account we are committing + pub pubkey: Pubkey, + /// Required size of the account tracking which chunks have been committed + pub chunks_account_size: u64, + /// Required size of the buffer account that holds the account data to commit + pub buffer_account_size: u64, + /// The latest on chain blockhash + pub blockhash: Hash, + /// The number of chunks we need to write until all the data is copied to the + /// buffer account + pub chunk_count: usize, + /// The size of each chunk that we write to the buffer account + pub chunk_size: u16, +} + +pub fn create_init_ix(args: CreateInitIxArgs) -> (Instruction, Pubkey, Pubkey) { + let CreateInitIxArgs { + authority, + pubkey, + chunks_account_size, + buffer_account_size, + blockhash, + chunk_count, + chunk_size, + } = args; + + let (chunks_pda, chunks_bump) = + pdas::chunks_pda(&authority, &pubkey, &blockhash); + let (buffer_pda, buffer_bump) = + pdas::buffer_pda(&authority, &pubkey, &blockhash); + let program_id = crate::id(); + let ix = CommittorInstruction::Init { + pubkey, + blockhash, + chunks_account_size, + buffer_account_size, + chunks_bump, + buffer_bump, + chunk_count, + chunk_size, + }; + let accounts = vec![ + AccountMeta::new(authority, true), + AccountMeta::new(chunks_pda, false), + AccountMeta::new(buffer_pda, false), + AccountMeta::new_readonly(system_program::id(), false), + ]; + ( + Instruction::new_with_borsh(program_id, &ix, accounts), + chunks_pda, + buffer_pda, + ) +} + +// ----------------- +// create_realloc_buffer_ix +// ----------------- +#[derive(Clone)] +pub struct CreateReallocBufferIxArgs { + pub authority: Pubkey, + pub pubkey: Pubkey, + pub buffer_account_size: u64, + pub blockhash: Hash, +} + +/// Creates the realloc ixs we need to invoke in order to realloc +/// the account to the desired size since we only can realloc up to +/// [consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE] in a single instruction. +/// Returns a tuple with the instructions and a bool indicating if we need to split +/// them into multiple instructions in order to avoid +/// [solana_program::program_error::MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED]J +pub fn create_realloc_buffer_ixs( + args: CreateReallocBufferIxArgs, +) -> Vec { + // We already allocated once during Init and only need to realloc + // if the buffer is larger than [consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE] + if args.buffer_account_size + <= consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64 + { + return vec![]; + } + + let remaining_size = args.buffer_account_size as i128 + - consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128; + + // A) We just need to realloc once + if remaining_size <= consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128 { + return vec![create_realloc_buffer_ix(args, 1)]; + } + + // B) We need to realloc multiple times + // SAFETY; remaining size > consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE + create_realloc_buffer_ixs_to_add_remaining(&args, remaining_size as u64) +} + +pub fn create_realloc_buffer_ixs_to_add_remaining( + args: &CreateReallocBufferIxArgs, + remaining_size: u64, +) -> Vec { + let invocation_count = (remaining_size as f64 + / consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as f64) + .ceil() as u16; + + let mut ixs = vec![]; + for i in 0..invocation_count { + ixs.push(create_realloc_buffer_ix(args.clone(), i + 1)); + } + + ixs +} + +fn create_realloc_buffer_ix( + args: CreateReallocBufferIxArgs, + invocation_count: u16, +) -> Instruction { + let CreateReallocBufferIxArgs { + authority, + pubkey, + buffer_account_size, + blockhash, + } = args; + let (buffer_pda, buffer_bump) = + pdas::buffer_pda(&authority, &pubkey, &blockhash); + + let program_id = crate::id(); + let ix = CommittorInstruction::ReallocBuffer { + pubkey, + buffer_account_size, + blockhash, + buffer_bump, + invocation_count, + }; + let accounts = vec![ + AccountMeta::new(authority, true), + AccountMeta::new(buffer_pda, false), + ]; + Instruction::new_with_borsh(program_id, &ix, accounts) +} + +// ----------------- +// create_write_ix +// ----------------- +pub struct CreateWriteIxArgs { + pub authority: Pubkey, + pub pubkey: Pubkey, + pub offset: u32, + pub data_chunk: Vec, + pub blockhash: Hash, +} + +pub fn create_write_ix(args: CreateWriteIxArgs) -> Instruction { + let CreateWriteIxArgs { + authority, + pubkey, + offset, + data_chunk, + blockhash, + } = args; + let (chunks_pda, chunks_bump) = + pdas::chunks_pda(&authority, &pubkey, &blockhash); + let (buffer_pda, buffer_bump) = + pdas::buffer_pda(&authority, &pubkey, &blockhash); + + let program_id = crate::id(); + let ix = CommittorInstruction::Write { + pubkey, + blockhash, + chunks_bump, + buffer_bump, + offset, + data_chunk, + }; + let accounts = vec![ + AccountMeta::new(authority, true), + AccountMeta::new(chunks_pda, false), + AccountMeta::new(buffer_pda, false), + ]; + Instruction::new_with_borsh(program_id, &ix, accounts) +} + +// ----------------- +// create_close_ix +// ----------------- +pub struct CreateCloseIxArgs { + pub authority: Pubkey, + pub pubkey: Pubkey, + pub blockhash: Hash, +} + +pub fn create_close_ix(args: CreateCloseIxArgs) -> Instruction { + let CreateCloseIxArgs { + authority, + pubkey, + blockhash, + } = args; + let (chunks_pda, chunks_bump) = + pdas::chunks_pda(&authority, &pubkey, &blockhash); + let (buffer_pda, buffer_bump) = + pdas::buffer_pda(&authority, &pubkey, &blockhash); + + let program_id = crate::id(); + let ix = CommittorInstruction::Close { + pubkey, + blockhash, + chunks_bump, + buffer_bump, + }; + let accounts = vec![ + AccountMeta::new(authority, true), + AccountMeta::new(chunks_pda, false), + AccountMeta::new(buffer_pda, false), + ]; + Instruction::new_with_borsh(program_id, &ix, accounts) +} diff --git a/magicblock-committor-program/src/instruction_chunks.rs b/magicblock-committor-program/src/instruction_chunks.rs new file mode 100644 index 000000000..a726f5e33 --- /dev/null +++ b/magicblock-committor-program/src/instruction_chunks.rs @@ -0,0 +1,53 @@ +use crate::instruction::{IX_INIT_SIZE, IX_REALLOC_SIZE}; + +use crate::consts::MAX_INSTRUCTION_DATA_SIZE; + +/// Creates chunks of realloc instructions such that each chunk fits into a single transaction. +/// - reallocs: The realloc instructions to split up +/// - init_ix: The init instruction that is combined with the first reallocs +pub fn chunk_realloc_ixs( + reallocs: Vec, + init_ix: Option, +) -> Vec> { + fn add_reallocs( + chunk: &mut Vec, + reallocs: &mut Vec, + start_size: u16, + ) { + let mut total_size = start_size; + loop { + total_size += IX_REALLOC_SIZE; + if total_size >= MAX_INSTRUCTION_DATA_SIZE { + return; + } + if let Some(realloc) = reallocs.pop() { + chunk.push(realloc); + } else { + return; + } + } + } + + let mut reallocs = reallocs; + // We add to the chunks by popping from the end and in order to retain the order + // of reallocs we reverse them here first + reallocs.reverse(); + + let mut chunks = vec![]; + + // First chunk combines reallocs with init instruction if present + if let Some(init_ix) = init_ix { + let mut chunk = vec![init_ix]; + add_reallocs(&mut chunk, &mut reallocs, IX_INIT_SIZE); + chunks.push(chunk); + } + + // All remaining chunks are pure realloc instructions + while let Some(realloc) = reallocs.pop() { + let mut chunk = vec![realloc]; + add_reallocs(&mut chunk, &mut reallocs, IX_REALLOC_SIZE); + chunks.push(chunk); + } + + chunks +} diff --git a/magicblock-committor-program/src/lib.rs b/magicblock-committor-program/src/lib.rs new file mode 100644 index 000000000..831bc7935 --- /dev/null +++ b/magicblock-committor-program/src/lib.rs @@ -0,0 +1,29 @@ +use solana_pubkey::declare_id; +pub mod consts; +pub mod error; +pub mod instruction; +pub mod instruction_chunks; +pub mod pdas; +mod state; + +// #[cfg(not(feature = "no-entrypoint"))] +mod utils; + +// #[cfg(not(feature = "no-entrypoint"))] +mod processor; +// #[cfg(not(feature = "no-entrypoint"))] +pub use processor::process; + +pub use state::{ + changeset::{ + ChangedAccount, ChangedAccountMeta, ChangedBundle, Changeset, + ChangesetBundles, ChangesetMeta, CommitableAccount, + }, + changeset_chunks::{ChangesetChunk, ChangesetChunks}, + chunks::Chunks, +}; + +#[cfg(not(feature = "no-entrypoint"))] +solana_program::entrypoint!(process); + +declare_id!("corabpNrkBEqbTZP7xfJgSWTdBmVdLf1PARWXZbcMcS"); diff --git a/magicblock-committor-program/src/pdas.rs b/magicblock-committor-program/src/pdas.rs new file mode 100644 index 000000000..e28a89a92 --- /dev/null +++ b/magicblock-committor-program/src/pdas.rs @@ -0,0 +1,107 @@ +use paste::paste; + +const CHUNKS_SEED: &[u8] = b"comittor_chunks"; +const BUFFER_SEED: &[u8] = b"comittor_buffer"; + +macro_rules! seeds { + ($prefix:ident, $bytes_const:expr) => { + paste! { + #[allow(clippy::needless_lifetimes)] + pub fn [<$prefix _seeds>]<'a>( + validator_auth: &'a ::solana_pubkey::Pubkey, + pubkey: &'a ::solana_pubkey::Pubkey, + blockhash: &'a ::solana_program::hash::Hash) -> [&'a [u8]; 5] { + [ + crate::ID.as_ref(), + $bytes_const, + validator_auth.as_ref(), + pubkey.as_ref(), + blockhash.as_ref(), + ] + } + #[allow(clippy::needless_lifetimes)] + pub fn [<$prefix _seeds_with_bump>]<'a>( + validator_auth: &'a ::solana_pubkey::Pubkey, + pubkey: &'a ::solana_pubkey::Pubkey, + blockhash: &'a ::solana_program::hash::Hash, + bump: &'a [u8], + ) -> [&'a [u8]; 6] { + [ + crate::ID.as_ref(), + $bytes_const, + validator_auth.as_ref(), + pubkey.as_ref(), + blockhash.as_ref(), + bump, + ] + } + } + }; +} + +macro_rules! pda { + ($prefix:ident) => { + paste! { + #[allow(clippy::needless_lifetimes)] + pub fn [<$prefix _pda>]<'a>( + validator_auth: &'a ::solana_pubkey::Pubkey, + pubkey: &'a ::solana_pubkey::Pubkey, + blockhash: &'a ::solana_program::hash::Hash, + ) -> (::solana_pubkey::Pubkey, u8) { + let program_id = &crate::id(); + let seeds = [<$prefix _seeds>](validator_auth, pubkey, blockhash); + ::solana_pubkey::Pubkey::find_program_address(&seeds, program_id) + } + #[allow(clippy::needless_lifetimes)] + pub fn []<'a>( + validator_auth: &'a ::solana_pubkey::Pubkey, + pubkey: &'a ::solana_pubkey::Pubkey, + blockhash: &'a ::solana_program::hash::Hash, + bump: &'a [u8], + ) -> $crate::error::CommittorResult<::solana_pubkey::Pubkey> { + let program_id = &crate::id(); + let seeds = [<$prefix _seeds_with_bump>](validator_auth, pubkey, blockhash, bump); + Ok(::solana_pubkey::Pubkey::create_program_address(&seeds, program_id)?) + } + } + }; +} + +seeds!(chunks, CHUNKS_SEED); +pda!(chunks); +seeds!(buffer, BUFFER_SEED); +pda!(buffer); + +#[macro_export] +macro_rules! verified_seeds_and_pda { + ($prefix:ident, + $authority_info:ident, + $pubkey:ident, + $account_info:ident, + $blockhash:ident, + $bump:ident) => {{ + ::paste::paste! { + let seeds = $crate::pdas::[<$prefix _seeds_with_bump>]( + $authority_info.key, + $pubkey, + &$blockhash, + $bump, + ); + let pda = $crate::pdas::[]( + $authority_info.key, + $pubkey, + &$blockhash, + $bump, + ) + .inspect_err(|err| msg!("ERR: {}", err))?; + $crate::utils::assert_keys_equal($account_info.key, &pda, || { + format!( + "Provided {} PDA does not match derived key '{}'", + stringify!($prefix), + pda + ) + })?; + (seeds, pda) + } + }}; +} diff --git a/magicblock-committor-program/src/processor.rs b/magicblock-committor-program/src/processor.rs new file mode 100644 index 000000000..db1455ee2 --- /dev/null +++ b/magicblock-committor-program/src/processor.rs @@ -0,0 +1,397 @@ +use borsh::{to_vec, BorshDeserialize}; +use solana_program::hash::Hash; +use solana_program::log::sol_log_64; +use solana_program::program::invoke_signed; +use solana_program::program_error::ProgramError; +use solana_program::sysvar::Sysvar; +use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult}; +use solana_program::{msg, system_instruction}; +use solana_pubkey::Pubkey; + +use crate::error::CommittorError; +use crate::instruction::CommittorInstruction; +use crate::utils::{ + assert_account_unallocated, assert_is_signer, assert_program_id, + close_and_refund_authority, +}; +use crate::{consts, verified_seeds_and_pda, Chunks}; + +pub fn process( + program_id: &Pubkey, + accounts: &[AccountInfo], + instruction_data: &[u8], +) -> ProgramResult { + assert_program_id(program_id)?; + + let ix = CommittorInstruction::try_from_slice(instruction_data)?; + use CommittorInstruction::*; + match ix { + Init { + pubkey, + chunks_account_size, + buffer_account_size, + blockhash, + chunks_bump, + buffer_bump, + chunk_count, + chunk_size, + } => process_init( + program_id, + accounts, + &pubkey, + chunks_account_size, + buffer_account_size, + blockhash, + chunks_bump, + buffer_bump, + chunk_count, + chunk_size, + ), + ReallocBuffer { + pubkey, + buffer_account_size, + blockhash, + buffer_bump, + invocation_count, + } => process_realloc_buffer( + accounts, + &pubkey, + buffer_account_size, + blockhash, + buffer_bump, + invocation_count, + ), + Write { + pubkey, + blockhash, + chunks_bump, + buffer_bump, + offset, + data_chunk, + } => process_write( + accounts, + &pubkey, + offset, + data_chunk, + blockhash, + chunks_bump, + buffer_bump, + ), + Close { + pubkey, + blockhash, + chunks_bump, + buffer_bump, + } => process_close( + accounts, + &pubkey, + blockhash, + chunks_bump, + buffer_bump, + ), + } +} + +// ----------------- +// process_init +// ----------------- +#[allow(clippy::too_many_arguments)] // private + only call site is close +fn process_init( + program_id: &Pubkey, + accounts: &[AccountInfo], + pubkey: &Pubkey, + chunks_account_size: u64, + buffer_account_size: u64, + blockhash: Hash, + chunks_bump: u8, + buffer_bump: u8, + chunk_count: usize, + chunk_size: u16, +) -> ProgramResult { + msg!("Instruction: Init"); + + let [authority_info, chunks_account_info, buffer_account_info, _system_program] = + accounts + else { + msg!("Need the following accounts: [authority, chunks, buffer, system program ], but got {}", accounts.len()); + return Err(ProgramError::NotEnoughAccountKeys); + }; + assert_is_signer(authority_info, "authority")?; + + let chunks_bump = &[chunks_bump]; + let (chunks_seeds, _chunks_pda) = verified_seeds_and_pda!( + chunks, + authority_info, + pubkey, + chunks_account_info, + blockhash, + chunks_bump + ); + + let buffer_bump = &[buffer_bump]; + let (buffer_seeds, _buffer_pda) = verified_seeds_and_pda!( + buffer, + authority_info, + pubkey, + buffer_account_info, + blockhash, + buffer_bump + ); + + assert_account_unallocated(chunks_account_info, "chunks")?; + assert_account_unallocated(buffer_account_info, "buffer")?; + + msg!("Creating Chunks and Buffer accounts"); + + // Create Chunks Account + let ix = system_instruction::create_account( + authority_info.key, + chunks_account_info.key, + solana_program::rent::Rent::get()? + .minimum_balance(chunks_account_size as usize), + chunks_account_size, + program_id, + ); + invoke_signed( + &ix, + &[authority_info.clone(), chunks_account_info.clone()], + &[&chunks_seeds], + )?; + + let initial_alloc_size = std::cmp::min( + buffer_account_size, + consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64, + ); + + // Create Buffer Account + let ix = system_instruction::create_account( + authority_info.key, + buffer_account_info.key, + // NOTE: we fund for the full size to allow realloc without funding more + solana_program::rent::Rent::get()? + .minimum_balance(buffer_account_size as usize), + initial_alloc_size, + program_id, + ); + invoke_signed( + &ix, + &[authority_info.clone(), buffer_account_info.clone()], + &[&buffer_seeds], + )?; + + msg!( + "Initialized and allocated {} of desired {} bytes.", + initial_alloc_size, + buffer_account_size, + ); + + // Initialize Chunks Account + let chunks = Chunks::new(chunk_count, chunk_size); + chunks_account_info + .data + .borrow_mut() + .copy_from_slice(&to_vec(&chunks)?); + + Ok(()) +} + +// ----------------- +// process_realloc_buffer +// ----------------- +fn process_realloc_buffer( + accounts: &[AccountInfo], + pubkey: &Pubkey, + buffer_account_size: u64, + blockhash: Hash, + buffer_bump: u8, + invocation_count: u16, +) -> ProgramResult { + msg!("Instruction: ReallocBuffer {}", invocation_count); + + let [authority_info, buffer_account_info] = accounts else { + msg!( + "Need the following accounts: [authority, buffer ], but got {}", + accounts.len() + ); + return Err(ProgramError::NotEnoughAccountKeys); + }; + + if buffer_account_info.data.borrow().len() >= buffer_account_size as usize { + msg!( + "Buffer account already has {} bytes, no need to realloc", + buffer_account_info.data.borrow().len() + ); + return Ok(()); + } + + assert_is_signer(authority_info, "authority")?; + + let buffer_bump = &[buffer_bump]; + verified_seeds_and_pda!( + buffer, + authority_info, + pubkey, + buffer_account_info, + blockhash, + buffer_bump + ); + + let current_buffer_size = buffer_account_info.data.borrow().len() as u64; + let next_alloc_size = std::cmp::min( + buffer_account_size, + current_buffer_size + + consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64, + ); + + msg!( + "Allocating from {} to {} of desired {} bytes.", + current_buffer_size, + next_alloc_size, + buffer_account_size, + ); + + // NOTE: we fund the account for the full desired account size during init + // Doing this as needed increases the cost for each realloc to 4,959 CUs. + // Reallocing without any rent check/increase uses only 4,025 CUs + // and does not require the system program to be provided. + buffer_account_info.realloc(next_alloc_size as usize, true)?; + + Ok(()) +} + +// ----------------- +// process_write +// ----------------- +fn process_write( + accounts: &[AccountInfo], + pubkey: &Pubkey, + offset: u32, + data_chunk: Vec, + blockhash: Hash, + chunks_bump: u8, + buffer_bump: u8, +) -> ProgramResult { + msg!("Instruction: Write"); + + let [authority_info, chunks_account_info, buffer_account_info] = accounts + else { + msg!("Need the following accounts: [authority, chunks, buffer ], but got {}", accounts.len()); + return Err(ProgramError::NotEnoughAccountKeys); + }; + assert_is_signer(authority_info, "authority")?; + + verify_seeds_and_pdas( + authority_info, + chunks_account_info, + buffer_account_info, + pubkey, + &blockhash, + chunks_bump, + buffer_bump, + )?; + + msg!("Updating Buffer and Chunks accounts [ _, chunks_acc_len, buffer_acc_len, offset, size ]"); + + { + let buffer_data = buffer_account_info.data.borrow(); + let chunks_data = chunks_account_info.data.borrow(); + + // Interpolating lens and offset increases CUs by ~1200. + // So we use this less pretty way since it still gives us the info we need + sol_log_64( + 0, + chunks_data.len() as u64, + buffer_data.len() as u64, + offset as u64, + data_chunk.len() as u64, + ); + + if offset as usize + data_chunk.len() > buffer_data.len() { + let err = CommittorError::OffsetChunkOutOfRange( + data_chunk.len(), + offset, + buffer_data.len(), + ); + msg!("ERR: {}", err); + return Err(err.into()); + } + } + + let mut buffer = buffer_account_info.data.borrow_mut(); + buffer[offset as usize..offset as usize + data_chunk.len()] + .copy_from_slice(&data_chunk); + + let mut chunks_data = chunks_account_info.data.borrow_mut(); + let mut chunks = Chunks::try_from_slice(&chunks_data)?; + chunks.set_offset(offset as usize)?; + chunks_data.copy_from_slice(&to_vec(&chunks)?); + + Ok(()) +} + +// ----------------- +// process_close +// ----------------- +pub fn process_close( + accounts: &[AccountInfo], + pubkey: &Pubkey, + blockhash: Hash, + chunks_bump: u8, + buffer_bump: u8, +) -> ProgramResult { + msg!("Instruction: Close"); + + let [authority_info, chunks_account_info, buffer_account_info] = accounts + else { + msg!("Need the following accounts: [authority, chunks, buffer ], but got {}", accounts.len()); + return Err(ProgramError::NotEnoughAccountKeys); + }; + assert_is_signer(authority_info, "authority")?; + + verify_seeds_and_pdas( + authority_info, + chunks_account_info, + buffer_account_info, + pubkey, + &blockhash, + chunks_bump, + buffer_bump, + )?; + + msg!("Closing Chunks and Buffer accounts"); + close_and_refund_authority(authority_info, chunks_account_info)?; + close_and_refund_authority(authority_info, buffer_account_info)?; + + Ok(()) +} + +fn verify_seeds_and_pdas( + authority_info: &AccountInfo, + chunks_account_info: &AccountInfo, + buffer_account_info: &AccountInfo, + pubkey: &Pubkey, + blockhash: &Hash, + chunks_bump: u8, + buffer_bump: u8, +) -> ProgramResult { + let chunks_bump = &[chunks_bump]; + let (_chunks_seeds, _chunks_pda) = verified_seeds_and_pda!( + chunks, + authority_info, + pubkey, + chunks_account_info, + blockhash, + chunks_bump + ); + + let buffer_bump = &[buffer_bump]; + let (_buffer_seeds, _buffer_pda) = verified_seeds_and_pda!( + buffer, + authority_info, + pubkey, + buffer_account_info, + blockhash, + buffer_bump + ); + Ok(()) +} diff --git a/magicblock-committor-program/src/state/changeset.rs b/magicblock-committor-program/src/state/changeset.rs new file mode 100644 index 000000000..4e52869c8 --- /dev/null +++ b/magicblock-committor-program/src/state/changeset.rs @@ -0,0 +1,498 @@ +use std::collections::{HashMap, HashSet}; + +use borsh::{BorshDeserialize, BorshSerialize}; +use solana_account::{Account, AccountSharedData, ReadableAccount}; +use solana_program::clock::Slot; +use solana_pubkey::Pubkey; + +use super::{ + changeset_chunks::{ChangesetChunks, ChangesetChunksIter}, + chunks::Chunks, +}; + +// ----------------- +// ChangedAccount +// ----------------- +pub type ChangedBundle = Vec<(Pubkey, ChangedAccount)>; + +#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Clone, Debug)] +pub enum ChangedAccount { + Full { + lamports: u64, + data: Vec, + /// The original owner of the delegated account on chain + owner: Pubkey, + /// This id will be the same for accounts that need to be committed together atomically + /// For single commit accounts it is still set for consistency + bundle_id: u64, + }, + // NOTE: placeholder for later without breaking existing + // buffers + Diff, +} + +#[derive(Debug, Default, Clone, PartialEq, Eq)] +pub struct ChangedAccountMeta { + /// The on chain and ephemeral address of the delegated account + pub pubkey: Pubkey, + /// The lamports the account holds in the ephemeral + pub lamports: u64, + /// The original owner of the delegated account on chain + pub owner: Pubkey, + /// This id will be the same for accounts that need to be committed together atomically + /// For single commit accounts it is still set for consistency + pub bundle_id: u64, +} + +impl From<(&Pubkey, &ChangedAccount)> for ChangedAccountMeta { + fn from((pubkey, changed_account): (&Pubkey, &ChangedAccount)) -> Self { + match changed_account { + ChangedAccount::Full { + lamports, + owner, + bundle_id, + .. + } => Self { + pubkey: *pubkey, + lamports: *lamports, + owner: *owner, + bundle_id: *bundle_id, + }, + ChangedAccount::Diff => { + unreachable!("We don't yet support account diffs") + } + } + } +} + +impl From<(Account, u64)> for ChangedAccount { + fn from((account, bundle_id): (Account, u64)) -> Self { + Self::Full { + lamports: account.lamports, + // NOTE: the owner of the account in the ephemeral is set to the original account owner + owner: account.owner, + data: account.data, + bundle_id, + } + } +} + +impl From<(AccountSharedData, u64)> for ChangedAccount { + fn from((value, bundle_id): (AccountSharedData, u64)) -> Self { + Self::Full { + lamports: value.lamports(), + owner: *value.owner(), + data: value.data().to_vec(), + bundle_id, + } + } +} + +impl ChangedAccount { + pub(crate) fn into_inner(self) -> (u64, Pubkey, Vec, u64) { + use ChangedAccount::*; + match self { + Full { + lamports, + owner, + data, + bundle_id, + } => (lamports, owner, data, bundle_id), + Diff => unreachable!("We don't yet support account diffs"), + } + } + + pub fn lamports(&self) -> u64 { + match self { + Self::Full { lamports, .. } => *lamports, + Self::Diff => unreachable!("We don't yet support account diffs"), + } + } + + pub fn data(&self) -> &[u8] { + match self { + Self::Full { data, .. } => data, + Self::Diff => unreachable!("We don't yet support account diffs"), + } + } + + pub fn owner(&self) -> Pubkey { + match self { + Self::Full { owner, .. } => *owner, + Self::Diff => unreachable!("We don't yet support account diffs"), + } + } + + pub fn bundle_id(&self) -> u64 { + match self { + Self::Full { bundle_id, .. } => *bundle_id, + Self::Diff => unreachable!("We don't yet support account diffs"), + } + } +} + +// ----------------- +// ChangeSet +// ----------------- + +/// This is data structure which holds the account changes to commit to chain. +/// Locally it will be filled with the changes to commit. +/// On chain it is initialized as empty at first and then is filled from the +/// local changeset via multiple transactions. +/// A related [Chunks] account is used in order to track which changes have been +/// applied successfully. +#[derive(Debug, Default, Clone, PartialEq, Eq)] +pub struct Changeset { + /// The accounts that should be updated + pub accounts: HashMap, + /// The ephemeral slot at which those changes were requested + pub slot: Slot, + /// The accounts that should be undelegated after they were committed + pub accounts_to_undelegate: HashSet, +} + +/// The meta data of the changeset which can be used to capture information about +/// the changeset before transferring ownership. Createing this metadata is +/// a lot cheaper than copying the entire changeset which includes the accounts data. +/// Thus it can be used to capture information to include with error responses. +#[derive(Debug, Default, Clone, PartialEq, Eq)] +pub struct ChangesetMeta { + /// The accounts that should be updated + pub accounts: Vec, + /// The ephemeral slot at which those changes were requested + pub slot: Slot, + /// The accounts that should be undelegated after they were committed + pub accounts_to_undelegate: HashSet, +} + +impl ChangesetMeta { + /// Separates information per account including the following: + /// - account commit metadata + /// - slot at which commit was requested + /// - if the account should be undelegated after it was committed + pub fn into_account_infos(self) -> Vec<(ChangedAccountMeta, Slot, bool)> { + self.accounts + .into_iter() + .map(|account| { + let undelegate = + self.accounts_to_undelegate.contains(&account.pubkey); + (account, self.slot, undelegate) + }) + .collect() + } +} + +impl From<&Changeset> for ChangesetMeta { + fn from(changeset: &Changeset) -> Self { + let accounts = changeset + .accounts + .iter() + .map(ChangedAccountMeta::from) + .collect(); + Self { + accounts, + slot: changeset.slot, + accounts_to_undelegate: changeset.accounts_to_undelegate.clone(), + } + } +} + +#[derive(Debug, Default, Clone, PartialEq, Eq)] +pub struct ChangesetBundles { + /// The bundles, each of which needs to be committed atomically + pub bundles: Vec, + /// The ephemeral slot at which those changes were requested + pub slot: Slot, + /// The accounts that should be undelegated after they were committed + pub accounts_to_undelegate: HashSet, +} + +impl Changeset { + /// Adds an account to the change set. + /// If it already exists, it will be replaced, thus the caller needs + /// to ensure that conflicting changes are added in the right order, i.e. + /// the last update needs to be added last. + /// + /// - **pubkey** public key of the account + /// - **account** account to add + /// + /// *returns* true if the account was already present and was replaced + pub fn add>( + &mut self, + pubkey: Pubkey, + account: T, + ) -> bool { + self.accounts.insert(pubkey, account.into()).is_some() + } + + /// This method should be called for all accounts that we want to + /// undelegate after committing them. + pub fn request_undelegation(&mut self, pubkey: Pubkey) { + self.accounts_to_undelegate.insert(pubkey); + } + + /// When we're ready to commit this changeset we convert it into + /// a [CommitableChangeSet] which allows to commit the changes in chunks. + pub fn into_committables(self, chunk_size: u16) -> Vec { + self.accounts + .into_iter() + .map(|(pubkey, acc)| { + let (lamports, owner, data, bundle_id) = acc.into_inner(); + CommitableAccount::new( + pubkey, + owner, + data, + lamports, + chunk_size, + self.slot, + self.accounts_to_undelegate.contains(&pubkey), + bundle_id, + ) + }) + .collect::>() + } + + pub fn account_keys(&self) -> Vec<&Pubkey> { + self.accounts.keys().collect() + } + + pub fn undelegate_keys(&self) -> Vec<&Pubkey> { + self.accounts_to_undelegate.iter().collect() + } + + pub fn owners(&self) -> HashMap { + self.accounts + .iter() + .map(|(pubkey, account)| (*pubkey, account.owner())) + .collect() + } + + /// Splits the accounts into bundles that need to be committed together + /// keeping each bundle as small as possible. + /// Accounts without a bundle id each get their own bundle here. + /// The return value returns info about accounts needing to be delegated and + /// the slot at which the changeset was created. + pub fn into_small_changeset_bundles(self) -> ChangesetBundles { + let mut bundles: HashMap = HashMap::new(); + let accounts_to_undelegate = self.accounts_to_undelegate; + let slot = self.slot; + for (pubkey, account) in self.accounts.into_iter() { + bundles + .entry(account.bundle_id()) + .or_default() + .push((pubkey, account)); + } + let bundles = bundles.into_values().collect::>(); + + ChangesetBundles { + bundles, + slot, + accounts_to_undelegate, + } + } + + pub fn is_empty(&self) -> bool { + self.accounts.is_empty() + } + + pub fn len(&self) -> usize { + self.accounts.len() + } + + pub fn overlaps(change_sets: &[&Self]) -> Vec { + let mut overlapping = HashSet::new(); + for change_set in change_sets { + for (pubkey, _) in change_set.accounts.iter() { + if overlapping.contains(pubkey) { + continue; + } + for other_change_set in change_sets { + if other_change_set == change_set { + continue; + } + if other_change_set.accounts.contains_key(pubkey) { + overlapping.insert(*pubkey); + } + } + } + } + overlapping.into_iter().collect() + } + + pub fn contains(&self, pubkey: &Pubkey) -> bool { + self.accounts.contains_key(pubkey) + } +} + +// ----------------- +// CommitableChangeSet +// ----------------- +/// There is one committable per account that we are trying to commit +#[derive(Debug)] +pub struct CommitableAccount { + /// The on chain address of the account + pub pubkey: Pubkey, + /// The original owner of the delegated account on chain + pub delegated_account_owner: Pubkey, + /// The account data to commit + pub data: Vec, + /// The lamports that the account holds in the ephemeral + pub lamports: u64, + /// Keep track of which part of the account data has been committed + chunks: Chunks, + /// The size of each data chunk that we send to fill the buffer + chunk_size: u16, + /// The ephemeral slot at which those changes were requested + pub slot: Slot, + /// If we also undelegate the account after committing it + pub undelegate: bool, + /// This id will be the same for accounts that need to be committed together atomically + /// For single commit accounts it is still set for consistency + pub bundle_id: u64, +} + +impl CommitableAccount { + #[allow(clippy::too_many_arguments)] // internal API + pub(crate) fn new( + pubkey: Pubkey, + delegated_account_owner: Pubkey, + data: Vec, + lamports: u64, + chunk_size: u16, + slot: Slot, + undelegate: bool, + bundle_id: u64, + ) -> Self { + let len = data.len(); + let chunk_count = if chunk_size == 0 { + // Special case for when the commit info is handled without chunking + 1 + } else { + let count = len / chunk_size as usize; + if len % chunk_size as usize > 0 { + count + 1 + } else { + count + } + }; + Self { + pubkey, + delegated_account_owner, + data, + lamports, + chunk_size, + chunks: Chunks::new(chunk_count, chunk_size), + slot, + undelegate, + bundle_id, + } + } + + /// Iterates all chunks of data no matter if they were committed or not. + /// Thus only use this the very first time when trying to commit all chunks. + pub fn iter_all(&self) -> ChangesetChunksIter<'_> { + ChangesetChunks::new(&self.chunks, self.chunk_size).iter(&self.data) + } + + /// Iterates all chunks of data that have not been committed yet. + /// Use this to discover chunks that failed to commit. + pub fn iter_missing(&self) -> ChangesetChunksIter<'_> { + ChangesetChunks::new(&self.chunks, self.chunk_size) + .iter_missing(&self.data) + } + + /// When all chunks were committed we query the chain to see which commits + /// actually landed. + /// We then update the chunks here in order to allow to retry the missing + /// chunks via [Self::iter_missing]. + pub fn set_chunks(&mut self, chunks: Chunks) { + self.chunks = chunks; + } + + /// The total size of the data that we we will commit. + /// Use this to initialize the empty account on chain. + pub fn size(&self) -> usize { + self.data.len() + } + + pub fn chunk_size(&self) -> u16 { + self.chunk_size + } + + pub fn chunk_count(&self) -> usize { + self.chunks.count() + } + + pub fn has_data(&self) -> bool { + !self.data.is_empty() + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_committing_changeset() { + let mut changeset = Changeset::default(); + let pubkey = Pubkey::new_unique(); + let owner = Pubkey::new_unique(); + let changed_account = ChangedAccount::Full { + lamports: 5_000, + owner, + data: vec![5; 547], + bundle_id: 1, + }; + changeset.add(pubkey, changed_account.clone()); + + // The below results in a buffer of 547 bytes and we split it into 14 chunks + let commitable = &mut changeset.into_committables(547 / 14)[0]; + eprintln!("SIZE: {}", commitable.size()); + assert_eq!(commitable.chunk_size(), 39); + assert_eq!(commitable.chunk_count(), 15); + assert_eq!(commitable.iter_all().count(), 15); + + // 1. Try to commit all chunks into a buffer simulating that some fail + let mut tgt_buf = vec![0u8; commitable.size()]; + let mut chunks = + Chunks::new(commitable.chunk_count(), commitable.chunk_size()); + + for chunk in commitable.iter_all() { + let idx = chunk.chunk_idx(); + // Skip the some chunks to simulate transactions not landing + if idx == 7 || idx == 8 || idx == 12 { + continue; + } + + chunks.set_idx(idx as usize); + + let start = chunk.offset; + for (i, d) in chunk.data_chunk.into_iter().enumerate() { + tgt_buf[start as usize + i] = d; + } + } + + // 2. Update the chunks we were able to commit + // We will get this updated data from chain as each commit landing will + // also update the chunks account + commitable.set_chunks(chunks.clone()); + assert_eq!(commitable.iter_missing().count(), 3); + + // 3. Retry the missing chunks + for chunk in commitable.iter_missing() { + chunks.set_idx(chunk.chunk_idx() as usize); + + let start = chunk.offset; + for (i, d) in chunk.data_chunk.into_iter().enumerate() { + tgt_buf[start as usize + i] = d; + } + } + + commitable.set_chunks(chunks); + assert_eq!(commitable.iter_missing().count(), 0); + + // 4. Ensure that the entire account data was committed + let (_, _, data, _) = changed_account.into_inner(); + assert_eq!(tgt_buf, data); + } +} diff --git a/magicblock-committor-program/src/state/changeset_chunks.rs b/magicblock-committor-program/src/state/changeset_chunks.rs new file mode 100644 index 000000000..990f366c0 --- /dev/null +++ b/magicblock-committor-program/src/state/changeset_chunks.rs @@ -0,0 +1,165 @@ +use std::collections::HashSet; + +use super::chunks::Chunks; +use borsh::{BorshDeserialize, BorshSerialize}; + +/// A chunk of change set data that we want to apply to the on chain +/// [ChangeSet] buffer +#[derive(Debug, Default, BorshSerialize, BorshDeserialize)] +pub struct ChangesetChunk { + // u32 is sufficient since the buffer size is limited and we will + // never exceed the u32 max value with an offset we need to address + // u32 max: 4_294_967_295 + // max offset ~10_000_660 + pub offset: u32, + pub data_chunk: Vec, + // chunk size can never exceed the ix max size which is well below u16::MAX (65_535) + #[borsh(skip)] + chunk_size: u16, +} + +impl From<(&[u8], u32, u16)> for ChangesetChunk { + fn from((data, offset, chunk_size): (&[u8], u32, u16)) -> Self { + let end = { + let end = (offset + chunk_size as u32) as usize; + // For the last chunk we might have less data than the chunk size left + end.min(data.len()) + }; + Self { + offset, + data_chunk: data[offset as usize..end].to_vec(), + chunk_size, + } + } +} + +impl ChangesetChunk { + /// The index that the chunk will has in the [Chunks] tracker. + pub fn chunk_idx(&self) -> u32 { + self.offset / self.chunk_size as u32 + } +} + +/// This is a helper struct which is never stored anywhere, but merely +/// combines the [Chunks] and [ChangeSetChunks::chunk_size] in order +/// to provide convenience methods. +pub struct ChangesetChunks<'chunks> { + /// The size of each data chunk that we send to fill the buffer. + /// It is a u16 since u16 max (65,535) is much larger than the max packet size (1,280) + chunk_size: u16, + /// Keeping track of which chunks have been delivered + chunks: &'chunks Chunks, +} + +impl<'chunks> ChangesetChunks<'chunks> { + pub fn new(chunks: &'chunks Chunks, chunk_size: u16) -> Self { + Self { chunks, chunk_size } + } + + fn assert_sizes(&self, data: &[u8]) { + let chunks_len = self.chunks.count() * self.chunk_size as usize; + assert!( + data.len() < chunks_len, + "data.len() ({}) >= chunks_len ({})", + data.len(), + chunks_len + ); + assert!( + chunks_len < data.len() + self.chunk_size as usize, + "chunks_len ({}) >= data.len() + chunk_size ({})", + chunks_len, + data.len() + self.chunk_size as usize + ); + } + + pub fn iter<'data>( + &'chunks self, + data: &'data [u8], + ) -> ChangesetChunksIter<'data> { + self.assert_sizes(data); + ChangesetChunksIter::new( + data, + self.chunk_size, + self.chunks.count(), + None, + ) + } + + pub fn iter_missing<'data>( + &self, + data: &'data [u8], + ) -> ChangesetChunksIter<'data> { + self.assert_sizes(data); + ChangesetChunksIter::new( + data, + self.chunk_size, + self.chunks.count(), + Some(self.chunks.get_missing_chunks()), + ) + } +} + +pub struct ChangesetChunksIter<'data> { + /// The data from which to extract chunks + data: &'data [u8], + /// Size of each chunk + chunk_size: u16, + /// Total number of chunks in the data + chunk_count: usize, + /// If set, only include chunks that are in the filter + filter: Option>, + /// Current index of the iterator + idx: usize, +} + +impl<'data> ChangesetChunksIter<'data> { + pub fn new( + data: &'data [u8], + chunk_size: u16, + chunk_count: usize, + filter: Option>, + ) -> Self { + Self { + data, + chunk_size, + chunk_count, + filter, + idx: 0, + } + } +} + +impl Iterator for ChangesetChunksIter<'_> { + type Item = ChangesetChunk; + + fn next(&mut self) -> Option { + // Skip all chunks that are not in the filter + if let Some(filter) = &self.filter { + while self.idx < self.chunk_count { + if filter.contains(&self.idx) { + break; + } + self.idx += 1; + } + } + + if self.idx >= self.chunk_count { + return None; + } + + let offset = self.idx * self.chunk_size as usize; + assert!( + offset < self.data.len(), + "offset out of bounds {} >= {}", + offset, + self.data.len() + ); + + let chunk = + ChangesetChunk::from((self.data, offset as u32, self.chunk_size)); + + self.idx += 1; + + Some(chunk) + } +} diff --git a/magicblock-committor-program/src/state/chunks.rs b/magicblock-committor-program/src/state/chunks.rs new file mode 100644 index 000000000..b68c2a26a --- /dev/null +++ b/magicblock-committor-program/src/state/chunks.rs @@ -0,0 +1,235 @@ +use borsh::{BorshDeserialize, BorshSerialize}; +use std::{collections::HashSet, fmt}; + +use crate::{ + consts, + error::{CommittorError, CommittorResult}, +}; + +const BIT_FIELD_SIZE: usize = 8; + +/// A bitfield based implementation to keep track of which chunks have been delivered. +/// This is much more memory efficient than a Vec which uses 1 byte per value. +/// [https://doc.rust-lang.org/reference/type-layout.html#r-layout.primitive.size] +#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)] +pub struct Chunks { + /// The bitfields tracking chunk state. + bits: Vec, + /// The tracking capacity which is + /// ```rust + /// let capacity = bits.len() * BIT_FIELD_SIZE + /// ``` + /// The amount of tracked chunks could be a bit smaller as it might only use + /// part of the last bit in [Chunks::bits]. + /// This count gives that smaller amount. + count: usize, + /// The size of chunks that we are tracking. + chunk_size: u16, +} + +impl fmt::Display for Chunks { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + for (idx, bit) in self.bits.iter().enumerate() { + if idx % 8 == 0 { + write!(f, "\n{:05}: ", idx * BIT_FIELD_SIZE)?; + } + let bit = format!("{:08b}", bit); + let bit = bit.chars().rev().collect::(); + // add space after 4 bits + let (bit1, bit2) = bit.split_at(4); + write!(f, "{} {} ", bit1, bit2)?; + } + Ok(()) + } +} + +impl Chunks { + pub fn new(chunk_count: usize, chunk_size: u16) -> Self { + // SAFETY: this is a bug and we need to crash and burn + assert!( + Self::bytes_for_count_len(chunk_count) + < consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as usize, + "Size ({}) needed to track {} chunks is too large track and would require to realloc. Max allowed is {} bytes", + Self::bytes_for_count_len(chunk_count), + chunk_count, + consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE + ); + Self { + bits: vec![0; Self::bits_for_count_len(chunk_count)], + count: chunk_count, + chunk_size, + } + } + + fn bits_for_count_len(count: usize) -> usize { + count / BIT_FIELD_SIZE + 1 + } + + pub fn bytes_for_count_len(count: usize) -> usize { + // bits: Vec, + Self::bits_for_count_len(count) * std::mem::size_of::() + // count: usize, + + std::mem::size_of::() + // chunk_size: u16, + + std::mem::size_of::() + } + + /// Returns `true` if the chunk at index has been delivered + pub fn get_idx(&self, idx: usize) -> bool { + if idx >= self.count { + return false; + } + let vec_idx = idx / BIT_FIELD_SIZE; + let bit_idx = idx % BIT_FIELD_SIZE; + (self.bits[vec_idx] & (1 << bit_idx)) != 0 + } + + /// Sets the chunk at index to `true` denoting that it has been delivered + pub(super) fn set_idx(&mut self, idx: usize) { + if idx < self.count { + let vec_idx = idx / BIT_FIELD_SIZE; + let bit_idx = idx % BIT_FIELD_SIZE; + self.bits[vec_idx] |= 1 << bit_idx; + } + } + + pub fn set_offset(&mut self, offset: usize) -> CommittorResult<()> { + if offset % self.chunk_size as usize != 0 { + return Err(CommittorError::OffsetMustBeMultipleOfChunkSize( + offset, + self.chunk_size, + )); + } + let idx = offset / self.chunk_size as usize; + self.set_idx(idx); + Ok(()) + } + + pub fn get_offset(&self, offset: usize) -> CommittorResult { + if offset % self.chunk_size as usize != 0 { + return Err(CommittorError::OffsetMustBeMultipleOfChunkSize( + offset, + self.chunk_size, + )); + } + let idx = offset / self.chunk_size as usize; + Ok(self.get_idx(idx)) + } + + pub fn count(&self) -> usize { + self.count + } + + pub fn chunk_size(&self) -> u16 { + self.chunk_size + } + + pub fn get_missing_chunks(&self) -> HashSet { + (0..self.count).filter(|&i| !self.get_idx(i)).collect() + } + + pub fn is_complete(&self) -> bool { + self.get_missing_chunks().is_empty() + } +} + +impl From<(Vec, u16)> for Chunks { + fn from((vec, chunk_size): (Vec, u16)) -> Self { + let bits = vec![0; vec.len() / BIT_FIELD_SIZE + 1]; + let mut chunks = Self { + bits, + count: vec.len(), + chunk_size, + }; + for (i, &d) in vec.iter().enumerate() { + if d { + chunks.set_idx(i); + } + } + chunks + } +} + +#[cfg(test)] +mod test { + use super::*; + + impl Chunks { + pub(super) fn iter(&self) -> ChunksIter { + ChunksIter { + chunks: self, + idx: 0, + } + } + } + + pub(super) struct ChunksIter<'a> { + chunks: &'a Chunks, + idx: usize, + } + + impl Iterator for ChunksIter<'_> { + type Item = bool; + fn next(&mut self) -> Option { + if self.idx < self.chunks.count { + let idx = self.idx; + self.idx += 1; + Some(self.chunks.get_idx(idx)) + } else { + None + } + } + } + + const CHUNK_SIZE: u16 = 128; + + #[test] + fn test_chunks_iter() { + let chunks = vec![true, false, false, false]; + let chunks = Chunks::from((chunks, CHUNK_SIZE)); + let vec = chunks.iter().collect::>(); + assert_eq!(vec, vec![true, false, false, false]); + } + + #[test] + fn test_chunks_set_get_idx() { + let chunks = vec![false; 12]; + let mut chunks = Chunks::from((chunks, CHUNK_SIZE)); + chunks.set_idx(0); + chunks.set_idx(10); + + assert!(chunks.get_idx(0)); + assert!(!chunks.get_idx(1)); + assert!(chunks.get_idx(10)); + + let vec = chunks.iter().collect::>(); + #[rustfmt::skip] + assert_eq!( + vec, + vec![ + true, false, false, false, false, false, false, false, + false, false, true, false + ] + ); + } + + #[test] + fn test_chunks_set_get_idx_large() { + let chunks = vec![false; 2048]; + let mut chunks = Chunks::from((chunks, CHUNK_SIZE)); + chunks.set_idx(99); + chunks.set_idx(1043); + + assert!(!chunks.get_idx(0)); + assert!(!chunks.get_idx(1)); + assert!(chunks.get_idx(99)); + assert!(!chunks.get_idx(1042)); + assert!(chunks.get_idx(1043)); + assert!(!chunks.get_idx(1044)); + + assert!(!chunks.get_idx(2048)); + assert!(!chunks.get_idx(2049)); + + assert_eq!(chunks.iter().count(), 2048); + } +} diff --git a/magicblock-committor-program/src/state/mod.rs b/magicblock-committor-program/src/state/mod.rs new file mode 100644 index 000000000..e14a7e4cb --- /dev/null +++ b/magicblock-committor-program/src/state/mod.rs @@ -0,0 +1,3 @@ +pub(crate) mod changeset; +pub(crate) mod changeset_chunks; +pub(crate) mod chunks; diff --git a/magicblock-committor-program/src/utils/account.rs b/magicblock-committor-program/src/utils/account.rs new file mode 100644 index 000000000..e794106f1 --- /dev/null +++ b/magicblock-committor-program/src/utils/account.rs @@ -0,0 +1,26 @@ +use solana_program::msg; +use solana_program::program_error::ProgramError; +use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult}; + +pub fn close_and_refund_authority( + authority: &AccountInfo, + account: &AccountInfo, +) -> ProgramResult { + // Realloc the account data to len 0 to avoid refunding attacks, i.e. keeping + // the account around in an instruction that is appended as part of this + // transaction + // https://www.helius.dev/blog/a-hitchhikers-guide-to-solana-program-security + account.realloc(0, false)?; + + // Transfer all lamports to authority + **authority.lamports.borrow_mut() = authority + .lamports() + .checked_add(account.lamports()) + .ok_or_else(|| { + msg!("Overflow when refunding authority"); + ProgramError::ArithmeticOverflow + })?; + **account.lamports.borrow_mut() = 0; + + Ok(()) +} diff --git a/magicblock-committor-program/src/utils/asserts.rs b/magicblock-committor-program/src/utils/asserts.rs new file mode 100644 index 000000000..838d139b3 --- /dev/null +++ b/magicblock-committor-program/src/utils/asserts.rs @@ -0,0 +1,60 @@ +use solana_program::pubkey::Pubkey; +use solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, msg, + program_error::ProgramError, +}; + +pub fn assert_keys_equal String>( + provided_key: &Pubkey, + expected_key: &Pubkey, + get_msg: F, +) -> ProgramResult { + if provided_key.ne(expected_key) { + msg!("Err: {}", get_msg()); + msg!("Err: provided {} expected {}", provided_key, expected_key); + Err(ProgramError::Custom(1)) + } else { + Ok(()) + } +} + +pub fn assert_account_unallocated( + account: &AccountInfo, + account_label: &str, +) -> ProgramResult { + if account.data.borrow().len() != 0 { + msg!( + "Err: account '{}' ({}) was already initialized", + account_label, + account.key + ); + Err(ProgramError::AccountAlreadyInitialized) + } else { + Ok(()) + } +} + +pub fn assert_is_signer( + account: &AccountInfo, + account_label: &str, +) -> ProgramResult { + if !account.is_signer { + msg!( + "Err: account '{}' ({}) should be signer", + account_label, + account.key + ); + Err(ProgramError::MissingRequiredSignature) + } else { + Ok(()) + } +} + +pub fn assert_program_id(program_id: &Pubkey) -> ProgramResult { + if program_id != &crate::id() { + msg!("ERR: invalid program id"); + Err(ProgramError::IncorrectProgramId) + } else { + Ok(()) + } +} diff --git a/magicblock-committor-program/src/utils/mod.rs b/magicblock-committor-program/src/utils/mod.rs new file mode 100644 index 000000000..cb8e597cd --- /dev/null +++ b/magicblock-committor-program/src/utils/mod.rs @@ -0,0 +1,15 @@ +mod account; +mod asserts; +pub use account::*; +pub use asserts::*; + +#[macro_export] +macro_rules! compute { + ($msg:expr=> $($tt:tt)*) => { + ::solana_program::msg!(concat!($msg, " {")); + ::solana_program::log::sol_log_compute_units(); + $($tt)* + ::solana_program::log::sol_log_compute_units(); + ::solana_program::msg!(concat!(" } // ", $msg)); + }; +} diff --git a/magicblock-committor-program/tests/prog_init_write_and_close.rs b/magicblock-committor-program/tests/prog_init_write_and_close.rs new file mode 100644 index 000000000..e5448095d --- /dev/null +++ b/magicblock-committor-program/tests/prog_init_write_and_close.rs @@ -0,0 +1,346 @@ +use borsh::{to_vec, BorshDeserialize}; +use magicblock_committor_program::{ + instruction::{ + create_init_ix, create_realloc_buffer_ixs, CreateInitIxArgs, + CreateReallocBufferIxArgs, + }, + instruction_chunks::chunk_realloc_ixs, + ChangedAccount, Changeset, Chunks, +}; +use solana_program_test::*; +use solana_pubkey::Pubkey; +use solana_sdk::{ + blake3::HASH_BYTES, hash::Hash, native_token::LAMPORTS_PER_SOL, + signer::Signer, transaction::Transaction, +}; + +macro_rules! exec { + ($banks_client:ident, $ix:expr, $auth:ident, $latest_blockhash:ident) => {{ + let mut transaction = + Transaction::new_with_payer($ix, Some(&$auth.pubkey())); + transaction.sign(&[$auth.insecure_clone()], $latest_blockhash); + $banks_client + .process_transaction(transaction) + .await + .unwrap(); + }}; +} + +macro_rules! get_chunks { + ($banks_client:expr, $chunks_pda:expr) => {{ + let chunks_data = $banks_client + .get_account($chunks_pda) + .await + .unwrap() + .unwrap() + .data; + Chunks::try_from_slice(&chunks_data).unwrap() + }}; +} + +macro_rules! get_buffer_data { + ($banks_client:expr, $buffer_pda:expr) => {{ + $banks_client + .get_account($buffer_pda) + .await + .unwrap() + .unwrap() + .data + }}; +} + +#[tokio::test] +async fn test_init_write_and_close_small_single_account() { + let mut changeset = Changeset::default(); + changeset.add( + Pubkey::new_unique(), + ChangedAccount::Full { + owner: Pubkey::new_unique(), + lamports: LAMPORTS_PER_SOL, + data: vec![1; 500], + bundle_id: 1, + }, + ); + init_write_and_close(changeset).await; +} + +const MULTIPLE_ITER: u64 = 3; + +#[tokio::test] +async fn test_init_write_and_close_small_changeset() { + let mut changeset = Changeset::default(); + for i in 1..MULTIPLE_ITER { + changeset.add( + Pubkey::new_unique(), + ChangedAccount::Full { + owner: Pubkey::new_unique(), + lamports: i, + data: vec![i as u8; 500], + bundle_id: 1, + }, + ); + } + init_write_and_close(changeset).await; +} + +#[tokio::test] +async fn test_init_write_and_close_large_changeset() { + let mut changeset = Changeset::default(); + for i in 1..MULTIPLE_ITER { + let pubkey = Pubkey::new_unique(); + changeset.add( + pubkey, + ChangedAccount::Full { + owner: Pubkey::new_unique(), + lamports: 1000 + i, + data: vec![i as u8; i as usize * 500], + bundle_id: 1, + }, + ); + if i % 2 == 0 { + changeset.request_undelegation(pubkey) + } + } + init_write_and_close(changeset).await; +} + +#[tokio::test] +async fn test_init_write_and_close_very_large_changeset() { + let mut changeset = Changeset::default(); + for i in 1..MULTIPLE_ITER { + let pubkey = Pubkey::new_unique(); + changeset.add( + pubkey, + ChangedAccount::Full { + owner: Pubkey::new_unique(), + lamports: 1000 + i, + data: vec![i as u8; i as usize * 5_000], + bundle_id: 1, + }, + ); + if i % 2 == 0 { + changeset.request_undelegation(pubkey) + } + } + init_write_and_close(changeset).await; +} + +#[tokio::test] +async fn test_init_write_and_close_extremely_large_changeset() { + let mut changeset = Changeset::default(); + for i in 1..MULTIPLE_ITER { + let pubkey = Pubkey::new_unique(); + changeset.add( + pubkey, + ChangedAccount::Full { + owner: Pubkey::new_unique(), + lamports: 1000 + i, + data: vec![i as u8; i as usize * 50_000], + bundle_id: 1, + }, + ); + if i % 2 == 0 { + changeset.request_undelegation(pubkey) + } + } + init_write_and_close(changeset).await; +} + +#[tokio::test] +async fn test_init_write_and_close_insanely_large_changeset() { + let mut changeset = Changeset::default(); + for i in 1..MULTIPLE_ITER { + let pubkey = Pubkey::new_unique(); + changeset.add( + pubkey, + ChangedAccount::Full { + owner: Pubkey::new_unique(), + lamports: 1000 + i, + data: vec![i as u8; i as usize * 90_000], + bundle_id: 1, + }, + ); + if i % 2 == 0 { + changeset.request_undelegation(pubkey) + } + } + init_write_and_close(changeset).await; +} + +async fn init_write_and_close(changeset: Changeset) { + let program_id = &magicblock_committor_program::id(); + + let (banks_client, auth, _) = ProgramTest::new( + "committor_program", + *program_id, + processor!(magicblock_committor_program::process), + ) + .start() + .await; + + let ephem_blockhash = Hash::from([1; HASH_BYTES]); + + let chunk_size = 439 / 14; + let commitables = changeset.into_committables(chunk_size); + for commitable in commitables.iter() { + let chunks = + Chunks::new(commitable.chunk_count(), commitable.chunk_size()); + + // Initialize the Changeset on chain + let (chunks_pda, buffer_pda) = { + let chunks_account_size = to_vec(&chunks).unwrap().len() as u64; + let (init_ix, chunks_pda, buffer_pda) = + create_init_ix(CreateInitIxArgs { + authority: auth.pubkey(), + pubkey: commitable.pubkey, + chunks_account_size, + buffer_account_size: commitable.size() as u64, + blockhash: ephem_blockhash, + chunk_count: commitable.chunk_count(), + chunk_size: commitable.chunk_size(), + }); + let realloc_ixs = + create_realloc_buffer_ixs(CreateReallocBufferIxArgs { + authority: auth.pubkey(), + pubkey: commitable.pubkey, + buffer_account_size: commitable.size() as u64, + blockhash: ephem_blockhash, + }); + + let ix_chunks = chunk_realloc_ixs(realloc_ixs, Some(init_ix)); + for ixs in ix_chunks { + let latest_blockhash = + banks_client.get_latest_blockhash().await.unwrap(); + exec!(banks_client, &ixs, auth, latest_blockhash); + } + + (chunks_pda, buffer_pda) + }; + + let chunks = get_chunks!(&banks_client, chunks_pda); + for i in 0..chunks.count() { + assert!(!chunks.get_idx(i)); + } + assert!(!chunks.is_complete()); + + let latest_blockhash = + banks_client.get_latest_blockhash().await.unwrap(); + + // Write the first chunk + { + let first_chunk = &commitable.iter_all().next().unwrap(); + let write_ix = magicblock_committor_program::instruction::create_write_ix( + magicblock_committor_program::instruction::CreateWriteIxArgs { + authority: auth.pubkey(), + pubkey: commitable.pubkey, + offset: first_chunk.offset, + data_chunk: first_chunk.data_chunk.clone(), + blockhash: ephem_blockhash, + }, + ); + exec!(banks_client, &[write_ix], auth, latest_blockhash); + + let chunks = get_chunks!(&banks_client, chunks_pda); + assert_eq!(chunks.count(), commitable.chunk_count()); + assert_eq!(chunks.chunk_size(), commitable.chunk_size()); + assert!(chunks.get_idx(0)); + for i in 1..chunks.count() { + assert!(!chunks.get_idx(i)); + } + assert!(!chunks.is_complete()); + + let buffer_data = get_buffer_data!(&banks_client, buffer_pda); + assert_eq!( + buffer_data[0..first_chunk.data_chunk.len()], + first_chunk.data_chunk + ); + } + + // Write third chunk + { + let third_chunk = &commitable.iter_all().nth(2).unwrap(); + let write_ix = magicblock_committor_program::instruction::create_write_ix( + magicblock_committor_program::instruction::CreateWriteIxArgs { + authority: auth.pubkey(), + pubkey: commitable.pubkey, + offset: third_chunk.offset, + data_chunk: third_chunk.data_chunk.clone(), + blockhash: ephem_blockhash, + }, + ); + exec!(banks_client, &[write_ix], auth, latest_blockhash); + + let chunks = get_chunks!(&banks_client, chunks_pda); + assert!(chunks.get_idx(0)); + assert!(!chunks.get_idx(1)); + assert!(chunks.get_idx(2)); + for i in 3..chunks.count() { + assert!(!chunks.get_idx(i)); + } + assert!(!chunks.is_complete()); + + let buffer_data = get_buffer_data!(&banks_client, buffer_pda); + assert_eq!( + buffer_data[third_chunk.offset as usize + ..third_chunk.offset as usize + + third_chunk.data_chunk.len()], + third_chunk.data_chunk + ); + } + + // Write the remaining chunks + { + for chunk in commitable.iter_missing() { + let latest_blockhash = + banks_client.get_latest_blockhash().await.unwrap(); + let write_ix = magicblock_committor_program::instruction::create_write_ix( + magicblock_committor_program::instruction::CreateWriteIxArgs { + authority: auth.pubkey(), + pubkey: commitable.pubkey, + offset: chunk.offset, + data_chunk: chunk.data_chunk.clone(), + blockhash: ephem_blockhash, + }, + ); + exec!(banks_client, &[write_ix], auth, latest_blockhash); + } + + let chunks = get_chunks!(&banks_client, chunks_pda); + for i in 0..chunks.count() { + assert!(chunks.get_idx(i)); + } + assert!(chunks.is_complete()); + + let buffer = get_buffer_data!(&banks_client, buffer_pda); + assert_eq!(buffer, commitable.data); + } + + // Close both accounts + { + let latest_blockhash = + banks_client.get_latest_blockhash().await.unwrap(); + + // Normally this instruction would be part of a transaction that processes + // the change set to update the corresponding accounts + let close_ix = magicblock_committor_program::instruction::create_close_ix( + magicblock_committor_program::instruction::CreateCloseIxArgs { + authority: auth.pubkey(), + pubkey: commitable.pubkey, + blockhash: ephem_blockhash, + }, + ); + exec!(banks_client, &[close_ix], auth, latest_blockhash); + + assert!(banks_client + .get_account(chunks_pda) + .await + .unwrap() + .is_none()); + assert!(banks_client + .get_account(buffer_pda) + .await + .unwrap() + .is_none()); + } + } +} diff --git a/magicblock-committor-program/tests/prog_security.rs b/magicblock-committor-program/tests/prog_security.rs new file mode 100644 index 000000000..12690ca08 --- /dev/null +++ b/magicblock-committor-program/tests/prog_security.rs @@ -0,0 +1,10 @@ +// TODO: add tests here that check that this program is secure +// - authority must sign +// - refund attack on close does not succeed +// - invalid PDAs are detected +// - invalid authority is detected (not matching PDAs derived from it) +#[tokio::test] +#[ignore] +async fn test_todo_security_tests() { + panic!("Implement security tests"); +} diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml new file mode 100644 index 000000000..bd00cb159 --- /dev/null +++ b/magicblock-committor-service/Cargo.toml @@ -0,0 +1,47 @@ +[package] +name = "magicblock-committor-service" +version.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true +license.workspace = true +edition.workspace = true + +[dependencies] +base64 = { workspace = true } +bincode = { workspace = true } +borsh = { workspace = true } +log = { workspace = true } +magicblock-committor-program = { workspace = true, features = [ + "no-entrypoint", +] } +magicblock-delegation-program = { workspace = true, features = [ + "no-entrypoint", +] } +magicblock-rpc-client = { workspace = true } +magicblock-table-mania = { workspace = true } +rusqlite = { workspace = true } +solana-account = { workspace = true } +solana-pubkey = { workspace = true } +solana-rpc-client = { workspace = true } +solana-rpc-client-api = { workspace = true } +solana-sdk = { workspace = true } +solana-transaction-status-client-types = { workspace = true } +static_assertions = { workspace = true } +thiserror = { workspace = true } +tokio = { workspace = true } +tokio-util = { workspace = true } + +[dev-dependencies] +env_logger = { workspace = true } +lazy_static = { workspace = true } +magicblock-table-mania = { workspace = true, features = [ + "randomize_lookup_table_slot", +] } +# program-flexi-counter = { workspace = true, features = ["no-entrypoint"] } +tokio = { workspace = true, features = ["rt", "macros"] } + +[features] +default = [] +test_table_close = [] +dev-context-only-utils = [] diff --git a/magicblock-committor-service/src/bundle_strategy.rs b/magicblock-committor-service/src/bundle_strategy.rs new file mode 100644 index 000000000..0f7a0f3bb --- /dev/null +++ b/magicblock-committor-service/src/bundle_strategy.rs @@ -0,0 +1,205 @@ +use std::collections::HashMap; + +use log::*; + +use crate::CommitInfo; + +/// Tries to merge bundles into chunks to leverage the max amount of commits +/// we can have in a single transaction. +pub(crate) fn efficient_bundle_chunks( + mut bundles: HashMap>, + max_per_chunk: usize, +) -> Vec> { + let lens = bundles + .iter() + .map(|(id, commits)| Len { + id: *id, + len: commits.len(), + }) + .collect::>(); + + let chunked_ids = efficient_merge_strategy(lens, max_per_chunk); + + let mut chunked_bundles = Vec::new(); + for chunk in chunked_ids { + let mut bundle_chunk = Vec::::new(); + for id in chunk { + if let Some(bundles) = bundles.remove(&id) { + bundle_chunk.extend(bundles); + } else { + debug_assert!(false, "BUG: bundle not found for id {}", id); + continue; + } + } + chunked_bundles.push(bundle_chunk); + } + + debug_assert!(bundles.is_empty()); + + chunked_bundles +} + +#[derive(PartialEq, Eq, Debug, Clone, Copy)] +struct Len { + id: u64, + len: usize, +} + +/// Returns the most efficient merge strategy for the given lens and max size. +/// WARN: Requires that no len is larger than max_size, otherwise this method will +/// get stuck +fn efficient_merge_strategy( + mut lens: Vec, + max_size: usize, +) -> Vec> { + // NOTE: crash in dev, use escape hatch in release + debug_assert!(lens.iter().all(|len| len.len <= max_size)); + + for len in lens.iter() { + if len.len > max_size { + // NOTE: This is an escape hatch, if we have a len that is larger + // than the max size since we can't merge it. + // This is caused by a programmer error in the calling code. + // It will most likely cause an issue higher in the call stack + // but handling it this way is better than crashing or getting + // stuck. + error!( + "BUG: len {} is too large for the max_size {}", + len.len, max_size + ); + return lens.iter().map(|len| vec![len.id]).collect(); + } + } + + lens.sort_by_key(|len| len.len); + + let mut chunks: Vec> = Vec::new(); + let Some(next_len) = lens.pop() else { + return vec![]; + }; + let mut current_chunk = vec![next_len.id]; + let mut current_size = next_len.len; + 'outer: loop { + let mut remaining_lens = vec![]; + for len in lens.iter().rev() { + if current_size + len.len <= max_size { + current_chunk.push(len.id); + current_size += len.len; + } else { + remaining_lens.push(*len); + continue; + } + } + + lens = lens + .drain(..) + .filter(|len| remaining_lens.contains(len)) + .collect(); + + if lens.is_empty() { + chunks.push(current_chunk); + break; + } + + if lens + .first() + .map(|len| current_size < len.len) + .unwrap_or(false) + { + continue 'outer; + } + + // If we have no more lens to add to the current chunk create a new one + chunks.push(current_chunk); + + // No more lens to process, we are done with the entire process + let Some(next_len) = lens.pop() else { + break 'outer; + }; + current_chunk = vec![next_len.id]; + current_size = next_len.len; + } + + chunks +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_efficient_merge_strategy() { + let lens = vec![ + Len { id: 1, len: 1 }, + Len { id: 2, len: 2 }, + Len { id: 3, len: 3 }, + Len { id: 4, len: 4 }, + Len { id: 5, len: 5 }, + Len { id: 6, len: 6 }, + Len { id: 7, len: 7 }, + Len { id: 8, len: 8 }, + Len { id: 9, len: 9 }, + Len { id: 10, len: 10 }, + ]; + + let res = efficient_merge_strategy(lens.clone(), 10); + assert_eq!( + res, + vec![ + vec![10], + vec![9, 1], + vec![8, 2], + vec![7, 3], + vec![6, 4], + vec![5] + ] + ); + + let res = efficient_merge_strategy(lens.clone(), 20); + assert_eq!(res, vec![vec![10, 9, 1], vec![8, 7, 5], vec![6, 4, 3, 2]]); + + let lens = vec![ + Len { id: 1, len: 1 }, + Len { id: 2, len: 2 }, + Len { id: 3, len: 3 }, + Len { id: 4, len: 4 }, + Len { id: 5, len: 5 }, + Len { id: 6, len: 6 }, + Len { id: 7, len: 7 }, + Len { id: 8, len: 8 }, + ]; + let res = efficient_merge_strategy(lens.clone(), 8); + assert_eq!( + res, + vec![vec![8], vec![7, 1], vec![6, 2], vec![5, 3], vec![4]] + ); + let lens = vec![ + Len { id: 1, len: 1 }, + Len { id: 2, len: 2 }, + Len { id: 3, len: 2 }, + Len { id: 4, len: 2 }, + Len { id: 5, len: 2 }, + Len { id: 6, len: 6 }, + Len { id: 7, len: 6 }, + Len { id: 8, len: 8 }, + ]; + let res = efficient_merge_strategy(lens.clone(), 8); + assert_eq!(res, vec![vec![8], vec![7, 5], vec![6, 4], vec![3, 2, 1]]); + + let lens = vec![ + Len { id: 1, len: 1 }, + Len { id: 3, len: 2 }, + Len { id: 4, len: 2 }, + Len { id: 5, len: 2 }, + Len { id: 6, len: 6 }, + Len { id: 7, len: 6 }, + Len { id: 8, len: 8 }, + Len { id: 9, len: 8 }, + ]; + let res = efficient_merge_strategy(lens.clone(), 8); + assert_eq!( + res, + vec![vec![9], vec![8], vec![7, 5], vec![6, 4], vec![3, 1]] + ); + } +} diff --git a/magicblock-committor-service/src/bundles.rs b/magicblock-committor-service/src/bundles.rs new file mode 100644 index 000000000..a030842f8 --- /dev/null +++ b/magicblock-committor-service/src/bundles.rs @@ -0,0 +1,273 @@ +use crate::{bundle_strategy::efficient_bundle_chunks, CommitInfo}; +use std::collections::HashMap; + +#[derive(Debug, Default)] +pub struct BundleChunksResult { + /// The valid chunks + pub chunks: Vec>, + /// Commit infos that were not included in any chunk since not all infos in + /// a bundle could fit into a single chunk. + /// key: bundle_id + /// value: commit infos + pub unchunked: HashMap>, +} + +/// Creates chunks that respect the following requirements: +/// 1. A chunk cannot be larger than [max_per_chunk]. +/// 2. All commit infos with the same bundle_id must be in the same chunk. +pub(crate) fn bundle_chunks( + mut commit_infos: Vec, + max_per_chunk: usize, +) -> BundleChunksResult { + if commit_infos.is_empty() { + return BundleChunksResult::default(); + } + + // Group commit infos by bundle_id + let mut bundles: HashMap> = HashMap::new(); + let mut not_bundled: Vec = Vec::new(); + for commit_info in commit_infos.drain(..) { + bundles + .entry(commit_info.bundle_id()) + .or_default() + .push(commit_info); + } + + // Remove bundles that are too large to fit into a single chunk + let (bundles, unbundled) = bundles.into_iter().fold( + (HashMap::new(), HashMap::new()), + |(mut bundles, mut unbundled), (key, bundle)| { + if bundle.len() > max_per_chunk { + unbundled.insert(key, bundle); + } else { + bundles.insert(key, bundle); + } + (bundles, unbundled) + }, + ); + + // Merge small bundles + let mut chunks = efficient_bundle_chunks(bundles, max_per_chunk); + + // Add any commits that were not bundled to any of the bundles that still + // have some room + for chunk in chunks.iter_mut() { + let remaining_space = max_per_chunk - chunk.len(); + if remaining_space > 0 { + let range_end = remaining_space.min(not_bundled.len()); + chunk.extend(&mut not_bundled.drain(..range_end)); + } + } + + // If we still have unbundled commits then add chunks for those + while !not_bundled.is_empty() { + let range_end = (max_per_chunk).min(not_bundled.len()); + chunks.push(not_bundled.drain(..range_end).collect()); + } + + BundleChunksResult { + chunks, + unchunked: unbundled, + } +} + +/// Use this for operations on commit infos that don't have to run atomically for a bundle. +/// As an example closing buffers needed for the commit can be done without respecting +/// bundles. +pub(crate) fn bundle_chunks_ignoring_bundle_id( + commit_infos: &[CommitInfo], + max_per_chunk: usize, +) -> BundleChunksResult { + if commit_infos.is_empty() { + return BundleChunksResult::default(); + } + let chunks = commit_infos + .chunks(max_per_chunk) + .map(|chunk| chunk.to_vec()) + .collect::>(); + + BundleChunksResult { + chunks, + unchunked: HashMap::new(), + } +} + +#[cfg(test)] +mod test { + use super::*; + use solana_sdk::hash::Hash; + use solana_sdk::pubkey::Pubkey; + use std::collections::HashSet; + + fn commit_info(bundle_id: u64) -> crate::CommitInfo { + CommitInfo::BufferedDataAccount { + pubkey: Pubkey::new_unique(), + delegated_account_owner: Pubkey::new_unique(), + slot: 0, + ephemeral_blockhash: Hash::new_unique(), + undelegate: false, + buffer_pda: Pubkey::new_unique(), + chunks_pda: Pubkey::new_unique(), + commit_state: Pubkey::new_unique(), + lamports: 0, + bundle_id, + finalize: false, + } + } + + macro_rules! chunk_and_verify { + ($commit_infos:ident, $max_per_chunk:expr) => {{ + let res = bundle_chunks($commit_infos.clone(), $max_per_chunk); + + // 1. All commit infos are accounted for + let bundled_commit_infos = + res.chunks.iter().flatten().cloned().collect::>(); + let unbundled_commit_infos = res + .unchunked + .values() + .flatten() + .cloned() + .collect::>(); + + for commit_info in $commit_infos { + assert!( + bundled_commit_infos.contains(&commit_info), + "{:#?} was not bundled in {:#?}", + commit_info, + bundled_commit_infos + ); + } + assert!( + unbundled_commit_infos.is_empty(), + "Unbundled: {:#?}", + unbundled_commit_infos + ); + + // 2. Chunk size is within limits + for chunk in res.chunks.iter() { + assert!(chunk.len() <= $max_per_chunk); + } + + // 3. All commit infos with the same bundle_id are in the same chunk + // If a chunk has a bundle id then no other chunk should have it + let bundle_ids = bundled_commit_infos + .iter() + .map(|commit_info| commit_info.bundle_id()) + .collect::>(); + for id in bundle_ids { + let mut count = 0; + for chunk in res.chunks.iter() { + let mut in_chunk = false; + for commit_info in chunk { + if commit_info.bundle_id() == id { + in_chunk = true + } + } + if in_chunk { + count += 1; + } + } + assert_eq!( + count, 1, + "Bundle id {} is in {} chunks. {:#?}", + id, count, res.chunks + ); + } + res + }}; + } + + const MAX_PER_CHUNK: usize = 3; + + #[test] + fn test_empty_bundle() { + let res = bundle_chunks(Vec::new(), MAX_PER_CHUNK); + assert!(res.chunks.is_empty()); + assert!(res.unchunked.is_empty()); + } + + #[test] + fn test_single_bundle_single_commit() { + let commit_infos = vec![commit_info(0)]; + chunk_and_verify!(commit_infos, MAX_PER_CHUNK); + } + + #[test] + fn test_single_bundle() { + let commit_infos = vec![commit_info(0), commit_info(0), commit_info(0)]; + chunk_and_verify!(commit_infos, MAX_PER_CHUNK); + } + + #[test] + fn test_single_bundle_too_large() { + let commit_infos = vec![ + commit_info(0), + commit_info(0), + commit_info(0), + commit_info(0), + ]; + let res = bundle_chunks(commit_infos.clone(), MAX_PER_CHUNK); + assert!(res.chunks.is_empty()); + assert_eq!(res.unchunked.len(), 1); + assert_eq!(res.unchunked.get(&0).unwrap(), &commit_infos); + } + + #[test] + fn test_multiple_bundles() { + let commit_infos = vec![ + // Bundle 0 + commit_info(0), + commit_info(0), + // Bundle 1 + commit_info(1), + commit_info(1), + commit_info(1), + // Bundle 2 + commit_info(2), + commit_info(2), + ]; + chunk_and_verify!(commit_infos, MAX_PER_CHUNK); + } + + #[test] + fn test_multiple_bundles_with_unbundled() { + let commit_infos = vec![ + // Bundle 0 + commit_info(0), + commit_info(0), + // Bundle 1 + commit_info(1), + commit_info(5), + commit_info(1), + commit_info(6), + commit_info(1), + // Bundle 2 + commit_info(2), + commit_info(2), + commit_info(7), + ]; + chunk_and_verify!(commit_infos, MAX_PER_CHUNK); + } + + #[test] + fn test_multiple_bundles_efficiency() { + let commit_infos = vec![ + // Bundle 0 + commit_info(0), + commit_info(0), + commit_info(0), + // Bundle 1 + commit_info(1), + commit_info(1), + commit_info(1), + // Bundle 2 + commit_info(2), + commit_info(2), + // Bundle 3 + commit_info(3), + commit_info(3), + ]; + let res = chunk_and_verify!(commit_infos, 5); + assert_eq!(res.chunks.len(), 2); + } +} diff --git a/magicblock-committor-service/src/commit/commit_using_args.rs b/magicblock-committor-service/src/commit/commit_using_args.rs new file mode 100644 index 000000000..525eb5314 --- /dev/null +++ b/magicblock-committor-service/src/commit/commit_using_args.rs @@ -0,0 +1,299 @@ +use crate::{ + commit::common::{ + get_accounts_to_undelegate, lookup_table_keys, send_and_confirm, + }, + commit_stage::CommitSignatures, + persist::CommitStrategy, + undelegate::undelegate_commitables_ixs, + CommitInfo, +}; + +use dlp::args::CommitStateArgs; +use log::*; +use solana_sdk::hash::Hash; +use std::{collections::HashSet, sync::Arc}; + +use magicblock_committor_program::Changeset; +use solana_sdk::signer::Signer; + +use crate::commit_stage::CommitStage; +use magicblock_rpc_client::MagicBlockSendTransactionConfig; + +use super::CommittorProcessor; + +impl CommittorProcessor { + /// Commits a changeset directly using args to include the commit state + /// - **changeset**: the changeset to commit + /// - **finalize**: whether to finalize the commit + /// - **finalize_separately**: whether to finalize the commit in a separate transaction, if + /// this is `false` we can include the finalize instructions with the process instructions + /// - **ephemeral_blockhash**: the ephemeral blockhash to use for the commit + /// - **latest_blockhash**: the latest blockhash on chain to use for the commit + /// - **use_lookup**: whether to use the lookup table for the instructions + pub async fn commit_changeset_using_args( + me: Arc, + changeset: Changeset, + (finalize, finalize_separately): (bool, bool), + ephemeral_blockhash: Hash, + latest_blockhash: Hash, + use_lookup: bool, + ) -> Vec { + // Each changeset is expected to fit into a single instruction which was ensured + // when splitting the original changeset + + let mut process_ixs = Vec::new(); + let mut finalize_ixs = Vec::new(); + let owners = changeset.owners(); + let accounts_to_undelegate = + get_accounts_to_undelegate(&changeset, finalize); + let commitables = changeset.into_committables(0); + // NOTE: we copy the commitables here in order to return them with an error + // [CommitStage] if needed. Since the data of these accounts is small + // (< 1024 bytes), it is acceptable perf overhead + // Alternatively we could include only metadata for the [CommitStage]. + for commitable in commitables.iter() { + let commit_args = CommitStateArgs { + slot: commitable.slot, + lamports: commitable.lamports, + allow_undelegation: commitable.undelegate, + data: commitable.data.clone(), + }; + + let ix = dlp::instruction_builder::commit_state( + me.authority.pubkey(), + commitable.pubkey, + commitable.delegated_account_owner, + commit_args, + ); + process_ixs.push(ix); + + // We either include the finalize instructions with the process instruction or + // if the strategy builder determined that they wouldn't fit then we run them + // in a separate transaction + if finalize { + let finalize_ix = dlp::instruction_builder::finalize( + me.authority.pubkey(), + commitable.pubkey, + ); + if finalize_separately { + finalize_ixs.push(finalize_ix); + } else { + process_ixs.push(finalize_ix); + } + } + } + + let commit_infos = commitables + .into_iter() + .map(|acc| { + CommitInfo::from_small_data_account( + acc, + ephemeral_blockhash, + finalize, + ) + }) + .collect::>(); + + let committees = commit_infos + .iter() + .map(|x| x.pubkey()) + .collect::>(); + + let table_mania = use_lookup.then(|| me.table_mania.clone()); + let table_mania_setup = table_mania.as_ref().map(|tm| { + let keys = lookup_table_keys(&me.authority, &committees, &owners); + (tm, keys) + }); + + let compute_budget_ixs = me + .compute_budget_config + .args_process_budget() + .instructions(committees.len()); + let process_sig = match send_and_confirm( + me.magicblock_rpc_client.clone(), + me.authority.insecure_clone(), + [compute_budget_ixs, process_ixs].concat(), + "commit changeset using args".to_string(), + Some(latest_blockhash), + MagicBlockSendTransactionConfig::ensure_committed(), + table_mania_setup.clone(), + ) + .await + { + Ok(sig) => sig, + Err(err) => { + error!("Failed to commit changeset using args: {:?}", err); + let strategy = CommitStrategy::args(use_lookup); + let sigs = err.signature().map(|sig| CommitSignatures { + process_signature: sig, + finalize_signature: None, + undelegate_signature: None, + }); + return commit_infos + .into_iter() + .map(|x| { + CommitStage::FailedProcess(( + x, + strategy, + sigs.as_ref().cloned(), + )) + }) + .collect(); + } + }; + + let finalize_sig = if !finalize_ixs.is_empty() { + let table_mania_setup = table_mania.as_ref().map(|tm| { + let keys = + lookup_table_keys(&me.authority, &committees, &owners); + (tm, keys) + }); + let finalize_budget_ixs = me + .compute_budget_config + .finalize_budget() + .instructions(committees.len()); + match send_and_confirm( + me.magicblock_rpc_client.clone(), + me.authority.insecure_clone(), + [finalize_budget_ixs, finalize_ixs].concat(), + "commit changeset using args".to_string(), + Some(latest_blockhash), + MagicBlockSendTransactionConfig::ensure_committed(), + table_mania_setup, + ) + .await + { + Ok(sig) => Some(sig), + Err(err) => { + error!( + "Failed to finalize changeset using args: {:?}", + err + ); + return commit_infos + .into_iter() + .map(|x| { + CommitStage::FailedFinalize(( + x, + CommitStrategy::args(use_lookup), + CommitSignatures { + process_signature: process_sig, + finalize_signature: err.signature(), + undelegate_signature: None, + }, + )) + }) + .collect(); + } + } + } else { + (!finalize_separately).then_some(process_sig) + }; + + trace!( + "Successfully processed {} commit infos via transaction '{}'", + commit_infos.len(), + process_sig + ); + + let undelegate_sig = if let Some(sig) = finalize_sig { + trace!( + "Successfully finalized {} commit infos via transaction '{}'", + commit_infos.len(), + sig + ); + + // If we successfully finalized the commit then we can undelegate accounts + if let Some(accounts) = accounts_to_undelegate { + let accounts_len = accounts.len(); + let undelegate_ixs = match undelegate_commitables_ixs( + &me.magicblock_rpc_client, + me.authority.pubkey(), + accounts, + ) + .await + { + Ok(ixs) => ixs.into_values().collect::>(), + Err(err) => { + error!( + "Failed to prepare accounts undelegation '{}': {:?}", + err, err + ); + return commit_infos + .into_iter() + .map(|x| { + CommitStage::FailedUndelegate(( + x, + CommitStrategy::args(use_lookup), + CommitSignatures { + process_signature: process_sig, + finalize_signature: finalize_sig, + undelegate_signature: err.signature(), + }, + )) + }) + .collect(); + } + }; + let undelegate_budget_ixs = me + .compute_budget_config + .undelegate_budget() + .instructions(accounts_len); + match send_and_confirm( + me.magicblock_rpc_client.clone(), + me.authority.insecure_clone(), + [undelegate_budget_ixs, undelegate_ixs].concat(), + "undelegate committed accounts using args".to_string(), + Some(latest_blockhash), + MagicBlockSendTransactionConfig::ensure_committed(), + table_mania_setup, + ) + .await + { + Ok(sig) => { + trace!("Successfully undelegated accounts via transaction '{}'", sig); + Some(sig) + } + Err(err) => { + error!( + "Failed to undelegate accounts via transaction '{}': {:?}", + err, err + ); + return commit_infos + .into_iter() + .map(|x| { + CommitStage::FailedUndelegate(( + x, + CommitStrategy::args(use_lookup), + CommitSignatures { + process_signature: process_sig, + finalize_signature: finalize_sig, + undelegate_signature: err.signature(), + }, + )) + }) + .collect(); + } + } + } else { + None + } + } else { + None + }; + + commit_infos + .into_iter() + .map(|x| { + CommitStage::Succeeded(( + x, + CommitStrategy::args(use_lookup), + CommitSignatures { + process_signature: process_sig, + finalize_signature: finalize_sig, + undelegate_signature: undelegate_sig, + }, + )) + }) + .collect() + } +} diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs new file mode 100644 index 000000000..4d99ff99d --- /dev/null +++ b/magicblock-committor-service/src/commit/commit_using_buffer.rs @@ -0,0 +1,1028 @@ +use borsh::{to_vec, BorshDeserialize}; +use dlp::pda::commit_state_pda_from_delegated_account; +use log::*; +use magicblock_rpc_client::{ + MagicBlockRpcClientError, MagicBlockRpcClientResult, + MagicBlockSendTransactionConfig, +}; +use solana_pubkey::Pubkey; +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, + time::Duration, +}; +use tokio::task::JoinSet; + +use magicblock_committor_program::{ + instruction::{ + create_init_ix, create_realloc_buffer_ixs, + create_realloc_buffer_ixs_to_add_remaining, create_write_ix, + CreateInitIxArgs, CreateReallocBufferIxArgs, CreateWriteIxArgs, + }, + instruction_chunks::chunk_realloc_ixs, + Changeset, ChangesetChunk, Chunks, CommitableAccount, +}; + +use crate::{ + commit::common::get_accounts_to_undelegate, + commit_stage::CommitSignatures, + error::{CommitAccountError, CommitAccountResult}, + finalize::{ + chunked_ixs_to_finalize_commitables, + ChunkedIxsToFinalizeCommitablesResult, + }, + persist::CommitStrategy, + types::InstructionsKind, + undelegate::{ + chunked_ixs_to_undelegate_commitables, undelegate_commitables_ixs, + }, + CommitInfo, CommitStage, +}; + +use super::{ + common::send_and_confirm, + process_buffers::{ + chunked_ixs_to_process_commitables_and_close_pdas, + ChunkedIxsToProcessCommitablesAndClosePdasResult, + }, + CommittorProcessor, +}; +use solana_sdk::{hash::Hash, instruction::Instruction, signer::Signer}; + +struct NextReallocs { + missing_size: u64, + start_idx: usize, +} + +impl CommittorProcessor { + /// Commits the changeset by initializing the accounts, writing the chunks, + /// and closing the pdas. + /// NOTE: we return no error since the validator would not know how to mitigate + /// the problem. + pub async fn commit_changeset_using_buffers( + processor: Arc, + changeset: Changeset, + finalize: bool, + ephemeral_blockhash: Hash, + use_lookup: bool, + ) -> Vec { + macro_rules! handle_unchunked { + ($unchunked:ident, $commit_stages:ident, $commit_stage:expr) => { + for (bundle_id, commit_infos) in $unchunked.into_iter() { + // The max amount of accounts we can commit and process as part of a single + // transaction is [crate::max_per_transaction::MAX_COMMIT_STATE_AND_CLOSE_PER_TRANSACTION]. + warn!( + "Commit infos for bundle id {} are too many to be processed in a single transaction", + bundle_id + ); + $commit_stages.extend( + commit_infos + .into_iter() + .map($commit_stage), + ); + } + } + } + + let owners = changeset.owners(); + let accounts_len = changeset.account_keys().len(); + let commit_strategy = if use_lookup { + CommitStrategy::FromBufferWithLookupTable + } else { + CommitStrategy::FromBuffer + }; + let accounts_to_undelegate = + get_accounts_to_undelegate(&changeset, finalize); + let results = processor + .prepare_changeset_buffers( + changeset, + ephemeral_blockhash, + commit_strategy, + finalize, + ) + .await; + + let mut commit_stages = vec![]; + + // 1. Init Buffer and Chunks Account + let (mut succeeded_inits, failed_inits): (Vec<_>, Vec<_>) = { + let (succeeded, failed): (Vec<_>, Vec<_>) = + results.into_iter().partition(Result::is_ok); + ( + succeeded + .into_iter() + .map(Result::unwrap) + .collect::>(), + failed + .into_iter() + .map(Result::unwrap_err) + .collect::>(), + ) + }; + + // If we couldn't init the buffers for a specific commit then we're done with it. + for commit_err in failed_inits.into_iter() { + let commit_stage = CommitStage::from(commit_err); + let bundle_id = commit_stage.commit_metadata().bundle_id(); + commit_stages.push(commit_stage); + + // We also need to skip all committables that are in the same bundle as + // a commit we're giving up on. + let (fail_in_order_to_respect_bundle, keep): (Vec<_>, Vec<_>) = + succeeded_inits.drain(..).partition(|commit_info| { + #[allow(clippy::let_and_return)] + let same_bundle = commit_info.bundle_id() == bundle_id; + same_bundle + }); + commit_stages.extend( + fail_in_order_to_respect_bundle.into_iter().map(|x| { + CommitStage::BufferAndChunkFullyInitialized(( + x, + commit_strategy, + )) + }), + ); + succeeded_inits.extend(keep); + } + + // 2. Create chunks of instructions that process the commits and respect desired bundles + let ChunkedIxsToProcessCommitablesAndClosePdasResult { + chunked_ixs, + chunked_close_ixs, + unchunked, + } = chunked_ixs_to_process_commitables_and_close_pdas( + processor.authority.pubkey(), + succeeded_inits.clone(), + use_lookup, + ); + handle_unchunked!( + unchunked, + commit_stages, + CommitStage::PartOfTooLargeBundleToProcess + ); + + // 3. Process all chunks via transactions, one per chunk of instructions + trace!( + "ChunkedIxs: {}", + chunked_ixs + .iter() + .map(|xs| xs + .iter() + .map(|x| x.to_string()) + .collect::>() + .join("\n")) + .collect::>() + .join("]\n\n[\n") + ); + debug_assert_eq!( + chunked_ixs.iter().map(|x| x.len()).sum::() + commit_stages.len(), + accounts_len, + "Sum of instructions and early bail out stages should have one instruction per commmitted account", + ); + + let table_mania = use_lookup.then(|| processor.table_mania.clone()); + let (succeeded_process, failed_process) = processor + .process_ixs_chunks( + chunked_ixs, + chunked_close_ixs, + table_mania.as_ref(), + &owners, + ) + .await; + + commit_stages.extend(failed_process.into_iter().flat_map( + |(sig, xs)| { + let sigs = sig.map(|x| CommitSignatures { + process_signature: x, + finalize_signature: None, + undelegate_signature: None, + }); + xs.into_iter() + .map(|x| { + CommitStage::FailedProcess(( + x, + commit_strategy, + sigs.as_ref().cloned(), + )) + }) + .collect::>() + }, + )); + + let mut processed_commit_infos = vec![]; + let mut processed_signatures = HashMap::new(); + for (sig, commit_infos) in succeeded_process { + if log_enabled!(Level::Trace) { + let kinds = commit_infos + .iter() + .map(|(_, kind)| *kind) + .collect::>(); + let handled = kinds + .iter() + .map(|x| format!("{:?}", x)) + .collect::>() + .join(" | "); + trace!( + "Successfully handled ({}) for {} commit info(s) via transaction '{}'", + handled, + commit_infos.len(), + sig + ); + } + for (commit_info, _) in commit_infos + .into_iter() + .filter(|(_, kind)| kind.is_processing()) + { + let bundle_id = commit_info.bundle_id(); + debug_assert!( + processed_signatures + .get(&bundle_id) + .map(|x| x == &sig) + .unwrap_or(true), + "BUG: Same processed bundle ids should have the same signature" + ); + processed_signatures.insert(bundle_id, sig); + processed_commit_infos.push(commit_info); + } + } + + // 4. Optionally finalize + undelegate all processed commits also respecting bundles + if finalize && !processed_commit_infos.is_empty() { + // 4.1. Create chunks of finalize instructions that fit in a single transaction + let ChunkedIxsToFinalizeCommitablesResult { + chunked_ixs, + unchunked, + } = chunked_ixs_to_finalize_commitables( + processor.authority.pubkey(), + processed_commit_infos, + use_lookup, + ); + handle_unchunked!( + unchunked, + commit_stages, + CommitStage::PartOfTooLargeBundleToFinalize + ); + + // 4.2. Run each finalize chunk in a single transaction + let (succeeded_finalize, failed_finalize): (Vec<_>, Vec<_>) = + processor + .process_ixs_chunks( + chunked_ixs, + None, + table_mania.as_ref(), + &owners, + ) + .await; + commit_stages.extend(failed_finalize.into_iter().flat_map( + |(sig, infos)| { + infos + .into_iter() + .map(|x| { + let bundle_id = x.bundle_id(); + CommitStage::FailedFinalize(( + x, + commit_strategy, + CommitSignatures { + // SAFETY: signatures for all bundles of succeeded process transactions + // have been added above + process_signature: *processed_signatures + .get(&bundle_id) + .unwrap(), + finalize_signature: sig, + undelegate_signature: None, + }, + )) + }) + .collect::>() + }, + )); + + let mut finalized_commit_infos = vec![]; + let mut finalized_signatures = HashMap::new(); + for (sig, commit_infos) in succeeded_finalize { + trace!( + "Successfully finalized {} commit infos via transaction '{}'", + commit_infos.len(), + sig + ); + for (commit_info, kind) in commit_infos.iter() { + debug_assert_eq!( + kind, + &InstructionsKind::Finalize, + "Expecting separate finalize instructions onky" + ); + let bundle_id = commit_info.bundle_id(); + debug_assert!( + finalized_signatures + .get(&bundle_id) + .map(|x| x == &sig) + .unwrap_or(true), + "BUG: Same finalized bundle ids should have the same signature" + ); + + finalized_signatures.insert(bundle_id, sig); + } + let commit_infos = commit_infos + .into_iter() + .map(|(info, _)| info) + .collect::>(); + finalized_commit_infos.extend(commit_infos); + } + // 4.2. Consider undelegation by first dividing finalized accounts into two sets, + let (finalize_and_undelegate, finalize_only) = + finalized_commit_infos + .into_iter() + .partition::, _>(|x| x.undelegate()); + // 4.3.a accounts we don't need to undelegate are done + commit_stages.extend(finalize_only.into_iter().map(|x| { + let bundle_id = x.bundle_id(); + CommitStage::Succeeded(( + x, + commit_strategy, + CommitSignatures { + // SAFETY: signatures for all bundles of succeeded process transactions + // have been added above + process_signature: *processed_signatures + .get(&bundle_id) + .unwrap(), + finalize_signature: finalized_signatures + .get(&bundle_id) + .cloned(), + undelegate_signature: None, + }, + )) + })); + // 4.3.b the other accounts need to be undelegated first + if let Some(accounts) = accounts_to_undelegate { + debug_assert_eq!( + accounts.len(), + finalize_and_undelegate.len(), + "BUG: same amount of accounts to undelegate as to finalize and undelegate" + ); + let undelegate_ixs = match undelegate_commitables_ixs( + &processor.magicblock_rpc_client, + processor.authority.pubkey(), + accounts, + ) + .await + { + Ok(ixs) => Some(ixs), + Err(err) => { + error!( + "Failed to prepare accounts undelegation '{}': {:?}", + err, err + ); + commit_stages.extend( + finalize_and_undelegate.iter().map(|x| { + let bundle_id = x.bundle_id(); + CommitStage::FailedUndelegate(( + x.clone(), + CommitStrategy::args(use_lookup), + CommitSignatures { + // SAFETY: signatures for all bundles of succeeded process transactions + // have been added above + process_signature: + *processed_signatures + .get(&bundle_id) + .unwrap(), + finalize_signature: + finalized_signatures + .get(&bundle_id) + .cloned(), + undelegate_signature: err.signature(), + }, + )) + }), + ); + None + } + }; + if let Some(undelegate_ixs) = undelegate_ixs { + let chunked_ixs = chunked_ixs_to_undelegate_commitables( + undelegate_ixs, + finalize_and_undelegate, + use_lookup, + ); + let (succeeded_undelegate, failed_undelegate): ( + Vec<_>, + Vec<_>, + ) = processor + .process_ixs_chunks( + chunked_ixs, + None, + table_mania.as_ref(), + &owners, + ) + .await; + + commit_stages.extend( + failed_undelegate.into_iter().flat_map( + |(sig, infos)| { + infos + .into_iter() + .map(|x| { + let bundle_id = x.bundle_id(); + CommitStage::FailedUndelegate(( + x, + commit_strategy, + CommitSignatures { + // SAFETY: signatures for all bundles of succeeded process transactions + // have been added above + process_signature: + *processed_signatures + .get(&bundle_id) + .unwrap(), + finalize_signature: + finalized_signatures + .get(&bundle_id) + .cloned(), + undelegate_signature: sig, + }, + )) + }) + .collect::>() + }, + ), + ); + commit_stages.extend( + succeeded_undelegate.into_iter().flat_map( + |(sig, infos)| { + infos + .into_iter() + .map(|(x, _)| { + let bundle_id = x.bundle_id(); + CommitStage::Succeeded(( + x, + commit_strategy, + CommitSignatures { + // SAFETY: signatures for all bundles of succeeded process transactions + // have been added above + process_signature: + *processed_signatures + .get(&bundle_id) + .unwrap(), + finalize_signature: + finalized_signatures + .get(&bundle_id) + .cloned(), + undelegate_signature: Some(sig), + }, + )) + }) + .collect::>() + }, + ), + ); + } + } else { + debug_assert!( + finalize_and_undelegate.is_empty(), + "BUG: We should either have accounts to undelegate or an empty finalize_and_undelegate" + ); + } + } else { + commit_stages.extend(processed_commit_infos.into_iter().map(|x| { + let bundle_id = x.bundle_id(); + CommitStage::Succeeded(( + x, + commit_strategy, + CommitSignatures { + // SAFETY: signatures for all bundles of succeeded process transactions + // have been added above + process_signature: *processed_signatures + .get(&bundle_id) + .unwrap(), + finalize_signature: None, + undelegate_signature: None, + }, + )) + })); + } + + debug_assert_eq!( + accounts_len, + CommitStage::commit_infos(&commit_stages).len(), + "Should have one commit stage per commmitted account ({}) {:#?}", + accounts_len, + commit_stages + ); + + commit_stages + } + + async fn prepare_changeset_buffers( + &self, + changeset: Changeset, + ephemeral_blockhash: Hash, + commit_strategy: CommitStrategy, + finalize: bool, + ) -> Vec> { + let commitables = + changeset.into_committables(crate::consts::MAX_WRITE_CHUNK_SIZE); + let mut join_set: JoinSet> = + JoinSet::new(); + for commitable in commitables { + let me = Arc::new(self.clone()); + join_set.spawn(Self::commit_account( + me, + commitable, + ephemeral_blockhash, + commit_strategy, + finalize, + )); + } + join_set.join_all().await + } + + async fn commit_account( + me: Arc, + mut commitable: CommitableAccount, + ephemeral_blockhash: Hash, + commit_strategy: CommitStrategy, + finalize: bool, + ) -> CommitAccountResult { + let commit_info = if commitable.has_data() { + let chunks = + Chunks::new(commitable.chunk_count(), commitable.chunk_size()); + let chunks_account_size = to_vec(&chunks).unwrap().len() as u64; + + // Initialize the Changeset and Chunks accounts on chain + let buffer_account_size = commitable.size() as u64; + + let (init_ix, chunks_pda, buffer_pda) = + create_init_ix(CreateInitIxArgs { + authority: me.authority.pubkey(), + pubkey: commitable.pubkey, + chunks_account_size, + buffer_account_size, + blockhash: ephemeral_blockhash, + chunk_count: commitable.chunk_count(), + chunk_size: commitable.chunk_size(), + }); + let realloc_ixs = + create_realloc_buffer_ixs(CreateReallocBufferIxArgs { + authority: me.authority.pubkey(), + pubkey: commitable.pubkey, + buffer_account_size, + blockhash: ephemeral_blockhash, + }); + + let commit_info = CommitInfo::BufferedDataAccount { + pubkey: commitable.pubkey, + commit_state: commit_state_pda_from_delegated_account( + &commitable.pubkey, + ), + delegated_account_owner: commitable.delegated_account_owner, + slot: commitable.slot, + ephemeral_blockhash, + undelegate: commitable.undelegate, + chunks_pda, + buffer_pda, + lamports: commitable.lamports, + bundle_id: commitable.bundle_id, + finalize, + }; + + // Even though this transaction also inits the chunks account we check + // that it succeeded by querying the buffer account since this is the + // only of the two that we may have to realloc. + let commit_info = Arc::new( + me.init_accounts( + init_ix, + realloc_ixs, + commitable.pubkey, + &buffer_pda, + buffer_account_size, + ephemeral_blockhash, + commit_info, + commit_strategy, + ) + .await?, + ); + + let mut last_write_chunks_err = None; + if let Err(err) = me + .write_chunks( + commitable.pubkey, + commitable.iter_all(), + ephemeral_blockhash, + ) + .await + { + last_write_chunks_err = Some(err); + }; + + let mut remaining_tries = 10; + const MAX_GET_ACCOUNT_RETRIES: usize = 5; + loop { + let mut acc = None; + let mut last_get_account_err = None; + for _ in 0..MAX_GET_ACCOUNT_RETRIES { + match me + .magicblock_rpc_client + .get_account(&chunks_pda) + .await + { + Ok(Some(x)) => { + acc.replace(x); + break; + } + Ok(None) => { + me.wait_for_account("chunks account", None).await + } + Err(err) => { + me.wait_for_account("chunks account", Some(&err)) + .await; + last_get_account_err.replace(err); + } + } + } + let Some(acc) = acc else { + return Err(CommitAccountError::GetChunksAccount( + last_get_account_err, + commit_info.clone(), + commit_strategy, + )); + }; + let chunks = + Chunks::try_from_slice(&acc.data).map_err(|err| { + CommitAccountError::DeserializeChunksAccount( + err, + commit_info.clone(), + commit_strategy, + ) + })?; + + if chunks.is_complete() { + break; + } + + remaining_tries -= 1; + if remaining_tries == 0 { + return Err( + CommitAccountError::WriteChunksRanOutOfRetries( + last_write_chunks_err, + commit_info.clone(), + commit_strategy, + ), + ); + } + commitable.set_chunks(chunks); + if let Err(err) = me + .write_chunks( + commitable.pubkey, + commitable.iter_missing(), + ephemeral_blockhash, + ) + .await + { + last_write_chunks_err = Some(err); + } + } + commit_info + } else { + Arc::new(CommitInfo::EmptyAccount { + pubkey: commitable.pubkey, + delegated_account_owner: commitable.delegated_account_owner, + slot: commitable.slot, + ephemeral_blockhash, + undelegate: commitable.undelegate, + lamports: commitable.lamports, + bundle_id: commitable.bundle_id, + finalize, + }) + }; + + let commit_info = Arc::::unwrap_or_clone(commit_info); + + Ok(commit_info) + } + + /// Sends init/realloc transactions until the account has the desired size + /// - `init_ix` - the instruction to initialize the buffer and chunk account + /// - `realloc_ixs` - the instructions to realloc the buffer account until it reaches the + /// size needed to store the account's data + /// - `pubkey` - the pubkey of the account whose data we are storing + /// - `buffer_pda` - the address of the account where we buffer the data to be committed + /// - `buffer_account_size` - the size of the buffer account + /// - `ephemeral_blockhash` - the blockhash in the ephemeral at which we are committing + /// - `commit_info` - the commit info to be returned or included in errors + /// - `commit_strategy` - the commit strategy that is used + #[allow(clippy::too_many_arguments)] // private method + async fn init_accounts( + &self, + init_ix: Instruction, + realloc_ixs: Vec, + pubkey: Pubkey, + buffer_pda: &Pubkey, + buffer_account_size: u64, + ephemeral_blockhash: Hash, + commit_info: CommitInfo, + commit_strategy: CommitStrategy, + ) -> CommitAccountResult { + // We cannot allocate more than MAX_INITIAL_BUFFER_SIZE in a single + // instruction. Therefore we append a realloc instruction if the buffer + // is very large. + // init_ixs is the init ix with as many realloc ixs as fit into one tx + // extra_realloc_ixs are the remaining realloc ixs that need to be sent + // in separate transactions + let (init_ix_chunk, extra_realloc_ix_chunks) = { + let mut chunked_ixs = chunk_realloc_ixs(realloc_ixs, Some(init_ix)); + let init_with_initial_reallocs = chunked_ixs.remove(0); + let remaining_reallocs = if chunked_ixs.is_empty() { + None + } else { + Some(chunked_ixs) + }; + (init_with_initial_reallocs, remaining_reallocs) + }; + + debug!( + "Init+Realloc chunk ixs {}, Extra Realloc Chunks {}", + init_ix_chunk.len(), + extra_realloc_ix_chunks.as_ref().map_or(0, |x| x.len()) + ); + + // First ensure that the tx including the init ix lands + let mut init_sig = None; + let mut last_err = None; + const MAX_RETRIES: usize = 2; + 'land_init_transaction: for _ in 0..MAX_RETRIES { + // Only retry the init transaction if it failed to send and confirm + if init_sig.is_none() { + let init_budget_ixs = self + .compute_budget_config + .buffer_init + .instructions(init_ix_chunk.len() - 1); + match send_and_confirm( + self.magicblock_rpc_client.clone(), + self.authority.insecure_clone(), + [init_budget_ixs, init_ix_chunk.clone()].concat(), + "init buffer and chunk account".to_string(), + None, + MagicBlockSendTransactionConfig::ensure_committed(), + None, + ) + .await + { + Err(err) => { + last_err = Some(err); + continue; + } + Ok(sig) => { + init_sig = Some(sig); + } + } + } + + // At this point the transaction was confirmed and we should be able + // to get the initialized pda and chunk account + const MAX_GET_ACCOUNT_RETRIES: usize = 5; + for _ in 0..MAX_GET_ACCOUNT_RETRIES { + match self.magicblock_rpc_client.get_account(buffer_pda).await { + Ok(Some(_)) => { + // The account was initialized + break 'land_init_transaction; + } + Ok(None) => { + self.wait_for_account("buffer account", None).await + } + Err(err) => { + self.wait_for_account("buffer account", Some(&err)) + .await + } + } + } + } // 'land_init_transaction + + if init_sig.is_none() { + let err = last_err + .as_ref() + .map(|x| x.to_string()) + .unwrap_or("Unknown Error".to_string()); + return Err(CommitAccountError::InitBufferAndChunkAccounts( + err, + Box::new(commit_info), + commit_strategy, + )); + } + + // After that we can ensure all extra reallocs in parallel + if let Some(realloc_ixs) = extra_realloc_ix_chunks { + let mut next_reallocs = self + .run_reallocs( + buffer_pda, + realloc_ixs, + buffer_account_size, + buffer_account_size, + 0, + ) + .await; + + if next_reallocs.is_some() { + let args = CreateReallocBufferIxArgs { + authority: self.authority.pubkey(), + pubkey, + buffer_account_size, + blockhash: ephemeral_blockhash, + }; + + while let Some(NextReallocs { + missing_size, + start_idx, + }) = next_reallocs + { + let realloc_ixs = { + let realloc_ixs = + create_realloc_buffer_ixs_to_add_remaining( + &args, + missing_size, + ); + + chunk_realloc_ixs(realloc_ixs, None) + }; + next_reallocs = self + .run_reallocs( + buffer_pda, + realloc_ixs, + buffer_account_size, + missing_size, + start_idx, + ) + .await; + // TODO(thlorenz): give up at some point + } + } + } + + Ok(commit_info) + } + + /// Returns the size that still needs to be allocated after running the instructions + /// along with the idx at which we start (in order to keep increasing the idx of realloc + /// attempt). + /// Returns `None` once the desired size is reached and we're done. + async fn run_reallocs( + &self, + pda: &Pubkey, + realloc_ixs: Vec>, + desired_size: u64, + missing_size: u64, + start_idx: usize, + ) -> Option { + let mut join_set = JoinSet::new(); + let count = realloc_ixs.len(); + let latest_blockhash = + match self.magicblock_rpc_client.get_latest_blockhash().await { + Ok(hash) => hash, + Err(err) => { + error!( + "Failed to get latest blockhash to run reallocs: {:?}", + err + ); + return Some(NextReallocs { + missing_size, + start_idx, + }); + } + }; + for (idx, ixs) in realloc_ixs.into_iter().enumerate() { + let authority = self.authority.insecure_clone(); + let rpc_client = self.magicblock_rpc_client.clone(); + let realloc_budget_ixs = self + .compute_budget_config + .buffer_realloc + .instructions(ixs.len()); + // NOTE: we ignore failures to send/confirm realloc transactions and just + // keep calling [CommittorProcessor::run_reallocs] until we reach the desired size + join_set.spawn(async move { + send_and_confirm( + rpc_client, + authority, + [realloc_budget_ixs, ixs].concat(), + format!( + "realloc buffer account {}/{}", + start_idx + idx, + start_idx + count + ), + Some(latest_blockhash), + MagicBlockSendTransactionConfig::ensure_processed(), + None, + ) + .await + .inspect_err(|err| { + warn!("{:?}", err); + }) + }); + } + join_set.join_all().await; + + match self.magicblock_rpc_client.get_account(pda).await { + Ok(Some(acc)) => { + // Once the account has the desired size we are done + let current_size = acc.data.len(); + if current_size as u64 >= desired_size { + None + } else { + Some(desired_size - current_size as u64) + } + } + // NOTE: if we cannot get the account we must assume that + // the entire size we just tried to alloc is still missing + Ok(None) => { + warn!("buffer account not found"); + Some(missing_size) + } + Err(err) => { + warn!("Failed to get buffer account: {:?}", err); + Some(missing_size) + } + } + .map(|missing_size| NextReallocs { + missing_size, + start_idx: count, + }) + } + + /// Sends a transaction to write each chunk. + /// Initially it gets latest blockhash and errors if that fails. + /// All other errors while sending the transaction are logged and ignored. + /// The chunks whose write transactions failed are expected to be retried in + /// the next run. + /// - `pubkey` - the on chain pubkey of the account whose data we are writing to the buffer + /// - `chunks` - the chunks to write + /// - `ephemeral_blockhash` - the blockhash to use for the transaction + async fn write_chunks>( + &self, + pubkey: Pubkey, + chunks: Iter, + ephemeral_blockhash: Hash, + ) -> MagicBlockRpcClientResult<()> { + let mut join_set = JoinSet::new(); + + let latest_blockhash = + self.magicblock_rpc_client.get_latest_blockhash().await?; + + for chunk in chunks.into_iter() { + let authority = self.authority.insecure_clone(); + let rpc_client = self.magicblock_rpc_client.clone(); + let chunk_bytes = chunk.data_chunk.len(); + let ix = create_write_ix(CreateWriteIxArgs { + authority: authority.pubkey(), + pubkey, + offset: chunk.offset, + data_chunk: chunk.data_chunk, + blockhash: ephemeral_blockhash, + }); + let write_budget_ixs = self + .compute_budget_config + .buffer_write + .instructions(chunk_bytes); + // NOTE: we ignore failures to send/confirm write transactions and just + // keep calling [CommittorProcessor::write_chunks] until all of them are + // written which is verified via the chunks account + join_set.spawn(async move { + send_and_confirm( + rpc_client, + authority, + [write_budget_ixs, vec![ix]].concat(), + format!("write chunk for offset {}", chunk.offset), + Some(latest_blockhash), + // NOTE: We could use `processed` here and wait to get the processed status at + // least which would make things a bit slower. + // However that way we would avoid sending unnecessary transactions potentially + // since we may not see some written chunks yet when we get the chunks account. + MagicBlockSendTransactionConfig::ensure_processed(), + None, + ) + .await + .inspect_err(|err| { + error!("{:?}", err); + }) + }); + } + if log::log_enabled!(log::Level::Trace) { + trace!("Writing {} chunks", join_set.len()); + } + + join_set.join_all().await; + + Ok(()) + } + + async fn wait_for_account( + &self, + account_label: &str, + err: Option<&MagicBlockRpcClientError>, + ) { + let sleep_time_ms = { + if let Some(err) = err { + error!("Failed to {} account: {:?}", account_label, err); + } else { + warn!("Failed to {} account", account_label); + } + 100 + }; + tokio::time::sleep(Duration::from_millis(sleep_time_ms)).await; + } +} diff --git a/magicblock-committor-service/src/commit/committor_processor.rs b/magicblock-committor-service/src/commit/committor_processor.rs new file mode 100644 index 000000000..3e6ea0ab2 --- /dev/null +++ b/magicblock-committor-service/src/commit/committor_processor.rs @@ -0,0 +1,560 @@ +use crate::{ + commit_strategy::{split_changesets_by_commit_strategy, SplitChangesets}, + compute_budget::{ComputeBudget, ComputeBudgetConfig}, + persist::{ + BundleSignatureRow, CommitPersister, CommitStatusRow, CommitStrategy, + }, + pubkeys_provider::provide_committee_pubkeys, + types::InstructionsKind, + CommitInfo, +}; + +use log::*; +use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; +use solana_sdk::{ + commitment_config::CommitmentConfig, hash::Hash, signature::Signature, +}; +use std::{ + collections::{HashMap, HashSet}, + path::Path, + sync::{Arc, Mutex}, +}; + +use magicblock_committor_program::{Changeset, ChangesetMeta}; +use solana_pubkey::Pubkey; +use solana_rpc_client::nonblocking::rpc_client::RpcClient; +use solana_sdk::{signature::Keypair, signer::Signer}; +use tokio::task::JoinSet; + +use crate::{ + commit_stage::CommitStage, config::ChainConfig, + error::CommittorServiceResult, types::InstructionsForCommitable, +}; +use magicblock_rpc_client::{ + MagicBlockSendTransactionConfig, MagicblockRpcClient, +}; + +use super::common::{lookup_table_keys, send_and_confirm}; + +pub(crate) struct CommittorProcessor { + pub(crate) magicblock_rpc_client: MagicblockRpcClient, + pub(crate) table_mania: TableMania, + pub(crate) authority: Keypair, + pub(crate) persister: Arc>, + pub(crate) compute_budget_config: Arc, +} + +impl Clone for CommittorProcessor { + fn clone(&self) -> Self { + Self { + magicblock_rpc_client: self.magicblock_rpc_client.clone(), + table_mania: self.table_mania.clone(), + authority: self.authority.insecure_clone(), + persister: self.persister.clone(), + compute_budget_config: self.compute_budget_config.clone(), + } + } +} + +impl CommittorProcessor { + pub fn try_new

( + authority: Keypair, + persist_file: P, + chain_config: ChainConfig, + ) -> CommittorServiceResult + where + P: AsRef, + { + let rpc_client = RpcClient::new_with_commitment( + chain_config.rpc_uri.to_string(), + CommitmentConfig { + commitment: chain_config.commitment, + }, + ); + let rpc_client = Arc::new(rpc_client); + let magic_block_rpc_client = MagicblockRpcClient::new(rpc_client); + let gc_config = GarbageCollectorConfig::default(); + let table_mania = TableMania::new( + magic_block_rpc_client.clone(), + &authority, + Some(gc_config), + ); + let persister = CommitPersister::try_new(persist_file)?; + Ok(Self { + authority, + magicblock_rpc_client: magic_block_rpc_client, + table_mania, + persister: Arc::new(Mutex::new(persister)), + compute_budget_config: Arc::new(chain_config.compute_budget_config), + }) + } + + pub async fn active_lookup_tables(&self) -> Vec { + self.table_mania.active_table_addresses().await + } + + pub async fn released_lookup_tables(&self) -> Vec { + self.table_mania.released_table_addresses().await + } + + pub fn auth_pubkey(&self) -> Pubkey { + self.authority.pubkey() + } + + pub(crate) async fn reserve_pubkeys( + &self, + pubkeys: HashSet, + ) -> CommittorServiceResult<()> { + Ok(self + .table_mania + .reserve_pubkeys(&self.authority, &pubkeys) + .await?) + } + + pub(crate) async fn release_pubkeys(&self, pubkeys: HashSet) { + self.table_mania.release_pubkeys(&pubkeys).await + } + + pub fn get_commit_statuses( + &self, + reqid: &str, + ) -> CommittorServiceResult> { + let commit_statuses = self + .persister + .lock() + .expect("persister mutex poisoned") + .get_commit_statuses_by_reqid(reqid)?; + Ok(commit_statuses) + } + + pub fn get_signature( + &self, + bundle_id: u64, + ) -> CommittorServiceResult> { + let signatures = self + .persister + .lock() + .expect("persister mutex poisoned") + .get_signature(bundle_id)?; + Ok(signatures) + } + + pub async fn commit_changeset( + &self, + changeset: Changeset, + finalize: bool, + ephemeral_blockhash: Hash, + ) -> Option { + let reqid = match self + .persister + .lock() + .expect("persister mutex poisoned") + .start_changeset(&changeset, ephemeral_blockhash, finalize) + { + Ok(id) => Some(id), + Err(err) => { + // We will still try to perform the commits, but the fact that we cannot + // persist the intent is very serious and we should probably restart the + // valiator + error!( + "DB EXCEPTION: Failed to persist changeset to be committed: {:?}", + err + ); + None + } + }; + let owners = changeset.owners(); + let commit_stages = self + .process_commit_changeset(changeset, finalize, ephemeral_blockhash) + .await; + + // Release pubkeys related to all undelegated accounts from the lookup tables + let releaseable_pubkeys = commit_stages + .iter() + .filter(|x| CommitStage::is_successfully_undelegated(x)) + .flat_map(|x| { + provide_committee_pubkeys(&x.pubkey(), owners.get(&x.pubkey())) + }) + .collect::>(); + self.table_mania.release_pubkeys(&releaseable_pubkeys).await; + + if let Some(reqid) = &reqid { + for stage in commit_stages { + let _ = self.persister + .lock() + .expect("persister mutex poisoned") + .update_status( + reqid, + &stage.pubkey(), + stage.commit_status(), + ).map_err(|err| { + // We log the error here, but there is nothing we can do if we encounter + // a db issue. + error!( + "DB EXCEPTION: Failed to update status of changeset {}: {:?}", + reqid, err + ); + }); + } + } + + reqid + } + + async fn process_commit_changeset( + &self, + changeset: Changeset, + finalize: bool, + ephemeral_blockhash: Hash, + ) -> Vec { + let changeset_meta = ChangesetMeta::from(&changeset); + let SplitChangesets { + args_changeset, + args_including_finalize_changeset, + args_with_lookup_changeset, + args_including_finalize_with_lookup_changeset, + from_buffer_changeset, + from_buffer_with_lookup_changeset, + } = match split_changesets_by_commit_strategy(changeset, finalize) { + Ok(changesets) => changesets, + Err(err) => { + error!("Failed to split changesets: {:?}", err); + return changeset_meta + .into_account_infos() + .into_iter() + .map(CommitStage::SplittingChangesets) + .collect(); + } + }; + + debug_assert!( + finalize + || (args_including_finalize_changeset.is_empty() + && args_including_finalize_with_lookup_changeset + .is_empty()), + "BUG: args including finalize strategies should not be created when not finalizing" + ); + + let mut join_set = JoinSet::new(); + if !args_changeset.is_empty() + || !args_with_lookup_changeset.is_empty() + || !args_including_finalize_changeset.is_empty() + || !args_including_finalize_with_lookup_changeset.is_empty() + { + let latest_blockhash = match self + .magicblock_rpc_client + .get_latest_blockhash() + .await + { + Ok(bh) => bh, + Err(err) => { + error!( + "Failed to get latest blockhash to commit using args: {:?}", + err + ); + let strategy = CommitStrategy::args( + !args_with_lookup_changeset.is_empty() + || !args_including_finalize_with_lookup_changeset + .is_empty(), + ); + return changeset_meta + .into_account_infos() + .into_iter() + .map(|(meta, slot, undelegate)| { + CommitStage::GettingLatestBlockhash(( + meta, slot, undelegate, strategy, + )) + }) + .collect(); + } + }; + + if !args_changeset.is_empty() { + join_set.spawn(Self::commit_changeset_using_args( + Arc::new(self.clone()), + args_changeset, + (finalize, true), + ephemeral_blockhash, + latest_blockhash, + false, + )); + } + + if !args_including_finalize_changeset.is_empty() { + join_set.spawn(Self::commit_changeset_using_args( + Arc::new(self.clone()), + args_including_finalize_changeset, + (finalize, false), + ephemeral_blockhash, + latest_blockhash, + false, + )); + } + + if !args_with_lookup_changeset.is_empty() { + join_set.spawn(Self::commit_changeset_using_args( + Arc::new(self.clone()), + args_with_lookup_changeset, + (finalize, true), + ephemeral_blockhash, + latest_blockhash, + true, + )); + } + + if !args_including_finalize_with_lookup_changeset.is_empty() { + join_set.spawn(Self::commit_changeset_using_args( + Arc::new(self.clone()), + args_including_finalize_with_lookup_changeset, + (finalize, false), + ephemeral_blockhash, + latest_blockhash, + true, + )); + } + } + + if !from_buffer_changeset.is_empty() { + join_set.spawn(Self::commit_changeset_using_buffers( + Arc::new(self.clone()), + from_buffer_changeset, + finalize, + ephemeral_blockhash, + false, + )); + } + if !from_buffer_with_lookup_changeset.is_empty() { + join_set.spawn(Self::commit_changeset_using_buffers( + Arc::new(self.clone()), + from_buffer_with_lookup_changeset, + finalize, + ephemeral_blockhash, + true, + )); + } + + join_set.join_all().await.into_iter().flatten().collect() + } + + pub(crate) async fn process_ixs_chunks( + &self, + ixs_chunks: Vec>, + chunked_close_ixs: Option>>, + table_mania: Option<&TableMania>, + owners: &HashMap, + ) -> ( + Vec<(Signature, Vec<(CommitInfo, InstructionsKind)>)>, + Vec<(Option, Vec)>, + ) { + let latest_blockhash = + match self.magicblock_rpc_client.get_latest_blockhash().await { + Ok(bh) => bh, + Err(err) => { + error!( + "Failed to get latest blockhash to process buffers: {:?}", + err + ); + // If we fail to get this blockhash we need to report all process + // instructions as failed + let commit_infos = ixs_chunks + .into_iter() + .map(|ixs_chunk| { + ( + None::, + ixs_chunk + .into_iter() + .map(|ixs| ixs.commit_info) + .collect::>(), + ) + }) + .collect::>(); + return (vec![], commit_infos); + } + }; + + let mut join_set = JoinSet::new(); + let successes = Arc::< + Mutex)>>, + >::default(); + let failures = + Arc::, Vec)>>>::default(); + for ixs_chunk in ixs_chunks { + let authority = self.authority.insecure_clone(); + let rpc_client = self.magicblock_rpc_client.clone(); + let compute_budget = + self.compute_budget_config.buffer_process_and_close_budget(); + let successes = successes.clone(); + let failures = failures.clone(); + let owners = owners.clone(); + let table_mania = table_mania.cloned(); + join_set.spawn(process_ixs_chunk( + ixs_chunk, + compute_budget, + authority, + rpc_client, + successes, + failures, + table_mania, + owners, + latest_blockhash, + )); + } + join_set.join_all().await; + + if let Some(chunked_close_ixs) = chunked_close_ixs { + if log::log_enabled!(log::Level::Trace) { + let ix_count = + chunked_close_ixs.iter().map(|x| x.len()).sum::(); + trace!( + "Processing {} close instruction chunk(s) with a total of {} instructions", + chunked_close_ixs.len(), + ix_count + ); + } + let latest_blockhash = match self + .magicblock_rpc_client + .get_latest_blockhash() + .await + { + Ok(bh) => Some(bh), + Err(err) => { + // If we fail to close the buffers then the commits were processed and we + // should not retry them, however eventually we'd want to close those buffers + error!( + "Failed to get latest blockhash to close buffer: {:?}", + err + ); + let commit_infos = chunked_close_ixs + .iter() + .map(|ixs_chunk| { + ixs_chunk + .iter() + .map(|ixs| ixs.commit_info.clone()) + .collect::>() + }) + .collect::>(); + error!("Therefore failed to close buffers for the following committed accounts: {:#?}", commit_infos); + None + } + }; + + if let Some(latest_blockhash) = latest_blockhash { + let mut join_set = JoinSet::new(); + let failures = Arc::< + Mutex, Vec)>>, + >::default(); + for ixs_chunk in chunked_close_ixs { + let authority = self.authority.insecure_clone(); + let rpc_client = self.magicblock_rpc_client.clone(); + let table_mania = table_mania.cloned(); + let owners = owners.clone(); + let compute_budget = + self.compute_budget_config.buffer_close_budget(); + // We ignore close successes + let successes = Default::default(); + // We only log close failures since the commit was processed successfully + let failures = failures.clone(); + join_set.spawn(process_ixs_chunk( + ixs_chunk, + compute_budget, + authority, + rpc_client, + successes, + failures, + table_mania, + owners, + latest_blockhash, + )); + } + join_set.join_all().await; + if !failures + .lock() + .expect("close failures mutex poisoned") + .is_empty() + { + error!("Failed to to close some buffers: {:?}", failures); + } + } + } + + let successes = Arc::try_unwrap(successes) + .expect("successes mutex still has multiple owners") + .into_inner() + .expect("successes mutex was poisoned"); + let failures = Arc::try_unwrap(failures) + .expect("failures mutex still has multiple owners") + .into_inner() + .expect("failures mutex was poisoned"); + + (successes, failures) + } +} + +/// Processes a single chunk of instructions, sending them as a transaction. +/// Updates the shared success or failure lists based on the transaction outcome. +#[allow(clippy::type_complexity, clippy::too_many_arguments)] +pub(crate) async fn process_ixs_chunk( + ixs_chunk: Vec, + compute_budget: ComputeBudget, + authority: Keypair, + rpc_client: MagicblockRpcClient, + successes: Arc< + Mutex)>>, + >, + failures: Arc, Vec)>>>, + table_mania: Option, + owners: HashMap, + latest_blockhash: Hash, +) { + let mut ixs = vec![]; + let mut commit_infos = vec![]; + for ix_chunk in ixs_chunk.into_iter() { + ixs.extend(ix_chunk.instructions); + commit_infos.push((ix_chunk.commit_info, ix_chunk.kind)); + } + let ixs_len = ixs.len(); + let table_mania_setup = table_mania.as_ref().map(|table_mania| { + let committees = commit_infos + .iter() + .map(|(x, _)| x.pubkey()) + .collect::>(); + let keys_from_table = + lookup_table_keys(&authority, &committees, &owners); + (table_mania, keys_from_table) + }); + let compute_budget_ixs = compute_budget.instructions(commit_infos.len()); + match send_and_confirm( + rpc_client, + authority, + [compute_budget_ixs, ixs].concat(), + "process commitable and/or close pdas".to_string(), + Some(latest_blockhash), + MagicBlockSendTransactionConfig::ensure_committed(), + table_mania_setup, + ) + .await + { + Ok(sig) => { + successes + .lock() + .expect("ix successes mutex poisoned") + .push((sig, commit_infos)); + } + Err(err) => { + error!( + "Processing {} instructions for {} commit infos {:?}", + ixs_len, + commit_infos.len(), + err + ); + let commit_infos = commit_infos + .into_iter() + .map(|(commit_info, _)| commit_info) + .collect(); + failures + .lock() + .expect("ix failures mutex poisoned") + .push((err.signature(), commit_infos)); + } + } +} diff --git a/magicblock-committor-service/src/commit/common.rs b/magicblock-committor-service/src/commit/common.rs new file mode 100644 index 000000000..c1e4317cb --- /dev/null +++ b/magicblock-committor-service/src/commit/common.rs @@ -0,0 +1,204 @@ +use log::*; +use magicblock_rpc_client::{ + MagicBlockSendTransactionConfig, MagicblockRpcClient, +}; +use magicblock_table_mania::TableMania; +use solana_sdk::{hash::Hash, message::v0::Message, signature::Signature}; +use std::{ + collections::{HashMap, HashSet}, + time::{Duration, Instant}, +}; + +use magicblock_committor_program::Changeset; +use solana_pubkey::Pubkey; +use solana_sdk::{ + instruction::Instruction, message::VersionedMessage, signature::Keypair, + signer::Signer, transaction::VersionedTransaction, +}; + +use crate::{ + error::{CommittorServiceError, CommittorServiceResult}, + pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, +}; + +pub(crate) fn lookup_table_keys( + authority: &Keypair, + committees: &HashSet, + owners: &HashMap, +) -> HashSet { + committees + .iter() + .flat_map(|x| provide_committee_pubkeys(x, owners.get(x))) + .chain(provide_common_pubkeys(&authority.pubkey())) + .collect::>() +} + +/// Returns the pubkeys of the accounts that are marked for undelegation we finalized +/// the commits of those accounts. +/// If we didn't finalize the commits then we cannot yet undelegate those accounts. +/// Returns tuples of the account to undelegate and its original owner +pub(crate) fn get_accounts_to_undelegate( + changeset: &Changeset, + finalize: bool, +) -> Option> { + if finalize { + let vec = changeset.accounts_to_undelegate.iter().flat_map(|x| { + let Some(acc) = changeset.accounts.get(x) else { + warn!("Account ({}) marked for undelegation not found in changeset", x); + return None; + }; + Some((*x, acc.owner())) + }).collect::>(); + (!vec.is_empty()).then_some(vec) + } else { + // if we don't finalize then we can only _mark_ accounts for undelegation + // but cannot run the undelegation instruction itself + None + } +} + +/// Gets the latest blockhash and sends and confirms a transaction with +/// the provided instructions. +/// Uses the commitment provided via the [ChainConfig::commitment] option when checking +/// the status of the transction signature. +/// - **rpc_client** - the rpc client to use +/// - **authority** - the authority to sign the transaction +/// - **ixs** - the instructions to include in the transaction +/// - **task_desc** - a description of the task included in logs +/// - **latest_blockhash** - the latest blockhash to use for the transaction, +/// if not provided it will be queried +/// - **send_config** - the send transaction config to use +/// - **use_table_mania** - whether to use table mania to optimize the size increase due +/// to accounts in the transaction via the use of lookup tables +/// +/// Returns the signature of the transaction. +pub(crate) async fn send_and_confirm( + rpc_client: MagicblockRpcClient, + authority: Keypair, + ixs: Vec, + task_desc: String, + latest_blockhash: Option, + send_config: MagicBlockSendTransactionConfig, + table_mania_setup: Option<(&TableMania, HashSet)>, +) -> CommittorServiceResult { + use CommittorServiceError::*; + // When lots of txs are spawned in parallel we reuse the blockhash + // instead of getting it for each tx + let latest_blockhash = if let Some(blockhash) = latest_blockhash { + blockhash + } else { + rpc_client.get_latest_blockhash().await.inspect_err(|err| { + error!( + "Failed to get latest blockhash to '{}': {:?}", + task_desc, err + ) + })? + }; + + let tables = + if let Some((table_mania, keys_from_tables)) = table_mania_setup { + let start = Instant::now(); + + // NOTE: we assume that all needed pubkeys were reserved earlier + let address_lookup_tables = table_mania + .try_get_active_address_lookup_table_accounts( + &keys_from_tables, + // enough time for init/extend lookup table transaction to complete + Duration::from_secs(50), + // enough time for lookup table to finalize + Duration::from_secs(50), + ) + .await?; + + if log_enabled!(Level::Trace) { + let tables = address_lookup_tables + .iter() + .map(|table| { + format!( + "\n {}: {} addresses", + table.key, + table.addresses.len() + ) + }) + .collect::>() + .join(", "); + trace!( + "Took {}ms to get finalized address lookup table(s) {}", + start.elapsed().as_millis(), + tables + ); + let all_accounts = ixs.iter().flat_map(|ix| { + ix.accounts.iter().map(|x| x.pubkey).clone() + }); + let keys_not_from_table = all_accounts + .filter(|x| !keys_from_tables.contains(x)) + .collect::>(); + trace!( + "{}/{} are provided from lookup tables", + keys_from_tables.len(), + keys_not_from_table.len() + keys_from_tables.len() + ); + trace!( + "The following keys are not:\n{}", + keys_not_from_table + .iter() + .map(|x| format!(" {}", x)) + .collect::>() + .join("\n") + ); + } + + address_lookup_tables + } else { + vec![] + }; + + let versioned_msg = match Message::try_compile( + &authority.pubkey(), + &ixs, + &tables, + latest_blockhash, + ) { + Ok(msg) => msg, + Err(err) => { + return Err( + CommittorServiceError::FailedToCompileTransactionMessage( + task_desc.clone(), + err, + ), + ); + } + }; + let tx = match VersionedTransaction::try_new( + VersionedMessage::V0(versioned_msg), + &[&authority], + ) { + Ok(tx) => tx, + Err(err) => { + return Err(CommittorServiceError::FailedToCreateTransaction( + task_desc.clone(), + err, + )); + } + }; + + let start = Instant::now(); + let res = rpc_client + .send_transaction(&tx, &send_config) + .await + .map_err(|err| { + FailedToSendAndConfirmTransaction(task_desc.clone(), err) + })?; + + trace!( + "Took {}ms to send and confirm transaction with {} instructions", + start.elapsed().as_millis(), + ixs.len() + ); + + if let Some(err) = res.error() { + Err(EncounteredTransactionError(task_desc, err.clone())) + } else { + Ok(res.into_signature()) + } +} diff --git a/magicblock-committor-service/src/commit/mod.rs b/magicblock-committor-service/src/commit/mod.rs new file mode 100644 index 000000000..f14e26aa4 --- /dev/null +++ b/magicblock-committor-service/src/commit/mod.rs @@ -0,0 +1,6 @@ +mod commit_using_args; +mod commit_using_buffer; +mod committor_processor; +mod common; +mod process_buffers; +pub(super) use committor_processor::CommittorProcessor; diff --git a/magicblock-committor-service/src/commit/process_buffers.rs b/magicblock-committor-service/src/commit/process_buffers.rs new file mode 100644 index 000000000..40cb2583c --- /dev/null +++ b/magicblock-committor-service/src/commit/process_buffers.rs @@ -0,0 +1,239 @@ +use std::collections::HashMap; + +use dlp::args::CommitStateFromBufferArgs; +use log::*; +use solana_pubkey::Pubkey; + +use crate::{ + bundles::{bundle_chunks, bundle_chunks_ignoring_bundle_id}, + transactions::{ + close_buffers_ix, process_and_close_ixs, process_commits_ix, + MAX_CLOSE_PER_TX, MAX_CLOSE_PER_TX_USING_LOOKUP, + MAX_PROCESS_AND_CLOSE_PER_TX, + MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP, MAX_PROCESS_PER_TX, + MAX_PROCESS_PER_TX_USING_LOOKUP, + }, + types::{InstructionsForCommitable, InstructionsKind}, + CommitInfo, +}; + +/// Returns instructions to process the commit/delegation request for a commitable. +/// Requires that the [CommitInfo::buffer_pda] holds all data to be committed. +/// It appends another instruction which closes both the [CommitInfo::buffer_pda] +/// and the [CommitInfo::chunks_pda]. +fn process_commitable_and_close_ixs( + validator_auth: Pubkey, + commit_info: CommitInfo, +) -> InstructionsForCommitable { + debug!("Processing commitable: {:?}", commit_info); + let CommitInfo::BufferedDataAccount { + pubkey, + delegated_account_owner, + slot, + ephemeral_blockhash, + undelegate, + buffer_pda, + lamports, + .. + } = &commit_info + else { + panic!("Only data accounts are supported for now"); + }; + + let commit_args = CommitStateFromBufferArgs { + slot: *slot, + lamports: *lamports, + allow_undelegation: *undelegate, + }; + + let instructions = process_and_close_ixs( + validator_auth, + pubkey, + delegated_account_owner, + buffer_pda, + ephemeral_blockhash, + commit_args, + ); + InstructionsForCommitable { + instructions, + commit_info, + kind: InstructionsKind::ProcessAndCloseBuffers, + } +} + +fn close_buffers_separate_ix( + validator_auth: Pubkey, + commit_info: CommitInfo, +) -> InstructionsForCommitable { + debug!("Processing commitable: {:?}", commit_info); + let CommitInfo::BufferedDataAccount { + pubkey, + ephemeral_blockhash, + .. + } = &commit_info + else { + panic!("Only data accounts are supported for now"); + }; + + let close_ix = + close_buffers_ix(validator_auth, pubkey, ephemeral_blockhash); + InstructionsForCommitable { + instructions: vec![close_ix], + commit_info, + kind: InstructionsKind::CloseBuffers, + } +} + +fn process_commitable_separate_ix( + validator_auth: Pubkey, + commit_info: CommitInfo, +) -> InstructionsForCommitable { + let CommitInfo::BufferedDataAccount { + pubkey, + delegated_account_owner, + slot, + undelegate, + buffer_pda, + lamports, + .. + } = &commit_info + else { + panic!("Only data accounts are supported for now"); + }; + + let commit_args = CommitStateFromBufferArgs { + slot: *slot, + lamports: *lamports, + allow_undelegation: *undelegate, + }; + + let process_ix = process_commits_ix( + validator_auth, + pubkey, + delegated_account_owner, + buffer_pda, + commit_args, + ); + InstructionsForCommitable { + instructions: vec![process_ix], + commit_info: commit_info.clone(), + kind: InstructionsKind::Process, + } +} + +pub(crate) struct ChunkedIxsToProcessCommitablesAndClosePdasResult { + /// Chunked instructions to process buffers and possibly also close them + /// Since they are part of the same transaction and correctly ordered, each + /// chunk can run in parallel + pub chunked_ixs: Vec>, + /// Separate buffer close transactions. + /// Since the process transactions nee to complete first we need to run them + /// after the [Self::chunked_ixs] transactions + pub chunked_close_ixs: Option>>, + /// Commitables that could not be chunked and thus cannot be committed while + /// respecting the bundle + pub unchunked: HashMap>, +} + +/// Processes commits +/// Creates single instruction chunk for commmitables with matching bundle_id +pub(crate) fn chunked_ixs_to_process_commitables_and_close_pdas( + validator_auth: Pubkey, + commit_infos: Vec, + use_lookup: bool, +) -> ChunkedIxsToProcessCommitablesAndClosePdasResult { + // First try to combine process and close into a single transaction + let max_per_chunk = if use_lookup { + MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP + } else { + MAX_PROCESS_AND_CLOSE_PER_TX + }; + let bundles_with_close = + bundle_chunks(commit_infos, max_per_chunk as usize); + + // Add instruction chunks that include process and close + let mut chunked_ixs: Vec<_> = bundles_with_close + .chunks + .into_iter() + .map(|chunk| { + chunk + .into_iter() + .map(|commit_info| { + process_commitable_and_close_ixs( + validator_auth, + commit_info, + ) + }) + .collect::>() + }) + .collect(); + + // If all bundles can be handled combining process and close then we're done + let all_bundles_handled = bundles_with_close.unchunked.is_empty(); + if all_bundles_handled { + return ChunkedIxsToProcessCommitablesAndClosePdasResult { + chunked_ixs, + chunked_close_ixs: None, + unchunked: bundles_with_close.unchunked, + }; + } + + // If not all chunks fit when trying to close and process in one transaction + // then let's process them separately + let unbundled_commit_infos = bundles_with_close + .unchunked + .into_iter() + .flat_map(|(_, commit_infos)| commit_infos) + .collect::>(); + + // For the bundles that are too large to include the close instructions add them + // as separate instruction chunks, one for process (which is the only part + // that needs to run atomic for a bundle) and another chunk for the close buffer + // instructions + let close_bundles = { + let max_per_chunk = if use_lookup { + MAX_CLOSE_PER_TX_USING_LOOKUP + } else { + MAX_CLOSE_PER_TX + }; + bundle_chunks_ignoring_bundle_id( + &unbundled_commit_infos, + max_per_chunk as usize, + ) + }; + + let process_bundles_with_separate_close = { + let max_per_chunk = if use_lookup { + MAX_PROCESS_PER_TX_USING_LOOKUP + } else { + MAX_PROCESS_PER_TX + }; + bundle_chunks(unbundled_commit_infos, max_per_chunk as usize) + }; + for bundle in process_bundles_with_separate_close.chunks { + let mut process_ixs = Vec::new(); + for commit_info in bundle { + let process_ix = + process_commitable_separate_ix(validator_auth, commit_info); + process_ixs.push(process_ix); + } + chunked_ixs.push(process_ixs); + } + + let mut close_ixs_chunks = Vec::new(); + for bundle in close_bundles.chunks { + let mut close_ixs = Vec::new(); + for commit_info in bundle { + let close_ix = + close_buffers_separate_ix(validator_auth, commit_info); + close_ixs.push(close_ix); + } + close_ixs_chunks.push(close_ixs); + } + + ChunkedIxsToProcessCommitablesAndClosePdasResult { + chunked_ixs, + chunked_close_ixs: Some(close_ixs_chunks), + unchunked: process_bundles_with_separate_close.unchunked, + } +} diff --git a/magicblock-committor-service/src/commit_info.rs b/magicblock-committor-service/src/commit_info.rs new file mode 100644 index 000000000..a669153bc --- /dev/null +++ b/magicblock-committor-service/src/commit_info.rs @@ -0,0 +1,177 @@ +use dlp::pda::commit_state_pda_from_delegated_account; +use magicblock_committor_program::CommitableAccount; +use solana_pubkey::Pubkey; +use solana_sdk::{clock::Slot, hash::Hash}; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum CommitInfo { + /// A commit for an account that has no data. In this case we are trying to + /// commit changes to its lamports. + EmptyAccount { + /// The on chain address of the delegated account + pubkey: Pubkey, + /// The original owner of the delegated account on chain + delegated_account_owner: Pubkey, + /// The ephemeral slot at which those changes were requested + slot: Slot, + /// The ephemeral blockhash at which those changes were requested + ephemeral_blockhash: Hash, + /// If we also undelegate the account after committing it + undelegate: bool, + /// Lamports of the account in the ephemeral + lamports: u64, + /// This id will be the same for accounts whose commits need to + /// be applied atomically in a single transaction + /// For single account commits it is also set for consistency + bundle_id: u64, + /// If `true` the account commit is finalized after it was processed + finalize: bool, + }, + /// A commit for an account that is part of a bundle whose data is small enough + /// to fit into a single process commit instruction. + DataAccount { + /// The on chain address of the delegated account + pubkey: Pubkey, + /// The account where the delegated account state is committed and stored + /// until it is finalized + commit_state: Pubkey, + /// The original owner of the delegated account on chain + delegated_account_owner: Pubkey, + /// The ephemeral slot at which those changes were requested + slot: Slot, + /// The ephemeral blockhash at which those changes were requested + ephemeral_blockhash: Hash, + /// If we also undelegate the account after committing it + undelegate: bool, + /// Lamports of the account in the ephemeral + lamports: u64, + /// This id will be the same for accounts whose commits need to + /// be applied atomically in a single transaction + /// For single account commits it is also set for consistency + bundle_id: u64, + /// If `true` the account commit is finalized after it was processed + finalize: bool, + }, + /// A commit for an account that is part of a bundle whose total data is so large + /// that we send the data in chunks to a buffer account before processing the + /// commit. + BufferedDataAccount { + /// The on chain address of the delegated account + pubkey: Pubkey, + /// The account where the delegated account state is committed and stored + /// until it is finalized + commit_state: Pubkey, + /// The original owner of the delegated account on chain + delegated_account_owner: Pubkey, + /// The ephemeral slot at which those changes were requested + slot: Slot, + /// The ephemeral blockhash at which those changes were requested + ephemeral_blockhash: Hash, + /// If we also undelegate the account after committing it + undelegate: bool, + /// The account that tracked that all chunks got written to the [CommitInfo::buffer_pda] + chunks_pda: Pubkey, + /// The temporary address where the data of the account is stored + buffer_pda: Pubkey, + /// Lamports of the account in the ephemeral + lamports: u64, + /// This id will be the same for accounts whose commits need to + /// be applied atomically in a single transaction + /// For single account commits it is also set for consistency + bundle_id: u64, + /// If `true` the account commit is finalized after it was processed + finalize: bool, + }, +} + +impl CommitInfo { + pub fn from_small_data_account( + commitable: CommitableAccount, + ephemeral_blockhash: Hash, + finalize: bool, + ) -> Self { + Self::DataAccount { + pubkey: commitable.pubkey, + delegated_account_owner: commitable.delegated_account_owner, + slot: commitable.slot, + ephemeral_blockhash, + undelegate: commitable.undelegate, + lamports: commitable.lamports, + bundle_id: commitable.bundle_id, + finalize, + commit_state: commit_state_pda_from_delegated_account( + &commitable.pubkey, + ), + } + } + pub fn has_data(&self) -> bool { + matches!(self, Self::BufferedDataAccount { .. }) + } + + pub fn pubkey(&self) -> Pubkey { + match self { + Self::EmptyAccount { pubkey, .. } => *pubkey, + Self::DataAccount { pubkey, .. } => *pubkey, + Self::BufferedDataAccount { pubkey, .. } => *pubkey, + } + } + + pub fn commit_state(&self) -> Option { + match self { + Self::BufferedDataAccount { commit_state, .. } => { + Some(*commit_state) + } + Self::DataAccount { commit_state, .. } => Some(*commit_state), + _ => None, + } + } + + pub fn lamports(&self) -> u64 { + match self { + Self::EmptyAccount { lamports, .. } => *lamports, + Self::DataAccount { lamports, .. } => *lamports, + Self::BufferedDataAccount { lamports, .. } => *lamports, + } + } + + pub fn bundle_id(&self) -> u64 { + match self { + Self::EmptyAccount { bundle_id, .. } => *bundle_id, + Self::DataAccount { bundle_id, .. } => *bundle_id, + Self::BufferedDataAccount { bundle_id, .. } => *bundle_id, + } + } + + pub fn undelegate(&self) -> bool { + match self { + Self::EmptyAccount { undelegate, .. } => *undelegate, + Self::DataAccount { undelegate, .. } => *undelegate, + Self::BufferedDataAccount { undelegate, .. } => *undelegate, + } + } + + pub fn chunks_pda(&self) -> Option { + match self { + Self::BufferedDataAccount { chunks_pda, .. } => Some(*chunks_pda), + _ => None, + } + } + + pub fn buffer_pda(&self) -> Option { + match self { + Self::BufferedDataAccount { buffer_pda, .. } => Some(*buffer_pda), + _ => None, + } + } + + pub fn pdas(&self) -> Option<(Pubkey, Pubkey)> { + match self { + Self::BufferedDataAccount { + chunks_pda, + buffer_pda, + .. + } => Some((*chunks_pda, *buffer_pda)), + _ => None, + } + } +} diff --git a/magicblock-committor-service/src/commit_stage.rs b/magicblock-committor-service/src/commit_stage.rs new file mode 100644 index 000000000..fe8299c7f --- /dev/null +++ b/magicblock-committor-service/src/commit_stage.rs @@ -0,0 +1,340 @@ +use magicblock_committor_program::ChangedAccountMeta; +use solana_pubkey::Pubkey; +use solana_sdk::{clock::Slot, signature::Signature}; + +use crate::{ + error::CommitAccountError, + persist::{CommitStatus, CommitStatusSignatures, CommitStrategy}, + CommitInfo, +}; +use log::*; +use std::sync::Arc; + +#[derive(Debug, Clone)] +pub struct CommitSignatures { + /// The signature of the transaction processing the commit + pub process_signature: Signature, + /// The signature of the transaction finalizing the commit. + /// If the account was not finalized or it failed the this is `None`. + /// If the finalize instruction was part of the process transaction then + /// this signature is the same as [Self::process_signature]. + pub finalize_signature: Option, + /// The signature of the transaction undelegating the committed accounts + /// if so requested. + /// If the account was not undelegated or it failed the this is `None`. + /// NOTE: this can be removed if we decide to perform the undelegation + /// step as part of the finalize instruction in the delegation program + pub undelegate_signature: Option, +} + +impl CommitSignatures { + pub fn process_only(process_signature: Signature) -> Self { + Self { + process_signature, + finalize_signature: None, + undelegate_signature: None, + } + } +} + +impl From for CommitStatusSignatures { + fn from(commit_signatures: CommitSignatures) -> Self { + Self { + process_signature: commit_signatures.process_signature, + finalize_signature: commit_signatures.finalize_signature, + undelegate_signature: commit_signatures.undelegate_signature, + } + } +} + +#[derive(Debug)] +pub enum CommitStage { + /// This account was part of a changeset that could not be split into + /// args only/args with lookup table or buffered changesets. + /// The commit for this account needs to be restarted from scratch. + SplittingChangesets((ChangedAccountMeta, Slot, bool)), + + /// This account was part of a changeset for which we could not obtain the + /// latest on chain blockhash when trying to commit them via args. + /// The commit for this account needs to be restarted from scratch. + GettingLatestBlockhash((ChangedAccountMeta, Slot, bool, CommitStrategy)), + + /// No part of the commit pipeline succeeded. + /// The commit for this account needs to be restarted from scratch. + Failed((CommitInfo, CommitStrategy)), + + /// The buffer and chunks account were initialized, but could either not + /// be retrieved or deserialized. It is recommended to fully re-initialize + /// them on retry. + BufferAndChunkPartiallyInitialized((CommitInfo, CommitStrategy)), + + /// The buffer and chunks accounts were initialized and all data was + /// written to them (for data accounts). + /// This means on retry we can skip that step and just try to process + /// these buffers to complete the commit. + /// This stage is returned in the following scenarios: + /// - the commit could not be processed + /// - another account in the same bundle failed to fully initialize + /// the buffer and chunks accounts and thus the bundle could not be + /// processed + BufferAndChunkFullyInitialized((CommitInfo, CommitStrategy)), + + /// The commit is part of a bundle that contains too many commits to be included + /// in a single transaction. Thus we cannot commit any of them. + /// The max amount of accounts we can commit and process as part of a single + /// transaction is [crate::max_per_transaction::MAX_COMMIT_STATE_AND_CLOSE_PER_TRANSACTION]. + /// These commits were prepared, which means the buffer and chunk accounts were fully + /// initialized, but then this issue was detected. + PartOfTooLargeBundleToProcess(CommitInfo), + + /// The commmit was properly initialized and added to a chunk of instructions to process + /// commits via a transaction. For large commits the buffer and chunk accounts were properly + /// prepared and haven't been closed. + /// However that transaction failed. + FailedProcess((CommitInfo, CommitStrategy, Option)), + + /// The commit was properly processed but the finalize instructions didn't fit into a single + /// transaction. + /// This should never happen since otherwise the [CommitStage::PartOfTooLargeBundleToProcess] + /// would have been returned as the bundle would have been too large to process in the + /// first place. + PartOfTooLargeBundleToFinalize(CommitInfo), + + /// The commit was properly processed but the requested finalize transaction failed. + FailedFinalize((CommitInfo, CommitStrategy, CommitSignatures)), + + /// The commit was properly processed but the requested undelegation transaction failed. + FailedUndelegate((CommitInfo, CommitStrategy, CommitSignatures)), + + /// All stages of the commit pipeline for this account succeeded + /// and we don't have to retry any of them. + /// This means the commit was processed and if so requested also finalized. + /// We are done committing this account. + Succeeded((CommitInfo, CommitStrategy, CommitSignatures)), +} + +impl From for CommitStage { + fn from(err: CommitAccountError) -> Self { + use CommitAccountError::*; + macro_rules! ci { + ($ci:ident) => { + Arc::::unwrap_or_clone($ci) + }; + } + + match err { + InitBufferAndChunkAccounts(err, commit_info, commit_strategy) => { + warn!("Init buffer and chunks accounts failed: {:?}", err); + Self::Failed((*commit_info, commit_strategy)) + } + GetChunksAccount(err, commit_info, commit_strategy) => { + warn!("Get chunks account failed: {:?}", err); + Self::BufferAndChunkPartiallyInitialized(( + ci!(commit_info), + commit_strategy, + )) + } + DeserializeChunksAccount(err, commit_info, commit_strategy) => { + warn!("Deserialize chunks account failed: {:?}", err); + Self::BufferAndChunkPartiallyInitialized(( + ci!(commit_info), + commit_strategy, + )) + } + WriteChunksRanOutOfRetries(err, commit_info, commit_strategy) => { + warn!("Write chunks ran out of retries: {:?}", err); + Self::BufferAndChunkPartiallyInitialized(( + ci!(commit_info), + commit_strategy, + )) + } + } + } +} + +pub enum CommitMetadata<'a> { + CommitInfo(&'a CommitInfo), + ChangedAccountMeta((&'a ChangedAccountMeta, Slot, bool)), +} + +impl<'a> From<&'a CommitInfo> for CommitMetadata<'a> { + fn from(commit_info: &'a CommitInfo) -> Self { + Self::CommitInfo(commit_info) + } +} + +impl CommitMetadata<'_> { + pub fn pubkey(&self) -> Pubkey { + use CommitMetadata::*; + match self { + CommitInfo(ci) => ci.pubkey(), + ChangedAccountMeta((cm, _, _)) => cm.pubkey, + } + } + + pub fn commit_state(&self) -> Option { + use CommitMetadata::*; + match self { + CommitInfo(ci) => ci.commit_state(), + ChangedAccountMeta((_, _, _)) => None, + } + } + + pub fn bundle_id(&self) -> u64 { + use CommitMetadata::*; + match self { + CommitInfo(ci) => ci.bundle_id(), + ChangedAccountMeta((cm, _, _)) => cm.bundle_id, + } + } +} + +impl CommitStage { + pub fn commit_metadata(&self) -> CommitMetadata<'_> { + use CommitStage::*; + match self { + SplittingChangesets((cm, slot, undelegate)) => { + CommitMetadata::ChangedAccountMeta((cm, *slot, *undelegate)) + } + GettingLatestBlockhash((cm, slot, undelegate, _)) => { + CommitMetadata::ChangedAccountMeta((cm, *slot, *undelegate)) + } + Failed((ci, _)) + | BufferAndChunkPartiallyInitialized((ci, _)) + | BufferAndChunkFullyInitialized((ci, _)) + | PartOfTooLargeBundleToProcess(ci) + | FailedProcess((ci, _, _)) + | PartOfTooLargeBundleToFinalize(ci) + | FailedFinalize((ci, _, _)) + | FailedUndelegate((ci, _, _)) + | Succeeded((ci, _, _)) => CommitMetadata::from(ci), + } + } + + pub fn commit_strategy(&self) -> CommitStrategy { + use CommitStage::*; + match self { + SplittingChangesets((_, _, _)) => CommitStrategy::Undetermined, + + // For the below two the only strategy that would possibly have worked is the one + // allowing most accounts per bundle, thus we return that as the assumed strategy + PartOfTooLargeBundleToProcess(_) + | PartOfTooLargeBundleToFinalize(_) => { + CommitStrategy::FromBufferWithLookupTable + } + + GettingLatestBlockhash((_, _, _, strategy)) + | Failed((_, strategy)) + | BufferAndChunkPartiallyInitialized((_, strategy)) + | BufferAndChunkFullyInitialized((_, strategy)) + | FailedProcess((_, strategy, _)) + | FailedFinalize((_, strategy, _)) + | FailedUndelegate((_, strategy, _)) + | Succeeded((_, strategy, _)) => *strategy, + } + } + + pub fn commit_status(&self) -> CommitStatus { + use CommitStage::*; + match self { + SplittingChangesets((meta, _, _)) + | GettingLatestBlockhash((meta, _, _, _)) => { + CommitStatus::Failed(meta.bundle_id) + } + Failed((ci, _)) => CommitStatus::Failed(ci.bundle_id()), + BufferAndChunkPartiallyInitialized((ci, _)) => { + CommitStatus::BufferAndChunkPartiallyInitialized(ci.bundle_id()) + } + BufferAndChunkFullyInitialized((ci, _)) => { + CommitStatus::BufferAndChunkFullyInitialized(ci.bundle_id()) + } + PartOfTooLargeBundleToProcess(ci) + // NOTE: the below cannot occur if the above didn't, so we can merge them + // here + | PartOfTooLargeBundleToFinalize(ci) => { + CommitStatus::PartOfTooLargeBundleToProcess(ci.bundle_id()) + } + FailedProcess((ci, strategy, sigs)) => CommitStatus::FailedProcess(( + ci.bundle_id(), + *strategy, + sigs.as_ref().cloned().map(CommitStatusSignatures::from), + )), + FailedFinalize((ci, strategy, sigs)) => CommitStatus::FailedFinalize(( + ci.bundle_id(), + *strategy, + CommitStatusSignatures::from(sigs.clone()), + )), + FailedUndelegate((ci, strategy, sigs)) => CommitStatus::FailedUndelegate(( + ci.bundle_id(), + *strategy, + CommitStatusSignatures::from(sigs.clone()), + )), + Succeeded((ci, strategy, sigs)) => CommitStatus::Succeeded(( + ci.bundle_id(), + *strategy, + CommitStatusSignatures::from(sigs.clone()), + )), + } + } + + pub fn commit_infos(commit_stages: &[Self]) -> Vec> { + commit_stages.iter().map(Self::commit_metadata).collect() + } + + /// Pubkey of the committed account + pub fn pubkey(&self) -> Pubkey { + self.commit_metadata().pubkey() + } + + /// Pubkey of the account holding the state we commit until the commit is finalized + pub fn commit_state(&self) -> Option { + self.commit_metadata().commit_state() + } + + /// Returns `true` if we need to init the chunks and buffer accounts when we + /// retry commiting this account + pub fn needs_accounts_init(&self) -> bool { + use CommitStage::*; + matches!(self, Failed(_) | BufferAndChunkPartiallyInitialized(_)) + } + + /// Returns `true` if we need to complete writing data to the buffer account + /// when we retry committing this account + pub fn needs_accounts_write(&self) -> bool { + use CommitStage::*; + self.needs_accounts_init() + || matches!(self, BufferAndChunkFullyInitialized(_)) + } + + /// Returns `true` if we need to process the buffer account in order to apply + /// the commit when we retry committing this account + pub fn needs_process(&self) -> bool { + use CommitStage::*; + self.needs_accounts_write() + || matches!( + self, + PartOfTooLargeBundleToProcess(_) | FailedProcess(_) + ) + } + + /// Returns `true` if we need to rerun the finalize transaction when we retry + /// committing this account + pub fn needs_finalize(&self) -> bool { + use CommitStage::*; + self.needs_process() + || matches!( + self, + PartOfTooLargeBundleToFinalize(_) | FailedFinalize(_) + ) + } + + /// Returns `true` if the commit was successfully processed and the account + /// was undelegated as part of the commit + pub fn is_successfully_undelegated(&self) -> bool { + use CommitStage::*; + match self { + Succeeded((ci, _, _)) => ci.undelegate(), + _ => false, + } + } +} diff --git a/magicblock-committor-service/src/commit_strategy.rs b/magicblock-committor-service/src/commit_strategy.rs new file mode 100644 index 000000000..32c9b7956 --- /dev/null +++ b/magicblock-committor-service/src/commit_strategy.rs @@ -0,0 +1,635 @@ +use std::collections::HashSet; + +use magicblock_committor_program::{ChangedBundle, Changeset}; +use solana_pubkey::Pubkey; + +use crate::{ + error::{CommittorServiceError, CommittorServiceResult}, + transactions::{ + commit_tx_report, CommitTxReport, MAX_ENCODED_TRANSACTION_SIZE, + }, +}; + +/// These are the commit strategies we can use to commit a changeset in order +/// of preference. We use lookup tables only as last resort since they are +/// slow to prepare. +#[derive(Debug)] +pub enum CommitBundleStrategy { + ArgsIncludeFinalize(ChangedBundle), + Args(ChangedBundle), + FromBuffer(ChangedBundle), + ArgsIncludeFinalizeWithLookupTable(ChangedBundle), + ArgsWithLookupTable(ChangedBundle), + FromBufferWithLookupTable(ChangedBundle), +} + +impl TryFrom<(ChangedBundle, bool)> for CommitBundleStrategy { + type Error = CommittorServiceError; + + /// Try to find the fastest/efficient commit strategy for the given bundle. + /// Order of preference: + /// 1. [CommitBundleStrategy::ArgsIncludeFinalize] + /// 2. [CommitBundleStrategy::Args] + /// 3. [CommitBundleStrategy::FromBuffer] + /// 4. [CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable] + /// 5. [CommitBundleStrategy::ArgsWithLookupTable] + /// 6. [CommitBundleStrategy::FromBufferWithLookupTable] + fn try_from( + (bundle, finalize): (ChangedBundle, bool), + ) -> Result { + let CommitTxReport { + size_args_including_finalize, + size_args, + fits_buffer, + size_args_with_lookup_including_finalize, + size_args_with_lookup, + fits_buffer_using_lookup, + } = commit_tx_report(&bundle, finalize)?; + // Try to combine process and finalize if finalize is true + if let Some(size_including_finalize) = size_args_including_finalize { + if size_including_finalize < MAX_ENCODED_TRANSACTION_SIZE { + return Ok(CommitBundleStrategy::ArgsIncludeFinalize(bundle)); + } + } + // Next still using args but with separate finalize if needed + if size_args < MAX_ENCODED_TRANSACTION_SIZE { + return Ok(CommitBundleStrategy::Args(bundle)); + } + + // Last option to avoid lookup tables + if fits_buffer { + return Ok(CommitBundleStrategy::FromBuffer(bundle)); + } + + // All the below use lookup tables and will be a lot slower + + // Combining finalize and process + if let Some(size_with_lookup_including_finalize) = + size_args_with_lookup_including_finalize + { + if size_with_lookup_including_finalize + < MAX_ENCODED_TRANSACTION_SIZE + { + return Ok( + CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable( + bundle, + ), + ); + } + } + // Using lookup tables but separate finalize + if let Some(size_with_lookup) = size_args_with_lookup { + if size_with_lookup < MAX_ENCODED_TRANSACTION_SIZE { + return Ok(CommitBundleStrategy::ArgsWithLookupTable(bundle)); + } + } + + // Worst case try to use a buffer with lookup tables + if fits_buffer_using_lookup { + return Ok(CommitBundleStrategy::FromBufferWithLookupTable(bundle)); + } + + // If none of the strategies work then we need to error + let bundle_id = bundle + .first() + .map(|(_, acc)| acc.bundle_id()) + .unwrap_or_default(); + Err(CommittorServiceError::CouldNotFindCommitStrategyForBundle( + bundle_id, + )) + } +} + +#[derive(Debug)] +pub struct SplitChangesets { + /// This changeset can be committed in one processing step, passing account data as args + pub args_changeset: Changeset, + /// This changeset can be committed in one processing step, passing account data as args + /// and the finalize instruction fits into the same transaction + pub args_including_finalize_changeset: Changeset, + /// This changeset can be committed in one processing step, passing account data as args + /// but needs to use lookup tables for the accounts + pub args_with_lookup_changeset: Changeset, + /// This changeset can be committed in one processing step, passing account data as args + /// and the finalize instruction fits into the same transaction. + /// It needs to use lookup tables for the accounts. + pub args_including_finalize_with_lookup_changeset: Changeset, + /// This changeset needs to be committed in two steps: + /// 1. Prepare the buffer account + /// 2. Process the buffer account + pub from_buffer_changeset: Changeset, + /// This changeset needs to be committed in three steps: + /// 1. Prepare the buffer account + /// 2. Prepare lookup table + /// 3. Process the buffer account + pub from_buffer_with_lookup_changeset: Changeset, +} + +pub fn split_changesets_by_commit_strategy( + changeset: Changeset, + finalize: bool, +) -> CommittorServiceResult { + fn add_to_changeset( + changeset: &mut Changeset, + accounts_to_undelegate: &HashSet, + bundle: ChangedBundle, + ) { + for (pubkey, acc) in bundle { + changeset.add(pubkey, acc); + if accounts_to_undelegate.contains(&pubkey) { + changeset.accounts_to_undelegate.insert(pubkey); + } + } + } + + let mut args_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + let mut args_including_finalize_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + let mut args_with_lookup_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + let mut args_including_finalize_with_lookup_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + let mut from_buffer_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + let mut from_buffer_with_lookup_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + + let accounts_to_undelegate = changeset.accounts_to_undelegate.clone(); + let changeset_bundles = changeset.into_small_changeset_bundles(); + for bundle in changeset_bundles.bundles.into_iter() { + let commit_strategy = + CommitBundleStrategy::try_from((bundle, finalize)); + match commit_strategy { + Ok(CommitBundleStrategy::Args(bundle)) => { + add_to_changeset( + &mut args_changeset, + &accounts_to_undelegate, + bundle, + ); + } + Ok(CommitBundleStrategy::ArgsIncludeFinalize(bundle)) => { + add_to_changeset( + &mut args_including_finalize_changeset, + &accounts_to_undelegate, + bundle, + ); + } + Ok(CommitBundleStrategy::ArgsWithLookupTable(bundle)) => { + add_to_changeset( + &mut args_with_lookup_changeset, + &accounts_to_undelegate, + bundle, + ); + } + Ok(CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable( + bundle, + )) => { + add_to_changeset( + &mut args_including_finalize_with_lookup_changeset, + &accounts_to_undelegate, + bundle, + ); + } + Ok(CommitBundleStrategy::FromBuffer(bundle)) => { + add_to_changeset( + &mut from_buffer_changeset, + &accounts_to_undelegate, + bundle, + ); + } + Ok(CommitBundleStrategy::FromBufferWithLookupTable(bundle)) => { + add_to_changeset( + &mut from_buffer_with_lookup_changeset, + &accounts_to_undelegate, + bundle, + ); + } + Err(err) => { + return Err(err); + } + } + } + + Ok(SplitChangesets { + args_changeset, + args_including_finalize_changeset, + args_with_lookup_changeset, + args_including_finalize_with_lookup_changeset, + from_buffer_changeset, + from_buffer_with_lookup_changeset, + }) +} + +#[cfg(test)] +mod test { + use super::*; + use log::*; + use magicblock_committor_program::ChangedAccount; + use solana_sdk::pubkey::Pubkey; + + fn init_logger() { + let _ = env_logger::builder() + .format_timestamp(None) + .is_test(true) + .try_init(); + } + + fn add_changed_account( + changeset: &mut Changeset, + size: usize, + bundle_id: u64, + undelegate: bool, + ) -> Pubkey { + let pubkey = Pubkey::new_unique(); + changeset.add( + pubkey, + ChangedAccount::Full { + data: vec![1; size], + owner: Pubkey::new_unique(), + lamports: 0, + bundle_id, + }, + ); + if undelegate { + changeset.accounts_to_undelegate.insert(pubkey); + } + pubkey + } + + macro_rules! debug_counts { + ($label:expr, $changeset:ident, $split_changesets:ident) => { + debug!( + "{}: ({}) {{ +args_changeset: {} +args_including_finalize_changeset: {} +args_with_lookup_changeset: {} +args_including_finalize_with_lookup_changeset: {} +from_buffer_changeset: {} +from_buffer_with_lookup_changeset: {} +}}", + $label, + $changeset.accounts.len(), + $split_changesets.args_changeset.len(), + $split_changesets.args_including_finalize_changeset.len(), + $split_changesets.args_with_lookup_changeset.len(), + $split_changesets + .args_including_finalize_with_lookup_changeset + .len(), + $split_changesets.from_buffer_changeset.len(), + $split_changesets.from_buffer_with_lookup_changeset.len() + ); + }; + } + + macro_rules! assert_accounts_sum_matches { + ($changeset:ident, $split_changesets:ident) => { + assert_eq!( + $split_changesets.args_changeset.len() + + $split_changesets.args_including_finalize_changeset.len() + + $split_changesets.args_with_lookup_changeset.len() + + $split_changesets + .args_including_finalize_with_lookup_changeset + .len() + + $split_changesets.from_buffer_changeset.len() + + $split_changesets.from_buffer_with_lookup_changeset.len(), + $changeset.len() + ); + }; + } + + macro_rules! assert_undelegate_sum_matches { + ($changeset:ident, $split_changesets:ident) => { + assert_eq!( + $split_changesets + .args_changeset + .accounts_to_undelegate + .len() + + $split_changesets + .args_including_finalize_changeset + .accounts_to_undelegate + .len() + + $split_changesets + .args_with_lookup_changeset + .accounts_to_undelegate + .len() + + $split_changesets + .args_including_finalize_with_lookup_changeset + .accounts_to_undelegate + .len() + + $split_changesets + .from_buffer_changeset + .accounts_to_undelegate + .len() + + $split_changesets + .from_buffer_with_lookup_changeset + .accounts_to_undelegate + .len(), + $changeset.accounts_to_undelegate.len() + ); + }; + } + #[test] + fn test_split_small_changesets_by_commit_strategy() { + init_logger(); + + // Setup a changeset with different bundle/account sizes + let mut changeset = Changeset { + slot: 1, + ..Default::default() + }; + + let bundle_id = 1111; + + // 2 accounts bundle that can be handled via args + for idx in 1..=2 { + add_changed_account(&mut changeset, 10, bundle_id, idx % 2 == 0); + } + + // 8 accounts bundle that needs lookup + for idx in 1..=8 { + add_changed_account( + &mut changeset, + 10, + bundle_id * 10, + idx % 2 == 0, + ); + } + + // No Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), false) + .unwrap(); + debug_counts!("No Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_changeset.len(), 2,); + assert_eq!(split_changesets.args_with_lookup_changeset.len(), 8,); + + // Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), true) + .unwrap(); + + debug_counts!("Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_including_finalize_changeset.len(), 2,); + assert_eq!( + split_changesets + .args_including_finalize_with_lookup_changeset + .len(), + 8, + ); + } + + #[test] + fn test_split_medium_changesets_by_commit_strategy() { + init_logger(); + + // Setup a changeset with different bundle/account sizes + let mut changeset = Changeset { + slot: 1, + ..Default::default() + }; + let bundle_id = 2222; + + // 2 accounts bundle that can be handled via args and include the finalize instructions + for idx in 1..=2 { + add_changed_account(&mut changeset, 80, bundle_id, idx % 2 == 0); + } + + // 2 accounts bundle that can be handled via args, but cannot include finalize due + // to the size of the data + for idx in 1..=2 { + add_changed_account( + &mut changeset, + 100, + bundle_id + 1, + idx % 2 == 0, + ); + } + + // 3 accounts bundle that needs lookup buffer due to overall args size + for idx in 1..=3 { + add_changed_account( + &mut changeset, + 100, + bundle_id + 3, + idx % 2 == 0, + ); + } + + // No Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), false) + .unwrap(); + debug_counts!("No Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_changeset.len(), 4,); + assert_eq!(split_changesets.from_buffer_changeset.len(), 3,); + + // Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), true) + .unwrap(); + debug_counts!("Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_changeset.len(), 2,); + assert_eq!(split_changesets.args_including_finalize_changeset.len(), 2,); + assert_eq!(split_changesets.from_buffer_changeset.len(), 3,); + } + + #[test] + fn test_split_large_changesets_by_commit_strategy() { + init_logger(); + + // Setup a changeset with different bundle/account sizes + let mut changeset = Changeset { + slot: 1, + ..Default::default() + }; + + let bundle_id = 3333; + + // 5 accounts bundle that needs to be handled via lookup (buffer) + for idx in 1..=5 { + add_changed_account(&mut changeset, 400, bundle_id, idx % 2 == 0); + } + + // 2 accounts bundle that can be handled without lookup (buffer) + for idx in 1..=2 { + add_changed_account( + &mut changeset, + 600, + bundle_id * 10, + idx % 2 == 0, + ); + } + + // No Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), false) + .unwrap(); + debug_counts!("No Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.from_buffer_changeset.len(), 2,); + assert_eq!(split_changesets.from_buffer_with_lookup_changeset.len(), 5,); + + // Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), true) + .unwrap(); + debug_counts!("Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.from_buffer_changeset.len(), 2,); + assert_eq!(split_changesets.from_buffer_with_lookup_changeset.len(), 5,); + } + + #[test] + fn test_split_different_size_changesets_by_commit_strategy() { + // Combining the different changeset sizes we already test above into one changeset to + // split + init_logger(); + + // Setup a changeset with different bundle/account sizes + let mut changeset = Changeset { + slot: 1, + ..Default::default() + }; + + // Small sized bundles + { + let bundle_id = 1111; + + // 2 accounts bundle that can be handled via args + for idx in 1..=2 { + add_changed_account( + &mut changeset, + 10, + bundle_id, + idx % 2 == 0, + ); + } + + // 8 accounts bundle that needs lookup + for idx in 1..=8 { + add_changed_account( + &mut changeset, + 10, + bundle_id * 10, + idx % 2 == 0, + ); + } + }; + + // Medium sized bundles + { + let bundle_id = 2222; + + // 2 accounts bundle that can be handled via args + for idx in 1..=2 { + add_changed_account( + &mut changeset, + 100, + bundle_id, + idx % 2 == 0, + ); + } + }; + + // Large sized bundles + { + let bundle_id = 3333; + + // 5 accounts bundle that needs to be handled via lookup (buffer) + for idx in 1..=5 { + add_changed_account( + &mut changeset, + 400, + bundle_id, + idx % 2 == 0, + ); + } + + // 2 accounts bundle that can be handled without lookup (buffer) + for idx in 1..=2 { + add_changed_account( + &mut changeset, + 600, + bundle_id * 10, + idx % 2 == 0, + ); + } + }; + + // No Finalize + { + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), false) + .unwrap(); + + debug_counts!("No Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_changeset.len(), 4); + assert_eq!(split_changesets.args_with_lookup_changeset.len(), 8); + assert_eq!(split_changesets.from_buffer_changeset.len(), 2); + assert_eq!( + split_changesets.from_buffer_with_lookup_changeset.len(), + 5 + ); + } + + // Finalize + { + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), true) + .unwrap(); + + debug_counts!("Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_changeset.len(), 2); + assert_eq!( + split_changesets.args_including_finalize_changeset.len(), + 2 + ); + assert_eq!( + split_changesets + .args_including_finalize_with_lookup_changeset + .len(), + 8 + ); + assert_eq!(split_changesets.from_buffer_changeset.len(), 2); + assert_eq!( + split_changesets.from_buffer_with_lookup_changeset.len(), + 5 + ); + } + } +} diff --git a/magicblock-committor-service/src/compute_budget.rs b/magicblock-committor-service/src/compute_budget.rs new file mode 100644 index 000000000..0b2aa3123 --- /dev/null +++ b/magicblock-committor-service/src/compute_budget.rs @@ -0,0 +1,218 @@ +use solana_sdk::{ + compute_budget::ComputeBudgetInstruction, instruction::Instruction, +}; + +// ----------------- +// Budgets +// ----------------- +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct Budget { + base_budget: u32, + per_committee: u32, + compute_unit_price: u64, +} + +impl Default for Budget { + fn default() -> Self { + Self { + base_budget: 80_000, + per_committee: 45_000, + compute_unit_price: 1_000_000, + } + } +} + +#[derive(Debug, Clone)] +pub struct BufferWithReallocBudget { + base_budget: u32, + per_realloc_ix: u32, + compute_unit_price: u64, +} + +impl BufferWithReallocBudget { + fn total_budget(&self, realloc_ixs_count: u32) -> u32 { + self.base_budget + (self.per_realloc_ix * realloc_ixs_count) + } + + pub fn instructions(&self, realloc_ixs_count: usize) -> Vec { + let realloc_ixs_count = + u32::try_from(realloc_ixs_count).unwrap_or(u32::MAX); + + instructions( + self.total_budget(realloc_ixs_count), + self.compute_unit_price, + ) + } +} + +#[derive(Debug, Clone)] +pub struct BufferWriteChunkBudget { + base_budget: u32, + per_byte: usize, + compute_unit_price: u64, +} + +impl BufferWriteChunkBudget { + fn total_budget(&self, bytes_count: usize) -> u32 { + self.base_budget + (self.per_byte * bytes_count) as u32 + } + + pub fn instructions(&self, bytes_count: usize) -> Vec { + instructions(self.total_budget(bytes_count), self.compute_unit_price) + } +} + +// ----------------- +// ComputeBudgetConfig +// ----------------- +#[derive(Debug, Clone)] +pub struct ComputeBudgetConfig { + pub args_process: Budget, + pub finalize: Budget, + pub buffer_close: Budget, + /// The budget used for processing and process + closing a buffer. + /// Since we mix pure process and process + close instructions, we need to + /// assume the worst case and use the process + close budget for all. + pub buffer_process_and_close: Budget, + pub undelegate: Budget, + pub buffer_init: BufferWithReallocBudget, + pub buffer_realloc: BufferWithReallocBudget, + pub buffer_write: BufferWriteChunkBudget, +} + +impl ComputeBudgetConfig { + pub fn new(compute_unit_price: u64) -> Self { + Self { + args_process: Budget { + compute_unit_price, + base_budget: 80_000, + per_committee: 35_000, + }, + buffer_close: Budget { + compute_unit_price, + base_budget: 10_000, + per_committee: 25_000, + }, + buffer_process_and_close: Budget { + compute_unit_price, + base_budget: 40_000, + per_committee: 45_000, + }, + finalize: Budget { + compute_unit_price, + base_budget: 80_000, + per_committee: 25_000, + }, + undelegate: Budget { + compute_unit_price, + base_budget: 40_000, + per_committee: 35_000, + }, + buffer_init: BufferWithReallocBudget { + base_budget: 12_000, + per_realloc_ix: 6_000, + compute_unit_price: 1_000_000, + }, + buffer_realloc: BufferWithReallocBudget { + base_budget: 12_000, + per_realloc_ix: 6_000, + compute_unit_price: 1_000_000, + }, + buffer_write: BufferWriteChunkBudget { + base_budget: 10_000, + per_byte: 3, + compute_unit_price: 1_000_000, + }, + } + } +} + +impl ComputeBudgetConfig { + pub fn args_process_budget(&self) -> ComputeBudget { + ComputeBudget::Process(self.args_process) + } + pub fn buffer_close_budget(&self) -> ComputeBudget { + ComputeBudget::Close(self.buffer_close) + } + pub fn buffer_process_and_close_budget(&self) -> ComputeBudget { + ComputeBudget::ProcessAndClose(self.buffer_process_and_close) + } + pub fn finalize_budget(&self) -> ComputeBudget { + ComputeBudget::Finalize(self.finalize) + } + pub fn undelegate_budget(&self) -> ComputeBudget { + ComputeBudget::Undelegate(self.undelegate) + } +} + +// ----------------- +// ComputeBudget +// ----------------- +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum ComputeBudget { + Process(Budget), + Close(Budget), + ProcessAndClose(Budget), + Finalize(Budget), + Undelegate(Budget), +} + +impl ComputeBudget { + fn base_budget(&self) -> u32 { + use ComputeBudget::*; + match self { + Process(budget) => budget.base_budget, + Close(budget) => budget.base_budget, + ProcessAndClose(budget) => budget.base_budget, + Finalize(budget) => budget.base_budget, + Undelegate(budget) => budget.base_budget, + } + } + + fn per_committee(&self) -> u32 { + use ComputeBudget::*; + match self { + Process(budget) => budget.per_committee, + Close(budget) => budget.per_committee, + ProcessAndClose(budget) => budget.per_committee, + Finalize(budget) => budget.per_committee, + Undelegate(budget) => budget.per_committee, + } + } + + fn compute_unit_price(&self) -> u64 { + use ComputeBudget::*; + match self { + Process(budget) => budget.compute_unit_price, + Close(budget) => budget.compute_unit_price, + ProcessAndClose(budget) => budget.compute_unit_price, + Finalize(budget) => budget.compute_unit_price, + Undelegate(budget) => budget.compute_unit_price, + } + } + + fn total_budget(&self, committee_count: u32) -> u32 { + self.base_budget() + (self.per_committee() * committee_count) + } + + pub fn instructions(&self, committee_count: usize) -> Vec { + let committee_count = + u32::try_from(committee_count).unwrap_or(u32::MAX); + + instructions( + self.total_budget(committee_count), + self.compute_unit_price(), + ) + } +} + +fn instructions( + compute_budget: u32, + compute_unit_price: u64, +) -> Vec { + let compute_budget_ix = + ComputeBudgetInstruction::set_compute_unit_limit(compute_budget); + let compute_unit_price_ix = + ComputeBudgetInstruction::set_compute_unit_price(compute_unit_price); + vec![compute_budget_ix, compute_unit_price_ix] +} diff --git a/magicblock-committor-service/src/config.rs b/magicblock-committor-service/src/config.rs new file mode 100644 index 000000000..8118ca5b7 --- /dev/null +++ b/magicblock-committor-service/src/config.rs @@ -0,0 +1,42 @@ +use solana_sdk::commitment_config::CommitmentLevel; + +use crate::compute_budget::ComputeBudgetConfig; + +#[derive(Debug, Clone)] +pub struct ChainConfig { + pub rpc_uri: String, + pub commitment: CommitmentLevel, + pub compute_budget_config: ComputeBudgetConfig, +} + +impl ChainConfig { + pub fn devnet(compute_budget_config: ComputeBudgetConfig) -> Self { + Self { + rpc_uri: "https://api.devnet.solana.com".to_string(), + commitment: CommitmentLevel::Confirmed, + compute_budget_config, + } + } + + pub fn mainnet(compute_budget_config: ComputeBudgetConfig) -> Self { + Self { + rpc_uri: "https://api.mainnet-beta.solana.com".to_string(), + commitment: CommitmentLevel::Confirmed, + compute_budget_config, + } + } + + pub fn local(compute_budget_config: ComputeBudgetConfig) -> Self { + Self { + rpc_uri: "http://localhost:7799".to_string(), + commitment: CommitmentLevel::Processed, + compute_budget_config, + } + } +} + +impl Default for ChainConfig { + fn default() -> Self { + Self::local(ComputeBudgetConfig::new(1_000_000)) + } +} diff --git a/magicblock-committor-service/src/consts.rs b/magicblock-committor-service/src/consts.rs new file mode 100644 index 000000000..3fb495cd3 --- /dev/null +++ b/magicblock-committor-service/src/consts.rs @@ -0,0 +1,15 @@ +// https://solana.com/docs/core/transactions#transaction-size + +use magicblock_committor_program::{ + consts::MAX_INSTRUCTION_DATA_SIZE, + instruction::IX_WRITE_SIZE_WITHOUT_CHUNKS, +}; + +const BUDGET_SET_COMPUTE_UNIT_PRICE_BYTES: u16 = (1 + 8) * 8; +const BUDGET_SET_COMPUTE_UNIT_LIMIT_BYTES: u16 = (1 + 4) * 8; + +/// The maximum size of a chunk that can be written as part of a single transaction +pub(super) const MAX_WRITE_CHUNK_SIZE: u16 = MAX_INSTRUCTION_DATA_SIZE + - IX_WRITE_SIZE_WITHOUT_CHUNKS + - BUDGET_SET_COMPUTE_UNIT_PRICE_BYTES + - BUDGET_SET_COMPUTE_UNIT_LIMIT_BYTES; diff --git a/magicblock-committor-service/src/error.rs b/magicblock-committor-service/src/error.rs new file mode 100644 index 000000000..d130cf1c3 --- /dev/null +++ b/magicblock-committor-service/src/error.rs @@ -0,0 +1,127 @@ +use std::sync::Arc; + +use crate::persist::CommitStrategy; +use magicblock_rpc_client::MagicBlockRpcClientError; +use solana_pubkey::Pubkey; +use solana_sdk::signature::Signature; +use thiserror::Error; + +use crate::CommitInfo; + +pub type CommittorServiceResult = + std::result::Result; + +#[derive(Error, Debug)] +pub enum CommittorServiceError { + #[error("CommittorError: {0} ({0:?})")] + CommittorError(#[from] magicblock_committor_program::error::CommittorError), + + #[error("CommitPersistError: {0} ({0:?})")] + CommitPersistError(#[from] crate::persist::error::CommitPersistError), + + #[error("MagicBlockRpcClientError: {0} ({0:?})")] + MagicBlockRpcClientError( + #[from] magicblock_rpc_client::MagicBlockRpcClientError, + ), + + #[error("TableManiaError: {0} ({0:?})")] + TableManiaError(#[from] magicblock_table_mania::error::TableManiaError), + + #[error( + "Failed send and confirm transaction to {0} on chain: {1} ({1:?})" + )] + FailedToSendAndConfirmTransaction( + String, + magicblock_rpc_client::MagicBlockRpcClientError, + ), + + #[error("The transaction to {0} was sent and confirmed, but encountered an error: {1} ({1:?})")] + EncounteredTransactionError( + String, + solana_sdk::transaction::TransactionError, + ), + + #[error("Failed to send init changeset account: {0} ({0:?})")] + FailedToSendInitChangesetAccount( + solana_rpc_client_api::client_error::Error, + ), + + #[error("Failed to confirm init changeset account: {0} ({0:?})")] + FailedToConfirmInitChangesetAccount( + solana_rpc_client_api::client_error::Error, + ), + #[error("Init transaction '{0}' was not confirmed")] + InitChangesetAccountNotConfirmed(String), + + #[error("Task {0} failed to compile transaction message: {1} ({1:?})")] + FailedToCompileTransactionMessage( + String, + solana_sdk::message::CompileError, + ), + + #[error("Task {0} failed to creqate transaction: {1} ({1:?})")] + FailedToCreateTransaction(String, solana_sdk::signer::SignerError), + + #[error("Could not find commit strategy for bundle {0}")] + CouldNotFindCommitStrategyForBundle(u64), + + #[error("Failed to fetch metadata account for {0}")] + FailedToFetchDelegationMetadata(Pubkey), + + #[error("Failed to deserialize metadata account for {0}, {1:?}")] + FailedToDeserializeDelegationMetadata( + Pubkey, + solana_sdk::program_error::ProgramError, + ), +} + +impl CommittorServiceError { + pub fn signature(&self) -> Option { + use CommittorServiceError::*; + match self { + MagicBlockRpcClientError(e) => e.signature(), + FailedToSendAndConfirmTransaction(_, e) => e.signature(), + _ => None, + } + } +} + +pub type CommitAccountResult = std::result::Result; +#[derive(Error, Debug)] +/// Specific error that always includes the commit info +pub enum CommitAccountError { + #[error("Failed to init buffer and chunk account: {0}")] + InitBufferAndChunkAccounts(String, Box, CommitStrategy), + + #[error("Failed to get chunks account: ({0:?})")] + GetChunksAccount( + Option, + Arc, + CommitStrategy, + ), + + #[error("Failed to deserialize chunks account: {0} ({0:?})")] + DeserializeChunksAccount(std::io::Error, Arc, CommitStrategy), + + #[error("Failed to write complete chunks of commit data after max retries. Last write error {0:?}")] + WriteChunksRanOutOfRetries( + Option, + Arc, + CommitStrategy, + ), +} + +impl CommitAccountError { + pub fn into_commit_info(self) -> CommitInfo { + use CommitAccountError::*; + let ci = match self { + InitBufferAndChunkAccounts(_, commit_info, _) => { + return *commit_info; + } + GetChunksAccount(_, commit_info, _) => commit_info, + DeserializeChunksAccount(_, commit_info, _) => commit_info, + WriteChunksRanOutOfRetries(_, commit_info, _) => commit_info, + }; + Arc::::unwrap_or_clone(ci) + } +} diff --git a/magicblock-committor-service/src/finalize.rs b/magicblock-committor-service/src/finalize.rs new file mode 100644 index 000000000..b63341400 --- /dev/null +++ b/magicblock-committor-service/src/finalize.rs @@ -0,0 +1,66 @@ +use std::collections::HashMap; + +use log::*; +use solana_pubkey::Pubkey; + +use crate::{ + bundles::bundle_chunks, + transactions::{ + finalize_ix, MAX_FINALIZE_PER_TX, MAX_FINALIZE_PER_TX_USING_LOOKUP, + }, + types::{InstructionsForCommitable, InstructionsKind}, + CommitInfo, +}; + +fn finalize_commitable( + validator_auth: Pubkey, + commit_info: CommitInfo, +) -> InstructionsForCommitable { + debug!("Finalizing commitable: {:?}", commit_info); + let CommitInfo::BufferedDataAccount { pubkey, .. } = &commit_info else { + panic!("Only data accounts are supported for now"); + }; + + let ix = finalize_ix(validator_auth, pubkey); + InstructionsForCommitable { + instructions: vec![ix], + commit_info, + kind: InstructionsKind::Finalize, + } +} + +pub(crate) struct ChunkedIxsToFinalizeCommitablesResult { + pub chunked_ixs: Vec>, + pub unchunked: HashMap>, +} + +/// Finalizes the previously processed commits +/// Ensures that commitables with matching bundle id are in a single chunk +pub(crate) fn chunked_ixs_to_finalize_commitables( + validator_auth: Pubkey, + commit_infos: Vec, + use_lookup: bool, +) -> ChunkedIxsToFinalizeCommitablesResult { + let max_per_chunk = if use_lookup { + MAX_FINALIZE_PER_TX_USING_LOOKUP + } else { + MAX_FINALIZE_PER_TX + }; + let bundles = bundle_chunks(commit_infos, max_per_chunk as usize); + let chunked_ixs: Vec<_> = bundles + .chunks + .into_iter() + .map(|chunk| { + chunk + .into_iter() + .map(|commit_info| { + finalize_commitable(validator_auth, commit_info) + }) + .collect::>() + }) + .collect(); + ChunkedIxsToFinalizeCommitablesResult { + chunked_ixs, + unchunked: bundles.unchunked, + } +} diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs new file mode 100644 index 000000000..274db7056 --- /dev/null +++ b/magicblock-committor-service/src/lib.rs @@ -0,0 +1,35 @@ +mod bundle_strategy; +mod bundles; +mod commit; +mod commit_info; +mod commit_stage; +mod commit_strategy; +mod compute_budget; +pub mod config; +mod consts; +pub mod error; +mod finalize; +pub mod persist; +mod pubkeys_provider; +mod service; +mod transactions; +mod types; +mod undelegate; + +#[cfg(feature = "dev-context-only-utils")] +pub mod stubs; + +pub use commit_info::CommitInfo; +pub use compute_budget::ComputeBudgetConfig; +pub use service::{ChangesetCommittor, CommittorService}; + +pub use commit_stage::CommitStage; +pub use magicblock_committor_program::{ + ChangedAccount, Changeset, ChangesetMeta, +}; +pub fn changeset_for_slot(slot: u64) -> Changeset { + Changeset { + slot, + ..Changeset::default() + } +} diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs new file mode 100644 index 000000000..33ade0f29 --- /dev/null +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -0,0 +1,254 @@ +use std::path::Path; +use std::sync::atomic::{AtomicU64, Ordering}; + +use solana_sdk::hash::Hash; +use solana_sdk::pubkey::Pubkey; + +use super::db::BundleSignatureRow; +use super::error::{CommitPersistError, CommitPersistResult}; +use super::utils::now; +use super::{db::CommitStatusRow, CommitStatus, CommitType, CommittorDb}; +use magicblock_committor_program::Changeset; + +pub struct CommitPersister { + db: CommittorDb, + request_id_counter: AtomicU64, +} + +impl CommitPersister { + pub fn try_new

(db_file: P) -> CommitPersistResult + where + P: AsRef, + { + let db = CommittorDb::new(db_file)?; + db.create_commit_status_table()?; + db.create_bundle_signature_table()?; + Ok(Self::for_db(db)) + } + + fn for_db(db: CommittorDb) -> Self { + Self { + db, + request_id_counter: AtomicU64::new(1), + } + } + + /// Generates a unique request ID for a changeset + fn generate_reqid(&self) -> String { + let id = self.request_id_counter.fetch_add(1, Ordering::SeqCst); + format!("req-{}", id) + } + + pub fn start_changeset( + &mut self, + changeset: &Changeset, + ephemeral_blockhash: Hash, + finalize: bool, + ) -> CommitPersistResult { + let reqid = self.generate_reqid(); + + let mut commit_rows = Vec::new(); + + for (pubkey, changed_account) in changeset.accounts.iter() { + let undelegate = changeset.accounts_to_undelegate.contains(pubkey); + let commit_type = if changed_account.data().is_empty() { + CommitType::EmptyAccount + } else { + CommitType::DataAccount + }; + + let data = if commit_type == CommitType::DataAccount { + Some(changed_account.data().to_vec()) + } else { + None + }; + + let now = now(); + + // Create a commit status row for this account + let commit_row = CommitStatusRow { + reqid: reqid.clone(), + pubkey: *pubkey, + delegated_account_owner: changed_account.owner(), + slot: changeset.slot, + ephemeral_blockhash, + undelegate, + lamports: changed_account.lamports(), + finalize, + data, + commit_type, + created_at: now, + commit_status: CommitStatus::Pending, + last_retried_at: now, + retries_count: 0, + }; + + commit_rows.push(commit_row); + } + + // Insert all commit rows into the database + self.db.insert_commit_status_rows(&commit_rows)?; + + Ok(reqid) + } + + pub fn update_status( + &mut self, + reqid: &str, + pubkey: &Pubkey, + status: CommitStatus, + ) -> Result<(), CommitPersistError> { + // NOTE: only Pending commits don't have a bundle id, but we should + // never update to Pending + let Some(bundle_id) = status.bundle_id() else { + return Err( + CommitPersistError::CommitStatusUpdateRequiresStatusWithBundleId( + status.as_str().to_string(), + ), + ); + }; + + let bundle_signature = status.signatures().map(|sigs| { + BundleSignatureRow::new( + bundle_id, + sigs.process_signature, + sigs.finalize_signature, + sigs.undelegate_signature, + ) + }); + + self.db.update_commit_status_and_bundle_signature( + reqid, + pubkey, + &status, + bundle_signature, + ) + + // TODO(thlorenz): @@ once we see this works remove the succeeded commits + } + + pub fn get_commit_statuses_by_reqid( + &self, + reqid: &str, + ) -> CommitPersistResult> { + self.db.get_commit_statuses_by_reqid(reqid) + } + + pub fn get_commit_status( + &self, + reqid: &str, + pubkey: &Pubkey, + ) -> CommitPersistResult> { + self.db.get_commit_status(reqid, pubkey) + } + + pub fn get_signature( + &self, + bundle_id: u64, + ) -> CommitPersistResult> { + self.db.get_bundle_signature_by_bundle_id(bundle_id) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::persist::{CommitStatusSignatures, CommitStrategy}; + use magicblock_committor_program::ChangedAccount; + use solana_pubkey::Pubkey; + use solana_sdk::signature::Signature; + + #[test] + fn test_start_changeset_and_update_status() { + let mut persister = CommitPersister::try_new(":memory:").unwrap(); + + // Create a test changeset + let mut changeset = Changeset { + slot: 100, + ..Default::default() + }; + + let pubkey1 = Pubkey::new_unique(); + let pubkey2 = Pubkey::new_unique(); + let owner = Pubkey::new_unique(); + + // Add an empty account + changeset.add( + pubkey1, + ChangedAccount::Full { + lamports: 1000, + owner, + data: vec![], + bundle_id: 1, + }, + ); + + // Add a data account + changeset.add( + pubkey2, + ChangedAccount::Full { + lamports: 2000, + owner, + data: vec![1, 2, 3, 4, 5], + bundle_id: 42, + }, + ); + + changeset.request_undelegation(pubkey1); + + // Start tracking the changeset + let blockhash = Hash::new_unique(); + let reqid = persister + .start_changeset(&changeset, blockhash, true) + .unwrap(); + + // Verify the rows were inserted correctly + let rows = persister.db.get_commit_statuses_by_reqid(&reqid).unwrap(); + assert_eq!(rows.len(), 2); + + let empty_account_row = + rows.iter().find(|row| row.pubkey == pubkey1).unwrap(); + assert_eq!(empty_account_row.commit_type, CommitType::EmptyAccount); + assert!(empty_account_row.undelegate); + assert_eq!(empty_account_row.data, None); + assert_eq!(empty_account_row.commit_status, CommitStatus::Pending); + assert_eq!(empty_account_row.retries_count, 0); + + let data_account_row = + rows.iter().find(|row| row.pubkey == pubkey2).unwrap(); + assert_eq!(data_account_row.commit_type, CommitType::DataAccount); + assert!(!data_account_row.undelegate); + assert_eq!(data_account_row.data, Some(vec![1, 2, 3, 4, 5])); + assert_eq!(data_account_row.commit_status, CommitStatus::Pending); + + // Update status and verify commit status and the signatures + let process_signature = Signature::new_unique(); + let finalize_signature = Some(Signature::new_unique()); + let new_status = CommitStatus::FailedFinalize(( + 1, + CommitStrategy::Args, + CommitStatusSignatures { + process_signature, + finalize_signature, + undelegate_signature: None, + }, + )); + persister + .update_status(&reqid, &pubkey1, new_status.clone()) + .unwrap(); + + let updated_row = persister + .get_commit_status(&reqid, &pubkey1) + .unwrap() + .unwrap(); + + assert_eq!(updated_row.commit_status, new_status); + + let signatures = persister + .get_signature(new_status.bundle_id().unwrap()) + .unwrap() + .unwrap(); + assert_eq!(signatures.processed_signature, process_signature); + assert_eq!(signatures.finalized_signature, finalize_signature); + } +} diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs new file mode 100644 index 000000000..8f00375f3 --- /dev/null +++ b/magicblock-committor-service/src/persist/db.rs @@ -0,0 +1,965 @@ +use std::{fmt, path::Path, str::FromStr}; + +use rusqlite::{params, Connection, Result, Transaction}; +use solana_pubkey::Pubkey; +use solana_sdk::{clock::Slot, hash::Hash, signature::Signature}; + +use super::{ + error::CommitPersistResult, + utils::{i64_into_u64, now, u64_into_i64}, + CommitStatus, CommitStatusSignatures, CommitStrategy, CommitType, +}; +// ----------------- +// CommitStatusRow +// ----------------- + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct CommitStatusRow { + /// Request ID that is common for some accounts + pub reqid: String, + /// The on chain address of the delegated account + pub pubkey: Pubkey, + /// The original owner of the delegated account on chain + pub delegated_account_owner: Pubkey, + /// The ephemeral slot at which those changes were requested + pub slot: Slot, + /// The ephemeral blockhash at which those changes were requested + pub ephemeral_blockhash: Hash, + /// If we also undelegate the account after committing it + pub undelegate: bool, + /// Lamports of the account in the ephemeral + pub lamports: u64, + /// If `true` the account commit is finalized after it was processed + pub finalize: bool, + /// The account data in the ephemeral (only set if the commit is for a data account) + pub data: Option>, + /// The type of commit that was requested, i.e. lamports only or including data + pub commit_type: CommitType, + /// Time since epoch at which the commit was requested + pub created_at: u64, + /// The current status of the commit + /// Includes the bundle_id which will be the same for accounts whose commits + /// need to be applied atomically in a single transaction + /// For single accounts a bundle_id will be gnerated as well for consistency + /// For Pending commits the bundle_id is not set + pub commit_status: CommitStatus, + /// Time since epoch at which the commit was last retried + pub last_retried_at: u64, + /// Number of times the commit was retried + pub retries_count: u16, +} + +impl fmt::Display for CommitStatusRow { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "CommitStatusRow {{ + reqid: {} + pubkey: {}, + delegated_account_owner: {}, + slot: {}, + ephemeral_blockhash: {}, + undelegate: {}, + lamports: {}, + finalize: {}, + data.len: {}, + commit_type: {}, + created_at: {}, + commit_status: {}, + last_retried_at: {}, + retries_count: {} +}}", + self.reqid, + self.pubkey, + self.delegated_account_owner, + self.slot, + self.ephemeral_blockhash, + self.undelegate, + self.lamports, + self.finalize, + self.data.as_ref().map(|x| x.len()).unwrap_or_default(), + self.commit_type.as_str(), + self.created_at, + self.commit_status, + self.last_retried_at, + self.retries_count + ) + } +} + +const ALL_COMMIT_STATUS_COLUMNS: &str = r#" + reqid, + pubkey, + delegated_account_owner, + slot, + ephemeral_blockhash, + undelegate, + lamports, + finalize, + bundle_id, + data, + commit_type, + created_at, + commit_status, + commit_strategy, + processed_signature, + finalized_signature, + undelegated_signature, + last_retried_at, + retries_count +"#; + +const SELECT_ALL_COMMIT_STATUS_COLUMNS: &str = r#" +SELECT + reqid, + pubkey, + delegated_account_owner, + slot, + ephemeral_blockhash, + undelegate, + lamports, + finalize, + bundle_id, + data, + commit_type, + created_at, + commit_status, + commit_strategy, + processed_signature, + finalized_signature, + undelegated_signature, + last_retried_at, + retries_count +FROM commit_status +"#; + +// ----------------- +// Bundle Signature +// ----------------- +// The BundleSignature table exists to store mappings from bundle_id to the signatures used +// to process/finalize these bundles. +// The signatures are repeated in the commit_status table, however the rows in there have a +// different lifetime than the bundle signature rows. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct BundleSignatureRow { + /// The id of the bundle that was commmitted + /// If an account was not part of a bundle it is treated as a single account bundle + /// for consistency. + /// The bundle_id is unique + pub bundle_id: u64, + /// The signature of the transaction on chain that processed the commit + pub processed_signature: Signature, + /// The signature of the transaction on chain that finalized the commit + /// if applicable + pub finalized_signature: Option, + /// The signature of the transaction on chain that undelegated the account(s) + /// if applicable + pub undelegate_signature: Option, + /// Time since epoch at which the bundle signature was created + pub created_at: u64, +} + +impl BundleSignatureRow { + pub fn new( + bundle_id: u64, + processed_signature: Signature, + finalized_signature: Option, + undelegate_signature: Option, + ) -> Self { + let created_at = now(); + Self { + bundle_id, + processed_signature, + finalized_signature, + undelegate_signature, + created_at, + } + } +} + +const ALL_BUNDLE_SIGNATURE_COLUMNS: &str = r#" + bundle_id, + processed_signature, + finalized_signature, + undelegate_signature, + created_at +"#; + +const SELECT_ALL_BUNDLE_SIGNATURE_COLUMNS: &str = r#" +SELECT + bundle_id, + processed_signature, + finalized_signature, + undelegate_signature, + created_at +FROM bundle_signature +"#; + +// ----------------- +// CommittorDb +// ----------------- +pub struct CommittorDb { + conn: Connection, +} + +impl CommittorDb { + pub fn new

(db_file: P) -> Result + where + P: AsRef, + { + let conn = Connection::open(db_file)?; + Ok(Self { conn }) + } + + pub fn path(&self) -> Option<&str> { + self.conn.path() + } + + // ----------------- + // Methods affecting both tables + // ----------------- + pub fn update_commit_status_and_bundle_signature( + &mut self, + reqid: &str, + pubkey: &Pubkey, + status: &CommitStatus, + bundle_signature: Option, + ) -> CommitPersistResult<()> { + let tx = self.conn.transaction()?; + Self::update_commit_status(&tx, reqid, pubkey, status)?; + if let Some(bundle_signature) = bundle_signature { + Self::insert_bundle_signature(&tx, &bundle_signature)?; + } + tx.commit()?; + Ok(()) + } + + // ----------------- + // Commit Status + // ----------------- + pub fn create_commit_status_table(&self) -> Result<()> { + // The bundle_id is NULL when we insert a pending commit + match self.conn.execute_batch( + " + BEGIN; + CREATE TABLE IF NOT EXISTS commit_status ( + reqid TEXT NOT NULL, + pubkey TEXT NOT NULL, + delegated_account_owner TEXT NOT NULL, + slot INTEGER NOT NULL, + ephemeral_blockhash TEXT NOT NULL, + undelegate INTEGER NOT NULL, + lamports INTEGER NOT NULL, + finalize INTEGER NOT NULL, + bundle_id INTEGER, + data BLOB, + commit_type TEXT NOT NULL, + created_at INTEGER NOT NULL, + commit_status TEXT NOT NULL, + commit_strategy TEXT NOT NULL, + processed_signature TEXT, + finalized_signature TEXT, + undelegated_signature TEXT, + last_retried_at INTEGER NOT NULL, + retries_count INTEGER NOT NULL + ); + CREATE INDEX IF NOT EXISTS idx_commits_pubkey ON commit_status (pubkey); + CREATE INDEX IF NOT EXISTS idx_commits_reqid ON commit_status (reqid); + COMMIT;", + ) { + Ok(_) => Ok(()), + Err(err) => { + eprintln!("Error creating commit_status table: {}", err); + Err(err) + } + } + } + + pub fn insert_commit_status_rows( + &mut self, + commit_rows: &[CommitStatusRow], + ) -> CommitPersistResult<()> { + let tx = self.conn.transaction()?; + for commit in commit_rows { + Self::insert_commit_status_row(&tx, commit)?; + } + tx.commit()?; + Ok(()) + } + + fn insert_commit_status_row( + tx: &Transaction<'_>, + commit: &CommitStatusRow, + ) -> CommitPersistResult<()> { + let (processed_signature, finalized_signature, undelegated_signature) = + match commit.commit_status.signatures() { + Some(sigs) => ( + Some(sigs.process_signature), + sigs.finalize_signature, + sigs.undelegate_signature, + ), + None => (None, None, None), + }; + tx.execute( + &format!( + "INSERT INTO commit_status ({ALL_COMMIT_STATUS_COLUMNS}) VALUES + (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19)", + ), + params![ + commit.reqid, + commit.pubkey.to_string(), + commit.delegated_account_owner.to_string(), + u64_into_i64(commit.slot), + commit.ephemeral_blockhash.to_string(), + if commit.undelegate { 1 } else { 0 }, + u64_into_i64(commit.lamports), + if commit.finalize { 1 } else { 0 }, + commit.commit_status.bundle_id().map(u64_into_i64), + commit.data.as_deref(), + commit.commit_type.as_str(), + u64_into_i64(commit.created_at), + commit.commit_status.as_str(), + commit.commit_status.commit_strategy().as_str(), + processed_signature + .as_ref() + .map(|s| s.to_string()), + finalized_signature + .as_ref() + .map(|s| s.to_string()), + undelegated_signature + .as_ref() + .map(|s| s.to_string()), + u64_into_i64(commit.last_retried_at), + commit.retries_count, + ], + )?; + Ok(()) + } + + fn update_commit_status( + tx: &Transaction<'_>, + reqid: &str, + pubkey: &Pubkey, + status: &CommitStatus, + ) -> CommitPersistResult<()> { + let query = "UPDATE commit_status + SET + commit_status = ?1, + bundle_id = ?2, + commit_strategy = ?3, + processed_signature = ?4, + finalized_signature = ?5, + undelegated_signature = ?6 + WHERE + pubkey = ?7 AND reqid = ?8"; + let stmt = &mut tx.prepare(query)?; + stmt.execute(params![ + status.as_str(), + status.bundle_id(), + status.commit_strategy().as_str(), + status.signatures().map(|s| s.process_signature.to_string()), + status + .signatures() + .and_then(|s| s.finalize_signature) + .map(|s| s.to_string()), + status + .signatures() + .and_then(|s| s.undelegate_signature) + .map(|s| s.to_string()), + pubkey.to_string(), + reqid + ])?; + Ok(()) + } + + #[cfg(test)] + fn get_commit_statuses_by_pubkey( + &self, + pubkey: &Pubkey, + ) -> CommitPersistResult> { + let query = + format!("{SELECT_ALL_COMMIT_STATUS_COLUMNS} WHERE pubkey = ?1"); + let stmt = &mut self.conn.prepare(&query)?; + let mut rows = stmt.query(params![pubkey.to_string()])?; + + extract_committor_rows(&mut rows) + } + + pub(crate) fn get_commit_statuses_by_reqid( + &self, + reqid: &str, + ) -> CommitPersistResult> { + let query = + format!("{SELECT_ALL_COMMIT_STATUS_COLUMNS} WHERE reqid = ?1"); + let stmt = &mut self.conn.prepare(&query)?; + let mut rows = stmt.query(params![reqid])?; + + extract_committor_rows(&mut rows) + } + + pub(crate) fn get_commit_status( + &self, + reqid: &str, + pubkey: &Pubkey, + ) -> CommitPersistResult> { + let query = format!( + "{SELECT_ALL_COMMIT_STATUS_COLUMNS} WHERE reqid = ?1 AND pubkey = ?2" + ); + let stmt = &mut self.conn.prepare(&query)?; + let mut rows = stmt.query(params![reqid, pubkey.to_string()])?; + + extract_committor_rows(&mut rows).map(|mut rows| rows.pop()) + } + + #[cfg(test)] + fn remove_commit_statuses_with_reqid( + &self, + reqid: &str, + ) -> CommitPersistResult<()> { + let query = "DELETE FROM commit_status WHERE reqid = ?1"; + let stmt = &mut self.conn.prepare(query)?; + stmt.execute(params![reqid])?; + Ok(()) + } + + // ----------------- + // Bundle Signature + // ----------------- + pub fn create_bundle_signature_table(&self) -> Result<()> { + match self.conn.execute_batch( + " + BEGIN; + CREATE TABLE IF NOT EXISTS bundle_signature ( + bundle_id INTEGER NOT NULL PRIMARY KEY, + processed_signature TEXT NOT NULL, + finalized_signature TEXT, + undelegate_signature TEXT, + created_at INTEGER NOT NULL + ); + CREATE INDEX IF NOT EXISTS idx_bundle_signature ON bundle_signature (bundle_id); + COMMIT;", + ) { + Ok(_) => Ok(()), + Err(err) => { + eprintln!("Error creating bundle_signature table: {}", err); + Err(err) + } + } + } + + fn insert_bundle_signature( + tx: &Transaction<'_>, + bundle_signature: &BundleSignatureRow, + ) -> CommitPersistResult<()> { + let query = if bundle_signature.finalized_signature.is_some() { + format!("INSERT OR REPLACE INTO bundle_signature ({ALL_BUNDLE_SIGNATURE_COLUMNS}) + VALUES (?1, ?2, ?3, ?4, ?5)") + } else { + format!("INSERT OR IGNORE INTO bundle_signature ({ALL_BUNDLE_SIGNATURE_COLUMNS}) + VALUES (?1, ?2, ?3, ?4, ?5)") + }; + tx.execute( + &query, + params![ + bundle_signature.bundle_id, + bundle_signature.processed_signature.to_string(), + bundle_signature + .finalized_signature + .as_ref() + .map(|s| s.to_string()), + bundle_signature + .undelegate_signature + .as_ref() + .map(|s| s.to_string()), + u64_into_i64(bundle_signature.created_at) + ], + )?; + Ok(()) + } + + pub fn get_bundle_signature_by_bundle_id( + &self, + bundle_id: u64, + ) -> CommitPersistResult> { + let query = format!( + "{SELECT_ALL_BUNDLE_SIGNATURE_COLUMNS} WHERE bundle_id = ?1" + ); + let stmt = &mut self.conn.prepare(&query)?; + let mut rows = stmt.query(params![bundle_id])?; + + if let Some(row) = rows.next()? { + let bundle_signature_row = extract_bundle_signature_row(row)?; + Ok(Some(bundle_signature_row)) + } else { + Ok(None) + } + } +} + +// ----------------- +// Commit Status Helpers +// ----------------- +fn extract_committor_rows( + rows: &mut rusqlite::Rows, +) -> CommitPersistResult> { + let mut commits = Vec::new(); + while let Some(row) = rows.next()? { + let commit_row = extract_committor_row(row)?; + commits.push(commit_row); + } + Ok(commits) +} + +fn extract_committor_row( + row: &rusqlite::Row, +) -> CommitPersistResult { + let reqid: String = row.get(0)?; + + let pubkey = { + let pubkey: String = row.get(1)?; + Pubkey::try_from(pubkey.as_str())? + }; + let delegated_account_owner = { + let delegated_account_owner: String = row.get(2)?; + Pubkey::try_from(delegated_account_owner.as_str())? + }; + let slot: Slot = { + let slot: i64 = row.get(3)?; + i64_into_u64(slot) + }; + + let ephemeral_blockhash = { + let ephemeral_blockhash: String = row.get(4)?; + Hash::from_str(ephemeral_blockhash.as_str())? + }; + + let undelegate: bool = { + let undelegate: u8 = row.get(5)?; + undelegate == 1 + }; + + let lamports: u64 = { + let lamports: i64 = row.get(6)?; + i64_into_u64(lamports) + }; + + let finalize: bool = { + let finalize: u8 = row.get(7)?; + finalize == 1 + }; + + let bundle_id: Option = { + let bundle_id: Option = row.get(8)?; + bundle_id.map(i64_into_u64) + }; + + let data: Option> = row.get(9)?; + + let commit_type = { + let commit_type: String = row.get(10)?; + CommitType::try_from(commit_type.as_str())? + }; + let created_at: u64 = { + let created_at: i64 = row.get(11)?; + i64_into_u64(created_at) + }; + let commit_status = { + let commit_status: String = row.get(12)?; + let commit_strategy = { + let commit_strategy: String = row.get(13)?; + CommitStrategy::from(commit_strategy.as_str()) + }; + let processed_signature = { + let processed_signature: Option = row.get(14)?; + processed_signature + .map(|s| Signature::from_str(s.as_str())) + .transpose()? + }; + let finalized_signature = { + let finalized_signature: Option = row.get(15)?; + finalized_signature + .map(|s| Signature::from_str(s.as_str())) + .transpose()? + }; + let undelegated_signature = { + let undelegated_signature: Option = row.get(16)?; + undelegated_signature + .map(|s| Signature::from_str(s.as_str())) + .transpose()? + }; + let sigs = processed_signature.map(|s| CommitStatusSignatures { + process_signature: s, + finalize_signature: finalized_signature, + undelegate_signature: undelegated_signature, + }); + CommitStatus::try_from(( + commit_status.as_str(), + bundle_id, + commit_strategy, + sigs, + ))? + }; + + let last_retried_at: u64 = { + let last_retried_at: i64 = row.get(17)?; + i64_into_u64(last_retried_at) + }; + let retries_count: u16 = { + let retries_count: i64 = row.get(18)?; + retries_count.try_into().unwrap_or_default() + }; + + Ok(CommitStatusRow { + reqid, + pubkey, + delegated_account_owner, + slot, + ephemeral_blockhash, + undelegate, + lamports, + finalize, + data, + commit_type, + created_at, + commit_status, + last_retried_at, + retries_count, + }) +} + +// ----------------- +// Bundle Signature Helpers +// ----------------- +fn extract_bundle_signature_row( + row: &rusqlite::Row, +) -> CommitPersistResult { + let bundle_id: u64 = { + let bundle_id: i64 = row.get(0)?; + i64_into_u64(bundle_id) + }; + let processed_signature = { + let processed_signature: String = row.get(1)?; + Signature::from_str(processed_signature.as_str())? + }; + let finalized_signature = { + let finalized_signature: Option = row.get(2)?; + finalized_signature + .map(|s| Signature::from_str(s.as_str())) + .transpose()? + }; + let undelegate_signature = { + let undelegate_signature: Option = row.get(3)?; + undelegate_signature + .map(|s| Signature::from_str(s.as_str())) + .transpose()? + }; + let created_at: u64 = { + let created_at: i64 = row.get(4)?; + i64_into_u64(created_at) + }; + + Ok(BundleSignatureRow { + bundle_id, + processed_signature, + finalized_signature, + undelegate_signature, + created_at, + }) +} + +#[cfg(test)] +mod test { + use super::*; + + fn setup_db() -> CommittorDb { + let db = CommittorDb::new(":memory:").unwrap(); + db.create_commit_status_table().unwrap(); + db.create_bundle_signature_table().unwrap(); + db + } + + // ----------------- + // Commit Status + // ----------------- + fn create_commit_status_row(reqid: &str) -> CommitStatusRow { + CommitStatusRow { + reqid: reqid.to_string(), + pubkey: Pubkey::new_unique(), + delegated_account_owner: Pubkey::new_unique(), + slot: 100, + ephemeral_blockhash: Hash::new_unique(), + undelegate: false, + lamports: 100, + finalize: true, + data: None, + commit_type: CommitType::EmptyAccount, + created_at: 1000, + commit_status: CommitStatus::Pending, + last_retried_at: 1000, + retries_count: 0, + } + } + + #[test] + fn test_round_trip_commit_status_rows() { + let one_unbundled_commit_row_no_data = CommitStatusRow { + reqid: "req-123".to_string(), + pubkey: Pubkey::new_unique(), + delegated_account_owner: Pubkey::new_unique(), + slot: 100, + ephemeral_blockhash: Hash::new_unique(), + undelegate: false, + lamports: 100, + finalize: true, + data: None, + commit_type: CommitType::EmptyAccount, + created_at: 1000, + commit_status: CommitStatus::Pending, + last_retried_at: 1000, + retries_count: 0, + }; + + let two_bundled_commit_row_with_data = CommitStatusRow { + reqid: "req-123".to_string(), + pubkey: Pubkey::new_unique(), + delegated_account_owner: Pubkey::new_unique(), + slot: 100, + ephemeral_blockhash: Hash::new_unique(), + undelegate: false, + lamports: 2000, + finalize: true, + data: Some(vec![1, 2, 3]), + commit_type: CommitType::DataAccount, + created_at: 1000, + commit_status: CommitStatus::FailedProcess(( + 2, + CommitStrategy::Args, + None, + )), + last_retried_at: 1000, + retries_count: 0, + }; + + let mut db = setup_db(); + db.insert_commit_status_rows(&[ + one_unbundled_commit_row_no_data.clone(), + two_bundled_commit_row_with_data.clone(), + ]) + .unwrap(); + + let one = db + .get_commit_statuses_by_pubkey( + &one_unbundled_commit_row_no_data.pubkey, + ) + .unwrap(); + assert_eq!(one.len(), 1); + assert_eq!(one[0], one_unbundled_commit_row_no_data); + + let two = db + .get_commit_statuses_by_pubkey( + &two_bundled_commit_row_with_data.pubkey, + ) + .unwrap(); + assert_eq!(two.len(), 1); + assert_eq!(two[0], two_bundled_commit_row_with_data); + + let by_reqid = db + .get_commit_statuses_by_reqid( + &one_unbundled_commit_row_no_data.reqid, + ) + .unwrap(); + assert_eq!(by_reqid.len(), 2); + assert_eq!( + by_reqid, + [ + one_unbundled_commit_row_no_data, + two_bundled_commit_row_with_data + ] + ); + } + + #[test] + fn test_commits_with_reqid() { + let mut db = setup_db(); + const REQID_ONE: &str = "req-123"; + const REQID_TWO: &str = "req-456"; + + let commit_row_one = create_commit_status_row(REQID_ONE); + let commit_row_one_other = create_commit_status_row(REQID_ONE); + let commit_row_two = create_commit_status_row(REQID_TWO); + db.insert_commit_status_rows(&[ + commit_row_one.clone(), + commit_row_one_other.clone(), + commit_row_two.clone(), + ]) + .unwrap(); + + let commits_one = db.get_commit_statuses_by_reqid(REQID_ONE).unwrap(); + assert_eq!(commits_one.len(), 2); + assert_eq!(commits_one[0], commit_row_one); + assert_eq!(commits_one[1], commit_row_one_other); + + let commits_two = db.get_commit_statuses_by_reqid(REQID_TWO).unwrap(); + assert_eq!(commits_two.len(), 1); + assert_eq!(commits_two[0], commit_row_two); + + // Remove commits with REQID_ONE + db.remove_commit_statuses_with_reqid(REQID_ONE).unwrap(); + let commits_one_after_removal = + db.get_commit_statuses_by_reqid(REQID_ONE).unwrap(); + assert_eq!(commits_one_after_removal.len(), 0); + + let commits_two_after_removal = + db.get_commit_statuses_by_reqid(REQID_TWO).unwrap(); + assert_eq!(commits_two_after_removal.len(), 1); + } + + // ----------------- + // Bundle Signature and Commit Status Updates + // ----------------- + fn create_bundle_signature_row( + commit_status: &CommitStatus, + ) -> Option { + commit_status + .bundle_id() + .map(|bundle_id| BundleSignatureRow { + bundle_id, + processed_signature: Signature::new_unique(), + finalized_signature: None, + undelegate_signature: None, + created_at: 1000, + }) + } + + #[test] + fn test_upsert_bundle_signature() { + let mut db = setup_db(); + + let process_only = + BundleSignatureRow::new(1, Signature::new_unique(), None, None); + let process_finalize_and_undelegate = BundleSignatureRow::new( + 2, + Signature::new_unique(), + Some(Signature::new_unique()), + Some(Signature::new_unique()), + ); + + // Add two rows, one with finalize and undelegate signatures + { + let tx = db.conn.transaction().unwrap(); + CommittorDb::insert_bundle_signature(&tx, &process_only).unwrap(); + CommittorDb::insert_bundle_signature( + &tx, + &process_finalize_and_undelegate, + ) + .unwrap(); + tx.commit().unwrap(); + } + + // Ensure we update with finalized and undelegate sigs + let process_now_with_finalize_and_undelegate = { + let tx = db.conn.transaction().unwrap(); + let process_now_with_finalize = BundleSignatureRow::new( + process_only.bundle_id, + process_finalize_and_undelegate.processed_signature, + Some(Signature::new_unique()), + Some(Signature::new_unique()), + ); + CommittorDb::insert_bundle_signature( + &tx, + &process_now_with_finalize, + ) + .unwrap(); + tx.commit().unwrap(); + + process_now_with_finalize + }; + assert_eq!( + db.get_bundle_signature_by_bundle_id(1).unwrap().unwrap(), + process_now_with_finalize_and_undelegate + ); + + // Ensure we don't erase finalized/undelegate sigs + { + let tx = db.conn.transaction().unwrap(); + let finalizes_now_only_process = BundleSignatureRow::new( + process_finalize_and_undelegate.bundle_id, + process_finalize_and_undelegate.processed_signature, + None, + None, + ); + CommittorDb::insert_bundle_signature( + &tx, + &finalizes_now_only_process, + ) + .unwrap(); + tx.commit().unwrap(); + } + assert_eq!( + db.get_bundle_signature_by_bundle_id(2).unwrap().unwrap(), + process_finalize_and_undelegate + ); + } + + #[test] + fn test_update_commit_status() { + let mut db = setup_db(); + const REQID: &str = "req-123"; + + let failing_commit_row = create_commit_status_row(REQID); + let success_commit_row = create_commit_status_row(REQID); + db.insert_commit_status_rows(&[ + failing_commit_row.clone(), + success_commit_row.clone(), + ]) + .unwrap(); + + // Update the statuses + let new_failing_status = + CommitStatus::FailedProcess((22, CommitStrategy::FromBuffer, None)); + db.update_commit_status_and_bundle_signature( + &failing_commit_row.reqid, + &failing_commit_row.pubkey, + &new_failing_status, + None, + ) + .unwrap(); + let sigs = CommitStatusSignatures { + process_signature: Signature::new_unique(), + finalize_signature: None, + undelegate_signature: None, + }; + let new_success_status = + CommitStatus::Succeeded((33, CommitStrategy::Args, sigs)); + let success_signatures_row = + create_bundle_signature_row(&new_success_status); + let success_signatures = success_signatures_row.clone().unwrap(); + db.update_commit_status_and_bundle_signature( + &success_commit_row.reqid, + &success_commit_row.pubkey, + &new_success_status, + success_signatures_row, + ) + .unwrap(); + + // Verify the statuses were updated + let failed_commit_row = db + .get_commit_status(REQID, &failing_commit_row.pubkey) + .unwrap() + .unwrap(); + assert_eq!(failed_commit_row.commit_status, new_failing_status); + + let succeeded_commit_row = db + .get_commit_status(REQID, &success_commit_row.pubkey) + .unwrap() + .unwrap(); + assert_eq!(succeeded_commit_row.commit_status, new_success_status); + let signature_row = + db.get_bundle_signature_by_bundle_id(33).unwrap().unwrap(); + assert_eq!( + signature_row.processed_signature, + success_signatures.processed_signature, + ); + assert_eq!(signature_row.finalized_signature, None); + } +} diff --git a/magicblock-committor-service/src/persist/error.rs b/magicblock-committor-service/src/persist/error.rs new file mode 100644 index 000000000..4980225f1 --- /dev/null +++ b/magicblock-committor-service/src/persist/error.rs @@ -0,0 +1,38 @@ +use thiserror::Error; + +pub type CommitPersistResult = Result; + +#[derive(Error, Debug)] +pub enum CommitPersistError { + #[error("RusqliteError: '{0}' ({0:?})")] + RusqliteError(#[from] rusqlite::Error), + + #[error("ParsePubkeyError: '{0}' ({0:?})")] + ParsePubkeyError(#[from] solana_sdk::pubkey::ParsePubkeyError), + + #[error("ParseSignatureError: '{0}' ({0:?})")] + ParseSignatureError(#[from] solana_sdk::signature::ParseSignatureError), + + #[error("ParseHashError: '{0}' ({0:?})")] + ParseHahsError(#[from] solana_sdk::hash::ParseHashError), + + #[error("Invalid Commity Type: '{0}' ({0:?})")] + InvalidCommitType(String), + + #[error("Invalid Commit Status: '{0}' ({0:?})")] + InvalidCommitStatus(String), + + #[error( + "Commit Status update requires status with bundle id: '{0}' ({0:?})" + )] + CommitStatusUpdateRequiresStatusWithBundleId(String), + + #[error("Commit Status needs bundle id: '{0}' ({0:?})")] + CommitStatusNeedsBundleId(String), + + #[error("Commit Status needs signatures: '{0}' ({0:?})")] + CommitStatusNeedsSignatures(String), + + #[error("Commit Status needs commit strategy: '{0}' ({0:?})")] + CommitStatusNeedsStrategy(String), +} diff --git a/magicblock-committor-service/src/persist/mod.rs b/magicblock-committor-service/src/persist/mod.rs new file mode 100644 index 000000000..21a9005a0 --- /dev/null +++ b/magicblock-committor-service/src/persist/mod.rs @@ -0,0 +1,11 @@ +mod commit_persister; +mod db; +pub mod error; +mod types; +mod utils; + +pub use commit_persister::CommitPersister; +pub use db::{BundleSignatureRow, CommitStatusRow, CommittorDb}; +pub use types::{ + CommitStatus, CommitStatusSignatures, CommitStrategy, CommitType, +}; diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs new file mode 100644 index 000000000..0e6c74a3c --- /dev/null +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -0,0 +1,269 @@ +use std::fmt; + +use solana_sdk::signature::Signature; + +use crate::persist::error::CommitPersistError; + +use super::commit_strategy::CommitStrategy; + +/// The status of a committed account. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum CommitStatus { + /// We sent the request to commit this account, but haven't received a result yet. + Pending, + /// No part of the commit pipeline succeeded. + /// The commit for this account needs to be restarted from scratch. + Failed(u64), + /// The buffer and chunks account were initialized, but could either not + /// be retrieved or deserialized. It is recommended to fully re-initialize + /// them on retry. + BufferAndChunkPartiallyInitialized(u64), + /// The buffer and chunks accounts were initialized and could be + /// deserialized, however we did not complete writing to them + /// We can reuse them on retry, but need to rewrite all chunks. + BufferAndChunkInitialized(u64), + /// The buffer and chunks accounts were initialized and all data was + /// written to them (for data accounts). + /// This means on retry we can skip that step and just try to process + /// these buffers to complete the commit. + BufferAndChunkFullyInitialized(u64), + /// The commit is part of a bundle that contains too many commits to be included + /// in a single transaction. Thus we cannot commit any of them. + PartOfTooLargeBundleToProcess(u64), + /// The commmit was properly initialized and added to a chunk of instructions to process + /// commits via a transaction. For large commits the buffer and chunk accounts were properly + /// prepared and haven't been closed. + FailedProcess((u64, CommitStrategy, Option)), + /// The commit was properly processed but the requested finalize transaction failed. + FailedFinalize((u64, CommitStrategy, CommitStatusSignatures)), + /// The commit was properly processed and finalized but the requested undelegate transaction failed. + FailedUndelegate((u64, CommitStrategy, CommitStatusSignatures)), + /// The commit was successfully processed and finalized. + Succeeded((u64, CommitStrategy, CommitStatusSignatures)), +} + +impl fmt::Display for CommitStatus { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + CommitStatus::Pending => write!(f, "Pending"), + CommitStatus::Failed(bundle_id) => { + write!(f, "Failed({})", bundle_id) + } + CommitStatus::BufferAndChunkPartiallyInitialized(bundle_id) => { + write!(f, "BufferAndChunkPartiallyInitialized({})", bundle_id) + } + CommitStatus::BufferAndChunkInitialized(bundle_id) => { + write!(f, "BufferAndChunkInitialized({})", bundle_id) + } + CommitStatus::BufferAndChunkFullyInitialized(bundle_id) => { + write!(f, "BufferAndChunkFullyInitialized({})", bundle_id) + } + CommitStatus::PartOfTooLargeBundleToProcess(bundle_id) => { + write!(f, "PartOfTooLargeBundleToProcess({})", bundle_id) + } + CommitStatus::FailedProcess((bundle_id, strategy, sigs)) => { + write!( + f, + "FailedProcess({}, {}, {:?})", + bundle_id, + strategy.as_str(), + sigs + ) + } + CommitStatus::FailedFinalize((bundle_id, strategy, sigs)) => { + write!( + f, + "FailedFinalize({}, {}, {:?})", + bundle_id, + strategy.as_str(), + sigs + ) + } + CommitStatus::FailedUndelegate((bundle_id, strategy, sigs)) => { + write!( + f, + "FailedUndelegate({}, {}, {:?})", + bundle_id, + strategy.as_str(), + sigs + ) + } + CommitStatus::Succeeded((bundle_id, strategy, sigs)) => { + write!( + f, + "Succeeded({}, {}, {:?})", + bundle_id, + strategy.as_str(), + sigs + ) + } + } + } +} + +impl + TryFrom<( + &str, + Option, + CommitStrategy, + Option, + )> for CommitStatus +{ + type Error = CommitPersistError; + + fn try_from( + (status, bundle_id, strategy, sigs): ( + &str, + Option, + CommitStrategy, + Option, + ), + ) -> Result { + macro_rules! get_bundle_id { + () => { + if let Some(bundle_id) = bundle_id { + bundle_id + } else { + return Err(CommitPersistError::CommitStatusNeedsBundleId( + status.to_string(), + )); + } + }; + } + macro_rules! get_sigs { + () => { + if let Some(sigs) = sigs { + sigs + } else { + return Err(CommitPersistError::CommitStatusNeedsBundleId( + status.to_string(), + )); + } + }; + } + + use CommitStatus::*; + match status { + "Pending" => Ok(Pending), + "Failed" => Ok(Failed(get_bundle_id!())), + "BufferAndChunkPartiallyInitialized" => { + Ok(BufferAndChunkPartiallyInitialized(get_bundle_id!())) + } + "BufferAndChunkInitialized" => { + Ok(BufferAndChunkInitialized(get_bundle_id!())) + } + "BufferAndChunkFullyInitialized" => { + Ok(BufferAndChunkFullyInitialized(get_bundle_id!())) + } + "PartOfTooLargeBundleToProcess" => { + Ok(PartOfTooLargeBundleToProcess(get_bundle_id!())) + } + "FailedProcess" => { + Ok(FailedProcess((get_bundle_id!(), strategy, sigs))) + } + "FailedFinalize" => { + Ok(FailedFinalize((get_bundle_id!(), strategy, get_sigs!()))) + } + "FailedUndelegate" => { + Ok(FailedUndelegate((get_bundle_id!(), strategy, get_sigs!()))) + } + "Succeeded" => { + Ok(Succeeded((get_bundle_id!(), strategy, get_sigs!()))) + } + _ => { + Err(CommitPersistError::InvalidCommitStatus(status.to_string())) + } + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct CommitStatusSignatures { + /// The signature of the transaction processing the commit + pub process_signature: Signature, + /// The signature of the transaction finalizing the commit. + /// If the account was not finalized or it failed the this is `None`. + /// If the finalize instruction was part of the process transaction then + /// this signature is the same as [Self::process_signature]. + pub finalize_signature: Option, + /// The signature of the transaction undelegating the committed accounts + /// if so requested. + /// If the account was not undelegated or it failed the this is `None`. + /// NOTE: this can be removed if we decide to perform the undelegation + /// step as part of the finalize instruction in the delegation program + pub undelegate_signature: Option, +} + +impl CommitStatus { + pub fn as_str(&self) -> &str { + use CommitStatus::*; + match self { + Pending => "Pending", + Failed(_) => "Failed", + BufferAndChunkPartiallyInitialized(_) => { + "BufferAndChunkPartiallyInitialized" + } + BufferAndChunkInitialized(_) => "BufferAndChunkInitialized", + BufferAndChunkFullyInitialized(_) => { + "BufferAndChunkFullyInitialized" + } + PartOfTooLargeBundleToProcess(_) => "PartOfTooLargeBundleToProcess", + FailedProcess(_) => "FailedProcess", + FailedFinalize(_) => "FailedFinalize", + FailedUndelegate(_) => "FailedUndelegate", + Succeeded(_) => "Succeeded", + } + } + + pub fn bundle_id(&self) -> Option { + use CommitStatus::*; + match self { + Failed(bundle_id) + | BufferAndChunkPartiallyInitialized(bundle_id) + | BufferAndChunkInitialized(bundle_id) + | BufferAndChunkFullyInitialized(bundle_id) + | PartOfTooLargeBundleToProcess(bundle_id) + | FailedProcess((bundle_id, _, _)) + | FailedFinalize((bundle_id, _, _)) + | FailedUndelegate((bundle_id, _, _)) + | Succeeded((bundle_id, _, _)) => Some(*bundle_id), + Pending => None, + } + } + + pub fn signatures(&self) -> Option { + use CommitStatus::*; + match self { + FailedProcess((_, _, sigs)) => sigs.as_ref().cloned(), + FailedFinalize((_, _, sigs)) => Some(sigs.clone()), + Succeeded((_, _, sigs)) => Some(sigs.clone()), + _ => None, + } + } + + pub fn commit_strategy(&self) -> CommitStrategy { + use CommitStatus::*; + match self { + Pending => CommitStrategy::Undetermined, + Failed(_) => CommitStrategy::Undetermined, + BufferAndChunkPartiallyInitialized(_) + | BufferAndChunkInitialized(_) + | BufferAndChunkFullyInitialized(_) => CommitStrategy::FromBuffer, + PartOfTooLargeBundleToProcess(_) => CommitStrategy::Undetermined, + FailedProcess((_, strategy, _)) => *strategy, + FailedFinalize((_, strategy, _)) => *strategy, + FailedUndelegate((_, strategy, _)) => *strategy, + Succeeded((_, strategy, _)) => *strategy, + } + } + + /// The commit fully succeeded and no retry is necessary. + pub fn is_complete(&self) -> bool { + use CommitStatus::*; + matches!(self, Succeeded(_)) + } + + pub fn all_completed(stages: &[Self]) -> bool { + stages.iter().all(Self::is_complete) + } +} diff --git a/magicblock-committor-service/src/persist/types/commit_strategy.rs b/magicblock-committor-service/src/persist/types/commit_strategy.rs new file mode 100644 index 000000000..8dc011d46 --- /dev/null +++ b/magicblock-committor-service/src/persist/types/commit_strategy.rs @@ -0,0 +1,54 @@ +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum CommitStrategy { + /// The commit strategy is not known yet + Undetermined, + /// Args without the use of a lookup table + Args, + /// Args with the use of a lookup table + ArgsWithLookupTable, + /// Buffer and chunks which has the most overhead + FromBuffer, + /// Buffer and chunks with the use of a lookup table + FromBufferWithLookupTable, +} + +impl CommitStrategy { + pub fn args(use_lookup: bool) -> Self { + if use_lookup { + Self::ArgsWithLookupTable + } else { + Self::Args + } + } + + pub fn as_str(&self) -> &str { + use CommitStrategy::*; + match self { + Undetermined => "Undetermined", + Args => "Args", + ArgsWithLookupTable => "ArgsWithLookupTable", + FromBuffer => "FromBuffer", + FromBufferWithLookupTable => "FromBufferWithLookupTable", + } + } + + pub fn uses_lookup(&self) -> bool { + matches!( + self, + CommitStrategy::ArgsWithLookupTable + | CommitStrategy::FromBufferWithLookupTable + ) + } +} + +impl From<&str> for CommitStrategy { + fn from(value: &str) -> Self { + match value { + "Args" => Self::Args, + "ArgsWithLookupTable" => Self::ArgsWithLookupTable, + "FromBuffer" => Self::FromBuffer, + "FromBufferWithLookupTable" => Self::FromBufferWithLookupTable, + _ => Self::Undetermined, + } + } +} diff --git a/magicblock-committor-service/src/persist/types/commit_type.rs b/magicblock-committor-service/src/persist/types/commit_type.rs new file mode 100644 index 000000000..96324456b --- /dev/null +++ b/magicblock-committor-service/src/persist/types/commit_type.rs @@ -0,0 +1,28 @@ +use crate::persist::error::CommitPersistError; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum CommitType { + EmptyAccount, + DataAccount, +} + +impl TryFrom<&str> for CommitType { + type Error = CommitPersistError; + + fn try_from(value: &str) -> Result { + match value { + "EmptyAccount" => Ok(CommitType::EmptyAccount), + "DataAccount" => Ok(CommitType::DataAccount), + _ => Err(CommitPersistError::InvalidCommitType(value.to_string())), + } + } +} + +impl CommitType { + pub fn as_str(&self) -> &str { + match self { + CommitType::EmptyAccount => "EmptyAccount", + CommitType::DataAccount => "DataAccount", + } + } +} diff --git a/magicblock-committor-service/src/persist/types/mod.rs b/magicblock-committor-service/src/persist/types/mod.rs new file mode 100644 index 000000000..b0c68fa59 --- /dev/null +++ b/magicblock-committor-service/src/persist/types/mod.rs @@ -0,0 +1,7 @@ +mod commit_status; +mod commit_strategy; +mod commit_type; + +pub use commit_status::*; +pub use commit_strategy::*; +pub use commit_type::*; diff --git a/magicblock-committor-service/src/persist/utils.rs b/magicblock-committor-service/src/persist/utils.rs new file mode 100644 index 000000000..d5c3aaf63 --- /dev/null +++ b/magicblock-committor-service/src/persist/utils.rs @@ -0,0 +1,58 @@ +use std::time::{SystemTime, UNIX_EPOCH}; + +/// Fits a u64 into an i64, by mapping the range [0, i64::MAX] to itself, and +/// mapping the range [i64::MAX + 1, u64::MAX - 1] into the negative range of i64. +/// NOTE: this fails for u64::MAX +pub(crate) fn u64_into_i64(n: u64) -> i64 { + if n > i64::MAX as u64 { + -((n - i64::MAX as u64) as i64) + } else { + n as i64 + } +} + +/// Extracts a u64 that was fitted into an i64 by `u64_into_i64`. +pub(crate) fn i64_into_u64(n: i64) -> u64 { + if n < 0 { + n.unsigned_abs() + i64::MAX as u64 + } else { + n as u64 + } +} + +/// Gets the current timestamp in seconds since the Unix epoch +pub(crate) fn now() -> u64 { + SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("Time went backwards") + .as_secs() +} + +#[cfg(test)] +mod tests { + use super::*; + + fn round_trip(u: u64) { + let i = u64_into_i64(u); + let u2 = i64_into_u64(i); + assert_eq!(u, u2); + } + + #[test] + fn test_u64_i64_conversion_via_round_trip() { + round_trip(0); + round_trip(1); + round_trip(i64::MAX as u64); + round_trip(i64::MAX as u64 + 1); + + // NOTE: the below which points out that we cannot round trip u64::MAX, + assert_eq!(i64::MAX as u64 * 2 + 1, u64::MAX); + + // This is the largest we can roundtrip + round_trip(u64::MAX - 1); + round_trip(i64::MAX as u64 * 2); + + // This would fail: + // round_trip(u64::MAX); + } +} diff --git a/magicblock-committor-service/src/pubkeys_provider.rs b/magicblock-committor-service/src/pubkeys_provider.rs new file mode 100644 index 000000000..595b5af24 --- /dev/null +++ b/magicblock-committor-service/src/pubkeys_provider.rs @@ -0,0 +1,75 @@ +use log::*; +use std::collections::HashSet; + +use dlp::pda; +use solana_pubkey::Pubkey; +use solana_sdk::system_program; + +/// Returns all accounts needed to process/finalize a commit for the account +/// with the provided `delegated_account`. +/// NOTE: that buffer and chunk accounts are different for each commit and +/// thus are not included +pub fn provide_committee_pubkeys( + committee: &Pubkey, + owner_program: Option<&Pubkey>, +) -> HashSet { + let mut set = HashSet::new(); + set.insert(*committee); + set.insert(pda::delegation_record_pda_from_delegated_account(committee)); + set.insert(pda::delegation_metadata_pda_from_delegated_account( + committee, + )); + set.insert(pda::commit_state_pda_from_delegated_account(committee)); + set.insert(pda::commit_record_pda_from_delegated_account(committee)); + set.insert(pda::undelegate_buffer_pda_from_delegated_account(committee)); + + // NOTE: ideally we'd also include the rent_fee_payer here, but that is + // not known to the validator at the time of cloning since it is + // stored inside the delegation metadata account instead of the + // delegation record + + if let Some(owner_program) = owner_program { + set.insert(pda::program_config_from_program_id(owner_program)); + } else { + warn!( + "No owner program provided for committee pubkey {}", + committee + ); + } + set +} + +/// Returns common accounts needed for process/finalize transactions, +/// namely the program ids used and the fees vaults and the validator itself. +pub fn provide_common_pubkeys(validator: &Pubkey) -> HashSet { + let mut set = HashSet::new(); + + let deleg_program = dlp::id(); + let protocol_fees_vault = pda::fees_vault_pda(); + let validator_fees_vault = + pda::validator_fees_vault_pda_from_validator(validator); + let committor_program = magicblock_committor_program::id(); + + trace!( + "Common pubkeys: + validator: {} + delegation program: {} + protoco fees vault: {} + validator fees vault: {} + committor program: {}", + validator, + deleg_program, + protocol_fees_vault, + validator_fees_vault, + committor_program + ); + + set.insert(*validator); + set.insert(system_program::id()); + set.insert(deleg_program); + set.insert(protocol_fees_vault); + set.insert(validator_fees_vault); + set.insert(committor_program); + + set +} diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs new file mode 100644 index 000000000..1b74ba219 --- /dev/null +++ b/magicblock-committor-service/src/service.rs @@ -0,0 +1,367 @@ +use std::{fmt::Display, path::Path}; + +use log::*; +use magicblock_committor_program::Changeset; +use solana_pubkey::Pubkey; +use solana_sdk::hash::Hash; +use solana_sdk::signature::Keypair; +use tokio::{ + select, + sync::{ + mpsc::{self, error::TrySendError}, + oneshot, + }, +}; +use tokio_util::sync::CancellationToken; + +use crate::{ + commit::CommittorProcessor, + config::ChainConfig, + error::CommittorServiceResult, + persist::{BundleSignatureRow, CommitStatusRow}, + pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, +}; + +#[derive(Debug)] +pub struct LookupTables { + pub active: Vec, + pub released: Vec, +} + +#[derive(Debug)] +pub enum CommittorMessage { + ReservePubkeysForCommittee { + /// Called once the pubkeys have been reserved + respond_to: oneshot::Sender>, + /// The comittee whose pubkeys to reserve in a lookup table + /// These pubkeys are used to process/finalize the commit + committee: Pubkey, + /// The owner program of the committee + owner: Pubkey, + }, + ReserveCommonPubkeys { + /// Called once the pubkeys have been reserved + respond_to: oneshot::Sender>, + }, + ReleaseCommonPubkeys { + /// Called once the pubkeys have been released + respond_to: oneshot::Sender<()>, + }, + CommitChangeset { + /// Called once the changeset has been committed + respond_to: oneshot::Sender>, + /// The changeset to commit + changeset: Changeset, + /// The blockhash in the ephemeral at the time the commit was requested + ephemeral_blockhash: Hash, + /// If `true`, account commits will be finalized after they were processed + finalize: bool, + }, + GetCommitStatuses { + respond_to: + oneshot::Sender>>, + reqid: String, + }, + GetBundleSignatures { + respond_to: + oneshot::Sender>>, + bundle_id: u64, + }, + GetLookupTables { + respond_to: oneshot::Sender, + }, +} + +// ----------------- +// CommittorActor +// ----------------- +struct CommittorActor { + receiver: mpsc::Receiver, + processor: CommittorProcessor, +} + +impl CommittorActor { + pub fn try_new

( + receiver: mpsc::Receiver, + authority: Keypair, + persist_file: P, + chain_config: ChainConfig, + ) -> CommittorServiceResult + where + P: AsRef, + { + let processor = + CommittorProcessor::try_new(authority, persist_file, chain_config)?; + Ok(Self { + receiver, + processor, + }) + } + + async fn handle_msg(&self, msg: CommittorMessage) { + use CommittorMessage::*; + match msg { + ReservePubkeysForCommittee { + respond_to, + committee, + owner, + } => { + let pubkeys = + provide_committee_pubkeys(&committee, Some(&owner)); + let reqid = self.processor.reserve_pubkeys(pubkeys).await; + if let Err(e) = respond_to.send(reqid) { + error!("Failed to send response {:?}", e); + } + } + ReserveCommonPubkeys { respond_to } => { + let pubkeys = + provide_common_pubkeys(&self.processor.auth_pubkey()); + let reqid = self.processor.reserve_pubkeys(pubkeys).await; + if let Err(e) = respond_to.send(reqid) { + error!("Failed to send response {:?}", e); + } + } + ReleaseCommonPubkeys { respond_to } => { + let pubkeys = + provide_common_pubkeys(&self.processor.auth_pubkey()); + self.processor.release_pubkeys(pubkeys).await; + if let Err(e) = respond_to.send(()) { + error!("Failed to send response {:?}", e); + } + } + CommitChangeset { + changeset, + ephemeral_blockhash, + respond_to, + finalize, + } => { + let reqid = self + .processor + .commit_changeset(changeset, finalize, ephemeral_blockhash) + .await; + if let Err(e) = respond_to.send(reqid) { + error!("Failed to send response {:?}", e); + } + } + GetCommitStatuses { reqid, respond_to } => { + let commit_statuses = + self.processor.get_commit_statuses(&reqid); + if let Err(e) = respond_to.send(commit_statuses) { + error!("Failed to send response {:?}", e); + } + } + GetBundleSignatures { + bundle_id, + respond_to, + } => { + let sig = self.processor.get_signature(bundle_id); + if let Err(e) = respond_to.send(sig) { + error!("Failed to send response {:?}", e); + } + } + GetLookupTables { respond_to } => { + let active_tables = self.processor.active_lookup_tables().await; + let released_tables = + self.processor.released_lookup_tables().await; + if let Err(e) = respond_to.send(LookupTables { + active: active_tables, + released: released_tables, + }) { + error!("Failed to send response {:?}", e); + } + } + } + } + + pub async fn run(&mut self, cancel_token: CancellationToken) { + loop { + select! { + msg = self.receiver.recv() => { + if let Some(msg) = msg { + self.handle_msg(msg).await; + } else { + break; + } + } + _ = cancel_token.cancelled() => { + break; + } + } + } + } +} + +// ----------------- +// CommittorService +// ----------------- +pub struct CommittorService { + sender: mpsc::Sender, + cancel_token: CancellationToken, +} + +impl CommittorService { + pub fn try_start

( + authority: Keypair, + persist_file: P, + chain_config: ChainConfig, + ) -> CommittorServiceResult + where + P: Display + AsRef, + { + debug!( + "Starting committor service with config: {:?}, persisting to: {}", + chain_config, persist_file + ); + let (sender, receiver) = mpsc::channel(1_000); + let cancel_token = CancellationToken::new(); + { + let cancel_token = cancel_token.clone(); + let mut actor = CommittorActor::try_new( + receiver, + authority, + persist_file, + chain_config, + )?; + tokio::spawn(async move { + actor.run(cancel_token).await; + }); + } + Ok(Self { + sender, + cancel_token, + }) + } + + pub fn reserve_common_pubkeys( + &self, + ) -> oneshot::Receiver> { + let (tx, rx) = oneshot::channel(); + self.try_send(CommittorMessage::ReserveCommonPubkeys { + respond_to: tx, + }); + rx + } + + pub fn release_common_pubkeys(&self) -> oneshot::Receiver<()> { + let (tx, rx) = oneshot::channel(); + self.try_send(CommittorMessage::ReleaseCommonPubkeys { + respond_to: tx, + }); + rx + } + + pub fn get_bundle_signatures( + &self, + bundle_id: u64, + ) -> oneshot::Receiver>> + { + let (tx, rx) = oneshot::channel(); + self.try_send(CommittorMessage::GetBundleSignatures { + respond_to: tx, + bundle_id, + }); + rx + } + + pub fn get_lookup_tables(&self) -> oneshot::Receiver { + let (tx, rx) = oneshot::channel(); + self.try_send(CommittorMessage::GetLookupTables { respond_to: tx }); + rx + } + + pub fn stop(&self) { + self.cancel_token.cancel(); + } + + fn try_send(&self, msg: CommittorMessage) { + if let Err(TrySendError::Full(msg)) = self.sender.try_send(msg) { + error!("Failed to send commit message {:?}", msg); + } + } +} + +impl ChangesetCommittor for CommittorService { + fn reserve_pubkeys_for_committee( + &self, + committee: Pubkey, + owner: Pubkey, + ) -> oneshot::Receiver> { + let (tx, rx) = oneshot::channel(); + self.try_send(CommittorMessage::ReservePubkeysForCommittee { + respond_to: tx, + committee, + owner, + }); + rx + } + + fn commit_changeset( + &self, + changeset: Changeset, + ephemeral_blockhash: Hash, + finalize: bool, + ) -> oneshot::Receiver> { + let (tx, rx) = oneshot::channel(); + self.try_send(CommittorMessage::CommitChangeset { + respond_to: tx, + changeset, + ephemeral_blockhash, + finalize, + }); + rx + } + + fn get_commit_statuses( + &self, + reqid: String, + ) -> oneshot::Receiver>> { + let (tx, rx) = oneshot::channel(); + self.try_send(CommittorMessage::GetCommitStatuses { + respond_to: tx, + reqid, + }); + rx + } + + fn get_bundle_signatures( + &self, + bundle_id: u64, + ) -> oneshot::Receiver>> + { + let (tx, rx) = oneshot::channel(); + self.try_send(CommittorMessage::GetBundleSignatures { + respond_to: tx, + bundle_id, + }); + rx + } +} + +pub trait ChangesetCommittor: Send + Sync + 'static { + /// Reserves pubkeys used in most commits in a lookup table + fn reserve_pubkeys_for_committee( + &self, + committee: Pubkey, + owner: Pubkey, + ) -> oneshot::Receiver>; + + /// Commits the changeset and returns the reqid + fn commit_changeset( + &self, + changeset: Changeset, + ephemeral_blockhash: Hash, + finalize: bool, + ) -> oneshot::Receiver>; + + /// Gets statuses of accounts that were committed as part of a request with provided reqid + fn get_commit_statuses( + &self, + reqid: String, + ) -> oneshot::Receiver>>; + + /// Gets signatures of commits processed as part of the bundle with the provided bundle_id + fn get_bundle_signatures( + &self, + bundle_id: u64, + ) -> oneshot::Receiver>>; +} diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs new file mode 100644 index 000000000..a618ee90d --- /dev/null +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -0,0 +1,140 @@ +use std::{ + collections::HashMap, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, Mutex, + }, + time::{SystemTime, UNIX_EPOCH}, +}; + +use magicblock_committor_program::Changeset; +use solana_pubkey::Pubkey; +use tokio::sync::oneshot; + +use crate::{ + error::CommittorServiceResult, + persist::{ + BundleSignatureRow, CommitStatus, CommitStatusRow, + CommitStatusSignatures, CommitStrategy, CommitType, + }, + ChangesetCommittor, +}; +use solana_sdk::{hash::Hash, signature::Signature}; + +#[derive(Default)] +pub struct ChangesetCommittorStub { + reserved_pubkeys_for_committee: Arc>>, + #[allow(clippy::type_complexity)] + committed_changesets: Arc>>, +} + +impl ChangesetCommittor for ChangesetCommittorStub { + fn commit_changeset( + &self, + changeset: Changeset, + ephemeral_blockhash: Hash, + finalize: bool, + ) -> oneshot::Receiver> { + static REQ_ID: AtomicU64 = AtomicU64::new(0); + let reqid = REQ_ID.fetch_add(1, Ordering::Relaxed); + let (tx, rx) = tokio::sync::oneshot::channel(); + self.committed_changesets + .lock() + .unwrap() + .insert(reqid, (changeset, ephemeral_blockhash, finalize)); + tx.send(Some(reqid.to_string())).unwrap_or_else(|_| { + log::error!("Failed to send commit changeset response"); + }); + rx + } + + fn get_commit_statuses( + &self, + reqid: String, + ) -> oneshot::Receiver>> { + let reqid = reqid.parse::().unwrap(); + let commit = self.committed_changesets.lock().unwrap().remove(&reqid); + let (tx, rx) = tokio::sync::oneshot::channel(); + let Some((changeset, hash, finalize)) = commit else { + tx.send(Ok(vec![])).unwrap_or_else(|_| { + log::error!("Failed to send commit status response"); + }); + return rx; + }; + let status_rows = changeset + .accounts + .iter() + .map(|(pubkey, acc)| CommitStatusRow { + reqid: reqid.to_string(), + pubkey: *pubkey, + delegated_account_owner: acc.owner(), + slot: changeset.slot, + ephemeral_blockhash: hash, + undelegate: changeset.accounts_to_undelegate.contains(pubkey), + lamports: acc.lamports(), + finalize, + data: Some(acc.data().to_vec()), + commit_type: CommitType::DataAccount, + created_at: now(), + commit_status: CommitStatus::Succeeded(( + reqid, + CommitStrategy::FromBuffer, + CommitStatusSignatures { + process_signature: Signature::new_unique(), + finalize_signature: Some(Signature::new_unique()), + undelegate_signature: None, + }, + )), + last_retried_at: now(), + retries_count: 0, + }) + .collect(); + tx.send(Ok(status_rows)).unwrap_or_else(|_| { + log::error!("Failed to send commit status response"); + }); + rx + } + + fn get_bundle_signatures( + &self, + bundle_id: u64, + ) -> tokio::sync::oneshot::Receiver< + crate::error::CommittorServiceResult>, + > { + let (tx, rx) = tokio::sync::oneshot::channel(); + let bundle_signature = BundleSignatureRow { + bundle_id, + processed_signature: Signature::new_unique(), + finalized_signature: Some(Signature::new_unique()), + undelegate_signature: None, + created_at: now(), + }; + tx.send(Ok(Some(bundle_signature))).unwrap_or_else(|_| { + log::error!("Failed to send bundle signatures response"); + }); + rx + } + + fn reserve_pubkeys_for_committee( + &self, + committee: Pubkey, + owner: Pubkey, + ) -> oneshot::Receiver> { + let (tx, rx) = + tokio::sync::oneshot::channel::>(); + self.reserved_pubkeys_for_committee + .lock() + .unwrap() + .insert(committee, owner); + tx.send(Ok(())).unwrap_or_else(|_| { + log::error!("Failed to send response"); + }); + rx + } +} +fn now() -> u64 { + SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("Time went backwards") + .as_secs() +} diff --git a/magicblock-committor-service/src/stubs/mod.rs b/magicblock-committor-service/src/stubs/mod.rs new file mode 100644 index 000000000..9cfb6e45c --- /dev/null +++ b/magicblock-committor-service/src/stubs/mod.rs @@ -0,0 +1,2 @@ +mod changeset_committor_stub; +pub use changeset_committor_stub::ChangesetCommittorStub; diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs new file mode 100644 index 000000000..fa53f03fb --- /dev/null +++ b/magicblock-committor-service/src/transactions.rs @@ -0,0 +1,778 @@ +use std::collections::HashSet; + +use base64::{prelude::BASE64_STANDARD, Engine}; +use dlp::args::{CommitStateArgs, CommitStateFromBufferArgs}; +use magicblock_committor_program::{ + instruction::{create_close_ix, CreateCloseIxArgs}, + ChangedBundle, +}; +use solana_pubkey::Pubkey; +use solana_rpc_client::rpc_client::SerializableTransaction; +use solana_sdk::hash::Hash; +use solana_sdk::instruction::Instruction; +use solana_sdk::message::v0::Message; +use solana_sdk::message::{AddressLookupTableAccount, VersionedMessage}; +use solana_sdk::signature::Keypair; +use solana_sdk::signer::Signer; +use solana_sdk::transaction::VersionedTransaction; +use static_assertions::const_assert; + +use crate::error::{CommittorServiceError, CommittorServiceResult}; + +/// From agave rpc/src/rpc.rs [MAX_BASE64_SIZE] +pub(crate) const MAX_ENCODED_TRANSACTION_SIZE: usize = 1644; + +/// How many process and commit buffer instructions fit into a single transaction +#[allow(unused)] // serves as documentation as well +pub(crate) const MAX_PROCESS_PER_TX: u8 = 3; + +/// How many process and commit buffer instructions fit into a single transaction +/// when using address lookup tables but not including the buffer account in the +/// lookup table +#[allow(unused)] // serves as documentation as well +pub(crate) const MAX_PROCESS_PER_TX_USING_LOOKUP: u8 = 12; + +/// How many close buffer instructions fit into a single transaction +#[allow(unused)] // serves as documentation as well +pub(crate) const MAX_CLOSE_PER_TX: u8 = 7; + +/// How many close buffer instructions fit into a single transaction +/// when using address lookup tables but not including the buffer account +/// nor chunk account in the lookup table +#[allow(unused)] // serves as documentation as well +pub(crate) const MAX_CLOSE_PER_TX_USING_LOOKUP: u8 = 7; + +/// How many process and commit buffer instructions combined with close buffer instructions +/// fit into a single transaction +#[allow(unused)] // serves as documentation as well +pub(crate) const MAX_PROCESS_AND_CLOSE_PER_TX: u8 = 2; + +/// How many process and commit buffer instructions combined with +/// close buffer instructions fit into a single transaction when +/// using lookup tables but not including the buffer account +#[allow(unused)] // serves as documentation as well +pub(crate) const MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP: u8 = 4; + +/// How many finalize instructions fit into a single transaction +#[allow(unused)] // serves as documentation as well +pub(crate) const MAX_FINALIZE_PER_TX: u8 = 5; + +/// How many finalize instructions fit into a single transaction +/// when using address lookup tables +#[allow(unused)] // serves as documentation as well +pub(crate) const MAX_FINALIZE_PER_TX_USING_LOOKUP: u8 = 48; + +/// How many undelegate instructions fit into a single transaction +/// NOTE: that we assume the rent reimbursement account to be the delegated account +#[allow(unused)] // serves as documentation as well +pub(crate) const MAX_UNDELEGATE_PER_TX: u8 = 3; + +/// How many undelegate instructions fit into a single transaction +/// when using address lookup tables +/// NOTE: that we assume the rent reimbursement account to be the delegated account +#[allow(unused)] // serves as documentation as well +pub(crate) const MAX_UNDELEGATE_PER_TX_USING_LOOKUP: u8 = 16; + +// Allows us to run undelegate instructions without rechunking them since we know +// that we didn't process more than we also can undelegatge +const_assert!(MAX_PROCESS_PER_TX <= MAX_UNDELEGATE_PER_TX,); + +// Allows us to run undelegate instructions using lookup tables without rechunking +// them since we know that we didn't process more than we also can undelegatge +const_assert!( + MAX_PROCESS_PER_TX_USING_LOOKUP <= MAX_UNDELEGATE_PER_TX_USING_LOOKUP +); + +// ----------------- +// Process Commitables using Args or Buffer +// ----------------- +pub(crate) struct CommitTxReport { + /// Size of the transaction without lookup tables. + pub size_args: usize, + + /// The size of the transaction including the finalize instruction + /// when not using lookup tables the `finalize` param of + /// [size_of_commit_with_args_tx] is `true`. + pub size_args_including_finalize: Option, + + /// If the bundle fits into a single transaction using buffers without + /// using lookup tables. + /// This does not depend on the size of the data, but only the number of + /// accounts in the bundle. + pub fits_buffer: bool, + + /// If the bundle fits into a single transaction using buffers using lookup tables. + /// This does not depend on the size of the data, but only the number of + /// accounts in the bundle. + pub fits_buffer_using_lookup: bool, + + /// Size of the transaction when using lookup tables. + /// This is only determined if the [SizeOfCommitWithArgs::size] is larger than + /// [MAX_ENCODED_TRANSACTION_SIZE]. + pub size_args_with_lookup: Option, + + /// The size of the transaction including the finalize instructionk + /// when using lookup tables + /// This is only determined if the [SizeOfCommitWithArgs::size_including_finalize] + /// is larger than [MAX_ENCODED_TRANSACTION_SIZE]. + pub size_args_with_lookup_including_finalize: Option, +} + +pub(crate) fn commit_tx_report( + bundle: &ChangedBundle, + finalize: bool, +) -> CommittorServiceResult { + let auth = Keypair::new(); + + let ixs = bundle + .iter() + .map(|(_, account)| { + let args = CommitStateArgs { + // TODO(thlorenz): this is expensive, but seems unavoidable in order to reliably + // calculate the size of the transaction + data: account.data().to_vec(), + ..CommitStateArgs::default() + }; + dlp::instruction_builder::commit_state( + auth.pubkey(), + Pubkey::new_unique(), + Pubkey::new_unique(), + args, + ) + }) + .collect::>(); + + let size = encoded_tx_size(&auth, &ixs, &TransactionOpts::NoLookupTable)?; + let size_with_lookup = (size > MAX_ENCODED_TRANSACTION_SIZE) + .then(|| encoded_tx_size(&auth, &ixs, &TransactionOpts::UseLookupTable)) + .transpose()?; + + if finalize { + let mut ixs = ixs.clone(); + let finalize_ixs = bundle.iter().map(|(pubkey, _)| { + dlp::instruction_builder::finalize(auth.pubkey(), *pubkey) + }); + ixs.extend(finalize_ixs); + + let size_including_finalize = + encoded_tx_size(&auth, &ixs, &TransactionOpts::NoLookupTable)?; + let size_with_lookup_including_finalize = (size_including_finalize + > MAX_ENCODED_TRANSACTION_SIZE) + .then(|| { + encoded_tx_size(&auth, &ixs, &TransactionOpts::UseLookupTable) + }) + .transpose()?; + + Ok(CommitTxReport { + size_args: size, + fits_buffer: bundle.len() <= MAX_PROCESS_PER_TX as usize, + fits_buffer_using_lookup: bundle.len() + <= MAX_PROCESS_PER_TX_USING_LOOKUP as usize, + size_args_with_lookup: size_with_lookup, + size_args_including_finalize: Some(size_including_finalize), + size_args_with_lookup_including_finalize: + size_with_lookup_including_finalize, + }) + } else { + Ok(CommitTxReport { + size_args: size, + fits_buffer: bundle.len() <= MAX_PROCESS_PER_TX as usize, + fits_buffer_using_lookup: bundle.len() + <= MAX_PROCESS_PER_TX_USING_LOOKUP as usize, + size_args_including_finalize: None, + size_args_with_lookup: size_with_lookup, + size_args_with_lookup_including_finalize: None, + }) + } +} + +// ----------------- +// Process Commitables and Close Buffers +// ----------------- +pub(crate) fn process_commits_ix( + validator_auth: Pubkey, + pubkey: &Pubkey, + delegated_account_owner: &Pubkey, + buffer_pda: &Pubkey, + commit_args: CommitStateFromBufferArgs, +) -> Instruction { + dlp::instruction_builder::commit_state_from_buffer( + validator_auth, + *pubkey, + *delegated_account_owner, + *buffer_pda, + commit_args, + ) +} + +pub(crate) fn close_buffers_ix( + validator_auth: Pubkey, + pubkey: &Pubkey, + ephemeral_blockhash: &Hash, +) -> Instruction { + create_close_ix(CreateCloseIxArgs { + authority: validator_auth, + pubkey: *pubkey, + blockhash: *ephemeral_blockhash, + }) +} + +pub(crate) fn process_and_close_ixs( + validator_auth: Pubkey, + pubkey: &Pubkey, + delegated_account_owner: &Pubkey, + buffer_pda: &Pubkey, + ephemeral_blockhash: &Hash, + commit_args: CommitStateFromBufferArgs, +) -> Vec { + let process_ix = process_commits_ix( + validator_auth, + pubkey, + delegated_account_owner, + buffer_pda, + commit_args, + ); + let close_ix = + close_buffers_ix(validator_auth, pubkey, ephemeral_blockhash); + + vec![process_ix, close_ix] +} + +// ----------------- +// Finalize +// ----------------- +pub(crate) fn finalize_ix( + validator_auth: Pubkey, + pubkey: &Pubkey, +) -> Instruction { + dlp::instruction_builder::finalize(validator_auth, *pubkey) +} + +// ----------------- +// Helpers +// ----------------- +#[allow(clippy::enum_variant_names)] +enum TransactionOpts { + NoLookupTable, + UseLookupTable, +} +fn encoded_tx_size( + auth: &Keypair, + ixs: &[Instruction], + opts: &TransactionOpts, +) -> CommittorServiceResult { + use CommittorServiceError::*; + use TransactionOpts::*; + let lookup_tables = match opts { + NoLookupTable => vec![], + UseLookupTable => get_lookup_tables(ixs), + }; + + let versioned_msg = Message::try_compile( + &auth.pubkey(), + ixs, + &lookup_tables, + Hash::default(), + ) + .map_err(|err| { + FailedToCompileTransactionMessage( + "Calculating transaction size".to_string(), + err, + ) + })?; + let versioned_tx = VersionedTransaction::try_new( + VersionedMessage::V0(versioned_msg), + &[&auth], + ) + .map_err(|err| { + FailedToCreateTransaction( + "Calculating transaction size".to_string(), + err, + ) + })?; + + let encoded = serialize_and_encode_base64(&versioned_tx); + Ok(encoded.len()) +} + +fn serialize_and_encode_base64( + transaction: &impl SerializableTransaction, +) -> String { + // SAFETY: runs statically + let serialized = bincode::serialize(transaction).unwrap(); + BASE64_STANDARD.encode(serialized) +} + +fn get_lookup_tables(ixs: &[Instruction]) -> Vec { + let pubkeys = ixs + .iter() + .flat_map(|ix| ix.accounts.iter().map(|acc| acc.pubkey)) + .collect::>(); + + let lookup_table = AddressLookupTableAccount { + key: Pubkey::default(), + addresses: pubkeys.into_iter().collect(), + }; + vec![lookup_table] +} + +#[cfg(test)] +mod test { + use crate::{ + compute_budget::{Budget, ComputeBudget}, + pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, + }; + + use super::*; + + use dlp::args::{CommitStateArgs, CommitStateFromBufferArgs}; + use lazy_static::lazy_static; + use solana_pubkey::Pubkey; + use solana_sdk::{ + address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES, + hash::Hash, + instruction::Instruction, + message::{v0::Message, AddressLookupTableAccount, VersionedMessage}, + signature::Keypair, + signer::Signer, + transaction::VersionedTransaction, + }; + + // These tests statically determine the optimal ix count to fit into a single + // transaction and assert that the const we export in prod match those numbers. + // Thus when an instruction changes and one of those numbers with it a failing + // test alerts us. + // This is less overhead than running those static functions each time at + // startup. + + #[test] + fn test_max_process_per_tx() { + assert_eq!(super::MAX_PROCESS_PER_TX, *MAX_PROCESS_PER_TX); + assert_eq!( + super::MAX_PROCESS_PER_TX_USING_LOOKUP, + *MAX_PROCESS_PER_TX_USING_LOOKUP + ); + } + + #[test] + fn test_max_close_per_tx() { + assert_eq!(super::MAX_CLOSE_PER_TX, *MAX_CLOSE_PER_TX); + assert_eq!( + super::MAX_CLOSE_PER_TX_USING_LOOKUP, + *MAX_CLOSE_PER_TX_USING_LOOKUP + ); + } + + #[test] + fn test_max_process_and_closes_per_tx() { + assert_eq!( + super::MAX_PROCESS_AND_CLOSE_PER_TX, + *MAX_PROCESS_AND_CLOSE_PER_TX + ); + assert_eq!( + super::MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP, + *MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP + ); + } + + #[test] + fn test_max_finalize_per_tx() { + assert_eq!(super::MAX_FINALIZE_PER_TX, *MAX_FINALIZE_PER_TX); + assert_eq!( + super::MAX_FINALIZE_PER_TX_USING_LOOKUP, + *MAX_FINALIZE_PER_TX_USING_LOOKUP + ); + } + + #[test] + fn test_max_undelegate_per_tx() { + assert_eq!(super::MAX_UNDELEGATE_PER_TX, *MAX_UNDELEGATE_PER_TX); + assert_eq!( + super::MAX_UNDELEGATE_PER_TX_USING_LOOKUP, + *MAX_UNDELEGATE_PER_TX_USING_LOOKUP + ); + } + + // ----------------- + // Process Commitables using Args + // ----------------- + #[test] + fn test_log_commit_args_ix_sizes() { + // This test is used to investigate the size of the transaction related to + // the amount of committed accounts and their data size. + fn run(auth: &Keypair, ixs: usize) { + let mut tx_lines = vec![]; + use TransactionOpts::*; + for tx_opts in [NoLookupTable, UseLookupTable] { + let mut tx_sizes = vec![]; + for size in [0, 10, 20, 50, 100, 200, 500, 1024] { + let ixs = (0..ixs) + .map(|_| make_ix(auth, size)) + .collect::>(); + + let tx_size = + encoded_tx_size(auth, &ixs, &tx_opts).unwrap(); + tx_sizes.push((size, tx_size)); + } + tx_lines.push(tx_sizes); + } + let sizes = tx_lines + .into_iter() + .map(|line| { + line.into_iter() + .map(|(size, len)| format!("{:4}:{:5}", size, len)) + .collect::>() + .join("|") + }) + .collect::>() + .join("\n"); + eprintln!("{:3} ixs:\n{}", ixs, sizes); + } + fn make_ix(auth: &Keypair, data_size: usize) -> Instruction { + let data = vec![1; data_size]; + let args = CommitStateArgs { + data, + ..CommitStateArgs::default() + }; + dlp::instruction_builder::commit_state( + auth.pubkey(), + Pubkey::new_unique(), + Pubkey::new_unique(), + args, + ) + } + + let auth = &Keypair::new(); + run(auth, 0); + run(auth, 1); + run(auth, 2); + run(auth, 5); + run(auth, 8); + run(auth, 10); + run(auth, 15); + run(auth, 20); + /* + 0 ixs: + 0: 184| 10: 184| 20: 184| 50: 184| 100: 184| 200: 184| 500: 184|1024: 184 + 0: 184| 10: 184| 20: 184| 50: 184| 100: 184| 200: 184| 500: 184|1024: 184 + 1 ixs: + 0: 620| 10: 636| 20: 648| 50: 688| 100: 756| 200: 888| 500: 1288|1024: 1988 + 0: 336| 10: 348| 20: 364| 50: 404| 100: 472| 200: 604| 500: 1004|1024: 1704 + 2 ixs: + 0: 932| 10: 960| 20: 984| 50: 1064| 100: 1200| 200: 1468| 500: 2268|1024: 3664 + 0: 400| 10: 424| 20: 452| 50: 532| 100: 668| 200: 936| 500: 1736|1024: 3132 + 5 ixs: + 0: 1864| 10: 1932| 20: 1996| 50: 2196| 100: 2536| 200: 3204| 500: 5204|1024: 8696 + 0: 588| 10: 652| 20: 720| 50: 920| 100: 1260| 200: 1928| 500: 3928|1024: 7420 + 8 ixs: + 0: 2796| 10: 2904| 20: 3008| 50: 3328| 100: 3872| 200: 4940| 500: 8140|1024:13728 + 0: 776| 10: 880| 20: 988| 50: 1308| 100: 1852| 200: 2920| 500: 6120|1024:11708 + 10 ixs: + 0: 3416| 10: 3552| 20: 3684| 50: 4084| 100: 4764| 200: 6096| 500:10096|1024:17084 + 0: 900| 10: 1032| 20: 1168| 50: 1568| 100: 2248| 200: 3580| 500: 7580|1024:14568 + 15 ixs: + 0: 4972| 10: 5172| 20: 5372| 50: 5972| 100: 6992| 200: 8992| 500:14992|1024:25472 + 0: 1212| 10: 1412| 20: 1612| 50: 2212| 100: 3232| 200: 5232| 500:11232|1024:21712 + 20 ixs: + 0: 6524| 10: 6792| 20: 7056| 50: 7856| 100: 9216| 200:11884| 500:19884|1024:33856 + 0: 1528| 10: 1792| 20: 2060| 50: 2860| 100: 4220| 200: 6888| 500:14888|1024:28860 + + Legend: + + x ixs: + data size/ix: encoded size | ... + data size/ix: encoded size | ... (using lookup tables) + + Given that max transaction size is 1644 bytes, we can see that the max data size is: + + - 1 ixs: slightly larger than 500 bytes + - 2 ixs: slightly larger than 200 bytes + - 5 ixs: slightly larger than 100 bytes + - 8 ixs: slightly larger than 50 bytes + - 10 ixs: slightly larger than 20 bytes + - 15 ixs: slightly larger than 10 bytes + - 20 ixs: no data supported (only lamport changes) + + Also it is clear that using a lookup table makes a huge difference especially if we commit + lots of different accounts. + */ + } + + // ----------------- + // Process Commitables and Close Buffers + // ----------------- + lazy_static! { + pub(crate) static ref MAX_PROCESS_PER_TX: u8 = { + max_chunks_per_transaction("Max process per tx", |auth_pubkey| { + let pubkey = Pubkey::new_unique(); + let delegated_account_owner = Pubkey::new_unique(); + let buffer_pda = Pubkey::new_unique(); + let commit_args = CommitStateFromBufferArgs::default(); + vec![super::process_commits_ix( + auth_pubkey, + &pubkey, + &delegated_account_owner, + &buffer_pda, + commit_args, + )] + }) + }; + pub(crate) static ref MAX_PROCESS_PER_TX_USING_LOOKUP: u8 = { + max_chunks_per_transaction_using_lookup_table( + "Max process per tx using lookup", + |auth_pubkey, committee, delegated_account_owner| { + let buffer_pda = Pubkey::new_unique(); + let commit_args = CommitStateFromBufferArgs::default(); + vec![super::process_commits_ix( + auth_pubkey, + &committee, + &delegated_account_owner, + &buffer_pda, + commit_args, + )] + }, + None, + ) + }; + pub(crate) static ref MAX_CLOSE_PER_TX: u8 = { + let ephemeral_blockhash = Hash::default(); + max_chunks_per_transaction("Max close per tx", |auth_pubkey| { + let pubkey = Pubkey::new_unique(); + vec![super::close_buffers_ix( + auth_pubkey, + &pubkey, + &ephemeral_blockhash, + )] + }) + }; + pub(crate) static ref MAX_CLOSE_PER_TX_USING_LOOKUP: u8 = { + let ephemeral_blockhash = Hash::default(); + max_chunks_per_transaction_using_lookup_table( + "Max close per tx using lookup", + |auth_pubkey, committee, _| { + vec![super::close_buffers_ix( + auth_pubkey, + &committee, + &ephemeral_blockhash, + )] + }, + None, + ) + }; + pub(crate) static ref MAX_PROCESS_AND_CLOSE_PER_TX: u8 = { + let ephemeral_blockhash = Hash::default(); + max_chunks_per_transaction( + "Max process and close per tx", + |auth_pubkey| { + let pubkey = Pubkey::new_unique(); + let delegated_account_owner = Pubkey::new_unique(); + let buffer_pda = Pubkey::new_unique(); + let commit_args = CommitStateFromBufferArgs::default(); + super::process_and_close_ixs( + auth_pubkey, + &pubkey, + &delegated_account_owner, + &buffer_pda, + &ephemeral_blockhash, + commit_args, + ) + }, + ) + }; + pub(crate) static ref MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP: u8 = { + let ephemeral_blockhash = Hash::default(); + max_chunks_per_transaction_using_lookup_table( + "Max process and close per tx using lookup", + |auth_pubkey, committee, delegated_account_owner| { + let commit_args = CommitStateFromBufferArgs::default(); + let buffer_pda = Pubkey::new_unique(); + super::process_and_close_ixs( + auth_pubkey, + &committee, + &delegated_account_owner, + &buffer_pda, + &ephemeral_blockhash, + commit_args, + ) + }, + None, + ) + }; + } + + // ----------------- + // Finalize + // ----------------- + lazy_static! { + pub(crate) static ref MAX_FINALIZE_PER_TX: u8 = { + max_chunks_per_transaction("Max finalize per tx", |auth_pubkey| { + let pubkey = Pubkey::new_unique(); + vec![super::finalize_ix(auth_pubkey, &pubkey)] + }) + }; + pub(crate) static ref MAX_FINALIZE_PER_TX_USING_LOOKUP: u8 = { + max_chunks_per_transaction_using_lookup_table( + "Max finalize per tx using lookup", + |auth_pubkey, committee, _| { + vec![super::finalize_ix(auth_pubkey, &committee)] + }, + Some(40), + ) + }; + } + + // ----------------- + // Undelegate + // ----------------- + lazy_static! { + pub(crate) static ref MAX_UNDELEGATE_PER_TX: u8 = { + max_chunks_per_transaction("Max undelegate per tx", |auth_pubkey| { + let pubkey = Pubkey::new_unique(); + let owner_program = Pubkey::new_unique(); + vec![dlp::instruction_builder::undelegate( + auth_pubkey, + pubkey, + owner_program, + auth_pubkey, + )] + }) + }; + pub(crate) static ref MAX_UNDELEGATE_PER_TX_USING_LOOKUP: u8 = { + max_chunks_per_transaction_using_lookup_table( + "Max undelegate per tx using lookup", + |auth_pubkey, committee, owner_program| { + vec![dlp::instruction_builder::undelegate( + auth_pubkey, + committee, + owner_program, + auth_pubkey, + )] + }, + None, + ) + }; + } + + // ----------------- + // Max Chunks Per Transaction + // ----------------- + + fn max_chunks_per_transaction Vec>( + label: &str, + create_ixs: F, + ) -> u8 { + eprintln!("{}", label); + + let auth = Keypair::new(); + let auth_pubkey = auth.pubkey(); + // NOTE: the size of the budget instructions is always the same, no matter + // which budget we provide + let mut ixs = ComputeBudget::Process(Budget::default()).instructions(1); + let mut chunks = 0_u8; + loop { + ixs.extend(create_ixs(auth_pubkey)); + chunks += 1; + + // SAFETY: runs statically + let versioned_msg = + Message::try_compile(&auth_pubkey, &ixs, &[], Hash::default()) + .unwrap(); + // SAFETY: runs statically + let versioned_tx = VersionedTransaction::try_new( + VersionedMessage::V0(versioned_msg), + &[&auth], + ) + .unwrap(); + let encoded = serialize_and_encode_base64(&versioned_tx); + eprintln!("{} ixs -> {} bytes", chunks, encoded.len()); + if encoded.len() > MAX_ENCODED_TRANSACTION_SIZE { + return chunks - 1; + } + } + } + + fn extend_lookup_table( + lookup_table: &mut AddressLookupTableAccount, + auth_pubkey: Pubkey, + committee: Pubkey, + owner: Option<&Pubkey>, + ) { + let keys = provide_committee_pubkeys(&committee, owner) + .into_iter() + .chain(provide_common_pubkeys(&auth_pubkey)) + .chain(lookup_table.addresses.iter().cloned()) + .collect::>(); + lookup_table.addresses = keys.into_iter().collect(); + assert!( + lookup_table.addresses.len() <= LOOKUP_TABLE_MAX_ADDRESSES, + "Lookup table has too many ({}) addresses", + lookup_table.addresses.len() + ); + } + + fn max_chunks_per_transaction_using_lookup_table< + FI: Fn(Pubkey, Pubkey, Pubkey) -> Vec, + >( + label: &str, + create_ixs: FI, + start_at: Option, + ) -> u8 { + eprintln!("{}", label); + let auth = Keypair::new(); + let auth_pubkey = auth.pubkey(); + let mut ixs = ComputeBudget::Process(Budget::default()).instructions(1); + let mut chunks = start_at.unwrap_or_default(); + let mut lookup_table = AddressLookupTableAccount { + key: Pubkey::default(), + addresses: vec![], + }; + // If we start at specific chunk size let's prep the ixs and assume + // we are using the same addresses to avoid blowing out the lookup table + if chunks > 0 { + let committee = Pubkey::new_unique(); + let owner_program = Pubkey::new_unique(); + extend_lookup_table( + &mut lookup_table, + auth_pubkey, + committee, + Some(&owner_program), + ); + for _ in 0..chunks { + ixs.extend(create_ixs(auth_pubkey, committee, owner_program)); + } + } + loop { + let committee = Pubkey::new_unique(); + let owner_program = Pubkey::new_unique(); + ixs.extend(create_ixs(auth_pubkey, committee, owner_program)); + + chunks += 1; + extend_lookup_table( + &mut lookup_table, + auth_pubkey, + committee, + Some(&owner_program), + ); + + // SAFETY: runs statically + let versioned_msg = Message::try_compile( + &auth_pubkey, + &ixs, + &[lookup_table.clone()], + Hash::default(), + ) + .unwrap(); + // SAFETY: runs statically + let versioned_tx = VersionedTransaction::try_new( + VersionedMessage::V0(versioned_msg), + &[&auth], + ) + .unwrap(); + let encoded = serialize_and_encode_base64(&versioned_tx); + eprintln!("{} ixs -> {} bytes", chunks, encoded.len()); + if encoded.len() > MAX_ENCODED_TRANSACTION_SIZE { + return chunks - 1; + } + } + } +} diff --git a/magicblock-committor-service/src/types.rs b/magicblock-committor-service/src/types.rs new file mode 100644 index 000000000..86b4e5d7e --- /dev/null +++ b/magicblock-committor-service/src/types.rs @@ -0,0 +1,57 @@ +use std::fmt; + +use solana_sdk::instruction::Instruction; + +use crate::CommitInfo; + +/// The kind of instructions included for the particular [CommitInfo] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum InstructionsKind { + /// The commit is processed only and may include the finalize instruction + Process, + /// The buffers to facilitate are closed, but processing occurred as part + /// of another set of instructions + CloseBuffers, + /// The commit is processed and the buffers closed all as part of this set + /// of instructions + ProcessAndCloseBuffers, + /// The commit is processed previously and only finalized by this set of + /// instructions + Finalize, + /// The commit is processed and finalized previously and the committee is + /// undelegated by this set of instructions + Undelegate, +} + +impl InstructionsKind { + pub fn is_processing(&self) -> bool { + matches!( + self, + InstructionsKind::Process + | InstructionsKind::ProcessAndCloseBuffers + ) + } +} + +#[derive(Debug)] +pub struct InstructionsForCommitable { + pub instructions: Vec, + pub commit_info: CommitInfo, + pub kind: InstructionsKind, +} + +impl fmt::Display for InstructionsForCommitable { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "InstructionsForCommitable {{ + instructions.len: {}, + commit_info: {} + kind: {:?} +}}", + self.instructions.len(), + self.commit_info.pubkey(), + self.kind + ) + } +} diff --git a/magicblock-committor-service/src/undelegate.rs b/magicblock-committor-service/src/undelegate.rs new file mode 100644 index 000000000..7064d5163 --- /dev/null +++ b/magicblock-committor-service/src/undelegate.rs @@ -0,0 +1,103 @@ +use std::collections::HashMap; + +use dlp::state::DelegationMetadata; +use magicblock_rpc_client::MagicblockRpcClient; +use solana_account::ReadableAccount; +use solana_pubkey::Pubkey; +use solana_sdk::instruction::Instruction; + +use crate::{ + error::{CommittorServiceError, CommittorServiceResult}, + transactions::{MAX_UNDELEGATE_PER_TX, MAX_UNDELEGATE_PER_TX_USING_LOOKUP}, + types::{InstructionsForCommitable, InstructionsKind}, + CommitInfo, +}; + +pub(crate) async fn undelegate_commitables_ixs( + rpc_client: &MagicblockRpcClient, + validator_auth: Pubkey, + accs: Vec<(Pubkey, Pubkey)>, +) -> CommittorServiceResult> { + let delegation_metadata_pubkeys = accs + .iter() + .map(|(delegated_account, _)| { + dlp::pda::delegation_metadata_pda_from_delegated_account( + delegated_account, + ) + }) + .collect::>(); + let metadata_accs = rpc_client + .get_multiple_accounts(&delegation_metadata_pubkeys, None) + .await?; + + let mut ixs = HashMap::new(); + + for (metadata_acc, (committee, owner)) in + metadata_accs.iter().zip(accs.iter()) + { + let Some(metadata_acc) = metadata_acc else { + return Err( + CommittorServiceError::FailedToFetchDelegationMetadata( + *committee, + ), + ); + }; + let metadata = DelegationMetadata::try_from_bytes_with_discriminator( + metadata_acc.data(), + ) + .map_err(|err| { + CommittorServiceError::FailedToDeserializeDelegationMetadata( + *committee, err, + ) + })?; + + ixs.insert( + *committee, + dlp::instruction_builder::undelegate( + validator_auth, + *committee, + *owner, + metadata.rent_payer, + ), + ); + } + Ok(ixs) +} + +pub(crate) fn chunked_ixs_to_undelegate_commitables( + mut ixs: HashMap, + commit_infos: Vec, + use_lookup: bool, +) -> Vec> { + let max_per_chunk = if use_lookup { + MAX_UNDELEGATE_PER_TX_USING_LOOKUP + } else { + MAX_UNDELEGATE_PER_TX + }; + + let chunks = commit_infos + .chunks(max_per_chunk as usize) + .map(|chunk| { + chunk + .iter() + .flat_map(|commit_info| { + ixs.remove(&commit_info.pubkey()).map(|ix| { + InstructionsForCommitable { + instructions: vec![ix], + commit_info: commit_info.clone(), + kind: InstructionsKind::Undelegate, + } + }) + }) + .collect::>() + }) + .collect::>(); + + debug_assert!( + ixs.is_empty(), + "BUG: Some undelegate instructions {:?} were not matched with a commit_info: {:?}", + ixs, commit_infos + ); + + chunks +} diff --git a/magicblock-committor-service/todo-tests/ix_commit_local.rs b/magicblock-committor-service/todo-tests/ix_commit_local.rs new file mode 100644 index 000000000..b3227e3b6 --- /dev/null +++ b/magicblock-committor-service/todo-tests/ix_commit_local.rs @@ -0,0 +1,886 @@ +use log::*; +use magicblock_committor_service::{ChangesetCommittor, ComputeBudgetConfig}; +use magicblock_rpc_client::MagicblockRpcClient; +use std::collections::{HashMap, HashSet}; +use std::time::{Duration, Instant}; +use tokio::task::JoinSet; +use utils::transactions::tx_logs_contain; + +use magicblock_committor_program::{ChangedAccount, Changeset}; +use magicblock_committor_service::{ + changeset_for_slot, + config::ChainConfig, + persist::{CommitStatus, CommitStrategy}, + CommittorService, +}; +use solana_account::{Account, AccountSharedData, ReadableAccount}; +use solana_pubkey::Pubkey; +use solana_rpc_client::nonblocking::rpc_client::RpcClient; +use solana_rpc_client_api::config::RpcSendTransactionConfig; +use solana_sdk::commitment_config::CommitmentConfig; +use solana_sdk::hash::Hash; +use solana_sdk::transaction::Transaction; +use solana_sdk::{ + native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, +}; +use utils::instructions::{ + init_account_and_delegate_ixs, init_validator_fees_vault_ix, + InitAccountAndDelegateIxs, +}; + +mod utils; + +// ----------------- +// Utilities and Setup +// ----------------- +type ExpectedStrategies = HashMap; + +fn expect_strategies( + strategies: &[(CommitStrategy, u8)], +) -> ExpectedStrategies { + let mut expected_strategies = HashMap::new(); + for (strategy, count) in strategies { + *expected_strategies.entry(*strategy).or_insert(0) += count; + } + expected_strategies +} + +fn uses_lookup(expected: &ExpectedStrategies) -> bool { + expected.iter().any(|(strategy, _)| strategy.uses_lookup()) +} + +macro_rules! get_account { + ($rpc_client:ident, $pubkey:expr, $label:literal, $predicate:expr) => {{ + const GET_ACCOUNT_RETRIES: u8 = 12; + + let mut remaining_tries = GET_ACCOUNT_RETRIES; + loop { + let acc = $rpc_client + .get_account_with_commitment( + &$pubkey, + CommitmentConfig::confirmed(), + ) + .await + .ok() + .and_then(|acc| acc.value); + if let Some(acc) = acc { + if $predicate(&acc, remaining_tries) { + break acc; + } + remaining_tries -= 1; + if remaining_tries == 0 { + panic!( + "{} account ({}) does not match condition after {} retries", + $label, $pubkey, GET_ACCOUNT_RETRIES + ); + } + utils::sleep_millis(800).await; + } else { + remaining_tries -= 1; + if remaining_tries == 0 { + panic!( + "Unable to get {} account ({}) matching condition after {} retries", + $label, $pubkey, GET_ACCOUNT_RETRIES + ); + } + if remaining_tries % 10 == 0 { + debug!( + "Waiting for {} account ({}) to become available", + $label, $pubkey + ); + } + utils::sleep_millis(800).await; + } + } + }}; + ($rpc_client:ident, $pubkey:expr, $label:literal) => {{ + get_account!($rpc_client, $pubkey, $label, |_: &Account, _: u8| true) + }}; +} + +/// This needs to be run once for all tests +async fn fund_validator_auth_and_ensure_validator_fees_vault( + validator_auth: &Keypair, +) { + let rpc_client = RpcClient::new("http://localhost:7799".to_string()); + rpc_client + .request_airdrop(&validator_auth.pubkey(), 777 * LAMPORTS_PER_SOL) + .await + .unwrap(); + debug!("Airdropped to validator: {} ", validator_auth.pubkey(),); + + let validator_fees_vault_exists = rpc_client + .get_account(&validator_auth.pubkey()) + .await + .is_ok(); + + if !validator_fees_vault_exists { + let latest_block_hash = + rpc_client.get_latest_blockhash().await.unwrap(); + let init_validator_fees_vault_ix = + init_validator_fees_vault_ix(validator_auth.pubkey()); + // If this fails it might be due to a race condition where another test + // already initialized it, so we can safely ignore the error + let _ = rpc_client + .send_and_confirm_transaction_with_spinner_and_config( + &Transaction::new_signed_with_payer( + &[init_validator_fees_vault_ix], + Some(&validator_auth.pubkey()), + &[&validator_auth], + latest_block_hash, + ), + CommitmentConfig::confirmed(), + RpcSendTransactionConfig { + skip_preflight: true, + ..Default::default() + }, + ) + .await + .map_err(|err| { + error!("Failed to init validator fees vault: {}", err); + }); + } +} + +/// This needs to be run for each test that required a new counter to be delegated +async fn init_and_delegate_account_on_chain( + counter_auth: &Keypair, + bytes: u64, +) -> (Pubkey, Account) { + let rpc_client = RpcClient::new("http://localhost:7799".to_string()); + + rpc_client + .request_airdrop(&counter_auth.pubkey(), 777 * LAMPORTS_PER_SOL) + .await + .unwrap(); + debug!("Airdropped to counter auth: {} SOL", 777 * LAMPORTS_PER_SOL); + + let InitAccountAndDelegateIxs { + init: init_counter_ix, + reallocs: realloc_ixs, + delegate: delegate_ix, + pda, + rent_excempt, + } = init_account_and_delegate_ixs(counter_auth.pubkey(), bytes); + + let latest_block_hash = rpc_client.get_latest_blockhash().await.unwrap(); + // 1. Init account + rpc_client + .send_and_confirm_transaction_with_spinner_and_config( + &Transaction::new_signed_with_payer( + &[init_counter_ix], + Some(&counter_auth.pubkey()), + &[&counter_auth], + latest_block_hash, + ), + CommitmentConfig::confirmed(), + RpcSendTransactionConfig { + skip_preflight: true, + ..Default::default() + }, + ) + .await + .expect("Failed to init account"); + debug!("Init account: {:?}", pda); + + // 2. Airdrop to account for extra rent needed for reallocs + rpc_client + .request_airdrop(&pda, rent_excempt) + .await + .unwrap(); + + debug!( + "Airdropped to account: {:4} {}SOL to pay rent for {} bytes", + pda, + rent_excempt as f64 / LAMPORTS_PER_SOL as f64, + bytes + ); + + // 3. Run reallocs + for realloc_ix_chunk in realloc_ixs.chunks(10) { + let tx = Transaction::new_signed_with_payer( + realloc_ix_chunk, + Some(&counter_auth.pubkey()), + &[&counter_auth], + latest_block_hash, + ); + rpc_client + .send_and_confirm_transaction_with_spinner_and_config( + &tx, + CommitmentConfig::confirmed(), + RpcSendTransactionConfig { + skip_preflight: true, + ..Default::default() + }, + ) + .await + .expect("Failed to realloc"); + } + debug!("Reallocs done"); + + // 4. Delegate account + rpc_client + .send_and_confirm_transaction_with_spinner_and_config( + &Transaction::new_signed_with_payer( + &[delegate_ix], + Some(&counter_auth.pubkey()), + &[&counter_auth], + latest_block_hash, + ), + CommitmentConfig::confirmed(), + RpcSendTransactionConfig { + skip_preflight: true, + ..Default::default() + }, + ) + .await + .expect("Failed to delegate"); + debug!("Delegated account: {:?}", pda); + let pda_acc = get_account!(rpc_client, pda, "pda"); + + (pda, pda_acc) +} + +// ----------------- +// +++++ Tests +++++ +// ----------------- + +// ----------------- +// Single Account Commits +// ----------------- +#[tokio::test] +async fn test_ix_commit_single_account_100_bytes() { + commit_single_account(100, CommitStrategy::Args, false).await; +} + +#[tokio::test] +async fn test_ix_commit_single_account_100_bytes_and_undelegate() { + commit_single_account(100, CommitStrategy::Args, true).await; +} + +#[tokio::test] +async fn test_ix_commit_single_account_800_bytes() { + commit_single_account(800, CommitStrategy::FromBuffer, false).await; +} + +#[tokio::test] +async fn test_ix_commit_single_account_800_bytes_and_undelegate() { + commit_single_account(800, CommitStrategy::FromBuffer, true).await; +} + +#[tokio::test] +async fn test_ix_commit_single_account_one_kb() { + commit_single_account(1024, CommitStrategy::FromBuffer, false).await; +} +#[tokio::test] +async fn test_ix_commit_single_account_ten_kb() { + commit_single_account(10 * 1024, CommitStrategy::FromBuffer, false).await; +} + +async fn commit_single_account( + bytes: usize, + expected_strategy: CommitStrategy, + undelegate: bool, +) { + utils::init_logger_target(); + let slot = 10; + let validator_auth = utils::get_validator_auth(); + + fund_validator_auth_and_ensure_validator_fees_vault(&validator_auth).await; + + // Run each test with and without finalizing + for (idx, finalize) in [false, true].into_iter().enumerate() { + let service = CommittorService::try_start( + validator_auth.insecure_clone(), + ":memory:", + ChainConfig::local(ComputeBudgetConfig::new(1_000_000)), + ) + .unwrap(); + + let (changeset, chain_lamports) = { + let mut changeset = changeset_for_slot(slot); + let mut chain_lamports = HashMap::new(); + let counter_auth = Keypair::new(); + let (pda, pda_acc) = + init_and_delegate_account_on_chain(&counter_auth, bytes as u64) + .await; + let account = Account { + lamports: LAMPORTS_PER_SOL, + data: vec![8; bytes], + owner: program_flexi_counter::id(), + ..Account::default() + }; + let account_shared = AccountSharedData::from(account); + let bundle_id = idx as u64; + changeset.add(pda, (account_shared, bundle_id)); + if undelegate { + changeset.request_undelegation(pda); + } + chain_lamports.insert(pda, pda_acc.lamports()); + (changeset, chain_lamports) + }; + + ix_commit_local( + service, + changeset.clone(), + chain_lamports.clone(), + finalize, + expect_strategies(&[(expected_strategy, 1)]), + ) + .await; + } +} + +// TODO(thlorenz): once delegation program supports larger commits +// add 1MB and 10MB tests + +// ----------------- +// Multiple Account Commits +// ----------------- +#[tokio::test] +async fn test_ix_commit_two_accounts_1kb_2kb() { + utils::init_logger(); + commit_multiple_accounts( + &[1024, 2048], + 1, + expect_strategies(&[(CommitStrategy::FromBuffer, 2)]), + false, + ) + .await; +} + +#[tokio::test] +async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() { + utils::init_logger(); + commit_multiple_accounts( + &[1024, 2 * 1024, 5 * 1024, 10 * 1024], + 1, + expect_strategies(&[(CommitStrategy::FromBuffer, 4)]), + false, + ) + .await; +} + +#[tokio::test] +async fn test_commit_20_accounts_1kb_bundle_size_2() { + commit_20_accounts_1kb( + 2, + expect_strategies(&[(CommitStrategy::FromBuffer, 20)]), + ) + .await; +} + +#[tokio::test] +async fn test_commit_5_accounts_1kb_bundle_size_3() { + commit_5_accounts_1kb( + 3, + expect_strategies(&[(CommitStrategy::FromBuffer, 5)]), + false, + ) + .await; +} + +#[tokio::test] +async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() { + commit_5_accounts_1kb( + 3, + expect_strategies(&[(CommitStrategy::FromBuffer, 5)]), + true, + ) + .await; +} + +#[tokio::test] +async fn test_commit_5_accounts_1kb_bundle_size_4() { + commit_5_accounts_1kb( + 4, + expect_strategies(&[ + (CommitStrategy::FromBuffer, 1), + (CommitStrategy::FromBufferWithLookupTable, 4), + ]), + false, + ) + .await; +} + +#[tokio::test] +async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() { + commit_5_accounts_1kb( + 4, + expect_strategies(&[ + (CommitStrategy::FromBuffer, 1), + (CommitStrategy::FromBufferWithLookupTable, 4), + ]), + true, + ) + .await; +} + +#[tokio::test] +async fn test_commit_20_accounts_1kb_bundle_size_3() { + commit_20_accounts_1kb( + 3, + expect_strategies(&[(CommitStrategy::FromBuffer, 20)]), + ) + .await; +} + +#[tokio::test] +async fn test_commit_20_accounts_1kb_bundle_size_4() { + commit_20_accounts_1kb( + 4, + expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]), + ) + .await; +} + +#[tokio::test] +async fn test_commit_20_accounts_1kb_bundle_size_6() { + commit_20_accounts_1kb( + 6, + expect_strategies(&[ + (CommitStrategy::FromBufferWithLookupTable, 18), + // Two accounts don't make it into the bundles of size 6 + (CommitStrategy::FromBuffer, 2), + ]), + ) + .await; +} + +#[tokio::test] +async fn test_commit_8_accounts_1kb_bundle_size_8() { + commit_8_accounts_1kb( + 8, + expect_strategies(&[ + // Four accounts don't make it into the bundles of size 8, but + // that bundle also needs lookup tables + (CommitStrategy::FromBufferWithLookupTable, 8), + ]), + ) + .await; +} +#[tokio::test] +async fn test_commit_20_accounts_1kb_bundle_size_8() { + commit_20_accounts_1kb( + 8, + expect_strategies(&[ + // Four accounts don't make it into the bundles of size 8, but + // that bundle also needs lookup tables + (CommitStrategy::FromBufferWithLookupTable, 20), + ]), + ) + .await; +} + +async fn commit_5_accounts_1kb( + bundle_size: usize, + expected_strategies: ExpectedStrategies, + undelegate_all: bool, +) { + utils::init_logger(); + let accs = (0..5).map(|_| 1024).collect::>(); + commit_multiple_accounts( + &accs, + bundle_size, + expected_strategies, + undelegate_all, + ) + .await; +} + +async fn commit_8_accounts_1kb( + bundle_size: usize, + expected_strategies: ExpectedStrategies, +) { + utils::init_logger(); + let accs = (0..8).map(|_| 1024).collect::>(); + commit_multiple_accounts(&accs, bundle_size, expected_strategies, false) + .await; +} + +async fn commit_20_accounts_1kb( + bundle_size: usize, + expected_strategies: ExpectedStrategies, +) { + utils::init_logger(); + let accs = (0..20).map(|_| 1024).collect::>(); + commit_multiple_accounts(&accs, bundle_size, expected_strategies, false) + .await; +} + +async fn commit_multiple_accounts( + bytess: &[usize], + bundle_size: usize, + expected_strategies: ExpectedStrategies, + undelegate_all: bool, +) { + utils::init_logger(); + let slot = 10; + let validator_auth = utils::get_validator_auth(); + + fund_validator_auth_and_ensure_validator_fees_vault(&validator_auth).await; + + for finalize in [false, true] { + let mut changeset = changeset_for_slot(slot); + + let service = CommittorService::try_start( + validator_auth.insecure_clone(), + ":memory:", + ChainConfig::local(ComputeBudgetConfig::new(1_000_000)), + ) + .unwrap(); + + let committees = + bytess.iter().map(|_| Keypair::new()).collect::>(); + + let mut chain_lamports = HashMap::new(); + let expected_strategies = expected_strategies.clone(); + + let mut join_set = JoinSet::new(); + let mut bundle_id = 0; + + for (idx, (bytes, counter_auth)) in + bytess.iter().zip(committees.into_iter()).enumerate() + { + if idx % bundle_size == 0 { + bundle_id += 1; + } + + let bytes = *bytes; + join_set.spawn(async move { + let (pda, pda_acc) = init_and_delegate_account_on_chain( + &counter_auth, + bytes as u64, + ) + .await; + + let account = Account { + lamports: LAMPORTS_PER_SOL, + data: vec![idx as u8; bytes], + owner: program_flexi_counter::id(), + ..Account::default() + }; + let account_shared = AccountSharedData::from(account); + let changed_account = + ChangedAccount::from((account_shared, bundle_id as u64)); + + // We can only undelegate accounts that are finalized + let request_undelegation = + finalize && (undelegate_all || idx % 2 == 0); + ( + pda, + pda_acc, + changed_account, + counter_auth.pubkey(), + request_undelegation, + ) + }); + } + + for ( + pda, + pda_acc, + changed_account, + counter_pubkey, + request_undelegation, + ) in join_set.join_all().await + { + changeset.add(pda, changed_account); + if request_undelegation { + changeset.request_undelegation(counter_pubkey); + } + chain_lamports.insert(pda, pda_acc.lamports()); + } + + if uses_lookup(&expected_strategies) { + let mut join_set = JoinSet::new(); + join_set.spawn(service.reserve_common_pubkeys()); + let owners = changeset.owners(); + for committee in changeset.account_keys().iter() { + join_set.spawn(service.reserve_pubkeys_for_committee( + **committee, + *owners.get(committee).unwrap(), + )); + } + debug!( + "Registering lookup tables for {} committees", + changeset.account_keys().len() + ); + join_set.join_all().await; + } + + ix_commit_local( + service, + changeset.clone(), + chain_lamports.clone(), + finalize, + expected_strategies, + ) + .await; + } +} + +// TODO(thlorenz): once delegation program supports larger commits add the following +// tests +// +// ## Scenario 1 +// +// All realloc instructions still fit into the same transaction as the init instruction +// of each account + +// ## Scenario 2 +// +// Max size that is allowed on solana (10MB) +// https://solana.com/docs/core/accounts +// 9,996,760 bytes 9.53MB requiring 69.57 SOL to be rent exempt + +// This requires a chunk tracking account of 1.30KB which can be fully allocated +// as part of the init instruction. Since no larger buffers are possible this +// chunk account size suffices and we don't have to worry about reallocs +// of that tracking account + +// This test pushes the validator to the max, sending >10K transactions in +// order to allocate enough space and write the chunks. +// It shows that committing buffers in that size range is not practically +// feasible, but still we ensure here that it is handled. + +// ----------------- +// Test Executor +// ----------------- +async fn ix_commit_local( + service: CommittorService, + changeset: Changeset, + chain_lamports: HashMap, + finalize: bool, + expected_strategies: ExpectedStrategies, +) { + let rpc_client = RpcClient::new("http://localhost:7799".to_string()); + + let ephemeral_blockhash = Hash::default(); + let reqid = service + .commit_changeset(changeset.clone(), ephemeral_blockhash, finalize) + .await + .unwrap() + .unwrap(); + let statuses = service.get_commit_statuses(reqid).await.unwrap().unwrap(); + service.release_common_pubkeys().await.unwrap(); + + debug!( + "{}", + statuses + .iter() + .map(|x| x.to_string()) + .collect::>() + .join("\n") + ); + assert_eq!(statuses.len(), changeset.accounts.len()); + assert!(CommitStatus::all_completed( + &statuses + .iter() + .map(|x| x.commit_status.clone()) + .collect::>() + )); + let mut strategies = ExpectedStrategies::new(); + for res in statuses { + let change = changeset.accounts.get(&res.pubkey).cloned().unwrap(); + let lamports = if finalize { + change.lamports() + } else { + // The commit state account will hold only the lamports needed + // to be rent exempt and debit the delegated account to reach the + // lamports of the account as changed in the ephemeral + change.lamports() - chain_lamports[&res.pubkey] + }; + + // Track the strategy used + let strategy = res.commit_status.commit_strategy(); + let strategy_count = strategies.entry(strategy).or_insert(0); + *strategy_count += 1; + + // Ensure that the signatures are pointing to the correct transactions + let signatures = + res.commit_status.signatures().expect("Missing signatures"); + + assert!( + tx_logs_contain( + &rpc_client, + &signatures.process_signature, + "CommitState" + ) + .await + ); + + // If we finalized the commit then the delegate account should have the + // committed state, otherwise it is still held in the commit state account + // NOTE: that we verify data/lamports via the get_account! condition + if finalize { + assert!( + signatures.finalize_signature.is_some(), + "Missing finalize signature" + ); + assert!( + tx_logs_contain( + &rpc_client, + &signatures.finalize_signature.unwrap(), + "Finalize" + ) + .await + ); + if res.undelegate { + assert!( + signatures.undelegate_signature.is_some(), + "Missing undelegate signature" + ); + assert!( + tx_logs_contain( + &rpc_client, + &signatures.undelegate_signature.unwrap(), + "Undelegate" + ) + .await + ); + } + get_account!( + rpc_client, + res.pubkey, + "delegated state", + |acc: &Account, remaining_tries: u8| { + let matches_data = acc.data() == change.data() + && acc.lamports() == lamports; + // When we finalize it is possible to also undelegate the account + let expected_owner = if res.undelegate { + program_flexi_counter::id() + } else { + dlp::id() + }; + let matches_undelegation = acc.owner().eq(&expected_owner); + let matches_all = matches_data && matches_undelegation; + + if !matches_all && remaining_tries % 4 == 0 { + if !matches_data { + trace!( + "Account ({}) data {} != {} || {} != {}", + res.pubkey, + acc.data().len(), + change.data().len(), + acc.lamports(), + lamports + ); + } + if !matches_undelegation { + trace!( + "Account ({}) is {} but should be. Owner {} != {}", + res.pubkey, + if res.undelegate { + "not undelegated" + } else { + "undelegated" + }, + acc.owner(), + expected_owner, + ); + } + } + matches_all + } + ) + } else { + let commit_state_pda = + dlp::pda::commit_state_pda_from_delegated_account(&res.pubkey); + get_account!( + rpc_client, + commit_state_pda, + "commit state", + |acc: &Account, remaining_tries: u8| { + if remaining_tries % 4 == 0 { + trace!( + "Commit state ({}) {} == {}? {} == {}?", + commit_state_pda, + acc.data().len(), + change.data().len(), + acc.lamports(), + lamports + ); + } + acc.data() == change.data() && acc.lamports() == lamports + } + ) + }; + } + + // Compare the strategies used with the expected ones + debug!("Strategies used: {:?}", strategies); + assert_eq!( + strategies, expected_strategies, + "Strategies used do not match expected ones" + ); + + let expect_empty_lookup_tables = false; + // changeset.accounts.len() == changeset.accounts_to_undelegate.len(); + if expect_empty_lookup_tables { + let lookup_tables = service.get_lookup_tables().await.unwrap(); + assert!(lookup_tables.active.is_empty()); + + if utils::TEST_TABLE_CLOSE { + let mut closing_tables = lookup_tables.released; + + // Tables deactivate after ~2.5 mins (150secs), but most times + // it takes a lot longer so we allow double the time + const MAX_TIME_TO_CLOSE: Duration = Duration::from_secs(300); + info!( + "Waiting for lookup tables close for up to {} secs", + MAX_TIME_TO_CLOSE.as_secs() + ); + + let start = Instant::now(); + let rpc_client = MagicblockRpcClient::from(rpc_client); + loop { + let accs = rpc_client + .get_multiple_accounts_with_commitment( + &closing_tables, + CommitmentConfig::confirmed(), + None, + ) + .await + .unwrap(); + let closed_pubkeys = accs + .into_iter() + .zip(closing_tables.iter()) + .filter_map(|(acc, pubkey)| { + if acc.is_none() { + Some(*pubkey) + } else { + None + } + }) + .collect::>(); + closing_tables.retain(|pubkey| { + if closed_pubkeys.contains(pubkey) { + debug!("Table {} closed", pubkey); + false + } else { + true + } + }); + if closing_tables.is_empty() { + break; + } + debug!( + "Still waiting for {} released table(s) to close", + closing_tables.len() + ); + if Instant::now() - start > MAX_TIME_TO_CLOSE { + panic!( + "Timed out waiting for tables close. Still open: {}", + closing_tables + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(", ") + ); + } + utils::sleep_millis(10_000).await; + } + } + } +} diff --git a/magicblock-committor-service/todo-tests/utils/instructions.rs b/magicblock-committor-service/todo-tests/utils/instructions.rs new file mode 100644 index 000000000..148ae6ce6 --- /dev/null +++ b/magicblock-committor-service/todo-tests/utils/instructions.rs @@ -0,0 +1,50 @@ +use solana_pubkey::Pubkey; +use solana_sdk::{instruction::Instruction, rent::Rent}; + +pub fn init_validator_fees_vault_ix(validator_auth: Pubkey) -> Instruction { + dlp::instruction_builder::init_validator_fees_vault( + validator_auth, + validator_auth, + validator_auth, + ) +} + +pub struct InitAccountAndDelegateIxs { + pub init: Instruction, + pub reallocs: Vec, + pub delegate: Instruction, + pub pda: Pubkey, + pub rent_excempt: u64, +} + +pub fn init_account_and_delegate_ixs( + payer: Pubkey, + bytes: u64, +) -> InitAccountAndDelegateIxs { + use program_flexi_counter::instruction::*; + use program_flexi_counter::state::*; + let init_counter_ix = create_init_ix(payer, "COUNTER".to_string()); + let rent_exempt = Rent::default().minimum_balance(bytes as usize); + let mut realloc_ixs = vec![]; + if bytes + > magicblock_committor_program::consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE + as u64 + { + // TODO: we may have to chunk those + let reallocs = bytes + / magicblock_committor_program::consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE + as u64; + for i in 0..reallocs { + realloc_ixs.push(create_realloc_ix(payer, bytes, i as u16)); + } + } + let delegate_ix = create_delegate_ix(payer); + let pda = FlexiCounter::pda(&payer).0; + InitAccountAndDelegateIxs { + init: init_counter_ix, + reallocs: realloc_ixs, + delegate: delegate_ix, + pda, + rent_excempt: rent_exempt, + } +} diff --git a/magicblock-committor-service/todo-tests/utils/mod.rs b/magicblock-committor-service/todo-tests/utils/mod.rs new file mode 100644 index 000000000..0b9433747 --- /dev/null +++ b/magicblock-committor-service/todo-tests/utils/mod.rs @@ -0,0 +1,51 @@ +use std::env; + +use env_logger::Target; +use solana_sdk::signature::Keypair; + +pub mod instructions; +pub mod transactions; +pub const TEST_TABLE_CLOSE: bool = cfg!(feature = "test_table_close"); + +pub async fn sleep_millis(millis: u64) { + tokio::time::sleep(tokio::time::Duration::from_millis(millis)).await; +} + +pub fn init_logger() { + let mut builder = env_logger::builder(); + builder + .format_timestamp(None) + .format_module_path(false) + .format_target(false) + .format_source_path(true) + .is_test(true); + + if let Ok(path) = env::var("TEST_LOG_FILE") { + builder.target(Target::Pipe(Box::new( + std::fs::File::create(path).unwrap(), + ))); + } + let _ = builder.try_init(); +} + +pub fn init_logger_target() { + let _ = env_logger::builder() + .format_timestamp(None) + .is_test(true) + .try_init(); +} + +/// This is the test authority used in the delegation program +/// https://github.com/magicblock-labs/delegation-program/blob/7fc0ae9a59e48bea5b046b173ea0e34fd433c3c7/tests/fixtures/accounts.rs#L46 +/// It is compiled in as the authority for the validator vault when we build via +/// `cargo build-sbf --features=unit_test_config` +pub fn get_validator_auth() -> Keypair { + const VALIDATOR_AUTHORITY: [u8; 64] = [ + 251, 62, 129, 184, 107, 49, 62, 184, 1, 147, 178, 128, 185, 157, 247, + 92, 56, 158, 145, 53, 51, 226, 202, 96, 178, 248, 195, 133, 133, 237, + 237, 146, 13, 32, 77, 204, 244, 56, 166, 172, 66, 113, 150, 218, 112, + 42, 110, 181, 98, 158, 222, 194, 130, 93, 175, 100, 190, 106, 9, 69, + 156, 80, 96, 72, + ]; + Keypair::from_bytes(&VALIDATOR_AUTHORITY).unwrap() +} diff --git a/magicblock-committor-service/todo-tests/utils/transactions.rs b/magicblock-committor-service/todo-tests/utils/transactions.rs new file mode 100644 index 000000000..f9e2edc06 --- /dev/null +++ b/magicblock-committor-service/todo-tests/utils/transactions.rs @@ -0,0 +1,58 @@ +use solana_rpc_client::nonblocking::rpc_client::RpcClient; +use solana_rpc_client_api::config::RpcTransactionConfig; +use solana_sdk::{commitment_config::CommitmentConfig, signature::Signature}; + +pub async fn tx_logs_contain( + rpc_client: &RpcClient, + signature: &Signature, + needle: &str, +) -> bool { + // NOTE: we encountered the following error a few times which makes tests fail for the + // wrong reason: + // Error { + // request: Some(GetTransaction), + // kind: SerdeJson( Error( + // "invalid type: null, + // expected struct EncodedConfirmedTransactionWithStatusMeta", + // line: 0, column: 0)) + // } + // Therefore we retry a few times. + const MAX_RETRIES: usize = 5; + let mut retries = MAX_RETRIES; + let tx = loop { + match rpc_client + .get_transaction_with_config( + signature, + RpcTransactionConfig { + commitment: Some(CommitmentConfig::confirmed()), + max_supported_transaction_version: Some(0), + ..Default::default() + }, + ) + .await + { + Ok(tx) => break tx, + Err(err) => { + log::error!("Failed to get transaction: {}", err); + retries -= 1; + if retries == 0 { + panic!( + "Failed to get transaction after {} retries", + MAX_RETRIES + ); + } + tokio::time::sleep(tokio::time::Duration::from_millis(100)) + .await; + } + }; + }; + let logs = tx + .transaction + .meta + .as_ref() + .unwrap() + .log_messages + .clone() + .unwrap_or_else(Vec::new); + logs.iter().any(|log| log.contains(needle)) +} diff --git a/magicblock-rpc-client/Cargo.toml b/magicblock-rpc-client/Cargo.toml new file mode 100644 index 000000000..2bc7430a5 --- /dev/null +++ b/magicblock-rpc-client/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "magicblock-rpc-client" +version.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true +license.workspace = true +edition.workspace = true + +[dependencies] +log = { workspace = true } +solana-rpc-client = { workspace = true } +solana-rpc-client-api = { workspace = true } +solana-sdk = { workspace = true } +solana-transaction-status-client-types = { workspace = true } +thiserror = { workspace = true } +tokio = { workspace = true } + +[dev-dependencies] +env_logger = { workspace = true } +tokio = { workspace = true, features = ["rt", "macros"] } diff --git a/magicblock-rpc-client/src/lib.rs b/magicblock-rpc-client/src/lib.rs new file mode 100644 index 000000000..f710fb3a9 --- /dev/null +++ b/magicblock-rpc-client/src/lib.rs @@ -0,0 +1,512 @@ +use log::*; +use std::{ + sync::Arc, + time::{Duration, Instant}, +}; + +use solana_rpc_client::{ + nonblocking::rpc_client::RpcClient, rpc_client::SerializableTransaction, +}; +use solana_rpc_client_api::client_error::ErrorKind as RpcClientErrorKind; +use solana_rpc_client_api::{ + config::RpcSendTransactionConfig, request::RpcError, +}; +use solana_sdk::{ + account::Account, + address_lookup_table::state::{AddressLookupTable, LookupTableMeta}, + clock::Slot, + commitment_config::{CommitmentConfig, CommitmentLevel}, + hash::Hash, + pubkey::Pubkey, + signature::Signature, + transaction::TransactionError, +}; +use solana_transaction_status_client_types::UiTransactionEncoding; +use tokio::task::JoinSet; + +/// The encoding to use when sending transactions +pub const SEND_TRANSACTION_ENCODING: UiTransactionEncoding = + UiTransactionEncoding::Base64; + +/// The configuration to use when sending transactions +pub const SEND_TRANSACTION_CONFIG: RpcSendTransactionConfig = + RpcSendTransactionConfig { + preflight_commitment: None, + skip_preflight: true, + encoding: Some(SEND_TRANSACTION_ENCODING), + max_retries: None, + min_context_slot: None, + }; + +// ----------------- +// MagicBlockRpcClientError +// ----------------- +#[derive(Debug, thiserror::Error)] +pub enum MagicBlockRpcClientError { + #[error("RPC Client error: {0}")] + RpcClientError(#[from] solana_rpc_client_api::client_error::Error), + + #[error("Error getting blockhash: {0} ({0:?})")] + GetLatestBlockhash(solana_rpc_client_api::client_error::Error), + + #[error("Error getting slot: {0} ({0:?})")] + GetSlot(solana_rpc_client_api::client_error::Error), + + #[error("Error deserializing lookup table: {0}")] + LookupTableDeserialize(solana_sdk::instruction::InstructionError), + + #[error("Error sending transaction: {0} ({0:?})")] + SendTransaction(solana_rpc_client_api::client_error::Error), + + #[error("Error getting signature status for: {0} {1}")] + CannotGetTransactionSignatureStatus(Signature, String), + + #[error( + "Error confirming signature status of {0} at desired commitment level {1}" + )] + CannotConfirmTransactionSignatureStatus(Signature, CommitmentLevel), + + #[error("Sent transaction {1} but got error: {0:?}")] + SentTransactionError(TransactionError, Signature), +} + +impl MagicBlockRpcClientError { + /// Returns the signature of the transaction that caused the error + /// if available. + pub fn signature(&self) -> Option { + use MagicBlockRpcClientError::*; + match self { + CannotGetTransactionSignatureStatus(sig, _) + | SentTransactionError(_, sig) + | CannotConfirmTransactionSignatureStatus(sig, _) => Some(*sig), + _ => None, + } + } +} + +pub type MagicBlockRpcClientResult = + std::result::Result; + +// ----------------- +// SendAndConfirmTransaction Config and Outcome +// ----------------- +pub enum MagicBlockSendTransactionConfig { + /// Just send the transaction and return the signature. + Send, + /// Send a transaction and confirm it with the given parameters. + SendAndConfirm { + /// If provided we will wait for the given blockhash to become valid if + /// getting the signature status fails due to `BlockhashNotFound`. + wait_for_blockhash_to_become_valid: Option, + /// If provided we will try multiple time so find the signature status + /// of the transaction at the 'processed' level even if the recent blockhash + /// already became valid. + wait_for_processed_level: Option, + /// How long to wait in between checks for processed commitment level. + check_for_processed_interval: Option, + /// If provided it will wait for the transaction to be committed at the given + /// commitment level. If not we just wait for the transaction to be processed and + /// return the processed status. + wait_for_commitment_level: Option, + /// How long to wait in between checks for desired commitment level. + check_for_commitment_interval: Option, + }, +} + +// This seems rather large, but if we pick a lower value then test fail locally running +// against a (busy) solana test validator +// I verified that it actually takes this long for the transaction to become available +// in the explorer. Power settings on my machine actually affect this behavior. +const DEFAULT_MAX_TIME_TO_PROCESSED: Duration = Duration::from_millis(50_000); + +impl MagicBlockSendTransactionConfig { + // This will be used if we change the strategy for reallocs or writes + #[allow(dead_code)] + pub fn ensure_sent() -> Self { + Self::Send + } + + pub fn ensure_processed() -> Self { + Self::SendAndConfirm { + wait_for_blockhash_to_become_valid: Some(Duration::from_millis( + 2_000, + )), + wait_for_processed_level: Some(DEFAULT_MAX_TIME_TO_PROCESSED), + check_for_processed_interval: Some(Duration::from_millis(400)), + wait_for_commitment_level: None, + check_for_commitment_interval: None, + } + } + + pub fn ensure_committed() -> Self { + Self::SendAndConfirm { + wait_for_blockhash_to_become_valid: Some(Duration::from_millis( + 2_000, + )), + wait_for_processed_level: Some(DEFAULT_MAX_TIME_TO_PROCESSED), + check_for_processed_interval: Some(Duration::from_millis(400)), + // NOTE: that this time is after we already verified that the transaction was + // processed + wait_for_commitment_level: Some(Duration::from_millis(8_000)), + check_for_commitment_interval: Some(Duration::from_millis(400)), + } + } + + pub fn ensures_committed(&self) -> bool { + use MagicBlockSendTransactionConfig::*; + match self { + Send => false, + SendAndConfirm { + wait_for_commitment_level, + .. + } => wait_for_commitment_level.is_some(), + } + } +} + +pub struct MagicBlockSendTransactionOutcome { + signature: Signature, + processed_err: Option, + confirmed_err: Option, +} + +impl MagicBlockSendTransactionOutcome { + pub fn into_signature(self) -> Signature { + self.signature + } + + pub fn into_signature_and_error( + self, + ) -> (Signature, Option) { + (self.signature, self.confirmed_err.or(self.processed_err)) + } + + /// Returns the error that occurred when processing the transaction. + /// NOTE: this is never set if we use the [MagicBlockSendConfig::Send] option. + pub fn error(&self) -> Option<&TransactionError> { + self.confirmed_err.as_ref().or(self.processed_err.as_ref()) + } +} + +// ----------------- +// MagicBlockRpcClient +// ----------------- + +// Derived from error from helius RPC: Failed to download accounts: Error { request: Some(GetMultipleAccounts), kind: RpcError(RpcResponseError { code: -32602, message: "Too many inputs provided; max 100", data: Empty }) } +const MAX_MULTIPLE_ACCOUNTS: usize = 100; + +/// Wraps a [RpcClient] to provide improved functionality, specifically +/// for sending transactions. +#[derive(Clone)] +pub struct MagicblockRpcClient { + client: Arc, +} + +impl From for MagicblockRpcClient { + fn from(client: RpcClient) -> Self { + Self::new(Arc::new(client)) + } +} + +impl MagicblockRpcClient { + /// Create a new [MagicBlockRpcClient] from an existing [RpcClient]. + pub fn new(client: Arc) -> Self { + Self { client } + } + + pub async fn get_latest_blockhash( + &self, + ) -> MagicBlockRpcClientResult { + self.client + .get_latest_blockhash() + .await + .map_err(MagicBlockRpcClientError::GetLatestBlockhash) + } + + pub async fn get_slot(&self) -> MagicBlockRpcClientResult { + self.client + .get_slot() + .await + .map_err(MagicBlockRpcClientError::GetSlot) + } + + pub async fn get_account( + &self, + pubkey: &Pubkey, + ) -> MagicBlockRpcClientResult> { + let err = match self.client.get_account(pubkey).await { + Ok(acc) => return Ok(Some(acc)), + Err(err) => match err.kind() { + RpcClientErrorKind::RpcError(rpc_err) => { + if let RpcError::ForUser(msg) = rpc_err { + if msg.starts_with("AccountNotFound") { + return Ok(None); + } + } + err + } + _ => err, + }, + }; + Err(MagicBlockRpcClientError::RpcClientError(err)) + } + pub async fn get_multiple_accounts( + &self, + pubkeys: &[Pubkey], + max_per_fetch: Option, + ) -> MagicBlockRpcClientResult>> { + self.get_multiple_accounts_with_commitment( + pubkeys, + self.commitment(), + max_per_fetch, + ) + .await + } + + pub async fn get_multiple_accounts_with_commitment( + &self, + pubkeys: &[Pubkey], + commitment: CommitmentConfig, + max_per_fetch: Option, + ) -> MagicBlockRpcClientResult>> { + let max_per_fetch = max_per_fetch.unwrap_or(MAX_MULTIPLE_ACCOUNTS); + + let mut join_set = JoinSet::new(); + for pubkey_chunk in pubkeys.chunks(max_per_fetch) { + let client = self.client.clone(); + let pubkeys = pubkey_chunk.to_vec(); + join_set.spawn(async move { + client + .get_multiple_accounts_with_commitment(&pubkeys, commitment) + .await + }); + } + let chunked_results = join_set.join_all().await; + let mut results = Vec::new(); + for result in chunked_results { + match result { + Ok(accs) => results.extend(accs.value), + Err(err) => { + return Err(MagicBlockRpcClientError::RpcClientError(err)) + } + } + } + Ok(results) + } + + pub async fn get_lookup_table_meta( + &self, + pubkey: &Pubkey, + ) -> MagicBlockRpcClientResult> { + let acc = self.get_account(pubkey).await?; + let Some(acc) = acc else { return Ok(None) }; + + let table = + AddressLookupTable::deserialize(&acc.data).map_err(|err| { + MagicBlockRpcClientError::LookupTableDeserialize(err) + })?; + Ok(Some(table.meta)) + } + + pub async fn get_lookup_table_addresses( + &self, + pubkey: &Pubkey, + ) -> MagicBlockRpcClientResult>> { + let acc = self.get_account(pubkey).await?; + let Some(acc) = acc else { return Ok(None) }; + + let table = + AddressLookupTable::deserialize(&acc.data).map_err(|err| { + MagicBlockRpcClientError::LookupTableDeserialize(err) + })?; + Ok(Some(table.addresses.to_vec())) + } + + pub async fn request_airdrop( + &self, + pubkey: &Pubkey, + lamports: u64, + ) -> MagicBlockRpcClientResult { + self.client + .request_airdrop(pubkey, lamports) + .await + .map_err(MagicBlockRpcClientError::RpcClientError) + } + + pub fn commitment(&self) -> CommitmentConfig { + self.client.commitment() + } + + pub fn commitment_level(&self) -> CommitmentLevel { + self.commitment().commitment + } + + pub async fn wait_for_next_slot(&self) -> MagicBlockRpcClientResult { + let slot = self.get_slot().await?; + self.wait_for_higher_slot(slot).await + } + + pub async fn wait_for_higher_slot( + &self, + slot: Slot, + ) -> MagicBlockRpcClientResult { + let higher_slot = loop { + let next_slot = self.get_slot().await?; + if next_slot > slot { + break next_slot; + } + tokio::time::sleep(Duration::from_millis(100)).await; + }; + + Ok(higher_slot) + } + + /// Sends a transaction skipping preflight checks and then attempts to confirm + /// it if so configured + /// To confirm a transaction it uses the `client.commitment()` when requesting + /// `get_signature_status_with_commitment` + /// + /// Does not support: + /// - durable nonce transactions + pub async fn send_transaction( + &self, + tx: &impl SerializableTransaction, + config: &MagicBlockSendTransactionConfig, + ) -> MagicBlockRpcClientResult { + let sig = self + .client + .send_transaction_with_config(tx, SEND_TRANSACTION_CONFIG) + .await + .map_err(MagicBlockRpcClientError::SendTransaction)?; + + let MagicBlockSendTransactionConfig::SendAndConfirm { + wait_for_processed_level, + check_for_processed_interval, + wait_for_blockhash_to_become_valid, + wait_for_commitment_level, + check_for_commitment_interval, + } = config + else { + return Ok(MagicBlockSendTransactionOutcome { + signature: sig, + processed_err: None, + confirmed_err: None, + }); + }; + + // 1. Get Signature Processed Status to Fail early on failed transactions + let start = Instant::now(); + let recent_blockhash = tx.get_recent_blockhash(); + debug_assert!( + recent_blockhash != &Hash::default(), + "BUG: recent blockhash is not set for the transaction" + ); + let processed_status = loop { + let status = self + .client + .get_signature_status_with_commitment( + &sig, + CommitmentConfig::processed(), + ) + .await?; + + let check_for_processed_interval = check_for_processed_interval + .unwrap_or_else(|| Duration::from_millis(200)); + match status { + Some(status) => break status, + None => { + if let Some(wait_for_blockhash_to_become_valid) = + wait_for_blockhash_to_become_valid + { + let blockhash_found = self + .client + .is_blockhash_valid( + recent_blockhash, + CommitmentConfig::processed(), + ) + .await?; + if !blockhash_found + && &start.elapsed() + < wait_for_blockhash_to_become_valid + { + trace!( + "Waiting for blockhash {} to become valid", + recent_blockhash + ); + tokio::time::sleep(Duration::from_millis(400)) + .await; + continue; + } else if start.elapsed() + < wait_for_processed_level.unwrap_or_default() + { + tokio::time::sleep(check_for_processed_interval) + .await; + continue; + } else { + return Err(MagicBlockRpcClientError::CannotGetTransactionSignatureStatus( + sig, + format!("blockhash {} found", if blockhash_found { + "was" + } else { + "was not" + }), + )); + } + } else { + return Err(MagicBlockRpcClientError::CannotGetTransactionSignatureStatus( + sig, + "timed out finding blockhash".to_string() + )); + } + } + } + }; + + if let Err(err) = processed_status { + return Err(MagicBlockRpcClientError::SentTransactionError( + err, sig, + )); + } + + // 2. At this point we know the transaction isn't failing + // and just wait for desired status + let confirmed_status = if let Some(wait_for_commitment_level) = + wait_for_commitment_level + { + let now = Instant::now(); + let check_for_commitment_interval = check_for_commitment_interval + .unwrap_or_else(|| Duration::from_millis(200)); + loop { + let confirmed_status = self + .client + .get_signature_status_with_commitment( + &sig, + self.client.commitment(), + ) + .await?; + + if let Some(confirmed_status) = confirmed_status { + break Some(confirmed_status); + } + + if &now.elapsed() < wait_for_commitment_level { + tokio::time::sleep(check_for_commitment_interval).await; + continue; + } else { + return Err(MagicBlockRpcClientError::CannotConfirmTransactionSignatureStatus( + sig, + self.client.commitment().commitment, + )); + } + } + } else { + None + }; + + Ok(MagicBlockSendTransactionOutcome { + signature: sig, + processed_err: processed_status.err(), + confirmed_err: confirmed_status.and_then(|status| status.err()), + }) + } +} diff --git a/magicblock-table-mania/Cargo.toml b/magicblock-table-mania/Cargo.toml new file mode 100644 index 000000000..c9866425c --- /dev/null +++ b/magicblock-table-mania/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "magicblock-table-mania" +version.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true +license.workspace = true +edition.workspace = true + +[dependencies] +ed25519-dalek = { workspace = true } +log = { workspace = true } +magicblock-rpc-client = { workspace = true } +rand = { workspace = true } +sha3 = { workspace = true } +solana-pubkey = { workspace = true } +solana-rpc-client = { workspace = true } +solana-rpc-client-api = { workspace = true } +solana-sdk = { workspace = true } +thiserror = { workspace = true } +tokio = { workspace = true } + +[dev-dependencies] +env_logger = { workspace = true } +paste = { workspace = true } +tokio = { workspace = true, features = ["rt", "macros"] } + +[features] +default = [] +test_table_close = [] +# Needed to allow multiple tests to run in parallel without trying to +# use the same lookup table address +randomize_lookup_table_slot = [] diff --git a/magicblock-table-mania/src/derive_keypair.rs b/magicblock-table-mania/src/derive_keypair.rs new file mode 100644 index 000000000..be3315eaa --- /dev/null +++ b/magicblock-table-mania/src/derive_keypair.rs @@ -0,0 +1,60 @@ +use ed25519_dalek::{PublicKey, SecretKey}; +use solana_sdk::{clock::Slot, signature::Keypair, signer::Signer}; + +pub fn derive_keypair( + authority: &Keypair, + slot: Slot, + sub_slot: Slot, +) -> Keypair { + let mut seeds = authority.pubkey().to_bytes().to_vec(); + seeds.extend_from_slice(&slot.to_le_bytes()); + seeds.extend_from_slice(&sub_slot.to_le_bytes()); + derive_from_keypair(authority, &seeds) +} + +fn derive_from_keypair(keypair: &Keypair, message: &[u8]) -> Keypair { + let sig = keypair.sign_message(message); + derive_insecure(sig.as_ref()) +} + +fn derive_insecure(message: &[u8]) -> Keypair { + let hash = ::digest(message); + let seed = &hash.as_slice()[0..32]; + + // Create a keypair using the seed bytes + let secret = SecretKey::from_bytes(seed).unwrap(); + let public = PublicKey::from(&secret); + + // Convert to Solana Keypair format + let mut keypair_bytes = [0u8; 64]; + keypair_bytes[0..32].copy_from_slice(secret.as_bytes()); + keypair_bytes[32..64].copy_from_slice(&public.to_bytes()); + + Keypair::from_bytes(&keypair_bytes).unwrap() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_derive_keypair_is_deterministic() { + let authority = Keypair::new(); + let mut first = vec![]; + for slot in 0..100 { + for sub_slot in 0..100 { + let keypair = derive_keypair(&authority, slot, sub_slot); + first.push(keypair.to_bytes()); + } + } + let mut second = vec![]; + for slot in 0..100 { + for sub_slot in 0..100 { + let keypair = derive_keypair(&authority, slot, sub_slot); + second.push(keypair.to_bytes()); + } + } + + assert_eq!(first, second); + } +} diff --git a/magicblock-table-mania/src/error.rs b/magicblock-table-mania/src/error.rs new file mode 100644 index 000000000..dee396521 --- /dev/null +++ b/magicblock-table-mania/src/error.rs @@ -0,0 +1,27 @@ +use solana_pubkey::Pubkey; +use thiserror::Error; + +pub type TableManiaResult = std::result::Result; + +#[derive(Error, Debug)] +pub enum TableManiaError { + #[error("MagicBlockRpcClientError: {0} ({0:?})")] + MagicBlockRpcClientError( + #[from] magicblock_rpc_client::MagicBlockRpcClientError, + ), + + #[error("Cannot extend deactivated table {0}.")] + CannotExtendDeactivatedTable(Pubkey), + + #[error("Can only use one authority for a TableMania instance. {0} does not match {1}.")] + InvalidAuthority(Pubkey, Pubkey), + + #[error("Can only extend by {0} pubkeys at a time, but was provided {1}")] + MaxExtendPubkeysExceeded(usize, usize), + + #[error("Timed out waiting for remote tables to update: {0}")] + TimedOutWaitingForRemoteTablesToUpdate(String), + + #[error("Timed out waiting for local tables to update: {0}")] + TimedOutWaitingForLocalTablesToUpdate(String), +} diff --git a/magicblock-table-mania/src/find_tables.rs b/magicblock-table-mania/src/find_tables.rs new file mode 100644 index 000000000..75e0c9b25 --- /dev/null +++ b/magicblock-table-mania/src/find_tables.rs @@ -0,0 +1,47 @@ +use magicblock_rpc_client::{MagicBlockRpcClientResult, MagicblockRpcClient}; +use solana_pubkey::Pubkey; +use solana_sdk::{ + address_lookup_table::instruction::derive_lookup_table_address, + clock::Slot, signature::Keypair, signer::Signer, +}; + +use crate::LookupTable; + +pub struct FindOpenTablesOutcome { + pub addresses_searched: Vec, + pub tables: Vec, +} + +pub async fn find_open_tables( + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + min_slot: Slot, + max_slot: Slot, + sub_slots_per_slot: u64, +) -> MagicBlockRpcClientResult { + let addresses_searched = + (min_slot..max_slot).fold(Vec::new(), |mut addresses, slot| { + for sub_slot in 0..sub_slots_per_slot { + let derived_auth = + LookupTable::derive_keypair(authority, slot, sub_slot); + let (table_address, _) = + derive_lookup_table_address(&derived_auth.pubkey(), slot); + addresses.push(table_address); + } + addresses + }); + + let mut tables = Vec::new(); + let accounts = rpc_client + .get_multiple_accounts(&addresses_searched, None) + .await?; + for (pubkey, account) in addresses_searched.iter().zip(accounts.iter()) { + if account.is_some() { + tables.push(*pubkey); + } + } + Ok(FindOpenTablesOutcome { + addresses_searched, + tables, + }) +} diff --git a/magicblock-table-mania/src/lib.rs b/magicblock-table-mania/src/lib.rs new file mode 100644 index 000000000..f88fb6c94 --- /dev/null +++ b/magicblock-table-mania/src/lib.rs @@ -0,0 +1,10 @@ +mod derive_keypair; +pub mod error; +mod find_tables; +mod lookup_table; +mod lookup_table_rc; +mod manager; + +pub use find_tables::find_open_tables; +pub use lookup_table::LookupTable; +pub use manager::*; diff --git a/magicblock-table-mania/src/lookup_table.rs b/magicblock-table-mania/src/lookup_table.rs new file mode 100644 index 000000000..3c1e54063 --- /dev/null +++ b/magicblock-table-mania/src/lookup_table.rs @@ -0,0 +1,535 @@ +use log::*; +use std::fmt; +use std::sync::Mutex; + +use crate::derive_keypair; +use crate::error::{TableManiaError, TableManiaResult}; +use magicblock_rpc_client::MagicBlockRpcClientError; +use magicblock_rpc_client::{ + MagicBlockSendTransactionConfig, MagicblockRpcClient, +}; +use solana_pubkey::Pubkey; +use solana_sdk::address_lookup_table::state::{ + LookupTableMeta, LOOKUP_TABLE_MAX_ADDRESSES, +}; +use solana_sdk::commitment_config::CommitmentLevel; +use solana_sdk::slot_hashes::MAX_ENTRIES; +use solana_sdk::{ + address_lookup_table as alt, + clock::Slot, + signature::{Keypair, Signature}, + signer::Signer, + transaction::Transaction, +}; + +/// Determined via trial and error. The keys themselves take up +/// 27 * 32 bytes = 864 bytes. +pub const MAX_ENTRIES_AS_PART_OF_EXTEND: u64 = 27; + +#[derive(Debug)] +pub enum LookupTable { + Active { + derived_auth: Keypair, + table_address: Pubkey, + pubkeys: Mutex>, + creation_slot: u64, + creation_sub_slot: u64, + init_signature: Signature, + extend_signatures: Vec, + }, + Deactivated { + derived_auth: Keypair, + table_address: Pubkey, + deactivation_slot: u64, + deactivate_signature: Signature, + }, +} + +impl fmt::Display for LookupTable { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Active { + derived_auth, + table_address, + pubkeys, + creation_slot, + creation_sub_slot, + init_signature, + extend_signatures, + } => { + let comma_separated_pubkeys = pubkeys + .lock() + .expect("pubkeys mutex poisoned") + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(", "); + let comma_separated_sigs = extend_signatures + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(", "); + write!( + f, + "LookupTable: Active {{ + derived_auth: {} + table_address: {} + pubkeys: {} + creation_slot: {} + creation_sub_slot: {} + init_signature: {} + extend_signatures: {} +}}", + derived_auth.pubkey(), + table_address, + comma_separated_pubkeys, + creation_slot, + creation_sub_slot, + init_signature, + comma_separated_sigs + ) + } + Self::Deactivated { + derived_auth, + table_address, + deactivation_slot, + deactivate_signature, + } => { + write!( + f, + "LookupTable: Deactivated {{ derived_auth: {}, table_address: {}, deactivation_slot: {}, deactivate_signature: {} }}", + derived_auth.pubkey(), + table_address, + deactivation_slot, + deactivate_signature, + ) + } + } + } +} + +impl LookupTable { + pub fn derived_auth(&self) -> &Keypair { + match self { + Self::Active { derived_auth, .. } => derived_auth, + Self::Deactivated { derived_auth, .. } => derived_auth, + } + } + pub fn table_address(&self) -> &Pubkey { + match self { + Self::Active { table_address, .. } => table_address, + Self::Deactivated { table_address, .. } => table_address, + } + } + + /// All pubkeys requested, no matter of the `reqid`. + /// The same pubkey might be included twice if requested with different `reqid`. + pub fn pubkeys(&self) -> Option> { + match self { + Self::Active { pubkeys, .. } => { + Some(pubkeys.lock().expect("pubkeys mutex poisoned").to_vec()) + } + Self::Deactivated { .. } => None, + } + } + + pub fn creation_slot(&self) -> Option { + match self { + Self::Active { creation_slot, .. } => Some(*creation_slot), + Self::Deactivated { .. } => None, + } + } + + pub fn has_more_capacity(&self) -> bool { + self.pubkeys() + .is_some_and(|x| x.len() < LOOKUP_TABLE_MAX_ADDRESSES) + } + + pub fn contains(&self, pubkey: &Pubkey, _reqid: u64) -> bool { + match self { + Self::Active { pubkeys, .. } => pubkeys + .lock() + .expect("pubkeys mutex poisoned") + .contains(pubkey), + Self::Deactivated { .. } => false, + } + } + + /// Returns `true` if the we requested to deactivate this table. + /// NOTE: this doesn't mean that the deactivation perios passed, thus + /// the table could still be considered _deactivating_ on chain. + pub fn deactivate_triggered(&self) -> bool { + use LookupTable::*; + matches!(self, Deactivated { .. }) + } + + pub fn is_active(&self) -> bool { + use LookupTable::*; + matches!(self, Active { .. }) + } + + pub fn derive_keypair( + authority: &Keypair, + slot: Slot, + sub_slot: Slot, + ) -> Keypair { + derive_keypair::derive_keypair(authority, slot, sub_slot) + } + + /// Initializes an address lookup table deriving its authority from the provided + /// [authority] keypair. The table is extended with the provided [pubkeys]. + /// The [authority] keypair pays for the transaction. + /// + /// - **rpc_client**: RPC client to use for sending transactions + /// - **authority**: Keypair to derive the authority of the lookup table + /// - **latest_slot**: the on chain slot at which we are creating the table + /// - **sub_slot**: a bump to allow creating multiple lookup tables with the same authority + /// at the same slot + /// - **pubkeys**: to extend the lookup table respecting respecting + /// solana_sdk::address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES] + /// after it is initialized + /// - **reqid**: id of the request adding the pubkeys + pub async fn init( + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + latest_slot: Slot, + sub_slot: Slot, + pubkeys: &[Pubkey], + _reqid: u64, + ) -> TableManiaResult { + check_max_pubkeys(pubkeys)?; + + let derived_auth = + Self::derive_keypair(authority, latest_slot, sub_slot); + + let (create_ix, table_address) = alt::instruction::create_lookup_table( + derived_auth.pubkey(), + authority.pubkey(), + latest_slot, + ); + + let end = pubkeys.len().min(LOOKUP_TABLE_MAX_ADDRESSES); + let extend_ix = alt::instruction::extend_lookup_table( + table_address, + derived_auth.pubkey(), + Some(authority.pubkey()), + pubkeys[..end].to_vec(), + ); + + let ixs = vec![create_ix, extend_ix]; + let latest_blockhash = rpc_client.get_latest_blockhash().await?; + let tx = Transaction::new_signed_with_payer( + &ixs, + Some(&authority.pubkey()), + &[authority, &derived_auth], + latest_blockhash, + ); + + let outcome = rpc_client + .send_transaction(&tx, &Self::get_commitment(rpc_client)) + .await?; + let (signature, error) = outcome.into_signature_and_error(); + if let Some(error) = &error { + error!( + "Error initializing lookup table: {:?} ({})", + error, signature + ); + return Err(MagicBlockRpcClientError::SentTransactionError( + error.clone(), + signature, + ) + .into()); + } + + Ok(Self::Active { + derived_auth, + table_address, + pubkeys: Mutex::new(pubkeys.to_vec()), + creation_slot: latest_slot, + creation_sub_slot: sub_slot, + init_signature: signature, + extend_signatures: vec![], + }) + } + + fn get_commitment( + rpc_client: &MagicblockRpcClient, + ) -> MagicBlockSendTransactionConfig { + use CommitmentLevel::*; + match rpc_client.commitment_level() { + Processed => MagicBlockSendTransactionConfig::ensure_processed(), + Confirmed | Finalized => { + MagicBlockSendTransactionConfig::ensure_committed() + } + } + } + + /// Extends this lookup table with the provided [pubkeys]. + /// The transaction is signed with the [Self::derived_auth]. + /// + /// - **rpc_client**: RPC client to use for sending the extend transaction + /// - **authority**: payer for the the extend transaction + /// - **pubkeys**: to extend the lookup table with + /// - **reqid**: id of the request adding the pubkeys + pub async fn extend( + &self, + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + extra_pubkeys: &[Pubkey], + _reqid: u64, + ) -> TableManiaResult<()> { + use LookupTable::*; + + check_max_pubkeys(extra_pubkeys)?; + + let pubkeys = match self { + Active { pubkeys, .. } => pubkeys, + Deactivated { .. } => { + return Err(TableManiaError::CannotExtendDeactivatedTable( + *self.table_address(), + )); + } + }; + let extend_ix = alt::instruction::extend_lookup_table( + *self.table_address(), + self.derived_auth().pubkey(), + Some(authority.pubkey()), + extra_pubkeys.to_vec(), + ); + + let ixs = vec![extend_ix]; + let latest_blockhash = rpc_client.get_latest_blockhash().await?; + let tx = Transaction::new_signed_with_payer( + &ixs, + Some(&authority.pubkey()), + &[authority, self.derived_auth()], + latest_blockhash, + ); + + let outcome = rpc_client + .send_transaction(&tx, &Self::get_commitment(rpc_client)) + .await?; + let (signature, error) = outcome.into_signature_and_error(); + if let Some(error) = &error { + error!("Error extending lookup table: {:?} ({})", error, signature); + return Err(MagicBlockRpcClientError::SentTransactionError( + error.clone(), + signature, + ) + .into()); + } else { + pubkeys + .lock() + .expect("pubkeys mutex poisoned") + .extend(extra_pubkeys); + } + + Ok(()) + } + + /// Extends this lookup table with the portion of the provided [pubkeys] that + /// fits into the table respecting [solana_sdk::address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES]. + /// + /// The transaction is signed with the [Self::derived_auth]. + /// + /// - **rpc_client**: RPC client to use for sending the extend transaction + /// - **authority**: payer for the the extend transaction + /// - **pubkeys**: to extend the lookup table with + /// - **reqid**: id of the request adding the pubkeys + /// + /// Returns: the pubkeys that were added to the table + pub async fn extend_respecting_capacity( + &self, + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + pubkeys: &[Pubkey], + reqid: u64, + ) -> TableManiaResult> { + let Some(len) = self.pubkeys().map(|x| x.len()) else { + return Err(TableManiaError::CannotExtendDeactivatedTable( + *self.table_address(), + )); + }; + let remaining_capacity = LOOKUP_TABLE_MAX_ADDRESSES.saturating_sub(len); + if remaining_capacity == 0 { + return Ok(vec![]); + } + + let storing = if pubkeys.len() >= remaining_capacity { + let (storing, _) = pubkeys.split_at(remaining_capacity); + storing + } else { + pubkeys + }; + + let res = self.extend(rpc_client, authority, storing, reqid).await; + res.map(|_| storing.to_vec()) + } + + /// Deactivates this lookup table. + /// + /// - **rpc_client**: RPC client to use for sending the deactivate transaction + /// - **authority**: pays for the the deactivate transaction + pub async fn deactivate( + &mut self, + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + ) -> TableManiaResult<()> { + let deactivate_ix = alt::instruction::deactivate_lookup_table( + *self.table_address(), + self.derived_auth().pubkey(), + ); + let ixs = vec![deactivate_ix]; + let latest_blockhash = rpc_client.get_latest_blockhash().await?; + let tx = Transaction::new_signed_with_payer( + &ixs, + Some(&authority.pubkey()), + &[authority, self.derived_auth()], + latest_blockhash, + ); + + let outcome = rpc_client + .send_transaction(&tx, &Self::get_commitment(rpc_client)) + .await?; + let (signature, error) = outcome.into_signature_and_error(); + if let Some(error) = &error { + error!( + "Error deactivating lookup table: {:?} ({})", + error, signature + ); + } + + let slot = rpc_client.get_slot().await?; + *self = Self::Deactivated { + derived_auth: self.derived_auth().insecure_clone(), + table_address: *self.table_address(), + deactivation_slot: slot, + deactivate_signature: signature, + }; + + Ok(()) + } + + /// Checks if this lookup table is deactivated via the following: + /// + /// 1. was [Self::deactivate] called + /// 2. is the [LookupTable::Deactivated::deactivation_slot] far enough in the past + pub async fn is_deactivated( + &self, + rpc_client: &MagicblockRpcClient, + current_slot: Option, + ) -> bool { + let Self::Deactivated { + deactivation_slot, .. + } = self + else { + return false; + }; + let slot = { + if let Some(slot) = current_slot { + slot + } else { + let Ok(slot) = rpc_client.get_slot().await else { + return false; + }; + slot + } + }; + // NOTE: the solana exporer will show an account as _deactivated_ once we deactivate it + // even though it is actually _deactivating_ + // I tried to shorten the wait here but found that this is the minimum time needed + // for the table to be considered fully _deactivated_ + let deactivated_slot = deactivation_slot + MAX_ENTRIES as u64; + trace!( + "'{}' deactivates in {} slots", + self.table_address(), + deactivated_slot.saturating_sub(slot), + ); + deactivated_slot <= slot + } + + pub async fn is_closed( + &self, + rpc_client: &MagicblockRpcClient, + ) -> TableManiaResult { + let acc = rpc_client.get_account(self.table_address()).await?; + Ok(acc.is_none()) + } + + /// Checks if the table was deactivated and if so closes the table account. + /// + /// - **rpc_client**: RPC client to use for sending the close transaction + /// - **authority**: pays for the the close transaction and is refunded the + /// table account rent + /// - **current_slot**: the current slot to use for checking deactivation + pub async fn close( + &self, + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + current_slot: Option, + ) -> TableManiaResult { + if !self.is_deactivated(rpc_client, current_slot).await { + return Ok(false); + } + + let close_ix = alt::instruction::close_lookup_table( + *self.table_address(), + self.derived_auth().pubkey(), + authority.pubkey(), + ); + let ixs = vec![close_ix]; + let latest_blockhash = rpc_client.get_latest_blockhash().await?; + let tx = Transaction::new_signed_with_payer( + &ixs, + Some(&authority.pubkey()), + &[authority, self.derived_auth()], + latest_blockhash, + ); + + let outcome = rpc_client + .send_transaction(&tx, &Self::get_commitment(rpc_client)) + .await?; + + let (signature, error) = outcome.into_signature_and_error(); + if let Some(error) = &error { + debug!( + "Error closing lookup table: {:?} ({}) - may need longer deactivation time", + error, signature + ); + } + self.is_closed(rpc_client).await + } + + pub async fn get_meta( + &self, + rpc_client: &MagicblockRpcClient, + ) -> TableManiaResult> { + Ok(rpc_client + .get_lookup_table_meta(self.table_address()) + .await?) + } + + pub async fn get_chain_pubkeys( + &self, + rpc_client: &MagicblockRpcClient, + ) -> TableManiaResult>> { + Self::get_chain_pubkeys_for(rpc_client, self.table_address()).await + } + + pub async fn get_chain_pubkeys_for( + rpc_client: &MagicblockRpcClient, + table_address: &Pubkey, + ) -> TableManiaResult>> { + Ok(rpc_client.get_lookup_table_addresses(table_address).await?) + } +} + +fn check_max_pubkeys(pubkeys: &[Pubkey]) -> TableManiaResult<()> { + if pubkeys.len() > MAX_ENTRIES_AS_PART_OF_EXTEND as usize { + return Err(TableManiaError::MaxExtendPubkeysExceeded( + MAX_ENTRIES_AS_PART_OF_EXTEND as usize, + pubkeys.len(), + )); + } + Ok(()) +} diff --git a/magicblock-table-mania/src/lookup_table_rc.rs b/magicblock-table-mania/src/lookup_table_rc.rs new file mode 100644 index 000000000..94e298cde --- /dev/null +++ b/magicblock-table-mania/src/lookup_table_rc.rs @@ -0,0 +1,708 @@ +use log::*; +use magicblock_rpc_client::{ + MagicBlockRpcClientError, MagicBlockSendTransactionConfig, + MagicblockRpcClient, +}; +use solana_sdk::{ + address_lookup_table::{ + self as alt, + state::{LookupTableMeta, LOOKUP_TABLE_MAX_ADDRESSES}, + }, + clock::Slot, + commitment_config::CommitmentLevel, + signature::{Keypair, Signature}, + signer::Signer, + slot_hashes::MAX_ENTRIES, + transaction::Transaction, +}; +use std::{ + collections::{HashMap, HashSet}, + fmt, + ops::Deref, + sync::{ + atomic::{AtomicUsize, Ordering}, + RwLock, RwLockReadGuard, RwLockWriteGuard, + }, +}; + +use solana_pubkey::Pubkey; + +use crate::{ + derive_keypair, + error::{TableManiaError, TableManiaResult}, +}; + +// ----------------- +// RefcountedPubkeys +// ----------------- + +/// A map of reference counted pubkeys that can be used to track the number of +/// reservations that exist for a pubkey in a lookup table +pub struct RefcountedPubkeys { + pubkeys: HashMap, +} + +impl RefcountedPubkeys { + fn new(pubkeys: &[Pubkey]) -> Self { + Self { + pubkeys: pubkeys + .iter() + .map(|pubkey| (*pubkey, AtomicUsize::new(1))) + .collect(), + } + } + + /// This should only be called for pubkeys that are not already in this table. + /// It is called when extending a lookup table with pubkeys that were not + /// found in any other table. + fn insert_many(&mut self, pubkeys: &[Pubkey]) { + for pubkey in pubkeys { + debug_assert!( + !self.pubkeys.contains_key(pubkey), + "Pubkey {} already exists in the table", + pubkey + ); + self.pubkeys.insert(*pubkey, AtomicUsize::new(1)); + } + } + + /// Add a reservation to the pubkey if it is part of this table + /// - *pubkey* to reserve + /// - *returns* `true` if the pubkey could be reserved + fn reserve(&self, pubkey: &Pubkey) -> bool { + if let Some(count) = self.pubkeys.get(pubkey) { + count.fetch_add(1, Ordering::SeqCst); + true + } else { + false + } + } + + /// Called when we are done with a pubkey + /// Will decrement the ref count of it or do nothing if the pubkey was + /// not found + /// - *pubkey* to release + /// - *returns* `true` if the pubkey was released + fn release(&self, pubkey: &Pubkey) -> bool { + if let Some(count) = self.pubkeys.get(pubkey) { + count + .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| { + if x == 0 { + None + } else { + Some(x - 1) + } + }) + .is_ok() + } else { + false + } + } + + /// Returns `true` if any of the pubkeys is still in use + fn has_reservations(&self) -> bool { + self.pubkeys + .values() + .any(|rc_pubkey| rc_pubkey.load(Ordering::SeqCst) > 0) + } +} + +impl Deref for RefcountedPubkeys { + type Target = HashMap; + + fn deref(&self) -> &Self::Target { + &self.pubkeys + } +} + +/// Determined via trial and error. The keys themselves take up +/// 27 * 32 bytes = 864 bytes. +pub const MAX_ENTRIES_AS_PART_OF_EXTEND: u64 = 27; + +// ----------------- +// LookupTableRc +// ----------------- +pub enum LookupTableRc { + Active { + derived_auth: Keypair, + table_address: Pubkey, + /// Reference counted pubkeys stored inside the [Self::table]. + /// When someone _checks out_ a pubkey the ref count is incremented + /// When it is _returned_ the ref count is decremented. + /// When all pubkeys have ref count 0 the table can be deactivated + pubkeys: RwLock, + creation_slot: u64, + creation_sub_slot: u64, + init_signature: Signature, + extend_signatures: Vec, + }, + Deactivated { + derived_auth: Keypair, + table_address: Pubkey, + deactivation_slot: u64, + deactivate_signature: Signature, + }, +} + +impl fmt::Display for LookupTableRc { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Active { + derived_auth, + table_address, + pubkeys, + creation_slot, + creation_sub_slot, + init_signature, + extend_signatures, + } => { + let comma_separated_pubkeys = pubkeys + .read() + .expect("pubkeys mutex poisoned") + .iter() + .map(|(key, _)| key.to_string()) + .collect::>() + .join(", "); + let comma_separated_sigs = extend_signatures + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(", "); + write!( + f, + "LookupTable: Active {{ + derived_auth: {} + table_address: {} + pubkeys: {} + creation_slot: {} + creation_sub_slot: {} + init_signature: {} + extend_signatures: {} +}}", + derived_auth.pubkey(), + table_address, + comma_separated_pubkeys, + creation_slot, + creation_sub_slot, + init_signature, + comma_separated_sigs + ) + } + Self::Deactivated { + derived_auth, + table_address, + deactivation_slot, + deactivate_signature, + } => { + write!( + f, + "LookupTable: Deactivated {{ derived_auth: {}, table_address: {}, deactivation_slot: {}, deactivate_signature: {} }}", + derived_auth.pubkey(), + table_address, + deactivation_slot, + deactivate_signature, + ) + } + } + } +} + +impl LookupTableRc { + pub fn derived_auth(&self) -> &Keypair { + match self { + Self::Active { derived_auth, .. } => derived_auth, + Self::Deactivated { derived_auth, .. } => derived_auth, + } + } + + pub fn table_address(&self) -> &Pubkey { + match self { + Self::Active { table_address, .. } => table_address, + Self::Deactivated { table_address, .. } => table_address, + } + } + + pub fn pubkeys(&self) -> Option> { + match self { + Self::Active { pubkeys, .. } => { + Some(pubkeys.read().expect("pubkeys mutex poisoned")) + } + Self::Deactivated { .. } => None, + } + } + + pub fn pubkeys_mut( + &self, + ) -> Option> { + match self { + Self::Active { pubkeys, .. } => { + Some(pubkeys.write().expect("pubkeys mutex poisoned")) + } + Self::Deactivated { .. } => None, + } + } + + pub fn creation_slot(&self) -> Option { + match self { + Self::Active { creation_slot, .. } => Some(*creation_slot), + Self::Deactivated { .. } => None, + } + } + + /// Returns `true` if the table has more capacity to add pubkeys + pub fn has_more_capacity(&self) -> bool { + self.pubkeys() + .is_some_and(|x| x.len() < LOOKUP_TABLE_MAX_ADDRESSES) + } + + pub fn is_full(&self) -> bool { + !self.has_more_capacity() + } + + pub fn contains_key(&self, pubkey: &Pubkey) -> bool { + self.pubkeys() + .is_some_and(|pubkeys| pubkeys.contains_key(pubkey)) + } + + /// Returns `true` if the table is active and any of the its pubkeys + /// is still in use + pub fn has_reservations(&self) -> bool { + self.pubkeys() + .is_some_and(|pubkeys| pubkeys.has_reservations()) + } + + pub fn provides(&self, pubkey: &Pubkey) -> bool { + self.pubkeys().is_some_and(|pubkeys| { + pubkeys + .get(pubkey) + .is_some_and(|count| count.load(Ordering::SeqCst) > 0) + }) + } + + /// Returns `true` if the we requested to deactivate this table. + /// NOTE: this doesn't mean that the deactivation perios passed, thus + /// the table could still be considered _deactivating_ on chain. + pub fn deactivate_triggered(&self) -> bool { + use LookupTableRc::*; + matches!(self, Deactivated { .. }) + } + + pub fn is_active(&self) -> bool { + use LookupTableRc::*; + matches!(self, Active { .. }) + } + + pub fn derive_keypair( + authority: &Keypair, + slot: Slot, + sub_slot: Slot, + ) -> Keypair { + derive_keypair::derive_keypair(authority, slot, sub_slot) + } + + /// Reserves the pubkey if it is part of this table. + /// - *pubkey* to reserve + /// - *returns* `true` if the pubkey could be reserved + pub fn reserve_pubkey(&self, pubkey: &Pubkey) -> bool { + self.pubkeys() + .is_some_and(|pubkeys| pubkeys.reserve(pubkey)) + } + + /// Releases one reservation for the given pubkey if it is part of this table + /// and has at least one reservation. + /// - *pubkey* to release + /// - *returns* `true` if the pubkey was released + pub fn release_pubkey(&self, pubkey: &Pubkey) -> bool { + self.pubkeys() + .is_some_and(|pubkeys| pubkeys.release(pubkey)) + } + + /// Matches pubkeys from the given set against the pubkeys it has reserved. + /// NOTE: the caller is responsible to hold a reservation to each pubkey it + /// is requesting to match against + pub fn match_pubkeys( + &self, + requested_pubkeys: &HashSet, + ) -> HashSet { + match self.pubkeys() { + Some(pubkeys) => requested_pubkeys + .iter() + .filter(|pubkey| pubkeys.contains_key(pubkey)) + .cloned() + .collect::>(), + None => HashSet::new(), + } + } + + /// Initializes an address lookup table deriving its authority from the provided + /// [authority] keypair. The table is extended with the provided [pubkeys]. + /// The [authority] keypair pays for the transaction. + /// + /// It is expectected that the provided pubkeys were not found in any other lookup + /// table nor in this one. + /// They are automatically reserved for one requestor. + /// + /// - **rpc_client**: RPC client to use for sending transactions + /// - **authority**: Keypair to derive the authority of the lookup table + /// - **latest_slot**: the on chain slot at which we are creating the table + /// - **sub_slot**: a bump to allow creating multiple lookup tables with the same authority + /// the same slot + /// - **pubkeys**: to extend the lookup table respecting respecting + /// [solana_sdk::address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES] + /// after it is initialized + pub async fn init( + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + latest_slot: Slot, + sub_slot: Slot, + pubkeys: &[Pubkey], + ) -> TableManiaResult { + check_max_pubkeys(pubkeys)?; + + let derived_auth = + Self::derive_keypair(authority, latest_slot, sub_slot); + + let (create_ix, table_address) = alt::instruction::create_lookup_table( + derived_auth.pubkey(), + authority.pubkey(), + latest_slot, + ); + trace!("Initializing lookup table {}", table_address); + + let end = pubkeys.len().min(LOOKUP_TABLE_MAX_ADDRESSES); + let extend_ix = alt::instruction::extend_lookup_table( + table_address, + derived_auth.pubkey(), + Some(authority.pubkey()), + pubkeys[..end].to_vec(), + ); + + let ixs = vec![create_ix, extend_ix]; + let latest_blockhash = rpc_client.get_latest_blockhash().await?; + let tx = Transaction::new_signed_with_payer( + &ixs, + Some(&authority.pubkey()), + &[authority, &derived_auth], + latest_blockhash, + ); + + let outcome = rpc_client + .send_transaction( + &tx, + &Self::get_send_transaction_config(rpc_client), + ) + .await?; + let (signature, error) = outcome.into_signature_and_error(); + if let Some(error) = &error { + error!( + "Error initializing lookup table: {:?} ({})", + error, signature + ); + return Err(MagicBlockRpcClientError::SentTransactionError( + error.clone(), + signature, + ) + .into()); + } + + Ok(Self::Active { + derived_auth, + table_address, + pubkeys: RwLock::new(RefcountedPubkeys::new(pubkeys)), + creation_slot: latest_slot, + creation_sub_slot: sub_slot, + init_signature: signature, + extend_signatures: vec![], + }) + } + + /// Extends this lookup table with the provided [pubkeys]. + /// The transaction is signed with the [Self::derived_auth]. + /// + /// It is expectected that the provided pubkeys were not found in any other lookup + /// table nor in this one. + /// They are automatically reserved for one requestor. + /// + /// - **rpc_client**: RPC client to use for sending the extend transaction + /// - **authority**: payer for the the extend transaction + /// - **pubkeys**: to extend the lookup table with + pub async fn extend( + &self, + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + extra_pubkeys: &[Pubkey], + ) -> TableManiaResult<()> { + use LookupTableRc::*; + + check_max_pubkeys(extra_pubkeys)?; + + let pubkeys = match self { + Active { pubkeys, .. } => pubkeys, + Deactivated { .. } => { + return Err(TableManiaError::CannotExtendDeactivatedTable( + *self.table_address(), + )); + } + }; + let extend_ix = alt::instruction::extend_lookup_table( + *self.table_address(), + self.derived_auth().pubkey(), + Some(authority.pubkey()), + extra_pubkeys.to_vec(), + ); + + let ixs = vec![extend_ix]; + let latest_blockhash = rpc_client.get_latest_blockhash().await?; + let tx = Transaction::new_signed_with_payer( + &ixs, + Some(&authority.pubkey()), + &[authority, self.derived_auth()], + latest_blockhash, + ); + + let outcome = rpc_client + .send_transaction( + &tx, + &Self::get_send_transaction_config(rpc_client), + ) + .await?; + let (signature, error) = outcome.into_signature_and_error(); + if let Some(error) = &error { + error!("Error extending lookup table: {:?} ({})", error, signature); + return Err(MagicBlockRpcClientError::SentTransactionError( + error.clone(), + signature, + ) + .into()); + } else { + pubkeys + .write() + .expect("pubkeys rwlock poisoned") + .insert_many(extra_pubkeys); + } + + Ok(()) + } + + /// Extends this lookup table with the portion of the provided [pubkeys] that + /// fits into the table respecting [solana_sdk::address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES]. + /// + /// The transaction is signed with the [Self::derived_auth]. + /// + /// - **rpc_client**: RPC client to use for sending the extend transaction + /// - **authority**: payer for the the extend transaction + /// - **pubkeys**: to extend the lookup table with + /// + /// Returns: the pubkeys that were added to the table + pub async fn extend_respecting_capacity( + &self, + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + pubkeys: &[Pubkey], + ) -> TableManiaResult> { + let Some(len) = self.pubkeys().map(|x| x.len()) else { + return Err(TableManiaError::CannotExtendDeactivatedTable( + *self.table_address(), + )); + }; + let remaining_capacity = LOOKUP_TABLE_MAX_ADDRESSES.saturating_sub(len); + if remaining_capacity == 0 { + return Ok(vec![]); + } + + let storing = if pubkeys.len() >= remaining_capacity { + let (storing, _) = pubkeys.split_at(remaining_capacity); + storing + } else { + pubkeys + }; + + let res = self.extend(rpc_client, authority, storing).await; + res.map(|_| storing.to_vec()) + } + + /// Deactivates this lookup table. + /// + /// - **rpc_client**: RPC client to use for sending the deactivate transaction + /// - **authority**: pays for the the deactivate transaction + pub async fn deactivate( + &mut self, + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + ) -> TableManiaResult<()> { + let deactivate_ix = alt::instruction::deactivate_lookup_table( + *self.table_address(), + self.derived_auth().pubkey(), + ); + let ixs = vec![deactivate_ix]; + let latest_blockhash = rpc_client.get_latest_blockhash().await?; + let tx = Transaction::new_signed_with_payer( + &ixs, + Some(&authority.pubkey()), + &[authority, self.derived_auth()], + latest_blockhash, + ); + + let outcome = rpc_client + .send_transaction( + &tx, + &Self::get_send_transaction_config(rpc_client), + ) + .await?; + let (signature, error) = outcome.into_signature_and_error(); + if let Some(error) = &error { + error!( + "Error deactivating lookup table: {:?} ({})", + error, signature + ); + } + + let slot = rpc_client.get_slot().await?; + *self = Self::Deactivated { + derived_auth: self.derived_auth().insecure_clone(), + table_address: *self.table_address(), + deactivation_slot: slot, + deactivate_signature: signature, + }; + + Ok(()) + } + + /// Checks if this lookup table is deactivated via the following: + /// + /// 1. was [Self::deactivate] called + /// 2. is the [LookupTable::Deactivated::deactivation_slot] far enough in the past + pub async fn is_deactivated( + &self, + rpc_client: &MagicblockRpcClient, + current_slot: Option, + ) -> bool { + let Self::Deactivated { + deactivation_slot, .. + } = self + else { + return false; + }; + let slot = { + if let Some(slot) = current_slot { + slot + } else { + let Ok(slot) = rpc_client.get_slot().await else { + return false; + }; + slot + } + }; + // NOTE: the solana exporer will show an account as _deactivated_ once we deactivate it + // even though it is actually _deactivating_ + // I tried to shorten the wait here but found that this is the minimum time needed + // for the table to be considered fully _deactivated_ + let deactivated_slot = deactivation_slot + MAX_ENTRIES as u64; + trace!( + "'{}' deactivates in {} slots", + self.table_address(), + deactivated_slot.saturating_sub(slot), + ); + deactivated_slot <= slot + } + + pub async fn is_closed( + &self, + rpc_client: &MagicblockRpcClient, + ) -> TableManiaResult { + let acc = rpc_client.get_account(self.table_address()).await?; + Ok(acc.is_none()) + } + + /// Checks if the table was deactivated and if so closes the table account. + /// + /// - **rpc_client**: RPC client to use for sending the close transaction + /// - **authority**: pays for the the close transaction and is refunded the + /// table account rent + /// - **current_slot**: the current slot to use for checking deactivation + pub async fn close( + &self, + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + current_slot: Option, + ) -> TableManiaResult { + if !self.is_deactivated(rpc_client, current_slot).await { + return Ok(false); + } + + let close_ix = alt::instruction::close_lookup_table( + *self.table_address(), + self.derived_auth().pubkey(), + authority.pubkey(), + ); + let ixs = vec![close_ix]; + let latest_blockhash = rpc_client.get_latest_blockhash().await?; + let tx = Transaction::new_signed_with_payer( + &ixs, + Some(&authority.pubkey()), + &[authority, self.derived_auth()], + latest_blockhash, + ); + + let outcome = rpc_client + .send_transaction( + &tx, + &Self::get_send_transaction_config(rpc_client), + ) + .await?; + + let (signature, error) = outcome.into_signature_and_error(); + if let Some(error) = &error { + debug!( + "Error closing lookup table: {:?} ({}) - may need longer deactivation time", + error, signature + ); + } + self.is_closed(rpc_client).await + } + + pub async fn get_meta( + &self, + rpc_client: &MagicblockRpcClient, + ) -> TableManiaResult> { + Ok(rpc_client + .get_lookup_table_meta(self.table_address()) + .await?) + } + + pub async fn get_chain_pubkeys( + &self, + rpc_client: &MagicblockRpcClient, + ) -> TableManiaResult>> { + Self::get_chain_pubkeys_for(rpc_client, self.table_address()).await + } + + pub async fn get_chain_pubkeys_for( + rpc_client: &MagicblockRpcClient, + table_address: &Pubkey, + ) -> TableManiaResult>> { + Ok(rpc_client.get_lookup_table_addresses(table_address).await?) + } + + fn get_send_transaction_config( + rpc_client: &MagicblockRpcClient, + ) -> MagicBlockSendTransactionConfig { + use CommitmentLevel::*; + match rpc_client.commitment_level() { + Processed => MagicBlockSendTransactionConfig::ensure_processed(), + Confirmed | Finalized => { + MagicBlockSendTransactionConfig::ensure_committed() + } + } + } +} + +fn check_max_pubkeys(pubkeys: &[Pubkey]) -> TableManiaResult<()> { + if pubkeys.len() > MAX_ENTRIES_AS_PART_OF_EXTEND as usize { + return Err(TableManiaError::MaxExtendPubkeysExceeded( + MAX_ENTRIES_AS_PART_OF_EXTEND as usize, + pubkeys.len(), + )); + } + Ok(()) +} diff --git a/magicblock-table-mania/src/manager.rs b/magicblock-table-mania/src/manager.rs new file mode 100644 index 000000000..e9eb2f9db --- /dev/null +++ b/magicblock-table-mania/src/manager.rs @@ -0,0 +1,702 @@ +use log::*; +use std::{ + collections::{HashMap, HashSet}, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, + }, + time::{Duration, Instant}, +}; + +use magicblock_rpc_client::MagicblockRpcClient; +use solana_pubkey::Pubkey; +use solana_sdk::{ + address_lookup_table::state::AddressLookupTable, + commitment_config::CommitmentConfig, message::AddressLookupTableAccount, + signature::Keypair, signer::Signer, +}; +use tokio::{ + sync::{Mutex, RwLock}, + time::sleep, +}; + +use crate::{ + error::{TableManiaError, TableManiaResult}, + lookup_table_rc::{LookupTableRc, MAX_ENTRIES_AS_PART_OF_EXTEND}, +}; + +// ----------------- +// GarbageCollectorConfig +// ----------------- + +/// Configures the Garbage Collector which deactivates and then closes +/// lookup tables whose pubkeys have been released. +#[derive(Debug, Clone)] +pub struct GarbageCollectorConfig { + /// The interval at which to check for tables to deactivate. + pub deactivate_interval_ms: u64, + /// The interval at which to check for deactivated tables to close. + pub close_interval_ms: u64, +} + +impl Default for GarbageCollectorConfig { + fn default() -> Self { + Self { + deactivate_interval_ms: 1_000, + close_interval_ms: 5_000, + } + } +} + +#[derive(Clone)] +pub struct TableMania { + pub active_tables: Arc>>, + released_tables: Arc>>, + authority_pubkey: Pubkey, + pub rpc_client: MagicblockRpcClient, + randomize_lookup_table_slot: bool, +} + +impl TableMania { + pub fn new( + rpc_client: MagicblockRpcClient, + authority: &Keypair, + garbage_collector_config: Option, + ) -> Self { + let me = Self { + active_tables: Arc::>>::default(), + released_tables: Arc::>>::default(), + authority_pubkey: authority.pubkey(), + rpc_client, + randomize_lookup_table_slot: randomize_lookup_table_slot(), + }; + if let Some(config) = garbage_collector_config { + Self::launch_garbage_collector( + &me.rpc_client, + authority, + me.released_tables.clone(), + config, + ); + } + me + } + + /// Returns the number of currently active tables + pub async fn active_tables_count(&self) -> usize { + self.active_tables.read().await.len() + } + + /// Returns the number of released tables + pub async fn released_tables_count(&self) -> usize { + self.released_tables.lock().await.len() + } + + /// Returns the addresses of all tables currently active + pub async fn active_table_addresses(&self) -> Vec { + let mut addresses = Vec::new(); + + for table in self.active_tables.read().await.iter() { + addresses.push(*table.table_address()); + } + + addresses + } + + /// Returns the addresses of all released tables + pub async fn released_table_addresses(&self) -> Vec { + self.released_tables + .lock() + .await + .iter() + .map(|table| *table.table_address()) + .collect() + } + + /// Returns the addresses stored accross all active tables + pub async fn active_table_pubkeys(&self) -> Vec { + let mut pubkeys = Vec::new(); + for table in self.active_tables.read().await.iter() { + if let Some(pks) = table.pubkeys() { + pubkeys.extend(pks.keys()); + } + } + pubkeys + } + + // ----------------- + // Reserve + // ----------------- + pub async fn reserve_pubkeys( + &self, + authority: &Keypair, + pubkeys: &HashSet, + ) -> TableManiaResult<()> { + let mut remaining = HashSet::new(); + // 1. Add reservations for pubkeys that are already in one of the tables + for pubkey in pubkeys { + if !self.reserve_pubkey(pubkey).await { + remaining.insert(*pubkey); + } + } + + // 2. Add new reservations for pubkeys that are not in any table + self.reserve_new_pubkeys(authority, &remaining).await + } + + /// Tries to find a table that holds this pubkey already and reserves it. + /// - *pubkey* to reserve + /// - *returns* `true` if the pubkey could be reserved + async fn reserve_pubkey(&self, pubkey: &Pubkey) -> bool { + for table in self.active_tables.read().await.iter() { + if table.reserve_pubkey(pubkey) { + trace!( + "Added reservation for pubkey {} to table {}", + pubkey, + table.table_address() + ); + return true; + } + } + trace!("No table found for which we can reserve pubkey {}", pubkey); + false + } + + /// Reserves pubkeys that haven't been found in any of the active tables. + /// Thus this is considered the first reservation for these pubkeys and thus includes + /// initializing/extending actual lookup tables on chain. + async fn reserve_new_pubkeys( + &self, + authority: &Keypair, + pubkeys: &HashSet, + ) -> TableManiaResult<()> { + self.check_authority(authority)?; + + let mut remaining = pubkeys.iter().cloned().collect::>(); + let mut tables_used = HashSet::new(); + + // Keep trying to store pubkeys until we're done + while !remaining.is_empty() { + // First try to use existing tables + let mut stored_in_existing = false; + { + // Taking a write lock here to prevent multiple tasks from + // updating tables at the same time + let active_tables_write_lock = self.active_tables.write().await; + + // Try to use the last table if it's not full + if let Some(table) = active_tables_write_lock.last() { + if !table.is_full() { + self.extend_table( + table, + authority, + &mut remaining, + &mut tables_used, + ) + .await; + stored_in_existing = true; + } + } + } + + // If we couldn't use existing tables, we need to create a new one + if !stored_in_existing && !remaining.is_empty() { + // We write lock the active tables to ensure that while we create a new + // table the requests looking for an existing table to extend are blocked + let mut active_tables_write_lock = + self.active_tables.write().await; + + // Double-check if a new table was created while we were waiting for the lock + if let Some(table) = active_tables_write_lock.last() { + if !table.is_full() { + // Another task created a table we can use, so drop the write lock + // and try again with the read lock + drop(active_tables_write_lock); + continue; + } + } + + // Create a new table and add it to active_tables + let table = self + .create_new_table_and_extend(authority, &mut remaining) + .await?; + + tables_used.insert(*table.table_address()); + active_tables_write_lock.push(table); + } + + // If we've stored all pubkeys, we're done + if remaining.is_empty() { + break; + } + } + + Ok(()) + } + + /// Extends the table to store as many of the provided pubkeys as possile. + /// The stored pubkeys are removed from the `remaining` vector. + /// If successful the table addres is added to the `tables_used` set. + /// Returns `true` if the table is full after adding the pubkeys + async fn extend_table( + &self, + table: &LookupTableRc, + authority: &Keypair, + remaining: &mut Vec, + tables_used: &mut HashSet, + ) { + let remaining_len = remaining.len(); + let storing_len = + remaining_len.min(MAX_ENTRIES_AS_PART_OF_EXTEND as usize); + trace!( + "Adding {}/{} pubkeys to existing table {}", + storing_len, + remaining_len, + table.table_address() + ); + let table_addresses_count = table.pubkeys().unwrap().len(); + + let storing = remaining[..storing_len].to_vec(); + match table + .extend_respecting_capacity(&self.rpc_client, authority, &storing) + .await + { + Ok(stored) => { + trace!("Stored {}", stored.len()); + tables_used.insert(*table.table_address()); + remaining.retain(|pk| !stored.contains(pk)); + } + // TODO: this could cause us to loop forever as remaining + // is never updated, possibly we need to return an error + // here instead + Err(err) => error!( + "Error extending table {}: {:?}", + table.table_address(), + err + ), + } + let stored_count = remaining_len - remaining.len(); + trace!("Stored {}, remaining: {}", stored_count, remaining.len()); + + debug_assert_eq!( + table_addresses_count + stored_count, + table.pubkeys().unwrap().len() + ); + } + + async fn create_new_table_and_extend( + &self, + authority: &Keypair, + pubkeys: &mut Vec, + ) -> TableManiaResult { + static SUB_SLOT: AtomicU64 = AtomicU64::new(0); + + let pubkeys_len = pubkeys.len(); + let slot = self.rpc_client.get_slot().await?; + + if self.randomize_lookup_table_slot { + use rand::Rng; + let mut rng = rand::thread_rng(); + let random_slot = rng.gen_range(0..=u64::MAX); + SUB_SLOT.store(random_slot, Ordering::Relaxed); + } else { + static LAST_SLOT: AtomicU64 = AtomicU64::new(0); + let prev_last_slot = LAST_SLOT.swap(slot, Ordering::Relaxed); + if prev_last_slot != slot { + SUB_SLOT.store(0, Ordering::Relaxed); + } else { + SUB_SLOT.fetch_add(1, Ordering::Relaxed); + } + } + + let len = pubkeys_len.min(MAX_ENTRIES_AS_PART_OF_EXTEND as usize); + let table = LookupTableRc::init( + &self.rpc_client, + authority, + slot, + SUB_SLOT.load(Ordering::Relaxed), + &pubkeys[..len], + ) + .await?; + pubkeys.retain_mut(|pk| !table.contains_key(pk)); + + trace!( + "Created new table and stored {}/{} pubkeys. {}", + len, + pubkeys_len, + table.table_address() + ); + Ok(table) + } + + // ----------------- + // Release + // ----------------- + pub async fn release_pubkeys(&self, pubkeys: &HashSet) { + for pubkey in pubkeys { + self.release_pubkey(pubkey).await; + } + // While we hold the write lock on the active tables no one can make + // a reservation on any of them until we mark them for deactivation. + let mut active_tables = self.active_tables.write().await; + let mut still_active = Vec::new(); + for table in active_tables.drain(..) { + if table.has_reservations() { + still_active.push(table); + } else { + self.released_tables.lock().await.push(table); + } + } + for table in still_active.into_iter() { + active_tables.push(table); + } + } + + async fn release_pubkey(&self, pubkey: &Pubkey) { + for table in self.active_tables.read().await.iter() { + if table.release_pubkey(pubkey) { + trace!( + "Removed reservation for pubkey {} from table {}", + pubkey, + table.table_address() + ); + return; + } + } + trace!("No table found for which we can release pubkey {}", pubkey); + } + + // ----------------- + // Tables for Reserved Pubkeys + // ----------------- + + /// Attempts to find a table that holds each of the pubkeys. + /// It only returns once the needed pubkeys are also present remotely in the + /// finalized table accounts. + /// + /// - *pubkeys* to find tables for + /// - *wait_for_local_table_match* how long to wait for local tables to match which + /// means the [Self::reserve_pubkeys] was completed including any transactions that were sent + /// - *wait_for_remote_table_match* how long to wait for remote tables to include the + /// matched pubkeys + pub async fn try_get_active_address_lookup_table_accounts( + &self, + pubkeys: &HashSet, + wait_for_local_table_match: Duration, + wait_for_remote_table_match: Duration, + ) -> TableManiaResult> { + // 1. Wait until all keys are present in a local table + let matching_tables = { + let start = Instant::now(); + loop { + { + let active_local_tables = self.active_tables.read().await; + let mut keys_to_match = pubkeys.clone(); + let mut matching_tables = HashMap::new(); + for table in active_local_tables.iter() { + let matching_keys = table.match_pubkeys(&keys_to_match); + if !matching_keys.is_empty() { + keys_to_match + .retain(|pk| !matching_keys.contains(pk)); + matching_tables + .insert(*table.table_address(), matching_keys); + } + } + if keys_to_match.is_empty() { + break matching_tables; + } + trace!( + "Matched {}/{} pubkeys", + pubkeys.len() - keys_to_match.len(), + pubkeys.len() + ); + } + if start.elapsed() > wait_for_local_table_match { + error!( + "Timed out waiting for local tables to match requested keys: {:?} for {:?}", + pubkeys, + wait_for_local_table_match, + + ); + return Err( + TableManiaError::TimedOutWaitingForRemoteTablesToUpdate( + format!("{:?}", pubkeys), + ), + ); + } + + sleep(Duration::from_millis(200)).await; + } + }; + + // 2. Ensure that all matching keys are also present remotely and have been finalized + let remote_tables = { + let mut last_slot = self.rpc_client.get_slot().await?; + + let matching_table_keys = + matching_tables.keys().cloned().collect::>(); + + let start = Instant::now(); + let table_keys_str = matching_table_keys + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(", "); + + loop { + // Fetch the tables from chain + let remote_table_accs = self + .rpc_client + .get_multiple_accounts_with_commitment( + &matching_table_keys, + // For lookup tables to be useful in a transaction all create/extend + // transactions on the table need to be finalized + CommitmentConfig::finalized(), + None, + ) + .await?; + + let remote_tables = remote_table_accs + .into_iter() + .enumerate() + .flat_map(|(idx, acc)| { + acc.and_then( + |acc| match AddressLookupTable::deserialize( + &acc.data, + ) { + Ok(table) => Some(( + matching_table_keys[idx], + table.addresses.to_vec(), + )), + Err(err) => { + error!( + "Failed to deserialize table {}: {:?}", + matching_table_keys[idx], err + ); + None + } + }, + ) + }) + .collect::>(); + + // Ensure we got the same amount of tables + if remote_tables.len() == matching_tables.len() { + // And that all locally matched keys are in the finalized remote table + let all_matches_are_remote = + matching_tables.iter().all(|(address, local_keys)| { + remote_tables.get(address).is_some_and( + |remote_keys| { + local_keys + .iter() + .all(|pk| remote_keys.contains(pk)) + }, + ) + }); + if all_matches_are_remote { + break remote_tables; + } + } + + if start.elapsed() > wait_for_remote_table_match { + error!( + "Timed out waiting for remote tables to match local tables for {:?}. \ + Local: {:#?}\nRemote: {:#?}", + wait_for_remote_table_match, matching_tables, remote_tables + ); + return Err( + TableManiaError::TimedOutWaitingForRemoteTablesToUpdate( + table_keys_str, + ), + ); + } + + if let Ok(slot) = self.rpc_client.wait_for_next_slot().await { + if slot - last_slot > 20 { + debug!( + "Waiting for remote tables {} to match local tables.", + table_keys_str + ); + } + last_slot = slot; + } + } + }; + + Ok(matching_tables + .into_keys() + .map(|address| AddressLookupTableAccount { + key: address, + // SAFETY: we confirmed above that we have a remote table for all matching + // tables and that they contain the addresses we need + addresses: remote_tables.get(&address).unwrap().to_vec(), + }) + .collect()) + } + + // ----------------- + // Garbage Collector + // ----------------- + + // For deactivate/close operations running as part of the garbage collector task + // we only log errors since there is no reasonable way to handle them. + // The next cycle will try the operation again so in case chain was congested + // the problem should resolve itself. + // Otherwise we can run a tool later to manually deactivate + close tables. + + fn launch_garbage_collector( + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + released_tables: Arc>>, + config: GarbageCollectorConfig, + ) -> tokio::task::JoinHandle<()> { + let rpc_client = rpc_client.clone(); + let authority = authority.insecure_clone(); + + tokio::spawn(async move { + let mut last_deactivate = tokio::time::Instant::now(); + let mut last_close = tokio::time::Instant::now(); + let mut sleep_ms = + config.deactivate_interval_ms.min(config.close_interval_ms); + loop { + let now = tokio::time::Instant::now(); + if now + .duration_since(last_deactivate) + .as_millis() + .try_into() + .unwrap_or(u64::MAX) + >= config.deactivate_interval_ms + { + Self::deactivate_tables( + &rpc_client, + &authority, + &released_tables, + ) + .await; + last_deactivate = now; + sleep_ms = sleep_ms.min(config.deactivate_interval_ms); + } + if now + .duration_since(last_close) + .as_millis() + .try_into() + .unwrap_or(u64::MAX) + >= config.close_interval_ms + { + Self::close_tables( + &rpc_client, + &authority, + &released_tables, + ) + .await; + last_close = now; + sleep_ms = sleep_ms.min(config.close_interval_ms); + } + + tokio::time::sleep(tokio::time::Duration::from_millis( + sleep_ms, + )) + .await; + } + }) + } + + /// Deactivates tables that were previously released + async fn deactivate_tables( + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + released_tables: &Mutex>, + ) { + for table in released_tables + .lock() + .await + .iter_mut() + .filter(|x| !x.deactivate_triggered()) + { + // We don't bubble errors as there is no reasonable way to handle them. + // Instead the next GC cycle will try again to deactivate the table. + let _ = table.deactivate(rpc_client, authority).await.inspect_err( + |err| { + error!( + "Error deactivating table {}: {:?}", + table.table_address(), + err + ) + }, + ); + } + } + + /// Closes tables that were previously released and deactivated. + async fn close_tables( + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + released_tables: &Mutex>, + ) { + let Ok(latest_slot) = rpc_client + .get_slot() + .await + .inspect_err(|err| error!("Error getting latest slot: {:?}", err)) + else { + return; + }; + + let mut closed_tables = vec![]; + { + for deactivated_table in released_tables + .lock() + .await + .iter_mut() + .filter(|x| x.deactivate_triggered()) + { + // NOTE: [LookupTable::close] will only close the table if it was deactivated + // according to the provided slot + // We don't bubble errors as there is no reasonable way to handle them. + // Instead the next GC cycle will try again to close the table. + match deactivated_table + .close(rpc_client, authority, Some(latest_slot)) + .await + { + Ok(closed) if closed => { + closed_tables.push(*deactivated_table.table_address()) + } + Ok(_) => { + // Table not ready to be closed" + } + Err(err) => error!( + "Error closing table {}: {:?}", + deactivated_table.table_address(), + err + ), + }; + } + } + released_tables + .lock() + .await + .retain(|x| !closed_tables.contains(x.table_address())); + } + + // ----------------- + // Checks + // ----------------- + fn check_authority(&self, authority: &Keypair) -> TableManiaResult<()> { + if authority.pubkey() != self.authority_pubkey { + return Err(TableManiaError::InvalidAuthority( + authority.pubkey(), + self.authority_pubkey, + )); + } + Ok(()) + } +} + +fn randomize_lookup_table_slot() -> bool { + #[cfg(feature = "randomize_lookup_table_slot")] + { + true + } + #[cfg(not(feature = "randomize_lookup_table_slot"))] + { + std::env::var("RANDOMIZE_LOOKUP_TABLE_SLOT").is_ok() + } +} diff --git a/magicblock-table-mania/tests/ix_lookup_table.rs b/magicblock-table-mania/tests/ix_lookup_table.rs new file mode 100644 index 000000000..8511491d7 --- /dev/null +++ b/magicblock-table-mania/tests/ix_lookup_table.rs @@ -0,0 +1,163 @@ +use log::*; + +use magicblock_rpc_client::MagicblockRpcClient; +use magicblock_table_mania::{find_open_tables, LookupTable}; +use solana_pubkey::Pubkey; +use solana_rpc_client::nonblocking::rpc_client::RpcClient; +use solana_sdk::{ + address_lookup_table::state::LookupTableMeta, clock::Slot, + commitment_config::CommitmentConfig, native_token::LAMPORTS_PER_SOL, + signature::Keypair, signer::Signer, +}; + +mod utils; + +pub async fn setup_lookup_table( + validator_auth: &Keypair, + pubkeys: &[Pubkey], +) -> (MagicblockRpcClient, LookupTable) { + let rpc_client = { + let client = RpcClient::new_with_commitment( + "http://localhost:7799".to_string(), + CommitmentConfig::confirmed(), + ); + MagicblockRpcClient::from(client) + }; + rpc_client + .request_airdrop(&validator_auth.pubkey(), 777 * LAMPORTS_PER_SOL) + .await + .unwrap(); + + let latest_slot = rpc_client.get_slot().await.unwrap(); + let sub_slot = 0; + let reqid = 0; + let lookup_table = LookupTable::init( + &rpc_client, + validator_auth, + latest_slot, + sub_slot, + pubkeys, + reqid, + ) + .await + .unwrap(); + (rpc_client, lookup_table) +} + +async fn get_table_meta( + rpc_client: &MagicblockRpcClient, + lookup_table: &LookupTable, +) -> LookupTableMeta { + lookup_table + .get_meta(rpc_client) + .await + .unwrap() + .expect("Table not found") +} + +async fn get_table_addresses( + rpc_client: &MagicblockRpcClient, + lookup_table: &LookupTable, +) -> Vec { + lookup_table + .get_chain_pubkeys(rpc_client) + .await + .unwrap() + .expect("Table not found") +} + +async fn get_open_tables( + rpc_client: &MagicblockRpcClient, + authority: &Keypair, + start_slot: Slot, +) -> Vec { + let end_slot = rpc_client.get_slot().await.unwrap(); + find_open_tables(rpc_client, authority, start_slot, end_slot, 10) + .await + .unwrap() + .tables +} + +#[tokio::test] +async fn test_create_fetch_and_close_lookup_table() { + utils::init_logger(); + + let validator_auth = Keypair::new(); + let pubkeys = vec![0; 10] + .into_iter() + .map(|_| Pubkey::new_unique()) + .collect::>(); + + // Init table + let (rpc_client, mut lookup_table) = + setup_lookup_table(&validator_auth, &pubkeys[0..5]).await; + let creation_slot = lookup_table.creation_slot().unwrap(); + let meta = get_table_meta(&rpc_client, &lookup_table).await; + + assert_eq!(meta.authority, Some(lookup_table.derived_auth().pubkey())); + assert_eq!(meta.deactivation_slot, u64::MAX); + assert_eq!(lookup_table.pubkeys().unwrap(), pubkeys[0..5]); + assert_eq!( + get_table_addresses(&rpc_client, &lookup_table).await, + pubkeys[0..5] + ); + debug!("{}", lookup_table); + + // Extend table + let reqid = 0; + debug!("Extending table ..."); + lookup_table + .extend(&rpc_client, &validator_auth, &pubkeys[5..10], reqid) + .await + .unwrap(); + assert_eq!(lookup_table.pubkeys().unwrap(), pubkeys[0..10]); + assert_eq!( + get_table_addresses(&rpc_client, &lookup_table).await, + pubkeys[0..10] + ); + + // Deactivate table + debug!("Deactivating table ..."); + lookup_table + .deactivate(&rpc_client, &validator_auth) + .await + .unwrap(); + + let meta = get_table_meta(&rpc_client, &lookup_table).await; + assert_eq!(meta.authority, Some(lookup_table.derived_auth().pubkey())); + assert_ne!(meta.deactivation_slot, u64::MAX); + assert!(!lookup_table.is_deactivated(&rpc_client, None).await); + + assert_eq!( + get_open_tables(&rpc_client, &validator_auth, creation_slot) + .await + .len(), + 1 + ); + + #[cfg(not(feature = "test_table_close"))] + eprintln!("SKIP: close table"); + + #[cfg(feature = "test_table_close")] + { + // Wait for deactivation and close table + debug!("{}", lookup_table); + + eprintln!("Waiting for table to deactivate for about 2.5 min ..."); + while !lookup_table.is_deactivated(&rpc_client, None).await { + utils::sleep_millis(5_000).await; + } + lookup_table + .close(&rpc_client, &validator_auth, None) + .await + .unwrap(); + assert!(lookup_table.is_closed(&rpc_client).await.unwrap()); + + assert_eq!( + get_open_tables(&rpc_client, &validator_auth, creation_slot) + .await + .len(), + 0 + ); + } +} diff --git a/magicblock-table-mania/tests/ix_release_pubkeys.rs b/magicblock-table-mania/tests/ix_release_pubkeys.rs new file mode 100644 index 000000000..33fc27f0f --- /dev/null +++ b/magicblock-table-mania/tests/ix_release_pubkeys.rs @@ -0,0 +1,106 @@ +use std::collections::HashSet; + +use solana_pubkey::Pubkey; +use solana_sdk::signature::Keypair; +mod utils; + +#[tokio::test] +async fn test_single_table_two_requests_with_overlapping_pubkeys() { + utils::init_logger(); + + let authority = Keypair::new(); + let table_mania = utils::setup_table_mania(&authority).await; + + let pubkeys_req1 = (0..10) + .map(|idx| Pubkey::from([idx; 32])) + .collect::>(); + let pubkeys_req2 = (6..10) + .map(|idx| Pubkey::from([idx; 32])) + .collect::>(); + + table_mania + .reserve_pubkeys(&authority, &pubkeys_req1) + .await + .unwrap(); + table_mania + .reserve_pubkeys(&authority, &pubkeys_req2) + .await + .unwrap(); + + utils::log_active_table_addresses(&table_mania).await; + + assert_eq!(table_mania.active_tables_count().await, 1); + assert_eq!(table_mania.released_tables_count().await, 0); + + // All of req2 pubkeys are also contained in req1 + // However when we release all req1 pubkeys the table should not be released + // yet since req2 still needs them + + table_mania.release_pubkeys(&pubkeys_req1).await; + assert_eq!(table_mania.active_tables_count().await, 1); + assert_eq!(table_mania.released_tables_count().await, 0); + + // Now releasing req2 pubkeys should release the table + table_mania.release_pubkeys(&pubkeys_req2).await; + assert_eq!(table_mania.active_tables_count().await, 0); + assert_eq!(table_mania.released_tables_count().await, 1); + + utils::close_released_tables(&table_mania).await +} + +#[tokio::test] +async fn test_two_table_three_requests_with_one_overlapping_pubkey() { + utils::init_logger(); + + let authority = Keypair::new(); + let table_mania = utils::setup_table_mania(&authority).await; + + let common_pubkey = Pubkey::new_unique(); + let mut pubkeys_req1 = (0..300) + .map(|_| Pubkey::new_unique()) + .collect::>(); + + // The common pubkey will be stored in the second table + pubkeys_req1.insert(common_pubkey); + + let pubkeys_req2 = HashSet::from([common_pubkey]); + let pubkeys_req3 = HashSet::from([common_pubkey]); + + table_mania + .reserve_pubkeys(&authority, &pubkeys_req1) + .await + .unwrap(); + table_mania + .reserve_pubkeys(&authority, &pubkeys_req2) + .await + .unwrap(); + table_mania + .reserve_pubkeys(&authority, &pubkeys_req3) + .await + .unwrap(); + + utils::log_active_table_addresses(&table_mania).await; + + assert_eq!(table_mania.active_tables_count().await, 2); + assert_eq!(table_mania.released_tables_count().await, 0); + + // Releasing req2 should not release any table since it only + // has the common pubkey + table_mania.release_pubkeys(&pubkeys_req2).await; + assert_eq!(table_mania.active_tables_count().await, 2); + assert_eq!(table_mania.released_tables_count().await, 0); + + // Releasing req1 should only release the first table since the + // second table has the common pubkey + table_mania.release_pubkeys(&pubkeys_req1).await; + assert_eq!(table_mania.active_tables_count().await, 1); + assert_eq!(table_mania.released_tables_count().await, 1); + + // Releasing req3 frees the common pubkey and thus allows the + // second table to be released + table_mania.release_pubkeys(&pubkeys_req3).await; + assert_eq!(table_mania.active_tables_count().await, 0); + assert_eq!(table_mania.released_tables_count().await, 2); + + utils::close_released_tables(&table_mania).await +} diff --git a/magicblock-table-mania/tests/ix_reserve_pubkeys.rs b/magicblock-table-mania/tests/ix_reserve_pubkeys.rs new file mode 100644 index 000000000..94d35f940 --- /dev/null +++ b/magicblock-table-mania/tests/ix_reserve_pubkeys.rs @@ -0,0 +1,132 @@ +use std::collections::HashSet; + +use log::*; +use solana_pubkey::Pubkey; +use solana_sdk::{ + address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES, signature::Keypair, +}; +use tokio::task::JoinSet; +mod utils; + +// ----------------- +// Fitting into single table different chunk sizes +// ----------------- +macro_rules! reserve_pubkeys_in_one_table { + ($chunk_size:expr) => { + ::paste::paste! { + #[tokio::test] + async fn []() { + reserve_pubkeys_in_one_table_in_chunks($chunk_size).await; + } + } + }; +} + +reserve_pubkeys_in_one_table!(8); +reserve_pubkeys_in_one_table!(32); +reserve_pubkeys_in_one_table!(80); +reserve_pubkeys_in_one_table!(100); +reserve_pubkeys_in_one_table!(256); + +async fn reserve_pubkeys_in_one_table_in_chunks(chunk_size: usize) { + utils::init_logger(); + let authority = Keypair::new(); + + let mut pubkeys = (0..LOOKUP_TABLE_MAX_ADDRESSES) + .map(|_| Pubkey::new_unique()) + .collect::>(); + pubkeys.sort(); + + let table_mania = utils::setup_table_mania(&authority).await; + + for chunk in pubkeys.chunks(chunk_size) { + debug!("Storing chunk of size: {}", chunk.len()); + let chunk_hashset = HashSet::from_iter(chunk.iter().cloned()); + table_mania + .reserve_pubkeys(&authority, &chunk_hashset) + .await + .unwrap(); + } + + utils::log_active_table_addresses(&table_mania).await; + + let mut active_table_pubkeys = table_mania.active_table_pubkeys().await; + active_table_pubkeys.sort(); + + assert_eq!(table_mania.active_tables_count().await, 1); + assert_eq!(active_table_pubkeys, pubkeys); + + let mut first_table_pubkeys = table_mania.active_tables.read().await[0] + .get_chain_pubkeys(&table_mania.rpc_client) + .await + .unwrap() + .unwrap(); + + first_table_pubkeys.sort(); + + assert_eq!(first_table_pubkeys, pubkeys); +} + +// ----------------- +// Fitting into multiple tables different chunk sizes +// ----------------- +macro_rules! reserve_pubkeys_in_multiple_tables { + ($amount:expr, $chunk_size:expr) => { + ::paste::paste! { + #[tokio::test] + async fn []() { + reserve_pubkeys_in_multiple_tables_in_chunks($amount, $chunk_size).await; + } + } + }; +} + +reserve_pubkeys_in_multiple_tables!(257, 100); +reserve_pubkeys_in_multiple_tables!(512, 100); +reserve_pubkeys_in_multiple_tables!(1_000, 20); +reserve_pubkeys_in_multiple_tables!(2_100, 10); + +async fn reserve_pubkeys_in_multiple_tables_in_chunks( + amount: usize, + chunk_size: usize, +) { + utils::init_logger(); + let authority = Keypair::new(); + + let pubkeys = (0..amount) + .map(|_| Pubkey::new_unique()) + .collect::>(); + + let table_mania = utils::setup_table_mania(&authority).await; + + let mut join_set = JoinSet::new(); + for chunk in pubkeys.chunks(chunk_size) { + debug!("Reserving chunk of size: {}", chunk.len()); + let chunk_hashset = HashSet::from_iter(chunk.iter().cloned()); + let table_mania = table_mania.clone(); + let authority = authority.insecure_clone(); + join_set.spawn(async move { + table_mania + .reserve_pubkeys(&authority, &chunk_hashset) + .await + }); + } + join_set + .join_all() + .await + .into_iter() + .collect::, _>>() + .unwrap(); + + utils::log_active_table_addresses(&table_mania).await; + let expected_tables_count = + (amount as f32 / LOOKUP_TABLE_MAX_ADDRESSES as f32).ceil() as usize; + assert_eq!( + table_mania.active_tables_count().await, + expected_tables_count + ); + assert_eq!( + table_mania.active_table_pubkeys().await.len(), + pubkeys.len() + ); +} diff --git a/magicblock-table-mania/tests/utils/mod.rs b/magicblock-table-mania/tests/utils/mod.rs new file mode 100644 index 000000000..385b2068a --- /dev/null +++ b/magicblock-table-mania/tests/utils/mod.rs @@ -0,0 +1,116 @@ +#![allow(dead_code)] + +use log::*; +use magicblock_rpc_client::MagicblockRpcClient; +use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; +use solana_rpc_client::nonblocking::rpc_client::RpcClient; +use solana_sdk::commitment_config::CommitmentConfig; +use solana_sdk::native_token::LAMPORTS_PER_SOL; +use solana_sdk::signature::Keypair; +use solana_sdk::signer::Signer; +use std::time::{Duration, Instant}; + +pub const TEST_TABLE_CLOSE: bool = cfg!(feature = "test_table_close"); + +pub async fn sleep_millis(millis: u64) { + tokio::time::sleep(tokio::time::Duration::from_millis(millis)).await; +} + +pub fn init_logger_file_path() { + let _ = env_logger::builder() + .format_timestamp(None) + .format_module_path(false) + .format_target(false) + .format_source_path(true) + .is_test(true) + .try_init(); +} + +pub fn init_logger() { + let _ = env_logger::builder() + .format_timestamp(None) + .is_test(true) + .try_init(); +} + +pub async fn setup_table_mania(validator_auth: &Keypair) -> TableMania { + let rpc_client = { + let client = RpcClient::new_with_commitment( + "http://localhost:7799".to_string(), + CommitmentConfig::processed(), + ); + MagicblockRpcClient::from(client) + }; + rpc_client + .request_airdrop(&validator_auth.pubkey(), 777 * LAMPORTS_PER_SOL) + .await + .unwrap(); + + if TEST_TABLE_CLOSE { + TableMania::new( + rpc_client, + validator_auth, + Some(GarbageCollectorConfig::default()), + ) + } else { + TableMania::new(rpc_client, validator_auth, None) + } +} + +pub async fn close_released_tables(table_mania: &TableMania) { + if TEST_TABLE_CLOSE { + // Tables deactivate after ~2.5 mins (150secs), but most times + // it takes a lot longer so we allow double the time + const MAX_TIME_TO_CLOSE: Duration = Duration::from_secs(300); + + info!( + "Waiting for table close for up to {} secs", + MAX_TIME_TO_CLOSE.as_secs() + ); + let start = Instant::now(); + let mut count = 0; + let releasing_pubkeys = table_mania.released_table_addresses().await; + + while table_mania.released_tables_count().await > 0 { + if Instant::now() - start > MAX_TIME_TO_CLOSE { + panic!("Timed out waiting for table close"); + } + count += 1; + if count % 10 == 0 { + debug!( + "Still waiting to close, {} released tables", + table_mania.released_tables_count().await + ); + } + sleep_millis(10_000).await; + } + + for released_pubkey in releasing_pubkeys { + let table = table_mania + .rpc_client + .get_account(&released_pubkey) + .await + .expect("Failed to get table account"); + assert!( + table.is_none(), + "Table {} not closed on chain", + released_pubkey + ); + } + } else { + info!("Skipping table close wait"); + } +} + +pub async fn log_active_table_addresses(table_mania: &TableMania) { + debug!( + "Active Tables: {}", + table_mania + .active_table_addresses() + .await + .into_iter() + .map(|x| x.to_string()) + .collect::>() + .join(", ") + ); +} From e6f1edd31d3195329a9b7f7f92c335a5aeebc34e Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 14 May 2025 18:26:48 +0545 Subject: [PATCH 024/199] chore: move committor service integration tests --- Cargo.toml | 2 +- magicblock-committor-service/Cargo.toml | 1 - test-integration/Cargo.lock | 42 ++++++++++++++----- test-integration/Cargo.toml | 8 ++++ .../committor-service/Cargo.toml | 28 +++++++++++++ .../committor-service/src/lib.rs | 2 + .../tests}/ix_commit_local.rs | 15 +++---- .../tests}/utils/instructions.rs | 0 .../committor-service/tests}/utils/mod.rs | 27 ------------ .../tests}/utils/transactions.rs | 0 10 files changed, 78 insertions(+), 47 deletions(-) create mode 100644 test-integration/schedulecommit/committor-service/Cargo.toml create mode 100644 test-integration/schedulecommit/committor-service/src/lib.rs rename {magicblock-committor-service/todo-tests => test-integration/schedulecommit/committor-service/tests}/ix_commit_local.rs (99%) rename {magicblock-committor-service/todo-tests => test-integration/schedulecommit/committor-service/tests}/utils/instructions.rs (100%) rename {magicblock-committor-service/todo-tests => test-integration/schedulecommit/committor-service/tests}/utils/mod.rs (63%) rename {magicblock-committor-service/todo-tests => test-integration/schedulecommit/committor-service/tests}/utils/transactions.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index ffc2e12af..1c2aac32e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,10 +102,10 @@ magicblock-accounts-api = { path = "./magicblock-accounts-api" } magicblock-accounts-db = { path = "./magicblock-accounts-db" } magicblock-api = { path = "./magicblock-api" } magicblock-bank = { path = "./magicblock-bank" } -magicblock-committor-service = { path = "./magicblock-committor-service" } magicblock-committor-program = { path = "./magicblock-committor-program", features = [ "no-entrypoint", ] } +magicblock-committor-service = { path = "./magicblock-committor-service" } magicblock-config = { path = "./magicblock-config" } magicblock-core = { path = "./magicblock-core" } magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index bd00cb159..25e82451e 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -43,5 +43,4 @@ tokio = { workspace = true, features = ["rt", "macros"] } [features] default = [] -test_table_close = [] dev-context-only-utils = [] diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index f479b90c0..02cb15d4f 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -2937,7 +2937,6 @@ dependencies = [ "log", "magicblock-config", "magicblock-core", - "magicblock-delegation-program 1.0.0", "rayon", "serde", "solana-rpc-client", @@ -3659,7 +3658,7 @@ dependencies = [ [[package]] name = "magicblock-committor-program" -version = "0.0.0" +version = "0.1.1" dependencies = [ "borsh 1.5.7", "borsh-derive 1.5.7", @@ -3668,19 +3667,19 @@ dependencies = [ "solana-account", "solana-program", "solana-pubkey", - "thiserror 2.0.11", + "thiserror 1.0.69", ] [[package]] name = "magicblock-committor-service" -version = "0.0.0" +version = "0.1.1" dependencies = [ - "base64 0.22.1", + "base64 0.21.7", "bincode", "borsh 1.5.7", "log", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", "magicblock-rpc-client", "magicblock-table-mania", "rusqlite", @@ -3690,7 +3689,8 @@ dependencies = [ "solana-rpc-client-api", "solana-sdk", "solana-transaction-status-client-types", - "thiserror 2.0.11", + "static_assertions", + "thiserror 1.0.69", "tokio", "tokio-util 0.7.13", ] @@ -3938,30 +3938,31 @@ dependencies = [ [[package]] name = "magicblock-rpc-client" -version = "0.0.0" +version = "0.1.1" dependencies = [ "log", "solana-rpc-client", "solana-rpc-client-api", "solana-sdk", "solana-transaction-status-client-types", - "thiserror 2.0.11", + "thiserror 1.0.69", "tokio", ] [[package]] name = "magicblock-table-mania" -version = "0.0.0" +version = "0.1.1" dependencies = [ "ed25519-dalek", "log", "magicblock-rpc-client", + "rand 0.8.5", "sha3", "solana-pubkey", "solana-rpc-client", "solana-rpc-client-api", "solana-sdk", - "thiserror 2.0.11", + "thiserror 1.0.69", "tokio", ] @@ -5690,6 +5691,25 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "schedulecommit-committor-service" +version = "0.0.0" +dependencies = [ + "log", + "magicblock-committor-program", + "magicblock-committor-service", + "magicblock-delegation-program 1.0.0", + "magicblock-rpc-client", + "program-flexi-counter", + "solana-account", + "solana-pubkey", + "solana-rpc-client", + "solana-rpc-client-api", + "solana-sdk", + "test-tools-core", + "tokio", +] + [[package]] name = "schedulecommit-test-scenarios" version = "0.0.0" diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 7edd25794..f20c8b988 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -5,6 +5,7 @@ members = [ "programs/schedulecommit-security", "programs/sysvars", "schedulecommit/client", + "schedulecommit/committor-service", "schedulecommit/test-scenarios", "schedulecommit/test-security", "test-cloning", @@ -34,15 +35,22 @@ magicblock-accounts-db = { path = "../magicblock-accounts-db", features = [ magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "eba7644", default-features = false } magicblock-config = { path = "../magicblock-config" } magicblock-core = { path = "../magicblock-core" } +magicblock-committor-program = { path = "../magicblock-committor-program", features = [ + "no-entrypoint", +] } magicblock-delegation-program = { path = "../../delegation-program" } +magicblock-committor-service = { path = "../magicblock-committor-service" } +magicblock-rpc-client = { path = "../magicblock-rpc-client" } program-flexi-counter = { path = "./programs/flexi-counter" } program-schedulecommit = { path = "programs/schedulecommit" } program-schedulecommit-security = { path = "programs/schedulecommit-security" } rayon = "1.10.0" schedulecommit-client = { path = "schedulecommit/client" } serde = "1.0.217" +solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "7bdfefc" } solana-program = "2.2" solana-program-test = "2.2" +solana-pubkey = { version = "2.2" } solana-rpc-client = "2.2" solana-rpc-client-api = "2.2" solana-sdk = "2.2" diff --git a/test-integration/schedulecommit/committor-service/Cargo.toml b/test-integration/schedulecommit/committor-service/Cargo.toml new file mode 100644 index 000000000..7667e32ce --- /dev/null +++ b/test-integration/schedulecommit/committor-service/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "schedulecommit-committor-service" +version.workspace = true +edition.workspace = true + +[dev-dependencies] +log = { workspace = true } +magicblock-committor-program = { workspace = true, features = [ + "no-entrypoint", +] } +magicblock-delegation-program = { workspace = true, features = [ + "no-entrypoint", +] } +magicblock-committor-service = { workspace = true, features = [ + "dev-context-only-utils", +] } +magicblock-rpc-client = { workspace = true } +program-flexi-counter = { workspace = true, features = ["no-entrypoint"] } +solana-account = { workspace = true } +solana-pubkey = { workspace = true } +solana-rpc-client = { workspace = true } +solana-rpc-client-api = { workspace = true } +solana-sdk = { workspace = true } +test-tools-core = { workspace = true } +tokio = { workspace = true } + +[features] +test_table_close = [] diff --git a/test-integration/schedulecommit/committor-service/src/lib.rs b/test-integration/schedulecommit/committor-service/src/lib.rs new file mode 100644 index 000000000..10f55cb13 --- /dev/null +++ b/test-integration/schedulecommit/committor-service/src/lib.rs @@ -0,0 +1,2 @@ +#[allow(unused)] +pub const HELLO: &str = "world"; diff --git a/magicblock-committor-service/todo-tests/ix_commit_local.rs b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs similarity index 99% rename from magicblock-committor-service/todo-tests/ix_commit_local.rs rename to test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs index b3227e3b6..5ba085e13 100644 --- a/magicblock-committor-service/todo-tests/ix_commit_local.rs +++ b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs @@ -3,6 +3,7 @@ use magicblock_committor_service::{ChangesetCommittor, ComputeBudgetConfig}; use magicblock_rpc_client::MagicblockRpcClient; use std::collections::{HashMap, HashSet}; use std::time::{Duration, Instant}; +use test_tools_core::init_logger; use tokio::task::JoinSet; use utils::transactions::tx_logs_contain; @@ -282,7 +283,7 @@ async fn commit_single_account( expected_strategy: CommitStrategy, undelegate: bool, ) { - utils::init_logger_target(); + init_logger!(); let slot = 10; let validator_auth = utils::get_validator_auth(); @@ -339,7 +340,7 @@ async fn commit_single_account( // ----------------- #[tokio::test] async fn test_ix_commit_two_accounts_1kb_2kb() { - utils::init_logger(); + init_logger!(); commit_multiple_accounts( &[1024, 2048], 1, @@ -351,7 +352,7 @@ async fn test_ix_commit_two_accounts_1kb_2kb() { #[tokio::test] async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() { - utils::init_logger(); + init_logger!(); commit_multiple_accounts( &[1024, 2 * 1024, 5 * 1024, 10 * 1024], 1, @@ -477,7 +478,7 @@ async fn commit_5_accounts_1kb( expected_strategies: ExpectedStrategies, undelegate_all: bool, ) { - utils::init_logger(); + init_logger!(); let accs = (0..5).map(|_| 1024).collect::>(); commit_multiple_accounts( &accs, @@ -492,7 +493,7 @@ async fn commit_8_accounts_1kb( bundle_size: usize, expected_strategies: ExpectedStrategies, ) { - utils::init_logger(); + init_logger!(); let accs = (0..8).map(|_| 1024).collect::>(); commit_multiple_accounts(&accs, bundle_size, expected_strategies, false) .await; @@ -502,7 +503,7 @@ async fn commit_20_accounts_1kb( bundle_size: usize, expected_strategies: ExpectedStrategies, ) { - utils::init_logger(); + init_logger!(); let accs = (0..20).map(|_| 1024).collect::>(); commit_multiple_accounts(&accs, bundle_size, expected_strategies, false) .await; @@ -514,7 +515,7 @@ async fn commit_multiple_accounts( expected_strategies: ExpectedStrategies, undelegate_all: bool, ) { - utils::init_logger(); + init_logger!(); let slot = 10; let validator_auth = utils::get_validator_auth(); diff --git a/magicblock-committor-service/todo-tests/utils/instructions.rs b/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs similarity index 100% rename from magicblock-committor-service/todo-tests/utils/instructions.rs rename to test-integration/schedulecommit/committor-service/tests/utils/instructions.rs diff --git a/magicblock-committor-service/todo-tests/utils/mod.rs b/test-integration/schedulecommit/committor-service/tests/utils/mod.rs similarity index 63% rename from magicblock-committor-service/todo-tests/utils/mod.rs rename to test-integration/schedulecommit/committor-service/tests/utils/mod.rs index 0b9433747..9cad5484c 100644 --- a/magicblock-committor-service/todo-tests/utils/mod.rs +++ b/test-integration/schedulecommit/committor-service/tests/utils/mod.rs @@ -1,6 +1,3 @@ -use std::env; - -use env_logger::Target; use solana_sdk::signature::Keypair; pub mod instructions; @@ -11,30 +8,6 @@ pub async fn sleep_millis(millis: u64) { tokio::time::sleep(tokio::time::Duration::from_millis(millis)).await; } -pub fn init_logger() { - let mut builder = env_logger::builder(); - builder - .format_timestamp(None) - .format_module_path(false) - .format_target(false) - .format_source_path(true) - .is_test(true); - - if let Ok(path) = env::var("TEST_LOG_FILE") { - builder.target(Target::Pipe(Box::new( - std::fs::File::create(path).unwrap(), - ))); - } - let _ = builder.try_init(); -} - -pub fn init_logger_target() { - let _ = env_logger::builder() - .format_timestamp(None) - .is_test(true) - .try_init(); -} - /// This is the test authority used in the delegation program /// https://github.com/magicblock-labs/delegation-program/blob/7fc0ae9a59e48bea5b046b173ea0e34fd433c3c7/tests/fixtures/accounts.rs#L46 /// It is compiled in as the authority for the validator vault when we build via diff --git a/magicblock-committor-service/todo-tests/utils/transactions.rs b/test-integration/schedulecommit/committor-service/tests/utils/transactions.rs similarity index 100% rename from magicblock-committor-service/todo-tests/utils/transactions.rs rename to test-integration/schedulecommit/committor-service/tests/utils/transactions.rs From 1c4dd7895556f419c60dcfaac0d7d1f7b5ec6d76 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 14 May 2025 18:32:51 +0545 Subject: [PATCH 025/199] chore: noting escrow/fee payer related test requirements --- .../test-scenarios/tests/03_commits_fee_payer.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs b/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs index f04c8bd71..8d606114f 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs @@ -23,6 +23,10 @@ mod utils; #[test] fn test_committing_fee_payer_without_escrowing_lamports() { + // NOTE: this test requires the following config + // [validator] + // base_fees = 1000 + // see ../../../configs/schedulecommit-conf-fees.ephem.toml run_test!({ let ctx = get_context_with_delegated_committees_without_payer_escrow(2); @@ -64,9 +68,8 @@ fn test_committing_fee_payer_without_escrowing_lamports() { }, ); info!("{} '{:?}'", sig, res); - assert!(!res.is_ok()); - // Should fail because the fee payer was not escrowed + assert!(res.is_err()); assert!(res .err() .unwrap() From 8c620feffa0a0e31873a7e48cd9ff7c1a5a302e4 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 11:00:41 +0545 Subject: [PATCH 026/199] chore: minor cleanup in test runner --- test-integration/test-runner/bin/run_tests.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index 5a85a936e..a9c322a66 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -1,9 +1,9 @@ use integration_test_tools::validator::start_test_validator_with_config; use integration_test_tools::{ - toml_to_args::{config_to_args, rpc_port_from_config, ProgramLoader}, + toml_to_args::ProgramLoader, validator::{ resolve_workspace_dir, start_magic_block_validator_with_config, - wait_for_validator, TestRunnerPaths, + TestRunnerPaths, }, }; use std::{ @@ -21,7 +21,7 @@ pub fn main() { let Ok((security_output, scenarios_output)) = run_schedule_commit_tests(&manifest_dir) else { - // TODO: why we don't report Error case lower? + // If any test fails or cannot run we bail immediately return; }; From f3e17d13444741dc2af9532dca49e84f6fd9d487 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 11:11:03 +0545 Subject: [PATCH 027/199] ix: load committor program for schedule commits --- test-integration/Makefile | 16 ++++++++++------ .../configs/schedulecommit-conf.devnet.toml | 11 ++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/test-integration/Makefile b/test-integration/Makefile index 614c938d7..153858bd5 100644 --- a/test-integration/Makefile +++ b/test-integration/Makefile @@ -1,21 +1,25 @@ DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) DEPLOY_DIR := $(DIR)target/deploy +ROOT_DEPLOY_DIR := $(DIR)../target/deploy RUST_LOG ?= 'warn,geyser_plugin=warn,magicblock=trace,rpc=trace,bank=trace,banking_stage=warn,solana_geyser_plugin_manager=warn,solana_svm=warn,test_tools=trace,schedulecommit_test=trace,' \ FLEXI_COUNTER_DIR := $(DIR)programs/flexi-counter SCHEDULECOMMIT_DIR := $(DIR)programs/schedulecommit SCHEDULECOMMIT_SECURITY_DIR := $(DIR)programs/schedulecommit-security +COMMITTOR_PROGRAM_DIR := $(DIR)../magicblock-committor-program/ FLEXI_COUNTER_SRC := $(shell find $(FLEXI_COUNTER_DIR) -name '*.rs' -o -name '*.toml') SCHEDULECOMMIT_SRC := $(shell find $(SCHEDULECOMMIT_DIR) -name '*.rs' -o -name '*.toml') SCHEDULECOMMIT_SECURITY_SRC := $(shell find $(SCHEDULECOMMIT_SECURITY_DIR) -name '*.rs' -o -name '*.toml') +COMMITTOR_PROGRAM_SRC := $(shell find $(COMMITTOR_PROGRAM_DIR) -name '*.rs' -o -name '*.toml') FLEXI_COUNTER_SO := $(DEPLOY_DIR)/program_flexi_counter.so SCHEDULECOMMIT_SO := $(DEPLOY_DIR)/program_schedulecommit.so SCHEDULECOMMIT_SECURITY_SO := $(DEPLOY_DIR)/program_schedulecommit_security.so +COMMITTOR_PROGRAM_SO := $(ROOT_DEPLOY_DIR)/magicblock_committor_program.so -PROGRAMS_SO := $(FLEXI_COUNTER_SO) $(SCHEDULECOMMIT_SO) $(SCHEDULECOMMIT_SECURITY_SO) +PROGRAMS_SO := $(FLEXI_COUNTER_SO) $(SCHEDULECOMMIT_SO) $(SCHEDULECOMMIT_SECURITY_SO) $(COMMITTOR_PROGRAM_SO) list-tasks: @cat Makefile | grep "^[a-z].*:" | sed 's/:.*//g' @@ -25,19 +29,19 @@ list-programs: test: $(PROGRAMS_SO) RUST_BACKTRACE=1 \ RUST_LOG=$(RUST_LOG) \ - cargo run --package test-runner --bin run-tests + cargo run --package test-runner --bin run-tests test-force-mb: $(PROGRAMS_SO) test-ledger-restore RUST_LOG=$(RUST_LOG) \ FORCE_MAGIC_BLOCK_VALIDATOR=1 \ - cargo run --package test-runner --bin run-tests + cargo run --package test-runner --bin run-tests $(FLEXI_COUNTER_SO): $(FLEXI_COUNTER_SRC) - cargo build-sbf --manifest-path $(FLEXI_COUNTER_DIR)/Cargo.toml + cargo build-sbf --manifest-path $(FLEXI_COUNTER_DIR)/Cargo.toml $(SCHEDULECOMMIT_SO): $(SCHEDULECOMMIT_SRC) - cargo build-sbf --manifest-path $(SCHEDULECOMMIT_DIR)/Cargo.toml + cargo build-sbf --manifest-path $(SCHEDULECOMMIT_DIR)/Cargo.toml $(SCHEDULECOMMIT_SECURITY_SO): $(SCHEDULECOMMIT_SECURITY_SRC) - cargo build-sbf --manifest-path $(SCHEDULECOMMIT_SECURITY_DIR)/Cargo.toml + cargo build-sbf --manifest-path $(SCHEDULECOMMIT_SECURITY_DIR)/Cargo.toml deploy-flexi-counter: $(FLEXI_COUNTER_SO) solana program deploy \ diff --git a/test-integration/configs/schedulecommit-conf.devnet.toml b/test-integration/configs/schedulecommit-conf.devnet.toml index de18df07e..e6b44cb23 100644 --- a/test-integration/configs/schedulecommit-conf.devnet.toml +++ b/test-integration/configs/schedulecommit-conf.devnet.toml @@ -6,14 +6,14 @@ commit = { frequency_millis = 9_000_000_000_000, compute_unit_price = 1_000_000 [accounts.db] # size of the main storage, we have to preallocate in advance -# it's advised to set this value based on formula 1KB * N * 3, -# where N is the number of accounts expected to be stored in +# it's advised to set this value based on formula 1KB * N * 3, +# where N is the number of accounts expected to be stored in # database, e.g. for million accounts this would be 3GB db-size = 1048576000 # 1GB # minimal indivisible unit of addressing in main storage # offsets are calculated in terms of blocks block-size = "block256" # possible values block128 | block256 | block512 -# size of index file, we have to preallocate, +# size of index file, we have to preallocate, # can be as low as 1% of main storage size, but setting it to higher values won't hurt index-map-size = 2048576 # max number of snapshots to keep around @@ -33,6 +33,11 @@ path = "../schedulecommit/elfs/dlp.so" id = "42Y73BJyGCXh2XUrqyz59WCk2DsBtqrFrt38t9ogB5sD" path = "../schedulecommit/elfs/mdp.so" +# NOTE: `cargo build-sbf` needs to run from the root to build the program +[[program]] +id = "corabpNrkBEqbTZP7xfJgSWTdBmVdLf1PARWXZbcMcS" +path = "../../target/deploy/magicblock_committor_program.so" + [[program]] id = "9hgprgZiRWmy8KkfvUuaVkDGrqo9GzeXMohwq6BazgUY" path = "../target/deploy/program_schedulecommit.so" From 6d109f933703015115f1eb7a1576048640203fc0 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 11:36:46 +0545 Subject: [PATCH 028/199] ix: allow configuring loaded accounts --- test-integration/Cargo.lock | 2 + .../tests/test_domain_registry.rs | 9 ++- test-integration/test-runner/bin/run_tests.rs | 10 +++ test-integration/test-tools/Cargo.toml | 4 ++ test-integration/test-tools/src/lib.rs | 1 + .../test-tools/src/loaded_accounts.rs | 63 +++++++++++++++++++ test-integration/test-tools/src/validator.rs | 18 +++--- 7 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 test-integration/test-tools/src/loaded_accounts.rs diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 02cb15d4f..b030e9d65 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -2937,8 +2937,10 @@ dependencies = [ "log", "magicblock-config", "magicblock-core", + "magicblock-delegation-program 1.0.0", "rayon", "serde", + "solana-pubkey", "solana-rpc-client", "solana-rpc-client-api", "solana-sdk", diff --git a/test-integration/test-magicblock-api/tests/test_domain_registry.rs b/test-integration/test-magicblock-api/tests/test_domain_registry.rs index 2c55e65e2..180d2a324 100644 --- a/test-integration/test-magicblock-api/tests/test_domain_registry.rs +++ b/test-integration/test-magicblock-api/tests/test_domain_registry.rs @@ -109,8 +109,13 @@ impl TestValidator { root_dir, workspace_dir, }; - let process = start_test_validator_with_config(&paths, None, "CHAIN") - .expect("Failed to start devnet process"); + let process = start_test_validator_with_config( + &paths, + None, + Default::default(), + "CHAIN", + ) + .expect("Failed to start devnet process"); Self { process } } diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index a9c322a66..e48f03c15 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -1,3 +1,4 @@ +use integration_test_tools::loaded_accounts::LoadedAccounts; use integration_test_tools::validator::start_test_validator_with_config; use integration_test_tools::{ toml_to_args::ProgramLoader, @@ -65,6 +66,7 @@ fn run_restore_ledger_tests( let mut devnet_validator = match start_validator( "restore-ledger-conf.devnet.toml", ValidatorCluster::Chain(None), + Default::default(), ) { Some(validator) => validator, None => { @@ -100,6 +102,7 @@ fn run_schedule_commit_tests( let mut devnet_validator = match start_validator( "schedulecommit-conf.devnet.toml", ValidatorCluster::Chain(None), + LoadedAccounts::with_delegation_program_test_authority(), ) { Some(validator) => validator, None => { @@ -115,6 +118,7 @@ fn run_schedule_commit_tests( let mut ephem_validator = match start_validator( "schedulecommit-conf-fees.ephem.toml", ValidatorCluster::Ephem, + LoadedAccounts::with_delegation_program_test_authority(), ) { Some(validator) => validator, None => { @@ -163,6 +167,7 @@ fn run_issues_frequent_commmits_tests( let mut devnet_validator = match start_validator( "schedulecommit-conf.devnet.toml", ValidatorCluster::Chain(None), + LoadedAccounts::with_delegation_program_test_authority(), ) { Some(validator) => validator, None => { @@ -172,6 +177,7 @@ fn run_issues_frequent_commmits_tests( let mut ephem_validator = match start_validator( "schedulecommit-conf.ephem.frequent-commits.toml", ValidatorCluster::Ephem, + LoadedAccounts::with_delegation_program_test_authority(), ) { Some(validator) => validator, None => { @@ -205,6 +211,7 @@ fn run_cloning_tests(manifest_dir: &str) -> Result> { let mut devnet_validator = match start_validator( "cloning-conf.devnet.toml", ValidatorCluster::Chain(Some(ProgramLoader::BpfProgram)), + LoadedAccounts::with_delegation_program_test_authority(), ) { Some(validator) => validator, None => { @@ -214,6 +221,7 @@ fn run_cloning_tests(manifest_dir: &str) -> Result> { let mut ephem_validator = match start_validator( "cloning-conf.ephem.toml", ValidatorCluster::Ephem, + LoadedAccounts::with_delegation_program_test_authority(), ) { Some(validator) => validator, None => { @@ -332,6 +340,7 @@ impl ValidatorCluster { fn start_validator( config_file: &str, cluster: ValidatorCluster, + loaded_accounts: LoadedAccounts, ) -> Option { let log_suffix = cluster.log_suffix(); let test_runner_paths = resolve_paths(config_file); @@ -343,6 +352,7 @@ fn start_validator( start_test_validator_with_config( &test_runner_paths, program_loader, + loaded_accounts, log_suffix, ) } diff --git a/test-integration/test-tools/Cargo.toml b/test-integration/test-tools/Cargo.toml index 50c3719ac..b3ea8bc73 100644 --- a/test-integration/test-tools/Cargo.toml +++ b/test-integration/test-tools/Cargo.toml @@ -11,6 +11,10 @@ rayon = { workspace = true } serde = { workspace = true } magicblock-core = { workspace = true } magicblock-config = { workspace = true } +magicblock-delegation-program = { workspace = true, features = [ + "no-entrypoint", +] } +solana-pubkey = { workspace = true } solana-rpc-client = { workspace = true } solana-rpc-client-api = { workspace = true } solana-sdk = { workspace = true } diff --git a/test-integration/test-tools/src/lib.rs b/test-integration/test-tools/src/lib.rs index 52f0abb30..10c4704dc 100644 --- a/test-integration/test-tools/src/lib.rs +++ b/test-integration/test-tools/src/lib.rs @@ -1,5 +1,6 @@ pub mod conversions; mod integration_test_context; +pub mod loaded_accounts; mod run_test; pub mod scheduled_commits; pub mod tmpdir; diff --git a/test-integration/test-tools/src/loaded_accounts.rs b/test-integration/test-tools/src/loaded_accounts.rs new file mode 100644 index 000000000..ea1238da9 --- /dev/null +++ b/test-integration/test-tools/src/loaded_accounts.rs @@ -0,0 +1,63 @@ +use solana_pubkey::pubkey; +use solana_sdk::pubkey::Pubkey; + +pub struct LoadedAccounts { + validator_authority: Pubkey, + luzid_authority: Pubkey, +} + +impl Default for LoadedAccounts { + fn default() -> Self { + Self { + validator_authority: pubkey!( + "mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev" + ), + luzid_authority: pubkey!( + "LUzidNSiPNjYNkxZcUm5hYHwnWPwsUfh2US1cpWwaBm" + ), + } + } +} + +impl LoadedAccounts { + pub fn new(validator_authority: Pubkey, luzid_authority: Pubkey) -> Self { + Self { + validator_authority, + luzid_authority, + } + } + + /// This use the test authority used in the delegation program as the validator + /// authority. + /// https://github.com/magicblock-labs/delegation-program/blob/7fc0ae9a59e48bea5b046b173ea0e34fd433c3c7/tests/fixtures/accounts.rs#L46 + /// It is compiled in as the authority for the validator vault when we build + /// the delegation program via: + /// `cargo build-sbf --features=unit_test_config` + pub fn with_delegation_program_test_authority() -> Self { + Self { + validator_authority: pubkey!( + "tEsT3eV6RFCWs1BZ7AXTzasHqTtMnMLCB2tjQ42TDXD" + ), + luzid_authority: pubkey!( + "LUzidNSiPNjYNkxZcUm5hYHwnWPwsUfh2US1cpWwaBm" + ), + } + } + + pub fn validator_authority(&self) -> Pubkey { + self.validator_authority + } + + pub fn luzid_authority(&self) -> Pubkey { + self.luzid_authority + } + + pub fn validator_fees_vault(&self) -> Pubkey { + dlp::pda::validator_fees_vault_pda_from_validator( + &self.validator_authority, + ) + } + pub fn protocol_fees_vault(&self) -> Pubkey { + dlp::pda::fees_vault_pda() + } +} diff --git a/test-integration/test-tools/src/validator.rs b/test-integration/test-tools/src/validator.rs index c2f897662..7999adbd2 100644 --- a/test-integration/test-tools/src/validator.rs +++ b/test-integration/test-tools/src/validator.rs @@ -6,8 +6,9 @@ use std::{ time::Duration, }; -use crate::toml_to_args::{ - config_to_args, rpc_port_from_config, ProgramLoader, +use crate::{ + loaded_accounts::LoadedAccounts, + toml_to_args::{config_to_args, rpc_port_from_config, ProgramLoader}, }; pub fn start_magic_block_validator_with_config( @@ -31,7 +32,7 @@ pub fn start_magic_block_validator_with_config( } let build_res = command.current_dir(root_dir.clone()).output(); - if build_res.map_or(false, |output| !output.status.success()) { + if build_res.is_ok_and(|output| !output.status.success()) { eprintln!("Failed to build validator"); return None; } @@ -57,6 +58,7 @@ pub fn start_magic_block_validator_with_config( pub fn start_test_validator_with_config( test_runner_paths: &TestRunnerPaths, program_loader: Option, + loaded_accounts: LoadedAccounts, log_suffix: &str, ) -> Option { let TestRunnerPaths { @@ -71,19 +73,19 @@ pub fn start_test_validator_with_config( let accounts_dir = workspace_dir.join("configs").join("accounts"); let accounts = [ ( - "mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev", + loaded_accounts.validator_authority().to_string(), "validator-authority.json", ), ( - "LUzidNSiPNjYNkxZcUm5hYHwnWPwsUfh2US1cpWwaBm", + loaded_accounts.luzid_authority().to_string(), "luzid-authority.json", ), ( - "EpJnX7ueXk7fKojBymqmVuCuwyhDQsYcLVL1XMsBbvDX", + loaded_accounts.validator_fees_vault().to_string(), "validator-fees-vault.json", ), ( - "7JrkjmZPprHwtuvtuGTXp9hwfGYFAQLnLeFM52kqAgXg", + loaded_accounts.protocol_fees_vault().to_string(), "protocol-fees-vault.json", ), ]; @@ -94,7 +96,7 @@ pub fn start_test_validator_with_config( let account_path = accounts_dir.join(file).canonicalize().unwrap(); vec![ "--account".to_string(), - account.to_string(), + account.clone(), account_path.to_str().unwrap().to_string(), ] }) From 0dceb8b46edbad91d7e6349af877bede4142019f Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 12:21:03 +0545 Subject: [PATCH 029/199] ix: match ephem validator keypair to the one we use on chain --- .../test-ledger-restore/src/lib.rs | 20 ++++++-- .../tests/test_domain_registry.rs | 2 +- test-integration/test-runner/bin/run_tests.rs | 5 +- .../test-tools/src/loaded_accounts.rs | 51 ++++++++++++------- .../test-tools/src/scheduled_commits.rs | 1 + test-integration/test-tools/src/validator.rs | 10 +++- 6 files changed, 63 insertions(+), 26 deletions(-) diff --git a/test-integration/test-ledger-restore/src/lib.rs b/test-integration/test-ledger-restore/src/lib.rs index 7ce9aaed2..1f9ff5562 100644 --- a/test-integration/test-ledger-restore/src/lib.rs +++ b/test-integration/test-ledger-restore/src/lib.rs @@ -3,6 +3,7 @@ use std::{fs, path::Path, process, process::Child}; use integration_test_tools::{ expect, + loaded_accounts::LoadedAccounts, tmpdir::resolve_tmp_dir, validator::{ resolve_workspace_dir, start_magic_block_validator_with_config, @@ -11,7 +12,10 @@ use integration_test_tools::{ workspace_paths::path_relative_to_workspace, IntegrationTestContext, }; -use magicblock_config::{AccountsConfig, EphemeralConfig, LedgerConfig, LifecycleMode, ProgramConfig, RemoteConfig, ValidatorConfig, DEFAULT_LEDGER_SIZE_BYTES}; +use magicblock_config::{ + AccountsConfig, EphemeralConfig, LedgerConfig, LifecycleMode, + ProgramConfig, RemoteConfig, ValidatorConfig, DEFAULT_LEDGER_SIZE_BYTES, +}; use program_flexi_counter::state::FlexiCounter; use solana_sdk::{ clock::Slot, @@ -36,6 +40,7 @@ pub const FLEXI_COUNTER_PUBKEY: Pubkey = /// Then uses that config to start the validator. pub fn start_validator_with_config( config: EphemeralConfig, + loaded_chain_accounts: &LoadedAccounts, ) -> (TempDir, Option) { let workspace_dir = resolve_workspace_dir(); let (default_tmpdir, temp_dir) = resolve_tmp_dir(TMP_DIR_CONFIG); @@ -56,7 +61,12 @@ pub fn start_validator_with_config( }; ( default_tmpdir, - start_magic_block_validator_with_config(&paths, "TEST", release), + start_magic_block_validator_with_config( + &paths, + "TEST", + loaded_chain_accounts, + release, + ), ) } @@ -104,7 +114,7 @@ pub fn setup_offline_validator( ledger: LedgerConfig { reset, path: Some(ledger_path.display().to_string()), - size: DEFAULT_LEDGER_SIZE_BYTES + size: DEFAULT_LEDGER_SIZE_BYTES, }, accounts: accounts_config.clone(), programs, @@ -112,7 +122,7 @@ pub fn setup_offline_validator( ..Default::default() }; let (default_tmpdir_config, Some(mut validator)) = - start_validator_with_config(config) + start_validator_with_config(config, &Default::default()) else { panic!("validator should set up correctly"); }; @@ -153,7 +163,7 @@ pub fn setup_validator_with_local_remote( }; let (default_tmpdir_config, Some(mut validator)) = - start_validator_with_config(config) + start_validator_with_config(config, &Default::default()) else { panic!("validator should set up correctly"); }; diff --git a/test-integration/test-magicblock-api/tests/test_domain_registry.rs b/test-integration/test-magicblock-api/tests/test_domain_registry.rs index 180d2a324..a8119c6ce 100644 --- a/test-integration/test-magicblock-api/tests/test_domain_registry.rs +++ b/test-integration/test-magicblock-api/tests/test_domain_registry.rs @@ -112,7 +112,7 @@ impl TestValidator { let process = start_test_validator_with_config( &paths, None, - Default::default(), + &Default::default(), "CHAIN", ) .expect("Failed to start devnet process"); diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index e48f03c15..71757c213 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -340,7 +340,7 @@ impl ValidatorCluster { fn start_validator( config_file: &str, cluster: ValidatorCluster, - loaded_accounts: LoadedAccounts, + loaded_chain_accounts: LoadedAccounts, ) -> Option { let log_suffix = cluster.log_suffix(); let test_runner_paths = resolve_paths(config_file); @@ -352,13 +352,14 @@ fn start_validator( start_test_validator_with_config( &test_runner_paths, program_loader, - loaded_accounts, + &loaded_chain_accounts, log_suffix, ) } _ => start_magic_block_validator_with_config( &test_runner_paths, log_suffix, + &loaded_chain_accounts, false, ), } diff --git a/test-integration/test-tools/src/loaded_accounts.rs b/test-integration/test-tools/src/loaded_accounts.rs index ea1238da9..5c9203b03 100644 --- a/test-integration/test-tools/src/loaded_accounts.rs +++ b/test-integration/test-tools/src/loaded_accounts.rs @@ -1,17 +1,32 @@ use solana_pubkey::pubkey; -use solana_sdk::pubkey::Pubkey; +use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer}; + +// mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev +const TEST_KEYPAIR_BYTES: [u8; 64] = [ + 7, 83, 184, 55, 200, 223, 238, 137, 166, 244, 107, 126, 189, 16, 194, 36, + 228, 68, 43, 143, 13, 91, 3, 81, 53, 253, 26, 36, 50, 198, 40, 159, 11, 80, + 9, 208, 183, 189, 108, 200, 89, 77, 168, 76, 233, 197, 132, 22, 21, 186, + 202, 240, 105, 168, 157, 64, 233, 249, 100, 104, 210, 41, 83, 87, +]; +// tEsT3eV6RFCWs1BZ7AXTzasHqTtMnMLCB2tjQ42TDXD +// 62LxqpAW6SWhp7iKBjCQneapn1w6btAhW7xHeREWSpPzw3xZbHCfAFesSR4R76ejQXCLWrndn37cKCCLFvx6Swps +pub const DLP_TEST_AUTHORITY_BYTES: [u8; 64] = [ + 251, 62, 129, 184, 107, 49, 62, 184, 1, 147, 178, 128, 185, 157, 247, 92, + 56, 158, 145, 53, 51, 226, 202, 96, 178, 248, 195, 133, 133, 237, 237, 146, + 13, 32, 77, 204, 244, 56, 166, 172, 66, 113, 150, 218, 112, 42, 110, 181, + 98, 158, 222, 194, 130, 93, 175, 100, 190, 106, 9, 69, 156, 80, 96, 72, +]; pub struct LoadedAccounts { - validator_authority: Pubkey, + validator_authority_kp: Keypair, luzid_authority: Pubkey, } impl Default for LoadedAccounts { fn default() -> Self { Self { - validator_authority: pubkey!( - "mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev" - ), + validator_authority_kp: Keypair::from_bytes(&TEST_KEYPAIR_BYTES) + .expect("Failed to create validator authority keypair"), luzid_authority: pubkey!( "LUzidNSiPNjYNkxZcUm5hYHwnWPwsUfh2US1cpWwaBm" ), @@ -20,13 +35,6 @@ impl Default for LoadedAccounts { } impl LoadedAccounts { - pub fn new(validator_authority: Pubkey, luzid_authority: Pubkey) -> Self { - Self { - validator_authority, - luzid_authority, - } - } - /// This use the test authority used in the delegation program as the validator /// authority. /// https://github.com/magicblock-labs/delegation-program/blob/7fc0ae9a59e48bea5b046b173ea0e34fd433c3c7/tests/fixtures/accounts.rs#L46 @@ -35,17 +43,26 @@ impl LoadedAccounts { /// `cargo build-sbf --features=unit_test_config` pub fn with_delegation_program_test_authority() -> Self { Self { - validator_authority: pubkey!( - "tEsT3eV6RFCWs1BZ7AXTzasHqTtMnMLCB2tjQ42TDXD" - ), + validator_authority_kp: Keypair::from_bytes( + &DLP_TEST_AUTHORITY_BYTES, + ) + .expect("Failed to create validator authority keypair"), luzid_authority: pubkey!( "LUzidNSiPNjYNkxZcUm5hYHwnWPwsUfh2US1cpWwaBm" ), } } + pub fn validator_authority_keypair(&self) -> &Keypair { + &self.validator_authority_kp + } + + pub fn validator_authority_base58(&self) -> String { + self.validator_authority_kp.to_base58_string() + } + pub fn validator_authority(&self) -> Pubkey { - self.validator_authority + self.validator_authority_kp.pubkey() } pub fn luzid_authority(&self) -> Pubkey { @@ -54,7 +71,7 @@ impl LoadedAccounts { pub fn validator_fees_vault(&self) -> Pubkey { dlp::pda::validator_fees_vault_pda_from_validator( - &self.validator_authority, + &self.validator_authority(), ) } pub fn protocol_fees_vault(&self) -> Pubkey { diff --git a/test-integration/test-tools/src/scheduled_commits.rs b/test-integration/test-tools/src/scheduled_commits.rs index e4c11ef3e..4c1418ad6 100644 --- a/test-integration/test-tools/src/scheduled_commits.rs +++ b/test-integration/test-tools/src/scheduled_commits.rs @@ -24,6 +24,7 @@ pub fn extract_scheduled_commit_sent_signature_from_logs( None } +#[allow(clippy::type_complexity)] pub fn extract_sent_commit_info_from_logs( logs: &[String], ) -> ( diff --git a/test-integration/test-tools/src/validator.rs b/test-integration/test-tools/src/validator.rs index 7999adbd2..5fceb5488 100644 --- a/test-integration/test-tools/src/validator.rs +++ b/test-integration/test-tools/src/validator.rs @@ -14,6 +14,7 @@ use crate::{ pub fn start_magic_block_validator_with_config( test_runner_paths: &TestRunnerPaths, log_suffix: &str, + loaded_chain_accounts: &LoadedAccounts, release: bool, ) -> Option { let TestRunnerPaths { @@ -26,6 +27,7 @@ pub fn start_magic_block_validator_with_config( // First build so that the validator can start fast let mut command = process::Command::new("cargo"); + let keypair_base58 = loaded_chain_accounts.validator_authority_base58(); command.arg("build"); if release { command.arg("--release"); @@ -47,9 +49,15 @@ pub fn start_magic_block_validator_with_config( .arg("--") .arg(config_path) .env("RUST_LOG_STYLE", log_suffix) + .env("VALIDATOR_KEYPAIR", keypair_base58.clone()) .current_dir(root_dir); eprintln!("Starting validator with {:?}", command); + eprintln!( + "Setting validator keypair to {} ({})", + loaded_chain_accounts.validator_authority(), + keypair_base58 + ); let validator = command.spawn().expect("Failed to start validator"); wait_for_validator(validator, port) @@ -58,7 +66,7 @@ pub fn start_magic_block_validator_with_config( pub fn start_test_validator_with_config( test_runner_paths: &TestRunnerPaths, program_loader: Option, - loaded_accounts: LoadedAccounts, + loaded_accounts: &LoadedAccounts, log_suffix: &str, ) -> Option { let TestRunnerPaths { From 7fdc7956bb263e5b36fe818ae6500c239a2baf12 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 12:32:09 +0545 Subject: [PATCH 030/199] ix: ensure we always pass same loaded chain accounts to chain + ephenm setup --- .../test-ledger-restore/src/lib.rs | 5 ++- test-integration/test-runner/bin/run_tests.rs | 31 ++++++++++++------- .../src/integration_test_context.rs | 2 +- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/test-integration/test-ledger-restore/src/lib.rs b/test-integration/test-ledger-restore/src/lib.rs index 1f9ff5562..7d528fa9d 100644 --- a/test-integration/test-ledger-restore/src/lib.rs +++ b/test-integration/test-ledger-restore/src/lib.rs @@ -163,7 +163,10 @@ pub fn setup_validator_with_local_remote( }; let (default_tmpdir_config, Some(mut validator)) = - start_validator_with_config(config, &Default::default()) + start_validator_with_config( + config, + &LoadedAccounts::with_delegation_program_test_authority(), + ) else { panic!("validator should set up correctly"); }; diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index 71757c213..bfc450092 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -18,7 +18,6 @@ use test_runner::cleanup::{cleanup_devnet_only, cleanup_validators}; pub fn main() { let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let Ok((security_output, scenarios_output)) = run_schedule_commit_tests(&manifest_dir) else { @@ -61,12 +60,14 @@ fn run_restore_ledger_tests( manifest_dir: &str, ) -> Result> { eprintln!("======== RUNNING RESTORE LEDGER TESTS ========"); + let loaded_chain_accounts = + LoadedAccounts::with_delegation_program_test_authority(); // The ledger tests manage their own ephem validator so all we start up here // is devnet let mut devnet_validator = match start_validator( "restore-ledger-conf.devnet.toml", ValidatorCluster::Chain(None), - Default::default(), + &loaded_chain_accounts, ) { Some(validator) => validator, None => { @@ -98,11 +99,14 @@ fn run_schedule_commit_tests( "======== Starting DEVNET Validator for Scenarios + Security ========" ); + let loaded_chain_accounts = + LoadedAccounts::with_delegation_program_test_authority(); + // Start validators via `cargo run --release -- let mut devnet_validator = match start_validator( "schedulecommit-conf.devnet.toml", ValidatorCluster::Chain(None), - LoadedAccounts::with_delegation_program_test_authority(), + &loaded_chain_accounts, ) { Some(validator) => validator, None => { @@ -118,7 +122,7 @@ fn run_schedule_commit_tests( let mut ephem_validator = match start_validator( "schedulecommit-conf-fees.ephem.toml", ValidatorCluster::Ephem, - LoadedAccounts::with_delegation_program_test_authority(), + &loaded_chain_accounts, ) { Some(validator) => validator, None => { @@ -164,10 +168,12 @@ fn run_issues_frequent_commmits_tests( manifest_dir: &str, ) -> Result> { eprintln!("======== RUNNING ISSUES TESTS - Frequent Commits ========"); + let loaded_chain_accounts = + LoadedAccounts::with_delegation_program_test_authority(); let mut devnet_validator = match start_validator( "schedulecommit-conf.devnet.toml", ValidatorCluster::Chain(None), - LoadedAccounts::with_delegation_program_test_authority(), + &loaded_chain_accounts, ) { Some(validator) => validator, None => { @@ -177,7 +183,7 @@ fn run_issues_frequent_commmits_tests( let mut ephem_validator = match start_validator( "schedulecommit-conf.ephem.frequent-commits.toml", ValidatorCluster::Ephem, - LoadedAccounts::with_delegation_program_test_authority(), + &loaded_chain_accounts, ) { Some(validator) => validator, None => { @@ -208,10 +214,13 @@ fn run_issues_frequent_commmits_tests( fn run_cloning_tests(manifest_dir: &str) -> Result> { eprintln!("======== RUNNING CLONING TESTS ========"); + let loaded_chain_accounts = + LoadedAccounts::with_delegation_program_test_authority(); + let mut devnet_validator = match start_validator( "cloning-conf.devnet.toml", ValidatorCluster::Chain(Some(ProgramLoader::BpfProgram)), - LoadedAccounts::with_delegation_program_test_authority(), + &loaded_chain_accounts, ) { Some(validator) => validator, None => { @@ -221,7 +230,7 @@ fn run_cloning_tests(manifest_dir: &str) -> Result> { let mut ephem_validator = match start_validator( "cloning-conf.ephem.toml", ValidatorCluster::Ephem, - LoadedAccounts::with_delegation_program_test_authority(), + &loaded_chain_accounts, ) { Some(validator) => validator, None => { @@ -340,7 +349,7 @@ impl ValidatorCluster { fn start_validator( config_file: &str, cluster: ValidatorCluster, - loaded_chain_accounts: LoadedAccounts, + loaded_chain_accounts: &LoadedAccounts, ) -> Option { let log_suffix = cluster.log_suffix(); let test_runner_paths = resolve_paths(config_file); @@ -352,14 +361,14 @@ fn start_validator( start_test_validator_with_config( &test_runner_paths, program_loader, - &loaded_chain_accounts, + loaded_chain_accounts, log_suffix, ) } _ => start_magic_block_validator_with_config( &test_runner_paths, log_suffix, - &loaded_chain_accounts, + loaded_chain_accounts, false, ), } diff --git a/test-integration/test-tools/src/integration_test_context.rs b/test-integration/test-tools/src/integration_test_context.rs index 4afd9ccc8..a6efa7c29 100644 --- a/test-integration/test-tools/src/integration_test_context.rs +++ b/test-integration/test-tools/src/integration_test_context.rs @@ -450,7 +450,7 @@ impl IntegrationTestContext { const MILLIS_UNTIL_RETRY: u64 = 200; let mut failure_count = 0; - // Allow transactions to take up to 20 seconds to confirm + // Allow transactions to take up to 40 seconds to confirm const MAX_UNCONFIRMED_COUNT: u64 = 40; const MILLIS_UNTIL_RECONFIRM: u64 = 500; let mut unconfirmed_count = 0; From 47ccee42ecdc01aec7a1552ab03494745e0b3190 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 14:10:23 +0545 Subject: [PATCH 031/199] ix: update dlp binary --- test-integration/schedulecommit/elfs/dlp.so | Bin 351544 -> 321056 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/test-integration/schedulecommit/elfs/dlp.so b/test-integration/schedulecommit/elfs/dlp.so index 8de09c66e427ee2806426b75b5ea5094c29ab7fa..71a5dd1efcde0c3e06963ed7a27e5760694b5c27 100755 GIT binary patch literal 321056 zcmeFadwg9-buYeU=fqBU$gy*5M;Bo!j$=hdMRs0}NVtNHN}cT z;_(I|I}jZIxZs2kOn$W0k^GP;y>)>$ZZECe{(4(Op>?4T18uJ+&3et6HM3_wbmJ>-n%2~m_%%KGc7oKvFHO^|UVCuj zi|5&|BNSEU{Q-W3c0TEAnxPNoOGl=&NU})o zZ?c@^(7q+2MT-eCC`=lN&kN^h|C&qJvs zDJB1M2KS+5OviB0=X!8{P#4bsA)M<_D@kHF=wCfJ->(bj?+K@yREgn$WA)&CuP&Uw zBAlzq=NJy;tsb23)`jzDgmV>YNxfBDl#eky$VEMP->D1l4-Fn_0p5lhc#w>G@cy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D$kyjqYrZh+71_LlclT)h&a9_l>+^Fz-{c;Q2a?>pXu_PD=z`Qn93ciw&B(!Gn5{V_OAAH3&efAOBXZeLuuFFjTt z??!v9xp!_d_w@hT=HEi+xA`%ex8>=trQh1S|8RQVr|H?>hpkt~cjhKnnh)4}$JqVf zzsUq<=PFO`&os9`eRPkXH!}{+?!(t=gZXoFetXLi^SRshzWKYS-PfkrUY~7m&*KM= z`TY4ieRdqzi8bx*e!gGLyv^LU1ViT2 From c85b52979fe393fe02777c3fedee198a82c69962 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 14:10:43 +0545 Subject: [PATCH 032/199] ix: add committor tests to run_tests --- test-integration/test-runner/bin/run_tests.rs | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index bfc450092..f50306954 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -18,13 +18,15 @@ use test_runner::cleanup::{cleanup_devnet_only, cleanup_validators}; pub fn main() { let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let Ok(committor_output) = run_committor_tests(&manifest_dir) else { + // If any test run panics (i.e. not just a failing test) then we bail + return; + }; let Ok((security_output, scenarios_output)) = run_schedule_commit_tests(&manifest_dir) else { - // If any test fails or cannot run we bail immediately return; }; - let Ok(issues_frequent_commits_output) = run_issues_frequent_commmits_tests(&manifest_dir) else { @@ -45,6 +47,7 @@ pub fn main() { }; // Assert that all tests passed + assert_cargo_tests_passed(committor_output); assert_cargo_tests_passed(security_output); assert_cargo_tests_passed(scenarios_output); assert_cargo_tests_passed(cloning_output); @@ -92,6 +95,41 @@ fn run_restore_ledger_tests( Ok(output) } +fn run_committor_tests(manifest_dir: &str) -> Result> { + eprintln!("======== Starting DEVNET Validator for Committor ========"); + + let loaded_chain_accounts = + LoadedAccounts::with_delegation_program_test_authority(); + + let mut devnet_validator = match start_validator( + "committor-conf.devnet.toml", + ValidatorCluster::Chain(None), + &loaded_chain_accounts, + ) { + Some(validator) => validator, + None => { + panic!("Failed to start devnet validator properly"); + } + }; + + // NOTE: the committor tests run directly against a chain validator + // therefore no ephemeral validator needs to be started + + let test_committor_dir = + format!("{}/../{}", manifest_dir, "schedulecommit/committor-service"); + eprintln!("Running committor tests in {}", test_committor_dir); + let test_output = match run_test(test_committor_dir, Default::default()) { + Ok(output) => output, + Err(err) => { + eprintln!("Failed to run committor: {:?}", err); + cleanup_devnet_only(&mut devnet_validator); + return Err(err.into()); + } + }; + cleanup_devnet_only(&mut devnet_validator); + Ok(test_output) +} + fn run_schedule_commit_tests( manifest_dir: &str, ) -> Result<(Output, Output), Box> { From cf609d48cbcec2f0285efb07aa1f3673d0629336 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 14:54:01 +0545 Subject: [PATCH 033/199] ix: move table mania tests to integration --- Cargo.lock | 2 -- magicblock-table-mania/Cargo.toml | 6 ----- test-integration/Cargo.lock | 15 ++++++++++++ test-integration/Cargo.toml | 5 +++- test-integration/test-table-mania/Cargo.toml | 21 +++++++++++++++++ test-integration/test-table-mania/src/lib.rs | 2 ++ .../tests/ix_lookup_table.rs | 3 ++- .../tests/ix_release_pubkeys.rs | 5 ++-- .../tests/ix_reserve_pubkeys.rs | 5 ++-- .../test-table-mania}/tests/utils/mod.rs | 23 ++++--------------- 10 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 test-integration/test-table-mania/Cargo.toml create mode 100644 test-integration/test-table-mania/src/lib.rs rename {magicblock-table-mania => test-integration/test-table-mania}/tests/ix_lookup_table.rs (98%) rename {magicblock-table-mania => test-integration/test-table-mania}/tests/ix_release_pubkeys.rs (97%) rename {magicblock-table-mania => test-integration/test-table-mania}/tests/ix_reserve_pubkeys.rs (98%) rename {magicblock-table-mania => test-integration/test-table-mania}/tests/utils/mod.rs (88%) diff --git a/Cargo.lock b/Cargo.lock index c7baa0bd5..634cfec23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4056,10 +4056,8 @@ name = "magicblock-table-mania" version = "0.1.1" dependencies = [ "ed25519-dalek", - "env_logger 0.11.6", "log", "magicblock-rpc-client", - "paste", "rand 0.8.5", "sha3", "solana-pubkey", diff --git a/magicblock-table-mania/Cargo.toml b/magicblock-table-mania/Cargo.toml index c9866425c..5767af61e 100644 --- a/magicblock-table-mania/Cargo.toml +++ b/magicblock-table-mania/Cargo.toml @@ -20,14 +20,8 @@ solana-sdk = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true } -[dev-dependencies] -env_logger = { workspace = true } -paste = { workspace = true } -tokio = { workspace = true, features = ["rt", "macros"] } - [features] default = [] -test_table_close = [] # Needed to allow multiple tests to run in parallel without trying to # use the same lookup table address randomize_lookup_table_slot = [] diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index b030e9d65..2c6e18693 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -10118,6 +10118,21 @@ dependencies = [ "teepee", ] +[[package]] +name = "test-table-mania" +version = "0.0.0" +dependencies = [ + "log", + "magicblock-rpc-client", + "magicblock-table-mania", + "paste", + "solana-pubkey", + "solana-rpc-client", + "solana-sdk", + "test-tools-core", + "tokio", +] + [[package]] name = "test-tools-core" version = "0.1.1" diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index f20c8b988..4c8d6dc47 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -11,9 +11,10 @@ members = [ "test-cloning", "test-issues", "test-ledger-restore", + "test-magicblock-api", "test-runner", + "test-table-mania", "test-tools", - "test-magicblock-api", ] resolver = "2" @@ -41,6 +42,8 @@ magicblock-committor-program = { path = "../magicblock-committor-program", featu magicblock-delegation-program = { path = "../../delegation-program" } magicblock-committor-service = { path = "../magicblock-committor-service" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } +magicblock-table-mania = { path = "../magicblock-table-mania" } +paste = "1.0" program-flexi-counter = { path = "./programs/flexi-counter" } program-schedulecommit = { path = "programs/schedulecommit" } program-schedulecommit-security = { path = "programs/schedulecommit-security" } diff --git a/test-integration/test-table-mania/Cargo.toml b/test-integration/test-table-mania/Cargo.toml new file mode 100644 index 000000000..3d16007e8 --- /dev/null +++ b/test-integration/test-table-mania/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "test-table-mania" +version.workspace = true +edition.workspace = true + +[dev-dependencies] +log = { workspace = true } +magicblock-rpc-client = { workspace = true } +magicblock-table-mania = { workspace = true, features = [ + "randomize_lookup_table_slot", +] } +paste = { workspace = true } +solana-pubkey = { workspace = true } +solana-rpc-client = { workspace = true } +solana-sdk = { workspace = true } +test-tools-core = { workspace = true } +tokio = { workspace = true } + +[features] +default = [] +test_table_close = [] diff --git a/test-integration/test-table-mania/src/lib.rs b/test-integration/test-table-mania/src/lib.rs new file mode 100644 index 000000000..10f55cb13 --- /dev/null +++ b/test-integration/test-table-mania/src/lib.rs @@ -0,0 +1,2 @@ +#[allow(unused)] +pub const HELLO: &str = "world"; diff --git a/magicblock-table-mania/tests/ix_lookup_table.rs b/test-integration/test-table-mania/tests/ix_lookup_table.rs similarity index 98% rename from magicblock-table-mania/tests/ix_lookup_table.rs rename to test-integration/test-table-mania/tests/ix_lookup_table.rs index 8511491d7..5bec6e2c5 100644 --- a/magicblock-table-mania/tests/ix_lookup_table.rs +++ b/test-integration/test-table-mania/tests/ix_lookup_table.rs @@ -9,6 +9,7 @@ use solana_sdk::{ commitment_config::CommitmentConfig, native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, }; +use test_tools_core::init_logger; mod utils; @@ -80,7 +81,7 @@ async fn get_open_tables( #[tokio::test] async fn test_create_fetch_and_close_lookup_table() { - utils::init_logger(); + init_logger!(); let validator_auth = Keypair::new(); let pubkeys = vec![0; 10] diff --git a/magicblock-table-mania/tests/ix_release_pubkeys.rs b/test-integration/test-table-mania/tests/ix_release_pubkeys.rs similarity index 97% rename from magicblock-table-mania/tests/ix_release_pubkeys.rs rename to test-integration/test-table-mania/tests/ix_release_pubkeys.rs index 33fc27f0f..dedcbd815 100644 --- a/magicblock-table-mania/tests/ix_release_pubkeys.rs +++ b/test-integration/test-table-mania/tests/ix_release_pubkeys.rs @@ -2,11 +2,12 @@ use std::collections::HashSet; use solana_pubkey::Pubkey; use solana_sdk::signature::Keypair; +use test_tools_core::init_logger; mod utils; #[tokio::test] async fn test_single_table_two_requests_with_overlapping_pubkeys() { - utils::init_logger(); + init_logger!(); let authority = Keypair::new(); let table_mania = utils::setup_table_mania(&authority).await; @@ -50,7 +51,7 @@ async fn test_single_table_two_requests_with_overlapping_pubkeys() { #[tokio::test] async fn test_two_table_three_requests_with_one_overlapping_pubkey() { - utils::init_logger(); + init_logger!(); let authority = Keypair::new(); let table_mania = utils::setup_table_mania(&authority).await; diff --git a/magicblock-table-mania/tests/ix_reserve_pubkeys.rs b/test-integration/test-table-mania/tests/ix_reserve_pubkeys.rs similarity index 98% rename from magicblock-table-mania/tests/ix_reserve_pubkeys.rs rename to test-integration/test-table-mania/tests/ix_reserve_pubkeys.rs index 94d35f940..47ededfb9 100644 --- a/magicblock-table-mania/tests/ix_reserve_pubkeys.rs +++ b/test-integration/test-table-mania/tests/ix_reserve_pubkeys.rs @@ -5,6 +5,7 @@ use solana_pubkey::Pubkey; use solana_sdk::{ address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES, signature::Keypair, }; +use test_tools_core::init_logger; use tokio::task::JoinSet; mod utils; @@ -29,7 +30,7 @@ reserve_pubkeys_in_one_table!(100); reserve_pubkeys_in_one_table!(256); async fn reserve_pubkeys_in_one_table_in_chunks(chunk_size: usize) { - utils::init_logger(); + init_logger!(); let authority = Keypair::new(); let mut pubkeys = (0..LOOKUP_TABLE_MAX_ADDRESSES) @@ -90,7 +91,7 @@ async fn reserve_pubkeys_in_multiple_tables_in_chunks( amount: usize, chunk_size: usize, ) { - utils::init_logger(); + init_logger!(); let authority = Keypair::new(); let pubkeys = (0..amount) diff --git a/magicblock-table-mania/tests/utils/mod.rs b/test-integration/test-table-mania/tests/utils/mod.rs similarity index 88% rename from magicblock-table-mania/tests/utils/mod.rs rename to test-integration/test-table-mania/tests/utils/mod.rs index 385b2068a..8ddd08c9e 100644 --- a/magicblock-table-mania/tests/utils/mod.rs +++ b/test-integration/test-table-mania/tests/utils/mod.rs @@ -1,5 +1,3 @@ -#![allow(dead_code)] - use log::*; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; @@ -10,29 +8,14 @@ use solana_sdk::signature::Keypair; use solana_sdk::signer::Signer; use std::time::{Duration, Instant}; +#[allow(unused)] // used in tests pub const TEST_TABLE_CLOSE: bool = cfg!(feature = "test_table_close"); pub async fn sleep_millis(millis: u64) { tokio::time::sleep(tokio::time::Duration::from_millis(millis)).await; } -pub fn init_logger_file_path() { - let _ = env_logger::builder() - .format_timestamp(None) - .format_module_path(false) - .format_target(false) - .format_source_path(true) - .is_test(true) - .try_init(); -} - -pub fn init_logger() { - let _ = env_logger::builder() - .format_timestamp(None) - .is_test(true) - .try_init(); -} - +#[allow(unused)] // used in tests pub async fn setup_table_mania(validator_auth: &Keypair) -> TableMania { let rpc_client = { let client = RpcClient::new_with_commitment( @@ -57,6 +40,7 @@ pub async fn setup_table_mania(validator_auth: &Keypair) -> TableMania { } } +#[allow(unused)] // used in tests pub async fn close_released_tables(table_mania: &TableMania) { if TEST_TABLE_CLOSE { // Tables deactivate after ~2.5 mins (150secs), but most times @@ -102,6 +86,7 @@ pub async fn close_released_tables(table_mania: &TableMania) { } } +#[allow(unused)] // used in tests pub async fn log_active_table_addresses(table_mania: &TableMania) { debug!( "Active Tables: {}", From b968ea5797808004b00949762afb2da430aaf51c Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 15:00:29 +0545 Subject: [PATCH 034/199] ix: run table mania as part of test suite --- test-integration/test-runner/bin/run_tests.rs | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index f50306954..c8caed449 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -18,7 +18,9 @@ use test_runner::cleanup::{cleanup_devnet_only, cleanup_validators}; pub fn main() { let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let Ok(committor_output) = run_committor_tests(&manifest_dir) else { + let Ok((table_mania_output, committor_output)) = + run_table_mania_and_committor_tests(&manifest_dir) + else { // If any test run panics (i.e. not just a failing test) then we bail return; }; @@ -47,6 +49,7 @@ pub fn main() { }; // Assert that all tests passed + assert_cargo_tests_passed(table_mania_output); assert_cargo_tests_passed(committor_output); assert_cargo_tests_passed(security_output); assert_cargo_tests_passed(scenarios_output); @@ -95,8 +98,10 @@ fn run_restore_ledger_tests( Ok(output) } -fn run_committor_tests(manifest_dir: &str) -> Result> { - eprintln!("======== Starting DEVNET Validator for Committor ========"); +fn run_table_mania_and_committor_tests( + manifest_dir: &str, +) -> Result<(Output, Output), Box> { + eprintln!("======== Starting DEVNET Validator for TableMania and Committor ========"); let loaded_chain_accounts = LoadedAccounts::with_delegation_program_test_authority(); @@ -112,22 +117,36 @@ fn run_committor_tests(manifest_dir: &str) -> Result> { } }; - // NOTE: the committor tests run directly against a chain validator - // therefore no ephemeral validator needs to be started + // NOTE: the table mania and committor tests run directly against + // a chain validator therefore no ephemeral validator needs to be started + + let test_table_mania_dir = + format!("{}/../{}", manifest_dir, "test-table-mania"); + let table_mania_test_output = + match run_test(test_table_mania_dir, Default::default()) { + Ok(output) => output, + Err(err) => { + eprintln!("Failed to run table-mania: {:?}", err); + cleanup_devnet_only(&mut devnet_validator); + return Err(err.into()); + } + }; let test_committor_dir = format!("{}/../{}", manifest_dir, "schedulecommit/committor-service"); eprintln!("Running committor tests in {}", test_committor_dir); - let test_output = match run_test(test_committor_dir, Default::default()) { - Ok(output) => output, - Err(err) => { - eprintln!("Failed to run committor: {:?}", err); - cleanup_devnet_only(&mut devnet_validator); - return Err(err.into()); - } - }; + let committor_test_output = + match run_test(test_committor_dir, Default::default()) { + Ok(output) => output, + Err(err) => { + eprintln!("Failed to run committor: {:?}", err); + cleanup_devnet_only(&mut devnet_validator); + return Err(err.into()); + } + }; cleanup_devnet_only(&mut devnet_validator); - Ok(test_output) + + Ok((table_mania_test_output, committor_test_output)) } fn run_schedule_commit_tests( From 7bde5967bf35a31f02b41d8f27d7fd9eca3f2712 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 15:18:33 +0545 Subject: [PATCH 035/199] chore: fmt --- .../src/remote_scheduled_commits_processor.rs | 17 +++---- magicblock-accounts/tests/ensure_accounts.rs | 2 +- magicblock-committor-program/src/error.rs | 3 +- .../src/instruction.rs | 9 ++-- .../src/instruction_chunks.rs | 7 +-- magicblock-committor-program/src/lib.rs | 1 - magicblock-committor-program/src/processor.rs | 27 ++++++----- .../src/state/changeset_chunks.rs | 3 +- .../src/state/chunks.rs | 3 +- .../src/utils/account.rs | 7 +-- .../src/utils/asserts.rs | 3 +- magicblock-committor-service/src/bundles.rs | 10 ++-- .../src/commit/commit_using_args.rs | 24 ++++------ .../src/commit/commit_using_buffer.rs | 37 +++++++-------- .../src/commit/committor_processor.rs | 47 +++++++++---------- .../src/commit/common.rs | 19 ++++---- .../src/commit_stage.rs | 5 +- .../src/commit_strategy.rs | 3 +- magicblock-committor-service/src/error.rs | 3 +- magicblock-committor-service/src/lib.rs | 5 +- .../src/persist/commit_persister.rs | 26 +++++----- .../src/persist/types/commit_status.rs | 3 +- .../src/pubkeys_provider.rs | 2 +- magicblock-committor-service/src/service.rs | 3 +- .../src/stubs/changeset_committor_stub.rs | 2 +- .../src/transactions.rs | 28 +++++------ magicblock-rpc-client/src/lib.rs | 4 +- magicblock-table-mania/src/lookup_table.rs | 26 +++++----- magicblock-table-mania/src/lookup_table_rc.rs | 22 ++++----- magicblock-table-mania/src/manager.rs | 2 +- 30 files changed, 180 insertions(+), 173 deletions(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 002a44d42..6727009e7 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -1,28 +1,29 @@ -use async_trait::async_trait; -use conjunto_transwise::AccountChainSnapshot; -use log::*; -use magicblock_bank::bank::Bank; -use magicblock_processor::execute_transaction::execute_legacy_transaction; -use magicblock_transaction_status::TransactionStatusSender; -use solana_sdk::hash::Hash; -use solana_sdk::{account::ReadableAccount, transaction::Transaction}; use std::{ collections::{HashMap, HashSet}, sync::Arc, }; +use async_trait::async_trait; +use conjunto_transwise::AccountChainSnapshot; +use log::*; use magicblock_account_cloner::{ AccountClonerOutput, AccountClonerOutput::Cloned, CloneOutputMap, }; use magicblock_accounts_api::InternalAccountProvider; +use magicblock_bank::bank::Bank; use magicblock_committor_service::{ persist::BundleSignatureRow, ChangedAccount, Changeset, ChangesetCommittor, ChangesetMeta, }; +use magicblock_processor::execute_transaction::execute_legacy_transaction; use magicblock_program::{ register_scheduled_commit_sent, FeePayerAccount, Pubkey, SentCommit, TransactionScheduler, }; +use magicblock_transaction_status::TransactionStatusSender; +use solana_sdk::{ + account::ReadableAccount, hash::Hash, transaction::Transaction, +}; use crate::{ errors::AccountsResult, AccountCommittee, ScheduledCommitsProcessor, diff --git a/magicblock-accounts/tests/ensure_accounts.rs b/magicblock-accounts/tests/ensure_accounts.rs index 036e10728..38ee4c541 100644 --- a/magicblock-accounts/tests/ensure_accounts.rs +++ b/magicblock-accounts/tests/ensure_accounts.rs @@ -1,4 +1,3 @@ -use log::*; use std::{collections::HashSet, sync::Arc}; use conjunto_transwise::{ @@ -6,6 +5,7 @@ use conjunto_transwise::{ transaction_accounts_holder::TransactionAccountsHolder, transaction_accounts_validator::TransactionAccountsValidatorImpl, }; +use log::*; use magicblock_account_cloner::{ AccountCloner, RemoteAccountClonerClient, RemoteAccountClonerWorker, ValidatorCollectionMode, diff --git a/magicblock-committor-program/src/error.rs b/magicblock-committor-program/src/error.rs index 35e7156d3..d201ae9da 100644 --- a/magicblock-committor-program/src/error.rs +++ b/magicblock-committor-program/src/error.rs @@ -1,5 +1,4 @@ -use solana_program::msg; -use solana_program::program_error::ProgramError; +use solana_program::{msg, program_error::ProgramError}; use thiserror::Error; pub type CommittorResult = std::result::Result; diff --git a/magicblock-committor-program/src/instruction.rs b/magicblock-committor-program/src/instruction.rs index 8ce2e7c78..b6bf1e28c 100644 --- a/magicblock-committor-program/src/instruction.rs +++ b/magicblock-committor-program/src/instruction.rs @@ -1,8 +1,9 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use solana_program::hash::Hash; -use solana_program::hash::HASH_BYTES; -use solana_program::instruction::{AccountMeta, Instruction}; -use solana_program::system_program; +use solana_program::{ + hash::{Hash, HASH_BYTES}, + instruction::{AccountMeta, Instruction}, + system_program, +}; use solana_pubkey::Pubkey; use crate::{consts, pdas}; diff --git a/magicblock-committor-program/src/instruction_chunks.rs b/magicblock-committor-program/src/instruction_chunks.rs index a726f5e33..fe4622f45 100644 --- a/magicblock-committor-program/src/instruction_chunks.rs +++ b/magicblock-committor-program/src/instruction_chunks.rs @@ -1,6 +1,7 @@ -use crate::instruction::{IX_INIT_SIZE, IX_REALLOC_SIZE}; - -use crate::consts::MAX_INSTRUCTION_DATA_SIZE; +use crate::{ + consts::MAX_INSTRUCTION_DATA_SIZE, + instruction::{IX_INIT_SIZE, IX_REALLOC_SIZE}, +}; /// Creates chunks of realloc instructions such that each chunk fits into a single transaction. /// - reallocs: The realloc instructions to split up diff --git a/magicblock-committor-program/src/lib.rs b/magicblock-committor-program/src/lib.rs index 831bc7935..eb0d51250 100644 --- a/magicblock-committor-program/src/lib.rs +++ b/magicblock-committor-program/src/lib.rs @@ -13,7 +13,6 @@ mod utils; mod processor; // #[cfg(not(feature = "no-entrypoint"))] pub use processor::process; - pub use state::{ changeset::{ ChangedAccount, ChangedAccountMeta, ChangedBundle, Changeset, diff --git a/magicblock-committor-program/src/processor.rs b/magicblock-committor-program/src/processor.rs index db1455ee2..e1068b60d 100644 --- a/magicblock-committor-program/src/processor.rs +++ b/magicblock-committor-program/src/processor.rs @@ -1,20 +1,21 @@ use borsh::{to_vec, BorshDeserialize}; -use solana_program::hash::Hash; -use solana_program::log::sol_log_64; -use solana_program::program::invoke_signed; -use solana_program::program_error::ProgramError; -use solana_program::sysvar::Sysvar; -use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult}; -use solana_program::{msg, system_instruction}; +use solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, hash::Hash, + log::sol_log_64, msg, program::invoke_signed, program_error::ProgramError, + system_instruction, sysvar::Sysvar, +}; use solana_pubkey::Pubkey; -use crate::error::CommittorError; -use crate::instruction::CommittorInstruction; -use crate::utils::{ - assert_account_unallocated, assert_is_signer, assert_program_id, - close_and_refund_authority, +use crate::{ + consts, + error::CommittorError, + instruction::CommittorInstruction, + utils::{ + assert_account_unallocated, assert_is_signer, assert_program_id, + close_and_refund_authority, + }, + verified_seeds_and_pda, Chunks, }; -use crate::{consts, verified_seeds_and_pda, Chunks}; pub fn process( program_id: &Pubkey, diff --git a/magicblock-committor-program/src/state/changeset_chunks.rs b/magicblock-committor-program/src/state/changeset_chunks.rs index 990f366c0..d1e3333b6 100644 --- a/magicblock-committor-program/src/state/changeset_chunks.rs +++ b/magicblock-committor-program/src/state/changeset_chunks.rs @@ -1,8 +1,9 @@ use std::collections::HashSet; -use super::chunks::Chunks; use borsh::{BorshDeserialize, BorshSerialize}; +use super::chunks::Chunks; + /// A chunk of change set data that we want to apply to the on chain /// [ChangeSet] buffer #[derive(Debug, Default, BorshSerialize, BorshDeserialize)] diff --git a/magicblock-committor-program/src/state/chunks.rs b/magicblock-committor-program/src/state/chunks.rs index b68c2a26a..06b3e3a69 100644 --- a/magicblock-committor-program/src/state/chunks.rs +++ b/magicblock-committor-program/src/state/chunks.rs @@ -1,6 +1,7 @@ -use borsh::{BorshDeserialize, BorshSerialize}; use std::{collections::HashSet, fmt}; +use borsh::{BorshDeserialize, BorshSerialize}; + use crate::{ consts, error::{CommittorError, CommittorResult}, diff --git a/magicblock-committor-program/src/utils/account.rs b/magicblock-committor-program/src/utils/account.rs index e794106f1..cdae0e96f 100644 --- a/magicblock-committor-program/src/utils/account.rs +++ b/magicblock-committor-program/src/utils/account.rs @@ -1,6 +1,7 @@ -use solana_program::msg; -use solana_program::program_error::ProgramError; -use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult}; +use solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, msg, + program_error::ProgramError, +}; pub fn close_and_refund_authority( authority: &AccountInfo, diff --git a/magicblock-committor-program/src/utils/asserts.rs b/magicblock-committor-program/src/utils/asserts.rs index 838d139b3..b83c21f05 100644 --- a/magicblock-committor-program/src/utils/asserts.rs +++ b/magicblock-committor-program/src/utils/asserts.rs @@ -1,7 +1,6 @@ -use solana_program::pubkey::Pubkey; use solana_program::{ account_info::AccountInfo, entrypoint::ProgramResult, msg, - program_error::ProgramError, + program_error::ProgramError, pubkey::Pubkey, }; pub fn assert_keys_equal String>( diff --git a/magicblock-committor-service/src/bundles.rs b/magicblock-committor-service/src/bundles.rs index a030842f8..086163df4 100644 --- a/magicblock-committor-service/src/bundles.rs +++ b/magicblock-committor-service/src/bundles.rs @@ -1,6 +1,7 @@ -use crate::{bundle_strategy::efficient_bundle_chunks, CommitInfo}; use std::collections::HashMap; +use crate::{bundle_strategy::efficient_bundle_chunks, CommitInfo}; + #[derive(Debug, Default)] pub struct BundleChunksResult { /// The valid chunks @@ -94,11 +95,12 @@ pub(crate) fn bundle_chunks_ignoring_bundle_id( #[cfg(test)] mod test { - use super::*; - use solana_sdk::hash::Hash; - use solana_sdk::pubkey::Pubkey; use std::collections::HashSet; + use solana_sdk::{hash::Hash, pubkey::Pubkey}; + + use super::*; + fn commit_info(bundle_id: u64) -> crate::CommitInfo { CommitInfo::BufferedDataAccount { pubkey: Pubkey::new_unique(), diff --git a/magicblock-committor-service/src/commit/commit_using_args.rs b/magicblock-committor-service/src/commit/commit_using_args.rs index 525eb5314..eb6dba196 100644 --- a/magicblock-committor-service/src/commit/commit_using_args.rs +++ b/magicblock-committor-service/src/commit/commit_using_args.rs @@ -1,26 +1,22 @@ +use std::{collections::HashSet, sync::Arc}; + +use dlp::args::CommitStateArgs; +use log::*; +use magicblock_committor_program::Changeset; +use magicblock_rpc_client::MagicBlockSendTransactionConfig; +use solana_sdk::{hash::Hash, signer::Signer}; + +use super::CommittorProcessor; use crate::{ commit::common::{ get_accounts_to_undelegate, lookup_table_keys, send_and_confirm, }, - commit_stage::CommitSignatures, + commit_stage::{CommitSignatures, CommitStage}, persist::CommitStrategy, undelegate::undelegate_commitables_ixs, CommitInfo, }; -use dlp::args::CommitStateArgs; -use log::*; -use solana_sdk::hash::Hash; -use std::{collections::HashSet, sync::Arc}; - -use magicblock_committor_program::Changeset; -use solana_sdk::signer::Signer; - -use crate::commit_stage::CommitStage; -use magicblock_rpc_client::MagicBlockSendTransactionConfig; - -use super::CommittorProcessor; - impl CommittorProcessor { /// Commits a changeset directly using args to include the commit state /// - **changeset**: the changeset to commit diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs index 4d99ff99d..e33a3f7fe 100644 --- a/magicblock-committor-service/src/commit/commit_using_buffer.rs +++ b/magicblock-committor-service/src/commit/commit_using_buffer.rs @@ -1,18 +1,12 @@ -use borsh::{to_vec, BorshDeserialize}; -use dlp::pda::commit_state_pda_from_delegated_account; -use log::*; -use magicblock_rpc_client::{ - MagicBlockRpcClientError, MagicBlockRpcClientResult, - MagicBlockSendTransactionConfig, -}; -use solana_pubkey::Pubkey; use std::{ collections::{HashMap, HashSet}, sync::Arc, time::Duration, }; -use tokio::task::JoinSet; +use borsh::{to_vec, BorshDeserialize}; +use dlp::pda::commit_state_pda_from_delegated_account; +use log::*; use magicblock_committor_program::{ instruction::{ create_init_ix, create_realloc_buffer_ixs, @@ -22,7 +16,22 @@ use magicblock_committor_program::{ instruction_chunks::chunk_realloc_ixs, Changeset, ChangesetChunk, Chunks, CommitableAccount, }; +use magicblock_rpc_client::{ + MagicBlockRpcClientError, MagicBlockRpcClientResult, + MagicBlockSendTransactionConfig, +}; +use solana_pubkey::Pubkey; +use solana_sdk::{hash::Hash, instruction::Instruction, signer::Signer}; +use tokio::task::JoinSet; +use super::{ + common::send_and_confirm, + process_buffers::{ + chunked_ixs_to_process_commitables_and_close_pdas, + ChunkedIxsToProcessCommitablesAndClosePdasResult, + }, + CommittorProcessor, +}; use crate::{ commit::common::get_accounts_to_undelegate, commit_stage::CommitSignatures, @@ -39,16 +48,6 @@ use crate::{ CommitInfo, CommitStage, }; -use super::{ - common::send_and_confirm, - process_buffers::{ - chunked_ixs_to_process_commitables_and_close_pdas, - ChunkedIxsToProcessCommitablesAndClosePdasResult, - }, - CommittorProcessor, -}; -use solana_sdk::{hash::Hash, instruction::Instruction, signer::Signer}; - struct NextReallocs { missing_size: u64, start_idx: usize, diff --git a/magicblock-committor-service/src/commit/committor_processor.rs b/magicblock-committor-service/src/commit/committor_processor.rs index 3e6ea0ab2..0db9171b2 100644 --- a/magicblock-committor-service/src/commit/committor_processor.rs +++ b/magicblock-committor-service/src/commit/committor_processor.rs @@ -1,41 +1,40 @@ -use crate::{ - commit_strategy::{split_changesets_by_commit_strategy, SplitChangesets}, - compute_budget::{ComputeBudget, ComputeBudgetConfig}, - persist::{ - BundleSignatureRow, CommitPersister, CommitStatusRow, CommitStrategy, - }, - pubkeys_provider::provide_committee_pubkeys, - types::InstructionsKind, - CommitInfo, -}; - -use log::*; -use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; -use solana_sdk::{ - commitment_config::CommitmentConfig, hash::Hash, signature::Signature, -}; use std::{ collections::{HashMap, HashSet}, path::Path, sync::{Arc, Mutex}, }; +use log::*; use magicblock_committor_program::{Changeset, ChangesetMeta}; +use magicblock_rpc_client::{ + MagicBlockSendTransactionConfig, MagicblockRpcClient, +}; +use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; use solana_pubkey::Pubkey; use solana_rpc_client::nonblocking::rpc_client::RpcClient; -use solana_sdk::{signature::Keypair, signer::Signer}; +use solana_sdk::{ + commitment_config::CommitmentConfig, + hash::Hash, + signature::{Keypair, Signature}, + signer::Signer, +}; use tokio::task::JoinSet; +use super::common::{lookup_table_keys, send_and_confirm}; use crate::{ - commit_stage::CommitStage, config::ChainConfig, - error::CommittorServiceResult, types::InstructionsForCommitable, -}; -use magicblock_rpc_client::{ - MagicBlockSendTransactionConfig, MagicblockRpcClient, + commit_stage::CommitStage, + commit_strategy::{split_changesets_by_commit_strategy, SplitChangesets}, + compute_budget::{ComputeBudget, ComputeBudgetConfig}, + config::ChainConfig, + error::CommittorServiceResult, + persist::{ + BundleSignatureRow, CommitPersister, CommitStatusRow, CommitStrategy, + }, + pubkeys_provider::provide_committee_pubkeys, + types::{InstructionsForCommitable, InstructionsKind}, + CommitInfo, }; -use super::common::{lookup_table_keys, send_and_confirm}; - pub(crate) struct CommittorProcessor { pub(crate) magicblock_rpc_client: MagicblockRpcClient, pub(crate) table_mania: TableMania, diff --git a/magicblock-committor-service/src/commit/common.rs b/magicblock-committor-service/src/commit/common.rs index c1e4317cb..ebfa0a1a1 100644 --- a/magicblock-committor-service/src/commit/common.rs +++ b/magicblock-committor-service/src/commit/common.rs @@ -1,19 +1,22 @@ -use log::*; -use magicblock_rpc_client::{ - MagicBlockSendTransactionConfig, MagicblockRpcClient, -}; -use magicblock_table_mania::TableMania; -use solana_sdk::{hash::Hash, message::v0::Message, signature::Signature}; use std::{ collections::{HashMap, HashSet}, time::{Duration, Instant}, }; +use log::*; use magicblock_committor_program::Changeset; +use magicblock_rpc_client::{ + MagicBlockSendTransactionConfig, MagicblockRpcClient, +}; +use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; use solana_sdk::{ - instruction::Instruction, message::VersionedMessage, signature::Keypair, - signer::Signer, transaction::VersionedTransaction, + hash::Hash, + instruction::Instruction, + message::{v0::Message, VersionedMessage}, + signature::{Keypair, Signature}, + signer::Signer, + transaction::VersionedTransaction, }; use crate::{ diff --git a/magicblock-committor-service/src/commit_stage.rs b/magicblock-committor-service/src/commit_stage.rs index fe8299c7f..66a5e8587 100644 --- a/magicblock-committor-service/src/commit_stage.rs +++ b/magicblock-committor-service/src/commit_stage.rs @@ -1,3 +1,6 @@ +use std::sync::Arc; + +use log::*; use magicblock_committor_program::ChangedAccountMeta; use solana_pubkey::Pubkey; use solana_sdk::{clock::Slot, signature::Signature}; @@ -7,8 +10,6 @@ use crate::{ persist::{CommitStatus, CommitStatusSignatures, CommitStrategy}, CommitInfo, }; -use log::*; -use std::sync::Arc; #[derive(Debug, Clone)] pub struct CommitSignatures { diff --git a/magicblock-committor-service/src/commit_strategy.rs b/magicblock-committor-service/src/commit_strategy.rs index 32c9b7956..22ac79921 100644 --- a/magicblock-committor-service/src/commit_strategy.rs +++ b/magicblock-committor-service/src/commit_strategy.rs @@ -235,11 +235,12 @@ pub fn split_changesets_by_commit_strategy( #[cfg(test)] mod test { - use super::*; use log::*; use magicblock_committor_program::ChangedAccount; use solana_sdk::pubkey::Pubkey; + use super::*; + fn init_logger() { let _ = env_logger::builder() .format_timestamp(None) diff --git a/magicblock-committor-service/src/error.rs b/magicblock-committor-service/src/error.rs index d130cf1c3..54344a978 100644 --- a/magicblock-committor-service/src/error.rs +++ b/magicblock-committor-service/src/error.rs @@ -1,12 +1,11 @@ use std::sync::Arc; -use crate::persist::CommitStrategy; use magicblock_rpc_client::MagicBlockRpcClientError; use solana_pubkey::Pubkey; use solana_sdk::signature::Signature; use thiserror::Error; -use crate::CommitInfo; +use crate::{persist::CommitStrategy, CommitInfo}; pub type CommittorServiceResult = std::result::Result; diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 274db7056..9c0c1ad89 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -20,13 +20,12 @@ mod undelegate; pub mod stubs; pub use commit_info::CommitInfo; -pub use compute_budget::ComputeBudgetConfig; -pub use service::{ChangesetCommittor, CommittorService}; - pub use commit_stage::CommitStage; +pub use compute_budget::ComputeBudgetConfig; pub use magicblock_committor_program::{ ChangedAccount, Changeset, ChangesetMeta, }; +pub use service::{ChangesetCommittor, CommittorService}; pub fn changeset_for_slot(slot: u64) -> Changeset { Changeset { slot, diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 33ade0f29..952ea4f1e 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -1,14 +1,17 @@ -use std::path::Path; -use std::sync::atomic::{AtomicU64, Ordering}; +use std::{ + path::Path, + sync::atomic::{AtomicU64, Ordering}, +}; -use solana_sdk::hash::Hash; -use solana_sdk::pubkey::Pubkey; - -use super::db::BundleSignatureRow; -use super::error::{CommitPersistError, CommitPersistResult}; -use super::utils::now; -use super::{db::CommitStatusRow, CommitStatus, CommitType, CommittorDb}; use magicblock_committor_program::Changeset; +use solana_sdk::{hash::Hash, pubkey::Pubkey}; + +use super::{ + db::{BundleSignatureRow, CommitStatusRow}, + error::{CommitPersistError, CommitPersistResult}, + utils::now, + CommitStatus, CommitType, CommittorDb, +}; pub struct CommitPersister { db: CommittorDb, @@ -152,12 +155,13 @@ impl CommitPersister { #[cfg(test)] mod tests { - use super::*; - use crate::persist::{CommitStatusSignatures, CommitStrategy}; use magicblock_committor_program::ChangedAccount; use solana_pubkey::Pubkey; use solana_sdk::signature::Signature; + use super::*; + use crate::persist::{CommitStatusSignatures, CommitStrategy}; + #[test] fn test_start_changeset_and_update_status() { let mut persister = CommitPersister::try_new(":memory:").unwrap(); diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index 0e6c74a3c..38bcad998 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -2,9 +2,8 @@ use std::fmt; use solana_sdk::signature::Signature; -use crate::persist::error::CommitPersistError; - use super::commit_strategy::CommitStrategy; +use crate::persist::error::CommitPersistError; /// The status of a committed account. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/magicblock-committor-service/src/pubkeys_provider.rs b/magicblock-committor-service/src/pubkeys_provider.rs index 595b5af24..d7ad1472e 100644 --- a/magicblock-committor-service/src/pubkeys_provider.rs +++ b/magicblock-committor-service/src/pubkeys_provider.rs @@ -1,7 +1,7 @@ -use log::*; use std::collections::HashSet; use dlp::pda; +use log::*; use solana_pubkey::Pubkey; use solana_sdk::system_program; diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 1b74ba219..4e022eea8 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -3,8 +3,7 @@ use std::{fmt::Display, path::Path}; use log::*; use magicblock_committor_program::Changeset; use solana_pubkey::Pubkey; -use solana_sdk::hash::Hash; -use solana_sdk::signature::Keypair; +use solana_sdk::{hash::Hash, signature::Keypair}; use tokio::{ select, sync::{ diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index a618ee90d..6e39bd653 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -9,6 +9,7 @@ use std::{ use magicblock_committor_program::Changeset; use solana_pubkey::Pubkey; +use solana_sdk::{hash::Hash, signature::Signature}; use tokio::sync::oneshot; use crate::{ @@ -19,7 +20,6 @@ use crate::{ }, ChangesetCommittor, }; -use solana_sdk::{hash::Hash, signature::Signature}; #[derive(Default)] pub struct ChangesetCommittorStub { diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs index fa53f03fb..63dfcddc7 100644 --- a/magicblock-committor-service/src/transactions.rs +++ b/magicblock-committor-service/src/transactions.rs @@ -8,13 +8,14 @@ use magicblock_committor_program::{ }; use solana_pubkey::Pubkey; use solana_rpc_client::rpc_client::SerializableTransaction; -use solana_sdk::hash::Hash; -use solana_sdk::instruction::Instruction; -use solana_sdk::message::v0::Message; -use solana_sdk::message::{AddressLookupTableAccount, VersionedMessage}; -use solana_sdk::signature::Keypair; -use solana_sdk::signer::Signer; -use solana_sdk::transaction::VersionedTransaction; +use solana_sdk::{ + hash::Hash, + instruction::Instruction, + message::{v0::Message, AddressLookupTableAccount, VersionedMessage}, + signature::Keypair, + signer::Signer, + transaction::VersionedTransaction, +}; use static_assertions::const_assert; use crate::error::{CommittorServiceError, CommittorServiceResult}; @@ -318,13 +319,6 @@ fn get_lookup_tables(ixs: &[Instruction]) -> Vec { #[cfg(test)] mod test { - use crate::{ - compute_budget::{Budget, ComputeBudget}, - pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, - }; - - use super::*; - use dlp::args::{CommitStateArgs, CommitStateFromBufferArgs}; use lazy_static::lazy_static; use solana_pubkey::Pubkey; @@ -338,6 +332,12 @@ mod test { transaction::VersionedTransaction, }; + use super::*; + use crate::{ + compute_budget::{Budget, ComputeBudget}, + pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, + }; + // These tests statically determine the optimal ix count to fit into a single // transaction and assert that the const we export in prod match those numbers. // Thus when an instruction changes and one of those numbers with it a failing diff --git a/magicblock-rpc-client/src/lib.rs b/magicblock-rpc-client/src/lib.rs index f710fb3a9..87f7753ab 100644 --- a/magicblock-rpc-client/src/lib.rs +++ b/magicblock-rpc-client/src/lib.rs @@ -1,14 +1,14 @@ -use log::*; use std::{ sync::Arc, time::{Duration, Instant}, }; +use log::*; use solana_rpc_client::{ nonblocking::rpc_client::RpcClient, rpc_client::SerializableTransaction, }; -use solana_rpc_client_api::client_error::ErrorKind as RpcClientErrorKind; use solana_rpc_client_api::{ + client_error::ErrorKind as RpcClientErrorKind, config::RpcSendTransactionConfig, request::RpcError, }; use solana_sdk::{ diff --git a/magicblock-table-mania/src/lookup_table.rs b/magicblock-table-mania/src/lookup_table.rs index 3c1e54063..ad7cc7b68 100644 --- a/magicblock-table-mania/src/lookup_table.rs +++ b/magicblock-table-mania/src/lookup_table.rs @@ -1,27 +1,29 @@ -use log::*; -use std::fmt; -use std::sync::Mutex; +use std::{fmt, sync::Mutex}; -use crate::derive_keypair; -use crate::error::{TableManiaError, TableManiaResult}; -use magicblock_rpc_client::MagicBlockRpcClientError; +use log::*; use magicblock_rpc_client::{ - MagicBlockSendTransactionConfig, MagicblockRpcClient, + MagicBlockRpcClientError, MagicBlockSendTransactionConfig, + MagicblockRpcClient, }; use solana_pubkey::Pubkey; -use solana_sdk::address_lookup_table::state::{ - LookupTableMeta, LOOKUP_TABLE_MAX_ADDRESSES, -}; -use solana_sdk::commitment_config::CommitmentLevel; -use solana_sdk::slot_hashes::MAX_ENTRIES; use solana_sdk::{ address_lookup_table as alt, + address_lookup_table::state::{ + LookupTableMeta, LOOKUP_TABLE_MAX_ADDRESSES, + }, clock::Slot, + commitment_config::CommitmentLevel, signature::{Keypair, Signature}, signer::Signer, + slot_hashes::MAX_ENTRIES, transaction::Transaction, }; +use crate::{ + derive_keypair, + error::{TableManiaError, TableManiaResult}, +}; + /// Determined via trial and error. The keys themselves take up /// 27 * 32 bytes = 864 bytes. pub const MAX_ENTRIES_AS_PART_OF_EXTEND: u64 = 27; diff --git a/magicblock-table-mania/src/lookup_table_rc.rs b/magicblock-table-mania/src/lookup_table_rc.rs index 94e298cde..386a28edb 100644 --- a/magicblock-table-mania/src/lookup_table_rc.rs +++ b/magicblock-table-mania/src/lookup_table_rc.rs @@ -1,8 +1,19 @@ +use std::{ + collections::{HashMap, HashSet}, + fmt, + ops::Deref, + sync::{ + atomic::{AtomicUsize, Ordering}, + RwLock, RwLockReadGuard, RwLockWriteGuard, + }, +}; + use log::*; use magicblock_rpc_client::{ MagicBlockRpcClientError, MagicBlockSendTransactionConfig, MagicblockRpcClient, }; +use solana_pubkey::Pubkey; use solana_sdk::{ address_lookup_table::{ self as alt, @@ -15,17 +26,6 @@ use solana_sdk::{ slot_hashes::MAX_ENTRIES, transaction::Transaction, }; -use std::{ - collections::{HashMap, HashSet}, - fmt, - ops::Deref, - sync::{ - atomic::{AtomicUsize, Ordering}, - RwLock, RwLockReadGuard, RwLockWriteGuard, - }, -}; - -use solana_pubkey::Pubkey; use crate::{ derive_keypair, diff --git a/magicblock-table-mania/src/manager.rs b/magicblock-table-mania/src/manager.rs index e9eb2f9db..d2202a3ef 100644 --- a/magicblock-table-mania/src/manager.rs +++ b/magicblock-table-mania/src/manager.rs @@ -1,4 +1,3 @@ -use log::*; use std::{ collections::{HashMap, HashSet}, sync::{ @@ -8,6 +7,7 @@ use std::{ time::{Duration, Instant}, }; +use log::*; use magicblock_rpc_client::MagicblockRpcClient; use solana_pubkey::Pubkey; use solana_sdk::{ From 52fd8310e2e4c839980c0f0db616e63147cd2f2e Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 16:48:54 +0545 Subject: [PATCH 036/199] chore: update delegation program reference --- Cargo.lock | 22 +++++++++++++++++++--- Cargo.toml | 2 +- test-integration/Cargo.lock | 9 +++++---- test-integration/Cargo.toml | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dce0e98f0..d5c825ea9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1185,7 +1185,7 @@ dependencies = [ "conjunto-addresses", "conjunto-core", "conjunto-providers", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", "serde", "solana-rpc-client", "solana-rpc-client-api", @@ -3641,7 +3641,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3797,7 +3797,7 @@ dependencies = [ "lazy_static", "log", "magicblock-committor-program", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", "magicblock-rpc-client", "magicblock-table-mania", "rusqlite", @@ -3836,6 +3836,22 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "magicblock-delegation-program" +version = "1.0.0" +source = "git+https://github.com/magicblock-labs/delegation-program.git?branch=main#9570abf24ab6d03ba75ecdbf8a6a787bb0d69d3a" +dependencies = [ + "bincode", + "borsh 1.5.5", + "bytemuck", + "num_enum", + "paste", + "solana-curve25519", + "solana-program", + "solana-security-txt", + "thiserror 1.0.69", +] + [[package]] name = "magicblock-delegation-program" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 14857532d..261f614b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,7 @@ magicblock-committor-program = { path = "./magicblock-committor-program", featur magicblock-committor-service = { path = "./magicblock-committor-service" } magicblock-config = { path = "./magicblock-config" } magicblock-core = { path = "./magicblock-core" } -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", branch = "main" } magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" } magicblock-ledger = { path = "./magicblock-ledger" } magicblock-metrics = { path = "./magicblock-metrics" } diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 8dda50d88..1e7446095 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -2937,7 +2937,7 @@ dependencies = [ "log", "magicblock-config", "magicblock-core", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", "rayon", "serde", "solana-pubkey", @@ -3550,7 +3550,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3692,7 +3692,7 @@ dependencies = [ "borsh 1.5.7", "log", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", "magicblock-rpc-client", "magicblock-table-mania", "rusqlite", @@ -3733,6 +3733,7 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" +source = "git+https://github.com/magicblock-labs/delegation-program.git?branch=main#9570abf24ab6d03ba75ecdbf8a6a787bb0d69d3a" dependencies = [ "bincode", "borsh 1.5.7", @@ -5711,7 +5712,7 @@ dependencies = [ "log", "magicblock-committor-program", "magicblock-committor-service", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", "magicblock-rpc-client", "program-flexi-counter", "solana-account", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 4c8d6dc47..beaaa3af4 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -39,7 +39,7 @@ magicblock-core = { path = "../magicblock-core" } magicblock-committor-program = { path = "../magicblock-committor-program", features = [ "no-entrypoint", ] } -magicblock-delegation-program = { path = "../../delegation-program" } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", branch = "main" } magicblock-committor-service = { path = "../magicblock-committor-service" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } magicblock-table-mania = { path = "../magicblock-table-mania" } From 714dd68edf7f0c081cdd75e74d99d0b76beba897 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 17:00:44 +0545 Subject: [PATCH 037/199] chore: opt out of doctests for added crates --- magicblock-committor-program/Cargo.toml | 1 + magicblock-committor-service/Cargo.toml | 3 +++ magicblock-rpc-client/Cargo.toml | 3 +++ magicblock-table-mania/Cargo.toml | 3 +++ 4 files changed, 10 insertions(+) diff --git a/magicblock-committor-program/Cargo.toml b/magicblock-committor-program/Cargo.toml index 2b17f5b3f..15164f42a 100644 --- a/magicblock-committor-program/Cargo.toml +++ b/magicblock-committor-program/Cargo.toml @@ -24,6 +24,7 @@ tokio = { workspace = true } [lib] crate-type = ["cdylib", "lib"] +doctest = false [features] no-entrypoint = [] diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index 25e82451e..34174a8f8 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -7,6 +7,9 @@ homepage.workspace = true license.workspace = true edition.workspace = true +[lib] +doctest = false + [dependencies] base64 = { workspace = true } bincode = { workspace = true } diff --git a/magicblock-rpc-client/Cargo.toml b/magicblock-rpc-client/Cargo.toml index 2bc7430a5..1004e7c7a 100644 --- a/magicblock-rpc-client/Cargo.toml +++ b/magicblock-rpc-client/Cargo.toml @@ -7,6 +7,9 @@ homepage.workspace = true license.workspace = true edition.workspace = true +[lib] +doctest = false + [dependencies] log = { workspace = true } solana-rpc-client = { workspace = true } diff --git a/magicblock-table-mania/Cargo.toml b/magicblock-table-mania/Cargo.toml index 5767af61e..5cca6e5f8 100644 --- a/magicblock-table-mania/Cargo.toml +++ b/magicblock-table-mania/Cargo.toml @@ -7,6 +7,9 @@ homepage.workspace = true license.workspace = true edition.workspace = true +[lib] +doctest = false + [dependencies] ed25519-dalek = { workspace = true } log = { workspace = true } From 0f94802d304e1f077059dd94d49e12ce5017e47f Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 17:03:12 +0545 Subject: [PATCH 038/199] ix: add rule to make committor program --- test-integration/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test-integration/Makefile b/test-integration/Makefile index 153858bd5..c4fa08a4b 100644 --- a/test-integration/Makefile +++ b/test-integration/Makefile @@ -42,6 +42,8 @@ $(SCHEDULECOMMIT_SO): $(SCHEDULECOMMIT_SRC) cargo build-sbf --manifest-path $(SCHEDULECOMMIT_DIR)/Cargo.toml $(SCHEDULECOMMIT_SECURITY_SO): $(SCHEDULECOMMIT_SECURITY_SRC) cargo build-sbf --manifest-path $(SCHEDULECOMMIT_SECURITY_DIR)/Cargo.toml +$(COMMITTOR_PROGRAM_SO): $(COMMITTOR_PROGRAM_SRC) + cargo build-sbf --manifest-path $(COMMITTOR_PROGRAM_DIR)/Cargo.toml deploy-flexi-counter: $(FLEXI_COUNTER_SO) solana program deploy \ From c8ddb165bfc55bafa4d4c9de9ee203332002c09b Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 17:04:32 +0545 Subject: [PATCH 039/199] fix: error misspelling --- magicblock-api/src/errors.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magicblock-api/src/errors.rs b/magicblock-api/src/errors.rs index 6cebbf8d0..0404bb374 100644 --- a/magicblock-api/src/errors.rs +++ b/magicblock-api/src/errors.rs @@ -33,8 +33,8 @@ pub enum ApiError { #[error("Validator '{0}' is insufficiently funded on chain. Minimum is ({1} SOL)")] ValidatorInsufficientlyFunded(Pubkey, u64), - #[error("CommittorSerivceError")] - CommittorSerivceError( + #[error("CommittorServiceError")] + CommittorServiceError( #[from] magicblock_committor_service::error::CommittorServiceError, ), From b246170cd8545b5f7102299a59e81abcb16ca978 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 17:23:10 +0545 Subject: [PATCH 040/199] chore: address some greptiles --- magicblock-accounts/src/errors.rs | 2 +- magicblock-accounts/src/lib.rs | 1 - .../old_remote_scheduled_commits_processor.rs | 300 ------------------ .../src/remote_scheduled_commits_processor.rs | 4 +- magicblock-committor-program/src/consts.rs | 4 +- .../src/instruction.rs | 31 +- magicblock-committor-program/src/pdas.rs | 2 +- magicblock-committor-program/src/processor.rs | 4 +- .../src/state/chunks.rs | 4 +- .../programs/flexi-counter/src/instruction.rs | 4 +- .../programs/flexi-counter/src/processor.rs | 4 +- .../tests/utils/instructions.rs | 4 +- 12 files changed, 32 insertions(+), 332 deletions(-) delete mode 100644 magicblock-accounts/src/old_remote_scheduled_commits_processor.rs diff --git a/magicblock-accounts/src/errors.rs b/magicblock-accounts/src/errors.rs index c7c18b2b3..61a3b5a2c 100644 --- a/magicblock-accounts/src/errors.rs +++ b/magicblock-accounts/src/errors.rs @@ -58,6 +58,6 @@ pub enum AccountsError { #[error("Too many committees: {0}")] TooManyCommittees(usize), - #[error("FailedToObtainReqidForCommittedChangeset {0:?}'")] + #[error("FailedToObtainReqidForCommittedChangeset {0:?}")] FailedToObtainReqidForCommittedChangeset(Box), } diff --git a/magicblock-accounts/src/lib.rs b/magicblock-accounts/src/lib.rs index 6b2eda27e..ec28920c7 100644 --- a/magicblock-accounts/src/lib.rs +++ b/magicblock-accounts/src/lib.rs @@ -2,7 +2,6 @@ mod accounts_manager; mod config; pub mod errors; mod external_accounts_manager; -// mod old_remote_scheduled_commits_processor; mod remote_account_committer; mod remote_scheduled_commits_processor; mod traits; diff --git a/magicblock-accounts/src/old_remote_scheduled_commits_processor.rs b/magicblock-accounts/src/old_remote_scheduled_commits_processor.rs deleted file mode 100644 index d42eb9037..000000000 --- a/magicblock-accounts/src/old_remote_scheduled_commits_processor.rs +++ /dev/null @@ -1,300 +0,0 @@ -use std::{collections::HashSet, sync::Arc}; - -use async_trait::async_trait; -use conjunto_transwise::AccountChainSnapshot; -use log::*; -use magicblock_account_cloner::{ - AccountClonerOutput, AccountClonerOutput::Cloned, CloneOutputMap, -}; -use magicblock_accounts_api::InternalAccountProvider; -use magicblock_bank::bank::Bank; -use magicblock_core::debug_panic; -use magicblock_metrics::metrics; -use magicblock_mutator::Cluster; -use magicblock_processor::execute_transaction::execute_legacy_transaction; -use magicblock_program::{ - register_scheduled_commit_sent, FeePayerAccount, SentCommit, - TransactionScheduler, -}; -use magicblock_transaction_status::TransactionStatusSender; -use solana_sdk::{pubkey::Pubkey, signature::Signature}; - -use crate::{ - errors::{AccountsError, AccountsResult}, - remote_account_committer::update_account_commit_metrics, - AccountCommittee, AccountCommitter, ScheduledCommitsProcessor, - SendableCommitAccountsPayload, -}; - -pub struct OldRemoteScheduledCommitsProcessor { - #[allow(unused)] - cluster: Cluster, - bank: Arc, - transaction_status_sender: Option, - transaction_scheduler: TransactionScheduler, - cloned_accounts: CloneOutputMap, -} - -#[async_trait] -impl ScheduledCommitsProcessor for OldRemoteScheduledCommitsProcessor { - async fn process( - &self, - committer: &Arc, - account_provider: &IAP, - ) -> AccountsResult<()> - where - AC: AccountCommitter, - IAP: InternalAccountProvider, - { - let scheduled_commits = - self.transaction_scheduler.take_scheduled_commits(); - - if scheduled_commits.is_empty() { - return Ok(()); - } - - let mut sendable_payloads_queue = vec![]; - for commit in scheduled_commits { - info!("Processing commit: {:?}", commit); - - // Determine which accounts are available and can be committed - let mut committees = vec![]; - let all_pubkeys: HashSet = HashSet::from_iter( - commit - .accounts - .iter() - .map(|ca| ca.pubkey) - .collect::>(), - ); - let mut feepayers = HashSet::new(); - - for committed_account in commit.accounts { - let mut commitment_pubkey = committed_account.pubkey; - let mut commitment_pubkey_owner = committed_account.owner; - if let Some(Cloned { - account_chain_snapshot, - .. - }) = Self::fetch_cloned_account( - &committed_account.pubkey, - &self.cloned_accounts, - ) { - // If the account is a FeePayer, we committed the mapped delegated account - if account_chain_snapshot.chain_state.is_feepayer() { - commitment_pubkey = - AccountChainSnapshot::ephemeral_balance_pda( - &committed_account.pubkey, - ); - commitment_pubkey_owner = - AccountChainSnapshot::ephemeral_balance_pda_owner(); - feepayers.insert(FeePayerAccount { - pubkey: committed_account.pubkey, - delegated_pda: commitment_pubkey, - }); - } else if account_chain_snapshot - .chain_state - .is_undelegated() - { - error!("Scheduled commit account '{}' is undelegated. This is not supported.", committed_account.pubkey); - } - } - - match account_provider.get_account(&committed_account.pubkey) { - Some(account_data) => { - committees.push(AccountCommittee { - pubkey: commitment_pubkey, - owner: commitment_pubkey_owner, - account_data, - slot: commit.slot, - undelegation_requested: commit.request_undelegation, - }); - } - None => { - error!( - "Scheduled commmit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", - committed_account.pubkey - ); - } - } - } - - let payloads = vec![ - committer - .create_commit_accounts_transaction(committees) - .await?, - ]; - - // Determine which payloads are a noop since all accounts are up to date - // and which require a commit to chain - let mut included_pubkeys = HashSet::new(); - let sendable_payloads = payloads - .into_iter() - .filter_map(|payload| { - if let Some(transaction) = payload.transaction { - included_pubkeys.extend( - payload - .committees - .iter() - .map(|(pubkey, _)| *pubkey), - ); - Some(SendableCommitAccountsPayload { - transaction, - committees: payload.committees, - }) - } else { - None - } - }) - .collect::>(); - - // Tally up the pubkeys that will not be committed since the account - // was not available as determined when creating sendable payloads - let excluded_pubkeys = all_pubkeys - .into_iter() - .filter(|pubkey| { - !included_pubkeys.contains(pubkey) - && !included_pubkeys.contains( - &AccountChainSnapshot::ephemeral_balance_pda( - pubkey, - ), - ) - }) - .collect::>(); - - // Extract signatures of all transactions that we will execute on - // chain in order to realize the commits needed - let signatures = sendable_payloads - .iter() - .map(|payload| payload.get_signature()) - .collect::>(); - - // Record that we are about to send the commit to chain including all - // information (mainly signatures) needed to track its outcome on chain - let sent_commit = SentCommit { - commit_id: commit.id, - slot: commit.slot, - blockhash: commit.blockhash, - payer: commit.payer, - chain_signatures: signatures, - included_pubkeys: included_pubkeys.into_iter().collect(), - excluded_pubkeys, - feepayers, - requested_undelegation: commit.request_undelegation, - }; - register_scheduled_commit_sent(sent_commit); - let signature = execute_legacy_transaction( - commit.commit_sent_transaction, - &self.bank, - self.transaction_status_sender.as_ref(), - ) - .map_err(Box::new)?; - - // In the case that no account needs to be committed we record that in - // our ledger and are done - if sendable_payloads.is_empty() { - debug!( - "Signaled no commit needed with internal signature: {:?}", - signature - ); - continue; - } else { - debug!( - "Signaled commit with internal signature: {:?}", - signature - ); - } - - // Queue up the actual commit - sendable_payloads_queue.extend(sendable_payloads); - } - - self.process_accounts_commits_in_background( - committer, - sendable_payloads_queue, - ); - - Ok(()) - } - - fn scheduled_commits_len(&self) -> usize { - self.transaction_scheduler.scheduled_commits_len() - } - - fn clear_scheduled_commits(&self) { - self.transaction_scheduler.clear_scheduled_commits(); - } -} - -impl OldRemoteScheduledCommitsProcessor { - pub(crate) fn new( - cluster: Cluster, - bank: Arc, - cloned_accounts: CloneOutputMap, - transaction_status_sender: Option, - ) -> Self { - Self { - cluster, - bank, - transaction_status_sender, - cloned_accounts, - transaction_scheduler: TransactionScheduler::default(), - } - } - - fn process_accounts_commits_in_background( - &self, - committer: &Arc, - sendable_payloads_queue: Vec, - ) { - // We process the queue on a separate task in order to not block - // the validator (slot advance) itself - // NOTE: @@ we have to be careful here and ensure that the validator does not - // shutdown before this task is done - // We will need some tracking machinery which is overkill until we get to the - // point where we do allow validator shutdown - let committer = committer.clone(); - tokio::task::spawn(async move { - let pending_commits = match committer - .send_commit_transactions(sendable_payloads_queue) - .await - { - Ok(pending) => pending, - Err(AccountsError::FailedToSendCommitTransaction( - err, - commit_and_undelegate_accounts, - commit_only_accounts, - )) => { - update_account_commit_metrics( - &commit_and_undelegate_accounts, - &commit_only_accounts, - metrics::Outcome::Error, - None, - ); - debug_panic!( - "Failed to send commit transactions: {:?}", - err - ); - return; - } - Err(err) => { - debug_panic!( - "Failed to send commit transactions, received invalid err: {:?}", - err - ); - return; - } - }; - - committer.confirm_pending_commits(pending_commits).await; - }); - } - - fn fetch_cloned_account( - pubkey: &Pubkey, - cloned_accounts: &CloneOutputMap, - ) -> Option { - cloned_accounts - .read() - .expect("RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned") - .get(pubkey).cloned() - } -} diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 6727009e7..92a268fcd 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -62,7 +62,7 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { .max() .unwrap(); // Safety we just obtained the max slot from the scheduled commits - let ephemereal_blockhash = scheduled_commits + let ephemeral_blockhash = scheduled_commits .iter() .find(|commit| commit.slot == max_slot) .map(|commit| commit.blockhash) @@ -175,7 +175,7 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { changeset_committor, changeset, sent_commits, - ephemereal_blockhash, + ephemeral_blockhash, ); Ok(()) diff --git a/magicblock-committor-program/src/consts.rs b/magicblock-committor-program/src/consts.rs index 4af1f467f..dfea9ce8c 100644 --- a/magicblock-committor-program/src/consts.rs +++ b/magicblock-committor-program/src/consts.rs @@ -1,7 +1,7 @@ -/// Max bytest that can be allocated as part of the one instruction. +/// Max bytes that can be allocated as part of the one instruction. /// For buffers that are larger than that ReallocBuffer needs to be /// invoked 1 or more times after Init completed. -pub const MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE: u16 = 10_240; +pub const MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE: u16 = 10_240; /// The maximum number of instructions that can be added to a single transaction. /// See: https://github.com/solana-labs/solana/issues/33863 diff --git a/magicblock-committor-program/src/instruction.rs b/magicblock-committor-program/src/instruction.rs index b6bf1e28c..df6cb7a1e 100644 --- a/magicblock-committor-program/src/instruction.rs +++ b/magicblock-committor-program/src/instruction.rs @@ -85,7 +85,7 @@ pub enum CommittorInstruction { /// It is called by the validator after the instruction that processes the /// change set stored in the buffer account and applies the commits to the /// relevant accounts. - /// Ideally it runs in the same transaction as the 'processs' instruction. + /// Ideally it runs in the same transaction as the 'process' instruction. /// /// The lamports gained due to closing both accounts are transferred to the /// validator authority. @@ -119,9 +119,9 @@ pub const IX_INIT_SIZE: u16 = // blockhash: Hash, HASH_BYTES as u16 + // chunks_bump: u8, - 8 + + 1 + // buffer_bump: u8, - 8 + + 1 + // chunk_count: usize, 8 + // chunk_size: u16, @@ -137,7 +137,7 @@ pub const IX_REALLOC_SIZE: u16 = // blockhash: Hash, HASH_BYTES as u16 + // buffer_bump: u8, - 8 + + 1 + // invocation_count: u16, 2 + // byte align @@ -149,9 +149,9 @@ pub const IX_WRITE_SIZE_WITHOUT_CHUNKS: u16 = // blockhash: Hash, HASH_BYTES as u16 + // chunks_bump: u8, - 8 + + 1 + // buffer_bump: u8, - 8 + + 1 + // offset: u32 32; @@ -161,9 +161,9 @@ pub const IX_CLOSE_SIZE: u16 = // blockhash: Hash, HASH_BYTES as u16 + // chunks_bump: u8, - 8 + + 1 + // buffer_bump: u8, - 8; + 1; // ----------------- // create_init_ix @@ -238,7 +238,7 @@ pub struct CreateReallocBufferIxArgs { /// Creates the realloc ixs we need to invoke in order to realloc /// the account to the desired size since we only can realloc up to -/// [consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE] in a single instruction. +/// [consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE] in a single instruction. /// Returns a tuple with the instructions and a bool indicating if we need to split /// them into multiple instructions in order to avoid /// [solana_program::program_error::MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED]J @@ -246,23 +246,24 @@ pub fn create_realloc_buffer_ixs( args: CreateReallocBufferIxArgs, ) -> Vec { // We already allocated once during Init and only need to realloc - // if the buffer is larger than [consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE] + // if the buffer is larger than [consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE] if args.buffer_account_size - <= consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64 + <= consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64 { return vec![]; } let remaining_size = args.buffer_account_size as i128 - - consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128; + - consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128; // A) We just need to realloc once - if remaining_size <= consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128 { + if remaining_size <= consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128 + { return vec![create_realloc_buffer_ix(args, 1)]; } // B) We need to realloc multiple times - // SAFETY; remaining size > consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE + // SAFETY; remaining size > consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE create_realloc_buffer_ixs_to_add_remaining(&args, remaining_size as u64) } @@ -271,7 +272,7 @@ pub fn create_realloc_buffer_ixs_to_add_remaining( remaining_size: u64, ) -> Vec { let invocation_count = (remaining_size as f64 - / consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as f64) + / consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as f64) .ceil() as u16; let mut ixs = vec![]; diff --git a/magicblock-committor-program/src/pdas.rs b/magicblock-committor-program/src/pdas.rs index e28a89a92..7e2a4dd62 100644 --- a/magicblock-committor-program/src/pdas.rs +++ b/magicblock-committor-program/src/pdas.rs @@ -93,7 +93,7 @@ macro_rules! verified_seeds_and_pda { &$blockhash, $bump, ) - .inspect_err(|err| msg!("ERR: {}", err))?; + .inspect_err(|err| ::solana_program::msg!("ERR: {}", err))?; $crate::utils::assert_keys_equal($account_info.key, &pda, || { format!( "Provided {} PDA does not match derived key '{}'", diff --git a/magicblock-committor-program/src/processor.rs b/magicblock-committor-program/src/processor.rs index e1068b60d..3becb7a20 100644 --- a/magicblock-committor-program/src/processor.rs +++ b/magicblock-committor-program/src/processor.rs @@ -161,7 +161,7 @@ fn process_init( let initial_alloc_size = std::cmp::min( buffer_account_size, - consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64, + consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64, ); // Create Buffer Account @@ -241,7 +241,7 @@ fn process_realloc_buffer( let next_alloc_size = std::cmp::min( buffer_account_size, current_buffer_size - + consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64, + + consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64, ); msg!( diff --git a/magicblock-committor-program/src/state/chunks.rs b/magicblock-committor-program/src/state/chunks.rs index 06b3e3a69..824a33453 100644 --- a/magicblock-committor-program/src/state/chunks.rs +++ b/magicblock-committor-program/src/state/chunks.rs @@ -49,11 +49,11 @@ impl Chunks { // SAFETY: this is a bug and we need to crash and burn assert!( Self::bytes_for_count_len(chunk_count) - < consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as usize, + < consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as usize, "Size ({}) needed to track {} chunks is too large track and would require to realloc. Max allowed is {} bytes", Self::bytes_for_count_len(chunk_count), chunk_count, - consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE + consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE ); Self { bits: vec![0; Self::bits_for_count_len(chunk_count)], diff --git a/test-integration/programs/flexi-counter/src/instruction.rs b/test-integration/programs/flexi-counter/src/instruction.rs index 7e061ea39..391f19529 100644 --- a/test-integration/programs/flexi-counter/src/instruction.rs +++ b/test-integration/programs/flexi-counter/src/instruction.rs @@ -17,7 +17,7 @@ pub struct DelegateArgs { pub commit_frequency_ms: u32, } -pub const MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE: u16 = 10_240; +pub const MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE: u16 = 10_240; /// The counter has both mul and add instructions in order to facilitate tests where /// order matters. For example in the case of the following operations: @@ -35,7 +35,7 @@ pub enum FlexiCounterInstruction { Init { label: String, bump: u8 }, /// Increases the size of the FlexiCounter to reach the given bytes. - /// Max increase is [MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE] per instruction + /// Max increase is [MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE] per instruction /// which means this instruction needs to be called multiple times to reach /// the desired size. /// diff --git a/test-integration/programs/flexi-counter/src/processor.rs b/test-integration/programs/flexi-counter/src/processor.rs index 9d43b371d..922e25870 100644 --- a/test-integration/programs/flexi-counter/src/processor.rs +++ b/test-integration/programs/flexi-counter/src/processor.rs @@ -17,7 +17,7 @@ use solana_program::{ sysvar::Sysvar, }; -use crate::instruction::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE; +use crate::instruction::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE; use crate::{ instruction::{DelegateArgs, FlexiCounterInstruction}, state::FlexiCounter, @@ -133,7 +133,7 @@ fn process_realloc( let next_alloc_size = std::cmp::min( bytes, - current_size + MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64, + current_size + MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64, ); msg!( diff --git a/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs b/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs index 148ae6ce6..1b9510c0a 100644 --- a/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs +++ b/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs @@ -27,12 +27,12 @@ pub fn init_account_and_delegate_ixs( let rent_exempt = Rent::default().minimum_balance(bytes as usize); let mut realloc_ixs = vec![]; if bytes - > magicblock_committor_program::consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE + > magicblock_committor_program::consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64 { // TODO: we may have to chunk those let reallocs = bytes - / magicblock_committor_program::consts::MAX_ACOUNT_ALLOC_PER_INSTRUCTION_SIZE + / magicblock_committor_program::consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64; for i in 0..reallocs { realloc_ixs.push(create_realloc_ix(payer, bytes, i as u16)); From d3892d151bf6b4bab046c897f27144b104392ed4 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 17:23:23 +0545 Subject: [PATCH 041/199] ix: check in missing config --- .../configs/committor-conf.devnet.toml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test-integration/configs/committor-conf.devnet.toml diff --git a/test-integration/configs/committor-conf.devnet.toml b/test-integration/configs/committor-conf.devnet.toml new file mode 100644 index 000000000..9e68ade3e --- /dev/null +++ b/test-integration/configs/committor-conf.devnet.toml @@ -0,0 +1,52 @@ +[accounts] +remote = "devnet" +lifecycle = "offline" +commit = { frequency_millis = 9_000_000_000_000, compute_unit_price = 1_000_000 } + + +[accounts.db] +# size of the main storage, we have to preallocate in advance +# it's advised to set this value based on formula 1KB * N * 3, +# where N is the number of accounts expected to be stored in +# database, e.g. for million accounts this would be 3GB +db-size = 1048576000 # 1GB +# minimal indivisible unit of addressing in main storage +# offsets are calculated in terms of blocks +block-size = "block256" # possible values block128 | block256 | block512 +# size of index file, we have to preallocate, +# can be as low as 1% of main storage size, but setting it to higher values won't hurt +index-map-size = 2048576 +# max number of snapshots to keep around +max-snapshots = 7 +# how frequently (slot-wise) we should take snapshots +snapshot-frequency = 1024 + +[validator] +millis_per_slot = 50 +sigverify = true + +[[program]] +id = "DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh" +path = "../schedulecommit/elfs/dlp.so" + +# NOTE: `cargo build-sbf` needs to run from the root to build the program +[[program]] +id = "corabpNrkBEqbTZP7xfJgSWTdBmVdLf1PARWXZbcMcS" +path = "../../target/deploy/magicblock_committor_program.so" + +[[program]] +id = "9hgprgZiRWmy8KkfvUuaVkDGrqo9GzeXMohwq6BazgUY" +path = "../target/deploy/program_schedulecommit.so" + +[[program]] +id = "f1exzKGtdeVX3d6UXZ89cY7twiNJe9S5uq84RTA4Rq4" +path = "../target/deploy/program_flexi_counter.so" + +[rpc] +port = 7799 + +[geyser_grpc] +port = 10001 + +[metrics] +enabled = false From ca5e9f4cf3a41eb0dfbaab8a6d0ee6e07bfe6719 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 17:57:24 +0545 Subject: [PATCH 042/199] chore: more greptiles --- magicblock-committor-program/src/processor.rs | 10 +++++++++- .../src/state/changeset.rs | 2 +- magicblock-committor-program/src/utils/asserts.rs | 4 ++-- magicblock-committor-service/src/bundles.rs | 2 +- .../src/commit/commit_using_buffer.rs | 2 +- .../src/commit/process_buffers.rs | 4 ++-- magicblock-committor-service/src/commit_info.rs | 3 --- magicblock-committor-service/src/commit_stage.rs | 4 ++-- magicblock-committor-service/src/compute_budget.rs | 14 ++++++++++++-- 9 files changed, 30 insertions(+), 15 deletions(-) diff --git a/magicblock-committor-program/src/processor.rs b/magicblock-committor-program/src/processor.rs index 3becb7a20..320ae5cab 100644 --- a/magicblock-committor-program/src/processor.rs +++ b/magicblock-committor-program/src/processor.rs @@ -307,7 +307,15 @@ fn process_write( data_chunk.len() as u64, ); - if offset as usize + data_chunk.len() > buffer_data.len() { + let end_offset = offset + .checked_add(data_chunk.len() as u32) + .map(|sum| sum as usize) + .ok_or(CommittorError::OffsetChunkOutOfRange( + data_chunk.len(), + offset, + buffer_data.len(), + ))?; + if end_offset > buffer_data.len() { let err = CommittorError::OffsetChunkOutOfRange( data_chunk.len(), offset, diff --git a/magicblock-committor-program/src/state/changeset.rs b/magicblock-committor-program/src/state/changeset.rs index 4e52869c8..3caf55327 100644 --- a/magicblock-committor-program/src/state/changeset.rs +++ b/magicblock-committor-program/src/state/changeset.rs @@ -409,7 +409,7 @@ impl CommitableAccount { self.chunks = chunks; } - /// The total size of the data that we we will commit. + /// The total size of the data that we will commit. /// Use this to initialize the empty account on chain. pub fn size(&self) -> usize { self.data.len() diff --git a/magicblock-committor-program/src/utils/asserts.rs b/magicblock-committor-program/src/utils/asserts.rs index b83c21f05..c6d5482df 100644 --- a/magicblock-committor-program/src/utils/asserts.rs +++ b/magicblock-committor-program/src/utils/asserts.rs @@ -21,7 +21,7 @@ pub fn assert_account_unallocated( account: &AccountInfo, account_label: &str, ) -> ProgramResult { - if account.data.borrow().len() != 0 { + if account.try_borrow_data()?.len() != 0 { msg!( "Err: account '{}' ({}) was already initialized", account_label, @@ -51,7 +51,7 @@ pub fn assert_is_signer( pub fn assert_program_id(program_id: &Pubkey) -> ProgramResult { if program_id != &crate::id() { - msg!("ERR: invalid program id"); + msg!("Err: invalid program id"); Err(ProgramError::IncorrectProgramId) } else { Ok(()) diff --git a/magicblock-committor-service/src/bundles.rs b/magicblock-committor-service/src/bundles.rs index 086163df4..ee778658e 100644 --- a/magicblock-committor-service/src/bundles.rs +++ b/magicblock-committor-service/src/bundles.rs @@ -62,7 +62,7 @@ pub(crate) fn bundle_chunks( // If we still have unbundled commits then add chunks for those while !not_bundled.is_empty() { - let range_end = (max_per_chunk).min(not_bundled.len()); + let range_end = max_per_chunk.min(not_bundled.len()); chunks.push(not_bundled.drain(..range_end).collect()); } diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs index e33a3f7fe..1c15bd7fb 100644 --- a/magicblock-committor-service/src/commit/commit_using_buffer.rs +++ b/magicblock-committor-service/src/commit/commit_using_buffer.rs @@ -308,7 +308,7 @@ impl CommittorProcessor { debug_assert_eq!( kind, &InstructionsKind::Finalize, - "Expecting separate finalize instructions onky" + "Expecting separate finalize instructions only" ); let bundle_id = commit_info.bundle_id(); debug_assert!( diff --git a/magicblock-committor-service/src/commit/process_buffers.rs b/magicblock-committor-service/src/commit/process_buffers.rs index 40cb2583c..542c4c3f7 100644 --- a/magicblock-committor-service/src/commit/process_buffers.rs +++ b/magicblock-committor-service/src/commit/process_buffers.rs @@ -116,7 +116,7 @@ fn process_commitable_separate_ix( ); InstructionsForCommitable { instructions: vec![process_ix], - commit_info: commit_info.clone(), + commit_info, kind: InstructionsKind::Process, } } @@ -127,7 +127,7 @@ pub(crate) struct ChunkedIxsToProcessCommitablesAndClosePdasResult { /// chunk can run in parallel pub chunked_ixs: Vec>, /// Separate buffer close transactions. - /// Since the process transactions nee to complete first we need to run them + /// Since the process transactions need to complete first we need to run them /// after the [Self::chunked_ixs] transactions pub chunked_close_ixs: Option>>, /// Commitables that could not be chunked and thus cannot be committed while diff --git a/magicblock-committor-service/src/commit_info.rs b/magicblock-committor-service/src/commit_info.rs index a669153bc..40b060cab 100644 --- a/magicblock-committor-service/src/commit_info.rs +++ b/magicblock-committor-service/src/commit_info.rs @@ -104,9 +104,6 @@ impl CommitInfo { ), } } - pub fn has_data(&self) -> bool { - matches!(self, Self::BufferedDataAccount { .. }) - } pub fn pubkey(&self) -> Pubkey { match self { diff --git a/magicblock-committor-service/src/commit_stage.rs b/magicblock-committor-service/src/commit_stage.rs index 66a5e8587..6e555ece1 100644 --- a/magicblock-committor-service/src/commit_stage.rs +++ b/magicblock-committor-service/src/commit_stage.rs @@ -16,7 +16,7 @@ pub struct CommitSignatures { /// The signature of the transaction processing the commit pub process_signature: Signature, /// The signature of the transaction finalizing the commit. - /// If the account was not finalized or it failed the this is `None`. + /// If the account was not finalized or it failed then this is `None`. /// If the finalize instruction was part of the process transaction then /// this signature is the same as [Self::process_signature]. pub finalize_signature: Option, @@ -293,7 +293,7 @@ impl CommitStage { } /// Returns `true` if we need to init the chunks and buffer accounts when we - /// retry commiting this account + /// retry committing this account pub fn needs_accounts_init(&self) -> bool { use CommitStage::*; matches!(self, Failed(_) | BufferAndChunkPartiallyInitialized(_)) diff --git a/magicblock-committor-service/src/compute_budget.rs b/magicblock-committor-service/src/compute_budget.rs index 0b2aa3123..1dacc425f 100644 --- a/magicblock-committor-service/src/compute_budget.rs +++ b/magicblock-committor-service/src/compute_budget.rs @@ -54,7 +54,14 @@ pub struct BufferWriteChunkBudget { impl BufferWriteChunkBudget { fn total_budget(&self, bytes_count: usize) -> u32 { - self.base_budget + (self.per_byte * bytes_count) as u32 + u32::try_from( + self.per_byte + .checked_mul(bytes_count) + .unwrap_or(u32::MAX as usize), + ) + .unwrap_or(u32::MAX) + .checked_add(self.base_budget) + .unwrap_or(u32::MAX) } pub fn instructions(&self, bytes_count: usize) -> Vec { @@ -192,7 +199,10 @@ impl ComputeBudget { } fn total_budget(&self, committee_count: u32) -> u32 { - self.base_budget() + (self.per_committee() * committee_count) + self.per_committee() + .checked_mul(committee_count) + .and_then(|product| product.checked_add(self.base_budget())) + .unwrap_or(u32::MAX) } pub fn instructions(&self, committee_count: usize) -> Vec { From bc48d5873f5dda003ab8ef830d59e2517c25b61b Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 18:09:04 +0545 Subject: [PATCH 043/199] ix: move table mania/committor tests last since they are the slowest --- test-integration/test-runner/bin/run_tests.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index d101cc0a9..f735d7c07 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -18,15 +18,10 @@ use test_runner::cleanup::{cleanup_devnet_only, cleanup_validators}; pub fn main() { let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let Ok((table_mania_output, committor_output)) = - run_table_mania_and_committor_tests(&manifest_dir) - else { - // If any test run panics (i.e. not just a failing test) then we bail - return; - }; let Ok((security_output, scenarios_output)) = run_schedule_commit_tests(&manifest_dir) else { + // If any test run panics (i.e. not just a failing test) then we bail return; }; let Ok(issues_frequent_commits_output) = @@ -48,15 +43,21 @@ pub fn main() { return; }; + let Ok((table_mania_output, committor_output)) = + run_table_mania_and_committor_tests(&manifest_dir) + else { + return; + }; + // Assert that all tests passed - assert_cargo_tests_passed(table_mania_output); - assert_cargo_tests_passed(committor_output); assert_cargo_tests_passed(security_output); assert_cargo_tests_passed(scenarios_output); assert_cargo_tests_passed(cloning_output); assert_cargo_tests_passed(issues_frequent_commits_output); assert_cargo_tests_passed(restore_ledger_output); assert_cargo_tests_passed(magicblock_api_output); + assert_cargo_tests_passed(table_mania_output); + assert_cargo_tests_passed(committor_output); } // ----------------- From 9fb082a5b6ceb618ab17af4a7178415ed48beb2d Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 18:18:09 +0545 Subject: [PATCH 044/199] chore: rollback delegation program version --- Cargo.lock | 22 +++-------------- Cargo.toml | 2 +- test-integration/Cargo.lock | 26 ++++---------------- test-integration/Cargo.toml | 2 +- test-integration/schedulecommit/elfs/dlp.so | Bin 321056 -> 319832 bytes 5 files changed, 10 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5c825ea9..dce0e98f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1185,7 +1185,7 @@ dependencies = [ "conjunto-addresses", "conjunto-core", "conjunto-providers", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", + "magicblock-delegation-program", "serde", "solana-rpc-client", "solana-rpc-client-api", @@ -3641,7 +3641,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", + "magicblock-delegation-program", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3797,7 +3797,7 @@ dependencies = [ "lazy_static", "log", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", + "magicblock-delegation-program", "magicblock-rpc-client", "magicblock-table-mania", "rusqlite", @@ -3836,22 +3836,6 @@ dependencies = [ "solana-sdk", ] -[[package]] -name = "magicblock-delegation-program" -version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?branch=main#9570abf24ab6d03ba75ecdbf8a6a787bb0d69d3a" -dependencies = [ - "bincode", - "borsh 1.5.5", - "bytemuck", - "num_enum", - "paste", - "solana-curve25519", - "solana-program", - "solana-security-txt", - "thiserror 1.0.69", -] - [[package]] name = "magicblock-delegation-program" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 261f614b0..14857532d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,7 @@ magicblock-committor-program = { path = "./magicblock-committor-program", featur magicblock-committor-service = { path = "./magicblock-committor-service" } magicblock-config = { path = "./magicblock-config" } magicblock-core = { path = "./magicblock-core" } -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", branch = "main" } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" } magicblock-ledger = { path = "./magicblock-ledger" } magicblock-metrics = { path = "./magicblock-metrics" } diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 1e7446095..93033d327 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1150,7 +1150,7 @@ dependencies = [ "conjunto-addresses", "conjunto-core", "conjunto-providers", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", + "magicblock-delegation-program", "serde", "solana-rpc-client", "solana-rpc-client-api", @@ -2937,7 +2937,7 @@ dependencies = [ "log", "magicblock-config", "magicblock-core", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", + "magicblock-delegation-program", "rayon", "serde", "solana-pubkey", @@ -3550,7 +3550,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", + "magicblock-delegation-program", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3692,7 +3692,7 @@ dependencies = [ "borsh 1.5.7", "log", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", + "magicblock-delegation-program", "magicblock-rpc-client", "magicblock-table-mania", "rusqlite", @@ -3730,22 +3730,6 @@ dependencies = [ "solana-sdk", ] -[[package]] -name = "magicblock-delegation-program" -version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?branch=main#9570abf24ab6d03ba75ecdbf8a6a787bb0d69d3a" -dependencies = [ - "bincode", - "borsh 1.5.7", - "bytemuck", - "num_enum", - "paste", - "solana-curve25519", - "solana-program", - "solana-security-txt", - "thiserror 1.0.69", -] - [[package]] name = "magicblock-delegation-program" version = "1.0.0" @@ -5712,7 +5696,7 @@ dependencies = [ "log", "magicblock-committor-program", "magicblock-committor-service", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?branch=main)", + "magicblock-delegation-program", "magicblock-rpc-client", "program-flexi-counter", "solana-account", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index beaaa3af4..b64288d28 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -39,7 +39,7 @@ magicblock-core = { path = "../magicblock-core" } magicblock-committor-program = { path = "../magicblock-committor-program", features = [ "no-entrypoint", ] } -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", branch = "main" } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } magicblock-committor-service = { path = "../magicblock-committor-service" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } magicblock-table-mania = { path = "../magicblock-table-mania" } diff --git a/test-integration/schedulecommit/elfs/dlp.so b/test-integration/schedulecommit/elfs/dlp.so index 71a5dd1efcde0c3e06963ed7a27e5760694b5c27..748c0d84b4a07c530a2cc84390bb5ab5647d6303 100755 GIT binary patch delta 39171 zcmbuo3tW`N_xS(J?1FeBKwZ}raJ?a#BKa{yQ$#abO_4MaO^HeoD~Ym@6@~RiXhzf& zhx!zumeHpo3S+5n!geDpH7YYKMJzQcBf4mG5r1c%3%fJb=ktHP{?F@`!~2{wGiPSb zT%Kp2-O3O4YksR=u{9(&b`4#LTeIFsp2&N|2@|nE2y=@iR5OoaQ(* zyPS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Nhvwz!9Cm27WkO;rln}^?4@U>PXs!g@y{{xwoi4On( From ee396dac533d1ff91dcb12c0a8a4d66da266b0b7 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 18:19:49 +0545 Subject: [PATCH 045/199] chore: cleanup stray log --- magicblock-api/src/magic_validator.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 2c0fe611a..32224fb35 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -807,7 +807,6 @@ impl MagicValidator { self.committor_service.reserve_common_pubkeys(), ) .await?; - info!("RESERVED"); if !self.config.ledger.reset { remote_account_cloner_worker.hydrate().await?; From 8635738b48f6f75275eb57dace26fa8597b83223 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 18:21:04 +0545 Subject: [PATCH 046/199] ix: give more compile time before expecting validator to listen --- test-integration/test-tools/src/validator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-integration/test-tools/src/validator.rs b/test-integration/test-tools/src/validator.rs index c5c646694..e206f7e8c 100644 --- a/test-integration/test-tools/src/validator.rs +++ b/test-integration/test-tools/src/validator.rs @@ -145,7 +145,7 @@ pub fn wait_for_validator(mut validator: Child, port: u16) -> Option { let max_retries = if std::env::var("CI").is_ok() { 1500 } else { - 75 + 800 }; for _ in 0..max_retries { From 7f3e0eb8636b039cad9f74098322af722423fb2a Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Thu, 15 May 2025 18:52:47 +0545 Subject: [PATCH 047/199] chore: greptiles --- .../src/remote_account_cloner_worker.rs | 2 +- .../src/state/changeset_chunks.rs | 2 +- magicblock-committor-service/src/commit/common.rs | 6 +++--- magicblock-committor-service/src/commit_stage.rs | 2 +- magicblock-committor-service/src/error.rs | 2 +- magicblock-committor-service/src/persist/db.rs | 2 +- magicblock-committor-service/src/persist/error.rs | 4 ++-- .../src/persist/types/commit_status.rs | 12 +++++++----- .../src/pubkeys_provider.rs | 2 +- magicblock-committor-service/src/service.rs | 15 ++++++++++++--- magicblock-committor-service/src/transactions.rs | 6 +++--- magicblock-table-mania/src/lookup_table.rs | 14 +++++++------- magicblock-table-mania/src/lookup_table_rc.rs | 12 ++++++------ programs/magicblock/src/magicblock_instruction.rs | 2 +- 14 files changed, 47 insertions(+), 36 deletions(-) diff --git a/magicblock-account-cloner/src/remote_account_cloner_worker.rs b/magicblock-account-cloner/src/remote_account_cloner_worker.rs index 72b242234..304231bf0 100644 --- a/magicblock-account-cloner/src/remote_account_cloner_worker.rs +++ b/magicblock-account-cloner/src/remote_account_cloner_worker.rs @@ -294,7 +294,7 @@ where let stream = stream::iter(account_keys); // NOTE: depending on the RPC provider we may get rate limited if we request // account states at a too high rate. - // I confirmed the the following concurrency working fine: + // I confirmed the following concurrency working fine: // Solana Mainnet: 10 // Helius: 20 // If we go higher than this we hit 429s which causes the fetcher to have to diff --git a/magicblock-committor-program/src/state/changeset_chunks.rs b/magicblock-committor-program/src/state/changeset_chunks.rs index d1e3333b6..b03c6427f 100644 --- a/magicblock-committor-program/src/state/changeset_chunks.rs +++ b/magicblock-committor-program/src/state/changeset_chunks.rs @@ -35,7 +35,7 @@ impl From<(&[u8], u32, u16)> for ChangesetChunk { } impl ChangesetChunk { - /// The index that the chunk will has in the [Chunks] tracker. + /// The index that the chunk will have in the [Chunks] tracker. pub fn chunk_idx(&self) -> u32 { self.offset / self.chunk_size as u32 } diff --git a/magicblock-committor-service/src/commit/common.rs b/magicblock-committor-service/src/commit/common.rs index ebfa0a1a1..f666ccba5 100644 --- a/magicblock-committor-service/src/commit/common.rs +++ b/magicblock-committor-service/src/commit/common.rs @@ -130,9 +130,9 @@ pub(crate) async fn send_and_confirm( start.elapsed().as_millis(), tables ); - let all_accounts = ixs.iter().flat_map(|ix| { - ix.accounts.iter().map(|x| x.pubkey).clone() - }); + let all_accounts = ixs + .iter() + .flat_map(|ix| ix.accounts.iter().map(|x| x.pubkey)); let keys_not_from_table = all_accounts .filter(|x| !keys_from_tables.contains(x)) .collect::>(); diff --git a/magicblock-committor-service/src/commit_stage.rs b/magicblock-committor-service/src/commit_stage.rs index 6e555ece1..1d7420372 100644 --- a/magicblock-committor-service/src/commit_stage.rs +++ b/magicblock-committor-service/src/commit_stage.rs @@ -88,7 +88,7 @@ pub enum CommitStage { /// initialized, but then this issue was detected. PartOfTooLargeBundleToProcess(CommitInfo), - /// The commmit was properly initialized and added to a chunk of instructions to process + /// The commit was properly initialized and added to a chunk of instructions to process /// commits via a transaction. For large commits the buffer and chunk accounts were properly /// prepared and haven't been closed. /// However that transaction failed. diff --git a/magicblock-committor-service/src/error.rs b/magicblock-committor-service/src/error.rs index 54344a978..d56b6e841 100644 --- a/magicblock-committor-service/src/error.rs +++ b/magicblock-committor-service/src/error.rs @@ -58,7 +58,7 @@ pub enum CommittorServiceError { solana_sdk::message::CompileError, ), - #[error("Task {0} failed to creqate transaction: {1} ({1:?})")] + #[error("Task {0} failed to create transaction: {1} ({1:?})")] FailedToCreateTransaction(String, solana_sdk::signer::SignerError), #[error("Could not find commit strategy for bundle {0}")] diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 8f00375f3..47a36ca05 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -40,7 +40,7 @@ pub struct CommitStatusRow { /// The current status of the commit /// Includes the bundle_id which will be the same for accounts whose commits /// need to be applied atomically in a single transaction - /// For single accounts a bundle_id will be gnerated as well for consistency + /// For single accounts a bundle_id will be generated as well for consistency /// For Pending commits the bundle_id is not set pub commit_status: CommitStatus, /// Time since epoch at which the commit was last retried diff --git a/magicblock-committor-service/src/persist/error.rs b/magicblock-committor-service/src/persist/error.rs index 4980225f1..1d5e75908 100644 --- a/magicblock-committor-service/src/persist/error.rs +++ b/magicblock-committor-service/src/persist/error.rs @@ -14,9 +14,9 @@ pub enum CommitPersistError { ParseSignatureError(#[from] solana_sdk::signature::ParseSignatureError), #[error("ParseHashError: '{0}' ({0:?})")] - ParseHahsError(#[from] solana_sdk::hash::ParseHashError), + ParseHashError(#[from] solana_sdk::hash::ParseHashError), - #[error("Invalid Commity Type: '{0}' ({0:?})")] + #[error("Invalid Commit Type: '{0}' ({0:?})")] InvalidCommitType(String), #[error("Invalid Commit Status: '{0}' ({0:?})")] diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index 38bcad998..e6964ecce 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -29,7 +29,7 @@ pub enum CommitStatus { /// The commit is part of a bundle that contains too many commits to be included /// in a single transaction. Thus we cannot commit any of them. PartOfTooLargeBundleToProcess(u64), - /// The commmit was properly initialized and added to a chunk of instructions to process + /// The commit was properly initialized and added to a chunk of instructions to process /// commits via a transaction. For large commits the buffer and chunk accounts were properly /// prepared and haven't been closed. FailedProcess((u64, CommitStrategy, Option)), @@ -134,9 +134,11 @@ impl if let Some(sigs) = sigs { sigs } else { - return Err(CommitPersistError::CommitStatusNeedsBundleId( - status.to_string(), - )); + return Err( + CommitPersistError::CommitStatusNeedsSignatures( + status.to_string(), + ), + ); } }; } @@ -181,7 +183,7 @@ pub struct CommitStatusSignatures { /// The signature of the transaction processing the commit pub process_signature: Signature, /// The signature of the transaction finalizing the commit. - /// If the account was not finalized or it failed the this is `None`. + /// If the account was not finalized or it failed then this is `None`. /// If the finalize instruction was part of the process transaction then /// this signature is the same as [Self::process_signature]. pub finalize_signature: Option, diff --git a/magicblock-committor-service/src/pubkeys_provider.rs b/magicblock-committor-service/src/pubkeys_provider.rs index d7ad1472e..b4c93a661 100644 --- a/magicblock-committor-service/src/pubkeys_provider.rs +++ b/magicblock-committor-service/src/pubkeys_provider.rs @@ -54,7 +54,7 @@ pub fn provide_common_pubkeys(validator: &Pubkey) -> HashSet { "Common pubkeys: validator: {} delegation program: {} - protoco fees vault: {} + protocol fees vault: {} validator fees vault: {} committor program: {}", validator, diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 4e022eea8..0cc1f3bd8 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -32,7 +32,7 @@ pub enum CommittorMessage { ReservePubkeysForCommittee { /// Called once the pubkeys have been reserved respond_to: oneshot::Sender>, - /// The comittee whose pubkeys to reserve in a lookup table + /// The committee whose pubkeys to reserve in a lookup table /// These pubkeys are used to process/finalize the commit committee: Pubkey, /// The owner program of the committee @@ -273,8 +273,17 @@ impl CommittorService { } fn try_send(&self, msg: CommittorMessage) { - if let Err(TrySendError::Full(msg)) = self.sender.try_send(msg) { - error!("Failed to send commit message {:?}", msg); + if let Err(e) = self.sender.try_send(msg) { + match e { + TrySendError::Full(msg) => error!( + "Channel full, failed to send commit message {:?}", + msg + ), + TrySendError::Closed(msg) => error!( + "Channel closed, failed to send commit message {:?}", + msg + ), + } } } } diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs index 63dfcddc7..33ba3d664 100644 --- a/magicblock-committor-service/src/transactions.rs +++ b/magicblock-committor-service/src/transactions.rs @@ -75,11 +75,11 @@ pub(crate) const MAX_UNDELEGATE_PER_TX: u8 = 3; pub(crate) const MAX_UNDELEGATE_PER_TX_USING_LOOKUP: u8 = 16; // Allows us to run undelegate instructions without rechunking them since we know -// that we didn't process more than we also can undelegatge +// that we didn't process more than we also can undelegate const_assert!(MAX_PROCESS_PER_TX <= MAX_UNDELEGATE_PER_TX,); // Allows us to run undelegate instructions using lookup tables without rechunking -// them since we know that we didn't process more than we also can undelegatge +// them since we know that we didn't process more than we also can undelegate const_assert!( MAX_PROCESS_PER_TX_USING_LOOKUP <= MAX_UNDELEGATE_PER_TX_USING_LOOKUP ); @@ -112,7 +112,7 @@ pub(crate) struct CommitTxReport { /// [MAX_ENCODED_TRANSACTION_SIZE]. pub size_args_with_lookup: Option, - /// The size of the transaction including the finalize instructionk + /// The size of the transaction including the finalize instruction /// when using lookup tables /// This is only determined if the [SizeOfCommitWithArgs::size_including_finalize] /// is larger than [MAX_ENCODED_TRANSACTION_SIZE]. diff --git a/magicblock-table-mania/src/lookup_table.rs b/magicblock-table-mania/src/lookup_table.rs index ad7cc7b68..dd0f6b0f3 100644 --- a/magicblock-table-mania/src/lookup_table.rs +++ b/magicblock-table-mania/src/lookup_table.rs @@ -158,7 +158,7 @@ impl LookupTable { } /// Returns `true` if the we requested to deactivate this table. - /// NOTE: this doesn't mean that the deactivation perios passed, thus + /// NOTE: this doesn't mean that the deactivation period passed, thus /// the table could still be considered _deactivating_ on chain. pub fn deactivate_triggered(&self) -> bool { use LookupTable::*; @@ -187,7 +187,7 @@ impl LookupTable { /// - **latest_slot**: the on chain slot at which we are creating the table /// - **sub_slot**: a bump to allow creating multiple lookup tables with the same authority /// at the same slot - /// - **pubkeys**: to extend the lookup table respecting respecting + /// - **pubkeys**: to extend the lookup table respecting /// solana_sdk::address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES] /// after it is initialized /// - **reqid**: id of the request adding the pubkeys @@ -270,7 +270,7 @@ impl LookupTable { /// The transaction is signed with the [Self::derived_auth]. /// /// - **rpc_client**: RPC client to use for sending the extend transaction - /// - **authority**: payer for the the extend transaction + /// - **authority**: payer for the extend transaction /// - **pubkeys**: to extend the lookup table with /// - **reqid**: id of the request adding the pubkeys pub async fn extend( @@ -335,7 +335,7 @@ impl LookupTable { /// The transaction is signed with the [Self::derived_auth]. /// /// - **rpc_client**: RPC client to use for sending the extend transaction - /// - **authority**: payer for the the extend transaction + /// - **authority**: payer for the extend transaction /// - **pubkeys**: to extend the lookup table with /// - **reqid**: id of the request adding the pubkeys /// @@ -371,7 +371,7 @@ impl LookupTable { /// Deactivates this lookup table. /// /// - **rpc_client**: RPC client to use for sending the deactivate transaction - /// - **authority**: pays for the the deactivate transaction + /// - **authority**: pays for the deactivate transaction pub async fn deactivate( &mut self, rpc_client: &MagicblockRpcClient, @@ -437,7 +437,7 @@ impl LookupTable { slot } }; - // NOTE: the solana exporer will show an account as _deactivated_ once we deactivate it + // NOTE: the solana explorer will show an account as _deactivated_ once we deactivate it // even though it is actually _deactivating_ // I tried to shorten the wait here but found that this is the minimum time needed // for the table to be considered fully _deactivated_ @@ -461,7 +461,7 @@ impl LookupTable { /// Checks if the table was deactivated and if so closes the table account. /// /// - **rpc_client**: RPC client to use for sending the close transaction - /// - **authority**: pays for the the close transaction and is refunded the + /// - **authority**: pays for the close transaction and is refunded the /// table account rent /// - **current_slot**: the current slot to use for checking deactivation pub async fn close( diff --git a/magicblock-table-mania/src/lookup_table_rc.rs b/magicblock-table-mania/src/lookup_table_rc.rs index 386a28edb..1450dbb1d 100644 --- a/magicblock-table-mania/src/lookup_table_rc.rs +++ b/magicblock-table-mania/src/lookup_table_rc.rs @@ -280,7 +280,7 @@ impl LookupTableRc { } /// Returns `true` if the we requested to deactivate this table. - /// NOTE: this doesn't mean that the deactivation perios passed, thus + /// NOTE: this doesn't mean that the deactivation period passed, thus /// the table could still be considered _deactivating_ on chain. pub fn deactivate_triggered(&self) -> bool { use LookupTableRc::*; @@ -424,7 +424,7 @@ impl LookupTableRc { /// They are automatically reserved for one requestor. /// /// - **rpc_client**: RPC client to use for sending the extend transaction - /// - **authority**: payer for the the extend transaction + /// - **authority**: payer for the extend transaction /// - **pubkeys**: to extend the lookup table with pub async fn extend( &self, @@ -490,7 +490,7 @@ impl LookupTableRc { /// The transaction is signed with the [Self::derived_auth]. /// /// - **rpc_client**: RPC client to use for sending the extend transaction - /// - **authority**: payer for the the extend transaction + /// - **authority**: payer for the extend transaction /// - **pubkeys**: to extend the lookup table with /// /// Returns: the pubkeys that were added to the table @@ -524,7 +524,7 @@ impl LookupTableRc { /// Deactivates this lookup table. /// /// - **rpc_client**: RPC client to use for sending the deactivate transaction - /// - **authority**: pays for the the deactivate transaction + /// - **authority**: pays for the deactivate transaction pub async fn deactivate( &mut self, rpc_client: &MagicblockRpcClient, @@ -593,7 +593,7 @@ impl LookupTableRc { slot } }; - // NOTE: the solana exporer will show an account as _deactivated_ once we deactivate it + // NOTE: the solana explorer will show an account as _deactivated_ once we deactivate it // even though it is actually _deactivating_ // I tried to shorten the wait here but found that this is the minimum time needed // for the table to be considered fully _deactivated_ @@ -617,7 +617,7 @@ impl LookupTableRc { /// Checks if the table was deactivated and if so closes the table account. /// /// - **rpc_client**: RPC client to use for sending the close transaction - /// - **authority**: pays for the the close transaction and is refunded the + /// - **authority**: pays for the close transaction and is refunded the /// table account rent /// - **current_slot**: the current slot to use for checking deactivation pub async fn close( diff --git a/programs/magicblock/src/magicblock_instruction.rs b/programs/magicblock/src/magicblock_instruction.rs index 036b572c5..2ecd39067 100644 --- a/programs/magicblock/src/magicblock_instruction.rs +++ b/programs/magicblock/src/magicblock_instruction.rs @@ -151,7 +151,7 @@ pub(crate) enum MagicBlockInstruction { /// - **1.** `[WRITE]` Magic Context Account containing the initially scheduled commits AcceptScheduleCommits, - /// Records the the attempt to realize a scheduled commit on chain. + /// Records the attempt to realize a scheduled commit on chain. /// /// The signature of this transaction can be pre-calculated since we pass the /// ID of the scheduled commit and retrieve the signature from a globally From 28504c12cf3fd1f04f9f67ef634f3f513edc3e47 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 09:28:55 +0545 Subject: [PATCH 048/199] chore: improved error handling in table mania manager --- magicblock-table-mania/src/manager.rs | 69 ++++++++++++++++----------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/magicblock-table-mania/src/manager.rs b/magicblock-table-mania/src/manager.rs index d2202a3ef..7b8960066 100644 --- a/magicblock-table-mania/src/manager.rs +++ b/magicblock-table-mania/src/manager.rs @@ -174,6 +174,9 @@ impl TableMania { let mut remaining = pubkeys.iter().cloned().collect::>(); let mut tables_used = HashSet::new(); + const MAX_ALLOWED_EXTEND_ERRORS: u8 = 5; + let mut extend_errors = 0; + // Keep trying to store pubkeys until we're done while !remaining.is_empty() { // First try to use existing tables @@ -186,14 +189,28 @@ impl TableMania { // Try to use the last table if it's not full if let Some(table) = active_tables_write_lock.last() { if !table.is_full() { - self.extend_table( - table, - authority, - &mut remaining, - &mut tables_used, - ) - .await; - stored_in_existing = true; + if let Err(err) = self + .extend_table( + table, + authority, + &mut remaining, + &mut tables_used, + ) + .await + { + error!( + "Error extending table {}: {:?}", + table.table_address(), + err + ); + if extend_errors >= MAX_ALLOWED_EXTEND_ERRORS { + extend_errors += 1; + } else { + return Err(err); + } + } else { + stored_in_existing = true; + } } } } @@ -243,7 +260,7 @@ impl TableMania { authority: &Keypair, remaining: &mut Vec, tables_used: &mut HashSet, - ) { + ) -> TableManiaResult<()> { let remaining_len = remaining.len(); let storing_len = remaining_len.min(MAX_ENTRIES_AS_PART_OF_EXTEND as usize); @@ -253,27 +270,21 @@ impl TableMania { remaining_len, table.table_address() ); - let table_addresses_count = table.pubkeys().unwrap().len(); + let Some(table_addresses_count) = table.pubkeys().map(|x| x.len()) + else { + return Err(TableManiaError::CannotExtendDeactivatedTable( + *table.table_address(), + )); + }; let storing = remaining[..storing_len].to_vec(); - match table + let stored = table .extend_respecting_capacity(&self.rpc_client, authority, &storing) - .await - { - Ok(stored) => { - trace!("Stored {}", stored.len()); - tables_used.insert(*table.table_address()); - remaining.retain(|pk| !stored.contains(pk)); - } - // TODO: this could cause us to loop forever as remaining - // is never updated, possibly we need to return an error - // here instead - Err(err) => error!( - "Error extending table {}: {:?}", - table.table_address(), - err - ), - } + .await?; + trace!("Stored {}", stored.len()); + tables_used.insert(*table.table_address()); + remaining.retain(|pk| !stored.contains(pk)); + let stored_count = remaining_len - remaining.len(); trace!("Stored {}, remaining: {}", stored_count, remaining.len()); @@ -281,6 +292,8 @@ impl TableMania { table_addresses_count + stored_count, table.pubkeys().unwrap().len() ); + + Ok(()) } async fn create_new_table_and_extend( @@ -660,7 +673,7 @@ impl TableMania { closed_tables.push(*deactivated_table.table_address()) } Ok(_) => { - // Table not ready to be closed" + // Table not ready to be closed } Err(err) => error!( "Error closing table {}: {:?}", From bc1324df8ec32c57127cffbe8621b686d0accc98 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 09:42:48 +0545 Subject: [PATCH 049/199] fix: greptiles --- test-integration/Makefile | 2 +- .../schedulecommit/committor-service/tests/ix_commit_local.rs | 3 ++- .../schedulecommit/test-scenarios/tests/utils/mod.rs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test-integration/Makefile b/test-integration/Makefile index c4fa08a4b..e1148af8a 100644 --- a/test-integration/Makefile +++ b/test-integration/Makefile @@ -7,7 +7,7 @@ RUST_LOG ?= 'warn,geyser_plugin=warn,magicblock=trace,rpc=trace,bank=trace,banki FLEXI_COUNTER_DIR := $(DIR)programs/flexi-counter SCHEDULECOMMIT_DIR := $(DIR)programs/schedulecommit SCHEDULECOMMIT_SECURITY_DIR := $(DIR)programs/schedulecommit-security -COMMITTOR_PROGRAM_DIR := $(DIR)../magicblock-committor-program/ +COMMITTOR_PROGRAM_DIR := $(DIR)../magicblock-committor-program FLEXI_COUNTER_SRC := $(shell find $(FLEXI_COUNTER_DIR) -name '*.rs' -o -name '*.toml') SCHEDULECOMMIT_SRC := $(shell find $(SCHEDULECOMMIT_DIR) -name '*.rs' -o -name '*.toml') diff --git a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs index 5ba085e13..7e0dfe389 100644 --- a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs +++ b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs @@ -872,7 +872,8 @@ async fn ix_commit_local( ); if Instant::now() - start > MAX_TIME_TO_CLOSE { panic!( - "Timed out waiting for tables close. Still open: {}", + "Timed out waiting for tables close after {} seconds. Still open: {}", + MAX_TIME_TO_CLOSE.as_secs(), closing_tables .iter() .map(|x| x.to_string()) diff --git a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs index 13ac51715..81f61477a 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs @@ -222,7 +222,7 @@ pub fn assert_account_was_undelegated_on_chain( let owner = ctx.fetch_chain_account_owner(pda).unwrap(); assert_ne!( owner, DELEGATION_PROGRAM_ID, - "{} not owned by delegation program", + "{} should not be owned by delegation program", pda ); assert_eq!(owner, new_owner, "{} has new owner", pda); From 644ad1c9f9186ddf8cba9e63437af3e0e29fd0b6 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 09:46:22 +0545 Subject: [PATCH 050/199] chore: demote some no longer urgent TODOs --- magicblock-api/src/magic_validator.rs | 4 ++-- magicblock-geyser-plugin/src/grpc.rs | 2 +- magicblock-rpc/src/transaction.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 32224fb35..d368002e2 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -174,7 +174,7 @@ impl MagicValidator { config: MagicValidatorConfig, identity_keypair: Keypair, ) -> ApiResult { - // TODO(thlorenz): @@ this will need to be recreated on each start + // TODO(thlorenz): this will need to be recreated on each start let token = CancellationToken::new(); let (geyser_manager, geyser_rpc_service) = @@ -650,7 +650,7 @@ impl MagicValidator { } async fn ensure_validator_funded_on_chain(&self) -> ApiResult<()> { - // TODO: @@@ configurable? + // TODO(thlorenz) make this configurable in the future const MIN_BALANCE_SOL: u64 = 5; // TODO: @@ duplicate code getting remote_rpc_config let accounts_config = try_convert_accounts_config( diff --git a/magicblock-geyser-plugin/src/grpc.rs b/magicblock-geyser-plugin/src/grpc.rs index aa060e6fe..1a74dc3f4 100644 --- a/magicblock-geyser-plugin/src/grpc.rs +++ b/magicblock-geyser-plugin/src/grpc.rs @@ -144,7 +144,7 @@ impl GrpcService { block_fail_action: ConfigBlockFailAction, ) { const PROCESSED_MESSAGES_MAX: usize = 31; - // TODO(thlorenz): @@@ This could become a bottleneck affecting latency + // TODO(thlorenz): This could become a bottleneck affecting latency const PROCESSED_MESSAGES_SLEEP: Duration = Duration::from_millis(10); let mut messages: BTreeMap = Default::default(); diff --git a/magicblock-rpc/src/transaction.rs b/magicblock-rpc/src/transaction.rs index 7113ace1d..9249c4493 100644 --- a/magicblock-rpc/src/transaction.rs +++ b/magicblock-rpc/src/transaction.rs @@ -213,7 +213,7 @@ pub(crate) async fn send_transaction( /// Verifies only the transaction signature and is used when sending a /// transaction to avoid the extra overhead of [sig_verify_transaction_and_check_precompiles] -/// TODO(thlorenz): @@ sigverify takes upwards of 90µs which is 30%+ of +/// TODO(thlorenz): sigverify takes upwards of 90µs which is 30%+ of /// the entire time it takes to execute a transaction. /// Therefore this an intermediate solution and we need to investigate verifying the /// wire_transaction instead (solana sigverify implementation is packet based) From 4f8ecc8f64903286e6a5a5d4dbecc0de7d800030 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 09:53:13 +0545 Subject: [PATCH 051/199] feat: committor service persists into ledger path --- magicblock-api/src/magic_validator.rs | 16 +++++++++++----- magicblock-committor-service/src/service.rs | 9 +++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index d368002e2..cf07b225f 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -198,22 +198,23 @@ impl MagicValidator { config.validator_config.ledger.reset, )?; - let exit = Arc::::default(); // SAFETY: // this code will never panic as the ledger_path always appends the // rocksdb directory to whatever path is preconfigured for the ledger, // see `Ledger::do_open`, thus this path will always have a parent - let adb_path = ledger + let ledger_parent_path = ledger .ledger_path() .parent() .expect("ledger_path didn't have a parent, should never happen"); + + let exit = Arc::::default(); let bank = Self::init_bank( Some(geyser_manager.clone()), &genesis_config, &config.validator_config.accounts.db, config.validator_config.validator.millis_per_slot, validator_pubkey, - adb_path, + ledger_parent_path, ledger.get_max_blockhash().map(|(slot, _)| slot)?, )?; @@ -310,10 +311,15 @@ impl MagicValidator { &faucet_keypair.pubkey(), ); + let committor_persist_path = + ledger_parent_path.join("committor_service.sqlite"); + debug!( + "Committor service persists to: {}", + committor_persist_path.display() + ); let committor_service = Arc::new(CommittorService::try_start( identity_keypair.insecure_clone(), - // TODO: @@@ config or inside ledger dir - "/tmp/committor_service.sqlite", + committor_persist_path, ChainConfig { rpc_uri: remote_rpc_config.url().to_string(), commitment: remote_rpc_config diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 0cc1f3bd8..41c5fa69d 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -1,4 +1,4 @@ -use std::{fmt::Display, path::Path}; +use std::path::Path; use log::*; use magicblock_committor_program::Changeset; @@ -205,12 +205,9 @@ impl CommittorService { chain_config: ChainConfig, ) -> CommittorServiceResult where - P: Display + AsRef, + P: AsRef, { - debug!( - "Starting committor service with config: {:?}, persisting to: {}", - chain_config, persist_file - ); + debug!("Starting committor service with config: {:?}", chain_config); let (sender, receiver) = mpsc::channel(1_000); let cancel_token = CancellationToken::new(); { From 3cf473da8ee703727551cdc2b52e49c0ffa46b42 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 10:09:51 +0545 Subject: [PATCH 052/199] chore: remove duplicate code in magic validator --- magicblock-api/src/magic_validator.rs | 40 +++++++++++++-------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index cf07b225f..cad2f8b5a 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -270,14 +270,10 @@ impl MagicValidator { None }; - let accounts_config = - try_convert_accounts_config(&config.validator_config.accounts) - .map_err(ApiError::ConfigError)?; - - let remote_rpc_config = RpcProviderConfig::new( - try_rpc_cluster_from_cluster(&accounts_config.remote_cluster)?, - Some(CommitmentLevel::Confirmed), - ); + let (accounts_config, remote_rpc_config) = + try_get_remote_accounts_and_rpc_config( + &config.validator_config.accounts, + )?; let remote_account_fetcher_worker = RemoteAccountFetcherWorker::new(remote_rpc_config.clone()); @@ -656,20 +652,10 @@ impl MagicValidator { } async fn ensure_validator_funded_on_chain(&self) -> ApiResult<()> { - // TODO(thlorenz) make this configurable in the future + // NOTE: 5 SOL seems reasonable, but we may require a different amount in the future const MIN_BALANCE_SOL: u64 = 5; - // TODO: @@ duplicate code getting remote_rpc_config - let accounts_config = try_convert_accounts_config( - &self.config.accounts, - ) - .expect( - "Failed to derive accounts config from provided magicblock config", - ); - let remote_rpc_config = RpcProviderConfig::new( - try_rpc_cluster_from_cluster(&accounts_config.remote_cluster)?, - Some(CommitmentLevel::Confirmed), - ); - + let (_, remote_rpc_config) = + try_get_remote_accounts_and_rpc_config(&self.config.accounts)?; let validator_pubkey = self.bank().get_identity(); let lamports = RpcClient::new_with_commitment( @@ -895,3 +881,15 @@ fn create_worker_runtime(thread_name: &str) -> tokio::runtime::Runtime { .build() .unwrap() } + +fn try_get_remote_accounts_and_rpc_config( + accounts: &magicblock_config::AccountsConfig, +) -> ApiResult<(magicblock_accounts::AccountsConfig, RpcProviderConfig)> { + let accounts_config = + try_convert_accounts_config(accounts).map_err(ApiError::ConfigError)?; + let remote_rpc_config = RpcProviderConfig::new( + try_rpc_cluster_from_cluster(&accounts_config.remote_cluster)?, + Some(CommitmentLevel::Confirmed), + ); + Ok((accounts_config, remote_rpc_config)) +} From a7b4aa5e256f778981fb2b78f48b59ca40ad00d5 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 10:30:04 +0545 Subject: [PATCH 053/199] feat: limiting stale reallocs until we bail --- .../src/commit/commit_using_buffer.rs | 34 ++++++++++++++++--- .../src/commit_stage.rs | 7 ++++ magicblock-committor-service/src/error.rs | 18 ++-------- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs index 1c15bd7fb..3e161fb8c 100644 --- a/magicblock-committor-service/src/commit/commit_using_buffer.rs +++ b/magicblock-committor-service/src/commit/commit_using_buffer.rs @@ -51,6 +51,7 @@ use crate::{ struct NextReallocs { missing_size: u64, start_idx: usize, + err: Option, } impl CommittorProcessor { @@ -826,11 +827,30 @@ impl CommittorProcessor { blockhash: ephemeral_blockhash, }; + const MAX_STALE_REALLOCS: u8 = 10; + let mut prev_missing_size = 0; + let mut remaining_tries = MAX_STALE_REALLOCS; while let Some(NextReallocs { missing_size, start_idx, + err, }) = next_reallocs { + if missing_size == prev_missing_size { + remaining_tries -= 1; + if remaining_tries == 0 { + return Err( + CommitAccountError::ReallocBufferRanOutOfRetries( + err.unwrap_or("No Error".to_string()), + Arc::new(commit_info.clone()), + commit_strategy, + ), + ); + } + } else { + remaining_tries = MAX_STALE_REALLOCS; + prev_missing_size = missing_size; + } let realloc_ixs = { let realloc_ixs = create_realloc_buffer_ixs_to_add_remaining( @@ -849,7 +869,6 @@ impl CommittorProcessor { start_idx, ) .await; - // TODO(thlorenz): give up at some point } } } @@ -882,6 +901,7 @@ impl CommittorProcessor { return Some(NextReallocs { missing_size, start_idx, + err: Some(format!("{:?}", err)), }); } }; @@ -923,23 +943,27 @@ impl CommittorProcessor { if current_size as u64 >= desired_size { None } else { - Some(desired_size - current_size as u64) + Some((desired_size - current_size as u64, None)) } } // NOTE: if we cannot get the account we must assume that // the entire size we just tried to alloc is still missing Ok(None) => { warn!("buffer account not found"); - Some(missing_size) + Some(( + missing_size, + Some("buffer account not found".to_string()), + )) } Err(err) => { warn!("Failed to get buffer account: {:?}", err); - Some(missing_size) + Some((missing_size, Some(format!("{:?}", err)))) } } - .map(|missing_size| NextReallocs { + .map(|(missing_size, err)| NextReallocs { missing_size, start_idx: count, + err, }) } diff --git a/magicblock-committor-service/src/commit_stage.rs b/magicblock-committor-service/src/commit_stage.rs index 1d7420372..41d50359b 100644 --- a/magicblock-committor-service/src/commit_stage.rs +++ b/magicblock-committor-service/src/commit_stage.rs @@ -142,6 +142,13 @@ impl From for CommitStage { commit_strategy, )) } + ReallocBufferRanOutOfRetries(err, commit_info, commit_strategy) => { + warn!("Realloc buffer ran out of retries: {:?}", err); + Self::BufferAndChunkPartiallyInitialized(( + ci!(commit_info), + commit_strategy, + )) + } WriteChunksRanOutOfRetries(err, commit_info, commit_strategy) => { warn!("Write chunks ran out of retries: {:?}", err); Self::BufferAndChunkPartiallyInitialized(( diff --git a/magicblock-committor-service/src/error.rs b/magicblock-committor-service/src/error.rs index d56b6e841..bf0555195 100644 --- a/magicblock-committor-service/src/error.rs +++ b/magicblock-committor-service/src/error.rs @@ -102,6 +102,9 @@ pub enum CommitAccountError { #[error("Failed to deserialize chunks account: {0} ({0:?})")] DeserializeChunksAccount(std::io::Error, Arc, CommitStrategy), + #[error("Failed to affect remaining size via realloc buffer after max retries. Last error {0}")] + ReallocBufferRanOutOfRetries(String, Arc, CommitStrategy), + #[error("Failed to write complete chunks of commit data after max retries. Last write error {0:?}")] WriteChunksRanOutOfRetries( Option, @@ -109,18 +112,3 @@ pub enum CommitAccountError { CommitStrategy, ), } - -impl CommitAccountError { - pub fn into_commit_info(self) -> CommitInfo { - use CommitAccountError::*; - let ci = match self { - InitBufferAndChunkAccounts(_, commit_info, _) => { - return *commit_info; - } - GetChunksAccount(_, commit_info, _) => commit_info, - DeserializeChunksAccount(_, commit_info, _) => commit_info, - WriteChunksRanOutOfRetries(_, commit_info, _) => commit_info, - }; - Arc::::unwrap_or_clone(ci) - } -} From 776bbf147b5e24b91b03c686c9c61c0ef7887e61 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 12:10:14 +0545 Subject: [PATCH 054/199] tmp: disabling ledger restore tests to isolate issues --- test-integration/test-runner/bin/run_tests.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index f735d7c07..1d95f2946 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -33,10 +33,10 @@ pub fn main() { return; }; - let Ok(restore_ledger_output) = run_restore_ledger_tests(&manifest_dir) - else { - return; - }; + // let Ok(restore_ledger_output) = run_restore_ledger_tests(&manifest_dir) + // else { + // return; + // }; let Ok(magicblock_api_output) = run_magicblock_api_tests(&manifest_dir) else { @@ -54,7 +54,7 @@ pub fn main() { assert_cargo_tests_passed(scenarios_output); assert_cargo_tests_passed(cloning_output); assert_cargo_tests_passed(issues_frequent_commits_output); - assert_cargo_tests_passed(restore_ledger_output); + // assert_cargo_tests_passed(restore_ledger_output); assert_cargo_tests_passed(magicblock_api_output); assert_cargo_tests_passed(table_mania_output); assert_cargo_tests_passed(committor_output); From aeeb5ae5f855cd691032691c6c29061744aa7ec8 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 12:11:43 +0545 Subject: [PATCH 055/199] tmp: disable all workflows but integration tests while isolating issues --- .github/workflows/ci-fmt.yml | 3 --- .github/workflows/ci-lint.yml | 3 --- .github/workflows/ci-test-unit.yml | 3 --- 3 files changed, 9 deletions(-) diff --git a/.github/workflows/ci-fmt.yml b/.github/workflows/ci-fmt.yml index 6feb3ed35..ae5f7d338 100644 --- a/.github/workflows/ci-fmt.yml +++ b/.github/workflows/ci-fmt.yml @@ -1,9 +1,6 @@ on: push: branches: [master] - pull_request: - branches: ["*"] - types: [opened, reopened, synchronize, ready_for_review] name: Run CI - Format diff --git a/.github/workflows/ci-lint.yml b/.github/workflows/ci-lint.yml index a59dc15e4..e30adc915 100644 --- a/.github/workflows/ci-lint.yml +++ b/.github/workflows/ci-lint.yml @@ -1,9 +1,6 @@ on: push: branches: [master] - pull_request: - branches: ["*"] - types: [opened, reopened, synchronize, ready_for_review] name: Run CI - Lint diff --git a/.github/workflows/ci-test-unit.yml b/.github/workflows/ci-test-unit.yml index fa8d84ea0..28c96e584 100644 --- a/.github/workflows/ci-test-unit.yml +++ b/.github/workflows/ci-test-unit.yml @@ -1,9 +1,6 @@ on: push: branches: [master] - pull_request: - branches: ["*"] - types: [opened, reopened, synchronize, ready_for_review] name: Run CI - Unit Tests From aedf9a2adcdc97bc785d77fda3073037be5c882b Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 17:10:39 +0545 Subject: [PATCH 056/199] fix: ordering of worker startups --- magicblock-api/src/magic_validator.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index cad2f8b5a..68dad7722 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -712,9 +712,12 @@ impl MagicValidator { self.token.clone(), )); - self.start_remote_account_cloner_worker().await?; + // NOTE: these need to startup in the right order, otherwise some worker + // that may be needed, i.e. during hydration after ledger replay + // are not started in time self.start_remote_account_fetcher_worker(); self.start_remote_account_updates_worker(); + self.start_remote_account_cloner_worker().await?; self.ledger_truncator.start(); From 1e9921d216a668f880bcd194d63e72dbcf70cc7d Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 17:11:39 +0545 Subject: [PATCH 057/199] Revert "tmp: disabling ledger restore tests to isolate issues" This reverts commit 776bbf147b5e24b91b03c686c9c61c0ef7887e61. --- test-integration/test-runner/bin/run_tests.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index 1d95f2946..f735d7c07 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -33,10 +33,10 @@ pub fn main() { return; }; - // let Ok(restore_ledger_output) = run_restore_ledger_tests(&manifest_dir) - // else { - // return; - // }; + let Ok(restore_ledger_output) = run_restore_ledger_tests(&manifest_dir) + else { + return; + }; let Ok(magicblock_api_output) = run_magicblock_api_tests(&manifest_dir) else { @@ -54,7 +54,7 @@ pub fn main() { assert_cargo_tests_passed(scenarios_output); assert_cargo_tests_passed(cloning_output); assert_cargo_tests_passed(issues_frequent_commits_output); - // assert_cargo_tests_passed(restore_ledger_output); + assert_cargo_tests_passed(restore_ledger_output); assert_cargo_tests_passed(magicblock_api_output); assert_cargo_tests_passed(table_mania_output); assert_cargo_tests_passed(committor_output); From 0e0ef0f485866db83f31e9eb490ec2660072ea5a Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 16 May 2025 17:11:54 +0545 Subject: [PATCH 058/199] Revert "tmp: disable all workflows but integration tests while isolating issues" This reverts commit aeeb5ae5f855cd691032691c6c29061744aa7ec8. --- .github/workflows/ci-fmt.yml | 3 +++ .github/workflows/ci-lint.yml | 3 +++ .github/workflows/ci-test-unit.yml | 3 +++ 3 files changed, 9 insertions(+) diff --git a/.github/workflows/ci-fmt.yml b/.github/workflows/ci-fmt.yml index ae5f7d338..6feb3ed35 100644 --- a/.github/workflows/ci-fmt.yml +++ b/.github/workflows/ci-fmt.yml @@ -1,6 +1,9 @@ on: push: branches: [master] + pull_request: + branches: ["*"] + types: [opened, reopened, synchronize, ready_for_review] name: Run CI - Format diff --git a/.github/workflows/ci-lint.yml b/.github/workflows/ci-lint.yml index e30adc915..a59dc15e4 100644 --- a/.github/workflows/ci-lint.yml +++ b/.github/workflows/ci-lint.yml @@ -1,6 +1,9 @@ on: push: branches: [master] + pull_request: + branches: ["*"] + types: [opened, reopened, synchronize, ready_for_review] name: Run CI - Lint diff --git a/.github/workflows/ci-test-unit.yml b/.github/workflows/ci-test-unit.yml index 28c96e584..fa8d84ea0 100644 --- a/.github/workflows/ci-test-unit.yml +++ b/.github/workflows/ci-test-unit.yml @@ -1,6 +1,9 @@ on: push: branches: [master] + pull_request: + branches: ["*"] + types: [opened, reopened, synchronize, ready_for_review] name: Run CI - Unit Tests From 2bfd49f508f23291f3af5a18a108f6e14b729299 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 4 Jun 2025 11:37:40 +0545 Subject: [PATCH 059/199] chore: address nits --- .../src/account_cloner.rs | 4 +++- .../src/commit_strategy.rs | 19 ++++++++----------- magicblock-table-mania/src/derive_keypair.rs | 6 ++++++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/magicblock-account-cloner/src/account_cloner.rs b/magicblock-account-cloner/src/account_cloner.rs index 03e476cab..290440c51 100644 --- a/magicblock-account-cloner/src/account_cloner.rs +++ b/magicblock-account-cloner/src/account_cloner.rs @@ -76,7 +76,9 @@ pub async fn map_committor_request_result( res.await .map_err(|err| { // Send request error - AccountClonerError::CommittorSerivceError(format!("{:?}", err)) + AccountClonerError::CommittorSerivceError(format!( + "error sending request {err:?}" + )) })? .map_err(|err| { // Commit error diff --git a/magicblock-committor-service/src/commit_strategy.rs b/magicblock-committor-service/src/commit_strategy.rs index 22ac79921..28e64257e 100644 --- a/magicblock-committor-service/src/commit_strategy.rs +++ b/magicblock-committor-service/src/commit_strategy.rs @@ -171,55 +171,52 @@ pub fn split_changesets_by_commit_strategy( let changeset_bundles = changeset.into_small_changeset_bundles(); for bundle in changeset_bundles.bundles.into_iter() { let commit_strategy = - CommitBundleStrategy::try_from((bundle, finalize)); + CommitBundleStrategy::try_from((bundle, finalize))?; match commit_strategy { - Ok(CommitBundleStrategy::Args(bundle)) => { + CommitBundleStrategy::Args(bundle) => { add_to_changeset( &mut args_changeset, &accounts_to_undelegate, bundle, ); } - Ok(CommitBundleStrategy::ArgsIncludeFinalize(bundle)) => { + CommitBundleStrategy::ArgsIncludeFinalize(bundle) => { add_to_changeset( &mut args_including_finalize_changeset, &accounts_to_undelegate, bundle, ); } - Ok(CommitBundleStrategy::ArgsWithLookupTable(bundle)) => { + CommitBundleStrategy::ArgsWithLookupTable(bundle) => { add_to_changeset( &mut args_with_lookup_changeset, &accounts_to_undelegate, bundle, ); } - Ok(CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable( + CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable( bundle, - )) => { + ) => { add_to_changeset( &mut args_including_finalize_with_lookup_changeset, &accounts_to_undelegate, bundle, ); } - Ok(CommitBundleStrategy::FromBuffer(bundle)) => { + CommitBundleStrategy::FromBuffer(bundle) => { add_to_changeset( &mut from_buffer_changeset, &accounts_to_undelegate, bundle, ); } - Ok(CommitBundleStrategy::FromBufferWithLookupTable(bundle)) => { + CommitBundleStrategy::FromBufferWithLookupTable(bundle) => { add_to_changeset( &mut from_buffer_with_lookup_changeset, &accounts_to_undelegate, bundle, ); } - Err(err) => { - return Err(err); - } } } diff --git a/magicblock-table-mania/src/derive_keypair.rs b/magicblock-table-mania/src/derive_keypair.rs index be3315eaa..f6c75bc9b 100644 --- a/magicblock-table-mania/src/derive_keypair.rs +++ b/magicblock-table-mania/src/derive_keypair.rs @@ -1,6 +1,12 @@ use ed25519_dalek::{PublicKey, SecretKey}; use solana_sdk::{clock::Slot, signature::Keypair, signer::Signer}; +/// This derives a keypair from the provided authority keypair, and given seeds which +/// here are slot and sub_slot. +/// Its goal is to be deterministic such that a keypair can be _found_ at a later date +/// given the same authority, cycling through slot/sub_slot combinations. +/// Using slot and sub_slot as seeds allows is only one option and we may change this +/// to use a different source for seeds in the future (as long as they are deterministic). pub fn derive_keypair( authority: &Keypair, slot: Slot, From 4d1b44f1e57f08393176a4729a71aeec2eda572f Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 4 Jun 2025 15:13:56 +0545 Subject: [PATCH 060/199] chore: update cargo lock files --- Cargo.lock | 2 +- test-integration/Cargo.lock | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c48affea4..dce0e98f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3547,7 +3547,7 @@ dependencies = [ [[package]] name = "magic-domain-program" version = "0.0.1" -source = "git+https://github.com/magicblock-labs/magic-domain-program.git?rev=ea04d46#ea04d4646ede8e19307683d288e582bf60a3547a" +source = "git+https://github.com/magicblock-labs/magic-domain-program.git?rev=eba7644#eba76443b39047e1be1dd5a1d72fc1943e5e1fc0" dependencies = [ "borsh 1.5.5", "bytemuck_derive", diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 24bb4369b..e48387bb4 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -3465,6 +3465,16 @@ dependencies = [ "solana-program", ] +[[package]] +name = "magic-domain-program" +version = "0.0.1" +source = "git+https://github.com/magicblock-labs/magic-domain-program.git?rev=eba7644#eba76443b39047e1be1dd5a1d72fc1943e5e1fc0" +dependencies = [ + "borsh 1.5.7", + "bytemuck_derive", + "solana-program", +] + [[package]] name = "magicblock-account-cloner" version = "0.1.2" @@ -3601,7 +3611,7 @@ dependencies = [ "itertools 0.14.0", "libloading 0.7.4", "log", - "magic-domain-program", + "magic-domain-program 0.0.1 (git+https://github.com/magicblock-labs/magic-domain-program.git?rev=eba7644)", "magicblock-account-cloner", "magicblock-account-dumper", "magicblock-account-fetcher", @@ -10099,7 +10109,7 @@ dependencies = [ "integration-test-tools", "isocountry", "lazy_static", - "magic-domain-program", + "magic-domain-program 0.0.1 (git+https://github.com/magicblock-labs/magic-domain-program.git?rev=ea04d46)", "magicblock-api", "solana-rpc-client", "solana-sdk", From 9e091fca32a2fd47bd8f3879f6f52ba385d61b5a Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 4 Jun 2025 15:53:57 +0545 Subject: [PATCH 061/199] chore: match mdp version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dce0e98f0..c48affea4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3547,7 +3547,7 @@ dependencies = [ [[package]] name = "magic-domain-program" version = "0.0.1" -source = "git+https://github.com/magicblock-labs/magic-domain-program.git?rev=eba7644#eba76443b39047e1be1dd5a1d72fc1943e5e1fc0" +source = "git+https://github.com/magicblock-labs/magic-domain-program.git?rev=ea04d46#ea04d4646ede8e19307683d288e582bf60a3547a" dependencies = [ "borsh 1.5.5", "bytemuck_derive", diff --git a/Cargo.toml b/Cargo.toml index 14857532d..e0ac42345 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,7 +92,7 @@ lazy_static = "1.4.0" libc = "0.2.153" libloading = "0.7.4" log = "0.4.20" -magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "eba7644", default-features = false } +magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "ea04d46", default-features = false } magicblock-account-cloner = { path = "./magicblock-account-cloner" } magicblock-account-dumper = { path = "./magicblock-account-dumper" } magicblock-account-fetcher = { path = "./magicblock-account-fetcher" } From b7b6e4b0cb3b796b6e8a564d63261efcaab4f745 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 15 May 2025 17:25:36 +0900 Subject: [PATCH 062/199] feat: added construction of ScheduleAction --- programs/magicblock/src/magic_context.rs | 364 +++++++++++++++++- .../magicblock/src/magicblock_instruction.rs | 46 ++- .../magicblock/src/magicblock_processor.rs | 8 + .../src/schedule_transactions/mod.rs | 8 +- .../process_schedule_action.rs | 137 +++++++ .../process_schedule_commit.rs | 13 +- programs/magicblock/src/utils/accounts.rs | 19 +- 7 files changed, 583 insertions(+), 12 deletions(-) create mode 100644 programs/magicblock/src/schedule_transactions/process_schedule_action.rs diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index c50f2e90d..7e2541f94 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -1,13 +1,29 @@ -use std::mem; +use std::{collections::HashSet, mem}; use magicblock_core::magic_program; use serde::{Deserialize, Serialize}; +use solana_log_collector::ic_msg; +use solana_program_runtime::{ + __private::InstructionError, invoke_context::InvokeContext, +}; use solana_sdk::{ account::{AccountSharedData, ReadableAccount}, clock::Slot, hash::Hash, pubkey::Pubkey, transaction::Transaction, + transaction_context::TransactionContext, +}; + +use crate::{ + magicblock_instruction::{ + scheduled_commit_sent, CallHandlerArgs, CommitAndUndelegateArgs, + CommitTypeArgs, HandlerArgs, MagicActionArgs, UndelegateTypeArgs, + }, + utils::accounts::{ + get_instruction_account_short_meta_with_idx, + get_instruction_account_with_idx, get_instruction_pubkey_with_idx, + }, }; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -35,6 +51,352 @@ pub struct ScheduledCommit { pub request_undelegation: bool, } +// New impl +pub struct ScheduleAction { + pub id: u64, + pub slot: Slot, + pub blockhash: Hash, + pub commit_sent_transaction: Transaction, + pub payer: Pubkey, + // Scheduled action + pub action: Action, +} + +impl ScheduleAction { + pub fn try_new<'a>( + args: &MagicActionArgs, + commit_id: u64, + slot: Slot, + payer_pubkey: &Pubkey, + context: &ConstructionContext<'a, '_>, + ) -> Result { + let action = Action::try_from_args(args, &context)?; + + let blockhash = context.invoke_context.environment_config.blockhash; + let commit_sent_transaction = + scheduled_commit_sent(commit_id, blockhash); + let commit_sent_sig = commit_sent_transaction.signatures[0]; + + Ok(ScheduleAction { + id: commit_id, + slot, + blockhash, + payer: *payer_pubkey, + commit_sent_transaction, + action, + }) + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct Handler { + pub escrow_index: u8, + pub data: Vec, +} + +impl From for Handler { + fn from(value: HandlerArgs) -> Self { + Self { + escrow_index: value.escrow_index, + data: value.data, + } + } +} + +impl From<&HandlerArgs> for Handler { + fn from(value: &HandlerArgs) -> Self { + value.clone().into() + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct ShortAccountMeta { + pub pubkey: Pubkey, + pub is_writable: bool, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct CallHandler { + pub destination_program: Pubkey, + pub data_per_program: Handler, + pub account_metas_per_program: Vec, +} + +impl CallHandler { + pub fn try_from_args<'a>( + args: &CallHandlerArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + let destination_program_pubkey = *get_instruction_pubkey_with_idx( + context.transaction_context, + args.destination_program as u16, + )?; + let destination_program = get_instruction_account_with_idx( + context.transaction_context, + args.destination_program as u16, + )?; + + if !destination_program.borrow().executable() { + ic_msg!( + context.invoke_context, + &format!( + "CallHandler: destination_program must be an executable. got: {}", + destination_program_pubkey + ) + ); + return Err(InstructionError::AccountNotExecutable); + } + + let account_metas = args + .accounts + .iter() + .map(|i| { + get_instruction_account_short_meta_with_idx( + context.transaction_context, + *i as u16, + ) + }) + .collect::, InstructionError>>()?; + + Ok(CallHandler { + destination_program: destination_program_pubkey, + data_per_program: args.args.clone().into(), + account_metas_per_program: account_metas, + }) + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct CommittedAccountV2 { + pub short_meta: ShortAccountMeta, + // TODO(GabrielePicco): We should read the owner from the delegation record rather + // than deriving/storing it. To remove once the cloning pipeline allow us to easily access the owner. + pub owner: Pubkey, +} + +pub enum CommitType { + /// Regular commit without actions + Standalone(Vec), // accounts to commit + /// Commits accounts and runs actions + WithHandler { + committed_accounts: Vec, + call_handlers: Vec, + }, +} + +impl CommitType { + fn validate_accounts<'a>( + account_indices: &[u8], + context: &ConstructionContext<'a, '_>, + ) -> Result<(), InstructionError> { + account_indices.iter().try_for_each(|index| { + let acc_pubkey = get_instruction_pubkey_with_idx(context.transaction_context, *index as u16)?; + let acc = get_instruction_account_with_idx(context.transaction_context, *index as u16)?; + let acc_owner = *acc.borrow().owner(); + + if context.parent_program_id.as_ref() != Some(acc_pubkey) && !context.signers.contains(acc_pubkey) { + match context.parent_program_id { + None => { + ic_msg!( + context.invoke_context, + "ScheduleCommit ERR: failed to find parent program id" + ); + Err(InstructionError::InvalidInstructionData) + } + Some(parent_id) => { + ic_msg!( + context.invoke_context, + "ScheduleCommit ERR: account {} must be owned by {} or be a signer, but is owned by {}", + acc_pubkey, parent_id, acc_owner + ); + Err(InstructionError::InvalidAccountOwner) + } + } + } else { + Ok(()) + } + }) + } + + fn extract_commit_accounts<'a>( + account_indices: &[u8], + context: &ConstructionContext<'a, '_>, + ) -> Result, InstructionError> { + account_indices + .iter() + .map(|i| { + let account = get_instruction_account_with_idx( + context.transaction_context, + *i as u16, + )?; + let owner = *account.borrow().owner(); + let short_meta = get_instruction_account_short_meta_with_idx( + context.transaction_context, + *i as u16, + )?; + + Ok(CommittedAccountV2 { + short_meta, + owner: context.parent_program_id.unwrap_or(owner), + }) + }) + .collect::, InstructionError>>() + } + + pub fn try_from_args<'a>( + args: &CommitTypeArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + match args { + CommitTypeArgs::Standalone(accounts) => { + Self::validate_accounts(accounts, context)?; + let committed_accounts = + Self::extract_commit_accounts(accounts, context)?; + + Ok(CommitType::Standalone(committed_accounts)) + } + CommitTypeArgs::WithHandler { + committed_accounts, + call_handlers, + } => { + Self::validate_accounts(committed_accounts, context)?; + let committed_accounts = + Self::extract_commit_accounts(committed_accounts, context)?; + let call_handlers = call_handlers + .iter() + .map(|args| CallHandler::try_from_args(args, context)) + .collect::, InstructionError>>()?; + + Ok(CommitType::WithHandler { + committed_accounts, + call_handlers, + }) + } + } + } +} + +/// No CommitedAccounts since it is only used with CommitAction. +pub enum UndelegateType { + Standalone, + WithHandler(Vec), +} + +impl UndelegateType { + pub fn try_from_args<'a>( + args: &UndelegateTypeArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + match args { + UndelegateTypeArgs::Standalone => Ok(UndelegateType::Standalone), + UndelegateTypeArgs::WithHandler { call_handlers } => { + let call_handlers = call_handlers + .iter() + .map(|call_handler| { + CallHandler::try_from_args(call_handler, context) + }) + .collect::, InstructionError>>()?; + Ok(UndelegateType::WithHandler(call_handlers)) + } + } + } +} + +pub struct CommitAndUndelegate { + pub commit_action: CommitType, + pub undelegate_action: UndelegateType, +} + +impl CommitAndUndelegate { + pub fn try_from_args<'a>( + args: &CommitAndUndelegateArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + let commit_action = + CommitType::try_from_args(&args.commit_type, context)?; + let undelegate_action = + UndelegateType::try_from_args(&args.undelegate_type, context)?; + + Ok(Self { + commit_action, + undelegate_action, + }) + } +} + +pub enum Action { + /// Actions without commitment or undelegation + CallHandler(Vec), + Commit(CommitType), + CommitAndUndelegate(CommitAndUndelegate), +} + +impl Action { + pub fn try_from_args<'a>( + args: &MagicActionArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + match args { + MagicActionArgs::L1Action(call_handlers_args) => { + let call_handlers = call_handlers_args + .iter() + .map(|args| CallHandler::try_from_args(args, context)) + .collect::, InstructionError>>()?; + Ok(Action::CallHandler(call_handlers)) + } + MagicActionArgs::Commit(type_) => { + let commit = CommitType::try_from_args(type_, context)?; + Ok(Action::Commit(commit)) + } + MagicActionArgs::CommitAndUndelegate(type_) => { + let commit_and_undelegate = + CommitAndUndelegate::try_from_args(type_, context)?; + Ok(Action::CommitAndUndelegate(commit_and_undelegate)) + } + } + } +} + +pub struct ConstructionContext<'a, 'ic> { + parent_program_id: Option, + signers: &'a HashSet, + transaction_context: &'a TransactionContext, + invoke_context: &'a mut InvokeContext<'ic>, +} + +impl<'a, 'ic> ConstructionContext<'a, 'ic> { + pub fn new( + parent_program_id: Option, + signers: &'a HashSet, + transaction_context: &'a TransactionContext, + invoke_context: &'a mut InvokeContext<'ic>, + ) -> Self { + Self { + parent_program_id, + signers, + transaction_context, + invoke_context, + } + } +} + +// Q: can user initiate actions on arbitrary accounts? +// No, then he could call any handler on any porgram +// Inititating transfer for himself +// +// Answer: No + +// Q; can user call any program but using account that he owns? +// Far example, there could Transfer from that implements logix for transfer +// Here the fact that magicblock-program schedyled that call huarantess that user apporved this +// +// Answer: Yes + +// user has multiple actions that he wants to perform on owned accounts +// he may schedule +// Those actions may have contraints: Undelegate can come only After Commit +// Commit can't come after undelegate + #[derive(Debug, Default, Serialize, Deserialize)] pub struct MagicContext { pub scheduled_commits: Vec, diff --git a/programs/magicblock/src/magicblock_instruction.rs b/programs/magicblock/src/magicblock_instruction.rs index 2ecd39067..fc5de8261 100644 --- a/programs/magicblock/src/magicblock_instruction.rs +++ b/programs/magicblock/src/magicblock_instruction.rs @@ -99,7 +99,7 @@ pub(crate) struct AccountModificationForInstruction { } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub(crate) enum MagicBlockInstruction { +pub enum MagicBlockInstruction { /// Modify one or more accounts /// /// # Account references @@ -160,8 +160,51 @@ pub(crate) enum MagicBlockInstruction { /// We implement it this way so we can log the signature of this transaction /// as part of the [MagicBlockInstruction::ScheduleCommit] instruction. ScheduledCommitSent(u64), + ScheduleAction(MagicActionArgs), } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct HandlerArgs { + pub escrow_index: u8, + pub data: Vec, +} + +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub struct CallHandlerArgs { + pub args: HandlerArgs, + pub destination_program: u8, // index of the account + pub accounts: Vec, // indecis of account +} + +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub enum CommitTypeArgs { + Standalone(Vec), // indices on accounts + WithHandler { + committed_accounts: Vec, // indices of accounts + call_handlers: Vec, + }, +} + +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub enum UndelegateTypeArgs { + Standalone, + WithHandler { call_handlers: Vec }, +} + +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub struct CommitAndUndelegateArgs { + pub commit_type: CommitTypeArgs, + pub undelegate_type: UndelegateTypeArgs, +} + +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub enum MagicActionArgs { + L1Action(Vec), + Commit(CommitTypeArgs), + CommitAndUndelegate(CommitAndUndelegateArgs), +} + +// TODO: why that exists? #[allow(unused)] impl MagicBlockInstruction { pub(crate) fn index(&self) -> u8 { @@ -172,6 +215,7 @@ impl MagicBlockInstruction { ScheduleCommitAndUndelegate => 2, AcceptScheduleCommits => 3, ScheduledCommitSent(_) => 4, + ScheduleAction(_) => 5, } } diff --git a/programs/magicblock/src/magicblock_processor.rs b/programs/magicblock/src/magicblock_processor.rs index 00293fcfd..a6f966ab9 100644 --- a/programs/magicblock/src/magicblock_processor.rs +++ b/programs/magicblock/src/magicblock_processor.rs @@ -1,6 +1,7 @@ use solana_program_runtime::declare_process_instruction; use solana_sdk::program_utils::limited_deserialize; +use crate::schedule_transactions::process_schedule_action; use crate::{ magicblock_instruction::MagicBlockInstruction, mutate_accounts::process_mutate_accounts, @@ -60,6 +61,13 @@ declare_process_instruction!( id, ) } + MagicBlockInstruction::ScheduleAction(args) => { + process_schedule_action( + signers, + invoke_context, + args, + ) + } } } ); diff --git a/programs/magicblock/src/schedule_transactions/mod.rs b/programs/magicblock/src/schedule_transactions/mod.rs index 6da807982..ef23b81d5 100644 --- a/programs/magicblock/src/schedule_transactions/mod.rs +++ b/programs/magicblock/src/schedule_transactions/mod.rs @@ -1,10 +1,16 @@ +mod process_schedule_action; mod process_schedule_commit; mod process_scheduled_commit_sent; pub(crate) mod transaction_scheduler; + +use std::sync::atomic::AtomicU64; + +pub(crate) use process_schedule_action::*; pub(crate) use process_schedule_commit::*; pub use process_scheduled_commit_sent::{ process_scheduled_commit_sent, register_scheduled_commit_sent, SentCommit, }; - #[cfg(test)] mod process_schedule_commit_tests; + +pub(crate) static COMMIT_ID: AtomicU64 = AtomicU64::new(0); diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs new file mode 100644 index 000000000..210243ecc --- /dev/null +++ b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs @@ -0,0 +1,137 @@ +use std::{collections::HashSet, sync::atomic::Ordering}; + +use solana_log_collector::ic_msg; +use solana_program_runtime::invoke_context::InvokeContext; +use solana_sdk::{ + instruction::InstructionError, pubkey::Pubkey, + transaction_context::TransactionContext, +}; + +use crate::{ + magic_context::{ConstructionContext, ScheduleAction}, + magicblock_instruction::MagicActionArgs, + schedule_transactions::{check_magic_context_id, COMMIT_ID}, + utils::accounts::get_instruction_pubkey_with_idx, +}; + +const PAYER_IDX: u16 = 0; +const MAGIC_CONTEXT_IDX: u16 = PAYER_IDX + 1; +const ACTION_ACCOUNTS_OFFSET: usize = MAGIC_CONTEXT_IDX as usize + 1; + +pub(crate) fn process_schedule_action( + signers: HashSet, + invoke_context: &mut InvokeContext, + args: MagicActionArgs, +) -> Result<(), InstructionError> { + check_magic_context_id(invoke_context, MAGIC_CONTEXT_IDX)?; + + let transaction_context = &invoke_context.transaction_context.clone(); + let ix_ctx = transaction_context.get_current_instruction_context()?; + + // Assert MagicBlock program + ix_ctx + .find_index_of_program_account(transaction_context, &crate::id()) + .ok_or_else(|| { + ic_msg!( + invoke_context, + "ScheduleCommit ERR: Magic program account not found" + ); + InstructionError::UnsupportedProgramId + })?; + + // Assert enough accounts + let ix_accs_len = ix_ctx.get_number_of_instruction_accounts() as usize; + if ix_accs_len <= ACTION_ACCOUNTS_OFFSET { + ic_msg!( + invoke_context, + "ScheduleCommit ERR: not enough accounts to schedule commit ({}), need payer, signing program an account for each pubkey to be committed", + ix_accs_len + ); + return Err(InstructionError::NotEnoughAccountKeys); + } + + // Assert Payer is signer + let payer_pubkey = + get_instruction_pubkey_with_idx(transaction_context, PAYER_IDX)?; + if !signers.contains(payer_pubkey) { + ic_msg!( + invoke_context, + "ScheduleCommit ERR: payer pubkey {} not in signers", + payer_pubkey + ); + return Err(InstructionError::MissingRequiredSignature); + } + + // + // Get the program_id of the parent instruction that invoked this one via CPI + // + + // We cannot easily simulate the transaction being invoked via CPI + // from the owning program during unit tests + // Instead the integration tests ensure that this works as expected + let parent_program_id = + get_parent_program_id(transaction_context, invoke_context)?; + + // It appears that in builtin programs `Clock::get` doesn't work as expected, thus + // we have to get it directly from the sysvar cache. + let clock = + invoke_context + .get_sysvar_cache() + .get_clock() + .map_err(|err| { + ic_msg!(invoke_context, "Failed to get clock sysvar: {}", err); + InstructionError::UnsupportedSysvar + })?; + + // Determine id and slot + let commit_id = COMMIT_ID.fetch_add(1, Ordering::Relaxed); + let construction_context = ConstructionContext::new( + parent_program_id, + &signers, + transaction_context, + invoke_context, + ); + let schedule_action = ScheduleAction::try_new( + &args, + commit_id, + clock.slot, + payer_pubkey, + &construction_context, + )?; + + Ok(()) +} + +#[cfg(not(test))] +fn get_parent_program_id( + transaction_context: &TransactionContext, + invoke_context: &mut InvokeContext, +) -> Result, InstructionError> { + let frames = crate::utils::instruction_context_frames::InstructionContextFrames::try_from(transaction_context)?; + let parent_program_id = + frames.find_program_id_of_parent_of_current_instruction(); + + ic_msg!( + invoke_context, + "ScheduleCommit: parent program id: {}", + parent_program_id + .map_or_else(|| "None".to_string(), |id| id.to_string()) + ); + + Ok(parent_program_id.map(Clone::clone)) +} + +#[cfg(test)] +fn get_parent_program_id( + transaction_context: &TransactionContext, + invoke_context: &mut InvokeContext, +) -> Result, InstructionError> { + let first_committee_owner = *get_instruction_account_with_idx( + transaction_context, + ACTION_ACCOUNTS_OFFSET as u16, + )? + .borrow() + .owner(); + + Ok(Some(first_committee_owner.clone())) +} diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs index 6016f374d..35d9217ec 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs @@ -1,7 +1,4 @@ -use std::{ - collections::HashSet, - sync::atomic::{AtomicU64, Ordering}, -}; +use std::{collections::HashSet, sync::atomic::Ordering}; use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; use solana_log_collector::ic_msg; @@ -13,7 +10,9 @@ use solana_sdk::{ use crate::{ magic_context::{CommittedAccount, MagicContext, ScheduledCommit}, magicblock_instruction::scheduled_commit_sent, - schedule_transactions::transaction_scheduler::TransactionScheduler, + schedule_transactions::{ + transaction_scheduler::TransactionScheduler, COMMIT_ID, + }, utils::{ account_actions::set_account_owner_to_delegation_program, accounts::{ @@ -33,8 +32,6 @@ pub(crate) fn process_schedule_commit( invoke_context: &mut InvokeContext, opts: ProcessScheduleCommitOptions, ) -> Result<(), InstructionError> { - static COMMIT_ID: AtomicU64 = AtomicU64::new(0); - const PAYER_IDX: u16 = 0; const MAGIC_CONTEXT_IDX: u16 = PAYER_IDX + 1; @@ -329,7 +326,7 @@ pub fn process_accept_scheduled_commits( Ok(()) } -fn check_magic_context_id( +pub fn check_magic_context_id( invoke_context: &InvokeContext, idx: u16, ) -> Result<(), InstructionError> { diff --git a/programs/magicblock/src/utils/accounts.rs b/programs/magicblock/src/utils/accounts.rs index 5b8c44136..5ad7ea3f2 100644 --- a/programs/magicblock/src/utils/accounts.rs +++ b/programs/magicblock/src/utils/accounts.rs @@ -6,11 +6,13 @@ use solana_program_runtime::invoke_context::InvokeContext; use solana_sdk::{ account::{Account, AccountSharedData, ReadableAccount, WritableAccount}, account_info::{AccountInfo, IntoAccountInfo}, - instruction::InstructionError, + instruction::{AccountMeta, InstructionError}, pubkey::Pubkey, transaction_context::TransactionContext, }; +use crate::magic_context::ShortAccountMeta; + pub(crate) fn find_tx_index_of_instruction_account( invoke_context: &InvokeContext, transaction_context: &TransactionContext, @@ -100,6 +102,21 @@ pub(crate) fn get_instruction_pubkey_with_idx( Ok(pubkey) } +pub(crate) fn get_instruction_account_short_meta_with_idx( + transaction_context: &TransactionContext, + idx: u16, +) -> Result { + let ix_ctx = transaction_context.get_current_instruction_context()?; + let tx_idx = ix_ctx.get_index_of_instruction_account_in_transaction(idx)?; + + let pubkey = *transaction_context.get_key_of_account_at_index(tx_idx)?; + let is_writable = ix_ctx.is_instruction_account_writable(idx)?; + Ok(ShortAccountMeta { + pubkey, + is_writable, + }) +} + pub(crate) fn debit_instruction_account_at_index( transaction_context: &TransactionContext, idx: u16, From 0cfda9caf8aa9ea3bbd98e6abb09b0b6b2f474bc Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 16 May 2025 17:22:53 +0900 Subject: [PATCH 063/199] refactor: changed file structure --- magicblock-api/src/tickers.rs | 8 +- magicblock-mutator/src/lib.rs | 4 +- magicblock-mutator/src/transactions.rs | 19 +- programs/magicblock/src/args.rs | 42 + programs/magicblock/src/errors.rs | 49 ++ programs/magicblock/src/lib.rs | 3 + programs/magicblock/src/magic_context.rs | 347 +------- .../magicblock/src/magic_schedule_action.rs | 353 ++++++++ .../magicblock/src/magicblock_instruction.rs | 325 +------ .../magicblock/src/magicblock_processor.rs | 11 +- .../src/mutate_accounts/account_mod_data.rs | 2 +- .../process_mutate_accounts.rs | 18 +- .../process_schedule_action.rs | 10 +- .../process_schedule_commit.rs | 5 +- .../process_schedule_commit_tests.rs | 826 +++++++++--------- .../process_scheduled_commit_sent.rs | 10 +- programs/magicblock/src/utils/accounts.rs | 2 +- .../magicblock/src/utils/instruction_utils.rs | 202 +++++ programs/magicblock/src/utils/mod.rs | 1 + 19 files changed, 1152 insertions(+), 1085 deletions(-) create mode 100644 programs/magicblock/src/args.rs create mode 100644 programs/magicblock/src/magic_schedule_action.rs create mode 100644 programs/magicblock/src/utils/instruction_utils.rs diff --git a/magicblock-api/src/tickers.rs b/magicblock-api/src/tickers.rs index 90f356a49..00e3afa5f 100644 --- a/magicblock-api/src/tickers.rs +++ b/magicblock-api/src/tickers.rs @@ -14,9 +14,7 @@ use magicblock_core::magic_program; use magicblock_ledger::Ledger; use magicblock_metrics::metrics; use magicblock_processor::execute_transaction::execute_legacy_transaction; -use magicblock_program::{ - magicblock_instruction::accept_scheduled_commits, MagicContext, -}; +use magicblock_program::{instruction_utils::InstructionUtils, MagicContext}; use magicblock_transaction_status::TransactionStatusSender; use solana_sdk::account::ReadableAccount; use tokio_util::sync::CancellationToken; @@ -54,7 +52,9 @@ pub fn init_slot_ticker( if MagicContext::has_scheduled_commits(magic_context_acc.data()) { // 1. Send the transaction to move the scheduled commits from the MagicContext // to the global ScheduledCommit store - let tx = accept_scheduled_commits(bank.last_blockhash()); + let tx = InstructionUtils::accept_scheduled_commits( + bank.last_blockhash(), + ); if let Err(err) = execute_legacy_transaction( tx, &bank, diff --git a/magicblock-mutator/src/lib.rs b/magicblock-mutator/src/lib.rs index 531cb8862..a0044f733 100644 --- a/magicblock-mutator/src/lib.rs +++ b/magicblock-mutator/src/lib.rs @@ -7,6 +7,4 @@ pub mod transactions; pub use cluster::*; pub use fetch::transaction_to_clone_pubkey_from_cluster; -pub use magicblock_program::magicblock_instruction::{ - modify_accounts, AccountModification, -}; +pub use magicblock_program::magicblock_instruction::AccountModification; diff --git a/magicblock-mutator/src/transactions.rs b/magicblock-mutator/src/transactions.rs index e529c361b..8af6f6943 100644 --- a/magicblock-mutator/src/transactions.rs +++ b/magicblock-mutator/src/transactions.rs @@ -1,8 +1,6 @@ use magicblock_program::{ - magicblock_instruction::{ - modify_accounts, modify_accounts_instruction, AccountModification, - }, - validator, + instruction_utils::InstructionUtils, + magicblock_instruction::AccountModification, validator, }; use solana_sdk::{ account::Account, bpf_loader_upgradeable, hash::Hash, pubkey::Pubkey, @@ -35,7 +33,10 @@ pub fn transaction_to_clone_regular_account( } } // We only need a single transaction with a single mutation in this case - modify_accounts(vec![account_modification], recent_blockhash) + InstructionUtils::modify_accounts( + vec![account_modification], + recent_blockhash, + ) } pub fn transaction_to_clone_program( @@ -61,10 +62,14 @@ pub fn transaction_to_clone_program( // If the program does not exist yet, we just need to update it's data and don't // need to explicitly update using the BPF loader's Upgrade IX if !needs_upgrade { - return modify_accounts(account_modifications, recent_blockhash); + return InstructionUtils::modify_accounts( + account_modifications, + recent_blockhash, + ); } // First dump the necessary set of account to our bank/ledger - let modify_ix = modify_accounts_instruction(account_modifications); + let modify_ix = + InstructionUtils::modify_accounts_instruction(account_modifications); // The validator is marked as the upgrade authority of all program accounts let validator_pubkey = &validator::validator_authority_id(); // Then we run the official BPF upgrade IX to notify the system of the new program diff --git a/programs/magicblock/src/args.rs b/programs/magicblock/src/args.rs new file mode 100644 index 000000000..e2be68104 --- /dev/null +++ b/programs/magicblock/src/args.rs @@ -0,0 +1,42 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct HandlerArgs { + pub escrow_index: u8, + pub data: Vec, +} + +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub struct CallHandlerArgs { + pub args: HandlerArgs, + pub destination_program: u8, // index of the account + pub accounts: Vec, // indices of account +} + +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub enum CommitTypeArgs { + Standalone(Vec), // indices on accounts + WithHandler { + committed_accounts: Vec, // indices of accounts + call_handlers: Vec, + }, +} + +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub enum UndelegateTypeArgs { + Standalone, + WithHandler { call_handlers: Vec }, +} + +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub struct CommitAndUndelegateArgs { + pub commit_type: CommitTypeArgs, + pub undelegate_type: UndelegateTypeArgs, +} + +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub enum MagicActionArgs { + L1Action(Vec), + Commit(CommitTypeArgs), + CommitAndUndelegate(CommitAndUndelegateArgs), +} diff --git a/programs/magicblock/src/errors.rs b/programs/magicblock/src/errors.rs index c5f0596a9..532c5cf1c 100644 --- a/programs/magicblock/src/errors.rs +++ b/programs/magicblock/src/errors.rs @@ -1,3 +1,8 @@ +use num_derive::{FromPrimitive, ToPrimitive}; +use serde::Serialize; +use solana_sdk::decode_error::DecodeError; +use thiserror::Error; + // ----------------- // Program CustomError Codes // ----------------- @@ -6,3 +11,47 @@ pub mod custom_error_codes { pub const UNABLE_TO_UNLOCK_SENT_COMMITS: u32 = 10_001; pub const CANNOT_FIND_SCHEDULED_COMMIT: u32 = 10_002; } + +#[derive( + Error, Debug, Serialize, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive, +)] +pub enum MagicBlockProgramError { + #[error("need at least one account to modify")] + NoAccountsToModify, + + #[error("number of accounts to modify needs to match number of account modifications")] + AccountsToModifyNotMatchingAccountModifications, + + #[error("The account modification for the provided key is missing.")] + AccountModificationMissing, + + #[error("first account needs to be MagicBlock authority")] + FirstAccountNeedsToBeMagicBlockAuthority, + + #[error("MagicBlock authority needs to be owned by system program")] + MagicBlockAuthorityNeedsToBeOwnedBySystemProgram, + + #[error("The account resolution for the provided key failed.")] + AccountDataResolutionFailed, + + #[error("The account data for the provided key is missing both from in-memory and ledger storage.")] + AccountDataMissing, + + #[error("The account data for the provided key is missing from in-memory and we are not replaying the ledger.")] + AccountDataMissingFromMemory, + + #[error("Tried to persist data that could not be resolved.")] + AttemptedToPersistUnresolvedData, + + #[error("Tried to persist data that was resolved from storage.")] + AttemptedToPersistDataFromStorage, + + #[error("Encountered an error when persisting account modification data.")] + FailedToPersistAccountModData, +} + +impl DecodeError for MagicBlockProgramError { + fn type_of() -> &'static str { + "MagicBlockProgramError" + } +} diff --git a/programs/magicblock/src/lib.rs b/programs/magicblock/src/lib.rs index ffe22905b..83b096794 100644 --- a/programs/magicblock/src/lib.rs +++ b/programs/magicblock/src/lib.rs @@ -3,6 +3,8 @@ mod magic_context; mod mutate_accounts; mod schedule_transactions; pub use magic_context::{FeePayerAccount, MagicContext, ScheduledCommit}; +mod args; +mod magic_schedule_action; pub mod magicblock_instruction; pub mod magicblock_processor; #[cfg(test)] @@ -16,3 +18,4 @@ pub use schedule_transactions::{ process_scheduled_commit_sent, register_scheduled_commit_sent, transaction_scheduler::TransactionScheduler, SentCommit, }; +pub use utils::instruction_utils; diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index 7e2541f94..6b1552ce0 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -1,29 +1,13 @@ -use std::{collections::HashSet, mem}; +use std::mem; use magicblock_core::magic_program; use serde::{Deserialize, Serialize}; -use solana_log_collector::ic_msg; -use solana_program_runtime::{ - __private::InstructionError, invoke_context::InvokeContext, -}; use solana_sdk::{ account::{AccountSharedData, ReadableAccount}, clock::Slot, hash::Hash, pubkey::Pubkey, transaction::Transaction, - transaction_context::TransactionContext, -}; - -use crate::{ - magicblock_instruction::{ - scheduled_commit_sent, CallHandlerArgs, CommitAndUndelegateArgs, - CommitTypeArgs, HandlerArgs, MagicActionArgs, UndelegateTypeArgs, - }, - utils::accounts::{ - get_instruction_account_short_meta_with_idx, - get_instruction_account_with_idx, get_instruction_pubkey_with_idx, - }, }; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -51,335 +35,6 @@ pub struct ScheduledCommit { pub request_undelegation: bool, } -// New impl -pub struct ScheduleAction { - pub id: u64, - pub slot: Slot, - pub blockhash: Hash, - pub commit_sent_transaction: Transaction, - pub payer: Pubkey, - // Scheduled action - pub action: Action, -} - -impl ScheduleAction { - pub fn try_new<'a>( - args: &MagicActionArgs, - commit_id: u64, - slot: Slot, - payer_pubkey: &Pubkey, - context: &ConstructionContext<'a, '_>, - ) -> Result { - let action = Action::try_from_args(args, &context)?; - - let blockhash = context.invoke_context.environment_config.blockhash; - let commit_sent_transaction = - scheduled_commit_sent(commit_id, blockhash); - let commit_sent_sig = commit_sent_transaction.signatures[0]; - - Ok(ScheduleAction { - id: commit_id, - slot, - blockhash, - payer: *payer_pubkey, - commit_sent_transaction, - action, - }) - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct Handler { - pub escrow_index: u8, - pub data: Vec, -} - -impl From for Handler { - fn from(value: HandlerArgs) -> Self { - Self { - escrow_index: value.escrow_index, - data: value.data, - } - } -} - -impl From<&HandlerArgs> for Handler { - fn from(value: &HandlerArgs) -> Self { - value.clone().into() - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ShortAccountMeta { - pub pubkey: Pubkey, - pub is_writable: bool, -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CallHandler { - pub destination_program: Pubkey, - pub data_per_program: Handler, - pub account_metas_per_program: Vec, -} - -impl CallHandler { - pub fn try_from_args<'a>( - args: &CallHandlerArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - let destination_program_pubkey = *get_instruction_pubkey_with_idx( - context.transaction_context, - args.destination_program as u16, - )?; - let destination_program = get_instruction_account_with_idx( - context.transaction_context, - args.destination_program as u16, - )?; - - if !destination_program.borrow().executable() { - ic_msg!( - context.invoke_context, - &format!( - "CallHandler: destination_program must be an executable. got: {}", - destination_program_pubkey - ) - ); - return Err(InstructionError::AccountNotExecutable); - } - - let account_metas = args - .accounts - .iter() - .map(|i| { - get_instruction_account_short_meta_with_idx( - context.transaction_context, - *i as u16, - ) - }) - .collect::, InstructionError>>()?; - - Ok(CallHandler { - destination_program: destination_program_pubkey, - data_per_program: args.args.clone().into(), - account_metas_per_program: account_metas, - }) - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CommittedAccountV2 { - pub short_meta: ShortAccountMeta, - // TODO(GabrielePicco): We should read the owner from the delegation record rather - // than deriving/storing it. To remove once the cloning pipeline allow us to easily access the owner. - pub owner: Pubkey, -} - -pub enum CommitType { - /// Regular commit without actions - Standalone(Vec), // accounts to commit - /// Commits accounts and runs actions - WithHandler { - committed_accounts: Vec, - call_handlers: Vec, - }, -} - -impl CommitType { - fn validate_accounts<'a>( - account_indices: &[u8], - context: &ConstructionContext<'a, '_>, - ) -> Result<(), InstructionError> { - account_indices.iter().try_for_each(|index| { - let acc_pubkey = get_instruction_pubkey_with_idx(context.transaction_context, *index as u16)?; - let acc = get_instruction_account_with_idx(context.transaction_context, *index as u16)?; - let acc_owner = *acc.borrow().owner(); - - if context.parent_program_id.as_ref() != Some(acc_pubkey) && !context.signers.contains(acc_pubkey) { - match context.parent_program_id { - None => { - ic_msg!( - context.invoke_context, - "ScheduleCommit ERR: failed to find parent program id" - ); - Err(InstructionError::InvalidInstructionData) - } - Some(parent_id) => { - ic_msg!( - context.invoke_context, - "ScheduleCommit ERR: account {} must be owned by {} or be a signer, but is owned by {}", - acc_pubkey, parent_id, acc_owner - ); - Err(InstructionError::InvalidAccountOwner) - } - } - } else { - Ok(()) - } - }) - } - - fn extract_commit_accounts<'a>( - account_indices: &[u8], - context: &ConstructionContext<'a, '_>, - ) -> Result, InstructionError> { - account_indices - .iter() - .map(|i| { - let account = get_instruction_account_with_idx( - context.transaction_context, - *i as u16, - )?; - let owner = *account.borrow().owner(); - let short_meta = get_instruction_account_short_meta_with_idx( - context.transaction_context, - *i as u16, - )?; - - Ok(CommittedAccountV2 { - short_meta, - owner: context.parent_program_id.unwrap_or(owner), - }) - }) - .collect::, InstructionError>>() - } - - pub fn try_from_args<'a>( - args: &CommitTypeArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - match args { - CommitTypeArgs::Standalone(accounts) => { - Self::validate_accounts(accounts, context)?; - let committed_accounts = - Self::extract_commit_accounts(accounts, context)?; - - Ok(CommitType::Standalone(committed_accounts)) - } - CommitTypeArgs::WithHandler { - committed_accounts, - call_handlers, - } => { - Self::validate_accounts(committed_accounts, context)?; - let committed_accounts = - Self::extract_commit_accounts(committed_accounts, context)?; - let call_handlers = call_handlers - .iter() - .map(|args| CallHandler::try_from_args(args, context)) - .collect::, InstructionError>>()?; - - Ok(CommitType::WithHandler { - committed_accounts, - call_handlers, - }) - } - } - } -} - -/// No CommitedAccounts since it is only used with CommitAction. -pub enum UndelegateType { - Standalone, - WithHandler(Vec), -} - -impl UndelegateType { - pub fn try_from_args<'a>( - args: &UndelegateTypeArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - match args { - UndelegateTypeArgs::Standalone => Ok(UndelegateType::Standalone), - UndelegateTypeArgs::WithHandler { call_handlers } => { - let call_handlers = call_handlers - .iter() - .map(|call_handler| { - CallHandler::try_from_args(call_handler, context) - }) - .collect::, InstructionError>>()?; - Ok(UndelegateType::WithHandler(call_handlers)) - } - } - } -} - -pub struct CommitAndUndelegate { - pub commit_action: CommitType, - pub undelegate_action: UndelegateType, -} - -impl CommitAndUndelegate { - pub fn try_from_args<'a>( - args: &CommitAndUndelegateArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - let commit_action = - CommitType::try_from_args(&args.commit_type, context)?; - let undelegate_action = - UndelegateType::try_from_args(&args.undelegate_type, context)?; - - Ok(Self { - commit_action, - undelegate_action, - }) - } -} - -pub enum Action { - /// Actions without commitment or undelegation - CallHandler(Vec), - Commit(CommitType), - CommitAndUndelegate(CommitAndUndelegate), -} - -impl Action { - pub fn try_from_args<'a>( - args: &MagicActionArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - match args { - MagicActionArgs::L1Action(call_handlers_args) => { - let call_handlers = call_handlers_args - .iter() - .map(|args| CallHandler::try_from_args(args, context)) - .collect::, InstructionError>>()?; - Ok(Action::CallHandler(call_handlers)) - } - MagicActionArgs::Commit(type_) => { - let commit = CommitType::try_from_args(type_, context)?; - Ok(Action::Commit(commit)) - } - MagicActionArgs::CommitAndUndelegate(type_) => { - let commit_and_undelegate = - CommitAndUndelegate::try_from_args(type_, context)?; - Ok(Action::CommitAndUndelegate(commit_and_undelegate)) - } - } - } -} - -pub struct ConstructionContext<'a, 'ic> { - parent_program_id: Option, - signers: &'a HashSet, - transaction_context: &'a TransactionContext, - invoke_context: &'a mut InvokeContext<'ic>, -} - -impl<'a, 'ic> ConstructionContext<'a, 'ic> { - pub fn new( - parent_program_id: Option, - signers: &'a HashSet, - transaction_context: &'a TransactionContext, - invoke_context: &'a mut InvokeContext<'ic>, - ) -> Self { - Self { - parent_program_id, - signers, - transaction_context, - invoke_context, - } - } -} - // Q: can user initiate actions on arbitrary accounts? // No, then he could call any handler on any porgram // Inititating transfer for himself diff --git a/programs/magicblock/src/magic_schedule_action.rs b/programs/magicblock/src/magic_schedule_action.rs new file mode 100644 index 000000000..df01e9b05 --- /dev/null +++ b/programs/magicblock/src/magic_schedule_action.rs @@ -0,0 +1,353 @@ +use std::collections::HashSet; + +use serde::{Deserialize, Serialize}; +use solana_log_collector::ic_msg; +use solana_program_runtime::{ + __private::{Hash, InstructionError, ReadableAccount, TransactionContext}, + invoke_context::InvokeContext, +}; +use solana_sdk::{clock::Slot, transaction::Transaction}; + +use crate::{ + args::{ + CallHandlerArgs, CommitAndUndelegateArgs, CommitTypeArgs, HandlerArgs, + MagicActionArgs, UndelegateTypeArgs, + }, + instruction_utils::InstructionUtils, + utils::accounts::{ + get_instruction_account_short_meta_with_idx, + get_instruction_account_with_idx, get_instruction_pubkey_with_idx, + }, + Pubkey, +}; + +/// Context necessary for construction of Schedule Action +pub struct ConstructionContext<'a, 'ic> { + parent_program_id: Option, + signers: &'a HashSet, + transaction_context: &'a TransactionContext, + invoke_context: &'a mut InvokeContext<'ic>, +} + +impl<'a, 'ic> ConstructionContext<'a, 'ic> { + pub fn new( + parent_program_id: Option, + signers: &'a HashSet, + transaction_context: &'a TransactionContext, + invoke_context: &'a mut InvokeContext<'ic>, + ) -> Self { + Self { + parent_program_id, + signers, + transaction_context, + invoke_context, + } + } +} + +/// Scheduled action to be executed on base layer +pub struct ScheduleAction { + pub id: u64, + pub slot: Slot, + pub blockhash: Hash, + pub commit_sent_transaction: Transaction, + pub payer: Pubkey, + // Scheduled action + pub action: MagicAction, +} + +impl ScheduleAction { + pub fn try_new<'a>( + args: &MagicActionArgs, + commit_id: u64, + slot: Slot, + payer_pubkey: &Pubkey, + context: &ConstructionContext<'a, '_>, + ) -> Result { + let action = MagicAction::try_from_args(args, &context)?; + + let blockhash = context.invoke_context.environment_config.blockhash; + let commit_sent_transaction = + InstructionUtils::scheduled_commit_sent(commit_id, blockhash); + let commit_sent_sig = commit_sent_transaction.signatures[0]; + + Ok(ScheduleAction { + id: commit_id, + slot, + blockhash, + payer: *payer_pubkey, + commit_sent_transaction, + action, + }) + } +} + +// Action that user wants to perform on base layer +pub enum MagicAction { + /// Actions without commitment or undelegation + CallHandler(Vec), + Commit(CommitType), + CommitAndUndelegate(CommitAndUndelegate), +} + +impl MagicAction { + pub fn try_from_args<'a>( + args: &MagicActionArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + match args { + MagicActionArgs::L1Action(call_handlers_args) => { + let call_handlers = call_handlers_args + .iter() + .map(|args| CallHandler::try_from_args(args, context)) + .collect::, InstructionError>>()?; + Ok(MagicAction::CallHandler(call_handlers)) + } + MagicActionArgs::Commit(type_) => { + let commit = CommitType::try_from_args(type_, context)?; + Ok(MagicAction::Commit(commit)) + } + MagicActionArgs::CommitAndUndelegate(type_) => { + let commit_and_undelegate = + CommitAndUndelegate::try_from_args(type_, context)?; + Ok(MagicAction::CommitAndUndelegate(commit_and_undelegate)) + } + } + } +} + +impl CommitType { + fn validate_accounts<'a>( + account_indices: &[u8], + context: &ConstructionContext<'a, '_>, + ) -> Result<(), InstructionError> { + account_indices.iter().try_for_each(|index| { + let acc_pubkey = get_instruction_pubkey_with_idx(context.transaction_context, *index as u16)?; + let acc = get_instruction_account_with_idx(context.transaction_context, *index as u16)?; + let acc_owner = *acc.borrow().owner(); + + if context.parent_program_id.as_ref() != Some(acc_pubkey) && !context.signers.contains(acc_pubkey) { + match context.parent_program_id { + None => { + ic_msg!( + context.invoke_context, + "ScheduleCommit ERR: failed to find parent program id" + ); + Err(InstructionError::InvalidInstructionData) + } + Some(parent_id) => { + ic_msg!( + context.invoke_context, + "ScheduleCommit ERR: account {} must be owned by {} or be a signer, but is owned by {}", + acc_pubkey, parent_id, acc_owner + ); + Err(InstructionError::InvalidAccountOwner) + } + } + } else { + Ok(()) + } + }) + } + + fn extract_commit_accounts<'a>( + account_indices: &[u8], + context: &ConstructionContext<'a, '_>, + ) -> Result, InstructionError> { + account_indices + .iter() + .map(|i| { + let account = get_instruction_account_with_idx( + context.transaction_context, + *i as u16, + )?; + let owner = *account.borrow().owner(); + let short_meta = get_instruction_account_short_meta_with_idx( + context.transaction_context, + *i as u16, + )?; + + Ok(CommittedAccountV2 { + short_meta, + owner: context.parent_program_id.unwrap_or(owner), + }) + }) + .collect::, InstructionError>>() + } + + pub fn try_from_args<'a>( + args: &CommitTypeArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + match args { + CommitTypeArgs::Standalone(accounts) => { + Self::validate_accounts(accounts, context)?; + let committed_accounts = + Self::extract_commit_accounts(accounts, context)?; + + Ok(CommitType::Standalone(committed_accounts)) + } + CommitTypeArgs::WithHandler { + committed_accounts, + call_handlers, + } => { + Self::validate_accounts(committed_accounts, context)?; + let committed_accounts = + Self::extract_commit_accounts(committed_accounts, context)?; + let call_handlers = call_handlers + .iter() + .map(|args| CallHandler::try_from_args(args, context)) + .collect::, InstructionError>>()?; + + Ok(CommitType::WithHandler { + committed_accounts, + call_handlers, + }) + } + } + } +} + +pub struct CommitAndUndelegate { + pub commit_action: CommitType, + pub undelegate_action: UndelegateType, +} + +impl CommitAndUndelegate { + pub fn try_from_args<'a>( + args: &CommitAndUndelegateArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + let commit_action = + CommitType::try_from_args(&args.commit_type, context)?; + let undelegate_action = + UndelegateType::try_from_args(&args.undelegate_type, context)?; + + Ok(Self { + commit_action, + undelegate_action, + }) + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct Handler { + pub escrow_index: u8, + pub data: Vec, +} + +impl From for Handler { + fn from(value: HandlerArgs) -> Self { + Self { + escrow_index: value.escrow_index, + data: value.data, + } + } +} + +impl From<&HandlerArgs> for Handler { + fn from(value: &HandlerArgs) -> Self { + value.clone().into() + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct ShortAccountMeta { + pub pubkey: Pubkey, + pub is_writable: bool, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct CallHandler { + pub destination_program: Pubkey, + pub data_per_program: Handler, + pub account_metas_per_program: Vec, +} + +impl CallHandler { + pub fn try_from_args<'a>( + args: &CallHandlerArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + let destination_program_pubkey = *get_instruction_pubkey_with_idx( + context.transaction_context, + args.destination_program as u16, + )?; + let destination_program = get_instruction_account_with_idx( + context.transaction_context, + args.destination_program as u16, + )?; + + if !destination_program.borrow().executable() { + ic_msg!( + context.invoke_context, + &format!( + "CallHandler: destination_program must be an executable. got: {}", + destination_program_pubkey + ) + ); + return Err(InstructionError::AccountNotExecutable); + } + + let account_metas = args + .accounts + .iter() + .map(|i| { + get_instruction_account_short_meta_with_idx( + context.transaction_context, + *i as u16, + ) + }) + .collect::, InstructionError>>()?; + + Ok(CallHandler { + destination_program: destination_program_pubkey, + data_per_program: args.args.clone().into(), + account_metas_per_program: account_metas, + }) + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct CommittedAccountV2 { + pub short_meta: ShortAccountMeta, + // TODO(GabrielePicco): We should read the owner from the delegation record rather + // than deriving/storing it. To remove once the cloning pipeline allow us to easily access the owner. + pub owner: Pubkey, +} + +pub enum CommitType { + /// Regular commit without actions + Standalone(Vec), // accounts to commit + /// Commits accounts and runs actions + WithHandler { + committed_accounts: Vec, + call_handlers: Vec, + }, +} + +/// No CommitedAccounts since it is only used with CommitAction. +pub enum UndelegateType { + Standalone, + WithHandler(Vec), +} + +impl UndelegateType { + pub fn try_from_args<'a>( + args: &UndelegateTypeArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + match args { + UndelegateTypeArgs::Standalone => Ok(UndelegateType::Standalone), + UndelegateTypeArgs::WithHandler { call_handlers } => { + let call_handlers = call_handlers + .iter() + .map(|call_handler| { + CallHandler::try_from_args(call_handler, context) + }) + .collect::, InstructionError>>()?; + Ok(UndelegateType::WithHandler(call_handlers)) + } + } + } +} diff --git a/programs/magicblock/src/magicblock_instruction.rs b/programs/magicblock/src/magicblock_instruction.rs index fc5de8261..8ababb613 100644 --- a/programs/magicblock/src/magicblock_instruction.rs +++ b/programs/magicblock/src/magicblock_instruction.rs @@ -1,102 +1,9 @@ use std::collections::HashMap; -use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; -use num_derive::{FromPrimitive, ToPrimitive}; use serde::{Deserialize, Serialize}; -use solana_sdk::{ - account::Account, - decode_error::DecodeError, - hash::Hash, - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - signature::Keypair, - signer::Signer, - transaction::Transaction, -}; -use thiserror::Error; +use solana_sdk::{account::Account, pubkey::Pubkey}; -use crate::{ - mutate_accounts::set_account_mod_data, - validator::{validator_authority, validator_authority_id}, -}; - -#[derive( - Error, Debug, Serialize, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive, -)] -pub enum MagicBlockProgramError { - #[error("need at least one account to modify")] - NoAccountsToModify, - - #[error("number of accounts to modify needs to match number of account modifications")] - AccountsToModifyNotMatchingAccountModifications, - - #[error("The account modification for the provided key is missing.")] - AccountModificationMissing, - - #[error("first account needs to be MagicBlock authority")] - FirstAccountNeedsToBeMagicBlockAuthority, - - #[error("MagicBlock authority needs to be owned by system program")] - MagicBlockAuthorityNeedsToBeOwnedBySystemProgram, - - #[error("The account resolution for the provided key failed.")] - AccountDataResolutionFailed, - - #[error("The account data for the provided key is missing both from in-memory and ledger storage.")] - AccountDataMissing, - - #[error("The account data for the provided key is missing from in-memory and we are not replaying the ledger.")] - AccountDataMissingFromMemory, - - #[error("Tried to persist data that could not be resolved.")] - AttemptedToPersistUnresolvedData, - - #[error("Tried to persist data that was resolved from storage.")] - AttemptedToPersistDataFromStorage, - - #[error("Encountered an error when persisting account modification data.")] - FailedToPersistAccountModData, -} - -impl DecodeError for MagicBlockProgramError { - fn type_of() -> &'static str { - "MagicBlockProgramError" - } -} - -#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub struct AccountModification { - pub pubkey: Pubkey, - pub lamports: Option, - pub owner: Option, - pub executable: Option, - pub data: Option>, - pub rent_epoch: Option, -} - -impl From<(&Pubkey, &Account)> for AccountModification { - fn from( - (account_pubkey, account): (&Pubkey, &Account), - ) -> AccountModification { - AccountModification { - pubkey: *account_pubkey, - lamports: Some(account.lamports), - owner: Some(account.owner), - executable: Some(account.executable), - data: Some(account.data.clone()), - rent_epoch: Some(account.rent_epoch), - } - } -} - -#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub(crate) struct AccountModificationForInstruction { - pub lamports: Option, - pub owner: Option, - pub executable: Option, - pub data_key: Option, - pub rent_epoch: Option, -} +use crate::args::MagicActionArgs; #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum MagicBlockInstruction { @@ -163,47 +70,6 @@ pub enum MagicBlockInstruction { ScheduleAction(MagicActionArgs), } -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct HandlerArgs { - pub escrow_index: u8, - pub data: Vec, -} - -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub struct CallHandlerArgs { - pub args: HandlerArgs, - pub destination_program: u8, // index of the account - pub accounts: Vec, // indecis of account -} - -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub enum CommitTypeArgs { - Standalone(Vec), // indices on accounts - WithHandler { - committed_accounts: Vec, // indices of accounts - call_handlers: Vec, - }, -} - -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub enum UndelegateTypeArgs { - Standalone, - WithHandler { call_handlers: Vec }, -} - -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub struct CommitAndUndelegateArgs { - pub commit_type: CommitTypeArgs, - pub undelegate_type: UndelegateTypeArgs, -} - -#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub enum MagicActionArgs { - L1Action(Vec), - Commit(CommitTypeArgs), - CommitAndUndelegate(CommitAndUndelegateArgs), -} - // TODO: why that exists? #[allow(unused)] impl MagicBlockInstruction { @@ -229,169 +95,36 @@ impl MagicBlockInstruction { } } -// ----------------- -// ModifyAccounts -// ----------------- -pub fn modify_accounts( - account_modifications: Vec, - recent_blockhash: Hash, -) -> Transaction { - let ix = modify_accounts_instruction(account_modifications); - into_transaction(&validator_authority(), ix, recent_blockhash) -} - -pub fn modify_accounts_instruction( - account_modifications: Vec, -) -> Instruction { - let mut account_metas = - vec![AccountMeta::new(validator_authority_id(), true)]; - let mut account_mods: HashMap = - HashMap::new(); - for account_modification in account_modifications { - account_metas - .push(AccountMeta::new(account_modification.pubkey, false)); - let account_mod_for_instruction = AccountModificationForInstruction { - lamports: account_modification.lamports, - owner: account_modification.owner, - executable: account_modification.executable, - data_key: account_modification.data.map(set_account_mod_data), - rent_epoch: account_modification.rent_epoch, - }; - account_mods - .insert(account_modification.pubkey, account_mod_for_instruction); - } - Instruction::new_with_bincode( - crate::id(), - &MagicBlockInstruction::ModifyAccounts(account_mods), - account_metas, - ) -} - -// ----------------- -// Schedule Commit -// ----------------- -pub fn schedule_commit( - payer: &Keypair, - pubkeys: Vec, - recent_blockhash: Hash, -) -> Transaction { - let ix = schedule_commit_instruction(&payer.pubkey(), pubkeys); - into_transaction(payer, ix, recent_blockhash) -} - -pub(crate) fn schedule_commit_instruction( - payer: &Pubkey, - pdas: Vec, -) -> Instruction { - let mut account_metas = vec![ - AccountMeta::new(*payer, true), - AccountMeta::new(MAGIC_CONTEXT_PUBKEY, false), - ]; - for pubkey in &pdas { - account_metas.push(AccountMeta::new_readonly(*pubkey, true)); - } - Instruction::new_with_bincode( - crate::id(), - &MagicBlockInstruction::ScheduleCommit, - account_metas, - ) -} - -// ----------------- -// Schedule Commit and Undelegate -// ----------------- -pub fn schedule_commit_and_undelegate( - payer: &Keypair, - pubkeys: Vec, - recent_blockhash: Hash, -) -> Transaction { - let ix = - schedule_commit_and_undelegate_instruction(&payer.pubkey(), pubkeys); - into_transaction(payer, ix, recent_blockhash) +#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub struct AccountModification { + pub pubkey: Pubkey, + pub lamports: Option, + pub owner: Option, + pub executable: Option, + pub data: Option>, + pub rent_epoch: Option, } -pub(crate) fn schedule_commit_and_undelegate_instruction( - payer: &Pubkey, - pdas: Vec, -) -> Instruction { - let mut account_metas = vec![ - AccountMeta::new(*payer, true), - AccountMeta::new(MAGIC_CONTEXT_PUBKEY, false), - ]; - for pubkey in &pdas { - account_metas.push(AccountMeta::new_readonly(*pubkey, true)); +impl From<(&Pubkey, &Account)> for AccountModification { + fn from( + (account_pubkey, account): (&Pubkey, &Account), + ) -> AccountModification { + AccountModification { + pubkey: *account_pubkey, + lamports: Some(account.lamports), + owner: Some(account.owner), + executable: Some(account.executable), + data: Some(account.data.clone()), + rent_epoch: Some(account.rent_epoch), + } } - Instruction::new_with_bincode( - crate::id(), - &MagicBlockInstruction::ScheduleCommitAndUndelegate, - account_metas, - ) } -// ----------------- -// Accept Scheduled Commits -// ----------------- -pub fn accept_scheduled_commits(recent_blockhash: Hash) -> Transaction { - let ix = accept_scheduled_commits_instruction(); - into_transaction(&validator_authority(), ix, recent_blockhash) -} - -pub(crate) fn accept_scheduled_commits_instruction() -> Instruction { - let account_metas = vec![ - AccountMeta::new_readonly(validator_authority_id(), true), - AccountMeta::new(MAGIC_CONTEXT_PUBKEY, false), - ]; - Instruction::new_with_bincode( - crate::id(), - &MagicBlockInstruction::AcceptScheduleCommits, - account_metas, - ) -} - -// ----------------- -// Scheduled Commit Sent -// ----------------- -pub fn scheduled_commit_sent( - scheduled_commit_id: u64, - recent_blockhash: Hash, -) -> Transaction { - let ix = scheduled_commit_sent_instruction( - &crate::id(), - &validator_authority_id(), - scheduled_commit_id, - ); - into_transaction(&validator_authority(), ix, recent_blockhash) -} - -pub(crate) fn scheduled_commit_sent_instruction( - magic_block_program: &Pubkey, - validator_authority: &Pubkey, - scheduled_commit_id: u64, -) -> Instruction { - let account_metas = vec![ - AccountMeta::new_readonly(*magic_block_program, false), - AccountMeta::new_readonly(*validator_authority, true), - ]; - Instruction::new_with_bincode( - *magic_block_program, - &MagicBlockInstruction::ScheduledCommitSent(scheduled_commit_id), - account_metas, - ) -} - -// ----------------- -// Utils -// ----------------- -pub(crate) fn into_transaction( - signer: &Keypair, - instruction: Instruction, - recent_blockhash: Hash, -) -> Transaction { - let signers = &[&signer]; - Transaction::new_signed_with_payer( - &[instruction], - Some(&signer.pubkey()), - signers, - recent_blockhash, - ) +#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +pub struct AccountModificationForInstruction { + pub lamports: Option, + pub owner: Option, + pub executable: Option, + pub data_key: Option, + pub rent_epoch: Option, } diff --git a/programs/magicblock/src/magicblock_processor.rs b/programs/magicblock/src/magicblock_processor.rs index a6f966ab9..bf4587999 100644 --- a/programs/magicblock/src/magicblock_processor.rs +++ b/programs/magicblock/src/magicblock_processor.rs @@ -1,14 +1,13 @@ use solana_program_runtime::declare_process_instruction; use solana_sdk::program_utils::limited_deserialize; -use crate::schedule_transactions::process_schedule_action; use crate::{ magicblock_instruction::MagicBlockInstruction, mutate_accounts::process_mutate_accounts, process_scheduled_commit_sent, schedule_transactions::{ - process_accept_scheduled_commits, process_schedule_commit, - ProcessScheduleCommitOptions, + process_accept_scheduled_commits, process_schedule_action, + process_schedule_commit, ProcessScheduleCommitOptions, }, }; @@ -62,11 +61,7 @@ declare_process_instruction!( ) } MagicBlockInstruction::ScheduleAction(args) => { - process_schedule_action( - signers, - invoke_context, - args, - ) + process_schedule_action(signers, invoke_context, args) } } } diff --git a/programs/magicblock/src/mutate_accounts/account_mod_data.rs b/programs/magicblock/src/mutate_accounts/account_mod_data.rs index 006c39e96..484a86015 100644 --- a/programs/magicblock/src/mutate_accounts/account_mod_data.rs +++ b/programs/magicblock/src/mutate_accounts/account_mod_data.rs @@ -12,7 +12,7 @@ use magicblock_core::traits::PersistsAccountModData; use solana_log_collector::ic_msg; use solana_program_runtime::invoke_context::InvokeContext; -use crate::{magicblock_instruction::MagicBlockProgramError, validator}; +use crate::{errors::MagicBlockProgramError, validator}; lazy_static! { /// In order to modify large data chunks we cannot include all the data as part of the diff --git a/programs/magicblock/src/mutate_accounts/process_mutate_accounts.rs b/programs/magicblock/src/mutate_accounts/process_mutate_accounts.rs index 5b23bbec5..7ec81b5a7 100644 --- a/programs/magicblock/src/mutate_accounts/process_mutate_accounts.rs +++ b/programs/magicblock/src/mutate_accounts/process_mutate_accounts.rs @@ -11,9 +11,8 @@ use solana_sdk::{ }; use crate::{ - magicblock_instruction::{ - AccountModificationForInstruction, MagicBlockProgramError, - }, + errors::MagicBlockProgramError, + magicblock_instruction::AccountModificationForInstruction, mutate_accounts::account_mod_data::resolve_account_mod_data, validator::validator_authority_id, }; @@ -277,9 +276,8 @@ mod tests { use super::*; use crate::{ - magicblock_instruction::{ - modify_accounts_instruction, AccountModification, - }, + instruction_utils::InstructionUtils, + magicblock_instruction::AccountModification, test_utils::{ ensure_started_validator, process_instruction, AUTHORITY_BALANCE, }, @@ -309,7 +307,9 @@ mod tests { data: Some(vec![1, 2, 3, 4, 5]), rent_epoch: Some(88), }; - let ix = modify_accounts_instruction(vec![modification.clone()]); + let ix = InstructionUtils::modify_accounts_instruction(vec![ + modification.clone(), + ]); let transaction_accounts = ix .accounts .iter() @@ -376,7 +376,7 @@ mod tests { }; ensure_started_validator(&mut account_data); - let ix = modify_accounts_instruction(vec![ + let ix = InstructionUtils::modify_accounts_instruction(vec![ AccountModification { pubkey: mod_key1, lamports: Some(300), @@ -473,7 +473,7 @@ mod tests { }; ensure_started_validator(&mut account_data); - let ix = modify_accounts_instruction(vec![ + let ix = InstructionUtils::modify_accounts_instruction(vec![ AccountModification { pubkey: mod_key1, lamports: Some(1000), diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs index 210243ecc..c4f3e6cbe 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs @@ -8,11 +8,12 @@ use solana_sdk::{ }; use crate::{ - magic_context::{ConstructionContext, ScheduleAction}, - magicblock_instruction::MagicActionArgs, + args::MagicActionArgs, + magic_schedule_action::ConstructionContext, schedule_transactions::{check_magic_context_id, COMMIT_ID}, utils::accounts::get_instruction_pubkey_with_idx, }; +use crate::magic_schedule_action::ScheduleAction; const PAYER_IDX: u16 = 0; const MAGIC_CONTEXT_IDX: u16 = PAYER_IDX + 1; @@ -124,8 +125,11 @@ fn get_parent_program_id( #[cfg(test)] fn get_parent_program_id( transaction_context: &TransactionContext, - invoke_context: &mut InvokeContext, + _: &mut InvokeContext, ) -> Result, InstructionError> { + use solana_sdk::account::ReadableAccount; + use crate::utils::accounts::get_instruction_account_with_idx; + let first_committee_owner = *get_instruction_account_with_idx( transaction_context, ACTION_ACCOUNTS_OFFSET as u16, diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs index 35d9217ec..ade8ce8a3 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs @@ -9,7 +9,6 @@ use solana_sdk::{ use crate::{ magic_context::{CommittedAccount, MagicContext, ScheduledCommit}, - magicblock_instruction::scheduled_commit_sent, schedule_transactions::{ transaction_scheduler::TransactionScheduler, COMMIT_ID, }, @@ -18,6 +17,7 @@ use crate::{ accounts::{ get_instruction_account_with_idx, get_instruction_pubkey_with_idx, }, + instruction_utils::InstructionUtils, }, validator::validator_authority_id, }; @@ -190,7 +190,8 @@ pub(crate) fn process_schedule_commit( })?; let blockhash = invoke_context.environment_config.blockhash; - let commit_sent_transaction = scheduled_commit_sent(commit_id, blockhash); + let commit_sent_transaction = + InstructionUtils::scheduled_commit_sent(commit_id, blockhash); let commit_sent_sig = commit_sent_transaction.signatures[0]; diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs index 2f93d2aa7..0250f898d 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs @@ -19,11 +19,7 @@ use test_tools_core::init_logger; use crate::{ magic_context::MagicContext, - magicblock_instruction::{ - accept_scheduled_commits_instruction, - schedule_commit_and_undelegate_instruction, - schedule_commit_instruction, MagicBlockInstruction, - }, + magicblock_instruction::MagicBlockInstruction, schedule_transactions::transaction_scheduler::TransactionScheduler, test_utils::{ensure_started_validator, process_instruction}, utils::DELEGATION_PROGRAM_ID, @@ -237,479 +233,509 @@ fn assert_first_commit( ); } -#[test] -fn test_schedule_commit_single_account_success() { - init_logger!(); - let payer = - Keypair::from_seed(b"schedule_commit_single_account_success").unwrap(); - let program = Pubkey::new_unique(); - let committee = Pubkey::new_unique(); +#[cfg(test)] +mod tests { + use super::*; + use crate::utils::instruction_utils::InstructionUtils; + + #[test] + fn test_schedule_commit_single_account_success() { + init_logger!(); + let payer = + Keypair::from_seed(b"schedule_commit_single_account_success") + .unwrap(); + let program = Pubkey::new_unique(); + let committee = Pubkey::new_unique(); + + // 1. We run the transaction that registers the intent to schedule a commit + let (processed_scheduled, magic_context_acc) = { + let (mut account_data, mut transaction_accounts) = + prepare_transaction_with_single_committee( + &payer, program, committee, + ); + + let ix = InstructionUtils::schedule_commit_instruction( + &payer.pubkey(), + vec![committee], + ); - // 1. We run the transaction that registers the intent to schedule a commit - let (processed_scheduled, magic_context_acc) = { - let (mut account_data, mut transaction_accounts) = - prepare_transaction_with_single_committee( - &payer, program, committee, + extend_transaction_accounts_from_ix( + &ix, + &mut account_data, + &mut transaction_accounts, ); - let ix = schedule_commit_instruction(&payer.pubkey(), vec![committee]); + let processed_scheduled = process_instruction( + ix.data.as_slice(), + transaction_accounts.clone(), + ix.accounts, + Ok(()), + ); - extend_transaction_accounts_from_ix( - &ix, - &mut account_data, - &mut transaction_accounts, - ); + // At this point the intent to commit was added to the magic context account, + // but not yet accepted + let magic_context_acc = assert_non_accepted_commits( + &processed_scheduled, + &payer.pubkey(), + 1, + ); - let processed_scheduled = process_instruction( - ix.data.as_slice(), - transaction_accounts.clone(), - ix.accounts, - Ok(()), - ); + (processed_scheduled.clone(), magic_context_acc.clone()) + }; + + // 2. We run the transaction that accepts the scheduled commit + { + let (mut account_data, mut transaction_accounts) = + prepare_transaction_with_single_committee( + &payer, program, committee, + ); + + let ix = InstructionUtils::accept_scheduled_commits_instruction(); + extend_transaction_accounts_from_ix_adding_magic_context( + &ix, + &magic_context_acc, + &mut account_data, + &mut transaction_accounts, + ); - // At this point the intent to commit was added to the magic context account, - // but not yet accepted - let magic_context_acc = assert_non_accepted_commits( - &processed_scheduled, - &payer.pubkey(), - 1, - ); + let processed_accepted = process_instruction( + ix.data.as_slice(), + transaction_accounts, + ix.accounts, + Ok(()), + ); - (processed_scheduled.clone(), magic_context_acc.clone()) - }; + // At this point the intended commits were accepted and moved to the global + let scheduled_commits = assert_accepted_commits( + &processed_accepted, + &payer.pubkey(), + 1, + ); - // 2. We run the transaction that accepts the scheduled commit - { - let (mut account_data, mut transaction_accounts) = - prepare_transaction_with_single_committee( - &payer, program, committee, + assert_first_commit( + &scheduled_commits, + &payer.pubkey(), + &[committee], + false, ); + } + let committed_account = processed_scheduled.last().unwrap(); + assert_eq!(*committed_account.owner(), program); + } - let ix = accept_scheduled_commits_instruction(); - extend_transaction_accounts_from_ix_adding_magic_context( - &ix, - &magic_context_acc, - &mut account_data, - &mut transaction_accounts, - ); + #[test] + fn test_schedule_commit_single_account_and_request_undelegate_success() { + init_logger!(); + let payer = + Keypair::from_seed(b"single_account_with_undelegate_success") + .unwrap(); + let program = Pubkey::new_unique(); + let committee = Pubkey::new_unique(); + + // 1. We run the transaction that registers the intent to schedule a commit + let (processed_scheduled, magic_context_acc) = { + let (mut account_data, mut transaction_accounts) = + prepare_transaction_with_single_committee( + &payer, program, committee, + ); + + let ix = + InstructionUtils::schedule_commit_and_undelegate_instruction( + &payer.pubkey(), + vec![committee], + ); + + extend_transaction_accounts_from_ix( + &ix, + &mut account_data, + &mut transaction_accounts, + ); - let processed_accepted = process_instruction( - ix.data.as_slice(), - transaction_accounts, - ix.accounts, - Ok(()), - ); + let processed_scheduled = process_instruction( + ix.data.as_slice(), + transaction_accounts.clone(), + ix.accounts, + Ok(()), + ); - // At this point the intended commits were accepted and moved to the global - let scheduled_commits = - assert_accepted_commits(&processed_accepted, &payer.pubkey(), 1); + // At this point the intent to commit was added to the magic context account, + // but not yet accepted + let magic_context_acc = assert_non_accepted_commits( + &processed_scheduled, + &payer.pubkey(), + 1, + ); - assert_first_commit( - &scheduled_commits, - &payer.pubkey(), - &[committee], - false, - ); - } - let committed_account = processed_scheduled.last().unwrap(); - assert_eq!(*committed_account.owner(), program); -} + (processed_scheduled.clone(), magic_context_acc.clone()) + }; + + // 2. We run the transaction that accepts the scheduled commit + { + let (mut account_data, mut transaction_accounts) = + prepare_transaction_with_single_committee( + &payer, program, committee, + ); + + let ix = InstructionUtils::accept_scheduled_commits_instruction(); + extend_transaction_accounts_from_ix_adding_magic_context( + &ix, + &magic_context_acc, + &mut account_data, + &mut transaction_accounts, + ); -#[test] -fn test_schedule_commit_single_account_and_request_undelegate_success() { - init_logger!(); - let payer = - Keypair::from_seed(b"single_account_with_undelegate_success").unwrap(); - let program = Pubkey::new_unique(); - let committee = Pubkey::new_unique(); + let processed_accepted = process_instruction( + ix.data.as_slice(), + transaction_accounts, + ix.accounts, + Ok(()), + ); - // 1. We run the transaction that registers the intent to schedule a commit - let (processed_scheduled, magic_context_acc) = { - let (mut account_data, mut transaction_accounts) = - prepare_transaction_with_single_committee( - &payer, program, committee, + // At this point the intended commits were accepted and moved to the global + let scheduled_commits = assert_accepted_commits( + &processed_accepted, + &payer.pubkey(), + 1, ); - let ix = schedule_commit_and_undelegate_instruction( - &payer.pubkey(), - vec![committee], - ); + assert_first_commit( + &scheduled_commits, + &payer.pubkey(), + &[committee], + true, + ); + } + let committed_account = processed_scheduled.last().unwrap(); + assert_eq!(*committed_account.owner(), DELEGATION_PROGRAM_ID); + } - extend_transaction_accounts_from_ix( - &ix, - &mut account_data, - &mut transaction_accounts, - ); + #[test] + fn test_schedule_commit_three_accounts_success() { + init_logger!(); - let processed_scheduled = process_instruction( - ix.data.as_slice(), - transaction_accounts.clone(), - ix.accounts, - Ok(()), - ); + let payer = + Keypair::from_seed(b"schedule_commit_three_accounts_success") + .unwrap(); - // At this point the intent to commit was added to the magic context account, - // but not yet accepted - let magic_context_acc = assert_non_accepted_commits( - &processed_scheduled, - &payer.pubkey(), - 1, - ); + // 1. We run the transaction that registers the intent to schedule a commit + let ( + mut processed_scheduled, + magic_context_acc, + program, + committee_uno, + committee_dos, + committee_tres, + ) = { + let PreparedTransactionThreeCommittees { + mut accounts_data, + committee_uno, + committee_dos, + committee_tres, + mut transaction_accounts, + program, + .. + } = prepare_transaction_with_three_committees(&payer, None); + + let ix = InstructionUtils::schedule_commit_instruction( + &payer.pubkey(), + vec![committee_uno, committee_dos, committee_tres], + ); + extend_transaction_accounts_from_ix( + &ix, + &mut accounts_data, + &mut transaction_accounts, + ); - (processed_scheduled.clone(), magic_context_acc.clone()) - }; + let processed_scheduled = process_instruction( + ix.data.as_slice(), + transaction_accounts, + ix.accounts, + Ok(()), + ); - // 2. We run the transaction that accepts the scheduled commit - { - let (mut account_data, mut transaction_accounts) = - prepare_transaction_with_single_committee( - &payer, program, committee, + // At this point the intent to commit was added to the magic context account, + // but not yet accepted + let magic_context_acc = assert_non_accepted_commits( + &processed_scheduled, + &payer.pubkey(), + 1, ); - let ix = accept_scheduled_commits_instruction(); - extend_transaction_accounts_from_ix_adding_magic_context( - &ix, - &magic_context_acc, - &mut account_data, - &mut transaction_accounts, - ); + ( + processed_scheduled.clone(), + magic_context_acc.clone(), + program, + committee_uno, + committee_dos, + committee_tres, + ) + }; + + // 2. We run the transaction that accepts the scheduled commit + { + let PreparedTransactionThreeCommittees { + mut accounts_data, + mut transaction_accounts, + .. + } = prepare_transaction_with_three_committees( + &payer, + Some((committee_uno, committee_dos, committee_tres)), + ); - let processed_accepted = process_instruction( - ix.data.as_slice(), - transaction_accounts, - ix.accounts, - Ok(()), - ); + let ix = InstructionUtils::accept_scheduled_commits_instruction(); + extend_transaction_accounts_from_ix_adding_magic_context( + &ix, + &magic_context_acc, + &mut accounts_data, + &mut transaction_accounts, + ); - // At this point the intended commits were accepted and moved to the global - let scheduled_commits = - assert_accepted_commits(&processed_accepted, &payer.pubkey(), 1); + let processed_accepted = process_instruction( + ix.data.as_slice(), + transaction_accounts, + ix.accounts, + Ok(()), + ); - assert_first_commit( - &scheduled_commits, - &payer.pubkey(), - &[committee], - true, - ); - } - let committed_account = processed_scheduled.last().unwrap(); - assert_eq!(*committed_account.owner(), DELEGATION_PROGRAM_ID); -} + // At this point the intended commits were accepted and moved to the global + let scheduled_commits = assert_accepted_commits( + &processed_accepted, + &payer.pubkey(), + 1, + ); -#[test] -fn test_schedule_commit_three_accounts_success() { - init_logger!(); + assert_first_commit( + &scheduled_commits, + &payer.pubkey(), + &[committee_uno, committee_dos, committee_tres], + false, + ); + for _ in &[committee_uno, committee_dos, committee_tres] { + let committed_account = processed_scheduled.pop().unwrap(); + assert_eq!(*committed_account.owner(), program); + } + } + } - let payer = - Keypair::from_seed(b"schedule_commit_three_accounts_success").unwrap(); + #[test] + fn test_schedule_commit_three_accounts_and_request_undelegate_success() { + let payer = Keypair::from_seed( + b"three_accounts_and_request_undelegate_success", + ) + .unwrap(); - // 1. We run the transaction that registers the intent to schedule a commit - let ( - mut processed_scheduled, - magic_context_acc, - program, - committee_uno, - committee_dos, - committee_tres, - ) = { - let PreparedTransactionThreeCommittees { - mut accounts_data, + // 1. We run the transaction that registers the intent to schedule a commit + let ( + mut processed_scheduled, + magic_context_acc, + _program, committee_uno, committee_dos, committee_tres, - mut transaction_accounts, - program, - .. - } = prepare_transaction_with_three_committees(&payer, None); - - let ix = schedule_commit_instruction( - &payer.pubkey(), - vec![committee_uno, committee_dos, committee_tres], - ); - extend_transaction_accounts_from_ix( - &ix, - &mut accounts_data, - &mut transaction_accounts, - ); + ) = { + let PreparedTransactionThreeCommittees { + mut accounts_data, + committee_uno, + committee_dos, + committee_tres, + mut transaction_accounts, + program, + .. + } = prepare_transaction_with_three_committees(&payer, None); + + let ix = + InstructionUtils::schedule_commit_and_undelegate_instruction( + &payer.pubkey(), + vec![committee_uno, committee_dos, committee_tres], + ); + + extend_transaction_accounts_from_ix( + &ix, + &mut accounts_data, + &mut transaction_accounts, + ); - let processed_scheduled = process_instruction( - ix.data.as_slice(), - transaction_accounts, - ix.accounts, - Ok(()), - ); + let processed_scheduled = process_instruction( + ix.data.as_slice(), + transaction_accounts, + ix.accounts, + Ok(()), + ); - // At this point the intent to commit was added to the magic context account, - // but not yet accepted - let magic_context_acc = assert_non_accepted_commits( - &processed_scheduled, - &payer.pubkey(), - 1, - ); + // At this point the intent to commit was added to the magic context account, + // but not yet accepted + let magic_context_acc = assert_non_accepted_commits( + &processed_scheduled, + &payer.pubkey(), + 1, + ); - ( - processed_scheduled.clone(), - magic_context_acc.clone(), - program, - committee_uno, - committee_dos, - committee_tres, - ) - }; + ( + processed_scheduled.clone(), + magic_context_acc.clone(), + program, + committee_uno, + committee_dos, + committee_tres, + ) + }; + + // 2. We run the transaction that accepts the scheduled commit + { + let PreparedTransactionThreeCommittees { + mut accounts_data, + mut transaction_accounts, + .. + } = prepare_transaction_with_three_committees( + &payer, + Some((committee_uno, committee_dos, committee_tres)), + ); - // 2. We run the transaction that accepts the scheduled commit - { - let PreparedTransactionThreeCommittees { - mut accounts_data, - mut transaction_accounts, - .. - } = prepare_transaction_with_three_committees( - &payer, - Some((committee_uno, committee_dos, committee_tres)), - ); + let ix = InstructionUtils::accept_scheduled_commits_instruction(); + extend_transaction_accounts_from_ix_adding_magic_context( + &ix, + &magic_context_acc, + &mut accounts_data, + &mut transaction_accounts, + ); - let ix = accept_scheduled_commits_instruction(); - extend_transaction_accounts_from_ix_adding_magic_context( - &ix, - &magic_context_acc, - &mut accounts_data, - &mut transaction_accounts, - ); + let processed_accepted = process_instruction( + ix.data.as_slice(), + transaction_accounts, + ix.accounts, + Ok(()), + ); - let processed_accepted = process_instruction( - ix.data.as_slice(), - transaction_accounts, - ix.accounts, - Ok(()), - ); + // At this point the intended commits were accepted and moved to the global + let scheduled_commits = assert_accepted_commits( + &processed_accepted, + &payer.pubkey(), + 1, + ); - // At this point the intended commits were accepted and moved to the global - let scheduled_commits = - assert_accepted_commits(&processed_accepted, &payer.pubkey(), 1); + assert_first_commit( + &scheduled_commits, + &payer.pubkey(), + &[committee_uno, committee_dos, committee_tres], + true, + ); + for _ in &[committee_uno, committee_dos, committee_tres] { + let committed_account = processed_scheduled.pop().unwrap(); + assert_eq!(*committed_account.owner(), DELEGATION_PROGRAM_ID); + } + } + } - assert_first_commit( - &scheduled_commits, - &payer.pubkey(), - &[committee_uno, committee_dos, committee_tres], - false, - ); - for _ in &[committee_uno, committee_dos, committee_tres] { - let committed_account = processed_scheduled.pop().unwrap(); - assert_eq!(*committed_account.owner(), program); + // ----------------- + // Failure Cases + // ---------------- + fn get_account_metas_for_schedule_commit( + payer: &Pubkey, + pdas: Vec, + ) -> Vec { + let mut account_metas = vec![ + AccountMeta::new(*payer, true), + AccountMeta::new(MAGIC_CONTEXT_PUBKEY, false), + ]; + for pubkey in &pdas { + account_metas.push(AccountMeta::new_readonly(*pubkey, true)); } + account_metas } -} -#[test] -fn test_schedule_commit_three_accounts_and_request_undelegate_success() { - let payer = - Keypair::from_seed(b"three_accounts_and_request_undelegate_success") - .unwrap(); - - // 1. We run the transaction that registers the intent to schedule a commit - let ( - mut processed_scheduled, - magic_context_acc, - _program, - committee_uno, - committee_dos, - committee_tres, - ) = { + fn account_metas_last_committee_not_signer( + payer: &Pubkey, + pdas: Vec, + ) -> Vec { + let mut account_metas = + get_account_metas_for_schedule_commit(payer, pdas); + let last = account_metas.pop().unwrap(); + account_metas.push(AccountMeta::new_readonly(last.pubkey, false)); + account_metas + } + + fn instruction_from_account_metas( + account_metas: Vec, + ) -> solana_sdk::instruction::Instruction { + Instruction::new_with_bincode( + crate::id(), + &MagicBlockInstruction::ScheduleCommit, + account_metas, + ) + } + + #[test] + fn test_schedule_commit_no_pdas_provided_to_ix() { + init_logger!(); + + let payer = + Keypair::from_seed(b"schedule_commit_no_pdas_provided_to_ix") + .unwrap(); + let PreparedTransactionThreeCommittees { mut accounts_data, - committee_uno, - committee_dos, - committee_tres, mut transaction_accounts, - program, .. } = prepare_transaction_with_three_committees(&payer, None); - let ix = schedule_commit_and_undelegate_instruction( - &payer.pubkey(), - vec![committee_uno, committee_dos, committee_tres], + let ix = instruction_from_account_metas( + get_account_metas_for_schedule_commit(&payer.pubkey(), vec![]), ); - extend_transaction_accounts_from_ix( &ix, &mut accounts_data, &mut transaction_accounts, ); - let processed_scheduled = process_instruction( + process_instruction( ix.data.as_slice(), transaction_accounts, ix.accounts, - Ok(()), + Err(InstructionError::NotEnoughAccountKeys), ); + } - // At this point the intent to commit was added to the magic context account, - // but not yet accepted - let magic_context_acc = assert_non_accepted_commits( - &processed_scheduled, - &payer.pubkey(), - 1, - ); + #[test] + fn test_schedule_commit_three_accounts_second_not_owned_by_program_and_not_signer( + ) { + init_logger!(); - ( - processed_scheduled.clone(), - magic_context_acc.clone(), - program, - committee_uno, - committee_dos, - committee_tres, - ) - }; + let payer = + Keypair::from_seed(b"three_accounts_last_not_owned_by_program") + .unwrap(); - // 2. We run the transaction that accepts the scheduled commit - { let PreparedTransactionThreeCommittees { mut accounts_data, + committee_uno, + committee_dos, + committee_tres, mut transaction_accounts, .. - } = prepare_transaction_with_three_committees( - &payer, - Some((committee_uno, committee_dos, committee_tres)), + } = prepare_transaction_with_three_committees(&payer, None); + + accounts_data.insert( + committee_dos, + AccountSharedData::new(0, 0, &Pubkey::new_unique()), + ); + + let ix = instruction_from_account_metas( + account_metas_last_committee_not_signer( + &payer.pubkey(), + vec![committee_uno, committee_tres, committee_dos], + ), ); - let ix = accept_scheduled_commits_instruction(); - extend_transaction_accounts_from_ix_adding_magic_context( + extend_transaction_accounts_from_ix( &ix, - &magic_context_acc, &mut accounts_data, &mut transaction_accounts, ); - let processed_accepted = process_instruction( + process_instruction( ix.data.as_slice(), transaction_accounts, ix.accounts, - Ok(()), - ); - - // At this point the intended commits were accepted and moved to the global - let scheduled_commits = - assert_accepted_commits(&processed_accepted, &payer.pubkey(), 1); - - assert_first_commit( - &scheduled_commits, - &payer.pubkey(), - &[committee_uno, committee_dos, committee_tres], - true, + Err(InstructionError::InvalidAccountOwner), ); - for _ in &[committee_uno, committee_dos, committee_tres] { - let committed_account = processed_scheduled.pop().unwrap(); - assert_eq!(*committed_account.owner(), DELEGATION_PROGRAM_ID); - } } } - -// ----------------- -// Failure Cases -// ---------------- -fn get_account_metas_for_schedule_commit( - payer: &Pubkey, - pdas: Vec, -) -> Vec { - let mut account_metas = vec![ - AccountMeta::new(*payer, true), - AccountMeta::new(MAGIC_CONTEXT_PUBKEY, false), - ]; - for pubkey in &pdas { - account_metas.push(AccountMeta::new_readonly(*pubkey, true)); - } - account_metas -} - -fn account_metas_last_committee_not_signer( - payer: &Pubkey, - pdas: Vec, -) -> Vec { - let mut account_metas = get_account_metas_for_schedule_commit(payer, pdas); - let last = account_metas.pop().unwrap(); - account_metas.push(AccountMeta::new_readonly(last.pubkey, false)); - account_metas -} - -fn instruction_from_account_metas( - account_metas: Vec, -) -> solana_sdk::instruction::Instruction { - Instruction::new_with_bincode( - crate::id(), - &MagicBlockInstruction::ScheduleCommit, - account_metas, - ) -} - -#[test] -fn test_schedule_commit_no_pdas_provided_to_ix() { - init_logger!(); - - let payer = - Keypair::from_seed(b"schedule_commit_no_pdas_provided_to_ix").unwrap(); - - let PreparedTransactionThreeCommittees { - mut accounts_data, - mut transaction_accounts, - .. - } = prepare_transaction_with_three_committees(&payer, None); - - let ix = instruction_from_account_metas( - get_account_metas_for_schedule_commit(&payer.pubkey(), vec![]), - ); - extend_transaction_accounts_from_ix( - &ix, - &mut accounts_data, - &mut transaction_accounts, - ); - - process_instruction( - ix.data.as_slice(), - transaction_accounts, - ix.accounts, - Err(InstructionError::NotEnoughAccountKeys), - ); -} - -#[test] -fn test_schedule_commit_three_accounts_second_not_owned_by_program_and_not_signer( -) { - init_logger!(); - - let payer = Keypair::from_seed(b"three_accounts_last_not_owned_by_program") - .unwrap(); - - let PreparedTransactionThreeCommittees { - mut accounts_data, - committee_uno, - committee_dos, - committee_tres, - mut transaction_accounts, - .. - } = prepare_transaction_with_three_committees(&payer, None); - - accounts_data.insert( - committee_dos, - AccountSharedData::new(0, 0, &Pubkey::new_unique()), - ); - - let ix = instruction_from_account_metas( - account_metas_last_committee_not_signer( - &payer.pubkey(), - vec![committee_uno, committee_tres, committee_dos], - ), - ); - - extend_transaction_accounts_from_ix( - &ix, - &mut accounts_data, - &mut transaction_accounts, - ); - - process_instruction( - ix.data.as_slice(), - transaction_accounts, - ix.accounts, - Err(InstructionError::InvalidAccountOwner), - ); -} diff --git a/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs b/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs index 58d76040f..b6701b187 100644 --- a/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs +++ b/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs @@ -240,7 +240,7 @@ mod tests { use super::*; use crate::{ - magicblock_instruction::scheduled_commit_sent_instruction, + instruction_utils::InstructionUtils, test_utils::{ensure_started_validator, process_instruction}, validator, }; @@ -292,7 +292,7 @@ mod tests { ensure_started_validator(&mut account_data); - let mut ix = scheduled_commit_sent_instruction( + let mut ix = InstructionUtils::scheduled_commit_sent_instruction( &crate::id(), &validator::validator_authority_id(), commit.commit_id, @@ -329,7 +329,7 @@ mod tests { }; ensure_started_validator(&mut account_data); - let ix = scheduled_commit_sent_instruction( + let ix = InstructionUtils::scheduled_commit_sent_instruction( &crate::id(), &fake_validator.pubkey(), commit.commit_id, @@ -364,7 +364,7 @@ mod tests { }; ensure_started_validator(&mut account_data); - let ix = scheduled_commit_sent_instruction( + let ix = InstructionUtils::scheduled_commit_sent_instruction( &fake_program.pubkey(), &validator::validator_authority_id(), commit.commit_id, @@ -393,7 +393,7 @@ mod tests { ensure_started_validator(&mut account_data); - let ix = scheduled_commit_sent_instruction( + let ix = InstructionUtils::scheduled_commit_sent_instruction( &crate::id(), &validator::validator_authority_id(), commit.commit_id, diff --git a/programs/magicblock/src/utils/accounts.rs b/programs/magicblock/src/utils/accounts.rs index 5ad7ea3f2..eaaff189a 100644 --- a/programs/magicblock/src/utils/accounts.rs +++ b/programs/magicblock/src/utils/accounts.rs @@ -11,7 +11,7 @@ use solana_sdk::{ transaction_context::TransactionContext, }; -use crate::magic_context::ShortAccountMeta; +use crate::magic_schedule_action::ShortAccountMeta; pub(crate) fn find_tx_index_of_instruction_account( invoke_context: &InvokeContext, diff --git a/programs/magicblock/src/utils/instruction_utils.rs b/programs/magicblock/src/utils/instruction_utils.rs new file mode 100644 index 000000000..60e9e5e2b --- /dev/null +++ b/programs/magicblock/src/utils/instruction_utils.rs @@ -0,0 +1,202 @@ +use std::collections::HashMap; + +use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; +use solana_program_runtime::__private::Hash; +use solana_sdk::{ + instruction::{AccountMeta, Instruction}, + signature::{Keypair, Signer}, + transaction::Transaction, +}; + +use crate::{ + magicblock_instruction::{ + AccountModification, AccountModificationForInstruction, + MagicBlockInstruction, + }, + mutate_accounts::set_account_mod_data, + validator::{validator_authority, validator_authority_id}, + Pubkey, +}; + +pub struct InstructionUtils; +impl InstructionUtils { + // ----------------- + // Schedule Commit + // ----------------- + #[cfg(test)] + pub fn schedule_commit( + payer: &Keypair, + pubkeys: Vec, + recent_blockhash: Hash, + ) -> Transaction { + let ix = Self::schedule_commit_instruction(&payer.pubkey(), pubkeys); + Self::into_transaction(payer, ix, recent_blockhash) + } + + #[cfg(test)] + pub(crate) fn schedule_commit_instruction( + payer: &Pubkey, + pdas: Vec, + ) -> Instruction { + let mut account_metas = vec![ + AccountMeta::new(*payer, true), + AccountMeta::new(MAGIC_CONTEXT_PUBKEY, false), + ]; + for pubkey in &pdas { + account_metas.push(AccountMeta::new_readonly(*pubkey, true)); + } + Instruction::new_with_bincode( + crate::id(), + &MagicBlockInstruction::ScheduleCommit, + account_metas, + ) + } + + // ----------------- + // Schedule Commit and Undelegate + // ----------------- + #[cfg(test)] + pub fn schedule_commit_and_undelegate( + payer: &Keypair, + pubkeys: Vec, + recent_blockhash: Hash, + ) -> Transaction { + let ix = Self::schedule_commit_and_undelegate_instruction( + &payer.pubkey(), + pubkeys, + ); + Self::into_transaction(payer, ix, recent_blockhash) + } + + #[cfg(test)] + pub(crate) fn schedule_commit_and_undelegate_instruction( + payer: &Pubkey, + pdas: Vec, + ) -> Instruction { + let mut account_metas = vec![ + AccountMeta::new(*payer, true), + AccountMeta::new(MAGIC_CONTEXT_PUBKEY, false), + ]; + for pubkey in &pdas { + account_metas.push(AccountMeta::new_readonly(*pubkey, true)); + } + Instruction::new_with_bincode( + crate::id(), + &MagicBlockInstruction::ScheduleCommitAndUndelegate, + account_metas, + ) + } + + // ----------------- + // Scheduled Commit Sent + // ----------------- + pub fn scheduled_commit_sent( + scheduled_commit_id: u64, + recent_blockhash: Hash, + ) -> Transaction { + let ix = Self::scheduled_commit_sent_instruction( + &crate::id(), + &validator_authority_id(), + scheduled_commit_id, + ); + Self::into_transaction(&validator_authority(), ix, recent_blockhash) + } + + pub(crate) fn scheduled_commit_sent_instruction( + magic_block_program: &Pubkey, + validator_authority: &Pubkey, + scheduled_commit_id: u64, + ) -> Instruction { + let account_metas = vec![ + AccountMeta::new_readonly(*magic_block_program, false), + AccountMeta::new_readonly(*validator_authority, true), + ]; + Instruction::new_with_bincode( + *magic_block_program, + &MagicBlockInstruction::ScheduledCommitSent(scheduled_commit_id), + account_metas, + ) + } + + // ----------------- + // Accept Scheduled Commits + // ----------------- + pub fn accept_scheduled_commits(recent_blockhash: Hash) -> Transaction { + let ix = Self::accept_scheduled_commits_instruction(); + Self::into_transaction(&validator_authority(), ix, recent_blockhash) + } + + pub(crate) fn accept_scheduled_commits_instruction() -> Instruction { + let account_metas = vec![ + AccountMeta::new_readonly(validator_authority_id(), true), + AccountMeta::new(MAGIC_CONTEXT_PUBKEY, false), + ]; + Instruction::new_with_bincode( + crate::id(), + &MagicBlockInstruction::AcceptScheduleCommits, + account_metas, + ) + } + + // ----------------- + // ModifyAccounts + // ----------------- + pub fn modify_accounts( + account_modifications: Vec, + recent_blockhash: Hash, + ) -> Transaction { + let ix = Self::modify_accounts_instruction(account_modifications); + Self::into_transaction(&validator_authority(), ix, recent_blockhash) + } + + pub fn modify_accounts_instruction( + account_modifications: Vec, + ) -> Instruction { + let mut account_metas = + vec![AccountMeta::new(validator_authority_id(), true)]; + let mut account_mods: HashMap< + Pubkey, + AccountModificationForInstruction, + > = HashMap::new(); + for account_modification in account_modifications { + account_metas + .push(AccountMeta::new(account_modification.pubkey, false)); + let account_mod_for_instruction = + AccountModificationForInstruction { + lamports: account_modification.lamports, + owner: account_modification.owner, + executable: account_modification.executable, + data_key: account_modification + .data + .map(set_account_mod_data), + rent_epoch: account_modification.rent_epoch, + }; + account_mods.insert( + account_modification.pubkey, + account_mod_for_instruction, + ); + } + Instruction::new_with_bincode( + crate::id(), + &MagicBlockInstruction::ModifyAccounts(account_mods), + account_metas, + ) + } + + // ----------------- + // Utils + // ----------------- + pub(crate) fn into_transaction( + signer: &Keypair, + instruction: Instruction, + recent_blockhash: Hash, + ) -> Transaction { + let signers = &[&signer]; + Transaction::new_signed_with_payer( + &[instruction], + Some(&signer.pubkey()), + signers, + recent_blockhash, + ) + } +} diff --git a/programs/magicblock/src/utils/mod.rs b/programs/magicblock/src/utils/mod.rs index 9dd1481bb..556ac28cc 100644 --- a/programs/magicblock/src/utils/mod.rs +++ b/programs/magicblock/src/utils/mod.rs @@ -4,6 +4,7 @@ pub mod account_actions; pub mod accounts; #[cfg(not(test))] pub(crate) mod instruction_context_frames; +pub mod instruction_utils; // NOTE: there is no low level SDK currently that exposes the program address // we hardcode it here to avoid either having to pull in the delegation program From f9f0307f165947e48afa221b62ef6593ce450299 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 19 May 2025 15:57:53 +0900 Subject: [PATCH 064/199] feat: replace ScheduledCommit -> SceduledAction in MagicContext --- programs/magicblock/src/lib.rs | 2 +- programs/magicblock/src/magic_context.rs | 80 ++++++++++++++----- .../magicblock/src/magic_schedule_action.rs | 14 +++- .../process_schedule_action.rs | 35 +++++++- .../process_schedule_commit.rs | 4 +- .../transaction_scheduler.rs | 33 ++++---- 6 files changed, 120 insertions(+), 48 deletions(-) diff --git a/programs/magicblock/src/lib.rs b/programs/magicblock/src/lib.rs index 83b096794..87d896a18 100644 --- a/programs/magicblock/src/lib.rs +++ b/programs/magicblock/src/lib.rs @@ -3,7 +3,7 @@ mod magic_context; mod mutate_accounts; mod schedule_transactions; pub use magic_context::{FeePayerAccount, MagicContext, ScheduledCommit}; -mod args; +pub mod args; mod magic_schedule_action; pub mod magicblock_instruction; pub mod magicblock_processor; diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index 6b1552ce0..eb0bbdf1d 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -10,13 +10,10 @@ use solana_sdk::{ transaction::Transaction, }; -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CommittedAccount { - pub pubkey: Pubkey, - // TODO(GabrielePicco): We should read the owner from the delegation record rather - // than deriving/storing it. To remove once the cloning pipeline allow us to easily access the owner. - pub owner: Pubkey, -} +use crate::magic_schedule_action::{ + CommitType, CommittedAccountV2, MagicAction, ScheduledAction, + ShortAccountMeta, +}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FeePayerAccount { @@ -24,17 +21,6 @@ pub struct FeePayerAccount { pub delegated_pda: Pubkey, } -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ScheduledCommit { - pub id: u64, - pub slot: Slot, - pub blockhash: Hash, - pub accounts: Vec, - pub payer: Pubkey, - pub commit_sent_transaction: Transaction, - pub request_undelegation: bool, -} - // Q: can user initiate actions on arbitrary accounts? // No, then he could call any handler on any porgram // Inititating transfer for himself @@ -54,7 +40,7 @@ pub struct ScheduledCommit { #[derive(Debug, Default, Serialize, Deserialize)] pub struct MagicContext { - pub scheduled_commits: Vec, + pub scheduled_commits: Vec, } impl MagicContext { @@ -70,11 +56,11 @@ impl MagicContext { } } - pub(crate) fn add_scheduled_commit(&mut self, commit: ScheduledCommit) { - self.scheduled_commits.push(commit); + pub(crate) fn add_scheduled_action(&mut self, action: ScheduledAction) { + self.scheduled_commits.push(action); } - pub(crate) fn take_scheduled_commits(&mut self) -> Vec { + pub(crate) fn take_scheduled_commits(&mut self) -> Vec { mem::take(&mut self.scheduled_commits) } @@ -98,3 +84,53 @@ fn is_zeroed(buf: &[u8]) -> bool { && chunks.remainder() == &ZEROS[..chunks.remainder().len()] } } + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct ScheduledCommit { + pub id: u64, + pub slot: Slot, + pub blockhash: Hash, + pub accounts: Vec, + pub payer: Pubkey, + pub commit_sent_transaction: Transaction, + pub request_undelegation: bool, +} + +impl From for ScheduledAction { + fn from(value: ScheduledCommit) -> Self { + Self { + id: value.id, + slot: value.slot, + blockhash: value.blockhash, + payer: value.payer, + commit_sent_transaction: value.commit_sent_transaction, + action: MagicAction::Commit(CommitType::Standalone( + value + .accounts + .into_iter() + .map(CommittedAccountV2::from) + .collect(), + )), + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct CommittedAccount { + pub pubkey: Pubkey, + // TODO(GabrielePicco): We should read the owner from the delegation record rather + // than deriving/storing it. To remove once the cloning pipeline allow us to easily access the owner. + pub owner: Pubkey, +} + +impl From for CommittedAccountV2 { + fn from(value: CommittedAccount) -> Self { + Self { + owner: value.owner, + short_meta: ShortAccountMeta { + pubkey: value.pubkey, + is_writable: false, + }, + } + } +} diff --git a/programs/magicblock/src/magic_schedule_action.rs b/programs/magicblock/src/magic_schedule_action.rs index df01e9b05..3bdec39ca 100644 --- a/programs/magicblock/src/magic_schedule_action.rs +++ b/programs/magicblock/src/magic_schedule_action.rs @@ -46,7 +46,8 @@ impl<'a, 'ic> ConstructionContext<'a, 'ic> { } /// Scheduled action to be executed on base layer -pub struct ScheduleAction { +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct ScheduledAction { pub id: u64, pub slot: Slot, pub blockhash: Hash, @@ -56,14 +57,14 @@ pub struct ScheduleAction { pub action: MagicAction, } -impl ScheduleAction { +impl ScheduledAction { pub fn try_new<'a>( args: &MagicActionArgs, commit_id: u64, slot: Slot, payer_pubkey: &Pubkey, context: &ConstructionContext<'a, '_>, - ) -> Result { + ) -> Result { let action = MagicAction::try_from_args(args, &context)?; let blockhash = context.invoke_context.environment_config.blockhash; @@ -71,7 +72,7 @@ impl ScheduleAction { InstructionUtils::scheduled_commit_sent(commit_id, blockhash); let commit_sent_sig = commit_sent_transaction.signatures[0]; - Ok(ScheduleAction { + Ok(ScheduledAction { id: commit_id, slot, blockhash, @@ -83,6 +84,7 @@ impl ScheduleAction { } // Action that user wants to perform on base layer +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum MagicAction { /// Actions without commitment or undelegation CallHandler(Vec), @@ -208,6 +210,7 @@ impl CommitType { } } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CommitAndUndelegate { pub commit_action: CommitType, pub undelegate_action: UndelegateType, @@ -316,8 +319,10 @@ pub struct CommittedAccountV2 { pub owner: Pubkey, } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum CommitType { /// Regular commit without actions + /// TODO: feels like ShortMeta isn't needed Standalone(Vec), // accounts to commit /// Commits accounts and runs actions WithHandler { @@ -327,6 +332,7 @@ pub enum CommitType { } /// No CommitedAccounts since it is only used with CommitAction. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum UndelegateType { Standalone, WithHandler(Vec), diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs index c4f3e6cbe..f349d058e 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs @@ -9,11 +9,13 @@ use solana_sdk::{ use crate::{ args::MagicActionArgs, - magic_schedule_action::ConstructionContext, + magic_schedule_action::{ConstructionContext, ScheduledAction}, schedule_transactions::{check_magic_context_id, COMMIT_ID}, - utils::accounts::get_instruction_pubkey_with_idx, + utils::accounts::{ + get_instruction_account_with_idx, get_instruction_pubkey_with_idx, + }, + TransactionScheduler, }; -use crate::magic_schedule_action::ScheduleAction; const PAYER_IDX: u16 = 0; const MAGIC_CONTEXT_IDX: u16 = PAYER_IDX + 1; @@ -92,7 +94,7 @@ pub(crate) fn process_schedule_action( transaction_context, invoke_context, ); - let schedule_action = ScheduleAction::try_new( + let scheduled_action = ScheduledAction::try_new( &args, commit_id, clock.slot, @@ -100,6 +102,30 @@ pub(crate) fn process_schedule_action( &construction_context, )?; + let context_acc = get_instruction_account_with_idx( + transaction_context, + MAGIC_CONTEXT_IDX, + )?; + TransactionScheduler::schedule_action( + invoke_context, + context_acc, + scheduled_action, + ) + .map_err(|err| { + ic_msg!( + invoke_context, + "ScheduleAction ERR: failed to schedule action: {}", + err + ); + InstructionError::GenericError + })?; + ic_msg!(invoke_context, "Scheduled commit with ID: {}", commit_id); + // ic_msg!( + // invoke_context, + // "ScheduledCommitSent signature: {}", + // commit_sent_sig, + // ); + Ok(()) } @@ -128,6 +154,7 @@ fn get_parent_program_id( _: &mut InvokeContext, ) -> Result, InstructionError> { use solana_sdk::account::ReadableAccount; + use crate::utils::accounts::get_instruction_account_with_idx; let first_committee_owner = *get_instruction_account_with_idx( diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs index ade8ce8a3..529673ea9 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs @@ -212,10 +212,10 @@ pub(crate) fn process_schedule_commit( transaction_context, MAGIC_CONTEXT_IDX, )?; - TransactionScheduler::schedule_commit( + TransactionScheduler::schedule_action( invoke_context, context_acc, - scheduled_commit, + scheduled_commit.into(), ) .map_err(|err| { ic_msg!( diff --git a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs index d6b151e6d..0fc7c370a 100644 --- a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs +++ b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs @@ -12,11 +12,14 @@ use solana_sdk::{ instruction::InstructionError, pubkey::Pubkey, }; -use crate::magic_context::{MagicContext, ScheduledCommit}; +use crate::{ + magic_context::{MagicContext, ScheduledCommit}, + magic_schedule_action::ScheduledAction, +}; #[derive(Clone)] pub struct TransactionScheduler { - scheduled_commits: Arc>>, + scheduled_action: Arc>>, } impl Default for TransactionScheduler { @@ -25,20 +28,20 @@ impl Default for TransactionScheduler { /// This vec tracks commits that went through the entire process of first /// being scheduled into the MagicContext, and then being moved /// over to this global. - static ref SCHEDULED_COMMITS: Arc>> = + static ref SCHEDULED_ACTION: Arc>> = Default::default(); } Self { - scheduled_commits: SCHEDULED_COMMITS.clone(), + scheduled_action: SCHEDULED_ACTION.clone(), } } } impl TransactionScheduler { - pub fn schedule_commit( + pub fn schedule_action( invoke_context: &InvokeContext, context_account: &RefCell, - commit: ScheduledCommit, + commit: ScheduledAction, ) -> Result<(), InstructionError> { let context_data = &mut context_account.borrow_mut(); let mut context = @@ -50,13 +53,13 @@ impl TransactionScheduler { ); InstructionError::GenericError })?; - context.add_scheduled_commit(commit); + context.add_scheduled_action(commit); context_data.set_state(&context)?; Ok(()) } - pub fn accept_scheduled_commits(&self, commits: Vec) { - self.scheduled_commits + pub fn accept_scheduled_commits(&self, commits: Vec) { + self.scheduled_action .write() .expect("scheduled_commits lock poisoned") .extend(commits); @@ -65,9 +68,9 @@ impl TransactionScheduler { pub fn get_scheduled_commits_by_payer( &self, payer: &Pubkey, - ) -> Vec { + ) -> Vec { let commits = self - .scheduled_commits + .scheduled_action .read() .expect("scheduled_commits lock poisoned"); @@ -78,9 +81,9 @@ impl TransactionScheduler { .collect::>() } - pub fn take_scheduled_commits(&self) -> Vec { + pub fn take_scheduled_commits(&self) -> Vec { let mut lock = self - .scheduled_commits + .scheduled_action .write() .expect("scheduled_commits lock poisoned"); mem::take(&mut *lock) @@ -88,7 +91,7 @@ impl TransactionScheduler { pub fn scheduled_commits_len(&self) -> usize { let lock = self - .scheduled_commits + .scheduled_action .read() .expect("scheduled_commits lock poisoned"); @@ -97,7 +100,7 @@ impl TransactionScheduler { pub fn clear_scheduled_commits(&self) { let mut lock = self - .scheduled_commits + .scheduled_action .write() .expect("scheduled_commits lock poisoned"); lock.clear(); From a2a372b3df659676e2f1981a8545b0755ab3d3da Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 19 May 2025 17:00:34 +0900 Subject: [PATCH 065/199] refactor: namings + some logging --- programs/magicblock/src/magic_context.rs | 2 +- programs/magicblock/src/magic_schedule_action.rs | 8 +++----- programs/magicblock/src/schedule_transactions/mod.rs | 6 ++++-- .../process_accept_scheduled_commits.rs | 1 + .../schedule_transactions/process_schedule_action.rs | 12 +++++++----- 5 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index eb0bbdf1d..340534097 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -103,7 +103,7 @@ impl From for ScheduledAction { slot: value.slot, blockhash: value.blockhash, payer: value.payer, - commit_sent_transaction: value.commit_sent_transaction, + action_sent_transaction: value.commit_sent_transaction, action: MagicAction::Commit(CommitType::Standalone( value .accounts diff --git a/programs/magicblock/src/magic_schedule_action.rs b/programs/magicblock/src/magic_schedule_action.rs index 3bdec39ca..ec9b4a81e 100644 --- a/programs/magicblock/src/magic_schedule_action.rs +++ b/programs/magicblock/src/magic_schedule_action.rs @@ -51,7 +51,7 @@ pub struct ScheduledAction { pub id: u64, pub slot: Slot, pub blockhash: Hash, - pub commit_sent_transaction: Transaction, + pub action_sent_transaction: Transaction, pub payer: Pubkey, // Scheduled action pub action: MagicAction, @@ -68,16 +68,14 @@ impl ScheduledAction { let action = MagicAction::try_from_args(args, &context)?; let blockhash = context.invoke_context.environment_config.blockhash; - let commit_sent_transaction = + let action_sent_transaction = InstructionUtils::scheduled_commit_sent(commit_id, blockhash); - let commit_sent_sig = commit_sent_transaction.signatures[0]; - Ok(ScheduledAction { id: commit_id, slot, blockhash, payer: *payer_pubkey, - commit_sent_transaction, + action_sent_transaction, action, }) } diff --git a/programs/magicblock/src/schedule_transactions/mod.rs b/programs/magicblock/src/schedule_transactions/mod.rs index ef23b81d5..740985557 100644 --- a/programs/magicblock/src/schedule_transactions/mod.rs +++ b/programs/magicblock/src/schedule_transactions/mod.rs @@ -1,16 +1,18 @@ +mod process_accept_scheduled_commits; mod process_schedule_action; mod process_schedule_commit; +#[cfg(test)] +mod process_schedule_commit_tests; mod process_scheduled_commit_sent; pub(crate) mod transaction_scheduler; use std::sync::atomic::AtomicU64; +pub(crate) use process_accept_scheduled_commits::*; pub(crate) use process_schedule_action::*; pub(crate) use process_schedule_commit::*; pub use process_scheduled_commit_sent::{ process_scheduled_commit_sent, register_scheduled_commit_sent, SentCommit, }; -#[cfg(test)] -mod process_schedule_commit_tests; pub(crate) static COMMIT_ID: AtomicU64 = AtomicU64::new(0); diff --git a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs @@ -0,0 +1 @@ + diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs index f349d058e..fee97db6a 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs @@ -101,6 +101,8 @@ pub(crate) fn process_schedule_action( payer_pubkey, &construction_context, )?; + let action_sent_signature = + scheduled_action.action_sent_transaction.signatures[0]; let context_acc = get_instruction_account_with_idx( transaction_context, @@ -120,11 +122,11 @@ pub(crate) fn process_schedule_action( InstructionError::GenericError })?; ic_msg!(invoke_context, "Scheduled commit with ID: {}", commit_id); - // ic_msg!( - // invoke_context, - // "ScheduledCommitSent signature: {}", - // commit_sent_sig, - // ); + ic_msg!( + invoke_context, + "ScheduledCommitSent signature: {}", + action_sent_signature, + ); Ok(()) } From c0cf401bf854255b8da0be6534f2330d29b4478a Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 19 May 2025 17:08:22 +0900 Subject: [PATCH 066/199] refactor: separate file for accepted commits --- .../src/schedule_transactions/mod.rs | 27 ++++ .../process_accept_scheduled_commits.rs | 110 ++++++++++++++++ .../process_schedule_commit.rs | 122 +----------------- .../transaction_scheduler.rs | 3 +- 4 files changed, 144 insertions(+), 118 deletions(-) diff --git a/programs/magicblock/src/schedule_transactions/mod.rs b/programs/magicblock/src/schedule_transactions/mod.rs index 740985557..89d7b470c 100644 --- a/programs/magicblock/src/schedule_transactions/mod.rs +++ b/programs/magicblock/src/schedule_transactions/mod.rs @@ -8,11 +8,38 @@ pub(crate) mod transaction_scheduler; use std::sync::atomic::AtomicU64; +use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; pub(crate) use process_accept_scheduled_commits::*; pub(crate) use process_schedule_action::*; pub(crate) use process_schedule_commit::*; pub use process_scheduled_commit_sent::{ process_scheduled_commit_sent, register_scheduled_commit_sent, SentCommit, }; +use solana_log_collector::ic_msg; +use solana_program_runtime::{ + __private::InstructionError, invoke_context::InvokeContext, +}; + +use crate::utils::accounts::get_instruction_pubkey_with_idx; pub(crate) static COMMIT_ID: AtomicU64 = AtomicU64::new(0); + +pub fn check_magic_context_id( + invoke_context: &InvokeContext, + idx: u16, +) -> Result<(), InstructionError> { + let provided_magic_context = get_instruction_pubkey_with_idx( + invoke_context.transaction_context, + idx, + )?; + if !provided_magic_context.eq(&MAGIC_CONTEXT_PUBKEY) { + ic_msg!( + invoke_context, + "ERR: invalid magic context account {}", + provided_magic_context + ); + return Err(InstructionError::MissingAccount); + } + + Ok(()) +} diff --git a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs index 8b1378917..8b999cb81 100644 --- a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs +++ b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs @@ -1 +1,111 @@ +use std::collections::HashSet; +use solana_log_collector::ic_msg; +use solana_program_runtime::{ + __private::{InstructionError, ReadableAccount}, + invoke_context::InvokeContext, +}; + +use crate::{ + schedule_transactions, + utils::accounts::{ + get_instruction_account_with_idx, get_instruction_pubkey_with_idx, + }, + validator::validator_authority_id, + MagicContext, Pubkey, TransactionScheduler, +}; + +pub fn process_accept_scheduled_commits( + signers: HashSet, + invoke_context: &mut InvokeContext, +) -> Result<(), InstructionError> { + const VALIDATOR_AUTHORITY_IDX: u16 = 0; + const MAGIC_CONTEXT_IDX: u16 = VALIDATOR_AUTHORITY_IDX + 1; + + let transaction_context = &invoke_context.transaction_context.clone(); + + // 1. Read all scheduled commits from the `MagicContext` account + // We do this first so we can skip all checks in case there is nothing + // to be processed + schedule_transactions::check_magic_context_id( + invoke_context, + MAGIC_CONTEXT_IDX, + )?; + let magic_context_acc = get_instruction_account_with_idx( + transaction_context, + MAGIC_CONTEXT_IDX, + )?; + let mut magic_context = + bincode::deserialize::(magic_context_acc.borrow().data()) + .map_err(|err| { + ic_msg!( + invoke_context, + "Failed to deserialize MagicContext: {}", + err + ); + InstructionError::InvalidAccountData + })?; + if magic_context.scheduled_commits.is_empty() { + ic_msg!( + invoke_context, + "AcceptScheduledCommits: no scheduled commits to accept" + ); + // NOTE: we should have not been called if no commits are scheduled + return Ok(()); + } + + // 2. Check that the validator authority (first account) is correct and signer + let provided_validator_auth = get_instruction_pubkey_with_idx( + transaction_context, + VALIDATOR_AUTHORITY_IDX, + )?; + let validator_auth = validator_authority_id(); + if !provided_validator_auth.eq(&validator_auth) { + ic_msg!( + invoke_context, + "AcceptScheduledCommits ERR: invalid validator authority {}, should be {}", + provided_validator_auth, + validator_auth + ); + return Err(InstructionError::InvalidArgument); + } + if !signers.contains(&validator_auth) { + ic_msg!( + invoke_context, + "AcceptScheduledCommits ERR: validator authority pubkey {} not in signers", + validator_auth + ); + return Err(InstructionError::MissingRequiredSignature); + } + + // 3. Move scheduled commits (without copying) + let scheduled_commits = magic_context.take_scheduled_commits(); + ic_msg!( + invoke_context, + "AcceptScheduledCommits: accepted {} scheduled commit(s)", + scheduled_commits.len() + ); + TransactionScheduler::default().accept_scheduled_commits(scheduled_commits); + + // 4. Serialize and store the updated `MagicContext` account + // Zero fill account before updating data + // NOTE: this may become expensive, but is a security measure and also prevents + // accidentally interpreting old data when deserializing + magic_context_acc + .borrow_mut() + .set_data_from_slice(&MagicContext::ZERO); + + magic_context_acc + .borrow_mut() + .serialize_data(&magic_context) + .map_err(|err| { + ic_msg!( + invoke_context, + "Failed to serialize MagicContext: {}", + err + ); + InstructionError::GenericError + })?; + + Ok(()) +} diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs index 529673ea9..8c53a489d 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs @@ -1,6 +1,5 @@ use std::{collections::HashSet, sync::atomic::Ordering}; -use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; use solana_log_collector::ic_msg; use solana_program_runtime::invoke_context::InvokeContext; use solana_sdk::{ @@ -8,7 +7,8 @@ use solana_sdk::{ }; use crate::{ - magic_context::{CommittedAccount, MagicContext, ScheduledCommit}, + magic_context::{CommittedAccount, ScheduledCommit}, + schedule_transactions, schedule_transactions::{ transaction_scheduler::TransactionScheduler, COMMIT_ID, }, @@ -19,7 +19,6 @@ use crate::{ }, instruction_utils::InstructionUtils, }, - validator::validator_authority_id, }; #[derive(Default)] @@ -35,7 +34,10 @@ pub(crate) fn process_schedule_commit( const PAYER_IDX: u16 = 0; const MAGIC_CONTEXT_IDX: u16 = PAYER_IDX + 1; - check_magic_context_id(invoke_context, MAGIC_CONTEXT_IDX)?; + schedule_transactions::check_magic_context_id( + invoke_context, + MAGIC_CONTEXT_IDX, + )?; let transaction_context = &invoke_context.transaction_context.clone(); let ix_ctx = transaction_context.get_current_instruction_context()?; @@ -234,115 +236,3 @@ pub(crate) fn process_schedule_commit( Ok(()) } - -pub fn process_accept_scheduled_commits( - signers: HashSet, - invoke_context: &mut InvokeContext, -) -> Result<(), InstructionError> { - const VALIDATOR_AUTHORITY_IDX: u16 = 0; - const MAGIC_CONTEXT_IDX: u16 = VALIDATOR_AUTHORITY_IDX + 1; - - let transaction_context = &invoke_context.transaction_context.clone(); - - // 1. Read all scheduled commits from the `MagicContext` account - // We do this first so we can skip all checks in case there is nothing - // to be processed - check_magic_context_id(invoke_context, MAGIC_CONTEXT_IDX)?; - let magic_context_acc = get_instruction_account_with_idx( - transaction_context, - MAGIC_CONTEXT_IDX, - )?; - let mut magic_context = - bincode::deserialize::(magic_context_acc.borrow().data()) - .map_err(|err| { - ic_msg!( - invoke_context, - "Failed to deserialize MagicContext: {}", - err - ); - InstructionError::InvalidAccountData - })?; - if magic_context.scheduled_commits.is_empty() { - ic_msg!( - invoke_context, - "AcceptScheduledCommits: no scheduled commits to accept" - ); - // NOTE: we should have not been called if no commits are scheduled - return Ok(()); - } - - // 2. Check that the validator authority (first account) is correct and signer - let provided_validator_auth = get_instruction_pubkey_with_idx( - transaction_context, - VALIDATOR_AUTHORITY_IDX, - )?; - let validator_auth = validator_authority_id(); - if !provided_validator_auth.eq(&validator_auth) { - ic_msg!( - invoke_context, - "AcceptScheduledCommits ERR: invalid validator authority {}, should be {}", - provided_validator_auth, - validator_auth - ); - return Err(InstructionError::InvalidArgument); - } - if !signers.contains(&validator_auth) { - ic_msg!( - invoke_context, - "AcceptScheduledCommits ERR: validator authority pubkey {} not in signers", - validator_auth - ); - return Err(InstructionError::MissingRequiredSignature); - } - - // 3. Move scheduled commits (without copying) - let scheduled_commits = magic_context.take_scheduled_commits(); - ic_msg!( - invoke_context, - "AcceptScheduledCommits: accepted {} scheduled commit(s)", - scheduled_commits.len() - ); - TransactionScheduler::default().accept_scheduled_commits(scheduled_commits); - - // 4. Serialize and store the updated `MagicContext` account - // Zero fill account before updating data - // NOTE: this may become expensive, but is a security measure and also prevents - // accidentally interpreting old data when deserializing - magic_context_acc - .borrow_mut() - .set_data_from_slice(&MagicContext::ZERO); - - magic_context_acc - .borrow_mut() - .serialize_data(&magic_context) - .map_err(|err| { - ic_msg!( - invoke_context, - "Failed to serialize MagicContext: {}", - err - ); - InstructionError::GenericError - })?; - - Ok(()) -} - -pub fn check_magic_context_id( - invoke_context: &InvokeContext, - idx: u16, -) -> Result<(), InstructionError> { - let provided_magic_context = get_instruction_pubkey_with_idx( - invoke_context.transaction_context, - idx, - )?; - if !provided_magic_context.eq(&MAGIC_CONTEXT_PUBKEY) { - ic_msg!( - invoke_context, - "ERR: invalid magic context account {}", - provided_magic_context - ); - return Err(InstructionError::MissingAccount); - } - - Ok(()) -} diff --git a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs index 0fc7c370a..58cb38272 100644 --- a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs +++ b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs @@ -13,8 +13,7 @@ use solana_sdk::{ }; use crate::{ - magic_context::{MagicContext, ScheduledCommit}, - magic_schedule_action::ScheduledAction, + magic_context::MagicContext, magic_schedule_action::ScheduledAction, }; #[derive(Clone)] From 9775d7dc9b9dee725171d2aaa1edaada50f31dae Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 19 May 2025 17:51:28 +0900 Subject: [PATCH 067/199] feat: error on process_schedule_action call until feature fully supported + some conversions --- programs/magicblock/src/magic_context.rs | 58 ++++++++++++++++++- .../process_schedule_action.rs | 6 ++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index 340534097..b4ffc57bc 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -12,7 +12,7 @@ use solana_sdk::{ use crate::magic_schedule_action::{ CommitType, CommittedAccountV2, MagicAction, ScheduledAction, - ShortAccountMeta, + ShortAccountMeta, UndelegateType, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -115,6 +115,53 @@ impl From for ScheduledAction { } } +impl TryFrom for ScheduledCommit { + type Error = (); + fn try_from(value: ScheduledAction) -> Result { + fn extract_accounts( + commit_type: CommitType, + ) -> Result, ()> { + match commit_type { + CommitType::Standalone(committed_accounts) => { + Ok(committed_accounts + .into_iter() + .map(CommittedAccount::from) + .collect()) + } + CommitType::WithHandler { .. } => Err(()), + } + } + + let (accounts, request_undelegation) = match value.action { + MagicAction::Commit(commit_action) => { + let accounts = extract_accounts(commit_action)?; + Ok((accounts, false)) + } + MagicAction::CommitAndUndelegate(value) => { + if let UndelegateType::Standalone = value.undelegate_action { + Ok(()) + } else { + Err(()) + }?; + + let accounts = extract_accounts(value.commit_action)?; + Ok((accounts, true)) + } + MagicAction::CallHandler(_) => Err(()), + }?; + + Ok(Self { + id: value.id, + slot: value.slot, + blockhash: value.blockhash, + payer: value.payer, + commit_sent_transaction: value.action_sent_transaction, + accounts, + request_undelegation, + }) + } +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CommittedAccount { pub pubkey: Pubkey, @@ -134,3 +181,12 @@ impl From for CommittedAccountV2 { } } } + +impl From for CommittedAccount { + fn from(value: CommittedAccountV2) -> Self { + Self { + pubkey: value.short_meta.pubkey, + owner: value.owner, + } + } +} diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs index fee97db6a..482bd3456 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs @@ -20,12 +20,18 @@ use crate::{ const PAYER_IDX: u16 = 0; const MAGIC_CONTEXT_IDX: u16 = PAYER_IDX + 1; const ACTION_ACCOUNTS_OFFSET: usize = MAGIC_CONTEXT_IDX as usize + 1; +const ACTIONS_SUPPORTED: bool = false; pub(crate) fn process_schedule_action( signers: HashSet, invoke_context: &mut InvokeContext, args: MagicActionArgs, ) -> Result<(), InstructionError> { + // TODO: remove once actions are supported + if !ACTIONS_SUPPORTED { + return Err(InstructionError::InvalidInstructionData); + } + check_magic_context_id(invoke_context, MAGIC_CONTEXT_IDX)?; let transaction_context = &invoke_context.transaction_context.clone(); From 597435e042cbefb30440e2ee6a5758ab58901303 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 19 May 2025 18:21:08 +0900 Subject: [PATCH 068/199] feat: until supported converting ScheduledAction to old ScheduledCommit. Calling schedule action will throw an error for now --- .../src/remote_scheduled_commits_processor.rs | 13 ++++++- programs/magicblock/src/magic_context.rs | 36 +++++++++++-------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 92a268fcd..a37e3018c 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -47,9 +47,20 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { IAP: InternalAccountProvider, CC: ChangesetCommittor, { - let scheduled_commits = + let scheduled_actions = self.transaction_scheduler.take_scheduled_commits(); + // TODO(edwin): remove once actions are supported + let scheduled_commits: Vec = scheduled_actions + .into_iter() + .filter_map(|action| { + action + .try_into() + .inspect_err(|err| error!("Unexpected action: {:?}", err)) + .ok() + }) + .collect(); + if scheduled_commits.is_empty() { return Ok(()); } diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index b4ffc57bc..55661d2eb 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -11,8 +11,8 @@ use solana_sdk::{ }; use crate::magic_schedule_action::{ - CommitType, CommittedAccountV2, MagicAction, ScheduledAction, - ShortAccountMeta, UndelegateType, + CommitAndUndelegate, CommitType, CommittedAccountV2, MagicAction, + ScheduledAction, ShortAccountMeta, UndelegateType, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -116,11 +116,11 @@ impl From for ScheduledAction { } impl TryFrom for ScheduledCommit { - type Error = (); + type Error = MagicAction; fn try_from(value: ScheduledAction) -> Result { fn extract_accounts( commit_type: CommitType, - ) -> Result, ()> { + ) -> Result, CommitType> { match commit_type { CommitType::Standalone(committed_accounts) => { Ok(committed_accounts @@ -128,26 +128,34 @@ impl TryFrom for ScheduledCommit { .map(CommittedAccount::from) .collect()) } - CommitType::WithHandler { .. } => Err(()), + val @ CommitType::WithHandler { .. } => Err(val), } } let (accounts, request_undelegation) = match value.action { MagicAction::Commit(commit_action) => { - let accounts = extract_accounts(commit_action)?; + let accounts = extract_accounts(commit_action) + .map_err(MagicAction::Commit)?; Ok((accounts, false)) } MagicAction::CommitAndUndelegate(value) => { - if let UndelegateType::Standalone = value.undelegate_action { - Ok(()) - } else { - Err(()) - }?; - - let accounts = extract_accounts(value.commit_action)?; + if let UndelegateType::WithHandler(..) = + &value.undelegate_action + { + return Err(MagicAction::CommitAndUndelegate(value)); + }; + + let accounts = extract_accounts(value.commit_action).map_err( + |commit_type| { + MagicAction::CommitAndUndelegate(CommitAndUndelegate { + commit_action: commit_type, + undelegate_action: value.undelegate_action, + }) + }, + )?; Ok((accounts, true)) } - MagicAction::CallHandler(_) => Err(()), + err @ MagicAction::CallHandler(_) => Err(err), }?; Ok(Self { From a955a1232cfbe4f677c2fc6e9fdd7d701a6f9556 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 19 May 2025 21:07:39 +0900 Subject: [PATCH 069/199] fix: tests + bug --- .../src/remote_scheduled_commits_processor.rs | 6 +- programs/magicblock/src/magic_context.rs | 24 +++++-- .../process_accept_scheduled_commits.rs | 2 +- .../process_schedule_commit_tests.rs | 68 +++++++++++++------ .../transaction_scheduler.rs | 10 +-- 5 files changed, 74 insertions(+), 36 deletions(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index a37e3018c..80e5ec014 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -48,7 +48,7 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { CC: ChangesetCommittor, { let scheduled_actions = - self.transaction_scheduler.take_scheduled_commits(); + self.transaction_scheduler.take_scheduled_actions(); // TODO(edwin): remove once actions are supported let scheduled_commits: Vec = scheduled_actions @@ -193,11 +193,11 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { } fn scheduled_commits_len(&self) -> usize { - self.transaction_scheduler.scheduled_commits_len() + self.transaction_scheduler.scheduled_actions_len() } fn clear_scheduled_commits(&self) { - self.transaction_scheduler.clear_scheduled_commits(); + self.transaction_scheduler.clear_scheduled_actions(); } } diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index 55661d2eb..b23c3c23b 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -98,19 +98,29 @@ pub struct ScheduledCommit { impl From for ScheduledAction { fn from(value: ScheduledCommit) -> Self { + let commit_type = CommitType::Standalone( + value + .accounts + .into_iter() + .map(CommittedAccountV2::from) + .collect(), + ); + let action = if value.request_undelegation { + MagicAction::CommitAndUndelegate(CommitAndUndelegate { + commit_action: commit_type, + undelegate_action: UndelegateType::Standalone + }) + } else { + MagicAction::Commit(commit_type) + }; + Self { id: value.id, slot: value.slot, blockhash: value.blockhash, payer: value.payer, action_sent_transaction: value.commit_sent_transaction, - action: MagicAction::Commit(CommitType::Standalone( - value - .accounts - .into_iter() - .map(CommittedAccountV2::from) - .collect(), - )), + action } } } diff --git a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs index 8b999cb81..19e424233 100644 --- a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs +++ b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs @@ -85,7 +85,7 @@ pub fn process_accept_scheduled_commits( "AcceptScheduledCommits: accepted {} scheduled commit(s)", scheduled_commits.len() ); - TransactionScheduler::default().accept_scheduled_commits(scheduled_commits); + TransactionScheduler::default().accept_scheduled_actions(scheduled_commits); // 4. Serialize and store the updated `MagicContext` account // Zero fill account before updating data diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs index 0250f898d..ecd110ffe 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs @@ -19,6 +19,7 @@ use test_tools_core::init_logger; use crate::{ magic_context::MagicContext, + magic_schedule_action::ScheduledAction, magicblock_instruction::MagicBlockInstruction, schedule_transactions::transaction_scheduler::TransactionScheduler, test_utils::{ensure_started_validator, process_instruction}, @@ -133,7 +134,7 @@ fn find_magic_context_account( .find(|acc| acc.owner() == &crate::id() && acc.lamports() == u64::MAX) } -fn assert_non_accepted_commits<'a>( +fn assert_non_accepted_actions<'a>( processed_scheduled: &'a [AccountSharedData], payer: &Pubkey, expected_non_accepted_commits: usize, @@ -143,34 +144,34 @@ fn assert_non_accepted_commits<'a>( let magic_context = bincode::deserialize::(magic_context_acc.data()).unwrap(); - let accepted_scheduled_commits = - TransactionScheduler::default().get_scheduled_commits_by_payer(payer); + let accepted_scheduled_actions = + TransactionScheduler::default().get_scheduled_actions_by_payer(payer); assert_eq!( magic_context.scheduled_commits.len(), expected_non_accepted_commits ); - assert_eq!(accepted_scheduled_commits.len(), 0); + assert_eq!(accepted_scheduled_actions.len(), 0); magic_context_acc } -fn assert_accepted_commits( +fn assert_accepted_actions( processed_accepted: &[AccountSharedData], payer: &Pubkey, - expected_scheduled_commits: usize, -) -> Vec { + expected_scheduled_actions: usize, +) -> Vec { let magic_context_acc = find_magic_context_account(processed_accepted) .expect("magic context account not found"); let magic_context = bincode::deserialize::(magic_context_acc.data()).unwrap(); - let scheduled_commits = - TransactionScheduler::default().get_scheduled_commits_by_payer(payer); + let scheduled_actions = + TransactionScheduler::default().get_scheduled_actions_by_payer(payer); assert_eq!(magic_context.scheduled_commits.len(), 0); - assert_eq!(scheduled_commits.len(), expected_scheduled_commits); + assert_eq!(scheduled_actions.len(), expected_scheduled_actions); - scheduled_commits + scheduled_actions } fn extend_transaction_accounts_from_ix( @@ -236,7 +237,10 @@ fn assert_first_commit( #[cfg(test)] mod tests { use super::*; - use crate::utils::instruction_utils::InstructionUtils; + use crate::{ + magic_schedule_action::MagicAction, + utils::instruction_utils::InstructionUtils, + }; #[test] fn test_schedule_commit_single_account_success() { @@ -274,7 +278,7 @@ mod tests { // At this point the intent to commit was added to the magic context account, // but not yet accepted - let magic_context_acc = assert_non_accepted_commits( + let magic_context_acc = assert_non_accepted_actions( &processed_scheduled, &payer.pubkey(), 1, @@ -306,12 +310,18 @@ mod tests { ); // At this point the intended commits were accepted and moved to the global - let scheduled_commits = assert_accepted_commits( + let scheduled_commits = assert_accepted_actions( &processed_accepted, &payer.pubkey(), 1, ); + let scheduled_commits = scheduled_commits + .into_iter() + .map(|el| el.try_into()) + .collect::, MagicAction>>() + .expect("only commit action"); + assert_first_commit( &scheduled_commits, &payer.pubkey(), @@ -360,7 +370,7 @@ mod tests { // At this point the intent to commit was added to the magic context account, // but not yet accepted - let magic_context_acc = assert_non_accepted_commits( + let magic_context_acc = assert_non_accepted_actions( &processed_scheduled, &payer.pubkey(), 1, @@ -392,12 +402,18 @@ mod tests { ); // At this point the intended commits were accepted and moved to the global - let scheduled_commits = assert_accepted_commits( + let scheduled_commits = assert_accepted_actions( &processed_accepted, &payer.pubkey(), 1, ); + let scheduled_commits = scheduled_commits + .into_iter() + .map(|el| el.try_into()) + .collect::, MagicAction>>() + .expect("only commit action"); + assert_first_commit( &scheduled_commits, &payer.pubkey(), @@ -455,7 +471,7 @@ mod tests { // At this point the intent to commit was added to the magic context account, // but not yet accepted - let magic_context_acc = assert_non_accepted_commits( + let magic_context_acc = assert_non_accepted_actions( &processed_scheduled, &payer.pubkey(), 1, @@ -498,12 +514,18 @@ mod tests { ); // At this point the intended commits were accepted and moved to the global - let scheduled_commits = assert_accepted_commits( + let scheduled_commits = assert_accepted_actions( &processed_accepted, &payer.pubkey(), 1, ); + let scheduled_commits = scheduled_commits + .into_iter() + .map(|el| el.try_into()) + .collect::, MagicAction>>() + .expect("only commit action"); + assert_first_commit( &scheduled_commits, &payer.pubkey(), @@ -564,7 +586,7 @@ mod tests { // At this point the intent to commit was added to the magic context account, // but not yet accepted - let magic_context_acc = assert_non_accepted_commits( + let magic_context_acc = assert_non_accepted_actions( &processed_scheduled, &payer.pubkey(), 1, @@ -607,12 +629,18 @@ mod tests { ); // At this point the intended commits were accepted and moved to the global - let scheduled_commits = assert_accepted_commits( + let scheduled_commits = assert_accepted_actions( &processed_accepted, &payer.pubkey(), 1, ); + let scheduled_commits = scheduled_commits + .into_iter() + .map(|el| el.try_into()) + .collect::, MagicAction>>() + .expect("only commit action"); + assert_first_commit( &scheduled_commits, &payer.pubkey(), diff --git a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs index 58cb38272..051fe13c9 100644 --- a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs +++ b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs @@ -57,14 +57,14 @@ impl TransactionScheduler { Ok(()) } - pub fn accept_scheduled_commits(&self, commits: Vec) { + pub fn accept_scheduled_actions(&self, commits: Vec) { self.scheduled_action .write() .expect("scheduled_commits lock poisoned") .extend(commits); } - pub fn get_scheduled_commits_by_payer( + pub fn get_scheduled_actions_by_payer( &self, payer: &Pubkey, ) -> Vec { @@ -80,7 +80,7 @@ impl TransactionScheduler { .collect::>() } - pub fn take_scheduled_commits(&self) -> Vec { + pub fn take_scheduled_actions(&self) -> Vec { let mut lock = self .scheduled_action .write() @@ -88,7 +88,7 @@ impl TransactionScheduler { mem::take(&mut *lock) } - pub fn scheduled_commits_len(&self) -> usize { + pub fn scheduled_actions_len(&self) -> usize { let lock = self .scheduled_action .read() @@ -97,7 +97,7 @@ impl TransactionScheduler { lock.len() } - pub fn clear_scheduled_commits(&self) { + pub fn clear_scheduled_actions(&self) { let mut lock = self .scheduled_action .write() From 39c4fd4c9dcff25615952d7e016dcf9cd8b4cb28 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 20 May 2025 18:28:45 +0900 Subject: [PATCH 070/199] refactor: renamings --- programs/magicblock/src/magic_context.rs | 4 ++-- .../process_schedule_action.rs | 2 +- .../schedule_transactions/transaction_scheduler.rs | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index b23c3c23b..6e559888b 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -108,7 +108,7 @@ impl From for ScheduledAction { let action = if value.request_undelegation { MagicAction::CommitAndUndelegate(CommitAndUndelegate { commit_action: commit_type, - undelegate_action: UndelegateType::Standalone + undelegate_action: UndelegateType::Standalone, }) } else { MagicAction::Commit(commit_type) @@ -120,7 +120,7 @@ impl From for ScheduledAction { blockhash: value.blockhash, payer: value.payer, action_sent_transaction: value.commit_sent_transaction, - action + action, } } } diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs index 482bd3456..40d1abd5f 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_action.rs @@ -43,7 +43,7 @@ pub(crate) fn process_schedule_action( .ok_or_else(|| { ic_msg!( invoke_context, - "ScheduleCommit ERR: Magic program account not found" + "ScheduleAction ERR: Magic program account not found" ); InstructionError::UnsupportedProgramId })?; diff --git a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs index 051fe13c9..a961e5965 100644 --- a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs +++ b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs @@ -40,7 +40,7 @@ impl TransactionScheduler { pub fn schedule_action( invoke_context: &InvokeContext, context_account: &RefCell, - commit: ScheduledAction, + action: ScheduledAction, ) -> Result<(), InstructionError> { let context_data = &mut context_account.borrow_mut(); let mut context = @@ -52,7 +52,7 @@ impl TransactionScheduler { ); InstructionError::GenericError })?; - context.add_scheduled_action(commit); + context.add_scheduled_action(action); context_data.set_state(&context)?; Ok(()) } @@ -60,7 +60,7 @@ impl TransactionScheduler { pub fn accept_scheduled_actions(&self, commits: Vec) { self.scheduled_action .write() - .expect("scheduled_commits lock poisoned") + .expect("scheduled_action lock poisoned") .extend(commits); } @@ -71,7 +71,7 @@ impl TransactionScheduler { let commits = self .scheduled_action .read() - .expect("scheduled_commits lock poisoned"); + .expect("scheduled_action lock poisoned"); commits .iter() @@ -84,7 +84,7 @@ impl TransactionScheduler { let mut lock = self .scheduled_action .write() - .expect("scheduled_commits lock poisoned"); + .expect("scheduled_action lock poisoned"); mem::take(&mut *lock) } @@ -92,7 +92,7 @@ impl TransactionScheduler { let lock = self .scheduled_action .read() - .expect("scheduled_commits lock poisoned"); + .expect("scheduled_action lock poisoned"); lock.len() } @@ -101,7 +101,7 @@ impl TransactionScheduler { let mut lock = self .scheduled_action .write() - .expect("scheduled_commits lock poisoned"); + .expect("scheduled_action lock poisoned"); lock.clear(); } } From 1abe69c43d66fc05e1cc2661a86a440cbb4f0d70 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 21 May 2025 15:35:17 +0700 Subject: [PATCH 071/199] fix: bug --- programs/magicblock/src/magic_schedule_action.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/magicblock/src/magic_schedule_action.rs b/programs/magicblock/src/magic_schedule_action.rs index ec9b4a81e..4c33029aa 100644 --- a/programs/magicblock/src/magic_schedule_action.rs +++ b/programs/magicblock/src/magic_schedule_action.rs @@ -126,7 +126,7 @@ impl CommitType { let acc = get_instruction_account_with_idx(context.transaction_context, *index as u16)?; let acc_owner = *acc.borrow().owner(); - if context.parent_program_id.as_ref() != Some(acc_pubkey) && !context.signers.contains(acc_pubkey) { + if context.parent_program_id != Some(acc_owner) && !context.signers.contains(acc_pubkey) { match context.parent_program_id { None => { ic_msg!( From 00733705f4b0f977a7c474af70aa4fe2fd069154 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 5 Jun 2025 13:27:03 +0900 Subject: [PATCH 072/199] fix: rebase --- magicblock-accounts/src/remote_scheduled_commits_processor.rs | 4 ++-- magicblock-api/src/magic_validator.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 80e5ec014..975be02ee 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -17,8 +17,8 @@ use magicblock_committor_service::{ }; use magicblock_processor::execute_transaction::execute_legacy_transaction; use magicblock_program::{ - register_scheduled_commit_sent, FeePayerAccount, Pubkey, SentCommit, - TransactionScheduler, + register_scheduled_commit_sent, FeePayerAccount, Pubkey, ScheduledCommit, + SentCommit, TransactionScheduler, }; use magicblock_transaction_status::TransactionStatusSender; use solana_sdk::{ diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index a5925e2a6..df8744cea 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -868,4 +868,4 @@ fn try_get_remote_accounts_and_rpc_config( Some(CommitmentLevel::Confirmed), ); Ok((accounts_config, remote_rpc_config)) -} \ No newline at end of file +} From 17e0dc1235c384e511dd86591eb03a76e1d8a352 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 5 Jun 2025 14:22:22 +0900 Subject: [PATCH 073/199] refactor: renamings --- programs/magicblock/src/args.rs | 16 +-- programs/magicblock/src/lib.rs | 2 +- programs/magicblock/src/magic_context.rs | 65 ++++------- ...action.rs => magic_schedule_l1_message.rs} | 104 +++++++++--------- .../magicblock/src/magicblock_instruction.rs | 6 +- .../magicblock/src/magicblock_processor.rs | 6 +- .../src/schedule_transactions/mod.rs | 6 +- .../process_schedule_commit.rs | 4 +- .../process_schedule_commit_tests.rs | 14 +-- ...tion.rs => process_schedule_l1_message.rs} | 18 +-- .../transaction_scheduler.rs | 14 +-- programs/magicblock/src/utils/accounts.rs | 2 +- 12 files changed, 120 insertions(+), 137 deletions(-) rename programs/magicblock/src/{magic_schedule_action.rs => magic_schedule_l1_message.rs} (79%) rename programs/magicblock/src/schedule_transactions/{process_schedule_action.rs => process_schedule_l1_message.rs} (91%) diff --git a/programs/magicblock/src/args.rs b/programs/magicblock/src/args.rs index e2be68104..83b25b741 100644 --- a/programs/magicblock/src/args.rs +++ b/programs/magicblock/src/args.rs @@ -1,14 +1,14 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct HandlerArgs { +pub struct ActionArgs { pub escrow_index: u8, pub data: Vec, } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub struct CallHandlerArgs { - pub args: HandlerArgs, +pub struct L1ActionArgs { + pub args: ActionArgs, pub destination_program: u8, // index of the account pub accounts: Vec, // indices of account } @@ -16,16 +16,16 @@ pub struct CallHandlerArgs { #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum CommitTypeArgs { Standalone(Vec), // indices on accounts - WithHandler { + WithL1Actions { committed_accounts: Vec, // indices of accounts - call_handlers: Vec, + l1_actions: Vec, }, } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum UndelegateTypeArgs { Standalone, - WithHandler { call_handlers: Vec }, + WithL1Actions { l1_actions: Vec }, } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] @@ -35,8 +35,8 @@ pub struct CommitAndUndelegateArgs { } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub enum MagicActionArgs { - L1Action(Vec), +pub enum MagicL1MessageArgs { + L1Actions(Vec), Commit(CommitTypeArgs), CommitAndUndelegate(CommitAndUndelegateArgs), } diff --git a/programs/magicblock/src/lib.rs b/programs/magicblock/src/lib.rs index 87d896a18..89e20eb88 100644 --- a/programs/magicblock/src/lib.rs +++ b/programs/magicblock/src/lib.rs @@ -4,7 +4,7 @@ mod mutate_accounts; mod schedule_transactions; pub use magic_context::{FeePayerAccount, MagicContext, ScheduledCommit}; pub mod args; -mod magic_schedule_action; +mod magic_schedule_l1_message; pub mod magicblock_instruction; pub mod magicblock_processor; #[cfg(test)] diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index 6e559888b..6497bebbe 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -10,9 +10,9 @@ use solana_sdk::{ transaction::Transaction, }; -use crate::magic_schedule_action::{ - CommitAndUndelegate, CommitType, CommittedAccountV2, MagicAction, - ScheduledAction, ShortAccountMeta, UndelegateType, +use crate::magic_schedule_l1_message::{ + CommitAndUndelegate, CommitType, CommittedAccountV2, MagicL1Message, + ScheduledL1Message, ShortAccountMeta, UndelegateType, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -21,26 +21,9 @@ pub struct FeePayerAccount { pub delegated_pda: Pubkey, } -// Q: can user initiate actions on arbitrary accounts? -// No, then he could call any handler on any porgram -// Inititating transfer for himself -// -// Answer: No - -// Q; can user call any program but using account that he owns? -// Far example, there could Transfer from that implements logix for transfer -// Here the fact that magicblock-program schedyled that call huarantess that user apporved this -// -// Answer: Yes - -// user has multiple actions that he wants to perform on owned accounts -// he may schedule -// Those actions may have contraints: Undelegate can come only After Commit -// Commit can't come after undelegate - #[derive(Debug, Default, Serialize, Deserialize)] pub struct MagicContext { - pub scheduled_commits: Vec, + pub scheduled_commits: Vec, } impl MagicContext { @@ -56,11 +39,11 @@ impl MagicContext { } } - pub(crate) fn add_scheduled_action(&mut self, action: ScheduledAction) { - self.scheduled_commits.push(action); + pub(crate) fn add_scheduled_action(&mut self, l1_message: ScheduledL1Message) { + self.scheduled_commits.push(l1_message); } - pub(crate) fn take_scheduled_commits(&mut self) -> Vec { + pub(crate) fn take_scheduled_commits(&mut self) -> Vec { mem::take(&mut self.scheduled_commits) } @@ -96,7 +79,7 @@ pub struct ScheduledCommit { pub request_undelegation: bool, } -impl From for ScheduledAction { +impl From for ScheduledL1Message { fn from(value: ScheduledCommit) -> Self { let commit_type = CommitType::Standalone( value @@ -105,13 +88,13 @@ impl From for ScheduledAction { .map(CommittedAccountV2::from) .collect(), ); - let action = if value.request_undelegation { - MagicAction::CommitAndUndelegate(CommitAndUndelegate { + let l1_message = if value.request_undelegation { + MagicL1Message::CommitAndUndelegate(CommitAndUndelegate { commit_action: commit_type, undelegate_action: UndelegateType::Standalone, }) } else { - MagicAction::Commit(commit_type) + MagicL1Message::Commit(commit_type) }; Self { @@ -120,14 +103,14 @@ impl From for ScheduledAction { blockhash: value.blockhash, payer: value.payer, action_sent_transaction: value.commit_sent_transaction, - action, + l1_message, } } } -impl TryFrom for ScheduledCommit { - type Error = MagicAction; - fn try_from(value: ScheduledAction) -> Result { +impl TryFrom for ScheduledCommit { + type Error = MagicL1Message; + fn try_from(value: ScheduledL1Message) -> Result { fn extract_accounts( commit_type: CommitType, ) -> Result, CommitType> { @@ -138,26 +121,26 @@ impl TryFrom for ScheduledCommit { .map(CommittedAccount::from) .collect()) } - val @ CommitType::WithHandler { .. } => Err(val), + val @ CommitType::WithL1Actions { .. } => Err(val), } } - let (accounts, request_undelegation) = match value.action { - MagicAction::Commit(commit_action) => { + let (accounts, request_undelegation) = match value.l1_message { + MagicL1Message::Commit(commit_action) => { let accounts = extract_accounts(commit_action) - .map_err(MagicAction::Commit)?; + .map_err(MagicL1Message::Commit)?; Ok((accounts, false)) } - MagicAction::CommitAndUndelegate(value) => { - if let UndelegateType::WithHandler(..) = + MagicL1Message::CommitAndUndelegate(value) => { + if let UndelegateType::WithL1Actions(..) = &value.undelegate_action { - return Err(MagicAction::CommitAndUndelegate(value)); + return Err(MagicL1Message::CommitAndUndelegate(value)); }; let accounts = extract_accounts(value.commit_action).map_err( |commit_type| { - MagicAction::CommitAndUndelegate(CommitAndUndelegate { + MagicL1Message::CommitAndUndelegate(CommitAndUndelegate { commit_action: commit_type, undelegate_action: value.undelegate_action, }) @@ -165,7 +148,7 @@ impl TryFrom for ScheduledCommit { )?; Ok((accounts, true)) } - err @ MagicAction::CallHandler(_) => Err(err), + err @ MagicL1Message::L1Actions(_) => Err(err), }?; Ok(Self { diff --git a/programs/magicblock/src/magic_schedule_action.rs b/programs/magicblock/src/magic_schedule_l1_message.rs similarity index 79% rename from programs/magicblock/src/magic_schedule_action.rs rename to programs/magicblock/src/magic_schedule_l1_message.rs index 4c33029aa..5911062ac 100644 --- a/programs/magicblock/src/magic_schedule_action.rs +++ b/programs/magicblock/src/magic_schedule_l1_message.rs @@ -10,8 +10,8 @@ use solana_sdk::{clock::Slot, transaction::Transaction}; use crate::{ args::{ - CallHandlerArgs, CommitAndUndelegateArgs, CommitTypeArgs, HandlerArgs, - MagicActionArgs, UndelegateTypeArgs, + L1ActionArgs, CommitAndUndelegateArgs, CommitTypeArgs, ActionArgs, + MagicL1MessageArgs, UndelegateTypeArgs, }, instruction_utils::InstructionUtils, utils::accounts::{ @@ -47,70 +47,70 @@ impl<'a, 'ic> ConstructionContext<'a, 'ic> { /// Scheduled action to be executed on base layer #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ScheduledAction { +pub struct ScheduledL1Message { pub id: u64, pub slot: Slot, pub blockhash: Hash, pub action_sent_transaction: Transaction, pub payer: Pubkey, // Scheduled action - pub action: MagicAction, + pub l1_message: MagicL1Message, } -impl ScheduledAction { +impl ScheduledL1Message { pub fn try_new<'a>( - args: &MagicActionArgs, + args: &MagicL1MessageArgs, commit_id: u64, slot: Slot, payer_pubkey: &Pubkey, context: &ConstructionContext<'a, '_>, - ) -> Result { - let action = MagicAction::try_from_args(args, &context)?; + ) -> Result { + let action = MagicL1Message::try_from_args(args, &context)?; let blockhash = context.invoke_context.environment_config.blockhash; let action_sent_transaction = InstructionUtils::scheduled_commit_sent(commit_id, blockhash); - Ok(ScheduledAction { + Ok(ScheduledL1Message { id: commit_id, slot, blockhash, payer: *payer_pubkey, action_sent_transaction, - action, + l1_message: action, }) } } // Action that user wants to perform on base layer #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub enum MagicAction { +pub enum MagicL1Message { /// Actions without commitment or undelegation - CallHandler(Vec), + L1Actions(Vec), Commit(CommitType), CommitAndUndelegate(CommitAndUndelegate), } -impl MagicAction { +impl MagicL1Message { pub fn try_from_args<'a>( - args: &MagicActionArgs, + args: &MagicL1MessageArgs, context: &ConstructionContext<'a, '_>, - ) -> Result { + ) -> Result { match args { - MagicActionArgs::L1Action(call_handlers_args) => { - let call_handlers = call_handlers_args + MagicL1MessageArgs::L1Actions(l1_actions) => { + let l1_actions = l1_actions .iter() - .map(|args| CallHandler::try_from_args(args, context)) - .collect::, InstructionError>>()?; - Ok(MagicAction::CallHandler(call_handlers)) + .map(|args| L1Action::try_from_args(args, context)) + .collect::, InstructionError>>()?; + Ok(MagicL1Message::L1Actions(l1_actions)) } - MagicActionArgs::Commit(type_) => { + MagicL1MessageArgs::Commit(type_) => { let commit = CommitType::try_from_args(type_, context)?; - Ok(MagicAction::Commit(commit)) + Ok(MagicL1Message::Commit(commit)) } - MagicActionArgs::CommitAndUndelegate(type_) => { + MagicL1MessageArgs::CommitAndUndelegate(type_) => { let commit_and_undelegate = CommitAndUndelegate::try_from_args(type_, context)?; - Ok(MagicAction::CommitAndUndelegate(commit_and_undelegate)) + Ok(MagicL1Message::CommitAndUndelegate(commit_and_undelegate)) } } } @@ -187,21 +187,21 @@ impl CommitType { Ok(CommitType::Standalone(committed_accounts)) } - CommitTypeArgs::WithHandler { + CommitTypeArgs::WithL1Actions { committed_accounts, - call_handlers, + l1_actions, } => { Self::validate_accounts(committed_accounts, context)?; let committed_accounts = Self::extract_commit_accounts(committed_accounts, context)?; - let call_handlers = call_handlers + let l1_actions = l1_actions .iter() - .map(|args| CallHandler::try_from_args(args, context)) - .collect::, InstructionError>>()?; + .map(|args| L1Action::try_from_args(args, context)) + .collect::, InstructionError>>()?; - Ok(CommitType::WithHandler { + Ok(CommitType::WithL1Actions { committed_accounts, - call_handlers, + l1_actions, }) } } @@ -232,13 +232,13 @@ impl CommitAndUndelegate { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct Handler { +pub struct ProgramArgs { pub escrow_index: u8, pub data: Vec, } -impl From for Handler { - fn from(value: HandlerArgs) -> Self { +impl From for ProgramArgs { + fn from(value: ActionArgs) -> Self { Self { escrow_index: value.escrow_index, data: value.data, @@ -246,8 +246,8 @@ impl From for Handler { } } -impl From<&HandlerArgs> for Handler { - fn from(value: &HandlerArgs) -> Self { +impl From<&ActionArgs> for ProgramArgs { + fn from(value: &ActionArgs) -> Self { value.clone().into() } } @@ -259,17 +259,17 @@ pub struct ShortAccountMeta { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CallHandler { +pub struct L1Action { pub destination_program: Pubkey, - pub data_per_program: Handler, + pub data_per_program: ProgramArgs, pub account_metas_per_program: Vec, } -impl CallHandler { +impl L1Action { pub fn try_from_args<'a>( - args: &CallHandlerArgs, + args: &L1ActionArgs, context: &ConstructionContext<'a, '_>, - ) -> Result { + ) -> Result { let destination_program_pubkey = *get_instruction_pubkey_with_idx( context.transaction_context, args.destination_program as u16, @@ -283,7 +283,7 @@ impl CallHandler { ic_msg!( context.invoke_context, &format!( - "CallHandler: destination_program must be an executable. got: {}", + "L1Action: destination_program must be an executable. got: {}", destination_program_pubkey ) ); @@ -301,7 +301,7 @@ impl CallHandler { }) .collect::, InstructionError>>()?; - Ok(CallHandler { + Ok(L1Action { destination_program: destination_program_pubkey, data_per_program: args.args.clone().into(), account_metas_per_program: account_metas, @@ -323,9 +323,9 @@ pub enum CommitType { /// TODO: feels like ShortMeta isn't needed Standalone(Vec), // accounts to commit /// Commits accounts and runs actions - WithHandler { + WithL1Actions { committed_accounts: Vec, - call_handlers: Vec, + l1_actions: Vec, }, } @@ -333,7 +333,7 @@ pub enum CommitType { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum UndelegateType { Standalone, - WithHandler(Vec), + WithL1Actions(Vec), } impl UndelegateType { @@ -343,14 +343,14 @@ impl UndelegateType { ) -> Result { match args { UndelegateTypeArgs::Standalone => Ok(UndelegateType::Standalone), - UndelegateTypeArgs::WithHandler { call_handlers } => { - let call_handlers = call_handlers + UndelegateTypeArgs::WithL1Actions { l1_actions } => { + let l1_actions = l1_actions .iter() - .map(|call_handler| { - CallHandler::try_from_args(call_handler, context) + .map(|l1_actions| { + L1Action::try_from_args(l1_actions, context) }) - .collect::, InstructionError>>()?; - Ok(UndelegateType::WithHandler(call_handlers)) + .collect::, InstructionError>>()?; + Ok(UndelegateType::WithL1Actions(l1_actions)) } } } diff --git a/programs/magicblock/src/magicblock_instruction.rs b/programs/magicblock/src/magicblock_instruction.rs index 8ababb613..8ab48537c 100644 --- a/programs/magicblock/src/magicblock_instruction.rs +++ b/programs/magicblock/src/magicblock_instruction.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use solana_sdk::{account::Account, pubkey::Pubkey}; -use crate::args::MagicActionArgs; +use crate::args::MagicL1MessageArgs; #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum MagicBlockInstruction { @@ -67,7 +67,7 @@ pub enum MagicBlockInstruction { /// We implement it this way so we can log the signature of this transaction /// as part of the [MagicBlockInstruction::ScheduleCommit] instruction. ScheduledCommitSent(u64), - ScheduleAction(MagicActionArgs), + ScheduleL1Message(MagicL1MessageArgs), } // TODO: why that exists? @@ -81,7 +81,7 @@ impl MagicBlockInstruction { ScheduleCommitAndUndelegate => 2, AcceptScheduleCommits => 3, ScheduledCommitSent(_) => 4, - ScheduleAction(_) => 5, + ScheduleL1Message(_) => 5, } } diff --git a/programs/magicblock/src/magicblock_processor.rs b/programs/magicblock/src/magicblock_processor.rs index bf4587999..e1b73f32c 100644 --- a/programs/magicblock/src/magicblock_processor.rs +++ b/programs/magicblock/src/magicblock_processor.rs @@ -6,7 +6,7 @@ use crate::{ mutate_accounts::process_mutate_accounts, process_scheduled_commit_sent, schedule_transactions::{ - process_accept_scheduled_commits, process_schedule_action, + process_accept_scheduled_commits, process_schedule_l1_message, process_schedule_commit, ProcessScheduleCommitOptions, }, }; @@ -60,8 +60,8 @@ declare_process_instruction!( id, ) } - MagicBlockInstruction::ScheduleAction(args) => { - process_schedule_action(signers, invoke_context, args) + MagicBlockInstruction::ScheduleL1Message(args) => { + process_schedule_l1_message(signers, invoke_context, args) } } } diff --git a/programs/magicblock/src/schedule_transactions/mod.rs b/programs/magicblock/src/schedule_transactions/mod.rs index 89d7b470c..40980f7c9 100644 --- a/programs/magicblock/src/schedule_transactions/mod.rs +++ b/programs/magicblock/src/schedule_transactions/mod.rs @@ -1,5 +1,5 @@ mod process_accept_scheduled_commits; -mod process_schedule_action; +mod process_schedule_l1_message; mod process_schedule_commit; #[cfg(test)] mod process_schedule_commit_tests; @@ -10,7 +10,7 @@ use std::sync::atomic::AtomicU64; use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; pub(crate) use process_accept_scheduled_commits::*; -pub(crate) use process_schedule_action::*; +pub(crate) use process_schedule_l1_message::*; pub(crate) use process_schedule_commit::*; pub use process_scheduled_commit_sent::{ process_scheduled_commit_sent, register_scheduled_commit_sent, SentCommit, @@ -22,7 +22,7 @@ use solana_program_runtime::{ use crate::utils::accounts::get_instruction_pubkey_with_idx; -pub(crate) static COMMIT_ID: AtomicU64 = AtomicU64::new(0); +pub(crate) static MESSAGE_ID: AtomicU64 = AtomicU64::new(0); pub fn check_magic_context_id( invoke_context: &InvokeContext, diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs index 8c53a489d..a1f0cc66e 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs @@ -10,7 +10,7 @@ use crate::{ magic_context::{CommittedAccount, ScheduledCommit}, schedule_transactions, schedule_transactions::{ - transaction_scheduler::TransactionScheduler, COMMIT_ID, + transaction_scheduler::TransactionScheduler, MESSAGE_ID, }, utils::{ account_actions::set_account_owner_to_delegation_program, @@ -178,7 +178,7 @@ pub(crate) fn process_schedule_commit( } // Determine id and slot - let commit_id = COMMIT_ID.fetch_add(1, Ordering::Relaxed); + let commit_id = MESSAGE_ID.fetch_add(1, Ordering::Relaxed); // It appears that in builtin programs `Clock::get` doesn't work as expected, thus // we have to get it directly from the sysvar cache. diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs index ecd110ffe..22cf97c59 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs @@ -19,7 +19,7 @@ use test_tools_core::init_logger; use crate::{ magic_context::MagicContext, - magic_schedule_action::ScheduledAction, + magic_schedule_l1_message::ScheduledL1Message, magicblock_instruction::MagicBlockInstruction, schedule_transactions::transaction_scheduler::TransactionScheduler, test_utils::{ensure_started_validator, process_instruction}, @@ -159,7 +159,7 @@ fn assert_accepted_actions( processed_accepted: &[AccountSharedData], payer: &Pubkey, expected_scheduled_actions: usize, -) -> Vec { +) -> Vec { let magic_context_acc = find_magic_context_account(processed_accepted) .expect("magic context account not found"); let magic_context = @@ -238,7 +238,7 @@ fn assert_first_commit( mod tests { use super::*; use crate::{ - magic_schedule_action::MagicAction, + magic_schedule_l1_message::MagicL1Message, utils::instruction_utils::InstructionUtils, }; @@ -319,7 +319,7 @@ mod tests { let scheduled_commits = scheduled_commits .into_iter() .map(|el| el.try_into()) - .collect::, MagicAction>>() + .collect::, MagicL1Message>>() .expect("only commit action"); assert_first_commit( @@ -411,7 +411,7 @@ mod tests { let scheduled_commits = scheduled_commits .into_iter() .map(|el| el.try_into()) - .collect::, MagicAction>>() + .collect::, MagicL1Message>>() .expect("only commit action"); assert_first_commit( @@ -523,7 +523,7 @@ mod tests { let scheduled_commits = scheduled_commits .into_iter() .map(|el| el.try_into()) - .collect::, MagicAction>>() + .collect::, MagicL1Message>>() .expect("only commit action"); assert_first_commit( @@ -638,7 +638,7 @@ mod tests { let scheduled_commits = scheduled_commits .into_iter() .map(|el| el.try_into()) - .collect::, MagicAction>>() + .collect::, MagicL1Message>>() .expect("only commit action"); assert_first_commit( diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs b/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs similarity index 91% rename from programs/magicblock/src/schedule_transactions/process_schedule_action.rs rename to programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs index 40d1abd5f..075bb5948 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_action.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs @@ -8,9 +8,9 @@ use solana_sdk::{ }; use crate::{ - args::MagicActionArgs, - magic_schedule_action::{ConstructionContext, ScheduledAction}, - schedule_transactions::{check_magic_context_id, COMMIT_ID}, + args::MagicL1MessageArgs, + magic_schedule_l1_message::{ConstructionContext, ScheduledL1Message}, + schedule_transactions::{check_magic_context_id, MESSAGE_ID}, utils::accounts::{ get_instruction_account_with_idx, get_instruction_pubkey_with_idx, }, @@ -22,10 +22,10 @@ const MAGIC_CONTEXT_IDX: u16 = PAYER_IDX + 1; const ACTION_ACCOUNTS_OFFSET: usize = MAGIC_CONTEXT_IDX as usize + 1; const ACTIONS_SUPPORTED: bool = false; -pub(crate) fn process_schedule_action( +pub(crate) fn process_schedule_l1_message( signers: HashSet, invoke_context: &mut InvokeContext, - args: MagicActionArgs, + args: MagicL1MessageArgs, ) -> Result<(), InstructionError> { // TODO: remove once actions are supported if !ACTIONS_SUPPORTED { @@ -93,16 +93,16 @@ pub(crate) fn process_schedule_action( })?; // Determine id and slot - let commit_id = COMMIT_ID.fetch_add(1, Ordering::Relaxed); + let message_id = MESSAGE_ID.fetch_add(1, Ordering::Relaxed); let construction_context = ConstructionContext::new( parent_program_id, &signers, transaction_context, invoke_context, ); - let scheduled_action = ScheduledAction::try_new( + let scheduled_action = ScheduledL1Message::try_new( &args, - commit_id, + message_id, clock.slot, payer_pubkey, &construction_context, @@ -127,7 +127,7 @@ pub(crate) fn process_schedule_action( ); InstructionError::GenericError })?; - ic_msg!(invoke_context, "Scheduled commit with ID: {}", commit_id); + ic_msg!(invoke_context, "Scheduled commit with ID: {}", message_id); ic_msg!( invoke_context, "ScheduledCommitSent signature: {}", diff --git a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs index a961e5965..c9768f375 100644 --- a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs +++ b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs @@ -13,12 +13,12 @@ use solana_sdk::{ }; use crate::{ - magic_context::MagicContext, magic_schedule_action::ScheduledAction, + magic_context::MagicContext, magic_schedule_l1_message::ScheduledL1Message, }; #[derive(Clone)] pub struct TransactionScheduler { - scheduled_action: Arc>>, + scheduled_action: Arc>>, } impl Default for TransactionScheduler { @@ -27,7 +27,7 @@ impl Default for TransactionScheduler { /// This vec tracks commits that went through the entire process of first /// being scheduled into the MagicContext, and then being moved /// over to this global. - static ref SCHEDULED_ACTION: Arc>> = + static ref SCHEDULED_ACTION: Arc>> = Default::default(); } Self { @@ -40,7 +40,7 @@ impl TransactionScheduler { pub fn schedule_action( invoke_context: &InvokeContext, context_account: &RefCell, - action: ScheduledAction, + action: ScheduledL1Message, ) -> Result<(), InstructionError> { let context_data = &mut context_account.borrow_mut(); let mut context = @@ -57,7 +57,7 @@ impl TransactionScheduler { Ok(()) } - pub fn accept_scheduled_actions(&self, commits: Vec) { + pub fn accept_scheduled_actions(&self, commits: Vec) { self.scheduled_action .write() .expect("scheduled_action lock poisoned") @@ -67,7 +67,7 @@ impl TransactionScheduler { pub fn get_scheduled_actions_by_payer( &self, payer: &Pubkey, - ) -> Vec { + ) -> Vec { let commits = self .scheduled_action .read() @@ -80,7 +80,7 @@ impl TransactionScheduler { .collect::>() } - pub fn take_scheduled_actions(&self) -> Vec { + pub fn take_scheduled_actions(&self) -> Vec { let mut lock = self .scheduled_action .write() diff --git a/programs/magicblock/src/utils/accounts.rs b/programs/magicblock/src/utils/accounts.rs index eaaff189a..4c9778e84 100644 --- a/programs/magicblock/src/utils/accounts.rs +++ b/programs/magicblock/src/utils/accounts.rs @@ -11,7 +11,7 @@ use solana_sdk::{ transaction_context::TransactionContext, }; -use crate::magic_schedule_action::ShortAccountMeta; +use crate::magic_schedule_l1_message::ShortAccountMeta; pub(crate) fn find_tx_index_of_instruction_account( invoke_context: &InvokeContext, From 7b0ea9b5155a1c263a78a0d59453a3c90a23688f Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 18 Jun 2025 16:04:02 +0900 Subject: [PATCH 074/199] feat: remove legacy code, introduce snapshots of account state at the moment of commit --- .../src/database/ledger_column.rs | 2 +- programs/magicblock/src/args.rs | 17 ++ programs/magicblock/src/lib.rs | 2 +- programs/magicblock/src/magic_context.rs | 129 +-------- .../src/magic_schedule_l1_message.rs | 246 +++++++++++------- .../magicblock/src/magicblock_processor.rs | 4 +- .../src/schedule_transactions/mod.rs | 5 +- .../process_schedule_commit.rs | 39 ++- .../process_schedule_l1_message.rs | 12 +- .../schedule_l1_message_processor.rs | 44 ++++ .../transaction_scheduler.rs | 2 +- 11 files changed, 256 insertions(+), 246 deletions(-) create mode 100644 programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs diff --git a/magicblock-ledger/src/database/ledger_column.rs b/magicblock-ledger/src/database/ledger_column.rs index 5e665fbeb..af7c87a35 100644 --- a/magicblock-ledger/src/database/ledger_column.rs +++ b/magicblock-ledger/src/database/ledger_column.rs @@ -99,7 +99,7 @@ where pub fn get_bytes( &self, key: C::Index, - ) -> std::result::Result>, LedgerError> { + ) -> Result>, LedgerError> { let is_perf_enabled = maybe_enable_rocksdb_perf( self.column_options.rocks_perf_sample_interval, &self.read_perf_status, diff --git a/programs/magicblock/src/args.rs b/programs/magicblock/src/args.rs index 83b25b741..8de92d135 100644 --- a/programs/magicblock/src/args.rs +++ b/programs/magicblock/src/args.rs @@ -22,6 +22,17 @@ pub enum CommitTypeArgs { }, } +impl CommitTypeArgs { + pub fn committed_accounts_indices(&self) -> &Vec { + match self { + Self::Standalone(value) => value, + Self::WithL1Actions { + committed_accounts, .. + } => committed_accounts, + } + } +} + #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum UndelegateTypeArgs { Standalone, @@ -34,6 +45,12 @@ pub struct CommitAndUndelegateArgs { pub undelegate_type: UndelegateTypeArgs, } +impl CommitAndUndelegateArgs { + pub fn committed_accounts_indices(&self) -> &Vec { + self.commit_type.committed_accounts_indices() + } +} + #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum MagicL1MessageArgs { L1Actions(Vec), diff --git a/programs/magicblock/src/lib.rs b/programs/magicblock/src/lib.rs index 89e20eb88..59cbae23c 100644 --- a/programs/magicblock/src/lib.rs +++ b/programs/magicblock/src/lib.rs @@ -2,7 +2,7 @@ pub mod errors; mod magic_context; mod mutate_accounts; mod schedule_transactions; -pub use magic_context::{FeePayerAccount, MagicContext, ScheduledCommit}; +pub use magic_context::{FeePayerAccount, MagicContext}; pub mod args; mod magic_schedule_l1_message; pub mod magicblock_instruction; diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index 6497bebbe..b4bbb4e9a 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -39,7 +39,10 @@ impl MagicContext { } } - pub(crate) fn add_scheduled_action(&mut self, l1_message: ScheduledL1Message) { + pub(crate) fn add_scheduled_action( + &mut self, + l1_message: ScheduledL1Message, + ) { self.scheduled_commits.push(l1_message); } @@ -67,127 +70,3 @@ fn is_zeroed(buf: &[u8]) -> bool { && chunks.remainder() == &ZEROS[..chunks.remainder().len()] } } - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ScheduledCommit { - pub id: u64, - pub slot: Slot, - pub blockhash: Hash, - pub accounts: Vec, - pub payer: Pubkey, - pub commit_sent_transaction: Transaction, - pub request_undelegation: bool, -} - -impl From for ScheduledL1Message { - fn from(value: ScheduledCommit) -> Self { - let commit_type = CommitType::Standalone( - value - .accounts - .into_iter() - .map(CommittedAccountV2::from) - .collect(), - ); - let l1_message = if value.request_undelegation { - MagicL1Message::CommitAndUndelegate(CommitAndUndelegate { - commit_action: commit_type, - undelegate_action: UndelegateType::Standalone, - }) - } else { - MagicL1Message::Commit(commit_type) - }; - - Self { - id: value.id, - slot: value.slot, - blockhash: value.blockhash, - payer: value.payer, - action_sent_transaction: value.commit_sent_transaction, - l1_message, - } - } -} - -impl TryFrom for ScheduledCommit { - type Error = MagicL1Message; - fn try_from(value: ScheduledL1Message) -> Result { - fn extract_accounts( - commit_type: CommitType, - ) -> Result, CommitType> { - match commit_type { - CommitType::Standalone(committed_accounts) => { - Ok(committed_accounts - .into_iter() - .map(CommittedAccount::from) - .collect()) - } - val @ CommitType::WithL1Actions { .. } => Err(val), - } - } - - let (accounts, request_undelegation) = match value.l1_message { - MagicL1Message::Commit(commit_action) => { - let accounts = extract_accounts(commit_action) - .map_err(MagicL1Message::Commit)?; - Ok((accounts, false)) - } - MagicL1Message::CommitAndUndelegate(value) => { - if let UndelegateType::WithL1Actions(..) = - &value.undelegate_action - { - return Err(MagicL1Message::CommitAndUndelegate(value)); - }; - - let accounts = extract_accounts(value.commit_action).map_err( - |commit_type| { - MagicL1Message::CommitAndUndelegate(CommitAndUndelegate { - commit_action: commit_type, - undelegate_action: value.undelegate_action, - }) - }, - )?; - Ok((accounts, true)) - } - err @ MagicL1Message::L1Actions(_) => Err(err), - }?; - - Ok(Self { - id: value.id, - slot: value.slot, - blockhash: value.blockhash, - payer: value.payer, - commit_sent_transaction: value.action_sent_transaction, - accounts, - request_undelegation, - }) - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CommittedAccount { - pub pubkey: Pubkey, - // TODO(GabrielePicco): We should read the owner from the delegation record rather - // than deriving/storing it. To remove once the cloning pipeline allow us to easily access the owner. - pub owner: Pubkey, -} - -impl From for CommittedAccountV2 { - fn from(value: CommittedAccount) -> Self { - Self { - owner: value.owner, - short_meta: ShortAccountMeta { - pubkey: value.pubkey, - is_writable: false, - }, - } - } -} - -impl From for CommittedAccount { - fn from(value: CommittedAccountV2) -> Self { - Self { - pubkey: value.short_meta.pubkey, - owner: value.owner, - } - } -} diff --git a/programs/magicblock/src/magic_schedule_l1_message.rs b/programs/magicblock/src/magic_schedule_l1_message.rs index 5911062ac..5f4e668c9 100644 --- a/programs/magicblock/src/magic_schedule_l1_message.rs +++ b/programs/magicblock/src/magic_schedule_l1_message.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::{cell::RefCell, collections::HashSet}; use serde::{Deserialize, Serialize}; use solana_log_collector::ic_msg; @@ -6,11 +6,15 @@ use solana_program_runtime::{ __private::{Hash, InstructionError, ReadableAccount, TransactionContext}, invoke_context::InvokeContext, }; -use solana_sdk::{clock::Slot, transaction::Transaction}; +use solana_sdk::{ + account::{Account, AccountSharedData}, + clock::Slot, + transaction::Transaction, +}; use crate::{ args::{ - L1ActionArgs, CommitAndUndelegateArgs, CommitTypeArgs, ActionArgs, + ActionArgs, CommitAndUndelegateArgs, CommitTypeArgs, L1ActionArgs, MagicL1MessageArgs, UndelegateTypeArgs, }, instruction_utils::InstructionUtils, @@ -25,8 +29,8 @@ use crate::{ pub struct ConstructionContext<'a, 'ic> { parent_program_id: Option, signers: &'a HashSet, - transaction_context: &'a TransactionContext, - invoke_context: &'a mut InvokeContext<'ic>, + pub transaction_context: &'a TransactionContext, + pub invoke_context: &'a mut InvokeContext<'ic>, } impl<'a, 'ic> ConstructionContext<'a, 'ic> { @@ -116,98 +120,6 @@ impl MagicL1Message { } } -impl CommitType { - fn validate_accounts<'a>( - account_indices: &[u8], - context: &ConstructionContext<'a, '_>, - ) -> Result<(), InstructionError> { - account_indices.iter().try_for_each(|index| { - let acc_pubkey = get_instruction_pubkey_with_idx(context.transaction_context, *index as u16)?; - let acc = get_instruction_account_with_idx(context.transaction_context, *index as u16)?; - let acc_owner = *acc.borrow().owner(); - - if context.parent_program_id != Some(acc_owner) && !context.signers.contains(acc_pubkey) { - match context.parent_program_id { - None => { - ic_msg!( - context.invoke_context, - "ScheduleCommit ERR: failed to find parent program id" - ); - Err(InstructionError::InvalidInstructionData) - } - Some(parent_id) => { - ic_msg!( - context.invoke_context, - "ScheduleCommit ERR: account {} must be owned by {} or be a signer, but is owned by {}", - acc_pubkey, parent_id, acc_owner - ); - Err(InstructionError::InvalidAccountOwner) - } - } - } else { - Ok(()) - } - }) - } - - fn extract_commit_accounts<'a>( - account_indices: &[u8], - context: &ConstructionContext<'a, '_>, - ) -> Result, InstructionError> { - account_indices - .iter() - .map(|i| { - let account = get_instruction_account_with_idx( - context.transaction_context, - *i as u16, - )?; - let owner = *account.borrow().owner(); - let short_meta = get_instruction_account_short_meta_with_idx( - context.transaction_context, - *i as u16, - )?; - - Ok(CommittedAccountV2 { - short_meta, - owner: context.parent_program_id.unwrap_or(owner), - }) - }) - .collect::, InstructionError>>() - } - - pub fn try_from_args<'a>( - args: &CommitTypeArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - match args { - CommitTypeArgs::Standalone(accounts) => { - Self::validate_accounts(accounts, context)?; - let committed_accounts = - Self::extract_commit_accounts(accounts, context)?; - - Ok(CommitType::Standalone(committed_accounts)) - } - CommitTypeArgs::WithL1Actions { - committed_accounts, - l1_actions, - } => { - Self::validate_accounts(committed_accounts, context)?; - let committed_accounts = - Self::extract_commit_accounts(committed_accounts, context)?; - let l1_actions = l1_actions - .iter() - .map(|args| L1Action::try_from_args(args, context)) - .collect::, InstructionError>>()?; - - Ok(CommitType::WithL1Actions { - committed_accounts, - l1_actions, - }) - } - } - } -} - #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CommitAndUndelegate { pub commit_action: CommitType, @@ -309,12 +221,20 @@ impl L1Action { } } +type CommittedAccountRef<'a> = (Pubkey, &'a RefCell); #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CommittedAccountV2 { - pub short_meta: ShortAccountMeta, - // TODO(GabrielePicco): We should read the owner from the delegation record rather - // than deriving/storing it. To remove once the cloning pipeline allow us to easily access the owner. - pub owner: Pubkey, + pub pubkey: Pubkey, + pub account: Account, +} + +impl<'a> From> for CommittedAccountV2 { + fn from(value: CommittedAccountRef<'a>) -> Self { + Self { + pubkey: value.0, + account: value.1.borrow().to_owned().into(), + } + } } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -329,6 +249,130 @@ pub enum CommitType { }, } +impl CommitType { + // TODO: move to processor + fn validate_accounts<'a>( + accounts: &[CommittedAccountRef], + context: &ConstructionContext<'a, '_>, + ) -> Result<(), InstructionError> { + accounts.iter().try_for_each(|(pubkey, account)| { + let owner = *account.borrow().owner(); + if context.parent_program_id != Some(owner) && !context.signers.contains(pubkey) { + match context.parent_program_id { + None => { + ic_msg!( + context.invoke_context, + "ScheduleCommit ERR: failed to find parent program id" + ); + Err(InstructionError::InvalidInstructionData) + } + Some(parent_id) => { + ic_msg!( + context.invoke_context, + "ScheduleCommit ERR: account {} must be owned by {} or be a signer, but is owned by {}", + pubkey, parent_id, owner + ); + Err(InstructionError::InvalidAccountOwner) + } + } + } else { + Ok(()) + } + }) + } + + // I delegated an account, now the owner is delegation program + // parent_program_id != Some(&acc_owner) should fail. or any modification on ER + // ER perceives owner as old one, hence for ER those are valid txs + // On commit_and_undelegate and commit we will set owner to DLP, for latter temparerily + // The owner shall be real owner on chain + // So first: + // 1. Validate + // 2. Fetch current account states + // TODO: 3. switch the ownership + pub fn extract_commit_accounts<'a>( + account_indices: &[u8], + transaction_context: &'a TransactionContext, + ) -> Result>, InstructionError> { + account_indices + .iter() + .map(|i| { + let account = get_instruction_account_with_idx( + transaction_context, + *i as u16, + )?; + let pubkey = *get_instruction_pubkey_with_idx( + transaction_context, + *i as u16, + )?; + + Ok((pubkey, account)) + }) + .collect::>() + } + + pub fn try_from_args<'a>( + args: &CommitTypeArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + match args { + CommitTypeArgs::Standalone(accounts) => { + let committed_accounts_ref = Self::extract_commit_accounts( + accounts, + context.transaction_context, + )?; + Self::validate_accounts(&committed_accounts_ref, context)?; + let committed_accounts = committed_accounts_ref + .into_iter() + .map(|el| { + let mut committed_account: CommittedAccountV2 = + el.into(); + committed_account.account.owner = context + .parent_program_id + .unwrap_or(committed_account.account.owner); + + committed_account + }) + .collect(); + + Ok(CommitType::Standalone(committed_accounts)) + } + CommitTypeArgs::WithL1Actions { + committed_accounts, + l1_actions, + } => { + let committed_accounts_ref = Self::extract_commit_accounts( + committed_accounts, + context.transaction_context, + )?; + Self::validate_accounts(&committed_accounts_ref, context)?; + + let l1_actions = l1_actions + .iter() + .map(|args| L1Action::try_from_args(args, context)) + .collect::, InstructionError>>()?; + let committed_accounts = committed_accounts_ref + .into_iter() + .map(|el| { + let mut committed_account: CommittedAccountV2 = + el.into(); + committed_account.account.owner = context + .parent_program_id + .unwrap_or(committed_account.account.owner); + + committed_account + }) + .collect(); + + Ok(CommitType::WithL1Actions { + committed_accounts, + l1_actions, + }) + } + } + } +} + /// No CommitedAccounts since it is only used with CommitAction. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum UndelegateType { diff --git a/programs/magicblock/src/magicblock_processor.rs b/programs/magicblock/src/magicblock_processor.rs index e1b73f32c..0207e3ec2 100644 --- a/programs/magicblock/src/magicblock_processor.rs +++ b/programs/magicblock/src/magicblock_processor.rs @@ -6,8 +6,8 @@ use crate::{ mutate_accounts::process_mutate_accounts, process_scheduled_commit_sent, schedule_transactions::{ - process_accept_scheduled_commits, process_schedule_l1_message, - process_schedule_commit, ProcessScheduleCommitOptions, + process_accept_scheduled_commits, process_schedule_commit, + process_schedule_l1_message, ProcessScheduleCommitOptions, }, }; diff --git a/programs/magicblock/src/schedule_transactions/mod.rs b/programs/magicblock/src/schedule_transactions/mod.rs index 40980f7c9..e03182e92 100644 --- a/programs/magicblock/src/schedule_transactions/mod.rs +++ b/programs/magicblock/src/schedule_transactions/mod.rs @@ -1,17 +1,18 @@ mod process_accept_scheduled_commits; -mod process_schedule_l1_message; mod process_schedule_commit; #[cfg(test)] mod process_schedule_commit_tests; +mod process_schedule_l1_message; mod process_scheduled_commit_sent; +mod schedule_l1_message_processor; pub(crate) mod transaction_scheduler; use std::sync::atomic::AtomicU64; use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; pub(crate) use process_accept_scheduled_commits::*; -pub(crate) use process_schedule_l1_message::*; pub(crate) use process_schedule_commit::*; +pub(crate) use process_schedule_l1_message::*; pub use process_scheduled_commit_sent::{ process_scheduled_commit_sent, register_scheduled_commit_sent, SentCommit, }; diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs index a1f0cc66e..207b23cfa 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs @@ -3,11 +3,16 @@ use std::{collections::HashSet, sync::atomic::Ordering}; use solana_log_collector::ic_msg; use solana_program_runtime::invoke_context::InvokeContext; use solana_sdk::{ - account::ReadableAccount, instruction::InstructionError, pubkey::Pubkey, + account::{Account, ReadableAccount}, + instruction::InstructionError, + pubkey::Pubkey, }; use crate::{ - magic_context::{CommittedAccount, ScheduledCommit}, + magic_schedule_l1_message::{ + CommitAndUndelegate, CommitType, CommittedAccountV2, MagicL1Message, + ScheduledL1Message, UndelegateType, + }, schedule_transactions, schedule_transactions::{ transaction_scheduler::TransactionScheduler, MESSAGE_ID, @@ -120,7 +125,7 @@ pub(crate) fn process_schedule_commit( // NOTE: we don't require PDAs to be signers as in our case verifying that the // program owning the PDAs invoked us via CPI is sufficient // Thus we can be `invoke`d unsigned and no seeds need to be provided - let mut pubkeys: Vec = Vec::new(); + let mut committed_accounts: Vec = Vec::new(); for idx in COMMITTEES_START..ix_accs_len { let acc_pubkey = get_instruction_pubkey_with_idx(transaction_context, idx as u16)?; @@ -150,10 +155,14 @@ pub(crate) fn process_schedule_commit( } }; } + + let mut account: Account = acc.borrow().to_owned().into(); + account.owner = parent_program_id.cloned().unwrap_or(account.owner); + #[allow(clippy::unnecessary_literal_unwrap)] - pubkeys.push(CommittedAccount { + committed_accounts.push(CommittedAccountV2 { pubkey: *acc_pubkey, - owner: *parent_program_id.unwrap_or(&acc_owner), + account, }); } @@ -197,14 +206,22 @@ pub(crate) fn process_schedule_commit( let commit_sent_sig = commit_sent_transaction.signatures[0]; - let scheduled_commit = ScheduledCommit { + let l1_message = if opts.request_undelegation { + MagicL1Message::CommitAndUndelegate(CommitAndUndelegate { + commit_action: CommitType::Standalone(committed_accounts), + undelegate_action: UndelegateType::Standalone, + }) + } else { + MagicL1Message::Commit(CommitType::Standalone(committed_accounts)) + }; + + let scheduled_l1_message = ScheduledL1Message { id: commit_id, slot: clock.slot, blockhash, - accounts: pubkeys, + action_sent_transaction: commit_sent_transaction, payer: *payer_pubkey, - commit_sent_transaction, - request_undelegation: opts.request_undelegation, + l1_message, }; // NOTE: this is only protected by all the above checks however if the @@ -214,10 +231,10 @@ pub(crate) fn process_schedule_commit( transaction_context, MAGIC_CONTEXT_IDX, )?; - TransactionScheduler::schedule_action( + TransactionScheduler::schedule_l1_message( invoke_context, context_acc, - scheduled_commit.into(), + scheduled_l1_message, ) .map_err(|err| { ic_msg!( diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs b/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs index 075bb5948..b13a7035c 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs @@ -10,7 +10,11 @@ use solana_sdk::{ use crate::{ args::MagicL1MessageArgs, magic_schedule_l1_message::{ConstructionContext, ScheduledL1Message}, - schedule_transactions::{check_magic_context_id, MESSAGE_ID}, + schedule_transactions::{ + check_magic_context_id, + schedule_l1_message_processor::process_scheddule_l1_message, + MESSAGE_ID, + }, utils::accounts::{ get_instruction_account_with_idx, get_instruction_pubkey_with_idx, }, @@ -107,6 +111,10 @@ pub(crate) fn process_schedule_l1_message( payer_pubkey, &construction_context, )?; + // TODO: move all logic to some Processor + // Rn this just locks accounts + process_scheddule_l1_message(&construction_context, &args)?; + let action_sent_signature = scheduled_action.action_sent_transaction.signatures[0]; @@ -114,7 +122,7 @@ pub(crate) fn process_schedule_l1_message( transaction_context, MAGIC_CONTEXT_IDX, )?; - TransactionScheduler::schedule_action( + TransactionScheduler::schedule_l1_message( invoke_context, context_acc, scheduled_action, diff --git a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs new file mode 100644 index 000000000..a212361a4 --- /dev/null +++ b/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs @@ -0,0 +1,44 @@ +use solana_program_runtime::invoke_context::InvokeContext; +use solana_sdk::{ + instruction::InstructionError, transaction_context::TransactionContext, +}; + +use crate::{ + args::MagicL1MessageArgs, + magic_schedule_l1_message::{CommitType, ConstructionContext}, + utils::account_actions::set_account_owner_to_delegation_program, +}; + +pub fn process_scheddule_l1_message<'a, 'ic>( + construction_context: &ConstructionContext<'a, 'ic>, + args: &MagicL1MessageArgs, +) -> Result<(), InstructionError> { + let commited_accounts_ref = match args { + MagicL1MessageArgs::Commit(commit_type) => { + let accounts_indices = commit_type.committed_accounts_indices(); + CommitType::extract_commit_accounts( + accounts_indices, + construction_context.transaction_context, + )? + } + MagicL1MessageArgs::CommitAndUndelegate(commit_and_undelegate_type) => { + let accounts_indices = + commit_and_undelegate_type.committed_accounts_indices(); + CommitType::extract_commit_accounts( + accounts_indices, + construction_context.transaction_context, + )? + } + MagicL1MessageArgs::L1Actions(_) => return Ok(()), + }; + + // TODO: proper explanation + // Change owner to dlp + commited_accounts_ref + .into_iter() + .for_each(|(_, account_ref)| { + set_account_owner_to_delegation_program(account_ref); + }); + + Ok(()) +} diff --git a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs index c9768f375..e6ed2ba40 100644 --- a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs +++ b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs @@ -37,7 +37,7 @@ impl Default for TransactionScheduler { } impl TransactionScheduler { - pub fn schedule_action( + pub fn schedule_l1_message( invoke_context: &InvokeContext, context_account: &RefCell, action: ScheduledL1Message, From cafd31baf60a69bd925ca738190646fc5069cb3e Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 18 Jun 2025 17:04:40 +0900 Subject: [PATCH 075/199] refactor: renaming --- .../src/schedule_transactions/process_schedule_l1_message.rs | 4 ++-- .../schedule_transactions/schedule_l1_message_processor.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs b/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs index b13a7035c..bad1dd221 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs @@ -12,7 +12,7 @@ use crate::{ magic_schedule_l1_message::{ConstructionContext, ScheduledL1Message}, schedule_transactions::{ check_magic_context_id, - schedule_l1_message_processor::process_scheddule_l1_message, + schedule_l1_message_processor::schedule_l1_message_processor, MESSAGE_ID, }, utils::accounts::{ @@ -113,7 +113,7 @@ pub(crate) fn process_schedule_l1_message( )?; // TODO: move all logic to some Processor // Rn this just locks accounts - process_scheddule_l1_message(&construction_context, &args)?; + schedule_l1_message_processor(&construction_context, &args)?; let action_sent_signature = scheduled_action.action_sent_transaction.signatures[0]; diff --git a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs index a212361a4..df0b6d36b 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs @@ -9,7 +9,7 @@ use crate::{ utils::account_actions::set_account_owner_to_delegation_program, }; -pub fn process_scheddule_l1_message<'a, 'ic>( +pub fn schedule_l1_message_processor<'a, 'ic>( construction_context: &ConstructionContext<'a, 'ic>, args: &MagicL1MessageArgs, ) -> Result<(), InstructionError> { From 409dbb0af206b671fa23a196b64f357a11c1bea2 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 3 Jul 2025 18:02:38 +0800 Subject: [PATCH 076/199] refactor: file structure changes + separate non program specific error for Chunks --- magicblock-committor-program/src/error.rs | 18 + .../src/instruction.rs | 326 +++--------------- .../src/instruction_builder/close_buffer.rs | 45 +++ .../src/instruction_builder/init_buffer.rs | 73 ++++ .../src/instruction_builder/mod.rs | 4 + .../src/instruction_builder/realloc_buffer.rs | 93 +++++ .../src/instruction_builder/write_buffer.rs | 51 +++ magicblock-committor-program/src/lib.rs | 2 + magicblock-committor-program/src/pdas.rs | 22 +- magicblock-committor-program/src/processor.rs | 55 +-- .../src/state/changeset.rs | 4 +- .../src/state/chunks.rs | 173 ++++++---- .../tests/prog_init_write_and_close.rs | 40 ++- 13 files changed, 497 insertions(+), 409 deletions(-) create mode 100644 magicblock-committor-program/src/instruction_builder/close_buffer.rs create mode 100644 magicblock-committor-program/src/instruction_builder/init_buffer.rs create mode 100644 magicblock-committor-program/src/instruction_builder/mod.rs create mode 100644 magicblock-committor-program/src/instruction_builder/realloc_buffer.rs create mode 100644 magicblock-committor-program/src/instruction_builder/write_buffer.rs diff --git a/magicblock-committor-program/src/error.rs b/magicblock-committor-program/src/error.rs index d201ae9da..40e091cf4 100644 --- a/magicblock-committor-program/src/error.rs +++ b/magicblock-committor-program/src/error.rs @@ -1,3 +1,4 @@ +use crate::state::chunks::ChunksError; use solana_program::{msg, program_error::ProgramError}; use thiserror::Error; @@ -16,6 +17,22 @@ pub enum CommittorError { #[error("Chunk of size {0} cannot be stored at offset {1} in buffer of size ({2})")] OffsetChunkOutOfRange(usize, u32, usize), + + #[error("Out of bound access to chunks")] + OutOfBoundsError, +} + +impl From for CommittorError { + fn from(value: ChunksError) -> Self { + match value { + ChunksError::OutOfBoundsError => CommittorError::OutOfBoundsError, + ChunksError::InvalidOffsetError(offset, chunk_size) => { + CommittorError::OffsetMustBeMultipleOfChunkSize( + offset, chunk_size, + ) + } + } + } } impl From for ProgramError { @@ -27,6 +44,7 @@ impl From for ProgramError { PubkeyError(_) => 0x69001, OffsetMustBeMultipleOfChunkSize(_, _) => 0x69002, OffsetChunkOutOfRange(_, _, _) => 0x69003, + OutOfBoundsError => 0x69004, }; ProgramError::Custom(n) } diff --git a/magicblock-committor-program/src/instruction.rs b/magicblock-committor-program/src/instruction.rs index df6cb7a1e..d58dc4a6e 100644 --- a/magicblock-committor-program/src/instruction.rs +++ b/magicblock-committor-program/src/instruction.rs @@ -1,13 +1,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use solana_program::{ - hash::{Hash, HASH_BYTES}, - instruction::{AccountMeta, Instruction}, - system_program, -}; +use solana_program::hash::HASH_BYTES; use solana_pubkey::Pubkey; -use crate::{consts, pdas}; - #[derive(BorshSerialize, BorshDeserialize, Debug, Clone)] pub enum CommittorInstruction { /// Initializes the buffer and [Chunks] accounts which will be used to @@ -27,9 +21,9 @@ pub enum CommittorInstruction { chunks_account_size: u64, /// The size that the buffer account needs to have in order to hold all commits buffer_account_size: u64, - /// The ephemeral blockhash of the changeset we are writing, + /// The commit id of when account got committed, /// needed to properly derive the seeds of the PDAs. - blockhash: Hash, + commit_id: u64, /// The bump to use when deriving seeds and PDA for the [Chunks] account. chunks_bump: u8, /// The bump to use when deriving seeds and PDA for the buffer account. @@ -48,9 +42,9 @@ pub enum CommittorInstruction { pubkey: Pubkey, /// The size that the buffer account needs to have in order to hold all commits buffer_account_size: u64, - /// The ephemeral blockhash of the changeset we are writing, + /// The commit id of when account got committed, /// needed to properly derive the seeds of the PDAs. - blockhash: Hash, + commit_id: u64, /// The bump to use when deriving seeds and PDA for the buffer account. buffer_bump: u8, /// The count of invocations of realloc buffer that this instruction represents. @@ -68,9 +62,9 @@ pub enum CommittorInstruction { /// The on chain address of the account we are committing /// This is part of the seeds used to derive the buffer and chunk account PDAs. pubkey: Pubkey, - /// The ephemeral blockhash of the changeset we are writing, + /// The commit id of when account got committed, /// needed to properly derive the seeds of the PDAs. - blockhash: Hash, + commit_id: u64, /// The bump to use when deriving seeds and PDA for the [Chunks] account. chunks_bump: u8, /// The bump to use when deriving seeds and PDA for the buffer account. @@ -99,9 +93,9 @@ pub enum CommittorInstruction { /// The on chain address of the account we committed. /// This is part of the seeds used to derive the buffer and chunk account PDAs. pubkey: Pubkey, - /// The ephemeral blockhash of the changeset we are writing, + /// The commit id of when account got committed, /// needed to properly derive the seeds of the PDAs. - blockhash: Hash, + commit_id: u64, /// The bump to use when deriving seeds and PDA for the [Chunks] account. chunks_bump: u8, /// The bump to use when deriving seeds and PDA for the buffer account. @@ -112,277 +106,55 @@ pub enum CommittorInstruction { pub const IX_INIT_SIZE: u16 = // pubkey: Pubkey, 32 + - // chunks_account_size: u64, - 8 + - // buffer_account_size: u64, - 8 + - // blockhash: Hash, - HASH_BYTES as u16 + - // chunks_bump: u8, - 1 + - // buffer_bump: u8, - 1 + - // chunk_count: usize, - 8 + - // chunk_size: u16, - 2 + - // byte align - 6; + // chunks_account_size: u64, + 8 + + // buffer_account_size: u64, + 8 + + // blockhash: Hash, + HASH_BYTES as u16 + + // chunks_bump: u8, + 1 + + // buffer_bump: u8, + 1 + + // chunk_count: usize, + 8 + + // chunk_size: u16, + 2 + + // byte align + 6; pub const IX_REALLOC_SIZE: u16 = // pubkey: Pubkey, 32 + - // buffer_account_size: u64, - 8 + - // blockhash: Hash, - HASH_BYTES as u16 + - // buffer_bump: u8, - 1 + - // invocation_count: u16, - 2 + - // byte align - 6; + // buffer_account_size: u64, + 8 + + // blockhash: Hash, + HASH_BYTES as u16 + + // buffer_bump: u8, + 1 + + // invocation_count: u16, + 2 + + // byte align + 6; pub const IX_WRITE_SIZE_WITHOUT_CHUNKS: u16 = // pubkey: Pubkey, 32+ - // blockhash: Hash, - HASH_BYTES as u16 + - // chunks_bump: u8, - 1 + - // buffer_bump: u8, - 1 + - // offset: u32 - 32; + // blockhash: Hash, + HASH_BYTES as u16 + + // chunks_bump: u8, + 1 + + // buffer_bump: u8, + 1 + + // offset: u32 + 32; pub const IX_CLOSE_SIZE: u16 = // pubkey: Pubkey, 32 + - // blockhash: Hash, - HASH_BYTES as u16 + - // chunks_bump: u8, - 1 + - // buffer_bump: u8, - 1; - -// ----------------- -// create_init_ix -// ----------------- -pub struct CreateInitIxArgs { - /// The validator authority - pub authority: Pubkey, - /// On chain address of the account we are committing - pub pubkey: Pubkey, - /// Required size of the account tracking which chunks have been committed - pub chunks_account_size: u64, - /// Required size of the buffer account that holds the account data to commit - pub buffer_account_size: u64, - /// The latest on chain blockhash - pub blockhash: Hash, - /// The number of chunks we need to write until all the data is copied to the - /// buffer account - pub chunk_count: usize, - /// The size of each chunk that we write to the buffer account - pub chunk_size: u16, -} - -pub fn create_init_ix(args: CreateInitIxArgs) -> (Instruction, Pubkey, Pubkey) { - let CreateInitIxArgs { - authority, - pubkey, - chunks_account_size, - buffer_account_size, - blockhash, - chunk_count, - chunk_size, - } = args; - - let (chunks_pda, chunks_bump) = - pdas::chunks_pda(&authority, &pubkey, &blockhash); - let (buffer_pda, buffer_bump) = - pdas::buffer_pda(&authority, &pubkey, &blockhash); - let program_id = crate::id(); - let ix = CommittorInstruction::Init { - pubkey, - blockhash, - chunks_account_size, - buffer_account_size, - chunks_bump, - buffer_bump, - chunk_count, - chunk_size, - }; - let accounts = vec![ - AccountMeta::new(authority, true), - AccountMeta::new(chunks_pda, false), - AccountMeta::new(buffer_pda, false), - AccountMeta::new_readonly(system_program::id(), false), - ]; - ( - Instruction::new_with_borsh(program_id, &ix, accounts), - chunks_pda, - buffer_pda, - ) -} - -// ----------------- -// create_realloc_buffer_ix -// ----------------- -#[derive(Clone)] -pub struct CreateReallocBufferIxArgs { - pub authority: Pubkey, - pub pubkey: Pubkey, - pub buffer_account_size: u64, - pub blockhash: Hash, -} - -/// Creates the realloc ixs we need to invoke in order to realloc -/// the account to the desired size since we only can realloc up to -/// [consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE] in a single instruction. -/// Returns a tuple with the instructions and a bool indicating if we need to split -/// them into multiple instructions in order to avoid -/// [solana_program::program_error::MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED]J -pub fn create_realloc_buffer_ixs( - args: CreateReallocBufferIxArgs, -) -> Vec { - // We already allocated once during Init and only need to realloc - // if the buffer is larger than [consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE] - if args.buffer_account_size - <= consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64 - { - return vec![]; - } - - let remaining_size = args.buffer_account_size as i128 - - consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128; - - // A) We just need to realloc once - if remaining_size <= consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128 - { - return vec![create_realloc_buffer_ix(args, 1)]; - } - - // B) We need to realloc multiple times - // SAFETY; remaining size > consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE - create_realloc_buffer_ixs_to_add_remaining(&args, remaining_size as u64) -} - -pub fn create_realloc_buffer_ixs_to_add_remaining( - args: &CreateReallocBufferIxArgs, - remaining_size: u64, -) -> Vec { - let invocation_count = (remaining_size as f64 - / consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as f64) - .ceil() as u16; - - let mut ixs = vec![]; - for i in 0..invocation_count { - ixs.push(create_realloc_buffer_ix(args.clone(), i + 1)); - } - - ixs -} - -fn create_realloc_buffer_ix( - args: CreateReallocBufferIxArgs, - invocation_count: u16, -) -> Instruction { - let CreateReallocBufferIxArgs { - authority, - pubkey, - buffer_account_size, - blockhash, - } = args; - let (buffer_pda, buffer_bump) = - pdas::buffer_pda(&authority, &pubkey, &blockhash); - - let program_id = crate::id(); - let ix = CommittorInstruction::ReallocBuffer { - pubkey, - buffer_account_size, - blockhash, - buffer_bump, - invocation_count, - }; - let accounts = vec![ - AccountMeta::new(authority, true), - AccountMeta::new(buffer_pda, false), - ]; - Instruction::new_with_borsh(program_id, &ix, accounts) -} - -// ----------------- -// create_write_ix -// ----------------- -pub struct CreateWriteIxArgs { - pub authority: Pubkey, - pub pubkey: Pubkey, - pub offset: u32, - pub data_chunk: Vec, - pub blockhash: Hash, -} - -pub fn create_write_ix(args: CreateWriteIxArgs) -> Instruction { - let CreateWriteIxArgs { - authority, - pubkey, - offset, - data_chunk, - blockhash, - } = args; - let (chunks_pda, chunks_bump) = - pdas::chunks_pda(&authority, &pubkey, &blockhash); - let (buffer_pda, buffer_bump) = - pdas::buffer_pda(&authority, &pubkey, &blockhash); - - let program_id = crate::id(); - let ix = CommittorInstruction::Write { - pubkey, - blockhash, - chunks_bump, - buffer_bump, - offset, - data_chunk, - }; - let accounts = vec![ - AccountMeta::new(authority, true), - AccountMeta::new(chunks_pda, false), - AccountMeta::new(buffer_pda, false), - ]; - Instruction::new_with_borsh(program_id, &ix, accounts) -} - -// ----------------- -// create_close_ix -// ----------------- -pub struct CreateCloseIxArgs { - pub authority: Pubkey, - pub pubkey: Pubkey, - pub blockhash: Hash, -} - -pub fn create_close_ix(args: CreateCloseIxArgs) -> Instruction { - let CreateCloseIxArgs { - authority, - pubkey, - blockhash, - } = args; - let (chunks_pda, chunks_bump) = - pdas::chunks_pda(&authority, &pubkey, &blockhash); - let (buffer_pda, buffer_bump) = - pdas::buffer_pda(&authority, &pubkey, &blockhash); - - let program_id = crate::id(); - let ix = CommittorInstruction::Close { - pubkey, - blockhash, - chunks_bump, - buffer_bump, - }; - let accounts = vec![ - AccountMeta::new(authority, true), - AccountMeta::new(chunks_pda, false), - AccountMeta::new(buffer_pda, false), - ]; - Instruction::new_with_borsh(program_id, &ix, accounts) -} + // blockhash: Hash, + HASH_BYTES as u16 + + // chunks_bump: u8, + 1 + + // buffer_bump: u8, + 1; diff --git a/magicblock-committor-program/src/instruction_builder/close_buffer.rs b/magicblock-committor-program/src/instruction_builder/close_buffer.rs new file mode 100644 index 000000000..840bfb9fc --- /dev/null +++ b/magicblock-committor-program/src/instruction_builder/close_buffer.rs @@ -0,0 +1,45 @@ +use solana_program::instruction::{AccountMeta, Instruction}; +use solana_pubkey::Pubkey; + +use crate::{instruction::CommittorInstruction, pdas}; + +// ----------------- +// create_close_ix +// ----------------- +pub struct CreateCloseIxArgs { + pub authority: Pubkey, + pub pubkey: Pubkey, + pub commit_id: u64, +} + +pub fn create_close_ix(args: CreateCloseIxArgs) -> Instruction { + let CreateCloseIxArgs { + authority, + pubkey, + commit_id, + } = args; + let (chunks_pda, chunks_bump) = pdas::chunks_pda( + &authority, + &pubkey, + commit_id.to_le_bytes().as_slice(), + ); + let (buffer_pda, buffer_bump) = pdas::buffer_pda( + &authority, + &pubkey, + commit_id.to_le_bytes().as_slice(), + ); + + let program_id = crate::id(); + let ix = CommittorInstruction::Close { + pubkey, + commit_id, + chunks_bump, + buffer_bump, + }; + let accounts = vec![ + AccountMeta::new(authority, true), + AccountMeta::new(chunks_pda, false), + AccountMeta::new(buffer_pda, false), + ]; + Instruction::new_with_borsh(program_id, &ix, accounts) +} diff --git a/magicblock-committor-program/src/instruction_builder/init_buffer.rs b/magicblock-committor-program/src/instruction_builder/init_buffer.rs new file mode 100644 index 000000000..04c5a1c08 --- /dev/null +++ b/magicblock-committor-program/src/instruction_builder/init_buffer.rs @@ -0,0 +1,73 @@ +use solana_program::{ + instruction::{AccountMeta, Instruction}, + system_program, +}; +use solana_pubkey::Pubkey; + +use crate::{instruction::CommittorInstruction, pdas}; + +// ----------------- +// create_init_ix +// ----------------- +pub struct CreateInitIxArgs { + /// The validator authority + pub authority: Pubkey, + /// On chain address of the account we are committing + pub pubkey: Pubkey, + /// Required size of the account tracking which chunks have been committed + pub chunks_account_size: u64, + /// Required size of the buffer account that holds the account data to commit + pub buffer_account_size: u64, + /// The commit_id account commitments associated with + pub commit_id: u64, + /// The number of chunks we need to write until all the data is copied to the + /// buffer account + pub chunk_count: usize, + /// The size of each chunk that we write to the buffer account + pub chunk_size: u16, +} + +pub fn create_init_ix(args: CreateInitIxArgs) -> (Instruction, Pubkey, Pubkey) { + let CreateInitIxArgs { + authority, + pubkey, + chunks_account_size, + buffer_account_size, + commit_id, + chunk_count, + chunk_size, + } = args; + + let (chunks_pda, chunks_bump) = pdas::chunks_pda( + &authority, + &pubkey, + commit_id.to_le_bytes().as_slice(), + ); + let (buffer_pda, buffer_bump) = pdas::buffer_pda( + &authority, + &pubkey, + commit_id.to_le_bytes().as_slice(), + ); + let program_id = crate::id(); + let ix = CommittorInstruction::Init { + pubkey, + commit_id, + chunks_account_size, + buffer_account_size, + chunks_bump, + buffer_bump, + chunk_count, + chunk_size, + }; + let accounts = vec![ + AccountMeta::new(authority, true), + AccountMeta::new(chunks_pda, false), + AccountMeta::new(buffer_pda, false), + AccountMeta::new_readonly(system_program::id(), false), + ]; + ( + Instruction::new_with_borsh(program_id, &ix, accounts), + chunks_pda, + buffer_pda, + ) +} diff --git a/magicblock-committor-program/src/instruction_builder/mod.rs b/magicblock-committor-program/src/instruction_builder/mod.rs new file mode 100644 index 000000000..ec76233ec --- /dev/null +++ b/magicblock-committor-program/src/instruction_builder/mod.rs @@ -0,0 +1,4 @@ +pub mod close_buffer; +pub mod init_buffer; +pub mod realloc_buffer; +pub mod write_buffer; diff --git a/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs b/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs new file mode 100644 index 000000000..22ef37f0b --- /dev/null +++ b/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs @@ -0,0 +1,93 @@ +use solana_program::instruction::{AccountMeta, Instruction}; +use solana_pubkey::Pubkey; + +use crate::{consts, instruction::CommittorInstruction, pdas}; + +// ----------------- +// create_realloc_buffer_ix +// ----------------- +#[derive(Clone)] +pub struct CreateReallocBufferIxArgs { + pub authority: Pubkey, + pub pubkey: Pubkey, + pub buffer_account_size: u64, + pub commit_id: u64, +} + +/// Creates the realloc ixs we need to invoke in order to realloc +/// the account to the desired size since we only can realloc up to +/// [consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE] in a single instruction. +/// Returns a tuple with the instructions and a bool indicating if we need to split +/// them into multiple instructions in order to avoid +/// [solana_program::program_error::MAX_INSTRUCTION_TRACE_LENGTH_EXCEEDED]J +pub fn create_realloc_buffer_ixs( + args: CreateReallocBufferIxArgs, +) -> Vec { + // We already allocated once during Init and only need to realloc + // if the buffer is larger than [consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE] + if args.buffer_account_size + <= consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64 + { + return vec![]; + } + + let remaining_size = args.buffer_account_size as i128 + - consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128; + + // A) We just need to realloc once + if remaining_size <= consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128 + { + return vec![create_realloc_buffer_ix(args, 1)]; + } + + // B) We need to realloc multiple times + // SAFETY; remaining size > consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE + create_realloc_buffer_ixs_to_add_remaining(&args, remaining_size as u64) +} + +pub fn create_realloc_buffer_ixs_to_add_remaining( + args: &CreateReallocBufferIxArgs, + remaining_size: u64, +) -> Vec { + let invocation_count = (remaining_size as f64 + / consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as f64) + .ceil() as u16; + + let mut ixs = vec![]; + for i in 0..invocation_count { + ixs.push(create_realloc_buffer_ix(args.clone(), i + 1)); + } + + ixs +} + +fn create_realloc_buffer_ix( + args: CreateReallocBufferIxArgs, + invocation_count: u16, +) -> Instruction { + let CreateReallocBufferIxArgs { + authority, + pubkey, + buffer_account_size, + commit_id, + } = args; + let (buffer_pda, buffer_bump) = pdas::buffer_pda( + &authority, + &pubkey, + commit_id.to_le_bytes().as_slice(), + ); + + let program_id = crate::id(); + let ix = CommittorInstruction::ReallocBuffer { + pubkey, + buffer_account_size, + commit_id, + buffer_bump, + invocation_count, + }; + let accounts = vec![ + AccountMeta::new(authority, true), + AccountMeta::new(buffer_pda, false), + ]; + Instruction::new_with_borsh(program_id, &ix, accounts) +} diff --git a/magicblock-committor-program/src/instruction_builder/write_buffer.rs b/magicblock-committor-program/src/instruction_builder/write_buffer.rs new file mode 100644 index 000000000..9cbba078c --- /dev/null +++ b/magicblock-committor-program/src/instruction_builder/write_buffer.rs @@ -0,0 +1,51 @@ +use solana_program::instruction::{AccountMeta, Instruction}; +use solana_pubkey::Pubkey; + +use crate::{instruction::CommittorInstruction, pdas}; + +// ----------------- +// create_write_ix +// ----------------- +pub struct CreateWriteIxArgs { + pub authority: Pubkey, + pub pubkey: Pubkey, + pub offset: u32, + pub data_chunk: Vec, + pub commit_id: u64, +} + +pub fn create_write_ix(args: CreateWriteIxArgs) -> Instruction { + let CreateWriteIxArgs { + authority, + pubkey, + offset, + data_chunk, + commit_id, + } = args; + let (chunks_pda, chunks_bump) = pdas::chunks_pda( + &authority, + &pubkey, + commit_id.to_le_bytes().as_slice(), + ); + let (buffer_pda, buffer_bump) = pdas::buffer_pda( + &authority, + &pubkey, + commit_id.to_le_bytes().as_slice(), + ); + + let program_id = crate::id(); + let ix = CommittorInstruction::Write { + pubkey, + commit_id, + chunks_bump, + buffer_bump, + offset, + data_chunk, + }; + let accounts = vec![ + AccountMeta::new(authority, true), + AccountMeta::new(chunks_pda, false), + AccountMeta::new(buffer_pda, false), + ]; + Instruction::new_with_borsh(program_id, &ix, accounts) +} diff --git a/magicblock-committor-program/src/lib.rs b/magicblock-committor-program/src/lib.rs index eb0d51250..888faf217 100644 --- a/magicblock-committor-program/src/lib.rs +++ b/magicblock-committor-program/src/lib.rs @@ -10,7 +10,9 @@ mod state; mod utils; // #[cfg(not(feature = "no-entrypoint"))] +pub mod instruction_builder; mod processor; + // #[cfg(not(feature = "no-entrypoint"))] pub use processor::process; pub use state::{ diff --git a/magicblock-committor-program/src/pdas.rs b/magicblock-committor-program/src/pdas.rs index 7e2a4dd62..8f411385a 100644 --- a/magicblock-committor-program/src/pdas.rs +++ b/magicblock-committor-program/src/pdas.rs @@ -10,20 +10,20 @@ macro_rules! seeds { pub fn [<$prefix _seeds>]<'a>( validator_auth: &'a ::solana_pubkey::Pubkey, pubkey: &'a ::solana_pubkey::Pubkey, - blockhash: &'a ::solana_program::hash::Hash) -> [&'a [u8]; 5] { + commit_id_slice: &'a [u8]) -> [&'a [u8]; 5] { [ crate::ID.as_ref(), $bytes_const, validator_auth.as_ref(), pubkey.as_ref(), - blockhash.as_ref(), + commit_id_slice, ] } #[allow(clippy::needless_lifetimes)] pub fn [<$prefix _seeds_with_bump>]<'a>( validator_auth: &'a ::solana_pubkey::Pubkey, pubkey: &'a ::solana_pubkey::Pubkey, - blockhash: &'a ::solana_program::hash::Hash, + commit_id_slice: &'a [u8], bump: &'a [u8], ) -> [&'a [u8]; 6] { [ @@ -31,7 +31,7 @@ macro_rules! seeds { $bytes_const, validator_auth.as_ref(), pubkey.as_ref(), - blockhash.as_ref(), + commit_id_slice, bump, ] } @@ -46,21 +46,21 @@ macro_rules! pda { pub fn [<$prefix _pda>]<'a>( validator_auth: &'a ::solana_pubkey::Pubkey, pubkey: &'a ::solana_pubkey::Pubkey, - blockhash: &'a ::solana_program::hash::Hash, + commit_id_slice: &'a [u8], ) -> (::solana_pubkey::Pubkey, u8) { let program_id = &crate::id(); - let seeds = [<$prefix _seeds>](validator_auth, pubkey, blockhash); + let seeds = [<$prefix _seeds>](validator_auth, pubkey, commit_id_slice); ::solana_pubkey::Pubkey::find_program_address(&seeds, program_id) } #[allow(clippy::needless_lifetimes)] pub fn []<'a>( validator_auth: &'a ::solana_pubkey::Pubkey, pubkey: &'a ::solana_pubkey::Pubkey, - blockhash: &'a ::solana_program::hash::Hash, + commit_id_slice: &'a [u8], bump: &'a [u8], ) -> $crate::error::CommittorResult<::solana_pubkey::Pubkey> { let program_id = &crate::id(); - let seeds = [<$prefix _seeds_with_bump>](validator_auth, pubkey, blockhash, bump); + let seeds = [<$prefix _seeds_with_bump>](validator_auth, pubkey, &commit_id_slice, bump); Ok(::solana_pubkey::Pubkey::create_program_address(&seeds, program_id)?) } } @@ -78,19 +78,19 @@ macro_rules! verified_seeds_and_pda { $authority_info:ident, $pubkey:ident, $account_info:ident, - $blockhash:ident, + $commit_id_slice:ident, $bump:ident) => {{ ::paste::paste! { let seeds = $crate::pdas::[<$prefix _seeds_with_bump>]( $authority_info.key, $pubkey, - &$blockhash, + $commit_id_slice, $bump, ); let pda = $crate::pdas::[]( $authority_info.key, $pubkey, - &$blockhash, + $commit_id_slice, $bump, ) .inspect_err(|err| ::solana_program::msg!("ERR: {}", err))?; diff --git a/magicblock-committor-program/src/processor.rs b/magicblock-committor-program/src/processor.rs index 320ae5cab..bc3e6637b 100644 --- a/magicblock-committor-program/src/processor.rs +++ b/magicblock-committor-program/src/processor.rs @@ -1,8 +1,8 @@ use borsh::{to_vec, BorshDeserialize}; use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, hash::Hash, - log::sol_log_64, msg, program::invoke_signed, program_error::ProgramError, - system_instruction, sysvar::Sysvar, + account_info::AccountInfo, entrypoint::ProgramResult, log::sol_log_64, msg, + program::invoke_signed, program_error::ProgramError, system_instruction, + sysvar::Sysvar, }; use solana_pubkey::Pubkey; @@ -31,7 +31,7 @@ pub fn process( pubkey, chunks_account_size, buffer_account_size, - blockhash, + commit_id, chunks_bump, buffer_bump, chunk_count, @@ -42,7 +42,7 @@ pub fn process( &pubkey, chunks_account_size, buffer_account_size, - blockhash, + commit_id, chunks_bump, buffer_bump, chunk_count, @@ -51,20 +51,20 @@ pub fn process( ReallocBuffer { pubkey, buffer_account_size, - blockhash, + commit_id, buffer_bump, invocation_count, } => process_realloc_buffer( accounts, &pubkey, buffer_account_size, - blockhash, + commit_id, buffer_bump, invocation_count, ), Write { pubkey, - blockhash, + commit_id, chunks_bump, buffer_bump, offset, @@ -74,19 +74,19 @@ pub fn process( &pubkey, offset, data_chunk, - blockhash, + commit_id, chunks_bump, buffer_bump, ), Close { pubkey, - blockhash, + commit_id, chunks_bump, buffer_bump, } => process_close( accounts, &pubkey, - blockhash, + commit_id, chunks_bump, buffer_bump, ), @@ -103,7 +103,7 @@ fn process_init( pubkey: &Pubkey, chunks_account_size: u64, buffer_account_size: u64, - blockhash: Hash, + commit_id: u64, chunks_bump: u8, buffer_bump: u8, chunk_count: usize, @@ -118,14 +118,14 @@ fn process_init( return Err(ProgramError::NotEnoughAccountKeys); }; assert_is_signer(authority_info, "authority")?; - let chunks_bump = &[chunks_bump]; + let commit_id_slice = &commit_id.to_le_bytes(); let (chunks_seeds, _chunks_pda) = verified_seeds_and_pda!( chunks, authority_info, pubkey, chunks_account_info, - blockhash, + commit_id_slice, chunks_bump ); @@ -135,7 +135,7 @@ fn process_init( authority_info, pubkey, buffer_account_info, - blockhash, + commit_id_slice, buffer_bump ); @@ -203,7 +203,7 @@ fn process_realloc_buffer( accounts: &[AccountInfo], pubkey: &Pubkey, buffer_account_size: u64, - blockhash: Hash, + commit_id: u64, buffer_bump: u8, invocation_count: u16, ) -> ProgramResult { @@ -228,12 +228,14 @@ fn process_realloc_buffer( assert_is_signer(authority_info, "authority")?; let buffer_bump = &[buffer_bump]; + let commit_id_slice = commit_id.to_le_bytes(); + let asd = commit_id_slice.as_slice(); verified_seeds_and_pda!( buffer, authority_info, pubkey, buffer_account_info, - blockhash, + asd, buffer_bump ); @@ -268,7 +270,7 @@ fn process_write( pubkey: &Pubkey, offset: u32, data_chunk: Vec, - blockhash: Hash, + commit_id: u64, chunks_bump: u8, buffer_bump: u8, ) -> ProgramResult { @@ -286,7 +288,7 @@ fn process_write( chunks_account_info, buffer_account_info, pubkey, - &blockhash, + commit_id, chunks_bump, buffer_bump, )?; @@ -332,7 +334,9 @@ fn process_write( let mut chunks_data = chunks_account_info.data.borrow_mut(); let mut chunks = Chunks::try_from_slice(&chunks_data)?; - chunks.set_offset(offset as usize)?; + chunks + .set_offset_delivered(offset as usize) + .map_err(CommittorError::from)?; chunks_data.copy_from_slice(&to_vec(&chunks)?); Ok(()) @@ -344,7 +348,7 @@ fn process_write( pub fn process_close( accounts: &[AccountInfo], pubkey: &Pubkey, - blockhash: Hash, + commit_id: u64, chunks_bump: u8, buffer_bump: u8, ) -> ProgramResult { @@ -362,7 +366,7 @@ pub fn process_close( chunks_account_info, buffer_account_info, pubkey, - &blockhash, + commit_id, chunks_bump, buffer_bump, )?; @@ -379,17 +383,18 @@ fn verify_seeds_and_pdas( chunks_account_info: &AccountInfo, buffer_account_info: &AccountInfo, pubkey: &Pubkey, - blockhash: &Hash, + commit_id: u64, chunks_bump: u8, buffer_bump: u8, ) -> ProgramResult { let chunks_bump = &[chunks_bump]; + let commit_id_slice = &commit_id.to_le_bytes(); let (_chunks_seeds, _chunks_pda) = verified_seeds_and_pda!( chunks, authority_info, pubkey, chunks_account_info, - blockhash, + commit_id_slice, chunks_bump ); @@ -399,7 +404,7 @@ fn verify_seeds_and_pdas( authority_info, pubkey, buffer_account_info, - blockhash, + commit_id_slice, buffer_bump ); Ok(()) diff --git a/magicblock-committor-program/src/state/changeset.rs b/magicblock-committor-program/src/state/changeset.rs index 3caf55327..23ff236d6 100644 --- a/magicblock-committor-program/src/state/changeset.rs +++ b/magicblock-committor-program/src/state/changeset.rs @@ -464,7 +464,7 @@ mod test { continue; } - chunks.set_idx(idx as usize); + chunks.set_chunk_delivered(idx as usize); let start = chunk.offset; for (i, d) in chunk.data_chunk.into_iter().enumerate() { @@ -480,7 +480,7 @@ mod test { // 3. Retry the missing chunks for chunk in commitable.iter_missing() { - chunks.set_idx(chunk.chunk_idx() as usize); + chunks.set_chunk_delivered(chunk.chunk_idx() as usize); let start = chunk.offset; for (i, d) in chunk.data_chunk.into_iter().enumerate() { diff --git a/magicblock-committor-program/src/state/chunks.rs b/magicblock-committor-program/src/state/chunks.rs index 824a33453..ea56dd0ee 100644 --- a/magicblock-committor-program/src/state/chunks.rs +++ b/magicblock-committor-program/src/state/chunks.rs @@ -2,12 +2,9 @@ use std::{collections::HashSet, fmt}; use borsh::{BorshDeserialize, BorshSerialize}; -use crate::{ - consts, - error::{CommittorError, CommittorResult}, -}; +use crate::consts; -const BIT_FIELD_SIZE: usize = 8; +const BITS_PER_BYTE: usize = 8; /// A bitfield based implementation to keep track of which chunks have been delivered. /// This is much more memory efficient than a Vec which uses 1 byte per value. @@ -28,47 +25,36 @@ pub struct Chunks { chunk_size: u16, } -impl fmt::Display for Chunks { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - for (idx, bit) in self.bits.iter().enumerate() { - if idx % 8 == 0 { - write!(f, "\n{:05}: ", idx * BIT_FIELD_SIZE)?; - } - let bit = format!("{:08b}", bit); - let bit = bit.chars().rev().collect::(); - // add space after 4 bits - let (bit1, bit2) = bit.split_at(4); - write!(f, "{} {} ", bit1, bit2)?; - } - Ok(()) - } -} - impl Chunks { pub fn new(chunk_count: usize, chunk_size: u16) -> Self { // SAFETY: this is a bug and we need to crash and burn assert!( - Self::bytes_for_count_len(chunk_count) + Self::struct_size(chunk_count) < consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as usize, "Size ({}) needed to track {} chunks is too large track and would require to realloc. Max allowed is {} bytes", - Self::bytes_for_count_len(chunk_count), + Self::struct_size(chunk_count), chunk_count, consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE ); Self { - bits: vec![0; Self::bits_for_count_len(chunk_count)], + bits: vec![0; Self::count_to_bitfield_bytes(chunk_count)], count: chunk_count, chunk_size, } } - fn bits_for_count_len(count: usize) -> usize { - count / BIT_FIELD_SIZE + 1 + /// Calculates the minimum number of bytes needed to store `count` boolean values in a bitfield. + /// + /// Each boolean is stored as a single bit, packing 8 booleans per byte. + /// Returns the number of bytes needed to store all flags, rounding up if necessary. + fn count_to_bitfield_bytes(count: usize) -> usize { + (count + BITS_PER_BYTE - 1) / BITS_PER_BYTE } - pub fn bytes_for_count_len(count: usize) -> usize { + /// Returns how many bytes [`Chunks`] will occupy certain count + pub fn struct_size(count: usize) -> usize { // bits: Vec, - Self::bits_for_count_len(count) * std::mem::size_of::() + Self::count_to_bitfield_bytes(count) * std::mem::size_of::() // count: usize, + std::mem::size_of::() // chunk_size: u16, @@ -76,45 +62,60 @@ impl Chunks { } /// Returns `true` if the chunk at index has been delivered - pub fn get_idx(&self, idx: usize) -> bool { + pub fn is_chunk_delivered(&self, idx: usize) -> Option { if idx >= self.count { - return false; + None + } else { + let vec_idx = idx / BITS_PER_BYTE; + let bit_idx = idx % BITS_PER_BYTE; + Some((self.bits[vec_idx] & (1 << bit_idx)) != 0) } - let vec_idx = idx / BIT_FIELD_SIZE; - let bit_idx = idx % BIT_FIELD_SIZE; - (self.bits[vec_idx] & (1 << bit_idx)) != 0 } /// Sets the chunk at index to `true` denoting that it has been delivered - pub(super) fn set_idx(&mut self, idx: usize) { + pub(super) fn set_chunk_delivered( + &mut self, + idx: usize, + ) -> Result<(), ChunksError> { if idx < self.count { - let vec_idx = idx / BIT_FIELD_SIZE; - let bit_idx = idx % BIT_FIELD_SIZE; + let vec_idx = idx / BITS_PER_BYTE; + let bit_idx = idx % BITS_PER_BYTE; self.bits[vec_idx] |= 1 << bit_idx; + Ok(()) + } else { + Err(ChunksError::OutOfBoundsError) } } - pub fn set_offset(&mut self, offset: usize) -> CommittorResult<()> { + /// Marks that chunk at offset was written to + pub fn set_offset_delivered( + &mut self, + offset: usize, + ) -> Result<(), ChunksError> { if offset % self.chunk_size as usize != 0 { - return Err(CommittorError::OffsetMustBeMultipleOfChunkSize( - offset, - self.chunk_size, - )); + Err(ChunksError::InvalidOffsetError(offset, self.chunk_size)) + } else { + let idx = offset / self.chunk_size as usize; + self.set_chunk_delivered(idx)?; + Ok(()) } - let idx = offset / self.chunk_size as usize; - self.set_idx(idx); - Ok(()) } - pub fn get_offset(&self, offset: usize) -> CommittorResult { + /// Return [`true`] if offset delivered + /// Returns error if offset isn't multuple of chunk + pub fn is_offset_delivered( + &self, + offset: usize, + ) -> Result { if offset % self.chunk_size as usize != 0 { - return Err(CommittorError::OffsetMustBeMultipleOfChunkSize( + return Err(ChunksError::InvalidOffsetError( offset, self.chunk_size, )); } let idx = offset / self.chunk_size as usize; - Ok(self.get_idx(idx)) + self.is_chunk_delivered(idx) + .ok_or(ChunksError::OutOfBoundsError) } pub fn count(&self) -> usize { @@ -126,7 +127,9 @@ impl Chunks { } pub fn get_missing_chunks(&self) -> HashSet { - (0..self.count).filter(|&i| !self.get_idx(i)).collect() + (0..self.count) + .filter(|&i| !self.is_chunk_delivered(i).expect("invariant")) + .collect() } pub fn is_complete(&self) -> bool { @@ -136,21 +139,41 @@ impl Chunks { impl From<(Vec, u16)> for Chunks { fn from((vec, chunk_size): (Vec, u16)) -> Self { - let bits = vec![0; vec.len() / BIT_FIELD_SIZE + 1]; - let mut chunks = Self { - bits, - count: vec.len(), - chunk_size, - }; - for (i, &d) in vec.iter().enumerate() { + let mut this = Chunks::new(vec.len(), chunk_size); + vec.into_iter().enumerate().for_each(|(i, d)| { if d { - chunks.set_idx(i); + this.set_chunk_delivered(i).expect("invariant"); + } + }); + + this + } +} + +impl fmt::Display for Chunks { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + for (idx, bit) in self.bits.iter().enumerate() { + if idx % 8 == 0 { + write!(f, "\n{:05}: ", idx * BITS_PER_BYTE)?; } + let bit = format!("{:08b}", bit); + let bit = bit.chars().rev().collect::(); + // add space after 4 bits + let (bit1, bit2) = bit.split_at(4); + write!(f, "{} {} ", bit1, bit2)?; } - chunks + Ok(()) } } +#[derive(thiserror::Error, Debug)] +pub enum ChunksError { + #[error("Out of bounds access")] + OutOfBoundsError, + #[error("Offset ({0}) must be multiple of chunk size ({1})")] + InvalidOffsetError(usize, u16), +} + #[cfg(test)] mod test { use super::*; @@ -175,7 +198,7 @@ mod test { if self.idx < self.chunks.count { let idx = self.idx; self.idx += 1; - Some(self.chunks.get_idx(idx)) + Some(self.chunks.is_chunk_delivered(idx)) } else { None } @@ -196,12 +219,12 @@ mod test { fn test_chunks_set_get_idx() { let chunks = vec![false; 12]; let mut chunks = Chunks::from((chunks, CHUNK_SIZE)); - chunks.set_idx(0); - chunks.set_idx(10); + chunks.set_chunk_delivered(0); + chunks.set_chunk_delivered(10); - assert!(chunks.get_idx(0)); - assert!(!chunks.get_idx(1)); - assert!(chunks.get_idx(10)); + assert!(chunks.is_chunk_delivered(0)); + assert!(!chunks.is_chunk_delivered(1)); + assert!(chunks.is_chunk_delivered(10)); let vec = chunks.iter().collect::>(); #[rustfmt::skip] @@ -218,18 +241,18 @@ mod test { fn test_chunks_set_get_idx_large() { let chunks = vec![false; 2048]; let mut chunks = Chunks::from((chunks, CHUNK_SIZE)); - chunks.set_idx(99); - chunks.set_idx(1043); - - assert!(!chunks.get_idx(0)); - assert!(!chunks.get_idx(1)); - assert!(chunks.get_idx(99)); - assert!(!chunks.get_idx(1042)); - assert!(chunks.get_idx(1043)); - assert!(!chunks.get_idx(1044)); - - assert!(!chunks.get_idx(2048)); - assert!(!chunks.get_idx(2049)); + chunks.set_chunk_delivered(99); + chunks.set_chunk_delivered(1043); + + assert!(!chunks.is_chunk_delivered(0)); + assert!(!chunks.is_chunk_delivered(1)); + assert!(chunks.is_chunk_delivered(99)); + assert!(!chunks.is_chunk_delivered(1042)); + assert!(chunks.is_chunk_delivered(1043)); + assert!(!chunks.is_chunk_delivered(1044)); + + assert!(!chunks.is_chunk_delivered(2048)); + assert!(!chunks.is_chunk_delivered(2049)); assert_eq!(chunks.iter().count(), 2048); } diff --git a/magicblock-committor-program/tests/prog_init_write_and_close.rs b/magicblock-committor-program/tests/prog_init_write_and_close.rs index e5448095d..77baa3809 100644 --- a/magicblock-committor-program/tests/prog_init_write_and_close.rs +++ b/magicblock-committor-program/tests/prog_init_write_and_close.rs @@ -1,8 +1,10 @@ use borsh::{to_vec, BorshDeserialize}; use magicblock_committor_program::{ - instruction::{ - create_init_ix, create_realloc_buffer_ixs, CreateInitIxArgs, - CreateReallocBufferIxArgs, + instruction_builder::{ + init_buffer::{create_init_ix, CreateInitIxArgs}, + realloc_buffer::{ + create_realloc_buffer_ixs, CreateReallocBufferIxArgs, + }, }, instruction_chunks::chunk_realloc_ixs, ChangedAccount, Changeset, Chunks, @@ -219,7 +221,7 @@ async fn init_write_and_close(changeset: Changeset) { let chunks = get_chunks!(&banks_client, chunks_pda); for i in 0..chunks.count() { - assert!(!chunks.get_idx(i)); + assert!(!chunks.is_chunk_delivered(i)); } assert!(!chunks.is_complete()); @@ -229,8 +231,8 @@ async fn init_write_and_close(changeset: Changeset) { // Write the first chunk { let first_chunk = &commitable.iter_all().next().unwrap(); - let write_ix = magicblock_committor_program::instruction::create_write_ix( - magicblock_committor_program::instruction::CreateWriteIxArgs { + let write_ix = magicblock_committor_program::instruction_builder::write_buffer::create_write_ix( + magicblock_committor_program::instruction_builder::write_buffer::CreateWriteIxArgs { authority: auth.pubkey(), pubkey: commitable.pubkey, offset: first_chunk.offset, @@ -243,9 +245,9 @@ async fn init_write_and_close(changeset: Changeset) { let chunks = get_chunks!(&banks_client, chunks_pda); assert_eq!(chunks.count(), commitable.chunk_count()); assert_eq!(chunks.chunk_size(), commitable.chunk_size()); - assert!(chunks.get_idx(0)); + assert!(chunks.is_chunk_delivered(0)); for i in 1..chunks.count() { - assert!(!chunks.get_idx(i)); + assert!(!chunks.is_chunk_delivered(i)); } assert!(!chunks.is_complete()); @@ -259,8 +261,8 @@ async fn init_write_and_close(changeset: Changeset) { // Write third chunk { let third_chunk = &commitable.iter_all().nth(2).unwrap(); - let write_ix = magicblock_committor_program::instruction::create_write_ix( - magicblock_committor_program::instruction::CreateWriteIxArgs { + let write_ix = magicblock_committor_program::instruction_builder::write_buffer::create_write_ix( + magicblock_committor_program::instruction_builder::write_buffer::CreateWriteIxArgs { authority: auth.pubkey(), pubkey: commitable.pubkey, offset: third_chunk.offset, @@ -271,11 +273,11 @@ async fn init_write_and_close(changeset: Changeset) { exec!(banks_client, &[write_ix], auth, latest_blockhash); let chunks = get_chunks!(&banks_client, chunks_pda); - assert!(chunks.get_idx(0)); - assert!(!chunks.get_idx(1)); - assert!(chunks.get_idx(2)); + assert!(chunks.is_chunk_delivered(0)); + assert!(!chunks.is_chunk_delivered(1)); + assert!(chunks.is_chunk_delivered(2)); for i in 3..chunks.count() { - assert!(!chunks.get_idx(i)); + assert!(!chunks.is_chunk_delivered(i)); } assert!(!chunks.is_complete()); @@ -293,8 +295,8 @@ async fn init_write_and_close(changeset: Changeset) { for chunk in commitable.iter_missing() { let latest_blockhash = banks_client.get_latest_blockhash().await.unwrap(); - let write_ix = magicblock_committor_program::instruction::create_write_ix( - magicblock_committor_program::instruction::CreateWriteIxArgs { + let write_ix = magicblock_committor_program::instruction_builder::write_buffer::create_write_ix( + magicblock_committor_program::instruction_builder::write_buffer::CreateWriteIxArgs { authority: auth.pubkey(), pubkey: commitable.pubkey, offset: chunk.offset, @@ -307,7 +309,7 @@ async fn init_write_and_close(changeset: Changeset) { let chunks = get_chunks!(&banks_client, chunks_pda); for i in 0..chunks.count() { - assert!(chunks.get_idx(i)); + assert!(chunks.is_chunk_delivered(i)); } assert!(chunks.is_complete()); @@ -322,8 +324,8 @@ async fn init_write_and_close(changeset: Changeset) { // Normally this instruction would be part of a transaction that processes // the change set to update the corresponding accounts - let close_ix = magicblock_committor_program::instruction::create_close_ix( - magicblock_committor_program::instruction::CreateCloseIxArgs { + let close_ix = magicblock_committor_program::instruction_builder::close_buffer::create_close_ix( + magicblock_committor_program::instruction_builder::close_buffer::CreateCloseIxArgs { authority: auth.pubkey(), pubkey: commitable.pubkey, blockhash: ephem_blockhash, From a087223596d5a4d8c2c0a73753969a4f560b69e1 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 3 Jul 2025 18:23:00 +0800 Subject: [PATCH 077/199] fix: test compilation --- .../src/state/changeset.rs | 6 +- .../src/state/chunks.rs | 37 +- .../tests/prog_init_write_and_close.rs | 117 ++-- .../src/commit/commit_scheduler.rs | 145 ++++ .../src/commit_strategist/commit_strategy.rs | 633 ++++++++++++++++++ .../src/commit_strategist/mod.rs | 2 + .../src/commit_strategist/report_builder.rs | 10 + .../budget_calculator.rs | 52 ++ .../src/transaction_preperator/error.rs | 14 + .../src/transaction_preperator/mod.rs | 4 + .../transaction_preperator/task_builder.rs | 0 .../transaction_preparator.rs | 69 ++ .../src/transaction_preperator/utils.rs | 0 .../src/magic_scheduled_l1_message.rs | 401 +++++++++++ 14 files changed, 1413 insertions(+), 77 deletions(-) create mode 100644 magicblock-committor-service/src/commit/commit_scheduler.rs create mode 100644 magicblock-committor-service/src/commit_strategist/commit_strategy.rs create mode 100644 magicblock-committor-service/src/commit_strategist/mod.rs create mode 100644 magicblock-committor-service/src/commit_strategist/report_builder.rs create mode 100644 magicblock-committor-service/src/transaction_preperator/budget_calculator.rs create mode 100644 magicblock-committor-service/src/transaction_preperator/error.rs create mode 100644 magicblock-committor-service/src/transaction_preperator/mod.rs create mode 100644 magicblock-committor-service/src/transaction_preperator/task_builder.rs create mode 100644 magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs create mode 100644 magicblock-committor-service/src/transaction_preperator/utils.rs create mode 100644 programs/magicblock/src/magic_scheduled_l1_message.rs diff --git a/magicblock-committor-program/src/state/changeset.rs b/magicblock-committor-program/src/state/changeset.rs index 23ff236d6..5e96cbbb9 100644 --- a/magicblock-committor-program/src/state/changeset.rs +++ b/magicblock-committor-program/src/state/changeset.rs @@ -464,7 +464,7 @@ mod test { continue; } - chunks.set_chunk_delivered(idx as usize); + chunks.set_chunk_delivered(idx as usize).unwrap(); let start = chunk.offset; for (i, d) in chunk.data_chunk.into_iter().enumerate() { @@ -480,7 +480,9 @@ mod test { // 3. Retry the missing chunks for chunk in commitable.iter_missing() { - chunks.set_chunk_delivered(chunk.chunk_idx() as usize); + chunks + .set_chunk_delivered(chunk.chunk_idx() as usize) + .unwrap(); let start = chunk.offset; for (i, d) in chunk.data_chunk.into_iter().enumerate() { diff --git a/magicblock-committor-program/src/state/chunks.rs b/magicblock-committor-program/src/state/chunks.rs index ea56dd0ee..96fb81971 100644 --- a/magicblock-committor-program/src/state/chunks.rs +++ b/magicblock-committor-program/src/state/chunks.rs @@ -198,7 +198,7 @@ mod test { if self.idx < self.chunks.count { let idx = self.idx; self.idx += 1; - Some(self.chunks.is_chunk_delivered(idx)) + Some(self.chunks.is_chunk_delivered(idx).expect("invariant")) } else { None } @@ -219,12 +219,12 @@ mod test { fn test_chunks_set_get_idx() { let chunks = vec![false; 12]; let mut chunks = Chunks::from((chunks, CHUNK_SIZE)); - chunks.set_chunk_delivered(0); - chunks.set_chunk_delivered(10); + assert!(chunks.set_chunk_delivered(0).is_ok()); + assert!(chunks.set_chunk_delivered(10).is_ok()); - assert!(chunks.is_chunk_delivered(0)); - assert!(!chunks.is_chunk_delivered(1)); - assert!(chunks.is_chunk_delivered(10)); + assert!(chunks.is_chunk_delivered(0).unwrap()); + assert!(!chunks.is_chunk_delivered(1).unwrap()); + assert!(chunks.is_chunk_delivered(10).unwrap()); let vec = chunks.iter().collect::>(); #[rustfmt::skip] @@ -241,18 +241,19 @@ mod test { fn test_chunks_set_get_idx_large() { let chunks = vec![false; 2048]; let mut chunks = Chunks::from((chunks, CHUNK_SIZE)); - chunks.set_chunk_delivered(99); - chunks.set_chunk_delivered(1043); - - assert!(!chunks.is_chunk_delivered(0)); - assert!(!chunks.is_chunk_delivered(1)); - assert!(chunks.is_chunk_delivered(99)); - assert!(!chunks.is_chunk_delivered(1042)); - assert!(chunks.is_chunk_delivered(1043)); - assert!(!chunks.is_chunk_delivered(1044)); - - assert!(!chunks.is_chunk_delivered(2048)); - assert!(!chunks.is_chunk_delivered(2049)); + assert!(chunks.set_chunk_delivered(99).is_ok()); + assert!(chunks.set_chunk_delivered(1043).is_ok()); + + assert!(!chunks.is_chunk_delivered(0).unwrap()); + assert!(!chunks.is_chunk_delivered(1).unwrap()); + assert!(chunks.is_chunk_delivered(99).unwrap()); + assert!(!chunks.is_chunk_delivered(1042).unwrap()); + assert!(chunks.is_chunk_delivered(1043).unwrap()); + assert!(!chunks.is_chunk_delivered(1044).unwrap()); + + // Out of bound request + assert!(chunks.is_chunk_delivered(2048).is_none()); + assert!(chunks.is_chunk_delivered(2049).is_none()); assert_eq!(chunks.iter().count(), 2048); } diff --git a/magicblock-committor-program/tests/prog_init_write_and_close.rs b/magicblock-committor-program/tests/prog_init_write_and_close.rs index 77baa3809..3fd6063b0 100644 --- a/magicblock-committor-program/tests/prog_init_write_and_close.rs +++ b/magicblock-committor-program/tests/prog_init_write_and_close.rs @@ -9,46 +9,50 @@ use magicblock_committor_program::{ instruction_chunks::chunk_realloc_ixs, ChangedAccount, Changeset, Chunks, }; +use solana_program::instruction::Instruction; use solana_program_test::*; use solana_pubkey::Pubkey; +use solana_sdk::signature::Keypair; use solana_sdk::{ blake3::HASH_BYTES, hash::Hash, native_token::LAMPORTS_PER_SOL, signer::Signer, transaction::Transaction, }; -macro_rules! exec { - ($banks_client:ident, $ix:expr, $auth:ident, $latest_blockhash:ident) => {{ - let mut transaction = - Transaction::new_with_payer($ix, Some(&$auth.pubkey())); - transaction.sign(&[$auth.insecure_clone()], $latest_blockhash); - $banks_client - .process_transaction(transaction) - .await - .unwrap(); - }}; +// Replace exec! macro +async fn exec( + banks_client: &BanksClient, + ixs: &[Instruction], + auth: &Keypair, + latest_blockhash: Hash, +) { + let mut transaction = + Transaction::new_with_payer(ixs, Some(&auth.pubkey())); + transaction.sign(&[auth.insecure_clone()], latest_blockhash); + banks_client.process_transaction(transaction).await.unwrap() } -macro_rules! get_chunks { - ($banks_client:expr, $chunks_pda:expr) => {{ - let chunks_data = $banks_client - .get_account($chunks_pda) - .await - .unwrap() - .unwrap() - .data; - Chunks::try_from_slice(&chunks_data).unwrap() - }}; +// Replace get_chunks! macro +async fn get_chunks(banks_client: &BanksClient, chunks_pda: &Pubkey) -> Chunks { + let chunks_data = banks_client + .get_account(*chunks_pda) + .await + .unwrap() + .unwrap() + .data; + Chunks::try_from_slice(&chunks_data).unwrap() } -macro_rules! get_buffer_data { - ($banks_client:expr, $buffer_pda:expr) => {{ - $banks_client - .get_account($buffer_pda) - .await - .unwrap() - .unwrap() - .data - }}; +// Replace get_buffer_data! macro +async fn get_buffer_data( + banks_client: &BanksClient, + buffer_pda: &Pubkey, +) -> Vec { + banks_client + .get_account(*buffer_pda) + .await + .unwrap() + .unwrap() + .data } #[tokio::test] @@ -180,8 +184,6 @@ async fn init_write_and_close(changeset: Changeset) { .start() .await; - let ephem_blockhash = Hash::from([1; HASH_BYTES]); - let chunk_size = 439 / 14; let commitables = changeset.into_committables(chunk_size); for commitable in commitables.iter() { @@ -197,7 +199,7 @@ async fn init_write_and_close(changeset: Changeset) { pubkey: commitable.pubkey, chunks_account_size, buffer_account_size: commitable.size() as u64, - blockhash: ephem_blockhash, + commit_id: commitable.bundle_id, chunk_count: commitable.chunk_count(), chunk_size: commitable.chunk_size(), }); @@ -206,22 +208,22 @@ async fn init_write_and_close(changeset: Changeset) { authority: auth.pubkey(), pubkey: commitable.pubkey, buffer_account_size: commitable.size() as u64, - blockhash: ephem_blockhash, + commit_id: commitable.bundle_id, }); let ix_chunks = chunk_realloc_ixs(realloc_ixs, Some(init_ix)); for ixs in ix_chunks { let latest_blockhash = banks_client.get_latest_blockhash().await.unwrap(); - exec!(banks_client, &ixs, auth, latest_blockhash); + exec(&banks_client, &ixs, &auth, latest_blockhash).await; } (chunks_pda, buffer_pda) }; - let chunks = get_chunks!(&banks_client, chunks_pda); + let chunks = get_chunks(&banks_client, &chunks_pda).await; for i in 0..chunks.count() { - assert!(!chunks.is_chunk_delivered(i)); + assert!(!chunks.is_chunk_delivered(i).unwrap()); } assert!(!chunks.is_complete()); @@ -237,21 +239,21 @@ async fn init_write_and_close(changeset: Changeset) { pubkey: commitable.pubkey, offset: first_chunk.offset, data_chunk: first_chunk.data_chunk.clone(), - blockhash: ephem_blockhash, + commit_id: commitable.bundle_id, }, ); - exec!(banks_client, &[write_ix], auth, latest_blockhash); + exec(&banks_client, &[write_ix], &auth, latest_blockhash).await; - let chunks = get_chunks!(&banks_client, chunks_pda); + let chunks = get_chunks(&banks_client, &chunks_pda).await; assert_eq!(chunks.count(), commitable.chunk_count()); assert_eq!(chunks.chunk_size(), commitable.chunk_size()); - assert!(chunks.is_chunk_delivered(0)); + assert!(chunks.is_chunk_delivered(0).unwrap()); for i in 1..chunks.count() { - assert!(!chunks.is_chunk_delivered(i)); + assert!(!chunks.is_chunk_delivered(i).unwrap()); } assert!(!chunks.is_complete()); - let buffer_data = get_buffer_data!(&banks_client, buffer_pda); + let buffer_data = get_buffer_data(&banks_client, &buffer_pda).await; assert_eq!( buffer_data[0..first_chunk.data_chunk.len()], first_chunk.data_chunk @@ -267,21 +269,22 @@ async fn init_write_and_close(changeset: Changeset) { pubkey: commitable.pubkey, offset: third_chunk.offset, data_chunk: third_chunk.data_chunk.clone(), - blockhash: ephem_blockhash, + commit_id: commitable.bundle_id, }, ); - exec!(banks_client, &[write_ix], auth, latest_blockhash); + exec(&banks_client, &[write_ix], &auth, latest_blockhash).await; - let chunks = get_chunks!(&banks_client, chunks_pda); - assert!(chunks.is_chunk_delivered(0)); - assert!(!chunks.is_chunk_delivered(1)); - assert!(chunks.is_chunk_delivered(2)); + let chunks = get_chunks(&banks_client, &chunks_pda).await; + assert!(chunks.is_chunk_delivered(0).unwrap()); + assert!(!chunks.is_chunk_delivered(1).unwrap()); + assert!(chunks.is_chunk_delivered(2).unwrap()); for i in 3..chunks.count() { - assert!(!chunks.is_chunk_delivered(i)); + assert!(!chunks.is_chunk_delivered(i).unwrap()); } assert!(!chunks.is_complete()); - let buffer_data = get_buffer_data!(&banks_client, buffer_pda); + let buffer_data = + get_buffer_data(&banks_client, &&buffer_pda).await; assert_eq!( buffer_data[third_chunk.offset as usize ..third_chunk.offset as usize @@ -301,19 +304,19 @@ async fn init_write_and_close(changeset: Changeset) { pubkey: commitable.pubkey, offset: chunk.offset, data_chunk: chunk.data_chunk.clone(), - blockhash: ephem_blockhash, + commit_id: commitable.bundle_id, }, ); - exec!(banks_client, &[write_ix], auth, latest_blockhash); + exec(&banks_client, &[write_ix], &auth, latest_blockhash).await; } - let chunks = get_chunks!(&banks_client, chunks_pda); + let chunks = get_chunks(&banks_client, &chunks_pda).await; for i in 0..chunks.count() { - assert!(chunks.is_chunk_delivered(i)); + assert!(chunks.is_chunk_delivered(i).unwrap()); } assert!(chunks.is_complete()); - let buffer = get_buffer_data!(&banks_client, buffer_pda); + let buffer = get_buffer_data(&banks_client, &&buffer_pda).await; assert_eq!(buffer, commitable.data); } @@ -328,10 +331,10 @@ async fn init_write_and_close(changeset: Changeset) { magicblock_committor_program::instruction_builder::close_buffer::CreateCloseIxArgs { authority: auth.pubkey(), pubkey: commitable.pubkey, - blockhash: ephem_blockhash, + commit_id: commitable.bundle_id, }, ); - exec!(banks_client, &[close_ix], auth, latest_blockhash); + exec(&banks_client, &[close_ix], &auth, latest_blockhash).await; assert!(banks_client .get_account(chunks_pda) diff --git a/magicblock-committor-service/src/commit/commit_scheduler.rs b/magicblock-committor-service/src/commit/commit_scheduler.rs new file mode 100644 index 000000000..b4754b332 --- /dev/null +++ b/magicblock-committor-service/src/commit/commit_scheduler.rs @@ -0,0 +1,145 @@ +use std::collections::VecDeque; +use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; +use tokio::sync::mpsc::error::{TryRecvError, TrySendError}; +use tokio::select; +use tokio::sync::mpsc::{channel, Receiver, Sender}; +use tokio::sync::mpsc::error::SendError; +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; + +pub struct CommitScheduler { + queue: VecDeque, + sender: Sender, +} + +impl CommitScheduler { + pub fn new() -> Self { + // TODO: define + let (sender, receiver) = channel(1000); + tokio::spawn(Self::start(receiver)); + + Self { + queue: VecDeque::default(), + sender + } + } + + async fn start(mut l1_message_receiver: Receiver, db_flag: Arc) { + // scheduler + // accepts messages + // if no commits we shall be idle + loop { + let message = match l1_message_receiver.try_recv() { + Ok(val) => { + val + } + Err(TryRecvError::Empty) => { + if let Ok(val) = Self::get_next_message(&mut l1_message_receiver, &db_flag).await { + val + } else { + // TODO(edwin): handle + panic!("Asdasd") + } + } + Err(TryRecvError::Disconnected) => { + // TODO(edwin): handle + panic!("Asdasd") + }, + }; + + // send and shit + todo!() + } + + while let Some(l1_messages) = l1_message_receiver.recv().await { + + } + } + + async fn get_next_message(l1_message_receiver: &mut Receiver, db_flag: &AtomicBool) -> Result { + if db_flag.load(Ordering::Relaxed) { + // TODO: expensive to fetch 1 by 1, implement fetching multiple. Could use static? + Self::get_message_from_db().await + } else { + if let Some(val) = l1_message_receiver.recv().await { + Ok(val) + } else { + Err(Error::ChannelClosed) + } + } + } + + // TODO(edwin) + async fn get_message_from_db() -> Result { + todo!() + } + + pub async fn schedule(&self, l1_messages: Vec) -> Result<(), Error>{ + for el in l1_messages { + let err = if let Err(err) = self.sender.try_send(el) { + err + } else { + continue; + }; + + if matches!(err, TrySendError::Closed(_)) { + return Err(Error::ChannelClosed) + } + + } + + Ok(()) + } +} + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("Channel was closed")] + ChannelClosed +} + + +/// ideal system: +/// +// Service keeps accepting messages +// once there's a full channel in order not to stall or overload RAM +// we write to + +// Having message service batches in optimal way + +/// WE NEED: +// - Split into proper Commitable chunks +// - + +/// We insert into scheduler and then figure out how to optimally split messages +// or we split messages and then try to commit specific chunks? + + +// we write to channel it becom3s full +// we need to write to db +// Who will + + + +// TODO Scheduler also return revicer chammel that will receive +// (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] +// can receive them and hande them txs and sucj + + + + +// after we flagged that items in db +// next sends can't fo to queue, since that will break an order +// they need to go to db. + + +// Our loop + + + +/// Design: +/// Let it be a general service +/// Gets directly commits from Processor, then +/// +/// +/// 1. \ No newline at end of file diff --git a/magicblock-committor-service/src/commit_strategist/commit_strategy.rs b/magicblock-committor-service/src/commit_strategist/commit_strategy.rs new file mode 100644 index 000000000..28e64257e --- /dev/null +++ b/magicblock-committor-service/src/commit_strategist/commit_strategy.rs @@ -0,0 +1,633 @@ +use std::collections::HashSet; + +use magicblock_committor_program::{ChangedBundle, Changeset}; +use solana_pubkey::Pubkey; + +use crate::{ + error::{CommittorServiceError, CommittorServiceResult}, + transactions::{ + commit_tx_report, CommitTxReport, MAX_ENCODED_TRANSACTION_SIZE, + }, +}; + +/// These are the commit strategies we can use to commit a changeset in order +/// of preference. We use lookup tables only as last resort since they are +/// slow to prepare. +#[derive(Debug)] +pub enum CommitBundleStrategy { + ArgsIncludeFinalize(ChangedBundle), + Args(ChangedBundle), + FromBuffer(ChangedBundle), + ArgsIncludeFinalizeWithLookupTable(ChangedBundle), + ArgsWithLookupTable(ChangedBundle), + FromBufferWithLookupTable(ChangedBundle), +} + +impl TryFrom<(ChangedBundle, bool)> for CommitBundleStrategy { + type Error = CommittorServiceError; + + /// Try to find the fastest/efficient commit strategy for the given bundle. + /// Order of preference: + /// 1. [CommitBundleStrategy::ArgsIncludeFinalize] + /// 2. [CommitBundleStrategy::Args] + /// 3. [CommitBundleStrategy::FromBuffer] + /// 4. [CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable] + /// 5. [CommitBundleStrategy::ArgsWithLookupTable] + /// 6. [CommitBundleStrategy::FromBufferWithLookupTable] + fn try_from( + (bundle, finalize): (ChangedBundle, bool), + ) -> Result { + let CommitTxReport { + size_args_including_finalize, + size_args, + fits_buffer, + size_args_with_lookup_including_finalize, + size_args_with_lookup, + fits_buffer_using_lookup, + } = commit_tx_report(&bundle, finalize)?; + // Try to combine process and finalize if finalize is true + if let Some(size_including_finalize) = size_args_including_finalize { + if size_including_finalize < MAX_ENCODED_TRANSACTION_SIZE { + return Ok(CommitBundleStrategy::ArgsIncludeFinalize(bundle)); + } + } + // Next still using args but with separate finalize if needed + if size_args < MAX_ENCODED_TRANSACTION_SIZE { + return Ok(CommitBundleStrategy::Args(bundle)); + } + + // Last option to avoid lookup tables + if fits_buffer { + return Ok(CommitBundleStrategy::FromBuffer(bundle)); + } + + // All the below use lookup tables and will be a lot slower + + // Combining finalize and process + if let Some(size_with_lookup_including_finalize) = + size_args_with_lookup_including_finalize + { + if size_with_lookup_including_finalize + < MAX_ENCODED_TRANSACTION_SIZE + { + return Ok( + CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable( + bundle, + ), + ); + } + } + // Using lookup tables but separate finalize + if let Some(size_with_lookup) = size_args_with_lookup { + if size_with_lookup < MAX_ENCODED_TRANSACTION_SIZE { + return Ok(CommitBundleStrategy::ArgsWithLookupTable(bundle)); + } + } + + // Worst case try to use a buffer with lookup tables + if fits_buffer_using_lookup { + return Ok(CommitBundleStrategy::FromBufferWithLookupTable(bundle)); + } + + // If none of the strategies work then we need to error + let bundle_id = bundle + .first() + .map(|(_, acc)| acc.bundle_id()) + .unwrap_or_default(); + Err(CommittorServiceError::CouldNotFindCommitStrategyForBundle( + bundle_id, + )) + } +} + +#[derive(Debug)] +pub struct SplitChangesets { + /// This changeset can be committed in one processing step, passing account data as args + pub args_changeset: Changeset, + /// This changeset can be committed in one processing step, passing account data as args + /// and the finalize instruction fits into the same transaction + pub args_including_finalize_changeset: Changeset, + /// This changeset can be committed in one processing step, passing account data as args + /// but needs to use lookup tables for the accounts + pub args_with_lookup_changeset: Changeset, + /// This changeset can be committed in one processing step, passing account data as args + /// and the finalize instruction fits into the same transaction. + /// It needs to use lookup tables for the accounts. + pub args_including_finalize_with_lookup_changeset: Changeset, + /// This changeset needs to be committed in two steps: + /// 1. Prepare the buffer account + /// 2. Process the buffer account + pub from_buffer_changeset: Changeset, + /// This changeset needs to be committed in three steps: + /// 1. Prepare the buffer account + /// 2. Prepare lookup table + /// 3. Process the buffer account + pub from_buffer_with_lookup_changeset: Changeset, +} + +pub fn split_changesets_by_commit_strategy( + changeset: Changeset, + finalize: bool, +) -> CommittorServiceResult { + fn add_to_changeset( + changeset: &mut Changeset, + accounts_to_undelegate: &HashSet, + bundle: ChangedBundle, + ) { + for (pubkey, acc) in bundle { + changeset.add(pubkey, acc); + if accounts_to_undelegate.contains(&pubkey) { + changeset.accounts_to_undelegate.insert(pubkey); + } + } + } + + let mut args_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + let mut args_including_finalize_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + let mut args_with_lookup_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + let mut args_including_finalize_with_lookup_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + let mut from_buffer_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + let mut from_buffer_with_lookup_changeset = Changeset { + slot: changeset.slot, + ..Default::default() + }; + + let accounts_to_undelegate = changeset.accounts_to_undelegate.clone(); + let changeset_bundles = changeset.into_small_changeset_bundles(); + for bundle in changeset_bundles.bundles.into_iter() { + let commit_strategy = + CommitBundleStrategy::try_from((bundle, finalize))?; + match commit_strategy { + CommitBundleStrategy::Args(bundle) => { + add_to_changeset( + &mut args_changeset, + &accounts_to_undelegate, + bundle, + ); + } + CommitBundleStrategy::ArgsIncludeFinalize(bundle) => { + add_to_changeset( + &mut args_including_finalize_changeset, + &accounts_to_undelegate, + bundle, + ); + } + CommitBundleStrategy::ArgsWithLookupTable(bundle) => { + add_to_changeset( + &mut args_with_lookup_changeset, + &accounts_to_undelegate, + bundle, + ); + } + CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable( + bundle, + ) => { + add_to_changeset( + &mut args_including_finalize_with_lookup_changeset, + &accounts_to_undelegate, + bundle, + ); + } + CommitBundleStrategy::FromBuffer(bundle) => { + add_to_changeset( + &mut from_buffer_changeset, + &accounts_to_undelegate, + bundle, + ); + } + CommitBundleStrategy::FromBufferWithLookupTable(bundle) => { + add_to_changeset( + &mut from_buffer_with_lookup_changeset, + &accounts_to_undelegate, + bundle, + ); + } + } + } + + Ok(SplitChangesets { + args_changeset, + args_including_finalize_changeset, + args_with_lookup_changeset, + args_including_finalize_with_lookup_changeset, + from_buffer_changeset, + from_buffer_with_lookup_changeset, + }) +} + +#[cfg(test)] +mod test { + use log::*; + use magicblock_committor_program::ChangedAccount; + use solana_sdk::pubkey::Pubkey; + + use super::*; + + fn init_logger() { + let _ = env_logger::builder() + .format_timestamp(None) + .is_test(true) + .try_init(); + } + + fn add_changed_account( + changeset: &mut Changeset, + size: usize, + bundle_id: u64, + undelegate: bool, + ) -> Pubkey { + let pubkey = Pubkey::new_unique(); + changeset.add( + pubkey, + ChangedAccount::Full { + data: vec![1; size], + owner: Pubkey::new_unique(), + lamports: 0, + bundle_id, + }, + ); + if undelegate { + changeset.accounts_to_undelegate.insert(pubkey); + } + pubkey + } + + macro_rules! debug_counts { + ($label:expr, $changeset:ident, $split_changesets:ident) => { + debug!( + "{}: ({}) {{ +args_changeset: {} +args_including_finalize_changeset: {} +args_with_lookup_changeset: {} +args_including_finalize_with_lookup_changeset: {} +from_buffer_changeset: {} +from_buffer_with_lookup_changeset: {} +}}", + $label, + $changeset.accounts.len(), + $split_changesets.args_changeset.len(), + $split_changesets.args_including_finalize_changeset.len(), + $split_changesets.args_with_lookup_changeset.len(), + $split_changesets + .args_including_finalize_with_lookup_changeset + .len(), + $split_changesets.from_buffer_changeset.len(), + $split_changesets.from_buffer_with_lookup_changeset.len() + ); + }; + } + + macro_rules! assert_accounts_sum_matches { + ($changeset:ident, $split_changesets:ident) => { + assert_eq!( + $split_changesets.args_changeset.len() + + $split_changesets.args_including_finalize_changeset.len() + + $split_changesets.args_with_lookup_changeset.len() + + $split_changesets + .args_including_finalize_with_lookup_changeset + .len() + + $split_changesets.from_buffer_changeset.len() + + $split_changesets.from_buffer_with_lookup_changeset.len(), + $changeset.len() + ); + }; + } + + macro_rules! assert_undelegate_sum_matches { + ($changeset:ident, $split_changesets:ident) => { + assert_eq!( + $split_changesets + .args_changeset + .accounts_to_undelegate + .len() + + $split_changesets + .args_including_finalize_changeset + .accounts_to_undelegate + .len() + + $split_changesets + .args_with_lookup_changeset + .accounts_to_undelegate + .len() + + $split_changesets + .args_including_finalize_with_lookup_changeset + .accounts_to_undelegate + .len() + + $split_changesets + .from_buffer_changeset + .accounts_to_undelegate + .len() + + $split_changesets + .from_buffer_with_lookup_changeset + .accounts_to_undelegate + .len(), + $changeset.accounts_to_undelegate.len() + ); + }; + } + #[test] + fn test_split_small_changesets_by_commit_strategy() { + init_logger(); + + // Setup a changeset with different bundle/account sizes + let mut changeset = Changeset { + slot: 1, + ..Default::default() + }; + + let bundle_id = 1111; + + // 2 accounts bundle that can be handled via args + for idx in 1..=2 { + add_changed_account(&mut changeset, 10, bundle_id, idx % 2 == 0); + } + + // 8 accounts bundle that needs lookup + for idx in 1..=8 { + add_changed_account( + &mut changeset, + 10, + bundle_id * 10, + idx % 2 == 0, + ); + } + + // No Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), false) + .unwrap(); + debug_counts!("No Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_changeset.len(), 2,); + assert_eq!(split_changesets.args_with_lookup_changeset.len(), 8,); + + // Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), true) + .unwrap(); + + debug_counts!("Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_including_finalize_changeset.len(), 2,); + assert_eq!( + split_changesets + .args_including_finalize_with_lookup_changeset + .len(), + 8, + ); + } + + #[test] + fn test_split_medium_changesets_by_commit_strategy() { + init_logger(); + + // Setup a changeset with different bundle/account sizes + let mut changeset = Changeset { + slot: 1, + ..Default::default() + }; + let bundle_id = 2222; + + // 2 accounts bundle that can be handled via args and include the finalize instructions + for idx in 1..=2 { + add_changed_account(&mut changeset, 80, bundle_id, idx % 2 == 0); + } + + // 2 accounts bundle that can be handled via args, but cannot include finalize due + // to the size of the data + for idx in 1..=2 { + add_changed_account( + &mut changeset, + 100, + bundle_id + 1, + idx % 2 == 0, + ); + } + + // 3 accounts bundle that needs lookup buffer due to overall args size + for idx in 1..=3 { + add_changed_account( + &mut changeset, + 100, + bundle_id + 3, + idx % 2 == 0, + ); + } + + // No Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), false) + .unwrap(); + debug_counts!("No Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_changeset.len(), 4,); + assert_eq!(split_changesets.from_buffer_changeset.len(), 3,); + + // Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), true) + .unwrap(); + debug_counts!("Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_changeset.len(), 2,); + assert_eq!(split_changesets.args_including_finalize_changeset.len(), 2,); + assert_eq!(split_changesets.from_buffer_changeset.len(), 3,); + } + + #[test] + fn test_split_large_changesets_by_commit_strategy() { + init_logger(); + + // Setup a changeset with different bundle/account sizes + let mut changeset = Changeset { + slot: 1, + ..Default::default() + }; + + let bundle_id = 3333; + + // 5 accounts bundle that needs to be handled via lookup (buffer) + for idx in 1..=5 { + add_changed_account(&mut changeset, 400, bundle_id, idx % 2 == 0); + } + + // 2 accounts bundle that can be handled without lookup (buffer) + for idx in 1..=2 { + add_changed_account( + &mut changeset, + 600, + bundle_id * 10, + idx % 2 == 0, + ); + } + + // No Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), false) + .unwrap(); + debug_counts!("No Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.from_buffer_changeset.len(), 2,); + assert_eq!(split_changesets.from_buffer_with_lookup_changeset.len(), 5,); + + // Finalize + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), true) + .unwrap(); + debug_counts!("Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.from_buffer_changeset.len(), 2,); + assert_eq!(split_changesets.from_buffer_with_lookup_changeset.len(), 5,); + } + + #[test] + fn test_split_different_size_changesets_by_commit_strategy() { + // Combining the different changeset sizes we already test above into one changeset to + // split + init_logger(); + + // Setup a changeset with different bundle/account sizes + let mut changeset = Changeset { + slot: 1, + ..Default::default() + }; + + // Small sized bundles + { + let bundle_id = 1111; + + // 2 accounts bundle that can be handled via args + for idx in 1..=2 { + add_changed_account( + &mut changeset, + 10, + bundle_id, + idx % 2 == 0, + ); + } + + // 8 accounts bundle that needs lookup + for idx in 1..=8 { + add_changed_account( + &mut changeset, + 10, + bundle_id * 10, + idx % 2 == 0, + ); + } + }; + + // Medium sized bundles + { + let bundle_id = 2222; + + // 2 accounts bundle that can be handled via args + for idx in 1..=2 { + add_changed_account( + &mut changeset, + 100, + bundle_id, + idx % 2 == 0, + ); + } + }; + + // Large sized bundles + { + let bundle_id = 3333; + + // 5 accounts bundle that needs to be handled via lookup (buffer) + for idx in 1..=5 { + add_changed_account( + &mut changeset, + 400, + bundle_id, + idx % 2 == 0, + ); + } + + // 2 accounts bundle that can be handled without lookup (buffer) + for idx in 1..=2 { + add_changed_account( + &mut changeset, + 600, + bundle_id * 10, + idx % 2 == 0, + ); + } + }; + + // No Finalize + { + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), false) + .unwrap(); + + debug_counts!("No Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_changeset.len(), 4); + assert_eq!(split_changesets.args_with_lookup_changeset.len(), 8); + assert_eq!(split_changesets.from_buffer_changeset.len(), 2); + assert_eq!( + split_changesets.from_buffer_with_lookup_changeset.len(), + 5 + ); + } + + // Finalize + { + let split_changesets = + split_changesets_by_commit_strategy(changeset.clone(), true) + .unwrap(); + + debug_counts!("Finalize", changeset, split_changesets); + assert_accounts_sum_matches!(changeset, split_changesets); + assert_undelegate_sum_matches!(changeset, split_changesets); + + assert_eq!(split_changesets.args_changeset.len(), 2); + assert_eq!( + split_changesets.args_including_finalize_changeset.len(), + 2 + ); + assert_eq!( + split_changesets + .args_including_finalize_with_lookup_changeset + .len(), + 8 + ); + assert_eq!(split_changesets.from_buffer_changeset.len(), 2); + assert_eq!( + split_changesets.from_buffer_with_lookup_changeset.len(), + 5 + ); + } + } +} diff --git a/magicblock-committor-service/src/commit_strategist/mod.rs b/magicblock-committor-service/src/commit_strategist/mod.rs new file mode 100644 index 000000000..ac2be56e5 --- /dev/null +++ b/magicblock-committor-service/src/commit_strategist/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod commit_strategy; +pub(crate) mod report_builder; \ No newline at end of file diff --git a/magicblock-committor-service/src/commit_strategist/report_builder.rs b/magicblock-committor-service/src/commit_strategist/report_builder.rs new file mode 100644 index 000000000..e22f70759 --- /dev/null +++ b/magicblock-committor-service/src/commit_strategist/report_builder.rs @@ -0,0 +1,10 @@ +pub(crate) struct L1MessageReport { + /// Size of the transaction without lookup tables. + size_args: usize, + + /// +} + +pub(crate) struct L1MessageReportBuilder { + +} diff --git a/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs b/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs new file mode 100644 index 000000000..5c0ccdd9d --- /dev/null +++ b/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs @@ -0,0 +1,52 @@ +use solana_sdk::instruction::Instruction; +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; +use crate::compute_budget::Budget; +use crate::ComputeBudgetConfig; + +// TODO(edwin): rename +struct ComputeBudgetV1 { + /// Total compute budget + pub compute_budget: u32, + pub compute_unit_price: u64 +} + +pub trait ComputeBudgetCalculator { + fn instruction(budget: ComputeBudgetV1) -> Instruction; + + /// Calculate budget for commit transaction + fn calculate_commit_budget(&self, l1_message: &ScheduledL1Message) -> ComputeBudgetV1; + /// Calculate budget for finalze transaction + fn calculate_finalize_budget(&self, l1_message: &ScheduledL1Message) -> ComputeBudgetV1; +} + +/// V1 implementation, works with TransactionPreparator V1 +/// Calculations for finalize may include cases for +pub struct ComputeBudgetCalculatorV1 { + compute_budget_config: ComputeBudgetConfig +} + +impl ComputeBudgetCalculatorV1 { + pub fn new(config: ComputeBudgetConfig) -> Self { + Self { + compute_budget_config: config + } + } +} + +impl ComputeBudgetCalculator for ComputeBudgetCalculatorV1 { + /// Calculate compute budget for V1 commit transaction + /// This includes only compute for account commits + fn calculate_commit_budget(&self, l1_message: &ScheduledL1Message) -> ComputeBudgetV1 { + todo!() + } + + fn calculate_finalize_budget(&self, l1_message: &ScheduledL1Message) -> ComputeBudgetV1 { + todo!() + } + + fn instruction(budget: ComputeBudgetV1) -> Instruction { + + } +} + +/// \ No newline at end of file diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preperator/error.rs new file mode 100644 index 000000000..c764c1ff5 --- /dev/null +++ b/magicblock-committor-service/src/transaction_preperator/error.rs @@ -0,0 +1,14 @@ +use thiserror::Error; +use crate::transaction_preperator::transaction_preparator::PreparatorVersion; + +#[derive(Error, Debug)] +pub enum Error { + #[error("Invalid action for version: {0}")] + VersionError(PreparatorVersion), + #[error("Failed to fit in single TX")] + FailedToFitError, + #[error("InternalError: {0}")] + InternalError(#[from] anyhow::Error), +} + +pub type PreparatorResult = Result; \ No newline at end of file diff --git a/magicblock-committor-service/src/transaction_preperator/mod.rs b/magicblock-committor-service/src/transaction_preperator/mod.rs new file mode 100644 index 000000000..2f9f9f716 --- /dev/null +++ b/magicblock-committor-service/src/transaction_preperator/mod.rs @@ -0,0 +1,4 @@ +mod transaction_preparator; +mod error; +mod budget_calculator; + diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs new file mode 100644 index 000000000..e69de29bb diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs new file mode 100644 index 000000000..1ad671fea --- /dev/null +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -0,0 +1,69 @@ +use async_trait::async_trait; +use solana_rpc_client::rpc_client::RpcClient; +use solana_sdk::message::v0::Message; +use solana_sdk::transaction::Transaction; +use magicblock_program::magic_scheduled_l1_message::{ + ScheduledL1Message, MagicL1Message +}; +use magicblock_rpc_client::MagicblockRpcClient; +use magicblock_table_mania::TableMania; +use crate::transaction_preperator::budget_calculator::{ComputeBudgetCalculator, ComputeBudgetCalculatorV1}; +use crate::transaction_preperator::error::{Error, PreparatorResult}; + +/// Transaction Preparator version +/// Some actions maybe imnvalid per version +#[derive(Debug)] +pub enum PreparatorVersion { + V1, +} + + +#[async_trait] +trait TransactionPreparator { + type BudgetCalculator: ComputeBudgetCalculator; + + fn version(&self) -> PreparatorVersion; + async fn prepare_commit_tx(&self, l1_message: &ScheduledL1Message) -> PreparatorResult; + async fn prepare_finalize_tx(&self, l1_message: &ScheduledL1Message) -> PreparatorResult; + +} + +/// [`TransactionPreparatorV1`] first version of preparator +/// It omits future commit_bundle/finalize_bundle logic +/// It creates TXs using current per account commit/finalize +struct TransactionPreparatorV1 { + rpc_client: MagicblockRpcClient, + table_mania: TableMania // TODO(edwin): Arc? +} + +impl TransactionPreparatorV1 { + pub fn new(rpc_client: MagicblockRpcClient, table_mania: TableMania) -> Self { + Self { + rpc_client, + table_mania + } + } +} + +impl TransactionPreparator for TransactionPreparatorV1 { + type BudgetCalculator = ComputeBudgetCalculatorV1; + + fn version(&self) -> PreparatorVersion { + PreparatorVersion::V1 + } + + /// In V1: prepares TX with commits for every account in message + /// For pure actions message - outputs Tx that runs actions + async fn prepare_commit_tx(&self, l1_message: &ScheduledL1Message) -> PreparatorResult { + todo!() + } + + /// In V1: prepares single TX with finalize, undelegation + actions + async fn prepare_finalize_tx(&self, l1_message: &ScheduledL1Message) -> PreparatorResult { + if matches!(l1_message.l1_message, MagicL1Message::L1Actions(_)) { + Err(Error::VersionError(PreparatorVersion::V1)) + } else { + Ok(()) + } + } +} \ No newline at end of file diff --git a/magicblock-committor-service/src/transaction_preperator/utils.rs b/magicblock-committor-service/src/transaction_preperator/utils.rs new file mode 100644 index 000000000..e69de29bb diff --git a/programs/magicblock/src/magic_scheduled_l1_message.rs b/programs/magicblock/src/magic_scheduled_l1_message.rs new file mode 100644 index 000000000..f7c53de14 --- /dev/null +++ b/programs/magicblock/src/magic_scheduled_l1_message.rs @@ -0,0 +1,401 @@ +use std::{cell::RefCell, collections::HashSet}; + +use serde::{Deserialize, Serialize}; +use solana_log_collector::ic_msg; +use solana_program_runtime::{ + __private::{Hash, InstructionError, ReadableAccount, TransactionContext}, + invoke_context::InvokeContext, +}; +use solana_sdk::{ + account::{Account, AccountSharedData}, + clock::Slot, + transaction::Transaction, +}; + +use crate::{ + args::{ + ActionArgs, CommitAndUndelegateArgs, CommitTypeArgs, L1ActionArgs, + MagicL1MessageArgs, UndelegateTypeArgs, + }, + instruction_utils::InstructionUtils, + utils::accounts::{ + get_instruction_account_short_meta_with_idx, + get_instruction_account_with_idx, get_instruction_pubkey_with_idx, + }, + Pubkey, +}; + +/// Context necessary for construction of Schedule Action +pub struct ConstructionContext<'a, 'ic> { + parent_program_id: Option, + signers: &'a HashSet, + pub transaction_context: &'a TransactionContext, + pub invoke_context: &'a mut InvokeContext<'ic>, +} + +impl<'a, 'ic> ConstructionContext<'a, 'ic> { + pub fn new( + parent_program_id: Option, + signers: &'a HashSet, + transaction_context: &'a TransactionContext, + invoke_context: &'a mut InvokeContext<'ic>, + ) -> Self { + Self { + parent_program_id, + signers, + transaction_context, + invoke_context, + } + } +} + +/// Scheduled action to be executed on base layer +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct ScheduledL1Message { + pub id: u64, + pub slot: Slot, + pub blockhash: Hash, + pub action_sent_transaction: Transaction, + pub payer: Pubkey, + // Scheduled action + pub l1_message: MagicL1Message, +} + +impl ScheduledL1Message { + pub fn try_new<'a>( + args: &MagicL1MessageArgs, + commit_id: u64, + slot: Slot, + payer_pubkey: &Pubkey, + context: &ConstructionContext<'a, '_>, + ) -> Result { + let action = MagicL1Message::try_from_args(args, &context)?; + + let blockhash = context.invoke_context.environment_config.blockhash; + let action_sent_transaction = + InstructionUtils::scheduled_commit_sent(commit_id, blockhash); + Ok(ScheduledL1Message { + id: commit_id, + slot, + blockhash, + payer: *payer_pubkey, + action_sent_transaction, + l1_message: action, + }) + } +} + +// L1Message user wants to send to base layer +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub enum MagicL1Message { + /// Actions without commitment or undelegation + L1Actions(Vec), + Commit(CommitType), + CommitAndUndelegate(CommitAndUndelegate), +} + +impl MagicL1Message { + pub fn try_from_args<'a>( + args: &MagicL1MessageArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + match args { + MagicL1MessageArgs::L1Actions(l1_actions) => { + let l1_actions = l1_actions + .iter() + .map(|args| L1Action::try_from_args(args, context)) + .collect::, InstructionError>>()?; + Ok(MagicL1Message::L1Actions(l1_actions)) + } + MagicL1MessageArgs::Commit(type_) => { + let commit = CommitType::try_from_args(type_, context)?; + Ok(MagicL1Message::Commit(commit)) + } + MagicL1MessageArgs::CommitAndUndelegate(type_) => { + let commit_and_undelegate = + CommitAndUndelegate::try_from_args(type_, context)?; + Ok(MagicL1Message::CommitAndUndelegate(commit_and_undelegate)) + } + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct CommitAndUndelegate { + pub commit_action: CommitType, + pub undelegate_action: UndelegateType, +} + +impl CommitAndUndelegate { + pub fn try_from_args<'a>( + args: &CommitAndUndelegateArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + let commit_action = + CommitType::try_from_args(&args.commit_type, context)?; + let undelegate_action = + UndelegateType::try_from_args(&args.undelegate_type, context)?; + + Ok(Self { + commit_action, + undelegate_action, + }) + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct ProgramArgs { + pub escrow_index: u8, + pub data: Vec, +} + +impl From for ProgramArgs { + fn from(value: ActionArgs) -> Self { + Self { + escrow_index: value.escrow_index, + data: value.data, + } + } +} + +impl From<&ActionArgs> for ProgramArgs { + fn from(value: &ActionArgs) -> Self { + value.clone().into() + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct ShortAccountMeta { + pub pubkey: Pubkey, + pub is_writable: bool, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct L1Action { + pub destination_program: Pubkey, + pub data_per_program: ProgramArgs, + pub account_metas_per_program: Vec, +} + +impl L1Action { + pub fn try_from_args<'a>( + args: &L1ActionArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + let destination_program_pubkey = *get_instruction_pubkey_with_idx( + context.transaction_context, + args.destination_program as u16, + )?; + let destination_program = get_instruction_account_with_idx( + context.transaction_context, + args.destination_program as u16, + )?; + + if !destination_program.borrow().executable() { + ic_msg!( + context.invoke_context, + &format!( + "L1Action: destination_program must be an executable. got: {}", + destination_program_pubkey + ) + ); + return Err(InstructionError::AccountNotExecutable); + } + + let account_metas = args + .accounts + .iter() + .map(|i| { + get_instruction_account_short_meta_with_idx( + context.transaction_context, + *i as u16, + ) + }) + .collect::, InstructionError>>()?; + + Ok(L1Action { + destination_program: destination_program_pubkey, + data_per_program: args.args.clone().into(), + account_metas_per_program: account_metas, + }) + } +} + +type CommittedAccountRef<'a> = (Pubkey, &'a RefCell); +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct CommittedAccountV2 { + pub pubkey: Pubkey, + pub account: Account, +} + +impl<'a> From> for CommittedAccountV2 { + fn from(value: CommittedAccountRef<'a>) -> Self { + Self { + pubkey: value.0, + account: value.1.borrow().to_owned().into(), + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub enum CommitType { + /// Regular commit without actions + /// TODO: feels like ShortMeta isn't needed + Standalone(Vec), // accounts to commit + /// Commits accounts and runs actions + WithL1Actions { + committed_accounts: Vec, + l1_actions: Vec, + }, +} + +impl CommitType { + // TODO: move to processor + fn validate_accounts<'a>( + accounts: &[CommittedAccountRef], + context: &ConstructionContext<'a, '_>, + ) -> Result<(), InstructionError> { + accounts.iter().try_for_each(|(pubkey, account)| { + let owner = *account.borrow().owner(); + if context.parent_program_id != Some(owner) && !context.signers.contains(pubkey) { + match context.parent_program_id { + None => { + ic_msg!( + context.invoke_context, + "ScheduleCommit ERR: failed to find parent program id" + ); + Err(InstructionError::InvalidInstructionData) + } + Some(parent_id) => { + ic_msg!( + context.invoke_context, + "ScheduleCommit ERR: account {} must be owned by {} or be a signer, but is owned by {}", + pubkey, parent_id, owner + ); + Err(InstructionError::InvalidAccountOwner) + } + } + } else { + Ok(()) + } + }) + } + + // I delegated an account, now the owner is delegation program + // parent_program_id != Some(&acc_owner) should fail. or any modification on ER + // ER perceives owner as old one, hence for ER those are valid txs + // On commit_and_undelegate and commit we will set owner to DLP, for latter temparerily + // The owner shall be real owner on chain + // So first: + // 1. Validate + // 2. Fetch current account states + // TODO: 3. switch the ownership + pub fn extract_commit_accounts<'a>( + account_indices: &[u8], + transaction_context: &'a TransactionContext, + ) -> Result>, InstructionError> { + account_indices + .iter() + .map(|i| { + let account = get_instruction_account_with_idx( + transaction_context, + *i as u16, + )?; + let pubkey = *get_instruction_pubkey_with_idx( + transaction_context, + *i as u16, + )?; + + Ok((pubkey, account)) + }) + .collect::>() + } + + pub fn try_from_args<'a>( + args: &CommitTypeArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + match args { + CommitTypeArgs::Standalone(accounts) => { + let committed_accounts_ref = Self::extract_commit_accounts( + accounts, + context.transaction_context, + )?; + Self::validate_accounts(&committed_accounts_ref, context)?; + let committed_accounts = committed_accounts_ref + .into_iter() + .map(|el| { + let mut committed_account: CommittedAccountV2 = + el.into(); + committed_account.account.owner = context + .parent_program_id + .unwrap_or(committed_account.account.owner); + + committed_account + }) + .collect(); + + Ok(CommitType::Standalone(committed_accounts)) + } + CommitTypeArgs::WithL1Actions { + committed_accounts, + l1_actions, + } => { + let committed_accounts_ref = Self::extract_commit_accounts( + committed_accounts, + context.transaction_context, + )?; + Self::validate_accounts(&committed_accounts_ref, context)?; + + let l1_actions = l1_actions + .iter() + .map(|args| L1Action::try_from_args(args, context)) + .collect::, InstructionError>>()?; + let committed_accounts = committed_accounts_ref + .into_iter() + .map(|el| { + let mut committed_account: CommittedAccountV2 = + el.into(); + committed_account.account.owner = context + .parent_program_id + .unwrap_or(committed_account.account.owner); + + committed_account + }) + .collect(); + + Ok(CommitType::WithL1Actions { + committed_accounts, + l1_actions, + }) + } + } + } +} + +/// No CommitedAccounts since it is only used with CommitAction. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub enum UndelegateType { + Standalone, + WithL1Actions(Vec), +} + +impl UndelegateType { + pub fn try_from_args<'a>( + args: &UndelegateTypeArgs, + context: &ConstructionContext<'a, '_>, + ) -> Result { + match args { + UndelegateTypeArgs::Standalone => Ok(UndelegateType::Standalone), + UndelegateTypeArgs::WithL1Actions { l1_actions } => { + let l1_actions = l1_actions + .iter() + .map(|l1_actions| { + L1Action::try_from_args(l1_actions, context) + }) + .collect::, InstructionError>>()?; + Ok(UndelegateType::WithL1Actions(l1_actions)) + } + } + } +} From 4011e3d2013ff6eefb2d04ec1175a6eeab910f28 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 3 Jul 2025 18:28:19 +0800 Subject: [PATCH 078/199] fix: tests --- magicblock-committor-program/tests/prog_init_write_and_close.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/magicblock-committor-program/tests/prog_init_write_and_close.rs b/magicblock-committor-program/tests/prog_init_write_and_close.rs index 3fd6063b0..90bbe6720 100644 --- a/magicblock-committor-program/tests/prog_init_write_and_close.rs +++ b/magicblock-committor-program/tests/prog_init_write_and_close.rs @@ -177,7 +177,7 @@ async fn init_write_and_close(changeset: Changeset) { let program_id = &magicblock_committor_program::id(); let (banks_client, auth, _) = ProgramTest::new( - "committor_program", + "magicblock_committor_program", *program_id, processor!(magicblock_committor_program::process), ) From 49b99c41b054481ac0ec36e6104802daffc3d5f0 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 7 Jul 2025 17:40:02 +0900 Subject: [PATCH 079/199] feat: introducing raw tasks, DeliveryStrategist, TransactionPreparator(RAW) --- Cargo.lock | 25 +- Cargo.toml | 2 +- .../src/external_accounts_manager.rs | 54 +- .../src/remote_scheduled_commits_processor.rs | 141 +--- magicblock-committor-program/src/error.rs | 3 +- .../tests/prog_init_write_and_close.rs | 3 +- magicblock-committor-service/Cargo.toml | 13 +- .../src/commit/commit_scheduler.rs | 76 ++- .../src/commit/commit_using_buffer.rs | 12 +- .../src/commit/committor_processor.rs | 12 +- .../src/commit/mod.rs | 2 + .../src/commit_strategist/mod.rs | 2 +- .../src/commit_strategist/report_builder.rs | 6 +- .../src/commit_strategy.rs | 633 ------------------ magicblock-committor-service/src/lib.rs | 4 +- magicblock-committor-service/src/service.rs | 15 +- .../budget_calculator.rs | 65 +- .../delivery_preparator.rs | 67 ++ .../delivery_strategist.rs | 195 ++++++ .../src/transaction_preperator/error.rs | 3 +- .../src/transaction_preperator/mod.rs | 9 +- .../transaction_preperator/task_builder.rs | 236 +++++++ .../transaction_preparator.rs | 112 +++- .../src/transaction_preperator/utils.rs | 20 + .../src/transactions.rs | 8 +- magicblock-rpc/src/traits/rpc_full.rs | 15 + magicblock-table-mania/src/manager.rs | 111 ++- programs/magicblock/src/args.rs | 3 +- programs/magicblock/src/lib.rs | 3 +- programs/magicblock/src/magic_context.rs | 2 +- .../src/magic_schedule_l1_message.rs | 401 ----------- .../src/magic_scheduled_l1_message.rs | 34 +- .../src/schedule_transactions/mod.rs | 1 + .../process_accept_scheduled_commits.rs | 3 +- .../process_schedule_commit.rs | 3 +- .../process_schedule_commit_tests.rs | 4 +- .../process_schedule_l1_message.rs | 2 +- .../schedule_l1_message_processor.rs | 2 +- .../transaction_scheduler.rs | 21 +- programs/magicblock/src/utils/accounts.rs | 2 +- test-integration/Cargo.lock | 29 +- test-integration/Cargo.toml | 2 +- 42 files changed, 956 insertions(+), 1400 deletions(-) delete mode 100644 magicblock-committor-service/src/commit_strategy.rs create mode 100644 magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs create mode 100644 magicblock-committor-service/src/transaction_preperator/delivery_strategist.rs delete mode 100644 programs/magicblock/src/magic_schedule_l1_message.rs diff --git a/Cargo.lock b/Cargo.lock index bf4180509..511636576 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1185,7 +1185,7 @@ dependencies = [ "conjunto-addresses", "conjunto-core", "conjunto-providers", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", "serde", "solana-rpc-client", "solana-rpc-client-api", @@ -3653,7 +3653,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3802,14 +3802,18 @@ dependencies = [ name = "magicblock-committor-service" version = "0.1.2" dependencies = [ + "anyhow", + "async-trait", "base64 0.21.7", "bincode", "borsh 1.5.5", "env_logger 0.11.6", + "futures-util", "lazy_static", "log", "magicblock-committor-program", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0", + "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", "rusqlite", @@ -3848,6 +3852,21 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "magicblock-delegation-program" +version = "1.0.0" +dependencies = [ + "bincode", + "borsh 1.5.5", + "bytemuck", + "num_enum", + "paste", + "solana-curve25519", + "solana-program", + "solana-security-txt", + "thiserror 1.0.69", +] + [[package]] name = "magicblock-delegation-program" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index e0ac42345..e63aba115 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,7 @@ magicblock-committor-program = { path = "./magicblock-committor-program", featur magicblock-committor-service = { path = "./magicblock-committor-service" } magicblock-config = { path = "./magicblock-config" } magicblock-core = { path = "./magicblock-core" } -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } +magicblock-delegation-program = { path = "../delegation-program" } magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" } magicblock-ledger = { path = "./magicblock-ledger" } magicblock-metrics = { path = "./magicblock-metrics" } diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 6b09bf8c8..65cfb7125 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -310,32 +310,38 @@ where slot: u64, undelegation_request: bool, ) -> AccountsResult> { - // Get current account states from internal account provider - let mut committees = Vec::new(); - for (pubkey, owner, committable_account_prev_hash) in - &accounts_to_be_committed - { - let account_state = - self.internal_account_provider.get_account(pubkey); - if let Some(acc) = account_state { + let mut committees = accounts_to_be_committed + .iter() + .filter_map(|(pubkey, owner, committable_account_prev_hash)| { + if let Some(account) = self.internal_account_provider.get_account(pubkey) { + Some((pubkey, owner, committable_account_prev_hash, account)) + } else { + error!( + "Cannot find state for account that needs to be committed '{}' ", + pubkey + ); + None + } + }) + .filter(|(pubkey, _, committable_account_prev_hash, acc)| { let should_commit = committable_account_prev_hash - .map_or(true, |hash| hash_account(&acc).ne(&hash)); - if should_commit { - committees.push(AccountCommittee { - pubkey: *pubkey, - owner: *owner, - account_data: acc, - slot, - undelegation_requested: undelegation_request, - }); + .map_or(true, |hash| hash_account(acc).ne(&hash)); + if !should_commit { + info!( + "Cannot find state for account that needs to be committed '{}'", + pubkey + ); } - } else { - error!( - "Cannot find state for account that needs to be committed '{}' ", - pubkey - ); - } - } + should_commit + }) + .map(|(pubkey, owner, _, acc)| AccountCommittee { + pubkey: *pubkey, + owner: *owner, + account_data: acc, + slot, + undelegation_requested: undelegation_request, + }) + .collect(); // NOTE: Once we run into issues that the data to be committed in a single // transaction is too large, we can split these into multiple batches diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 975be02ee..1fcd7128a 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -17,6 +17,7 @@ use magicblock_committor_service::{ }; use magicblock_processor::execute_transaction::execute_legacy_transaction; use magicblock_program::{ + magic_scheduled_l1_message::ScheduledL1Message, register_scheduled_commit_sent, FeePayerAccount, Pubkey, ScheduledCommit, SentCommit, TransactionScheduler, }; @@ -47,147 +48,14 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { IAP: InternalAccountProvider, CC: ChangesetCommittor, { - let scheduled_actions = + let scheduled_l1_messages = self.transaction_scheduler.take_scheduled_actions(); - // TODO(edwin): remove once actions are supported - let scheduled_commits: Vec = scheduled_actions - .into_iter() - .filter_map(|action| { - action - .try_into() - .inspect_err(|err| error!("Unexpected action: {:?}", err)) - .ok() - }) - .collect(); - - if scheduled_commits.is_empty() { + if scheduled_l1_messages.is_empty() { return Ok(()); } - let mut changeset = Changeset::default(); - // SAFETY: we only get here if the scheduled commits are not empty - let max_slot = scheduled_commits - .iter() - .map(|commit| commit.slot) - .max() - .unwrap(); - // Safety we just obtained the max slot from the scheduled commits - let ephemeral_blockhash = scheduled_commits - .iter() - .find(|commit| commit.slot == max_slot) - .map(|commit| commit.blockhash) - .unwrap(); - - changeset.slot = max_slot; - - let mut sent_commits = HashMap::new(); - for commit in scheduled_commits { - // Determine which accounts are available and can be committed - let mut committees = vec![]; - let mut feepayers = HashSet::new(); - let mut excluded_pubkeys = vec![]; - for committed_account in commit.accounts { - let mut committee_pubkey = committed_account.pubkey; - let mut committee_owner = committed_account.owner; - if let Some(Cloned { - account_chain_snapshot, - .. - }) = Self::fetch_cloned_account( - &committed_account.pubkey, - &self.cloned_accounts, - ) { - // If the account is a FeePayer, we commit the mapped delegated account - if account_chain_snapshot.chain_state.is_feepayer() { - committee_pubkey = - AccountChainSnapshot::ephemeral_balance_pda( - &committed_account.pubkey, - ); - committee_owner = - AccountChainSnapshot::ephemeral_balance_pda_owner(); - feepayers.insert(FeePayerAccount { - pubkey: committed_account.pubkey, - delegated_pda: committee_pubkey, - }); - } else if account_chain_snapshot - .chain_state - .is_undelegated() - { - error!("Scheduled commit account '{}' is undelegated. This is not supported.", committed_account.pubkey); - excluded_pubkeys.push(committed_account.pubkey); - continue; - } - } - - match account_provider.get_account(&committed_account.pubkey) { - Some(account_data) => { - committees.push(( - commit.id, - AccountCommittee { - pubkey: committee_pubkey, - owner: committee_owner, - account_data, - slot: commit.slot, - undelegation_requested: commit - .request_undelegation, - }, - )); - } - None => { - error!( - "Scheduled commmit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", - committed_account.pubkey - ); - excluded_pubkeys.push(committed_account.pubkey); - continue; - } - } - } - - // Collect all SentCommit info available at this stage - // We add the chain_signatures after we sent off the changeset - let sent_commit = SentCommit { - chain_signatures: vec![], - commit_id: commit.id, - slot: commit.slot, - payer: commit.payer, - blockhash: commit.blockhash, - included_pubkeys: committees - .iter() - .map(|(_, committee)| committee.pubkey) - .collect(), - excluded_pubkeys, - feepayers, - requested_undelegation: commit.request_undelegation, - }; - sent_commits.insert( - commit.id, - (commit.commit_sent_transaction, sent_commit), - ); - - // Add the committee to the changeset - for (bundle_id, committee) in committees { - changeset.add( - committee.pubkey, - ChangedAccount::Full { - lamports: committee.account_data.lamports(), - data: committee.account_data.data().to_vec(), - owner: committee.owner, - bundle_id, - }, - ); - if committee.undelegation_requested { - changeset.request_undelegation(committee.pubkey); - } - } - } - - self.process_changeset( - changeset_committor, - changeset, - sent_commits, - ephemeral_blockhash, - ); + self.process_changeset(changeset_committor, changeset, sent_commits); Ok(()) } @@ -214,6 +82,7 @@ impl RemoteScheduledCommitsProcessor { transaction_scheduler: TransactionScheduler::default(), } } + fn fetch_cloned_account( pubkey: &Pubkey, cloned_accounts: &CloneOutputMap, diff --git a/magicblock-committor-program/src/error.rs b/magicblock-committor-program/src/error.rs index 40e091cf4..c3fa62b39 100644 --- a/magicblock-committor-program/src/error.rs +++ b/magicblock-committor-program/src/error.rs @@ -1,7 +1,8 @@ -use crate::state::chunks::ChunksError; use solana_program::{msg, program_error::ProgramError}; use thiserror::Error; +use crate::state::chunks::ChunksError; + pub type CommittorResult = std::result::Result; #[derive(Error, Debug, Clone)] diff --git a/magicblock-committor-program/tests/prog_init_write_and_close.rs b/magicblock-committor-program/tests/prog_init_write_and_close.rs index 90bbe6720..4f9537105 100644 --- a/magicblock-committor-program/tests/prog_init_write_and_close.rs +++ b/magicblock-committor-program/tests/prog_init_write_and_close.rs @@ -12,9 +12,8 @@ use magicblock_committor_program::{ use solana_program::instruction::Instruction; use solana_program_test::*; use solana_pubkey::Pubkey; -use solana_sdk::signature::Keypair; use solana_sdk::{ - blake3::HASH_BYTES, hash::Hash, native_token::LAMPORTS_PER_SOL, + hash::Hash, native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, transaction::Transaction, }; diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index 34174a8f8..01dec23b8 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -11,18 +11,23 @@ edition.workspace = true doctest = false [dependencies] -base64 = { workspace = true } -bincode = { workspace = true } -borsh = { workspace = true } -log = { workspace = true } magicblock-committor-program = { workspace = true, features = [ "no-entrypoint", ] } magicblock-delegation-program = { workspace = true, features = [ "no-entrypoint", ] } +magicblock-program = { workspace = true } magicblock-rpc-client = { workspace = true } magicblock-table-mania = { workspace = true } + +async-trait = { workspace = true } +anyhow = { workspace = true } +base64 = { workspace = true } +bincode = { workspace = true } +borsh = { workspace = true } +futures-util = { workspace = true } +log = { workspace = true } rusqlite = { workspace = true } solana-account = { workspace = true } solana-pubkey = { workspace = true } diff --git a/magicblock-committor-service/src/commit/commit_scheduler.rs b/magicblock-committor-service/src/commit/commit_scheduler.rs index b4754b332..0fe6f1e04 100644 --- a/magicblock-committor-service/src/commit/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit/commit_scheduler.rs @@ -1,11 +1,20 @@ -use std::collections::VecDeque; -use std::sync::Arc; -use std::sync::atomic::{AtomicBool, Ordering}; -use tokio::sync::mpsc::error::{TryRecvError, TrySendError}; -use tokio::select; -use tokio::sync::mpsc::{channel, Receiver, Sender}; -use tokio::sync::mpsc::error::SendError; +use std::{ + collections::VecDeque, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, +}; + use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; +use tokio::{ + select, + sync::mpsc::{ + channel, + error::{SendError, TryRecvError, TrySendError}, + Receiver, Sender, + }, +}; pub struct CommitScheduler { queue: VecDeque, @@ -20,21 +29,27 @@ impl CommitScheduler { Self { queue: VecDeque::default(), - sender + sender, } } - async fn start(mut l1_message_receiver: Receiver, db_flag: Arc) { + async fn start( + mut l1_message_receiver: Receiver, + db_flag: Arc, + ) { // scheduler // accepts messages // if no commits we shall be idle loop { let message = match l1_message_receiver.try_recv() { - Ok(val) => { - val - } + Ok(val) => val, Err(TryRecvError::Empty) => { - if let Ok(val) = Self::get_next_message(&mut l1_message_receiver, &db_flag).await { + if let Ok(val) = Self::get_next_message( + &mut l1_message_receiver, + &db_flag, + ) + .await + { val } else { // TODO(edwin): handle @@ -44,19 +59,20 @@ impl CommitScheduler { Err(TryRecvError::Disconnected) => { // TODO(edwin): handle panic!("Asdasd") - }, + } }; // send and shit todo!() } - while let Some(l1_messages) = l1_message_receiver.recv().await { - - } + while let Some(l1_messages) = l1_message_receiver.recv().await {} } - async fn get_next_message(l1_message_receiver: &mut Receiver, db_flag: &AtomicBool) -> Result { + async fn get_next_message( + l1_message_receiver: &mut Receiver, + db_flag: &AtomicBool, + ) -> Result { if db_flag.load(Ordering::Relaxed) { // TODO: expensive to fetch 1 by 1, implement fetching multiple. Could use static? Self::get_message_from_db().await @@ -74,7 +90,10 @@ impl CommitScheduler { todo!() } - pub async fn schedule(&self, l1_messages: Vec) -> Result<(), Error>{ + pub async fn schedule( + &self, + l1_messages: Vec, + ) -> Result<(), Error> { for el in l1_messages { let err = if let Err(err) = self.sender.try_send(el) { err @@ -83,9 +102,8 @@ impl CommitScheduler { }; if matches!(err, TrySendError::Closed(_)) { - return Err(Error::ChannelClosed) + return Err(Error::ChannelClosed); } - } Ok(()) @@ -95,10 +113,9 @@ impl CommitScheduler { #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Channel was closed")] - ChannelClosed + ChannelClosed, } - /// ideal system: /// // Service keeps accepting messages @@ -114,32 +131,21 @@ pub enum Error { /// We insert into scheduler and then figure out how to optimally split messages // or we split messages and then try to commit specific chunks? - // we write to channel it becom3s full // we need to write to db // Who will - - // TODO Scheduler also return revicer chammel that will receive // (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] // can receive them and hande them txs and sucj - - - // after we flagged that items in db // next sends can't fo to queue, since that will break an order // they need to go to db. - // Our loop - - /// Design: /// Let it be a general service /// Gets directly commits from Processor, then -/// -/// -/// 1. \ No newline at end of file +fn useless() {} diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs index 3e161fb8c..15144d0a0 100644 --- a/magicblock-committor-service/src/commit/commit_using_buffer.rs +++ b/magicblock-committor-service/src/commit/commit_using_buffer.rs @@ -8,10 +8,14 @@ use borsh::{to_vec, BorshDeserialize}; use dlp::pda::commit_state_pda_from_delegated_account; use log::*; use magicblock_committor_program::{ - instruction::{ - create_init_ix, create_realloc_buffer_ixs, - create_realloc_buffer_ixs_to_add_remaining, create_write_ix, - CreateInitIxArgs, CreateReallocBufferIxArgs, CreateWriteIxArgs, + instruction_builder::{ + init_buffer::{create_init_ix, CreateInitIxArgs}, + realloc_buffer::{ + create_realloc_buffer_ixs, + create_realloc_buffer_ixs_to_add_remaining, + CreateReallocBufferIxArgs, + }, + write_buffer::{create_write_ix, CreateWriteIxArgs}, }, instruction_chunks::chunk_realloc_ixs, Changeset, ChangesetChunk, Chunks, CommitableAccount, diff --git a/magicblock-committor-service/src/commit/committor_processor.rs b/magicblock-committor-service/src/commit/committor_processor.rs index 0db9171b2..944c964a6 100644 --- a/magicblock-committor-service/src/commit/committor_processor.rs +++ b/magicblock-committor-service/src/commit/committor_processor.rs @@ -6,6 +6,7 @@ use std::{ use log::*; use magicblock_committor_program::{Changeset, ChangesetMeta}; +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::{ MagicBlockSendTransactionConfig, MagicblockRpcClient, }; @@ -23,7 +24,9 @@ use tokio::task::JoinSet; use super::common::{lookup_table_keys, send_and_confirm}; use crate::{ commit_stage::CommitStage, - commit_strategy::{split_changesets_by_commit_strategy, SplitChangesets}, + commit_strategist::commit_strategy::{ + split_changesets_by_commit_strategy, SplitChangesets, + }, compute_budget::{ComputeBudget, ComputeBudgetConfig}, config::ChainConfig, error::CommittorServiceResult, @@ -140,15 +143,13 @@ impl CommittorProcessor { pub async fn commit_changeset( &self, - changeset: Changeset, - finalize: bool, - ephemeral_blockhash: Hash, + l1_messages: Vec, ) -> Option { let reqid = match self .persister .lock() .expect("persister mutex poisoned") - .start_changeset(&changeset, ephemeral_blockhash, finalize) + .start_changeset(&l1_messages) { Ok(id) => Some(id), Err(err) => { @@ -162,7 +163,6 @@ impl CommittorProcessor { None } }; - let owners = changeset.owners(); let commit_stages = self .process_commit_changeset(changeset, finalize, ephemeral_blockhash) .await; diff --git a/magicblock-committor-service/src/commit/mod.rs b/magicblock-committor-service/src/commit/mod.rs index f14e26aa4..0b07f60c7 100644 --- a/magicblock-committor-service/src/commit/mod.rs +++ b/magicblock-committor-service/src/commit/mod.rs @@ -1,6 +1,8 @@ +mod commit_scheduler; mod commit_using_args; mod commit_using_buffer; mod committor_processor; mod common; mod process_buffers; + pub(super) use committor_processor::CommittorProcessor; diff --git a/magicblock-committor-service/src/commit_strategist/mod.rs b/magicblock-committor-service/src/commit_strategist/mod.rs index ac2be56e5..a1ffe2992 100644 --- a/magicblock-committor-service/src/commit_strategist/mod.rs +++ b/magicblock-committor-service/src/commit_strategist/mod.rs @@ -1,2 +1,2 @@ pub(crate) mod commit_strategy; -pub(crate) mod report_builder; \ No newline at end of file +pub(crate) mod report_builder; diff --git a/magicblock-committor-service/src/commit_strategist/report_builder.rs b/magicblock-committor-service/src/commit_strategist/report_builder.rs index e22f70759..20e3351dc 100644 --- a/magicblock-committor-service/src/commit_strategist/report_builder.rs +++ b/magicblock-committor-service/src/commit_strategist/report_builder.rs @@ -1,10 +1,6 @@ pub(crate) struct L1MessageReport { /// Size of the transaction without lookup tables. size_args: usize, - - /// } -pub(crate) struct L1MessageReportBuilder { - -} +pub(crate) struct L1MessageReportBuilder {} diff --git a/magicblock-committor-service/src/commit_strategy.rs b/magicblock-committor-service/src/commit_strategy.rs deleted file mode 100644 index 28e64257e..000000000 --- a/magicblock-committor-service/src/commit_strategy.rs +++ /dev/null @@ -1,633 +0,0 @@ -use std::collections::HashSet; - -use magicblock_committor_program::{ChangedBundle, Changeset}; -use solana_pubkey::Pubkey; - -use crate::{ - error::{CommittorServiceError, CommittorServiceResult}, - transactions::{ - commit_tx_report, CommitTxReport, MAX_ENCODED_TRANSACTION_SIZE, - }, -}; - -/// These are the commit strategies we can use to commit a changeset in order -/// of preference. We use lookup tables only as last resort since they are -/// slow to prepare. -#[derive(Debug)] -pub enum CommitBundleStrategy { - ArgsIncludeFinalize(ChangedBundle), - Args(ChangedBundle), - FromBuffer(ChangedBundle), - ArgsIncludeFinalizeWithLookupTable(ChangedBundle), - ArgsWithLookupTable(ChangedBundle), - FromBufferWithLookupTable(ChangedBundle), -} - -impl TryFrom<(ChangedBundle, bool)> for CommitBundleStrategy { - type Error = CommittorServiceError; - - /// Try to find the fastest/efficient commit strategy for the given bundle. - /// Order of preference: - /// 1. [CommitBundleStrategy::ArgsIncludeFinalize] - /// 2. [CommitBundleStrategy::Args] - /// 3. [CommitBundleStrategy::FromBuffer] - /// 4. [CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable] - /// 5. [CommitBundleStrategy::ArgsWithLookupTable] - /// 6. [CommitBundleStrategy::FromBufferWithLookupTable] - fn try_from( - (bundle, finalize): (ChangedBundle, bool), - ) -> Result { - let CommitTxReport { - size_args_including_finalize, - size_args, - fits_buffer, - size_args_with_lookup_including_finalize, - size_args_with_lookup, - fits_buffer_using_lookup, - } = commit_tx_report(&bundle, finalize)?; - // Try to combine process and finalize if finalize is true - if let Some(size_including_finalize) = size_args_including_finalize { - if size_including_finalize < MAX_ENCODED_TRANSACTION_SIZE { - return Ok(CommitBundleStrategy::ArgsIncludeFinalize(bundle)); - } - } - // Next still using args but with separate finalize if needed - if size_args < MAX_ENCODED_TRANSACTION_SIZE { - return Ok(CommitBundleStrategy::Args(bundle)); - } - - // Last option to avoid lookup tables - if fits_buffer { - return Ok(CommitBundleStrategy::FromBuffer(bundle)); - } - - // All the below use lookup tables and will be a lot slower - - // Combining finalize and process - if let Some(size_with_lookup_including_finalize) = - size_args_with_lookup_including_finalize - { - if size_with_lookup_including_finalize - < MAX_ENCODED_TRANSACTION_SIZE - { - return Ok( - CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable( - bundle, - ), - ); - } - } - // Using lookup tables but separate finalize - if let Some(size_with_lookup) = size_args_with_lookup { - if size_with_lookup < MAX_ENCODED_TRANSACTION_SIZE { - return Ok(CommitBundleStrategy::ArgsWithLookupTable(bundle)); - } - } - - // Worst case try to use a buffer with lookup tables - if fits_buffer_using_lookup { - return Ok(CommitBundleStrategy::FromBufferWithLookupTable(bundle)); - } - - // If none of the strategies work then we need to error - let bundle_id = bundle - .first() - .map(|(_, acc)| acc.bundle_id()) - .unwrap_or_default(); - Err(CommittorServiceError::CouldNotFindCommitStrategyForBundle( - bundle_id, - )) - } -} - -#[derive(Debug)] -pub struct SplitChangesets { - /// This changeset can be committed in one processing step, passing account data as args - pub args_changeset: Changeset, - /// This changeset can be committed in one processing step, passing account data as args - /// and the finalize instruction fits into the same transaction - pub args_including_finalize_changeset: Changeset, - /// This changeset can be committed in one processing step, passing account data as args - /// but needs to use lookup tables for the accounts - pub args_with_lookup_changeset: Changeset, - /// This changeset can be committed in one processing step, passing account data as args - /// and the finalize instruction fits into the same transaction. - /// It needs to use lookup tables for the accounts. - pub args_including_finalize_with_lookup_changeset: Changeset, - /// This changeset needs to be committed in two steps: - /// 1. Prepare the buffer account - /// 2. Process the buffer account - pub from_buffer_changeset: Changeset, - /// This changeset needs to be committed in three steps: - /// 1. Prepare the buffer account - /// 2. Prepare lookup table - /// 3. Process the buffer account - pub from_buffer_with_lookup_changeset: Changeset, -} - -pub fn split_changesets_by_commit_strategy( - changeset: Changeset, - finalize: bool, -) -> CommittorServiceResult { - fn add_to_changeset( - changeset: &mut Changeset, - accounts_to_undelegate: &HashSet, - bundle: ChangedBundle, - ) { - for (pubkey, acc) in bundle { - changeset.add(pubkey, acc); - if accounts_to_undelegate.contains(&pubkey) { - changeset.accounts_to_undelegate.insert(pubkey); - } - } - } - - let mut args_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - let mut args_including_finalize_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - let mut args_with_lookup_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - let mut args_including_finalize_with_lookup_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - let mut from_buffer_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - let mut from_buffer_with_lookup_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - - let accounts_to_undelegate = changeset.accounts_to_undelegate.clone(); - let changeset_bundles = changeset.into_small_changeset_bundles(); - for bundle in changeset_bundles.bundles.into_iter() { - let commit_strategy = - CommitBundleStrategy::try_from((bundle, finalize))?; - match commit_strategy { - CommitBundleStrategy::Args(bundle) => { - add_to_changeset( - &mut args_changeset, - &accounts_to_undelegate, - bundle, - ); - } - CommitBundleStrategy::ArgsIncludeFinalize(bundle) => { - add_to_changeset( - &mut args_including_finalize_changeset, - &accounts_to_undelegate, - bundle, - ); - } - CommitBundleStrategy::ArgsWithLookupTable(bundle) => { - add_to_changeset( - &mut args_with_lookup_changeset, - &accounts_to_undelegate, - bundle, - ); - } - CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable( - bundle, - ) => { - add_to_changeset( - &mut args_including_finalize_with_lookup_changeset, - &accounts_to_undelegate, - bundle, - ); - } - CommitBundleStrategy::FromBuffer(bundle) => { - add_to_changeset( - &mut from_buffer_changeset, - &accounts_to_undelegate, - bundle, - ); - } - CommitBundleStrategy::FromBufferWithLookupTable(bundle) => { - add_to_changeset( - &mut from_buffer_with_lookup_changeset, - &accounts_to_undelegate, - bundle, - ); - } - } - } - - Ok(SplitChangesets { - args_changeset, - args_including_finalize_changeset, - args_with_lookup_changeset, - args_including_finalize_with_lookup_changeset, - from_buffer_changeset, - from_buffer_with_lookup_changeset, - }) -} - -#[cfg(test)] -mod test { - use log::*; - use magicblock_committor_program::ChangedAccount; - use solana_sdk::pubkey::Pubkey; - - use super::*; - - fn init_logger() { - let _ = env_logger::builder() - .format_timestamp(None) - .is_test(true) - .try_init(); - } - - fn add_changed_account( - changeset: &mut Changeset, - size: usize, - bundle_id: u64, - undelegate: bool, - ) -> Pubkey { - let pubkey = Pubkey::new_unique(); - changeset.add( - pubkey, - ChangedAccount::Full { - data: vec![1; size], - owner: Pubkey::new_unique(), - lamports: 0, - bundle_id, - }, - ); - if undelegate { - changeset.accounts_to_undelegate.insert(pubkey); - } - pubkey - } - - macro_rules! debug_counts { - ($label:expr, $changeset:ident, $split_changesets:ident) => { - debug!( - "{}: ({}) {{ -args_changeset: {} -args_including_finalize_changeset: {} -args_with_lookup_changeset: {} -args_including_finalize_with_lookup_changeset: {} -from_buffer_changeset: {} -from_buffer_with_lookup_changeset: {} -}}", - $label, - $changeset.accounts.len(), - $split_changesets.args_changeset.len(), - $split_changesets.args_including_finalize_changeset.len(), - $split_changesets.args_with_lookup_changeset.len(), - $split_changesets - .args_including_finalize_with_lookup_changeset - .len(), - $split_changesets.from_buffer_changeset.len(), - $split_changesets.from_buffer_with_lookup_changeset.len() - ); - }; - } - - macro_rules! assert_accounts_sum_matches { - ($changeset:ident, $split_changesets:ident) => { - assert_eq!( - $split_changesets.args_changeset.len() - + $split_changesets.args_including_finalize_changeset.len() - + $split_changesets.args_with_lookup_changeset.len() - + $split_changesets - .args_including_finalize_with_lookup_changeset - .len() - + $split_changesets.from_buffer_changeset.len() - + $split_changesets.from_buffer_with_lookup_changeset.len(), - $changeset.len() - ); - }; - } - - macro_rules! assert_undelegate_sum_matches { - ($changeset:ident, $split_changesets:ident) => { - assert_eq!( - $split_changesets - .args_changeset - .accounts_to_undelegate - .len() - + $split_changesets - .args_including_finalize_changeset - .accounts_to_undelegate - .len() - + $split_changesets - .args_with_lookup_changeset - .accounts_to_undelegate - .len() - + $split_changesets - .args_including_finalize_with_lookup_changeset - .accounts_to_undelegate - .len() - + $split_changesets - .from_buffer_changeset - .accounts_to_undelegate - .len() - + $split_changesets - .from_buffer_with_lookup_changeset - .accounts_to_undelegate - .len(), - $changeset.accounts_to_undelegate.len() - ); - }; - } - #[test] - fn test_split_small_changesets_by_commit_strategy() { - init_logger(); - - // Setup a changeset with different bundle/account sizes - let mut changeset = Changeset { - slot: 1, - ..Default::default() - }; - - let bundle_id = 1111; - - // 2 accounts bundle that can be handled via args - for idx in 1..=2 { - add_changed_account(&mut changeset, 10, bundle_id, idx % 2 == 0); - } - - // 8 accounts bundle that needs lookup - for idx in 1..=8 { - add_changed_account( - &mut changeset, - 10, - bundle_id * 10, - idx % 2 == 0, - ); - } - - // No Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), false) - .unwrap(); - debug_counts!("No Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_changeset.len(), 2,); - assert_eq!(split_changesets.args_with_lookup_changeset.len(), 8,); - - // Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), true) - .unwrap(); - - debug_counts!("Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_including_finalize_changeset.len(), 2,); - assert_eq!( - split_changesets - .args_including_finalize_with_lookup_changeset - .len(), - 8, - ); - } - - #[test] - fn test_split_medium_changesets_by_commit_strategy() { - init_logger(); - - // Setup a changeset with different bundle/account sizes - let mut changeset = Changeset { - slot: 1, - ..Default::default() - }; - let bundle_id = 2222; - - // 2 accounts bundle that can be handled via args and include the finalize instructions - for idx in 1..=2 { - add_changed_account(&mut changeset, 80, bundle_id, idx % 2 == 0); - } - - // 2 accounts bundle that can be handled via args, but cannot include finalize due - // to the size of the data - for idx in 1..=2 { - add_changed_account( - &mut changeset, - 100, - bundle_id + 1, - idx % 2 == 0, - ); - } - - // 3 accounts bundle that needs lookup buffer due to overall args size - for idx in 1..=3 { - add_changed_account( - &mut changeset, - 100, - bundle_id + 3, - idx % 2 == 0, - ); - } - - // No Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), false) - .unwrap(); - debug_counts!("No Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_changeset.len(), 4,); - assert_eq!(split_changesets.from_buffer_changeset.len(), 3,); - - // Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), true) - .unwrap(); - debug_counts!("Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_changeset.len(), 2,); - assert_eq!(split_changesets.args_including_finalize_changeset.len(), 2,); - assert_eq!(split_changesets.from_buffer_changeset.len(), 3,); - } - - #[test] - fn test_split_large_changesets_by_commit_strategy() { - init_logger(); - - // Setup a changeset with different bundle/account sizes - let mut changeset = Changeset { - slot: 1, - ..Default::default() - }; - - let bundle_id = 3333; - - // 5 accounts bundle that needs to be handled via lookup (buffer) - for idx in 1..=5 { - add_changed_account(&mut changeset, 400, bundle_id, idx % 2 == 0); - } - - // 2 accounts bundle that can be handled without lookup (buffer) - for idx in 1..=2 { - add_changed_account( - &mut changeset, - 600, - bundle_id * 10, - idx % 2 == 0, - ); - } - - // No Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), false) - .unwrap(); - debug_counts!("No Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.from_buffer_changeset.len(), 2,); - assert_eq!(split_changesets.from_buffer_with_lookup_changeset.len(), 5,); - - // Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), true) - .unwrap(); - debug_counts!("Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.from_buffer_changeset.len(), 2,); - assert_eq!(split_changesets.from_buffer_with_lookup_changeset.len(), 5,); - } - - #[test] - fn test_split_different_size_changesets_by_commit_strategy() { - // Combining the different changeset sizes we already test above into one changeset to - // split - init_logger(); - - // Setup a changeset with different bundle/account sizes - let mut changeset = Changeset { - slot: 1, - ..Default::default() - }; - - // Small sized bundles - { - let bundle_id = 1111; - - // 2 accounts bundle that can be handled via args - for idx in 1..=2 { - add_changed_account( - &mut changeset, - 10, - bundle_id, - idx % 2 == 0, - ); - } - - // 8 accounts bundle that needs lookup - for idx in 1..=8 { - add_changed_account( - &mut changeset, - 10, - bundle_id * 10, - idx % 2 == 0, - ); - } - }; - - // Medium sized bundles - { - let bundle_id = 2222; - - // 2 accounts bundle that can be handled via args - for idx in 1..=2 { - add_changed_account( - &mut changeset, - 100, - bundle_id, - idx % 2 == 0, - ); - } - }; - - // Large sized bundles - { - let bundle_id = 3333; - - // 5 accounts bundle that needs to be handled via lookup (buffer) - for idx in 1..=5 { - add_changed_account( - &mut changeset, - 400, - bundle_id, - idx % 2 == 0, - ); - } - - // 2 accounts bundle that can be handled without lookup (buffer) - for idx in 1..=2 { - add_changed_account( - &mut changeset, - 600, - bundle_id * 10, - idx % 2 == 0, - ); - } - }; - - // No Finalize - { - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), false) - .unwrap(); - - debug_counts!("No Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_changeset.len(), 4); - assert_eq!(split_changesets.args_with_lookup_changeset.len(), 8); - assert_eq!(split_changesets.from_buffer_changeset.len(), 2); - assert_eq!( - split_changesets.from_buffer_with_lookup_changeset.len(), - 5 - ); - } - - // Finalize - { - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), true) - .unwrap(); - - debug_counts!("Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_changeset.len(), 2); - assert_eq!( - split_changesets.args_including_finalize_changeset.len(), - 2 - ); - assert_eq!( - split_changesets - .args_including_finalize_with_lookup_changeset - .len(), - 8 - ); - assert_eq!(split_changesets.from_buffer_changeset.len(), 2); - assert_eq!( - split_changesets.from_buffer_with_lookup_changeset.len(), - 5 - ); - } - } -} diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 9c0c1ad89..7674324f5 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -3,7 +3,7 @@ mod bundles; mod commit; mod commit_info; mod commit_stage; -mod commit_strategy; +mod commit_strategist; mod compute_budget; pub mod config; mod consts; @@ -16,8 +16,10 @@ mod transactions; mod types; mod undelegate; +mod commit_strategist; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; +mod transaction_preperator; pub use commit_info::CommitInfo; pub use commit_stage::CommitStage; diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 41c5fa69d..7fa9f3a48 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -2,6 +2,7 @@ use std::path::Path; use log::*; use magicblock_committor_program::Changeset; +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::Pubkey; use solana_sdk::{hash::Hash, signature::Keypair}; use tokio::{ @@ -50,9 +51,7 @@ pub enum CommittorMessage { /// Called once the changeset has been committed respond_to: oneshot::Sender>, /// The changeset to commit - changeset: Changeset, - /// The blockhash in the ephemeral at the time the commit was requested - ephemeral_blockhash: Hash, + l1_messages: Vec, /// If `true`, account commits will be finalized after they were processed finalize: bool, }, @@ -129,15 +128,11 @@ impl CommittorActor { } } CommitChangeset { - changeset, - ephemeral_blockhash, + l1_messages, respond_to, finalize, } => { - let reqid = self - .processor - .commit_changeset(changeset, finalize, ephemeral_blockhash) - .await; + let reqid = self.processor.commit_changeset(l1_messages).await; if let Err(e) = respond_to.send(reqid) { error!("Failed to send response {:?}", e); } @@ -303,7 +298,6 @@ impl ChangesetCommittor for CommittorService { fn commit_changeset( &self, changeset: Changeset, - ephemeral_blockhash: Hash, finalize: bool, ) -> oneshot::Receiver> { let (tx, rx) = oneshot::channel(); @@ -354,7 +348,6 @@ pub trait ChangesetCommittor: Send + Sync + 'static { fn commit_changeset( &self, changeset: Changeset, - ephemeral_blockhash: Hash, finalize: bool, ) -> oneshot::Receiver>; diff --git a/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs b/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs index 5c0ccdd9d..5024d5e11 100644 --- a/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs +++ b/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs @@ -1,34 +1,52 @@ -use solana_sdk::instruction::Instruction; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; -use crate::compute_budget::Budget; -use crate::ComputeBudgetConfig; +use solana_sdk::{ + compute_budget::ComputeBudgetInstruction, instruction::Instruction, +}; + +use crate::{compute_budget::Budget, ComputeBudgetConfig}; // TODO(edwin): rename struct ComputeBudgetV1 { /// Total compute budget pub compute_budget: u32, - pub compute_unit_price: u64 + pub compute_unit_price: u64, +} + +impl ComputeBudgetV1 { + /// Needed just to create dummy ixs, and evaluate size + fn dummy() -> Self { + Self { + compute_budget: 0, + compute_unit_price: 0, + } + } } pub trait ComputeBudgetCalculator { - fn instruction(budget: ComputeBudgetV1) -> Instruction; + fn budget_instructions(budget: ComputeBudgetV1) -> [Instruction; 2]; /// Calculate budget for commit transaction - fn calculate_commit_budget(&self, l1_message: &ScheduledL1Message) -> ComputeBudgetV1; + fn calculate_commit_budget( + &self, + l1_message: &ScheduledL1Message, + ) -> ComputeBudgetV1; /// Calculate budget for finalze transaction - fn calculate_finalize_budget(&self, l1_message: &ScheduledL1Message) -> ComputeBudgetV1; + fn calculate_finalize_budget( + &self, + l1_message: &ScheduledL1Message, + ) -> ComputeBudgetV1; } /// V1 implementation, works with TransactionPreparator V1 /// Calculations for finalize may include cases for pub struct ComputeBudgetCalculatorV1 { - compute_budget_config: ComputeBudgetConfig + compute_budget_config: ComputeBudgetConfig, } impl ComputeBudgetCalculatorV1 { pub fn new(config: ComputeBudgetConfig) -> Self { Self { - compute_budget_config: config + compute_budget_config: config, } } } @@ -36,17 +54,36 @@ impl ComputeBudgetCalculatorV1 { impl ComputeBudgetCalculator for ComputeBudgetCalculatorV1 { /// Calculate compute budget for V1 commit transaction /// This includes only compute for account commits - fn calculate_commit_budget(&self, l1_message: &ScheduledL1Message) -> ComputeBudgetV1 { + fn calculate_commit_budget( + &self, + l1_message: &ScheduledL1Message, + ) -> ComputeBudgetV1 { todo!() } - fn calculate_finalize_budget(&self, l1_message: &ScheduledL1Message) -> ComputeBudgetV1 { + fn calculate_finalize_budget( + &self, + l1_message: &ScheduledL1Message, + ) -> ComputeBudgetV1 { todo!() } - fn instruction(budget: ComputeBudgetV1) -> Instruction { - + fn budget_instructions(budget: ComputeBudgetV1) -> [Instruction; 2] { + let compute_budget_ix = + ComputeBudgetInstruction::set_compute_unit_limit( + budget.compute_budget, + ); + let compute_unit_price_ix = + ComputeBudgetInstruction::set_compute_unit_price( + budget.compute_unit_price, + ); + + [compute_budget_ix, compute_unit_price_ix] } } -/// \ No newline at end of file +// We need to create an optimal TX +// Optimal tx - [ComputeBudget, Args(acc1), Buffer(acc2), Args(Action))] +// Estimate actual budget +// Recreate TX +// diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs new file mode 100644 index 000000000..5a1f8484e --- /dev/null +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -0,0 +1,67 @@ +use std::future::Future; + +use futures_util::future::{join, join_all}; +use magicblock_rpc_client::MagicblockRpcClient; +use magicblock_table_mania::TableMania; +use solana_sdk::message::AddressLookupTableAccount; + +use crate::transaction_preperator::{ + delivery_strategist::{TaskDeliveryStrategy, TransactionStrategy}, + error::PreparatorResult, + task_builder::Task, +}; + +type PreparationFuture = impl Future>; + +pub struct DeliveryPreparationResult { + lookup_tables: Vec, +} + +pub struct DeliveryPreparator { + rpc_client: MagicblockRpcClient, + table_mania: TableMania, +} + +impl DeliveryPreparator { + pub fn new( + rpc_client: MagicblockRpcClient, + table_mania: TableMania, + ) -> Self { + Self { + rpc_client, + table_mania, + } + } + + /// Prepares buffers and necessary pieces for optimized TX + pub async fn prepare_for_delivery( + &self, + strategy: &TransactionStrategy, + ) -> DeliveryPreparationResult { + let preparation_futures = strategy + .task_strategies + .iter() + .filter_map(|strategy| match strategy { + TaskDeliveryStrategy::Args(_) => None, + TaskDeliveryStrategy::Buffer(task) => Some(task), + }) + .map(|task| self.prepare_buffer(task)); + // .collect::>>>(); + + join_all(preparation_futures); + join() + } + + async fn prepare_buffer(&self, task: &Task) -> PreparatorResult<()> { + todo!(); + Ok(()) + } + + async fn prepare_lookup_tables( + &self, + strategies: Vec, + ) -> PreparatorResult> { + // self.table_mania. + todo!() + } +} diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_strategist.rs b/magicblock-committor-service/src/transaction_preperator/delivery_strategist.rs new file mode 100644 index 000000000..dd4892b7d --- /dev/null +++ b/magicblock-committor-service/src/transaction_preperator/delivery_strategist.rs @@ -0,0 +1,195 @@ +use std::collections::BinaryHeap; + +use solana_pubkey::Pubkey; +use solana_sdk::{ + hash::Hash, + instruction::Instruction, + message::{v0::Message, VersionedMessage}, + signature::Keypair, + transaction::{Transaction, VersionedTransaction}, +}; + +use crate::{ + transaction_preperator::{ + error::{Error, PreparatorResult}, + task_builder::Task, + utils::estimate_lookup_tables_for_tx, + }, + transactions::{serialize_and_encode_base64, MAX_ENCODED_TRANSACTION_SIZE}, +}; + +#[derive(Clone)] +pub enum TaskDeliveryStrategy { + Args(Task), + Buffer(Task), +} + +impl TaskDeliveryStrategy { + pub fn instruction(&self) -> Instruction { + todo!() + } +} + +#[derive(Clone)] +pub struct TransactionStrategy { + pub task_strategies: Vec, + pub use_lookup_table: bool, +} + +impl TaskDeliveryStrategy { + fn decrease(self) -> Result { + match self { + Self::Args(task) => { + if task.is_bufferable() { + Ok(Self::Buffer(task)) + } else { + // Can't decrease size for task + Err(Self::Args(task)) + } + } + val @ Self::Buffer(_) => Err(val), // No other shorter strategy + } + } +} + +pub struct DeliveryStrategist; +impl DeliveryStrategist { + /// Returns [`TaskDeliveryStrategy`] for every [`Task`] + pub fn build_strategies( + tasks: Vec, + ) -> PreparatorResult { + // TODO(edwin): we could have Vec + // In runtime "BufferedTask" could replace "ArgTask" + let mut strategies = tasks + .into_iter() + .map(|el| TaskDeliveryStrategy::Args(el)) + .collect::>(); + + // Optimize stategy + if Self::optimize_strategy(&mut strategies) + <= MAX_ENCODED_TRANSACTION_SIZE + { + return Ok(TransactionStrategy { + task_strategies: strategies, + use_lookup_table: false, + }); + } + + let alt_tx = Self::assemble_tx_with_lookup_table(&strategies); + if alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE { + Ok(TransactionStrategy { + task_strategies: strategies, + use_lookup_table: false, + }) + } else { + Err(Error::FailedToFitError) + } + } + + /// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`] + /// Returns size of tx after optimizations + fn optimize_strategy(strategies: &mut [TaskDeliveryStrategy]) -> usize { + let ixs = Self::assemble_ixs(&strategies); + let tx = Self::assemble_tx_with_budget(&strategies); + let mut current_tx_length = serialize_and_encode_base64(&tx).len(); + + // Create heap size -> index + let sizes = ixs + .iter() + .map(|ix| borsh::object_length(ix)) + .collect::, _>>() + .unwrap(); + + let mut map = sizes + .into_iter() + .enumerate() + .map(|(index, size)| (size, index)) + .collect::>(); + // We keep popping heaviest el-ts & try to optimize while heap is non-empty + while let Some((_, index)) = map.pop() { + if current_tx_length <= MAX_ENCODED_TRANSACTION_SIZE { + break; + } + + let task = &mut strategies[index]; + // SAFETY: we have exclusive access to [`strategies`]. + // We create bitwise copy, and then replace it with `self`. + // No memory will be double-freed since we use `std::ptr::write` + // No memory is leaked since we use don't allocate anything new + // Critical invariants: + // - decrease(self) shall never drop self + // NOTE: don't want [`Task`] to implement `Default` + unsafe { + let task_ptr = task as *mut TaskDeliveryStrategy; + let old_value = std::ptr::read(task_ptr); + match old_value.decrease() { + // If we can decrease: + // 1. Calculate new tx size & ix size + // 2. Insert item's data back in the heap + // 3. Update overall tx size + Ok(next_strategy) => { + std::ptr::write(task_ptr, next_strategy); + // TODO(edwin): this is expensive + let new_ix = strategies[index].instruction(); + let new_ix_size = + borsh::object_length(&new_ix).unwrap(); // TODO(edwin): unwrap + let new_tx = Self::assemble_tx_with_budget(&strategies); + + map.push((new_ix_size, index)); + current_tx_length = + serialize_and_encode_base64(&new_tx).len(); + } + // That means el-t can't be optimized further + // We move it back with oldest state + // Heap forgets about this el-t + Err(old_strategy) => { + std::ptr::write(task_ptr, old_strategy); + } + } + } + } + + current_tx_length + } + + // TODO(edwin): improve + fn assemble_tx_with_lookup_table( + strategies: &[TaskDeliveryStrategy], + ) -> VersionedTransaction { + // In case we can't fit with optimal strategy - try ALT + let tx = Self::assemble_tx_with_budget(&strategies); + let alts = estimate_lookup_tables_for_tx(&tx); + let ixs = Self::assemble_ixs_with_budget(&strategies); + let message = Message::try_compile( + &Pubkey::new_unique(), + &ixs, + &alts, + Hash::new_unique(), + ) + .unwrap(); // TODO(edwin): unwrap + let tx = VersionedTransaction::try_new( + VersionedMessage::V0(message), + &&[Keypair::new()], + ) + .unwrap(); + tx + } + + fn assemble_ixs_with_budget( + strategies: &[TaskDeliveryStrategy], + ) -> Vec { + todo!() + } + + fn assemble_ixs(tasks: &[TaskDeliveryStrategy]) -> Vec { + // Just given Strategy(Task) creates dummy ixs + // Then assemls ixs into tx + todo!() + } + + fn assemble_tx_with_budget( + tasks: &[TaskDeliveryStrategy], + ) -> VersionedTransaction { + todo!() + } +} diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preperator/error.rs index c764c1ff5..d40af99af 100644 --- a/magicblock-committor-service/src/transaction_preperator/error.rs +++ b/magicblock-committor-service/src/transaction_preperator/error.rs @@ -1,4 +1,5 @@ use thiserror::Error; + use crate::transaction_preperator::transaction_preparator::PreparatorVersion; #[derive(Error, Debug)] @@ -11,4 +12,4 @@ pub enum Error { InternalError(#[from] anyhow::Error), } -pub type PreparatorResult = Result; \ No newline at end of file +pub type PreparatorResult = Result; diff --git a/magicblock-committor-service/src/transaction_preperator/mod.rs b/magicblock-committor-service/src/transaction_preperator/mod.rs index 2f9f9f716..ea2369a7d 100644 --- a/magicblock-committor-service/src/transaction_preperator/mod.rs +++ b/magicblock-committor-service/src/transaction_preperator/mod.rs @@ -1,4 +1,7 @@ -mod transaction_preparator; -mod error; mod budget_calculator; - +mod delivery_preparator; +mod delivery_strategist; +mod error; +mod task_builder; +mod transaction_preparator; +mod utils; diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs index e69de29bb..d282763ca 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_builder.rs @@ -0,0 +1,236 @@ +use dlp::args::{CallHandlerArgs, CommitStateArgs, CommitStateFromBufferArgs}; +use magicblock_program::magic_scheduled_l1_message::{ + CommitAndUndelegate, CommitType, CommittedAccountV2, L1Action, + MagicL1Message, ScheduledL1Message, UndelegateType, +}; +use solana_pubkey::Pubkey; +use solana_sdk::instruction::{AccountMeta, Instruction}; + +// pub trait PossibleTaskTrait { +// fn instruction() -> Instruction; +// fn decrease(self: Box) -> Result, Box>; +// // If task is "preparable" returns Instructions for preparations +// fn prepare(self: Box) -> Option>; +// } + +#[derive(Clone)] +pub struct CommitTask { + pub allow_undelegatio: bool, + pub committed_account: CommittedAccountV2, +} + +#[derive(Clone)] +pub struct UndelegateTask { + pub delegated_account: Pubkey, + pub owner_program: Pubkey, + pub rent_reimbursement: Pubkey, +} + +#[derive(Clone)] +pub struct FinalizeTask { + pub delegated_account: Pubkey, +} + +#[derive(Clone)] +pub enum Task { + Commit(CommitTask), + Finalize(FinalizeTask), // TODO(edwin): introduce Stages instead? + Undelegate(UndelegateTask), // Special action really + L1Action(L1Action), +} + +impl Task { + pub fn is_bufferable(&self) -> bool { + match self { + Self::Commit(_) => true, + Self::Finalize(_) => false, + Self::Undelegate(_) => false, + Self::L1Action(_) => false, // TODO(edwin): enable + } + } + + pub fn args_instruction( + &self, + validator: Pubkey, + commit_id: u64, + ) -> Instruction { + match self { + Task::Commit(value) => { + let args = CommitStateArgs { + slot: commit_id, // TODO(edwin): change slot, + lamports: value.committed_account.account.lamports, + data: value.committed_account.account.data.clone(), + allow_undelegation: value.allow_undelegatio, // TODO(edwin): + }; + dlp::instruction_builder::commit_state( + validator, + value.committed_account.pubkey, + value.committed_account.account.owner, + args, + ) + } + Task::Finalize(value) => dlp::instruction_builder::finalize( + validator, + value.delegated_account, + ), + Task::Undelegate(value) => dlp::instruction_builder::undelegate( + validator, + value.delegated_account, + value.owner_program, + value.rent_reimbursement, + ), + Task::L1Action(value) => { + let account_metas = value + .account_metas_per_program + .iter() + .map(|short_meta| AccountMeta { + pubkey: short_meta.pubkey, + is_writable: short_meta.is_writable, + is_signer: false, + }) + .collect(); + dlp::instruction_builder::call_handler( + validator, + value.destination_program, + value.escrow_authority, + account_metas, + CallHandlerArgs { + data: value.data_per_program.data.clone(), + escrow_index: value.data_per_program.escrow_index, + }, + ) + } + } + todo!() + } + + pub fn buffer_instruction( + &self, + validator: Pubkey, + commit_id: u64, + ) -> Instruction { + // TODO(edwin): now this is bad, while impossible + // We should use dyn Task + match self { + Task::Commit(value) => { + let commit_id_slice = commit_id.to_le_bytes(); + let (commit_buffer_pubkey, _) = + magicblock_committor_program::pdas::chunks_pda( + &validator, + &value.committed_account.pubkey, + &commit_id_slice, + ); + dlp::instruction_builder::commit_state_from_buffer( + validator, + value.committed_account.pubkey, + value.committed_account.account.owner, + commit_buffer_pubkey, + CommitStateFromBufferArgs { + slot: commit_id, //TODO(edwin): change to commit_id + lamports: value.committed_account.account.lamports, + allow_undelegation: value.allow_undelegatio, + }, + ) + } + Task::Undelegate(_) => unreachable!(), + Task::Finalize(_) => unreachable!(), + Task::L1Action(_) => unreachable!(), // TODO(edwin): enable + } + } +} + +pub trait TasksBuilder { + // Creates tasks for commit stage + fn commit_tasks(l1_message: &ScheduledL1Message) -> Vec; + + // Create tasks for finalize stage + fn finalize_tasks(l1_message: &ScheduledL1Message) -> Vec; +} + +/// V1 Task builder +/// V1: Actions are part of finalize tx +pub struct TaskBuilderV1; +impl TasksBuilder for TaskBuilderV1 { + /// Returns [`Task`]s for Commit stage + fn commit_tasks(l1_message: &ScheduledL1Message) -> Vec { + let accounts = match &l1_message.l1_message { + MagicL1Message::L1Actions(actions) => { + return actions + .into_iter() + .map(|el| Task::L1Action(el.clone())) + .collect() + } + MagicL1Message::Commit(t) => t.get_committed_accounts(), + MagicL1Message::CommitAndUndelegate(t) => { + t.commit_action.get_committed_accounts() + } + }; + + accounts + .into_iter() + .map(|account| Task::Commit(account.clone())) + .collect() + } + + /// Returns [`Task`]s for Finalize stage + fn finalize_tasks(l1_message: &ScheduledL1Message) -> Vec { + fn commit_type_tasks(value: &CommitType) -> Vec { + match value { + CommitType::Standalone(accounts) => accounts + .into_iter() + .map(|account| Task::Finalize(account.clone())) + .collect(), + CommitType::WithL1Actions { + committed_accounts, + l1_actions, + } => { + let mut tasks = committed_accounts + .into_iter() + .map(|account| Task::Finalize(account.clone())) + .collect::>(); + tasks.extend( + l1_actions + .into_iter() + .map(|action| Task::L1Action(action.clone())), + ); + tasks + } + } + } + + // TODO(edwin): improve, separate into smaller pieces. Maybe Visitor? + match &l1_message.l1_message { + MagicL1Message::L1Actions(_) => panic!("enable"), // TODO(edwin) + MagicL1Message::Commit(value) => commit_type_tasks(value), + MagicL1Message::CommitAndUndelegate(t) => { + let mut commit_tasks = commit_type_tasks(&t.commit_action); + match &t.undelegate_action { + UndelegateType::Standalone => { + let accounts = t.get_committed_accounts(); + commit_tasks.extend( + accounts.into_iter().map(|account| { + Task::Undelegate(account.clone()) + }), + ); + } + UndelegateType::WithL1Actions(actions) => { + // tasks example: [Finalize(Acc1), Action, Undelegate(Acc1), Action] + let accounts = t.get_committed_accounts(); + commit_tasks.extend( + accounts.into_iter().map(|account| { + Task::Undelegate(account.clone()) + }), + ); + commit_tasks.extend( + actions + .into_iter() + .map(|action| Task::L1Action(action.clone())), + ); + } + }; + + commit_tasks + } + } + } +} diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 1ad671fea..baa924881 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -1,14 +1,17 @@ use async_trait::async_trait; -use solana_rpc_client::rpc_client::RpcClient; -use solana_sdk::message::v0::Message; -use solana_sdk::transaction::Transaction; use magicblock_program::magic_scheduled_l1_message::{ - ScheduledL1Message, MagicL1Message + CommittedAccountV2, L1Action, MagicL1Message, ScheduledL1Message, }; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; -use crate::transaction_preperator::budget_calculator::{ComputeBudgetCalculator, ComputeBudgetCalculatorV1}; -use crate::transaction_preperator::error::{Error, PreparatorResult}; +use solana_sdk::message::v0::Message; + +use crate::transaction_preperator::{ + budget_calculator::{ComputeBudgetCalculator, ComputeBudgetCalculatorV1}, + delivery_strategist::DeliveryStrategist, + error::{Error, PreparatorResult}, + task_builder::{TaskBuilderV1, TasksBuilder}, +}; /// Transaction Preparator version /// Some actions maybe imnvalid per version @@ -17,15 +20,17 @@ pub enum PreparatorVersion { V1, } - #[async_trait] trait TransactionPreparator { - type BudgetCalculator: ComputeBudgetCalculator; - fn version(&self) -> PreparatorVersion; - async fn prepare_commit_tx(&self, l1_message: &ScheduledL1Message) -> PreparatorResult; - async fn prepare_finalize_tx(&self, l1_message: &ScheduledL1Message) -> PreparatorResult; - + async fn prepare_commit_tx( + &self, + l1_message: &ScheduledL1Message, + ) -> PreparatorResult; + async fn prepare_finalize_tx( + &self, + l1_message: &ScheduledL1Message, + ) -> PreparatorResult; } /// [`TransactionPreparatorV1`] first version of preparator @@ -33,37 +38,94 @@ trait TransactionPreparator { /// It creates TXs using current per account commit/finalize struct TransactionPreparatorV1 { rpc_client: MagicblockRpcClient, - table_mania: TableMania // TODO(edwin): Arc? + table_mania: TableMania, // TODO(edwin): Arc? } impl TransactionPreparatorV1 { - pub fn new(rpc_client: MagicblockRpcClient, table_mania: TableMania) -> Self { + pub fn new( + rpc_client: MagicblockRpcClient, + table_mania: TableMania, + ) -> Self { Self { rpc_client, - table_mania + table_mania, } } + + // TODO(edwin) + fn prepare_action_tx(actions: &Vec) -> PreparatorResult { + todo!() + } + + fn prepare_committed_accounts_tx( + account: &Vec, + ) -> PreparatorResult { + todo!() + } } impl TransactionPreparator for TransactionPreparatorV1 { - type BudgetCalculator = ComputeBudgetCalculatorV1; - fn version(&self) -> PreparatorVersion { PreparatorVersion::V1 } /// In V1: prepares TX with commits for every account in message /// For pure actions message - outputs Tx that runs actions - async fn prepare_commit_tx(&self, l1_message: &ScheduledL1Message) -> PreparatorResult { + async fn prepare_commit_tx( + &self, + l1_message: &ScheduledL1Message, + ) -> PreparatorResult { + // 1. create tasks + // 2. optimize to fit tx size. aka Delivery Strategy + // 3. Pre tx preparations. Create buffer accs + lookup tables + // 4. Build resulting TX to be executed + + // 1. + let tasks = TaskBuilderV1::commit_tasks(l1_message); + // 2. + let tx_strategy = DeliveryStrategist::build_strategies(tasks)?; + // 3. + todo!() } /// In V1: prepares single TX with finalize, undelegation + actions - async fn prepare_finalize_tx(&self, l1_message: &ScheduledL1Message) -> PreparatorResult { - if matches!(l1_message.l1_message, MagicL1Message::L1Actions(_)) { - Err(Error::VersionError(PreparatorVersion::V1)) - } else { - Ok(()) - } + async fn prepare_finalize_tx( + &self, + l1_message: &ScheduledL1Message, + ) -> PreparatorResult { + let tasks = TaskBuilderV1::finalize_tasks(l1_message); + let tx_strategy = DeliveryStrategist::build_strategies(tasks); + + todo!() } -} \ No newline at end of file +} + +/// We have 2 stages for L1Message +/// 1. commit +/// 2. finalize +/// +/// Now, single "task" can be differently represented in 2 stage +/// In terms of transaction and so on + +/// We have: +/// Stages - type +/// Strategy - enum +/// Task - enum + +// Can [`Task`] have [`Strategy`] based on [`Stage`] +// We receive proposals and actions from users +// Those have to + +/// We get tasks we need to pass them through +/// Strategy: +// 1. Try to fit Vec into TX. save tx_size +// 2. Start optimizing +// 3. Find biggest ix +// 4. Replace with BufferedIx(maybe pop from Heap) +// 5. tx_size -= (og_size - buffered_size) +// 6. If doesn't fit - continue +// 7. If heap.is_empty() - doesn't fit with buffered +// 8. Apply lookup table +// 9. if fits - return Ok(tx), else return Err(Failed) +fn useless() {} diff --git a/magicblock-committor-service/src/transaction_preperator/utils.rs b/magicblock-committor-service/src/transaction_preperator/utils.rs index e69de29bb..3b4f3b1f3 100644 --- a/magicblock-committor-service/src/transaction_preperator/utils.rs +++ b/magicblock-committor-service/src/transaction_preperator/utils.rs @@ -0,0 +1,20 @@ +use solana_pubkey::Pubkey; +use solana_sdk::{ + address_lookup_table::state::AddressLookupTable, + message::AddressLookupTableAccount, transaction::VersionedTransaction, +}; + +/// Returns [`Vec`] where all TX accounts stored in ALT +pub fn estimate_lookup_tables_for_tx( + transaction: &VersionedTransaction, +) -> Vec { + transaction + .message + .static_account_keys() + .chunks(256) + .map(|addresses| AddressLookupTableAccount { + key: Pubkey::new_unique(), + addresses: addresses.to_vec(), + }) + .collect() +} diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs index 33ba3d664..50e13a68d 100644 --- a/magicblock-committor-service/src/transactions.rs +++ b/magicblock-committor-service/src/transactions.rs @@ -3,7 +3,7 @@ use std::collections::HashSet; use base64::{prelude::BASE64_STANDARD, Engine}; use dlp::args::{CommitStateArgs, CommitStateFromBufferArgs}; use magicblock_committor_program::{ - instruction::{create_close_ix, CreateCloseIxArgs}, + instruction_builder::close_buffer::{create_close_ix, CreateCloseIxArgs}, ChangedBundle, }; use solana_pubkey::Pubkey; @@ -296,7 +296,7 @@ fn encoded_tx_size( Ok(encoded.len()) } -fn serialize_and_encode_base64( +pub fn serialize_and_encode_base64( transaction: &impl SerializableTransaction, ) -> String { // SAFETY: runs statically @@ -508,7 +508,7 @@ mod test { let delegated_account_owner = Pubkey::new_unique(); let buffer_pda = Pubkey::new_unique(); let commit_args = CommitStateFromBufferArgs::default(); - vec![super::process_commits_ix( + vec![process_commits_ix( auth_pubkey, &pubkey, &delegated_account_owner, @@ -523,7 +523,7 @@ mod test { |auth_pubkey, committee, delegated_account_owner| { let buffer_pda = Pubkey::new_unique(); let commit_args = CommitStateFromBufferArgs::default(); - vec![super::process_commits_ix( + vec![process_commits_ix( auth_pubkey, &committee, &delegated_account_owner, diff --git a/magicblock-rpc/src/traits/rpc_full.rs b/magicblock-rpc/src/traits/rpc_full.rs index 2728e1051..618627cfc 100644 --- a/magicblock-rpc/src/traits/rpc_full.rs +++ b/magicblock-rpc/src/traits/rpc_full.rs @@ -185,3 +185,18 @@ pub trait Full { pubkey_strs: Option>, ) -> Result>; } + +// ideally +// 1. We add all of ScheduledL1Message on baselayer +// 2. We finalize them: +// 1. Runs committs per account +// 2. Runs actions(undelegate one actions) +// + +// That means +// Commits - shall be atomic(1 tx) +// Finalization - Shall be one per batch + +// Current solution: +// 1. We create a single commit tx, with multiple ixs +// 2. We create "finalize" tx diff --git a/magicblock-table-mania/src/manager.rs b/magicblock-table-mania/src/manager.rs index 7b8960066..c77ede8f1 100644 --- a/magicblock-table-mania/src/manager.rs +++ b/magicblock-table-mania/src/manager.rs @@ -180,74 +180,69 @@ impl TableMania { // Keep trying to store pubkeys until we're done while !remaining.is_empty() { // First try to use existing tables - let mut stored_in_existing = false; + let mut active_tables_write_lock = self.active_tables.write().await; + match self + .try_extend_existing_table( + &active_tables_write_lock, + &authority, + &mut remaining, + &mut tables_used, + ) + .await { - // Taking a write lock here to prevent multiple tasks from - // updating tables at the same time - let active_tables_write_lock = self.active_tables.write().await; - - // Try to use the last table if it's not full - if let Some(table) = active_tables_write_lock.last() { - if !table.is_full() { - if let Err(err) = self - .extend_table( - table, - authority, - &mut remaining, - &mut tables_used, - ) - .await - { - error!( - "Error extending table {}: {:?}", - table.table_address(), - err - ); - if extend_errors >= MAX_ALLOWED_EXTEND_ERRORS { - extend_errors += 1; - } else { - return Err(err); - } - } else { - stored_in_existing = true; - } + Ok(true) => continue, + Ok(false) => {} + Err(err) => { + if extend_errors >= MAX_ALLOWED_EXTEND_ERRORS { + extend_errors += 1; + } else { + return Err(err); } } } // If we couldn't use existing tables, we need to create a new one - if !stored_in_existing && !remaining.is_empty() { - // We write lock the active tables to ensure that while we create a new - // table the requests looking for an existing table to extend are blocked - let mut active_tables_write_lock = - self.active_tables.write().await; - - // Double-check if a new table was created while we were waiting for the lock - if let Some(table) = active_tables_write_lock.last() { - if !table.is_full() { - // Another task created a table we can use, so drop the write lock - // and try again with the read lock - drop(active_tables_write_lock); - continue; - } - } + // We write lock the active tables to ensure that while we create a new + // table the requests looking for an existing table to extend are blocked + // Create a new table and add it to active_tables + let table = self + .create_new_table_and_extend(authority, &mut remaining) + .await?; + + tables_used.insert(*table.table_address()); + active_tables_write_lock.push(table); + } - // Create a new table and add it to active_tables - let table = self - .create_new_table_and_extend(authority, &mut remaining) - .await?; + Ok(()) + } - tables_used.insert(*table.table_address()); - active_tables_write_lock.push(table); - } + /// Tries to extend last table + /// Returns [`true`] if the table isn't full at we were able to insert some keys + /// Returns [`false`] otherwise + async fn try_extend_existing_table( + &self, + active_tables: &Vec, + authority: &Keypair, + remaining: &mut Vec, + tables_used: &mut HashSet, + ) -> TableManiaResult { + // Try to use the last table if it's not full + let table = match active_tables.last() { + Some(table) if !table.is_full() => table, + _ => return Ok(false), + }; - // If we've stored all pubkeys, we're done - if remaining.is_empty() { - break; - } - } + self.extend_table(table, authority, remaining, tables_used) + .await + .inspect_err(|err| { + error!( + "Error extending table {}: {:?}", + table.table_address(), + err + ); + })?; - Ok(()) + Ok(true) } /// Extends the table to store as many of the provided pubkeys as possile. diff --git a/programs/magicblock/src/args.rs b/programs/magicblock/src/args.rs index 8de92d135..72d8df1f0 100644 --- a/programs/magicblock/src/args.rs +++ b/programs/magicblock/src/args.rs @@ -9,8 +9,9 @@ pub struct ActionArgs { #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct L1ActionArgs { pub args: ActionArgs, + pub escrow_authority: u8, // index of account authorizing action on actor pda pub destination_program: u8, // index of the account - pub accounts: Vec, // indices of account + pub accounts: Vec, // indices of account } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] diff --git a/programs/magicblock/src/lib.rs b/programs/magicblock/src/lib.rs index 59cbae23c..a53b70ccd 100644 --- a/programs/magicblock/src/lib.rs +++ b/programs/magicblock/src/lib.rs @@ -4,8 +4,9 @@ mod mutate_accounts; mod schedule_transactions; pub use magic_context::{FeePayerAccount, MagicContext}; pub mod args; -mod magic_schedule_l1_message; +pub mod magic_scheduled_l1_message; pub mod magicblock_instruction; +// TODO(edwin): isolate with features pub mod magicblock_processor; #[cfg(test)] mod test_utils; diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index b4bbb4e9a..916d163e4 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -10,7 +10,7 @@ use solana_sdk::{ transaction::Transaction, }; -use crate::magic_schedule_l1_message::{ +use crate::magic_scheduled_l1_message::{ CommitAndUndelegate, CommitType, CommittedAccountV2, MagicL1Message, ScheduledL1Message, ShortAccountMeta, UndelegateType, }; diff --git a/programs/magicblock/src/magic_schedule_l1_message.rs b/programs/magicblock/src/magic_schedule_l1_message.rs deleted file mode 100644 index 5f4e668c9..000000000 --- a/programs/magicblock/src/magic_schedule_l1_message.rs +++ /dev/null @@ -1,401 +0,0 @@ -use std::{cell::RefCell, collections::HashSet}; - -use serde::{Deserialize, Serialize}; -use solana_log_collector::ic_msg; -use solana_program_runtime::{ - __private::{Hash, InstructionError, ReadableAccount, TransactionContext}, - invoke_context::InvokeContext, -}; -use solana_sdk::{ - account::{Account, AccountSharedData}, - clock::Slot, - transaction::Transaction, -}; - -use crate::{ - args::{ - ActionArgs, CommitAndUndelegateArgs, CommitTypeArgs, L1ActionArgs, - MagicL1MessageArgs, UndelegateTypeArgs, - }, - instruction_utils::InstructionUtils, - utils::accounts::{ - get_instruction_account_short_meta_with_idx, - get_instruction_account_with_idx, get_instruction_pubkey_with_idx, - }, - Pubkey, -}; - -/// Context necessary for construction of Schedule Action -pub struct ConstructionContext<'a, 'ic> { - parent_program_id: Option, - signers: &'a HashSet, - pub transaction_context: &'a TransactionContext, - pub invoke_context: &'a mut InvokeContext<'ic>, -} - -impl<'a, 'ic> ConstructionContext<'a, 'ic> { - pub fn new( - parent_program_id: Option, - signers: &'a HashSet, - transaction_context: &'a TransactionContext, - invoke_context: &'a mut InvokeContext<'ic>, - ) -> Self { - Self { - parent_program_id, - signers, - transaction_context, - invoke_context, - } - } -} - -/// Scheduled action to be executed on base layer -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ScheduledL1Message { - pub id: u64, - pub slot: Slot, - pub blockhash: Hash, - pub action_sent_transaction: Transaction, - pub payer: Pubkey, - // Scheduled action - pub l1_message: MagicL1Message, -} - -impl ScheduledL1Message { - pub fn try_new<'a>( - args: &MagicL1MessageArgs, - commit_id: u64, - slot: Slot, - payer_pubkey: &Pubkey, - context: &ConstructionContext<'a, '_>, - ) -> Result { - let action = MagicL1Message::try_from_args(args, &context)?; - - let blockhash = context.invoke_context.environment_config.blockhash; - let action_sent_transaction = - InstructionUtils::scheduled_commit_sent(commit_id, blockhash); - Ok(ScheduledL1Message { - id: commit_id, - slot, - blockhash, - payer: *payer_pubkey, - action_sent_transaction, - l1_message: action, - }) - } -} - -// Action that user wants to perform on base layer -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub enum MagicL1Message { - /// Actions without commitment or undelegation - L1Actions(Vec), - Commit(CommitType), - CommitAndUndelegate(CommitAndUndelegate), -} - -impl MagicL1Message { - pub fn try_from_args<'a>( - args: &MagicL1MessageArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - match args { - MagicL1MessageArgs::L1Actions(l1_actions) => { - let l1_actions = l1_actions - .iter() - .map(|args| L1Action::try_from_args(args, context)) - .collect::, InstructionError>>()?; - Ok(MagicL1Message::L1Actions(l1_actions)) - } - MagicL1MessageArgs::Commit(type_) => { - let commit = CommitType::try_from_args(type_, context)?; - Ok(MagicL1Message::Commit(commit)) - } - MagicL1MessageArgs::CommitAndUndelegate(type_) => { - let commit_and_undelegate = - CommitAndUndelegate::try_from_args(type_, context)?; - Ok(MagicL1Message::CommitAndUndelegate(commit_and_undelegate)) - } - } - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CommitAndUndelegate { - pub commit_action: CommitType, - pub undelegate_action: UndelegateType, -} - -impl CommitAndUndelegate { - pub fn try_from_args<'a>( - args: &CommitAndUndelegateArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - let commit_action = - CommitType::try_from_args(&args.commit_type, context)?; - let undelegate_action = - UndelegateType::try_from_args(&args.undelegate_type, context)?; - - Ok(Self { - commit_action, - undelegate_action, - }) - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ProgramArgs { - pub escrow_index: u8, - pub data: Vec, -} - -impl From for ProgramArgs { - fn from(value: ActionArgs) -> Self { - Self { - escrow_index: value.escrow_index, - data: value.data, - } - } -} - -impl From<&ActionArgs> for ProgramArgs { - fn from(value: &ActionArgs) -> Self { - value.clone().into() - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ShortAccountMeta { - pub pubkey: Pubkey, - pub is_writable: bool, -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct L1Action { - pub destination_program: Pubkey, - pub data_per_program: ProgramArgs, - pub account_metas_per_program: Vec, -} - -impl L1Action { - pub fn try_from_args<'a>( - args: &L1ActionArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - let destination_program_pubkey = *get_instruction_pubkey_with_idx( - context.transaction_context, - args.destination_program as u16, - )?; - let destination_program = get_instruction_account_with_idx( - context.transaction_context, - args.destination_program as u16, - )?; - - if !destination_program.borrow().executable() { - ic_msg!( - context.invoke_context, - &format!( - "L1Action: destination_program must be an executable. got: {}", - destination_program_pubkey - ) - ); - return Err(InstructionError::AccountNotExecutable); - } - - let account_metas = args - .accounts - .iter() - .map(|i| { - get_instruction_account_short_meta_with_idx( - context.transaction_context, - *i as u16, - ) - }) - .collect::, InstructionError>>()?; - - Ok(L1Action { - destination_program: destination_program_pubkey, - data_per_program: args.args.clone().into(), - account_metas_per_program: account_metas, - }) - } -} - -type CommittedAccountRef<'a> = (Pubkey, &'a RefCell); -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CommittedAccountV2 { - pub pubkey: Pubkey, - pub account: Account, -} - -impl<'a> From> for CommittedAccountV2 { - fn from(value: CommittedAccountRef<'a>) -> Self { - Self { - pubkey: value.0, - account: value.1.borrow().to_owned().into(), - } - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub enum CommitType { - /// Regular commit without actions - /// TODO: feels like ShortMeta isn't needed - Standalone(Vec), // accounts to commit - /// Commits accounts and runs actions - WithL1Actions { - committed_accounts: Vec, - l1_actions: Vec, - }, -} - -impl CommitType { - // TODO: move to processor - fn validate_accounts<'a>( - accounts: &[CommittedAccountRef], - context: &ConstructionContext<'a, '_>, - ) -> Result<(), InstructionError> { - accounts.iter().try_for_each(|(pubkey, account)| { - let owner = *account.borrow().owner(); - if context.parent_program_id != Some(owner) && !context.signers.contains(pubkey) { - match context.parent_program_id { - None => { - ic_msg!( - context.invoke_context, - "ScheduleCommit ERR: failed to find parent program id" - ); - Err(InstructionError::InvalidInstructionData) - } - Some(parent_id) => { - ic_msg!( - context.invoke_context, - "ScheduleCommit ERR: account {} must be owned by {} or be a signer, but is owned by {}", - pubkey, parent_id, owner - ); - Err(InstructionError::InvalidAccountOwner) - } - } - } else { - Ok(()) - } - }) - } - - // I delegated an account, now the owner is delegation program - // parent_program_id != Some(&acc_owner) should fail. or any modification on ER - // ER perceives owner as old one, hence for ER those are valid txs - // On commit_and_undelegate and commit we will set owner to DLP, for latter temparerily - // The owner shall be real owner on chain - // So first: - // 1. Validate - // 2. Fetch current account states - // TODO: 3. switch the ownership - pub fn extract_commit_accounts<'a>( - account_indices: &[u8], - transaction_context: &'a TransactionContext, - ) -> Result>, InstructionError> { - account_indices - .iter() - .map(|i| { - let account = get_instruction_account_with_idx( - transaction_context, - *i as u16, - )?; - let pubkey = *get_instruction_pubkey_with_idx( - transaction_context, - *i as u16, - )?; - - Ok((pubkey, account)) - }) - .collect::>() - } - - pub fn try_from_args<'a>( - args: &CommitTypeArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - match args { - CommitTypeArgs::Standalone(accounts) => { - let committed_accounts_ref = Self::extract_commit_accounts( - accounts, - context.transaction_context, - )?; - Self::validate_accounts(&committed_accounts_ref, context)?; - let committed_accounts = committed_accounts_ref - .into_iter() - .map(|el| { - let mut committed_account: CommittedAccountV2 = - el.into(); - committed_account.account.owner = context - .parent_program_id - .unwrap_or(committed_account.account.owner); - - committed_account - }) - .collect(); - - Ok(CommitType::Standalone(committed_accounts)) - } - CommitTypeArgs::WithL1Actions { - committed_accounts, - l1_actions, - } => { - let committed_accounts_ref = Self::extract_commit_accounts( - committed_accounts, - context.transaction_context, - )?; - Self::validate_accounts(&committed_accounts_ref, context)?; - - let l1_actions = l1_actions - .iter() - .map(|args| L1Action::try_from_args(args, context)) - .collect::, InstructionError>>()?; - let committed_accounts = committed_accounts_ref - .into_iter() - .map(|el| { - let mut committed_account: CommittedAccountV2 = - el.into(); - committed_account.account.owner = context - .parent_program_id - .unwrap_or(committed_account.account.owner); - - committed_account - }) - .collect(); - - Ok(CommitType::WithL1Actions { - committed_accounts, - l1_actions, - }) - } - } - } -} - -/// No CommitedAccounts since it is only used with CommitAction. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub enum UndelegateType { - Standalone, - WithL1Actions(Vec), -} - -impl UndelegateType { - pub fn try_from_args<'a>( - args: &UndelegateTypeArgs, - context: &ConstructionContext<'a, '_>, - ) -> Result { - match args { - UndelegateTypeArgs::Standalone => Ok(UndelegateType::Standalone), - UndelegateTypeArgs::WithL1Actions { l1_actions } => { - let l1_actions = l1_actions - .iter() - .map(|l1_actions| { - L1Action::try_from_args(l1_actions, context) - }) - .collect::, InstructionError>>()?; - Ok(UndelegateType::WithL1Actions(l1_actions)) - } - } - } -} diff --git a/programs/magicblock/src/magic_scheduled_l1_message.rs b/programs/magicblock/src/magic_scheduled_l1_message.rs index f7c53de14..02222ca1f 100644 --- a/programs/magicblock/src/magic_scheduled_l1_message.rs +++ b/programs/magicblock/src/magic_scheduled_l1_message.rs @@ -141,6 +141,10 @@ impl CommitAndUndelegate { undelegate_action, }) } + + pub fn get_committed_accounts(&self) -> &Vec { + self.commit_action.get_committed_accounts() + } } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -173,6 +177,7 @@ pub struct ShortAccountMeta { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct L1Action { pub destination_program: Pubkey, + pub escrow_authority: Pubkey, pub data_per_program: ProgramArgs, pub account_metas_per_program: Vec, } @@ -190,7 +195,6 @@ impl L1Action { context.transaction_context, args.destination_program as u16, )?; - if !destination_program.borrow().executable() { ic_msg!( context.invoke_context, @@ -202,6 +206,24 @@ impl L1Action { return Err(InstructionError::AccountNotExecutable); } + // Since action on L1 performed on behalf of some escrow + // We need to ensure that action was authorized by legit owner + let authority_pubkey = get_instruction_pubkey_with_idx( + context.transaction_context, + args.destination_program as u16, + )?; + if !context.signers.contains(authority_pubkey) { + ic_msg!( + context.invoke_context, + &format!( + "L1Action: authority pubkey must sign transaction: {}", + authority_pubkey + ) + ); + + return Err(InstructionError::MissingRequiredSignature); + } + let account_metas = args .accounts .iter() @@ -215,6 +237,7 @@ impl L1Action { Ok(L1Action { destination_program: destination_program_pubkey, + escrow_authority: *authority_pubkey, data_per_program: args.args.clone().into(), account_metas_per_program: account_metas, }) @@ -371,6 +394,15 @@ impl CommitType { } } } + + pub fn get_committed_accounts(&self) -> &Vec { + match self { + Self::Standalone(committed_accounts) => committed_accounts, + Self::WithL1Actions { + committed_accounts, .. + } => committed_accounts, + } + } } /// No CommitedAccounts since it is only used with CommitAction. diff --git a/programs/magicblock/src/schedule_transactions/mod.rs b/programs/magicblock/src/schedule_transactions/mod.rs index e03182e92..38b4eae5f 100644 --- a/programs/magicblock/src/schedule_transactions/mod.rs +++ b/programs/magicblock/src/schedule_transactions/mod.rs @@ -23,6 +23,7 @@ use solana_program_runtime::{ use crate::utils::accounts::get_instruction_pubkey_with_idx; +// TODO(edwin): is reset on restart pub(crate) static MESSAGE_ID: AtomicU64 = AtomicU64::new(0); pub fn check_magic_context_id( diff --git a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs index 19e424233..fe4d7801e 100644 --- a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs +++ b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs @@ -85,7 +85,8 @@ pub fn process_accept_scheduled_commits( "AcceptScheduledCommits: accepted {} scheduled commit(s)", scheduled_commits.len() ); - TransactionScheduler::default().accept_scheduled_actions(scheduled_commits); + TransactionScheduler::default() + .accept_scheduled_l1_message(scheduled_commits); // 4. Serialize and store the updated `MagicContext` account // Zero fill account before updating data diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs index 207b23cfa..cdc3d33e3 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs @@ -9,7 +9,7 @@ use solana_sdk::{ }; use crate::{ - magic_schedule_l1_message::{ + magic_scheduled_l1_message::{ CommitAndUndelegate, CommitType, CommittedAccountV2, MagicL1Message, ScheduledL1Message, UndelegateType, }, @@ -131,7 +131,6 @@ pub(crate) fn process_schedule_commit( get_instruction_pubkey_with_idx(transaction_context, idx as u16)?; let acc = get_instruction_account_with_idx(transaction_context, idx as u16)?; - { let acc_owner = *acc.borrow().owner(); if parent_program_id != Some(&acc_owner) diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs index 22cf97c59..3b03338f4 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs @@ -19,7 +19,7 @@ use test_tools_core::init_logger; use crate::{ magic_context::MagicContext, - magic_schedule_l1_message::ScheduledL1Message, + magic_scheduled_l1_message::ScheduledL1Message, magicblock_instruction::MagicBlockInstruction, schedule_transactions::transaction_scheduler::TransactionScheduler, test_utils::{ensure_started_validator, process_instruction}, @@ -238,7 +238,7 @@ fn assert_first_commit( mod tests { use super::*; use crate::{ - magic_schedule_l1_message::MagicL1Message, + magic_scheduled_l1_message::MagicL1Message, utils::instruction_utils::InstructionUtils, }; diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs b/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs index bad1dd221..fcc016630 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs @@ -9,7 +9,7 @@ use solana_sdk::{ use crate::{ args::MagicL1MessageArgs, - magic_schedule_l1_message::{ConstructionContext, ScheduledL1Message}, + magic_scheduled_l1_message::{ConstructionContext, ScheduledL1Message}, schedule_transactions::{ check_magic_context_id, schedule_l1_message_processor::schedule_l1_message_processor, diff --git a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs index df0b6d36b..29a878858 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs @@ -5,7 +5,7 @@ use solana_sdk::{ use crate::{ args::MagicL1MessageArgs, - magic_schedule_l1_message::{CommitType, ConstructionContext}, + magic_scheduled_l1_message::{CommitType, ConstructionContext}, utils::account_actions::set_account_owner_to_delegation_program, }; diff --git a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs index e6ed2ba40..b5551c101 100644 --- a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs +++ b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs @@ -13,12 +13,12 @@ use solana_sdk::{ }; use crate::{ - magic_context::MagicContext, magic_schedule_l1_message::ScheduledL1Message, + magic_context::MagicContext, magic_scheduled_l1_message::ScheduledL1Message, }; #[derive(Clone)] pub struct TransactionScheduler { - scheduled_action: Arc>>, + scheduled_l1_message: Arc>>, } impl Default for TransactionScheduler { @@ -31,7 +31,7 @@ impl Default for TransactionScheduler { Default::default(); } Self { - scheduled_action: SCHEDULED_ACTION.clone(), + scheduled_l1_message: SCHEDULED_ACTION.clone(), } } } @@ -57,8 +57,11 @@ impl TransactionScheduler { Ok(()) } - pub fn accept_scheduled_actions(&self, commits: Vec) { - self.scheduled_action + pub fn accept_scheduled_l1_message( + &self, + commits: Vec, + ) { + self.scheduled_l1_message .write() .expect("scheduled_action lock poisoned") .extend(commits); @@ -69,7 +72,7 @@ impl TransactionScheduler { payer: &Pubkey, ) -> Vec { let commits = self - .scheduled_action + .scheduled_l1_message .read() .expect("scheduled_action lock poisoned"); @@ -82,7 +85,7 @@ impl TransactionScheduler { pub fn take_scheduled_actions(&self) -> Vec { let mut lock = self - .scheduled_action + .scheduled_l1_message .write() .expect("scheduled_action lock poisoned"); mem::take(&mut *lock) @@ -90,7 +93,7 @@ impl TransactionScheduler { pub fn scheduled_actions_len(&self) -> usize { let lock = self - .scheduled_action + .scheduled_l1_message .read() .expect("scheduled_action lock poisoned"); @@ -99,7 +102,7 @@ impl TransactionScheduler { pub fn clear_scheduled_actions(&self) { let mut lock = self - .scheduled_action + .scheduled_l1_message .write() .expect("scheduled_action lock poisoned"); lock.clear(); diff --git a/programs/magicblock/src/utils/accounts.rs b/programs/magicblock/src/utils/accounts.rs index 4c9778e84..a161d79de 100644 --- a/programs/magicblock/src/utils/accounts.rs +++ b/programs/magicblock/src/utils/accounts.rs @@ -11,7 +11,7 @@ use solana_sdk::{ transaction_context::TransactionContext, }; -use crate::magic_schedule_l1_message::ShortAccountMeta; +use crate::magic_scheduled_l1_message::ShortAccountMeta; pub(crate) fn find_tx_index_of_instruction_account( invoke_context: &InvokeContext, diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 20c285b89..b5fedf62b 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1150,7 +1150,7 @@ dependencies = [ "conjunto-addresses", "conjunto-core", "conjunto-providers", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c)", "serde", "solana-rpc-client", "solana-rpc-client-api", @@ -2949,7 +2949,7 @@ dependencies = [ "log", "magicblock-config", "magicblock-core", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0", "rayon", "serde", "solana-pubkey", @@ -3562,7 +3562,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3699,12 +3699,16 @@ dependencies = [ name = "magicblock-committor-service" version = "0.1.2" dependencies = [ + "anyhow", + "async-trait", "base64 0.21.7", "bincode", "borsh 1.5.7", + "futures-util", "log", "magicblock-committor-program", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0", + "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", "rusqlite", @@ -3742,6 +3746,21 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "magicblock-delegation-program" +version = "1.0.0" +dependencies = [ + "bincode", + "borsh 1.5.7", + "bytemuck", + "num_enum", + "paste", + "solana-curve25519", + "solana-program", + "solana-security-txt", + "thiserror 1.0.69", +] + [[package]] name = "magicblock-delegation-program" version = "1.0.0" @@ -5728,7 +5747,7 @@ dependencies = [ "log", "magicblock-committor-program", "magicblock-committor-service", - "magicblock-delegation-program", + "magicblock-delegation-program 1.0.0", "magicblock-rpc-client", "program-flexi-counter", "solana-account", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index f8d6596f6..5d56b6fc6 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -38,7 +38,7 @@ magicblock-core = { path = "../magicblock-core" } magicblock-committor-program = { path = "../magicblock-committor-program", features = [ "no-entrypoint", ] } -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } +magicblock-delegation-program = { path = "../../delegation-program" } magicblock-committor-service = { path = "../magicblock-committor-service" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } magicblock-table-mania = { path = "../magicblock-table-mania" } From 18781d5e3be93ad0a76a7e7238762670fe687997 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 8 Jul 2025 13:45:44 +0900 Subject: [PATCH 080/199] refactor: code cleanup --- .../src/instruction.rs | 16 ++++----- .../src/instruction_builder/realloc_buffer.rs | 35 ++++++++----------- .../src/instruction_chunks.rs | 7 ++-- .../src/state/chunks.rs | 5 +++ 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/magicblock-committor-program/src/instruction.rs b/magicblock-committor-program/src/instruction.rs index d58dc4a6e..d0bd7d36f 100644 --- a/magicblock-committor-program/src/instruction.rs +++ b/magicblock-committor-program/src/instruction.rs @@ -110,8 +110,8 @@ pub const IX_INIT_SIZE: u16 = 8 + // buffer_account_size: u64, 8 + - // blockhash: Hash, - HASH_BYTES as u16 + + // commit_id: u64, + 8 + // chunks_bump: u8, 1 + // buffer_bump: u8, @@ -128,8 +128,8 @@ pub const IX_REALLOC_SIZE: u16 = 32 + // buffer_account_size: u64, 8 + - // blockhash: Hash, - HASH_BYTES as u16 + + // commit_id: u64, + 8 + // buffer_bump: u8, 1 + // invocation_count: u16, @@ -140,8 +140,8 @@ pub const IX_REALLOC_SIZE: u16 = pub const IX_WRITE_SIZE_WITHOUT_CHUNKS: u16 = // pubkey: Pubkey, 32+ - // blockhash: Hash, - HASH_BYTES as u16 + + // commit_id: u64, + 8 + // chunks_bump: u8, 1 + // buffer_bump: u8, @@ -152,8 +152,8 @@ pub const IX_WRITE_SIZE_WITHOUT_CHUNKS: u16 = pub const IX_CLOSE_SIZE: u16 = // pubkey: Pubkey, 32 + - // blockhash: Hash, - HASH_BYTES as u16 + + // commit_id: u64, + 8 + // chunks_bump: u8, 1 + // buffer_bump: u8, diff --git a/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs b/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs index 22ef37f0b..a1f5a9d95 100644 --- a/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs +++ b/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs @@ -1,7 +1,10 @@ use solana_program::instruction::{AccountMeta, Instruction}; use solana_pubkey::Pubkey; -use crate::{consts, instruction::CommittorInstruction, pdas}; +use crate::{ + consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE, + instruction::CommittorInstruction, pdas, +}; // ----------------- // create_realloc_buffer_ix @@ -25,20 +28,14 @@ pub fn create_realloc_buffer_ixs( ) -> Vec { // We already allocated once during Init and only need to realloc // if the buffer is larger than [consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE] - if args.buffer_account_size - <= consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64 + if args.buffer_account_size <= MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64 { return vec![]; } - let remaining_size = args.buffer_account_size as i128 - - consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128; - - // A) We just need to realloc once - if remaining_size <= consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as i128 - { - return vec![create_realloc_buffer_ix(args, 1)]; - } + // Use remaining since [`MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE`] allocated at init + let remaining_size = args.buffer_account_size + - MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64; // B) We need to realloc multiple times // SAFETY; remaining size > consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE @@ -49,16 +46,14 @@ pub fn create_realloc_buffer_ixs_to_add_remaining( args: &CreateReallocBufferIxArgs, remaining_size: u64, ) -> Vec { - let invocation_count = (remaining_size as f64 - / consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as f64) - .ceil() as u16; - - let mut ixs = vec![]; - for i in 0..invocation_count { - ixs.push(create_realloc_buffer_ix(args.clone(), i + 1)); - } + let remaining_invocation_count = + (remaining_size + MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64 - 1) + / MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64; - ixs + // Generate one instruction per needed allocation + (1..=remaining_invocation_count) + .map(|i| create_realloc_buffer_ix(args.clone(), i as u16)) + .collect() } fn create_realloc_buffer_ix( diff --git a/magicblock-committor-program/src/instruction_chunks.rs b/magicblock-committor-program/src/instruction_chunks.rs index fe4622f45..4f698db0b 100644 --- a/magicblock-committor-program/src/instruction_chunks.rs +++ b/magicblock-committor-program/src/instruction_chunks.rs @@ -16,13 +16,10 @@ pub fn chunk_realloc_ixs( start_size: u16, ) { let mut total_size = start_size; - loop { - total_size += IX_REALLOC_SIZE; - if total_size >= MAX_INSTRUCTION_DATA_SIZE { - return; - } + while total_size + IX_REALLOC_SIZE < MAX_INSTRUCTION_DATA_SIZE { if let Some(realloc) = reallocs.pop() { chunk.push(realloc); + total_size += IX_REALLOC_SIZE; } else { return; } diff --git a/magicblock-committor-program/src/state/chunks.rs b/magicblock-committor-program/src/state/chunks.rs index 96fb81971..990b819c9 100644 --- a/magicblock-committor-program/src/state/chunks.rs +++ b/magicblock-committor-program/src/state/chunks.rs @@ -43,6 +43,11 @@ impl Chunks { } } + pub fn from_data_length(data_len: usize, chunk_size: u16) -> Self { + let chunk_count = (data_len + chunk_size as usize - 1) / chunk_size as usize; + Self::new(chunk_count, chunk_size) + } + /// Calculates the minimum number of bytes needed to store `count` boolean values in a bitfield. /// /// Each boolean is stored as a single bit, packing 8 booleans per byte. From b40797da93ef5320a0d2217bff9724ac62eae23b Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 8 Jul 2025 17:53:47 +0900 Subject: [PATCH 081/199] feat: buffer preparations in DeliveryPreparator --- .../src/state/chunks.rs | 3 +- .../src/commit/common.rs | 4 +- .../delivery_preparator.rs | 292 ++++++++++++++++-- .../transaction_preperator/task_builder.rs | 123 +++++++- .../transaction_preparator.rs | 9 + 5 files changed, 392 insertions(+), 39 deletions(-) diff --git a/magicblock-committor-program/src/state/chunks.rs b/magicblock-committor-program/src/state/chunks.rs index 990b819c9..5ed93a648 100644 --- a/magicblock-committor-program/src/state/chunks.rs +++ b/magicblock-committor-program/src/state/chunks.rs @@ -44,7 +44,8 @@ impl Chunks { } pub fn from_data_length(data_len: usize, chunk_size: u16) -> Self { - let chunk_count = (data_len + chunk_size as usize - 1) / chunk_size as usize; + let chunk_count = + (data_len + chunk_size as usize - 1) / chunk_size as usize; Self::new(chunk_count, chunk_size) } diff --git a/magicblock-committor-service/src/commit/common.rs b/magicblock-committor-service/src/commit/common.rs index f666ccba5..50c3f7ace 100644 --- a/magicblock-committor-service/src/commit/common.rs +++ b/magicblock-committor-service/src/commit/common.rs @@ -77,7 +77,7 @@ pub(crate) fn get_accounts_to_undelegate( /// Returns the signature of the transaction. pub(crate) async fn send_and_confirm( rpc_client: MagicblockRpcClient, - authority: Keypair, + authority: &Keypair, ixs: Vec, task_desc: String, latest_blockhash: Option, @@ -174,7 +174,7 @@ pub(crate) async fn send_and_confirm( }; let tx = match VersionedTransaction::try_new( VersionedMessage::V0(versioned_msg), - &[&authority], + &[authority], ) { Ok(tx) => tx, Err(err) => { diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 5a1f8484e..a914835d2 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -1,16 +1,50 @@ -use std::future::Future; +use std::{future::Future, ptr::write, sync::Arc, time::Duration}; +use anyhow::anyhow; +use borsh::BorshDeserialize; use futures_util::future::{join, join_all}; -use magicblock_rpc_client::MagicblockRpcClient; +use log::{error, warn}; +use magicblock_committor_program::{ + instruction_builder::{ + init_buffer::{create_init_ix, CreateInitIxArgs}, + realloc_buffer::{ + create_realloc_buffer_ixs, CreateReallocBufferIxArgs, + }, + }, + Chunks, CommitableAccount, +}; +use magicblock_rpc_client::{ + MagicBlockRpcClientError, MagicBlockSendTransactionConfig, + MagicblockRpcClient, +}; use magicblock_table_mania::TableMania; -use solana_sdk::message::AddressLookupTableAccount; +use solana_account::ReadableAccount; +use solana_rpc_client_api::client_error::reqwest::Version; +use solana_sdk::{ + hash::Hash, + instruction::Instruction, + message::{ + v0::Message, AddressLookupTableAccount, CompileError, VersionedMessage, + }, + signature::Keypair, + signer::{Signer, SignerError}, + transaction::VersionedTransaction, +}; +use tokio::{task::JoinSet, time::sleep}; -use crate::transaction_preperator::{ - delivery_strategist::{TaskDeliveryStrategy, TransactionStrategy}, - error::PreparatorResult, - task_builder::Task, +use crate::{ + consts::MAX_WRITE_CHUNK_SIZE, + error::{CommitAccountError, CommitAccountResult}, + persist::CommitStrategy, + transaction_preperator::{ + delivery_strategist::{TaskDeliveryStrategy, TransactionStrategy}, + error::PreparatorResult, + task_builder::{CommitTask, Task, TaskPreparationInfo}, + }, + CommitInfo, ComputeBudgetConfig, }; +// TODO: likely separate errors type PreparationFuture = impl Future>; pub struct DeliveryPreparationResult { @@ -20,48 +54,268 @@ pub struct DeliveryPreparationResult { pub struct DeliveryPreparator { rpc_client: MagicblockRpcClient, table_mania: TableMania, + compute_budget_config: ComputeBudgetConfig, // TODO(edwin): needed? } impl DeliveryPreparator { pub fn new( rpc_client: MagicblockRpcClient, table_mania: TableMania, + compute_budget_config: ComputeBudgetConfig, ) -> Self { Self { rpc_client, table_mania, + compute_budget_config, } } /// Prepares buffers and necessary pieces for optimized TX pub async fn prepare_for_delivery( &self, + authority: &Keypair, strategy: &TransactionStrategy, - ) -> DeliveryPreparationResult { + ) -> DeliveryPreparatorResult<()> { let preparation_futures = strategy .task_strategies .iter() - .filter_map(|strategy| match strategy { - TaskDeliveryStrategy::Args(_) => None, - TaskDeliveryStrategy::Buffer(task) => Some(task), + .map(|task| self.prepare_task(authority, task)); + + let fut1 = join_all(preparation_futures); + let fut2 = if strategy.use_lookup_table { + self.prepare_lookup_tables(&strategy.task_strategies) + } else { + std::future::ready(Ok(())) + }; + let (res1, res2) = join(fut1, fut2).await; + res1.into_iter().collect::, _>>()?; + res2?; + Ok(()) + } + + /// Prepares necessary parts for TX if needed, otherwise returns immediately + // TODO(edwin): replace with interfaces + async fn prepare_task( + &self, + authority: &Keypair, + task: &TaskDeliveryStrategy, + ) -> DeliveryPreparatorResult<()> { + let TaskDeliveryStrategy::Buffer(task) = task else { + return Ok(()); + }; + let Some(preparation_info) = + task.get_preparation_instructions(authority) + else { + return Ok(()); + }; + + // Initialize buffer account. Init + reallocs + self.initialize_buffer_account(authority, task, &preparation_info) + .await?; + // Writing chunks with some retries. Stol + self.write_buffer_with_retries::<5>(authority, &preparation_info) + .await?; + + Ok(()) + } + + /// Initializes buffer account for future writes + async fn initialize_buffer_account( + &self, + authority: &Keypair, + task: &Task, + preparation_info: &TaskPreparationInfo, + ) -> DeliveryPreparatorResult<()> { + let preparation_instructions = + task.instructions_from_info(&preparation_info); + let preparation_instructions = preparation_instructions + .into_iter() + .enumerate() + .map(|(i, ixs)| { + let mut ixs_with_budget = if i == 0 { + let init_budget_ixs = self + .compute_budget_config + .buffer_init + .instructions(ixs.len() - 1); + init_budget_ixs + } else { + let realloc_budget_ixs = self + .compute_budget_config + .buffer_realloc + .instructions(ixs.len() - 1); + realloc_budget_ixs + }; + ixs_with_budget.extend(ixs.into_iter()); + ixs_with_budget }) - .map(|task| self.prepare_buffer(task)); - // .collect::>>>(); + .collect::>(); + + // Initialization & reallocs + for instructions in preparation_instructions { + self.send_ixs_with_retry::<2>(&instructions, authority) + .await?; + } + + Ok(()) + } + + /// Based on Chunks state, try MAX_RETRIES to fill buffer + async fn write_buffer_with_retries( + &self, + authority: &Keypair, + info: &TaskPreparationInfo, + ) -> DeliveryPreparatorResult<()> { + let mut last_error = + Error::InternalError(anyhow!("ZeroRetriesRequested")); + for _ in 0..MAX_RETRIES { + let chunks = + match self.rpc_client.get_account(&info.chunks_pda).await { + Ok(Some(account)) => { + Chunks::try_from_slice(account.data())? + } + Ok(None) => { + error!( + "Chunks PDA does not exist for writing. pda: {}", + info.chunks_pda + ); + return Err(Error::InternalError(anyhow!( + "Chunks PDA does not exist for writing. pda: {}", + info.chunks_pda + ))); + } + Err(err) => { + last_error = err.into(); + sleep(Duration::from_millis(100)).await; + continue; + } + }; - join_all(preparation_futures); - join() + match self + .write_missing_chunks( + authority, + &chunks, + &info.write_instructions, + ) + .await + { + Ok(()) => return Ok(()), + Err(err) => { + error!("Error on write missing chunks attempt: {:?}", err); + last_error = err + } + } + } + + Err(last_error) } - async fn prepare_buffer(&self, task: &Task) -> PreparatorResult<()> { - todo!(); + /// Extract & write missing chunks asynchronously + async fn write_missing_chunks( + &self, + authority: &Keypair, + chunks: &Chunks, + write_instructions: &[Instruction], + ) -> DeliveryPreparatorResult<()> { + if write_instructions.len() != chunks.count() { + let err = anyhow!("Chunks count mismatches write instruction! chunks: {}, ixs: {}", write_instructions.len(), chunks.count()); + error!(err.to_string()); + return Err(Error::InternalError(err)); + } + + let mut join_set = JoinSet::new(); + let missing_chunks = chunks.get_missing_chunks(); + for missing_index in missing_chunks { + let instruction = write_instructions[missing_index].clone(); + let mut instructions = self + .compute_budget_config + .buffer_write + .instructions(instruction.data.len()); + instructions.push(instruction); + join_set.spawn(async move { + self.send_ixs_with_retry::<2>(&write_instructions, authority) + .await + .inspect_err(|err| { + error!("Error writing into buffect account: {:?}", err) + }) + }); + } + + join_set + .join_all() + .await + .iter() + .collect::, _>>()?; + Ok(()) + } + + // TODO(edwin): move somewhere appropritate + // CommitProcessor::init_accounts analog + async fn send_ixs_with_retry( + &self, + instructions: &[Instruction], + authority: &Keypair, + ) -> DeliveryPreparatorResult<()> { + let mut last_error = + Error::InternalError(anyhow!("ZeroRetriesRequested")); + for _ in 0..MAX_RETRIES { + match self.try_send_ixs(instructions, authority).await { + Ok(()) => return Ok(()), + Err(err) => last_error = err, + } + sleep(Duration::from_millis(200)).await; + } + + Err(last_error) + } + + async fn try_send_ixs( + &self, + instructions: &[Instruction], + authority: &Keypair, + ) -> DeliveryPreparatorResult<()> { + let latest_block_hash = self.rpc_client.get_latest_blockhash().await?; + let message = Message::try_compile( + &authority.pubkey(), + instructions, + &vec![], + latest_block_hash, + )?; + let transaction = VersionedTransaction::try_new( + VersionedMessage::V0(message), + &[authority], + )?; + + self.rpc_client + .send_transaction( + &transaction, + &MagicBlockSendTransactionConfig::ensure_committed(), + ) + .await?; Ok(()) } async fn prepare_lookup_tables( &self, - strategies: Vec, - ) -> PreparatorResult> { + strategies: &[TaskDeliveryStrategy], + ) -> DeliveryPreparatorResult> { // self.table_mania. todo!() } } + +// TODO(edwin): properly define these for TransactionPreparator interface +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("InternalError: {0}")] + InternalError(anyhow::Error), + #[error("BorshError: {0}")] + BorshError(#[from] std::io::Error), + #[error("TransactionCreationError: {0}")] + TransactionCreationError(#[from] CompileError), + #[error("TransactionSigningError: {0]")] + TransactionSigningError(#[from] SignerError), + #[error("FailedToPrepareBufferError: {0}")] + FailedToPrepareBufferError(#[from] MagicBlockRpcClientError), +} + +pub type DeliveryPreparatorResult = Result; diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs index d282763ca..ec82264d9 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_builder.rs @@ -1,11 +1,27 @@ use dlp::args::{CallHandlerArgs, CommitStateArgs, CommitStateFromBufferArgs}; +use magicblock_committor_program::{ + instruction_builder::{ + init_buffer::{create_init_ix, CreateInitIxArgs}, + realloc_buffer::{ + create_realloc_buffer_ixs, CreateReallocBufferIxArgs, + }, + write_buffer::{create_write_ix, CreateWriteIxArgs}, + }, + instruction_chunks::chunk_realloc_ixs, + ChangesetChunks, Chunks, +}; use magicblock_program::magic_scheduled_l1_message::{ CommitAndUndelegate, CommitType, CommittedAccountV2, L1Action, MagicL1Message, ScheduledL1Message, UndelegateType, }; use solana_pubkey::Pubkey; -use solana_sdk::instruction::{AccountMeta, Instruction}; +use solana_sdk::{ + instruction::{AccountMeta, Instruction}, + signature::Keypair, + signer::Signer, +}; +use crate::consts::MAX_WRITE_CHUNK_SIZE; // pub trait PossibleTaskTrait { // fn instruction() -> Instruction; // fn decrease(self: Box) -> Result, Box>; @@ -13,14 +29,25 @@ use solana_sdk::instruction::{AccountMeta, Instruction}; // fn prepare(self: Box) -> Option>; // } +pub struct TaskPreparationInfo { + pub chunks_pda: Pubkey, + pub buffer_pda: Pubkey, + pub init_instruction: Instruction, + pub realloc_instructions: Vec, + pub write_instructions: Vec, +} + +// TODO(edwin): commit_id is common thing, extract #[derive(Clone)] pub struct CommitTask { - pub allow_undelegatio: bool, + pub commit_id: u64, + pub allow_undelegation: bool, pub committed_account: CommittedAccountV2, } #[derive(Clone)] pub struct UndelegateTask { + pub commit_id: u64, pub delegated_account: Pubkey, pub owner_program: Pubkey, pub rent_reimbursement: Pubkey, @@ -28,6 +55,7 @@ pub struct UndelegateTask { #[derive(Clone)] pub struct FinalizeTask { + pub commit_id: u64, pub delegated_account: Pubkey, } @@ -49,18 +77,14 @@ impl Task { } } - pub fn args_instruction( - &self, - validator: Pubkey, - commit_id: u64, - ) -> Instruction { + pub fn args_instruction(&self, validator: Pubkey) -> Instruction { match self { Task::Commit(value) => { let args = CommitStateArgs { - slot: commit_id, // TODO(edwin): change slot, + slot: value.commit_id, // TODO(edwin): change slot, lamports: value.committed_account.account.lamports, data: value.committed_account.account.data.clone(), - allow_undelegation: value.allow_undelegatio, // TODO(edwin): + allow_undelegation: value.allow_undelegation, // TODO(edwin): }; dlp::instruction_builder::commit_state( validator, @@ -104,16 +128,12 @@ impl Task { todo!() } - pub fn buffer_instruction( - &self, - validator: Pubkey, - commit_id: u64, - ) -> Instruction { + pub fn buffer_instruction(&self, validator: Pubkey) -> Instruction { // TODO(edwin): now this is bad, while impossible // We should use dyn Task match self { Task::Commit(value) => { - let commit_id_slice = commit_id.to_le_bytes(); + let commit_id_slice = value.commit_id.to_le_bytes(); let (commit_buffer_pubkey, _) = magicblock_committor_program::pdas::chunks_pda( &validator, @@ -126,9 +146,9 @@ impl Task { value.committed_account.account.owner, commit_buffer_pubkey, CommitStateFromBufferArgs { - slot: commit_id, //TODO(edwin): change to commit_id + slot: value.commit_id, //TODO(edwin): change to commit_id lamports: value.committed_account.account.lamports, - allow_undelegation: value.allow_undelegatio, + allow_undelegation: value.allow_undelegation, }, ) } @@ -137,6 +157,75 @@ impl Task { Task::L1Action(_) => unreachable!(), // TODO(edwin): enable } } + + pub fn get_preparation_instructions( + &self, + authority: &Keypair, + ) -> Option { + let Self::Commit(commit_task) = self else { + None + }; + + let committed_account = &commit_task.committed_account; + let chunks = Chunks::from_data_length( + committed_account.account.data.len(), + MAX_WRITE_CHUNK_SIZE, + ); + let chunks_account_size = + borsh::object_length(&chunks).unwrap().len() as u64; + let buffer_account_size = committed_account.account.data.len() as u64; + + let (init_instruction, chunks_pda, buffer_pda) = + create_init_ix(CreateInitIxArgs { + authority: authority.pubkey(), + pubkey: committed_account.pubkey, + chunks_account_size, + buffer_account_size, + commit_id, + chunk_count: chunks.count(), + chunk_size: chunks.chunk_size(), + }); + + let realloc_instructions = + create_realloc_buffer_ixs(CreateReallocBufferIxArgs { + authority: authority.pubkey(), + pubkey: committed_account.pubkey, + buffer_account_size, + commit_id, + }); + + let chunks_iter = ChangesetChunks::new(&chunks, chunks.chunk_size()) + .iter(&committed_account.account.data); + let write_instructions = chunks_iter + .map(|chunk| { + create_write_ix(CreateWriteIxArgs { + authority: authority.pubkey(), + pubkey, + offset: chunk.offset, + data_chunk: chunk.data_chunk, + commit_id, + }) + }) + .collect::>(); + + Some(TaskPreparationInfo { + chunks_pda, + buffer_pda, + init_instruction, + realloc_instructions, + write_instructions, + }) + } + + pub fn instructions_from_info( + &self, + info: &TaskPreparationInfo, + ) -> Vec> { + chunk_realloc_ixs( + info.realloc_instructions.clone(), + Some(info.init_instruction.clone()), + ) + } } pub trait TasksBuilder { diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index baa924881..1d35a866b 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -128,4 +128,13 @@ impl TransactionPreparator for TransactionPreparatorV1 { // 7. If heap.is_empty() - doesn't fit with buffered // 8. Apply lookup table // 9. if fits - return Ok(tx), else return Err(Failed) + +// Committor flow: +// 1. Gets commits +// 2. Passes to Scheduler +// 3. Scheduler checks if any can run in parallel. Does scheduling basically +// 4. Calls TransactionPreparator for those +// 5. Executes TXs if all ok +// 6. Populates Persister with necessary data + fn useless() {} From 8bb5d5874856770bc8e79e0da8eaeb1f96608614 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 9 Jul 2025 16:16:48 +0900 Subject: [PATCH 082/199] feat: trait for tasks --- .../budget_calculator.rs | 2 +- .../delivery_preparator.rs | 8 +- .../delivery_strategist.rs | 195 ------------- .../src/transaction_preperator/mod.rs | 3 +- .../transaction_preperator/task_builder.rs | 81 +++--- .../transaction_preperator/task_strategist.rs | 198 ++++++++++++++ .../src/transaction_preperator/tasks.rs | 257 ++++++++++++++++++ .../transaction_preparator.rs | 6 +- 8 files changed, 502 insertions(+), 248 deletions(-) delete mode 100644 magicblock-committor-service/src/transaction_preperator/delivery_strategist.rs create mode 100644 magicblock-committor-service/src/transaction_preperator/task_strategist.rs create mode 100644 magicblock-committor-service/src/transaction_preperator/tasks.rs diff --git a/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs b/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs index 5024d5e11..ef91f8969 100644 --- a/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs +++ b/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs @@ -6,7 +6,7 @@ use solana_sdk::{ use crate::{compute_budget::Budget, ComputeBudgetConfig}; // TODO(edwin): rename -struct ComputeBudgetV1 { +pub struct ComputeBudgetV1 { /// Total compute budget pub compute_budget: u32, pub compute_unit_price: u64, diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index a914835d2..4fc66b2fd 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -37,9 +37,10 @@ use crate::{ error::{CommitAccountError, CommitAccountResult}, persist::CommitStrategy, transaction_preperator::{ - delivery_strategist::{TaskDeliveryStrategy, TransactionStrategy}, error::PreparatorResult, - task_builder::{CommitTask, Task, TaskPreparationInfo}, + task_builder::Task, + task_strategist::{TaskDeliveryStrategy, TransactionStrategy}, + tasks::{CommitTask, TaskPreparationInfo}, }, CommitInfo, ComputeBudgetConfig, }; @@ -184,6 +185,7 @@ impl DeliveryPreparator { ))); } Err(err) => { + error!("Failed to fetch chunks PDA: {:?}", err); last_error = err.into(); sleep(Duration::from_millis(100)).await; continue; @@ -231,6 +233,7 @@ impl DeliveryPreparator { .buffer_write .instructions(instruction.data.len()); instructions.push(instruction); + join_set.spawn(async move { self.send_ixs_with_retry::<2>(&write_instructions, authority) .await @@ -245,6 +248,7 @@ impl DeliveryPreparator { .await .iter() .collect::, _>>()?; + Ok(()) } diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_strategist.rs b/magicblock-committor-service/src/transaction_preperator/delivery_strategist.rs deleted file mode 100644 index dd4892b7d..000000000 --- a/magicblock-committor-service/src/transaction_preperator/delivery_strategist.rs +++ /dev/null @@ -1,195 +0,0 @@ -use std::collections::BinaryHeap; - -use solana_pubkey::Pubkey; -use solana_sdk::{ - hash::Hash, - instruction::Instruction, - message::{v0::Message, VersionedMessage}, - signature::Keypair, - transaction::{Transaction, VersionedTransaction}, -}; - -use crate::{ - transaction_preperator::{ - error::{Error, PreparatorResult}, - task_builder::Task, - utils::estimate_lookup_tables_for_tx, - }, - transactions::{serialize_and_encode_base64, MAX_ENCODED_TRANSACTION_SIZE}, -}; - -#[derive(Clone)] -pub enum TaskDeliveryStrategy { - Args(Task), - Buffer(Task), -} - -impl TaskDeliveryStrategy { - pub fn instruction(&self) -> Instruction { - todo!() - } -} - -#[derive(Clone)] -pub struct TransactionStrategy { - pub task_strategies: Vec, - pub use_lookup_table: bool, -} - -impl TaskDeliveryStrategy { - fn decrease(self) -> Result { - match self { - Self::Args(task) => { - if task.is_bufferable() { - Ok(Self::Buffer(task)) - } else { - // Can't decrease size for task - Err(Self::Args(task)) - } - } - val @ Self::Buffer(_) => Err(val), // No other shorter strategy - } - } -} - -pub struct DeliveryStrategist; -impl DeliveryStrategist { - /// Returns [`TaskDeliveryStrategy`] for every [`Task`] - pub fn build_strategies( - tasks: Vec, - ) -> PreparatorResult { - // TODO(edwin): we could have Vec - // In runtime "BufferedTask" could replace "ArgTask" - let mut strategies = tasks - .into_iter() - .map(|el| TaskDeliveryStrategy::Args(el)) - .collect::>(); - - // Optimize stategy - if Self::optimize_strategy(&mut strategies) - <= MAX_ENCODED_TRANSACTION_SIZE - { - return Ok(TransactionStrategy { - task_strategies: strategies, - use_lookup_table: false, - }); - } - - let alt_tx = Self::assemble_tx_with_lookup_table(&strategies); - if alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE { - Ok(TransactionStrategy { - task_strategies: strategies, - use_lookup_table: false, - }) - } else { - Err(Error::FailedToFitError) - } - } - - /// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`] - /// Returns size of tx after optimizations - fn optimize_strategy(strategies: &mut [TaskDeliveryStrategy]) -> usize { - let ixs = Self::assemble_ixs(&strategies); - let tx = Self::assemble_tx_with_budget(&strategies); - let mut current_tx_length = serialize_and_encode_base64(&tx).len(); - - // Create heap size -> index - let sizes = ixs - .iter() - .map(|ix| borsh::object_length(ix)) - .collect::, _>>() - .unwrap(); - - let mut map = sizes - .into_iter() - .enumerate() - .map(|(index, size)| (size, index)) - .collect::>(); - // We keep popping heaviest el-ts & try to optimize while heap is non-empty - while let Some((_, index)) = map.pop() { - if current_tx_length <= MAX_ENCODED_TRANSACTION_SIZE { - break; - } - - let task = &mut strategies[index]; - // SAFETY: we have exclusive access to [`strategies`]. - // We create bitwise copy, and then replace it with `self`. - // No memory will be double-freed since we use `std::ptr::write` - // No memory is leaked since we use don't allocate anything new - // Critical invariants: - // - decrease(self) shall never drop self - // NOTE: don't want [`Task`] to implement `Default` - unsafe { - let task_ptr = task as *mut TaskDeliveryStrategy; - let old_value = std::ptr::read(task_ptr); - match old_value.decrease() { - // If we can decrease: - // 1. Calculate new tx size & ix size - // 2. Insert item's data back in the heap - // 3. Update overall tx size - Ok(next_strategy) => { - std::ptr::write(task_ptr, next_strategy); - // TODO(edwin): this is expensive - let new_ix = strategies[index].instruction(); - let new_ix_size = - borsh::object_length(&new_ix).unwrap(); // TODO(edwin): unwrap - let new_tx = Self::assemble_tx_with_budget(&strategies); - - map.push((new_ix_size, index)); - current_tx_length = - serialize_and_encode_base64(&new_tx).len(); - } - // That means el-t can't be optimized further - // We move it back with oldest state - // Heap forgets about this el-t - Err(old_strategy) => { - std::ptr::write(task_ptr, old_strategy); - } - } - } - } - - current_tx_length - } - - // TODO(edwin): improve - fn assemble_tx_with_lookup_table( - strategies: &[TaskDeliveryStrategy], - ) -> VersionedTransaction { - // In case we can't fit with optimal strategy - try ALT - let tx = Self::assemble_tx_with_budget(&strategies); - let alts = estimate_lookup_tables_for_tx(&tx); - let ixs = Self::assemble_ixs_with_budget(&strategies); - let message = Message::try_compile( - &Pubkey::new_unique(), - &ixs, - &alts, - Hash::new_unique(), - ) - .unwrap(); // TODO(edwin): unwrap - let tx = VersionedTransaction::try_new( - VersionedMessage::V0(message), - &&[Keypair::new()], - ) - .unwrap(); - tx - } - - fn assemble_ixs_with_budget( - strategies: &[TaskDeliveryStrategy], - ) -> Vec { - todo!() - } - - fn assemble_ixs(tasks: &[TaskDeliveryStrategy]) -> Vec { - // Just given Strategy(Task) creates dummy ixs - // Then assemls ixs into tx - todo!() - } - - fn assemble_tx_with_budget( - tasks: &[TaskDeliveryStrategy], - ) -> VersionedTransaction { - todo!() - } -} diff --git a/magicblock-committor-service/src/transaction_preperator/mod.rs b/magicblock-committor-service/src/transaction_preperator/mod.rs index ea2369a7d..9ccdca4a5 100644 --- a/magicblock-committor-service/src/transaction_preperator/mod.rs +++ b/magicblock-committor-service/src/transaction_preperator/mod.rs @@ -1,7 +1,8 @@ mod budget_calculator; mod delivery_preparator; -mod delivery_strategist; mod error; mod task_builder; +mod task_strategist; +mod tasks; mod transaction_preparator; mod utils; diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs index ec82264d9..b4469bd8d 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_builder.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use dlp::args::{CallHandlerArgs, CommitStateArgs, CommitStateFromBufferArgs}; use magicblock_committor_program::{ instruction_builder::{ @@ -11,8 +13,7 @@ use magicblock_committor_program::{ ChangesetChunks, Chunks, }; use magicblock_program::magic_scheduled_l1_message::{ - CommitAndUndelegate, CommitType, CommittedAccountV2, L1Action, - MagicL1Message, ScheduledL1Message, UndelegateType, + CommitType, L1Action, MagicL1Message, ScheduledL1Message, UndelegateType, }; use solana_pubkey::Pubkey; use solana_sdk::{ @@ -21,43 +22,13 @@ use solana_sdk::{ signer::Signer, }; -use crate::consts::MAX_WRITE_CHUNK_SIZE; -// pub trait PossibleTaskTrait { -// fn instruction() -> Instruction; -// fn decrease(self: Box) -> Result, Box>; -// // If task is "preparable" returns Instructions for preparations -// fn prepare(self: Box) -> Option>; -// } - -pub struct TaskPreparationInfo { - pub chunks_pda: Pubkey, - pub buffer_pda: Pubkey, - pub init_instruction: Instruction, - pub realloc_instructions: Vec, - pub write_instructions: Vec, -} - -// TODO(edwin): commit_id is common thing, extract -#[derive(Clone)] -pub struct CommitTask { - pub commit_id: u64, - pub allow_undelegation: bool, - pub committed_account: CommittedAccountV2, -} - -#[derive(Clone)] -pub struct UndelegateTask { - pub commit_id: u64, - pub delegated_account: Pubkey, - pub owner_program: Pubkey, - pub rent_reimbursement: Pubkey, -} - -#[derive(Clone)] -pub struct FinalizeTask { - pub commit_id: u64, - pub delegated_account: Pubkey, -} +use crate::{ + consts::MAX_WRITE_CHUNK_SIZE, + transaction_preperator::tasks::{ + ArgsTask, CommitTask, FinalizeTask, L1Task, TaskPreparationInfo, + UndelegateTask, + }, +}; #[derive(Clone)] pub enum Task { @@ -230,7 +201,10 @@ impl Task { pub trait TasksBuilder { // Creates tasks for commit stage - fn commit_tasks(l1_message: &ScheduledL1Message) -> Vec; + fn commit_tasks( + l1_message: &ScheduledL1Message, + commit_ids: HashMap, + ) -> Vec; // Create tasks for finalize stage fn finalize_tasks(l1_message: &ScheduledL1Message) -> Vec; @@ -241,24 +215,39 @@ pub trait TasksBuilder { pub struct TaskBuilderV1; impl TasksBuilder for TaskBuilderV1 { /// Returns [`Task`]s for Commit stage - fn commit_tasks(l1_message: &ScheduledL1Message) -> Vec { - let accounts = match &l1_message.l1_message { + fn commit_tasks( + l1_message: &ScheduledL1Message, + commit_ids: HashMap, + ) -> Vec> { + let (accounts, allow_undelegation) = match &l1_message.l1_message { MagicL1Message::L1Actions(actions) => { return actions .into_iter() .map(|el| Task::L1Action(el.clone())) .collect() } - MagicL1Message::Commit(t) => t.get_committed_accounts(), + MagicL1Message::Commit(t) => (t.get_committed_accounts(), false), MagicL1Message::CommitAndUndelegate(t) => { - t.commit_action.get_committed_accounts() + (t.commit_action.get_committed_accounts(), true) } }; accounts .into_iter() - .map(|account| Task::Commit(account.clone())) - .collect() + .map(|account| { + if let Some(commit_id) = commit_ids.get(&account.pubkey) { + Ok(ArgsTask::Commit(CommitTask { + commit_id: *commit_id + 1, + allow_undelegation, + committed_account: account.clone(), + })) + } else { + // TODO(edwin): proper error + Err(()) + } + }) + .collect::>() + .unwrap() } /// Returns [`Task`]s for Finalize stage diff --git a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs new file mode 100644 index 000000000..9f913bc42 --- /dev/null +++ b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs @@ -0,0 +1,198 @@ +use std::collections::{BinaryHeap, HashSet}; + +use solana_pubkey::Pubkey; +use solana_sdk::{ + address_lookup_table::AddressLookupTableAccount, + hash::Hash, + instruction::Instruction, + message::{v0::Message, VersionedMessage}, + signature::Keypair, + transaction::VersionedTransaction, +}; + +use crate::{ + transaction_preperator::{ + budget_calculator::ComputeBudgetV1, + error::{Error, PreparatorResult}, + task_builder::Task, + tasks::L1Task, + }, + transactions::{serialize_and_encode_base64, MAX_ENCODED_TRANSACTION_SIZE}, +}; + +#[derive(Clone)] +pub struct TransactionStrategy { + pub optimized_tasks: Vec>, + pub lookup_tables_keys: Vec>, +} + +pub struct TaskStrategist; +impl TaskStrategist { + /// Returns [`TaskDeliveryStrategy`] for every [`Task`] + pub fn build_strategy( + mut tasks: Vec>, + validator: &Pubkey, + ) -> PreparatorResult { + // Optimize srategy + if Self::optimize_strategy(&mut tasks) <= MAX_ENCODED_TRANSACTION_SIZE { + return Ok(TransactionStrategy { + optimized_tasks: tasks, + lookup_tables_keys: vec![], + }); + } + + let budget_instructions = Self::budget_instructions( + &tasks.iter().map(|task| task.budget()).collect(), + ); + let lookup_tables = Self::assemble_lookup_table( + &mut tasks, + validator, + &budget_instructions, + ); + let alt_tx = Self::assemble_tx_with_lookup_table( + &tasks, + &budget_instructions, + &lookup_tables, + ); + if alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE { + let lookup_tables_keys = + lookup_tables.iter().map(|table| table.addresses).collect(); + Ok(TransactionStrategy { + optimized_tasks: tasks, + lookup_tables_keys, + }) + } else { + Err(Error::FailedToFitError) + } + } + + /// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`] + /// Returns size of tx after optimizations + fn optimize_strategy(tasks: &mut [Box]) -> usize { + let ixs = Self::assemble_ixs(&tasks); + let tx = Self::assemble_tx_with_budget(&tasks); + let mut current_tx_length = serialize_and_encode_base64(&tx).len(); + + // Create heap size -> index + let sizes = ixs + .iter() + .map(|ix| borsh::object_length(ix)) + .collect::, _>>() + .unwrap(); + + let mut map = sizes + .into_iter() + .enumerate() + .map(|(index, size)| (size, index)) + .collect::>(); + // We keep popping heaviest el-ts & try to optimize while heap is non-empty + while let Some((_, index)) = map.pop() { + if current_tx_length <= MAX_ENCODED_TRANSACTION_SIZE { + break; + } + + let task = &mut tasks[index]; + let task = std::mem::replace(task, Box::new_uninit()); + match task.decrease() { + // If we can decrease: + // 1. Calculate new tx size & ix size + // 2. Insert item's data back in the heap + // 3. Update overall tx size + Ok(optimized_task) => { + task[index] = optimized_task; + // TODO(edwin): this is expensive + let new_ix = + tasks[index].instruction(&Pubkey::new_unique()); + let new_ix_size = borsh::object_length(&new_ix).unwrap(); // TODO(edwin): unwrap + let new_tx = Self::assemble_tx_with_budget(&tasks); + + map.push((new_ix_size, index)); + current_tx_length = + serialize_and_encode_base64(&new_tx).len(); + } + // That means el-t can't be optimized further + // We move it back with oldest state + // Heap forgets about this el-t + Err(old_task) => { + task[index] = old_task; + } + } + } + + current_tx_length + } + + fn assemble_lookup_table( + tasks: &[Box], + validator: &Pubkey, + budget_instructions: &[Instruction], + ) -> Vec { + // Collect all unique pubkeys from tasks and budget instructions + let mut all_pubkeys: HashSet = tasks + .iter() + .flat_map(|task| task.involved_accounts(validator)) + .collect(); + + all_pubkeys.extend( + budget_instructions + .iter() + .flat_map(|ix| ix.accounts.iter().map(|meta| meta.pubkey)), + ); + + // Split into chunks of max 256 addresses + all_pubkeys + .into_iter() + .collect::>() + .chunks(256) + .map(|addresses| AddressLookupTableAccount { + key: Pubkey::new_unique(), + addresses: addresses.to_vec(), + }) + .collect() + } + + // TODO(edwin): improve + fn assemble_tx_with_lookup_table( + tasks: &[Box], + budget_instructions: &[Instruction], + lookup_tables: &[AddressLookupTableAccount], + ) -> VersionedTransaction { + // In case we can't fit with optimal strategy - try ALT + let ixs = Self::assemble_ixs_with_budget(&tasks); + let message = Message::try_compile( + &Pubkey::new_unique(), + &[budget_instructions, &ixs].concat(), + &lookup_tables, + Hash::new_unique(), + ) + .unwrap(); // TODO(edwin): unwrap + let tx = VersionedTransaction::try_new( + VersionedMessage::V0(message), + &&[Keypair::new()], + ) + .unwrap(); + tx + } + + fn budget_instructions(budgets: &[ComputeBudgetV1]) -> Vec { + todo!() + } + + fn assemble_ixs_with_budget( + strategies: &[Box], + ) -> Vec { + todo!() + } + + fn assemble_ixs(tasks: &[Box]) -> Vec { + // Just given Strategy(Task) creates dummy ixs + // Then assemls ixs into tx + todo!() + } + + fn assemble_tx_with_budget( + tasks: &[Box], + ) -> VersionedTransaction { + todo!() + } +} diff --git a/magicblock-committor-service/src/transaction_preperator/tasks.rs b/magicblock-committor-service/src/transaction_preperator/tasks.rs new file mode 100644 index 000000000..7d1c99e2d --- /dev/null +++ b/magicblock-committor-service/src/transaction_preperator/tasks.rs @@ -0,0 +1,257 @@ +use std::arch::aarch64::vcale_f32; + +use dlp::args::{CallHandlerArgs, CommitStateArgs, CommitStateFromBufferArgs}; +use magicblock_committor_program::{ + instruction_builder::{ + init_buffer::{create_init_ix, CreateInitIxArgs}, + realloc_buffer::{ + create_realloc_buffer_ixs, CreateReallocBufferIxArgs, + }, + write_buffer::{create_write_ix, CreateWriteIxArgs}, + }, + ChangesetChunks, Chunks, +}; +use magicblock_program::magic_scheduled_l1_message::{ + CommittedAccountV2, L1Action, +}; +use solana_pubkey::Pubkey; +use solana_sdk::instruction::{AccountMeta, Instruction}; + +use crate::{ + consts::MAX_WRITE_CHUNK_SIZE, + transaction_preperator::{ + budget_calculator::ComputeBudgetV1, task_builder::Task, + }, +}; + +pub struct TaskPreparationInfo { + pub chunks_pda: Pubkey, + pub buffer_pda: Pubkey, + pub init_instruction: Instruction, + pub realloc_instructions: Vec, + pub write_instructions: Vec, +} + +pub trait L1Task { + /// Gets all pubkeys that involved in Task's instruction + fn involved_accounts(&self, validator: &Pubkey) -> Vec { + self.instruction(validator) + .accounts + .iter() + .map(|meta| meta.pubkey) + .collect() + } + + /// Gets instruction for task execution + fn instruction(&self, validator: &Pubkey) -> Instruction; + + /// If has optimizations returns optimized Task, otherwise returns itself + fn optimize(self: Box) -> Result, Box>; + + /// Returns [`TaskPreparationInfo`] if task needs to be prepared before executing, + /// otherwise returns None + fn preparation_info( + &self, + authority_pubkey: &Pubkey, + ) -> Option; + + /// Returns [`Task`] budget + fn budget(&self) -> ComputeBudgetV1; +} + +// TODO(edwin): commit_id is common thing, extract +#[derive(Clone)] +pub struct CommitTask { + pub commit_id: u64, + pub allow_undelegation: bool, + pub committed_account: CommittedAccountV2, +} + +#[derive(Clone)] +pub struct UndelegateTask { + pub commit_id: u64, + pub delegated_account: Pubkey, + pub owner_program: Pubkey, + pub rent_reimbursement: Pubkey, +} + +#[derive(Clone)] +pub struct FinalizeTask { + pub commit_id: u64, + pub delegated_account: Pubkey, +} + +#[derive(Clone)] +pub enum ArgsTask { + Commit(CommitTask), + Finalize(FinalizeTask), // TODO(edwin): introduce Stages instead? + Undelegate(UndelegateTask), // Special action really + L1Action(L1Action), +} + +impl L1Task for ArgsTask { + fn instruction(&self, validator: &Pubkey) -> Instruction { + match self { + Task::Commit(value) => { + let args = CommitStateArgs { + slot: value.commit_id, // TODO(edwin): change slot, + lamports: value.committed_account.account.lamports, + data: value.committed_account.account.data.clone(), + allow_undelegation: value.allow_undelegation, // TODO(edwin): + }; + dlp::instruction_builder::commit_state( + *validator, + value.committed_account.pubkey, + value.committed_account.account.owner, + args, + ) + } + Task::Finalize(value) => dlp::instruction_builder::finalize( + *validator, + value.delegated_account, + ), + Task::Undelegate(value) => dlp::instruction_builder::undelegate( + *validator, + value.delegated_account, + value.owner_program, + value.rent_reimbursement, + ), + Task::L1Action(value) => { + let account_metas = value + .account_metas_per_program + .iter() + .map(|short_meta| AccountMeta { + pubkey: short_meta.pubkey, + is_writable: short_meta.is_writable, + is_signer: false, + }) + .collect(); + dlp::instruction_builder::call_handler( + *validator, + value.destination_program, + value.escrow_authority, + account_metas, + CallHandlerArgs { + data: value.data_per_program.data.clone(), + escrow_index: value.data_per_program.escrow_index, + }, + ) + } + } + } + + fn optimize(self: Box) -> Result, Box> { + match self { + Self::Commit(value) => Ok(Box::new(BufferTask::Commit(value))), + Self::L1Action(_) | Self::Finalize(_) | Self::Undelegate(_) => { + Err(self) + } + } + } + + /// Nothing to prepare for [`ArgsTask`] type + fn preparation_info(&self, _: &Pubkey) -> Option { + None + } + + fn budget(&self) -> ComputeBudgetV1 { + todo!() + } +} + +/// Tasks that could be executed using buffers +pub enum BufferTask { + Commit(CommitTask), + // TODO(edwin): Action in the future +} + +impl L1Task for BufferTask { + fn instruction(&self, validator: &Pubkey) -> Instruction { + let Self::Commit(value) = self; + let commit_id_slice = value.commit_id.to_le_bytes(); + let (commit_buffer_pubkey, _) = + magicblock_committor_program::pdas::chunks_pda( + validator, + &value.committed_account.pubkey, + &commit_id_slice, + ); + + dlp::instruction_builder::commit_state_from_buffer( + *validator, + value.committed_account.pubkey, + value.committed_account.account.owner, + commit_buffer_pubkey, + CommitStateFromBufferArgs { + slot: value.commit_id, //TODO(edwin): change to commit_id + lamports: value.committed_account.account.lamports, + allow_undelegation: value.allow_undelegation, + }, + ) + } + + /// No further optimizations + fn optimize(self: Box) -> Result, Box> { + Err(self) + } + + fn preparation_info( + &self, + authority_pubkey: &Pubkey, + ) -> Option { + let Self::Commit(commit_task) = self; + + let committed_account = &commit_task.committed_account; + let chunks = Chunks::from_data_length( + committed_account.account.data.len(), + MAX_WRITE_CHUNK_SIZE, + ); + let chunks_account_size = + borsh::object_length(&chunks).unwrap().len() as u64; + let buffer_account_size = committed_account.account.data.len() as u64; + + let (init_instruction, chunks_pda, buffer_pda) = + create_init_ix(CreateInitIxArgs { + authority: *authority_pubkey, + pubkey: committed_account.pubkey, + chunks_account_size, + buffer_account_size, + commit_id, + chunk_count: chunks.count(), + chunk_size: chunks.chunk_size(), + }); + + let realloc_instructions = + create_realloc_buffer_ixs(CreateReallocBufferIxArgs { + authority: *authority_pubkey, + pubkey: committed_account.pubkey, + buffer_account_size, + commit_id, + }); + + let chunks_iter = ChangesetChunks::new(&chunks, chunks.chunk_size()) + .iter(&committed_account.account.data); + let write_instructions = chunks_iter + .map(|chunk| { + create_write_ix(CreateWriteIxArgs { + authority: *authority_pubkey, + pubkey, + offset: chunk.offset, + data_chunk: chunk.data_chunk, + commit_id, + }) + }) + .collect::>(); + + Some(TaskPreparationInfo { + chunks_pda, + buffer_pda, + init_instruction, + realloc_instructions, + write_instructions, + }) + } + + fn budget(&self) -> ComputeBudgetV1 { + todo!() + } +} diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 1d35a866b..0759d2d07 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -8,9 +8,9 @@ use solana_sdk::message::v0::Message; use crate::transaction_preperator::{ budget_calculator::{ComputeBudgetCalculator, ComputeBudgetCalculatorV1}, - delivery_strategist::DeliveryStrategist, error::{Error, PreparatorResult}, task_builder::{TaskBuilderV1, TasksBuilder}, + task_strategist::TaskStrategist, }; /// Transaction Preparator version @@ -83,7 +83,7 @@ impl TransactionPreparator for TransactionPreparatorV1 { // 1. let tasks = TaskBuilderV1::commit_tasks(l1_message); // 2. - let tx_strategy = DeliveryStrategist::build_strategies(tasks)?; + let tx_strategy = TaskStrategist::build_strategy(tasks)?; // 3. todo!() @@ -95,7 +95,7 @@ impl TransactionPreparator for TransactionPreparatorV1 { l1_message: &ScheduledL1Message, ) -> PreparatorResult { let tasks = TaskBuilderV1::finalize_tasks(l1_message); - let tx_strategy = DeliveryStrategist::build_strategies(tasks); + let tx_strategy = TaskStrategist::build_strategy(tasks); todo!() } From 4c05ca6431386ce3d75ec78641ffc1daf6795c01 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 9 Jul 2025 16:32:46 +0900 Subject: [PATCH 083/199] raw --- .../transaction_preperator/task_builder.rs | 128 ++++++++++++++---- .../src/transaction_preperator/tasks.rs | 2 - 2 files changed, 104 insertions(+), 26 deletions(-) diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs index b4469bd8d..e2d1c9bf8 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_builder.rs @@ -12,9 +12,7 @@ use magicblock_committor_program::{ instruction_chunks::chunk_realloc_ixs, ChangesetChunks, Chunks, }; -use magicblock_program::magic_scheduled_l1_message::{ - CommitType, L1Action, MagicL1Message, ScheduledL1Message, UndelegateType, -}; +use magicblock_program::magic_scheduled_l1_message::{CommitType, CommittedAccountV2, L1Action, MagicL1Message, ScheduledL1Message, UndelegateType}; use solana_pubkey::Pubkey; use solana_sdk::{ instruction::{AccountMeta, Instruction}, @@ -204,10 +202,13 @@ pub trait TasksBuilder { fn commit_tasks( l1_message: &ScheduledL1Message, commit_ids: HashMap, - ) -> Vec; + ) -> Vec>; // Create tasks for finalize stage - fn finalize_tasks(l1_message: &ScheduledL1Message) -> Vec; + fn finalize_tasks( + l1_message: &ScheduledL1Message, + rent_reimbursement: &Pubkey, + ) -> Vec>; } /// V1 Task builder @@ -247,16 +248,23 @@ impl TasksBuilder for TaskBuilderV1 { } }) .collect::>() - .unwrap() + .unwrap() // TODO(edwin): remove } /// Returns [`Task`]s for Finalize stage - fn finalize_tasks(l1_message: &ScheduledL1Message) -> Vec { - fn commit_type_tasks(value: &CommitType) -> Vec { + fn finalize_tasks( + l1_message: &ScheduledL1Message, + rent_reimbursement: &Pubkey, + ) -> Vec> { + fn commit_type_tasks(value: &CommitType) -> Vec> { match value { CommitType::Standalone(accounts) => accounts .into_iter() - .map(|account| Task::Finalize(account.clone())) + .map(|account| { + Box::new(ArgsTask::Finalize(FinalizeTask { + delegated_account: account.pubkey, + })) + }) .collect(), CommitType::WithL1Actions { committed_accounts, @@ -264,21 +272,24 @@ impl TasksBuilder for TaskBuilderV1 { } => { let mut tasks = committed_accounts .into_iter() - .map(|account| Task::Finalize(account.clone())) - .collect::>(); - tasks.extend( - l1_actions - .into_iter() - .map(|action| Task::L1Action(action.clone())), - ); + .map(|account| { + Box::new(ArgsTask::Finalize(FinalizeTask { + delegated_account: account.pubkey, + })) + }) + .collect(); + + tasks.extend(l1_actions.into_iter().map(|action| { + Box::new(ArgsTask::L1Action(action.clone())) + })); tasks } } } - // TODO(edwin): improve, separate into smaller pieces. Maybe Visitor? + // TODO(edwin): improve match &l1_message.l1_message { - MagicL1Message::L1Actions(_) => panic!("enable"), // TODO(edwin) + MagicL1Message::L1Actions(_) => vec![], MagicL1Message::Commit(value) => commit_type_tasks(value), MagicL1Message::CommitAndUndelegate(t) => { let mut commit_tasks = commit_type_tasks(&t.commit_action); @@ -286,18 +297,32 @@ impl TasksBuilder for TaskBuilderV1 { UndelegateType::Standalone => { let accounts = t.get_committed_accounts(); commit_tasks.extend( - accounts.into_iter().map(|account| { - Task::Undelegate(account.clone()) - }), + accounts + .into_iter() + .map(|account| { + ArgsTask::Undelegate(UndelegateTask { + delegated_account: account.pubkey, + owner_program: account.account.owner, + rent_reimbursement: *rent_reimbursement, + }) + }) + .map(Box::new), ); } UndelegateType::WithL1Actions(actions) => { // tasks example: [Finalize(Acc1), Action, Undelegate(Acc1), Action] let accounts = t.get_committed_accounts(); commit_tasks.extend( - accounts.into_iter().map(|account| { - Task::Undelegate(account.clone()) - }), + accounts + .into_iter() + .map(|account| { + ArgsTask::Undelegate(UndelegateTask { + delegated_account: account.pubkey, + owner_program: account.account.owner, + rent_reimbursement: *rent_reimbursement, + }) + }) + .map(Box::new), ); commit_tasks.extend( actions @@ -311,4 +336,59 @@ impl TasksBuilder for TaskBuilderV1 { } } } + + /// Returns tasks for Finalize stage + fn finalize_tasks( + l1_message: &ScheduledL1Message, + rent_reimbursement: &Pubkey, + ) -> Vec> { + // Helper to create a finalize task + fn finalize_task(account: &CommittedAccountV2) -> Box { + Box::new(ArgsTask::Finalize(FinalizeTask { + delegated_account: account.pubkey, + })) + } + + // Helper to create an undelegate task + fn undelegate_task(account: &CommittedAccountV2, rent: &Pubkey) -> Box { + Box::new(ArgsTask::Undelegate(UndelegateTask { + delegated_account: account.pubkey, + owner_program: account.account.owner, + rent_reimbursement: *rent, + })) + } + + // Helper to process commit types + fn process_commit(commit: &CommitType) -> Vec> { + match commit { + CommitType::Standalone(accounts) => accounts.iter().map(finalize_task).collect(), + CommitType::WithL1Actions { committed_accounts, l1_actions } => { + let mut tasks = committed_accounts.iter().map(finalize_task).collect::>(); + tasks.extend(l1_actions.iter().map(|a| Box::new(ArgsTask::L1Action(a.clone())))); + tasks + } + } + } + + match &l1_message.l1_message { + MagicL1Message::L1Actions(_) => vec![], + MagicL1Message::Commit(commit) => process_commit(commit), + MagicL1Message::CommitAndUndelegate(t) => { + let mut tasks = process_commit(&t.commit_action); + let accounts = t.get_committed_accounts(); + + match &t.undelegate_action { + UndelegateType::Standalone => { + tasks.extend(accounts.iter().map(|a| undelegate_task(a, rent_reimbursement))); + } + UndelegateType::WithL1Actions(actions) => { + tasks.extend(accounts.iter().map(|a| undelegate_task(a, rent_reimbursement))); + tasks.extend(actions.iter().map(|a| Box::new(ArgsTask::L1Action(a.clone())))); + } + } + + tasks + } + } + } } diff --git a/magicblock-committor-service/src/transaction_preperator/tasks.rs b/magicblock-committor-service/src/transaction_preperator/tasks.rs index 7d1c99e2d..eaf7e9044 100644 --- a/magicblock-committor-service/src/transaction_preperator/tasks.rs +++ b/magicblock-committor-service/src/transaction_preperator/tasks.rs @@ -69,7 +69,6 @@ pub struct CommitTask { #[derive(Clone)] pub struct UndelegateTask { - pub commit_id: u64, pub delegated_account: Pubkey, pub owner_program: Pubkey, pub rent_reimbursement: Pubkey, @@ -77,7 +76,6 @@ pub struct UndelegateTask { #[derive(Clone)] pub struct FinalizeTask { - pub commit_id: u64, pub delegated_account: Pubkey, } From 5507bb32e2dd186043f35e4eabb22954f6e5bb75 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 9 Jul 2025 16:34:35 +0900 Subject: [PATCH 084/199] fix: TaskBuilder after L1Task trait introduction --- .../transaction_preperator/task_builder.rs | 90 +------------------ 1 file changed, 2 insertions(+), 88 deletions(-) diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs index e2d1c9bf8..94db77165 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_builder.rs @@ -252,92 +252,6 @@ impl TasksBuilder for TaskBuilderV1 { } /// Returns [`Task`]s for Finalize stage - fn finalize_tasks( - l1_message: &ScheduledL1Message, - rent_reimbursement: &Pubkey, - ) -> Vec> { - fn commit_type_tasks(value: &CommitType) -> Vec> { - match value { - CommitType::Standalone(accounts) => accounts - .into_iter() - .map(|account| { - Box::new(ArgsTask::Finalize(FinalizeTask { - delegated_account: account.pubkey, - })) - }) - .collect(), - CommitType::WithL1Actions { - committed_accounts, - l1_actions, - } => { - let mut tasks = committed_accounts - .into_iter() - .map(|account| { - Box::new(ArgsTask::Finalize(FinalizeTask { - delegated_account: account.pubkey, - })) - }) - .collect(); - - tasks.extend(l1_actions.into_iter().map(|action| { - Box::new(ArgsTask::L1Action(action.clone())) - })); - tasks - } - } - } - - // TODO(edwin): improve - match &l1_message.l1_message { - MagicL1Message::L1Actions(_) => vec![], - MagicL1Message::Commit(value) => commit_type_tasks(value), - MagicL1Message::CommitAndUndelegate(t) => { - let mut commit_tasks = commit_type_tasks(&t.commit_action); - match &t.undelegate_action { - UndelegateType::Standalone => { - let accounts = t.get_committed_accounts(); - commit_tasks.extend( - accounts - .into_iter() - .map(|account| { - ArgsTask::Undelegate(UndelegateTask { - delegated_account: account.pubkey, - owner_program: account.account.owner, - rent_reimbursement: *rent_reimbursement, - }) - }) - .map(Box::new), - ); - } - UndelegateType::WithL1Actions(actions) => { - // tasks example: [Finalize(Acc1), Action, Undelegate(Acc1), Action] - let accounts = t.get_committed_accounts(); - commit_tasks.extend( - accounts - .into_iter() - .map(|account| { - ArgsTask::Undelegate(UndelegateTask { - delegated_account: account.pubkey, - owner_program: account.account.owner, - rent_reimbursement: *rent_reimbursement, - }) - }) - .map(Box::new), - ); - commit_tasks.extend( - actions - .into_iter() - .map(|action| Task::L1Action(action.clone())), - ); - } - }; - - commit_tasks - } - } - } - - /// Returns tasks for Finalize stage fn finalize_tasks( l1_message: &ScheduledL1Message, rent_reimbursement: &Pubkey, @@ -350,11 +264,11 @@ impl TasksBuilder for TaskBuilderV1 { } // Helper to create an undelegate task - fn undelegate_task(account: &CommittedAccountV2, rent: &Pubkey) -> Box { + fn undelegate_task(account: &CommittedAccountV2, rent_reimbursement: &Pubkey) -> Box { Box::new(ArgsTask::Undelegate(UndelegateTask { delegated_account: account.pubkey, owner_program: account.account.owner, - rent_reimbursement: *rent, + rent_reimbursement: *rent_reimbursement, })) } From 076177419cf0ecda701b3a1c8ed7d3369e793c99 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 9 Jul 2025 16:47:33 +0900 Subject: [PATCH 085/199] refactor: TaskBuilder::finalize_tasks --- .../transaction_preperator/task_builder.rs | 48 +++++++++++++++---- .../transaction_preparator.rs | 24 ++++++++-- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs index 94db77165..23b5cd10a 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_builder.rs @@ -12,7 +12,10 @@ use magicblock_committor_program::{ instruction_chunks::chunk_realloc_ixs, ChangesetChunks, Chunks, }; -use magicblock_program::magic_scheduled_l1_message::{CommitType, CommittedAccountV2, L1Action, MagicL1Message, ScheduledL1Message, UndelegateType}; +use magicblock_program::magic_scheduled_l1_message::{ + CommitType, CommittedAccountV2, L1Action, MagicL1Message, + ScheduledL1Message, UndelegateType, +}; use solana_pubkey::Pubkey; use solana_sdk::{ instruction::{AccountMeta, Instruction}, @@ -264,7 +267,10 @@ impl TasksBuilder for TaskBuilderV1 { } // Helper to create an undelegate task - fn undelegate_task(account: &CommittedAccountV2, rent_reimbursement: &Pubkey) -> Box { + fn undelegate_task( + account: &CommittedAccountV2, + rent_reimbursement: &Pubkey, + ) -> Box { Box::new(ArgsTask::Undelegate(UndelegateTask { delegated_account: account.pubkey, owner_program: account.account.owner, @@ -275,10 +281,22 @@ impl TasksBuilder for TaskBuilderV1 { // Helper to process commit types fn process_commit(commit: &CommitType) -> Vec> { match commit { - CommitType::Standalone(accounts) => accounts.iter().map(finalize_task).collect(), - CommitType::WithL1Actions { committed_accounts, l1_actions } => { - let mut tasks = committed_accounts.iter().map(finalize_task).collect::>(); - tasks.extend(l1_actions.iter().map(|a| Box::new(ArgsTask::L1Action(a.clone())))); + CommitType::Standalone(accounts) => { + accounts.iter().map(finalize_task).collect() + } + CommitType::WithL1Actions { + committed_accounts, + l1_actions, + } => { + let mut tasks = committed_accounts + .iter() + .map(finalize_task) + .collect::>(); + tasks.extend( + l1_actions + .iter() + .map(|a| Box::new(ArgsTask::L1Action(a.clone()))), + ); tasks } } @@ -293,11 +311,23 @@ impl TasksBuilder for TaskBuilderV1 { match &t.undelegate_action { UndelegateType::Standalone => { - tasks.extend(accounts.iter().map(|a| undelegate_task(a, rent_reimbursement))); + tasks.extend( + accounts.iter().map(|a| { + undelegate_task(a, rent_reimbursement) + }), + ); } UndelegateType::WithL1Actions(actions) => { - tasks.extend(accounts.iter().map(|a| undelegate_task(a, rent_reimbursement))); - tasks.extend(actions.iter().map(|a| Box::new(ArgsTask::L1Action(a.clone())))); + tasks.extend( + accounts.iter().map(|a| { + undelegate_task(a, rent_reimbursement) + }), + ); + tasks.extend( + actions.iter().map(|a| { + Box::new(ArgsTask::L1Action(a.clone())) + }), + ); } } diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 0759d2d07..03882e0b7 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -1,10 +1,13 @@ +use std::collections::HashMap; + use async_trait::async_trait; use magicblock_program::magic_scheduled_l1_message::{ CommittedAccountV2, L1Action, MagicL1Message, ScheduledL1Message, }; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; -use solana_sdk::message::v0::Message; +use solana_pubkey::Pubkey; +use solana_sdk::{message::v0::Message, signature::Keypair, signer::Signer}; use crate::transaction_preperator::{ budget_calculator::{ComputeBudgetCalculator, ComputeBudgetCalculatorV1}, @@ -25,10 +28,14 @@ trait TransactionPreparator { fn version(&self) -> PreparatorVersion; async fn prepare_commit_tx( &self, + authority: &Keypair, l1_message: &ScheduledL1Message, + commit_ids: HashMap, ) -> PreparatorResult; async fn prepare_finalize_tx( &self, + authority: &Keypair, + rent_reimbursement: &Pubkey, l1_message: &ScheduledL1Message, ) -> PreparatorResult; } @@ -73,7 +80,9 @@ impl TransactionPreparator for TransactionPreparatorV1 { /// For pure actions message - outputs Tx that runs actions async fn prepare_commit_tx( &self, + authority: &Keypair, l1_message: &ScheduledL1Message, + commit_ids: HashMap, ) -> PreparatorResult { // 1. create tasks // 2. optimize to fit tx size. aka Delivery Strategy @@ -81,9 +90,10 @@ impl TransactionPreparator for TransactionPreparatorV1 { // 4. Build resulting TX to be executed // 1. - let tasks = TaskBuilderV1::commit_tasks(l1_message); + let tasks = TaskBuilderV1::commit_tasks(l1_message, commit_ids); // 2. - let tx_strategy = TaskStrategist::build_strategy(tasks)?; + let tx_strategy = + TaskStrategist::build_strategy(tasks, &authority.pubkey())?; // 3. todo!() @@ -92,10 +102,14 @@ impl TransactionPreparator for TransactionPreparatorV1 { /// In V1: prepares single TX with finalize, undelegation + actions async fn prepare_finalize_tx( &self, + authority: &Keypair, + rent_reimbursement: &Pubkey, l1_message: &ScheduledL1Message, ) -> PreparatorResult { - let tasks = TaskBuilderV1::finalize_tasks(l1_message); - let tx_strategy = TaskStrategist::build_strategy(tasks); + let tasks = + TaskBuilderV1::finalize_tasks(l1_message, rent_reimbursement); + let tx_strategy = + TaskStrategist::build_strategy(tasks, &authority.pubkey()); todo!() } From b49882d75ff510d38227aa02c47c79ee8b8df2cc Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 9 Jul 2025 17:47:02 +0900 Subject: [PATCH 086/199] fix: some compilation errors --- .../src/commit/commit_using_args.rs | 6 +- magicblock-committor-service/src/lib.rs | 1 - .../delivery_preparator.rs | 35 ++-- .../transaction_preperator/task_builder.rs | 198 ++---------------- .../transaction_preperator/task_strategist.rs | 40 ++-- .../src/transaction_preperator/tasks.rs | 45 ++-- 6 files changed, 83 insertions(+), 242 deletions(-) diff --git a/magicblock-committor-service/src/commit/commit_using_args.rs b/magicblock-committor-service/src/commit/commit_using_args.rs index eb6dba196..263390991 100644 --- a/magicblock-committor-service/src/commit/commit_using_args.rs +++ b/magicblock-committor-service/src/commit/commit_using_args.rs @@ -107,7 +107,7 @@ impl CommittorProcessor { .instructions(committees.len()); let process_sig = match send_and_confirm( me.magicblock_rpc_client.clone(), - me.authority.insecure_clone(), + &me.authority, [compute_budget_ixs, process_ixs].concat(), "commit changeset using args".to_string(), Some(latest_blockhash), @@ -150,7 +150,7 @@ impl CommittorProcessor { .instructions(committees.len()); match send_and_confirm( me.magicblock_rpc_client.clone(), - me.authority.insecure_clone(), + &me.authority, [finalize_budget_ixs, finalize_ixs].concat(), "commit changeset using args".to_string(), Some(latest_blockhash), @@ -236,7 +236,7 @@ impl CommittorProcessor { .instructions(accounts_len); match send_and_confirm( me.magicblock_rpc_client.clone(), - me.authority.insecure_clone(), + &me.authority, [undelegate_budget_ixs, undelegate_ixs].concat(), "undelegate committed accounts using args".to_string(), Some(latest_blockhash), diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 7674324f5..db03f70a3 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -16,7 +16,6 @@ mod transactions; mod types; mod undelegate; -mod commit_strategist; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; mod transaction_preperator; diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 4fc66b2fd..3df801df9 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -19,6 +19,7 @@ use magicblock_rpc_client::{ }; use magicblock_table_mania::TableMania; use solana_account::ReadableAccount; +use solana_pubkey::Pubkey; use solana_rpc_client_api::client_error::reqwest::Version; use solana_sdk::{ hash::Hash, @@ -38,16 +39,12 @@ use crate::{ persist::CommitStrategy, transaction_preperator::{ error::PreparatorResult, - task_builder::Task, - task_strategist::{TaskDeliveryStrategy, TransactionStrategy}, - tasks::{CommitTask, TaskPreparationInfo}, + task_strategist::TransactionStrategy, + tasks::{CommitTask, L1Task, TaskPreparationInfo}, }, CommitInfo, ComputeBudgetConfig, }; -// TODO: likely separate errors -type PreparationFuture = impl Future>; - pub struct DeliveryPreparationResult { lookup_tables: Vec, } @@ -78,16 +75,13 @@ impl DeliveryPreparator { strategy: &TransactionStrategy, ) -> DeliveryPreparatorResult<()> { let preparation_futures = strategy - .task_strategies + .optimized_tasks .iter() .map(|task| self.prepare_task(authority, task)); let fut1 = join_all(preparation_futures); - let fut2 = if strategy.use_lookup_table { - self.prepare_lookup_tables(&strategy.task_strategies) - } else { - std::future::ready(Ok(())) - }; + let fut2 = self.prepare_lookup_tables(&strategy.lookup_tables_keys); + let (res1, res2) = join(fut1, fut2).await; res1.into_iter().collect::, _>>()?; res2?; @@ -99,13 +93,9 @@ impl DeliveryPreparator { async fn prepare_task( &self, authority: &Keypair, - task: &TaskDeliveryStrategy, + task: &Box, ) -> DeliveryPreparatorResult<()> { - let TaskDeliveryStrategy::Buffer(task) = task else { - return Ok(()); - }; - let Some(preparation_info) = - task.get_preparation_instructions(authority) + let Some(preparation_info) = task.preparation_info(&authority.pubkey()) else { return Ok(()); }; @@ -124,7 +114,7 @@ impl DeliveryPreparator { async fn initialize_buffer_account( &self, authority: &Keypair, - task: &Task, + task: &dyn L1Task, preparation_info: &TaskPreparationInfo, ) -> DeliveryPreparatorResult<()> { let preparation_instructions = @@ -220,7 +210,7 @@ impl DeliveryPreparator { ) -> DeliveryPreparatorResult<()> { if write_instructions.len() != chunks.count() { let err = anyhow!("Chunks count mismatches write instruction! chunks: {}, ixs: {}", write_instructions.len(), chunks.count()); - error!(err.to_string()); + error!("{}", err.to_string()); return Err(Error::InternalError(err)); } @@ -298,9 +288,10 @@ impl DeliveryPreparator { Ok(()) } + /// Prepares ALTs for pubkeys participating in tx async fn prepare_lookup_tables( &self, - strategies: &[TaskDeliveryStrategy], + lookup_table_keys: &[Vec], ) -> DeliveryPreparatorResult> { // self.table_mania. todo!() @@ -316,7 +307,7 @@ pub enum Error { BorshError(#[from] std::io::Error), #[error("TransactionCreationError: {0}")] TransactionCreationError(#[from] CompileError), - #[error("TransactionSigningError: {0]")] + #[error("TransactionSigningError: {0}")] TransactionSigningError(#[from] SignerError), #[error("FailedToPrepareBufferError: {0}")] FailedToPrepareBufferError(#[from] MagicBlockRpcClientError), diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs index 23b5cd10a..99c726c64 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_builder.rs @@ -23,183 +23,11 @@ use solana_sdk::{ signer::Signer, }; -use crate::{ - consts::MAX_WRITE_CHUNK_SIZE, - transaction_preperator::tasks::{ - ArgsTask, CommitTask, FinalizeTask, L1Task, TaskPreparationInfo, - UndelegateTask, - }, +use crate::transaction_preperator::tasks::{ + ArgsTask, CommitTask, FinalizeTask, L1Task, TaskPreparationInfo, + UndelegateTask, }; -#[derive(Clone)] -pub enum Task { - Commit(CommitTask), - Finalize(FinalizeTask), // TODO(edwin): introduce Stages instead? - Undelegate(UndelegateTask), // Special action really - L1Action(L1Action), -} - -impl Task { - pub fn is_bufferable(&self) -> bool { - match self { - Self::Commit(_) => true, - Self::Finalize(_) => false, - Self::Undelegate(_) => false, - Self::L1Action(_) => false, // TODO(edwin): enable - } - } - - pub fn args_instruction(&self, validator: Pubkey) -> Instruction { - match self { - Task::Commit(value) => { - let args = CommitStateArgs { - slot: value.commit_id, // TODO(edwin): change slot, - lamports: value.committed_account.account.lamports, - data: value.committed_account.account.data.clone(), - allow_undelegation: value.allow_undelegation, // TODO(edwin): - }; - dlp::instruction_builder::commit_state( - validator, - value.committed_account.pubkey, - value.committed_account.account.owner, - args, - ) - } - Task::Finalize(value) => dlp::instruction_builder::finalize( - validator, - value.delegated_account, - ), - Task::Undelegate(value) => dlp::instruction_builder::undelegate( - validator, - value.delegated_account, - value.owner_program, - value.rent_reimbursement, - ), - Task::L1Action(value) => { - let account_metas = value - .account_metas_per_program - .iter() - .map(|short_meta| AccountMeta { - pubkey: short_meta.pubkey, - is_writable: short_meta.is_writable, - is_signer: false, - }) - .collect(); - dlp::instruction_builder::call_handler( - validator, - value.destination_program, - value.escrow_authority, - account_metas, - CallHandlerArgs { - data: value.data_per_program.data.clone(), - escrow_index: value.data_per_program.escrow_index, - }, - ) - } - } - todo!() - } - - pub fn buffer_instruction(&self, validator: Pubkey) -> Instruction { - // TODO(edwin): now this is bad, while impossible - // We should use dyn Task - match self { - Task::Commit(value) => { - let commit_id_slice = value.commit_id.to_le_bytes(); - let (commit_buffer_pubkey, _) = - magicblock_committor_program::pdas::chunks_pda( - &validator, - &value.committed_account.pubkey, - &commit_id_slice, - ); - dlp::instruction_builder::commit_state_from_buffer( - validator, - value.committed_account.pubkey, - value.committed_account.account.owner, - commit_buffer_pubkey, - CommitStateFromBufferArgs { - slot: value.commit_id, //TODO(edwin): change to commit_id - lamports: value.committed_account.account.lamports, - allow_undelegation: value.allow_undelegation, - }, - ) - } - Task::Undelegate(_) => unreachable!(), - Task::Finalize(_) => unreachable!(), - Task::L1Action(_) => unreachable!(), // TODO(edwin): enable - } - } - - pub fn get_preparation_instructions( - &self, - authority: &Keypair, - ) -> Option { - let Self::Commit(commit_task) = self else { - None - }; - - let committed_account = &commit_task.committed_account; - let chunks = Chunks::from_data_length( - committed_account.account.data.len(), - MAX_WRITE_CHUNK_SIZE, - ); - let chunks_account_size = - borsh::object_length(&chunks).unwrap().len() as u64; - let buffer_account_size = committed_account.account.data.len() as u64; - - let (init_instruction, chunks_pda, buffer_pda) = - create_init_ix(CreateInitIxArgs { - authority: authority.pubkey(), - pubkey: committed_account.pubkey, - chunks_account_size, - buffer_account_size, - commit_id, - chunk_count: chunks.count(), - chunk_size: chunks.chunk_size(), - }); - - let realloc_instructions = - create_realloc_buffer_ixs(CreateReallocBufferIxArgs { - authority: authority.pubkey(), - pubkey: committed_account.pubkey, - buffer_account_size, - commit_id, - }); - - let chunks_iter = ChangesetChunks::new(&chunks, chunks.chunk_size()) - .iter(&committed_account.account.data); - let write_instructions = chunks_iter - .map(|chunk| { - create_write_ix(CreateWriteIxArgs { - authority: authority.pubkey(), - pubkey, - offset: chunk.offset, - data_chunk: chunk.data_chunk, - commit_id, - }) - }) - .collect::>(); - - Some(TaskPreparationInfo { - chunks_pda, - buffer_pda, - init_instruction, - realloc_instructions, - write_instructions, - }) - } - - pub fn instructions_from_info( - &self, - info: &TaskPreparationInfo, - ) -> Vec> { - chunk_realloc_ixs( - info.realloc_instructions.clone(), - Some(info.init_instruction.clone()), - ) - } -} - pub trait TasksBuilder { // Creates tasks for commit stage fn commit_tasks( @@ -244,7 +72,7 @@ impl TasksBuilder for TaskBuilderV1 { commit_id: *commit_id + 1, allow_undelegation, committed_account: account.clone(), - })) + })) as Result, ()> } else { // TODO(edwin): proper error Err(()) @@ -292,11 +120,10 @@ impl TasksBuilder for TaskBuilderV1 { .iter() .map(finalize_task) .collect::>(); - tasks.extend( - l1_actions - .iter() - .map(|a| Box::new(ArgsTask::L1Action(a.clone()))), - ); + tasks.extend(l1_actions.iter().map(|a| { + Box::new(ArgsTask::L1Action(a.clone())) + as Box + })); tasks } } @@ -323,11 +150,10 @@ impl TasksBuilder for TaskBuilderV1 { undelegate_task(a, rent_reimbursement) }), ); - tasks.extend( - actions.iter().map(|a| { - Box::new(ArgsTask::L1Action(a.clone())) - }), - ); + tasks.extend(actions.iter().map(|a| { + Box::new(ArgsTask::L1Action(a.clone())) + as Box + })); } } diff --git a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs index 9f913bc42..30126882b 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs @@ -1,4 +1,7 @@ -use std::collections::{BinaryHeap, HashSet}; +use std::{ + collections::{BinaryHeap, HashSet}, + ptr::NonNull, +}; use solana_pubkey::Pubkey; use solana_sdk::{ @@ -14,13 +17,11 @@ use crate::{ transaction_preperator::{ budget_calculator::ComputeBudgetV1, error::{Error, PreparatorResult}, - task_builder::Task, - tasks::L1Task, + tasks::{ArgsTask, L1Task}, }, transactions::{serialize_and_encode_base64, MAX_ENCODED_TRANSACTION_SIZE}, }; -#[derive(Clone)] pub struct TransactionStrategy { pub optimized_tasks: Vec>, pub lookup_tables_keys: Vec>, @@ -42,7 +43,7 @@ impl TaskStrategist { } let budget_instructions = Self::budget_instructions( - &tasks.iter().map(|task| task.budget()).collect(), + &tasks.iter().map(|task| task.budget()).collect::>(), ); let lookup_tables = Self::assemble_lookup_table( &mut tasks, @@ -54,9 +55,12 @@ impl TaskStrategist { &budget_instructions, &lookup_tables, ); - if alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE { - let lookup_tables_keys = - lookup_tables.iter().map(|table| table.addresses).collect(); + let encoded_alt_tx = serialize_and_encode_base64(&alt_tx); + if encoded_alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE { + let lookup_tables_keys = lookup_tables + .into_iter() + .map(|table| table.addresses) + .collect(); Ok(TransactionStrategy { optimized_tasks: tasks, lookup_tables_keys, @@ -84,7 +88,7 @@ impl TaskStrategist { .into_iter() .enumerate() .map(|(index, size)| (size, index)) - .collect::>(); + .collect::>(); // We keep popping heaviest el-ts & try to optimize while heap is non-empty while let Some((_, index)) = map.pop() { if current_tx_length <= MAX_ENCODED_TRANSACTION_SIZE { @@ -92,14 +96,24 @@ impl TaskStrategist { } let task = &mut tasks[index]; - let task = std::mem::replace(task, Box::new_uninit()); - match task.decrease() { + let task = { + // SAFETY: + // 1. We create a dangling pointer purely for temporary storage during replace + // 2. The pointer is never dereferenced before being replaced + // 3. No memory allocated, hence no leakage + let dangling = NonNull::::dangling(); + let tmp_task = unsafe { Box::from_raw(dangling.as_ptr()) } + as Box; + + std::mem::replace(task, tmp_task) + }; + match task.optimize() { // If we can decrease: // 1. Calculate new tx size & ix size // 2. Insert item's data back in the heap // 3. Update overall tx size Ok(optimized_task) => { - task[index] = optimized_task; + tasks[index] = optimized_task; // TODO(edwin): this is expensive let new_ix = tasks[index].instruction(&Pubkey::new_unique()); @@ -114,7 +128,7 @@ impl TaskStrategist { // We move it back with oldest state // Heap forgets about this el-t Err(old_task) => { - task[index] = old_task; + tasks[index] = old_task; } } } diff --git a/magicblock-committor-service/src/transaction_preperator/tasks.rs b/magicblock-committor-service/src/transaction_preperator/tasks.rs index eaf7e9044..3efa17dcf 100644 --- a/magicblock-committor-service/src/transaction_preperator/tasks.rs +++ b/magicblock-committor-service/src/transaction_preperator/tasks.rs @@ -9,6 +9,7 @@ use magicblock_committor_program::{ }, write_buffer::{create_write_ix, CreateWriteIxArgs}, }, + instruction_chunks::chunk_realloc_ixs, ChangesetChunks, Chunks, }; use magicblock_program::magic_scheduled_l1_message::{ @@ -19,9 +20,7 @@ use solana_sdk::instruction::{AccountMeta, Instruction}; use crate::{ consts::MAX_WRITE_CHUNK_SIZE, - transaction_preperator::{ - budget_calculator::ComputeBudgetV1, task_builder::Task, - }, + transaction_preperator::budget_calculator::ComputeBudgetV1, }; pub struct TaskPreparationInfo { @@ -46,7 +45,7 @@ pub trait L1Task { fn instruction(&self, validator: &Pubkey) -> Instruction; /// If has optimizations returns optimized Task, otherwise returns itself - fn optimize(self: Box) -> Result, Box>; + fn optimize(self: Box) -> Result, Box>; /// Returns [`TaskPreparationInfo`] if task needs to be prepared before executing, /// otherwise returns None @@ -57,6 +56,18 @@ pub trait L1Task { /// Returns [`Task`] budget fn budget(&self) -> ComputeBudgetV1; + + /// Returns Instructions per TX + // TODO(edwin): shall be here? + fn instructions_from_info( + &self, + info: &TaskPreparationInfo, + ) -> Vec> { + chunk_realloc_ixs( + info.realloc_instructions.clone(), + Some(info.init_instruction.clone()), + ) + } } // TODO(edwin): commit_id is common thing, extract @@ -90,7 +101,7 @@ pub enum ArgsTask { impl L1Task for ArgsTask { fn instruction(&self, validator: &Pubkey) -> Instruction { match self { - Task::Commit(value) => { + Self::Commit(value) => { let args = CommitStateArgs { slot: value.commit_id, // TODO(edwin): change slot, lamports: value.committed_account.account.lamports, @@ -104,17 +115,17 @@ impl L1Task for ArgsTask { args, ) } - Task::Finalize(value) => dlp::instruction_builder::finalize( + Self::Finalize(value) => dlp::instruction_builder::finalize( *validator, value.delegated_account, ), - Task::Undelegate(value) => dlp::instruction_builder::undelegate( + Self::Undelegate(value) => dlp::instruction_builder::undelegate( *validator, value.delegated_account, value.owner_program, value.rent_reimbursement, ), - Task::L1Action(value) => { + Self::L1Action(value) => { let account_metas = value .account_metas_per_program .iter() @@ -138,8 +149,8 @@ impl L1Task for ArgsTask { } } - fn optimize(self: Box) -> Result, Box> { - match self { + fn optimize(self: Box) -> Result, Box> { + match *self { Self::Commit(value) => Ok(Box::new(BufferTask::Commit(value))), Self::L1Action(_) | Self::Finalize(_) | Self::Undelegate(_) => { Err(self) @@ -158,6 +169,7 @@ impl L1Task for ArgsTask { } /// Tasks that could be executed using buffers +#[derive(Clone)] pub enum BufferTask { Commit(CommitTask), // TODO(edwin): Action in the future @@ -188,7 +200,7 @@ impl L1Task for BufferTask { } /// No further optimizations - fn optimize(self: Box) -> Result, Box> { + fn optimize(self: Box) -> Result, Box> { Err(self) } @@ -203,8 +215,7 @@ impl L1Task for BufferTask { committed_account.account.data.len(), MAX_WRITE_CHUNK_SIZE, ); - let chunks_account_size = - borsh::object_length(&chunks).unwrap().len() as u64; + let chunks_account_size = borsh::object_length(&chunks).unwrap() as u64; let buffer_account_size = committed_account.account.data.len() as u64; let (init_instruction, chunks_pda, buffer_pda) = @@ -213,7 +224,7 @@ impl L1Task for BufferTask { pubkey: committed_account.pubkey, chunks_account_size, buffer_account_size, - commit_id, + commit_id: commit_task.commit_id, chunk_count: chunks.count(), chunk_size: chunks.chunk_size(), }); @@ -223,7 +234,7 @@ impl L1Task for BufferTask { authority: *authority_pubkey, pubkey: committed_account.pubkey, buffer_account_size, - commit_id, + commit_id: commit_task.commit_id, }); let chunks_iter = ChangesetChunks::new(&chunks, chunks.chunk_size()) @@ -232,10 +243,10 @@ impl L1Task for BufferTask { .map(|chunk| { create_write_ix(CreateWriteIxArgs { authority: *authority_pubkey, - pubkey, + pubkey: committed_account.pubkey, offset: chunk.offset, data_chunk: chunk.data_chunk, - commit_id, + commit_id: commit_task.commit_id, }) }) .collect::>(); From 40eb0cd5b33c498366d12e7097b3a25aca39d16a Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 9 Jul 2025 17:57:27 +0900 Subject: [PATCH 087/199] fix: more compilation fixes --- .../src/commit/commit_using_buffer.rs | 2 +- .../transaction_preperator/delivery_preparator.rs | 13 +++++++++---- .../src/transaction_preperator/task_builder.rs | 11 +++-------- .../src/transaction_preperator/task_strategist.rs | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs index 15144d0a0..fcb214abe 100644 --- a/magicblock-committor-service/src/commit/commit_using_buffer.rs +++ b/magicblock-committor-service/src/commit/commit_using_buffer.rs @@ -760,7 +760,7 @@ impl CommittorProcessor { .instructions(init_ix_chunk.len() - 1); match send_and_confirm( self.magicblock_rpc_client.clone(), - self.authority.insecure_clone(), + &self.authority, [init_budget_ixs, init_ix_chunk.clone()].concat(), "init buffer and chunk account".to_string(), None, diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 3df801df9..a0f980181 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -101,8 +101,12 @@ impl DeliveryPreparator { }; // Initialize buffer account. Init + reallocs - self.initialize_buffer_account(authority, task, &preparation_info) - .await?; + self.initialize_buffer_account( + authority, + task.as_ref(), + &preparation_info, + ) + .await?; // Writing chunks with some retries. Stol self.write_buffer_with_retries::<5>(authority, &preparation_info) .await?; @@ -224,8 +228,9 @@ impl DeliveryPreparator { .instructions(instruction.data.len()); instructions.push(instruction); + // TODO: replace with join_all join_set.spawn(async move { - self.send_ixs_with_retry::<2>(&write_instructions, authority) + self.send_ixs_with_retry::<2>(&instructions, authority) .await .inspect_err(|err| { error!("Error writing into buffect account: {:?}", err) @@ -236,7 +241,7 @@ impl DeliveryPreparator { join_set .join_all() .await - .iter() + .into_iter() .collect::, _>>()?; Ok(()) diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs index 99c726c64..4f80fd4ab 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_builder.rs @@ -17,11 +17,6 @@ use magicblock_program::magic_scheduled_l1_message::{ ScheduledL1Message, UndelegateType, }; use solana_pubkey::Pubkey; -use solana_sdk::{ - instruction::{AccountMeta, Instruction}, - signature::Keypair, - signer::Signer, -}; use crate::transaction_preperator::tasks::{ ArgsTask, CommitTask, FinalizeTask, L1Task, TaskPreparationInfo, @@ -55,7 +50,7 @@ impl TasksBuilder for TaskBuilderV1 { MagicL1Message::L1Actions(actions) => { return actions .into_iter() - .map(|el| Task::L1Action(el.clone())) + .map(|el| Box::new(ArgsTask::L1Action(el.clone())) as Box) .collect() } MagicL1Message::Commit(t) => (t.get_committed_accounts(), false), @@ -68,11 +63,11 @@ impl TasksBuilder for TaskBuilderV1 { .into_iter() .map(|account| { if let Some(commit_id) = commit_ids.get(&account.pubkey) { - Ok(ArgsTask::Commit(CommitTask { + Ok(Box::new(ArgsTask::Commit(CommitTask { commit_id: *commit_id + 1, allow_undelegation, committed_account: account.clone(), - })) as Result, ()> + })) as Box) } else { // TODO(edwin): proper error Err(()) diff --git a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs index 30126882b..ebe4608e7 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs @@ -182,7 +182,7 @@ impl TaskStrategist { .unwrap(); // TODO(edwin): unwrap let tx = VersionedTransaction::try_new( VersionedMessage::V0(message), - &&[Keypair::new()], + &[Keypair::new()], ) .unwrap(); tx From 1fde0562286aef337bdd6ec8168679868dee4276 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 9 Jul 2025 19:14:19 +0900 Subject: [PATCH 088/199] fix: more compilation fixes --- .../src/instruction.rs | 1 - .../src/commit/commit_using_buffer.rs | 2 +- .../src/commit/committor_processor.rs | 2 +- .../delivery_preparator.rs | 57 +++++++------------ .../transaction_preperator/task_builder.rs | 17 ++---- .../transaction_preperator/task_strategist.rs | 5 +- .../transaction_preparator.rs | 1 + programs/magicblock/src/magic_context.rs | 8 +-- .../schedule_l1_message_processor.rs | 1 - 9 files changed, 32 insertions(+), 62 deletions(-) diff --git a/magicblock-committor-program/src/instruction.rs b/magicblock-committor-program/src/instruction.rs index d0bd7d36f..f6ef449bb 100644 --- a/magicblock-committor-program/src/instruction.rs +++ b/magicblock-committor-program/src/instruction.rs @@ -1,5 +1,4 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use solana_program::hash::HASH_BYTES; use solana_pubkey::Pubkey; #[derive(BorshSerialize, BorshDeserialize, Debug, Clone)] diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs index fcb214abe..a546d3b5e 100644 --- a/magicblock-committor-service/src/commit/commit_using_buffer.rs +++ b/magicblock-committor-service/src/commit/commit_using_buffer.rs @@ -921,7 +921,7 @@ impl CommittorProcessor { join_set.spawn(async move { send_and_confirm( rpc_client, - authority, + &authority, [realloc_budget_ixs, ixs].concat(), format!( "realloc buffer account {}/{}", diff --git a/magicblock-committor-service/src/commit/committor_processor.rs b/magicblock-committor-service/src/commit/committor_processor.rs index 944c964a6..fcdb9c998 100644 --- a/magicblock-committor-service/src/commit/committor_processor.rs +++ b/magicblock-committor-service/src/commit/committor_processor.rs @@ -524,7 +524,7 @@ pub(crate) async fn process_ixs_chunk( let compute_budget_ixs = compute_budget.instructions(commit_infos.len()); match send_and_confirm( rpc_client, - authority, + &authority, [compute_budget_ixs, ixs].concat(), "process commitable and/or close pdas".to_string(), Some(latest_blockhash), diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index a0f980181..6746866a4 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -1,18 +1,10 @@ -use std::{future::Future, ptr::write, sync::Arc, time::Duration}; +use std::time::Duration; use anyhow::anyhow; use borsh::BorshDeserialize; use futures_util::future::{join, join_all}; use log::{error, warn}; -use magicblock_committor_program::{ - instruction_builder::{ - init_buffer::{create_init_ix, CreateInitIxArgs}, - realloc_buffer::{ - create_realloc_buffer_ixs, CreateReallocBufferIxArgs, - }, - }, - Chunks, CommitableAccount, -}; +use magicblock_committor_program::{Chunks, CommitableAccount}; use magicblock_rpc_client::{ MagicBlockRpcClientError, MagicBlockSendTransactionConfig, MagicblockRpcClient, @@ -22,7 +14,6 @@ use solana_account::ReadableAccount; use solana_pubkey::Pubkey; use solana_rpc_client_api::client_error::reqwest::Version; use solana_sdk::{ - hash::Hash, instruction::Instruction, message::{ v0::Message, AddressLookupTableAccount, CompileError, VersionedMessage, @@ -31,18 +22,15 @@ use solana_sdk::{ signer::{Signer, SignerError}, transaction::VersionedTransaction, }; -use tokio::{task::JoinSet, time::sleep}; +use tokio::time::sleep; use crate::{ - consts::MAX_WRITE_CHUNK_SIZE, - error::{CommitAccountError, CommitAccountResult}, - persist::CommitStrategy, transaction_preperator::{ error::PreparatorResult, task_strategist::TransactionStrategy, - tasks::{CommitTask, L1Task, TaskPreparationInfo}, + tasks::{L1Task, TaskPreparationInfo}, }, - CommitInfo, ComputeBudgetConfig, + ComputeBudgetConfig, }; pub struct DeliveryPreparationResult { @@ -218,28 +206,25 @@ impl DeliveryPreparator { return Err(Error::InternalError(err)); } - let mut join_set = JoinSet::new(); let missing_chunks = chunks.get_missing_chunks(); - for missing_index in missing_chunks { - let instruction = write_instructions[missing_index].clone(); - let mut instructions = self - .compute_budget_config - .buffer_write - .instructions(instruction.data.len()); - instructions.push(instruction); + let chunks_write_instructions = missing_chunks + .into_iter() + .map(|missing_index| { + let instruction = write_instructions[missing_index].clone(); + let mut instructions = self + .compute_budget_config + .buffer_write + .instructions(instruction.data.len()); + instructions.push(instruction); + instructions + }) + .collect::>(); - // TODO: replace with join_all - join_set.spawn(async move { - self.send_ixs_with_retry::<2>(&instructions, authority) - .await - .inspect_err(|err| { - error!("Error writing into buffect account: {:?}", err) - }) - }); - } + let fut_iter = chunks_write_instructions.iter().map(|instructions| { + self.send_ixs_with_retry::<2>(instructions.as_slice(), authority) + }); - join_set - .join_all() + join_all(fut_iter) .await .into_iter() .collect::, _>>()?; diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs index 4f80fd4ab..57569ff65 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_builder.rs @@ -1,17 +1,5 @@ use std::collections::HashMap; -use dlp::args::{CallHandlerArgs, CommitStateArgs, CommitStateFromBufferArgs}; -use magicblock_committor_program::{ - instruction_builder::{ - init_buffer::{create_init_ix, CreateInitIxArgs}, - realloc_buffer::{ - create_realloc_buffer_ixs, CreateReallocBufferIxArgs, - }, - write_buffer::{create_write_ix, CreateWriteIxArgs}, - }, - instruction_chunks::chunk_realloc_ixs, - ChangesetChunks, Chunks, -}; use magicblock_program::magic_scheduled_l1_message::{ CommitType, CommittedAccountV2, L1Action, MagicL1Message, ScheduledL1Message, UndelegateType, @@ -50,7 +38,10 @@ impl TasksBuilder for TaskBuilderV1 { MagicL1Message::L1Actions(actions) => { return actions .into_iter() - .map(|el| Box::new(ArgsTask::L1Action(el.clone())) as Box) + .map(|el| { + Box::new(ArgsTask::L1Action(el.clone())) + as Box + }) .collect() } MagicL1Message::Commit(t) => (t.get_committed_accounts(), false), diff --git a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs index ebe4608e7..f3566f00c 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs @@ -80,7 +80,7 @@ impl TaskStrategist { // Create heap size -> index let sizes = ixs .iter() - .map(|ix| borsh::object_length(ix)) + .map(|ix| bincode::serialized_size(ix).map(|size| size as usize)) .collect::, _>>() .unwrap(); @@ -117,7 +117,8 @@ impl TaskStrategist { // TODO(edwin): this is expensive let new_ix = tasks[index].instruction(&Pubkey::new_unique()); - let new_ix_size = borsh::object_length(&new_ix).unwrap(); // TODO(edwin): unwrap + let new_ix_size = + bincode::serialized_size(&new_ix).unwrap() as usize; // TODO(edwin): unwrap let new_tx = Self::assemble_tx_with_budget(&tasks); map.push((new_ix_size, index)); diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 03882e0b7..bfa346614 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -71,6 +71,7 @@ impl TransactionPreparatorV1 { } } +#[async_trait] impl TransactionPreparator for TransactionPreparatorV1 { fn version(&self) -> PreparatorVersion { PreparatorVersion::V1 diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index 916d163e4..f245e1904 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -4,16 +4,10 @@ use magicblock_core::magic_program; use serde::{Deserialize, Serialize}; use solana_sdk::{ account::{AccountSharedData, ReadableAccount}, - clock::Slot, - hash::Hash, pubkey::Pubkey, - transaction::Transaction, }; -use crate::magic_scheduled_l1_message::{ - CommitAndUndelegate, CommitType, CommittedAccountV2, MagicL1Message, - ScheduledL1Message, ShortAccountMeta, UndelegateType, -}; +use crate::magic_scheduled_l1_message::ScheduledL1Message; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FeePayerAccount { diff --git a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs index 29a878858..02d3fd1e5 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs @@ -1,4 +1,3 @@ -use solana_program_runtime::invoke_context::InvokeContext; use solana_sdk::{ instruction::InstructionError, transaction_context::TransactionContext, }; From 82b7f5375b76454a805a1bdd6171f763af16f7f0 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 10 Jul 2025 12:56:32 +0900 Subject: [PATCH 089/199] feat: TransactionUtilities to assemle TX from Tasks --- .../delivery_preparator.rs | 45 +++-- .../transaction_preperator/task_strategist.rs | 154 ++++++------------ .../transaction_preparator.rs | 35 +++- .../src/transaction_preperator/utils.rs | 107 ++++++++++++ 4 files changed, 220 insertions(+), 121 deletions(-) diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 6746866a4..44d260718 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -1,5 +1,14 @@ +use std::collections::HashSet; use std::time::Duration; +use crate::{ + transaction_preperator::{ + error::PreparatorResult, + task_strategist::TransactionStrategy, + tasks::{L1Task, TaskPreparationInfo}, + }, + ComputeBudgetConfig, +}; use anyhow::anyhow; use borsh::BorshDeserialize; use futures_util::future::{join, join_all}; @@ -9,6 +18,7 @@ use magicblock_rpc_client::{ MagicBlockRpcClientError, MagicBlockSendTransactionConfig, MagicblockRpcClient, }; +use magicblock_table_mania::error::TableManiaError; use magicblock_table_mania::TableMania; use solana_account::ReadableAccount; use solana_pubkey::Pubkey; @@ -24,15 +34,6 @@ use solana_sdk::{ }; use tokio::time::sleep; -use crate::{ - transaction_preperator::{ - error::PreparatorResult, - task_strategist::TransactionStrategy, - tasks::{L1Task, TaskPreparationInfo}, - }, - ComputeBudgetConfig, -}; - pub struct DeliveryPreparationResult { lookup_tables: Vec, } @@ -68,7 +69,8 @@ impl DeliveryPreparator { .map(|task| self.prepare_task(authority, task)); let fut1 = join_all(preparation_futures); - let fut2 = self.prepare_lookup_tables(&strategy.lookup_tables_keys); + let fut2 = + self.prepare_lookup_tables(authority, &strategy.lookup_tables_keys); let (res1, res2) = join(fut1, fut2).await; res1.into_iter().collect::, _>>()?; @@ -281,9 +283,28 @@ impl DeliveryPreparator { /// Prepares ALTs for pubkeys participating in tx async fn prepare_lookup_tables( &self, + authority: &Keypair, lookup_table_keys: &[Vec], ) -> DeliveryPreparatorResult> { - // self.table_mania. + let pubkeys = HashSet::from_iter(lookup_table_keys.iter().flatten()); + self.table_mania + .reserve_pubkeys(authority, &pubkeys) + .await?; + + let alts = self + .table_mania + .try_get_active_address_lookup_table_accounts( + &pubkeys, // enough time for init/extend lookup table transaction to complete + Duration::from_secs(50), + // enough time for lookup table to finalize + Duration::from_secs(50), + ) + .await?; + Ok(alts) + } + + // TODO(edwin): cleanup + async fn clean() { todo!() } } @@ -295,6 +316,8 @@ pub enum Error { InternalError(anyhow::Error), #[error("BorshError: {0}")] BorshError(#[from] std::io::Error), + #[error("TableManiaError: {0}")] + TableManiaError(#[from] TableManiaError), #[error("TransactionCreationError: {0}")] TransactionCreationError(#[from] CompileError), #[error("TransactionSigningError: {0}")] diff --git a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs index f3566f00c..50b6f747f 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs @@ -5,17 +5,12 @@ use std::{ use solana_pubkey::Pubkey; use solana_sdk::{ - address_lookup_table::AddressLookupTableAccount, - hash::Hash, - instruction::Instruction, - message::{v0::Message, VersionedMessage}, signature::Keypair, - transaction::VersionedTransaction, }; +use crate::transaction_preperator::utils::TransactionUtils; use crate::{ transaction_preperator::{ - budget_calculator::ComputeBudgetV1, error::{Error, PreparatorResult}, tasks::{ArgsTask, L1Task}, }, @@ -34,37 +29,58 @@ impl TaskStrategist { mut tasks: Vec>, validator: &Pubkey, ) -> PreparatorResult { - // Optimize srategy + // Attempt optimizing tasks themselves(using buffers) if Self::optimize_strategy(&mut tasks) <= MAX_ENCODED_TRANSACTION_SIZE { - return Ok(TransactionStrategy { + Ok(TransactionStrategy { optimized_tasks: tasks, lookup_tables_keys: vec![], - }); + }) + } else { + // In case task optimization didn't work + // attempt using lookup tables for all keys involved in tasks + let lookup_tables_keys = + Self::attempt_lookup_tables(&validator, &tasks)?; + Ok(TransactionStrategy { + optimized_tasks: tasks, + lookup_tables_keys, + }) } + } - let budget_instructions = Self::budget_instructions( - &tasks.iter().map(|task| task.budget()).collect::>(), - ); - let lookup_tables = Self::assemble_lookup_table( - &mut tasks, + /// Attempt to use ALTs for ALL keys in tx + /// TODO: optimize to use only necessary amount of pubkeys + fn attempt_lookup_tables( + validator: &Pubkey, + tasks: &[Box], + ) -> PreparatorResult>> { + // Gather all involved keys in tx + let budgets = TransactionUtils::tasks_budgets(&tasks); + let budget_instructions = + TransactionUtils::budget_instructions(&budgets); + let unique_involved_pubkeys = TransactionUtils::unique_involved_pubkeys( + &tasks, validator, &budget_instructions, ); - let alt_tx = Self::assemble_tx_with_lookup_table( - &tasks, + let dummy_lookup_tables = + TransactionUtils::dummy_lookup_table(&unique_involved_pubkeys); + + // Create final tx + let instructions = + TransactionUtils::tasks_instructions(validator, &tasks); + let alt_tx = TransactionUtils::assemble_tx_raw( + &Keypair::new(), + &instructions, &budget_instructions, - &lookup_tables, + &dummy_lookup_tables, ); let encoded_alt_tx = serialize_and_encode_base64(&alt_tx); if encoded_alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE { - let lookup_tables_keys = lookup_tables + let lookup_tables_keys = dummy_lookup_tables .into_iter() .map(|table| table.addresses) .collect(); - Ok(TransactionStrategy { - optimized_tasks: tasks, - lookup_tables_keys, - }) + Ok(lookup_tables_keys) } else { Err(Error::FailedToFitError) } @@ -73,22 +89,25 @@ impl TaskStrategist { /// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`] /// Returns size of tx after optimizations fn optimize_strategy(tasks: &mut [Box]) -> usize { - let ixs = Self::assemble_ixs(&tasks); - let tx = Self::assemble_tx_with_budget(&tasks); + // Get initial transaction size + let tx = + TransactionUtils::assemble_tasks_tx(&Keypair::new(), &tasks, &[]); let mut current_tx_length = serialize_and_encode_base64(&tx).len(); // Create heap size -> index + // TODO(edwin): OPTIMIZATION. update ixs arr, since we know index, coul then reuse for tx creation + let ixs = TransactionUtils::tasks_instructions(&tasks); let sizes = ixs .iter() .map(|ix| bincode::serialized_size(ix).map(|size| size as usize)) .collect::, _>>() .unwrap(); - let mut map = sizes .into_iter() .enumerate() .map(|(index, size)| (size, index)) .collect::>(); + // We keep popping heaviest el-ts & try to optimize while heap is non-empty while let Some((_, index)) = map.pop() { if current_tx_length <= MAX_ENCODED_TRANSACTION_SIZE { @@ -117,9 +136,14 @@ impl TaskStrategist { // TODO(edwin): this is expensive let new_ix = tasks[index].instruction(&Pubkey::new_unique()); - let new_ix_size = - bincode::serialized_size(&new_ix).unwrap() as usize; // TODO(edwin): unwrap - let new_tx = Self::assemble_tx_with_budget(&tasks); + let new_ix_size = bincode::serialized_size(&new_ix) + .expect("instruction serialization") + as usize; // TODO(edwin): unwrap + let new_tx = TransactionUtils::assemble_tasks_tx( + &Keypair::new(), + &tasks, + &[], + ); map.push((new_ix_size, index)); current_tx_length = @@ -136,78 +160,4 @@ impl TaskStrategist { current_tx_length } - - fn assemble_lookup_table( - tasks: &[Box], - validator: &Pubkey, - budget_instructions: &[Instruction], - ) -> Vec { - // Collect all unique pubkeys from tasks and budget instructions - let mut all_pubkeys: HashSet = tasks - .iter() - .flat_map(|task| task.involved_accounts(validator)) - .collect(); - - all_pubkeys.extend( - budget_instructions - .iter() - .flat_map(|ix| ix.accounts.iter().map(|meta| meta.pubkey)), - ); - - // Split into chunks of max 256 addresses - all_pubkeys - .into_iter() - .collect::>() - .chunks(256) - .map(|addresses| AddressLookupTableAccount { - key: Pubkey::new_unique(), - addresses: addresses.to_vec(), - }) - .collect() - } - - // TODO(edwin): improve - fn assemble_tx_with_lookup_table( - tasks: &[Box], - budget_instructions: &[Instruction], - lookup_tables: &[AddressLookupTableAccount], - ) -> VersionedTransaction { - // In case we can't fit with optimal strategy - try ALT - let ixs = Self::assemble_ixs_with_budget(&tasks); - let message = Message::try_compile( - &Pubkey::new_unique(), - &[budget_instructions, &ixs].concat(), - &lookup_tables, - Hash::new_unique(), - ) - .unwrap(); // TODO(edwin): unwrap - let tx = VersionedTransaction::try_new( - VersionedMessage::V0(message), - &[Keypair::new()], - ) - .unwrap(); - tx - } - - fn budget_instructions(budgets: &[ComputeBudgetV1]) -> Vec { - todo!() - } - - fn assemble_ixs_with_budget( - strategies: &[Box], - ) -> Vec { - todo!() - } - - fn assemble_ixs(tasks: &[Box]) -> Vec { - // Just given Strategy(Task) creates dummy ixs - // Then assemls ixs into tx - todo!() - } - - fn assemble_tx_with_budget( - tasks: &[Box], - ) -> VersionedTransaction { - todo!() - } } diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index bfa346614..f4d619546 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -1,5 +1,13 @@ use std::collections::HashMap; +use crate::transaction_preperator::delivery_preparator::DeliveryPreparator; +use crate::transaction_preperator::{ + budget_calculator::{ComputeBudgetCalculator, ComputeBudgetCalculatorV1}, + error::{Error, PreparatorResult}, + task_builder::{TaskBuilderV1, TasksBuilder}, + task_strategist::TaskStrategist, +}; +use crate::ComputeBudgetConfig; use async_trait::async_trait; use magicblock_program::magic_scheduled_l1_message::{ CommittedAccountV2, L1Action, MagicL1Message, ScheduledL1Message, @@ -9,13 +17,6 @@ use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; use solana_sdk::{message::v0::Message, signature::Keypair, signer::Signer}; -use crate::transaction_preperator::{ - budget_calculator::{ComputeBudgetCalculator, ComputeBudgetCalculatorV1}, - error::{Error, PreparatorResult}, - task_builder::{TaskBuilderV1, TasksBuilder}, - task_strategist::TaskStrategist, -}; - /// Transaction Preparator version /// Some actions maybe imnvalid per version #[derive(Debug)] @@ -44,6 +45,7 @@ trait TransactionPreparator { /// It omits future commit_bundle/finalize_bundle logic /// It creates TXs using current per account commit/finalize struct TransactionPreparatorV1 { + delivery_preparator: DeliveryPreparator, rpc_client: MagicblockRpcClient, table_mania: TableMania, // TODO(edwin): Arc? } @@ -52,10 +54,17 @@ impl TransactionPreparatorV1 { pub fn new( rpc_client: MagicblockRpcClient, table_mania: TableMania, + compute_budget_config: ComputeBudgetConfig, ) -> Self { + let delivery_preparator = DeliveryPreparator::new( + rpc_client.clone(), + table_mania.clone(), + compute_budget_config, + ); Self { rpc_client, table_mania, + delivery_preparator, } } @@ -96,6 +105,11 @@ impl TransactionPreparator for TransactionPreparatorV1 { let tx_strategy = TaskStrategist::build_strategy(tasks, &authority.pubkey())?; // 3. + let _ = self + .delivery_preparator + .prepare_for_delivery(authority, &tx_strategy) + .await + .unwrap(); // TODO: fix todo!() } @@ -110,7 +124,12 @@ impl TransactionPreparator for TransactionPreparatorV1 { let tasks = TaskBuilderV1::finalize_tasks(l1_message, rent_reimbursement); let tx_strategy = - TaskStrategist::build_strategy(tasks, &authority.pubkey()); + TaskStrategist::build_strategy(tasks, &authority.pubkey())?; + let _ = self + .delivery_preparator + .prepare_for_delivery(authority, &tx_strategy) + .await + .unwrap(); // TODO: fix todo!() } diff --git a/magicblock-committor-service/src/transaction_preperator/utils.rs b/magicblock-committor-service/src/transaction_preperator/utils.rs index 3b4f3b1f3..b998c2c93 100644 --- a/magicblock-committor-service/src/transaction_preperator/utils.rs +++ b/magicblock-committor-service/src/transaction_preperator/utils.rs @@ -1,8 +1,17 @@ +use crate::transaction_preperator::budget_calculator::ComputeBudgetV1; +use crate::transaction_preperator::tasks::L1Task; use solana_pubkey::Pubkey; +use solana_sdk::hash::Hash; +use solana_sdk::instruction::Instruction; +use solana_sdk::message::v0::Message; +use solana_sdk::message::VersionedMessage; +use solana_sdk::signature::Keypair; +use solana_sdk::signer::Signer; use solana_sdk::{ address_lookup_table::state::AddressLookupTable, message::AddressLookupTableAccount, transaction::VersionedTransaction, }; +use std::collections::HashSet; /// Returns [`Vec`] where all TX accounts stored in ALT pub fn estimate_lookup_tables_for_tx( @@ -18,3 +27,101 @@ pub fn estimate_lookup_tables_for_tx( }) .collect() } + +pub struct TransactionUtils; +impl TransactionUtils { + pub fn dummy_lookup_table( + pubkeys: &[Pubkey], + ) -> Vec { + pubkeys + .chunks(256) + .map(|addresses| AddressLookupTableAccount { + key: Pubkey::new_unique(), + addresses: addresses.to_vec(), + }) + .collect() + } + + pub fn unique_involved_pubkeys( + tasks: &[Box], + validator: &Pubkey, + budget_instructions: &[Instruction], + ) -> Vec { + // Collect all unique pubkeys from tasks and budget instructions + let mut all_pubkeys: HashSet = tasks + .iter() + .flat_map(|task| task.involved_accounts(validator)) + .collect(); + + all_pubkeys.extend( + budget_instructions + .iter() + .flat_map(|ix| ix.accounts.iter().map(|meta| meta.pubkey)), + ); + + all_pubkeys.into_iter().collect::>() + } + + pub fn tasks_instructions( + validator: &Pubkey, + tasks: &[Box], + ) -> Vec { + tasks + .iter() + .map(|task| task.instruction(validator)) + .collect() + } + + pub fn assemble_tasks_tx( + authority: &Keypair, + tasks: &[Box], + lookup_tables: &[AddressLookupTableAccount], + ) -> VersionedTransaction { + // In case we can't fit with optimal strategy - try ALT + let budget_instructions = + Self::budget_instructions(&Self::tasks_budgets(&tasks)); + let ixs = Self::tasks_instructions(&authority.pubkey(), &tasks); + Self::assemble_tx_raw( + authority, + &ixs, + &budget_instructions, + lookup_tables, + ) + } + + pub fn assemble_tx_raw( + authority: &Keypair, + instructions: &[Instruction], + budget_instructions: &[Instruction], + lookup_tables: &[AddressLookupTableAccount], + ) -> VersionedTransaction { + let message = Message::try_compile( + &Pubkey::new_unique(), + &[budget_instructions, instructions].concat(), + &lookup_tables, + Hash::new_unique(), + ) + .unwrap(); // TODO(edwin): unwrap + let tx = VersionedTransaction::try_new( + VersionedMessage::V0(message), + &[authority], + ) + .unwrap(); + tx + } + + pub fn tasks_budgets( + tasks: &[impl AsRef], + ) -> Vec { + tasks + .iter() + .map(|task| task.as_ref().budget()) + .collect::>() + } + + pub fn budget_instructions( + budgets: &[ComputeBudgetV1], + ) -> [Instruction; 2] { + todo!() + } +} From 93020a90081130f1c2e415b91693e5f9c8d33bef Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 10 Jul 2025 12:56:47 +0900 Subject: [PATCH 090/199] refactor: fmt --- .../delivery_preparator.rs | 23 +++++++++---------- .../transaction_preperator/task_strategist.rs | 6 ++--- .../transaction_preparator.rs | 21 ++++++++++------- .../src/transaction_preperator/utils.rs | 22 ++++++++++-------- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 44d260718..5f71fed96 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -1,14 +1,5 @@ -use std::collections::HashSet; -use std::time::Duration; +use std::{collections::HashSet, time::Duration}; -use crate::{ - transaction_preperator::{ - error::PreparatorResult, - task_strategist::TransactionStrategy, - tasks::{L1Task, TaskPreparationInfo}, - }, - ComputeBudgetConfig, -}; use anyhow::anyhow; use borsh::BorshDeserialize; use futures_util::future::{join, join_all}; @@ -18,8 +9,7 @@ use magicblock_rpc_client::{ MagicBlockRpcClientError, MagicBlockSendTransactionConfig, MagicblockRpcClient, }; -use magicblock_table_mania::error::TableManiaError; -use magicblock_table_mania::TableMania; +use magicblock_table_mania::{error::TableManiaError, TableMania}; use solana_account::ReadableAccount; use solana_pubkey::Pubkey; use solana_rpc_client_api::client_error::reqwest::Version; @@ -34,6 +24,15 @@ use solana_sdk::{ }; use tokio::time::sleep; +use crate::{ + transaction_preperator::{ + error::PreparatorResult, + task_strategist::TransactionStrategy, + tasks::{L1Task, TaskPreparationInfo}, + }, + ComputeBudgetConfig, +}; + pub struct DeliveryPreparationResult { lookup_tables: Vec, } diff --git a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs index 50b6f747f..089331941 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs @@ -4,15 +4,13 @@ use std::{ }; use solana_pubkey::Pubkey; -use solana_sdk::{ - signature::Keypair, -}; +use solana_sdk::signature::Keypair; -use crate::transaction_preperator::utils::TransactionUtils; use crate::{ transaction_preperator::{ error::{Error, PreparatorResult}, tasks::{ArgsTask, L1Task}, + utils::TransactionUtils, }, transactions::{serialize_and_encode_base64, MAX_ENCODED_TRANSACTION_SIZE}, }; diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index f4d619546..da4caa08d 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -1,13 +1,5 @@ use std::collections::HashMap; -use crate::transaction_preperator::delivery_preparator::DeliveryPreparator; -use crate::transaction_preperator::{ - budget_calculator::{ComputeBudgetCalculator, ComputeBudgetCalculatorV1}, - error::{Error, PreparatorResult}, - task_builder::{TaskBuilderV1, TasksBuilder}, - task_strategist::TaskStrategist, -}; -use crate::ComputeBudgetConfig; use async_trait::async_trait; use magicblock_program::magic_scheduled_l1_message::{ CommittedAccountV2, L1Action, MagicL1Message, ScheduledL1Message, @@ -17,6 +9,19 @@ use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; use solana_sdk::{message::v0::Message, signature::Keypair, signer::Signer}; +use crate::{ + transaction_preperator::{ + budget_calculator::{ + ComputeBudgetCalculator, ComputeBudgetCalculatorV1, + }, + delivery_preparator::DeliveryPreparator, + error::{Error, PreparatorResult}, + task_builder::{TaskBuilderV1, TasksBuilder}, + task_strategist::TaskStrategist, + }, + ComputeBudgetConfig, +}; + /// Transaction Preparator version /// Some actions maybe imnvalid per version #[derive(Debug)] diff --git a/magicblock-committor-service/src/transaction_preperator/utils.rs b/magicblock-committor-service/src/transaction_preperator/utils.rs index b998c2c93..f0141edca 100644 --- a/magicblock-committor-service/src/transaction_preperator/utils.rs +++ b/magicblock-committor-service/src/transaction_preperator/utils.rs @@ -1,17 +1,19 @@ -use crate::transaction_preperator::budget_calculator::ComputeBudgetV1; -use crate::transaction_preperator::tasks::L1Task; +use std::collections::HashSet; + use solana_pubkey::Pubkey; -use solana_sdk::hash::Hash; -use solana_sdk::instruction::Instruction; -use solana_sdk::message::v0::Message; -use solana_sdk::message::VersionedMessage; -use solana_sdk::signature::Keypair; -use solana_sdk::signer::Signer; use solana_sdk::{ address_lookup_table::state::AddressLookupTable, - message::AddressLookupTableAccount, transaction::VersionedTransaction, + hash::Hash, + instruction::Instruction, + message::{v0::Message, AddressLookupTableAccount, VersionedMessage}, + signature::Keypair, + signer::Signer, + transaction::VersionedTransaction, +}; + +use crate::transaction_preperator::{ + budget_calculator::ComputeBudgetV1, tasks::L1Task, }; -use std::collections::HashSet; /// Returns [`Vec`] where all TX accounts stored in ALT pub fn estimate_lookup_tables_for_tx( From 18c10a588d038c88eefd8a7ebc0399465932d000 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 10 Jul 2025 13:38:15 +0900 Subject: [PATCH 091/199] fix: some compilation errors --- .../src/commit/commit_using_buffer.rs | 2 +- .../delivery_preparator.rs | 17 +++-- .../src/transaction_preperator/error.rs | 2 +- .../transaction_preperator/task_strategist.rs | 14 ++-- .../src/transaction_preperator/tasks.rs | 2 +- .../transaction_preparator.rs | 75 +++++++++++-------- .../src/transaction_preperator/utils.rs | 3 +- 7 files changed, 61 insertions(+), 54 deletions(-) diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs index a546d3b5e..0b78139e4 100644 --- a/magicblock-committor-service/src/commit/commit_using_buffer.rs +++ b/magicblock-committor-service/src/commit/commit_using_buffer.rs @@ -1011,7 +1011,7 @@ impl CommittorProcessor { join_set.spawn(async move { send_and_confirm( rpc_client, - authority, + &authority, [write_budget_ixs, vec![ix]].concat(), format!("write chunk for offset {}", chunk.offset), Some(latest_blockhash), diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 5f71fed96..598428d79 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -61,20 +61,21 @@ impl DeliveryPreparator { &self, authority: &Keypair, strategy: &TransactionStrategy, - ) -> DeliveryPreparatorResult<()> { + ) -> DeliveryPreparatorResult> { let preparation_futures = strategy .optimized_tasks .iter() .map(|task| self.prepare_task(authority, task)); - let fut1 = join_all(preparation_futures); - let fut2 = + let task_preparations = join_all(preparation_futures); + let alts_preparations = self.prepare_lookup_tables(authority, &strategy.lookup_tables_keys); - let (res1, res2) = join(fut1, fut2).await; + let (res1, res2) = join(task_preparations, alts_preparations).await; res1.into_iter().collect::, _>>()?; - res2?; - Ok(()) + + let lookup_tables = res2?; + Ok(lookup_tables) } /// Prepares necessary parts for TX if needed, otherwise returns immediately @@ -283,9 +284,9 @@ impl DeliveryPreparator { async fn prepare_lookup_tables( &self, authority: &Keypair, - lookup_table_keys: &[Vec], + lookup_table_keys: &[Pubkey], ) -> DeliveryPreparatorResult> { - let pubkeys = HashSet::from_iter(lookup_table_keys.iter().flatten()); + let pubkeys = HashSet::from_iter(lookup_table_keys.iter().copied()); self.table_mania .reserve_pubkeys(authority, &pubkeys) .await?; diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preperator/error.rs index d40af99af..1099bb257 100644 --- a/magicblock-committor-service/src/transaction_preperator/error.rs +++ b/magicblock-committor-service/src/transaction_preperator/error.rs @@ -4,7 +4,7 @@ use crate::transaction_preperator::transaction_preparator::PreparatorVersion; #[derive(Error, Debug)] pub enum Error { - #[error("Invalid action for version: {0}")] + #[error("Invalid action for TransactionPreparatir version: {0}")] VersionError(PreparatorVersion), #[error("Failed to fit in single TX")] FailedToFitError, diff --git a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs index 089331941..91917c811 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs @@ -17,12 +17,13 @@ use crate::{ pub struct TransactionStrategy { pub optimized_tasks: Vec>, - pub lookup_tables_keys: Vec>, + pub lookup_tables_keys: Vec, } pub struct TaskStrategist; impl TaskStrategist { /// Returns [`TaskDeliveryStrategy`] for every [`Task`] + /// Returns Error if all optimizations weren't enough pub fn build_strategy( mut tasks: Vec>, validator: &Pubkey, @@ -50,7 +51,7 @@ impl TaskStrategist { fn attempt_lookup_tables( validator: &Pubkey, tasks: &[Box], - ) -> PreparatorResult>> { + ) -> PreparatorResult> { // Gather all involved keys in tx let budgets = TransactionUtils::tasks_budgets(&tasks); let budget_instructions = @@ -74,11 +75,7 @@ impl TaskStrategist { ); let encoded_alt_tx = serialize_and_encode_base64(&alt_tx); if encoded_alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE { - let lookup_tables_keys = dummy_lookup_tables - .into_iter() - .map(|table| table.addresses) - .collect(); - Ok(lookup_tables_keys) + Ok(unique_involved_pubkeys) } else { Err(Error::FailedToFitError) } @@ -94,7 +91,8 @@ impl TaskStrategist { // Create heap size -> index // TODO(edwin): OPTIMIZATION. update ixs arr, since we know index, coul then reuse for tx creation - let ixs = TransactionUtils::tasks_instructions(&tasks); + let ixs = + TransactionUtils::tasks_instructions(&Pubkey::new_unique(), &tasks); let sizes = ixs .iter() .map(|ix| bincode::serialized_size(ix).map(|size| size as usize)) diff --git a/magicblock-committor-service/src/transaction_preperator/tasks.rs b/magicblock-committor-service/src/transaction_preperator/tasks.rs index 3efa17dcf..876418069 100644 --- a/magicblock-committor-service/src/transaction_preperator/tasks.rs +++ b/magicblock-committor-service/src/transaction_preperator/tasks.rs @@ -31,7 +31,7 @@ pub struct TaskPreparationInfo { pub write_instructions: Vec, } -pub trait L1Task { +pub trait L1Task: Send + Sync { /// Gets all pubkeys that involved in Task's instruction fn involved_accounts(&self, validator: &Pubkey) -> Vec { self.instruction(validator) diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index da4caa08d..5e6206e8a 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -1,49 +1,61 @@ -use std::collections::HashMap; +use std::{collections::HashMap, fmt::Formatter}; use async_trait::async_trait; -use magicblock_program::magic_scheduled_l1_message::{ - CommittedAccountV2, L1Action, MagicL1Message, ScheduledL1Message, -}; +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; -use solana_sdk::{message::v0::Message, signature::Keypair, signer::Signer}; +use solana_sdk::{ + message::VersionedMessage, signature::Keypair, signer::Signer, +}; use crate::{ transaction_preperator::{ - budget_calculator::{ - ComputeBudgetCalculator, ComputeBudgetCalculatorV1, - }, delivery_preparator::DeliveryPreparator, - error::{Error, PreparatorResult}, + error::PreparatorResult, task_builder::{TaskBuilderV1, TasksBuilder}, task_strategist::TaskStrategist, + utils::TransactionUtils, }, ComputeBudgetConfig, }; /// Transaction Preparator version -/// Some actions maybe imnvalid per version +/// Some actions maybe invalid per version #[derive(Debug)] pub enum PreparatorVersion { V1, } +impl std::fmt::Display for PreparatorVersion { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + Self::V1 => write!(f, "V1"), + } + } +} + #[async_trait] trait TransactionPreparator { fn version(&self) -> PreparatorVersion; + + /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks + /// Handles all necessary preparations for Message to be valid async fn prepare_commit_tx( &self, authority: &Keypair, l1_message: &ScheduledL1Message, commit_ids: HashMap, - ) -> PreparatorResult; + ) -> PreparatorResult; + + /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks + /// Handles all necessary preparations for Message to be valid async fn prepare_finalize_tx( &self, authority: &Keypair, rent_reimbursement: &Pubkey, l1_message: &ScheduledL1Message, - ) -> PreparatorResult; + ) -> PreparatorResult; } /// [`TransactionPreparatorV1`] first version of preparator @@ -72,17 +84,6 @@ impl TransactionPreparatorV1 { delivery_preparator, } } - - // TODO(edwin) - fn prepare_action_tx(actions: &Vec) -> PreparatorResult { - todo!() - } - - fn prepare_committed_accounts_tx( - account: &Vec, - ) -> PreparatorResult { - todo!() - } } #[async_trait] @@ -98,25 +99,27 @@ impl TransactionPreparator for TransactionPreparatorV1 { authority: &Keypair, l1_message: &ScheduledL1Message, commit_ids: HashMap, - ) -> PreparatorResult { + ) -> PreparatorResult { // 1. create tasks // 2. optimize to fit tx size. aka Delivery Strategy // 3. Pre tx preparations. Create buffer accs + lookup tables // 4. Build resulting TX to be executed - - // 1. let tasks = TaskBuilderV1::commit_tasks(l1_message, commit_ids); - // 2. let tx_strategy = TaskStrategist::build_strategy(tasks, &authority.pubkey())?; - // 3. - let _ = self + let lookup_tables = self .delivery_preparator .prepare_for_delivery(authority, &tx_strategy) .await .unwrap(); // TODO: fix - todo!() + let message = TransactionUtils::assemble_tasks_tx( + authority, + &tx_strategy.optimized_tasks, + &lookup_tables, + ) + .message; + Ok(message) } /// In V1: prepares single TX with finalize, undelegation + actions @@ -125,18 +128,24 @@ impl TransactionPreparator for TransactionPreparatorV1 { authority: &Keypair, rent_reimbursement: &Pubkey, l1_message: &ScheduledL1Message, - ) -> PreparatorResult { + ) -> PreparatorResult { let tasks = TaskBuilderV1::finalize_tasks(l1_message, rent_reimbursement); let tx_strategy = TaskStrategist::build_strategy(tasks, &authority.pubkey())?; - let _ = self + let lookup_tables = self .delivery_preparator .prepare_for_delivery(authority, &tx_strategy) .await .unwrap(); // TODO: fix - todo!() + let message = TransactionUtils::assemble_tasks_tx( + authority, + &tx_strategy.optimized_tasks, + &lookup_tables, + ) + .message; + Ok(message) } } diff --git a/magicblock-committor-service/src/transaction_preperator/utils.rs b/magicblock-committor-service/src/transaction_preperator/utils.rs index f0141edca..14ceecdcc 100644 --- a/magicblock-committor-service/src/transaction_preperator/utils.rs +++ b/magicblock-committor-service/src/transaction_preperator/utils.rs @@ -79,7 +79,6 @@ impl TransactionUtils { tasks: &[Box], lookup_tables: &[AddressLookupTableAccount], ) -> VersionedTransaction { - // In case we can't fit with optimal strategy - try ALT let budget_instructions = Self::budget_instructions(&Self::tasks_budgets(&tasks)); let ixs = Self::tasks_instructions(&authority.pubkey(), &tasks); @@ -98,7 +97,7 @@ impl TransactionUtils { lookup_tables: &[AddressLookupTableAccount], ) -> VersionedTransaction { let message = Message::try_compile( - &Pubkey::new_unique(), + &authority.pubkey(), &[budget_instructions, instructions].concat(), &lookup_tables, Hash::new_unique(), From d36ef488479742706a537f6e174a009d0c644788 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 11 Jul 2025 13:42:32 +0900 Subject: [PATCH 092/199] feat: initial scheduler --- Cargo.toml | 1 + .../src/commit/commit_scheduler.rs | 151 ------------ .../src/commit/committor_processor.rs | 137 +---------- .../src/commit/mod.rs | 1 - .../src/commit_scheduler.rs | 100 ++++++++ .../commit_scheduler_worker.rs | 223 ++++++++++++++++++ .../src/commit_scheduler/db.rs | 69 ++++++ .../src/commit_stage.rs | 1 + magicblock-committor-service/src/lib.rs | 1 + magicblock-committor-service/src/service.rs | 6 +- .../src/transaction_preperator/tasks.rs | 2 + .../transaction_preparator.rs | 2 + 12 files changed, 402 insertions(+), 292 deletions(-) delete mode 100644 magicblock-committor-service/src/commit/commit_scheduler.rs create mode 100644 magicblock-committor-service/src/commit_scheduler.rs create mode 100644 magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs create mode 100644 magicblock-committor-service/src/commit_scheduler/db.rs diff --git a/Cargo.toml b/Cargo.toml index e63aba115..a42d9a170 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -179,6 +179,7 @@ spl-token-2022 = "=6.0" static_assertions = "1.1.0" strum = "0.24" strum_macros = "0.24" +lru = "0.16.0" tempfile = "3.10.1" test-tools = { path = "./test-tools" } test-tools-core = { path = "./test-tools-core" } diff --git a/magicblock-committor-service/src/commit/commit_scheduler.rs b/magicblock-committor-service/src/commit/commit_scheduler.rs deleted file mode 100644 index 0fe6f1e04..000000000 --- a/magicblock-committor-service/src/commit/commit_scheduler.rs +++ /dev/null @@ -1,151 +0,0 @@ -use std::{ - collections::VecDeque, - sync::{ - atomic::{AtomicBool, Ordering}, - Arc, - }, -}; - -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; -use tokio::{ - select, - sync::mpsc::{ - channel, - error::{SendError, TryRecvError, TrySendError}, - Receiver, Sender, - }, -}; - -pub struct CommitScheduler { - queue: VecDeque, - sender: Sender, -} - -impl CommitScheduler { - pub fn new() -> Self { - // TODO: define - let (sender, receiver) = channel(1000); - tokio::spawn(Self::start(receiver)); - - Self { - queue: VecDeque::default(), - sender, - } - } - - async fn start( - mut l1_message_receiver: Receiver, - db_flag: Arc, - ) { - // scheduler - // accepts messages - // if no commits we shall be idle - loop { - let message = match l1_message_receiver.try_recv() { - Ok(val) => val, - Err(TryRecvError::Empty) => { - if let Ok(val) = Self::get_next_message( - &mut l1_message_receiver, - &db_flag, - ) - .await - { - val - } else { - // TODO(edwin): handle - panic!("Asdasd") - } - } - Err(TryRecvError::Disconnected) => { - // TODO(edwin): handle - panic!("Asdasd") - } - }; - - // send and shit - todo!() - } - - while let Some(l1_messages) = l1_message_receiver.recv().await {} - } - - async fn get_next_message( - l1_message_receiver: &mut Receiver, - db_flag: &AtomicBool, - ) -> Result { - if db_flag.load(Ordering::Relaxed) { - // TODO: expensive to fetch 1 by 1, implement fetching multiple. Could use static? - Self::get_message_from_db().await - } else { - if let Some(val) = l1_message_receiver.recv().await { - Ok(val) - } else { - Err(Error::ChannelClosed) - } - } - } - - // TODO(edwin) - async fn get_message_from_db() -> Result { - todo!() - } - - pub async fn schedule( - &self, - l1_messages: Vec, - ) -> Result<(), Error> { - for el in l1_messages { - let err = if let Err(err) = self.sender.try_send(el) { - err - } else { - continue; - }; - - if matches!(err, TrySendError::Closed(_)) { - return Err(Error::ChannelClosed); - } - } - - Ok(()) - } -} - -#[derive(thiserror::Error, Debug)] -pub enum Error { - #[error("Channel was closed")] - ChannelClosed, -} - -/// ideal system: -/// -// Service keeps accepting messages -// once there's a full channel in order not to stall or overload RAM -// we write to - -// Having message service batches in optimal way - -/// WE NEED: -// - Split into proper Commitable chunks -// - - -/// We insert into scheduler and then figure out how to optimally split messages -// or we split messages and then try to commit specific chunks? - -// we write to channel it becom3s full -// we need to write to db -// Who will - -// TODO Scheduler also return revicer chammel that will receive -// (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] -// can receive them and hande them txs and sucj - -// after we flagged that items in db -// next sends can't fo to queue, since that will break an order -// they need to go to db. - -// Our loop - -/// Design: -/// Let it be a general service -/// Gets directly commits from Processor, then -fn useless() {} diff --git a/magicblock-committor-service/src/commit/committor_processor.rs b/magicblock-committor-service/src/commit/committor_processor.rs index fcdb9c998..4ba90d5f8 100644 --- a/magicblock-committor-service/src/commit/committor_processor.rs +++ b/magicblock-committor-service/src/commit/committor_processor.rs @@ -141,7 +141,7 @@ impl CommittorProcessor { Ok(signatures) } - pub async fn commit_changeset( + pub async fn commit_l1_messages( &self, l1_messages: Vec, ) -> Option { @@ -200,141 +200,6 @@ impl CommittorProcessor { reqid } - async fn process_commit_changeset( - &self, - changeset: Changeset, - finalize: bool, - ephemeral_blockhash: Hash, - ) -> Vec { - let changeset_meta = ChangesetMeta::from(&changeset); - let SplitChangesets { - args_changeset, - args_including_finalize_changeset, - args_with_lookup_changeset, - args_including_finalize_with_lookup_changeset, - from_buffer_changeset, - from_buffer_with_lookup_changeset, - } = match split_changesets_by_commit_strategy(changeset, finalize) { - Ok(changesets) => changesets, - Err(err) => { - error!("Failed to split changesets: {:?}", err); - return changeset_meta - .into_account_infos() - .into_iter() - .map(CommitStage::SplittingChangesets) - .collect(); - } - }; - - debug_assert!( - finalize - || (args_including_finalize_changeset.is_empty() - && args_including_finalize_with_lookup_changeset - .is_empty()), - "BUG: args including finalize strategies should not be created when not finalizing" - ); - - let mut join_set = JoinSet::new(); - if !args_changeset.is_empty() - || !args_with_lookup_changeset.is_empty() - || !args_including_finalize_changeset.is_empty() - || !args_including_finalize_with_lookup_changeset.is_empty() - { - let latest_blockhash = match self - .magicblock_rpc_client - .get_latest_blockhash() - .await - { - Ok(bh) => bh, - Err(err) => { - error!( - "Failed to get latest blockhash to commit using args: {:?}", - err - ); - let strategy = CommitStrategy::args( - !args_with_lookup_changeset.is_empty() - || !args_including_finalize_with_lookup_changeset - .is_empty(), - ); - return changeset_meta - .into_account_infos() - .into_iter() - .map(|(meta, slot, undelegate)| { - CommitStage::GettingLatestBlockhash(( - meta, slot, undelegate, strategy, - )) - }) - .collect(); - } - }; - - if !args_changeset.is_empty() { - join_set.spawn(Self::commit_changeset_using_args( - Arc::new(self.clone()), - args_changeset, - (finalize, true), - ephemeral_blockhash, - latest_blockhash, - false, - )); - } - - if !args_including_finalize_changeset.is_empty() { - join_set.spawn(Self::commit_changeset_using_args( - Arc::new(self.clone()), - args_including_finalize_changeset, - (finalize, false), - ephemeral_blockhash, - latest_blockhash, - false, - )); - } - - if !args_with_lookup_changeset.is_empty() { - join_set.spawn(Self::commit_changeset_using_args( - Arc::new(self.clone()), - args_with_lookup_changeset, - (finalize, true), - ephemeral_blockhash, - latest_blockhash, - true, - )); - } - - if !args_including_finalize_with_lookup_changeset.is_empty() { - join_set.spawn(Self::commit_changeset_using_args( - Arc::new(self.clone()), - args_including_finalize_with_lookup_changeset, - (finalize, false), - ephemeral_blockhash, - latest_blockhash, - true, - )); - } - } - - if !from_buffer_changeset.is_empty() { - join_set.spawn(Self::commit_changeset_using_buffers( - Arc::new(self.clone()), - from_buffer_changeset, - finalize, - ephemeral_blockhash, - false, - )); - } - if !from_buffer_with_lookup_changeset.is_empty() { - join_set.spawn(Self::commit_changeset_using_buffers( - Arc::new(self.clone()), - from_buffer_with_lookup_changeset, - finalize, - ephemeral_blockhash, - true, - )); - } - - join_set.join_all().await.into_iter().flatten().collect() - } - pub(crate) async fn process_ixs_chunks( &self, ixs_chunks: Vec>, diff --git a/magicblock-committor-service/src/commit/mod.rs b/magicblock-committor-service/src/commit/mod.rs index 0b07f60c7..e539b881a 100644 --- a/magicblock-committor-service/src/commit/mod.rs +++ b/magicblock-committor-service/src/commit/mod.rs @@ -1,4 +1,3 @@ -mod commit_scheduler; mod commit_using_args; mod commit_using_buffer; mod committor_processor; diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs new file mode 100644 index 000000000..bf60835da --- /dev/null +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -0,0 +1,100 @@ +mod commit_scheduler_worker; +mod db; + +use std::sync::Arc; + +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; +use magicblock_rpc_client::MagicblockRpcClient; +use tokio::sync::mpsc::{channel, error::TrySendError, Sender}; + +use crate::commit_scheduler::{ + commit_scheduler_worker::CommitSchedulerWorker, db::DB, +}; + +pub struct CommitScheduler { + db: Arc, + sender: Sender, +} + +impl CommitScheduler { + pub fn new(rpc_client: MagicblockRpcClient, db: D) -> Self { + let db = Arc::new(db); + let (sender, receiver) = channel(1000); + + // TODO(edwin): add concellation logic + let worker = + CommitSchedulerWorker::new(db.clone(), rpc_client, receiver); + tokio::spawn(worker.start()); + + Self { db, sender } + } + + /// Schedules [`ScheduledL1Message`] message to be executed + /// In case the channel is full we write message to DB + /// Messages will be extracted and handled in the [`CommitSchedulerWorker`] + pub async fn schedule( + &self, + l1_messages: Vec, + ) -> Result<(), Error> { + for el in l1_messages { + let err = if let Err(err) = self.sender.try_send(el) { + err + } else { + continue; + }; + + if matches!(err, TrySendError::Closed(_)) { + Err(Error::ChannelClosed) + } else { + self.db + .store_l1_messages(l1_messages) + .await + .map_err(Error::from) + }? + } + + Ok(()) + } +} + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("Channel was closed")] + ChannelClosed, + #[error("DBError: {0}")] + DBError(#[from] db::Error), +} + +/// ideal system: +/// +// Service keeps accepting messages +// once there's a full channel in order not to stall or overload RAM +// we write to + +// Having message service batches in optimal way + +/// WE NEED: +// - Split into proper Commitable chunks +// - + +/// We insert into scheduler and then figure out how to optimally split messages +// or we split messages and then try to commit specific chunks? + +// we write to channel it becom3s full +// we need to write to db +// Who will + +// TODO Scheduler also return revicer chammel that will receive +// (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] +// can receive them and hande them txs and sucj + +// after we flagged that items in db +// next sends can't fo to queue, since that will break an order +// they need to go to db. + +// Our loop + +/// Design: +/// Let it be a general service +/// Gets directly commits from Processor, then +fn useless() {} diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs new file mode 100644 index 000000000..0553d28b6 --- /dev/null +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -0,0 +1,223 @@ +use std::{ + collections::{btree_map::Entry, HashMap, LinkedList, VecDeque}, + sync::Arc, +}; + +use magicblock_program::magic_scheduled_l1_message::{ + MagicL1Message, ScheduledL1Message, +}; +use magicblock_rpc_client::MagicblockRpcClient; +use solana_pubkey::Pubkey; +use tokio::sync::mpsc::{error::TryRecvError, Receiver, Sender}; + +use crate::commit_scheduler::{db::DB, Error}; + +type MessageID = u64; + +struct MessageMeta { + num_keys: usize, + message: ScheduledL1Message, +} + +/// A scheduler that ensures mutually exclusive access to pubkeys across messages +/// +/// # Data Structures +/// +/// 1. `executing`: Tracks currently running messages and their locked pubkeys +/// - Key: MessageID +/// - Value: Vec of locked Pubkeys +/// +/// 2. `blocked_keys`: Maintains FIFO queues of messages waiting for each pubkey +/// - Key: Pubkey +/// - Value: Queue of MessageIDs in arrival order +/// +/// 3. `blocked_messages`: Stores metadata for all blocked messages +/// - Key: MessageID +/// - Value: Message metadata including original message +/// +/// # Scheduling Logic +/// +/// 1. On message arrival: +/// - Check if any required pubkey exists in `blocked_keys` +/// - If conflicted: Add message to all relevant pubkey queues +/// - Else: Start executing immediately +/// +/// 2. On message completion: +/// - Remove message from all pubkey queues +/// - For each modified queue: +/// * If front message now has all its pubkeys available: +/// - Move from `blocked_messages` to `executing` +/// +/// (1) Assume t1: +/// executing: [a1, a2, a3] [b1, b2, b3] +/// blocked: [a1, b1] +/// arriving: [a1, a3] +/// +/// t2: +/// executing: [b1, b2, b3] +/// blocked: [a1, b1] +/// CAN't be executed - [a1, a3], since [a1, b3] needs to be sent first, it has earlier state +/// +/// (2) Assume: +/// executing: [a1, a2, a3] +/// blocked: [c1, a1] +/// arriving: [c2, c1] +/// [c2, c1] - Even there's no overlaps with executing +/// we can't be proceed since blocked one has [c1] that has to be executed first +pub(crate) struct CommitSchedulerWorker { + db: Arc, + rpc_client: MagicblockRpcClient, + receiver: Receiver, + + executing: HashMap>, + blocked_keys: HashMap>, + blocked_messages: HashMap, +} + +impl CommitSchedulerWorker { + pub fn new( + db: Arc, + rpc_client: MagicblockRpcClient, + receiver: Receiver, + ) -> Self { + Self { + db, + rpc_client, + receiver, + executing: HashMap::new(), + blocked_keys: HashMap::new(), + blocked_messages: HashMap::new(), + } + } + + pub async fn start(mut self) { + loop { + let l1_message = match self.receiver.try_recv() { + Ok(val) => val, + Err(TryRecvError::Empty) => { + match self.get_or_wait_next_message().await { + Ok(val) => val, + Err(err) => panic!(err), // TODO(edwin): handle + } + } + Err(TryRecvError::Disconnected) => { + // TODO(edwin): handle + panic!("Asdasd") + } + }; + + self.handle_message(l1_message).await; + } + } + + async fn handle_message(&mut self, l1_message: ScheduledL1Message) { + let message_id = l1_message.id; + let accounts = match &l1_message.l1_message { + MagicL1Message::L1Actions(val) => todo!(), + MagicL1Message::Commit(val) => val.get_committed_accounts(), + MagicL1Message::CommitAndUndelegate(val) => { + val.get_committed_accounts() + } + }; + let pubkeys = accounts + .iter() + .map(|account| *account.pubkey) + .collect::>(); + + if Self::process_conflicting( + message_id, + &pubkeys, + &mut self.blocked_keys, + ) { + self.blocked_messages.insert( + message_id, + MessageMeta { + num_keys: pubkeys.len(), + message: l1_message, + }, + ); + } else { + // Can start to execute + self.executing.insert(message_id, pubkeys); + tokio::spawn(self.execute(l1_message)); + } + } + + fn process_conflicting( + message_id: MessageID, + pubkeys: &[Pubkey], + blocked_keys: &mut HashMap>, + ) -> bool { + pubkeys.iter().any(|pubkey| { + blocked_keys + .entry(*pubkey) + .or_default() + .push_back(message_id); + + // If had values before - conflicting + blocked_keys[pubkey].len() > 1 + }) + } + + fn complete_message(&mut self, message_id: MessageID) { + // Release data for completed message + let pubkeys = self.executing.remove(&message_id).expect("bug"); + for pubkey in pubkeys { + let mut entry = match self.blocked_keys.entry(pubkey) { + Entry::Vacant(_) => panic!("bug"), // TODO(edwin): improve?, + Entry::Occupied(entry) => entry, + }; + let blocked_messages: &mut VecDeque = entry.get_mut(); + assert_eq!( + message_id, + blocked_messages.pop_front().expect("bug"), + "bug" + ); + + if blocked_messages.is_empty() { + entry.remove() + } + } + + let mut asd: HashMap = HashMap::new(); + self.blocked_keys.iter().for_each(|(pubkey, queue)| { + let message_id = queue.front().expect("bug"); + *asd.entry(*message_id).or_default() += 1; + }); + + let mut can_execute = Vec::new(); + for (message_id, free_keys) in asd { + if self + .blocked_messages + .get(&message_id) + .expect("bug") + .num_keys + == free_keys + { + can_execute + .push(self.blocked_messages.remove(&message_id).unwrap()); + // TODO(edwin): update executing + } + } + } + + async fn execute(&self, l1_message: ScheduledL1Message) { + todo!() + } + + /// Return [`ScheduledL1Message`] from DB, otherwise waits on channel + async fn get_or_wait_next_message( + &mut self, + ) -> Result { + // TODO: expensive to fetch 1 by 1, implement fetching multiple. Could use static? + if let Some(l1_message) = self.db.pop_l1_message().await? { + Ok(l1_message) + } else { + if let Some(val) = self.receiver.recv().await { + Ok(val) + } else { + Err(Error::ChannelClosed) + } + } + } +} diff --git a/magicblock-committor-service/src/commit_scheduler/db.rs b/magicblock-committor-service/src/commit_scheduler/db.rs new file mode 100644 index 000000000..f8647feef --- /dev/null +++ b/magicblock-committor-service/src/commit_scheduler/db.rs @@ -0,0 +1,69 @@ +use std::{collections::VecDeque, sync::Mutex}; + +/// DB for storing messages that overflow committor channel +use async_trait::async_trait; +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; + +const POISONED_MUTEX_MSG: &str = "Mutex poisoned"; + +#[async_trait] +pub(crate) trait DB { + async fn store_l1_message( + &self, + l1_message: ScheduledL1Message, + ) -> DBResult<()>; + async fn store_l1_messages( + &self, + l1_messages: Vec, + ) -> DBResult<()>; + /// Return message with smallest bundle_id + async fn pop_l1_message(&self) -> DBResult>; + fn is_empty(&self) -> bool; +} + +struct DummyDB { + db: Mutex>, +} + +#[async_trait] +impl DB for DummyDB { + async fn store_l1_message( + &self, + l1_message: ScheduledL1Message, + ) -> DBResult<()> { + self.db + .lock() + .expect(POISONED_MUTEX_MSG) + .push_back(l1_message); + Ok(()) + } + + async fn store_l1_messages( + &self, + l1_messages: Vec, + ) -> DBResult<()> { + self.db + .lock() + .expect(POISONED_MUTEX_MSG) + .extend(l1_messages.into_iter()); + Ok(()) + } + + async fn pop_l1_message(&self) -> DBResult> { + Ok(self.db.lock().expect(POISONED_MUTEX_MSG).pop_front()) + } + + fn is_empty(&self) -> bool { + self.db.lock().expect(POISONED_MUTEX_MSG).is_empty() + } +} + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("StoreError: {0}")] + StoreError(anyhow::Error), + #[error("FetchError: {0}")] + FetchError(anyhow::Error), +} + +pub type DBResult = Result; diff --git a/magicblock-committor-service/src/commit_stage.rs b/magicblock-committor-service/src/commit_stage.rs index 41d50359b..1a15ffa5f 100644 --- a/magicblock-committor-service/src/commit_stage.rs +++ b/magicblock-committor-service/src/commit_stage.rs @@ -48,6 +48,7 @@ impl From for CommitStatusSignatures { } } +// TODO(edwin): integrate #[derive(Debug)] pub enum CommitStage { /// This account was part of a changeset that could not be split into diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index db03f70a3..013cd27c6 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -16,6 +16,7 @@ mod transactions; mod types; mod undelegate; +mod commit_scheduler; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; mod transaction_preperator; diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 7fa9f3a48..e1859f1fa 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -52,8 +52,6 @@ pub enum CommittorMessage { respond_to: oneshot::Sender>, /// The changeset to commit l1_messages: Vec, - /// If `true`, account commits will be finalized after they were processed - finalize: bool, }, GetCommitStatuses { respond_to: @@ -130,9 +128,9 @@ impl CommittorActor { CommitChangeset { l1_messages, respond_to, - finalize, } => { - let reqid = self.processor.commit_changeset(l1_messages).await; + let reqid = + self.processor.commit_l1_messages(l1_messages).await; if let Err(e) = respond_to.send(reqid) { error!("Failed to send response {:?}", e); } diff --git a/magicblock-committor-service/src/transaction_preperator/tasks.rs b/magicblock-committor-service/src/transaction_preperator/tasks.rs index 876418069..f49255057 100644 --- a/magicblock-committor-service/src/transaction_preperator/tasks.rs +++ b/magicblock-committor-service/src/transaction_preperator/tasks.rs @@ -31,6 +31,7 @@ pub struct TaskPreparationInfo { pub write_instructions: Vec, } +/// A trait representing a task that can be executed on Base layer pub trait L1Task: Send + Sync { /// Gets all pubkeys that involved in Task's instruction fn involved_accounts(&self, validator: &Pubkey) -> Vec { @@ -90,6 +91,7 @@ pub struct FinalizeTask { pub delegated_account: Pubkey, } +/// Task that will be executed on Base layer via arguments #[derive(Clone)] pub enum ArgsTask { Commit(CommitTask), diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 5e6206e8a..c9e3929d6 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -41,6 +41,7 @@ trait TransactionPreparator { /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks /// Handles all necessary preparations for Message to be valid + /// NOTE: [`VersionedMessage`] contains dummy recent_block_hash that should be replaced async fn prepare_commit_tx( &self, authority: &Keypair, @@ -50,6 +51,7 @@ trait TransactionPreparator { /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks /// Handles all necessary preparations for Message to be valid + // NOTE: [`VersionedMessage`] contains dummy recent_block_hash that should be replaced async fn prepare_finalize_tx( &self, authority: &Keypair, From ef9db261fd3d0ae4b7482cc051600b5bc140704f Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 14 Jul 2025 13:54:39 +0900 Subject: [PATCH 093/199] refactor: extract core schuduling logic into CommitSchedulerInner --- .../src/commit_scheduler.rs | 1 + .../commit_scheduler_inner.rs | 197 ++++++++++++++++++ .../commit_scheduler_worker.rs | 173 +++------------ 3 files changed, 225 insertions(+), 146 deletions(-) create mode 100644 magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index bf60835da..4bcbfb55f 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -1,3 +1,4 @@ +mod commit_scheduler_inner; mod commit_scheduler_worker; mod db; diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs new file mode 100644 index 000000000..0a612bf71 --- /dev/null +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -0,0 +1,197 @@ +use std::collections::{hash_map::Entry, HashMap, VecDeque}; + +use magicblock_program::magic_scheduled_l1_message::{ + MagicL1Message, ScheduledL1Message, +}; +use solana_pubkey::Pubkey; + +type MessageID = u64; +struct MessageMeta { + num_keys: usize, + message: ScheduledL1Message, +} + +/// A scheduler that ensures mutually exclusive access to pubkeys across messages +/// +/// # Data Structures +/// +/// 1. `blocked_keys`: Maintains FIFO queues of messages waiting for each pubkey +/// - Key: Pubkey +/// - Value: Queue of MessageIDs in arrival order +/// +/// 2. `blocked_messages`: Stores metadata for all blocked messages +/// - Key: MessageID +/// - Value: Message metadata including original message +/// +/// # Scheduling Logic +/// +/// 1. On message arrival: +/// - Check if any required pubkey exists in `blocked_keys` +/// - If conflicted: Add message to all relevant pubkey queues +/// - Else: Start executing immediately +/// +/// 2. On message completion: +/// - Pop 1st el-t from corresponding to Message `blocked_keys` queues, +/// Note: `blocked_keys[msg.keys]` == msg.id +/// - This moves forward other messages that were blocked by this one. +/// +/// 3. On popping next message to be executed: +/// - Find the first message in `blocked_messages` which +/// has all of its pubkeys unblocked, +/// i.e they are first at corresponding queues +/// +/// Some examples/edge cases: +/// (1) Assume `t1`: +/// executing: `[a1, a2, a3] [b1, b2, b3]` - 1 +/// blocked: `[a1, b1]` - 2 +/// arriving: `[a1, a3]` - 3 +/// +/// `t2`: +/// executing: `[b1, b2, b3]` +/// blocked: `[a1, b1]` +/// `[a1, a3]` - CAN't be executed, since `[a1, b1]` needs to be sent first, it has earlier state. +/// +/// (2) Assume: +/// executing: `[a1, a2, a3]` +/// blocked: `[c1, a1]` +/// arriving: `[c2, c1]` +/// `[c2, c1]` - Even there's no overlaps with executing +/// we can't proceed since blocked message has [c1] that has to be executed first +pub(crate) struct CommitSchedulerInner { + blocked_keys: HashMap>, + blocked_messages: HashMap, +} + +impl CommitSchedulerInner { + pub fn new() -> Self { + Self { + blocked_keys: HashMap::new(), + blocked_messages: HashMap::new(), + } + } + + /// Returns [`ScheduledL1Message`] if message can be executed, + /// otherwise consumes it and enqueues + pub fn schedule( + &mut self, + l1_message: ScheduledL1Message, + ) -> Option { + let message_id = l1_message.id; + let accounts = match &l1_message.l1_message { + MagicL1Message::L1Actions(val) => { + // This L1Action can be executed right away + return Some(l1_message); + } + MagicL1Message::Commit(t) => t.get_committed_accounts(), + MagicL1Message::CommitAndUndelegate(t) => { + t.get_committed_accounts() + } + }; + let pubkeys = accounts + .iter() + .map(|account| *account.pubkey) + .collect::>(); + + let (entries, is_conflicting) = + Self::find_conflicting_entries(&pubkeys, &mut self.blocked_keys); + // In any case block the corresponding accounts + entries + .into_iter() + .for_each(|entry| entry.or_default().push_back(message_id)); + if is_conflicting { + // Enqueue incoming message + self.blocked_messages.insert( + message_id, + MessageMeta { + num_keys: pubkeys.len(), + message: l1_message, + }, + ); + None + } else { + Some(l1_message) + } + } + + /// Completes Message, cleaning up data after itself and allowing Messages to move forward + /// Note: this shall be called on executing messages to finilize their execution. + /// Calling on incorrect `pubkyes` set will result in panic + pub fn complete(&mut self, message_id: MessageID, pubkeys: &[Pubkey]) { + // Release data for completed message + let (entries, _) = + Self::find_conflicting_entries(&pubkeys, &mut self.blocked_keys); + entries.into_iter().for_each(|entry| { + let mut occupied = match entry { + Entry::Vacant(_) => unreachable!("Invariant: queue for conflicting tasks shall exist"), + Entry::Occupied(value) => value + }; + + let blocked_messages: &mut VecDeque = occupied.get_mut(); + assert_eq!( + message_id, + blocked_messages.pop_front().expect("Invariant: if message executing, queue for each account is non-empty"), + "Invariant: executing message must be first at qeueue" + ); + + if blocked_messages.is_empty() { + occupied.remove(); + } + }); + } + + // Returns [`ScheduledL1Message`] that can be executed + pub fn pop_next_scheduled_message(&mut self) -> Option { + // TODO(edwin): optimize. Create counter im MessageMeta & update + let mut execute_candidates: HashMap = HashMap::new(); + self.blocked_keys.iter().for_each(|(pubkey, queue)| { + let message_id = queue + .front() + .expect("Invariant: we maintain ony non-empty queues"); + *execute_candidates.entry(*message_id).or_default() += 1; + }); + + let candidate = + self.blocked_messages.iter().find_map(|(message_id, meta)| { + if execute_candidates.get(message_id).expect( + "Invariant: blocked messages are always in candidates", + ) == meta.num_keys + { + Some(message_id) + } else { + None + } + }); + + if let Some(next) = candidate { + Some(self.blocked_messages.remove(next).unwrap().message) + } else { + None + } + } + + fn find_conflicting_entries<'a>( + pubkeys: &[Pubkey], + blocked_keys: &'a mut HashMap>, + ) -> (Vec>>, bool) { + let mut is_conflicting = false; + let entries = pubkeys + .iter() + .map(|pubkey| { + let entry = blocked_keys.entry(*pubkey); + + if is_conflicting { + entry + } else { + if let Entry::Occupied(_) = &entry { + is_conflicting = true; + entry + } else { + entry + } + } + }) + .collect(); + + (entries, is_conflicting) + } +} diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 0553d28b6..46c1333ea 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -1,6 +1,6 @@ use std::{ - collections::{btree_map::Entry, HashMap, LinkedList, VecDeque}, - sync::Arc, + collections::{hash_map::Entry, HashMap, LinkedList, VecDeque}, + sync::{Arc, Mutex}, }; use magicblock_program::magic_scheduled_l1_message::{ @@ -8,70 +8,19 @@ use magicblock_program::magic_scheduled_l1_message::{ }; use magicblock_rpc_client::MagicblockRpcClient; use solana_pubkey::Pubkey; -use tokio::sync::mpsc::{error::TryRecvError, Receiver, Sender}; +use tokio::sync::mpsc::{error::TryRecvError, Receiver}; -use crate::commit_scheduler::{db::DB, Error}; - -type MessageID = u64; - -struct MessageMeta { - num_keys: usize, - message: ScheduledL1Message, -} +use crate::commit_scheduler::{ + commit_scheduler_inner::CommitSchedulerInner, db::DB, Error, +}; +const POISONED_INNER_MSG: &str = "Mutex on CommitSchedulerInner is poisoned."; -/// A scheduler that ensures mutually exclusive access to pubkeys across messages -/// -/// # Data Structures -/// -/// 1. `executing`: Tracks currently running messages and their locked pubkeys -/// - Key: MessageID -/// - Value: Vec of locked Pubkeys -/// -/// 2. `blocked_keys`: Maintains FIFO queues of messages waiting for each pubkey -/// - Key: Pubkey -/// - Value: Queue of MessageIDs in arrival order -/// -/// 3. `blocked_messages`: Stores metadata for all blocked messages -/// - Key: MessageID -/// - Value: Message metadata including original message -/// -/// # Scheduling Logic -/// -/// 1. On message arrival: -/// - Check if any required pubkey exists in `blocked_keys` -/// - If conflicted: Add message to all relevant pubkey queues -/// - Else: Start executing immediately -/// -/// 2. On message completion: -/// - Remove message from all pubkey queues -/// - For each modified queue: -/// * If front message now has all its pubkeys available: -/// - Move from `blocked_messages` to `executing` -/// -/// (1) Assume t1: -/// executing: [a1, a2, a3] [b1, b2, b3] -/// blocked: [a1, b1] -/// arriving: [a1, a3] -/// -/// t2: -/// executing: [b1, b2, b3] -/// blocked: [a1, b1] -/// CAN't be executed - [a1, a3], since [a1, b3] needs to be sent first, it has earlier state -/// -/// (2) Assume: -/// executing: [a1, a2, a3] -/// blocked: [c1, a1] -/// arriving: [c2, c1] -/// [c2, c1] - Even there's no overlaps with executing -/// we can't be proceed since blocked one has [c1] that has to be executed first pub(crate) struct CommitSchedulerWorker { db: Arc, rpc_client: MagicblockRpcClient, receiver: Receiver, - executing: HashMap>, - blocked_keys: HashMap>, - blocked_messages: HashMap, + inner: Arc>, } impl CommitSchedulerWorker { @@ -84,9 +33,7 @@ impl CommitSchedulerWorker { db, rpc_client, receiver, - executing: HashMap::new(), - blocked_keys: HashMap::new(), - blocked_messages: HashMap::new(), + inner: Arc::new(Mutex::new(CommitSchedulerInner::new())), } } @@ -111,96 +58,30 @@ impl CommitSchedulerWorker { } async fn handle_message(&mut self, l1_message: ScheduledL1Message) { - let message_id = l1_message.id; - let accounts = match &l1_message.l1_message { - MagicL1Message::L1Actions(val) => todo!(), - MagicL1Message::Commit(val) => val.get_committed_accounts(), - MagicL1Message::CommitAndUndelegate(val) => { - val.get_committed_accounts() - } - }; - let pubkeys = accounts - .iter() - .map(|account| *account.pubkey) - .collect::>(); - - if Self::process_conflicting( - message_id, - &pubkeys, - &mut self.blocked_keys, - ) { - self.blocked_messages.insert( - message_id, - MessageMeta { - num_keys: pubkeys.len(), - message: l1_message, - }, - ); - } else { - // Can start to execute - self.executing.insert(message_id, pubkeys); + if let Some(l1_message) = self + .inner + .lock() + .expect(POISONED_INNER_MSG) + .schedule(l1_message) + { tokio::spawn(self.execute(l1_message)); } } - fn process_conflicting( - message_id: MessageID, - pubkeys: &[Pubkey], - blocked_keys: &mut HashMap>, - ) -> bool { - pubkeys.iter().any(|pubkey| { - blocked_keys - .entry(*pubkey) - .or_default() - .push_back(message_id); - - // If had values before - conflicting - blocked_keys[pubkey].len() > 1 - }) - } - - fn complete_message(&mut self, message_id: MessageID) { - // Release data for completed message - let pubkeys = self.executing.remove(&message_id).expect("bug"); - for pubkey in pubkeys { - let mut entry = match self.blocked_keys.entry(pubkey) { - Entry::Vacant(_) => panic!("bug"), // TODO(edwin): improve?, - Entry::Occupied(entry) => entry, - }; - let blocked_messages: &mut VecDeque = entry.get_mut(); - assert_eq!( - message_id, - blocked_messages.pop_front().expect("bug"), - "bug" - ); - - if blocked_messages.is_empty() { - entry.remove() - } - } + // SchedulerWorker + // Message arrives + // Can execute? + // Yes - execute + // No - enqueue - let mut asd: HashMap = HashMap::new(); - self.blocked_keys.iter().for_each(|(pubkey, queue)| { - let message_id = queue.front().expect("bug"); - *asd.entry(*message_id).or_default() += 1; - }); - - let mut can_execute = Vec::new(); - for (message_id, free_keys) in asd { - if self - .blocked_messages - .get(&message_id) - .expect("bug") - .num_keys - == free_keys - { - can_execute - .push(self.blocked_messages.remove(&message_id).unwrap()); - // TODO(edwin): update executing - } - } - } + // SchedulerWorker \ + /// Planner + // MessageProcessor / + /// ScheduledL1Message arrives: + /// 1. Sent to Scheduler + /// 2. Scheduler sents to SchedulerWorker + /// 3. SchedulerWorker checks Sche async fn execute(&self, l1_message: ScheduledL1Message) { todo!() } From 9623d388244d3437eacee544c24a574d5b1a3883 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 14 Jul 2025 18:50:40 +0900 Subject: [PATCH 094/199] feat: initialize MessageExecutor --- .../src/commit_scheduler.rs | 11 +- .../commit_scheduler_inner.rs | 27 +-- .../commit_scheduler_worker.rs | 68 +++---- .../src/l1_message_executor.rs | 172 ++++++++++++++++++ magicblock-committor-service/src/lib.rs | 5 +- .../src/transaction_preperator/mod.rs | 4 +- .../transaction_preparator.rs | 4 +- magicblock-committor-service/src/utils.rs | 27 +++ 8 files changed, 269 insertions(+), 49 deletions(-) create mode 100644 magicblock-committor-service/src/l1_message_executor.rs create mode 100644 magicblock-committor-service/src/utils.rs diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index 4bcbfb55f..e76477a53 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -1,4 +1,4 @@ -mod commit_scheduler_inner; +pub(crate) mod commit_scheduler_inner; mod commit_scheduler_worker; mod db; @@ -38,6 +38,15 @@ impl CommitScheduler { l1_messages: Vec, ) -> Result<(), Error> { for el in l1_messages { + // If db not empty push el-t there + // This means that at some point channel got full + // Worker first will clean-up channel, and then DB. + // Pushing into channel would break order of commits + if !self.db.is_empty() { + self.db.store_l1_messages(l1_messages).await?; + continue; + } + let err = if let Err(err) = self.sender.try_send(el) { err } else { diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index 0a612bf71..92e94e04d 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -5,6 +5,11 @@ use magicblock_program::magic_scheduled_l1_message::{ }; use solana_pubkey::Pubkey; +use crate::utils::ScheduledMessageExt; + +pub(crate) const POISONED_INNER_MSG: &str = + "Mutex on CommitSchedulerInner is poisoned."; + type MessageID = u64; struct MessageMeta { num_keys: usize, @@ -77,16 +82,10 @@ impl CommitSchedulerInner { l1_message: ScheduledL1Message, ) -> Option { let message_id = l1_message.id; - let accounts = match &l1_message.l1_message { - MagicL1Message::L1Actions(val) => { - // This L1Action can be executed right away - return Some(l1_message); - } - MagicL1Message::Commit(t) => t.get_committed_accounts(), - MagicL1Message::CommitAndUndelegate(t) => { - t.get_committed_accounts() - } + let Some(accounts) = l1_message.get_committed_accounts() else { + return Some(l1_message); }; + let pubkeys = accounts .iter() .map(|account| *account.pubkey) @@ -116,8 +115,14 @@ impl CommitSchedulerInner { /// Completes Message, cleaning up data after itself and allowing Messages to move forward /// Note: this shall be called on executing messages to finilize their execution. /// Calling on incorrect `pubkyes` set will result in panic - pub fn complete(&mut self, message_id: MessageID, pubkeys: &[Pubkey]) { + pub fn complete(&mut self, l1_message: &ScheduledL1Message) { // Release data for completed message + let message_id = l1_message.id; + let Some(pubkeys) = l1_message.get_committed_pubkeys() else { + // This means L1Action, it doesn't have to be scheduled + return; + }; + let (entries, _) = Self::find_conflicting_entries(&pubkeys, &mut self.blocked_keys); entries.into_iter().for_each(|entry| { @@ -154,7 +159,7 @@ impl CommitSchedulerInner { self.blocked_messages.iter().find_map(|(message_id, meta)| { if execute_candidates.get(message_id).expect( "Invariant: blocked messages are always in candidates", - ) == meta.num_keys + ) == &meta.num_keys { Some(message_id) } else { diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 46c1333ea..d1d84f78a 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -1,23 +1,25 @@ -use std::{ - collections::{hash_map::Entry, HashMap, LinkedList, VecDeque}, - sync::{Arc, Mutex}, -}; +use std::sync::{Arc, Mutex}; -use magicblock_program::magic_scheduled_l1_message::{ - MagicL1Message, ScheduledL1Message, -}; +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::MagicblockRpcClient; -use solana_pubkey::Pubkey; +use magicblock_table_mania::TableMania; use tokio::sync::mpsc::{error::TryRecvError, Receiver}; -use crate::commit_scheduler::{ - commit_scheduler_inner::CommitSchedulerInner, db::DB, Error, +use crate::{ + commit_scheduler::{ + commit_scheduler_inner::{CommitSchedulerInner, POISONED_INNER_MSG}, + db::DB, + Error, + }, + l1_message_executor::L1MessageExecutor, + ComputeBudgetConfig, }; -const POISONED_INNER_MSG: &str = "Mutex on CommitSchedulerInner is poisoned."; pub(crate) struct CommitSchedulerWorker { db: Arc, rpc_client: MagicblockRpcClient, + table_mania: TableMania, + compute_budget_config: ComputeBudgetConfig, receiver: Receiver, inner: Arc>, @@ -27,11 +29,15 @@ impl CommitSchedulerWorker { pub fn new( db: Arc, rpc_client: MagicblockRpcClient, + table_mania: TableMania, + compute_budget_config: ComputeBudgetConfig, receiver: Receiver, ) -> Self { Self { db, rpc_client, + table_mania, + compute_budget_config, receiver, inner: Arc::new(Mutex::new(CommitSchedulerInner::new())), } @@ -58,39 +64,32 @@ impl CommitSchedulerWorker { } async fn handle_message(&mut self, l1_message: ScheduledL1Message) { - if let Some(l1_message) = self + let l1_message = if let Some(l1_message) = self .inner .lock() .expect(POISONED_INNER_MSG) .schedule(l1_message) { - tokio::spawn(self.execute(l1_message)); - } - } - - // SchedulerWorker - // Message arrives - // Can execute? - // Yes - execute - // No - enqueue - - // SchedulerWorker \ - /// Planner - // MessageProcessor / + l1_message + } else { + return; + }; - /// ScheduledL1Message arrives: - /// 1. Sent to Scheduler - /// 2. Scheduler sents to SchedulerWorker - /// 3. SchedulerWorker checks Sche - async fn execute(&self, l1_message: ScheduledL1Message) { - todo!() + let executor = L1MessageExecutor::new_v1( + self.inner.clone(), + self.rpc_client.clone(), + self.table_mania.clone(), + self.compute_budget_config.clone(), + ); + tokio::spawn(executor.execute(l1_message, todo!())); } /// Return [`ScheduledL1Message`] from DB, otherwise waits on channel async fn get_or_wait_next_message( &mut self, ) -> Result { - // TODO: expensive to fetch 1 by 1, implement fetching multiple. Could use static? + // Worker either cleaned-up congested channel and now need to clean-up DB + // or we're just waiting on empty channel if let Some(l1_message) = self.db.pop_l1_message().await? { Ok(l1_message) } else { @@ -102,3 +101,8 @@ impl CommitSchedulerWorker { } } } + +// Worker schedule: +// We have a pool of workers +// We are ready to accept message +// When we have a worker available to process it diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs new file mode 100644 index 000000000..ab0fb82dd --- /dev/null +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -0,0 +1,172 @@ +use std::{ + collections::HashMap, + marker::PhantomData, + sync::{Arc, Mutex}, +}; + +use log::warn; +use magicblock_program::{ + magic_scheduled_l1_message::ScheduledL1Message, + validator::validator_authority, +}; +use magicblock_rpc_client::{ + MagicBlockRpcClientError, MagicBlockSendTransactionConfig, + MagicblockRpcClient, +}; +use magicblock_table_mania::TableMania; +use solana_pubkey::Pubkey; +use solana_sdk::{ + message::VersionedMessage, + signature::Keypair, + signer::{Signer, SignerError}, + transaction::VersionedTransaction, +}; + +use crate::{ + commit_scheduler::commit_scheduler_inner::{ + CommitSchedulerInner, POISONED_INNER_MSG, + }, + transaction_preperator::transaction_preparator::{ + TransactionPreparator, TransactionPreparatorV1, + }, + ComputeBudgetConfig, +}; + +pub(crate) struct L1MessageExecutor { + authority: Keypair, + rpc_client: MagicblockRpcClient, + transaction_preparator: T, + inner: Arc>, +} + +impl L1MessageExecutor { + pub fn new_v1( + inner: Arc>, + rpc_client: MagicblockRpcClient, + table_mania: TableMania, + compute_budget_config: ComputeBudgetConfig, + ) -> Self { + let authority = validator_authority(); + let transaction_preparator = TransactionPreparatorV1::new( + rpc_client.clone(), + table_mania, + compute_budget_config, + ); + Self { + authority, + rpc_client, + transaction_preparator, + inner, + } + } + + /// Executes message on L1 + pub async fn execute( + mut self, + l1_message: ScheduledL1Message, + commit_ids: HashMap, + ) -> MessageExecutorResult<()> { + // Commit message first + self.commit(&l1_message, commit_ids).await?; + // At the moment validator finalizes right away + // In the future there will be a challenge window + self.finalize(&l1_message).await?; + // Signal that task is completed + // TODO(edwin): handle error case here as well + self.inner + .lock() + .expect(POISONED_INNER_MSG) + .complete(&l1_message); + Ok(()) + } + + /// Executes Commit stage + async fn commit( + &self, + l1_message: &ScheduledL1Message, + commit_ids: HashMap, + ) -> MessageExecutorResult<()> { + let mut prepared_message = self + .transaction_preparator + .prepare_commit_tx(&self.authority, &l1_message, commit_ids) + .await?; + + let latest_blockhash = self.rpc_client.get_latest_blockhash()?; + match &mut prepared_message { + VersionedMessage::V0(value) => { + value.recent_blockhash = latest_blockhash; + } + VersionedMessage::Legacy(value) => { + warn!("TransactionPreparator v1 does not use Legacy message"); + value.recent_blockhash = latest_blockhash; + } + }; + + let transaction = VersionedTransaction::try_new( + prepared_message, + &[&self.authority], + )?; + // TODO(edwin): add retries here? + self.rpc_client + .send_transaction( + &transaction, + &MagicBlockSendTransactionConfig::ensure_committed(), + ) + .await?; + Ok(()) + } + + /// Executes Finalize stage + async fn finalize( + &self, + l1_message: &ScheduledL1Message, + ) -> MessageExecutorResult<()> { + // TODO(edwin): properly define this. + let rent_reimbursement = self.authority.pubkey(); + let mut prepared_message = self + .transaction_preparator + .prepare_finalize_tx( + &self.authority, + &rent_reimbursement, + &l1_message, + ) + .await?; + + let latest_blockhash = self.rpc_client.get_latest_blockhash()?; + match &mut prepared_message { + VersionedMessage::V0(value) => { + value.recent_blockhash = latest_blockhash; + } + VersionedMessage::Legacy(value) => { + warn!("TransactionPreparator v1 does not use Legacy message"); + value.recent_blockhash = latest_blockhash; + } + }; + + let transaction = VersionedTransaction::try_new( + prepared_message, + &[&self.authority], + )?; + // TODO(edwin): add retries here? + self.rpc_client + .send_transaction( + &transaction, + &MagicBlockSendTransactionConfig::ensure_committed(), + ) + .await?; + Ok(()) + } +} + +// TODO(edwin): properly define +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("SignerError: {0}")] + SignerError(#[from] SignerError), + #[error("PreparatorError: {0}")] + PreparatorError(#[from] crate::transaction_preperator::error::Error), + #[error("MagicBlockRpcClientError: {)}")] + MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), +} + +pub type MessageExecutorResult = Result; diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 013cd27c6..c326f22f5 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -17,9 +17,12 @@ mod types; mod undelegate; mod commit_scheduler; +// TODO(edwin): define visibility +pub(crate) mod l1_message_executor; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; -mod transaction_preperator; +pub(crate) mod transaction_preperator; +pub(crate) mod utils; pub use commit_info::CommitInfo; pub use commit_stage::CommitStage; diff --git a/magicblock-committor-service/src/transaction_preperator/mod.rs b/magicblock-committor-service/src/transaction_preperator/mod.rs index 9ccdca4a5..8c647896a 100644 --- a/magicblock-committor-service/src/transaction_preperator/mod.rs +++ b/magicblock-committor-service/src/transaction_preperator/mod.rs @@ -1,8 +1,8 @@ mod budget_calculator; mod delivery_preparator; -mod error; +pub mod error; mod task_builder; mod task_strategist; mod tasks; -mod transaction_preparator; +pub mod transaction_preparator; mod utils; diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index c9e3929d6..16bf0dcca 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -36,7 +36,7 @@ impl std::fmt::Display for PreparatorVersion { } #[async_trait] -trait TransactionPreparator { +pub trait TransactionPreparator { fn version(&self) -> PreparatorVersion; /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks @@ -63,7 +63,7 @@ trait TransactionPreparator { /// [`TransactionPreparatorV1`] first version of preparator /// It omits future commit_bundle/finalize_bundle logic /// It creates TXs using current per account commit/finalize -struct TransactionPreparatorV1 { +pub struct TransactionPreparatorV1 { delivery_preparator: DeliveryPreparator, rpc_client: MagicblockRpcClient, table_mania: TableMania, // TODO(edwin): Arc? diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs new file mode 100644 index 000000000..fb69019c1 --- /dev/null +++ b/magicblock-committor-service/src/utils.rs @@ -0,0 +1,27 @@ +use magicblock_program::magic_scheduled_l1_message::{ + CommittedAccountV2, MagicL1Message, ScheduledL1Message, +}; +use solana_pubkey::Pubkey; + +pub trait ScheduledMessageExt { + fn get_committed_accounts(&self) -> Option<&Vec>; + fn get_committed_pubkeys(&self) -> Option<&Vec>; +} + +impl ScheduledMessageExt for ScheduledL1Message { + fn get_committed_accounts(&self) -> Option<&Vec> { + match &self.l1_message { + MagicL1Message::L1Actions(_) => None, + MagicL1Message::Commit(t) => Some(t.get_committed_accounts()), + MagicL1Message::CommitAndUndelegate(t) => { + Some(t.get_committed_accounts()) + } + } + } + + fn get_committed_pubkeys(&self) -> Option<&Vec> { + self.get_committed_accounts().map(|accounts| { + accounts.iter().map(|account| *account.pubkey).collect() + }) + } +} From 7c00710c4b19c07b83f19c0712c11ffb70f88bfa Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 15 Jul 2025 15:18:07 +0900 Subject: [PATCH 095/199] refactor: move committor out of account manager --- .../src/remote_account_cloner_client.rs | 4 +- .../src/remote_account_cloner_worker.rs | 4 +- magicblock-accounts/src/accounts_manager.rs | 9 +- .../src/external_accounts_manager.rs | 21 +- .../src/remote_scheduled_commits_processor.rs | 212 ++++-------------- .../src/remote_scheduled_commits_worker.rs | 138 ++++++++++++ magicblock-accounts/src/traits.rs | 8 +- magicblock-api/src/tickers.rs | 25 +-- 8 files changed, 198 insertions(+), 223 deletions(-) create mode 100644 magicblock-accounts/src/remote_scheduled_commits_worker.rs diff --git a/magicblock-account-cloner/src/remote_account_cloner_client.rs b/magicblock-account-cloner/src/remote_account_cloner_client.rs index d3070022b..b98f6b3fb 100644 --- a/magicblock-account-cloner/src/remote_account_cloner_client.rs +++ b/magicblock-account-cloner/src/remote_account_cloner_client.rs @@ -11,7 +11,7 @@ use magicblock_account_dumper::AccountDumper; use magicblock_account_fetcher::AccountFetcher; use magicblock_account_updates::AccountUpdates; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::ChangesetCommittor; +use magicblock_committor_service::L1MessageCommittor; use solana_sdk::pubkey::Pubkey; use tokio::sync::{mpsc::UnboundedSender, oneshot::channel}; @@ -34,7 +34,7 @@ impl RemoteAccountClonerClient { AFE: AccountFetcher, AUP: AccountUpdates, ADU: AccountDumper, - CC: ChangesetCommittor, + CC: L1MessageCommittor, { Self { clone_request_sender: worker.get_clone_request_sender(), diff --git a/magicblock-account-cloner/src/remote_account_cloner_worker.rs b/magicblock-account-cloner/src/remote_account_cloner_worker.rs index 304231bf0..161d0b0d3 100644 --- a/magicblock-account-cloner/src/remote_account_cloner_worker.rs +++ b/magicblock-account-cloner/src/remote_account_cloner_worker.rs @@ -20,7 +20,7 @@ use magicblock_account_dumper::AccountDumper; use magicblock_account_fetcher::AccountFetcher; use magicblock_account_updates::{AccountUpdates, AccountUpdatesResult}; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::ChangesetCommittor; +use magicblock_committor_service::L1MessageCommittor; use magicblock_metrics::metrics; use magicblock_mutator::idl::{get_pubkey_anchor_idl, get_pubkey_shank_idl}; use solana_sdk::{ @@ -138,7 +138,7 @@ where AFE: AccountFetcher, AUP: AccountUpdates, ADU: AccountDumper, - CC: ChangesetCommittor, + CC: L1MessageCommittor, { #[allow(clippy::too_many_arguments)] pub fn new( diff --git a/magicblock-accounts/src/accounts_manager.rs b/magicblock-accounts/src/accounts_manager.rs index 90957e98f..57698396f 100644 --- a/magicblock-accounts/src/accounts_manager.rs +++ b/magicblock-accounts/src/accounts_manager.rs @@ -32,7 +32,7 @@ impl AccountsManager { bank: &Arc, cloned_accounts: &CloneOutputMap, remote_account_cloner_client: RemoteAccountClonerClient, - transaction_status_sender: Option, + transaction_status_sender: TransactionStatusSender, validator_keypair: Keypair, config: AccountsConfig, ) -> AccountsResult { @@ -49,12 +49,6 @@ impl AccountsManager { config.commit_compute_unit_price, ); - let scheduled_commits_processor = RemoteScheduledCommitsProcessor::new( - bank.clone(), - cloned_accounts.clone(), - transaction_status_sender.clone(), - ); - Ok(Self { internal_account_provider, account_cloner: remote_account_cloner_client, @@ -62,7 +56,6 @@ impl AccountsManager { transaction_accounts_extractor: TransactionAccountsExtractorImpl, transaction_accounts_validator: TransactionAccountsValidatorImpl, lifecycle: config.lifecycle, - scheduled_commits_processor, external_commitable_accounts: Default::default(), }) } diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 65cfb7125..4146dbf3d 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -16,7 +16,7 @@ use futures_util::future::{try_join, try_join_all}; use log::*; use magicblock_account_cloner::{AccountCloner, AccountClonerOutput}; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::ChangesetCommittor; +use magicblock_committor_service::L1MessageCommittor; use magicblock_core::magic_program; use solana_sdk::{ account::{AccountSharedData, ReadableAccount}, @@ -87,14 +87,12 @@ where ACM: AccountCommitter, TAE: TransactionAccountsExtractor, TAV: TransactionAccountsValidator, - SCP: ScheduledCommitsProcessor, { pub internal_account_provider: IAP, pub account_cloner: ACL, pub account_committer: Arc, pub transaction_accounts_extractor: TAE, pub transaction_accounts_validator: TAV, - pub scheduled_commits_processor: SCP, pub lifecycle: LifecycleMode, pub external_commitable_accounts: RwLock>, @@ -408,23 +406,6 @@ where .get(pubkey) .map(|x| x.last_committed_at()) } - - pub async fn process_scheduled_commits( - &self, - changeset_committor: &Arc, - ) -> AccountsResult<()> { - self.scheduled_commits_processor - .process(&self.internal_account_provider, changeset_committor) - .await - } - - pub fn scheduled_commits_len(&self) -> usize { - self.scheduled_commits_processor.scheduled_commits_len() - } - - pub fn clear_scheduled_commits(&self) { - self.scheduled_commits_processor.clear_scheduled_commits() - } } fn should_clone_account(pubkey: &Pubkey) -> bool { diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 1fcd7128a..53eb78730 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -1,53 +1,54 @@ -use std::{ - collections::{HashMap, HashSet}, - sync::Arc, -}; +use std::sync::Arc; use async_trait::async_trait; -use conjunto_transwise::AccountChainSnapshot; -use log::*; -use magicblock_account_cloner::{ - AccountClonerOutput, AccountClonerOutput::Cloned, CloneOutputMap, -}; -use magicblock_accounts_api::InternalAccountProvider; use magicblock_bank::bank::Bank; -use magicblock_committor_service::{ - persist::BundleSignatureRow, ChangedAccount, Changeset, ChangesetCommittor, - ChangesetMeta, -}; -use magicblock_processor::execute_transaction::execute_legacy_transaction; +use magicblock_committor_service::L1MessageCommittor; use magicblock_program::{ - magic_scheduled_l1_message::ScheduledL1Message, - register_scheduled_commit_sent, FeePayerAccount, Pubkey, ScheduledCommit, - SentCommit, TransactionScheduler, + magic_scheduled_l1_message::ScheduledL1Message, TransactionScheduler, }; use magicblock_transaction_status::TransactionStatusSender; -use solana_sdk::{ - account::ReadableAccount, hash::Hash, transaction::Transaction, -}; +use tokio::sync::mpsc::{channel, Sender}; use crate::{ - errors::AccountsResult, AccountCommittee, ScheduledCommitsProcessor, + errors::AccountsResult, + remote_scheduled_commits_worker::RemoteScheduledCommitsWorker, + ScheduledCommitsProcessor, }; -pub struct RemoteScheduledCommitsProcessor { +pub struct RemoteScheduledCommitsProcessor { transaction_scheduler: TransactionScheduler, - cloned_accounts: CloneOutputMap, bank: Arc, - transaction_status_sender: Option, + worker_sender: Sender>, +} + +impl RemoteScheduledCommitsProcessor { + pub fn new( + bank: Arc, + committor: Arc, + transaction_status_sender: TransactionStatusSender, + ) -> Self { + let (worker_sender, worker_receiver) = channel(1000); + let worker = RemoteScheduledCommitsWorker::new( + bank.clone(), + committor, + transaction_status_sender, + worker_receiver, + ); + tokio::spawn(worker.start()); + + Self { + bank, + worker_sender, + transaction_scheduler: TransactionScheduler::default(), + } + } } #[async_trait] -impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { - async fn process( - &self, - account_provider: &IAP, - changeset_committor: &Arc, - ) -> AccountsResult<()> - where - IAP: InternalAccountProvider, - CC: ChangesetCommittor, - { +impl ScheduledCommitsProcessor + for RemoteScheduledCommitsProcessor +{ + async fn process(&self) -> AccountsResult<()> { let scheduled_l1_messages = self.transaction_scheduler.take_scheduled_actions(); @@ -55,7 +56,10 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { return Ok(()); } - self.process_changeset(changeset_committor, changeset, sent_commits); + self.worker_sender + .send(scheduled_l1_messages) + .await + .expect("We shall be able to processs commmits"); Ok(()) } @@ -68,139 +72,3 @@ impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { self.transaction_scheduler.clear_scheduled_actions(); } } - -impl RemoteScheduledCommitsProcessor { - pub fn new( - bank: Arc, - cloned_accounts: CloneOutputMap, - transaction_status_sender: Option, - ) -> Self { - Self { - bank, - transaction_status_sender, - cloned_accounts, - transaction_scheduler: TransactionScheduler::default(), - } - } - - fn fetch_cloned_account( - pubkey: &Pubkey, - cloned_accounts: &CloneOutputMap, - ) -> Option { - cloned_accounts - .read() - .expect("RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned") - .get(pubkey).cloned() - } - - fn process_changeset( - &self, - changeset_committor: &Arc, - changeset: Changeset, - mut sent_commits: HashMap, - ephemeral_blockhash: Hash, - ) { - // We process the changeset on a separate task in order to not block - // the validator (slot advance) itself - let changeset_committor = changeset_committor.clone(); - let bank = self.bank.clone(); - let transaction_status_sender = self.transaction_status_sender.clone(); - - tokio::task::spawn(async move { - // Create one sent commit transaction per bundle in our validator - let changeset_metadata = ChangesetMeta::from(&changeset); - debug!( - "Committing changeset with {} accounts", - changeset_metadata.accounts.len() - ); - match changeset_committor - .commit_changeset(changeset, ephemeral_blockhash, true) - .await - { - Ok(Some(reqid)) => { - debug!( - "Committed changeset with {} accounts via reqid {}", - changeset_metadata.accounts.len(), - reqid - ); - } - Ok(None) => { - debug!( - "Committed changeset with {} accounts, but did not get a reqid", - changeset_metadata.accounts.len() - ); - } - Err(err) => { - error!( - "Tried to commit changeset with {} accounts but failed to send request ({:#?})", - changeset_metadata.accounts.len(),err - ); - } - } - for bundle_id in changeset_metadata - .accounts - .iter() - .map(|account| account.bundle_id) - .collect::>() - { - let bundle_signatures = match changeset_committor - .get_bundle_signatures(bundle_id) - .await - { - Ok(Ok(sig)) => sig, - Ok(Err(err)) => { - error!("Encountered error while getting bundle signatures for {}: {:?}", bundle_id, err); - continue; - } - Err(err) => { - error!("Encountered error while getting bundle signatures for {}: {:?}", bundle_id, err); - continue; - } - }; - match bundle_signatures { - Some(BundleSignatureRow { - processed_signature, - finalized_signature, - bundle_id, - .. - }) => { - let mut chain_signatures = vec![processed_signature]; - if let Some(finalized_signature) = finalized_signature { - chain_signatures.push(finalized_signature); - } - if let Some(( - commit_sent_transaction, - mut sent_commit, - )) = sent_commits.remove(&bundle_id) - { - sent_commit.chain_signatures = chain_signatures; - register_scheduled_commit_sent(sent_commit); - match execute_legacy_transaction( - commit_sent_transaction, - &bank, - transaction_status_sender.as_ref() - ) { - Ok(signature) => debug!( - "Signaled sent commit with internal signature: {:?}", - signature - ), - Err(err) => { - error!("Failed to signal sent commit via transaction: {}", err); - } - } - } else { - error!( - "BUG: Failed to get sent commit for bundle id {} that should have been added", - bundle_id - ); - } - } - None => error!( - "Failed to get bundle signatures for bundle id {}", - bundle_id - ), - } - } - }); - } -} diff --git a/magicblock-accounts/src/remote_scheduled_commits_worker.rs b/magicblock-accounts/src/remote_scheduled_commits_worker.rs new file mode 100644 index 000000000..5a4481795 --- /dev/null +++ b/magicblock-accounts/src/remote_scheduled_commits_worker.rs @@ -0,0 +1,138 @@ +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, +}; + +use log::{debug, error}; +use magicblock_bank::bank::Bank; +use magicblock_committor_service::{ + persist::BundleSignatureRow, ChangesetMeta, L1MessageCommittor, +}; +use magicblock_processor::execute_transaction::execute_legacy_transaction; +use magicblock_program::{ + magic_scheduled_l1_message::ScheduledL1Message, + register_scheduled_commit_sent, SentCommit, +}; +use magicblock_transaction_status::TransactionStatusSender; +use solana_sdk::transaction::Transaction; +use tokio::sync::mpsc::Receiver; + +pub(crate) struct RemoteScheduledCommitsWorker { + bank: Arc, + committor: Arc, + transaction_status_sender: TransactionStatusSender, + message_receiver: Receiver>, +} + +impl RemoteScheduledCommitsWorker { + pub fn new( + bank: Arc, + committor: Arc, + transaction_status_sender: TransactionStatusSender, + message_receiver: Receiver>, + ) -> Self { + Self { + bank, + committor, + transaction_status_sender, + message_receiver, + } + } + + pub async fn start(mut self) { + while let Some(l1_messages) = self.message_receiver.recv().await { + let metadata = ChangesetMeta::from(&l1_messages); + match self.committor.commit_l1_messages(l1_messages).await { + Ok(Some(reqid)) => { + debug!( + "Committed changeset with {} accounts via reqid {}", + metadata.accounts.len(), + reqid + ); + } + Ok(None) => { + debug!( + "Committed changeset with {} accounts, but did not get a reqid", + metadata.accounts.len() + ); + } + Err(err) => { + error!( + "Tried to commit changeset with {} accounts but failed to send request ({:#?})", + metadata.accounts.len(),err + ); + } + } + } + } + + async fn process_message_result( + &self, + metadata: ChangesetMeta, + mut sent_commits: HashMap, + ) { + for bundle_id in metadata + .accounts + .iter() + .map(|account| account.bundle_id) + .collect::>() + { + let bundle_signatures = match self + .committor + .get_bundle_signatures(bundle_id) + .await + { + Ok(Ok(sig)) => sig, + Ok(Err(err)) => { + error!("Encountered error while getting bundle signatures for {}: {:?}", bundle_id, err); + continue; + } + Err(err) => { + error!("Encountered error while getting bundle signatures for {}: {:?}", bundle_id, err); + continue; + } + }; + match bundle_signatures { + Some(BundleSignatureRow { + processed_signature, + finalized_signature, + bundle_id, + .. + }) => { + let mut chain_signatures = vec![processed_signature]; + if let Some(finalized_signature) = finalized_signature { + chain_signatures.push(finalized_signature); + } + if let Some((commit_sent_transaction, mut sent_commit)) = + sent_commits.remove(&bundle_id) + { + sent_commit.chain_signatures = chain_signatures; + register_scheduled_commit_sent(sent_commit); + match execute_legacy_transaction( + commit_sent_transaction, + &self.bank, + Some(&self.transaction_status_sender), + ) { + Ok(signature) => debug!( + "Signaled sent commit with internal signature: {:?}", + signature + ), + Err(err) => { + error!("Failed to signal sent commit via transaction: {}", err); + } + } + } else { + error!( + "BUG: Failed to get sent commit for bundle id {} that should have been added", + bundle_id + ); + } + } + None => error!( + "Failed to get bundle signatures for bundle id {}", + bundle_id + ), + } + } + } +} diff --git a/magicblock-accounts/src/traits.rs b/magicblock-accounts/src/traits.rs index 94699bf37..444180f83 100644 --- a/magicblock-accounts/src/traits.rs +++ b/magicblock-accounts/src/traits.rs @@ -2,7 +2,7 @@ use std::{collections::HashSet, sync::Arc}; use async_trait::async_trait; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::ChangesetCommittor; +use magicblock_committor_service::L1MessageCommittor; use magicblock_metrics::metrics::HistogramTimer; use solana_rpc_client::rpc_client::SerializableTransaction; use solana_sdk::{ @@ -15,11 +15,7 @@ use crate::errors::AccountsResult; #[async_trait] pub trait ScheduledCommitsProcessor { /// Processes all commits that were scheduled and accepted - async fn process( - &self, - account_provider: &IAP, - changeset_committor: &Arc, - ) -> AccountsResult<()>; + async fn process(&self) -> AccountsResult<()>; /// Returns the number of commits that were scheduled and accepted fn scheduled_commits_len(&self) -> usize; diff --git a/magicblock-api/src/tickers.rs b/magicblock-api/src/tickers.rs index 00e3afa5f..8cccaae6f 100644 --- a/magicblock-api/src/tickers.rs +++ b/magicblock-api/src/tickers.rs @@ -7,7 +7,10 @@ use std::{ }; use log::*; -use magicblock_accounts::AccountsManager; +use magicblock_accounts::{ + remote_scheduled_commits_processor::RemoteScheduledCommitsProcessor, + AccountsManager, ScheduledCommitsProcessor, +}; use magicblock_bank::bank::Bank; use magicblock_committor_service::CommittorService; use magicblock_core::magic_program; @@ -21,20 +24,19 @@ use tokio_util::sync::CancellationToken; use crate::slot::advance_slot_and_update_ledger; -pub fn init_slot_ticker( +pub fn init_slot_ticker( bank: &Arc, - accounts_manager: &Arc, - committor_service: &Arc, - transaction_status_sender: Option, + committor_processor: &Arc, + transaction_status_sender: TransactionStatusSender, ledger: Arc, tick_duration: Duration, exit: Arc, ) -> tokio::task::JoinHandle<()> { let bank = bank.clone(); - let accounts_manager = accounts_manager.clone(); - let committor_service = committor_service.clone(); - let log = tick_duration >= Duration::from_secs(5); + let committor_processor = committor_processor.clone(); + tokio::task::spawn(async move { + let log = tick_duration >= Duration::from_secs(5); while !exit.load(Ordering::Relaxed) { tokio::time::sleep(tick_duration).await; @@ -58,17 +60,14 @@ pub fn init_slot_ticker( if let Err(err) = execute_legacy_transaction( tx, &bank, - transaction_status_sender.as_ref(), + Some(&transaction_status_sender), ) { error!("Failed to accept scheduled commits: {:?}", err); } else { // 2. Process those scheduled commits // TODO: fix the possible delay here // https://github.com/magicblock-labs/magicblock-validator/issues/104 - if let Err(err) = accounts_manager - .process_scheduled_commits(&committor_service) - .await - { + if let Err(err) = committor_processor.process().await { error!( "Failed to process scheduled commits: {:?}", err From 1f74fe4958e3ca4340a3a261495da7d4305c7a60 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 15 Jul 2025 15:22:52 +0900 Subject: [PATCH 096/199] fix: compilation with new RemoteCommitor --- magicblock-api/src/magic_validator.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index df8744cea..b09db2f44 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -24,9 +24,7 @@ use magicblock_account_fetcher::{ use magicblock_account_updates::{ RemoteAccountUpdatesClient, RemoteAccountUpdatesWorker, }; -use magicblock_accounts::{ - utils::try_rpc_cluster_from_cluster, AccountsManager, -}; +use magicblock_accounts::{remote_scheduled_commits_processor::RemoteScheduledCommitsProcessor, utils::try_rpc_cluster_from_cluster, AccountsManager, ScheduledCommitsProcessor}; use magicblock_accounts_api::BankAccountProvider; use magicblock_accounts_db::{ config::AccountsDbConfig, error::AccountsDbError, @@ -142,6 +140,8 @@ pub struct MagicValidator { pubsub_close_handle: PubsubServiceCloseHandle, sample_performance_service: Option, commit_accounts_ticker: Option>, + remote_scheduled_commits_processor: + Arc>, remote_account_fetcher_worker: Option, remote_account_fetcher_handle: Option>, remote_account_updates_worker: Option, @@ -323,6 +323,13 @@ impl MagicValidator { }, )?); + let remote_scheduled_commits_processor = + Arc::new(RemoteScheduledCommitsProcessor::new( + bank.clone(), + committor_service.clone(), + transaction_status_sender.clone(), + )); + let remote_account_cloner_worker = RemoteAccountClonerWorker::new( bank_account_provider, remote_account_fetcher_client, @@ -378,6 +385,7 @@ impl MagicValidator { geyser_rpc_service, slot_ticker: None, commit_accounts_ticker: None, + remote_scheduled_commits_processor, remote_account_fetcher_worker: Some(remote_account_fetcher_worker), remote_account_fetcher_handle: None, remote_account_updates_worker: Some(remote_account_updates_worker), @@ -448,7 +456,7 @@ impl MagicValidator { bank, cloned_accounts, remote_account_cloner_client, - Some(transaction_status_sender), + transaction_status_sender, // NOTE: we could avoid passing a copy of the keypair here if we instead pass // something akin to a ValidatorTransactionSigner that gets it via the [validator_authority] // method from the [magicblock_program] module, forgetting it immediately after. @@ -573,12 +581,12 @@ impl MagicValidator { // Thus while the ledger is processed we don't yet run the machinery to handle // scheduled commits and we clear all scheduled commits before fully starting the // validator. - let scheduled_commits = self.accounts_manager.scheduled_commits_len(); + let scheduled_commits = self.remote_scheduled_commits_processor.scheduled_commits_len(); debug!( "Found {} scheduled commits while processing ledger, clearing them", scheduled_commits ); - self.accounts_manager.clear_scheduled_commits(); + self.remote_scheduled_commits_processor.clear_scheduled_commits(); // We want the next transaction either due to hydrating of cloned accounts or // user request to be processed in the next slot such that it doesn't become @@ -694,9 +702,8 @@ impl MagicValidator { self.slot_ticker = Some(init_slot_ticker( &self.bank, - &self.accounts_manager, - &self.committor_service, - Some(self.transaction_status_sender.clone()), + &self.remote_scheduled_commits_processor, + self.transaction_status_sender.clone(), self.ledger.clone(), Duration::from_millis(self.config.validator.millis_per_slot), self.exit.clone(), From ad8f968046dc0f416d0145f0a51e2888105d1314 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 16 Jul 2025 14:54:27 +0900 Subject: [PATCH 097/199] feat: added CommitSchedulerWorker that populations Inner Schedule, handles incoming messages & creates new executors for available tasks --- magicblock-accounts/src/lib.rs | 3 +- .../src/remote_scheduled_commits_worker.rs | 4 + .../stubs/scheduled_commits_processor_stub.rs | 8 +- magicblock-api/src/magic_validator.rs | 13 +- .../src/commit/committor_processor.rs | 4 - .../src/commit_scheduler.rs | 1 + .../commit_scheduler_inner.rs | 6 + .../commit_scheduler_worker.rs | 207 ++++++++++++++---- .../src/commit_scheduler/executor_pool.rs | 55 +++++ .../src/l1_message_executor.rs | 4 +- magicblock-committor-service/src/lib.rs | 2 +- magicblock-committor-service/src/service.rs | 18 +- .../src/stubs/changeset_committor_stub.rs | 6 +- .../delivery_preparator.rs | 7 +- .../tests/ix_commit_local.rs | 4 +- 15 files changed, 261 insertions(+), 81 deletions(-) create mode 100644 magicblock-committor-service/src/commit_scheduler/executor_pool.rs diff --git a/magicblock-accounts/src/lib.rs b/magicblock-accounts/src/lib.rs index ec28920c7..9e3e0c854 100644 --- a/magicblock-accounts/src/lib.rs +++ b/magicblock-accounts/src/lib.rs @@ -3,7 +3,8 @@ mod config; pub mod errors; mod external_accounts_manager; mod remote_account_committer; -mod remote_scheduled_commits_processor; +pub mod remote_scheduled_commits_processor; +mod remote_scheduled_commits_worker; mod traits; pub mod utils; diff --git a/magicblock-accounts/src/remote_scheduled_commits_worker.rs b/magicblock-accounts/src/remote_scheduled_commits_worker.rs index 5a4481795..2948cc3fd 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_worker.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_worker.rs @@ -42,6 +42,8 @@ impl RemoteScheduledCommitsWorker { pub async fn start(mut self) { while let Some(l1_messages) = self.message_receiver.recv().await { let metadata = ChangesetMeta::from(&l1_messages); + // TODO(edwin) mayne actuall self.committor.commit_l1_messages(l1_messages). + // should be on a client, and here we just send receivers to wait on and process match self.committor.commit_l1_messages(l1_messages).await { Ok(Some(reqid)) => { debug!( @@ -63,6 +65,8 @@ impl RemoteScheduledCommitsWorker { ); } } + + self.process_message_result(metadata, todo!()).await; } } diff --git a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs index 9fe51cb37..30b21e02b 100644 --- a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs +++ b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs @@ -3,18 +3,14 @@ use std::sync::Arc; use async_trait::async_trait; use magicblock_accounts::{errors::AccountsResult, ScheduledCommitsProcessor}; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::ChangesetCommittor; +use magicblock_committor_service::L1MessageCommittor; #[derive(Default)] pub struct ScheduledCommitsProcessorStub {} #[async_trait] impl ScheduledCommitsProcessor for ScheduledCommitsProcessorStub { - async fn process( - &self, - _account_provider: &IAP, - _changeset_committor: &Arc, - ) -> AccountsResult<()> { + async fn process(&self) -> AccountsResult<()> { Ok(()) } fn scheduled_commits_len(&self) -> usize { diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index b09db2f44..39b9ddf23 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -24,7 +24,11 @@ use magicblock_account_fetcher::{ use magicblock_account_updates::{ RemoteAccountUpdatesClient, RemoteAccountUpdatesWorker, }; -use magicblock_accounts::{remote_scheduled_commits_processor::RemoteScheduledCommitsProcessor, utils::try_rpc_cluster_from_cluster, AccountsManager, ScheduledCommitsProcessor}; +use magicblock_accounts::{ + remote_scheduled_commits_processor::RemoteScheduledCommitsProcessor, + utils::try_rpc_cluster_from_cluster, AccountsManager, + ScheduledCommitsProcessor, +}; use magicblock_accounts_api::BankAccountProvider; use magicblock_accounts_db::{ config::AccountsDbConfig, error::AccountsDbError, @@ -581,12 +585,15 @@ impl MagicValidator { // Thus while the ledger is processed we don't yet run the machinery to handle // scheduled commits and we clear all scheduled commits before fully starting the // validator. - let scheduled_commits = self.remote_scheduled_commits_processor.scheduled_commits_len(); + let scheduled_commits = self + .remote_scheduled_commits_processor + .scheduled_commits_len(); debug!( "Found {} scheduled commits while processing ledger, clearing them", scheduled_commits ); - self.remote_scheduled_commits_processor.clear_scheduled_commits(); + self.remote_scheduled_commits_processor + .clear_scheduled_commits(); // We want the next transaction either due to hydrating of cloned accounts or // user request to be processed in the next slot such that it doesn't become diff --git a/magicblock-committor-service/src/commit/committor_processor.rs b/magicblock-committor-service/src/commit/committor_processor.rs index 4ba90d5f8..0bf436555 100644 --- a/magicblock-committor-service/src/commit/committor_processor.rs +++ b/magicblock-committor-service/src/commit/committor_processor.rs @@ -5,7 +5,6 @@ use std::{ }; use log::*; -use magicblock_committor_program::{Changeset, ChangesetMeta}; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::{ MagicBlockSendTransactionConfig, MagicblockRpcClient, @@ -24,9 +23,6 @@ use tokio::task::JoinSet; use super::common::{lookup_table_keys, send_and_confirm}; use crate::{ commit_stage::CommitStage, - commit_strategist::commit_strategy::{ - split_changesets_by_commit_strategy, SplitChangesets, - }, compute_budget::{ComputeBudget, ComputeBudgetConfig}, config::ChainConfig, error::CommittorServiceResult, diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index e76477a53..9e80bc245 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -1,6 +1,7 @@ pub(crate) mod commit_scheduler_inner; mod commit_scheduler_worker; mod db; +mod executor_pool; use std::sync::Arc; diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index 92e94e04d..9cce8ac2a 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -199,4 +199,10 @@ impl CommitSchedulerInner { (entries, is_conflicting) } + + /// Returns number of blocked messages + /// Note: this doesn't include "executing" messages + pub fn blocked_messages_len(&self) -> usize { + self.blocked_messages.len() + } } diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index d1d84f78a..4a57d624b 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -1,9 +1,17 @@ -use std::sync::{Arc, Mutex}; +use std::{ + collections::HashMap, + sync::{Arc, Mutex}, +}; +use log::{info, trace, warn}; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; -use tokio::sync::mpsc::{error::TryRecvError, Receiver}; +use solana_pubkey::Pubkey; +use tokio::sync::{ + mpsc::{error::TryRecvError, Receiver}, + Notify, OwnedSemaphorePermit, Semaphore, +}; use crate::{ commit_scheduler::{ @@ -12,9 +20,12 @@ use crate::{ Error, }, l1_message_executor::L1MessageExecutor, + transaction_preperator::transaction_preparator::TransactionPreparator, ComputeBudgetConfig, }; +const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; + pub(crate) struct CommitSchedulerWorker { db: Arc, rpc_client: MagicblockRpcClient, @@ -22,6 +33,9 @@ pub(crate) struct CommitSchedulerWorker { compute_budget_config: ComputeBudgetConfig, receiver: Receiver, + // TODO(edwin): replace notify. issue: 2 simultaneous notifications + notify: Arc, + executors_semaphore: Arc, inner: Arc>, } @@ -33,76 +47,179 @@ impl CommitSchedulerWorker { compute_budget_config: ComputeBudgetConfig, receiver: Receiver, ) -> Self { + // Number of executors that can send messages in parallel to L1 + const NUM_OF_EXECUTORS: u8 = 50; + Self { db, rpc_client, table_mania, compute_budget_config, receiver, + notify: Arc::new(Notify::new()), + executors_semaphore: Arc::new(Semaphore::new( + NUM_OF_EXECUTORS as usize, + )), inner: Arc::new(Mutex::new(CommitSchedulerInner::new())), } } pub async fn start(mut self) { loop { - let l1_message = match self.receiver.try_recv() { - Ok(val) => val, - Err(TryRecvError::Empty) => { - match self.get_or_wait_next_message().await { - Ok(val) => val, - Err(err) => panic!(err), // TODO(edwin): handle - } - } - Err(TryRecvError::Disconnected) => { - // TODO(edwin): handle - panic!("Asdasd") - } + // TODO: unwraps + let l1_message = self.next_scheduled_message().await.unwrap(); + let Some(l1_message) = l1_message else { + // Messages are blocked, skipping + info!("Could not schedule any messages, as all of them are blocked!"); + continue; }; - self.handle_message(l1_message).await; + // Waiting until there's available executor + let permit = self + .executors_semaphore + .clone() + .acquire_owned() + .await + .expect(SEMAPHORE_CLOSED_MSG); + + // Prepare data for execution + let commit_ids = self.deduce_commit_ids(&l1_message).await; + let executor = L1MessageExecutor::new_v1( + self.inner.clone(), + self.rpc_client.clone(), + self.table_mania.clone(), + self.compute_budget_config.clone(), + ); + + // Spawn executor + tokio::spawn(Self::execute( + executor, + l1_message, + commit_ids, + self.inner.clone(), + permit, + self.notify.clone(), + )); } } - async fn handle_message(&mut self, l1_message: ScheduledL1Message) { - let l1_message = if let Some(l1_message) = self - .inner - .lock() - .expect(POISONED_INNER_MSG) - .schedule(l1_message) - { - l1_message - } else { - return; + /// Returns [`ScheduledL1Message`] or None if all messages are blocked + async fn next_scheduled_message( + &mut self, + ) -> Result, Error> { + // Limit on number of messages that can be stored in scheduler + const SCHEDULER_CAPACITY: usize = 1000; + + let can_receive = || { + let num_blocked_messages = self + .inner + .lock() + .expect(POISONED_INNER_MSG) + .blocked_messages_len(); + if num_blocked_messages < SCHEDULER_CAPACITY { + true + } else { + warn!("Scheduler capacity exceeded: {}", num_blocked_messages); + false + } + }; + let message = tokio::select! { + // Notify polled first to prioritize unblocked messages over new one + biased; + _ = self.notify.notified() => { + trace!("Worker executed L1Message, fetching new available one"); + // TODO(edwin): ensure that worker properly completes message in inner schedyler + self.inner.lock().expect(POISONED_INNER_MSG).pop_next_scheduled_message() + }, + result = self.get_new_message(), if can_receive() => { + let l1_message = result?; + self.inner.lock().expect(POISONED_INNER_MSG).schedule(l1_message) + } }; - let executor = L1MessageExecutor::new_v1( - self.inner.clone(), - self.rpc_client.clone(), - self.table_mania.clone(), - self.compute_budget_config.clone(), - ); - tokio::spawn(executor.execute(l1_message, todo!())); + Ok(message) } - /// Return [`ScheduledL1Message`] from DB, otherwise waits on channel - async fn get_or_wait_next_message( - &mut self, - ) -> Result { - // Worker either cleaned-up congested channel and now need to clean-up DB - // or we're just waiting on empty channel - if let Some(l1_message) = self.db.pop_l1_message().await? { - Ok(l1_message) - } else { - if let Some(val) = self.receiver.recv().await { - Ok(val) - } else { - Err(Error::ChannelClosed) + /// Returns [`ScheduledL1Message`] from external channel + async fn get_new_message(&mut self) -> Result { + match self.receiver.try_recv() { + Ok(val) => Ok(val), + Err(TryRecvError::Empty) => { + // Worker either cleaned-up congested channel and now need to clean-up DB + // or we're just waiting on empty channel + if let Some(l1_message) = self.db.pop_l1_message().await? { + Ok(l1_message) + } else { + self.receiver.recv().await.ok_or(Error::ChannelClosed) + } } + Err(TryRecvError::Disconnected) => Err(Error::ChannelClosed), } } + + /// Wrapper on [`L1MessageExecutor`] that handles its results and drops execution permit + async fn execute( + executor: L1MessageExecutor, + l1_message: ScheduledL1Message, + commit_ids: HashMap, + inner_scheduler: Arc>, + execution_permit: OwnedSemaphorePermit, + notify: Arc, + ) { + let _ = executor.execute(l1_message.clone(), commit_ids).await; + // Remove executed task from Scheduler to unblock other messages + inner_scheduler.lock().expect(POISONED_INNER_MSG).complete(&l1_message); + // Notify main loop that executor is done + // This will trigger scheduling next message + notify.notify_waiters(); + // Free worker + drop(execution_permit); + } + + async fn deduce_commit_ids( + &mut self, + l1_message: &ScheduledL1Message, + ) -> HashMap { + todo!() + } } // Worker schedule: // We have a pool of workers // We are ready to accept message // When we have a worker available to process it + +/// 1. L1Messages arrive +/// 2. We call to schedule their execution +/// 3. Once landed we need to execute a sent tx on L2s + +/// There's a part that schedules and sends TXs +/// L1MessageExecutor - runs Preparator + executes txs +/// Scheduler/MessageExecutionManager - Schedules execution of L1MessageExecutor +/// Committor - gets results and persists them +/// RemoteScheduledCommitsProcessor - just gets results and writes them to db +/// +fn useless() {} + +// Committor needs to get result of execution & persist it +// Committor needs to send results to Remote + +// Could committor retry or handle failed execution somehow? +// Should that be a business of persister? +// + +// Committor is used to manager TableMania +// On commits we fetch the state + +// Does Remote care about readiness of particular task? No +// It just runs TXs where he commits results to l2. +// TODO(edwin): Remote takes single channel for result + +// Does Committor care about readiness of particular task? +// It kinda doesn't +// Is it correct for MessageExecutionManager to be just a Stream? +// + +// TODO(edwin): TransactionExecutor doesn't care about channels and shit +// It gets message, sends, retries & gives back result +fn useless2() {} diff --git a/magicblock-committor-service/src/commit_scheduler/executor_pool.rs b/magicblock-committor-service/src/commit_scheduler/executor_pool.rs new file mode 100644 index 000000000..d8dfe1c7e --- /dev/null +++ b/magicblock-committor-service/src/commit_scheduler/executor_pool.rs @@ -0,0 +1,55 @@ +use std::future::Future; + +use tokio::{ + sync::{Semaphore, SemaphorePermit}, + task::JoinHandle, +}; + +type MessageExecutorResult = (); + +pub(crate) struct MessageExecutorsPool { + limit: u8, + semaphore: Semaphore, + handles: Vec>, +} + +impl MessageExecutorsPool { + pub fn new(limit: u8) -> Self { + Self { + limit, + semaphore: Semaphore::new(limit as usize), + handles: vec![], + } + } + + pub async fn execute>( + &self, + f: impl FnOnce(SemaphorePermit) -> T, + ) { + let permit = self.semaphore.acquire().await.expect("asd"); + f(permit).await + } + + pub async fn get_worker_permit(&self) -> SemaphorePermit { + let permit = self.semaphore.acquire().await.unwrap(); + permit + } +} + +// TODO: how executiong works? +// case - No available worker +// We can't process any messages - waiting + +// Say worker finished +// Messages still blocked by each other +// We move to get message from channel +// We stuck +// If we get worker without + +// Flow: +// 1. check if there's available message to be executed +// 2. Fetch it and wait for available worker to execute it + +// If no messages workers are idle +// If more tham one free, then we will launch woker and pick another +// on next iteration diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index ab0fb82dd..c9e3193bc 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -45,7 +45,7 @@ impl L1MessageExecutor { rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, - ) -> Self { + ) -> L1MessageExecutor { let authority = validator_authority(); let transaction_preparator = TransactionPreparatorV1::new( rpc_client.clone(), @@ -165,7 +165,7 @@ pub enum Error { SignerError(#[from] SignerError), #[error("PreparatorError: {0}")] PreparatorError(#[from] crate::transaction_preperator::error::Error), - #[error("MagicBlockRpcClientError: {)}")] + #[error("MagicBlockRpcClientError: {0}")] MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), } diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index c326f22f5..ac28cd1f1 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -30,7 +30,7 @@ pub use compute_budget::ComputeBudgetConfig; pub use magicblock_committor_program::{ ChangedAccount, Changeset, ChangesetMeta, }; -pub use service::{ChangesetCommittor, CommittorService}; +pub use service::{CommittorService, L1MessageCommittor}; pub fn changeset_for_slot(slot: u64) -> Changeset { Changeset { slot, diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index e1859f1fa..bc6337b16 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -278,7 +278,7 @@ impl CommittorService { } } -impl ChangesetCommittor for CommittorService { +impl L1MessageCommittor for CommittorService { fn reserve_pubkeys_for_committee( &self, committee: Pubkey, @@ -293,17 +293,14 @@ impl ChangesetCommittor for CommittorService { rx } - fn commit_changeset( + fn commit_l1_messages( &self, - changeset: Changeset, - finalize: bool, + l1_messages: Vec, ) -> oneshot::Receiver> { let (tx, rx) = oneshot::channel(); self.try_send(CommittorMessage::CommitChangeset { respond_to: tx, - changeset, - ephemeral_blockhash, - finalize, + l1_messages, }); rx } @@ -334,7 +331,7 @@ impl ChangesetCommittor for CommittorService { } } -pub trait ChangesetCommittor: Send + Sync + 'static { +pub trait L1MessageCommittor: Send + Sync + 'static { /// Reserves pubkeys used in most commits in a lookup table fn reserve_pubkeys_for_committee( &self, @@ -343,10 +340,9 @@ pub trait ChangesetCommittor: Send + Sync + 'static { ) -> oneshot::Receiver>; /// Commits the changeset and returns the reqid - fn commit_changeset( + fn commit_l1_messages( &self, - changeset: Changeset, - finalize: bool, + l1_messages: Vec, ) -> oneshot::Receiver>; /// Gets statuses of accounts that were committed as part of a request with provided reqid diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index 6e39bd653..c6294cfd6 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -18,7 +18,7 @@ use crate::{ BundleSignatureRow, CommitStatus, CommitStatusRow, CommitStatusSignatures, CommitStrategy, CommitType, }, - ChangesetCommittor, + L1MessageCommittor, }; #[derive(Default)] @@ -28,8 +28,8 @@ pub struct ChangesetCommittorStub { committed_changesets: Arc>>, } -impl ChangesetCommittor for ChangesetCommittorStub { - fn commit_changeset( +impl L1MessageCommittor for ChangesetCommittorStub { + fn commit_l1_messages( &self, changeset: Changeset, ephemeral_blockhash: Hash, diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 598428d79..e9eef49fa 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -98,7 +98,7 @@ impl DeliveryPreparator { ) .await?; // Writing chunks with some retries. Stol - self.write_buffer_with_retries::<5>(authority, &preparation_info) + self.write_buffer_with_retries(authority, &preparation_info, 5) .await?; Ok(()) @@ -145,14 +145,15 @@ impl DeliveryPreparator { } /// Based on Chunks state, try MAX_RETRIES to fill buffer - async fn write_buffer_with_retries( + async fn write_buffer_with_retries( &self, authority: &Keypair, info: &TaskPreparationInfo, + max_retries: usize, ) -> DeliveryPreparatorResult<()> { let mut last_error = Error::InternalError(anyhow!("ZeroRetriesRequested")); - for _ in 0..MAX_RETRIES { + for _ in 0..max_retries { let chunks = match self.rpc_client.get_account(&info.chunks_pda).await { Ok(Some(account)) => { diff --git a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs index 7e0dfe389..a1e9eb7a9 100644 --- a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs +++ b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs @@ -1,5 +1,5 @@ use log::*; -use magicblock_committor_service::{ChangesetCommittor, ComputeBudgetConfig}; +use magicblock_committor_service::{L1MessageCommittor, ComputeBudgetConfig}; use magicblock_rpc_client::MagicblockRpcClient; use std::collections::{HashMap, HashSet}; use std::time::{Duration, Instant}; @@ -659,7 +659,7 @@ async fn ix_commit_local( let ephemeral_blockhash = Hash::default(); let reqid = service - .commit_changeset(changeset.clone(), ephemeral_blockhash, finalize) + .commit_l1_messages(changeset.clone(), ephemeral_blockhash, finalize) .await .unwrap() .unwrap(); From a7a0456d0d4e9e1ced8736494fc629ff0faa4f3e Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 16 Jul 2025 18:21:19 +0900 Subject: [PATCH 098/199] refactor: expose result stream from SchedulerWorker --- .../src/commit_scheduler.rs | 81 ++++++++----------- .../commit_scheduler_worker.rs | 47 ++++++++--- .../src/l1_message_executor.rs | 17 ++-- 3 files changed, 78 insertions(+), 67 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index 9e80bc245..77402b176 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -7,28 +7,49 @@ use std::sync::Arc; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::MagicblockRpcClient; -use tokio::sync::mpsc::{channel, error::TrySendError, Sender}; - -use crate::commit_scheduler::{ - commit_scheduler_worker::CommitSchedulerWorker, db::DB, +use magicblock_table_mania::TableMania; +use tokio::sync::{broadcast, mpsc, mpsc::error::TrySendError}; + +use crate::{ + commit_scheduler::{ + commit_scheduler_worker::CommitSchedulerWorker, db::DB, + }, + l1_message_executor::{ExecutionOutput, MessageExecutorResult}, + ComputeBudgetConfig, }; pub struct CommitScheduler { db: Arc, - sender: Sender, + result_receiver: + broadcast::Receiver>, + message_sender: mpsc::Sender, } impl CommitScheduler { - pub fn new(rpc_client: MagicblockRpcClient, db: D) -> Self { + pub fn new( + rpc_client: MagicblockRpcClient, + db: D, + table_mania: TableMania, + compute_budget_config: ComputeBudgetConfig, + ) -> Self { let db = Arc::new(db); - let (sender, receiver) = channel(1000); + let (sender, receiver) = mpsc::channel(1000); // TODO(edwin): add concellation logic - let worker = - CommitSchedulerWorker::new(db.clone(), rpc_client, receiver); - tokio::spawn(worker.start()); - - Self { db, sender } + let worker = CommitSchedulerWorker::new( + db.clone(), + rpc_client, + table_mania, + compute_budget_config, + receiver, + ); + let result_receiver = worker.spawn(); + + Self { + db, + message_sender: sender, + result_receiver, + } } /// Schedules [`ScheduledL1Message`] message to be executed @@ -48,7 +69,7 @@ impl CommitScheduler { continue; } - let err = if let Err(err) = self.sender.try_send(el) { + let err = if let Err(err) = self.message_sender.try_send(el) { err } else { continue; @@ -75,37 +96,3 @@ pub enum Error { #[error("DBError: {0}")] DBError(#[from] db::Error), } - -/// ideal system: -/// -// Service keeps accepting messages -// once there's a full channel in order not to stall or overload RAM -// we write to - -// Having message service batches in optimal way - -/// WE NEED: -// - Split into proper Commitable chunks -// - - -/// We insert into scheduler and then figure out how to optimally split messages -// or we split messages and then try to commit specific chunks? - -// we write to channel it becom3s full -// we need to write to db -// Who will - -// TODO Scheduler also return revicer chammel that will receive -// (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] -// can receive them and hande them txs and sucj - -// after we flagged that items in db -// next sends can't fo to queue, since that will break an order -// they need to go to db. - -// Our loop - -/// Design: -/// Let it be a general service -/// Gets directly commits from Processor, then -fn useless() {} diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 4a57d624b..6ae73ce91 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -9,8 +9,8 @@ use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; use tokio::sync::{ - mpsc::{error::TryRecvError, Receiver}, - Notify, OwnedSemaphorePermit, Semaphore, + broadcast, mpsc, mpsc::error::TryRecvError, Notify, OwnedSemaphorePermit, + Semaphore, }; use crate::{ @@ -19,7 +19,9 @@ use crate::{ db::DB, Error, }, - l1_message_executor::L1MessageExecutor, + l1_message_executor::{ + ExecutionOutput, L1MessageExecutor, MessageExecutorResult, + }, transaction_preperator::transaction_preparator::TransactionPreparator, ComputeBudgetConfig, }; @@ -31,7 +33,7 @@ pub(crate) struct CommitSchedulerWorker { rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, - receiver: Receiver, + receiver: mpsc::Receiver, // TODO(edwin): replace notify. issue: 2 simultaneous notifications notify: Arc, @@ -45,7 +47,7 @@ impl CommitSchedulerWorker { rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, - receiver: Receiver, + receiver: mpsc::Receiver, ) -> Self { // Number of executors that can send messages in parallel to L1 const NUM_OF_EXECUTORS: u8 = 50; @@ -64,7 +66,26 @@ impl CommitSchedulerWorker { } } - pub async fn start(mut self) { + /// Spawns `main_loop` and return `Receiver` listening to results + pub fn spawn( + mut self, + ) -> broadcast::Receiver> { + let (sender, receiver) = broadcast::channel(100); + tokio::spawn(self.main_loop(sender)); + + receiver + } + + /// Main loop that: + /// 1. Handles & schedules incoming message + /// 2. Finds available executor + /// 3. Spawns execution of scheduled message + async fn main_loop( + mut self, + result_sender: broadcast::Sender< + MessageExecutorResult, + >, + ) { loop { // TODO: unwraps let l1_message = self.next_scheduled_message().await.unwrap(); @@ -85,7 +106,6 @@ impl CommitSchedulerWorker { // Prepare data for execution let commit_ids = self.deduce_commit_ids(&l1_message).await; let executor = L1MessageExecutor::new_v1( - self.inner.clone(), self.rpc_client.clone(), self.table_mania.clone(), self.compute_budget_config.clone(), @@ -98,6 +118,7 @@ impl CommitSchedulerWorker { commit_ids, self.inner.clone(), permit, + result_sender.clone(), self.notify.clone(), )); } @@ -164,11 +185,19 @@ impl CommitSchedulerWorker { commit_ids: HashMap, inner_scheduler: Arc>, execution_permit: OwnedSemaphorePermit, + result_sender: broadcast::Sender< + MessageExecutorResult, + >, notify: Arc, ) { - let _ = executor.execute(l1_message.clone(), commit_ids).await; + let result = executor.execute(l1_message.clone(), commit_ids).await; + // TODO: unwrap + result_sender.send(result).unwrap(); // Remove executed task from Scheduler to unblock other messages - inner_scheduler.lock().expect(POISONED_INNER_MSG).complete(&l1_message); + inner_scheduler + .lock() + .expect(POISONED_INNER_MSG) + .complete(&l1_message); // Notify main loop that executor is done // This will trigger scheduling next message notify.notify_waiters(); diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index c9e3193bc..008d9abef 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -32,16 +32,18 @@ use crate::{ ComputeBudgetConfig, }; +// TODO(edwin): define struct +// (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] +pub struct ExecutionOutput {} + pub(crate) struct L1MessageExecutor { authority: Keypair, rpc_client: MagicblockRpcClient, transaction_preparator: T, - inner: Arc>, } impl L1MessageExecutor { pub fn new_v1( - inner: Arc>, rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, @@ -56,7 +58,6 @@ impl L1MessageExecutor { authority, rpc_client, transaction_preparator, - inner, } } @@ -65,19 +66,13 @@ impl L1MessageExecutor { mut self, l1_message: ScheduledL1Message, commit_ids: HashMap, - ) -> MessageExecutorResult<()> { + ) -> MessageExecutorResult { // Commit message first self.commit(&l1_message, commit_ids).await?; // At the moment validator finalizes right away // In the future there will be a challenge window self.finalize(&l1_message).await?; - // Signal that task is completed - // TODO(edwin): handle error case here as well - self.inner - .lock() - .expect(POISONED_INNER_MSG) - .complete(&l1_message); - Ok(()) + Ok(ExecutionOutput {}) } /// Executes Commit stage From 6a63a2cb5c173190d14a708d1854f3ccb1aefea0 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 16 Jul 2025 19:31:05 +0900 Subject: [PATCH 099/199] feat: initialized CommitIdTracker --- Cargo.lock | 10 ++ magicblock-committor-service/Cargo.toml | 1 + .../src/commit_scheduler.rs | 1 + .../src/commit_scheduler/commit_id_tracker.rs | 91 +++++++++++++++++++ .../commit_scheduler_worker.rs | 19 ++-- .../src/l1_message_executor.rs | 2 +- test-integration/Cargo.lock | 10 ++ 7 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs diff --git a/Cargo.lock b/Cargo.lock index 511636576..c77c224cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3537,6 +3537,15 @@ dependencies = [ "hashbrown 0.15.2", ] +[[package]] +name = "lru" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ea4e65087ff52f3862caff188d489f1fab49a0cb09e01b2e3f1a617b10aaed" +dependencies = [ + "hashbrown 0.15.2", +] + [[package]] name = "lz4" version = "1.28.1" @@ -3811,6 +3820,7 @@ dependencies = [ "futures-util", "lazy_static", "log", + "lru 0.16.0", "magicblock-committor-program", "magicblock-delegation-program 1.0.0", "magicblock-program", diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index 01dec23b8..dc42fee95 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -28,6 +28,7 @@ bincode = { workspace = true } borsh = { workspace = true } futures-util = { workspace = true } log = { workspace = true } +lru = { workspace = true } rusqlite = { workspace = true } solana-account = { workspace = true } solana-pubkey = { workspace = true } diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index 77402b176..0350727fe 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -1,3 +1,4 @@ +mod commit_id_tracker; pub(crate) mod commit_scheduler_inner; mod commit_scheduler_worker; mod db; diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs new file mode 100644 index 000000000..f44c06b10 --- /dev/null +++ b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs @@ -0,0 +1,91 @@ +use std::{ + collections::HashMap, + num::{NonZero, NonZeroUsize}, +}; + +use lru::LruCache; +use magicblock_rpc_client::{ + MagicBlockRpcClientError, MagicBlockRpcClientResult, MagicblockRpcClient, +}; +use solana_pubkey::Pubkey; + +// +pub struct CommitIdTracker { + rpc_client: MagicblockRpcClient, + cache: LruCache, +} + +impl CommitIdTracker { + pub fn new(rpc_client: MagicblockRpcClient) -> Self { + const CACHE_SIZE: NonZeroUsize = + unsafe { NonZeroUsize::new_unchecked(1000) }; + + Self { + rpc_client, + cache: LruCache::new(CACHE_SIZE), + } + } + + /// Returns next ids for requested pubkeys + /// If key isn't in cache, it will be requested + pub async fn next_commit_ids( + &mut self, + pubkeys: &[Pubkey], + ) -> CommitIdTrackerResult> { + let mut result = HashMap::new(); + let mut to_request = Vec::new(); + for pubkey in pubkeys { + // in case already inserted + if result.contains_key(pubkey) { + continue; + } + + if let Some(id) = self.cache.get_mut(pubkey) { + *id += 1; + result.insert(*pubkey, *id); + } else { + to_request.push(*pubkey); + } + } + + // Remove duplicates + to_request.sort(); + to_request.dedup(); + + let remaining_ids = + Self::fetch_commit_ids(&self.rpc_client, &to_request).await?; + to_request + .iter() + .zip(remaining_ids) + .for_each(|(pubkey, id)| { + result.insert(*pubkey, id + 1); + self.cache.push(*pubkey, id + 1); + }); + + Ok(result) + } + + /// Returns current commit id without raising priority + pub fn peek_commit_id(&self, pubkey: &Pubkey) -> Option<&u64> { + self.cache.peek(pubkey) + } + + /// Fetches commit_ids using RPC + /// Note: remove duplicates prior to calling + pub async fn fetch_commit_ids( + rpc_client: &MagicblockRpcClient, + pubkeys: &[Pubkey], + ) -> MagicBlockRpcClientResult> { + todo!() + } +} + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("Failed to get keys: {0}")] + GetCommitIdsError(Vec), + #[error("MagicBlockRpcClientError: {0}")] + MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), +} + +pub type CommitIdTrackerResult = Result; diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 6ae73ce91..303840c71 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -25,14 +25,17 @@ use crate::{ transaction_preperator::transaction_preparator::TransactionPreparator, ComputeBudgetConfig, }; +use crate::commit_scheduler::commit_id_tracker::CommitIdTracker; const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; +// TODO(edwin): reduce num of params: 1,2,3, could be united pub(crate) struct CommitSchedulerWorker { db: Arc, - rpc_client: MagicblockRpcClient, - table_mania: TableMania, - compute_budget_config: ComputeBudgetConfig, + rpc_client: MagicblockRpcClient, // 1. + table_mania: TableMania, // 2. + compute_budget_config: ComputeBudgetConfig, // 3. + commit_id_tracker: CommitIdTracker, receiver: mpsc::Receiver, // TODO(edwin): replace notify. issue: 2 simultaneous notifications @@ -54,9 +57,10 @@ impl CommitSchedulerWorker { Self { db, - rpc_client, + rpc_client: rpc_client.clone(), table_mania, compute_budget_config, + commit_id_tracker: CommitIdTracker::new(rpc_client), receiver, notify: Arc::new(Notify::new()), executors_semaphore: Arc::new(Semaphore::new( @@ -70,10 +74,10 @@ impl CommitSchedulerWorker { pub fn spawn( mut self, ) -> broadcast::Receiver> { - let (sender, receiver) = broadcast::channel(100); - tokio::spawn(self.main_loop(sender)); + let (result_sender, result_receiver) = broadcast::channel(100); + tokio::spawn(self.main_loop(result_sender)); - receiver + result_receiver } /// Main loop that: @@ -149,7 +153,6 @@ impl CommitSchedulerWorker { biased; _ = self.notify.notified() => { trace!("Worker executed L1Message, fetching new available one"); - // TODO(edwin): ensure that worker properly completes message in inner schedyler self.inner.lock().expect(POISONED_INNER_MSG).pop_next_scheduled_message() }, result = self.get_new_message(), if can_receive() => { diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index 008d9abef..e37df1b84 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -63,7 +63,7 @@ impl L1MessageExecutor { /// Executes message on L1 pub async fn execute( - mut self, + &self, l1_message: ScheduledL1Message, commit_ids: HashMap, ) -> MessageExecutorResult { diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index b5fedf62b..450c204ed 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -3448,6 +3448,15 @@ dependencies = [ "hashbrown 0.15.2", ] +[[package]] +name = "lru" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ea4e65087ff52f3862caff188d489f1fab49a0cb09e01b2e3f1a617b10aaed" +dependencies = [ + "hashbrown 0.15.2", +] + [[package]] name = "lz4" version = "1.28.1" @@ -3706,6 +3715,7 @@ dependencies = [ "borsh 1.5.7", "futures-util", "log", + "lru 0.16.0", "magicblock-committor-program", "magicblock-delegation-program 1.0.0", "magicblock-program", From e18522af93e8a068f9a4b31f5eca9769f29eba62 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 17 Jul 2025 15:00:47 +0900 Subject: [PATCH 100/199] feat: adapting Persister to new implementation --- magicblock-committor-service/CHANGES.md | 0 .../src/persist/commit_persister.rs | 171 ++++--- .../src/persist/db.rs | 480 ++++-------------- 3 files changed, 189 insertions(+), 462 deletions(-) create mode 100644 magicblock-committor-service/CHANGES.md diff --git a/magicblock-committor-service/CHANGES.md b/magicblock-committor-service/CHANGES.md new file mode 100644 index 000000000..e69de29bb diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 952ea4f1e..4e037d868 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -2,20 +2,40 @@ use std::{ path::Path, sync::atomic::{AtomicU64, Ordering}, }; - +use std::sync::{Arc, Mutex}; use magicblock_committor_program::Changeset; use solana_sdk::{hash::Hash, pubkey::Pubkey}; - +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use super::{ - db::{BundleSignatureRow, CommitStatusRow}, + db::{CommitStatusRow}, error::{CommitPersistError, CommitPersistResult}, utils::now, CommitStatus, CommitType, CommittorDb, }; +const POISONED_MUTEX_MSG: &str = "Commitor Persister lock poisoned"; + +/// Records lifespan pf commit +pub trait CommitPersisterIface: Send + Sync + Clone { + /// Starts persisting L1Message + fn start_l1_messages(&self, l1_message: &ScheduledL1Message) -> CommitPersistResult<()>; + fn start_l1_message(&self, l1_message: &ScheduledL1Message) -> CommitPersistResult<()>; + fn update_status(&self, message_id: u64, status: CommitStatus) -> CommitPersistResult<()>; + fn get_commit_statuses_by_id( + &self, + message_id: u64, + ) -> CommitPersistResult>; + fn get_commit_status( + &self, + message_id: u64, + pubkey: &Pubkey, + ) -> CommitPersistResult>; + // fn finalize_l1_message() +} + +#[derive(Clone)] pub struct CommitPersister { - db: CommittorDb, - request_id_counter: AtomicU64, + db: Arc>, } impl CommitPersister { @@ -26,73 +46,45 @@ impl CommitPersister { let db = CommittorDb::new(db_file)?; db.create_commit_status_table()?; db.create_bundle_signature_table()?; - Ok(Self::for_db(db)) - } - fn for_db(db: CommittorDb) -> Self { - Self { - db, - request_id_counter: AtomicU64::new(1), - } + Ok(Self { + db: Arc::new(Mutex::new(db)) + }) } - /// Generates a unique request ID for a changeset - fn generate_reqid(&self) -> String { - let id = self.request_id_counter.fetch_add(1, Ordering::SeqCst); - format!("req-{}", id) - } - - pub fn start_changeset( - &mut self, - changeset: &Changeset, - ephemeral_blockhash: Hash, - finalize: bool, - ) -> CommitPersistResult { - let reqid = self.generate_reqid(); - - let mut commit_rows = Vec::new(); - - for (pubkey, changed_account) in changeset.accounts.iter() { - let undelegate = changeset.accounts_to_undelegate.contains(pubkey); - let commit_type = if changed_account.data().is_empty() { - CommitType::EmptyAccount - } else { - CommitType::DataAccount - }; - - let data = if commit_type == CommitType::DataAccount { - Some(changed_account.data().to_vec()) - } else { - None - }; - - let now = now(); - - // Create a commit status row for this account - let commit_row = CommitStatusRow { - reqid: reqid.clone(), - pubkey: *pubkey, - delegated_account_owner: changed_account.owner(), - slot: changeset.slot, - ephemeral_blockhash, - undelegate, - lamports: changed_account.lamports(), - finalize, - data, - commit_type, - created_at: now, - commit_status: CommitStatus::Pending, - last_retried_at: now, - retries_count: 0, - }; - - commit_rows.push(commit_row); - } + fn create_row(l1_message: &ScheduledL1Message) -> CommitPersistResult { + let undelegate = l1_message.accounts_to_undelegate.contains(pubkey); + let commit_type = if changed_account.data().is_empty() { + CommitType::EmptyAccount + } else { + CommitType::DataAccount + }; - // Insert all commit rows into the database - self.db.insert_commit_status_rows(&commit_rows)?; + let data = if commit_type == CommitType::DataAccount { + Some(changed_account.data().to_vec()) + } else { + None + }; - Ok(reqid) + let now = now(); + + // Create a commit status row for this account + let commit_row = CommitStatusRow { + reqid: reqid.clone(), + pubkey: *pubkey, + delegated_account_owner: changed_account.owner(), + slot: changeset.slot, + ephemeral_blockhash, + undelegate, + lamports: changed_account.lamports(), + finalize, + data, + commit_type, + created_at: now, + commit_status: CommitStatus::Pending, + last_retried_at: now, + retries_count: 0, + }; } pub fn update_status( @@ -129,27 +121,44 @@ impl CommitPersister { // TODO(thlorenz): @@ once we see this works remove the succeeded commits } +} - pub fn get_commit_statuses_by_reqid( + +impl CommitPersisterIface for CommitPersister { + fn start_l1_messages( &self, - reqid: &str, - ) -> CommitPersistResult> { - self.db.get_commit_statuses_by_reqid(reqid) + l1_message: &Vec, + ) -> CommitPersistResult<()> { + let commit_rows = l1_message.iter().map(Self::create_row).collect(); + // Insert all commit rows into the database + self.db.lock().expect(POISONED_MUTEX_MSG).insert_commit_status_rows(&commit_rows)?; + Ok(()) + } + + fn start_l1_message(&self, l1_message: &ScheduledL1Message) -> CommitPersistResult<()> { + let commit_row = Self::create_row(l1_message)?; + self.db.lock().expect(POISONED_MUTEX_MSG).insert_commit_status_rows(&[commit_row])?; + + Ok(()) + } + + fn update_status(&self, message_id: u64, status: CommitStatus) -> CommitPersistResult<()> { + } - pub fn get_commit_status( + fn get_commit_statuses_by_id( &self, - reqid: &str, - pubkey: &Pubkey, - ) -> CommitPersistResult> { - self.db.get_commit_status(reqid, pubkey) + message_id: u64, + ) -> CommitPersistResult> { + self.db.lock().expect(POISONED_MUTEX_MSG).get_commit_statuses_by_id(message_id) } - pub fn get_signature( + fn get_commit_status( &self, - bundle_id: u64, - ) -> CommitPersistResult> { - self.db.get_bundle_signature_by_bundle_id(bundle_id) + message_id: u64, + pubkey: &Pubkey, + ) -> CommitPersistResult> { + self.db.lock().expect(POISONED_MUTEX_MSG).get_commit_status(message_id, pubkey) } } @@ -203,7 +212,7 @@ mod tests { // Start tracking the changeset let blockhash = Hash::new_unique(); let reqid = persister - .start_changeset(&changeset, blockhash, true) + .start_l1_messages(&changeset, blockhash, true) .unwrap(); // Verify the rows were inserted correctly diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 47a36ca05..fa8d636ab 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -15,8 +15,8 @@ use super::{ #[derive(Debug, Clone, PartialEq, Eq)] pub struct CommitStatusRow { - /// Request ID that is common for some accounts - pub reqid: String, + /// ID of the message + pub message_id: u64, /// The on chain address of the delegated account pub pubkey: Pubkey, /// The original owner of the delegated account on chain @@ -29,8 +29,6 @@ pub struct CommitStatusRow { pub undelegate: bool, /// Lamports of the account in the ephemeral pub lamports: u64, - /// If `true` the account commit is finalized after it was processed - pub finalize: bool, /// The account data in the ephemeral (only set if the commit is for a data account) pub data: Option>, /// The type of commit that was requested, i.e. lamports only or including data @@ -49,19 +47,31 @@ pub struct CommitStatusRow { pub retries_count: u16, } +pub struct MessageSignatures { + /// The signature of the transaction on chain that processed the commit + pub processed_signature: Signature, + /// The signature of the transaction on chain that finalized the commit + /// if applicable + pub finalized_signature: Option, + /// The signature of the transaction on chain that undelegated the account(s) + /// if applicable + pub undelegate_signature: Option, + /// Time since epoch at which the bundle signature was created + pub created_at: u64, +} + impl fmt::Display for CommitStatusRow { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "CommitStatusRow {{ - reqid: {} + message_id: {} pubkey: {}, delegated_account_owner: {}, slot: {}, ephemeral_blockhash: {}, undelegate: {}, lamports: {}, - finalize: {}, data.len: {}, commit_type: {}, created_at: {}, @@ -69,14 +79,13 @@ impl fmt::Display for CommitStatusRow { last_retried_at: {}, retries_count: {} }}", - self.reqid, + self.message_id, self.pubkey, self.delegated_account_owner, self.slot, self.ephemeral_blockhash, self.undelegate, self.lamports, - self.finalize, self.data.as_ref().map(|x| x.len()).unwrap_or_default(), self.commit_type.as_str(), self.created_at, @@ -87,8 +96,8 @@ impl fmt::Display for CommitStatusRow { } } -const ALL_COMMIT_STATUS_COLUMNS: &str = r#" - reqid, +const ALL_COMMIT_STATUS_COLUMNS: &str = " + message_id, pubkey, delegated_account_owner, slot, @@ -107,93 +116,12 @@ const ALL_COMMIT_STATUS_COLUMNS: &str = r#" undelegated_signature, last_retried_at, retries_count -"#; +"; -const SELECT_ALL_COMMIT_STATUS_COLUMNS: &str = r#" -SELECT - reqid, - pubkey, - delegated_account_owner, - slot, - ephemeral_blockhash, - undelegate, - lamports, - finalize, - bundle_id, - data, - commit_type, - created_at, - commit_status, - commit_strategy, - processed_signature, - finalized_signature, - undelegated_signature, - last_retried_at, - retries_count -FROM commit_status -"#; -// ----------------- -// Bundle Signature -// ----------------- -// The BundleSignature table exists to store mappings from bundle_id to the signatures used -// to process/finalize these bundles. -// The signatures are repeated in the commit_status table, however the rows in there have a -// different lifetime than the bundle signature rows. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct BundleSignatureRow { - /// The id of the bundle that was commmitted - /// If an account was not part of a bundle it is treated as a single account bundle - /// for consistency. - /// The bundle_id is unique - pub bundle_id: u64, - /// The signature of the transaction on chain that processed the commit - pub processed_signature: Signature, - /// The signature of the transaction on chain that finalized the commit - /// if applicable - pub finalized_signature: Option, - /// The signature of the transaction on chain that undelegated the account(s) - /// if applicable - pub undelegate_signature: Option, - /// Time since epoch at which the bundle signature was created - pub created_at: u64, -} - -impl BundleSignatureRow { - pub fn new( - bundle_id: u64, - processed_signature: Signature, - finalized_signature: Option, - undelegate_signature: Option, - ) -> Self { - let created_at = now(); - Self { - bundle_id, - processed_signature, - finalized_signature, - undelegate_signature, - created_at, - } - } -} - -const ALL_BUNDLE_SIGNATURE_COLUMNS: &str = r#" - bundle_id, - processed_signature, - finalized_signature, - undelegate_signature, - created_at -"#; - -const SELECT_ALL_BUNDLE_SIGNATURE_COLUMNS: &str = r#" -SELECT - bundle_id, - processed_signature, - finalized_signature, - undelegate_signature, - created_at -FROM bundle_signature -"#; +const SELECT_ALL_COMMIT_STATUS_COLUMNS: &str = const { + concat!("SELECT", ALL_COMMIT_STATUS_COLUMNS, "FROM commit_status") +}; // ----------------- // CommittorDb @@ -218,19 +146,16 @@ impl CommittorDb { // ----------------- // Methods affecting both tables // ----------------- - pub fn update_commit_status_and_bundle_signature( + pub fn update_commit_status( &mut self, - reqid: &str, + message_id: u64, pubkey: &Pubkey, status: &CommitStatus, - bundle_signature: Option, ) -> CommitPersistResult<()> { let tx = self.conn.transaction()?; - Self::update_commit_status(&tx, reqid, pubkey, status)?; - if let Some(bundle_signature) = bundle_signature { - Self::insert_bundle_signature(&tx, &bundle_signature)?; - } + Self::update_commit_status_impl(&tx, message_id, pubkey, status)?; tx.commit()?; + Ok(()) } @@ -238,20 +163,17 @@ impl CommittorDb { // Commit Status // ----------------- pub fn create_commit_status_table(&self) -> Result<()> { - // The bundle_id is NULL when we insert a pending commit match self.conn.execute_batch( - " + " BEGIN; CREATE TABLE IF NOT EXISTS commit_status ( - reqid TEXT NOT NULL, + message_id INTEGER NOT NULL, pubkey TEXT NOT NULL, delegated_account_owner TEXT NOT NULL, slot INTEGER NOT NULL, ephemeral_blockhash TEXT NOT NULL, undelegate INTEGER NOT NULL, lamports INTEGER NOT NULL, - finalize INTEGER NOT NULL, - bundle_id INTEGER, data BLOB, commit_type TEXT NOT NULL, created_at INTEGER NOT NULL, @@ -261,10 +183,11 @@ impl CommittorDb { finalized_signature TEXT, undelegated_signature TEXT, last_retried_at INTEGER NOT NULL, - retries_count INTEGER NOT NULL + retries_count INTEGER NOT NULL, + PRIMARY KEY (message_id, pubkey) ); CREATE INDEX IF NOT EXISTS idx_commits_pubkey ON commit_status (pubkey); - CREATE INDEX IF NOT EXISTS idx_commits_reqid ON commit_status (reqid); + CREATE INDEX IF NOT EXISTS idx_commits_message_id ON commit_status (message_id); COMMIT;", ) { Ok(_) => Ok(()), @@ -306,14 +229,13 @@ impl CommittorDb { (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19)", ), params![ - commit.reqid, + commit.message_id, commit.pubkey.to_string(), commit.delegated_account_owner.to_string(), u64_into_i64(commit.slot), commit.ephemeral_blockhash.to_string(), if commit.undelegate { 1 } else { 0 }, u64_into_i64(commit.lamports), - if commit.finalize { 1 } else { 0 }, commit.commit_status.bundle_id().map(u64_into_i64), commit.data.as_deref(), commit.commit_type.as_str(), @@ -336,9 +258,9 @@ impl CommittorDb { Ok(()) } - fn update_commit_status( + fn update_commit_status_impl( tx: &Transaction<'_>, - reqid: &str, + message_id: u64, pubkey: &Pubkey, status: &CommitStatus, ) -> CommitPersistResult<()> { @@ -351,7 +273,7 @@ impl CommittorDb { finalized_signature = ?5, undelegated_signature = ?6 WHERE - pubkey = ?7 AND reqid = ?8"; + pubkey = ?7 AND message_id = ?8"; let stmt = &mut tx.prepare(query)?; stmt.execute(params![ status.as_str(), @@ -367,7 +289,7 @@ impl CommittorDb { .and_then(|s| s.undelegate_signature) .map(|s| s.to_string()), pubkey.to_string(), - reqid + message_id ])?; Ok(()) } @@ -385,114 +307,47 @@ impl CommittorDb { extract_committor_rows(&mut rows) } - pub(crate) fn get_commit_statuses_by_reqid( + pub(crate) fn get_commit_statuses_by_id( &self, - reqid: &str, + message_id: u64, ) -> CommitPersistResult> { let query = - format!("{SELECT_ALL_COMMIT_STATUS_COLUMNS} WHERE reqid = ?1"); + format!("{SELECT_ALL_COMMIT_STATUS_COLUMNS} WHERE message_id = ?1"); let stmt = &mut self.conn.prepare(&query)?; - let mut rows = stmt.query(params![reqid])?; + let mut rows = stmt.query(params![message_id])?; extract_committor_rows(&mut rows) } pub(crate) fn get_commit_status( &self, - reqid: &str, + message_id: u64, pubkey: &Pubkey, ) -> CommitPersistResult> { let query = format!( - "{SELECT_ALL_COMMIT_STATUS_COLUMNS} WHERE reqid = ?1 AND pubkey = ?2" + "{SELECT_ALL_COMMIT_STATUS_COLUMNS} WHERE message_id = ?1 AND pubkey = ?2" ); let stmt = &mut self.conn.prepare(&query)?; - let mut rows = stmt.query(params![reqid, pubkey.to_string()])?; + let mut rows = stmt.query(params![message_id, pubkey.to_string()])?; extract_committor_rows(&mut rows).map(|mut rows| rows.pop()) } - #[cfg(test)] - fn remove_commit_statuses_with_reqid( + pub fn remove_commit_statuses_with_id( &self, - reqid: &str, + message_id: u64, ) -> CommitPersistResult<()> { - let query = "DELETE FROM commit_status WHERE reqid = ?1"; + let query = "DELETE FROM commit_status WHERE message_id = ?1"; let stmt = &mut self.conn.prepare(query)?; - stmt.execute(params![reqid])?; - Ok(()) - } - - // ----------------- - // Bundle Signature - // ----------------- - pub fn create_bundle_signature_table(&self) -> Result<()> { - match self.conn.execute_batch( - " - BEGIN; - CREATE TABLE IF NOT EXISTS bundle_signature ( - bundle_id INTEGER NOT NULL PRIMARY KEY, - processed_signature TEXT NOT NULL, - finalized_signature TEXT, - undelegate_signature TEXT, - created_at INTEGER NOT NULL - ); - CREATE INDEX IF NOT EXISTS idx_bundle_signature ON bundle_signature (bundle_id); - COMMIT;", - ) { - Ok(_) => Ok(()), - Err(err) => { - eprintln!("Error creating bundle_signature table: {}", err); - Err(err) - } - } - } - - fn insert_bundle_signature( - tx: &Transaction<'_>, - bundle_signature: &BundleSignatureRow, - ) -> CommitPersistResult<()> { - let query = if bundle_signature.finalized_signature.is_some() { - format!("INSERT OR REPLACE INTO bundle_signature ({ALL_BUNDLE_SIGNATURE_COLUMNS}) - VALUES (?1, ?2, ?3, ?4, ?5)") - } else { - format!("INSERT OR IGNORE INTO bundle_signature ({ALL_BUNDLE_SIGNATURE_COLUMNS}) - VALUES (?1, ?2, ?3, ?4, ?5)") - }; - tx.execute( - &query, - params![ - bundle_signature.bundle_id, - bundle_signature.processed_signature.to_string(), - bundle_signature - .finalized_signature - .as_ref() - .map(|s| s.to_string()), - bundle_signature - .undelegate_signature - .as_ref() - .map(|s| s.to_string()), - u64_into_i64(bundle_signature.created_at) - ], - )?; + stmt.execute(params![message_id])?; Ok(()) } - pub fn get_bundle_signature_by_bundle_id( + pub fn get_signatures_by_id( &self, - bundle_id: u64, - ) -> CommitPersistResult> { - let query = format!( - "{SELECT_ALL_BUNDLE_SIGNATURE_COLUMNS} WHERE bundle_id = ?1" - ); - let stmt = &mut self.conn.prepare(&query)?; - let mut rows = stmt.query(params![bundle_id])?; - - if let Some(row) = rows.next()? { - let bundle_signature_row = extract_bundle_signature_row(row)?; - Ok(Some(bundle_signature_row)) - } else { - Ok(None) - } + message_id: u64 + ) -> CommitPersistResult { + todo!() } } @@ -513,7 +368,10 @@ fn extract_committor_rows( fn extract_committor_row( row: &rusqlite::Row, ) -> CommitPersistResult { - let reqid: String = row.get(0)?; + let message_id: u64 = { + let message_id: i64 = row.get(0)?; + i64_into_u64(message_id) + }; let pubkey = { let pubkey: String = row.get(1)?; @@ -543,46 +401,41 @@ fn extract_committor_row( i64_into_u64(lamports) }; - let finalize: bool = { - let finalize: u8 = row.get(7)?; - finalize == 1 - }; - let bundle_id: Option = { - let bundle_id: Option = row.get(8)?; + let bundle_id: Option = row.get(7)?; bundle_id.map(i64_into_u64) }; - let data: Option> = row.get(9)?; + let data: Option> = row.get(8)?; let commit_type = { - let commit_type: String = row.get(10)?; + let commit_type: String = row.get(9)?; CommitType::try_from(commit_type.as_str())? }; let created_at: u64 = { - let created_at: i64 = row.get(11)?; + let created_at: i64 = row.get(10)?; i64_into_u64(created_at) }; let commit_status = { - let commit_status: String = row.get(12)?; + let commit_status: String = row.get(11)?; let commit_strategy = { - let commit_strategy: String = row.get(13)?; + let commit_strategy: String = row.get(12)?; CommitStrategy::from(commit_strategy.as_str()) }; let processed_signature = { - let processed_signature: Option = row.get(14)?; + let processed_signature: Option = row.get(13)?; processed_signature .map(|s| Signature::from_str(s.as_str())) .transpose()? }; let finalized_signature = { - let finalized_signature: Option = row.get(15)?; + let finalized_signature: Option = row.get(14)?; finalized_signature .map(|s| Signature::from_str(s.as_str())) .transpose()? }; let undelegated_signature = { - let undelegated_signature: Option = row.get(16)?; + let undelegated_signature: Option = row.get(15)?; undelegated_signature .map(|s| Signature::from_str(s.as_str())) .transpose()? @@ -601,23 +454,22 @@ fn extract_committor_row( }; let last_retried_at: u64 = { - let last_retried_at: i64 = row.get(17)?; + let last_retried_at: i64 = row.get(16)?; i64_into_u64(last_retried_at) }; let retries_count: u16 = { - let retries_count: i64 = row.get(18)?; + let retries_count: i64 = row.get(17)?; retries_count.try_into().unwrap_or_default() }; Ok(CommitStatusRow { - reqid, + message_id, pubkey, delegated_account_owner, slot, ephemeral_blockhash, undelegate, lamports, - finalize, data, commit_type, created_at, @@ -627,45 +479,6 @@ fn extract_committor_row( }) } -// ----------------- -// Bundle Signature Helpers -// ----------------- -fn extract_bundle_signature_row( - row: &rusqlite::Row, -) -> CommitPersistResult { - let bundle_id: u64 = { - let bundle_id: i64 = row.get(0)?; - i64_into_u64(bundle_id) - }; - let processed_signature = { - let processed_signature: String = row.get(1)?; - Signature::from_str(processed_signature.as_str())? - }; - let finalized_signature = { - let finalized_signature: Option = row.get(2)?; - finalized_signature - .map(|s| Signature::from_str(s.as_str())) - .transpose()? - }; - let undelegate_signature = { - let undelegate_signature: Option = row.get(3)?; - undelegate_signature - .map(|s| Signature::from_str(s.as_str())) - .transpose()? - }; - let created_at: u64 = { - let created_at: i64 = row.get(4)?; - i64_into_u64(created_at) - }; - - Ok(BundleSignatureRow { - bundle_id, - processed_signature, - finalized_signature, - undelegate_signature, - created_at, - }) -} #[cfg(test)] mod test { @@ -674,23 +487,21 @@ mod test { fn setup_db() -> CommittorDb { let db = CommittorDb::new(":memory:").unwrap(); db.create_commit_status_table().unwrap(); - db.create_bundle_signature_table().unwrap(); db } // ----------------- // Commit Status // ----------------- - fn create_commit_status_row(reqid: &str) -> CommitStatusRow { + fn create_commit_status_row(message_id: u64) -> CommitStatusRow { CommitStatusRow { - reqid: reqid.to_string(), + message_id, pubkey: Pubkey::new_unique(), delegated_account_owner: Pubkey::new_unique(), slot: 100, ephemeral_blockhash: Hash::new_unique(), undelegate: false, lamports: 100, - finalize: true, data: None, commit_type: CommitType::EmptyAccount, created_at: 1000, @@ -703,14 +514,13 @@ mod test { #[test] fn test_round_trip_commit_status_rows() { let one_unbundled_commit_row_no_data = CommitStatusRow { - reqid: "req-123".to_string(), + message_id: 123, pubkey: Pubkey::new_unique(), delegated_account_owner: Pubkey::new_unique(), slot: 100, ephemeral_blockhash: Hash::new_unique(), undelegate: false, lamports: 100, - finalize: true, data: None, commit_type: CommitType::EmptyAccount, created_at: 1000, @@ -720,14 +530,13 @@ mod test { }; let two_bundled_commit_row_with_data = CommitStatusRow { - reqid: "req-123".to_string(), + message_id: 123, pubkey: Pubkey::new_unique(), delegated_account_owner: Pubkey::new_unique(), slot: 100, ephemeral_blockhash: Hash::new_unique(), undelegate: false, lamports: 2000, - finalize: true, data: Some(vec![1, 2, 3]), commit_type: CommitType::DataAccount, created_at: 1000, @@ -763,14 +572,14 @@ mod test { assert_eq!(two.len(), 1); assert_eq!(two[0], two_bundled_commit_row_with_data); - let by_reqid = db - .get_commit_statuses_by_reqid( - &one_unbundled_commit_row_no_data.reqid, + let by_message_id = db + .get_commit_statuses_by_id( + one_unbundled_commit_row_no_data.message_id, ) .unwrap(); - assert_eq!(by_reqid.len(), 2); + assert_eq!(by_message_id.len(), 2); assert_eq!( - by_reqid, + by_message_id, [ one_unbundled_commit_row_no_data, two_bundled_commit_row_with_data @@ -779,14 +588,14 @@ mod test { } #[test] - fn test_commits_with_reqid() { + fn test_commits_with_message_id() { let mut db = setup_db(); - const REQID_ONE: &str = "req-123"; - const REQID_TWO: &str = "req-456"; + const MESSAGE_ID_ONE: u64 = 123; + const MESSAGE_ID_TWO: u64 = 456; - let commit_row_one = create_commit_status_row(REQID_ONE); - let commit_row_one_other = create_commit_status_row(REQID_ONE); - let commit_row_two = create_commit_status_row(REQID_TWO); + let commit_row_one = create_commit_status_row(MESSAGE_ID_ONE); + let commit_row_one_other = create_commit_status_row(MESSAGE_ID_ONE); + let commit_row_two = create_commit_status_row(MESSAGE_ID_TWO); db.insert_commit_status_rows(&[ commit_row_one.clone(), commit_row_one_other.clone(), @@ -794,120 +603,33 @@ mod test { ]) .unwrap(); - let commits_one = db.get_commit_statuses_by_reqid(REQID_ONE).unwrap(); + let commits_one = db.get_commit_statuses_by_id(MESSAGE_ID_ONE).unwrap(); assert_eq!(commits_one.len(), 2); assert_eq!(commits_one[0], commit_row_one); assert_eq!(commits_one[1], commit_row_one_other); - let commits_two = db.get_commit_statuses_by_reqid(REQID_TWO).unwrap(); + let commits_two = db.get_commit_statuses_by_id(MESSAGE_ID_TWO).unwrap(); assert_eq!(commits_two.len(), 1); assert_eq!(commits_two[0], commit_row_two); - // Remove commits with REQID_ONE - db.remove_commit_statuses_with_reqid(REQID_ONE).unwrap(); + // Remove commits with MESSAGE_ID_ONE + db.remove_commit_statuses_with_id(MESSAGE_ID_ONE).unwrap(); let commits_one_after_removal = - db.get_commit_statuses_by_reqid(REQID_ONE).unwrap(); + db.get_commit_statuses_by_id(MESSAGE_ID_ONE).unwrap(); assert_eq!(commits_one_after_removal.len(), 0); let commits_two_after_removal = - db.get_commit_statuses_by_reqid(REQID_TWO).unwrap(); + db.get_commit_statuses_by_id(MESSAGE_ID_TWO).unwrap(); assert_eq!(commits_two_after_removal.len(), 1); } - // ----------------- - // Bundle Signature and Commit Status Updates - // ----------------- - fn create_bundle_signature_row( - commit_status: &CommitStatus, - ) -> Option { - commit_status - .bundle_id() - .map(|bundle_id| BundleSignatureRow { - bundle_id, - processed_signature: Signature::new_unique(), - finalized_signature: None, - undelegate_signature: None, - created_at: 1000, - }) - } - - #[test] - fn test_upsert_bundle_signature() { - let mut db = setup_db(); - - let process_only = - BundleSignatureRow::new(1, Signature::new_unique(), None, None); - let process_finalize_and_undelegate = BundleSignatureRow::new( - 2, - Signature::new_unique(), - Some(Signature::new_unique()), - Some(Signature::new_unique()), - ); - - // Add two rows, one with finalize and undelegate signatures - { - let tx = db.conn.transaction().unwrap(); - CommittorDb::insert_bundle_signature(&tx, &process_only).unwrap(); - CommittorDb::insert_bundle_signature( - &tx, - &process_finalize_and_undelegate, - ) - .unwrap(); - tx.commit().unwrap(); - } - - // Ensure we update with finalized and undelegate sigs - let process_now_with_finalize_and_undelegate = { - let tx = db.conn.transaction().unwrap(); - let process_now_with_finalize = BundleSignatureRow::new( - process_only.bundle_id, - process_finalize_and_undelegate.processed_signature, - Some(Signature::new_unique()), - Some(Signature::new_unique()), - ); - CommittorDb::insert_bundle_signature( - &tx, - &process_now_with_finalize, - ) - .unwrap(); - tx.commit().unwrap(); - - process_now_with_finalize - }; - assert_eq!( - db.get_bundle_signature_by_bundle_id(1).unwrap().unwrap(), - process_now_with_finalize_and_undelegate - ); - - // Ensure we don't erase finalized/undelegate sigs - { - let tx = db.conn.transaction().unwrap(); - let finalizes_now_only_process = BundleSignatureRow::new( - process_finalize_and_undelegate.bundle_id, - process_finalize_and_undelegate.processed_signature, - None, - None, - ); - CommittorDb::insert_bundle_signature( - &tx, - &finalizes_now_only_process, - ) - .unwrap(); - tx.commit().unwrap(); - } - assert_eq!( - db.get_bundle_signature_by_bundle_id(2).unwrap().unwrap(), - process_finalize_and_undelegate - ); - } - #[test] fn test_update_commit_status() { let mut db = setup_db(); - const REQID: &str = "req-123"; + const MESSAGE_ID: u64 = 123; - let failing_commit_row = create_commit_status_row(REQID); - let success_commit_row = create_commit_status_row(REQID); + let failing_commit_row = create_commit_status_row(MESSAGE_ID); + let success_commit_row = create_commit_status_row(MESSAGE_ID); db.insert_commit_status_rows(&[ failing_commit_row.clone(), success_commit_row.clone(), @@ -917,8 +639,8 @@ mod test { // Update the statuses let new_failing_status = CommitStatus::FailedProcess((22, CommitStrategy::FromBuffer, None)); - db.update_commit_status_and_bundle_signature( - &failing_commit_row.reqid, + db.update_commit_status( + failing_commit_row.message_id, &failing_commit_row.pubkey, &new_failing_status, None, @@ -931,31 +653,27 @@ mod test { }; let new_success_status = CommitStatus::Succeeded((33, CommitStrategy::Args, sigs)); - let success_signatures_row = - create_bundle_signature_row(&new_success_status); - let success_signatures = success_signatures_row.clone().unwrap(); - db.update_commit_status_and_bundle_signature( - &success_commit_row.reqid, + db.update_commit_status( + success_commit_row.message_id, &success_commit_row.pubkey, &new_success_status, - success_signatures_row, ) .unwrap(); // Verify the statuses were updated let failed_commit_row = db - .get_commit_status(REQID, &failing_commit_row.pubkey) + .get_commit_status(MESSAGE_ID, &failing_commit_row.pubkey) .unwrap() .unwrap(); assert_eq!(failed_commit_row.commit_status, new_failing_status); let succeeded_commit_row = db - .get_commit_status(REQID, &success_commit_row.pubkey) + .get_commit_status(MESSAGE_ID, &success_commit_row.pubkey) .unwrap() .unwrap(); assert_eq!(succeeded_commit_row.commit_status, new_success_status); let signature_row = - db.get_bundle_signature_by_bundle_id(33).unwrap().unwrap(); + db.get_signatures_by_id(33).unwrap().unwrap(); assert_eq!( signature_row.processed_signature, success_signatures.processed_signature, From 24a6360c4353a28c27aa097dc4344152d39fd530 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 18 Jul 2025 13:23:27 +0900 Subject: [PATCH 101/199] feat: Persistor keeps track per Action not per Message --- .../src/persist/commit_persister.rs | 250 +++++++++++------- .../src/persist/db.rs | 226 ++++++++++------ .../src/persist/mod.rs | 4 +- .../src/persist/types/commit_status.rs | 45 +--- .../src/persist/utils.rs | 1 + 5 files changed, 316 insertions(+), 210 deletions(-) diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 4e037d868..a054ccaf7 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -1,26 +1,45 @@ use std::{ path::Path, - sync::atomic::{AtomicU64, Ordering}, + sync::{Arc, Mutex}, }; -use std::sync::{Arc, Mutex}; + use magicblock_committor_program::Changeset; -use solana_sdk::{hash::Hash, pubkey::Pubkey}; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; +use solana_sdk::{hash::Hash, pubkey::Pubkey}; + use super::{ - db::{CommitStatusRow}, + db::CommitStatusRow, error::{CommitPersistError, CommitPersistResult}, utils::now, - CommitStatus, CommitType, CommittorDb, + CommitStatus, CommitType, CommittsDb, MessageSignatures, }; +use crate::utils::ScheduledMessageExt; const POISONED_MUTEX_MSG: &str = "Commitor Persister lock poisoned"; -/// Records lifespan pf commit -pub trait CommitPersisterIface: Send + Sync + Clone { +/// Records lifespan pf L1Message +pub trait L1MessagesPersisterIface: Send + Sync + Clone { /// Starts persisting L1Message - fn start_l1_messages(&self, l1_message: &ScheduledL1Message) -> CommitPersistResult<()>; - fn start_l1_message(&self, l1_message: &ScheduledL1Message) -> CommitPersistResult<()>; - fn update_status(&self, message_id: u64, status: CommitStatus) -> CommitPersistResult<()>; + fn start_l1_messages( + &self, + l1_message: &ScheduledL1Message, + ) -> CommitPersistResult<()>; + fn start_l1_message( + &self, + l1_message: &ScheduledL1Message, + ) -> CommitPersistResult<()>; + fn set_commit_id( + &self, + message_id: u64, + pubkey: &Pubkey, + commit_id: u64, + ) -> CommitPersistResult<()>; + fn update_status( + &self, + message_id: u64, + pubkey: &Pubkey, + status: CommitStatus, + ) -> CommitPersistResult<()>; fn get_commit_statuses_by_id( &self, message_id: u64, @@ -30,127 +49,146 @@ pub trait CommitPersisterIface: Send + Sync + Clone { message_id: u64, pubkey: &Pubkey, ) -> CommitPersistResult>; - // fn finalize_l1_message() + fn get_signatures( + &self, + commit_ud: u64, + ) -> CommitPersistResult>; + // fn finalize_l1_message(&self blockhash: Hash) -> CommitPersistResult<()>; } #[derive(Clone)] -pub struct CommitPersister { - db: Arc>, +pub struct L1MessagePersister { + // DB that tracks lifespan of Commit intents + commits_db: Arc>, + // TODO(edwin): something like + // actions_db: Arc> } -impl CommitPersister { +impl L1MessagePersister { pub fn try_new

(db_file: P) -> CommitPersistResult where P: AsRef, { - let db = CommittorDb::new(db_file)?; + let db = CommittsDb::new(db_file)?; db.create_commit_status_table()?; - db.create_bundle_signature_table()?; Ok(Self { - db: Arc::new(Mutex::new(db)) + commits_db: Arc::new(Mutex::new(db)), }) } - fn create_row(l1_message: &ScheduledL1Message) -> CommitPersistResult { - let undelegate = l1_message.accounts_to_undelegate.contains(pubkey); - let commit_type = if changed_account.data().is_empty() { - CommitType::EmptyAccount - } else { - CommitType::DataAccount - }; - - let data = if commit_type == CommitType::DataAccount { - Some(changed_account.data().to_vec()) - } else { - None - }; - - let now = now(); - - // Create a commit status row for this account - let commit_row = CommitStatusRow { - reqid: reqid.clone(), - pubkey: *pubkey, - delegated_account_owner: changed_account.owner(), - slot: changeset.slot, - ephemeral_blockhash, - undelegate, - lamports: changed_account.lamports(), - finalize, - data, - commit_type, - created_at: now, - commit_status: CommitStatus::Pending, - last_retried_at: now, - retries_count: 0, - }; - } - - pub fn update_status( - &mut self, - reqid: &str, - pubkey: &Pubkey, - status: CommitStatus, - ) -> Result<(), CommitPersistError> { - // NOTE: only Pending commits don't have a bundle id, but we should - // never update to Pending - let Some(bundle_id) = status.bundle_id() else { - return Err( - CommitPersistError::CommitStatusUpdateRequiresStatusWithBundleId( - status.as_str().to_string(), - ), - ); + fn create_commit_rows( + l1_message: &ScheduledL1Message, + ) -> Vec { + let Some(committed_accounts) = l1_message.get_committed_accounts() + else { + // We don't persist standalone actions + return vec![]; }; - let bundle_signature = status.signatures().map(|sigs| { - BundleSignatureRow::new( - bundle_id, - sigs.process_signature, - sigs.finalize_signature, - sigs.undelegate_signature, - ) - }); - - self.db.update_commit_status_and_bundle_signature( - reqid, - pubkey, - &status, - bundle_signature, - ) - - // TODO(thlorenz): @@ once we see this works remove the succeeded commits + let undelegate = l1_message.is_undelegate(); + let created_at = now(); + committed_accounts + .iter() + .map(|account| { + let data = &account.account.data; + let commit_type = if data.is_empty() { + CommitType::EmptyAccount + } else { + CommitType::DataAccount + }; + + let data = if commit_type == CommitType::DataAccount { + Some(data.clone()) + } else { + None + }; + + // Create a commit status row for this account + CommitStatusRow { + message_id: l1_message.id, + commit_id: 0, // Not known at creation, set later + pubkey: *account.pubkey, + delegated_account_owner: account.account.owner, + slot: l1_message.slot, + ephemeral_blockhash: l1_message.blockhash, + undelegate, + lamports: account.account.lamports, + data, + commit_type, + created_at, + commit_status: CommitStatus::Pending, + last_retried_at: created_at, + retries_count: 0, + } + }) + .collect() } } - -impl CommitPersisterIface for CommitPersister { +impl L1MessagesPersisterIface for L1MessagePersister { fn start_l1_messages( &self, l1_message: &Vec, ) -> CommitPersistResult<()> { - let commit_rows = l1_message.iter().map(Self::create_row).collect(); + let commit_rows = l1_message + .iter() + .map(Self::create_commit_rows) + .flatten() + .collect::>(); // Insert all commit rows into the database - self.db.lock().expect(POISONED_MUTEX_MSG).insert_commit_status_rows(&commit_rows)?; + self.commits_db + .lock() + .expect(POISONED_MUTEX_MSG) + .insert_commit_status_rows(&commit_rows)?; Ok(()) } - fn start_l1_message(&self, l1_message: &ScheduledL1Message) -> CommitPersistResult<()> { - let commit_row = Self::create_row(l1_message)?; - self.db.lock().expect(POISONED_MUTEX_MSG).insert_commit_status_rows(&[commit_row])?; + fn start_l1_message( + &self, + l1_message: &ScheduledL1Message, + ) -> CommitPersistResult<()> { + let commit_row = Self::create_commit_rows(l1_message); + self.commits_db + .lock() + .expect(POISONED_MUTEX_MSG) + .insert_commit_status_rows(&commit_row)?; Ok(()) } - fn update_status(&self, message_id: u64, status: CommitStatus) -> CommitPersistResult<()> { + fn set_commit_id( + &self, + message_id: u64, + pubkey: &Pubkey, + commit_id: u64, + ) -> CommitPersistResult<()> { + self.commits_db + .lock() + .expect(POISONED_MUTEX_MSG) + .set_commit_id(message_id, pubkey, commit_id) + } + fn update_status( + &self, + message_id: u64, + pubkey: &Pubkey, + status: CommitStatus, + ) -> CommitPersistResult<()> { + self.commits_db + .lock() + .expect(POISONED_MUTEX_MSG) + .update_commit_status(message_id, pubkey, &status) } fn get_commit_statuses_by_id( &self, message_id: u64, ) -> CommitPersistResult> { - self.db.lock().expect(POISONED_MUTEX_MSG).get_commit_statuses_by_id(message_id) + self.commits_db + .lock() + .expect(POISONED_MUTEX_MSG) + .get_commit_statuses_by_id(message_id) } fn get_commit_status( @@ -158,8 +196,25 @@ impl CommitPersisterIface for CommitPersister { message_id: u64, pubkey: &Pubkey, ) -> CommitPersistResult> { - self.db.lock().expect(POISONED_MUTEX_MSG).get_commit_status(message_id, pubkey) + self.commits_db + .lock() + .expect(POISONED_MUTEX_MSG) + .get_commit_status(message_id, pubkey) } + + fn get_signatures( + &self, + commit_ud: u64, + ) -> CommitPersistResult> { + self.commits_db + .lock() + .expect(POISONED_MUTEX_MSG) + .get_signatures(commit_ud) + } + + // fn finalize_l1_message(&self, blockhash: Hash) -> CommitPersistResult<()> { + // self.db.lock().expect(POISONED_MUTEX_MSG). + // } } #[cfg(test)] @@ -173,7 +228,7 @@ mod tests { #[test] fn test_start_changeset_and_update_status() { - let mut persister = CommitPersister::try_new(":memory:").unwrap(); + let mut persister = L1MessagePersister::try_new(":memory:").unwrap(); // Create a test changeset let mut changeset = Changeset { @@ -216,7 +271,10 @@ mod tests { .unwrap(); // Verify the rows were inserted correctly - let rows = persister.db.get_commit_statuses_by_reqid(&reqid).unwrap(); + let rows = persister + .commits_db + .get_commit_statuses_by_reqid(&reqid) + .unwrap(); assert_eq!(rows.len(), 2); let empty_account_row = @@ -258,7 +316,7 @@ mod tests { assert_eq!(updated_row.commit_status, new_status); let signatures = persister - .get_signature(new_status.bundle_id().unwrap()) + .get_signatures(new_status.bundle_id().unwrap()) .unwrap() .unwrap(); assert_eq!(signatures.processed_signature, process_signature); diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index fa8d636ab..2c50cc630 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -9,16 +9,19 @@ use super::{ utils::{i64_into_u64, now, u64_into_i64}, CommitStatus, CommitStatusSignatures, CommitStrategy, CommitType, }; + // ----------------- // CommitStatusRow // ----------------- - #[derive(Debug, Clone, PartialEq, Eq)] pub struct CommitStatusRow { - /// ID of the message + /// ID of the messages within which this account is committed pub message_id: u64, /// The on chain address of the delegated account pub pubkey: Pubkey, + /// Commit ID of an account + /// Determined and set during runtime + pub commit_id: u64, /// The original owner of the delegated account on chain pub delegated_account_owner: Pubkey, /// The ephemeral slot at which those changes were requested @@ -67,6 +70,7 @@ impl fmt::Display for CommitStatusRow { "CommitStatusRow {{ message_id: {} pubkey: {}, + commit_id: {}, delegated_account_owner: {}, slot: {}, ephemeral_blockhash: {}, @@ -81,6 +85,7 @@ impl fmt::Display for CommitStatusRow { }}", self.message_id, self.pubkey, + self.commit_id, self.delegated_account_owner, self.slot, self.ephemeral_blockhash, @@ -97,28 +102,26 @@ impl fmt::Display for CommitStatusRow { } const ALL_COMMIT_STATUS_COLUMNS: &str = " - message_id, - pubkey, - delegated_account_owner, - slot, - ephemeral_blockhash, - undelegate, - lamports, - finalize, - bundle_id, - data, - commit_type, - created_at, - commit_status, - commit_strategy, - processed_signature, - finalized_signature, - undelegated_signature, - last_retried_at, - retries_count + message_id, // 1 + pubkey, // 2 + commit_id, // 3 + delegated_account_owner, // 4 + slot, // 5 + ephemeral_blockhash, // 6 + undelegate, // 7 + lamports, // 8 + data, // 9 + commit_type, // 10 + created_at, // 11 + commit_status, // 12 + commit_strategy, // 13 + processed_signature, // 14 + finalized_signature, // 15 + undelegated_signature, // 16 + last_retried_at, // 17 + retries_count // 18 "; - const SELECT_ALL_COMMIT_STATUS_COLUMNS: &str = const { concat!("SELECT", ALL_COMMIT_STATUS_COLUMNS, "FROM commit_status") }; @@ -126,11 +129,11 @@ const SELECT_ALL_COMMIT_STATUS_COLUMNS: &str = const { // ----------------- // CommittorDb // ----------------- -pub struct CommittorDb { +pub struct CommittsDb { conn: Connection, } -impl CommittorDb { +impl CommittsDb { pub fn new

(db_file: P) -> Result where P: AsRef, @@ -159,6 +162,24 @@ impl CommittorDb { Ok(()) } + pub fn set_commit_id( + &mut self, + message_id: u64, + pubkey: &Pubkey, + commit_id: u64, + ) -> CommitPersistResult<()> { + let query = "UPDATE commit_status + SET + commit_id = ?1, + WHERE + pubkey = ?2 AND message_id = ?3"; + let tx = self.conn.transaction()?; + let stmt = &mut tx.prepare(query)?; + stmt.execute(params![commit_id, pubkey.to_string(), message_id])?; + + Ok(()) + } + // ----------------- // Commit Status // ----------------- @@ -167,8 +188,9 @@ impl CommittorDb { " BEGIN; CREATE TABLE IF NOT EXISTS commit_status ( - message_id INTEGER NOT NULL, + message_id INTEGER NOT NULL, pubkey TEXT NOT NULL, + commit_id INTEGER NOT NULL, delegated_account_owner TEXT NOT NULL, slot INTEGER NOT NULL, ephemeral_blockhash TEXT NOT NULL, @@ -202,6 +224,10 @@ impl CommittorDb { &mut self, commit_rows: &[CommitStatusRow], ) -> CommitPersistResult<()> { + if commit_rows.is_empty() { + return Ok(()); + } + let tx = self.conn.transaction()?; for commit in commit_rows { Self::insert_commit_status_row(&tx, commit)?; @@ -226,34 +252,34 @@ impl CommittorDb { tx.execute( &format!( "INSERT INTO commit_status ({ALL_COMMIT_STATUS_COLUMNS}) VALUES - (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19)", + (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18)", ), params![ - commit.message_id, - commit.pubkey.to_string(), - commit.delegated_account_owner.to_string(), - u64_into_i64(commit.slot), - commit.ephemeral_blockhash.to_string(), - if commit.undelegate { 1 } else { 0 }, - u64_into_i64(commit.lamports), - commit.commit_status.bundle_id().map(u64_into_i64), - commit.data.as_deref(), - commit.commit_type.as_str(), - u64_into_i64(commit.created_at), - commit.commit_status.as_str(), - commit.commit_status.commit_strategy().as_str(), - processed_signature - .as_ref() - .map(|s| s.to_string()), - finalized_signature - .as_ref() - .map(|s| s.to_string()), - undelegated_signature - .as_ref() - .map(|s| s.to_string()), - u64_into_i64(commit.last_retried_at), - commit.retries_count, - ], + commit.message_id, + commit.pubkey.to_string(), + commit.commit_id, + commit.delegated_account_owner.to_string(), + u64_into_i64(commit.slot), + commit.ephemeral_blockhash.to_string(), + if commit.undelegate { 1 } else { 0 }, + u64_into_i64(commit.lamports), + commit.data.as_deref(), + commit.commit_type.as_str(), + u64_into_i64(commit.created_at), + commit.commit_status.as_str(), + commit.commit_status.commit_strategy().as_str(), + processed_signature + .as_ref() + .map(|s| s.to_string()), + finalized_signature + .as_ref() + .map(|s| s.to_string()), + undelegated_signature + .as_ref() + .map(|s| s.to_string()), + u64_into_i64(commit.last_retried_at), + commit.retries_count, + ], )?; Ok(()) } @@ -267,7 +293,6 @@ impl CommittorDb { let query = "UPDATE commit_status SET commit_status = ?1, - bundle_id = ?2, commit_strategy = ?3, processed_signature = ?4, finalized_signature = ?5, @@ -277,7 +302,6 @@ impl CommittorDb { let stmt = &mut tx.prepare(query)?; stmt.execute(params![ status.as_str(), - status.bundle_id(), status.commit_strategy().as_str(), status.signatures().map(|s| s.process_signature.to_string()), status @@ -343,11 +367,43 @@ impl CommittorDb { Ok(()) } - pub fn get_signatures_by_id( + pub fn get_signatures( &self, - message_id: u64 - ) -> CommitPersistResult { - todo!() + commit_id: u64, + ) -> CommitPersistResult> { + let query = "SELECT + processed_signature, finalized_signature, undelegated_signature, created_at + FROM commit_status + WHERE commit_id = ?1 + LIMIT 1"; + + let mut stmt = self.conn.prepare(&query)?; + let mut rows = stmt.query(params![commit_id])?; + + let result = rows + .next()? + .map(|row| { + let processed_signature: String = row.get(0)?; + let finalized_signature: Option = row.get(1)?; + let undelegated_signature: Option = row.get(2)?; + let created_at: i64 = row.get(3)?; + + Ok(MessageSignatures { + processed_signature: Signature::from_str( + &processed_signature, + )?, + finalized_signature: finalized_signature + .map(|s| Signature::from_str(&s)) + .transpose()?, + undelegate_signature: undelegated_signature + .map(|s| Signature::from_str(&s)) + .transpose()?, + created_at: i64_into_u64(created_at), + }) + }) + .transpose()?; + + Ok(result) } } @@ -377,35 +433,34 @@ fn extract_committor_row( let pubkey: String = row.get(1)?; Pubkey::try_from(pubkey.as_str())? }; + let commit_id = { + let message_id: i64 = row.get(2)?; + i64_into_u64(message_id) + }; let delegated_account_owner = { - let delegated_account_owner: String = row.get(2)?; + let delegated_account_owner: String = row.get(3)?; Pubkey::try_from(delegated_account_owner.as_str())? }; let slot: Slot = { - let slot: i64 = row.get(3)?; + let slot: i64 = row.get(4)?; i64_into_u64(slot) }; let ephemeral_blockhash = { - let ephemeral_blockhash: String = row.get(4)?; + let ephemeral_blockhash: String = row.get(5)?; Hash::from_str(ephemeral_blockhash.as_str())? }; let undelegate: bool = { - let undelegate: u8 = row.get(5)?; + let undelegate: u8 = row.get(6)?; undelegate == 1 }; let lamports: u64 = { - let lamports: i64 = row.get(6)?; + let lamports: i64 = row.get(7)?; i64_into_u64(lamports) }; - let bundle_id: Option = { - let bundle_id: Option = row.get(7)?; - bundle_id.map(i64_into_u64) - }; - let data: Option> = row.get(8)?; let commit_type = { @@ -445,12 +500,7 @@ fn extract_committor_row( finalize_signature: finalized_signature, undelegate_signature: undelegated_signature, }); - CommitStatus::try_from(( - commit_status.as_str(), - bundle_id, - commit_strategy, - sigs, - ))? + CommitStatus::try_from((commit_status.as_str(), commit_strategy, sigs))? }; let last_retried_at: u64 = { @@ -465,6 +515,7 @@ fn extract_committor_row( Ok(CommitStatusRow { message_id, pubkey, + commit_id, delegated_account_owner, slot, ephemeral_blockhash, @@ -479,13 +530,12 @@ fn extract_committor_row( }) } - #[cfg(test)] mod test { use super::*; - fn setup_db() -> CommittorDb { - let db = CommittorDb::new(":memory:").unwrap(); + fn setup_db() -> CommittsDb { + let db = CommittsDb::new(":memory:").unwrap(); db.create_commit_status_table().unwrap(); db } @@ -496,6 +546,7 @@ mod test { fn create_commit_status_row(message_id: u64) -> CommitStatusRow { CommitStatusRow { message_id, + commit_id: 0, pubkey: Pubkey::new_unique(), delegated_account_owner: Pubkey::new_unique(), slot: 100, @@ -515,6 +566,7 @@ mod test { fn test_round_trip_commit_status_rows() { let one_unbundled_commit_row_no_data = CommitStatusRow { message_id: 123, + commit_id: 0, pubkey: Pubkey::new_unique(), delegated_account_owner: Pubkey::new_unique(), slot: 100, @@ -531,6 +583,7 @@ mod test { let two_bundled_commit_row_with_data = CommitStatusRow { message_id: 123, + commit_id: 0, pubkey: Pubkey::new_unique(), delegated_account_owner: Pubkey::new_unique(), slot: 100, @@ -587,6 +640,19 @@ mod test { ); } + fn create_message_signature_row( + commit_status: &CommitStatus, + ) -> Option { + commit_status + .bundle_id() + .map(|bundle_id| MessageSignatures { + processed_signature: Signature::new_unique(), + finalized_signature: None, + undelegate_signature: None, + created_at: 1000, + }) + } + #[test] fn test_commits_with_message_id() { let mut db = setup_db(); @@ -596,6 +662,7 @@ mod test { let commit_row_one = create_commit_status_row(MESSAGE_ID_ONE); let commit_row_one_other = create_commit_status_row(MESSAGE_ID_ONE); let commit_row_two = create_commit_status_row(MESSAGE_ID_TWO); + db.insert_commit_status_rows(&[ commit_row_one.clone(), commit_row_one_other.clone(), @@ -643,7 +710,6 @@ mod test { failing_commit_row.message_id, &failing_commit_row.pubkey, &new_failing_status, - None, ) .unwrap(); let sigs = CommitStatusSignatures { @@ -653,6 +719,9 @@ mod test { }; let new_success_status = CommitStatus::Succeeded((33, CommitStrategy::Args, sigs)); + let success_signatures_row = + create_message_signature_row(&new_success_status); + let success_signatures = success_signatures_row.clone().unwrap(); db.update_commit_status( success_commit_row.message_id, &success_commit_row.pubkey, @@ -672,8 +741,7 @@ mod test { .unwrap() .unwrap(); assert_eq!(succeeded_commit_row.commit_status, new_success_status); - let signature_row = - db.get_signatures_by_id(33).unwrap().unwrap(); + let signature_row = db.get_signatures(33).unwrap().unwrap(); assert_eq!( signature_row.processed_signature, success_signatures.processed_signature, diff --git a/magicblock-committor-service/src/persist/mod.rs b/magicblock-committor-service/src/persist/mod.rs index 21a9005a0..ece2dda1b 100644 --- a/magicblock-committor-service/src/persist/mod.rs +++ b/magicblock-committor-service/src/persist/mod.rs @@ -4,8 +4,8 @@ pub mod error; mod types; mod utils; -pub use commit_persister::CommitPersister; -pub use db::{BundleSignatureRow, CommitStatusRow, CommittorDb}; +pub use commit_persister::L1MessagePersister; +pub use db::{CommitStatusRow, CommittsDb, MessageSignatures}; pub use types::{ CommitStatus, CommitStatusSignatures, CommitStrategy, CommitType, }; diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index e6964ecce..baba23f50 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -100,48 +100,27 @@ impl fmt::Display for CommitStatus { } } -impl - TryFrom<( - &str, - Option, - CommitStrategy, - Option, - )> for CommitStatus +impl TryFrom<(&str, CommitStrategy, Option)> + for CommitStatus { type Error = CommitPersistError; fn try_from( - (status, bundle_id, strategy, sigs): ( + (status, strategy, sigs): ( &str, - Option, CommitStrategy, Option, ), ) -> Result { - macro_rules! get_bundle_id { - () => { - if let Some(bundle_id) = bundle_id { - bundle_id - } else { - return Err(CommitPersistError::CommitStatusNeedsBundleId( - status.to_string(), - )); - } - }; - } - macro_rules! get_sigs { - () => { - if let Some(sigs) = sigs { - sigs - } else { - return Err( - CommitPersistError::CommitStatusNeedsSignatures( - status.to_string(), - ), - ); - } - }; - } + let get_sigs = || { + if let Some(sigs) = sigs { + Ok(sigs) + } else { + return Err(CommitPersistError::CommitStatusNeedsSignatures( + status.to_string(), + )); + } + }; use CommitStatus::*; match status { diff --git a/magicblock-committor-service/src/persist/utils.rs b/magicblock-committor-service/src/persist/utils.rs index d5c3aaf63..b1040d90f 100644 --- a/magicblock-committor-service/src/persist/utils.rs +++ b/magicblock-committor-service/src/persist/utils.rs @@ -3,6 +3,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; /// Fits a u64 into an i64, by mapping the range [0, i64::MAX] to itself, and /// mapping the range [i64::MAX + 1, u64::MAX - 1] into the negative range of i64. /// NOTE: this fails for u64::MAX +/// TODO(edwin): just store bit-copy in i64 pub(crate) fn u64_into_i64(n: u64) -> i64 { if n > i64::MAX as u64 { -((n - i64::MAX as u64) as i64) From 7f6dd79b7a6e2ebda477728d6500a54750383719 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 18 Jul 2025 15:51:08 +0900 Subject: [PATCH 102/199] fix: compilation --- .../src/remote_scheduled_commits_worker.rs | 5 +- magicblock-committor-service/CHANGES.md | 3 + .../src/commit/committor_processor.rs | 124 ++++++------------ .../src/commit/process_buffers.rs | 11 +- .../src/commit_scheduler.rs | 15 ++- .../src/commit_scheduler/commit_id_tracker.rs | 7 +- .../commit_scheduler_inner.rs | 22 ++-- .../commit_scheduler_worker.rs | 72 +++++++--- .../src/commit_scheduler/db.rs | 10 +- .../src/commit_scheduler/executor_pool.rs | 38 ------ .../src/l1_message_executor.rs | 77 +++++------ .../src/persist/commit_persister.rs | 11 +- .../src/persist/db.rs | 13 +- .../src/persist/mod.rs | 2 +- .../src/persist/types/commit_status.rs | 29 ++-- magicblock-committor-service/src/service.rs | 31 +++-- .../src/stubs/changeset_committor_stub.rs | 8 +- .../delivery_preparator.rs | 2 +- .../transaction_preparator.rs | 13 +- .../src/transactions.rs | 21 +-- magicblock-committor-service/src/utils.rs | 17 ++- .../schedule_l1_message_processor.rs | 4 +- 22 files changed, 253 insertions(+), 282 deletions(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_worker.rs b/magicblock-accounts/src/remote_scheduled_commits_worker.rs index 2948cc3fd..00fb7c414 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_worker.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_worker.rs @@ -6,7 +6,7 @@ use std::{ use log::{debug, error}; use magicblock_bank::bank::Bank; use magicblock_committor_service::{ - persist::BundleSignatureRow, ChangesetMeta, L1MessageCommittor, + persist::MessageSignatures, ChangesetMeta, L1MessageCommittor, }; use magicblock_processor::execute_transaction::execute_legacy_transaction; use magicblock_program::{ @@ -39,6 +39,7 @@ impl RemoteScheduledCommitsWorker { } } + // TODO(edwin): maybe not needed pub async fn start(mut self) { while let Some(l1_messages) = self.message_receiver.recv().await { let metadata = ChangesetMeta::from(&l1_messages); @@ -97,7 +98,7 @@ impl RemoteScheduledCommitsWorker { } }; match bundle_signatures { - Some(BundleSignatureRow { + Some(MessageSignatures { processed_signature, finalized_signature, bundle_id, diff --git a/magicblock-committor-service/CHANGES.md b/magicblock-committor-service/CHANGES.md index e69de29bb..114e68bcd 100644 --- a/magicblock-committor-service/CHANGES.md +++ b/magicblock-committor-service/CHANGES.md @@ -0,0 +1,3 @@ +- Persister changed from reqid & bundle_id format to message_id. Meaning row created per message. A particular Row tracking lifespan of Intent +- Persister will be passed along into Executors & Scheduler for them to update Intent statuses during execution +- No notion of bundles anymore, we represent things by Intent id \ No newline at end of file diff --git a/magicblock-committor-service/src/commit/committor_processor.rs b/magicblock-committor-service/src/commit/committor_processor.rs index 0bf436555..e8d125844 100644 --- a/magicblock-committor-service/src/commit/committor_processor.rs +++ b/magicblock-committor-service/src/commit/committor_processor.rs @@ -22,12 +22,14 @@ use tokio::task::JoinSet; use super::common::{lookup_table_keys, send_and_confirm}; use crate::{ + commit_scheduler::{db::DummyDB, CommitScheduler}, commit_stage::CommitStage, compute_budget::{ComputeBudget, ComputeBudgetConfig}, config::ChainConfig, error::CommittorServiceResult, persist::{ - BundleSignatureRow, CommitPersister, CommitStatusRow, CommitStrategy, + CommitStatusRow, CommitStrategy, L1MessagePersister, + L1MessagesPersisterIface, MessageSignatures, }, pubkeys_provider::provide_committee_pubkeys, types::{InstructionsForCommitable, InstructionsKind}, @@ -38,20 +40,9 @@ pub(crate) struct CommittorProcessor { pub(crate) magicblock_rpc_client: MagicblockRpcClient, pub(crate) table_mania: TableMania, pub(crate) authority: Keypair, - pub(crate) persister: Arc>, - pub(crate) compute_budget_config: Arc, -} - -impl Clone for CommittorProcessor { - fn clone(&self) -> Self { - Self { - magicblock_rpc_client: self.magicblock_rpc_client.clone(), - table_mania: self.table_mania.clone(), - authority: self.authority.insecure_clone(), - persister: self.persister.clone(), - compute_budget_config: self.compute_budget_config.clone(), - } - } + pub(crate) compute_budget_config: ComputeBudgetConfig, + persister: L1MessagePersister, + commits_scheduler: CommitScheduler, } impl CommittorProcessor { @@ -71,19 +62,34 @@ impl CommittorProcessor { ); let rpc_client = Arc::new(rpc_client); let magic_block_rpc_client = MagicblockRpcClient::new(rpc_client); + + // Create TableMania let gc_config = GarbageCollectorConfig::default(); let table_mania = TableMania::new( magic_block_rpc_client.clone(), &authority, Some(gc_config), ); - let persister = CommitPersister::try_new(persist_file)?; + + // Create commit persister + let persister = L1MessagePersister::try_new(persist_file)?; + + // Create commit scheduler + let commits_scheduler = CommitScheduler::new( + magic_block_rpc_client.clone(), + DummyDB::new(), + persister.clone(), + table_mania.clone(), + chain_config.compute_budget_config.clone(), + ); + Ok(Self { authority, magicblock_rpc_client: magic_block_rpc_client, table_mania, - persister: Arc::new(Mutex::new(persister)), - compute_budget_config: Arc::new(chain_config.compute_budget_config), + commits_scheduler, + persister, + compute_budget_config: chain_config.compute_budget_config, }) } @@ -115,85 +121,39 @@ impl CommittorProcessor { pub fn get_commit_statuses( &self, - reqid: &str, + message_id: u64, ) -> CommittorServiceResult> { - let commit_statuses = self - .persister - .lock() - .expect("persister mutex poisoned") - .get_commit_statuses_by_reqid(reqid)?; + let commit_statuses = + self.persister.get_commit_statuses_by_id(message_id)?; Ok(commit_statuses) } pub fn get_signature( &self, - bundle_id: u64, - ) -> CommittorServiceResult> { - let signatures = self - .persister - .lock() - .expect("persister mutex poisoned") - .get_signature(bundle_id)?; + commit_id: u64, + ) -> CommittorServiceResult> { + let signatures = self.persister.get_signatures(commit_id)?; Ok(signatures) } pub async fn commit_l1_messages( &self, l1_messages: Vec, - ) -> Option { - let reqid = match self - .persister - .lock() - .expect("persister mutex poisoned") - .start_changeset(&l1_messages) - { - Ok(id) => Some(id), - Err(err) => { - // We will still try to perform the commits, but the fact that we cannot - // persist the intent is very serious and we should probably restart the - // valiator - error!( - "DB EXCEPTION: Failed to persist changeset to be committed: {:?}", - err - ); - None - } + ) { + if let Err(err) = self.persister.start_l1_messages(&l1_messages) { + // We will still try to perform the commits, but the fact that we cannot + // persist the intent is very serious and we should probably restart the + // valiator + error!( + "DB EXCEPTION: Failed to persist changeset to be committed: {:?}", + err + ); }; - let commit_stages = self - .process_commit_changeset(changeset, finalize, ephemeral_blockhash) - .await; - // Release pubkeys related to all undelegated accounts from the lookup tables - let releaseable_pubkeys = commit_stages - .iter() - .filter(|x| CommitStage::is_successfully_undelegated(x)) - .flat_map(|x| { - provide_committee_pubkeys(&x.pubkey(), owners.get(&x.pubkey())) - }) - .collect::>(); - self.table_mania.release_pubkeys(&releaseable_pubkeys).await; - - if let Some(reqid) = &reqid { - for stage in commit_stages { - let _ = self.persister - .lock() - .expect("persister mutex poisoned") - .update_status( - reqid, - &stage.pubkey(), - stage.commit_status(), - ).map_err(|err| { - // We log the error here, but there is nothing we can do if we encounter - // a db issue. - error!( - "DB EXCEPTION: Failed to update status of changeset {}: {:?}", - reqid, err - ); - }); - } + if let Err(err) = self.commits_scheduler.schedule(l1_messages).await { + error!("Failed to schedule L1 message: {}", err); + // TODO(edwin): handle } - - reqid } pub(crate) async fn process_ixs_chunks( diff --git a/magicblock-committor-service/src/commit/process_buffers.rs b/magicblock-committor-service/src/commit/process_buffers.rs index 542c4c3f7..ea3ff5acb 100644 --- a/magicblock-committor-service/src/commit/process_buffers.rs +++ b/magicblock-committor-service/src/commit/process_buffers.rs @@ -66,17 +66,12 @@ fn close_buffers_separate_ix( commit_info: CommitInfo, ) -> InstructionsForCommitable { debug!("Processing commitable: {:?}", commit_info); - let CommitInfo::BufferedDataAccount { - pubkey, - ephemeral_blockhash, - .. - } = &commit_info - else { + let CommitInfo::BufferedDataAccount { pubkey, .. } = &commit_info else { panic!("Only data accounts are supported for now"); }; - let close_ix = - close_buffers_ix(validator_auth, pubkey, ephemeral_blockhash); + // TODO(edwin)L fix commit_id + let close_ix = close_buffers_ix(validator_auth, pubkey, 0); InstructionsForCommitable { instructions: vec![close_ix], commit_info, diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index 0350727fe..15d48da7a 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -1,7 +1,7 @@ mod commit_id_tracker; pub(crate) mod commit_scheduler_inner; mod commit_scheduler_worker; -mod db; +pub(crate) mod db; // TODO(edwin): define visibility mod executor_pool; use std::sync::Arc; @@ -13,23 +13,27 @@ use tokio::sync::{broadcast, mpsc, mpsc::error::TrySendError}; use crate::{ commit_scheduler::{ - commit_scheduler_worker::CommitSchedulerWorker, db::DB, + commit_scheduler_worker::{ + BroadcasteddMessageExecutionResult, CommitSchedulerWorker, + }, + db::DB, }, l1_message_executor::{ExecutionOutput, MessageExecutorResult}, + persist::L1MessagesPersisterIface, ComputeBudgetConfig, }; pub struct CommitScheduler { db: Arc, - result_receiver: - broadcast::Receiver>, + result_receiver: broadcast::Receiver, message_sender: mpsc::Sender, } impl CommitScheduler { - pub fn new( + pub fn new( rpc_client: MagicblockRpcClient, db: D, + l1_message_persister: P, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, ) -> Self { @@ -39,6 +43,7 @@ impl CommitScheduler { // TODO(edwin): add concellation logic let worker = CommitSchedulerWorker::new( db.clone(), + l1_message_persister, rpc_client, table_mania, compute_budget_config, diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs index f44c06b10..e5950a1b2 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs @@ -1,7 +1,4 @@ -use std::{ - collections::HashMap, - num::{NonZero, NonZeroUsize}, -}; +use std::{collections::HashMap, num::NonZeroUsize}; use lru::LruCache; use magicblock_rpc_client::{ @@ -82,7 +79,7 @@ impl CommitIdTracker { #[derive(thiserror::Error, Debug)] pub enum Error { - #[error("Failed to get keys: {0}")] + #[error("Failed to get keys: {:?0}")] GetCommitIdsError(Vec), #[error("MagicBlockRpcClientError: {0}")] MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index 9cce8ac2a..39df524b9 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -1,8 +1,6 @@ use std::collections::{hash_map::Entry, HashMap, VecDeque}; -use magicblock_program::magic_scheduled_l1_message::{ - MagicL1Message, ScheduledL1Message, -}; +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::Pubkey; use crate::utils::ScheduledMessageExt; @@ -82,15 +80,10 @@ impl CommitSchedulerInner { l1_message: ScheduledL1Message, ) -> Option { let message_id = l1_message.id; - let Some(accounts) = l1_message.get_committed_accounts() else { + let Some(pubkeys) = l1_message.get_committed_pubkeys() else { return Some(l1_message); }; - let pubkeys = accounts - .iter() - .map(|account| *account.pubkey) - .collect::>(); - let (entries, is_conflicting) = Self::find_conflicting_entries(&pubkeys, &mut self.blocked_keys); // In any case block the corresponding accounts @@ -161,23 +154,26 @@ impl CommitSchedulerInner { "Invariant: blocked messages are always in candidates", ) == &meta.num_keys { - Some(message_id) + Some(*message_id) } else { None } }); if let Some(next) = candidate { - Some(self.blocked_messages.remove(next).unwrap().message) + Some(self.blocked_messages.remove(&next).unwrap().message) } else { None } } - fn find_conflicting_entries<'a>( + fn find_conflicting_entries<'a, 'b>( pubkeys: &[Pubkey], blocked_keys: &'a mut HashMap>, - ) -> (Vec>>, bool) { + ) -> (Vec>>, bool) + where + 'a: 'b, + { let mut is_conflicting = false; let entries = pubkeys .iter() diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 303840c71..aa95303a7 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -15,6 +15,7 @@ use tokio::sync::{ use crate::{ commit_scheduler::{ + commit_id_tracker::CommitIdTracker, commit_scheduler_inner::{CommitSchedulerInner, POISONED_INNER_MSG}, db::DB, Error, @@ -22,18 +23,27 @@ use crate::{ l1_message_executor::{ ExecutionOutput, L1MessageExecutor, MessageExecutorResult, }, - transaction_preperator::transaction_preparator::TransactionPreparator, + persist::L1MessagesPersisterIface, + transaction_preperator::transaction_preparator::{ + TransactionPreparator, TransactionPreparatorV1, + }, + utils::ScheduledMessageExt, ComputeBudgetConfig, }; -use crate::commit_scheduler::commit_id_tracker::CommitIdTracker; const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; +pub type BroadcasteddMessageExecutionResult = MessageExecutorResult< + ExecutionOutput, + Arc, +>; + // TODO(edwin): reduce num of params: 1,2,3, could be united -pub(crate) struct CommitSchedulerWorker { +pub(crate) struct CommitSchedulerWorker { db: Arc, + l1_messages_persister: P, rpc_client: MagicblockRpcClient, // 1. - table_mania: TableMania, // 2. + table_mania: TableMania, // 2. compute_budget_config: ComputeBudgetConfig, // 3. commit_id_tracker: CommitIdTracker, receiver: mpsc::Receiver, @@ -44,9 +54,10 @@ pub(crate) struct CommitSchedulerWorker { inner: Arc>, } -impl CommitSchedulerWorker { +impl CommitSchedulerWorker { pub fn new( db: Arc, + l1_messages_persister: P, rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, @@ -57,6 +68,7 @@ impl CommitSchedulerWorker { Self { db, + l1_messages_persister, rpc_client: rpc_client.clone(), table_mania, compute_budget_config, @@ -73,7 +85,7 @@ impl CommitSchedulerWorker { /// Spawns `main_loop` and return `Receiver` listening to results pub fn spawn( mut self, - ) -> broadcast::Receiver> { + ) -> broadcast::Receiver { let (result_sender, result_receiver) = broadcast::channel(100); tokio::spawn(self.main_loop(result_sender)); @@ -86,9 +98,7 @@ impl CommitSchedulerWorker { /// 3. Spawns execution of scheduled message async fn main_loop( mut self, - result_sender: broadcast::Sender< - MessageExecutorResult, - >, + result_sender: broadcast::Sender, ) { loop { // TODO: unwraps @@ -108,22 +118,35 @@ impl CommitSchedulerWorker { .expect(SEMAPHORE_CLOSED_MSG); // Prepare data for execution - let commit_ids = self.deduce_commit_ids(&l1_message).await; - let executor = L1MessageExecutor::new_v1( - self.rpc_client.clone(), - self.table_mania.clone(), - self.compute_budget_config.clone(), - ); + let commit_ids = + if let Some(pubkeys) = l1_message.get_committed_pubkeys() { + self.commit_id_tracker + .next_commit_ids(&pubkeys) + .await + .unwrap() + } else { + // Pure L1Action, no commit ids used + HashMap::new() + }; + let executor = + L1MessageExecutor::::new_v1( + self.rpc_client.clone(), + self.table_mania.clone(), + self.compute_budget_config.clone(), + self.l1_messages_persister.clone(), + ); // Spawn executor + let inner = self.inner.clone(); + let notify = self.notify.clone(); tokio::spawn(Self::execute( executor, l1_message, commit_ids, - self.inner.clone(), + inner, permit, result_sender.clone(), - self.notify.clone(), + notify, )); } } @@ -148,10 +171,11 @@ impl CommitSchedulerWorker { false } }; + let notify = self.notify.clone(); let message = tokio::select! { // Notify polled first to prioritize unblocked messages over new one biased; - _ = self.notify.notified() => { + _ = notify.notified() => { trace!("Worker executed L1Message, fetching new available one"); self.inner.lock().expect(POISONED_INNER_MSG).pop_next_scheduled_message() }, @@ -183,17 +207,23 @@ impl CommitSchedulerWorker { /// Wrapper on [`L1MessageExecutor`] that handles its results and drops execution permit async fn execute( - executor: L1MessageExecutor, + executor: L1MessageExecutor, l1_message: ScheduledL1Message, commit_ids: HashMap, inner_scheduler: Arc>, execution_permit: OwnedSemaphorePermit, result_sender: broadcast::Sender< - MessageExecutorResult, + MessageExecutorResult< + ExecutionOutput, + Arc, + >, >, notify: Arc, ) { - let result = executor.execute(l1_message.clone(), commit_ids).await; + let result = executor + .execute(l1_message.clone(), commit_ids) + .await + .map_err(|err| Arc::new(err)); // TODO: unwrap result_sender.send(result).unwrap(); // Remove executed task from Scheduler to unblock other messages diff --git a/magicblock-committor-service/src/commit_scheduler/db.rs b/magicblock-committor-service/src/commit_scheduler/db.rs index f8647feef..bfc50af41 100644 --- a/magicblock-committor-service/src/commit_scheduler/db.rs +++ b/magicblock-committor-service/src/commit_scheduler/db.rs @@ -21,10 +21,18 @@ pub(crate) trait DB { fn is_empty(&self) -> bool; } -struct DummyDB { +pub(crate) struct DummyDB { db: Mutex>, } +impl DummyDB { + pub fn new() -> Self { + Self { + db: Mutex::new(VecDeque::new()), + } + } +} + #[async_trait] impl DB for DummyDB { async fn store_l1_message( diff --git a/magicblock-committor-service/src/commit_scheduler/executor_pool.rs b/magicblock-committor-service/src/commit_scheduler/executor_pool.rs index d8dfe1c7e..20e014048 100644 --- a/magicblock-committor-service/src/commit_scheduler/executor_pool.rs +++ b/magicblock-committor-service/src/commit_scheduler/executor_pool.rs @@ -1,41 +1,3 @@ -use std::future::Future; - -use tokio::{ - sync::{Semaphore, SemaphorePermit}, - task::JoinHandle, -}; - -type MessageExecutorResult = (); - -pub(crate) struct MessageExecutorsPool { - limit: u8, - semaphore: Semaphore, - handles: Vec>, -} - -impl MessageExecutorsPool { - pub fn new(limit: u8) -> Self { - Self { - limit, - semaphore: Semaphore::new(limit as usize), - handles: vec![], - } - } - - pub async fn execute>( - &self, - f: impl FnOnce(SemaphorePermit) -> T, - ) { - let permit = self.semaphore.acquire().await.expect("asd"); - f(permit).await - } - - pub async fn get_worker_permit(&self) -> SemaphorePermit { - let permit = self.semaphore.acquire().await.unwrap(); - permit - } -} - // TODO: how executiong works? // case - No available worker // We can't process any messages - waiting diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index e37df1b84..ebe38bcd9 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -1,8 +1,4 @@ -use std::{ - collections::HashMap, - marker::PhantomData, - sync::{Arc, Mutex}, -}; +use std::collections::HashMap; use log::warn; use magicblock_program::{ @@ -23,9 +19,7 @@ use solana_sdk::{ }; use crate::{ - commit_scheduler::commit_scheduler_inner::{ - CommitSchedulerInner, POISONED_INNER_MSG, - }, + persist::L1MessagesPersisterIface, transaction_preperator::transaction_preparator::{ TransactionPreparator, TransactionPreparatorV1, }, @@ -34,30 +28,38 @@ use crate::{ // TODO(edwin): define struct // (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] +#[derive(Clone, Debug)] pub struct ExecutionOutput {} -pub(crate) struct L1MessageExecutor { +pub(crate) struct L1MessageExecutor { authority: Keypair, rpc_client: MagicblockRpcClient, transaction_preparator: T, + l1_messages_persister: P, } -impl L1MessageExecutor { +impl L1MessageExecutor +where + T: TransactionPreparator, + P: L1MessagesPersisterIface, +{ pub fn new_v1( rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, - ) -> L1MessageExecutor { + l1_messages_persister: P, + ) -> L1MessageExecutor { let authority = validator_authority(); let transaction_preparator = TransactionPreparatorV1::new( rpc_client.clone(), table_mania, compute_budget_config, ); - Self { + L1MessageExecutor:: { authority, rpc_client, transaction_preparator, + l1_messages_persister, } } @@ -81,34 +83,17 @@ impl L1MessageExecutor { l1_message: &ScheduledL1Message, commit_ids: HashMap, ) -> MessageExecutorResult<()> { - let mut prepared_message = self + let prepared_message = self .transaction_preparator - .prepare_commit_tx(&self.authority, &l1_message, commit_ids) - .await?; - - let latest_blockhash = self.rpc_client.get_latest_blockhash()?; - match &mut prepared_message { - VersionedMessage::V0(value) => { - value.recent_blockhash = latest_blockhash; - } - VersionedMessage::Legacy(value) => { - warn!("TransactionPreparator v1 does not use Legacy message"); - value.recent_blockhash = latest_blockhash; - } - }; - - let transaction = VersionedTransaction::try_new( - prepared_message, - &[&self.authority], - )?; - // TODO(edwin): add retries here? - self.rpc_client - .send_transaction( - &transaction, - &MagicBlockSendTransactionConfig::ensure_committed(), + .prepare_commit_tx( + &self.authority, + l1_message, + commit_ids, + &self.l1_messages_persister, ) .await?; - Ok(()) + + self.send_prepared_message(prepared_message).await } /// Executes Finalize stage @@ -116,18 +101,26 @@ impl L1MessageExecutor { &self, l1_message: &ScheduledL1Message, ) -> MessageExecutorResult<()> { - // TODO(edwin): properly define this. let rent_reimbursement = self.authority.pubkey(); - let mut prepared_message = self + let prepared_message = self .transaction_preparator .prepare_finalize_tx( &self.authority, &rent_reimbursement, - &l1_message, + l1_message, + &self.l1_messages_persister, ) .await?; - let latest_blockhash = self.rpc_client.get_latest_blockhash()?; + self.send_prepared_message(prepared_message).await + } + + /// Shared helper for sending transactions + async fn send_prepared_message( + &self, + mut prepared_message: VersionedMessage, + ) -> MessageExecutorResult<()> { + let latest_blockhash = self.rpc_client.get_latest_blockhash().await?; match &mut prepared_message { VersionedMessage::V0(value) => { value.recent_blockhash = latest_blockhash; @@ -142,13 +135,13 @@ impl L1MessageExecutor { prepared_message, &[&self.authority], )?; - // TODO(edwin): add retries here? self.rpc_client .send_transaction( &transaction, &MagicBlockSendTransactionConfig::ensure_committed(), ) .await?; + Ok(()) } } diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index a054ccaf7..6af162d26 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -3,15 +3,12 @@ use std::{ sync::{Arc, Mutex}, }; -use magicblock_committor_program::Changeset; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; -use solana_sdk::{hash::Hash, pubkey::Pubkey}; +use solana_sdk::pubkey::Pubkey; use super::{ - db::CommitStatusRow, - error::{CommitPersistError, CommitPersistResult}, - utils::now, - CommitStatus, CommitType, CommittsDb, MessageSignatures, + db::CommitStatusRow, error::CommitPersistResult, utils::now, CommitStatus, + CommitType, CommittsDb, MessageSignatures, }; use crate::utils::ScheduledMessageExt; @@ -108,7 +105,7 @@ impl L1MessagePersister { CommitStatusRow { message_id: l1_message.id, commit_id: 0, // Not known at creation, set later - pubkey: *account.pubkey, + pubkey: account.pubkey, delegated_account_owner: account.account.owner, slot: l1_message.slot, ephemeral_blockhash: l1_message.blockhash, diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 2c50cc630..9a941aa35 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -6,9 +6,10 @@ use solana_sdk::{clock::Slot, hash::Hash, signature::Signature}; use super::{ error::CommitPersistResult, - utils::{i64_into_u64, now, u64_into_i64}, + utils::{i64_into_u64, u64_into_i64}, CommitStatus, CommitStatusSignatures, CommitStrategy, CommitType, }; +use crate::persist::error::CommitPersistError; // ----------------- // CommitStatusRow @@ -50,6 +51,7 @@ pub struct CommitStatusRow { pub retries_count: u16, } +#[derive(Debug)] pub struct MessageSignatures { /// The signature of the transaction on chain that processed the commit pub processed_signature: Signature, @@ -388,7 +390,7 @@ impl CommittsDb { let undelegated_signature: Option = row.get(2)?; let created_at: i64 = row.get(3)?; - Ok(MessageSignatures { + Ok::<_, CommitPersistError>(MessageSignatures { processed_signature: Signature::from_str( &processed_signature, )?, @@ -500,7 +502,12 @@ fn extract_committor_row( finalize_signature: finalized_signature, undelegate_signature: undelegated_signature, }); - CommitStatus::try_from((commit_status.as_str(), commit_strategy, sigs))? + CommitStatus::try_from(( + commit_status.as_str(), + commit_id, + commit_strategy, + sigs, + ))? }; let last_retried_at: u64 = { diff --git a/magicblock-committor-service/src/persist/mod.rs b/magicblock-committor-service/src/persist/mod.rs index ece2dda1b..5256de6e5 100644 --- a/magicblock-committor-service/src/persist/mod.rs +++ b/magicblock-committor-service/src/persist/mod.rs @@ -4,7 +4,7 @@ pub mod error; mod types; mod utils; -pub use commit_persister::L1MessagePersister; +pub use commit_persister::{L1MessagePersister, L1MessagesPersisterIface}; pub use db::{CommitStatusRow, CommittsDb, MessageSignatures}; pub use types::{ CommitStatus, CommitStatusSignatures, CommitStrategy, CommitType, diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index baba23f50..3be1d8cd5 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -100,20 +100,21 @@ impl fmt::Display for CommitStatus { } } -impl TryFrom<(&str, CommitStrategy, Option)> +impl TryFrom<(&str, u64, CommitStrategy, Option)> for CommitStatus { type Error = CommitPersistError; fn try_from( - (status, strategy, sigs): ( + (status, commit_id, strategy, sigs): ( &str, + u64, CommitStrategy, Option, ), ) -> Result { let get_sigs = || { - if let Some(sigs) = sigs { + if let Some(sigs) = sigs.clone() { Ok(sigs) } else { return Err(CommitPersistError::CommitStatusNeedsSignatures( @@ -125,31 +126,27 @@ impl TryFrom<(&str, CommitStrategy, Option)> use CommitStatus::*; match status { "Pending" => Ok(Pending), - "Failed" => Ok(Failed(get_bundle_id!())), + "Failed" => Ok(Failed(commit_id)), "BufferAndChunkPartiallyInitialized" => { - Ok(BufferAndChunkPartiallyInitialized(get_bundle_id!())) + Ok(BufferAndChunkPartiallyInitialized(commit_id)) } "BufferAndChunkInitialized" => { - Ok(BufferAndChunkInitialized(get_bundle_id!())) + Ok(BufferAndChunkInitialized(commit_id)) } "BufferAndChunkFullyInitialized" => { - Ok(BufferAndChunkFullyInitialized(get_bundle_id!())) + Ok(BufferAndChunkFullyInitialized(commit_id)) } "PartOfTooLargeBundleToProcess" => { - Ok(PartOfTooLargeBundleToProcess(get_bundle_id!())) - } - "FailedProcess" => { - Ok(FailedProcess((get_bundle_id!(), strategy, sigs))) + Ok(PartOfTooLargeBundleToProcess(commit_id)) } + "FailedProcess" => Ok(FailedProcess((commit_id, strategy, sigs))), "FailedFinalize" => { - Ok(FailedFinalize((get_bundle_id!(), strategy, get_sigs!()))) + Ok(FailedFinalize((commit_id, strategy, get_sigs()?))) } "FailedUndelegate" => { - Ok(FailedUndelegate((get_bundle_id!(), strategy, get_sigs!()))) - } - "Succeeded" => { - Ok(Succeeded((get_bundle_id!(), strategy, get_sigs!()))) + Ok(FailedUndelegate((commit_id, strategy, get_sigs()?))) } + "Succeeded" => Ok(Succeeded((commit_id, strategy, get_sigs()?))), _ => { Err(CommitPersistError::InvalidCommitStatus(status.to_string())) } diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index bc6337b16..5afedb4fb 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -4,10 +4,12 @@ use log::*; use magicblock_committor_program::Changeset; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::Pubkey; -use solana_sdk::{hash::Hash, signature::Keypair}; +use solana_sdk::signature::Keypair; use tokio::{ select, sync::{ + broadcast, + broadcast::Receiver, mpsc::{self, error::TrySendError}, oneshot, }, @@ -18,7 +20,7 @@ use crate::{ commit::CommittorProcessor, config::ChainConfig, error::CommittorServiceResult, - persist::{BundleSignatureRow, CommitStatusRow}, + persist::{CommitStatusRow, MessageSignatures}, pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, }; @@ -60,7 +62,7 @@ pub enum CommittorMessage { }, GetBundleSignatures { respond_to: - oneshot::Sender>>, + oneshot::Sender>>, bundle_id: u64, }, GetLookupTables { @@ -242,7 +244,7 @@ impl CommittorService { pub fn get_bundle_signatures( &self, bundle_id: u64, - ) -> oneshot::Receiver>> + ) -> oneshot::Receiver>> { let (tx, rx) = oneshot::channel(); self.try_send(CommittorMessage::GetBundleSignatures { @@ -320,7 +322,7 @@ impl L1MessageCommittor for CommittorService { fn get_bundle_signatures( &self, bundle_id: u64, - ) -> oneshot::Receiver>> + ) -> oneshot::Receiver>> { let (tx, rx) = oneshot::channel(); self.try_send(CommittorMessage::GetBundleSignatures { @@ -329,6 +331,10 @@ impl L1MessageCommittor for CommittorService { }); rx } + + fn subscribe_for_results(&self) -> Receiver<()> { + todo!() + } } pub trait L1MessageCommittor: Send + Sync + 'static { @@ -339,21 +345,20 @@ pub trait L1MessageCommittor: Send + Sync + 'static { owner: Pubkey, ) -> oneshot::Receiver>; - /// Commits the changeset and returns the reqid - fn commit_l1_messages( - &self, - l1_messages: Vec, - ) -> oneshot::Receiver>; + /// Commits the changeset and returns + fn commit_l1_messages(&self, l1_messages: Vec); + + fn subscribe_for_results(&self) -> broadcast::Receiver<()>; - /// Gets statuses of accounts that were committed as part of a request with provided reqid + /// Gets statuses of accounts that were committed as part of a request with provided message_id fn get_commit_statuses( &self, - reqid: String, + message_id: u64, ) -> oneshot::Receiver>>; /// Gets signatures of commits processed as part of the bundle with the provided bundle_id fn get_bundle_signatures( &self, bundle_id: u64, - ) -> oneshot::Receiver>>; + ) -> oneshot::Receiver>>; } diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index c6294cfd6..36ec3a82c 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -15,8 +15,8 @@ use tokio::sync::oneshot; use crate::{ error::CommittorServiceResult, persist::{ - BundleSignatureRow, CommitStatus, CommitStatusRow, - CommitStatusSignatures, CommitStrategy, CommitType, + CommitStatus, CommitStatusRow, CommitStatusSignatures, CommitStrategy, + CommitType, MessageSignatures, }, L1MessageCommittor, }; @@ -99,10 +99,10 @@ impl L1MessageCommittor for ChangesetCommittorStub { &self, bundle_id: u64, ) -> tokio::sync::oneshot::Receiver< - crate::error::CommittorServiceResult>, + crate::error::CommittorServiceResult>, > { let (tx, rx) = tokio::sync::oneshot::channel(); - let bundle_signature = BundleSignatureRow { + let bundle_signature = MessageSignatures { bundle_id, processed_signature: Signature::new_unique(), finalized_signature: Some(Signature::new_unique()), diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index e9eef49fa..726d4f816 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -3,7 +3,7 @@ use std::{collections::HashSet, time::Duration}; use anyhow::anyhow; use borsh::BorshDeserialize; use futures_util::future::{join, join_all}; -use log::{error, warn}; +use log::error; use magicblock_committor_program::{Chunks, CommitableAccount}; use magicblock_rpc_client::{ MagicBlockRpcClientError, MagicBlockSendTransactionConfig, diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 16bf0dcca..bfe04b584 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -10,6 +10,7 @@ use solana_sdk::{ }; use crate::{ + persist::L1MessagesPersisterIface, transaction_preperator::{ delivery_preparator::DeliveryPreparator, error::PreparatorResult, @@ -42,21 +43,23 @@ pub trait TransactionPreparator { /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks /// Handles all necessary preparations for Message to be valid /// NOTE: [`VersionedMessage`] contains dummy recent_block_hash that should be replaced - async fn prepare_commit_tx( + async fn prepare_commit_tx( &self, authority: &Keypair, l1_message: &ScheduledL1Message, commit_ids: HashMap, + l1_messages_persister: &P, ) -> PreparatorResult; /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks /// Handles all necessary preparations for Message to be valid // NOTE: [`VersionedMessage`] contains dummy recent_block_hash that should be replaced - async fn prepare_finalize_tx( + async fn prepare_finalize_tx( &self, authority: &Keypair, rent_reimbursement: &Pubkey, l1_message: &ScheduledL1Message, + l1_messages_persister: &P, ) -> PreparatorResult; } @@ -96,11 +99,12 @@ impl TransactionPreparator for TransactionPreparatorV1 { /// In V1: prepares TX with commits for every account in message /// For pure actions message - outputs Tx that runs actions - async fn prepare_commit_tx( + async fn prepare_commit_tx( &self, authority: &Keypair, l1_message: &ScheduledL1Message, commit_ids: HashMap, + l1_messages_persister: &P, ) -> PreparatorResult { // 1. create tasks // 2. optimize to fit tx size. aka Delivery Strategy @@ -125,11 +129,12 @@ impl TransactionPreparator for TransactionPreparatorV1 { } /// In V1: prepares single TX with finalize, undelegation + actions - async fn prepare_finalize_tx( + async fn prepare_finalize_tx( &self, authority: &Keypair, rent_reimbursement: &Pubkey, l1_message: &ScheduledL1Message, + l1_messages_persister: &P, ) -> PreparatorResult { let tasks = TaskBuilderV1::finalize_tasks(l1_message, rent_reimbursement); diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs index 50e13a68d..a23ae4ee6 100644 --- a/magicblock-committor-service/src/transactions.rs +++ b/magicblock-committor-service/src/transactions.rs @@ -195,6 +195,7 @@ pub(crate) fn process_commits_ix( pubkey: &Pubkey, delegated_account_owner: &Pubkey, buffer_pda: &Pubkey, + commit_id: u64, commit_args: CommitStateFromBufferArgs, ) -> Instruction { dlp::instruction_builder::commit_state_from_buffer( @@ -209,12 +210,12 @@ pub(crate) fn process_commits_ix( pub(crate) fn close_buffers_ix( validator_auth: Pubkey, pubkey: &Pubkey, - ephemeral_blockhash: &Hash, + commit_id: u64, ) -> Instruction { create_close_ix(CreateCloseIxArgs { authority: validator_auth, pubkey: *pubkey, - blockhash: *ephemeral_blockhash, + commit_id, }) } @@ -508,7 +509,7 @@ mod test { let delegated_account_owner = Pubkey::new_unique(); let buffer_pda = Pubkey::new_unique(); let commit_args = CommitStateFromBufferArgs::default(); - vec![process_commits_ix( + vec![dlp::instruction_builder::process_commits_ix( auth_pubkey, &pubkey, &delegated_account_owner, @@ -535,10 +536,10 @@ mod test { ) }; pub(crate) static ref MAX_CLOSE_PER_TX: u8 = { - let ephemeral_blockhash = Hash::default(); + let commit_id = 0; max_chunks_per_transaction("Max close per tx", |auth_pubkey| { let pubkey = Pubkey::new_unique(); - vec![super::close_buffers_ix( + vec![close_buffers_ix( auth_pubkey, &pubkey, &ephemeral_blockhash, @@ -546,11 +547,11 @@ mod test { }) }; pub(crate) static ref MAX_CLOSE_PER_TX_USING_LOOKUP: u8 = { - let ephemeral_blockhash = Hash::default(); + let commit_id = 0; max_chunks_per_transaction_using_lookup_table( "Max close per tx using lookup", |auth_pubkey, committee, _| { - vec![super::close_buffers_ix( + vec![close_buffers_ix( auth_pubkey, &committee, &ephemeral_blockhash, @@ -560,7 +561,7 @@ mod test { ) }; pub(crate) static ref MAX_PROCESS_AND_CLOSE_PER_TX: u8 = { - let ephemeral_blockhash = Hash::default(); + let commit_id = 0; max_chunks_per_transaction( "Max process and close per tx", |auth_pubkey| { @@ -568,12 +569,12 @@ mod test { let delegated_account_owner = Pubkey::new_unique(); let buffer_pda = Pubkey::new_unique(); let commit_args = CommitStateFromBufferArgs::default(); - super::process_and_close_ixs( + process_and_close_ixs( auth_pubkey, &pubkey, &delegated_account_owner, &buffer_pda, - &ephemeral_blockhash, + commit_id, commit_args, ) }, diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index fb69019c1..ae8436347 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -5,7 +5,10 @@ use solana_pubkey::Pubkey; pub trait ScheduledMessageExt { fn get_committed_accounts(&self) -> Option<&Vec>; - fn get_committed_pubkeys(&self) -> Option<&Vec>; + fn get_committed_pubkeys(&self) -> Option>; + + // TODO(edwin): ugly + fn is_undelegate(&self) -> bool; } impl ScheduledMessageExt for ScheduledL1Message { @@ -19,9 +22,17 @@ impl ScheduledMessageExt for ScheduledL1Message { } } - fn get_committed_pubkeys(&self) -> Option<&Vec> { + fn get_committed_pubkeys(&self) -> Option> { self.get_committed_accounts().map(|accounts| { - accounts.iter().map(|account| *account.pubkey).collect() + accounts.iter().map(|account| account.pubkey).collect() }) } + + fn is_undelegate(&self) -> bool { + match &self.l1_message { + MagicL1Message::L1Actions(_) => false, + MagicL1Message::Commit(_) => false, + MagicL1Message::CommitAndUndelegate(_) => true, + } + } } diff --git a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs index 02d3fd1e5..85beb5e12 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs @@ -1,6 +1,4 @@ -use solana_sdk::{ - instruction::InstructionError, transaction_context::TransactionContext, -}; +use solana_sdk::instruction::InstructionError; use crate::{ args::MagicL1MessageArgs, From be0b2b8a456534a0e85c126b80fdf5c21ffab3ea Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 18 Jul 2025 16:02:32 +0900 Subject: [PATCH 103/199] fix: compilation + some code cleaning --- .../src/commit/commit_using_buffer.rs | 6 ++-- .../src/commit/committor_processor.rs | 6 ++-- .../src/commit_scheduler.rs | 33 +++++++++---------- .../src/commit_scheduler/commit_id_tracker.rs | 2 +- .../commit_scheduler_worker.rs | 7 +--- .../src/commit_scheduler/db.rs | 2 +- .../src/persist/commit_persister.rs | 6 ++-- magicblock-committor-service/src/service.rs | 1 - .../budget_calculator.rs | 2 +- .../delivery_preparator.rs | 4 +-- .../transaction_preperator/task_builder.rs | 7 ++-- .../transaction_preperator/task_strategist.rs | 5 +-- .../src/transaction_preperator/tasks.rs | 2 -- .../src/transaction_preperator/utils.rs | 1 - 14 files changed, 32 insertions(+), 52 deletions(-) diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs index 0b78139e4..545362839 100644 --- a/magicblock-committor-service/src/commit/commit_using_buffer.rs +++ b/magicblock-committor-service/src/commit/commit_using_buffer.rs @@ -559,7 +559,7 @@ impl CommittorProcessor { pubkey: commitable.pubkey, chunks_account_size, buffer_account_size, - blockhash: ephemeral_blockhash, + commit_id: 0, // TODO(edwin) chunk_count: commitable.chunk_count(), chunk_size: commitable.chunk_size(), }); @@ -568,7 +568,7 @@ impl CommittorProcessor { authority: me.authority.pubkey(), pubkey: commitable.pubkey, buffer_account_size, - blockhash: ephemeral_blockhash, + commit_id: 0, // TODO(edwin) }); let commit_info = CommitInfo::BufferedDataAccount { @@ -999,7 +999,7 @@ impl CommittorProcessor { pubkey, offset: chunk.offset, data_chunk: chunk.data_chunk, - blockhash: ephemeral_blockhash, + commit_id: 0, // TODO(edwin) }); let write_budget_ixs = self .compute_budget_config diff --git a/magicblock-committor-service/src/commit/committor_processor.rs b/magicblock-committor-service/src/commit/committor_processor.rs index e8d125844..1247d6188 100644 --- a/magicblock-committor-service/src/commit/committor_processor.rs +++ b/magicblock-committor-service/src/commit/committor_processor.rs @@ -23,15 +23,13 @@ use tokio::task::JoinSet; use super::common::{lookup_table_keys, send_and_confirm}; use crate::{ commit_scheduler::{db::DummyDB, CommitScheduler}, - commit_stage::CommitStage, compute_budget::{ComputeBudget, ComputeBudgetConfig}, config::ChainConfig, error::CommittorServiceResult, persist::{ - CommitStatusRow, CommitStrategy, L1MessagePersister, - L1MessagesPersisterIface, MessageSignatures, + CommitStatusRow, L1MessagePersister, L1MessagesPersisterIface, + MessageSignatures, }, - pubkeys_provider::provide_committee_pubkeys, types::{InstructionsForCommitable, InstructionsKind}, CommitInfo, }; diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index 15d48da7a..ab919d36a 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -18,7 +18,6 @@ use crate::{ }, db::DB, }, - l1_message_executor::{ExecutionOutput, MessageExecutorResult}, persist::L1MessagesPersisterIface, ComputeBudgetConfig, }; @@ -65,30 +64,28 @@ impl CommitScheduler { &self, l1_messages: Vec, ) -> Result<(), Error> { - for el in l1_messages { - // If db not empty push el-t there - // This means that at some point channel got full - // Worker first will clean-up channel, and then DB. - // Pushing into channel would break order of commits - if !self.db.is_empty() { - self.db.store_l1_messages(l1_messages).await?; - continue; - } + // If db not empty push el-t there + // This means that at some point channel got full + // Worker first will clean-up channel, and then DB. + // Pushing into channel would break order of commits + if !self.db.is_empty() { + self.db.store_l1_messages(l1_messages).await?; + return Ok(()); + } + for el in l1_messages { let err = if let Err(err) = self.message_sender.try_send(el) { err } else { continue; }; - if matches!(err, TrySendError::Closed(_)) { - Err(Error::ChannelClosed) - } else { - self.db - .store_l1_messages(l1_messages) - .await - .map_err(Error::from) - }? + match err { + TrySendError::Closed(_) => Err(Error::ChannelClosed), + TrySendError::Full(el) => { + self.db.store_l1_message(el).await.map_err(Error::from) + } + }?; } Ok(()) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs index e5950a1b2..fe0344e3d 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs @@ -79,7 +79,7 @@ impl CommitIdTracker { #[derive(thiserror::Error, Debug)] pub enum Error { - #[error("Failed to get keys: {:?0}")] + #[error("Failed to get keys: {0:?}")] GetCommitIdsError(Vec), #[error("MagicBlockRpcClientError: {0}")] MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index aa95303a7..8e75cf23b 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -212,12 +212,7 @@ impl CommitSchedulerWorker { commit_ids: HashMap, inner_scheduler: Arc>, execution_permit: OwnedSemaphorePermit, - result_sender: broadcast::Sender< - MessageExecutorResult< - ExecutionOutput, - Arc, - >, - >, + result_sender: broadcast::Sender, notify: Arc, ) { let result = executor diff --git a/magicblock-committor-service/src/commit_scheduler/db.rs b/magicblock-committor-service/src/commit_scheduler/db.rs index bfc50af41..94e5881fe 100644 --- a/magicblock-committor-service/src/commit_scheduler/db.rs +++ b/magicblock-committor-service/src/commit_scheduler/db.rs @@ -7,7 +7,7 @@ use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; const POISONED_MUTEX_MSG: &str = "Mutex poisoned"; #[async_trait] -pub(crate) trait DB { +pub(crate) trait DB: Send + Sync + 'static { async fn store_l1_message( &self, l1_message: ScheduledL1Message, diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 6af162d26..538d89dd6 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -15,11 +15,11 @@ use crate::utils::ScheduledMessageExt; const POISONED_MUTEX_MSG: &str = "Commitor Persister lock poisoned"; /// Records lifespan pf L1Message -pub trait L1MessagesPersisterIface: Send + Sync + Clone { +pub trait L1MessagesPersisterIface: Send + Sync + Clone + 'static { /// Starts persisting L1Message fn start_l1_messages( &self, - l1_message: &ScheduledL1Message, + l1_message: &[ScheduledL1Message], ) -> CommitPersistResult<()>; fn start_l1_message( &self, @@ -126,7 +126,7 @@ impl L1MessagePersister { impl L1MessagesPersisterIface for L1MessagePersister { fn start_l1_messages( &self, - l1_message: &Vec, + l1_message: &[ScheduledL1Message], ) -> CommitPersistResult<()> { let commit_rows = l1_message .iter() diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 5afedb4fb..88feb7fb9 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -1,7 +1,6 @@ use std::path::Path; use log::*; -use magicblock_committor_program::Changeset; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::Pubkey; use solana_sdk::signature::Keypair; diff --git a/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs b/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs index ef91f8969..70eb97f83 100644 --- a/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs +++ b/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs @@ -3,7 +3,7 @@ use solana_sdk::{ compute_budget::ComputeBudgetInstruction, instruction::Instruction, }; -use crate::{compute_budget::Budget, ComputeBudgetConfig}; +use crate::ComputeBudgetConfig; // TODO(edwin): rename pub struct ComputeBudgetV1 { diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 726d4f816..010507829 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -4,7 +4,7 @@ use anyhow::anyhow; use borsh::BorshDeserialize; use futures_util::future::{join, join_all}; use log::error; -use magicblock_committor_program::{Chunks, CommitableAccount}; +use magicblock_committor_program::Chunks; use magicblock_rpc_client::{ MagicBlockRpcClientError, MagicBlockSendTransactionConfig, MagicblockRpcClient, @@ -12,7 +12,6 @@ use magicblock_rpc_client::{ use magicblock_table_mania::{error::TableManiaError, TableMania}; use solana_account::ReadableAccount; use solana_pubkey::Pubkey; -use solana_rpc_client_api::client_error::reqwest::Version; use solana_sdk::{ instruction::Instruction, message::{ @@ -26,7 +25,6 @@ use tokio::time::sleep; use crate::{ transaction_preperator::{ - error::PreparatorResult, task_strategist::TransactionStrategy, tasks::{L1Task, TaskPreparationInfo}, }, diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/transaction_preperator/task_builder.rs index 57569ff65..cc2a9f770 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_builder.rs @@ -1,14 +1,13 @@ use std::collections::HashMap; use magicblock_program::magic_scheduled_l1_message::{ - CommitType, CommittedAccountV2, L1Action, MagicL1Message, - ScheduledL1Message, UndelegateType, + CommitType, CommittedAccountV2, MagicL1Message, ScheduledL1Message, + UndelegateType, }; use solana_pubkey::Pubkey; use crate::transaction_preperator::tasks::{ - ArgsTask, CommitTask, FinalizeTask, L1Task, TaskPreparationInfo, - UndelegateTask, + ArgsTask, CommitTask, FinalizeTask, L1Task, UndelegateTask, }; pub trait TasksBuilder { diff --git a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs index 91917c811..ef1a2284b 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs +++ b/magicblock-committor-service/src/transaction_preperator/task_strategist.rs @@ -1,7 +1,4 @@ -use std::{ - collections::{BinaryHeap, HashSet}, - ptr::NonNull, -}; +use std::{collections::BinaryHeap, ptr::NonNull}; use solana_pubkey::Pubkey; use solana_sdk::signature::Keypair; diff --git a/magicblock-committor-service/src/transaction_preperator/tasks.rs b/magicblock-committor-service/src/transaction_preperator/tasks.rs index f49255057..b1bcbefd1 100644 --- a/magicblock-committor-service/src/transaction_preperator/tasks.rs +++ b/magicblock-committor-service/src/transaction_preperator/tasks.rs @@ -1,5 +1,3 @@ -use std::arch::aarch64::vcale_f32; - use dlp::args::{CallHandlerArgs, CommitStateArgs, CommitStateFromBufferArgs}; use magicblock_committor_program::{ instruction_builder::{ diff --git a/magicblock-committor-service/src/transaction_preperator/utils.rs b/magicblock-committor-service/src/transaction_preperator/utils.rs index 14ceecdcc..862fd490f 100644 --- a/magicblock-committor-service/src/transaction_preperator/utils.rs +++ b/magicblock-committor-service/src/transaction_preperator/utils.rs @@ -2,7 +2,6 @@ use std::collections::HashSet; use solana_pubkey::Pubkey; use solana_sdk::{ - address_lookup_table::state::AddressLookupTable, hash::Hash, instruction::Instruction, message::{v0::Message, AddressLookupTableAccount, VersionedMessage}, From 8df9db184ccb09928cf34b5ea5b523677933ee0e Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 18 Jul 2025 17:11:09 +0900 Subject: [PATCH 104/199] refactor: extract tasks into separate module --- magicblock-committor-service/src/lib.rs | 1 + .../budget_calculator.rs | 0 magicblock-committor-service/src/tasks/mod.rs | 5 +++++ .../task_builder.rs | 2 +- .../task_strategist.rs | 15 +++++++++++---- .../{transaction_preperator => tasks}/tasks.rs | 3 +-- .../{transaction_preperator => tasks}/utils.rs | 4 +--- .../transaction_preperator/delivery_preparator.rs | 2 +- .../src/transaction_preperator/error.rs | 10 ++++++++++ .../src/transaction_preperator/mod.rs | 5 ----- .../transaction_preparator.rs | 7 ++++--- 11 files changed, 35 insertions(+), 19 deletions(-) rename magicblock-committor-service/src/{transaction_preperator => tasks}/budget_calculator.rs (100%) create mode 100644 magicblock-committor-service/src/tasks/mod.rs rename magicblock-committor-service/src/{transaction_preperator => tasks}/task_builder.rs (99%) rename magicblock-committor-service/src/{transaction_preperator => tasks}/task_strategist.rs (95%) rename magicblock-committor-service/src/{transaction_preperator => tasks}/tasks.rs (98%) rename magicblock-committor-service/src/{transaction_preperator => tasks}/utils.rs (97%) diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index ac28cd1f1..0ec77ddf4 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -21,6 +21,7 @@ mod commit_scheduler; pub(crate) mod l1_message_executor; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; +pub mod tasks; pub(crate) mod transaction_preperator; pub(crate) mod utils; diff --git a/magicblock-committor-service/src/transaction_preperator/budget_calculator.rs b/magicblock-committor-service/src/tasks/budget_calculator.rs similarity index 100% rename from magicblock-committor-service/src/transaction_preperator/budget_calculator.rs rename to magicblock-committor-service/src/tasks/budget_calculator.rs diff --git a/magicblock-committor-service/src/tasks/mod.rs b/magicblock-committor-service/src/tasks/mod.rs new file mode 100644 index 000000000..483d9341b --- /dev/null +++ b/magicblock-committor-service/src/tasks/mod.rs @@ -0,0 +1,5 @@ +mod budget_calculator; +pub mod task_builder; +pub mod task_strategist; +pub mod tasks; +pub mod utils; diff --git a/magicblock-committor-service/src/transaction_preperator/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs similarity index 99% rename from magicblock-committor-service/src/transaction_preperator/task_builder.rs rename to magicblock-committor-service/src/tasks/task_builder.rs index cc2a9f770..7c1d5e794 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -6,7 +6,7 @@ use magicblock_program::magic_scheduled_l1_message::{ }; use solana_pubkey::Pubkey; -use crate::transaction_preperator::tasks::{ +use crate::tasks::tasks::{ ArgsTask, CommitTask, FinalizeTask, L1Task, UndelegateTask, }; diff --git a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs similarity index 95% rename from magicblock-committor-service/src/transaction_preperator/task_strategist.rs rename to magicblock-committor-service/src/tasks/task_strategist.rs index ef1a2284b..123ddb3e0 100644 --- a/magicblock-committor-service/src/transaction_preperator/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -4,8 +4,7 @@ use solana_pubkey::Pubkey; use solana_sdk::signature::Keypair; use crate::{ - transaction_preperator::{ - error::{Error, PreparatorResult}, + tasks::{ tasks::{ArgsTask, L1Task}, utils::TransactionUtils, }, @@ -24,7 +23,7 @@ impl TaskStrategist { pub fn build_strategy( mut tasks: Vec>, validator: &Pubkey, - ) -> PreparatorResult { + ) -> TaskStrategistResult { // Attempt optimizing tasks themselves(using buffers) if Self::optimize_strategy(&mut tasks) <= MAX_ENCODED_TRANSACTION_SIZE { Ok(TransactionStrategy { @@ -48,7 +47,7 @@ impl TaskStrategist { fn attempt_lookup_tables( validator: &Pubkey, tasks: &[Box], - ) -> PreparatorResult> { + ) -> TaskStrategistResult> { // Gather all involved keys in tx let budgets = TransactionUtils::tasks_budgets(&tasks); let budget_instructions = @@ -154,3 +153,11 @@ impl TaskStrategist { current_tx_length } } + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("Failed to fit in single TX")] + FailedToFitError, +} + +pub type TaskStrategistResult = Result; diff --git a/magicblock-committor-service/src/transaction_preperator/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs similarity index 98% rename from magicblock-committor-service/src/transaction_preperator/tasks.rs rename to magicblock-committor-service/src/tasks/tasks.rs index b1bcbefd1..f81937802 100644 --- a/magicblock-committor-service/src/transaction_preperator/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -17,8 +17,7 @@ use solana_pubkey::Pubkey; use solana_sdk::instruction::{AccountMeta, Instruction}; use crate::{ - consts::MAX_WRITE_CHUNK_SIZE, - transaction_preperator::budget_calculator::ComputeBudgetV1, + consts::MAX_WRITE_CHUNK_SIZE, tasks::budget_calculator::ComputeBudgetV1, }; pub struct TaskPreparationInfo { diff --git a/magicblock-committor-service/src/transaction_preperator/utils.rs b/magicblock-committor-service/src/tasks/utils.rs similarity index 97% rename from magicblock-committor-service/src/transaction_preperator/utils.rs rename to magicblock-committor-service/src/tasks/utils.rs index 862fd490f..fddefe615 100644 --- a/magicblock-committor-service/src/transaction_preperator/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -10,9 +10,7 @@ use solana_sdk::{ transaction::VersionedTransaction, }; -use crate::transaction_preperator::{ - budget_calculator::ComputeBudgetV1, tasks::L1Task, -}; +use crate::tasks::{budget_calculator::ComputeBudgetV1, tasks::L1Task}; /// Returns [`Vec`] where all TX accounts stored in ALT pub fn estimate_lookup_tables_for_tx( diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 010507829..6753d8bc2 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -24,7 +24,7 @@ use solana_sdk::{ use tokio::time::sleep; use crate::{ - transaction_preperator::{ + tasks::{ task_strategist::TransactionStrategy, tasks::{L1Task, TaskPreparationInfo}, }, diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preperator/error.rs index 1099bb257..24e0cdc80 100644 --- a/magicblock-committor-service/src/transaction_preperator/error.rs +++ b/magicblock-committor-service/src/transaction_preperator/error.rs @@ -12,4 +12,14 @@ pub enum Error { InternalError(#[from] anyhow::Error), } +impl From for Error { + fn from(value: crate::tasks::task_strategist::Error) -> Self { + match value { + crate::tasks::task_strategist::Error::FailedToFitError => { + Self::FailedToFitError + } + } + } +} + pub type PreparatorResult = Result; diff --git a/magicblock-committor-service/src/transaction_preperator/mod.rs b/magicblock-committor-service/src/transaction_preperator/mod.rs index 8c647896a..029398737 100644 --- a/magicblock-committor-service/src/transaction_preperator/mod.rs +++ b/magicblock-committor-service/src/transaction_preperator/mod.rs @@ -1,8 +1,3 @@ -mod budget_calculator; mod delivery_preparator; pub mod error; -mod task_builder; -mod task_strategist; -mod tasks; pub mod transaction_preparator; -mod utils; diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index bfe04b584..b73657c5e 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -11,13 +11,14 @@ use solana_sdk::{ use crate::{ persist::L1MessagesPersisterIface, - transaction_preperator::{ - delivery_preparator::DeliveryPreparator, - error::PreparatorResult, + tasks::{ task_builder::{TaskBuilderV1, TasksBuilder}, task_strategist::TaskStrategist, utils::TransactionUtils, }, + transaction_preperator::{ + delivery_preparator::DeliveryPreparator, error::PreparatorResult, + }, ComputeBudgetConfig, }; From eba1af5213bd4be6dfda833e18b2284002656082 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 18 Jul 2025 19:20:21 +0900 Subject: [PATCH 105/199] feat: persister integration into services --- .../src/remote_scheduled_commits_worker.rs | 2 +- .../src/commit/commit_using_buffer.rs | 2 +- .../src/commit/committor_processor.rs | 226 +----------------- .../commit_scheduler_worker.rs | 98 +++++--- .../src/l1_message_executor.rs | 25 +- .../src/persist/commit_persister.rs | 50 ++-- .../src/persist/db.rs | 114 +++++---- magicblock-committor-service/src/service.rs | 56 ++--- .../src/stubs/changeset_committor_stub.rs | 2 +- .../src/tasks/task_builder.rs | 22 +- .../src/tasks/tasks.rs | 4 + .../delivery_preparator.rs | 24 +- .../src/transaction_preperator/error.rs | 13 + .../transaction_preparator.rs | 82 +++---- .../src/transactions.rs | 4 +- 15 files changed, 299 insertions(+), 425 deletions(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_worker.rs b/magicblock-accounts/src/remote_scheduled_commits_worker.rs index 00fb7c414..c62679868 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_worker.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_worker.rs @@ -84,7 +84,7 @@ impl RemoteScheduledCommitsWorker { { let bundle_signatures = match self .committor - .get_bundle_signatures(bundle_id) + .get_commit_signatures(bundle_id) .await { Ok(Ok(sig)) => sig, diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs index 545362839..a7e8ebea7 100644 --- a/magicblock-committor-service/src/commit/commit_using_buffer.rs +++ b/magicblock-committor-service/src/commit/commit_using_buffer.rs @@ -828,7 +828,7 @@ impl CommittorProcessor { authority: self.authority.pubkey(), pubkey, buffer_account_size, - blockhash: ephemeral_blockhash, + commit_id: 0, // TODO(edwin) }; const MAX_STALE_REALLOCS: u8 = 10; diff --git a/magicblock-committor-service/src/commit/committor_processor.rs b/magicblock-committor-service/src/commit/committor_processor.rs index 1247d6188..6b772702b 100644 --- a/magicblock-committor-service/src/commit/committor_processor.rs +++ b/magicblock-committor-service/src/commit/committor_processor.rs @@ -122,7 +122,7 @@ impl CommittorProcessor { message_id: u64, ) -> CommittorServiceResult> { let commit_statuses = - self.persister.get_commit_statuses_by_id(message_id)?; + self.persister.get_commit_statuses_by_message(message_id)?; Ok(commit_statuses) } @@ -130,7 +130,7 @@ impl CommittorProcessor { &self, commit_id: u64, ) -> CommittorServiceResult> { - let signatures = self.persister.get_signatures(commit_id)?; + let signatures = self.persister.get_signatures_by_commit(commit_id)?; Ok(signatures) } @@ -153,226 +153,4 @@ impl CommittorProcessor { // TODO(edwin): handle } } - - pub(crate) async fn process_ixs_chunks( - &self, - ixs_chunks: Vec>, - chunked_close_ixs: Option>>, - table_mania: Option<&TableMania>, - owners: &HashMap, - ) -> ( - Vec<(Signature, Vec<(CommitInfo, InstructionsKind)>)>, - Vec<(Option, Vec)>, - ) { - let latest_blockhash = - match self.magicblock_rpc_client.get_latest_blockhash().await { - Ok(bh) => bh, - Err(err) => { - error!( - "Failed to get latest blockhash to process buffers: {:?}", - err - ); - // If we fail to get this blockhash we need to report all process - // instructions as failed - let commit_infos = ixs_chunks - .into_iter() - .map(|ixs_chunk| { - ( - None::, - ixs_chunk - .into_iter() - .map(|ixs| ixs.commit_info) - .collect::>(), - ) - }) - .collect::>(); - return (vec![], commit_infos); - } - }; - - let mut join_set = JoinSet::new(); - let successes = Arc::< - Mutex)>>, - >::default(); - let failures = - Arc::, Vec)>>>::default(); - for ixs_chunk in ixs_chunks { - let authority = self.authority.insecure_clone(); - let rpc_client = self.magicblock_rpc_client.clone(); - let compute_budget = - self.compute_budget_config.buffer_process_and_close_budget(); - let successes = successes.clone(); - let failures = failures.clone(); - let owners = owners.clone(); - let table_mania = table_mania.cloned(); - join_set.spawn(process_ixs_chunk( - ixs_chunk, - compute_budget, - authority, - rpc_client, - successes, - failures, - table_mania, - owners, - latest_blockhash, - )); - } - join_set.join_all().await; - - if let Some(chunked_close_ixs) = chunked_close_ixs { - if log::log_enabled!(log::Level::Trace) { - let ix_count = - chunked_close_ixs.iter().map(|x| x.len()).sum::(); - trace!( - "Processing {} close instruction chunk(s) with a total of {} instructions", - chunked_close_ixs.len(), - ix_count - ); - } - let latest_blockhash = match self - .magicblock_rpc_client - .get_latest_blockhash() - .await - { - Ok(bh) => Some(bh), - Err(err) => { - // If we fail to close the buffers then the commits were processed and we - // should not retry them, however eventually we'd want to close those buffers - error!( - "Failed to get latest blockhash to close buffer: {:?}", - err - ); - let commit_infos = chunked_close_ixs - .iter() - .map(|ixs_chunk| { - ixs_chunk - .iter() - .map(|ixs| ixs.commit_info.clone()) - .collect::>() - }) - .collect::>(); - error!("Therefore failed to close buffers for the following committed accounts: {:#?}", commit_infos); - None - } - }; - - if let Some(latest_blockhash) = latest_blockhash { - let mut join_set = JoinSet::new(); - let failures = Arc::< - Mutex, Vec)>>, - >::default(); - for ixs_chunk in chunked_close_ixs { - let authority = self.authority.insecure_clone(); - let rpc_client = self.magicblock_rpc_client.clone(); - let table_mania = table_mania.cloned(); - let owners = owners.clone(); - let compute_budget = - self.compute_budget_config.buffer_close_budget(); - // We ignore close successes - let successes = Default::default(); - // We only log close failures since the commit was processed successfully - let failures = failures.clone(); - join_set.spawn(process_ixs_chunk( - ixs_chunk, - compute_budget, - authority, - rpc_client, - successes, - failures, - table_mania, - owners, - latest_blockhash, - )); - } - join_set.join_all().await; - if !failures - .lock() - .expect("close failures mutex poisoned") - .is_empty() - { - error!("Failed to to close some buffers: {:?}", failures); - } - } - } - - let successes = Arc::try_unwrap(successes) - .expect("successes mutex still has multiple owners") - .into_inner() - .expect("successes mutex was poisoned"); - let failures = Arc::try_unwrap(failures) - .expect("failures mutex still has multiple owners") - .into_inner() - .expect("failures mutex was poisoned"); - - (successes, failures) - } -} - -/// Processes a single chunk of instructions, sending them as a transaction. -/// Updates the shared success or failure lists based on the transaction outcome. -#[allow(clippy::type_complexity, clippy::too_many_arguments)] -pub(crate) async fn process_ixs_chunk( - ixs_chunk: Vec, - compute_budget: ComputeBudget, - authority: Keypair, - rpc_client: MagicblockRpcClient, - successes: Arc< - Mutex)>>, - >, - failures: Arc, Vec)>>>, - table_mania: Option, - owners: HashMap, - latest_blockhash: Hash, -) { - let mut ixs = vec![]; - let mut commit_infos = vec![]; - for ix_chunk in ixs_chunk.into_iter() { - ixs.extend(ix_chunk.instructions); - commit_infos.push((ix_chunk.commit_info, ix_chunk.kind)); - } - let ixs_len = ixs.len(); - let table_mania_setup = table_mania.as_ref().map(|table_mania| { - let committees = commit_infos - .iter() - .map(|(x, _)| x.pubkey()) - .collect::>(); - let keys_from_table = - lookup_table_keys(&authority, &committees, &owners); - (table_mania, keys_from_table) - }); - let compute_budget_ixs = compute_budget.instructions(commit_infos.len()); - match send_and_confirm( - rpc_client, - &authority, - [compute_budget_ixs, ixs].concat(), - "process commitable and/or close pdas".to_string(), - Some(latest_blockhash), - MagicBlockSendTransactionConfig::ensure_committed(), - table_mania_setup, - ) - .await - { - Ok(sig) => { - successes - .lock() - .expect("ix successes mutex poisoned") - .push((sig, commit_infos)); - } - Err(err) => { - error!( - "Processing {} instructions for {} commit infos {:?}", - ixs_len, - commit_infos.len(), - err - ); - let commit_infos = commit_infos - .into_iter() - .map(|(commit_info, _)| commit_info) - .collect(); - failures - .lock() - .expect("ix failures mutex poisoned") - .push((err.signature(), commit_infos)); - } - } } diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 8e75cf23b..b0a3a4a11 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -3,7 +3,7 @@ use std::{ sync::{Arc, Mutex}, }; -use log::{info, trace, warn}; +use log::{error, info, trace, warn}; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; @@ -39,12 +39,10 @@ pub type BroadcasteddMessageExecutionResult = MessageExecutorResult< >; // TODO(edwin): reduce num of params: 1,2,3, could be united -pub(crate) struct CommitSchedulerWorker { +pub(crate) struct CommitSchedulerWorker { db: Arc, l1_messages_persister: P, - rpc_client: MagicblockRpcClient, // 1. - table_mania: TableMania, // 2. - compute_budget_config: ComputeBudgetConfig, // 3. + executor_factory: L1MessageExecutorFactory

, commit_id_tracker: CommitIdTracker, receiver: mpsc::Receiver, @@ -54,7 +52,11 @@ pub(crate) struct CommitSchedulerWorker { inner: Arc>, } -impl CommitSchedulerWorker { +impl CommitSchedulerWorker +where + D: DB, + P: L1MessagesPersisterIface, +{ pub fn new( db: Arc, l1_messages_persister: P, @@ -66,13 +68,18 @@ impl CommitSchedulerWorker { // Number of executors that can send messages in parallel to L1 const NUM_OF_EXECUTORS: u8 = 50; - Self { - db, - l1_messages_persister, + let executor_factory = L1MessageExecutorFactory { rpc_client: rpc_client.clone(), table_mania, compute_budget_config, - commit_id_tracker: CommitIdTracker::new(rpc_client), + l1_messages_persister: l1_messages_persister.clone(), + }; + let commit_id_tracker = CommitIdTracker::new(rpc_client); + Self { + db, + l1_messages_persister, + executor_factory, + commit_id_tracker, receiver, notify: Arc::new(Notify::new()), executors_semaphore: Arc::new(Semaphore::new( @@ -118,25 +125,31 @@ impl CommitSchedulerWorker { .expect(SEMAPHORE_CLOSED_MSG); // Prepare data for execution - let commit_ids = - if let Some(pubkeys) = l1_message.get_committed_pubkeys() { - self.commit_id_tracker - .next_commit_ids(&pubkeys) - .await - .unwrap() - } else { - // Pure L1Action, no commit ids used - HashMap::new() - }; - let executor = - L1MessageExecutor::::new_v1( - self.rpc_client.clone(), - self.table_mania.clone(), - self.compute_budget_config.clone(), - self.l1_messages_persister.clone(), - ); + let commit_ids = if let Some(pubkeys) = + l1_message.get_committed_pubkeys() + { + let commit_ids = self + .commit_id_tracker + .next_commit_ids(&pubkeys) + .await + .unwrap(); + // Persist data + commit_ids + .iter() + .for_each(|(pubkey, commit_id) | { + if let Err(err) = self.l1_messages_persister.set_commit_id(l1_message.id, pubkey, *commit_id) { + error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.id, pubkey, err); + } + }); + + commit_ids + } else { + // Pure L1Action, no commit ids used + HashMap::new() + }; // Spawn executor + let executor = self.executor_factory.create_executor(); let inner = self.inner.clone(); let notify = self.notify.clone(); tokio::spawn(Self::execute( @@ -219,8 +232,11 @@ impl CommitSchedulerWorker { .execute(l1_message.clone(), commit_ids) .await .map_err(|err| Arc::new(err)); - // TODO: unwrap - result_sender.send(result).unwrap(); + + // Broadcast result to subscribers + if let Err(err) = result_sender.send(result) { + error!("Failed to broadcast result: {}", err); + } // Remove executed task from Scheduler to unblock other messages inner_scheduler .lock() @@ -232,12 +248,26 @@ impl CommitSchedulerWorker { // Free worker drop(execution_permit); } +} - async fn deduce_commit_ids( - &mut self, - l1_message: &ScheduledL1Message, - ) -> HashMap { - todo!() +/// Dummy struct to implify signatur +struct L1MessageExecutorFactory

{ + rpc_client: MagicblockRpcClient, + table_mania: TableMania, + compute_budget_config: ComputeBudgetConfig, + l1_messages_persister: P, +} + +impl L1MessageExecutorFactory

{ + pub fn create_executor( + &self, + ) -> L1MessageExecutor { + L1MessageExecutor::::new_v1( + self.rpc_client.clone(), + self.table_mania.clone(), + self.compute_budget_config.clone(), + self.l1_messages_persister.clone(), + ) } } diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index ebe38bcd9..03f56241a 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -31,43 +31,40 @@ use crate::{ #[derive(Clone, Debug)] pub struct ExecutionOutput {} -pub(crate) struct L1MessageExecutor { +pub(crate) struct L1MessageExecutor { authority: Keypair, rpc_client: MagicblockRpcClient, transaction_preparator: T, - l1_messages_persister: P, } -impl L1MessageExecutor +impl L1MessageExecutor where T: TransactionPreparator, - P: L1MessagesPersisterIface, { pub fn new_v1( rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, - l1_messages_persister: P, - ) -> L1MessageExecutor { + ) -> L1MessageExecutor { let authority = validator_authority(); let transaction_preparator = TransactionPreparatorV1::new( rpc_client.clone(), table_mania, compute_budget_config, ); - L1MessageExecutor:: { + L1MessageExecutor:: { authority, rpc_client, transaction_preparator, - l1_messages_persister, } } /// Executes message on L1 - pub async fn execute( + pub async fn execute( &self, l1_message: ScheduledL1Message, commit_ids: HashMap, + persister: Option

, ) -> MessageExecutorResult { // Commit message first self.commit(&l1_message, commit_ids).await?; @@ -78,10 +75,11 @@ where } /// Executes Commit stage - async fn commit( + async fn commit( &self, l1_message: &ScheduledL1Message, commit_ids: HashMap, + persister: Option

, ) -> MessageExecutorResult<()> { let prepared_message = self .transaction_preparator @@ -89,7 +87,7 @@ where &self.authority, l1_message, commit_ids, - &self.l1_messages_persister, + &persister, ) .await?; @@ -97,9 +95,10 @@ where } /// Executes Finalize stage - async fn finalize( + async fn finalize( &self, l1_message: &ScheduledL1Message, + persister: Option

, ) -> MessageExecutorResult<()> { let rent_reimbursement = self.authority.pubkey(); let prepared_message = self @@ -108,7 +107,7 @@ where &self.authority, &rent_reimbursement, l1_message, - &self.l1_messages_persister, + &persister, ) .await?; diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 538d89dd6..ebd92ecc7 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -31,24 +31,31 @@ pub trait L1MessagesPersisterIface: Send + Sync + Clone + 'static { pubkey: &Pubkey, commit_id: u64, ) -> CommitPersistResult<()>; - fn update_status( + fn update_status_by_message( &self, message_id: u64, pubkey: &Pubkey, status: CommitStatus, ) -> CommitPersistResult<()>; - fn get_commit_statuses_by_id( + fn update_status_by_commit( + &self, + commit_id: u64, + pubkey: &Pubkey, + status: CommitStatus, + ) -> CommitPersistResult<()>; + fn get_commit_statuses_by_message( &self, message_id: u64, ) -> CommitPersistResult>; - fn get_commit_status( + fn get_commit_status_by_message( &self, message_id: u64, pubkey: &Pubkey, ) -> CommitPersistResult>; - fn get_signatures( + fn get_signatures_by_commit( &self, - commit_ud: u64, + commit_id: u64, + pubkey: &Pubkey, ) -> CommitPersistResult>; // fn finalize_l1_message(&self blockhash: Hash) -> CommitPersistResult<()>; } @@ -166,7 +173,7 @@ impl L1MessagesPersisterIface for L1MessagePersister { .set_commit_id(message_id, pubkey, commit_id) } - fn update_status( + fn update_status_by_message( &self, message_id: u64, pubkey: &Pubkey, @@ -175,10 +182,22 @@ impl L1MessagesPersisterIface for L1MessagePersister { self.commits_db .lock() .expect(POISONED_MUTEX_MSG) - .update_commit_status(message_id, pubkey, &status) + .update_status_by_message(message_id, pubkey, &status) } - fn get_commit_statuses_by_id( + fn update_status_by_commit( + &self, + commit_id: u64, + pubkey: &Pubkey, + status: CommitStatus, + ) -> CommitPersistResult<()> { + self.commits_db + .lock() + .expect(POISONED_MUTEX_MSG) + .update_status_by_commit(commit_id, pubkey, &status) + } + + fn get_commit_statuses_by_message( &self, message_id: u64, ) -> CommitPersistResult> { @@ -188,7 +207,7 @@ impl L1MessagesPersisterIface for L1MessagePersister { .get_commit_statuses_by_id(message_id) } - fn get_commit_status( + fn get_commit_status_by_message( &self, message_id: u64, pubkey: &Pubkey, @@ -199,14 +218,15 @@ impl L1MessagesPersisterIface for L1MessagePersister { .get_commit_status(message_id, pubkey) } - fn get_signatures( + fn get_signatures_by_commit( &self, - commit_ud: u64, + commit_id: u64, + pubkey: &Pubkey, ) -> CommitPersistResult> { self.commits_db .lock() .expect(POISONED_MUTEX_MSG) - .get_signatures(commit_ud) + .get_signatures_by_commit(commit_id, pubkey) } // fn finalize_l1_message(&self, blockhash: Hash) -> CommitPersistResult<()> { @@ -302,18 +322,18 @@ mod tests { }, )); persister - .update_status(&reqid, &pubkey1, new_status.clone()) + .update_status_by_message(&reqid, &pubkey1, new_status.clone()) .unwrap(); let updated_row = persister - .get_commit_status(&reqid, &pubkey1) + .get_commit_status_by_message(&reqid, &pubkey1) .unwrap() .unwrap(); assert_eq!(updated_row.commit_status, new_status); let signatures = persister - .get_signatures(new_status.bundle_id().unwrap()) + .get_signatures_by_commit(new_status.bundle_id().unwrap()) .unwrap() .unwrap(); assert_eq!(signatures.processed_signature, process_signature); diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 9a941aa35..5ae91092b 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -151,14 +151,77 @@ impl CommittsDb { // ----------------- // Methods affecting both tables // ----------------- - pub fn update_commit_status( + pub fn update_status_by_message( &mut self, message_id: u64, pubkey: &Pubkey, status: &CommitStatus, ) -> CommitPersistResult<()> { + let query = "UPDATE commit_status + SET + commit_status = ?1, + commit_strategy = ?3, + processed_signature = ?4, + finalized_signature = ?5, + undelegated_signature = ?6 + WHERE + pubkey = ?7 AND message_id = ?8"; + let tx = self.conn.transaction()?; - Self::update_commit_status_impl(&tx, message_id, pubkey, status)?; + let stmt = &mut tx.prepare(query)?; + stmt.execute(params![ + status.as_str(), + status.commit_strategy().as_str(), + status.signatures().map(|s| s.process_signature.to_string()), + status + .signatures() + .and_then(|s| s.finalize_signature) + .map(|s| s.to_string()), + status + .signatures() + .and_then(|s| s.undelegate_signature) + .map(|s| s.to_string()), + pubkey.to_string(), + message_id + ])?; + tx.commit()?; + + Ok(()) + } + + pub fn update_status_by_commit( + &mut self, + commit_id: u64, + pubkey: &Pubkey, + status: &CommitStatus, + ) -> CommitPersistResult<()> { + let query = "UPDATE commit_status + SET + commit_status = ?1, + commit_strategy = ?3, + processed_signature = ?4, + finalized_signature = ?5, + undelegated_signature = ?6 + WHERE + pubkey = ?7 AND commit_id = ?8"; + + let tx = self.conn.transaction()?; + let stmt = &mut tx.prepare(query)?; + stmt.execute(params![ + status.as_str(), + status.commit_strategy().as_str(), + status.signatures().map(|s| s.process_signature.to_string()), + status + .signatures() + .and_then(|s| s.finalize_signature) + .map(|s| s.to_string()), + status + .signatures() + .and_then(|s| s.undelegate_signature) + .map(|s| s.to_string()), + pubkey.to_string(), + commit_id + ])?; tx.commit()?; Ok(()) @@ -286,40 +349,6 @@ impl CommittsDb { Ok(()) } - fn update_commit_status_impl( - tx: &Transaction<'_>, - message_id: u64, - pubkey: &Pubkey, - status: &CommitStatus, - ) -> CommitPersistResult<()> { - let query = "UPDATE commit_status - SET - commit_status = ?1, - commit_strategy = ?3, - processed_signature = ?4, - finalized_signature = ?5, - undelegated_signature = ?6 - WHERE - pubkey = ?7 AND message_id = ?8"; - let stmt = &mut tx.prepare(query)?; - stmt.execute(params![ - status.as_str(), - status.commit_strategy().as_str(), - status.signatures().map(|s| s.process_signature.to_string()), - status - .signatures() - .and_then(|s| s.finalize_signature) - .map(|s| s.to_string()), - status - .signatures() - .and_then(|s| s.undelegate_signature) - .map(|s| s.to_string()), - pubkey.to_string(), - message_id - ])?; - Ok(()) - } - #[cfg(test)] fn get_commit_statuses_by_pubkey( &self, @@ -369,18 +398,19 @@ impl CommittsDb { Ok(()) } - pub fn get_signatures( + pub fn get_signatures_by_commit( &self, commit_id: u64, + pubkey: &Pubkey, ) -> CommitPersistResult> { let query = "SELECT processed_signature, finalized_signature, undelegated_signature, created_at FROM commit_status - WHERE commit_id = ?1 + WHERE commit_id = ?1 AND pubkey = ?2 LIMIT 1"; let mut stmt = self.conn.prepare(&query)?; - let mut rows = stmt.query(params![commit_id])?; + let mut rows = stmt.query(params![commit_id, pubkey])?; let result = rows .next()? @@ -713,7 +743,7 @@ mod test { // Update the statuses let new_failing_status = CommitStatus::FailedProcess((22, CommitStrategy::FromBuffer, None)); - db.update_commit_status( + db.update_status_by_message( failing_commit_row.message_id, &failing_commit_row.pubkey, &new_failing_status, @@ -729,7 +759,7 @@ mod test { let success_signatures_row = create_message_signature_row(&new_success_status); let success_signatures = success_signatures_row.clone().unwrap(); - db.update_commit_status( + db.update_status_by_message( success_commit_row.message_id, &success_commit_row.pubkey, &new_success_status, @@ -748,7 +778,7 @@ mod test { .unwrap() .unwrap(); assert_eq!(succeeded_commit_row.commit_status, new_success_status); - let signature_row = db.get_signatures(33).unwrap().unwrap(); + let signature_row = db.get_signatures_by_commit(33).unwrap().unwrap(); assert_eq!( signature_row.processed_signature, success_signatures.processed_signature, diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 88feb7fb9..78eab37ee 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -49,20 +49,18 @@ pub enum CommittorMessage { respond_to: oneshot::Sender<()>, }, CommitChangeset { - /// Called once the changeset has been committed - respond_to: oneshot::Sender>, - /// The changeset to commit + /// The [`ScheduledL1Message`]s to commit l1_messages: Vec, }, GetCommitStatuses { respond_to: oneshot::Sender>>, - reqid: String, + message_id: u64, }, - GetBundleSignatures { + GetCommitSignatures { respond_to: oneshot::Sender>>, - bundle_id: u64, + commit_id: u64, }, GetLookupTables { respond_to: oneshot::Sender, @@ -126,28 +124,24 @@ impl CommittorActor { error!("Failed to send response {:?}", e); } } - CommitChangeset { - l1_messages, + CommitChangeset { l1_messages } => { + self.processor.commit_l1_messages(l1_messages).await; + } + GetCommitStatuses { + message_id, respond_to, } => { - let reqid = - self.processor.commit_l1_messages(l1_messages).await; - if let Err(e) = respond_to.send(reqid) { - error!("Failed to send response {:?}", e); - } - } - GetCommitStatuses { reqid, respond_to } => { let commit_statuses = - self.processor.get_commit_statuses(&reqid); + self.processor.get_commit_statuses(message_id); if let Err(e) = respond_to.send(commit_statuses) { error!("Failed to send response {:?}", e); } } - GetBundleSignatures { - bundle_id, + GetCommitSignatures { + commit_id, respond_to, } => { - let sig = self.processor.get_signature(bundle_id); + let sig = self.processor.get_signature(commit_id); if let Err(e) = respond_to.send(sig) { error!("Failed to send response {:?}", e); } @@ -240,15 +234,15 @@ impl CommittorService { rx } - pub fn get_bundle_signatures( + pub fn get_commit_signatures( &self, - bundle_id: u64, + commit_id: u64, ) -> oneshot::Receiver>> { let (tx, rx) = oneshot::channel(); - self.try_send(CommittorMessage::GetBundleSignatures { + self.try_send(CommittorMessage::GetCommitSignatures { respond_to: tx, - bundle_id, + commit_id, }); rx } @@ -308,25 +302,25 @@ impl L1MessageCommittor for CommittorService { fn get_commit_statuses( &self, - reqid: String, + message_id: u64, ) -> oneshot::Receiver>> { let (tx, rx) = oneshot::channel(); self.try_send(CommittorMessage::GetCommitStatuses { respond_to: tx, - reqid, + message_id, }); rx } - fn get_bundle_signatures( + fn get_commit_signatures( &self, - bundle_id: u64, + commit_id: u64, ) -> oneshot::Receiver>> { let (tx, rx) = oneshot::channel(); - self.try_send(CommittorMessage::GetBundleSignatures { + self.try_send(CommittorMessage::GetCommitSignatures { respond_to: tx, - bundle_id, + commit_id, }); rx } @@ -355,8 +349,8 @@ pub trait L1MessageCommittor: Send + Sync + 'static { message_id: u64, ) -> oneshot::Receiver>>; - /// Gets signatures of commits processed as part of the bundle with the provided bundle_id - fn get_bundle_signatures( + /// Gets signatures for commit of particular accounts + fn get_commit_signatures( &self, bundle_id: u64, ) -> oneshot::Receiver>>; diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index 36ec3a82c..f2e484898 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -95,7 +95,7 @@ impl L1MessageCommittor for ChangesetCommittorStub { rx } - fn get_bundle_signatures( + fn get_commit_signatures( &self, bundle_id: u64, ) -> tokio::sync::oneshot::Receiver< diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 7c1d5e794..3d9fbe04b 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -31,8 +31,8 @@ impl TasksBuilder for TaskBuilderV1 { /// Returns [`Task`]s for Commit stage fn commit_tasks( l1_message: &ScheduledL1Message, - commit_ids: HashMap, - ) -> Vec> { + commit_ids: &HashMap, + ) -> TaskBuilderResult>> { let (accounts, allow_undelegation) = match &l1_message.l1_message { MagicL1Message::L1Actions(actions) => { return actions @@ -49,7 +49,7 @@ impl TasksBuilder for TaskBuilderV1 { } }; - accounts + let tasks = accounts .into_iter() .map(|account| { if let Some(commit_id) = commit_ids.get(&account.pubkey) { @@ -59,12 +59,12 @@ impl TasksBuilder for TaskBuilderV1 { committed_account: account.clone(), })) as Box) } else { - // TODO(edwin): proper error - Err(()) + Err(Error::MissingCommitIdError(account.pubkey)) } }) - .collect::>() - .unwrap() // TODO(edwin): remove + .collect::>()?; + + Ok(tasks) } /// Returns [`Task`]s for Finalize stage @@ -147,3 +147,11 @@ impl TasksBuilder for TaskBuilderV1 { } } } + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("Missing commit id for pubkey: {0}")] + MissingCommitIdError(Pubkey), +} + +pub type TaskBuilderResult = Result; diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index f81937802..0f89dc539 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -21,6 +21,8 @@ use crate::{ }; pub struct TaskPreparationInfo { + pub commit_id: u64, + pub pubkey: Pubkey, pub chunks_pda: Pubkey, pub buffer_pda: Pubkey, pub init_instruction: Instruction, @@ -251,6 +253,8 @@ impl L1Task for BufferTask { .collect::>(); Some(TaskPreparationInfo { + commit_id: commit_task.commit_id, + pubkey: commit_task.committed_account.pubkey, chunks_pda, buffer_pda, init_instruction, diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 6753d8bc2..ae7a91ef7 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -24,6 +24,7 @@ use solana_sdk::{ use tokio::time::sleep; use crate::{ + persist::{CommitStatus, L1MessagesPersisterIface}, tasks::{ task_strategist::TransactionStrategy, tasks::{L1Task, TaskPreparationInfo}, @@ -55,10 +56,11 @@ impl DeliveryPreparator { } /// Prepares buffers and necessary pieces for optimized TX - pub async fn prepare_for_delivery( + pub async fn prepare_for_delivery( &self, authority: &Keypair, strategy: &TransactionStrategy, + persister: &Option

, ) -> DeliveryPreparatorResult> { let preparation_futures = strategy .optimized_tasks @@ -78,10 +80,11 @@ impl DeliveryPreparator { /// Prepares necessary parts for TX if needed, otherwise returns immediately // TODO(edwin): replace with interfaces - async fn prepare_task( + async fn prepare_task( &self, authority: &Keypair, task: &Box, + persister: Option

, ) -> DeliveryPreparatorResult<()> { let Some(preparation_info) = task.preparation_info(&authority.pubkey()) else { @@ -99,6 +102,23 @@ impl DeliveryPreparator { self.write_buffer_with_retries(authority, &preparation_info, 5) .await?; + // Persist that buffer account initiated successfully + if let Some(persister) = &persister { + let update_status = CommitStatus::BufferAndChunkFullyInitialized( + preparation_info.commit_id, + ); + if let Err(err) = persister.update_status_by_message( + preparation_info.commit_id, + &preparation_info.pubkey, + update_status.clone(), + ) { + error!( + "Failed to persist new status {}: {}", + update_status, err + ); + } + } + Ok(()) } diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preperator/error.rs index 24e0cdc80..59238f010 100644 --- a/magicblock-committor-service/src/transaction_preperator/error.rs +++ b/magicblock-committor-service/src/transaction_preperator/error.rs @@ -1,3 +1,4 @@ +use solana_pubkey::{pubkey, Pubkey}; use thiserror::Error; use crate::transaction_preperator::transaction_preparator::PreparatorVersion; @@ -8,6 +9,8 @@ pub enum Error { VersionError(PreparatorVersion), #[error("Failed to fit in single TX")] FailedToFitError, + #[error("Missing commit id for pubkey: {0}")] + MissingCommitIdError(Pubkey), #[error("InternalError: {0}")] InternalError(#[from] anyhow::Error), } @@ -22,4 +25,14 @@ impl From for Error { } } +impl From for Error { + fn from(value: crate::tasks::task_builder::Error) -> Self { + match value { + crate::tasks::task_builder::Error::MissingCommitIdError(pubkey) => { + Self::MissingCommitIdError(pubkey) + } + } + } +} + pub type PreparatorResult = Result; diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index b73657c5e..41edd72f6 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -49,7 +49,7 @@ pub trait TransactionPreparator { authority: &Keypair, l1_message: &ScheduledL1Message, commit_ids: HashMap, - l1_messages_persister: &P, + l1_messages_persister: &Option

, ) -> PreparatorResult; /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks @@ -60,7 +60,7 @@ pub trait TransactionPreparator { authority: &Keypair, rent_reimbursement: &Pubkey, l1_message: &ScheduledL1Message, - l1_messages_persister: &P, + l1_messages_persister: &Option

, ) -> PreparatorResult; } @@ -105,21 +105,36 @@ impl TransactionPreparator for TransactionPreparatorV1 { authority: &Keypair, l1_message: &ScheduledL1Message, commit_ids: HashMap, - l1_messages_persister: &P, + l1_messages_persister: &Option

, ) -> PreparatorResult { - // 1. create tasks - // 2. optimize to fit tx size. aka Delivery Strategy - // 3. Pre tx preparations. Create buffer accs + lookup tables - // 4. Build resulting TX to be executed - let tasks = TaskBuilderV1::commit_tasks(l1_message, commit_ids); - let tx_strategy = - TaskStrategist::build_strategy(tasks, &authority.pubkey())?; + // create tasks + let tasks = TaskBuilderV1::commit_tasks(l1_message, &commit_ids)?; + // optimize to fit tx size. aka Delivery Strategy + let tx_strategy = match TaskStrategist::build_strategy( + tasks, + &authority.pubkey(), + ) { + Ok(value) => Ok(value), + Err(err) => match err { + err + @ crate::tasks::task_strategist::Error::FailedToFitError => { + // TODO(edwin) + commit_ids.iter().for_each(|(pubkey, commit_id)| {}); + Err(err.into()) + } + }, + }?; + // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self .delivery_preparator - .prepare_for_delivery(authority, &tx_strategy) + .prepare_for_delivery( + authority, + &tx_strategy, + l1_messages_persister, + ) .await .unwrap(); // TODO: fix - + // Build resulting TX to be executed let message = TransactionUtils::assemble_tasks_tx( authority, &tx_strategy.optimized_tasks, @@ -135,12 +150,15 @@ impl TransactionPreparator for TransactionPreparatorV1 { authority: &Keypair, rent_reimbursement: &Pubkey, l1_message: &ScheduledL1Message, - l1_messages_persister: &P, + l1_messages_persister: &Option

, ) -> PreparatorResult { + // create tasks let tasks = TaskBuilderV1::finalize_tasks(l1_message, rent_reimbursement); + // optimize to fit tx size. aka Delivery Strategy let tx_strategy = TaskStrategist::build_strategy(tasks, &authority.pubkey())?; + // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self .delivery_preparator .prepare_for_delivery(authority, &tx_strategy) @@ -156,41 +174,3 @@ impl TransactionPreparator for TransactionPreparatorV1 { Ok(message) } } - -/// We have 2 stages for L1Message -/// 1. commit -/// 2. finalize -/// -/// Now, single "task" can be differently represented in 2 stage -/// In terms of transaction and so on - -/// We have: -/// Stages - type -/// Strategy - enum -/// Task - enum - -// Can [`Task`] have [`Strategy`] based on [`Stage`] -// We receive proposals and actions from users -// Those have to - -/// We get tasks we need to pass them through -/// Strategy: -// 1. Try to fit Vec into TX. save tx_size -// 2. Start optimizing -// 3. Find biggest ix -// 4. Replace with BufferedIx(maybe pop from Heap) -// 5. tx_size -= (og_size - buffered_size) -// 6. If doesn't fit - continue -// 7. If heap.is_empty() - doesn't fit with buffered -// 8. Apply lookup table -// 9. if fits - return Ok(tx), else return Err(Failed) - -// Committor flow: -// 1. Gets commits -// 2. Passes to Scheduler -// 3. Scheduler checks if any can run in parallel. Does scheduling basically -// 4. Calls TransactionPreparator for those -// 5. Executes TXs if all ok -// 6. Populates Persister with necessary data - -fn useless() {} diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs index a23ae4ee6..199119347 100644 --- a/magicblock-committor-service/src/transactions.rs +++ b/magicblock-committor-service/src/transactions.rs @@ -195,7 +195,6 @@ pub(crate) fn process_commits_ix( pubkey: &Pubkey, delegated_account_owner: &Pubkey, buffer_pda: &Pubkey, - commit_id: u64, commit_args: CommitStateFromBufferArgs, ) -> Instruction { dlp::instruction_builder::commit_state_from_buffer( @@ -234,8 +233,7 @@ pub(crate) fn process_and_close_ixs( buffer_pda, commit_args, ); - let close_ix = - close_buffers_ix(validator_auth, pubkey, ephemeral_blockhash); + let close_ix = close_buffers_ix(validator_auth, pubkey, 0); // TODO(edwin) vec![process_ix, close_ix] } From c87abac1fd147c36201d394e0ed977a31ec24d19 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 21 Jul 2025 16:22:45 +0900 Subject: [PATCH 106/199] feat: improving error handling --- .../src/commit_scheduler.rs | 2 +- .../commit_scheduler_worker.rs | 26 +-- .../src/l1_message_executor.rs | 159 +++++++++++------- magicblock-committor-service/src/lib.rs | 2 +- .../src/persist/types/commit_status.rs | 17 -- .../src/tasks/tasks.rs | 1 + .../delivery_preparator.rs | 89 ++++++---- .../src/transaction_preperator/error.rs | 4 + .../transaction_preparator.rs | 31 ++-- magicblock-committor-service/src/utils.rs | 45 +++++ 10 files changed, 234 insertions(+), 142 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index ab919d36a..90adc1651 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -32,7 +32,7 @@ impl CommitScheduler { pub fn new( rpc_client: MagicblockRpcClient, db: D, - l1_message_persister: P, + l1_message_persister: Option

, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, ) -> Self { diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index b0a3a4a11..fef60e73b 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -41,8 +41,8 @@ pub type BroadcasteddMessageExecutionResult = MessageExecutorResult< // TODO(edwin): reduce num of params: 1,2,3, could be united pub(crate) struct CommitSchedulerWorker { db: Arc, - l1_messages_persister: P, - executor_factory: L1MessageExecutorFactory

, + l1_messages_persister: Option

, + executor_factory: L1MessageExecutorFactory, commit_id_tracker: CommitIdTracker, receiver: mpsc::Receiver, @@ -59,7 +59,7 @@ where { pub fn new( db: Arc, - l1_messages_persister: P, + l1_messages_persister: Option

, rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, @@ -72,7 +72,6 @@ where rpc_client: rpc_client.clone(), table_mania, compute_budget_config, - l1_messages_persister: l1_messages_persister.clone(), }; let commit_id_tracker = CommitIdTracker::new(rpc_client); Self { @@ -150,10 +149,13 @@ where // Spawn executor let executor = self.executor_factory.create_executor(); + let persister = self.l1_messages_persister.clone(); let inner = self.inner.clone(); let notify = self.notify.clone(); + tokio::spawn(Self::execute( executor, + persister, l1_message, commit_ids, inner, @@ -220,7 +222,8 @@ where /// Wrapper on [`L1MessageExecutor`] that handles its results and drops execution permit async fn execute( - executor: L1MessageExecutor, + executor: L1MessageExecutor, + persister: Option

, l1_message: ScheduledL1Message, commit_ids: HashMap, inner_scheduler: Arc>, @@ -229,8 +232,9 @@ where notify: Arc, ) { let result = executor - .execute(l1_message.clone(), commit_ids) + .execute(l1_message.clone(), commit_ids, persister) .await + .inspect_err(|err| error!("Failed to execute L1Message: {:?}", err)) .map_err(|err| Arc::new(err)); // Broadcast result to subscribers @@ -251,22 +255,20 @@ where } /// Dummy struct to implify signatur -struct L1MessageExecutorFactory

{ +struct L1MessageExecutorFactory { rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, - l1_messages_persister: P, } -impl L1MessageExecutorFactory

{ +impl L1MessageExecutorFactory { pub fn create_executor( &self, - ) -> L1MessageExecutor { - L1MessageExecutor::::new_v1( + ) -> L1MessageExecutor { + L1MessageExecutor::::new_v1( self.rpc_client.clone(), self.table_mania.clone(), self.compute_budget_config.clone(), - self.l1_messages_persister.clone(), ) } } diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index 03f56241a..14249040d 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -13,23 +13,27 @@ use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; use solana_sdk::{ message::VersionedMessage, - signature::Keypair, + signature::{Keypair, Signature}, signer::{Signer, SignerError}, transaction::VersionedTransaction, }; use crate::{ - persist::L1MessagesPersisterIface, + persist::{CommitStatus, L1MessagesPersisterIface}, transaction_preperator::transaction_preparator::{ TransactionPreparator, TransactionPreparatorV1, }, + utils::persist_status_update_set, ComputeBudgetConfig, }; // TODO(edwin): define struct // (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] #[derive(Clone, Debug)] -pub struct ExecutionOutput {} +pub struct ExecutionOutput { + commit_signature: Signature, + finalize_signature: Signature, +} pub(crate) struct L1MessageExecutor { authority: Keypair, @@ -66,60 +70,77 @@ where commit_ids: HashMap, persister: Option

, ) -> MessageExecutorResult { - // Commit message first - self.commit(&l1_message, commit_ids).await?; - // At the moment validator finalizes right away - // In the future there will be a challenge window - self.finalize(&l1_message).await?; - Ok(ExecutionOutput {}) - } + // Update tasks status to Pending + { + let update_status = CommitStatus::Pending; + persist_status_update_set(&persister, &commit_ids, update_status); + } - /// Executes Commit stage - async fn commit( - &self, - l1_message: &ScheduledL1Message, - commit_ids: HashMap, - persister: Option

, - ) -> MessageExecutorResult<()> { - let prepared_message = self - .transaction_preparator - .prepare_commit_tx( - &self.authority, - l1_message, - commit_ids, - &persister, - ) - .await?; + // Commit stage + let commit_signature = { + // Prepare everything for commit + let prepared_message = self + .transaction_preparator + .prepare_commit_tx( + &self.authority, + &l1_message, + commit_ids, + &persister, + ) + .await?; - self.send_prepared_message(prepared_message).await - } + // Commit + self.send_prepared_message(prepared_message).await.map_err( + |(err, signature)| Error::FailedToCommitError { + err, + signature, + }, + )? + }; - /// Executes Finalize stage - async fn finalize( - &self, - l1_message: &ScheduledL1Message, - persister: Option

, - ) -> MessageExecutorResult<()> { - let rent_reimbursement = self.authority.pubkey(); - let prepared_message = self - .transaction_preparator - .prepare_finalize_tx( - &self.authority, - &rent_reimbursement, - l1_message, - &persister, - ) - .await?; + // Finalize stage + // At the moment validator finalizes right away + // In the future there will be a challenge window + let finalize_signature = { + // Prepare eveything for finalize + let rent_reimbursement = self.authority.pubkey(); + let prepared_message = self + .transaction_preparator + .prepare_finalize_tx( + &self.authority, + &rent_reimbursement, + &l1_message, + &persister, + ) + .await?; + + // Finalize + self.send_prepared_message(prepared_message).await.map_err( + |(err, finalize_signature)| Error::FailedToFinalizeError { + err, + commit_signature, + finalize_signature, + }, + )? + }; - self.send_prepared_message(prepared_message).await + Ok(ExecutionOutput { + commit_signature, + finalize_signature, + }) } /// Shared helper for sending transactions async fn send_prepared_message( &self, mut prepared_message: VersionedMessage, - ) -> MessageExecutorResult<()> { - let latest_blockhash = self.rpc_client.get_latest_blockhash().await?; + ) -> MessageExecutorResult)> + { + let latest_blockhash = self + .rpc_client + .get_latest_blockhash() + .await + .map_err(|err| (err.into(), None))?; match &mut prepared_message { VersionedMessage::V0(value) => { value.recent_blockhash = latest_blockhash; @@ -130,30 +151,52 @@ where } }; - let transaction = VersionedTransaction::try_new( - prepared_message, - &[&self.authority], - )?; - self.rpc_client + let transaction = + VersionedTransaction::try_new(prepared_message, &[&self.authority]) + .map_err(|err| (err.into(), None))?; + let result = self + .rpc_client .send_transaction( &transaction, &MagicBlockSendTransactionConfig::ensure_committed(), ) - .await?; + .await + .map_err(|err| { + let signature = err.signature(); + (err.into(), signature) + })?; - Ok(()) + Ok(result.into_signature()) } } -// TODO(edwin): properly define #[derive(thiserror::Error, Debug)] -pub enum Error { +pub enum InternalError { #[error("SignerError: {0}")] SignerError(#[from] SignerError), - #[error("PreparatorError: {0}")] - PreparatorError(#[from] crate::transaction_preperator::error::Error), #[error("MagicBlockRpcClientError: {0}")] MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), } +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("FailedToCommitError: {0}")] + FailedToCommitError { + #[source] + err: InternalError, + signature: Option, + }, + #[error("FailedToFinalizeError: {0}")] + FailedToFinalizeError { + #[source] + err: InternalError, + commit_signature: Signature, + finalize_signature: Option, + }, + #[error("PreparatorError: {0}")] + FailedToPrepareTransactionError( + #[from] crate::transaction_preperator::error::Error, + ), +} + pub type MessageExecutorResult = Result; diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 0ec77ddf4..5916b4a4f 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -16,7 +16,7 @@ mod transactions; mod types; mod undelegate; -mod commit_scheduler; +pub mod commit_scheduler; // TODO(edwin): define visibility pub(crate) mod l1_message_executor; #[cfg(feature = "dev-context-only-utils")] diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index 3be1d8cd5..607a5283f 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -35,8 +35,6 @@ pub enum CommitStatus { FailedProcess((u64, CommitStrategy, Option)), /// The commit was properly processed but the requested finalize transaction failed. FailedFinalize((u64, CommitStrategy, CommitStatusSignatures)), - /// The commit was properly processed and finalized but the requested undelegate transaction failed. - FailedUndelegate((u64, CommitStrategy, CommitStatusSignatures)), /// The commit was successfully processed and finalized. Succeeded((u64, CommitStrategy, CommitStatusSignatures)), } @@ -78,15 +76,6 @@ impl fmt::Display for CommitStatus { sigs ) } - CommitStatus::FailedUndelegate((bundle_id, strategy, sigs)) => { - write!( - f, - "FailedUndelegate({}, {}, {:?})", - bundle_id, - strategy.as_str(), - sigs - ) - } CommitStatus::Succeeded((bundle_id, strategy, sigs)) => { write!( f, @@ -143,9 +132,6 @@ impl TryFrom<(&str, u64, CommitStrategy, Option)> "FailedFinalize" => { Ok(FailedFinalize((commit_id, strategy, get_sigs()?))) } - "FailedUndelegate" => { - Ok(FailedUndelegate((commit_id, strategy, get_sigs()?))) - } "Succeeded" => Ok(Succeeded((commit_id, strategy, get_sigs()?))), _ => { Err(CommitPersistError::InvalidCommitStatus(status.to_string())) @@ -187,7 +173,6 @@ impl CommitStatus { PartOfTooLargeBundleToProcess(_) => "PartOfTooLargeBundleToProcess", FailedProcess(_) => "FailedProcess", FailedFinalize(_) => "FailedFinalize", - FailedUndelegate(_) => "FailedUndelegate", Succeeded(_) => "Succeeded", } } @@ -202,7 +187,6 @@ impl CommitStatus { | PartOfTooLargeBundleToProcess(bundle_id) | FailedProcess((bundle_id, _, _)) | FailedFinalize((bundle_id, _, _)) - | FailedUndelegate((bundle_id, _, _)) | Succeeded((bundle_id, _, _)) => Some(*bundle_id), Pending => None, } @@ -229,7 +213,6 @@ impl CommitStatus { PartOfTooLargeBundleToProcess(_) => CommitStrategy::Undetermined, FailedProcess((_, strategy, _)) => *strategy, FailedFinalize((_, strategy, _)) => *strategy, - FailedUndelegate((_, strategy, _)) => *strategy, Succeeded((_, strategy, _)) => *strategy, } } diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index 0f89dc539..a4f9e23e9 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -20,6 +20,7 @@ use crate::{ consts::MAX_WRITE_CHUNK_SIZE, tasks::budget_calculator::ComputeBudgetV1, }; +#[derive(Clone, Debug)] pub struct TaskPreparationInfo { pub commit_id: u64, pub pubkey: Pubkey, diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index ae7a91ef7..68b2776c8 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -29,6 +29,7 @@ use crate::{ task_strategist::TransactionStrategy, tasks::{L1Task, TaskPreparationInfo}, }, + utils::persist_status_update, ComputeBudgetConfig, }; @@ -65,16 +66,18 @@ impl DeliveryPreparator { let preparation_futures = strategy .optimized_tasks .iter() - .map(|task| self.prepare_task(authority, task)); + .map(|task| self.prepare_task(authority, task, persister)); let task_preparations = join_all(preparation_futures); let alts_preparations = self.prepare_lookup_tables(authority, &strategy.lookup_tables_keys); let (res1, res2) = join(task_preparations, alts_preparations).await; - res1.into_iter().collect::, _>>()?; + res1.into_iter() + .collect::, _>>() + .map_err(Error::FailedToPrepareBufferAccounts)?; - let lookup_tables = res2?; + let lookup_tables = res2.map_err(Error::FailedToCreateALTError)?; Ok(lookup_tables) } @@ -84,13 +87,24 @@ impl DeliveryPreparator { &self, authority: &Keypair, task: &Box, - persister: Option

, - ) -> DeliveryPreparatorResult<()> { + persister: &Option

, + ) -> DeliveryPreparatorResult<(), InternalError> { let Some(preparation_info) = task.preparation_info(&authority.pubkey()) else { return Ok(()); }; + // Persist as failed until rewritten + let update_status = CommitStatus::BufferAndChunkPartiallyInitialized( + preparation_info.commit_id, + ); + persist_status_update( + persister, + &preparation_info.pubkey, + preparation_info.commit_id, + update_status, + ); + // Initialize buffer account. Init + reallocs self.initialize_buffer_account( authority, @@ -98,26 +112,29 @@ impl DeliveryPreparator { &preparation_info, ) .await?; + // Persist initialization success + let update_status = + CommitStatus::BufferAndChunkInitialized(preparation_info.commit_id); + persist_status_update( + persister, + &preparation_info.pubkey, + preparation_info.commit_id, + update_status, + ); + // Writing chunks with some retries. Stol self.write_buffer_with_retries(authority, &preparation_info, 5) .await?; - // Persist that buffer account initiated successfully - if let Some(persister) = &persister { - let update_status = CommitStatus::BufferAndChunkFullyInitialized( - preparation_info.commit_id, - ); - if let Err(err) = persister.update_status_by_message( - preparation_info.commit_id, - &preparation_info.pubkey, - update_status.clone(), - ) { - error!( - "Failed to persist new status {}: {}", - update_status, err - ); - } - } + let update_status = CommitStatus::BufferAndChunkFullyInitialized( + preparation_info.commit_id, + ); + persist_status_update( + persister, + &preparation_info.pubkey, + preparation_info.commit_id, + update_status, + ); Ok(()) } @@ -128,7 +145,7 @@ impl DeliveryPreparator { authority: &Keypair, task: &dyn L1Task, preparation_info: &TaskPreparationInfo, - ) -> DeliveryPreparatorResult<()> { + ) -> DeliveryPreparatorResult<(), InternalError> { let preparation_instructions = task.instructions_from_info(&preparation_info); let preparation_instructions = preparation_instructions @@ -168,9 +185,9 @@ impl DeliveryPreparator { authority: &Keypair, info: &TaskPreparationInfo, max_retries: usize, - ) -> DeliveryPreparatorResult<()> { + ) -> DeliveryPreparatorResult<(), InternalError> { let mut last_error = - Error::InternalError(anyhow!("ZeroRetriesRequested")); + InternalError::InternalError(anyhow!("ZeroRetriesRequested")); for _ in 0..max_retries { let chunks = match self.rpc_client.get_account(&info.chunks_pda).await { @@ -182,7 +199,7 @@ impl DeliveryPreparator { "Chunks PDA does not exist for writing. pda: {}", info.chunks_pda ); - return Err(Error::InternalError(anyhow!( + return Err(InternalError::InternalError(anyhow!( "Chunks PDA does not exist for writing. pda: {}", info.chunks_pda ))); @@ -220,11 +237,11 @@ impl DeliveryPreparator { authority: &Keypair, chunks: &Chunks, write_instructions: &[Instruction], - ) -> DeliveryPreparatorResult<()> { + ) -> DeliveryPreparatorResult<(), InternalError> { if write_instructions.len() != chunks.count() { let err = anyhow!("Chunks count mismatches write instruction! chunks: {}, ixs: {}", write_instructions.len(), chunks.count()); error!("{}", err.to_string()); - return Err(Error::InternalError(err)); + return Err(InternalError::InternalError(err)); } let missing_chunks = chunks.get_missing_chunks(); @@ -259,9 +276,9 @@ impl DeliveryPreparator { &self, instructions: &[Instruction], authority: &Keypair, - ) -> DeliveryPreparatorResult<()> { + ) -> DeliveryPreparatorResult<(), InternalError> { let mut last_error = - Error::InternalError(anyhow!("ZeroRetriesRequested")); + InternalError::InternalError(anyhow!("ZeroRetriesRequested")); for _ in 0..MAX_RETRIES { match self.try_send_ixs(instructions, authority).await { Ok(()) => return Ok(()), @@ -277,7 +294,7 @@ impl DeliveryPreparator { &self, instructions: &[Instruction], authority: &Keypair, - ) -> DeliveryPreparatorResult<()> { + ) -> DeliveryPreparatorResult<(), InternalError> { let latest_block_hash = self.rpc_client.get_latest_blockhash().await?; let message = Message::try_compile( &authority.pubkey(), @@ -304,7 +321,8 @@ impl DeliveryPreparator { &self, authority: &Keypair, lookup_table_keys: &[Pubkey], - ) -> DeliveryPreparatorResult> { + ) -> DeliveryPreparatorResult, InternalError> + { let pubkeys = HashSet::from_iter(lookup_table_keys.iter().copied()); self.table_mania .reserve_pubkeys(authority, &pubkeys) @@ -328,9 +346,8 @@ impl DeliveryPreparator { } } -// TODO(edwin): properly define these for TransactionPreparator interface #[derive(thiserror::Error, Debug)] -pub enum Error { +pub enum InternalError { #[error("InternalError: {0}")] InternalError(anyhow::Error), #[error("BorshError: {0}")] @@ -345,4 +362,10 @@ pub enum Error { FailedToPrepareBufferError(#[from] MagicBlockRpcClientError), } +#[derive(thiserror::Error, Debug)] +pub enum Error { + FailedToPrepareBufferAccounts(#[source] InternalError), + FailedToCreateALTError(#[source] InternalError), +} + pub type DeliveryPreparatorResult = Result; diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preperator/error.rs index 59238f010..a7c27b0bf 100644 --- a/magicblock-committor-service/src/transaction_preperator/error.rs +++ b/magicblock-committor-service/src/transaction_preperator/error.rs @@ -11,6 +11,10 @@ pub enum Error { FailedToFitError, #[error("Missing commit id for pubkey: {0}")] MissingCommitIdError(Pubkey), + #[error("DeliveryPreparationError: {0}")] + DeliveryPreparationError( + #[from] crate::transaction_preperator::delivery_preparator::Error, + ), #[error("InternalError: {0}")] InternalError(#[from] anyhow::Error), } diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 41edd72f6..099f0eb5a 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -110,20 +110,8 @@ impl TransactionPreparator for TransactionPreparatorV1 { // create tasks let tasks = TaskBuilderV1::commit_tasks(l1_message, &commit_ids)?; // optimize to fit tx size. aka Delivery Strategy - let tx_strategy = match TaskStrategist::build_strategy( - tasks, - &authority.pubkey(), - ) { - Ok(value) => Ok(value), - Err(err) => match err { - err - @ crate::tasks::task_strategist::Error::FailedToFitError => { - // TODO(edwin) - commit_ids.iter().for_each(|(pubkey, commit_id)| {}); - Err(err.into()) - } - }, - }?; + let tx_strategy = + TaskStrategist::build_strategy(tasks, &authority.pubkey())?; // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self .delivery_preparator @@ -132,9 +120,9 @@ impl TransactionPreparator for TransactionPreparatorV1 { &tx_strategy, l1_messages_persister, ) - .await - .unwrap(); // TODO: fix - // Build resulting TX to be executed + .await?; + + // Build resulting TX to be executed let message = TransactionUtils::assemble_tasks_tx( authority, &tx_strategy.optimized_tasks, @@ -161,9 +149,12 @@ impl TransactionPreparator for TransactionPreparatorV1 { // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self .delivery_preparator - .prepare_for_delivery(authority, &tx_strategy) - .await - .unwrap(); // TODO: fix + .prepare_for_delivery( + authority, + &tx_strategy, + l1_messages_persister, + ) + .await?; let message = TransactionUtils::assemble_tasks_tx( authority, diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index ae8436347..0d1315f59 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -1,8 +1,16 @@ +use std::collections::HashMap; + +use log::error; use magicblock_program::magic_scheduled_l1_message::{ CommittedAccountV2, MagicL1Message, ScheduledL1Message, }; use solana_pubkey::Pubkey; +use crate::{ + persist::{CommitStatus, L1MessagesPersisterIface}, + tasks::tasks::TaskPreparationInfo, +}; + pub trait ScheduledMessageExt { fn get_committed_accounts(&self) -> Option<&Vec>; fn get_committed_pubkeys(&self) -> Option>; @@ -36,3 +44,40 @@ impl ScheduledMessageExt for ScheduledL1Message { } } } + +pub(crate) fn persist_status_update( + persister: &Option

, + pubkey: &Pubkey, + commit_id: u64, + update_status: CommitStatus, +) { + let Some(persister) = persister else { + return; + }; + if let Err(err) = persister.update_status_by_message( + commit_id, + pubkey, + update_status.clone(), + ) { + error!("Failed to persist new status {}: {}", update_status, err); + } +} + +pub(crate) fn persist_status_update_set( + persister: &Option

, + commit_ids_map: &HashMap, + update_status: CommitStatus, +) { + let Some(persister) = persister else { + return; + }; + commit_ids_map.iter().for_each(|(pubkey, commit_id)| { + if let Err(err) = persister.update_status_by_commit( + *commit_id, + pubkey, + update_status.clone(), + ) { + error!("Failed to persist new status {}: {}", update_status, err); + } + }); +} From 4013de1eb2f73ccf70f46d597eece6bafd01f35d Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 22 Jul 2025 16:27:05 +0900 Subject: [PATCH 107/199] feat: introduced visitor + compilation & persistor fixes --- .../commit_scheduler_worker.rs | 5 +- .../src/commit_stage.rs | 12 +- .../src/l1_message_executor.rs | 96 ++++++++++++++-- .../src/persist/commit_persister.rs | 20 +++- .../src/persist/db.rs | 107 ++++++++---------- .../src/persist/types/commit_status.rs | 65 ++++------- magicblock-committor-service/src/tasks/mod.rs | 2 + .../src/tasks/task_builder.rs | 7 +- .../src/tasks/task_strategist.rs | 33 +++++- .../src/tasks/task_visitors/mod.rs | 1 + .../tasks/task_visitors/persistor_visitor.rs | 70 ++++++++++++ .../src/tasks/tasks.rs | 35 +++++- .../src/tasks/visitor.rs | 6 + .../delivery_preparator.rs | 2 + .../src/transaction_preperator/error.rs | 6 +- .../transaction_preparator.rs | 20 ++-- 16 files changed, 345 insertions(+), 142 deletions(-) create mode 100644 magicblock-committor-service/src/tasks/task_visitors/mod.rs create mode 100644 magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs create mode 100644 magicblock-committor-service/src/tasks/visitor.rs diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index fef60e73b..f42dc7017 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -136,7 +136,10 @@ where commit_ids .iter() .for_each(|(pubkey, commit_id) | { - if let Err(err) = self.l1_messages_persister.set_commit_id(l1_message.id, pubkey, *commit_id) { + let Some(persistor) = &self.l1_messages_persister else { + return; + }; + if let Err(err) = persistor.set_commit_id(l1_message.id, pubkey, *commit_id) { error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.id, pubkey, err); } }); diff --git a/magicblock-committor-service/src/commit_stage.rs b/magicblock-committor-service/src/commit_stage.rs index 1a15ffa5f..328e6597a 100644 --- a/magicblock-committor-service/src/commit_stage.rs +++ b/magicblock-committor-service/src/commit_stage.rs @@ -20,12 +20,6 @@ pub struct CommitSignatures { /// If the finalize instruction was part of the process transaction then /// this signature is the same as [Self::process_signature]. pub finalize_signature: Option, - /// The signature of the transaction undelegating the committed accounts - /// if so requested. - /// If the account was not undelegated or it failed the this is `None`. - /// NOTE: this can be removed if we decide to perform the undelegation - /// step as part of the finalize instruction in the delegation program - pub undelegate_signature: Option, } impl CommitSignatures { @@ -33,7 +27,6 @@ impl CommitSignatures { Self { process_signature, finalize_signature: None, - undelegate_signature: None, } } } @@ -43,7 +36,6 @@ impl From for CommitStatusSignatures { Self { process_signature: commit_signatures.process_signature, finalize_signature: commit_signatures.finalize_signature, - undelegate_signature: commit_signatures.undelegate_signature, } } } @@ -263,14 +255,12 @@ impl CommitStage { | PartOfTooLargeBundleToFinalize(ci) => { CommitStatus::PartOfTooLargeBundleToProcess(ci.bundle_id()) } - FailedProcess((ci, strategy, sigs)) => CommitStatus::FailedProcess(( + FailedProcess((ci, sigs)) => CommitStatus::FailedProcess(( ci.bundle_id(), - *strategy, sigs.as_ref().cloned().map(CommitStatusSignatures::from), )), FailedFinalize((ci, strategy, sigs)) => CommitStatus::FailedFinalize(( ci.bundle_id(), - *strategy, CommitStatusSignatures::from(sigs.clone()), )), FailedUndelegate((ci, strategy, sigs)) => CommitStatus::FailedUndelegate(( diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index 14249040d..0e5c3c1c8 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -18,6 +18,8 @@ use solana_sdk::{ transaction::VersionedTransaction, }; +use crate::persist::CommitStatusSignatures; +use crate::utils::persist_status_update; use crate::{ persist::{CommitStatus, L1MessagesPersisterIface}, transaction_preperator::transaction_preparator::{ @@ -69,6 +71,18 @@ where l1_message: ScheduledL1Message, commit_ids: HashMap, persister: Option

, + ) -> MessageExecutorResult { + let result = self.execute_inner(l1_message, &commit_ids, &persister).await; + Self::persist_result(&persister, &result, &commit_ids); + + result + } + + async fn execute_inner( + &self, + l1_message: ScheduledL1Message, + commit_ids: &HashMap, + persister: &Option

, ) -> MessageExecutorResult { // Update tasks status to Pending { @@ -87,7 +101,8 @@ where commit_ids, &persister, ) - .await?; + .await + .map_err(Error::FailedCommitPreparationError)?; // Commit self.send_prepared_message(prepared_message).await.map_err( @@ -112,7 +127,8 @@ where &l1_message, &persister, ) - .await?; + .await + .map_err(Error::FailedFinalizePreparationError)?; // Finalize self.send_prepared_message(prepared_message).await.map_err( @@ -168,6 +184,68 @@ where Ok(result.into_signature()) } + + fn persist_result( + persistor: &Option

, + result: &MessageExecutorResult, + commit_ids: &HashMap, + ) { + match result { + Ok(value) => { + commit_ids.iter().for_each(|(pubkey, commit_id)| { + let signatures = CommitStatusSignatures { + process_signature: value.commit_signature, + finalize_signature: Some(value.commit_signature) + }; + let update_status = CommitStatus::Succeeded((*commit_id, signatures)); + persist_status_update(persistor, pubkey, *commit_id, update_status) + }); + } + Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::FailedToFitError)) => { + commit_ids.iter().for_each(|(pubkey, commit_id)| { + let update_status = CommitStatus::PartOfTooLargeBundleToProcess(*commit_id); + persist_status_update(persistor, pubkey, *commit_id, update_status) + }); + } + Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::MissingCommitIdError(_))) => { + commit_ids.iter().for_each(|(pubkey, commit_id)| { + // Invalid task + let update_status = CommitStatus::Failed(*commit_id); + persist_status_update(persistor, pubkey, *commit_id, update_status) + }); + }, + Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::DeliveryPreparationError(_))) => { + // Persisted internally + }, + Err(Error::FailedToCommitError {err: _, signature}) => { + // Commit is a single TX, so if it fails, all of commited accounts marked FailedProcess + commit_ids.iter().for_each(|(pubkey, commit_id)| { + // Invalid task + let status_signature = signature.map(|sig| CommitStatusSignatures { + process_signature: sig, + finalize_signature: None + }); + let update_status = CommitStatus::FailedProcess((*commit_id, status_signature)); + persist_status_update(persistor, pubkey, *commit_id, update_status) + }); + } + Err(Error::FailedFinalizePreparationError(_)) => { + // TODO(edwin): not supported by persister yet + }, + Err(Error::FailedToFinalizeError {err, commit_signature, finalize_signature}) => { + // Finalize is a single TX, so if it fails, all of commited accounts marked FailedFinalize + commit_ids.iter().for_each(|(pubkey, commit_id)| { + // Invalid task + let status_signature = CommitStatusSignatures { + process_signature: *commit_signature, + finalize_signature: *finalize_signature + }; + let update_status = CommitStatus::FailedFinalize((*commit_id, status_signature)); + persist_status_update(persistor, pubkey, *commit_id, update_status) + }); + } + } + } } #[derive(thiserror::Error, Debug)] @@ -180,22 +258,26 @@ pub enum InternalError { #[derive(thiserror::Error, Debug)] pub enum Error { - #[error("FailedToCommitError: {0}")] + #[error("FailedToCommitError: {err}")] FailedToCommitError { #[source] err: InternalError, signature: Option, }, - #[error("FailedToFinalizeError: {0}")] + #[error("FailedToFinalizeError: {err}")] FailedToFinalizeError { #[source] err: InternalError, commit_signature: Signature, finalize_signature: Option, }, - #[error("PreparatorError: {0}")] - FailedToPrepareTransactionError( - #[from] crate::transaction_preperator::error::Error, + #[error("FailedCommitPreparationError: {0}")] + FailedCommitPreparationError( + #[source] crate::transaction_preperator::error::Error, + ), + #[error("FailedFinalizePreparationError: {0}")] + FailedFinalizePreparationError( + #[source] crate::transaction_preperator::error::Error, ), } diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index ebd92ecc7..097c36692 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -8,7 +8,7 @@ use solana_sdk::pubkey::Pubkey; use super::{ db::CommitStatusRow, error::CommitPersistResult, utils::now, CommitStatus, - CommitType, CommittsDb, MessageSignatures, + CommitStrategy, CommitType, CommittsDb, MessageSignatures, }; use crate::utils::ScheduledMessageExt; @@ -31,6 +31,12 @@ pub trait L1MessagesPersisterIface: Send + Sync + Clone + 'static { pubkey: &Pubkey, commit_id: u64, ) -> CommitPersistResult<()>; + fn set_commit_strategy( + &self, + commit_id: u64, + pubkey: &Pubkey, + value: CommitStrategy, + ) -> CommitPersistResult<()>; fn update_status_by_message( &self, message_id: u64, @@ -173,6 +179,18 @@ impl L1MessagesPersisterIface for L1MessagePersister { .set_commit_id(message_id, pubkey, commit_id) } + fn set_commit_strategy( + &self, + commit_id: u64, + pubkey: &Pubkey, + value: CommitStrategy, + ) -> CommitPersistResult<()> { + self.commits_db + .lock() + .expect(POISONED_MUTEX_MSG) + .set_commit_strategy(commit_id, pubkey, value) + } + fn update_status_by_message( &self, message_id: u64, diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 5ae91092b..847476e4c 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -45,6 +45,8 @@ pub struct CommitStatusRow { /// For single accounts a bundle_id will be generated as well for consistency /// For Pending commits the bundle_id is not set pub commit_status: CommitStatus, + /// Strategy defined for Commit of a particular account + pub commit_strategy: CommitStrategy, /// Time since epoch at which the commit was last retried pub last_retried_at: u64, /// Number of times the commit was retried @@ -58,9 +60,6 @@ pub struct MessageSignatures { /// The signature of the transaction on chain that finalized the commit /// if applicable pub finalized_signature: Option, - /// The signature of the transaction on chain that undelegated the account(s) - /// if applicable - pub undelegate_signature: Option, /// Time since epoch at which the bundle signature was created pub created_at: u64, } @@ -82,6 +81,7 @@ impl fmt::Display for CommitStatusRow { commit_type: {}, created_at: {}, commit_status: {}, + commit_strategy: {}, last_retried_at: {}, retries_count: {} }}", @@ -97,6 +97,7 @@ impl fmt::Display for CommitStatusRow { self.commit_type.as_str(), self.created_at, self.commit_status, + self.commit_strategy.as_str(), self.last_retried_at, self.retries_count ) @@ -115,13 +116,12 @@ const ALL_COMMIT_STATUS_COLUMNS: &str = " data, // 9 commit_type, // 10 created_at, // 11 - commit_status, // 12 - commit_strategy, // 13 + commit_strategy, // 12 + commit_status, // 13 processed_signature, // 14 finalized_signature, // 15 - undelegated_signature, // 16 - last_retried_at, // 17 - retries_count // 18 + last_retried_at, // 16 + retries_count // 17 "; const SELECT_ALL_COMMIT_STATUS_COLUMNS: &str = const { @@ -160,31 +160,23 @@ impl CommittsDb { let query = "UPDATE commit_status SET commit_status = ?1, - commit_strategy = ?3, - processed_signature = ?4, - finalized_signature = ?5, - undelegated_signature = ?6 + processed_signature = ?2, + finalized_signature = ?3, WHERE - pubkey = ?7 AND message_id = ?8"; + pubkey = ?4 AND message_id = ?5"; let tx = self.conn.transaction()?; let stmt = &mut tx.prepare(query)?; stmt.execute(params![ status.as_str(), - status.commit_strategy().as_str(), status.signatures().map(|s| s.process_signature.to_string()), status .signatures() .and_then(|s| s.finalize_signature) .map(|s| s.to_string()), - status - .signatures() - .and_then(|s| s.undelegate_signature) - .map(|s| s.to_string()), pubkey.to_string(), message_id ])?; - tx.commit()?; Ok(()) } @@ -198,31 +190,42 @@ impl CommittsDb { let query = "UPDATE commit_status SET commit_status = ?1, - commit_strategy = ?3, - processed_signature = ?4, - finalized_signature = ?5, - undelegated_signature = ?6 + processed_signature = ?2, + finalized_signature = ?3, WHERE - pubkey = ?7 AND commit_id = ?8"; + pubkey = ?4 AND commit_id = ?5"; let tx = self.conn.transaction()?; let stmt = &mut tx.prepare(query)?; stmt.execute(params![ status.as_str(), - status.commit_strategy().as_str(), status.signatures().map(|s| s.process_signature.to_string()), status .signatures() .and_then(|s| s.finalize_signature) .map(|s| s.to_string()), - status - .signatures() - .and_then(|s| s.undelegate_signature) - .map(|s| s.to_string()), pubkey.to_string(), commit_id ])?; - tx.commit()?; + + Ok(()) + } + + pub fn set_commit_strategy( + &mut self, + commit_id: u64, + pubkey: &Pubkey, + value: CommitStrategy, + ) -> CommitPersistResult<()> { + let query = "UPDATE commit_status + SET + commit_strategy = ?1, + WHERE + pubkey = ?2 AND commit_id = ?3"; + + let tx = self.conn.transaction()?; + let stmt = &mut tx.prepare(query)?; + stmt.execute(params![value.as_str(), pubkey.to_string(), commit_id])?; Ok(()) } @@ -264,11 +267,10 @@ impl CommittsDb { data BLOB, commit_type TEXT NOT NULL, created_at INTEGER NOT NULL, - commit_status TEXT NOT NULL, commit_strategy TEXT NOT NULL, + commit_status TEXT NOT NULL, processed_signature TEXT, finalized_signature TEXT, - undelegated_signature TEXT, last_retried_at INTEGER NOT NULL, retries_count INTEGER NOT NULL, PRIMARY KEY (message_id, pubkey) @@ -305,19 +307,18 @@ impl CommittsDb { tx: &Transaction<'_>, commit: &CommitStatusRow, ) -> CommitPersistResult<()> { - let (processed_signature, finalized_signature, undelegated_signature) = + let (processed_signature, finalized_signature) = match commit.commit_status.signatures() { Some(sigs) => ( Some(sigs.process_signature), sigs.finalize_signature, - sigs.undelegate_signature, ), - None => (None, None, None), + None => (None, None), }; tx.execute( &format!( "INSERT INTO commit_status ({ALL_COMMIT_STATUS_COLUMNS}) VALUES - (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18)", + (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17)", ), params![ commit.message_id, @@ -331,17 +332,14 @@ impl CommittsDb { commit.data.as_deref(), commit.commit_type.as_str(), u64_into_i64(commit.created_at), + commit.commit_strategy.as_str(), commit.commit_status.as_str(), - commit.commit_status.commit_strategy().as_str(), processed_signature .as_ref() .map(|s| s.to_string()), finalized_signature .as_ref() .map(|s| s.to_string()), - undelegated_signature - .as_ref() - .map(|s| s.to_string()), u64_into_i64(commit.last_retried_at), commit.retries_count, ], @@ -404,7 +402,7 @@ impl CommittsDb { pubkey: &Pubkey, ) -> CommitPersistResult> { let query = "SELECT - processed_signature, finalized_signature, undelegated_signature, created_at + processed_signature, finalized_signature, created_at FROM commit_status WHERE commit_id = ?1 AND pubkey = ?2 LIMIT 1"; @@ -417,8 +415,7 @@ impl CommittsDb { .map(|row| { let processed_signature: String = row.get(0)?; let finalized_signature: Option = row.get(1)?; - let undelegated_signature: Option = row.get(2)?; - let created_at: i64 = row.get(3)?; + let created_at: i64 = row.get(2)?; Ok::<_, CommitPersistError>(MessageSignatures { processed_signature: Signature::from_str( @@ -427,9 +424,6 @@ impl CommittsDb { finalized_signature: finalized_signature .map(|s| Signature::from_str(&s)) .transpose()?, - undelegate_signature: undelegated_signature - .map(|s| Signature::from_str(&s)) - .transpose()?, created_at: i64_into_u64(created_at), }) }) @@ -503,12 +497,14 @@ fn extract_committor_row( let created_at: i64 = row.get(10)?; i64_into_u64(created_at) }; + + let commit_strategy = { + let commit_strategy: String = row.get(11)?; + CommitStrategy::from(commit_strategy.as_str()) + }; + let commit_status = { - let commit_status: String = row.get(11)?; - let commit_strategy = { - let commit_strategy: String = row.get(12)?; - CommitStrategy::from(commit_strategy.as_str()) - }; + let commit_status: String = row.get(12)?; let processed_signature = { let processed_signature: Option = row.get(13)?; processed_signature @@ -521,21 +517,13 @@ fn extract_committor_row( .map(|s| Signature::from_str(s.as_str())) .transpose()? }; - let undelegated_signature = { - let undelegated_signature: Option = row.get(15)?; - undelegated_signature - .map(|s| Signature::from_str(s.as_str())) - .transpose()? - }; let sigs = processed_signature.map(|s| CommitStatusSignatures { process_signature: s, finalize_signature: finalized_signature, - undelegate_signature: undelegated_signature, }); CommitStatus::try_from(( commit_status.as_str(), commit_id, - commit_strategy, sigs, ))? }; @@ -561,6 +549,7 @@ fn extract_committor_row( data, commit_type, created_at, + commit_strategy, commit_status, last_retried_at, retries_count, diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index 607a5283f..e2b534793 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -32,11 +32,11 @@ pub enum CommitStatus { /// The commit was properly initialized and added to a chunk of instructions to process /// commits via a transaction. For large commits the buffer and chunk accounts were properly /// prepared and haven't been closed. - FailedProcess((u64, CommitStrategy, Option)), + FailedProcess((u64, Option)), /// The commit was properly processed but the requested finalize transaction failed. - FailedFinalize((u64, CommitStrategy, CommitStatusSignatures)), + FailedFinalize((u64, CommitStatusSignatures)), /// The commit was successfully processed and finalized. - Succeeded((u64, CommitStrategy, CommitStatusSignatures)), + Succeeded((u64, CommitStatusSignatures)), } impl fmt::Display for CommitStatus { @@ -58,30 +58,27 @@ impl fmt::Display for CommitStatus { CommitStatus::PartOfTooLargeBundleToProcess(bundle_id) => { write!(f, "PartOfTooLargeBundleToProcess({})", bundle_id) } - CommitStatus::FailedProcess((bundle_id, strategy, sigs)) => { + CommitStatus::FailedProcess((bundle_id, sigs)) => { write!( f, - "FailedProcess({}, {}, {:?})", + "FailedProcess({}, {:?})", bundle_id, - strategy.as_str(), sigs ) } - CommitStatus::FailedFinalize((bundle_id, strategy, sigs)) => { + CommitStatus::FailedFinalize((bundle_id, sigs)) => { write!( f, - "FailedFinalize({}, {}, {:?})", + "FailedFinalize({}, {:?})", bundle_id, - strategy.as_str(), sigs ) } - CommitStatus::Succeeded((bundle_id, strategy, sigs)) => { + CommitStatus::Succeeded((bundle_id, sigs)) => { write!( f, - "Succeeded({}, {}, {:?})", + "Succeeded({}, {:?})", bundle_id, - strategy.as_str(), sigs ) } @@ -89,16 +86,15 @@ impl fmt::Display for CommitStatus { } } -impl TryFrom<(&str, u64, CommitStrategy, Option)> +impl TryFrom<(&str, u64, Option)> for CommitStatus { type Error = CommitPersistError; fn try_from( - (status, commit_id, strategy, sigs): ( + (status, commit_id, sigs): ( &str, u64, - CommitStrategy, Option, ), ) -> Result { @@ -128,11 +124,11 @@ impl TryFrom<(&str, u64, CommitStrategy, Option)> "PartOfTooLargeBundleToProcess" => { Ok(PartOfTooLargeBundleToProcess(commit_id)) } - "FailedProcess" => Ok(FailedProcess((commit_id, strategy, sigs))), + "FailedProcess" => Ok(FailedProcess((commit_id, sigs))), "FailedFinalize" => { - Ok(FailedFinalize((commit_id, strategy, get_sigs()?))) + Ok(FailedFinalize((commit_id, get_sigs()?))) } - "Succeeded" => Ok(Succeeded((commit_id, strategy, get_sigs()?))), + "Succeeded" => Ok(Succeeded((commit_id, get_sigs()?))), _ => { Err(CommitPersistError::InvalidCommitStatus(status.to_string())) } @@ -149,12 +145,6 @@ pub struct CommitStatusSignatures { /// If the finalize instruction was part of the process transaction then /// this signature is the same as [Self::process_signature]. pub finalize_signature: Option, - /// The signature of the transaction undelegating the committed accounts - /// if so requested. - /// If the account was not undelegated or it failed the this is `None`. - /// NOTE: this can be removed if we decide to perform the undelegation - /// step as part of the finalize instruction in the delegation program - pub undelegate_signature: Option, } impl CommitStatus { @@ -185,9 +175,9 @@ impl CommitStatus { | BufferAndChunkInitialized(bundle_id) | BufferAndChunkFullyInitialized(bundle_id) | PartOfTooLargeBundleToProcess(bundle_id) - | FailedProcess((bundle_id, _, _)) - | FailedFinalize((bundle_id, _, _)) - | Succeeded((bundle_id, _, _)) => Some(*bundle_id), + | FailedProcess((bundle_id, _)) + | FailedFinalize((bundle_id, _)) + | Succeeded((bundle_id, _)) => Some(*bundle_id), Pending => None, } } @@ -195,28 +185,13 @@ impl CommitStatus { pub fn signatures(&self) -> Option { use CommitStatus::*; match self { - FailedProcess((_, _, sigs)) => sigs.as_ref().cloned(), - FailedFinalize((_, _, sigs)) => Some(sigs.clone()), - Succeeded((_, _, sigs)) => Some(sigs.clone()), + FailedProcess((_, sigs)) => sigs.as_ref().cloned(), + FailedFinalize((_, sigs)) => Some(sigs.clone()), + Succeeded((_, sigs)) => Some(sigs.clone()), _ => None, } } - pub fn commit_strategy(&self) -> CommitStrategy { - use CommitStatus::*; - match self { - Pending => CommitStrategy::Undetermined, - Failed(_) => CommitStrategy::Undetermined, - BufferAndChunkPartiallyInitialized(_) - | BufferAndChunkInitialized(_) - | BufferAndChunkFullyInitialized(_) => CommitStrategy::FromBuffer, - PartOfTooLargeBundleToProcess(_) => CommitStrategy::Undetermined, - FailedProcess((_, strategy, _)) => *strategy, - FailedFinalize((_, strategy, _)) => *strategy, - Succeeded((_, strategy, _)) => *strategy, - } - } - /// The commit fully succeeded and no retry is necessary. pub fn is_complete(&self) -> bool { use CommitStatus::*; diff --git a/magicblock-committor-service/src/tasks/mod.rs b/magicblock-committor-service/src/tasks/mod.rs index 483d9341b..4dcf91c12 100644 --- a/magicblock-committor-service/src/tasks/mod.rs +++ b/magicblock-committor-service/src/tasks/mod.rs @@ -1,5 +1,7 @@ mod budget_calculator; pub mod task_builder; pub mod task_strategist; +pub(crate) mod task_visitors; pub mod tasks; pub mod utils; +pub mod visitor; diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 3d9fbe04b..1b7c65df9 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -14,7 +14,7 @@ pub trait TasksBuilder { // Creates tasks for commit stage fn commit_tasks( l1_message: &ScheduledL1Message, - commit_ids: HashMap, + commit_ids: &HashMap, ) -> Vec>; // Create tasks for finalize stage @@ -35,13 +35,14 @@ impl TasksBuilder for TaskBuilderV1 { ) -> TaskBuilderResult>> { let (accounts, allow_undelegation) = match &l1_message.l1_message { MagicL1Message::L1Actions(actions) => { - return actions + let tasks = actions .into_iter() .map(|el| { Box::new(ArgsTask::L1Action(el.clone())) as Box }) - .collect() + .collect(); + return Ok(tasks); } MagicL1Message::Commit(t) => (t.get_committed_accounts(), false), MagicL1Message::CommitAndUndelegate(t) => { diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 123ddb3e0..c261bd29d 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -3,6 +3,10 @@ use std::{collections::BinaryHeap, ptr::NonNull}; use solana_pubkey::Pubkey; use solana_sdk::signature::Keypair; +use crate::persist::L1MessagesPersisterIface; +use crate::tasks::task_visitors::persistor_visitor::{ + PersistorContext, PersistorVisitor, +}; use crate::{ tasks::{ tasks::{ArgsTask, L1Task}, @@ -20,12 +24,26 @@ pub struct TaskStrategist; impl TaskStrategist { /// Returns [`TaskDeliveryStrategy`] for every [`Task`] /// Returns Error if all optimizations weren't enough - pub fn build_strategy( + pub fn build_strategy( mut tasks: Vec>, validator: &Pubkey, + persistor: &Option

, ) -> TaskStrategistResult { // Attempt optimizing tasks themselves(using buffers) if Self::optimize_strategy(&mut tasks) <= MAX_ENCODED_TRANSACTION_SIZE { + // Persist tasks strategy + if let Some(persistor) = persistor { + let mut persistor_visitor = PersistorVisitor { + persistor, + context: PersistorContext::PersistStrategy { + uses_lookup_tables: false, + }, + }; + tasks + .iter() + .for_each(|task| task.visit(&mut persistor_visitor)); + } + Ok(TransactionStrategy { optimized_tasks: tasks, lookup_tables_keys: vec![], @@ -35,6 +53,19 @@ impl TaskStrategist { // attempt using lookup tables for all keys involved in tasks let lookup_tables_keys = Self::attempt_lookup_tables(&validator, &tasks)?; + + // Persist tasks strategy + if let Some(persistor) = persistor { + let mut persistor_visitor = PersistorVisitor { + persistor, + context: PersistorContext::PersistStrategy { + uses_lookup_tables: true, + }, + }; + tasks + .iter() + .for_each(|task| task.visit(&mut persistor_visitor)); + } Ok(TransactionStrategy { optimized_tasks: tasks, lookup_tables_keys, diff --git a/magicblock-committor-service/src/tasks/task_visitors/mod.rs b/magicblock-committor-service/src/tasks/task_visitors/mod.rs new file mode 100644 index 000000000..3a4ed8d36 --- /dev/null +++ b/magicblock-committor-service/src/tasks/task_visitors/mod.rs @@ -0,0 +1 @@ +pub(crate) mod persistor_visitor; diff --git a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs new file mode 100644 index 000000000..e306d1c70 --- /dev/null +++ b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs @@ -0,0 +1,70 @@ +use crate::persist::{CommitStrategy, L1MessagesPersisterIface}; +use crate::tasks::tasks::{ArgsTask, BufferTask}; +use crate::tasks::visitor::Visitor; +use log::error; + +pub enum PersistorContext { + PersistStrategy { uses_lookup_tables: bool }, + // Other possible persist +} + +pub struct PersistorVisitor<'a, P> { + pub persistor: &'a P, + pub context: PersistorContext, +} + +impl<'a, P> Visitor for PersistorVisitor<'a, P> +where + P: L1MessagesPersisterIface, +{ + fn visit_args_task(&mut self, task: &ArgsTask) { + match self.context { + PersistorContext::PersistStrategy { uses_lookup_tables } => { + let ArgsTask::Commit(commit_task) = task else { + return; + }; + + let commit_strategy = if uses_lookup_tables { + CommitStrategy::Args + } else { + CommitStrategy::ArgsWithLookupTable + }; + + if let Err(err) = self.persistor.set_commit_strategy( + commit_task.commit_id, + &commit_task.committed_account.pubkey, + commit_strategy, + ) { + error!( + "Failed to persist commit strategy {}: {}", + commit_strategy.as_str(), err + ); + } + } + } + } + + fn visit_buffer_task(&mut self, task: &BufferTask) { + match self.context { + PersistorContext::PersistStrategy { uses_lookup_tables } => { + let BufferTask::Commit(commit_task) = task; + let commit_strategy = if uses_lookup_tables { + CommitStrategy::FromBuffer + } else { + CommitStrategy::FromBufferWithLookupTable + }; + + if let Err(err) = self.persistor.set_commit_strategy( + commit_task.commit_id, + &commit_task.committed_account.pubkey, + commit_strategy, + ) { + error!( + "Failed to persist commit strategy {}: {}", + commit_strategy.as_str(), err + ); + } + } + } + } +} diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index a4f9e23e9..5e2ddc7e9 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -16,10 +16,16 @@ use magicblock_program::magic_scheduled_l1_message::{ use solana_pubkey::Pubkey; use solana_sdk::instruction::{AccountMeta, Instruction}; +use crate::tasks::visitor::Visitor; use crate::{ consts::MAX_WRITE_CHUNK_SIZE, tasks::budget_calculator::ComputeBudgetV1, }; +pub enum TaskStrategy { + Args, + Buffer, +} + #[derive(Clone, Debug)] pub struct TaskPreparationInfo { pub commit_id: u64, @@ -45,7 +51,7 @@ pub trait L1Task: Send + Sync { /// Gets instruction for task execution fn instruction(&self, validator: &Pubkey) -> Instruction; - /// If has optimizations returns optimized Task, otherwise returns itself + /// Optimizes Task strategy if possible, otherwise returns itself fn optimize(self: Box) -> Result, Box>; /// Returns [`TaskPreparationInfo`] if task needs to be prepared before executing, @@ -69,9 +75,14 @@ pub trait L1Task: Send + Sync { Some(info.init_instruction.clone()), ) } + + /// Returns current [`TaskStrategy`] + fn strategy(&self) -> TaskStrategy; + + /// Calls [`Visitor`] with specific task type + fn visit(&self, visitor: &mut dyn Visitor); } -// TODO(edwin): commit_id is common thing, extract #[derive(Clone)] pub struct CommitTask { pub commit_id: u64, @@ -95,7 +106,7 @@ pub struct FinalizeTask { #[derive(Clone)] pub enum ArgsTask { Commit(CommitTask), - Finalize(FinalizeTask), // TODO(edwin): introduce Stages instead? + Finalize(FinalizeTask), Undelegate(UndelegateTask), // Special action really L1Action(L1Action), } @@ -168,6 +179,15 @@ impl L1Task for ArgsTask { fn budget(&self) -> ComputeBudgetV1 { todo!() } + + fn strategy(&self) -> TaskStrategy { + TaskStrategy::Args + } + + /// For tasks using Args strategy call corresponding `Visitor` method + fn visit(&self, visitor: &mut dyn Visitor) { + visitor.visit_args_task(self); + } } /// Tasks that could be executed using buffers @@ -267,4 +287,13 @@ impl L1Task for BufferTask { fn budget(&self) -> ComputeBudgetV1 { todo!() } + + fn strategy(&self) -> TaskStrategy { + TaskStrategy::Buffer + } + + /// For tasks using Args strategy call corresponding `Visitor` method + fn visit(&self, visitor: &mut dyn Visitor) { + visitor.visit_buffer_task(self); + } } diff --git a/magicblock-committor-service/src/tasks/visitor.rs b/magicblock-committor-service/src/tasks/visitor.rs new file mode 100644 index 000000000..74ae01a87 --- /dev/null +++ b/magicblock-committor-service/src/tasks/visitor.rs @@ -0,0 +1,6 @@ +use crate::tasks::tasks::{ArgsTask, BufferTask}; + +pub trait Visitor { + fn visit_args_task(&mut self, task: &ArgsTask); + fn visit_buffer_task(&mut self, task: &BufferTask); +} diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 68b2776c8..65fc09dce 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -364,7 +364,9 @@ pub enum InternalError { #[derive(thiserror::Error, Debug)] pub enum Error { + #[error("FailedToPrepareBufferAccounts: {0}")] FailedToPrepareBufferAccounts(#[source] InternalError), + #[error("FailedToCreateALTError: {0}")] FailedToCreateALTError(#[source] InternalError), } diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preperator/error.rs index a7c27b0bf..db4fd2021 100644 --- a/magicblock-committor-service/src/transaction_preperator/error.rs +++ b/magicblock-committor-service/src/transaction_preperator/error.rs @@ -5,8 +5,8 @@ use crate::transaction_preperator::transaction_preparator::PreparatorVersion; #[derive(Error, Debug)] pub enum Error { - #[error("Invalid action for TransactionPreparatir version: {0}")] - VersionError(PreparatorVersion), + // #[error("Invalid action for TransactionPreparator version: {0}")] + // VersionError(PreparatorVersion), #[error("Failed to fit in single TX")] FailedToFitError, #[error("Missing commit id for pubkey: {0}")] @@ -15,8 +15,6 @@ pub enum Error { DeliveryPreparationError( #[from] crate::transaction_preperator::delivery_preparator::Error, ), - #[error("InternalError: {0}")] - InternalError(#[from] anyhow::Error), } impl From for Error { diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 099f0eb5a..9adb6cef4 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -48,7 +48,7 @@ pub trait TransactionPreparator { &self, authority: &Keypair, l1_message: &ScheduledL1Message, - commit_ids: HashMap, + commit_ids: &HashMap, l1_messages_persister: &Option

, ) -> PreparatorResult; @@ -104,14 +104,17 @@ impl TransactionPreparator for TransactionPreparatorV1 { &self, authority: &Keypair, l1_message: &ScheduledL1Message, - commit_ids: HashMap, + commit_ids: &HashMap, l1_messages_persister: &Option

, ) -> PreparatorResult { // create tasks - let tasks = TaskBuilderV1::commit_tasks(l1_message, &commit_ids)?; + let tasks = TaskBuilderV1::commit_tasks(l1_message, commit_ids)?; // optimize to fit tx size. aka Delivery Strategy - let tx_strategy = - TaskStrategist::build_strategy(tasks, &authority.pubkey())?; + let tx_strategy = TaskStrategist::build_strategy( + tasks, + &authority.pubkey(), + l1_messages_persister, + )?; // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self .delivery_preparator @@ -144,8 +147,11 @@ impl TransactionPreparator for TransactionPreparatorV1 { let tasks = TaskBuilderV1::finalize_tasks(l1_message, rent_reimbursement); // optimize to fit tx size. aka Delivery Strategy - let tx_strategy = - TaskStrategist::build_strategy(tasks, &authority.pubkey())?; + let tx_strategy = TaskStrategist::build_strategy( + tasks, + &authority.pubkey(), + l1_messages_persister, + )?; // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self .delivery_preparator From e242e67500390ddd4b3038f13a17c7b2ad0fcd7f Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 22 Jul 2025 18:21:54 +0900 Subject: [PATCH 108/199] feat: added visitor into tasks fix: some compilation fixes refactor: removing unused files --- .../src/commit/commit_using_args.rs | 295 ----- .../src/commit/commit_using_buffer.rs | 1055 ----------------- .../src/commit/common.rs | 207 ---- .../src/commit/mod.rs | 7 - .../src/commit/process_buffers.rs | 234 ---- .../commit_scheduler_inner.rs | 53 +- .../commit_scheduler_worker.rs | 2 +- .../src/commit_stage.rs | 339 ------ .../src/{commit => }/committor_processor.rs | 30 +- .../src/l1_message_executor.rs | 10 +- magicblock-committor-service/src/lib.rs | 4 +- .../src/persist/commit_persister.rs | 1 + .../src/persist/db.rs | 41 +- .../src/persist/error.rs | 3 + .../src/persist/types/commit_status.rs | 36 +- .../src/persist/types/commit_strategy.rs | 25 +- magicblock-committor-service/src/service.rs | 14 +- .../src/tasks/task_builder.rs | 2 +- .../src/tasks/task_strategist.rs | 8 +- .../tasks/task_visitors/persistor_visitor.rs | 17 +- .../src/tasks/tasks.rs | 4 +- .../src/transaction_preperator/error.rs | 4 +- 22 files changed, 114 insertions(+), 2277 deletions(-) delete mode 100644 magicblock-committor-service/src/commit/commit_using_args.rs delete mode 100644 magicblock-committor-service/src/commit/commit_using_buffer.rs delete mode 100644 magicblock-committor-service/src/commit/common.rs delete mode 100644 magicblock-committor-service/src/commit/mod.rs delete mode 100644 magicblock-committor-service/src/commit/process_buffers.rs delete mode 100644 magicblock-committor-service/src/commit_stage.rs rename magicblock-committor-service/src/{commit => }/committor_processor.rs (86%) diff --git a/magicblock-committor-service/src/commit/commit_using_args.rs b/magicblock-committor-service/src/commit/commit_using_args.rs deleted file mode 100644 index 263390991..000000000 --- a/magicblock-committor-service/src/commit/commit_using_args.rs +++ /dev/null @@ -1,295 +0,0 @@ -use std::{collections::HashSet, sync::Arc}; - -use dlp::args::CommitStateArgs; -use log::*; -use magicblock_committor_program::Changeset; -use magicblock_rpc_client::MagicBlockSendTransactionConfig; -use solana_sdk::{hash::Hash, signer::Signer}; - -use super::CommittorProcessor; -use crate::{ - commit::common::{ - get_accounts_to_undelegate, lookup_table_keys, send_and_confirm, - }, - commit_stage::{CommitSignatures, CommitStage}, - persist::CommitStrategy, - undelegate::undelegate_commitables_ixs, - CommitInfo, -}; - -impl CommittorProcessor { - /// Commits a changeset directly using args to include the commit state - /// - **changeset**: the changeset to commit - /// - **finalize**: whether to finalize the commit - /// - **finalize_separately**: whether to finalize the commit in a separate transaction, if - /// this is `false` we can include the finalize instructions with the process instructions - /// - **ephemeral_blockhash**: the ephemeral blockhash to use for the commit - /// - **latest_blockhash**: the latest blockhash on chain to use for the commit - /// - **use_lookup**: whether to use the lookup table for the instructions - pub async fn commit_changeset_using_args( - me: Arc, - changeset: Changeset, - (finalize, finalize_separately): (bool, bool), - ephemeral_blockhash: Hash, - latest_blockhash: Hash, - use_lookup: bool, - ) -> Vec { - // Each changeset is expected to fit into a single instruction which was ensured - // when splitting the original changeset - - let mut process_ixs = Vec::new(); - let mut finalize_ixs = Vec::new(); - let owners = changeset.owners(); - let accounts_to_undelegate = - get_accounts_to_undelegate(&changeset, finalize); - let commitables = changeset.into_committables(0); - // NOTE: we copy the commitables here in order to return them with an error - // [CommitStage] if needed. Since the data of these accounts is small - // (< 1024 bytes), it is acceptable perf overhead - // Alternatively we could include only metadata for the [CommitStage]. - for commitable in commitables.iter() { - let commit_args = CommitStateArgs { - slot: commitable.slot, - lamports: commitable.lamports, - allow_undelegation: commitable.undelegate, - data: commitable.data.clone(), - }; - - let ix = dlp::instruction_builder::commit_state( - me.authority.pubkey(), - commitable.pubkey, - commitable.delegated_account_owner, - commit_args, - ); - process_ixs.push(ix); - - // We either include the finalize instructions with the process instruction or - // if the strategy builder determined that they wouldn't fit then we run them - // in a separate transaction - if finalize { - let finalize_ix = dlp::instruction_builder::finalize( - me.authority.pubkey(), - commitable.pubkey, - ); - if finalize_separately { - finalize_ixs.push(finalize_ix); - } else { - process_ixs.push(finalize_ix); - } - } - } - - let commit_infos = commitables - .into_iter() - .map(|acc| { - CommitInfo::from_small_data_account( - acc, - ephemeral_blockhash, - finalize, - ) - }) - .collect::>(); - - let committees = commit_infos - .iter() - .map(|x| x.pubkey()) - .collect::>(); - - let table_mania = use_lookup.then(|| me.table_mania.clone()); - let table_mania_setup = table_mania.as_ref().map(|tm| { - let keys = lookup_table_keys(&me.authority, &committees, &owners); - (tm, keys) - }); - - let compute_budget_ixs = me - .compute_budget_config - .args_process_budget() - .instructions(committees.len()); - let process_sig = match send_and_confirm( - me.magicblock_rpc_client.clone(), - &me.authority, - [compute_budget_ixs, process_ixs].concat(), - "commit changeset using args".to_string(), - Some(latest_blockhash), - MagicBlockSendTransactionConfig::ensure_committed(), - table_mania_setup.clone(), - ) - .await - { - Ok(sig) => sig, - Err(err) => { - error!("Failed to commit changeset using args: {:?}", err); - let strategy = CommitStrategy::args(use_lookup); - let sigs = err.signature().map(|sig| CommitSignatures { - process_signature: sig, - finalize_signature: None, - undelegate_signature: None, - }); - return commit_infos - .into_iter() - .map(|x| { - CommitStage::FailedProcess(( - x, - strategy, - sigs.as_ref().cloned(), - )) - }) - .collect(); - } - }; - - let finalize_sig = if !finalize_ixs.is_empty() { - let table_mania_setup = table_mania.as_ref().map(|tm| { - let keys = - lookup_table_keys(&me.authority, &committees, &owners); - (tm, keys) - }); - let finalize_budget_ixs = me - .compute_budget_config - .finalize_budget() - .instructions(committees.len()); - match send_and_confirm( - me.magicblock_rpc_client.clone(), - &me.authority, - [finalize_budget_ixs, finalize_ixs].concat(), - "commit changeset using args".to_string(), - Some(latest_blockhash), - MagicBlockSendTransactionConfig::ensure_committed(), - table_mania_setup, - ) - .await - { - Ok(sig) => Some(sig), - Err(err) => { - error!( - "Failed to finalize changeset using args: {:?}", - err - ); - return commit_infos - .into_iter() - .map(|x| { - CommitStage::FailedFinalize(( - x, - CommitStrategy::args(use_lookup), - CommitSignatures { - process_signature: process_sig, - finalize_signature: err.signature(), - undelegate_signature: None, - }, - )) - }) - .collect(); - } - } - } else { - (!finalize_separately).then_some(process_sig) - }; - - trace!( - "Successfully processed {} commit infos via transaction '{}'", - commit_infos.len(), - process_sig - ); - - let undelegate_sig = if let Some(sig) = finalize_sig { - trace!( - "Successfully finalized {} commit infos via transaction '{}'", - commit_infos.len(), - sig - ); - - // If we successfully finalized the commit then we can undelegate accounts - if let Some(accounts) = accounts_to_undelegate { - let accounts_len = accounts.len(); - let undelegate_ixs = match undelegate_commitables_ixs( - &me.magicblock_rpc_client, - me.authority.pubkey(), - accounts, - ) - .await - { - Ok(ixs) => ixs.into_values().collect::>(), - Err(err) => { - error!( - "Failed to prepare accounts undelegation '{}': {:?}", - err, err - ); - return commit_infos - .into_iter() - .map(|x| { - CommitStage::FailedUndelegate(( - x, - CommitStrategy::args(use_lookup), - CommitSignatures { - process_signature: process_sig, - finalize_signature: finalize_sig, - undelegate_signature: err.signature(), - }, - )) - }) - .collect(); - } - }; - let undelegate_budget_ixs = me - .compute_budget_config - .undelegate_budget() - .instructions(accounts_len); - match send_and_confirm( - me.magicblock_rpc_client.clone(), - &me.authority, - [undelegate_budget_ixs, undelegate_ixs].concat(), - "undelegate committed accounts using args".to_string(), - Some(latest_blockhash), - MagicBlockSendTransactionConfig::ensure_committed(), - table_mania_setup, - ) - .await - { - Ok(sig) => { - trace!("Successfully undelegated accounts via transaction '{}'", sig); - Some(sig) - } - Err(err) => { - error!( - "Failed to undelegate accounts via transaction '{}': {:?}", - err, err - ); - return commit_infos - .into_iter() - .map(|x| { - CommitStage::FailedUndelegate(( - x, - CommitStrategy::args(use_lookup), - CommitSignatures { - process_signature: process_sig, - finalize_signature: finalize_sig, - undelegate_signature: err.signature(), - }, - )) - }) - .collect(); - } - } - } else { - None - } - } else { - None - }; - - commit_infos - .into_iter() - .map(|x| { - CommitStage::Succeeded(( - x, - CommitStrategy::args(use_lookup), - CommitSignatures { - process_signature: process_sig, - finalize_signature: finalize_sig, - undelegate_signature: undelegate_sig, - }, - )) - }) - .collect() - } -} diff --git a/magicblock-committor-service/src/commit/commit_using_buffer.rs b/magicblock-committor-service/src/commit/commit_using_buffer.rs deleted file mode 100644 index a7e8ebea7..000000000 --- a/magicblock-committor-service/src/commit/commit_using_buffer.rs +++ /dev/null @@ -1,1055 +0,0 @@ -use std::{ - collections::{HashMap, HashSet}, - sync::Arc, - time::Duration, -}; - -use borsh::{to_vec, BorshDeserialize}; -use dlp::pda::commit_state_pda_from_delegated_account; -use log::*; -use magicblock_committor_program::{ - instruction_builder::{ - init_buffer::{create_init_ix, CreateInitIxArgs}, - realloc_buffer::{ - create_realloc_buffer_ixs, - create_realloc_buffer_ixs_to_add_remaining, - CreateReallocBufferIxArgs, - }, - write_buffer::{create_write_ix, CreateWriteIxArgs}, - }, - instruction_chunks::chunk_realloc_ixs, - Changeset, ChangesetChunk, Chunks, CommitableAccount, -}; -use magicblock_rpc_client::{ - MagicBlockRpcClientError, MagicBlockRpcClientResult, - MagicBlockSendTransactionConfig, -}; -use solana_pubkey::Pubkey; -use solana_sdk::{hash::Hash, instruction::Instruction, signer::Signer}; -use tokio::task::JoinSet; - -use super::{ - common::send_and_confirm, - process_buffers::{ - chunked_ixs_to_process_commitables_and_close_pdas, - ChunkedIxsToProcessCommitablesAndClosePdasResult, - }, - CommittorProcessor, -}; -use crate::{ - commit::common::get_accounts_to_undelegate, - commit_stage::CommitSignatures, - error::{CommitAccountError, CommitAccountResult}, - finalize::{ - chunked_ixs_to_finalize_commitables, - ChunkedIxsToFinalizeCommitablesResult, - }, - persist::CommitStrategy, - types::InstructionsKind, - undelegate::{ - chunked_ixs_to_undelegate_commitables, undelegate_commitables_ixs, - }, - CommitInfo, CommitStage, -}; - -struct NextReallocs { - missing_size: u64, - start_idx: usize, - err: Option, -} - -impl CommittorProcessor { - /// Commits the changeset by initializing the accounts, writing the chunks, - /// and closing the pdas. - /// NOTE: we return no error since the validator would not know how to mitigate - /// the problem. - pub async fn commit_changeset_using_buffers( - processor: Arc, - changeset: Changeset, - finalize: bool, - ephemeral_blockhash: Hash, - use_lookup: bool, - ) -> Vec { - macro_rules! handle_unchunked { - ($unchunked:ident, $commit_stages:ident, $commit_stage:expr) => { - for (bundle_id, commit_infos) in $unchunked.into_iter() { - // The max amount of accounts we can commit and process as part of a single - // transaction is [crate::max_per_transaction::MAX_COMMIT_STATE_AND_CLOSE_PER_TRANSACTION]. - warn!( - "Commit infos for bundle id {} are too many to be processed in a single transaction", - bundle_id - ); - $commit_stages.extend( - commit_infos - .into_iter() - .map($commit_stage), - ); - } - } - } - - let owners = changeset.owners(); - let accounts_len = changeset.account_keys().len(); - let commit_strategy = if use_lookup { - CommitStrategy::FromBufferWithLookupTable - } else { - CommitStrategy::FromBuffer - }; - let accounts_to_undelegate = - get_accounts_to_undelegate(&changeset, finalize); - let results = processor - .prepare_changeset_buffers( - changeset, - ephemeral_blockhash, - commit_strategy, - finalize, - ) - .await; - - let mut commit_stages = vec![]; - - // 1. Init Buffer and Chunks Account - let (mut succeeded_inits, failed_inits): (Vec<_>, Vec<_>) = { - let (succeeded, failed): (Vec<_>, Vec<_>) = - results.into_iter().partition(Result::is_ok); - ( - succeeded - .into_iter() - .map(Result::unwrap) - .collect::>(), - failed - .into_iter() - .map(Result::unwrap_err) - .collect::>(), - ) - }; - - // If we couldn't init the buffers for a specific commit then we're done with it. - for commit_err in failed_inits.into_iter() { - let commit_stage = CommitStage::from(commit_err); - let bundle_id = commit_stage.commit_metadata().bundle_id(); - commit_stages.push(commit_stage); - - // We also need to skip all committables that are in the same bundle as - // a commit we're giving up on. - let (fail_in_order_to_respect_bundle, keep): (Vec<_>, Vec<_>) = - succeeded_inits.drain(..).partition(|commit_info| { - #[allow(clippy::let_and_return)] - let same_bundle = commit_info.bundle_id() == bundle_id; - same_bundle - }); - commit_stages.extend( - fail_in_order_to_respect_bundle.into_iter().map(|x| { - CommitStage::BufferAndChunkFullyInitialized(( - x, - commit_strategy, - )) - }), - ); - succeeded_inits.extend(keep); - } - - // 2. Create chunks of instructions that process the commits and respect desired bundles - let ChunkedIxsToProcessCommitablesAndClosePdasResult { - chunked_ixs, - chunked_close_ixs, - unchunked, - } = chunked_ixs_to_process_commitables_and_close_pdas( - processor.authority.pubkey(), - succeeded_inits.clone(), - use_lookup, - ); - handle_unchunked!( - unchunked, - commit_stages, - CommitStage::PartOfTooLargeBundleToProcess - ); - - // 3. Process all chunks via transactions, one per chunk of instructions - trace!( - "ChunkedIxs: {}", - chunked_ixs - .iter() - .map(|xs| xs - .iter() - .map(|x| x.to_string()) - .collect::>() - .join("\n")) - .collect::>() - .join("]\n\n[\n") - ); - debug_assert_eq!( - chunked_ixs.iter().map(|x| x.len()).sum::() + commit_stages.len(), - accounts_len, - "Sum of instructions and early bail out stages should have one instruction per commmitted account", - ); - - let table_mania = use_lookup.then(|| processor.table_mania.clone()); - let (succeeded_process, failed_process) = processor - .process_ixs_chunks( - chunked_ixs, - chunked_close_ixs, - table_mania.as_ref(), - &owners, - ) - .await; - - commit_stages.extend(failed_process.into_iter().flat_map( - |(sig, xs)| { - let sigs = sig.map(|x| CommitSignatures { - process_signature: x, - finalize_signature: None, - undelegate_signature: None, - }); - xs.into_iter() - .map(|x| { - CommitStage::FailedProcess(( - x, - commit_strategy, - sigs.as_ref().cloned(), - )) - }) - .collect::>() - }, - )); - - let mut processed_commit_infos = vec![]; - let mut processed_signatures = HashMap::new(); - for (sig, commit_infos) in succeeded_process { - if log_enabled!(Level::Trace) { - let kinds = commit_infos - .iter() - .map(|(_, kind)| *kind) - .collect::>(); - let handled = kinds - .iter() - .map(|x| format!("{:?}", x)) - .collect::>() - .join(" | "); - trace!( - "Successfully handled ({}) for {} commit info(s) via transaction '{}'", - handled, - commit_infos.len(), - sig - ); - } - for (commit_info, _) in commit_infos - .into_iter() - .filter(|(_, kind)| kind.is_processing()) - { - let bundle_id = commit_info.bundle_id(); - debug_assert!( - processed_signatures - .get(&bundle_id) - .map(|x| x == &sig) - .unwrap_or(true), - "BUG: Same processed bundle ids should have the same signature" - ); - processed_signatures.insert(bundle_id, sig); - processed_commit_infos.push(commit_info); - } - } - - // 4. Optionally finalize + undelegate all processed commits also respecting bundles - if finalize && !processed_commit_infos.is_empty() { - // 4.1. Create chunks of finalize instructions that fit in a single transaction - let ChunkedIxsToFinalizeCommitablesResult { - chunked_ixs, - unchunked, - } = chunked_ixs_to_finalize_commitables( - processor.authority.pubkey(), - processed_commit_infos, - use_lookup, - ); - handle_unchunked!( - unchunked, - commit_stages, - CommitStage::PartOfTooLargeBundleToFinalize - ); - - // 4.2. Run each finalize chunk in a single transaction - let (succeeded_finalize, failed_finalize): (Vec<_>, Vec<_>) = - processor - .process_ixs_chunks( - chunked_ixs, - None, - table_mania.as_ref(), - &owners, - ) - .await; - commit_stages.extend(failed_finalize.into_iter().flat_map( - |(sig, infos)| { - infos - .into_iter() - .map(|x| { - let bundle_id = x.bundle_id(); - CommitStage::FailedFinalize(( - x, - commit_strategy, - CommitSignatures { - // SAFETY: signatures for all bundles of succeeded process transactions - // have been added above - process_signature: *processed_signatures - .get(&bundle_id) - .unwrap(), - finalize_signature: sig, - undelegate_signature: None, - }, - )) - }) - .collect::>() - }, - )); - - let mut finalized_commit_infos = vec![]; - let mut finalized_signatures = HashMap::new(); - for (sig, commit_infos) in succeeded_finalize { - trace!( - "Successfully finalized {} commit infos via transaction '{}'", - commit_infos.len(), - sig - ); - for (commit_info, kind) in commit_infos.iter() { - debug_assert_eq!( - kind, - &InstructionsKind::Finalize, - "Expecting separate finalize instructions only" - ); - let bundle_id = commit_info.bundle_id(); - debug_assert!( - finalized_signatures - .get(&bundle_id) - .map(|x| x == &sig) - .unwrap_or(true), - "BUG: Same finalized bundle ids should have the same signature" - ); - - finalized_signatures.insert(bundle_id, sig); - } - let commit_infos = commit_infos - .into_iter() - .map(|(info, _)| info) - .collect::>(); - finalized_commit_infos.extend(commit_infos); - } - // 4.2. Consider undelegation by first dividing finalized accounts into two sets, - let (finalize_and_undelegate, finalize_only) = - finalized_commit_infos - .into_iter() - .partition::, _>(|x| x.undelegate()); - // 4.3.a accounts we don't need to undelegate are done - commit_stages.extend(finalize_only.into_iter().map(|x| { - let bundle_id = x.bundle_id(); - CommitStage::Succeeded(( - x, - commit_strategy, - CommitSignatures { - // SAFETY: signatures for all bundles of succeeded process transactions - // have been added above - process_signature: *processed_signatures - .get(&bundle_id) - .unwrap(), - finalize_signature: finalized_signatures - .get(&bundle_id) - .cloned(), - undelegate_signature: None, - }, - )) - })); - // 4.3.b the other accounts need to be undelegated first - if let Some(accounts) = accounts_to_undelegate { - debug_assert_eq!( - accounts.len(), - finalize_and_undelegate.len(), - "BUG: same amount of accounts to undelegate as to finalize and undelegate" - ); - let undelegate_ixs = match undelegate_commitables_ixs( - &processor.magicblock_rpc_client, - processor.authority.pubkey(), - accounts, - ) - .await - { - Ok(ixs) => Some(ixs), - Err(err) => { - error!( - "Failed to prepare accounts undelegation '{}': {:?}", - err, err - ); - commit_stages.extend( - finalize_and_undelegate.iter().map(|x| { - let bundle_id = x.bundle_id(); - CommitStage::FailedUndelegate(( - x.clone(), - CommitStrategy::args(use_lookup), - CommitSignatures { - // SAFETY: signatures for all bundles of succeeded process transactions - // have been added above - process_signature: - *processed_signatures - .get(&bundle_id) - .unwrap(), - finalize_signature: - finalized_signatures - .get(&bundle_id) - .cloned(), - undelegate_signature: err.signature(), - }, - )) - }), - ); - None - } - }; - if let Some(undelegate_ixs) = undelegate_ixs { - let chunked_ixs = chunked_ixs_to_undelegate_commitables( - undelegate_ixs, - finalize_and_undelegate, - use_lookup, - ); - let (succeeded_undelegate, failed_undelegate): ( - Vec<_>, - Vec<_>, - ) = processor - .process_ixs_chunks( - chunked_ixs, - None, - table_mania.as_ref(), - &owners, - ) - .await; - - commit_stages.extend( - failed_undelegate.into_iter().flat_map( - |(sig, infos)| { - infos - .into_iter() - .map(|x| { - let bundle_id = x.bundle_id(); - CommitStage::FailedUndelegate(( - x, - commit_strategy, - CommitSignatures { - // SAFETY: signatures for all bundles of succeeded process transactions - // have been added above - process_signature: - *processed_signatures - .get(&bundle_id) - .unwrap(), - finalize_signature: - finalized_signatures - .get(&bundle_id) - .cloned(), - undelegate_signature: sig, - }, - )) - }) - .collect::>() - }, - ), - ); - commit_stages.extend( - succeeded_undelegate.into_iter().flat_map( - |(sig, infos)| { - infos - .into_iter() - .map(|(x, _)| { - let bundle_id = x.bundle_id(); - CommitStage::Succeeded(( - x, - commit_strategy, - CommitSignatures { - // SAFETY: signatures for all bundles of succeeded process transactions - // have been added above - process_signature: - *processed_signatures - .get(&bundle_id) - .unwrap(), - finalize_signature: - finalized_signatures - .get(&bundle_id) - .cloned(), - undelegate_signature: Some(sig), - }, - )) - }) - .collect::>() - }, - ), - ); - } - } else { - debug_assert!( - finalize_and_undelegate.is_empty(), - "BUG: We should either have accounts to undelegate or an empty finalize_and_undelegate" - ); - } - } else { - commit_stages.extend(processed_commit_infos.into_iter().map(|x| { - let bundle_id = x.bundle_id(); - CommitStage::Succeeded(( - x, - commit_strategy, - CommitSignatures { - // SAFETY: signatures for all bundles of succeeded process transactions - // have been added above - process_signature: *processed_signatures - .get(&bundle_id) - .unwrap(), - finalize_signature: None, - undelegate_signature: None, - }, - )) - })); - } - - debug_assert_eq!( - accounts_len, - CommitStage::commit_infos(&commit_stages).len(), - "Should have one commit stage per commmitted account ({}) {:#?}", - accounts_len, - commit_stages - ); - - commit_stages - } - - async fn prepare_changeset_buffers( - &self, - changeset: Changeset, - ephemeral_blockhash: Hash, - commit_strategy: CommitStrategy, - finalize: bool, - ) -> Vec> { - let commitables = - changeset.into_committables(crate::consts::MAX_WRITE_CHUNK_SIZE); - let mut join_set: JoinSet> = - JoinSet::new(); - for commitable in commitables { - let me = Arc::new(self.clone()); - join_set.spawn(Self::commit_account( - me, - commitable, - ephemeral_blockhash, - commit_strategy, - finalize, - )); - } - join_set.join_all().await - } - - async fn commit_account( - me: Arc, - mut commitable: CommitableAccount, - ephemeral_blockhash: Hash, - commit_strategy: CommitStrategy, - finalize: bool, - ) -> CommitAccountResult { - let commit_info = if commitable.has_data() { - let chunks = - Chunks::new(commitable.chunk_count(), commitable.chunk_size()); - let chunks_account_size = to_vec(&chunks).unwrap().len() as u64; - - // Initialize the Changeset and Chunks accounts on chain - let buffer_account_size = commitable.size() as u64; - - let (init_ix, chunks_pda, buffer_pda) = - create_init_ix(CreateInitIxArgs { - authority: me.authority.pubkey(), - pubkey: commitable.pubkey, - chunks_account_size, - buffer_account_size, - commit_id: 0, // TODO(edwin) - chunk_count: commitable.chunk_count(), - chunk_size: commitable.chunk_size(), - }); - let realloc_ixs = - create_realloc_buffer_ixs(CreateReallocBufferIxArgs { - authority: me.authority.pubkey(), - pubkey: commitable.pubkey, - buffer_account_size, - commit_id: 0, // TODO(edwin) - }); - - let commit_info = CommitInfo::BufferedDataAccount { - pubkey: commitable.pubkey, - commit_state: commit_state_pda_from_delegated_account( - &commitable.pubkey, - ), - delegated_account_owner: commitable.delegated_account_owner, - slot: commitable.slot, - ephemeral_blockhash, - undelegate: commitable.undelegate, - chunks_pda, - buffer_pda, - lamports: commitable.lamports, - bundle_id: commitable.bundle_id, - finalize, - }; - - // Even though this transaction also inits the chunks account we check - // that it succeeded by querying the buffer account since this is the - // only of the two that we may have to realloc. - let commit_info = Arc::new( - me.init_accounts( - init_ix, - realloc_ixs, - commitable.pubkey, - &buffer_pda, - buffer_account_size, - ephemeral_blockhash, - commit_info, - commit_strategy, - ) - .await?, - ); - - let mut last_write_chunks_err = None; - if let Err(err) = me - .write_chunks( - commitable.pubkey, - commitable.iter_all(), - ephemeral_blockhash, - ) - .await - { - last_write_chunks_err = Some(err); - }; - - let mut remaining_tries = 10; - const MAX_GET_ACCOUNT_RETRIES: usize = 5; - loop { - let mut acc = None; - let mut last_get_account_err = None; - for _ in 0..MAX_GET_ACCOUNT_RETRIES { - match me - .magicblock_rpc_client - .get_account(&chunks_pda) - .await - { - Ok(Some(x)) => { - acc.replace(x); - break; - } - Ok(None) => { - me.wait_for_account("chunks account", None).await - } - Err(err) => { - me.wait_for_account("chunks account", Some(&err)) - .await; - last_get_account_err.replace(err); - } - } - } - let Some(acc) = acc else { - return Err(CommitAccountError::GetChunksAccount( - last_get_account_err, - commit_info.clone(), - commit_strategy, - )); - }; - let chunks = - Chunks::try_from_slice(&acc.data).map_err(|err| { - CommitAccountError::DeserializeChunksAccount( - err, - commit_info.clone(), - commit_strategy, - ) - })?; - - if chunks.is_complete() { - break; - } - - remaining_tries -= 1; - if remaining_tries == 0 { - return Err( - CommitAccountError::WriteChunksRanOutOfRetries( - last_write_chunks_err, - commit_info.clone(), - commit_strategy, - ), - ); - } - commitable.set_chunks(chunks); - if let Err(err) = me - .write_chunks( - commitable.pubkey, - commitable.iter_missing(), - ephemeral_blockhash, - ) - .await - { - last_write_chunks_err = Some(err); - } - } - commit_info - } else { - Arc::new(CommitInfo::EmptyAccount { - pubkey: commitable.pubkey, - delegated_account_owner: commitable.delegated_account_owner, - slot: commitable.slot, - ephemeral_blockhash, - undelegate: commitable.undelegate, - lamports: commitable.lamports, - bundle_id: commitable.bundle_id, - finalize, - }) - }; - - let commit_info = Arc::::unwrap_or_clone(commit_info); - - Ok(commit_info) - } - - /// Sends init/realloc transactions until the account has the desired size - /// - `init_ix` - the instruction to initialize the buffer and chunk account - /// - `realloc_ixs` - the instructions to realloc the buffer account until it reaches the - /// size needed to store the account's data - /// - `pubkey` - the pubkey of the account whose data we are storing - /// - `buffer_pda` - the address of the account where we buffer the data to be committed - /// - `buffer_account_size` - the size of the buffer account - /// - `ephemeral_blockhash` - the blockhash in the ephemeral at which we are committing - /// - `commit_info` - the commit info to be returned or included in errors - /// - `commit_strategy` - the commit strategy that is used - #[allow(clippy::too_many_arguments)] // private method - async fn init_accounts( - &self, - init_ix: Instruction, - realloc_ixs: Vec, - pubkey: Pubkey, - buffer_pda: &Pubkey, - buffer_account_size: u64, - ephemeral_blockhash: Hash, - commit_info: CommitInfo, - commit_strategy: CommitStrategy, - ) -> CommitAccountResult { - // We cannot allocate more than MAX_INITIAL_BUFFER_SIZE in a single - // instruction. Therefore we append a realloc instruction if the buffer - // is very large. - // init_ixs is the init ix with as many realloc ixs as fit into one tx - // extra_realloc_ixs are the remaining realloc ixs that need to be sent - // in separate transactions - let (init_ix_chunk, extra_realloc_ix_chunks) = { - let mut chunked_ixs = chunk_realloc_ixs(realloc_ixs, Some(init_ix)); - let init_with_initial_reallocs = chunked_ixs.remove(0); - let remaining_reallocs = if chunked_ixs.is_empty() { - None - } else { - Some(chunked_ixs) - }; - (init_with_initial_reallocs, remaining_reallocs) - }; - - debug!( - "Init+Realloc chunk ixs {}, Extra Realloc Chunks {}", - init_ix_chunk.len(), - extra_realloc_ix_chunks.as_ref().map_or(0, |x| x.len()) - ); - - // First ensure that the tx including the init ix lands - let mut init_sig = None; - let mut last_err = None; - const MAX_RETRIES: usize = 2; - 'land_init_transaction: for _ in 0..MAX_RETRIES { - // Only retry the init transaction if it failed to send and confirm - if init_sig.is_none() { - let init_budget_ixs = self - .compute_budget_config - .buffer_init - .instructions(init_ix_chunk.len() - 1); - match send_and_confirm( - self.magicblock_rpc_client.clone(), - &self.authority, - [init_budget_ixs, init_ix_chunk.clone()].concat(), - "init buffer and chunk account".to_string(), - None, - MagicBlockSendTransactionConfig::ensure_committed(), - None, - ) - .await - { - Err(err) => { - last_err = Some(err); - continue; - } - Ok(sig) => { - init_sig = Some(sig); - } - } - } - - // At this point the transaction was confirmed and we should be able - // to get the initialized pda and chunk account - const MAX_GET_ACCOUNT_RETRIES: usize = 5; - for _ in 0..MAX_GET_ACCOUNT_RETRIES { - match self.magicblock_rpc_client.get_account(buffer_pda).await { - Ok(Some(_)) => { - // The account was initialized - break 'land_init_transaction; - } - Ok(None) => { - self.wait_for_account("buffer account", None).await - } - Err(err) => { - self.wait_for_account("buffer account", Some(&err)) - .await - } - } - } - } // 'land_init_transaction - - if init_sig.is_none() { - let err = last_err - .as_ref() - .map(|x| x.to_string()) - .unwrap_or("Unknown Error".to_string()); - return Err(CommitAccountError::InitBufferAndChunkAccounts( - err, - Box::new(commit_info), - commit_strategy, - )); - } - - // After that we can ensure all extra reallocs in parallel - if let Some(realloc_ixs) = extra_realloc_ix_chunks { - let mut next_reallocs = self - .run_reallocs( - buffer_pda, - realloc_ixs, - buffer_account_size, - buffer_account_size, - 0, - ) - .await; - - if next_reallocs.is_some() { - let args = CreateReallocBufferIxArgs { - authority: self.authority.pubkey(), - pubkey, - buffer_account_size, - commit_id: 0, // TODO(edwin) - }; - - const MAX_STALE_REALLOCS: u8 = 10; - let mut prev_missing_size = 0; - let mut remaining_tries = MAX_STALE_REALLOCS; - while let Some(NextReallocs { - missing_size, - start_idx, - err, - }) = next_reallocs - { - if missing_size == prev_missing_size { - remaining_tries -= 1; - if remaining_tries == 0 { - return Err( - CommitAccountError::ReallocBufferRanOutOfRetries( - err.unwrap_or("No Error".to_string()), - Arc::new(commit_info.clone()), - commit_strategy, - ), - ); - } - } else { - remaining_tries = MAX_STALE_REALLOCS; - prev_missing_size = missing_size; - } - let realloc_ixs = { - let realloc_ixs = - create_realloc_buffer_ixs_to_add_remaining( - &args, - missing_size, - ); - - chunk_realloc_ixs(realloc_ixs, None) - }; - next_reallocs = self - .run_reallocs( - buffer_pda, - realloc_ixs, - buffer_account_size, - missing_size, - start_idx, - ) - .await; - } - } - } - - Ok(commit_info) - } - - /// Returns the size that still needs to be allocated after running the instructions - /// along with the idx at which we start (in order to keep increasing the idx of realloc - /// attempt). - /// Returns `None` once the desired size is reached and we're done. - async fn run_reallocs( - &self, - pda: &Pubkey, - realloc_ixs: Vec>, - desired_size: u64, - missing_size: u64, - start_idx: usize, - ) -> Option { - let mut join_set = JoinSet::new(); - let count = realloc_ixs.len(); - let latest_blockhash = - match self.magicblock_rpc_client.get_latest_blockhash().await { - Ok(hash) => hash, - Err(err) => { - error!( - "Failed to get latest blockhash to run reallocs: {:?}", - err - ); - return Some(NextReallocs { - missing_size, - start_idx, - err: Some(format!("{:?}", err)), - }); - } - }; - for (idx, ixs) in realloc_ixs.into_iter().enumerate() { - let authority = self.authority.insecure_clone(); - let rpc_client = self.magicblock_rpc_client.clone(); - let realloc_budget_ixs = self - .compute_budget_config - .buffer_realloc - .instructions(ixs.len()); - // NOTE: we ignore failures to send/confirm realloc transactions and just - // keep calling [CommittorProcessor::run_reallocs] until we reach the desired size - join_set.spawn(async move { - send_and_confirm( - rpc_client, - &authority, - [realloc_budget_ixs, ixs].concat(), - format!( - "realloc buffer account {}/{}", - start_idx + idx, - start_idx + count - ), - Some(latest_blockhash), - MagicBlockSendTransactionConfig::ensure_processed(), - None, - ) - .await - .inspect_err(|err| { - warn!("{:?}", err); - }) - }); - } - join_set.join_all().await; - - match self.magicblock_rpc_client.get_account(pda).await { - Ok(Some(acc)) => { - // Once the account has the desired size we are done - let current_size = acc.data.len(); - if current_size as u64 >= desired_size { - None - } else { - Some((desired_size - current_size as u64, None)) - } - } - // NOTE: if we cannot get the account we must assume that - // the entire size we just tried to alloc is still missing - Ok(None) => { - warn!("buffer account not found"); - Some(( - missing_size, - Some("buffer account not found".to_string()), - )) - } - Err(err) => { - warn!("Failed to get buffer account: {:?}", err); - Some((missing_size, Some(format!("{:?}", err)))) - } - } - .map(|(missing_size, err)| NextReallocs { - missing_size, - start_idx: count, - err, - }) - } - - /// Sends a transaction to write each chunk. - /// Initially it gets latest blockhash and errors if that fails. - /// All other errors while sending the transaction are logged and ignored. - /// The chunks whose write transactions failed are expected to be retried in - /// the next run. - /// - `pubkey` - the on chain pubkey of the account whose data we are writing to the buffer - /// - `chunks` - the chunks to write - /// - `ephemeral_blockhash` - the blockhash to use for the transaction - async fn write_chunks>( - &self, - pubkey: Pubkey, - chunks: Iter, - ephemeral_blockhash: Hash, - ) -> MagicBlockRpcClientResult<()> { - let mut join_set = JoinSet::new(); - - let latest_blockhash = - self.magicblock_rpc_client.get_latest_blockhash().await?; - - for chunk in chunks.into_iter() { - let authority = self.authority.insecure_clone(); - let rpc_client = self.magicblock_rpc_client.clone(); - let chunk_bytes = chunk.data_chunk.len(); - let ix = create_write_ix(CreateWriteIxArgs { - authority: authority.pubkey(), - pubkey, - offset: chunk.offset, - data_chunk: chunk.data_chunk, - commit_id: 0, // TODO(edwin) - }); - let write_budget_ixs = self - .compute_budget_config - .buffer_write - .instructions(chunk_bytes); - // NOTE: we ignore failures to send/confirm write transactions and just - // keep calling [CommittorProcessor::write_chunks] until all of them are - // written which is verified via the chunks account - join_set.spawn(async move { - send_and_confirm( - rpc_client, - &authority, - [write_budget_ixs, vec![ix]].concat(), - format!("write chunk for offset {}", chunk.offset), - Some(latest_blockhash), - // NOTE: We could use `processed` here and wait to get the processed status at - // least which would make things a bit slower. - // However that way we would avoid sending unnecessary transactions potentially - // since we may not see some written chunks yet when we get the chunks account. - MagicBlockSendTransactionConfig::ensure_processed(), - None, - ) - .await - .inspect_err(|err| { - error!("{:?}", err); - }) - }); - } - if log::log_enabled!(log::Level::Trace) { - trace!("Writing {} chunks", join_set.len()); - } - - join_set.join_all().await; - - Ok(()) - } - - async fn wait_for_account( - &self, - account_label: &str, - err: Option<&MagicBlockRpcClientError>, - ) { - let sleep_time_ms = { - if let Some(err) = err { - error!("Failed to {} account: {:?}", account_label, err); - } else { - warn!("Failed to {} account", account_label); - } - 100 - }; - tokio::time::sleep(Duration::from_millis(sleep_time_ms)).await; - } -} diff --git a/magicblock-committor-service/src/commit/common.rs b/magicblock-committor-service/src/commit/common.rs deleted file mode 100644 index 50c3f7ace..000000000 --- a/magicblock-committor-service/src/commit/common.rs +++ /dev/null @@ -1,207 +0,0 @@ -use std::{ - collections::{HashMap, HashSet}, - time::{Duration, Instant}, -}; - -use log::*; -use magicblock_committor_program::Changeset; -use magicblock_rpc_client::{ - MagicBlockSendTransactionConfig, MagicblockRpcClient, -}; -use magicblock_table_mania::TableMania; -use solana_pubkey::Pubkey; -use solana_sdk::{ - hash::Hash, - instruction::Instruction, - message::{v0::Message, VersionedMessage}, - signature::{Keypair, Signature}, - signer::Signer, - transaction::VersionedTransaction, -}; - -use crate::{ - error::{CommittorServiceError, CommittorServiceResult}, - pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, -}; - -pub(crate) fn lookup_table_keys( - authority: &Keypair, - committees: &HashSet, - owners: &HashMap, -) -> HashSet { - committees - .iter() - .flat_map(|x| provide_committee_pubkeys(x, owners.get(x))) - .chain(provide_common_pubkeys(&authority.pubkey())) - .collect::>() -} - -/// Returns the pubkeys of the accounts that are marked for undelegation we finalized -/// the commits of those accounts. -/// If we didn't finalize the commits then we cannot yet undelegate those accounts. -/// Returns tuples of the account to undelegate and its original owner -pub(crate) fn get_accounts_to_undelegate( - changeset: &Changeset, - finalize: bool, -) -> Option> { - if finalize { - let vec = changeset.accounts_to_undelegate.iter().flat_map(|x| { - let Some(acc) = changeset.accounts.get(x) else { - warn!("Account ({}) marked for undelegation not found in changeset", x); - return None; - }; - Some((*x, acc.owner())) - }).collect::>(); - (!vec.is_empty()).then_some(vec) - } else { - // if we don't finalize then we can only _mark_ accounts for undelegation - // but cannot run the undelegation instruction itself - None - } -} - -/// Gets the latest blockhash and sends and confirms a transaction with -/// the provided instructions. -/// Uses the commitment provided via the [ChainConfig::commitment] option when checking -/// the status of the transction signature. -/// - **rpc_client** - the rpc client to use -/// - **authority** - the authority to sign the transaction -/// - **ixs** - the instructions to include in the transaction -/// - **task_desc** - a description of the task included in logs -/// - **latest_blockhash** - the latest blockhash to use for the transaction, -/// if not provided it will be queried -/// - **send_config** - the send transaction config to use -/// - **use_table_mania** - whether to use table mania to optimize the size increase due -/// to accounts in the transaction via the use of lookup tables -/// -/// Returns the signature of the transaction. -pub(crate) async fn send_and_confirm( - rpc_client: MagicblockRpcClient, - authority: &Keypair, - ixs: Vec, - task_desc: String, - latest_blockhash: Option, - send_config: MagicBlockSendTransactionConfig, - table_mania_setup: Option<(&TableMania, HashSet)>, -) -> CommittorServiceResult { - use CommittorServiceError::*; - // When lots of txs are spawned in parallel we reuse the blockhash - // instead of getting it for each tx - let latest_blockhash = if let Some(blockhash) = latest_blockhash { - blockhash - } else { - rpc_client.get_latest_blockhash().await.inspect_err(|err| { - error!( - "Failed to get latest blockhash to '{}': {:?}", - task_desc, err - ) - })? - }; - - let tables = - if let Some((table_mania, keys_from_tables)) = table_mania_setup { - let start = Instant::now(); - - // NOTE: we assume that all needed pubkeys were reserved earlier - let address_lookup_tables = table_mania - .try_get_active_address_lookup_table_accounts( - &keys_from_tables, - // enough time for init/extend lookup table transaction to complete - Duration::from_secs(50), - // enough time for lookup table to finalize - Duration::from_secs(50), - ) - .await?; - - if log_enabled!(Level::Trace) { - let tables = address_lookup_tables - .iter() - .map(|table| { - format!( - "\n {}: {} addresses", - table.key, - table.addresses.len() - ) - }) - .collect::>() - .join(", "); - trace!( - "Took {}ms to get finalized address lookup table(s) {}", - start.elapsed().as_millis(), - tables - ); - let all_accounts = ixs - .iter() - .flat_map(|ix| ix.accounts.iter().map(|x| x.pubkey)); - let keys_not_from_table = all_accounts - .filter(|x| !keys_from_tables.contains(x)) - .collect::>(); - trace!( - "{}/{} are provided from lookup tables", - keys_from_tables.len(), - keys_not_from_table.len() + keys_from_tables.len() - ); - trace!( - "The following keys are not:\n{}", - keys_not_from_table - .iter() - .map(|x| format!(" {}", x)) - .collect::>() - .join("\n") - ); - } - - address_lookup_tables - } else { - vec![] - }; - - let versioned_msg = match Message::try_compile( - &authority.pubkey(), - &ixs, - &tables, - latest_blockhash, - ) { - Ok(msg) => msg, - Err(err) => { - return Err( - CommittorServiceError::FailedToCompileTransactionMessage( - task_desc.clone(), - err, - ), - ); - } - }; - let tx = match VersionedTransaction::try_new( - VersionedMessage::V0(versioned_msg), - &[authority], - ) { - Ok(tx) => tx, - Err(err) => { - return Err(CommittorServiceError::FailedToCreateTransaction( - task_desc.clone(), - err, - )); - } - }; - - let start = Instant::now(); - let res = rpc_client - .send_transaction(&tx, &send_config) - .await - .map_err(|err| { - FailedToSendAndConfirmTransaction(task_desc.clone(), err) - })?; - - trace!( - "Took {}ms to send and confirm transaction with {} instructions", - start.elapsed().as_millis(), - ixs.len() - ); - - if let Some(err) = res.error() { - Err(EncounteredTransactionError(task_desc, err.clone())) - } else { - Ok(res.into_signature()) - } -} diff --git a/magicblock-committor-service/src/commit/mod.rs b/magicblock-committor-service/src/commit/mod.rs deleted file mode 100644 index e539b881a..000000000 --- a/magicblock-committor-service/src/commit/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod commit_using_args; -mod commit_using_buffer; -mod committor_processor; -mod common; -mod process_buffers; - -pub(super) use committor_processor::CommittorProcessor; diff --git a/magicblock-committor-service/src/commit/process_buffers.rs b/magicblock-committor-service/src/commit/process_buffers.rs deleted file mode 100644 index ea3ff5acb..000000000 --- a/magicblock-committor-service/src/commit/process_buffers.rs +++ /dev/null @@ -1,234 +0,0 @@ -use std::collections::HashMap; - -use dlp::args::CommitStateFromBufferArgs; -use log::*; -use solana_pubkey::Pubkey; - -use crate::{ - bundles::{bundle_chunks, bundle_chunks_ignoring_bundle_id}, - transactions::{ - close_buffers_ix, process_and_close_ixs, process_commits_ix, - MAX_CLOSE_PER_TX, MAX_CLOSE_PER_TX_USING_LOOKUP, - MAX_PROCESS_AND_CLOSE_PER_TX, - MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP, MAX_PROCESS_PER_TX, - MAX_PROCESS_PER_TX_USING_LOOKUP, - }, - types::{InstructionsForCommitable, InstructionsKind}, - CommitInfo, -}; - -/// Returns instructions to process the commit/delegation request for a commitable. -/// Requires that the [CommitInfo::buffer_pda] holds all data to be committed. -/// It appends another instruction which closes both the [CommitInfo::buffer_pda] -/// and the [CommitInfo::chunks_pda]. -fn process_commitable_and_close_ixs( - validator_auth: Pubkey, - commit_info: CommitInfo, -) -> InstructionsForCommitable { - debug!("Processing commitable: {:?}", commit_info); - let CommitInfo::BufferedDataAccount { - pubkey, - delegated_account_owner, - slot, - ephemeral_blockhash, - undelegate, - buffer_pda, - lamports, - .. - } = &commit_info - else { - panic!("Only data accounts are supported for now"); - }; - - let commit_args = CommitStateFromBufferArgs { - slot: *slot, - lamports: *lamports, - allow_undelegation: *undelegate, - }; - - let instructions = process_and_close_ixs( - validator_auth, - pubkey, - delegated_account_owner, - buffer_pda, - ephemeral_blockhash, - commit_args, - ); - InstructionsForCommitable { - instructions, - commit_info, - kind: InstructionsKind::ProcessAndCloseBuffers, - } -} - -fn close_buffers_separate_ix( - validator_auth: Pubkey, - commit_info: CommitInfo, -) -> InstructionsForCommitable { - debug!("Processing commitable: {:?}", commit_info); - let CommitInfo::BufferedDataAccount { pubkey, .. } = &commit_info else { - panic!("Only data accounts are supported for now"); - }; - - // TODO(edwin)L fix commit_id - let close_ix = close_buffers_ix(validator_auth, pubkey, 0); - InstructionsForCommitable { - instructions: vec![close_ix], - commit_info, - kind: InstructionsKind::CloseBuffers, - } -} - -fn process_commitable_separate_ix( - validator_auth: Pubkey, - commit_info: CommitInfo, -) -> InstructionsForCommitable { - let CommitInfo::BufferedDataAccount { - pubkey, - delegated_account_owner, - slot, - undelegate, - buffer_pda, - lamports, - .. - } = &commit_info - else { - panic!("Only data accounts are supported for now"); - }; - - let commit_args = CommitStateFromBufferArgs { - slot: *slot, - lamports: *lamports, - allow_undelegation: *undelegate, - }; - - let process_ix = process_commits_ix( - validator_auth, - pubkey, - delegated_account_owner, - buffer_pda, - commit_args, - ); - InstructionsForCommitable { - instructions: vec![process_ix], - commit_info, - kind: InstructionsKind::Process, - } -} - -pub(crate) struct ChunkedIxsToProcessCommitablesAndClosePdasResult { - /// Chunked instructions to process buffers and possibly also close them - /// Since they are part of the same transaction and correctly ordered, each - /// chunk can run in parallel - pub chunked_ixs: Vec>, - /// Separate buffer close transactions. - /// Since the process transactions need to complete first we need to run them - /// after the [Self::chunked_ixs] transactions - pub chunked_close_ixs: Option>>, - /// Commitables that could not be chunked and thus cannot be committed while - /// respecting the bundle - pub unchunked: HashMap>, -} - -/// Processes commits -/// Creates single instruction chunk for commmitables with matching bundle_id -pub(crate) fn chunked_ixs_to_process_commitables_and_close_pdas( - validator_auth: Pubkey, - commit_infos: Vec, - use_lookup: bool, -) -> ChunkedIxsToProcessCommitablesAndClosePdasResult { - // First try to combine process and close into a single transaction - let max_per_chunk = if use_lookup { - MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP - } else { - MAX_PROCESS_AND_CLOSE_PER_TX - }; - let bundles_with_close = - bundle_chunks(commit_infos, max_per_chunk as usize); - - // Add instruction chunks that include process and close - let mut chunked_ixs: Vec<_> = bundles_with_close - .chunks - .into_iter() - .map(|chunk| { - chunk - .into_iter() - .map(|commit_info| { - process_commitable_and_close_ixs( - validator_auth, - commit_info, - ) - }) - .collect::>() - }) - .collect(); - - // If all bundles can be handled combining process and close then we're done - let all_bundles_handled = bundles_with_close.unchunked.is_empty(); - if all_bundles_handled { - return ChunkedIxsToProcessCommitablesAndClosePdasResult { - chunked_ixs, - chunked_close_ixs: None, - unchunked: bundles_with_close.unchunked, - }; - } - - // If not all chunks fit when trying to close and process in one transaction - // then let's process them separately - let unbundled_commit_infos = bundles_with_close - .unchunked - .into_iter() - .flat_map(|(_, commit_infos)| commit_infos) - .collect::>(); - - // For the bundles that are too large to include the close instructions add them - // as separate instruction chunks, one for process (which is the only part - // that needs to run atomic for a bundle) and another chunk for the close buffer - // instructions - let close_bundles = { - let max_per_chunk = if use_lookup { - MAX_CLOSE_PER_TX_USING_LOOKUP - } else { - MAX_CLOSE_PER_TX - }; - bundle_chunks_ignoring_bundle_id( - &unbundled_commit_infos, - max_per_chunk as usize, - ) - }; - - let process_bundles_with_separate_close = { - let max_per_chunk = if use_lookup { - MAX_PROCESS_PER_TX_USING_LOOKUP - } else { - MAX_PROCESS_PER_TX - }; - bundle_chunks(unbundled_commit_infos, max_per_chunk as usize) - }; - for bundle in process_bundles_with_separate_close.chunks { - let mut process_ixs = Vec::new(); - for commit_info in bundle { - let process_ix = - process_commitable_separate_ix(validator_auth, commit_info); - process_ixs.push(process_ix); - } - chunked_ixs.push(process_ixs); - } - - let mut close_ixs_chunks = Vec::new(); - for bundle in close_bundles.chunks { - let mut close_ixs = Vec::new(); - for commit_info in bundle { - let close_ix = - close_buffers_separate_ix(validator_auth, commit_info); - close_ixs.push(close_ix); - } - close_ixs_chunks.push(close_ixs); - } - - ChunkedIxsToProcessCommitablesAndClosePdasResult { - chunked_ixs, - chunked_close_ixs: Some(close_ixs_chunks), - unchunked: process_bundles_with_separate_close.unchunked, - } -} diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index 39df524b9..2156d9b68 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -84,12 +84,18 @@ impl CommitSchedulerInner { return Some(l1_message); }; - let (entries, is_conflicting) = - Self::find_conflicting_entries(&pubkeys, &mut self.blocked_keys); + // Check if there are any conflicting keys + let is_conflicting = pubkeys + .iter() + .any(|pubkey| self.blocked_keys.contains_key(pubkey)); // In any case block the corresponding accounts - entries - .into_iter() - .for_each(|entry| entry.or_default().push_back(message_id)); + pubkeys.iter().for_each(|pubkey| { + self.blocked_keys + .entry(*pubkey) + .or_default() + .push_back(message_id) + }); + if is_conflicting { // Enqueue incoming message self.blocked_messages.insert( @@ -116,10 +122,10 @@ impl CommitSchedulerInner { return; }; - let (entries, _) = - Self::find_conflicting_entries(&pubkeys, &mut self.blocked_keys); - entries.into_iter().for_each(|entry| { - let mut occupied = match entry { + pubkeys + .iter() + .for_each(|pubkey| { + let mut occupied = match self.blocked_keys.entry(*pubkey) { Entry::Vacant(_) => unreachable!("Invariant: queue for conflicting tasks shall exist"), Entry::Occupied(value) => value }; @@ -167,35 +173,6 @@ impl CommitSchedulerInner { } } - fn find_conflicting_entries<'a, 'b>( - pubkeys: &[Pubkey], - blocked_keys: &'a mut HashMap>, - ) -> (Vec>>, bool) - where - 'a: 'b, - { - let mut is_conflicting = false; - let entries = pubkeys - .iter() - .map(|pubkey| { - let entry = blocked_keys.entry(*pubkey); - - if is_conflicting { - entry - } else { - if let Entry::Occupied(_) = &entry { - is_conflicting = true; - entry - } else { - entry - } - } - }) - .collect(); - - (entries, is_conflicting) - } - /// Returns number of blocked messages /// Note: this doesn't include "executing" messages pub fn blocked_messages_len(&self) -> usize { diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index f42dc7017..8c9700906 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -90,7 +90,7 @@ where /// Spawns `main_loop` and return `Receiver` listening to results pub fn spawn( - mut self, + self, ) -> broadcast::Receiver { let (result_sender, result_receiver) = broadcast::channel(100); tokio::spawn(self.main_loop(result_sender)); diff --git a/magicblock-committor-service/src/commit_stage.rs b/magicblock-committor-service/src/commit_stage.rs deleted file mode 100644 index 328e6597a..000000000 --- a/magicblock-committor-service/src/commit_stage.rs +++ /dev/null @@ -1,339 +0,0 @@ -use std::sync::Arc; - -use log::*; -use magicblock_committor_program::ChangedAccountMeta; -use solana_pubkey::Pubkey; -use solana_sdk::{clock::Slot, signature::Signature}; - -use crate::{ - error::CommitAccountError, - persist::{CommitStatus, CommitStatusSignatures, CommitStrategy}, - CommitInfo, -}; - -#[derive(Debug, Clone)] -pub struct CommitSignatures { - /// The signature of the transaction processing the commit - pub process_signature: Signature, - /// The signature of the transaction finalizing the commit. - /// If the account was not finalized or it failed then this is `None`. - /// If the finalize instruction was part of the process transaction then - /// this signature is the same as [Self::process_signature]. - pub finalize_signature: Option, -} - -impl CommitSignatures { - pub fn process_only(process_signature: Signature) -> Self { - Self { - process_signature, - finalize_signature: None, - } - } -} - -impl From for CommitStatusSignatures { - fn from(commit_signatures: CommitSignatures) -> Self { - Self { - process_signature: commit_signatures.process_signature, - finalize_signature: commit_signatures.finalize_signature, - } - } -} - -// TODO(edwin): integrate -#[derive(Debug)] -pub enum CommitStage { - /// This account was part of a changeset that could not be split into - /// args only/args with lookup table or buffered changesets. - /// The commit for this account needs to be restarted from scratch. - SplittingChangesets((ChangedAccountMeta, Slot, bool)), - - /// This account was part of a changeset for which we could not obtain the - /// latest on chain blockhash when trying to commit them via args. - /// The commit for this account needs to be restarted from scratch. - GettingLatestBlockhash((ChangedAccountMeta, Slot, bool, CommitStrategy)), - - /// No part of the commit pipeline succeeded. - /// The commit for this account needs to be restarted from scratch. - Failed((CommitInfo, CommitStrategy)), - - /// The buffer and chunks account were initialized, but could either not - /// be retrieved or deserialized. It is recommended to fully re-initialize - /// them on retry. - BufferAndChunkPartiallyInitialized((CommitInfo, CommitStrategy)), - - /// The buffer and chunks accounts were initialized and all data was - /// written to them (for data accounts). - /// This means on retry we can skip that step and just try to process - /// these buffers to complete the commit. - /// This stage is returned in the following scenarios: - /// - the commit could not be processed - /// - another account in the same bundle failed to fully initialize - /// the buffer and chunks accounts and thus the bundle could not be - /// processed - BufferAndChunkFullyInitialized((CommitInfo, CommitStrategy)), - - /// The commit is part of a bundle that contains too many commits to be included - /// in a single transaction. Thus we cannot commit any of them. - /// The max amount of accounts we can commit and process as part of a single - /// transaction is [crate::max_per_transaction::MAX_COMMIT_STATE_AND_CLOSE_PER_TRANSACTION]. - /// These commits were prepared, which means the buffer and chunk accounts were fully - /// initialized, but then this issue was detected. - PartOfTooLargeBundleToProcess(CommitInfo), - - /// The commit was properly initialized and added to a chunk of instructions to process - /// commits via a transaction. For large commits the buffer and chunk accounts were properly - /// prepared and haven't been closed. - /// However that transaction failed. - FailedProcess((CommitInfo, CommitStrategy, Option)), - - /// The commit was properly processed but the finalize instructions didn't fit into a single - /// transaction. - /// This should never happen since otherwise the [CommitStage::PartOfTooLargeBundleToProcess] - /// would have been returned as the bundle would have been too large to process in the - /// first place. - PartOfTooLargeBundleToFinalize(CommitInfo), - - /// The commit was properly processed but the requested finalize transaction failed. - FailedFinalize((CommitInfo, CommitStrategy, CommitSignatures)), - - /// The commit was properly processed but the requested undelegation transaction failed. - FailedUndelegate((CommitInfo, CommitStrategy, CommitSignatures)), - - /// All stages of the commit pipeline for this account succeeded - /// and we don't have to retry any of them. - /// This means the commit was processed and if so requested also finalized. - /// We are done committing this account. - Succeeded((CommitInfo, CommitStrategy, CommitSignatures)), -} - -impl From for CommitStage { - fn from(err: CommitAccountError) -> Self { - use CommitAccountError::*; - macro_rules! ci { - ($ci:ident) => { - Arc::::unwrap_or_clone($ci) - }; - } - - match err { - InitBufferAndChunkAccounts(err, commit_info, commit_strategy) => { - warn!("Init buffer and chunks accounts failed: {:?}", err); - Self::Failed((*commit_info, commit_strategy)) - } - GetChunksAccount(err, commit_info, commit_strategy) => { - warn!("Get chunks account failed: {:?}", err); - Self::BufferAndChunkPartiallyInitialized(( - ci!(commit_info), - commit_strategy, - )) - } - DeserializeChunksAccount(err, commit_info, commit_strategy) => { - warn!("Deserialize chunks account failed: {:?}", err); - Self::BufferAndChunkPartiallyInitialized(( - ci!(commit_info), - commit_strategy, - )) - } - ReallocBufferRanOutOfRetries(err, commit_info, commit_strategy) => { - warn!("Realloc buffer ran out of retries: {:?}", err); - Self::BufferAndChunkPartiallyInitialized(( - ci!(commit_info), - commit_strategy, - )) - } - WriteChunksRanOutOfRetries(err, commit_info, commit_strategy) => { - warn!("Write chunks ran out of retries: {:?}", err); - Self::BufferAndChunkPartiallyInitialized(( - ci!(commit_info), - commit_strategy, - )) - } - } - } -} - -pub enum CommitMetadata<'a> { - CommitInfo(&'a CommitInfo), - ChangedAccountMeta((&'a ChangedAccountMeta, Slot, bool)), -} - -impl<'a> From<&'a CommitInfo> for CommitMetadata<'a> { - fn from(commit_info: &'a CommitInfo) -> Self { - Self::CommitInfo(commit_info) - } -} - -impl CommitMetadata<'_> { - pub fn pubkey(&self) -> Pubkey { - use CommitMetadata::*; - match self { - CommitInfo(ci) => ci.pubkey(), - ChangedAccountMeta((cm, _, _)) => cm.pubkey, - } - } - - pub fn commit_state(&self) -> Option { - use CommitMetadata::*; - match self { - CommitInfo(ci) => ci.commit_state(), - ChangedAccountMeta((_, _, _)) => None, - } - } - - pub fn bundle_id(&self) -> u64 { - use CommitMetadata::*; - match self { - CommitInfo(ci) => ci.bundle_id(), - ChangedAccountMeta((cm, _, _)) => cm.bundle_id, - } - } -} - -impl CommitStage { - pub fn commit_metadata(&self) -> CommitMetadata<'_> { - use CommitStage::*; - match self { - SplittingChangesets((cm, slot, undelegate)) => { - CommitMetadata::ChangedAccountMeta((cm, *slot, *undelegate)) - } - GettingLatestBlockhash((cm, slot, undelegate, _)) => { - CommitMetadata::ChangedAccountMeta((cm, *slot, *undelegate)) - } - Failed((ci, _)) - | BufferAndChunkPartiallyInitialized((ci, _)) - | BufferAndChunkFullyInitialized((ci, _)) - | PartOfTooLargeBundleToProcess(ci) - | FailedProcess((ci, _, _)) - | PartOfTooLargeBundleToFinalize(ci) - | FailedFinalize((ci, _, _)) - | FailedUndelegate((ci, _, _)) - | Succeeded((ci, _, _)) => CommitMetadata::from(ci), - } - } - - pub fn commit_strategy(&self) -> CommitStrategy { - use CommitStage::*; - match self { - SplittingChangesets((_, _, _)) => CommitStrategy::Undetermined, - - // For the below two the only strategy that would possibly have worked is the one - // allowing most accounts per bundle, thus we return that as the assumed strategy - PartOfTooLargeBundleToProcess(_) - | PartOfTooLargeBundleToFinalize(_) => { - CommitStrategy::FromBufferWithLookupTable - } - - GettingLatestBlockhash((_, _, _, strategy)) - | Failed((_, strategy)) - | BufferAndChunkPartiallyInitialized((_, strategy)) - | BufferAndChunkFullyInitialized((_, strategy)) - | FailedProcess((_, strategy, _)) - | FailedFinalize((_, strategy, _)) - | FailedUndelegate((_, strategy, _)) - | Succeeded((_, strategy, _)) => *strategy, - } - } - - pub fn commit_status(&self) -> CommitStatus { - use CommitStage::*; - match self { - SplittingChangesets((meta, _, _)) - | GettingLatestBlockhash((meta, _, _, _)) => { - CommitStatus::Failed(meta.bundle_id) - } - Failed((ci, _)) => CommitStatus::Failed(ci.bundle_id()), - BufferAndChunkPartiallyInitialized((ci, _)) => { - CommitStatus::BufferAndChunkPartiallyInitialized(ci.bundle_id()) - } - BufferAndChunkFullyInitialized((ci, _)) => { - CommitStatus::BufferAndChunkFullyInitialized(ci.bundle_id()) - } - PartOfTooLargeBundleToProcess(ci) - // NOTE: the below cannot occur if the above didn't, so we can merge them - // here - | PartOfTooLargeBundleToFinalize(ci) => { - CommitStatus::PartOfTooLargeBundleToProcess(ci.bundle_id()) - } - FailedProcess((ci, sigs)) => CommitStatus::FailedProcess(( - ci.bundle_id(), - sigs.as_ref().cloned().map(CommitStatusSignatures::from), - )), - FailedFinalize((ci, strategy, sigs)) => CommitStatus::FailedFinalize(( - ci.bundle_id(), - CommitStatusSignatures::from(sigs.clone()), - )), - FailedUndelegate((ci, strategy, sigs)) => CommitStatus::FailedUndelegate(( - ci.bundle_id(), - *strategy, - CommitStatusSignatures::from(sigs.clone()), - )), - Succeeded((ci, strategy, sigs)) => CommitStatus::Succeeded(( - ci.bundle_id(), - *strategy, - CommitStatusSignatures::from(sigs.clone()), - )), - } - } - - pub fn commit_infos(commit_stages: &[Self]) -> Vec> { - commit_stages.iter().map(Self::commit_metadata).collect() - } - - /// Pubkey of the committed account - pub fn pubkey(&self) -> Pubkey { - self.commit_metadata().pubkey() - } - - /// Pubkey of the account holding the state we commit until the commit is finalized - pub fn commit_state(&self) -> Option { - self.commit_metadata().commit_state() - } - - /// Returns `true` if we need to init the chunks and buffer accounts when we - /// retry committing this account - pub fn needs_accounts_init(&self) -> bool { - use CommitStage::*; - matches!(self, Failed(_) | BufferAndChunkPartiallyInitialized(_)) - } - - /// Returns `true` if we need to complete writing data to the buffer account - /// when we retry committing this account - pub fn needs_accounts_write(&self) -> bool { - use CommitStage::*; - self.needs_accounts_init() - || matches!(self, BufferAndChunkFullyInitialized(_)) - } - - /// Returns `true` if we need to process the buffer account in order to apply - /// the commit when we retry committing this account - pub fn needs_process(&self) -> bool { - use CommitStage::*; - self.needs_accounts_write() - || matches!( - self, - PartOfTooLargeBundleToProcess(_) | FailedProcess(_) - ) - } - - /// Returns `true` if we need to rerun the finalize transaction when we retry - /// committing this account - pub fn needs_finalize(&self) -> bool { - use CommitStage::*; - self.needs_process() - || matches!( - self, - PartOfTooLargeBundleToFinalize(_) | FailedFinalize(_) - ) - } - - /// Returns `true` if the commit was successfully processed and the account - /// was undelegated as part of the commit - pub fn is_successfully_undelegated(&self) -> bool { - use CommitStage::*; - match self { - Succeeded((ci, _, _)) => ci.undelegate(), - _ => false, - } - } -} diff --git a/magicblock-committor-service/src/commit/committor_processor.rs b/magicblock-committor-service/src/committor_processor.rs similarity index 86% rename from magicblock-committor-service/src/commit/committor_processor.rs rename to magicblock-committor-service/src/committor_processor.rs index 6b772702b..c0c11e227 100644 --- a/magicblock-committor-service/src/commit/committor_processor.rs +++ b/magicblock-committor-service/src/committor_processor.rs @@ -1,37 +1,24 @@ -use std::{ - collections::{HashMap, HashSet}, - path::Path, - sync::{Arc, Mutex}, -}; +use std::{collections::HashSet, path::Path, sync::Arc}; use log::*; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; -use magicblock_rpc_client::{ - MagicBlockSendTransactionConfig, MagicblockRpcClient, -}; +use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; use solana_pubkey::Pubkey; use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ - commitment_config::CommitmentConfig, - hash::Hash, - signature::{Keypair, Signature}, - signer::Signer, + commitment_config::CommitmentConfig, signature::Keypair, signer::Signer, }; -use tokio::task::JoinSet; -use super::common::{lookup_table_keys, send_and_confirm}; use crate::{ commit_scheduler::{db::DummyDB, CommitScheduler}, - compute_budget::{ComputeBudget, ComputeBudgetConfig}, + compute_budget::ComputeBudgetConfig, config::ChainConfig, error::CommittorServiceResult, persist::{ CommitStatusRow, L1MessagePersister, L1MessagesPersisterIface, MessageSignatures, }, - types::{InstructionsForCommitable, InstructionsKind}, - CommitInfo, }; pub(crate) struct CommittorProcessor { @@ -76,7 +63,7 @@ impl CommittorProcessor { let commits_scheduler = CommitScheduler::new( magic_block_rpc_client.clone(), DummyDB::new(), - persister.clone(), + Some(persister.clone()), table_mania.clone(), chain_config.compute_budget_config.clone(), ); @@ -126,11 +113,14 @@ impl CommittorProcessor { Ok(commit_statuses) } - pub fn get_signature( + pub fn get_commit_signature( &self, commit_id: u64, + pubkey: Pubkey, ) -> CommittorServiceResult> { - let signatures = self.persister.get_signatures_by_commit(commit_id)?; + let signatures = self + .persister + .get_signatures_by_commit(commit_id, &pubkey)?; Ok(signatures) } diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index 0e5c3c1c8..246e939cb 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -18,14 +18,12 @@ use solana_sdk::{ transaction::VersionedTransaction, }; -use crate::persist::CommitStatusSignatures; -use crate::utils::persist_status_update; use crate::{ - persist::{CommitStatus, L1MessagesPersisterIface}, + persist::{CommitStatus, CommitStatusSignatures, L1MessagesPersisterIface}, transaction_preperator::transaction_preparator::{ TransactionPreparator, TransactionPreparatorV1, }, - utils::persist_status_update_set, + utils::{persist_status_update, persist_status_update_set}, ComputeBudgetConfig, }; @@ -72,7 +70,9 @@ where commit_ids: HashMap, persister: Option

, ) -> MessageExecutorResult { - let result = self.execute_inner(l1_message, &commit_ids, &persister).await; + let result = self + .execute_inner(l1_message, &commit_ids, &persister) + .await; Self::persist_result(&persister, &result, &commit_ids); result diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 5916b4a4f..4d6701d58 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -1,8 +1,6 @@ mod bundle_strategy; mod bundles; -mod commit; mod commit_info; -mod commit_stage; mod commit_strategist; mod compute_budget; pub mod config; @@ -18,6 +16,7 @@ mod undelegate; pub mod commit_scheduler; // TODO(edwin): define visibility +mod committor_processor; pub(crate) mod l1_message_executor; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; @@ -26,7 +25,6 @@ pub(crate) mod transaction_preperator; pub(crate) mod utils; pub use commit_info::CommitInfo; -pub use commit_stage::CommitStage; pub use compute_budget::ComputeBudgetConfig; pub use magicblock_committor_program::{ ChangedAccount, Changeset, ChangesetMeta, diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 097c36692..e62d50c1a 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -127,6 +127,7 @@ impl L1MessagePersister { data, commit_type, created_at, + commit_strategy: CommitStrategy::default(), commit_status: CommitStatus::Pending, last_retried_at: created_at, retries_count: 0, diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 847476e4c..3c25f0098 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -124,9 +124,27 @@ const ALL_COMMIT_STATUS_COLUMNS: &str = " retries_count // 17 "; -const SELECT_ALL_COMMIT_STATUS_COLUMNS: &str = const { - concat!("SELECT", ALL_COMMIT_STATUS_COLUMNS, "FROM commit_status") -}; +const SELECT_ALL_COMMIT_STATUS_COLUMNS: &str = r#" +SELECT + message_id, // 1 + pubkey, // 2 + commit_id, // 3 + delegated_account_owner, // 4 + slot, // 5 + ephemeral_blockhash, // 6 + undelegate, // 7 + lamports, // 8 + data, // 9 + commit_type, // 10 + created_at, // 11 + commit_strategy, // 12 + commit_status, // 13 + processed_signature, // 14 + finalized_signature, // 15 + last_retried_at, // 16 + retries_count // 17 +FROM commit_status +"#; // ----------------- // CommittorDb @@ -309,10 +327,9 @@ impl CommittsDb { ) -> CommitPersistResult<()> { let (processed_signature, finalized_signature) = match commit.commit_status.signatures() { - Some(sigs) => ( - Some(sigs.process_signature), - sigs.finalize_signature, - ), + Some(sigs) => { + (Some(sigs.process_signature), sigs.finalize_signature) + } None => (None, None), }; tx.execute( @@ -408,7 +425,7 @@ impl CommittsDb { LIMIT 1"; let mut stmt = self.conn.prepare(&query)?; - let mut rows = stmt.query(params![commit_id, pubkey])?; + let mut rows = stmt.query(params![commit_id, pubkey.to_string()])?; let result = rows .next()? @@ -500,7 +517,7 @@ fn extract_committor_row( let commit_strategy = { let commit_strategy: String = row.get(11)?; - CommitStrategy::from(commit_strategy.as_str()) + CommitStrategy::try_from(commit_strategy.as_str())? }; let commit_status = { @@ -521,11 +538,7 @@ fn extract_committor_row( process_signature: s, finalize_signature: finalized_signature, }); - CommitStatus::try_from(( - commit_status.as_str(), - commit_id, - sigs, - ))? + CommitStatus::try_from((commit_status.as_str(), commit_id, sigs))? }; let last_retried_at: u64 = { diff --git a/magicblock-committor-service/src/persist/error.rs b/magicblock-committor-service/src/persist/error.rs index 1d5e75908..1763acca4 100644 --- a/magicblock-committor-service/src/persist/error.rs +++ b/magicblock-committor-service/src/persist/error.rs @@ -22,6 +22,9 @@ pub enum CommitPersistError { #[error("Invalid Commit Status: '{0}' ({0:?})")] InvalidCommitStatus(String), + #[error("Invalid Commit Strategy: '{0}' ({0:?})")] + InvalidCommitStrategy(String), + #[error( "Commit Status update requires status with bundle id: '{0}' ({0:?})" )] diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index e2b534793..842f0b75a 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -2,7 +2,6 @@ use std::fmt; use solana_sdk::signature::Signature; -use super::commit_strategy::CommitStrategy; use crate::persist::error::CommitPersistError; /// The status of a committed account. @@ -59,44 +58,23 @@ impl fmt::Display for CommitStatus { write!(f, "PartOfTooLargeBundleToProcess({})", bundle_id) } CommitStatus::FailedProcess((bundle_id, sigs)) => { - write!( - f, - "FailedProcess({}, {:?})", - bundle_id, - sigs - ) + write!(f, "FailedProcess({}, {:?})", bundle_id, sigs) } CommitStatus::FailedFinalize((bundle_id, sigs)) => { - write!( - f, - "FailedFinalize({}, {:?})", - bundle_id, - sigs - ) + write!(f, "FailedFinalize({}, {:?})", bundle_id, sigs) } CommitStatus::Succeeded((bundle_id, sigs)) => { - write!( - f, - "Succeeded({}, {:?})", - bundle_id, - sigs - ) + write!(f, "Succeeded({}, {:?})", bundle_id, sigs) } } } } -impl TryFrom<(&str, u64, Option)> - for CommitStatus -{ +impl TryFrom<(&str, u64, Option)> for CommitStatus { type Error = CommitPersistError; fn try_from( - (status, commit_id, sigs): ( - &str, - u64, - Option, - ), + (status, commit_id, sigs): (&str, u64, Option), ) -> Result { let get_sigs = || { if let Some(sigs) = sigs.clone() { @@ -125,9 +103,7 @@ impl TryFrom<(&str, u64, Option)> Ok(PartOfTooLargeBundleToProcess(commit_id)) } "FailedProcess" => Ok(FailedProcess((commit_id, sigs))), - "FailedFinalize" => { - Ok(FailedFinalize((commit_id, get_sigs()?))) - } + "FailedFinalize" => Ok(FailedFinalize((commit_id, get_sigs()?))), "Succeeded" => Ok(Succeeded((commit_id, get_sigs()?))), _ => { Err(CommitPersistError::InvalidCommitStatus(status.to_string())) diff --git a/magicblock-committor-service/src/persist/types/commit_strategy.rs b/magicblock-committor-service/src/persist/types/commit_strategy.rs index 8dc011d46..c9261f70d 100644 --- a/magicblock-committor-service/src/persist/types/commit_strategy.rs +++ b/magicblock-committor-service/src/persist/types/commit_strategy.rs @@ -1,8 +1,9 @@ -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +use crate::persist::error::CommitPersistError; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)] pub enum CommitStrategy { - /// The commit strategy is not known yet - Undetermined, /// Args without the use of a lookup table + #[default] Args, /// Args with the use of a lookup table ArgsWithLookupTable, @@ -24,7 +25,6 @@ impl CommitStrategy { pub fn as_str(&self) -> &str { use CommitStrategy::*; match self { - Undetermined => "Undetermined", Args => "Args", ArgsWithLookupTable => "ArgsWithLookupTable", FromBuffer => "FromBuffer", @@ -41,14 +41,17 @@ impl CommitStrategy { } } -impl From<&str> for CommitStrategy { - fn from(value: &str) -> Self { +impl TryFrom<&str> for CommitStrategy { + type Error = CommitPersistError; + fn try_from(value: &str) -> Result { match value { - "Args" => Self::Args, - "ArgsWithLookupTable" => Self::ArgsWithLookupTable, - "FromBuffer" => Self::FromBuffer, - "FromBufferWithLookupTable" => Self::FromBufferWithLookupTable, - _ => Self::Undetermined, + "Args" => Ok(Self::Args), + "ArgsWithLookupTable" => Ok(Self::ArgsWithLookupTable), + "FromBuffer" => Ok(Self::FromBuffer), + "FromBufferWithLookupTable" => Ok(Self::FromBufferWithLookupTable), + _ => Err(CommitPersistError::InvalidCommitStrategy( + value.to_string(), + )), } } } diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 78eab37ee..8361b2aa9 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -16,7 +16,7 @@ use tokio::{ use tokio_util::sync::CancellationToken; use crate::{ - commit::CommittorProcessor, + committor_processor::CommittorProcessor, config::ChainConfig, error::CommittorServiceResult, persist::{CommitStatusRow, MessageSignatures}, @@ -61,6 +61,7 @@ pub enum CommittorMessage { respond_to: oneshot::Sender>>, commit_id: u64, + pubkey: Pubkey, }, GetLookupTables { respond_to: oneshot::Sender, @@ -140,8 +141,10 @@ impl CommittorActor { GetCommitSignatures { commit_id, respond_to, + pubkey, } => { - let sig = self.processor.get_signature(commit_id); + let sig = + self.processor.get_commit_signature(commit_id, pubkey); if let Err(e) = respond_to.send(sig) { error!("Failed to send response {:?}", e); } @@ -237,12 +240,14 @@ impl CommittorService { pub fn get_commit_signatures( &self, commit_id: u64, + pubkey: Pubkey, ) -> oneshot::Receiver>> { let (tx, rx) = oneshot::channel(); self.try_send(CommittorMessage::GetCommitSignatures { respond_to: tx, commit_id, + pubkey, }); rx } @@ -315,12 +320,14 @@ impl L1MessageCommittor for CommittorService { fn get_commit_signatures( &self, commit_id: u64, + pubkey: Pubkey, ) -> oneshot::Receiver>> { let (tx, rx) = oneshot::channel(); self.try_send(CommittorMessage::GetCommitSignatures { respond_to: tx, commit_id, + pubkey, }); rx } @@ -352,6 +359,7 @@ pub trait L1MessageCommittor: Send + Sync + 'static { /// Gets signatures for commit of particular accounts fn get_commit_signatures( &self, - bundle_id: u64, + commit_id: u64, + pubkey: Pubkey, ) -> oneshot::Receiver>>; } diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 1b7c65df9..d60c7d451 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -15,7 +15,7 @@ pub trait TasksBuilder { fn commit_tasks( l1_message: &ScheduledL1Message, commit_ids: &HashMap, - ) -> Vec>; + ) -> TaskBuilderResult>>; // Create tasks for finalize stage fn finalize_tasks( diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index c261bd29d..eee1c0809 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -3,12 +3,12 @@ use std::{collections::BinaryHeap, ptr::NonNull}; use solana_pubkey::Pubkey; use solana_sdk::signature::Keypair; -use crate::persist::L1MessagesPersisterIface; -use crate::tasks::task_visitors::persistor_visitor::{ - PersistorContext, PersistorVisitor, -}; use crate::{ + persist::L1MessagesPersisterIface, tasks::{ + task_visitors::persistor_visitor::{ + PersistorContext, PersistorVisitor, + }, tasks::{ArgsTask, L1Task}, utils::TransactionUtils, }, diff --git a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs index e306d1c70..d55ebdf70 100644 --- a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs +++ b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs @@ -1,8 +1,13 @@ -use crate::persist::{CommitStrategy, L1MessagesPersisterIface}; -use crate::tasks::tasks::{ArgsTask, BufferTask}; -use crate::tasks::visitor::Visitor; use log::error; +use crate::{ + persist::{CommitStrategy, L1MessagesPersisterIface}, + tasks::{ + tasks::{ArgsTask, BufferTask}, + visitor::Visitor, + }, +}; + pub enum PersistorContext { PersistStrategy { uses_lookup_tables: bool }, // Other possible persist @@ -37,7 +42,8 @@ where ) { error!( "Failed to persist commit strategy {}: {}", - commit_strategy.as_str(), err + commit_strategy.as_str(), + err ); } } @@ -61,7 +67,8 @@ where ) { error!( "Failed to persist commit strategy {}: {}", - commit_strategy.as_str(), err + commit_strategy.as_str(), + err ); } } diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index 5e2ddc7e9..80bf3dadb 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -16,9 +16,9 @@ use magicblock_program::magic_scheduled_l1_message::{ use solana_pubkey::Pubkey; use solana_sdk::instruction::{AccountMeta, Instruction}; -use crate::tasks::visitor::Visitor; use crate::{ - consts::MAX_WRITE_CHUNK_SIZE, tasks::budget_calculator::ComputeBudgetV1, + consts::MAX_WRITE_CHUNK_SIZE, + tasks::{budget_calculator::ComputeBudgetV1, visitor::Visitor}, }; pub enum TaskStrategy { diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preperator/error.rs index db4fd2021..9a4ca5453 100644 --- a/magicblock-committor-service/src/transaction_preperator/error.rs +++ b/magicblock-committor-service/src/transaction_preperator/error.rs @@ -1,8 +1,6 @@ -use solana_pubkey::{pubkey, Pubkey}; +use solana_pubkey::Pubkey; use thiserror::Error; -use crate::transaction_preperator::transaction_preparator::PreparatorVersion; - #[derive(Error, Debug)] pub enum Error { // #[error("Invalid action for TransactionPreparator version: {0}")] From a4f9532e8afd9df832fb71a6c58e42f0bd9a0d80 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 22 Jul 2025 19:10:51 +0900 Subject: [PATCH 109/199] feat: expose subscribe method on CommittorService --- .../src/commit_scheduler.rs | 18 ++++++--- .../commit_scheduler_worker.rs | 32 ++++++++------- .../src/committor_processor.rs | 11 +++++- .../src/l1_message_executor.rs | 5 ++- magicblock-committor-service/src/lib.rs | 4 +- magicblock-committor-service/src/service.rs | 39 ++++++++++++------- 6 files changed, 72 insertions(+), 37 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index 90adc1651..38d21274e 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -13,18 +13,17 @@ use tokio::sync::{broadcast, mpsc, mpsc::error::TrySendError}; use crate::{ commit_scheduler::{ - commit_scheduler_worker::{ - BroadcasteddMessageExecutionResult, CommitSchedulerWorker, - }, + commit_scheduler_worker::{CommitSchedulerWorker, ResultSubscriber}, db::DB, }, + l1_message_executor::BroadcastedMessageExecutionResult, persist::L1MessagesPersisterIface, ComputeBudgetConfig, }; pub struct CommitScheduler { db: Arc, - result_receiver: broadcast::Receiver, + result_subscriber: ResultSubscriber, message_sender: mpsc::Sender, } @@ -48,12 +47,12 @@ impl CommitScheduler { compute_budget_config, receiver, ); - let result_receiver = worker.spawn(); + let result_subscriber = worker.spawn(); Self { db, message_sender: sender, - result_receiver, + result_subscriber, } } @@ -90,6 +89,13 @@ impl CommitScheduler { Ok(()) } + + /// Creates a subscription for results of L1Message execution + pub fn subscribe_for_results( + &self, + ) -> broadcast::Receiver { + self.result_subscriber.subscribe() + } } #[derive(thiserror::Error, Debug)] diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 8c9700906..f0e9bd8b1 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -21,7 +21,8 @@ use crate::{ Error, }, l1_message_executor::{ - ExecutionOutput, L1MessageExecutor, MessageExecutorResult, + BroadcastedMessageExecutionResult, ExecutionOutput, L1MessageExecutor, + MessageExecutorResult, }, persist::L1MessagesPersisterIface, transaction_preperator::transaction_preparator::{ @@ -33,10 +34,17 @@ use crate::{ const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; -pub type BroadcasteddMessageExecutionResult = MessageExecutorResult< - ExecutionOutput, - Arc, ->; +/// Struct that exposes only `subscribe` method of `broadcast::Sender` for better isolation +pub struct ResultSubscriber( + broadcast::Sender, +); +impl ResultSubscriber { + pub fn subscribe( + &self, + ) -> broadcast::Receiver { + self.0.subscribe() + } +} // TODO(edwin): reduce num of params: 1,2,3, could be united pub(crate) struct CommitSchedulerWorker { @@ -89,13 +97,11 @@ where } /// Spawns `main_loop` and return `Receiver` listening to results - pub fn spawn( - self, - ) -> broadcast::Receiver { - let (result_sender, result_receiver) = broadcast::channel(100); - tokio::spawn(self.main_loop(result_sender)); + pub fn spawn(self) -> ResultSubscriber { + let (result_sender, _) = broadcast::channel(100); + tokio::spawn(self.main_loop(result_sender.clone())); - result_receiver + ResultSubscriber(result_sender) } /// Main loop that: @@ -104,7 +110,7 @@ where /// 3. Spawns execution of scheduled message async fn main_loop( mut self, - result_sender: broadcast::Sender, + result_sender: broadcast::Sender, ) { loop { // TODO: unwraps @@ -231,7 +237,7 @@ where commit_ids: HashMap, inner_scheduler: Arc>, execution_permit: OwnedSemaphorePermit, - result_sender: broadcast::Sender, + result_sender: broadcast::Sender, notify: Arc, ) { let result = executor diff --git a/magicblock-committor-service/src/committor_processor.rs b/magicblock-committor-service/src/committor_processor.rs index c0c11e227..e6c436f4a 100644 --- a/magicblock-committor-service/src/committor_processor.rs +++ b/magicblock-committor-service/src/committor_processor.rs @@ -9,12 +9,14 @@ use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ commitment_config::CommitmentConfig, signature::Keypair, signer::Signer, }; +use tokio::sync::broadcast; use crate::{ commit_scheduler::{db::DummyDB, CommitScheduler}, compute_budget::ComputeBudgetConfig, config::ChainConfig, error::CommittorServiceResult, + l1_message_executor::BroadcastedMessageExecutionResult, persist::{ CommitStatusRow, L1MessagePersister, L1MessagesPersisterIface, MessageSignatures, @@ -140,7 +142,14 @@ impl CommittorProcessor { if let Err(err) = self.commits_scheduler.schedule(l1_messages).await { error!("Failed to schedule L1 message: {}", err); - // TODO(edwin): handle + // TODO(edwin): handsle } } + + /// Creates a subscription for results of L1Message execution + pub fn subscribe_for_results( + &self, + ) -> broadcast::Receiver { + self.commits_scheduler.subscribe_for_results() + } } diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index 246e939cb..97ceecae5 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap, sync::Arc}; use log::warn; use magicblock_program::{ @@ -27,6 +27,9 @@ use crate::{ ComputeBudgetConfig, }; +pub type BroadcastedMessageExecutionResult = + MessageExecutorResult>; + // TODO(edwin): define struct // (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] #[derive(Clone, Debug)] diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 4d6701d58..61ef25fdb 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -17,11 +17,11 @@ mod undelegate; pub mod commit_scheduler; // TODO(edwin): define visibility mod committor_processor; -pub(crate) mod l1_message_executor; +pub mod l1_message_executor; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; pub mod tasks; -pub(crate) mod transaction_preperator; +pub mod transaction_preperator; pub(crate) mod utils; pub use commit_info::CommitInfo; diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 8361b2aa9..e84a610a7 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -8,7 +8,6 @@ use tokio::{ select, sync::{ broadcast, - broadcast::Receiver, mpsc::{self, error::TrySendError}, oneshot, }, @@ -19,6 +18,7 @@ use crate::{ committor_processor::CommittorProcessor, config::ChainConfig, error::CommittorServiceResult, + l1_message_executor::BroadcastedMessageExecutionResult, persist::{CommitStatusRow, MessageSignatures}, pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, }; @@ -66,6 +66,11 @@ pub enum CommittorMessage { GetLookupTables { respond_to: oneshot::Sender, }, + SubscribeForResults { + respond_to: oneshot::Sender< + broadcast::Receiver, + >, + }, } // ----------------- @@ -160,6 +165,12 @@ impl CommittorActor { error!("Failed to send response {:?}", e); } } + SubscribeForResults { respond_to } => { + let subscription = self.processor.subscribe_for_results(); + if let Err(err) = respond_to.send(subscription) { + error!("Failed to send response {:?}", err); + } + } } } @@ -293,16 +304,8 @@ impl L1MessageCommittor for CommittorService { rx } - fn commit_l1_messages( - &self, - l1_messages: Vec, - ) -> oneshot::Receiver> { - let (tx, rx) = oneshot::channel(); - self.try_send(CommittorMessage::CommitChangeset { - respond_to: tx, - l1_messages, - }); - rx + fn commit_l1_messages(&self, l1_messages: Vec) { + self.try_send(CommittorMessage::CommitChangeset { l1_messages }); } fn get_commit_statuses( @@ -332,8 +335,13 @@ impl L1MessageCommittor for CommittorService { rx } - fn subscribe_for_results(&self) -> Receiver<()> { - todo!() + fn subscribe_for_results( + &self, + ) -> oneshot::Receiver> + { + let (tx, rx) = oneshot::channel(); + self.try_send(CommittorMessage::SubscribeForResults { respond_to: tx }); + rx } } @@ -348,7 +356,10 @@ pub trait L1MessageCommittor: Send + Sync + 'static { /// Commits the changeset and returns fn commit_l1_messages(&self, l1_messages: Vec); - fn subscribe_for_results(&self) -> broadcast::Receiver<()>; + /// Subscribes for results of L1Message execution + fn subscribe_for_results( + &self, + ) -> oneshot::Receiver>; /// Gets statuses of accounts that were committed as part of a request with provided message_id fn get_commit_statuses( From ff8347f5befc1a23575e121e2bf8d241c376461a Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 22 Jul 2025 19:17:23 +0900 Subject: [PATCH 110/199] fix: magicblock-committor-service compiles! --- .../src/commit_scheduler/commit_scheduler_inner.rs | 2 +- .../src/commit_scheduler/commit_scheduler_worker.rs | 4 +--- magicblock-committor-service/src/commit_scheduler/db.rs | 2 +- magicblock-committor-service/src/l1_message_executor.rs | 4 ++-- magicblock-committor-service/src/utils.rs | 1 - 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index 2156d9b68..19dab1fc0 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -147,7 +147,7 @@ impl CommitSchedulerInner { pub fn pop_next_scheduled_message(&mut self) -> Option { // TODO(edwin): optimize. Create counter im MessageMeta & update let mut execute_candidates: HashMap = HashMap::new(); - self.blocked_keys.iter().for_each(|(pubkey, queue)| { + self.blocked_keys.iter().for_each(|(_, queue)| { let message_id = queue .front() .expect("Invariant: we maintain ony non-empty queues"); diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index f0e9bd8b1..f700ea171 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -21,8 +21,7 @@ use crate::{ Error, }, l1_message_executor::{ - BroadcastedMessageExecutionResult, ExecutionOutput, L1MessageExecutor, - MessageExecutorResult, + BroadcastedMessageExecutionResult, L1MessageExecutor, }, persist::L1MessagesPersisterIface, transaction_preperator::transaction_preparator::{ @@ -46,7 +45,6 @@ impl ResultSubscriber { } } -// TODO(edwin): reduce num of params: 1,2,3, could be united pub(crate) struct CommitSchedulerWorker { db: Arc, l1_messages_persister: Option

, diff --git a/magicblock-committor-service/src/commit_scheduler/db.rs b/magicblock-committor-service/src/commit_scheduler/db.rs index 94e5881fe..5cb1af0a2 100644 --- a/magicblock-committor-service/src/commit_scheduler/db.rs +++ b/magicblock-committor-service/src/commit_scheduler/db.rs @@ -7,7 +7,7 @@ use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; const POISONED_MUTEX_MSG: &str = "Mutex poisoned"; #[async_trait] -pub(crate) trait DB: Send + Sync + 'static { +pub trait DB: Send + Sync + 'static { async fn store_l1_message( &self, l1_message: ScheduledL1Message, diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index 97ceecae5..2e9bf46c3 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -233,9 +233,9 @@ where }); } Err(Error::FailedFinalizePreparationError(_)) => { - // TODO(edwin): not supported by persister yet + // Not supported in persistor }, - Err(Error::FailedToFinalizeError {err, commit_signature, finalize_signature}) => { + Err(Error::FailedToFinalizeError {err: _, commit_signature, finalize_signature}) => { // Finalize is a single TX, so if it fails, all of commited accounts marked FailedFinalize commit_ids.iter().for_each(|(pubkey, commit_id)| { // Invalid task diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index 0d1315f59..02e045ebb 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -8,7 +8,6 @@ use solana_pubkey::Pubkey; use crate::{ persist::{CommitStatus, L1MessagesPersisterIface}, - tasks::tasks::TaskPreparationInfo, }; pub trait ScheduledMessageExt { From fcefa806ba1a1a3bab08423f16604b077900d97f Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 23 Jul 2025 16:09:28 +0900 Subject: [PATCH 111/199] feat: filter accs in L1Message --- .../src/remote_scheduled_commits_processor.rs | 204 ++++++++++++++++-- .../src/remote_scheduled_commits_worker.rs | 71 +++--- .../src/l1_message_executor.rs | 116 +++++----- magicblock-committor-service/src/lib.rs | 4 +- magicblock-committor-service/src/types.rs | 10 + magicblock-committor-service/src/utils.rs | 16 +- .../src/magic_scheduled_l1_message.rs | 15 ++ .../process_scheduled_commit_sent.rs | 24 +-- 8 files changed, 346 insertions(+), 114 deletions(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 53eb78730..fc06f184d 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -1,12 +1,23 @@ -use std::sync::Arc; +use std::{collections::HashSet, sync::Arc}; use async_trait::async_trait; +use conjunto_transwise::AccountChainSnapshot; +use log::error; +use magicblock_account_cloner::{AccountClonerOutput, CloneOutputMap}; use magicblock_bank::bank::Bank; -use magicblock_committor_service::L1MessageCommittor; +use magicblock_committor_service::{ + types::ScheduledL1MessageWrapper, utils::ScheduledMessageExt, + L1MessageCommittor, +}; use magicblock_program::{ - magic_scheduled_l1_message::ScheduledL1Message, TransactionScheduler, + magic_scheduled_l1_message::{CommittedAccountV2, ScheduledL1Message}, + FeePayerAccount, TransactionScheduler, }; use magicblock_transaction_status::TransactionStatusSender; +use solana_sdk::{ + account::{Account, ReadableAccount}, + pubkey::Pubkey, +}; use tokio::sync::mpsc::{channel, Sender}; use crate::{ @@ -15,33 +26,204 @@ use crate::{ ScheduledCommitsProcessor, }; +const POISONED_RWLOCK_MSG: &str = + "RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned"; + pub struct RemoteScheduledCommitsProcessor { transaction_scheduler: TransactionScheduler, + cloned_accounts: CloneOutputMap, bank: Arc, - worker_sender: Sender>, + committor: Arc, } impl RemoteScheduledCommitsProcessor { pub fn new( bank: Arc, + cloned_accounts: CloneOutputMap, committor: Arc, transaction_status_sender: TransactionStatusSender, ) -> Self { - let (worker_sender, worker_receiver) = channel(1000); + let result_subscriber = committor.subscribe_for_results(); let worker = RemoteScheduledCommitsWorker::new( bank.clone(), - committor, + result_subscriber, transaction_status_sender, - worker_receiver, ); tokio::spawn(worker.start()); Self { bank, - worker_sender, + cloned_accounts, + committor, transaction_scheduler: TransactionScheduler::default(), } } + + // fn preprocess_messages(&self, mut l1_messages: Vec) -> Vec { + // l1_messages. + // } + + fn preprocess_message( + &self, + mut l1_message: ScheduledL1Message, + ) -> ScheduledL1MessageWrapper { + let Some(committed_accounts) = l1_message.get_committed_accounts_mut() + else { + return ScheduledL1MessageWrapper { + scheduled_l1_message: l1_message, + excluded_pubkeys: Vec::new(), + feepayers: Vec::new(), + }; + }; + + let mut excluded_pubkeys = HashSet::new(); + let mut feepayers = HashSet::new(); + + let process_feepayer = |account: &mut CommittedAccountV2| -> bool { + let pubkey = account.pubkey; + let ephemeral_pubkey = + AccountChainSnapshot::ephemeral_balance_pda(&pubkey); + + feepayers.insert(FeePayerAccount { + pubkey: *pubkey, + delegated_pda: ephemeral_pubkey, + }); + + match self.bank.get_account(&ephemeral_pubkey) { + Some(account_data) => { + let ephemeral_owner = + AccountChainSnapshot::ephemeral_balance_pda_owner(); + account.pubkey = ephemeral_pubkey; + account.account = Account { + lamports: account_data.lamports(), + data: account_data.data().to_vec(), + owner: ephemeral_owner, + executable: account_data.executable(), + rent_epoch: account_data.rent_epoch(), + }; + true + } + None => { + error!( + "Scheduled commit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", + pubkey + ); + excluded_pubkeys.insert(*pubkey); + false + } + } + }; + + committed_accounts.retain_mut(|account| { + let pubkey = account.pubkey; + let cloned_accounts = + self.cloned_accounts.read().expect(POISONED_RWLOCK_MSG); + + match cloned_accounts.get(&pubkey) { + Some(AccountClonerOutput::Cloned { + account_chain_snapshot, + .. + }) => { + if account_chain_snapshot.chain_state.is_feepayer() { + process_feepayer(account) + } else if account_chain_snapshot + .chain_state + .is_undelegated() + { + excluded_pubkeys.insert(pubkey); + false + } else { + true + } + } + Some(AccountClonerOutput::Unclonable {..}) => { + todo!() + } + None => true, + } + }); + + ScheduledL1MessageWrapper { + scheduled_l1_message: l1_message, + feepayers: feepayers.into_iter().collect(), + excluded_pubkeys: excluded_pubkeys.into_iter().collect(), + } + } + + fn preprocess_message2( + &self, + mut l1_message: ScheduledL1Message, + ) -> ScheduledL1MessageWrapper { + let Some(committed_accounts) = l1_message.get_committed_accounts_mut() + else { + return ScheduledL1MessageWrapper { + scheduled_l1_message: l1_message, + excluded_pubkeys: vec![], + feepayers: vec![], + }; + }; + + let mut excluded_pubkeys = HashSet::new(); + let mut feepayers = HashSet::new(); + committed_accounts.retain_mut(|account| { + let pubkey = account.pubkey; + if let Some(AccountClonerOutput::Cloned { + account_chain_snapshot, + .. + }) = self + .cloned_accounts + .read() + .expect(POISONED_RWLOCK_MSG) + .get(&pubkey) + { + if account_chain_snapshot.chain_state.is_feepayer() { + let ephemeral_pubkey = + AccountChainSnapshot::ephemeral_balance_pda(&pubkey); + let ephemeral_owner = + AccountChainSnapshot::ephemeral_balance_pda_owner(); + feepayers.insert(FeePayerAccount { + pubkey: *pubkey, + delegated_pda: ephemeral_pubkey, + }); + + if let Some(account_data) = self.bank.get_account(&ephemeral_pubkey) { + account.pubkey = ephemeral_pubkey; + account.account = Account { + lamports: account_data.lamports(), + data: account_data.data().to_vec(), + owner: ephemeral_owner, + executable: account_data.executable(), + rent_epoch: account_data.rent_epoch() + }; + true + } else { + error!( + "Scheduled commmit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", + pubkey + ); + + // Exclude this + // TODO(edwin): should fail commit really + excluded_pubkeys.insert(pubkey); + false + } + } else if account_chain_snapshot.chain_state.is_undelegated() { + excluded_pubkeys.insert(pubkey); + false + } else { + true + } + } else { + true + } + }); + + ScheduledL1MessageWrapper { + scheduled_l1_message: l1_message, + feepayers: feepayers.into_iter().collect(), + excluded_pubkeys: excluded_pubkeys.into_iter().collect(), + } + } } #[async_trait] @@ -56,10 +238,8 @@ impl ScheduledCommitsProcessor return Ok(()); } - self.worker_sender - .send(scheduled_l1_messages) - .await - .expect("We shall be able to processs commmits"); + let l1_messages = self.preprocess(scheduled_l1_messages); + self.committor.commit_l1_messages(scheduled_l1_messages); Ok(()) } diff --git a/magicblock-accounts/src/remote_scheduled_commits_worker.rs b/magicblock-accounts/src/remote_scheduled_commits_worker.rs index c62679868..413c094a8 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_worker.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_worker.rs @@ -6,7 +6,9 @@ use std::{ use log::{debug, error}; use magicblock_bank::bank::Bank; use magicblock_committor_service::{ - persist::MessageSignatures, ChangesetMeta, L1MessageCommittor, + l1_message_executor::{BroadcastedMessageExecutionResult, ExecutionOutput}, + persist::MessageSignatures, + ChangesetMeta, L1MessageCommittor, }; use magicblock_processor::execute_transaction::execute_legacy_transaction; use magicblock_program::{ @@ -15,63 +17,63 @@ use magicblock_program::{ }; use magicblock_transaction_status::TransactionStatusSender; use solana_sdk::transaction::Transaction; -use tokio::sync::mpsc::Receiver; +use tokio::sync::{broadcast, mpsc::Receiver, oneshot}; pub(crate) struct RemoteScheduledCommitsWorker { bank: Arc, - committor: Arc, + result_subscriber: oneshot::Receiver< + broadcast::Receiver, + >, transaction_status_sender: TransactionStatusSender, - message_receiver: Receiver>, } impl RemoteScheduledCommitsWorker { pub fn new( bank: Arc, - committor: Arc, + result_subscriber: oneshot::Receiver< + broadcast::Receiver, + >, transaction_status_sender: TransactionStatusSender, - message_receiver: Receiver>, ) -> Self { Self { bank, - committor, + result_subscriber, transaction_status_sender, - message_receiver, } } // TODO(edwin): maybe not needed pub async fn start(mut self) { - while let Some(l1_messages) = self.message_receiver.recv().await { - let metadata = ChangesetMeta::from(&l1_messages); - // TODO(edwin) mayne actuall self.committor.commit_l1_messages(l1_messages). - // should be on a client, and here we just send receivers to wait on and process - match self.committor.commit_l1_messages(l1_messages).await { - Ok(Some(reqid)) => { - debug!( - "Committed changeset with {} accounts via reqid {}", - metadata.accounts.len(), - reqid - ); - } - Ok(None) => { - debug!( - "Committed changeset with {} accounts, but did not get a reqid", - metadata.accounts.len() - ); - } - Err(err) => { - error!( - "Tried to commit changeset with {} accounts but failed to send request ({:#?})", - metadata.accounts.len(),err - ); - } - } + const SUBSCRIPTION_ERR_MSG: &str = + "Failed to get subscription of results of L1Messages execution"; + let mut result_receiver = + self.result_subscriber.await.expect(SUBSCRIPTION_ERR_MSG); + while let Ok(l1_messages) = result_receiver.recv().await { + let metadata = ChangesetMeta::from(&l1_messages); self.process_message_result(metadata, todo!()).await; } } - async fn process_message_result( + async fn process_message_result(&self, execution_outcome: ExecutionOutput) { + sent_commit.chain_signatures = chain_signatures; + register_scheduled_commit_sent(sent_commit); + match execute_legacy_transaction( + commit_sent_transaction, + &self.bank, + Some(&self.transaction_status_sender), + ) { + Ok(signature) => debug!( + "Signaled sent commit with internal signature: {:?}", + signature + ), + Err(err) => { + error!("Failed to signal sent commit via transaction: {}", err); + } + } + } + + async fn process_message_result_old( &self, metadata: ChangesetMeta, mut sent_commits: HashMap, @@ -101,7 +103,6 @@ impl RemoteScheduledCommitsWorker { Some(MessageSignatures { processed_signature, finalized_signature, - bundle_id, .. }) => { let mut chain_signatures = vec![processed_signature]; diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index 2e9bf46c3..9ef0ef2b6 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, sync::Arc}; use log::warn; use magicblock_program::{ magic_scheduled_l1_message::ScheduledL1Message, - validator::validator_authority, + validator::validator_authority, SentCommit, }; use magicblock_rpc_client::{ MagicBlockRpcClientError, MagicBlockSendTransactionConfig, @@ -15,7 +15,7 @@ use solana_sdk::{ message::VersionedMessage, signature::{Keypair, Signature}, signer::{Signer, SignerError}, - transaction::VersionedTransaction, + transaction::{Transaction, VersionedTransaction}, }; use crate::{ @@ -36,6 +36,8 @@ pub type BroadcastedMessageExecutionResult = pub struct ExecutionOutput { commit_signature: Signature, finalize_signature: Signature, + sent_commit: SentCommit, + action_sent_transaction: Transaction, } pub(crate) struct L1MessageExecutor { @@ -88,67 +90,81 @@ where persister: &Option

, ) -> MessageExecutorResult { // Update tasks status to Pending - { - let update_status = CommitStatus::Pending; - persist_status_update_set(&persister, &commit_ids, update_status); - } + let update_status = CommitStatus::Pending; + persist_status_update_set(&persister, &commit_ids, update_status); // Commit stage - let commit_signature = { - // Prepare everything for commit - let prepared_message = self - .transaction_preparator - .prepare_commit_tx( - &self.authority, - &l1_message, - commit_ids, - &persister, - ) - .await - .map_err(Error::FailedCommitPreparationError)?; - - // Commit - self.send_prepared_message(prepared_message).await.map_err( - |(err, signature)| Error::FailedToCommitError { - err, - signature, - }, - )? - }; - + let commit_signature = self + .execute_commit_stage(&l1_message, commit_ids, persister) + .await?; // Finalize stage // At the moment validator finalizes right away // In the future there will be a challenge window - let finalize_signature = { - // Prepare eveything for finalize - let rent_reimbursement = self.authority.pubkey(); - let prepared_message = self - .transaction_preparator - .prepare_finalize_tx( - &self.authority, - &rent_reimbursement, - &l1_message, - &persister, - ) - .await - .map_err(Error::FailedFinalizePreparationError)?; + let finalize_signature = self + .execute_finalize_stage(&l1_message, commit_signature, persister) + .await?; - // Finalize - self.send_prepared_message(prepared_message).await.map_err( - |(err, finalize_signature)| Error::FailedToFinalizeError { - err, - commit_signature, - finalize_signature, - }, - )? + let sent_commit = SentCommit { + message_id: l1_message.id, + slot: l1_message.slot, + blockhash: l1_message.blockhash, }; - Ok(ExecutionOutput { commit_signature, finalize_signature, + action_sent_transaction: l1_message.action_sent_transaction, }) } + async fn execute_commit_stage( + &self, + l1_message: &ScheduledL1Message, + commit_ids: &HashMap, + persister: &Option

, + ) -> MessageExecutorResult { + let prepared_message = self + .transaction_preparator + .prepare_commit_tx( + &self.authority, + l1_message, + commit_ids, + persister, + ) + .await + .map_err(Error::FailedCommitPreparationError)?; + + self.send_prepared_message(prepared_message).await.map_err( + |(err, signature)| Error::FailedToCommitError { err, signature }, + ) + } + + async fn execute_finalize_stage( + &self, + l1_message: &ScheduledL1Message, + commit_signature: Signature, + persister: &Option

, + ) -> MessageExecutorResult { + let rent_reimbursement = self.authority.pubkey(); + let prepared_message = self + .transaction_preparator + .prepare_finalize_tx( + &self.authority, + &rent_reimbursement, + l1_message, + persister, + ) + .await + .map_err(Error::FailedFinalizePreparationError)?; + + self.send_prepared_message(prepared_message).await.map_err( + |(err, finalize_signature)| Error::FailedToFinalizeError { + err, + commit_signature, + finalize_signature, + }, + ) + } + /// Shared helper for sending transactions async fn send_prepared_message( &self, diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 61ef25fdb..4372ebe9e 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -11,7 +11,7 @@ pub mod persist; mod pubkeys_provider; mod service; mod transactions; -mod types; +pub mod types; mod undelegate; pub mod commit_scheduler; @@ -22,7 +22,7 @@ pub mod l1_message_executor; pub mod stubs; pub mod tasks; pub mod transaction_preperator; -pub(crate) mod utils; +pub mod utils; // TODO(edwin) pub(crate) pub use commit_info::CommitInfo; pub use compute_budget::ComputeBudgetConfig; diff --git a/magicblock-committor-service/src/types.rs b/magicblock-committor-service/src/types.rs index 86b4e5d7e..2f4071638 100644 --- a/magicblock-committor-service/src/types.rs +++ b/magicblock-committor-service/src/types.rs @@ -1,5 +1,9 @@ use std::fmt; +use magicblock_program::{ + magic_scheduled_l1_message::ScheduledL1Message, FeePayerAccount, +}; +use solana_pubkey::Pubkey; use solana_sdk::instruction::Instruction; use crate::CommitInfo; @@ -55,3 +59,9 @@ impl fmt::Display for InstructionsForCommitable { ) } } + +pub struct ScheduledL1MessageWrapper { + pub scheduled_l1_message: ScheduledL1Message, + pub feepayers: Vec, + pub excluded_pubkeys: Vec, +} diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index 02e045ebb..bdee92d81 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -6,9 +6,7 @@ use magicblock_program::magic_scheduled_l1_message::{ }; use solana_pubkey::Pubkey; -use crate::{ - persist::{CommitStatus, L1MessagesPersisterIface}, -}; +use crate::persist::{CommitStatus, L1MessagesPersisterIface}; pub trait ScheduledMessageExt { fn get_committed_accounts(&self) -> Option<&Vec>; @@ -29,6 +27,18 @@ impl ScheduledMessageExt for ScheduledL1Message { } } + fn get_committed_accounts_mut( + &mut self, + ) -> Option<&mut Vec> { + match &self.l1_message { + MagicL1Message::L1Actions(_) => None, + MagicL1Message::Commit(t) => Some(t.get_committed_accounts()), + MagicL1Message::CommitAndUndelegate(t) => { + Some(t.get_committed_accounts()) + } + } + } + fn get_committed_pubkeys(&self) -> Option> { self.get_committed_accounts().map(|accounts| { accounts.iter().map(|account| account.pubkey).collect() diff --git a/programs/magicblock/src/magic_scheduled_l1_message.rs b/programs/magicblock/src/magic_scheduled_l1_message.rs index 02222ca1f..fd69d3f5e 100644 --- a/programs/magicblock/src/magic_scheduled_l1_message.rs +++ b/programs/magicblock/src/magic_scheduled_l1_message.rs @@ -145,6 +145,10 @@ impl CommitAndUndelegate { pub fn get_committed_accounts(&self) -> &Vec { self.commit_action.get_committed_accounts() } + + pub fn get_committed_accounts_mut(&mut self) -> &Vec { + self.commit_action.get_committed_accounts_mut() + } } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -403,6 +407,17 @@ impl CommitType { } => committed_accounts, } } + + pub fn get_committed_accounts_mut( + &mut self, + ) -> &mut Vec { + match self { + Self::Standalone(committed_accounts) => committed_accounts, + Self::WithL1Actions { + committed_accounts, .. + } => committed_accounts, + } + } } /// No CommitedAccounts since it is only used with CommitAction. diff --git a/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs b/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs index b6701b187..fa40bb466 100644 --- a/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs +++ b/programs/magicblock/src/schedule_transactions/process_scheduled_commit_sent.rs @@ -19,7 +19,7 @@ use crate::{ #[derive(Default, Debug, Clone)] pub struct SentCommit { - pub commit_id: u64, + pub message_id: u64, pub slot: Slot, pub blockhash: Hash, pub payer: Pubkey, @@ -48,7 +48,7 @@ struct SentCommitPrintable { impl From for SentCommitPrintable { fn from(commit: SentCommit) -> Self { Self { - id: commit.commit_id, + id: commit.message_id, slot: commit.slot, blockhash: commit.blockhash.to_string(), payer: commit.payer.to_string(), @@ -90,7 +90,7 @@ lazy_static! { } pub fn register_scheduled_commit_sent(commit: SentCommit) { - let id = commit.commit_id; + let id = commit.message_id; SENT_COMMITS .write() .expect("SENT_COMMITS lock poisoned") @@ -251,7 +251,7 @@ mod tests { let payer = Pubkey::new_unique(); let acc = Pubkey::new_unique(); SentCommit { - commit_id, + message_id: commit_id, slot, blockhash: Hash::default(), payer, @@ -295,7 +295,7 @@ mod tests { let mut ix = InstructionUtils::scheduled_commit_sent_instruction( &crate::id(), &validator::validator_authority_id(), - commit.commit_id, + commit.message_id, ); ix.accounts[1].is_signer = false; @@ -309,7 +309,7 @@ mod tests { ); assert!( - get_scheduled_commit(commit.commit_id).is_some(), + get_scheduled_commit(commit.message_id).is_some(), "does not remove scheduled commit data" ); } @@ -332,7 +332,7 @@ mod tests { let ix = InstructionUtils::scheduled_commit_sent_instruction( &crate::id(), &fake_validator.pubkey(), - commit.commit_id, + commit.message_id, ); let transaction_accounts = transaction_accounts_from_map(&ix, &mut account_data); @@ -344,7 +344,7 @@ mod tests { ); assert!( - get_scheduled_commit(commit.commit_id).is_some(), + get_scheduled_commit(commit.message_id).is_some(), "does not remove scheduled commit data" ); } @@ -367,7 +367,7 @@ mod tests { let ix = InstructionUtils::scheduled_commit_sent_instruction( &fake_program.pubkey(), &validator::validator_authority_id(), - commit.commit_id, + commit.message_id, ); let transaction_accounts = transaction_accounts_from_map(&ix, &mut account_data); @@ -380,7 +380,7 @@ mod tests { ); assert!( - get_scheduled_commit(commit.commit_id).is_some(), + get_scheduled_commit(commit.message_id).is_some(), "does not remove scheduled commit data" ); } @@ -396,7 +396,7 @@ mod tests { let ix = InstructionUtils::scheduled_commit_sent_instruction( &crate::id(), &validator::validator_authority_id(), - commit.commit_id, + commit.message_id, ); let transaction_accounts = @@ -409,7 +409,7 @@ mod tests { ); assert!( - get_scheduled_commit(commit.commit_id).is_none(), + get_scheduled_commit(commit.message_id).is_none(), "removes scheduled commit data" ); } From dde67bcf00b28e1dde6d7fecf489b63d6c345bbb Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 23 Jul 2025 17:20:52 +0900 Subject: [PATCH 112/199] feat: integrate l2 tx execution on processed commit --- magicblock-accounts/src/accounts_manager.rs | 3 - .../src/external_accounts_manager.rs | 7 +- .../src/remote_scheduled_commits_processor.rs | 97 +++---------------- .../src/remote_scheduled_commits_worker.rs | 94 ++++-------------- .../src/commit_scheduler.rs | 9 +- .../commit_scheduler_inner.rs | 18 ++-- .../commit_scheduler_worker.rs | 96 +++++++++++++++--- .../src/commit_scheduler/db.rs | 20 ++-- .../src/committor_processor.rs | 14 ++- .../src/l1_message_executor.rs | 16 +-- magicblock-committor-service/src/service.rs | 9 +- magicblock-committor-service/src/types.rs | 1 + magicblock-committor-service/src/utils.rs | 10 +- .../src/magic_scheduled_l1_message.rs | 4 +- 14 files changed, 171 insertions(+), 227 deletions(-) diff --git a/magicblock-accounts/src/accounts_manager.rs b/magicblock-accounts/src/accounts_manager.rs index 57698396f..32b86f977 100644 --- a/magicblock-accounts/src/accounts_manager.rs +++ b/magicblock-accounts/src/accounts_manager.rs @@ -24,15 +24,12 @@ pub type AccountsManager = ExternalAccountsManager< RemoteAccountCommitter, TransactionAccountsExtractorImpl, TransactionAccountsValidatorImpl, - RemoteScheduledCommitsProcessor, >; impl AccountsManager { pub fn try_new( bank: &Arc, - cloned_accounts: &CloneOutputMap, remote_account_cloner_client: RemoteAccountClonerClient, - transaction_status_sender: TransactionStatusSender, validator_keypair: Keypair, config: AccountsConfig, ) -> AccountsResult { diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 4146dbf3d..66f05a655 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -80,7 +80,7 @@ impl ExternalCommitableAccount { } #[derive(Debug)] -pub struct ExternalAccountsManager +pub struct ExternalAccountsManager where IAP: InternalAccountProvider, ACL: AccountCloner, @@ -98,15 +98,14 @@ where RwLock>, } -impl - ExternalAccountsManager +impl + ExternalAccountsManager where IAP: InternalAccountProvider, ACL: AccountCloner, ACM: AccountCommitter, TAE: TransactionAccountsExtractor, TAV: TransactionAccountsValidator, - SCP: ScheduledCommitsProcessor, { pub async fn ensure_accounts( &self, diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index fc06f184d..00c1de7ae 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -59,10 +59,6 @@ impl RemoteScheduledCommitsProcessor { } } - // fn preprocess_messages(&self, mut l1_messages: Vec) -> Vec { - // l1_messages. - // } - fn preprocess_message( &self, mut l1_message: ScheduledL1Message, @@ -85,7 +81,7 @@ impl RemoteScheduledCommitsProcessor { AccountChainSnapshot::ephemeral_balance_pda(&pubkey); feepayers.insert(FeePayerAccount { - pubkey: *pubkey, + pubkey, delegated_pda: ephemeral_pubkey, }); @@ -105,9 +101,9 @@ impl RemoteScheduledCommitsProcessor { } None => { error!( - "Scheduled commit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", - pubkey - ); + "Scheduled commit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", + pubkey + ); excluded_pubkeys.insert(*pubkey); false } @@ -136,7 +132,7 @@ impl RemoteScheduledCommitsProcessor { true } } - Some(AccountClonerOutput::Unclonable {..}) => { + Some(AccountClonerOutput::Unclonable { .. }) => { todo!() } None => true, @@ -149,81 +145,6 @@ impl RemoteScheduledCommitsProcessor { excluded_pubkeys: excluded_pubkeys.into_iter().collect(), } } - - fn preprocess_message2( - &self, - mut l1_message: ScheduledL1Message, - ) -> ScheduledL1MessageWrapper { - let Some(committed_accounts) = l1_message.get_committed_accounts_mut() - else { - return ScheduledL1MessageWrapper { - scheduled_l1_message: l1_message, - excluded_pubkeys: vec![], - feepayers: vec![], - }; - }; - - let mut excluded_pubkeys = HashSet::new(); - let mut feepayers = HashSet::new(); - committed_accounts.retain_mut(|account| { - let pubkey = account.pubkey; - if let Some(AccountClonerOutput::Cloned { - account_chain_snapshot, - .. - }) = self - .cloned_accounts - .read() - .expect(POISONED_RWLOCK_MSG) - .get(&pubkey) - { - if account_chain_snapshot.chain_state.is_feepayer() { - let ephemeral_pubkey = - AccountChainSnapshot::ephemeral_balance_pda(&pubkey); - let ephemeral_owner = - AccountChainSnapshot::ephemeral_balance_pda_owner(); - feepayers.insert(FeePayerAccount { - pubkey: *pubkey, - delegated_pda: ephemeral_pubkey, - }); - - if let Some(account_data) = self.bank.get_account(&ephemeral_pubkey) { - account.pubkey = ephemeral_pubkey; - account.account = Account { - lamports: account_data.lamports(), - data: account_data.data().to_vec(), - owner: ephemeral_owner, - executable: account_data.executable(), - rent_epoch: account_data.rent_epoch() - }; - true - } else { - error!( - "Scheduled commmit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", - pubkey - ); - - // Exclude this - // TODO(edwin): should fail commit really - excluded_pubkeys.insert(pubkey); - false - } - } else if account_chain_snapshot.chain_state.is_undelegated() { - excluded_pubkeys.insert(pubkey); - false - } else { - true - } - } else { - true - } - }); - - ScheduledL1MessageWrapper { - scheduled_l1_message: l1_message, - feepayers: feepayers.into_iter().collect(), - excluded_pubkeys: excluded_pubkeys.into_iter().collect(), - } - } } #[async_trait] @@ -238,8 +159,12 @@ impl ScheduledCommitsProcessor return Ok(()); } - let l1_messages = self.preprocess(scheduled_l1_messages); - self.committor.commit_l1_messages(scheduled_l1_messages); + let scheduled_l1_messages_wrapped = scheduled_l1_messages + .into_iter() + .map(|message| self.preprocess_message(message)) + .collect(); + self.committor + .commit_l1_messages(scheduled_l1_messages_wrapped); Ok(()) } diff --git a/magicblock-accounts/src/remote_scheduled_commits_worker.rs b/magicblock-accounts/src/remote_scheduled_commits_worker.rs index 413c094a8..82e4f19ae 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_worker.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_worker.rs @@ -6,7 +6,10 @@ use std::{ use log::{debug, error}; use magicblock_bank::bank::Bank; use magicblock_committor_service::{ - l1_message_executor::{BroadcastedMessageExecutionResult, ExecutionOutput}, + commit_scheduler::{ + BroadcastedMessageExecutionResult, ExecutionOutputWrapper, + }, + l1_message_executor::ExecutionOutput, persist::MessageSignatures, ChangesetMeta, L1MessageCommittor, }; @@ -49,17 +52,23 @@ impl RemoteScheduledCommitsWorker { let mut result_receiver = self.result_subscriber.await.expect(SUBSCRIPTION_ERR_MSG); - while let Ok(l1_messages) = result_receiver.recv().await { - let metadata = ChangesetMeta::from(&l1_messages); - self.process_message_result(metadata, todo!()).await; + while let Ok(execution_result) = result_receiver.recv().await { + match execution_result { + Ok(value) => self.process_message_result(value).await, + Err(err) => { + todo!() + } + } } } - async fn process_message_result(&self, execution_outcome: ExecutionOutput) { - sent_commit.chain_signatures = chain_signatures; - register_scheduled_commit_sent(sent_commit); + async fn process_message_result( + &self, + execution_outcome: ExecutionOutputWrapper, + ) { + register_scheduled_commit_sent(execution_outcome.sent_commit); match execute_legacy_transaction( - commit_sent_transaction, + execution_outcome.action_sent_transaction, &self.bank, Some(&self.transaction_status_sender), ) { @@ -72,73 +81,4 @@ impl RemoteScheduledCommitsWorker { } } } - - async fn process_message_result_old( - &self, - metadata: ChangesetMeta, - mut sent_commits: HashMap, - ) { - for bundle_id in metadata - .accounts - .iter() - .map(|account| account.bundle_id) - .collect::>() - { - let bundle_signatures = match self - .committor - .get_commit_signatures(bundle_id) - .await - { - Ok(Ok(sig)) => sig, - Ok(Err(err)) => { - error!("Encountered error while getting bundle signatures for {}: {:?}", bundle_id, err); - continue; - } - Err(err) => { - error!("Encountered error while getting bundle signatures for {}: {:?}", bundle_id, err); - continue; - } - }; - match bundle_signatures { - Some(MessageSignatures { - processed_signature, - finalized_signature, - .. - }) => { - let mut chain_signatures = vec![processed_signature]; - if let Some(finalized_signature) = finalized_signature { - chain_signatures.push(finalized_signature); - } - if let Some((commit_sent_transaction, mut sent_commit)) = - sent_commits.remove(&bundle_id) - { - sent_commit.chain_signatures = chain_signatures; - register_scheduled_commit_sent(sent_commit); - match execute_legacy_transaction( - commit_sent_transaction, - &self.bank, - Some(&self.transaction_status_sender), - ) { - Ok(signature) => debug!( - "Signaled sent commit with internal signature: {:?}", - signature - ), - Err(err) => { - error!("Failed to signal sent commit via transaction: {}", err); - } - } - } else { - error!( - "BUG: Failed to get sent commit for bundle id {} that should have been added", - bundle_id - ); - } - } - None => error!( - "Failed to get bundle signatures for bundle id {}", - bundle_id - ), - } - } - } } diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index 38d21274e..c94659934 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -6,6 +6,9 @@ mod executor_pool; use std::sync::Arc; +pub use commit_scheduler_worker::{ + BroadcastedMessageExecutionResult, ExecutionOutputWrapper, +}; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; @@ -16,15 +19,15 @@ use crate::{ commit_scheduler_worker::{CommitSchedulerWorker, ResultSubscriber}, db::DB, }, - l1_message_executor::BroadcastedMessageExecutionResult, persist::L1MessagesPersisterIface, + types::ScheduledL1MessageWrapper, ComputeBudgetConfig, }; pub struct CommitScheduler { db: Arc, result_subscriber: ResultSubscriber, - message_sender: mpsc::Sender, + message_sender: mpsc::Sender, } impl CommitScheduler { @@ -61,7 +64,7 @@ impl CommitScheduler { /// Messages will be extracted and handled in the [`CommitSchedulerWorker`] pub async fn schedule( &self, - l1_messages: Vec, + l1_messages: Vec, ) -> Result<(), Error> { // If db not empty push el-t there // This means that at some point channel got full diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index 19dab1fc0..7a277823d 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -3,7 +3,7 @@ use std::collections::{hash_map::Entry, HashMap, VecDeque}; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::Pubkey; -use crate::utils::ScheduledMessageExt; +use crate::{types::ScheduledL1MessageWrapper, utils::ScheduledMessageExt}; pub(crate) const POISONED_INNER_MSG: &str = "Mutex on CommitSchedulerInner is poisoned."; @@ -11,7 +11,7 @@ pub(crate) const POISONED_INNER_MSG: &str = type MessageID = u64; struct MessageMeta { num_keys: usize, - message: ScheduledL1Message, + message: ScheduledL1MessageWrapper, } /// A scheduler that ensures mutually exclusive access to pubkeys across messages @@ -77,10 +77,12 @@ impl CommitSchedulerInner { /// otherwise consumes it and enqueues pub fn schedule( &mut self, - l1_message: ScheduledL1Message, - ) -> Option { - let message_id = l1_message.id; - let Some(pubkeys) = l1_message.get_committed_pubkeys() else { + l1_message: ScheduledL1MessageWrapper, + ) -> Option { + let message_id = l1_message.scheduled_l1_message.id; + let Some(pubkeys) = + l1_message.scheduled_l1_message.get_committed_pubkeys() + else { return Some(l1_message); }; @@ -144,7 +146,9 @@ impl CommitSchedulerInner { } // Returns [`ScheduledL1Message`] that can be executed - pub fn pop_next_scheduled_message(&mut self) -> Option { + pub fn pop_next_scheduled_message( + &mut self, + ) -> Option { // TODO(edwin): optimize. Create counter im MessageMeta & update let mut execute_candidates: HashMap = HashMap::new(); self.blocked_keys.iter().for_each(|(_, queue)| { diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index f700ea171..17e693203 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -1,13 +1,16 @@ use std::{ - collections::HashMap, + collections::{HashMap, HashSet}, sync::{Arc, Mutex}, }; use log::{error, info, trace, warn}; -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; +use magicblock_program::{ + magic_scheduled_l1_message::ScheduledL1Message, FeePayerAccount, SentCommit, +}; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; +use solana_sdk::transaction::Transaction; use tokio::sync::{ broadcast, mpsc, mpsc::error::TryRecvError, Notify, OwnedSemaphorePermit, Semaphore, @@ -21,18 +24,31 @@ use crate::{ Error, }, l1_message_executor::{ - BroadcastedMessageExecutionResult, L1MessageExecutor, + ExecutionOutput, L1MessageExecutor, MessageExecutorResult, }, persist::L1MessagesPersisterIface, transaction_preperator::transaction_preparator::{ TransactionPreparator, TransactionPreparatorV1, }, + types::ScheduledL1MessageWrapper, utils::ScheduledMessageExt, ComputeBudgetConfig, }; const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; +// TODO(edwin): rename +#[derive(Clone)] +pub struct ExecutionOutputWrapper { + pub output: ExecutionOutput, + pub action_sent_transaction: Transaction, + pub sent_commit: SentCommit, +} +pub type BroadcastedMessageExecutionResult = MessageExecutorResult< + ExecutionOutputWrapper, + Arc, +>; + /// Struct that exposes only `subscribe` method of `broadcast::Sender` for better isolation pub struct ResultSubscriber( broadcast::Sender, @@ -50,7 +66,7 @@ pub(crate) struct CommitSchedulerWorker { l1_messages_persister: Option

, executor_factory: L1MessageExecutorFactory, commit_id_tracker: CommitIdTracker, - receiver: mpsc::Receiver, + receiver: mpsc::Receiver, // TODO(edwin): replace notify. issue: 2 simultaneous notifications notify: Arc, @@ -69,7 +85,7 @@ where rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, - receiver: mpsc::Receiver, + receiver: mpsc::Receiver, ) -> Self { // Number of executors that can send messages in parallel to L1 const NUM_OF_EXECUTORS: u8 = 50; @@ -129,7 +145,7 @@ where // Prepare data for execution let commit_ids = if let Some(pubkeys) = - l1_message.get_committed_pubkeys() + l1_message.scheduled_l1_message.get_committed_pubkeys() { let commit_ids = self .commit_id_tracker @@ -143,8 +159,8 @@ where let Some(persistor) = &self.l1_messages_persister else { return; }; - if let Err(err) = persistor.set_commit_id(l1_message.id, pubkey, *commit_id) { - error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.id, pubkey, err); + if let Err(err) = persistor.set_commit_id(l1_message.scheduled_l1_message.id, pubkey, *commit_id) { + error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.scheduled_l1_message.id, pubkey, err); } }); @@ -173,10 +189,10 @@ where } } - /// Returns [`ScheduledL1Message`] or None if all messages are blocked + /// Returns [`ScheduledL1MessageWrapper`] or None if all messages are blocked async fn next_scheduled_message( &mut self, - ) -> Result, Error> { + ) -> Result, Error> { // Limit on number of messages that can be stored in scheduler const SCHEDULER_CAPACITY: usize = 1000; @@ -211,7 +227,9 @@ where } /// Returns [`ScheduledL1Message`] from external channel - async fn get_new_message(&mut self) -> Result { + async fn get_new_message( + &mut self, + ) -> Result { match self.receiver.try_recv() { Ok(val) => Ok(val), Err(TryRecvError::Empty) => { @@ -231,7 +249,7 @@ where async fn execute( executor: L1MessageExecutor, persister: Option

, - l1_message: ScheduledL1Message, + l1_message: ScheduledL1MessageWrapper, commit_ids: HashMap, inner_scheduler: Arc>, execution_permit: OwnedSemaphorePermit, @@ -239,9 +257,16 @@ where notify: Arc, ) { let result = executor - .execute(l1_message.clone(), commit_ids, persister) + .execute( + l1_message.scheduled_l1_message.clone(), + commit_ids, + persister, + ) .await .inspect_err(|err| error!("Failed to execute L1Message: {:?}", err)) + .map(|raw_result| { + Self::map_execution_outcome(&l1_message, raw_result) + }) .map_err(|err| Arc::new(err)); // Broadcast result to subscribers @@ -252,13 +277,56 @@ where inner_scheduler .lock() .expect(POISONED_INNER_MSG) - .complete(&l1_message); + .complete(&l1_message.scheduled_l1_message); // Notify main loop that executor is done // This will trigger scheduling next message notify.notify_waiters(); // Free worker drop(execution_permit); } + + /// Maps output of `L1MessageExecutor` to final result + fn map_execution_outcome( + l1_message: &ScheduledL1MessageWrapper, + raw_outcome: ExecutionOutput, + ) -> ExecutionOutputWrapper { + let ScheduledL1MessageWrapper { + scheduled_l1_message, + feepayers, + excluded_pubkeys, + } = l1_message; + let included_pubkeys = if let Some(included_pubkeys) = + scheduled_l1_message.get_committed_pubkeys() + { + included_pubkeys + } else { + // Case with standalone actions + vec![] + }; + let requested_undelegation = scheduled_l1_message.is_undelegate(); + let chain_signatures = + vec![raw_outcome.commit_signature, raw_outcome.finalize_signature]; + + let sent_commit = SentCommit { + message_id: scheduled_l1_message.id, + slot: scheduled_l1_message.slot, + blockhash: scheduled_l1_message.blockhash, + payer: scheduled_l1_message.payer, + included_pubkeys, + excluded_pubkeys: excluded_pubkeys.clone(), + feepayers: HashSet::from_iter(feepayers.iter().cloned()), + requested_undelegation, + chain_signatures, + }; + + ExecutionOutputWrapper { + output: raw_outcome, + action_sent_transaction: scheduled_l1_message + .action_sent_transaction + .clone(), + sent_commit, + } + } } /// Dummy struct to implify signatur diff --git a/magicblock-committor-service/src/commit_scheduler/db.rs b/magicblock-committor-service/src/commit_scheduler/db.rs index 5cb1af0a2..626377cde 100644 --- a/magicblock-committor-service/src/commit_scheduler/db.rs +++ b/magicblock-committor-service/src/commit_scheduler/db.rs @@ -4,25 +4,29 @@ use std::{collections::VecDeque, sync::Mutex}; use async_trait::async_trait; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; +use crate::types::ScheduledL1MessageWrapper; + const POISONED_MUTEX_MSG: &str = "Mutex poisoned"; #[async_trait] pub trait DB: Send + Sync + 'static { async fn store_l1_message( &self, - l1_message: ScheduledL1Message, + l1_message: ScheduledL1MessageWrapper, ) -> DBResult<()>; async fn store_l1_messages( &self, - l1_messages: Vec, + l1_messages: Vec, ) -> DBResult<()>; /// Return message with smallest bundle_id - async fn pop_l1_message(&self) -> DBResult>; + async fn pop_l1_message( + &self, + ) -> DBResult>; fn is_empty(&self) -> bool; } pub(crate) struct DummyDB { - db: Mutex>, + db: Mutex>, } impl DummyDB { @@ -37,7 +41,7 @@ impl DummyDB { impl DB for DummyDB { async fn store_l1_message( &self, - l1_message: ScheduledL1Message, + l1_message: ScheduledL1MessageWrapper, ) -> DBResult<()> { self.db .lock() @@ -48,7 +52,7 @@ impl DB for DummyDB { async fn store_l1_messages( &self, - l1_messages: Vec, + l1_messages: Vec, ) -> DBResult<()> { self.db .lock() @@ -57,7 +61,9 @@ impl DB for DummyDB { Ok(()) } - async fn pop_l1_message(&self) -> DBResult> { + async fn pop_l1_message( + &self, + ) -> DBResult> { Ok(self.db.lock().expect(POISONED_MUTEX_MSG).pop_front()) } diff --git a/magicblock-committor-service/src/committor_processor.rs b/magicblock-committor-service/src/committor_processor.rs index e6c436f4a..7ffd3a4cc 100644 --- a/magicblock-committor-service/src/committor_processor.rs +++ b/magicblock-committor-service/src/committor_processor.rs @@ -12,15 +12,17 @@ use solana_sdk::{ use tokio::sync::broadcast; use crate::{ - commit_scheduler::{db::DummyDB, CommitScheduler}, + commit_scheduler::{ + db::DummyDB, BroadcastedMessageExecutionResult, CommitScheduler, + }, compute_budget::ComputeBudgetConfig, config::ChainConfig, error::CommittorServiceResult, - l1_message_executor::BroadcastedMessageExecutionResult, persist::{ CommitStatusRow, L1MessagePersister, L1MessagesPersisterIface, MessageSignatures, }, + types::ScheduledL1MessageWrapper, }; pub(crate) struct CommittorProcessor { @@ -128,9 +130,13 @@ impl CommittorProcessor { pub async fn commit_l1_messages( &self, - l1_messages: Vec, + l1_messages: Vec, ) { - if let Err(err) = self.persister.start_l1_messages(&l1_messages) { + let l1_messages_inner = l1_messages + .iter() + .map(|l1_message| l1_message.scheduled_l1_message.clone()) + .collect::>(); + if let Err(err) = self.persister.start_l1_messages(&l1_messages_inner) { // We will still try to perform the commits, but the fact that we cannot // persist the intent is very serious and we should probably restart the // valiator diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index 9ef0ef2b6..9c2cbf51f 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -23,21 +23,17 @@ use crate::{ transaction_preperator::transaction_preparator::{ TransactionPreparator, TransactionPreparatorV1, }, + types::ScheduledL1MessageWrapper, utils::{persist_status_update, persist_status_update_set}, ComputeBudgetConfig, }; -pub type BroadcastedMessageExecutionResult = - MessageExecutorResult>; - // TODO(edwin): define struct // (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] #[derive(Clone, Debug)] pub struct ExecutionOutput { - commit_signature: Signature, - finalize_signature: Signature, - sent_commit: SentCommit, - action_sent_transaction: Transaction, + pub commit_signature: Signature, + pub finalize_signature: Signature, } pub(crate) struct L1MessageExecutor { @@ -104,15 +100,9 @@ where .execute_finalize_stage(&l1_message, commit_signature, persister) .await?; - let sent_commit = SentCommit { - message_id: l1_message.id, - slot: l1_message.slot, - blockhash: l1_message.blockhash, - }; Ok(ExecutionOutput { commit_signature, finalize_signature, - action_sent_transaction: l1_message.action_sent_transaction, }) } diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index e84a610a7..178ff0b62 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -15,12 +15,13 @@ use tokio::{ use tokio_util::sync::CancellationToken; use crate::{ + commit_scheduler::BroadcastedMessageExecutionResult, committor_processor::CommittorProcessor, config::ChainConfig, error::CommittorServiceResult, - l1_message_executor::BroadcastedMessageExecutionResult, persist::{CommitStatusRow, MessageSignatures}, pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, + types::ScheduledL1MessageWrapper, }; #[derive(Debug)] @@ -50,7 +51,7 @@ pub enum CommittorMessage { }, CommitChangeset { /// The [`ScheduledL1Message`]s to commit - l1_messages: Vec, + l1_messages: Vec, }, GetCommitStatuses { respond_to: @@ -304,7 +305,7 @@ impl L1MessageCommittor for CommittorService { rx } - fn commit_l1_messages(&self, l1_messages: Vec) { + fn commit_l1_messages(&self, l1_messages: Vec) { self.try_send(CommittorMessage::CommitChangeset { l1_messages }); } @@ -354,7 +355,7 @@ pub trait L1MessageCommittor: Send + Sync + 'static { ) -> oneshot::Receiver>; /// Commits the changeset and returns - fn commit_l1_messages(&self, l1_messages: Vec); + fn commit_l1_messages(&self, l1_messages: Vec); /// Subscribes for results of L1Message execution fn subscribe_for_results( diff --git a/magicblock-committor-service/src/types.rs b/magicblock-committor-service/src/types.rs index 2f4071638..203a09d94 100644 --- a/magicblock-committor-service/src/types.rs +++ b/magicblock-committor-service/src/types.rs @@ -60,6 +60,7 @@ impl fmt::Display for InstructionsForCommitable { } } +#[derive(Clone, Debug)] pub struct ScheduledL1MessageWrapper { pub scheduled_l1_message: ScheduledL1Message, pub feepayers: Vec, diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index bdee92d81..2150c06f3 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -11,7 +11,9 @@ use crate::persist::{CommitStatus, L1MessagesPersisterIface}; pub trait ScheduledMessageExt { fn get_committed_accounts(&self) -> Option<&Vec>; fn get_committed_pubkeys(&self) -> Option>; - + fn get_committed_accounts_mut( + &mut self, + ) -> Option<&mut Vec>; // TODO(edwin): ugly fn is_undelegate(&self) -> bool; } @@ -30,11 +32,11 @@ impl ScheduledMessageExt for ScheduledL1Message { fn get_committed_accounts_mut( &mut self, ) -> Option<&mut Vec> { - match &self.l1_message { + match &mut self.l1_message { MagicL1Message::L1Actions(_) => None, - MagicL1Message::Commit(t) => Some(t.get_committed_accounts()), + MagicL1Message::Commit(t) => Some(t.get_committed_accounts_mut()), MagicL1Message::CommitAndUndelegate(t) => { - Some(t.get_committed_accounts()) + Some(t.get_committed_accounts_mut()) } } } diff --git a/programs/magicblock/src/magic_scheduled_l1_message.rs b/programs/magicblock/src/magic_scheduled_l1_message.rs index fd69d3f5e..9812b18f4 100644 --- a/programs/magicblock/src/magic_scheduled_l1_message.rs +++ b/programs/magicblock/src/magic_scheduled_l1_message.rs @@ -146,7 +146,9 @@ impl CommitAndUndelegate { self.commit_action.get_committed_accounts() } - pub fn get_committed_accounts_mut(&mut self) -> &Vec { + pub fn get_committed_accounts_mut( + &mut self, + ) -> &mut Vec { self.commit_action.get_committed_accounts_mut() } } From d3301a0f91c4e93503eae0a5cda6b4526f7a23cb Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 23 Jul 2025 17:44:13 +0900 Subject: [PATCH 113/199] refactor: removed unnecessary worker --- .../src/external_accounts_manager.rs | 3 +- magicblock-accounts/src/lib.rs | 1 - .../src/remote_scheduled_commits_processor.rs | 77 ++++++++++++++--- .../src/remote_scheduled_commits_worker.rs | 84 ------------------- 4 files changed, 68 insertions(+), 97 deletions(-) delete mode 100644 magicblock-accounts/src/remote_scheduled_commits_worker.rs diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 66f05a655..8fe1bc2e5 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -98,8 +98,7 @@ where RwLock>, } -impl - ExternalAccountsManager +impl ExternalAccountsManager where IAP: InternalAccountProvider, ACL: AccountCloner, diff --git a/magicblock-accounts/src/lib.rs b/magicblock-accounts/src/lib.rs index 9e3e0c854..aef732800 100644 --- a/magicblock-accounts/src/lib.rs +++ b/magicblock-accounts/src/lib.rs @@ -4,7 +4,6 @@ pub mod errors; mod external_accounts_manager; mod remote_account_committer; pub mod remote_scheduled_commits_processor; -mod remote_scheduled_commits_worker; mod traits; pub mod utils; diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 00c1de7ae..d155d6fa0 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -2,27 +2,35 @@ use std::{collections::HashSet, sync::Arc}; use async_trait::async_trait; use conjunto_transwise::AccountChainSnapshot; -use log::error; +use log::{debug, error}; use magicblock_account_cloner::{AccountClonerOutput, CloneOutputMap}; use magicblock_bank::bank::Bank; use magicblock_committor_service::{ - types::ScheduledL1MessageWrapper, utils::ScheduledMessageExt, + commit_scheduler::{ + BroadcastedMessageExecutionResult, ExecutionOutputWrapper, + }, + types::ScheduledL1MessageWrapper, + utils::ScheduledMessageExt, L1MessageCommittor, }; +use magicblock_processor::execute_transaction::execute_legacy_transaction; use magicblock_program::{ magic_scheduled_l1_message::{CommittedAccountV2, ScheduledL1Message}, - FeePayerAccount, TransactionScheduler, + register_scheduled_commit_sent, FeePayerAccount, TransactionScheduler, }; use magicblock_transaction_status::TransactionStatusSender; use solana_sdk::{ account::{Account, ReadableAccount}, pubkey::Pubkey, }; -use tokio::sync::mpsc::{channel, Sender}; +use tokio::sync::{ + broadcast, + mpsc::{channel, Sender}, + oneshot, +}; use crate::{ errors::AccountsResult, - remote_scheduled_commits_worker::RemoteScheduledCommitsWorker, ScheduledCommitsProcessor, }; @@ -44,12 +52,11 @@ impl RemoteScheduledCommitsProcessor { transaction_status_sender: TransactionStatusSender, ) -> Self { let result_subscriber = committor.subscribe_for_results(); - let worker = RemoteScheduledCommitsWorker::new( + tokio::spawn(Self::result_processor( bank.clone(), result_subscriber, transaction_status_sender, - ); - tokio::spawn(worker.start()); + )); Self { bank, @@ -75,7 +82,7 @@ impl RemoteScheduledCommitsProcessor { let mut excluded_pubkeys = HashSet::new(); let mut feepayers = HashSet::new(); - let process_feepayer = |account: &mut CommittedAccountV2| -> bool { + let mut process_feepayer = |account: &mut CommittedAccountV2| -> bool { let pubkey = account.pubkey; let ephemeral_pubkey = AccountChainSnapshot::ephemeral_balance_pda(&pubkey); @@ -104,7 +111,7 @@ impl RemoteScheduledCommitsProcessor { "Scheduled commit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", pubkey ); - excluded_pubkeys.insert(*pubkey); + excluded_pubkeys.insert(pubkey); false } } @@ -145,6 +152,56 @@ impl RemoteScheduledCommitsProcessor { excluded_pubkeys: excluded_pubkeys.into_iter().collect(), } } + + async fn result_processor( + bank: Arc, + result_subscriber: oneshot::Receiver< + broadcast::Receiver, + >, + transaction_status_sender: TransactionStatusSender, + ) { + const SUBSCRIPTION_ERR_MSG: &str = + "Failed to get subscription of results of L1Messages execution"; + + let mut result_receiver = + result_subscriber.await.expect(SUBSCRIPTION_ERR_MSG); + while let Ok(execution_result) = result_receiver.recv().await { + match execution_result { + Ok(value) => { + Self::process_message_result( + &bank, + &transaction_status_sender, + value, + ) + .await + } + Err(err) => { + todo!() + } + } + } + } + + async fn process_message_result( + bank: &Arc, + transaction_status_sender: &TransactionStatusSender, + execution_outcome: ExecutionOutputWrapper, + ) { + register_scheduled_commit_sent(execution_outcome.sent_commit); + match execute_legacy_transaction( + execution_outcome.action_sent_transaction, + bank, + Some(transaction_status_sender), + ) { + Ok(signature) => debug!( + "Signaled sent commit with internal signature: {:?}", + signature + ), + Err(err) => { + error!("Failed to signal sent commit via transaction: {}", err); + } + } + } } #[async_trait] diff --git a/magicblock-accounts/src/remote_scheduled_commits_worker.rs b/magicblock-accounts/src/remote_scheduled_commits_worker.rs deleted file mode 100644 index 82e4f19ae..000000000 --- a/magicblock-accounts/src/remote_scheduled_commits_worker.rs +++ /dev/null @@ -1,84 +0,0 @@ -use std::{ - collections::{HashMap, HashSet}, - sync::Arc, -}; - -use log::{debug, error}; -use magicblock_bank::bank::Bank; -use magicblock_committor_service::{ - commit_scheduler::{ - BroadcastedMessageExecutionResult, ExecutionOutputWrapper, - }, - l1_message_executor::ExecutionOutput, - persist::MessageSignatures, - ChangesetMeta, L1MessageCommittor, -}; -use magicblock_processor::execute_transaction::execute_legacy_transaction; -use magicblock_program::{ - magic_scheduled_l1_message::ScheduledL1Message, - register_scheduled_commit_sent, SentCommit, -}; -use magicblock_transaction_status::TransactionStatusSender; -use solana_sdk::transaction::Transaction; -use tokio::sync::{broadcast, mpsc::Receiver, oneshot}; - -pub(crate) struct RemoteScheduledCommitsWorker { - bank: Arc, - result_subscriber: oneshot::Receiver< - broadcast::Receiver, - >, - transaction_status_sender: TransactionStatusSender, -} - -impl RemoteScheduledCommitsWorker { - pub fn new( - bank: Arc, - result_subscriber: oneshot::Receiver< - broadcast::Receiver, - >, - transaction_status_sender: TransactionStatusSender, - ) -> Self { - Self { - bank, - result_subscriber, - transaction_status_sender, - } - } - - // TODO(edwin): maybe not needed - pub async fn start(mut self) { - const SUBSCRIPTION_ERR_MSG: &str = - "Failed to get subscription of results of L1Messages execution"; - - let mut result_receiver = - self.result_subscriber.await.expect(SUBSCRIPTION_ERR_MSG); - while let Ok(execution_result) = result_receiver.recv().await { - match execution_result { - Ok(value) => self.process_message_result(value).await, - Err(err) => { - todo!() - } - } - } - } - - async fn process_message_result( - &self, - execution_outcome: ExecutionOutputWrapper, - ) { - register_scheduled_commit_sent(execution_outcome.sent_commit); - match execute_legacy_transaction( - execution_outcome.action_sent_transaction, - &self.bank, - Some(&self.transaction_status_sender), - ) { - Ok(signature) => debug!( - "Signaled sent commit with internal signature: {:?}", - signature - ), - Err(err) => { - error!("Failed to signal sent commit via transaction: {}", err); - } - } - } -} From 03a9d987099034838090b8e328124353f3e8b507 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 23 Jul 2025 18:00:00 +0900 Subject: [PATCH 114/199] fix: compilation --- .../src/remote_scheduled_commits_processor.rs | 132 ++++++++++-------- 1 file changed, 75 insertions(+), 57 deletions(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index d155d6fa0..237811595 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -29,10 +29,7 @@ use tokio::sync::{ oneshot, }; -use crate::{ - errors::AccountsResult, - ScheduledCommitsProcessor, -}; +use crate::{errors::AccountsResult, ScheduledCommitsProcessor}; const POISONED_RWLOCK_MSG: &str = "RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned"; @@ -79,77 +76,98 @@ impl RemoteScheduledCommitsProcessor { }; }; - let mut excluded_pubkeys = HashSet::new(); - let mut feepayers = HashSet::new(); + struct Processor<'a> { + excluded_pubkeys: HashSet, + feepayers: HashSet, + bank: &'a Bank, + } - let mut process_feepayer = |account: &mut CommittedAccountV2| -> bool { - let pubkey = account.pubkey; - let ephemeral_pubkey = - AccountChainSnapshot::ephemeral_balance_pda(&pubkey); - - feepayers.insert(FeePayerAccount { - pubkey, - delegated_pda: ephemeral_pubkey, - }); - - match self.bank.get_account(&ephemeral_pubkey) { - Some(account_data) => { - let ephemeral_owner = - AccountChainSnapshot::ephemeral_balance_pda_owner(); - account.pubkey = ephemeral_pubkey; - account.account = Account { - lamports: account_data.lamports(), - data: account_data.data().to_vec(), - owner: ephemeral_owner, - executable: account_data.executable(), - rent_epoch: account_data.rent_epoch(), - }; - true - } - None => { - error!( - "Scheduled commit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", - pubkey - ); - excluded_pubkeys.insert(pubkey); - false + impl<'a> Processor<'a> { + /// Handles case when committed account is feepayer + /// Returns `true` if account should be retained, `false` otherwise + fn process_feepayer( + &mut self, + account: &mut CommittedAccountV2, + ) -> bool { + let pubkey = account.pubkey; + let ephemeral_pubkey = + AccountChainSnapshot::ephemeral_balance_pda(&pubkey); + + self.feepayers.insert(FeePayerAccount { + pubkey, + delegated_pda: ephemeral_pubkey, + }); + + match self.bank.get_account(&ephemeral_pubkey) { + Some(account_data) => { + let ephemeral_owner = + AccountChainSnapshot::ephemeral_balance_pda_owner(); + account.pubkey = ephemeral_pubkey; + account.account = Account { + lamports: account_data.lamports(), + data: account_data.data().to_vec(), + owner: ephemeral_owner, + executable: account_data.executable(), + rent_epoch: account_data.rent_epoch(), + }; + true + } + None => { + // TODO(edwin): shouldn't be possible panic? + error!( + "Scheduled commit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", + pubkey + ); + self.excluded_pubkeys.insert(pubkey); + false + } } } + } + + let mut processor = Processor { + excluded_pubkeys: HashSet::new(), + feepayers: HashSet::new(), + bank: &self.bank, }; + /// Retains onlu account that are valid to be commited committed_accounts.retain_mut(|account| { let pubkey = account.pubkey; - let cloned_accounts = - self.cloned_accounts.read().expect(POISONED_RWLOCK_MSG); - - match cloned_accounts.get(&pubkey) { + let account_chain_snapshot = match self + .cloned_accounts + .read() + .expect(POISONED_RWLOCK_MSG) + .get(&pubkey) + { Some(AccountClonerOutput::Cloned { account_chain_snapshot, .. - }) => { - if account_chain_snapshot.chain_state.is_feepayer() { - process_feepayer(account) - } else if account_chain_snapshot - .chain_state - .is_undelegated() - { - excluded_pubkeys.insert(pubkey); - false - } else { - true - } - } + }) => account_chain_snapshot, Some(AccountClonerOutput::Unclonable { .. }) => { todo!() } - None => true, + // TODO(edwin): hmm + None => return true, + }; + + if account_chain_snapshot.chain_state.is_feepayer() { + // Feepayer case, should actually always return true + processor.process_feepayer(account) + } else if account_chain_snapshot.chain_state.is_undelegated() { + // Can be safely excluded + processor.excluded_pubkeys.insert(account.pubkey); + false + } else { + // Means delegated so we keep it + true } }); ScheduledL1MessageWrapper { scheduled_l1_message: l1_message, - feepayers: feepayers.into_iter().collect(), - excluded_pubkeys: excluded_pubkeys.into_iter().collect(), + feepayers: processor.feepayers.into_iter().collect(), + excluded_pubkeys: processor.excluded_pubkeys.into_iter().collect(), } } From 1a4889fa70aa4d613d90f0abc2a3850757281437 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 24 Jul 2025 16:35:34 +0900 Subject: [PATCH 115/199] feat: Integrated CommittorService into AccountsManager --- .../src/bank_account_provider.rs | 7 +- .../src/internal_account_provider.rs | 5 +- .../src/internal_account_provider_stub.rs | 8 +- magicblock-accounts/README.md | 5 +- magicblock-accounts/src/accounts_manager.rs | 30 +- magicblock-accounts/src/errors.rs | 11 +- .../src/external_accounts_manager.rs | 253 ++++++----- magicblock-accounts/src/lib.rs | 1 - .../src/remote_account_committer.rs | 398 ------------------ .../src/remote_scheduled_commits_processor.rs | 52 ++- magicblock-accounts/src/traits.rs | 28 +- magicblock-api/src/magic_validator.rs | 37 +- .../commit_scheduler_worker.rs | 58 +-- magicblock-committor-service/src/lib.rs | 6 +- .../src/service_ext.rs | 178 ++++++++ .../src/transactions.rs | 20 +- magicblock-committor-service/src/types.rs | 9 + 17 files changed, 471 insertions(+), 635 deletions(-) delete mode 100644 magicblock-accounts/src/remote_account_committer.rs create mode 100644 magicblock-committor-service/src/service_ext.rs diff --git a/magicblock-accounts-api/src/bank_account_provider.rs b/magicblock-accounts-api/src/bank_account_provider.rs index 75fa90736..e6a4ef477 100644 --- a/magicblock-accounts-api/src/bank_account_provider.rs +++ b/magicblock-accounts-api/src/bank_account_provider.rs @@ -1,7 +1,9 @@ use std::sync::Arc; use magicblock_bank::bank::Bank; -use solana_sdk::{account::AccountSharedData, clock::Slot, pubkey::Pubkey}; +use solana_sdk::{ + account::AccountSharedData, clock::Slot, hash::Hash, pubkey::Pubkey, +}; use crate::InternalAccountProvider; @@ -33,4 +35,7 @@ impl InternalAccountProvider for BankAccountProvider { fn get_slot(&self) -> Slot { self.bank.slot() } + fn get_blockhash(&self) -> Hash { + self.bank.last_blockhash() + } } diff --git a/magicblock-accounts-api/src/internal_account_provider.rs b/magicblock-accounts-api/src/internal_account_provider.rs index fa94d43cb..1178bab80 100644 --- a/magicblock-accounts-api/src/internal_account_provider.rs +++ b/magicblock-accounts-api/src/internal_account_provider.rs @@ -1,4 +1,6 @@ -use solana_sdk::{account::AccountSharedData, clock::Slot, pubkey::Pubkey}; +use solana_sdk::{ + account::AccountSharedData, clock::Slot, hash::Hash, pubkey::Pubkey, +}; pub trait InternalAccountProvider: Send + Sync { fn has_account(&self, pubkey: &Pubkey) -> bool; @@ -6,4 +8,5 @@ pub trait InternalAccountProvider: Send + Sync { fn get_account(&self, pubkey: &Pubkey) -> Option; fn get_all_accounts(&self) -> Vec<(Pubkey, AccountSharedData)>; fn get_slot(&self) -> Slot; + fn get_blockhash(&self) -> Hash; } diff --git a/magicblock-accounts-api/src/internal_account_provider_stub.rs b/magicblock-accounts-api/src/internal_account_provider_stub.rs index be63718e2..2fafd011b 100644 --- a/magicblock-accounts-api/src/internal_account_provider_stub.rs +++ b/magicblock-accounts-api/src/internal_account_provider_stub.rs @@ -3,13 +3,16 @@ use std::{ sync::{Arc, RwLock}, }; -use solana_sdk::{account::AccountSharedData, clock::Slot, pubkey::Pubkey}; +use solana_sdk::{ + account::AccountSharedData, clock::Slot, hash::Hash, pubkey::Pubkey, +}; use crate::InternalAccountProvider; #[derive(Debug, Clone, Default)] pub struct InternalAccountProviderStub { slot: Slot, + hash: Hash, accounts: Arc>>, } @@ -37,4 +40,7 @@ impl InternalAccountProvider for InternalAccountProviderStub { fn get_slot(&self) -> Slot { self.slot } + fn get_blockhash(&self) -> Hash { + self.hash + } } diff --git a/magicblock-accounts/README.md b/magicblock-accounts/README.md index bbcc4dfa3..550279827 100644 --- a/magicblock-accounts/README.md +++ b/magicblock-accounts/README.md @@ -14,8 +14,8 @@ Implements a `AccountsManager`, which is reponsible for: - Implemented by a `ExternalAccountsManager` - depends on an `InternalAccountProvider` (implemented by `BankAccountProvider`) - depends on an `AccountCloner` (implemented by `RemoteAccountCloner`) - - depends on an `AccountCommitter` (implemented by `RemoteAccountCommitter`) - depends on a `Transwise` + - denepds on a `CommittorServiceExt` that is used for Manual commits - Implements `ensure_accounts` function - Maintains a local cache of accounts already validated and cloned @@ -25,9 +25,6 @@ Implements a `AccountsManager`, which is reponsible for: - `RemoteAccountCloner` - depends on a `Bank` -- `RemoteAccountCommitter` - - depends on an `RpcClient` - # Notes *How does `ensure_accounts` work:* diff --git a/magicblock-accounts/src/accounts_manager.rs b/magicblock-accounts/src/accounts_manager.rs index 32b86f977..4b6cff83f 100644 --- a/magicblock-accounts/src/accounts_manager.rs +++ b/magicblock-accounts/src/accounts_manager.rs @@ -4,52 +4,38 @@ use conjunto_transwise::{ transaction_accounts_extractor::TransactionAccountsExtractorImpl, transaction_accounts_validator::TransactionAccountsValidatorImpl, }; -use magicblock_account_cloner::{CloneOutputMap, RemoteAccountClonerClient}; +use magicblock_account_cloner::RemoteAccountClonerClient; use magicblock_accounts_api::BankAccountProvider; use magicblock_bank::bank::Bank; -use magicblock_transaction_status::TransactionStatusSender; -use solana_rpc_client::nonblocking::rpc_client::RpcClient; -use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair}; +use magicblock_committor_service::{ + service_ext::CommittorServiceExt, CommittorService, +}; use crate::{ - config::AccountsConfig, errors::AccountsResult, - remote_account_committer::RemoteAccountCommitter, - remote_scheduled_commits_processor::RemoteScheduledCommitsProcessor, - utils::try_rpc_cluster_from_cluster, ExternalAccountsManager, + config::AccountsConfig, errors::AccountsResult, ExternalAccountsManager, }; pub type AccountsManager = ExternalAccountsManager< BankAccountProvider, RemoteAccountClonerClient, - RemoteAccountCommitter, TransactionAccountsExtractorImpl, TransactionAccountsValidatorImpl, + CommittorServiceExt, >; impl AccountsManager { pub fn try_new( bank: &Arc, + committor_service: Arc>, remote_account_cloner_client: RemoteAccountClonerClient, - validator_keypair: Keypair, config: AccountsConfig, ) -> AccountsResult { - let remote_cluster = config.remote_cluster; let internal_account_provider = BankAccountProvider::new(bank.clone()); - let rpc_cluster = try_rpc_cluster_from_cluster(&remote_cluster)?; - let rpc_client = RpcClient::new_with_commitment( - rpc_cluster.url().to_string(), - CommitmentConfig::confirmed(), - ); - let account_committer = RemoteAccountCommitter::new( - rpc_client, - validator_keypair, - config.commit_compute_unit_price, - ); Ok(Self { + committor_service, internal_account_provider, account_cloner: remote_account_cloner_client, - account_committer: Arc::new(account_committer), transaction_accounts_extractor: TransactionAccountsExtractorImpl, transaction_accounts_validator: TransactionAccountsValidatorImpl, lifecycle: config.lifecycle, diff --git a/magicblock-accounts/src/errors.rs b/magicblock-accounts/src/errors.rs index 61a3b5a2c..e51e16dae 100644 --- a/magicblock-accounts/src/errors.rs +++ b/magicblock-accounts/src/errors.rs @@ -11,13 +11,13 @@ pub type AccountsResult = std::result::Result; #[derive(Error, Debug)] pub enum AccountsError { - #[error("TranswiseError")] + #[error("TranswiseError: {0}")] TranswiseError(#[from] Box), - #[error("UrlParseError")] + #[error("UrlParseError: {0}")] UrlParseError(#[from] Box), - #[error("TransactionError")] + #[error("TransactionError: {0}")] TransactionError(#[from] Box), #[error("CommittorSerivceError")] @@ -25,6 +25,11 @@ pub enum AccountsError { #[from] Box, ), + #[error("CommittorServiceExtError: {0}")] + CommittorServiceExtError( + #[from] magicblock_committor_service::service_ext::Error, + ), + #[error("TokioOneshotRecvError")] TokioOneshotRecvError(#[from] Box), diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 8fe1bc2e5..e063ed736 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -1,6 +1,9 @@ use std::{ collections::{hash_map::Entry, HashMap}, - sync::{Arc, RwLock}, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, RwLock, + }, time::Duration, vec, }; @@ -16,14 +19,30 @@ use futures_util::future::{try_join, try_join_all}; use log::*; use magicblock_account_cloner::{AccountCloner, AccountClonerOutput}; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::L1MessageCommittor; +use magicblock_committor_service::{ + commit_scheduler::{ + BroadcastedMessageExecutionResult, ExecutionOutputWrapper, + }, + l1_message_executor::ExecutionOutput, + service_ext::L1MessageCommittorExt, + transactions::MAX_PROCESS_PER_TX, + types::{ScheduledL1MessageWrapper, TriggerType}, + utils::ScheduledMessageExt, + L1MessageCommittor, +}; use magicblock_core::magic_program; +use magicblock_program::{ + magic_scheduled_l1_message::{ + CommitType, CommittedAccountV2, MagicL1Message, ScheduledL1Message, + }, + validator::validator_authority_id, +}; use solana_sdk::{ account::{AccountSharedData, ReadableAccount}, hash::Hash, pubkey::Pubkey, signature::Signature, - transaction::SanitizedTransaction, + transaction::{SanitizedTransaction, Transaction}, }; use crate::{ @@ -80,31 +99,31 @@ impl ExternalCommitableAccount { } #[derive(Debug)] -pub struct ExternalAccountsManager +pub struct ExternalAccountsManager where IAP: InternalAccountProvider, ACL: AccountCloner, - ACM: AccountCommitter, TAE: TransactionAccountsExtractor, TAV: TransactionAccountsValidator, + CC: L1MessageCommittorExt, { pub internal_account_provider: IAP, pub account_cloner: ACL, - pub account_committer: Arc, pub transaction_accounts_extractor: TAE, pub transaction_accounts_validator: TAV, + pub committor_service: Arc, pub lifecycle: LifecycleMode, pub external_commitable_accounts: RwLock>, } -impl ExternalAccountsManager +impl ExternalAccountsManager where IAP: InternalAccountProvider, ACL: AccountCloner, - ACM: AccountCommitter, TAE: TransactionAccountsExtractor, TAV: TransactionAccountsValidator, + CC: L1MessageCommittorExt, { pub async fn ensure_accounts( &self, @@ -247,7 +266,9 @@ where /// This will look at the time that passed since the last commit and determine /// which accounts are due to be committed, perform that step for them /// and return the signatures of the transactions that were sent to the cluster. - pub async fn commit_delegated(&self) -> AccountsResult> { + pub async fn commit_delegated( + &self, + ) -> AccountsResult> { let now = get_epoch(); // Find all accounts that are due to be committed let accounts_to_be_committed = self let accounts_to_be_committed = self @@ -269,107 +290,64 @@ where return Ok(vec![]); } - // NOTE: the scheduled commits use the slot at which the commit was scheduled - // However frequent commits run async and could be running before a slot is completed - // Thus they really commit in between two slots instead of at the end of a particular slot. - // Therefore we use the current slot which could result in two commits with the same - // slot. However since we most likely will phase out frequent commits we accept this - // inconsistency for now. - let slot = self.internal_account_provider.get_slot(); - let commit_infos = self - .create_transactions_to_commit_specific_accounts( - accounts_to_be_committed, - slot, - false, - ) + // Convert committees to L1Messages s + let scheduled_l1_messages = + self.create_scheduled_l1_message(accounts_to_be_committed); + + // Commit L1Messages + let results = self + .committor_service + .commit_l1_messages_waiting(scheduled_l1_messages.clone()) .await?; - let sendables = commit_infos - .into_iter() - .flat_map(|x| match x.transaction { - Some(tx) => Some(SendableCommitAccountsPayload { - transaction: tx, - committees: x.committees, - }), - None => None, - }) - .collect::>(); - // NOTE: we ignore the [PendingCommitTransaction::undelegated_accounts] here since for - // scheduled commits we never request undelegation - self.run_transactions_to_commit_specific_accounts(now, sendables) - .await - .map(|pendings| pendings.into_iter().map(|x| x.signature).collect()) + + // Process results + let output = self.process_l1_messages_results( + &now, + results, + &scheduled_l1_messages, + ); + Ok(output) } - async fn create_transactions_to_commit_specific_accounts( + fn process_l1_messages_results( &self, - accounts_to_be_committed: Vec<(Pubkey, Pubkey, Option)>, - slot: u64, - undelegation_request: bool, - ) -> AccountsResult> { - let mut committees = accounts_to_be_committed - .iter() - .filter_map(|(pubkey, owner, committable_account_prev_hash)| { - if let Some(account) = self.internal_account_provider.get_account(pubkey) { - Some((pubkey, owner, committable_account_prev_hash, account)) - } else { - error!( - "Cannot find state for account that needs to be committed '{}' ", - pubkey - ); + now: &Duration, + results: Vec, + scheduled_l1_messages: &[ScheduledL1MessageWrapper], + ) -> Vec { + // Filter failed l1 messages, log failed ones + let outputs = results + .into_iter() + .filter_map(|execution_result| match execution_result { + Ok(value) => Some(value), + Err(err) => { + error!("Failed to send l1 message: {}", err.1); None } }) - .filter(|(pubkey, _, committable_account_prev_hash, acc)| { - let should_commit = committable_account_prev_hash - .map_or(true, |hash| hash_account(acc).ne(&hash)); - if !should_commit { - info!( - "Cannot find state for account that needs to be committed '{}'", - pubkey - ); - } - should_commit - }) - .map(|(pubkey, owner, _, acc)| AccountCommittee { - pubkey: *pubkey, - owner: *owner, - account_data: acc, - slot, - undelegation_requested: undelegation_request, - }) - .collect(); + .map(|output| (output.id, output)) + .collect::>(); - // NOTE: Once we run into issues that the data to be committed in a single - // transaction is too large, we can split these into multiple batches - // That is why we return a Vec of CreateCommitAccountsTransactionResult - let txs = try_join_all(committees.into_iter().map(|commitee| { - self.account_committer - .create_commit_accounts_transaction(vec![commitee]) - })) - .await?; - - Ok(txs) - } - - pub async fn run_transactions_to_commit_specific_accounts( - &self, - now: Duration, - payloads: Vec, - ) -> AccountsResult> { - let pubkeys_with_hashes = payloads + // For successfully committed accounts get their (pubkey, hash) + let pubkeys_with_hashes = scheduled_l1_messages .iter() - .flat_map(|x| { - x.committees.iter().map(|(pubkey, account_shared_data)| { - (*pubkey, hash_account(account_shared_data)) - }) + // Filter out unsuccessful messages + .filter(|message| { + outputs.contains_key(&message.scheduled_l1_message.id) }) - .collect::>(); - - // Commit all transactions - let pending_commits = self - .account_committer - .send_commit_transactions(payloads) - .await?; + // Extract accounts that got committed + .filter_map(|message| { + message.scheduled_l1_message.get_committed_accounts() + }) + .flatten() + // Calculate hash of committed accounts + .map(|committed_account| { + let acc = + AccountSharedData::from(committed_account.account.clone()); + let hash = hash_account(&acc); + (committed_account.pubkey, hash) + }) + .collect::>(); // Mark committed accounts for (pubkey, hash) in pubkeys_with_hashes { @@ -377,7 +355,7 @@ where .external_commitable_accounts .write() .expect( - "RwLock of ExternalAccountsManager.external_commitable_accounts is poisoned", + "RwLock of ExternalAccountsManager.external_commitable_accounts is poisoned", ) .get_mut(&pubkey) { @@ -392,7 +370,78 @@ where } } - Ok(pending_commits) + outputs + .into_iter() + .map(|(_, output)| output.output) + .collect() + } + + fn create_scheduled_l1_message( + &self, + accounts_to_be_committed: Vec<(Pubkey, Pubkey, Option)>, + ) -> Vec { + // NOTE: the scheduled commits use the slot at which the commit was scheduled + // However frequent commits run async and could be running before a slot is completed + // Thus they really commit in between two slots instead of at the end of a particular slot. + // Therefore we use the current slot which could result in two commits with the same + // slot. However since we most likely will phase out frequent commits we accept this + // inconsistency for now. + static MESSAGE_ID: AtomicU64 = AtomicU64::new(u64::MAX - 1); + + let slot = self.internal_account_provider.get_slot(); + let blockhash = self.internal_account_provider.get_blockhash(); + + // Deduce accounts that should be committed + let committees = accounts_to_be_committed + .iter() + .filter_map(|(pubkey, owner, prev_hash)| { + self.internal_account_provider.get_account(pubkey) + .map(|account| (pubkey, owner, prev_hash, account)) + .or_else(|| { + error!("Cannot find state for account that needs to be committed '{}'", pubkey); + None + }) + }) + .filter(|(pubkey, _, prev_hash, acc)| { + prev_hash.map_or(true, |hash| hash_account(acc) != hash) + }) + .map(|(pubkey, owner, _, acc)| AccountCommittee { + pubkey: *pubkey, + owner: *owner, + account_data: acc, + slot, + undelegation_requested: false, + }) + .collect::>(); + + committees + .chunks(MAX_PROCESS_PER_TX as usize) + .into_iter() + .map(|committees| { + let committees = committees + .iter() + .cloned() + .map(|committee| CommittedAccountV2::from(committee)) + .collect(); + ScheduledL1Message { + // isn't important but shall be unique + id: MESSAGE_ID.fetch_sub(1, Ordering::Relaxed), + slot, + blockhash, + action_sent_transaction: Transaction::default(), + payer: validator_authority_id(), + l1_message: MagicL1Message::Commit(CommitType::Standalone( + committees, + )), + } + }) + .map(|scheduled_l1_message| ScheduledL1MessageWrapper { + scheduled_l1_message, + excluded_pubkeys: vec![], + feepayers: vec![], + trigger_type: TriggerType::OffChain, + }) + .collect() } pub fn last_commit(&self, pubkey: &Pubkey) -> Option { diff --git a/magicblock-accounts/src/lib.rs b/magicblock-accounts/src/lib.rs index aef732800..22352c1f2 100644 --- a/magicblock-accounts/src/lib.rs +++ b/magicblock-accounts/src/lib.rs @@ -2,7 +2,6 @@ mod accounts_manager; mod config; pub mod errors; mod external_accounts_manager; -mod remote_account_committer; pub mod remote_scheduled_commits_processor; mod traits; pub mod utils; diff --git a/magicblock-accounts/src/remote_account_committer.rs b/magicblock-accounts/src/remote_account_committer.rs deleted file mode 100644 index d8c10962a..000000000 --- a/magicblock-accounts/src/remote_account_committer.rs +++ /dev/null @@ -1,398 +0,0 @@ -use std::collections::HashSet; - -use async_trait::async_trait; -use dlp::{ - args::CommitStateArgs, - instruction_builder::{commit_state, finalize, undelegate}, - pda::delegation_metadata_pda_from_delegated_account, - state::DelegationMetadata, -}; -use futures_util::future::join_all; -use log::*; -use magicblock_metrics::metrics; -use magicblock_program::{validator, Pubkey}; -use solana_rpc_client::{ - nonblocking::rpc_client::RpcClient, rpc_client::SerializableTransaction, -}; -use solana_rpc_client_api::config::RpcSendTransactionConfig; -use solana_sdk::{ - account::ReadableAccount, clock::MAX_HASH_AGE_IN_SECONDS, - commitment_config::CommitmentConfig, - compute_budget::ComputeBudgetInstruction, instruction::Instruction, - signature::Keypair, signer::Signer, transaction::Transaction, -}; - -use crate::{ - errors::{AccountsError, AccountsResult}, - AccountCommittee, AccountCommitter, CommitAccountsPayload, - CommitAccountsTransaction, PendingCommitTransaction, - SendableCommitAccountsPayload, -}; - -// [solana_sdk::clock::MAX_HASH_AGE_IN_SECONDS] (120secs) is the max time window at which -// a transaction could still land. For us that is excessive and waiting for 30secs -// should be enough. -const MAX_TRANSACTION_CONFIRMATION_SECS: u64 = - MAX_HASH_AGE_IN_SECONDS as u64 / 4; - -// ----------------- -// RemoteAccountCommitter -// ----------------- -pub struct RemoteAccountCommitter { - rpc_client: RpcClient, - committer_authority: Keypair, - compute_unit_price: u64, -} - -impl RemoteAccountCommitter { - pub fn new( - rpc_client: RpcClient, - committer_authority: Keypair, - compute_unit_price: u64, - ) -> Self { - Self { - rpc_client, - committer_authority, - compute_unit_price, - } - } -} - -#[async_trait] -impl AccountCommitter for RemoteAccountCommitter { - async fn create_commit_accounts_transaction( - &self, - committees: Vec, - ) -> AccountsResult { - // Get blockhash once since this is a slow operation - let latest_blockhash = self - .rpc_client - .get_latest_blockhash() - .await - .map_err(|err| { - AccountsError::FailedToGetLatestBlockhash(err.to_string()) - })?; - - let committee_count: u32 = committees - .len() - .try_into() - .map_err(|_| AccountsError::TooManyCommittees(committees.len()))?; - let undelegation_count: u32 = committees - .iter() - .filter(|c| c.undelegation_requested) - .count() - .try_into() - .map_err(|_| AccountsError::TooManyCommittees(committees.len()))?; - let (compute_budget_ix, compute_unit_price_ix) = - self.compute_instructions(committee_count, undelegation_count); - - let mut undelegated_accounts = HashSet::new(); - let mut committed_only_accounts = HashSet::new(); - let mut ixs = vec![compute_budget_ix, compute_unit_price_ix]; - - for AccountCommittee { - pubkey, - owner, - account_data, - slot, - undelegation_requested: undelegation_request, - } in committees.iter() - { - let committer = self.committer_authority.pubkey(); - let commit_args = CommitStateArgs { - slot: *slot, - allow_undelegation: *undelegation_request, - data: account_data.data().to_vec(), - lamports: account_data.lamports(), - }; - let commit_ix = - commit_state(committer, *pubkey, *owner, commit_args); - - let finalize_ix = finalize(committer, *pubkey); - ixs.extend(vec![commit_ix, finalize_ix]); - if *undelegation_request { - let metadata_account = self - .rpc_client - .get_account( - &delegation_metadata_pda_from_delegated_account(pubkey), - ) - .await - .map_err(|err| { - AccountsError::FailedToGetReimbursementAddress( - err.to_string(), - ) - })?; - let metadata = - DelegationMetadata::try_from_bytes_with_discriminator( - &metadata_account.data, - ) - .map_err(|err| { - AccountsError::FailedToGetReimbursementAddress( - err.to_string(), - ) - })?; - let undelegate_ix = undelegate( - validator::validator_authority_id(), - *pubkey, - *owner, - metadata.rent_payer, - ); - ixs.push(undelegate_ix); - undelegated_accounts.insert(*pubkey); - } else { - committed_only_accounts.insert(*pubkey); - } - } - - // For now we always commit all accounts in one transaction, but - // in the future we may split them up into batches to avoid running - // over the max instruction args size - let tx = Transaction::new_signed_with_payer( - &ixs, - Some(&self.committer_authority.pubkey()), - &[&self.committer_authority], - latest_blockhash, - ); - let committees = committees - .into_iter() - .map(|c| (c.pubkey, c.account_data)) - .collect(); - - Ok(CommitAccountsPayload { - transaction: Some(CommitAccountsTransaction { - transaction: tx, - undelegated_accounts, - committed_only_accounts, - }), - committees, - }) - } - - async fn send_commit_transactions( - &self, - payloads: Vec, - ) -> AccountsResult> { - let mut pending_commits = Vec::new(); - for SendableCommitAccountsPayload { - transaction: - CommitAccountsTransaction { - transaction, - committed_only_accounts, - undelegated_accounts, - }, - committees, - } in payloads - { - let pubkeys = committees - .iter() - .map(|(pubkey, _)| *pubkey) - .collect::>(); - let tx_sig = transaction.get_signature(); - - let pubkeys_display = if log_enabled!(log::Level::Debug) { - let pubkeys_display = pubkeys - .iter() - .map(|x| x.to_string()) - .collect::>() - .join(", "); - debug!( - "Committing accounts [{}] sig: {:?} to {}", - pubkeys_display, - tx_sig, - self.rpc_client.url() - ); - Some(pubkeys_display) - } else { - None - }; - - if log_enabled!(log::Level::Debug) - && !undelegated_accounts.is_empty() - { - debug!( - "Requesting to undelegate: {}", - undelegated_accounts - .iter() - .map(|x| x.to_string()) - .collect::>() - .join(", ") - ); - } - - let timer = metrics::account_commit_start(); - let signature = self - .rpc_client - .send_transaction_with_config( - &transaction, - RpcSendTransactionConfig { - skip_preflight: true, - ..Default::default() - }, - ) - .await - .map_err(|err| { - AccountsError::FailedToSendCommitTransaction( - err.to_string(), - undelegated_accounts.clone(), - committed_only_accounts.clone(), - ) - })?; - - if &signature != tx_sig { - error!( - "Transaction Signature mismatch: {:?} != {:?}", - signature, tx_sig - ); - } - debug!( - "Sent commit for [{}] | signature: '{:?}'", - pubkeys_display.unwrap_or_default(), - signature - ); - pending_commits.push(PendingCommitTransaction { - signature, - undelegated_accounts, - committed_only_accounts, - timer, - }); - } - Ok(pending_commits) - } - - async fn confirm_pending_commits( - &self, - pending_commits: Vec, - ) { - let mut futures = Vec::new(); - for pc in pending_commits.into_iter() { - let fut = async move { - let now = std::time::Instant::now(); - loop { - match self - .rpc_client - .confirm_transaction_with_commitment( - &pc.signature, - CommitmentConfig::confirmed(), - ) - .await - { - Ok(res) => { - // The RPC `confirm_transaction_with_commitment` doesn't provide - // the info to distinguish between a not yet confirmed or - // failed transaction. - // Failed transactions should be rare, so it's ok to check - // them over and over until the timeout is reached. - // If we see that happen a lot we can write our custom confirm method - // that makes this more straightforward. - let confirmed_and_succeeded = res.value; - if confirmed_and_succeeded { - update_account_commit_metrics( - &pc.undelegated_accounts, - &pc.committed_only_accounts, - metrics::Outcome::from_success(res.value), - Some(pc.timer), - ); - break; - } else if now.elapsed().as_secs() - > MAX_TRANSACTION_CONFIRMATION_SECS - { - error!( - "Timed out confirming commit-transaction success '{:?}': {:?}. This means that the transaction failed or failed to confirm in time.", - pc.signature, res - ); - update_account_commit_metrics( - &pc.undelegated_accounts, - &pc.committed_only_accounts, - metrics::Outcome::Error, - None, - ); - break; - } else { - tokio::time::sleep( - std::time::Duration::from_millis(50), - ) - .await; - } - } - Err(err) => { - error!( - "Failed to confirm commit transaction '{:?}': {:?}", - pc.signature, err - ); - update_account_commit_metrics( - &pc.undelegated_accounts, - &pc.committed_only_accounts, - metrics::Outcome::Error, - None, - ); - break; - } - } - } - - if log_enabled!(log::Level::Trace) { - trace!( - "Confirmed commit for {:?} in {:?}", - pc.signature, - now.elapsed() - ); - } - }; - futures.push(fut); - } - join_all(futures).await; - } -} - -pub(crate) fn update_account_commit_metrics( - commit_and_undelegate_accounts: &HashSet, - commit_only_accounts: &HashSet, - outcome: metrics::Outcome, - timer: Option, -) { - for pubkey in commit_and_undelegate_accounts { - metrics::inc_account_commit( - metrics::AccountCommit::CommitAndUndelegate { - pubkey: &pubkey.to_string(), - outcome, - }, - ); - } - for pubkey in commit_only_accounts { - metrics::inc_account_commit(metrics::AccountCommit::CommitOnly { - pubkey: &pubkey.to_string(), - outcome, - }); - } - - // The timer is only present if a transaction's success was confirmed - if let Some(timer) = timer { - metrics::account_commit_end(timer); - } -} - -impl RemoteAccountCommitter { - fn compute_instructions( - &self, - committee_count: u32, - undelegation_count: u32, - ) -> (Instruction, Instruction) { - // TODO(thlorenz): We may need to consider account size as well since - // the account is copied which could affect CUs - const BASE_COMPUTE_BUDGET: u32 = 80_000; - const COMPUTE_BUDGET_PER_COMMITTEE: u32 = 45_000; - const COMPUTE_BUDGET_PER_UNDELEGATION: u32 = 70_000; - - let compute_budget = BASE_COMPUTE_BUDGET - + (COMPUTE_BUDGET_PER_COMMITTEE * committee_count) - + (COMPUTE_BUDGET_PER_UNDELEGATION * undelegation_count); - - let compute_budget_ix = - ComputeBudgetInstruction::set_compute_unit_limit(compute_budget); - let compute_unit_price_ix = - ComputeBudgetInstruction::set_compute_unit_price( - self.compute_unit_price, - ); - (compute_budget_ix, compute_unit_price_ix) - } -} diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 237811595..43523555c 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -2,14 +2,14 @@ use std::{collections::HashSet, sync::Arc}; use async_trait::async_trait; use conjunto_transwise::AccountChainSnapshot; -use log::{debug, error}; +use log::{debug, error, info}; use magicblock_account_cloner::{AccountClonerOutput, CloneOutputMap}; use magicblock_bank::bank::Bank; use magicblock_committor_service::{ commit_scheduler::{ BroadcastedMessageExecutionResult, ExecutionOutputWrapper, }, - types::ScheduledL1MessageWrapper, + types::{ScheduledL1MessageWrapper, TriggerType}, utils::ScheduledMessageExt, L1MessageCommittor, }; @@ -73,6 +73,7 @@ impl RemoteScheduledCommitsProcessor { scheduled_l1_message: l1_message, excluded_pubkeys: Vec::new(), feepayers: Vec::new(), + trigger_type: TriggerType::OnChain, }; }; @@ -134,12 +135,9 @@ impl RemoteScheduledCommitsProcessor { /// Retains onlu account that are valid to be commited committed_accounts.retain_mut(|account| { let pubkey = account.pubkey; - let account_chain_snapshot = match self - .cloned_accounts - .read() - .expect(POISONED_RWLOCK_MSG) - .get(&pubkey) - { + let cloned_accounts = + self.cloned_accounts.read().expect(POISONED_RWLOCK_MSG); + let account_chain_snapshot = match cloned_accounts.get(&pubkey) { Some(AccountClonerOutput::Cloned { account_chain_snapshot, .. @@ -168,6 +166,7 @@ impl RemoteScheduledCommitsProcessor { scheduled_l1_message: l1_message, feepayers: processor.feepayers.into_iter().collect(), excluded_pubkeys: processor.excluded_pubkeys.into_iter().collect(), + trigger_type: TriggerType::OnChain, } } @@ -194,6 +193,7 @@ impl RemoteScheduledCommitsProcessor { .await } Err(err) => { + error!("Failed to commit: {:?}", err); todo!() } } @@ -205,19 +205,31 @@ impl RemoteScheduledCommitsProcessor { transaction_status_sender: &TransactionStatusSender, execution_outcome: ExecutionOutputWrapper, ) { - register_scheduled_commit_sent(execution_outcome.sent_commit); - match execute_legacy_transaction( - execution_outcome.action_sent_transaction, - bank, - Some(transaction_status_sender), - ) { - Ok(signature) => debug!( - "Signaled sent commit with internal signature: {:?}", - signature - ), - Err(err) => { - error!("Failed to signal sent commit via transaction: {}", err); + // We don't trigger sent tx for `TriggerType::OffChain` + // TODO: should be removed once crank supported + if matches!(execution_outcome.trigger_type, TriggerType::OnChain) { + register_scheduled_commit_sent(execution_outcome.sent_commit); + match execute_legacy_transaction( + execution_outcome.action_sent_transaction, + bank, + Some(transaction_status_sender), + ) { + Ok(signature) => debug!( + "Signaled sent commit with internal signature: {:?}", + signature + ), + Err(err) => { + error!( + "Failed to signal sent commit via transaction: {}", + err + ); + } } + } else { + info!( + "OffChain triggered L1Message executed: {}", + execution_outcome.sent_commit.message_id + ); } } } diff --git a/magicblock-accounts/src/traits.rs b/magicblock-accounts/src/traits.rs index 444180f83..786443a60 100644 --- a/magicblock-accounts/src/traits.rs +++ b/magicblock-accounts/src/traits.rs @@ -4,16 +4,22 @@ use async_trait::async_trait; use magicblock_accounts_api::InternalAccountProvider; use magicblock_committor_service::L1MessageCommittor; use magicblock_metrics::metrics::HistogramTimer; +use magicblock_program::magic_scheduled_l1_message::{ + CommittedAccountV2, ScheduledL1Message, +}; use solana_rpc_client::rpc_client::SerializableTransaction; use solana_sdk::{ - account::AccountSharedData, pubkey::Pubkey, signature::Signature, + account::{Account, AccountSharedData, ReadableAccount}, + clock::Epoch, + pubkey::Pubkey, + signature::Signature, transaction::Transaction, }; use crate::errors::AccountsResult; #[async_trait] -pub trait ScheduledCommitsProcessor { +pub trait ScheduledCommitsProcessor: Send + Sync + 'static { /// Processes all commits that were scheduled and accepted async fn process(&self) -> AccountsResult<()>; @@ -23,6 +29,8 @@ pub trait ScheduledCommitsProcessor { fn clear_scheduled_commits(&self); } +// TODO(edwin): remove this +#[derive(Clone)] pub struct AccountCommittee { /// The pubkey of the account to be committed. pub pubkey: Pubkey, @@ -38,6 +46,22 @@ pub struct AccountCommittee { pub undelegation_requested: bool, } +impl From for CommittedAccountV2 { + fn from(value: AccountCommittee) -> Self { + CommittedAccountV2 { + pubkey: value.pubkey, + account: Account { + lamports: value.account_data.lamports(), + data: value.account_data.data().to_vec(), + // TODO(edwin): shall take from account_data instead? + owner: value.owner, + executable: value.account_data.executable(), + rent_epoch: value.account_data.rent_epoch(), + }, + } + } +} + #[derive(Debug)] pub struct CommitAccountsTransaction { /// The transaction that is running on chain to commit and possibly undelegate diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 39b9ddf23..c977a8aff 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -41,7 +41,8 @@ use magicblock_bank::{ transaction_logs::TransactionLogCollectorFilter, }; use magicblock_committor_service::{ - config::ChainConfig, CommittorService, ComputeBudgetConfig, + config::ChainConfig, service_ext::CommittorServiceExt, CommittorService, + ComputeBudgetConfig, }; use magicblock_config::{EphemeralConfig, LifecycleMode, ProgramConfig}; use magicblock_geyser_plugin::rpc::GeyserRpcService; @@ -326,13 +327,8 @@ impl MagicValidator { ), }, )?); - - let remote_scheduled_commits_processor = - Arc::new(RemoteScheduledCommitsProcessor::new( - bank.clone(), - committor_service.clone(), - transaction_status_sender.clone(), - )); + let committor_service_ext = + Arc::new(CommittorServiceExt::new(committor_service.clone())); let remote_account_cloner_worker = RemoteAccountClonerWorker::new( bank_account_provider, @@ -353,12 +349,18 @@ impl MagicValidator { config.validator_config.accounts.max_monitored_accounts, ); + let remote_scheduled_commits_processor = + Arc::new(RemoteScheduledCommitsProcessor::new( + bank.clone(), + remote_account_cloner_worker.get_last_clone_output(), + committor_service.clone(), + transaction_status_sender.clone(), + )); + let accounts_manager = Self::init_accounts_manager( &bank, - &remote_account_cloner_worker.get_last_clone_output(), + &committor_service_ext, RemoteAccountClonerClient::new(&remote_account_cloner_worker), - transaction_status_sender.clone(), - &identity_keypair, &config.validator_config, ); @@ -446,10 +448,8 @@ impl MagicValidator { fn init_accounts_manager( bank: &Arc, - cloned_accounts: &CloneOutputMap, + commitor_service: &Arc>, remote_account_cloner_client: RemoteAccountClonerClient, - transaction_status_sender: TransactionStatusSender, - validator_keypair: &Keypair, config: &EphemeralConfig, ) -> Arc { let accounts_config = try_convert_accounts_config(&config.accounts) @@ -458,15 +458,8 @@ impl MagicValidator { ); let accounts_manager = AccountsManager::try_new( bank, - cloned_accounts, + commitor_service.clone(), remote_account_cloner_client, - transaction_status_sender, - // NOTE: we could avoid passing a copy of the keypair here if we instead pass - // something akin to a ValidatorTransactionSigner that gets it via the [validator_authority] - // method from the [magicblock_program] module, forgetting it immediately after. - // That way we would at least hold it in memory for a long time only in one place and in all other - // places only temporarily - validator_keypair.insecure_clone(), accounts_config, ) .expect("Failed to create accounts manager"); diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 17e693203..07837ba09 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -30,7 +30,7 @@ use crate::{ transaction_preperator::transaction_preparator::{ TransactionPreparator, TransactionPreparatorV1, }, - types::ScheduledL1MessageWrapper, + types::{ScheduledL1MessageWrapper, TriggerType}, utils::ScheduledMessageExt, ComputeBudgetConfig, }; @@ -40,14 +40,17 @@ const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; // TODO(edwin): rename #[derive(Clone)] pub struct ExecutionOutputWrapper { + pub id: u64, pub output: ExecutionOutput, pub action_sent_transaction: Transaction, pub sent_commit: SentCommit, + pub trigger_type: TriggerType, } -pub type BroadcastedMessageExecutionResult = MessageExecutorResult< - ExecutionOutputWrapper, - Arc, ->; + +pub type BroadcastedError = (u64, Arc); + +pub type BroadcastedMessageExecutionResult = + MessageExecutorResult; /// Struct that exposes only `subscribe` method of `broadcast::Sender` for better isolation pub struct ResultSubscriber( @@ -267,7 +270,7 @@ where .map(|raw_result| { Self::map_execution_outcome(&l1_message, raw_result) }) - .map_err(|err| Arc::new(err)); + .map_err(|err| (l1_message.scheduled_l1_message.id, Arc::new(err))); // Broadcast result to subscribers if let Err(err) = result_sender.send(result) { @@ -294,6 +297,7 @@ where scheduled_l1_message, feepayers, excluded_pubkeys, + trigger_type, } = l1_message; let included_pubkeys = if let Some(included_pubkeys) = scheduled_l1_message.get_committed_pubkeys() @@ -320,10 +324,12 @@ where }; ExecutionOutputWrapper { + id: scheduled_l1_message.id, output: raw_outcome, action_sent_transaction: scheduled_l1_message .action_sent_transaction .clone(), + trigger_type: *trigger_type, sent_commit, } } @@ -347,43 +353,3 @@ impl L1MessageExecutorFactory { ) } } - -// Worker schedule: -// We have a pool of workers -// We are ready to accept message -// When we have a worker available to process it - -/// 1. L1Messages arrive -/// 2. We call to schedule their execution -/// 3. Once landed we need to execute a sent tx on L2s - -/// There's a part that schedules and sends TXs -/// L1MessageExecutor - runs Preparator + executes txs -/// Scheduler/MessageExecutionManager - Schedules execution of L1MessageExecutor -/// Committor - gets results and persists them -/// RemoteScheduledCommitsProcessor - just gets results and writes them to db -/// -fn useless() {} - -// Committor needs to get result of execution & persist it -// Committor needs to send results to Remote - -// Could committor retry or handle failed execution somehow? -// Should that be a business of persister? -// - -// Committor is used to manager TableMania -// On commits we fetch the state - -// Does Remote care about readiness of particular task? No -// It just runs TXs where he commits results to l2. -// TODO(edwin): Remote takes single channel for result - -// Does Committor care about readiness of particular task? -// It kinda doesn't -// Is it correct for MessageExecutionManager to be just a Stream? -// - -// TODO(edwin): TransactionExecutor doesn't care about channels and shit -// It gets message, sends, retries & gives back result -fn useless2() {} diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 4372ebe9e..27cf64484 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -10,7 +10,8 @@ mod finalize; pub mod persist; mod pubkeys_provider; mod service; -mod transactions; +pub mod service_ext; +pub mod transactions; pub mod types; mod undelegate; @@ -22,7 +23,8 @@ pub mod l1_message_executor; pub mod stubs; pub mod tasks; pub mod transaction_preperator; -pub mod utils; // TODO(edwin) pub(crate) +pub mod utils; +// TODO(edwin) pub(crate) pub use commit_info::CommitInfo; pub use compute_budget::ComputeBudgetConfig; diff --git a/magicblock-committor-service/src/service_ext.rs b/magicblock-committor-service/src/service_ext.rs new file mode 100644 index 000000000..c2fe69443 --- /dev/null +++ b/magicblock-committor-service/src/service_ext.rs @@ -0,0 +1,178 @@ +use std::{ + collections::{hash_map::Entry, HashMap}, + ops::Deref, + sync::{Arc, Mutex}, +}; + +use async_trait::async_trait; +use futures_util::future::join_all; +use log::error; +use solana_pubkey::Pubkey; +use tokio::sync::{broadcast, oneshot, oneshot::error::RecvError}; + +use crate::{ + commit_scheduler::BroadcastedMessageExecutionResult, + error::CommittorServiceResult, + persist::{CommitStatusRow, MessageSignatures}, + types::ScheduledL1MessageWrapper, + L1MessageCommittor, +}; + +const POISONED_MUTEX_MSG: &str = + "CommittorServiceExt pending messages mutex poisoned!"; + +#[async_trait] +pub trait L1MessageCommittorExt: L1MessageCommittor { + /// Schedules l1 messages and waits for their results + async fn commit_l1_messages_waiting( + &self, + l1_messages: Vec, + ) -> L1MessageCommitorExtResult>; +} + +type MessageResultListener = oneshot::Sender; +pub struct CommittorServiceExt { + inner: Arc, + pending_messages: Arc>>, +} + +impl CommittorServiceExt { + pub fn new(inner: Arc) -> Self { + let pending_messages = Arc::new(Mutex::new(HashMap::new())); + let results_subscription = inner.subscribe_for_results(); + tokio::spawn(Self::dispatcher( + results_subscription, + pending_messages.clone(), + )); + + Self { + inner, + pending_messages, + } + } + + async fn dispatcher( + results_subscription: oneshot::Receiver< + broadcast::Receiver, + >, + pending_message: Arc>>, + ) { + let mut results_subscription = results_subscription.await.unwrap(); + while let Ok(execution_result) = results_subscription.recv().await { + let id = match &execution_result { + Ok(value) => value.id, + Err(err) => err.0, + }; + + let sender = if let Some(sender) = pending_message + .lock() + .expect(POISONED_MUTEX_MSG) + .remove(&id) + { + sender + } else { + continue; + }; + + if let Err(_) = sender.send(execution_result) { + error!("Failed to send L1Message execution result to listener"); + } + } + } +} + +#[async_trait] +impl L1MessageCommittorExt for CommittorServiceExt { + async fn commit_l1_messages_waiting( + &self, + l1_messages: Vec, + ) -> L1MessageCommitorExtResult> + { + let mut receivers = { + let mut pending_messages = + self.pending_messages.lock().expect(POISONED_MUTEX_MSG); + + l1_messages + .iter() + .map(|l1_message| { + let (sender, receiver) = oneshot::channel(); + match pending_messages + .entry(l1_message.scheduled_l1_message.id) + { + Entry::Vacant(vacant) => { + vacant.insert(sender); + Ok(receiver) + } + Entry::Occupied(_) => { + Err(Error::RepeatingMessageError( + l1_message.scheduled_l1_message.id, + )) + } + } + }) + .collect::, _>>()? + }; + + let results = join_all(receivers.into_iter()) + .await + .into_iter() + .collect::, RecvError>>()?; + + Ok(results) + } +} + +impl L1MessageCommittor for CommittorServiceExt { + fn reserve_pubkeys_for_committee( + &self, + committee: Pubkey, + owner: Pubkey, + ) -> oneshot::Receiver> { + self.inner.reserve_pubkeys_for_committee(committee, owner) + } + + fn commit_l1_messages(&self, l1_messages: Vec) { + self.inner.commit_l1_messages(l1_messages) + } + + fn subscribe_for_results( + &self, + ) -> oneshot::Receiver> + { + self.inner.subscribe_for_results() + } + + fn get_commit_statuses( + &self, + message_id: u64, + ) -> oneshot::Receiver>> { + self.inner.get_commit_statuses(message_id) + } + + fn get_commit_signatures( + &self, + commit_id: u64, + pubkey: Pubkey, + ) -> oneshot::Receiver>> + { + self.inner.get_commit_signatures(commit_id, pubkey) + } +} + +impl Deref for CommittorServiceExt { + type Target = Arc; + + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("Attempt to schedule already scheduled message id: {0}")] + RepeatingMessageError(u64), + #[error("RecvError: {0}")] + RecvError(#[from] RecvError), +} + +pub type L1MessageCommitorExtResult = Result; diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs index 199119347..e4fc52a48 100644 --- a/magicblock-committor-service/src/transactions.rs +++ b/magicblock-committor-service/src/transactions.rs @@ -25,54 +25,54 @@ pub(crate) const MAX_ENCODED_TRANSACTION_SIZE: usize = 1644; /// How many process and commit buffer instructions fit into a single transaction #[allow(unused)] // serves as documentation as well -pub(crate) const MAX_PROCESS_PER_TX: u8 = 3; +pub const MAX_PROCESS_PER_TX: u8 = 3; /// How many process and commit buffer instructions fit into a single transaction /// when using address lookup tables but not including the buffer account in the /// lookup table #[allow(unused)] // serves as documentation as well -pub(crate) const MAX_PROCESS_PER_TX_USING_LOOKUP: u8 = 12; +pub const MAX_PROCESS_PER_TX_USING_LOOKUP: u8 = 12; /// How many close buffer instructions fit into a single transaction #[allow(unused)] // serves as documentation as well -pub(crate) const MAX_CLOSE_PER_TX: u8 = 7; +pub const MAX_CLOSE_PER_TX: u8 = 7; /// How many close buffer instructions fit into a single transaction /// when using address lookup tables but not including the buffer account /// nor chunk account in the lookup table #[allow(unused)] // serves as documentation as well -pub(crate) const MAX_CLOSE_PER_TX_USING_LOOKUP: u8 = 7; +pub const MAX_CLOSE_PER_TX_USING_LOOKUP: u8 = 7; /// How many process and commit buffer instructions combined with close buffer instructions /// fit into a single transaction #[allow(unused)] // serves as documentation as well -pub(crate) const MAX_PROCESS_AND_CLOSE_PER_TX: u8 = 2; +pub const MAX_PROCESS_AND_CLOSE_PER_TX: u8 = 2; /// How many process and commit buffer instructions combined with /// close buffer instructions fit into a single transaction when /// using lookup tables but not including the buffer account #[allow(unused)] // serves as documentation as well -pub(crate) const MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP: u8 = 4; +pub const MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP: u8 = 4; /// How many finalize instructions fit into a single transaction #[allow(unused)] // serves as documentation as well -pub(crate) const MAX_FINALIZE_PER_TX: u8 = 5; +pub const MAX_FINALIZE_PER_TX: u8 = 5; /// How many finalize instructions fit into a single transaction /// when using address lookup tables #[allow(unused)] // serves as documentation as well -pub(crate) const MAX_FINALIZE_PER_TX_USING_LOOKUP: u8 = 48; +pub const MAX_FINALIZE_PER_TX_USING_LOOKUP: u8 = 48; /// How many undelegate instructions fit into a single transaction /// NOTE: that we assume the rent reimbursement account to be the delegated account #[allow(unused)] // serves as documentation as well -pub(crate) const MAX_UNDELEGATE_PER_TX: u8 = 3; +pub const MAX_UNDELEGATE_PER_TX: u8 = 3; /// How many undelegate instructions fit into a single transaction /// when using address lookup tables /// NOTE: that we assume the rent reimbursement account to be the delegated account #[allow(unused)] // serves as documentation as well -pub(crate) const MAX_UNDELEGATE_PER_TX_USING_LOOKUP: u8 = 16; +pub const MAX_UNDELEGATE_PER_TX_USING_LOOKUP: u8 = 16; // Allows us to run undelegate instructions without rechunking them since we know // that we didn't process more than we also can undelegate diff --git a/magicblock-committor-service/src/types.rs b/magicblock-committor-service/src/types.rs index 203a09d94..849140899 100644 --- a/magicblock-committor-service/src/types.rs +++ b/magicblock-committor-service/src/types.rs @@ -60,9 +60,18 @@ impl fmt::Display for InstructionsForCommitable { } } +// TODO: should be removed once cranks are supported +// Ideally even now OffChain/"Manual" commits should be triggered via Tx +#[derive(Clone, Copy, Debug)] +pub enum TriggerType { + OnChain, + OffChain, +} + #[derive(Clone, Debug)] pub struct ScheduledL1MessageWrapper { pub scheduled_l1_message: ScheduledL1Message, pub feepayers: Vec, pub excluded_pubkeys: Vec, + pub trigger_type: TriggerType, } From d43a19cef1d05c1fef4b8334d49b7bf4812eae0c Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 25 Jul 2025 14:59:50 +0900 Subject: [PATCH 116/199] feat: added & fixed persistor tests --- Cargo.lock | 1 + magicblock-committor-service/CHANGES.md | 5 +- magicblock-committor-service/Cargo.toml | 1 + .../src/commit_scheduler.rs | 1 - .../commit_scheduler_worker.rs | 4 +- .../src/commit_scheduler/db.rs | 1 - .../src/l1_message_executor.rs | 7 +- .../src/persist/commit_persister.rs | 257 +++++++--- .../src/persist/db.rs | 470 +++++++++--------- magicblock-committor-service/src/service.rs | 1 - .../src/service_ext.rs | 2 +- .../src/transactions.rs | 24 +- test-integration/Cargo.lock | 1 + 13 files changed, 425 insertions(+), 350 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c77c224cc..a81dfdea2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3834,6 +3834,7 @@ dependencies = [ "solana-sdk", "solana-transaction-status-client-types", "static_assertions", + "tempfile", "thiserror 1.0.69", "tokio", "tokio-util 0.7.13", diff --git a/magicblock-committor-service/CHANGES.md b/magicblock-committor-service/CHANGES.md index 114e68bcd..ffb89c253 100644 --- a/magicblock-committor-service/CHANGES.md +++ b/magicblock-committor-service/CHANGES.md @@ -1,3 +1,6 @@ - Persister changed from reqid & bundle_id format to message_id. Meaning row created per message. A particular Row tracking lifespan of Intent - Persister will be passed along into Executors & Scheduler for them to update Intent statuses during execution -- No notion of bundles anymore, we represent things by Intent id \ No newline at end of file +- No notion of bundles anymore, we represent things by Intent id +- AccountsManager doesn't use custom `AccountCommitter` for periodic commits of accounts but instead uses CommittorService +- RemoteScheduledCommitsProcessor extracted from AccountsManager since has nothing to do with it +- \ No newline at end of file diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index dc42fee95..724274395 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -40,6 +40,7 @@ static_assertions = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true } tokio-util = { workspace = true } +tempfile = { workspace = true } [dev-dependencies] env_logger = { workspace = true } diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index c94659934..c37081537 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -9,7 +9,6 @@ use std::sync::Arc; pub use commit_scheduler_worker::{ BroadcastedMessageExecutionResult, ExecutionOutputWrapper, }; -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; use tokio::sync::{broadcast, mpsc, mpsc::error::TrySendError}; diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 07837ba09..ade27b4ea 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -4,9 +4,7 @@ use std::{ }; use log::{error, info, trace, warn}; -use magicblock_program::{ - magic_scheduled_l1_message::ScheduledL1Message, FeePayerAccount, SentCommit, -}; +use magicblock_program::SentCommit; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; diff --git a/magicblock-committor-service/src/commit_scheduler/db.rs b/magicblock-committor-service/src/commit_scheduler/db.rs index 626377cde..1a232defa 100644 --- a/magicblock-committor-service/src/commit_scheduler/db.rs +++ b/magicblock-committor-service/src/commit_scheduler/db.rs @@ -2,7 +2,6 @@ use std::{collections::VecDeque, sync::Mutex}; /// DB for storing messages that overflow committor channel use async_trait::async_trait; -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use crate::types::ScheduledL1MessageWrapper; diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/l1_message_executor.rs index 9c2cbf51f..6673da8a4 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/l1_message_executor.rs @@ -1,9 +1,9 @@ -use std::{collections::HashMap, sync::Arc}; +use std::collections::HashMap; use log::warn; use magicblock_program::{ magic_scheduled_l1_message::ScheduledL1Message, - validator::validator_authority, SentCommit, + validator::validator_authority, }; use magicblock_rpc_client::{ MagicBlockRpcClientError, MagicBlockSendTransactionConfig, @@ -15,7 +15,7 @@ use solana_sdk::{ message::VersionedMessage, signature::{Keypair, Signature}, signer::{Signer, SignerError}, - transaction::{Transaction, VersionedTransaction}, + transaction::VersionedTransaction, }; use crate::{ @@ -23,7 +23,6 @@ use crate::{ transaction_preperator::transaction_preparator::{ TransactionPreparator, TransactionPreparatorV1, }, - types::ScheduledL1MessageWrapper, utils::{persist_status_update, persist_status_update_set}, ComputeBudgetConfig, }; diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index e62d50c1a..165370d0c 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -255,107 +255,208 @@ impl L1MessagesPersisterIface for L1MessagePersister { #[cfg(test)] mod tests { - use magicblock_committor_program::ChangedAccount; - use solana_pubkey::Pubkey; - use solana_sdk::signature::Signature; + use magicblock_program::magic_scheduled_l1_message::{ + CommitType, CommittedAccountV2, MagicL1Message, + }; + use solana_sdk::{ + account::Account, hash::Hash, pubkey::Pubkey, signature::Signature, + transaction::Transaction, + }; + use tempfile::NamedTempFile; use super::*; - use crate::persist::{CommitStatusSignatures, CommitStrategy}; + use crate::persist::{db, types, CommitStatusSignatures}; - #[test] - fn test_start_changeset_and_update_status() { - let mut persister = L1MessagePersister::try_new(":memory:").unwrap(); + fn create_test_persister() -> (L1MessagePersister, NamedTempFile) { + let temp_file = NamedTempFile::new().unwrap(); + let persister = L1MessagePersister::try_new(temp_file.path()).unwrap(); + (persister, temp_file) + } - // Create a test changeset - let mut changeset = Changeset { - slot: 100, - ..Default::default() + fn create_test_message(id: u64) -> ScheduledL1Message { + let account1 = Account { + lamports: 1000, + owner: Pubkey::new_unique(), + data: vec![], + executable: false, + rent_epoch: 0, + }; + let account2 = Account { + lamports: 2000, + owner: Pubkey::new_unique(), + data: vec![1, 2, 3], + executable: false, + rent_epoch: 0, }; - let pubkey1 = Pubkey::new_unique(); - let pubkey2 = Pubkey::new_unique(); - let owner = Pubkey::new_unique(); - - // Add an empty account - changeset.add( - pubkey1, - ChangedAccount::Full { - lamports: 1000, - owner, - data: vec![], - bundle_id: 1, - }, - ); + ScheduledL1Message { + id, + slot: 100, + blockhash: Hash::new_unique(), + action_sent_transaction: Transaction::default(), + payer: Pubkey::new_unique(), + l1_message: MagicL1Message::Commit(CommitType::Standalone(vec![ + CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: account1, + }, + CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: account2, + }, + ])), + } + } - // Add a data account - changeset.add( - pubkey2, - ChangedAccount::Full { - lamports: 2000, - owner, - data: vec![1, 2, 3, 4, 5], - bundle_id: 42, - }, + #[test] + fn test_create_commit_rows() { + let message = create_test_message(1); + let rows = L1MessagePersister::create_commit_rows(&message); + + assert_eq!(rows.len(), 2); + + let empty_account = rows.iter().find(|r| r.data.is_none()).unwrap(); + assert_eq!(empty_account.commit_type, types::CommitType::EmptyAccount); + assert_eq!(empty_account.lamports, 1000); + + let data_account = rows.iter().find(|r| r.data.is_some()).unwrap(); + assert_eq!(data_account.commit_type, types::CommitType::DataAccount); + assert_eq!(data_account.lamports, 2000); + assert_eq!(data_account.data, Some(vec![1, 2, 3])); + } + + #[test] + fn test_start_l1_message() { + let (persister, _temp_file) = create_test_persister(); + let message = create_test_message(1); + + persister.start_l1_message(&message).unwrap(); + + let expected_statuses = + L1MessagePersister::create_commit_rows(&message); + let statuses = persister.get_commit_statuses_by_message(1).unwrap(); + + assert_eq!(statuses.len(), 2); + assert_eq!(expected_statuses[0], statuses[0]); + assert_eq!(expected_statuses[1], statuses[1]); + } + + #[test] + fn test_start_l1_messages() { + let (persister, _temp_file) = create_test_persister(); + let message1 = create_test_message(1); + let message2 = create_test_message(2); + + persister.start_l1_messages(&[message1, message2]).unwrap(); + + let statuses1 = persister.get_commit_statuses_by_message(1).unwrap(); + let statuses2 = persister.get_commit_statuses_by_message(2).unwrap(); + assert_eq!(statuses1.len(), 2); + assert_eq!(statuses2.len(), 2); + } + + #[test] + fn test_update_status() { + let (persister, _temp_file) = create_test_persister(); + let message = create_test_message(1); + persister.start_l1_message(&message).unwrap(); + + let pubkey = message.get_committed_pubkeys().unwrap()[0]; + + // Update by message + persister + .update_status_by_message(1, &pubkey, CommitStatus::Pending) + .unwrap(); + + let updated = persister + .get_commit_status_by_message(1, &pubkey) + .unwrap() + .unwrap(); + assert_eq!(updated.commit_status, CommitStatus::Pending); + + // Set commit ID and update by commit + persister.set_commit_id(1, &pubkey, 100).unwrap(); + persister + .update_status_by_commit( + 100, + &pubkey, + CommitStatus::BufferAndChunkInitialized(100), + ) + .unwrap(); + + let updated = persister + .get_commit_status_by_message(1, &pubkey) + .unwrap() + .unwrap(); + assert_eq!( + updated.commit_status, + CommitStatus::BufferAndChunkInitialized(100) ); + } - changeset.request_undelegation(pubkey1); + #[test] + fn test_set_commit_strategy() { + let (persister, _temp_file) = create_test_persister(); + let message = create_test_message(1); + persister.start_l1_message(&message).unwrap(); + + let pubkey = message.get_committed_pubkeys().unwrap()[0]; + persister.set_commit_id(1, &pubkey, 100).unwrap(); - // Start tracking the changeset - let blockhash = Hash::new_unique(); - let reqid = persister - .start_l1_messages(&changeset, blockhash, true) + persister + .set_commit_strategy(100, &pubkey, CommitStrategy::Args) .unwrap(); - // Verify the rows were inserted correctly - let rows = persister - .commits_db - .get_commit_statuses_by_reqid(&reqid) + let updated = persister + .get_commit_status_by_message(1, &pubkey) + .unwrap() .unwrap(); - assert_eq!(rows.len(), 2); + assert_eq!(updated.commit_strategy, CommitStrategy::Args); + } - let empty_account_row = - rows.iter().find(|row| row.pubkey == pubkey1).unwrap(); - assert_eq!(empty_account_row.commit_type, CommitType::EmptyAccount); - assert!(empty_account_row.undelegate); - assert_eq!(empty_account_row.data, None); - assert_eq!(empty_account_row.commit_status, CommitStatus::Pending); - assert_eq!(empty_account_row.retries_count, 0); - - let data_account_row = - rows.iter().find(|row| row.pubkey == pubkey2).unwrap(); - assert_eq!(data_account_row.commit_type, CommitType::DataAccount); - assert!(!data_account_row.undelegate); - assert_eq!(data_account_row.data, Some(vec![1, 2, 3, 4, 5])); - assert_eq!(data_account_row.commit_status, CommitStatus::Pending); - - // Update status and verify commit status and the signatures - let process_signature = Signature::new_unique(); - let finalize_signature = Some(Signature::new_unique()); - let new_status = CommitStatus::FailedFinalize(( - 1, - CommitStrategy::Args, + #[test] + fn test_get_signatures() { + let (persister, _temp_file) = create_test_persister(); + let message = create_test_message(1); + persister.start_l1_message(&message).unwrap(); + + let statuses = persister.get_commit_statuses_by_message(1).unwrap(); + let pubkey = statuses[0].pubkey; + persister.set_commit_id(1, &pubkey, 100).unwrap(); + + let process_sig = Signature::new_unique(); + let finalize_sig = Signature::new_unique(); + let status = CommitStatus::Succeeded(( + 100, CommitStatusSignatures { - process_signature, - finalize_signature, - undelegate_signature: None, + process_signature: process_sig, + finalize_signature: Some(finalize_sig), }, )); + persister - .update_status_by_message(&reqid, &pubkey1, new_status.clone()) + .update_status_by_commit(100, &pubkey, status) .unwrap(); - let updated_row = persister - .get_commit_status_by_message(&reqid, &pubkey1) + let sigs = persister + .get_signatures_by_commit(100, &pubkey) .unwrap() .unwrap(); + assert_eq!(sigs.processed_signature, process_sig); + assert_eq!(sigs.finalized_signature, Some(finalize_sig)); + } - assert_eq!(updated_row.commit_status, new_status); + #[test] + fn test_empty_accounts_not_persisted() { + let (persister, _temp_file) = create_test_persister(); + let message = ScheduledL1Message { + l1_message: MagicL1Message::L1Actions(vec![]), // No committed accounts + ..create_test_message(1) + }; - let signatures = persister - .get_signatures_by_commit(new_status.bundle_id().unwrap()) - .unwrap() - .unwrap(); - assert_eq!(signatures.processed_signature, process_signature); - assert_eq!(signatures.finalized_signature, finalize_signature); + persister.start_l1_message(&message).unwrap(); + + let statuses = persister.get_commit_statuses_by_message(1).unwrap(); + assert_eq!(statuses.len(), 0); // No rows should be persisted } } diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 3c25f0098..800a6c597 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -1,6 +1,6 @@ use std::{fmt, path::Path, str::FromStr}; -use rusqlite::{params, Connection, Result, Transaction}; +use rusqlite::{params, Connection, OptionalExtension, Result, Transaction}; use solana_pubkey::Pubkey; use solana_sdk::{clock::Slot, hash::Hash, signature::Signature}; @@ -105,44 +105,44 @@ impl fmt::Display for CommitStatusRow { } const ALL_COMMIT_STATUS_COLUMNS: &str = " - message_id, // 1 - pubkey, // 2 - commit_id, // 3 - delegated_account_owner, // 4 - slot, // 5 - ephemeral_blockhash, // 6 - undelegate, // 7 - lamports, // 8 - data, // 9 - commit_type, // 10 - created_at, // 11 - commit_strategy, // 12 - commit_status, // 13 - processed_signature, // 14 - finalized_signature, // 15 - last_retried_at, // 16 - retries_count // 17 + message_id, + pubkey, + commit_id, + delegated_account_owner, + slot, + ephemeral_blockhash, + undelegate, + lamports, + data, + commit_type, + created_at, + commit_strategy, + commit_status, + processed_signature, + finalized_signature, + last_retried_at, + retries_count "; const SELECT_ALL_COMMIT_STATUS_COLUMNS: &str = r#" SELECT - message_id, // 1 - pubkey, // 2 - commit_id, // 3 - delegated_account_owner, // 4 - slot, // 5 - ephemeral_blockhash, // 6 - undelegate, // 7 - lamports, // 8 - data, // 9 - commit_type, // 10 - created_at, // 11 - commit_strategy, // 12 - commit_status, // 13 - processed_signature, // 14 - finalized_signature, // 15 - last_retried_at, // 16 - retries_count // 17 + message_id, + pubkey, + commit_id, + delegated_account_owner, + slot, + ephemeral_blockhash, + undelegate, + lamports, + data, + commit_type, + created_at, + commit_strategy, + commit_status, + processed_signature, + finalized_signature, + last_retried_at, + retries_count FROM commit_status "#; @@ -179,13 +179,12 @@ impl CommittsDb { SET commit_status = ?1, processed_signature = ?2, - finalized_signature = ?3, + finalized_signature = ?3 WHERE pubkey = ?4 AND message_id = ?5"; let tx = self.conn.transaction()?; - let stmt = &mut tx.prepare(query)?; - stmt.execute(params![ + tx.prepare(query)?.execute(params![ status.as_str(), status.signatures().map(|s| s.process_signature.to_string()), status @@ -195,6 +194,7 @@ impl CommittsDb { pubkey.to_string(), message_id ])?; + tx.commit()?; Ok(()) } @@ -209,13 +209,12 @@ impl CommittsDb { SET commit_status = ?1, processed_signature = ?2, - finalized_signature = ?3, + finalized_signature = ?3 WHERE pubkey = ?4 AND commit_id = ?5"; let tx = self.conn.transaction()?; - let stmt = &mut tx.prepare(query)?; - stmt.execute(params![ + tx.prepare(query)?.execute(params![ status.as_str(), status.signatures().map(|s| s.process_signature.to_string()), status @@ -225,6 +224,7 @@ impl CommittsDb { pubkey.to_string(), commit_id ])?; + tx.commit()?; Ok(()) } @@ -237,13 +237,17 @@ impl CommittsDb { ) -> CommitPersistResult<()> { let query = "UPDATE commit_status SET - commit_strategy = ?1, + commit_strategy = ?1 WHERE pubkey = ?2 AND commit_id = ?3"; let tx = self.conn.transaction()?; - let stmt = &mut tx.prepare(query)?; - stmt.execute(params![value.as_str(), pubkey.to_string(), commit_id])?; + tx.prepare(query)?.execute(params![ + value.as_str(), + pubkey.to_string(), + commit_id + ])?; + tx.commit()?; Ok(()) } @@ -255,14 +259,19 @@ impl CommittsDb { commit_id: u64, ) -> CommitPersistResult<()> { let query = "UPDATE commit_status - SET - commit_id = ?1, - WHERE - pubkey = ?2 AND message_id = ?3"; + SET + commit_id = ?1 + WHERE + pubkey = ?2 AND message_id = ?3"; + let tx = self.conn.transaction()?; - let stmt = &mut tx.prepare(query)?; - stmt.execute(params![commit_id, pubkey.to_string(), message_id])?; + tx.prepare(query)?.execute(params![ + commit_id, + pubkey.to_string(), + message_id + ])?; + tx.commit()?; Ok(()) } @@ -291,10 +300,11 @@ impl CommittsDb { finalized_signature TEXT, last_retried_at INTEGER NOT NULL, retries_count INTEGER NOT NULL, - PRIMARY KEY (message_id, pubkey) + PRIMARY KEY (message_id, commit_id, pubkey) ); CREATE INDEX IF NOT EXISTS idx_commits_pubkey ON commit_status (pubkey); CREATE INDEX IF NOT EXISTS idx_commits_message_id ON commit_status (message_id); + CREATE INDEX IF NOT EXISTS idx_commits_commit_id ON commit_status (commit_id); COMMIT;", ) { Ok(_) => Ok(()), @@ -418,11 +428,12 @@ impl CommittsDb { commit_id: u64, pubkey: &Pubkey, ) -> CommitPersistResult> { - let query = "SELECT - processed_signature, finalized_signature, created_at - FROM commit_status + let query = " + SELECT + processed_signature, finalized_signature, created_at + FROM commit_status WHERE commit_id = ?1 AND pubkey = ?2 - LIMIT 1"; + LIMIT 1"; let mut stmt = self.conn.prepare(&query)?; let mut rows = stmt.query(params![commit_id, pubkey.to_string()])?; @@ -542,11 +553,11 @@ fn extract_committor_row( }; let last_retried_at: u64 = { - let last_retried_at: i64 = row.get(16)?; + let last_retried_at: i64 = row.get(15)?; i64_into_u64(last_retried_at) }; let retries_count: u16 = { - let retries_count: i64 = row.get(17)?; + let retries_count: i64 = row.get(16)?; retries_count.try_into().unwrap_or_default() }; @@ -570,221 +581,192 @@ fn extract_committor_row( } #[cfg(test)] -mod test { +mod tests { use super::*; + use solana_sdk::{signature::Signature, hash::Hash}; + use tempfile::NamedTempFile; - fn setup_db() -> CommittsDb { - let db = CommittsDb::new(":memory:").unwrap(); + // Helper to create a test database + fn setup_test_db() -> (CommittsDb, NamedTempFile) { + let temp_file = NamedTempFile::new().unwrap(); + let mut db = CommittsDb::new(temp_file.path()).unwrap(); db.create_commit_status_table().unwrap(); - db + + (db, temp_file) } - // ----------------- - // Commit Status - // ----------------- - fn create_commit_status_row(message_id: u64) -> CommitStatusRow { + // Helper to create a test CommitStatusRow + fn create_test_row(message_id: u64, commit_id: u64) -> CommitStatusRow { CommitStatusRow { message_id, - commit_id: 0, + commit_id, pubkey: Pubkey::new_unique(), delegated_account_owner: Pubkey::new_unique(), slot: 100, ephemeral_blockhash: Hash::new_unique(), undelegate: false, - lamports: 100, - data: None, - commit_type: CommitType::EmptyAccount, + lamports: 1000, + data: Some(vec![1, 2, 3]), + commit_type: CommitType::DataAccount, created_at: 1000, commit_status: CommitStatus::Pending, + commit_strategy: CommitStrategy::Args, last_retried_at: 1000, retries_count: 0, } } #[test] - fn test_round_trip_commit_status_rows() { - let one_unbundled_commit_row_no_data = CommitStatusRow { - message_id: 123, - commit_id: 0, - pubkey: Pubkey::new_unique(), - delegated_account_owner: Pubkey::new_unique(), - slot: 100, - ephemeral_blockhash: Hash::new_unique(), - undelegate: false, - lamports: 100, - data: None, - commit_type: CommitType::EmptyAccount, - created_at: 1000, - commit_status: CommitStatus::Pending, - last_retried_at: 1000, - retries_count: 0, - }; + fn test_table_creation() { + let (db, _) = setup_test_db(); + + // Verify table exists + let table_exists: bool = db.conn.query_row( + "SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='commit_status')", + [], + |row| row.get(0), + ).unwrap(); + assert!(table_exists); + } - let two_bundled_commit_row_with_data = CommitStatusRow { - message_id: 123, - commit_id: 0, - pubkey: Pubkey::new_unique(), - delegated_account_owner: Pubkey::new_unique(), - slot: 100, - ephemeral_blockhash: Hash::new_unique(), - undelegate: false, - lamports: 2000, - data: Some(vec![1, 2, 3]), - commit_type: CommitType::DataAccount, - created_at: 1000, - commit_status: CommitStatus::FailedProcess(( - 2, - CommitStrategy::Args, - None, - )), - last_retried_at: 1000, - retries_count: 0, - }; + #[test] + fn test_insert_and_retrieve_rows() { + let (mut db, _file) = setup_test_db(); + let row1 = create_test_row(1, 0); + let row2 = create_test_row(1, 0); // Same message_id, different pubkey + + // Insert rows + db.insert_commit_status_rows(&[row1.clone(), row2.clone()]).unwrap(); + + // Retrieve by message_id + let rows = db.get_commit_statuses_by_id(1).unwrap(); + assert_eq!(rows.len(), 2); + assert!(rows.contains(&row1)); + assert!(rows.contains(&row2)); + + // Retrieve individual row + let retrieved = db.get_commit_status(1, &row1.pubkey).unwrap().unwrap(); + assert_eq!(retrieved, row1); + } - let mut db = setup_db(); - db.insert_commit_status_rows(&[ - one_unbundled_commit_row_no_data.clone(), - two_bundled_commit_row_with_data.clone(), - ]) - .unwrap(); - - let one = db - .get_commit_statuses_by_pubkey( - &one_unbundled_commit_row_no_data.pubkey, - ) - .unwrap(); - assert_eq!(one.len(), 1); - assert_eq!(one[0], one_unbundled_commit_row_no_data); - - let two = db - .get_commit_statuses_by_pubkey( - &two_bundled_commit_row_with_data.pubkey, - ) - .unwrap(); - assert_eq!(two.len(), 1); - assert_eq!(two[0], two_bundled_commit_row_with_data); - - let by_message_id = db - .get_commit_statuses_by_id( - one_unbundled_commit_row_no_data.message_id, - ) - .unwrap(); - assert_eq!(by_message_id.len(), 2); - assert_eq!( - by_message_id, - [ - one_unbundled_commit_row_no_data, - two_bundled_commit_row_with_data - ] - ); + #[test] + fn test_set_commit_id() { + let (mut db, _file) = setup_test_db(); + let mut row = create_test_row(1, 0); + db.insert_commit_status_rows(&[row.clone()]).unwrap(); + + // Update commit_id + db.set_commit_id(1, &row.pubkey, 100).unwrap(); + + // Verify update + let updated = db.get_commit_status(1, &row.pubkey).unwrap().unwrap(); + assert_eq!(updated.commit_id, 100); } - fn create_message_signature_row( - commit_status: &CommitStatus, - ) -> Option { - commit_status - .bundle_id() - .map(|bundle_id| MessageSignatures { - processed_signature: Signature::new_unique(), - finalized_signature: None, - undelegate_signature: None, - created_at: 1000, - }) + #[test] + fn test_update_status_by_message() { + let (mut db, _file) = setup_test_db(); + let row = create_test_row(1, 0); + db.insert_commit_status_rows(&[row.clone()]).unwrap(); + + let new_status = CommitStatus::Pending; + db.update_status_by_message(1, &row.pubkey, &new_status).unwrap(); + + let updated = db.get_commit_status(1, &row.pubkey).unwrap().unwrap(); + assert_eq!(updated.commit_status, new_status); } #[test] - fn test_commits_with_message_id() { - let mut db = setup_db(); - const MESSAGE_ID_ONE: u64 = 123; - const MESSAGE_ID_TWO: u64 = 456; - - let commit_row_one = create_commit_status_row(MESSAGE_ID_ONE); - let commit_row_one_other = create_commit_status_row(MESSAGE_ID_ONE); - let commit_row_two = create_commit_status_row(MESSAGE_ID_TWO); - - db.insert_commit_status_rows(&[ - commit_row_one.clone(), - commit_row_one_other.clone(), - commit_row_two.clone(), - ]) - .unwrap(); - - let commits_one = db.get_commit_statuses_by_id(MESSAGE_ID_ONE).unwrap(); - assert_eq!(commits_one.len(), 2); - assert_eq!(commits_one[0], commit_row_one); - assert_eq!(commits_one[1], commit_row_one_other); - - let commits_two = db.get_commit_statuses_by_id(MESSAGE_ID_TWO).unwrap(); - assert_eq!(commits_two.len(), 1); - assert_eq!(commits_two[0], commit_row_two); - - // Remove commits with MESSAGE_ID_ONE - db.remove_commit_statuses_with_id(MESSAGE_ID_ONE).unwrap(); - let commits_one_after_removal = - db.get_commit_statuses_by_id(MESSAGE_ID_ONE).unwrap(); - assert_eq!(commits_one_after_removal.len(), 0); - - let commits_two_after_removal = - db.get_commit_statuses_by_id(MESSAGE_ID_TWO).unwrap(); - assert_eq!(commits_two_after_removal.len(), 1); + fn test_update_status_by_commit() { + let (mut db, _file) = setup_test_db(); + let mut row = create_test_row(1, 100); // Set commit_id to 100 + db.insert_commit_status_rows(&[row.clone()]).unwrap(); + + let new_status = CommitStatus::Succeeded(( + 100, + CommitStatusSignatures { + process_signature: Signature::new_unique(), + finalize_signature: None, + }, + )); + db.update_status_by_commit(100, &row.pubkey, &new_status).unwrap(); + + let updated = db.get_commit_status(1, &row.pubkey).unwrap().unwrap(); + assert_eq!(updated.commit_status, new_status); } #[test] - fn test_update_commit_status() { - let mut db = setup_db(); - const MESSAGE_ID: u64 = 123; - - let failing_commit_row = create_commit_status_row(MESSAGE_ID); - let success_commit_row = create_commit_status_row(MESSAGE_ID); - db.insert_commit_status_rows(&[ - failing_commit_row.clone(), - success_commit_row.clone(), - ]) - .unwrap(); - - // Update the statuses - let new_failing_status = - CommitStatus::FailedProcess((22, CommitStrategy::FromBuffer, None)); - db.update_status_by_message( - failing_commit_row.message_id, - &failing_commit_row.pubkey, - &new_failing_status, - ) - .unwrap(); - let sigs = CommitStatusSignatures { - process_signature: Signature::new_unique(), - finalize_signature: None, - undelegate_signature: None, - }; - let new_success_status = - CommitStatus::Succeeded((33, CommitStrategy::Args, sigs)); - let success_signatures_row = - create_message_signature_row(&new_success_status); - let success_signatures = success_signatures_row.clone().unwrap(); - db.update_status_by_message( - success_commit_row.message_id, - &success_commit_row.pubkey, - &new_success_status, - ) - .unwrap(); - - // Verify the statuses were updated - let failed_commit_row = db - .get_commit_status(MESSAGE_ID, &failing_commit_row.pubkey) - .unwrap() - .unwrap(); - assert_eq!(failed_commit_row.commit_status, new_failing_status); - - let succeeded_commit_row = db - .get_commit_status(MESSAGE_ID, &success_commit_row.pubkey) - .unwrap() - .unwrap(); - assert_eq!(succeeded_commit_row.commit_status, new_success_status); - let signature_row = db.get_signatures_by_commit(33).unwrap().unwrap(); - assert_eq!( - signature_row.processed_signature, - success_signatures.processed_signature, - ); - assert_eq!(signature_row.finalized_signature, None); + fn test_set_commit_strategy() { + let (mut db, _file) = setup_test_db(); + let mut row = create_test_row(1, 100); + db.insert_commit_status_rows(&[row.clone()]).unwrap(); + + let new_strategy = CommitStrategy::FromBuffer; + db.set_commit_strategy(100, &row.pubkey, new_strategy).unwrap(); + + let updated = db.get_commit_status(1, &row.pubkey).unwrap().unwrap(); + assert_eq!(updated.commit_strategy, new_strategy); } -} + + #[test] + fn test_get_signatures_by_commit() { + let (mut db, _file) = setup_test_db(); + let process_sig = Signature::new_unique(); + let finalize_sig = Signature::new_unique(); + + let mut row = create_test_row(1, 100); + row.commit_status = CommitStatus::Succeeded(( + 100, + CommitStatusSignatures { + process_signature: process_sig, + finalize_signature: Some(finalize_sig), + }, + )); + db.insert_commit_status_rows(&[row.clone()]).unwrap(); + + let sigs = db.get_signatures_by_commit(100, &row.pubkey).unwrap().unwrap(); + assert_eq!(sigs.processed_signature, process_sig); + assert_eq!(sigs.finalized_signature, Some(finalize_sig)); + } + + #[test] + fn test_remove_commit_statuses() { + let (mut db, _file) = setup_test_db(); + let row1 = create_test_row(1, 0); + let row2 = create_test_row(2, 0); + db.insert_commit_status_rows(&[row1.clone(), row2.clone()]).unwrap(); + + // Remove one message + db.remove_commit_statuses_with_id(1).unwrap(); + + // Verify removal + assert!(db.get_commit_statuses_by_id(1).unwrap().is_empty()); + assert_eq!(db.get_commit_statuses_by_id(2).unwrap().len(), 1); + } + + #[test] + fn test_empty_data_handling() { + let (mut db, _file) = setup_test_db(); + let mut row = create_test_row(1, 0); + row.data = None; + row.commit_type = CommitType::EmptyAccount; + + db.insert_commit_status_rows(&[row.clone()]).unwrap(); + + let retrieved = db.get_commit_status(1, &row.pubkey).unwrap().unwrap(); + assert!(retrieved.data.is_none()); + assert_eq!(retrieved.commit_type, CommitType::EmptyAccount); + } + + #[test] + fn test_undelegate_flag() { + let (mut db, _file) = setup_test_db(); + let mut row = create_test_row(1, 0); + row.undelegate = true; + + db.insert_commit_status_rows(&[row.clone()]).unwrap(); + + let retrieved = db.get_commit_status(1, &row.pubkey).unwrap().unwrap(); + assert!(retrieved.undelegate); + } +} \ No newline at end of file diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 178ff0b62..d594d12de 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -1,7 +1,6 @@ use std::path::Path; use log::*; -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::Pubkey; use solana_sdk::signature::Keypair; use tokio::{ diff --git a/magicblock-committor-service/src/service_ext.rs b/magicblock-committor-service/src/service_ext.rs index c2fe69443..a57de0745 100644 --- a/magicblock-committor-service/src/service_ext.rs +++ b/magicblock-committor-service/src/service_ext.rs @@ -88,7 +88,7 @@ impl L1MessageCommittorExt for CommittorServiceExt { l1_messages: Vec, ) -> L1MessageCommitorExtResult> { - let mut receivers = { + let receivers = { let mut pending_messages = self.pending_messages.lock().expect(POISONED_MUTEX_MSG); diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs index e4fc52a48..f5d54e889 100644 --- a/magicblock-committor-service/src/transactions.rs +++ b/magicblock-committor-service/src/transactions.rs @@ -223,7 +223,7 @@ pub(crate) fn process_and_close_ixs( pubkey: &Pubkey, delegated_account_owner: &Pubkey, buffer_pda: &Pubkey, - ephemeral_blockhash: &Hash, + commit_id: u64, commit_args: CommitStateFromBufferArgs, ) -> Vec { let process_ix = process_commits_ix( @@ -233,7 +233,7 @@ pub(crate) fn process_and_close_ixs( buffer_pda, commit_args, ); - let close_ix = close_buffers_ix(validator_auth, pubkey, 0); // TODO(edwin) + let close_ix = close_buffers_ix(validator_auth, pubkey, commit_id); vec![process_ix, close_ix] } @@ -507,7 +507,7 @@ mod test { let delegated_account_owner = Pubkey::new_unique(); let buffer_pda = Pubkey::new_unique(); let commit_args = CommitStateFromBufferArgs::default(); - vec![dlp::instruction_builder::process_commits_ix( + vec![process_commits_ix( auth_pubkey, &pubkey, &delegated_account_owner, @@ -537,11 +537,7 @@ mod test { let commit_id = 0; max_chunks_per_transaction("Max close per tx", |auth_pubkey| { let pubkey = Pubkey::new_unique(); - vec![close_buffers_ix( - auth_pubkey, - &pubkey, - &ephemeral_blockhash, - )] + vec![close_buffers_ix(auth_pubkey, &pubkey, commit_id)] }) }; pub(crate) static ref MAX_CLOSE_PER_TX_USING_LOOKUP: u8 = { @@ -549,11 +545,7 @@ mod test { max_chunks_per_transaction_using_lookup_table( "Max close per tx using lookup", |auth_pubkey, committee, _| { - vec![close_buffers_ix( - auth_pubkey, - &committee, - &ephemeral_blockhash, - )] + vec![close_buffers_ix(auth_pubkey, &committee, commit_id)] }, None, ) @@ -579,18 +571,18 @@ mod test { ) }; pub(crate) static ref MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP: u8 = { - let ephemeral_blockhash = Hash::default(); + let commit_id = 0; max_chunks_per_transaction_using_lookup_table( "Max process and close per tx using lookup", |auth_pubkey, committee, delegated_account_owner| { let commit_args = CommitStateFromBufferArgs::default(); let buffer_pda = Pubkey::new_unique(); - super::process_and_close_ixs( + process_and_close_ixs( auth_pubkey, &committee, &delegated_account_owner, &buffer_pda, - &ephemeral_blockhash, + commit_id, commit_args, ) }, diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 450c204ed..dc8e32712 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -3729,6 +3729,7 @@ dependencies = [ "solana-sdk", "solana-transaction-status-client-types", "static_assertions", + "tempfile", "thiserror 1.0.69", "tokio", "tokio-util 0.7.13", From 9f1b2a0d06fa4a0b9898848bfc3390a7d4c3d453 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 25 Jul 2025 16:04:25 +0900 Subject: [PATCH 117/199] feat: scheduler tests --- .../commit_scheduler_inner.rs | 281 +++++++++++++++++- .../commit_scheduler_worker.rs | 2 +- magicblock-committor-service/src/types.rs | 4 +- 3 files changed, 279 insertions(+), 8 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index 7a277823d..e252aa2c0 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -1,8 +1,6 @@ use std::collections::{hash_map::Entry, HashMap, VecDeque}; - -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::Pubkey; - +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use crate::{types::ScheduledL1MessageWrapper, utils::ScheduledMessageExt}; pub(crate) const POISONED_INNER_MSG: &str = @@ -114,7 +112,8 @@ impl CommitSchedulerInner { } /// Completes Message, cleaning up data after itself and allowing Messages to move forward - /// Note: this shall be called on executing messages to finilize their execution. + /// NOTE: This doesn't unblock message, hence Self::messages_blocked will return old value. + /// NOTE: this shall be called on executing messages to finilize their execution. /// Calling on incorrect `pubkyes` set will result in panic pub fn complete(&mut self, l1_message: &ScheduledL1Message) { // Release data for completed message @@ -179,7 +178,279 @@ impl CommitSchedulerInner { /// Returns number of blocked messages /// Note: this doesn't include "executing" messages - pub fn blocked_messages_len(&self) -> usize { + pub fn messages_blocked(&self) -> usize { self.blocked_messages.len() } } + + +/// Set of simple tests +#[cfg(test)] +mod simple_test { + use super::*; + use solana_pubkey::pubkey; + + #[test] + fn test_empty_scheduler() { + let mut scheduler = CommitSchedulerInner::new(); + assert_eq!(scheduler.messages_blocked(), 0); + assert!(scheduler.pop_next_scheduled_message().is_none()); + } + + /// Ensure messages with non-conflicting set of keys can run in parallel + #[test] + fn test_non_conflicting_messages() { + let mut scheduler = CommitSchedulerInner::new(); + let msg1 = create_test_message(1, &[pubkey!("1111111111111111111111111111111111111111111")]); + let msg2 = create_test_message(2, &[pubkey!("22222222222222222222222222222222222222222222")]); + + // First message should execute immediately + assert!(scheduler.schedule(msg1.clone()).is_some()); + // Second message should also execute immediately + assert!(scheduler.schedule(msg2.clone()).is_some()); + // No messages are blocked + assert_eq!(scheduler.messages_blocked(), 0); + } + + /// Ensure messages conflicting messages get blocked + #[test] + fn test_conflicting_messages() { + const NUM_MESSAGES: u64 = 10; + + let mut scheduler = CommitSchedulerInner::new(); + let pubkey = pubkey!("1111111111111111111111111111111111111111111"); + let msg1 = create_test_message(1, &[pubkey]); + + // First message executes immediately + assert!(scheduler.schedule(msg1).is_some()); + for id in 2..=NUM_MESSAGES { + let msg = create_test_message(id, &[pubkey]); + // Message gets blocked + assert!(scheduler.schedule(msg).is_none()); + } + + // 1 message executing, NUM_MESSAGES - 1 are blocked + assert_eq!(scheduler.messages_blocked() as u64, NUM_MESSAGES - 1); + } +} + +/// Set of simple completion tests +#[cfg(test)] +mod completion_simple_test { + use super::*; + use solana_pubkey::pubkey; + + #[test] + fn test_completion_unblocks_messages() { + let mut scheduler = CommitSchedulerInner::new(); + let pubkey = pubkey!("1111111111111111111111111111111111111111111"); + let msg1 = create_test_message(1, &[pubkey]); + let msg2 = create_test_message(2, &[pubkey]); + + // First message executes immediately + let executed = scheduler.schedule(msg1.clone()).unwrap(); + // Second message gets blocked + assert!(scheduler.schedule(msg2.clone()).is_none()); + assert_eq!(scheduler.messages_blocked(), 1); + + // Complete first message + scheduler.complete(&executed.scheduled_l1_message); + + let next = scheduler.pop_next_scheduled_message().unwrap(); + assert_eq!(next, msg2); + assert_eq!(scheduler.messages_blocked(), 0); + } + + #[test] + fn test_multiple_blocked_messages() { + let mut scheduler = CommitSchedulerInner::new(); + let pubkey = pubkey!("1111111111111111111111111111111111111111111"); + let msg1 = create_test_message(1, &[pubkey]); + let msg2 = create_test_message(2, &[pubkey]); + let msg3 = create_test_message(3, &[pubkey]); + + // First message executes immediately + let executed = scheduler.schedule(msg1.clone()).unwrap(); + // Others get blocked + assert!(scheduler.schedule(msg2.clone()).is_none()); + assert!(scheduler.schedule(msg3.clone()).is_none()); + assert_eq!(scheduler.messages_blocked(), 2); + + // Complete first message + scheduler.complete(&executed.scheduled_l1_message); + + // Second message should now be available + let expected_msg2 = scheduler.pop_next_scheduled_message().unwrap(); + assert_eq!(expected_msg2, msg2); + assert_eq!(scheduler.messages_blocked(), 1); + + // Complete second message + scheduler.complete(&expected_msg2.scheduled_l1_message); + + // Third message should now be available + let expected_msg3 = scheduler.pop_next_scheduled_message().unwrap(); + assert_eq!(expected_msg3, msg3); + assert_eq!(scheduler.messages_blocked(), 0); + } +} + +#[cfg(test)] +mod complex_blocking { + use super::*; + use solana_pubkey::pubkey; + + /// Case: + /// executing: `[a1, a2, a3] [b1, b2, b3]` - 1 + /// blocked: `[a1, b1]` - 2 + /// arriving: `[a1, a3]` - 3 + #[test] + fn test_edge_case_1_earlier_message_blocks_later_overlapping() { + let mut scheduler = CommitSchedulerInner::new(); + let a1 = pubkey!("1111111111111111111111111111111111111111111"); + let a2 = pubkey!("21111111111111111111111111111111111111111111"); + let a3 = pubkey!("31111111111111111111111111111111111111111111"); + let b1 = pubkey!("41111111111111111111111111111111111111111111"); + let b2 = pubkey!("51111111111111111111111111111111111111111111"); + let b3 = pubkey!("61111111111111111111111111111111111111111111"); + + // Message 1: [a1, a2, a3] + let msg1_keys = vec![a1, a2, a3]; + let msg1 = create_test_message(1, &msg1_keys); + assert!(scheduler.schedule(msg1.clone()).is_some()); + assert_eq!(scheduler.messages_blocked(), 0); + + // Message 2: [b1, b2, b3] + let msg2_keys = vec![b1, b2, b3]; + let msg2 = create_test_message(2, &msg2_keys); + assert!(scheduler.schedule(msg2.clone()).is_some()); + assert_eq!(scheduler.messages_blocked(), 0); + + // Message 3: [a1, b1] - blocked by msg1 & msg2 + let msg3_keys = vec![a1, b1]; + let msg3 = create_test_message(3, &msg3_keys); + assert!(scheduler.schedule(msg3.clone()).is_none()); + assert_eq!(scheduler.messages_blocked(), 1); + + // Message 4: [a1, a3] - blocked by msg1 & msg3 + let msg4_keys = vec![a1, a3]; + let msg4 = create_test_message(4, &msg4_keys); + assert!(scheduler.schedule(msg4.clone()).is_none()); + assert_eq!(scheduler.messages_blocked(), 2); + + // Complete msg1 + scheduler.complete(&msg1.scheduled_l1_message); + // None of the messages can execute yet + // msg3 is blocked msg2 + // msg4 is blocked by msg3 + assert!(scheduler.pop_next_scheduled_message().is_none()); + + // Complete msg2 + scheduler.complete(&msg2.scheduled_l1_message); + // Now msg3 is unblocked + let next = scheduler.pop_next_scheduled_message().unwrap(); + assert_eq!(next, msg3); + assert_eq!(scheduler.messages_blocked(), 1); + // Complete msg3 + scheduler.complete(&next.scheduled_l1_message); + + // Now msg4 should be available + let next = scheduler.pop_next_scheduled_message().unwrap(); + assert_eq!(next, msg4); + assert_eq!(scheduler.messages_blocked(), 0); + } + + /// Case: + /// executing: `[a1, a2, a3]` + /// blocked: `[c1, a1]` + /// arriving: `[c2, c1]` + /// `[c2, c1]` - Even there's no overlaps with executing + #[test] + fn test_edge_case_2_indirect_blocking_through_shared_key() { + let mut scheduler = CommitSchedulerInner::new(); + let a1 = pubkey!("1111111111111111111111111111111111111111111"); + let a2 = pubkey!("21111111111111111111111111111111111111111111"); + let a3 = pubkey!("31111111111111111111111111111111111111111111"); + let c1 = pubkey!("41111111111111111111111111111111111111111111"); + let c2 = pubkey!("51111111111111111111111111111111111111111111"); + + // Message 1: [a1, a2, a3] (executing) + let msg1_keys = vec![a1, a2, a3]; + let msg1 = create_test_message(1, &msg1_keys); + + // Message 2: [c1, a1] (blocked by msg1) + let msg2_keys = vec![c1, a1]; + let msg2 = create_test_message(2, &msg2_keys); + + // Message 3: [c2, c1] (arriving later) + let msg3_keys = vec![c2, c1]; + let msg3 = create_test_message(3, &msg3_keys); + + // Schedule msg1 (executes immediately) + let executed_msg1 = scheduler.schedule(msg1.clone()).unwrap(); + assert_eq!(executed_msg1, msg1); + + // Schedule msg2 (gets blocked) + assert!(scheduler.schedule(msg2.clone()).is_none()); + assert_eq!(scheduler.messages_blocked(), 1); + + // Schedule msg3 (gets blocked, even though c2 is available) + assert!(scheduler.schedule(msg3.clone()).is_none()); + assert_eq!(scheduler.messages_blocked(), 2); + + // Complete msg1 + scheduler.complete(&executed_msg1.scheduled_l1_message); + + // Now only msg2 should be available (not msg3) + let expected_msg2 = scheduler.pop_next_scheduled_message().unwrap(); + assert_eq!(expected_msg2, msg2); + assert_eq!(scheduler.messages_blocked(), 1); + // msg 3 still should be blocked + assert_eq!(scheduler.pop_next_scheduled_message(), None); + + // Complete msg2 + scheduler.complete(&expected_msg2.scheduled_l1_message); + + // Now msg3 should be available + let expected_msg3 = scheduler.pop_next_scheduled_message().unwrap(); + assert_eq!(expected_msg3, msg3); + assert_eq!(scheduler.messages_blocked(), 0); + } +} + + + +// Helper function to create test messages +#[cfg(test)] +fn create_test_message(id: u64, pubkeys: &[Pubkey]) -> ScheduledL1MessageWrapper { + use solana_sdk::hash::Hash; + use solana_sdk::transaction::Transaction; + use magicblock_program::magic_scheduled_l1_message::{CommitType, CommittedAccountV2, MagicL1Message}; + use crate::types::TriggerType; + use solana_account::Account; + + let mut message = ScheduledL1Message { + id, + slot: 0, + blockhash: Hash::default(), + action_sent_transaction: Transaction::default(), + payer: Pubkey::default(), + l1_message: MagicL1Message::L1Actions(vec![]), + }; + + // Only set pubkeys if provided + if !pubkeys.is_empty() { + let committed_accounts = pubkeys.iter().map(|&pubkey| CommittedAccountV2 { + pubkey, + account: Account::default(), + }).collect(); + + message.l1_message = MagicL1Message::Commit(CommitType::Standalone(committed_accounts)); + } + + ScheduledL1MessageWrapper { + scheduled_l1_message: message, + feepayers: vec![], + excluded_pubkeys: vec![], + trigger_type: TriggerType::OffChain, + } +} \ No newline at end of file diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index ade27b4ea..131b88bd7 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -202,7 +202,7 @@ where .inner .lock() .expect(POISONED_INNER_MSG) - .blocked_messages_len(); + .messages_blocked(); if num_blocked_messages < SCHEDULER_CAPACITY { true } else { diff --git a/magicblock-committor-service/src/types.rs b/magicblock-committor-service/src/types.rs index 849140899..d44c543ff 100644 --- a/magicblock-committor-service/src/types.rs +++ b/magicblock-committor-service/src/types.rs @@ -62,13 +62,13 @@ impl fmt::Display for InstructionsForCommitable { // TODO: should be removed once cranks are supported // Ideally even now OffChain/"Manual" commits should be triggered via Tx -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum TriggerType { OnChain, OffChain, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct ScheduledL1MessageWrapper { pub scheduled_l1_message: ScheduledL1Message, pub feepayers: Vec, From 54ff1075a1b2be43e6a7285363ce03623bdbfb87 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 25 Jul 2025 18:11:17 +0900 Subject: [PATCH 118/199] fix: scheduler bug in pop_next_scheduled_message + some more tests --- .../commit_scheduler_inner.rs | 172 +++++++++++++++--- .../src/persist/db.rs | 27 ++- 2 files changed, 162 insertions(+), 37 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index e252aa2c0..f1a008739 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -1,6 +1,8 @@ use std::collections::{hash_map::Entry, HashMap, VecDeque}; -use solana_pubkey::Pubkey; + use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; +use solana_pubkey::Pubkey; + use crate::{types::ScheduledL1MessageWrapper, utils::ScheduledMessageExt}; pub(crate) const POISONED_INNER_MSG: &str = @@ -132,9 +134,10 @@ impl CommitSchedulerInner { }; let blocked_messages: &mut VecDeque = occupied.get_mut(); + let front = blocked_messages.pop_front(); assert_eq!( message_id, - blocked_messages.pop_front().expect("Invariant: if message executing, queue for each account is non-empty"), + front.expect("Invariant: if message executing, queue for each account is non-empty"), "Invariant: executing message must be first at qeueue" ); @@ -157,20 +160,37 @@ impl CommitSchedulerInner { *execute_candidates.entry(*message_id).or_default() += 1; }); + // NOTE: + // Not all self.blocked_messages would be in execute_candidates + // t1: + // 1: [a, b] + // 2: [a, b] + // 3: [b] + // t2: + // 1: [a, b] - completed + // 2: [a, b] + // 3: [b] + // now 3 is in blocked messages but not in execute candidate + // NOTE: + // Other way around is also true, since execute_candidates also include + // currently executing messages let candidate = - self.blocked_messages.iter().find_map(|(message_id, meta)| { - if execute_candidates.get(message_id).expect( - "Invariant: blocked messages are always in candidates", - ) == &meta.num_keys - { - Some(*message_id) + execute_candidates.iter().find_map(|(id, ready_keys)| { + if let Some(candidate) = self.blocked_messages.get(id) { + if candidate.num_keys.eq(ready_keys) { + Some(id) + } else { + // Not enough keys are ready + None + } } else { + // This means that this message id is currently executing & not blocked None } }); if let Some(next) = candidate { - Some(self.blocked_messages.remove(&next).unwrap().message) + Some(self.blocked_messages.remove(next).unwrap().message) } else { None } @@ -183,13 +203,13 @@ impl CommitSchedulerInner { } } - /// Set of simple tests #[cfg(test)] mod simple_test { - use super::*; use solana_pubkey::pubkey; + use super::*; + #[test] fn test_empty_scheduler() { let mut scheduler = CommitSchedulerInner::new(); @@ -201,8 +221,14 @@ mod simple_test { #[test] fn test_non_conflicting_messages() { let mut scheduler = CommitSchedulerInner::new(); - let msg1 = create_test_message(1, &[pubkey!("1111111111111111111111111111111111111111111")]); - let msg2 = create_test_message(2, &[pubkey!("22222222222222222222222222222222222222222222")]); + let msg1 = create_test_message( + 1, + &[pubkey!("1111111111111111111111111111111111111111111")], + ); + let msg2 = create_test_message( + 2, + &[pubkey!("22222222222222222222222222222222222222222222")], + ); // First message should execute immediately assert!(scheduler.schedule(msg1.clone()).is_some()); @@ -237,9 +263,10 @@ mod simple_test { /// Set of simple completion tests #[cfg(test)] mod completion_simple_test { - use super::*; use solana_pubkey::pubkey; + use super::*; + #[test] fn test_completion_unblocks_messages() { let mut scheduler = CommitSchedulerInner::new(); @@ -295,10 +322,11 @@ mod completion_simple_test { } #[cfg(test)] -mod complex_blocking { - use super::*; +mod complex_blocking_test { use solana_pubkey::pubkey; + use super::*; + /// Case: /// executing: `[a1, a2, a3] [b1, b2, b3]` - 1 /// blocked: `[a1, b1]` - 2 @@ -415,18 +443,102 @@ mod complex_blocking { assert_eq!(expected_msg3, msg3); assert_eq!(scheduler.messages_blocked(), 0); } + + #[test] + fn test_complex_contention_scenario() { + let mut scheduler = CommitSchedulerInner::new(); + let a = pubkey!("1111111111111111111111111111111111111111111"); + let b = pubkey!("21111111111111111111111111111111111111111111"); + let c = pubkey!("31111111111111111111111111111111111111111111"); + + // Messages with various key combinations + let msg1 = create_test_message(1, &[a, b]); + let msg2 = create_test_message(2, &[a, c]); + let msg3 = create_test_message(3, &[c]); + let msg4 = create_test_message(4, &[b]); + let msg5 = create_test_message(5, &[a]); + + // msg1 executes immediately + let executed1 = scheduler.schedule(msg1.clone()).unwrap(); + // Others get blocked + assert!(scheduler.schedule(msg2.clone()).is_none()); + assert!(scheduler.schedule(msg3.clone()).is_none()); + assert!(scheduler.schedule(msg4.clone()).is_none()); + assert!(scheduler.schedule(msg5.clone()).is_none()); + assert_eq!(scheduler.messages_blocked(), 4); + + // Complete msg1 + scheduler.complete(&executed1.scheduled_l1_message); + + // msg2 and msg4 should be available (they don't conflict) + let next_msgs = [ + scheduler.pop_next_scheduled_message().unwrap(), + scheduler.pop_next_scheduled_message().unwrap(), + ]; + assert!(next_msgs.contains(&msg2)); + assert!(next_msgs.contains(&msg4)); + assert_eq!(scheduler.messages_blocked(), 2); + + // Complete msg2 + scheduler.complete(&msg2.scheduled_l1_message); + // msg2 and msg4 should be available (they don't conflict) + let next_messages = [ + scheduler.pop_next_scheduled_message().unwrap(), + scheduler.pop_next_scheduled_message().unwrap(), + ]; + assert!(next_messages.contains(&msg3)); + assert!(next_messages.contains(&msg5)); + assert_eq!(scheduler.messages_blocked(), 0); + } } +#[cfg(test)] +mod edge_cases_test { + use magicblock_program::magic_scheduled_l1_message::MagicL1Message; + use solana_pubkey::pubkey; + use super::*; + + #[test] + fn test_message_without_pubkeys() { + let mut scheduler = CommitSchedulerInner::new(); + let mut msg = create_test_message(1, &[]); + msg.scheduled_l1_message.l1_message = MagicL1Message::L1Actions(vec![]); + + // Should execute immediately since it has no pubkeys + assert!(scheduler.schedule(msg.clone()).is_some()); + assert_eq!(scheduler.messages_blocked(), 0); + } + + #[test] + fn test_completion_without_scheduling() { + let mut scheduler = CommitSchedulerInner::new(); + let msg = create_test_message( + 1, + &[pubkey!("11111111111111111111111111111111")], + ); + + // Completing a message that wasn't scheduled should panic + let result = std::panic::catch_unwind(move || { + scheduler.complete(&msg.scheduled_l1_message) + }); + assert!(result.is_err()); + } +} // Helper function to create test messages #[cfg(test)] -fn create_test_message(id: u64, pubkeys: &[Pubkey]) -> ScheduledL1MessageWrapper { - use solana_sdk::hash::Hash; - use solana_sdk::transaction::Transaction; - use magicblock_program::magic_scheduled_l1_message::{CommitType, CommittedAccountV2, MagicL1Message}; - use crate::types::TriggerType; +fn create_test_message( + id: u64, + pubkeys: &[Pubkey], +) -> ScheduledL1MessageWrapper { + use magicblock_program::magic_scheduled_l1_message::{ + CommitType, CommittedAccountV2, MagicL1Message, + }; use solana_account::Account; + use solana_sdk::{hash::Hash, transaction::Transaction}; + + use crate::types::TriggerType; let mut message = ScheduledL1Message { id, @@ -439,12 +551,16 @@ fn create_test_message(id: u64, pubkeys: &[Pubkey]) -> ScheduledL1MessageWrapper // Only set pubkeys if provided if !pubkeys.is_empty() { - let committed_accounts = pubkeys.iter().map(|&pubkey| CommittedAccountV2 { - pubkey, - account: Account::default(), - }).collect(); - - message.l1_message = MagicL1Message::Commit(CommitType::Standalone(committed_accounts)); + let committed_accounts = pubkeys + .iter() + .map(|&pubkey| CommittedAccountV2 { + pubkey, + account: Account::default(), + }) + .collect(); + + message.l1_message = + MagicL1Message::Commit(CommitType::Standalone(committed_accounts)); } ScheduledL1MessageWrapper { @@ -453,4 +569,4 @@ fn create_test_message(id: u64, pubkeys: &[Pubkey]) -> ScheduledL1MessageWrapper excluded_pubkeys: vec![], trigger_type: TriggerType::OffChain, } -} \ No newline at end of file +} diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 800a6c597..80052e765 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -582,10 +582,11 @@ fn extract_committor_row( #[cfg(test)] mod tests { - use super::*; - use solana_sdk::{signature::Signature, hash::Hash}; + use solana_sdk::{hash::Hash, signature::Signature}; use tempfile::NamedTempFile; + use super::*; + // Helper to create a test database fn setup_test_db() -> (CommittsDb, NamedTempFile) { let temp_file = NamedTempFile::new().unwrap(); @@ -636,7 +637,8 @@ mod tests { let row2 = create_test_row(1, 0); // Same message_id, different pubkey // Insert rows - db.insert_commit_status_rows(&[row1.clone(), row2.clone()]).unwrap(); + db.insert_commit_status_rows(&[row1.clone(), row2.clone()]) + .unwrap(); // Retrieve by message_id let rows = db.get_commit_statuses_by_id(1).unwrap(); @@ -670,7 +672,8 @@ mod tests { db.insert_commit_status_rows(&[row.clone()]).unwrap(); let new_status = CommitStatus::Pending; - db.update_status_by_message(1, &row.pubkey, &new_status).unwrap(); + db.update_status_by_message(1, &row.pubkey, &new_status) + .unwrap(); let updated = db.get_commit_status(1, &row.pubkey).unwrap().unwrap(); assert_eq!(updated.commit_status, new_status); @@ -689,7 +692,8 @@ mod tests { finalize_signature: None, }, )); - db.update_status_by_commit(100, &row.pubkey, &new_status).unwrap(); + db.update_status_by_commit(100, &row.pubkey, &new_status) + .unwrap(); let updated = db.get_commit_status(1, &row.pubkey).unwrap().unwrap(); assert_eq!(updated.commit_status, new_status); @@ -702,7 +706,8 @@ mod tests { db.insert_commit_status_rows(&[row.clone()]).unwrap(); let new_strategy = CommitStrategy::FromBuffer; - db.set_commit_strategy(100, &row.pubkey, new_strategy).unwrap(); + db.set_commit_strategy(100, &row.pubkey, new_strategy) + .unwrap(); let updated = db.get_commit_status(1, &row.pubkey).unwrap().unwrap(); assert_eq!(updated.commit_strategy, new_strategy); @@ -724,7 +729,10 @@ mod tests { )); db.insert_commit_status_rows(&[row.clone()]).unwrap(); - let sigs = db.get_signatures_by_commit(100, &row.pubkey).unwrap().unwrap(); + let sigs = db + .get_signatures_by_commit(100, &row.pubkey) + .unwrap() + .unwrap(); assert_eq!(sigs.processed_signature, process_sig); assert_eq!(sigs.finalized_signature, Some(finalize_sig)); } @@ -734,7 +742,8 @@ mod tests { let (mut db, _file) = setup_test_db(); let row1 = create_test_row(1, 0); let row2 = create_test_row(2, 0); - db.insert_commit_status_rows(&[row1.clone(), row2.clone()]).unwrap(); + db.insert_commit_status_rows(&[row1.clone(), row2.clone()]) + .unwrap(); // Remove one message db.remove_commit_statuses_with_id(1).unwrap(); @@ -769,4 +778,4 @@ mod tests { let retrieved = db.get_commit_status(1, &row.pubkey).unwrap().unwrap(); assert!(retrieved.undelegate); } -} \ No newline at end of file +} From 1bb4b718afb1b40040a272335e2708dbe7e3765b Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 25 Jul 2025 18:49:28 +0900 Subject: [PATCH 119/199] refactor: some docs --- .../src/commit_scheduler/commit_scheduler_inner.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index f1a008739..5f1720e38 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -1,5 +1,6 @@ use std::collections::{hash_map::Entry, HashMap, VecDeque}; +use log::warn; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::Pubkey; @@ -75,11 +76,19 @@ impl CommitSchedulerInner { /// Returns [`ScheduledL1Message`] if message can be executed, /// otherwise consumes it and enqueues + /// + /// CRITICAL: MessageIds should be unique + /// Message should be scheduled once! pub fn schedule( &mut self, l1_message: ScheduledL1MessageWrapper, ) -> Option { let message_id = l1_message.scheduled_l1_message.id; + if self.blocked_messages.contains_key(&message_id) { + warn!("Attempt to schedule already scheduled message!"); + return None; + } + let Some(pubkeys) = l1_message.scheduled_l1_message.get_committed_pubkeys() else { @@ -116,7 +125,7 @@ impl CommitSchedulerInner { /// Completes Message, cleaning up data after itself and allowing Messages to move forward /// NOTE: This doesn't unblock message, hence Self::messages_blocked will return old value. /// NOTE: this shall be called on executing messages to finilize their execution. - /// Calling on incorrect `pubkyes` set will result in panic + /// Calling on incorrect `pubkeys` set will result in panic pub fn complete(&mut self, l1_message: &ScheduledL1Message) { // Release data for completed message let message_id = l1_message.id; From 2241889cea42a6ee2eae4e137cd2d24be3f0b263 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Sat, 26 Jul 2025 12:41:41 +0900 Subject: [PATCH 120/199] feat: add traits for testing --- .../src/external_accounts_manager.rs | 2 +- .../src/commit_scheduler.rs | 18 +++-- .../src/commit_scheduler/commit_id_tracker.rs | 40 ++++++---- .../commit_scheduler_worker.rs | 57 +++++-------- magicblock-committor-service/src/lib.rs | 2 +- .../src/message_executor/error.rs | 37 +++++++++ .../message_executor.rs} | 80 ++++++------------- .../message_executor_factory.rs | 33 ++++++++ .../src/message_executor/mod.rs | 36 +++++++++ .../transaction_preparator.rs | 2 +- 10 files changed, 190 insertions(+), 117 deletions(-) create mode 100644 magicblock-committor-service/src/message_executor/error.rs rename magicblock-committor-service/src/{l1_message_executor.rs => message_executor/message_executor.rs} (86%) create mode 100644 magicblock-committor-service/src/message_executor/message_executor_factory.rs create mode 100644 magicblock-committor-service/src/message_executor/mod.rs diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index e063ed736..4fc7a9612 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -23,7 +23,7 @@ use magicblock_committor_service::{ commit_scheduler::{ BroadcastedMessageExecutionResult, ExecutionOutputWrapper, }, - l1_message_executor::ExecutionOutput, + message_executor::ExecutionOutput, service_ext::L1MessageCommittorExt, transactions::MAX_PROCESS_PER_TX, types::{ScheduledL1MessageWrapper, TriggerType}, diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index c37081537..5d5b65977 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -15,9 +15,11 @@ use tokio::sync::{broadcast, mpsc, mpsc::error::TrySendError}; use crate::{ commit_scheduler::{ + commit_id_tracker::CommitIdTrackerImpl, commit_scheduler_worker::{CommitSchedulerWorker, ResultSubscriber}, db::DB, }, + message_executor::message_executor_factory::L1MessageExecutorFactory, persist::L1MessagesPersisterIface, types::ScheduledL1MessageWrapper, ComputeBudgetConfig, @@ -38,17 +40,23 @@ impl CommitScheduler { compute_budget_config: ComputeBudgetConfig, ) -> Self { let db = Arc::new(db); - let (sender, receiver) = mpsc::channel(1000); - // TODO(edwin): add concellation logic + let executor_factory = L1MessageExecutorFactory { + rpc_client: rpc_client.clone(), + table_mania, + compute_budget_config, + }; + let commit_id_tracker = CommitIdTrackerImpl::new(rpc_client); + + let (sender, receiver) = mpsc::channel(1000); let worker = CommitSchedulerWorker::new( db.clone(), + executor_factory, + commit_id_tracker, l1_message_persister, - rpc_client, - table_mania, - compute_budget_config, receiver, ); + // TODO(edwin): add concellation logic let result_subscriber = worker.spawn(); Self { diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs index fe0344e3d..5e2d2896b 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs @@ -6,13 +6,22 @@ use magicblock_rpc_client::{ }; use solana_pubkey::Pubkey; -// -pub struct CommitIdTracker { +#[async_trait::async_trait] +pub trait CommitIdTracker { + async fn next_commit_ids( + &mut self, + pubkeys: &[Pubkey], + ) -> CommitIdTrackerResult>; + + fn peek_commit_id(&self, pubkey: &Pubkey) -> Option<&u64>; +} + +pub struct CommitIdTrackerImpl { rpc_client: MagicblockRpcClient, cache: LruCache, } -impl CommitIdTracker { +impl CommitIdTrackerImpl { pub fn new(rpc_client: MagicblockRpcClient) -> Self { const CACHE_SIZE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(1000) }; @@ -23,9 +32,21 @@ impl CommitIdTracker { } } + /// Fetches commit_ids using RPC + /// Note: remove duplicates prior to calling + pub async fn fetch_commit_ids( + rpc_client: &MagicblockRpcClient, + pubkeys: &[Pubkey], + ) -> MagicBlockRpcClientResult> { + todo!() + } +} + +#[async_trait::async_trait] +impl CommitIdTracker for CommitIdTrackerImpl { /// Returns next ids for requested pubkeys /// If key isn't in cache, it will be requested - pub async fn next_commit_ids( + async fn next_commit_ids( &mut self, pubkeys: &[Pubkey], ) -> CommitIdTrackerResult> { @@ -63,18 +84,9 @@ impl CommitIdTracker { } /// Returns current commit id without raising priority - pub fn peek_commit_id(&self, pubkey: &Pubkey) -> Option<&u64> { + fn peek_commit_id(&self, pubkey: &Pubkey) -> Option<&u64> { self.cache.peek(pubkey) } - - /// Fetches commit_ids using RPC - /// Note: remove duplicates prior to calling - pub async fn fetch_commit_ids( - rpc_client: &MagicblockRpcClient, - pubkeys: &[Pubkey], - ) -> MagicBlockRpcClientResult> { - todo!() - } } #[derive(thiserror::Error, Debug)] diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 131b88bd7..313369679 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -16,13 +16,15 @@ use tokio::sync::{ use crate::{ commit_scheduler::{ - commit_id_tracker::CommitIdTracker, + commit_id_tracker::{CommitIdTracker, CommitIdTrackerImpl}, commit_scheduler_inner::{CommitSchedulerInner, POISONED_INNER_MSG}, db::DB, Error, }, - l1_message_executor::{ - ExecutionOutput, L1MessageExecutor, MessageExecutorResult, + message_executor::{ + error::MessageExecutorResult, + message_executor_factory::MessageExecutorFactory, ExecutionOutput, + L1MessageExecutor, MessageExecutor, }, persist::L1MessagesPersisterIface, transaction_preperator::transaction_preparator::{ @@ -45,7 +47,7 @@ pub struct ExecutionOutputWrapper { pub trigger_type: TriggerType, } -pub type BroadcastedError = (u64, Arc); +pub type BroadcastedError = (u64, Arc); pub type BroadcastedMessageExecutionResult = MessageExecutorResult; @@ -62,11 +64,11 @@ impl ResultSubscriber { } } -pub(crate) struct CommitSchedulerWorker { +pub(crate) struct CommitSchedulerWorker { db: Arc, l1_messages_persister: Option

, - executor_factory: L1MessageExecutorFactory, - commit_id_tracker: CommitIdTracker, + executor_factory: F, + commit_id_tracker: C, receiver: mpsc::Receiver, // TODO(edwin): replace notify. issue: 2 simultaneous notifications @@ -75,28 +77,24 @@ pub(crate) struct CommitSchedulerWorker { inner: Arc>, } -impl CommitSchedulerWorker +impl CommitSchedulerWorker where D: DB, P: L1MessagesPersisterIface, + F: MessageExecutorFactory + Send + Sync + 'static, + E: MessageExecutor, + C: CommitIdTracker + Send + Sync + 'static, { pub fn new( db: Arc, + executor_factory: F, + commit_id_tracker: C, l1_messages_persister: Option

, - rpc_client: MagicblockRpcClient, - table_mania: TableMania, - compute_budget_config: ComputeBudgetConfig, receiver: mpsc::Receiver, ) -> Self { // Number of executors that can send messages in parallel to L1 const NUM_OF_EXECUTORS: u8 = 50; - let executor_factory = L1MessageExecutorFactory { - rpc_client: rpc_client.clone(), - table_mania, - compute_budget_config, - }; - let commit_id_tracker = CommitIdTracker::new(rpc_client); Self { db, l1_messages_persister, @@ -172,7 +170,7 @@ where }; // Spawn executor - let executor = self.executor_factory.create_executor(); + let executor = self.executor_factory.create_instance(); let persister = self.l1_messages_persister.clone(); let inner = self.inner.clone(); let notify = self.notify.clone(); @@ -247,8 +245,8 @@ where } /// Wrapper on [`L1MessageExecutor`] that handles its results and drops execution permit - async fn execute( - executor: L1MessageExecutor, + async fn execute( + executor: E, persister: Option

, l1_message: ScheduledL1MessageWrapper, commit_ids: HashMap, @@ -332,22 +330,3 @@ where } } } - -/// Dummy struct to implify signatur -struct L1MessageExecutorFactory { - rpc_client: MagicblockRpcClient, - table_mania: TableMania, - compute_budget_config: ComputeBudgetConfig, -} - -impl L1MessageExecutorFactory { - pub fn create_executor( - &self, - ) -> L1MessageExecutor { - L1MessageExecutor::::new_v1( - self.rpc_client.clone(), - self.table_mania.clone(), - self.compute_budget_config.clone(), - ) - } -} diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 27cf64484..299a476fb 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -18,7 +18,7 @@ mod undelegate; pub mod commit_scheduler; // TODO(edwin): define visibility mod committor_processor; -pub mod l1_message_executor; +pub mod message_executor; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; pub mod tasks; diff --git a/magicblock-committor-service/src/message_executor/error.rs b/magicblock-committor-service/src/message_executor/error.rs new file mode 100644 index 000000000..73d17b64b --- /dev/null +++ b/magicblock-committor-service/src/message_executor/error.rs @@ -0,0 +1,37 @@ +use magicblock_rpc_client::MagicBlockRpcClientError; +use solana_sdk::signature::{Signature, SignerError}; + +#[derive(thiserror::Error, Debug)] +pub enum InternalError { + #[error("SignerError: {0}")] + SignerError(#[from] SignerError), + #[error("MagicBlockRpcClientError: {0}")] + MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), +} + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("FailedToCommitError: {err}")] + FailedToCommitError { + #[source] + err: InternalError, + signature: Option, + }, + #[error("FailedToFinalizeError: {err}")] + FailedToFinalizeError { + #[source] + err: InternalError, + commit_signature: Signature, + finalize_signature: Option, + }, + #[error("FailedCommitPreparationError: {0}")] + FailedCommitPreparationError( + #[source] crate::transaction_preperator::error::Error, + ), + #[error("FailedFinalizePreparationError: {0}")] + FailedFinalizePreparationError( + #[source] crate::transaction_preperator::error::Error, + ), +} + +pub type MessageExecutorResult = Result; diff --git a/magicblock-committor-service/src/l1_message_executor.rs b/magicblock-committor-service/src/message_executor/message_executor.rs similarity index 86% rename from magicblock-committor-service/src/l1_message_executor.rs rename to magicblock-committor-service/src/message_executor/message_executor.rs index 6673da8a4..d7039c985 100644 --- a/magicblock-committor-service/src/l1_message_executor.rs +++ b/magicblock-committor-service/src/message_executor/message_executor.rs @@ -19,6 +19,10 @@ use solana_sdk::{ }; use crate::{ + message_executor::{ + error::{Error, InternalError, MessageExecutorResult}, + ExecutionOutput, MessageExecutor, + }, persist::{CommitStatus, CommitStatusSignatures, L1MessagesPersisterIface}, transaction_preperator::transaction_preparator::{ TransactionPreparator, TransactionPreparatorV1, @@ -27,15 +31,7 @@ use crate::{ ComputeBudgetConfig, }; -// TODO(edwin): define struct -// (commit_id, signature)s that it sent. Single worker in [`RemoteScheduledCommitsProcessor`] -#[derive(Clone, Debug)] -pub struct ExecutionOutput { - pub commit_signature: Signature, - pub finalize_signature: Signature, -} - -pub(crate) struct L1MessageExecutor { +pub struct L1MessageExecutor { authority: Keypair, rpc_client: MagicblockRpcClient, transaction_preparator: T, @@ -63,21 +59,6 @@ where } } - /// Executes message on L1 - pub async fn execute( - &self, - l1_message: ScheduledL1Message, - commit_ids: HashMap, - persister: Option

, - ) -> MessageExecutorResult { - let result = self - .execute_inner(l1_message, &commit_ids, &persister) - .await; - Self::persist_result(&persister, &result, &commit_ids); - - result - } - async fn execute_inner( &self, l1_message: ScheduledL1Message, @@ -256,37 +237,24 @@ where } } -#[derive(thiserror::Error, Debug)] -pub enum InternalError { - #[error("SignerError: {0}")] - SignerError(#[from] SignerError), - #[error("MagicBlockRpcClientError: {0}")] - MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), -} +#[async_trait::async_trait] +impl MessageExecutor for L1MessageExecutor +where + T: TransactionPreparator, +{ + /// Executes Message on Base layer + /// Returns `ExecutionOutput` or an `Error` + async fn execute( + &self, + l1_message: ScheduledL1Message, + commit_ids: HashMap, + persister: Option

, + ) -> MessageExecutorResult { + let result = self + .execute_inner(l1_message, &commit_ids, &persister) + .await; + Self::persist_result(&persister, &result, &commit_ids); -#[derive(thiserror::Error, Debug)] -pub enum Error { - #[error("FailedToCommitError: {err}")] - FailedToCommitError { - #[source] - err: InternalError, - signature: Option, - }, - #[error("FailedToFinalizeError: {err}")] - FailedToFinalizeError { - #[source] - err: InternalError, - commit_signature: Signature, - finalize_signature: Option, - }, - #[error("FailedCommitPreparationError: {0}")] - FailedCommitPreparationError( - #[source] crate::transaction_preperator::error::Error, - ), - #[error("FailedFinalizePreparationError: {0}")] - FailedFinalizePreparationError( - #[source] crate::transaction_preperator::error::Error, - ), + result + } } - -pub type MessageExecutorResult = Result; diff --git a/magicblock-committor-service/src/message_executor/message_executor_factory.rs b/magicblock-committor-service/src/message_executor/message_executor_factory.rs new file mode 100644 index 000000000..48169536f --- /dev/null +++ b/magicblock-committor-service/src/message_executor/message_executor_factory.rs @@ -0,0 +1,33 @@ +use magicblock_rpc_client::MagicblockRpcClient; +use magicblock_table_mania::TableMania; + +use crate::{ + message_executor::{L1MessageExecutor, MessageExecutor}, + transaction_preperator::transaction_preparator::TransactionPreparatorV1, + ComputeBudgetConfig, +}; + +pub trait MessageExecutorFactory { + type Executor: MessageExecutor; + + fn create_instance(&self) -> Self::Executor; +} + +/// Dummy struct to simplify signature of CommitSchedulerWorker +pub struct L1MessageExecutorFactory { + pub rpc_client: MagicblockRpcClient, + pub table_mania: TableMania, + pub compute_budget_config: ComputeBudgetConfig, +} + +impl MessageExecutorFactory for L1MessageExecutorFactory { + type Executor = L1MessageExecutor; + + fn create_instance(&self) -> Self::Executor { + L1MessageExecutor::::new_v1( + self.rpc_client.clone(), + self.table_mania.clone(), + self.compute_budget_config.clone(), + ) + } +} diff --git a/magicblock-committor-service/src/message_executor/mod.rs b/magicblock-committor-service/src/message_executor/mod.rs new file mode 100644 index 000000000..87a100736 --- /dev/null +++ b/magicblock-committor-service/src/message_executor/mod.rs @@ -0,0 +1,36 @@ +pub mod error; +pub mod message_executor; +pub(crate) mod message_executor_factory; + +use std::collections::HashMap; + +use async_trait::async_trait; +use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; +pub use message_executor::L1MessageExecutor; +use solana_pubkey::Pubkey; +use solana_sdk::signature::Signature; + +use crate::{ + message_executor::error::MessageExecutorResult, + persist::L1MessagesPersisterIface, +}; + +#[derive(Clone, Debug)] +pub struct ExecutionOutput { + /// Commit stage signature + pub commit_signature: Signature, + /// Finalize stage signature + pub finalize_signature: Signature, +} + +#[async_trait] +pub trait MessageExecutor: Send + Sync + 'static { + /// Executes Message on Base layer + /// Returns `ExecutionOutput` or an `Error` + async fn execute( + &self, + l1_message: ScheduledL1Message, + commit_ids: HashMap, + persister: Option

, + ) -> MessageExecutorResult; +} diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 9adb6cef4..e428add72 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -38,7 +38,7 @@ impl std::fmt::Display for PreparatorVersion { } #[async_trait] -pub trait TransactionPreparator { +pub trait TransactionPreparator: Send + Sync + 'static { fn version(&self) -> PreparatorVersion; /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks From f8ff5fc76c9f95790f174e9d9810d0516887132c Mon Sep 17 00:00:00 2001 From: taco-paco Date: Sat, 26 Jul 2025 15:41:09 +0900 Subject: [PATCH 121/199] feat: added initial tests to scheduler_worker --- .../commit_scheduler_inner.rs | 2 +- .../commit_scheduler_worker.rs | 229 +++++++++++++++++- .../src/committor_processor.rs | 1 - .../src/persist/commit_persister.rs | 117 +++++++++ 4 files changed, 341 insertions(+), 8 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index 5f1720e38..2a8bfe399 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -537,7 +537,7 @@ mod edge_cases_test { // Helper function to create test messages #[cfg(test)] -fn create_test_message( +pub(crate) fn create_test_message( id: u64, pubkeys: &[Pubkey], ) -> ScheduledL1MessageWrapper { diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 313369679..7c336b3cb 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -16,7 +16,7 @@ use tokio::sync::{ use crate::{ commit_scheduler::{ - commit_id_tracker::{CommitIdTracker, CommitIdTrackerImpl}, + commit_id_tracker::CommitIdTracker, commit_scheduler_inner::{CommitSchedulerInner, POISONED_INNER_MSG}, db::DB, Error, @@ -24,15 +24,11 @@ use crate::{ message_executor::{ error::MessageExecutorResult, message_executor_factory::MessageExecutorFactory, ExecutionOutput, - L1MessageExecutor, MessageExecutor, + MessageExecutor, }, persist::L1MessagesPersisterIface, - transaction_preperator::transaction_preparator::{ - TransactionPreparator, TransactionPreparatorV1, - }, types::{ScheduledL1MessageWrapper, TriggerType}, utils::ScheduledMessageExt, - ComputeBudgetConfig, }; const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; @@ -330,3 +326,224 @@ where } } } + +/// Worker tests +#[cfg(test)] +mod tests { + use std::sync::Arc; + + use async_trait::async_trait; + use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; + use solana_pubkey::pubkey; + use solana_sdk::{signature::Signature, signer::SignerError}; + use tokio::sync::mpsc; + + use super::*; + use crate::{ + commit_scheduler::{ + commit_id_tracker::{CommitIdTracker, CommitIdTrackerResult}, + commit_scheduler_inner::create_test_message, + db::{DummyDB, DB}, + }, + message_executor::error::{ + Error as ExecutorError, InternalError, MessageExecutorResult, + }, + persist::L1MessagePersister, + }; + + type MockCommitSchedulerWorker = CommitSchedulerWorker< + DummyDB, + L1MessagePersister, + MockMessageExecutorFactory, + MockCommitIdTracker, + >; + fn setup_worker(should_fail: bool) -> ( + mpsc::Sender, + MockCommitSchedulerWorker, + ) { + let (sender, receiver) = mpsc::channel(10); + + let db = Arc::new(DummyDB::new()); + let executor_factory = if !should_fail { + MockMessageExecutorFactory::new() + } else { + MockMessageExecutorFactory::new_failing() + }; + let commit_id_tracker = MockCommitIdTracker::new(); + let worker = CommitSchedulerWorker::new( + db.clone(), + executor_factory, + commit_id_tracker, + None::, + receiver, + ); + + (sender, worker) + } + + #[tokio::test] + async fn test_worker_processes_messages() { + let (sender, worker) = setup_worker(false); + let result_subscriber = worker.spawn(); + let mut result_receiver = result_subscriber.subscribe(); + + // Send a test message + let msg = create_test_message( + 1, + &[pubkey!("1111111111111111111111111111111111111111111")], + ); + sender.send(msg.clone()).await.unwrap(); + + // Verify the message was processed + let result = result_receiver.recv().await.unwrap(); + assert!(result.is_ok()); + let output = result.unwrap(); + assert_eq!(output.id, 1); + } + + #[tokio::test] + async fn test_worker_handles_conflicting_messages() { + let (sender, worker) = setup_worker(false); + let result_subscriber = worker.spawn(); + let mut result_receiver = result_subscriber.subscribe(); + + // Send two conflicting messages + let pubkey = pubkey!("1111111111111111111111111111111111111111111"); + let msg1 = create_test_message(1, &[pubkey]); + let msg2 = create_test_message(2, &[pubkey]); + + sender.send(msg1.clone()).await.unwrap(); + sender.send(msg2.clone()).await.unwrap(); + + // First message should be processed immediately + let result1 = result_receiver.recv().await.unwrap(); + assert!(result1.is_ok()); + assert_eq!(result1.unwrap().id, 1); + + // Second message should be processed after first completes + let result2 = result_receiver.recv().await.unwrap(); + assert!(result2.is_ok()); + assert_eq!(result2.unwrap().id, 2); + } + + #[tokio::test] + async fn test_worker_handles_executor_failure() { + let (sender, worker) = setup_worker(true); + let result_subscriber = worker.spawn(); + let mut result_receiver = result_subscriber.subscribe(); + + // Send a test message that will fail + let msg = create_test_message( + 1, + &[pubkey!("1111111111111111111111111111111111111111111")], + ); + sender.send(msg.clone()).await.unwrap(); + + // Verify the failure was properly reported + let result = result_receiver.recv().await.unwrap(); + let Err((id, err)) = result else { + panic!(); + }; + assert_eq!(id, 1); + assert_eq!( + err.to_string(), + "FailedToCommitError: SignerError: custom error: oops" + ); + } + + #[tokio::test] + async fn test_worker_falls_back_to_db_when_channel_empty() { + let (sender, worker) = setup_worker(false); + + // Add a message to the DB + let msg = create_test_message( + 1, + &[pubkey!("1111111111111111111111111111111111111111111")], + ); + worker.db.store_l1_message(msg.clone()).await.unwrap(); + + // Start worker + let result_subscriber = worker.spawn(); + let mut result_receiver = result_subscriber.subscribe(); + + // Verify the message from DB was processed + let result = result_receiver.recv().await.unwrap(); + assert!(result.is_ok()); + assert_eq!(result.unwrap().id, 1); + } + + // Mock implementations for testing + pub struct MockMessageExecutorFactory { + should_fail: bool, + } + + impl MockMessageExecutorFactory { + pub fn new() -> Self { + Self { should_fail: false } + } + + pub fn new_failing() -> Self { + Self { should_fail: true } + } + } + + impl MessageExecutorFactory for MockMessageExecutorFactory { + type Executor = MockMessageExecutor; + + fn create_instance(&self) -> Self::Executor { + MockMessageExecutor { + should_fail: self.should_fail, + } + } + } + + pub struct MockMessageExecutor { + should_fail: bool, + } + + #[async_trait] + impl MessageExecutor for MockMessageExecutor { + async fn execute( + &self, + l1_message: ScheduledL1Message, + _commit_ids: HashMap, + _persister: Option

, + ) -> MessageExecutorResult { + // TODO: add sleep + if self.should_fail { + Err(ExecutorError::FailedToCommitError { + err: InternalError::SignerError(SignerError::Custom( + "oops".to_string(), + )), + signature: None, + }) + } else { + Ok(ExecutionOutput { + commit_signature: Signature::default(), + finalize_signature: Signature::default(), + }) + } + } + } + + pub struct MockCommitIdTracker; + impl MockCommitIdTracker { + pub fn new() -> Self { + Self + } + } + + #[async_trait] + impl CommitIdTracker for MockCommitIdTracker { + async fn next_commit_ids( + &mut self, + pubkeys: &[Pubkey], + ) -> CommitIdTrackerResult> { + Ok(pubkeys.iter().map(|&k| (k, 1)).collect()) + } + + fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option<&u64> { + None + } + } +} diff --git a/magicblock-committor-service/src/committor_processor.rs b/magicblock-committor-service/src/committor_processor.rs index 7ffd3a4cc..93cd4ea16 100644 --- a/magicblock-committor-service/src/committor_processor.rs +++ b/magicblock-committor-service/src/committor_processor.rs @@ -1,7 +1,6 @@ use std::{collections::HashSet, path::Path, sync::Arc}; use log::*; -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; use solana_pubkey::Pubkey; diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 165370d0c..84215e6bc 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -253,6 +253,123 @@ impl L1MessagesPersisterIface for L1MessagePersister { // } } +/// Blanket implementation for Option +impl L1MessagesPersisterIface for Option { + fn start_l1_messages( + &self, + l1_messages: &[ScheduledL1Message], + ) -> CommitPersistResult<()> { + match self { + Some(persister) => persister.start_l1_messages(l1_messages), + None => Ok(()), + } + } + + fn start_l1_message( + &self, + l1_message: &ScheduledL1Message, + ) -> CommitPersistResult<()> { + match self { + Some(persister) => persister.start_l1_message(l1_message), + None => Ok(()), + } + } + + fn set_commit_id( + &self, + message_id: u64, + pubkey: &Pubkey, + commit_id: u64, + ) -> CommitPersistResult<()> { + match self { + Some(persister) => { + persister.set_commit_id(message_id, pubkey, commit_id) + } + None => Ok(()), + } + } + + fn set_commit_strategy( + &self, + commit_id: u64, + pubkey: &Pubkey, + value: CommitStrategy, + ) -> CommitPersistResult<()> { + match self { + Some(persister) => { + persister.set_commit_strategy(commit_id, pubkey, value) + } + None => Ok(()), + } + } + + fn update_status_by_message( + &self, + message_id: u64, + pubkey: &Pubkey, + status: CommitStatus, + ) -> CommitPersistResult<()> { + match self { + Some(persister) => { + persister.update_status_by_message(message_id, pubkey, status) + } + None => Ok(()), + } + } + + fn update_status_by_commit( + &self, + commit_id: u64, + pubkey: &Pubkey, + status: CommitStatus, + ) -> CommitPersistResult<()> { + match self { + Some(persister) => { + persister.update_status_by_commit(commit_id, pubkey, status) + } + None => Ok(()), + } + } + + fn get_commit_statuses_by_message( + &self, + message_id: u64, + ) -> CommitPersistResult> { + match self { + Some(persister) => { + persister.get_commit_statuses_by_message(message_id) + } + None => Ok(Vec::new()), + } + } + + fn get_commit_status_by_message( + &self, + message_id: u64, + pubkey: &Pubkey, + ) -> CommitPersistResult> { + match self { + Some(persister) => { + persister.get_commit_status_by_message(message_id, pubkey) + } + None => Ok(None), + } + } + + fn get_signatures_by_commit( + &self, + commit_id: u64, + pubkey: &Pubkey, + ) -> CommitPersistResult> { + match self { + Some(persister) => { + persister.get_signatures_by_commit(commit_id, pubkey) + } + None => Ok(None), + } + } +} + #[cfg(test)] mod tests { use magicblock_program::magic_scheduled_l1_message::{ From 4f178cee6402a8af46934e8eb028253173de9520 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Sat, 26 Jul 2025 17:31:39 +0900 Subject: [PATCH 122/199] fix: replace notify with FuturesUnordered --- .../commit_scheduler_worker.rs | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 7c336b3cb..76a292f30 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -2,7 +2,8 @@ use std::{ collections::{HashMap, HashSet}, sync::{Arc, Mutex}, }; - +use futures_util::stream::FuturesUnordered; +use futures_util::StreamExt; use log::{error, info, trace, warn}; use magicblock_program::SentCommit; use magicblock_rpc_client::MagicblockRpcClient; @@ -13,7 +14,7 @@ use tokio::sync::{ broadcast, mpsc, mpsc::error::TryRecvError, Notify, OwnedSemaphorePermit, Semaphore, }; - +use tokio::task::JoinHandle; use crate::{ commit_scheduler::{ commit_id_tracker::CommitIdTracker, @@ -68,7 +69,7 @@ pub(crate) struct CommitSchedulerWorker { receiver: mpsc::Receiver, // TODO(edwin): replace notify. issue: 2 simultaneous notifications - notify: Arc, + running_executors: FuturesUnordered>, executors_semaphore: Arc, inner: Arc>, } @@ -97,7 +98,7 @@ where executor_factory, commit_id_tracker, receiver, - notify: Arc::new(Notify::new()), + running_executors: FuturesUnordered::new(), executors_semaphore: Arc::new(Semaphore::new( NUM_OF_EXECUTORS as usize, )), @@ -169,9 +170,8 @@ where let executor = self.executor_factory.create_instance(); let persister = self.l1_messages_persister.clone(); let inner = self.inner.clone(); - let notify = self.notify.clone(); - tokio::spawn(Self::execute( + let handle = tokio::spawn(Self::execute( executor, persister, l1_message, @@ -179,8 +179,9 @@ where inner, permit, result_sender.clone(), - notify, )); + + self.running_executors.push(handle); } } @@ -204,17 +205,29 @@ where false } }; - let notify = self.notify.clone(); + + let running_executors = &mut self.running_executors; + let receiver = &mut self.receiver; + let db = &self.db; let message = tokio::select! { // Notify polled first to prioritize unblocked messages over new one biased; - _ = notify.notified() => { + Some(result) = running_executors.next() => { + if let Err(err) = result { + error!("Executor failed to complete: {}", err); + }; trace!("Worker executed L1Message, fetching new available one"); self.inner.lock().expect(POISONED_INNER_MSG).pop_next_scheduled_message() }, - result = self.get_new_message(), if can_receive() => { + result = Self::get_new_message(receiver, db), if can_receive() => { let l1_message = result?; self.inner.lock().expect(POISONED_INNER_MSG).schedule(l1_message) + }, + else => { + // Shouldn't be possible + // If no executors spawned -> we can receive + // If can't receive -> there are running executors + unreachable!("next_scheduled_message") } }; @@ -223,17 +236,18 @@ where /// Returns [`ScheduledL1Message`] from external channel async fn get_new_message( - &mut self, + receiver: &mut mpsc::Receiver, + db: &Arc ) -> Result { - match self.receiver.try_recv() { + match receiver.try_recv() { Ok(val) => Ok(val), Err(TryRecvError::Empty) => { // Worker either cleaned-up congested channel and now need to clean-up DB // or we're just waiting on empty channel - if let Some(l1_message) = self.db.pop_l1_message().await? { + if let Some(l1_message) = db.pop_l1_message().await? { Ok(l1_message) } else { - self.receiver.recv().await.ok_or(Error::ChannelClosed) + receiver.recv().await.ok_or(Error::ChannelClosed) } } Err(TryRecvError::Disconnected) => Err(Error::ChannelClosed), @@ -249,7 +263,6 @@ where inner_scheduler: Arc>, execution_permit: OwnedSemaphorePermit, result_sender: broadcast::Sender, - notify: Arc, ) { let result = executor .execute( @@ -273,9 +286,7 @@ where .lock() .expect(POISONED_INNER_MSG) .complete(&l1_message.scheduled_l1_message); - // Notify main loop that executor is done - // This will trigger scheduling next message - notify.notify_waiters(); + // Free worker drop(execution_permit); } From f40a26deb41ab498f7b7e1e39d8383346a83478e Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 28 Jul 2025 12:16:50 +0900 Subject: [PATCH 123/199] feat: addedd sleep into MockExecutor to simulate work --- .../src/commit_scheduler/commit_scheduler_worker.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 76a292f30..493656af7 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -342,7 +342,8 @@ where #[cfg(test)] mod tests { use std::sync::Arc; - + use tokio::time::sleep; + use std::time::Duration; use async_trait::async_trait; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::pubkey; @@ -520,7 +521,9 @@ mod tests { _commit_ids: HashMap, _persister: Option

, ) -> MessageExecutorResult { - // TODO: add sleep + // Simulate some work + sleep(Duration::from_millis(50)).await; + if self.should_fail { Err(ExecutorError::FailedToCommitError { err: InternalError::SignerError(SignerError::Custom( From 8176edc3a2342551d165f3a2c259327e263d1fd4 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 28 Jul 2025 13:15:20 +0900 Subject: [PATCH 124/199] feat: SchedulerWorker tests --- Cargo.lock | 1 + magicblock-committor-service/Cargo.toml | 1 + .../commit_scheduler_worker.rs | 284 ++++++++++++++++-- 3 files changed, 265 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a81dfdea2..abf5081bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3826,6 +3826,7 @@ dependencies = [ "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", + "rand 0.8.5", "rusqlite", "solana-account", "solana-pubkey", diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index 724274395..79bd38040 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -50,6 +50,7 @@ magicblock-table-mania = { workspace = true, features = [ ] } # program-flexi-counter = { workspace = true, features = ["no-entrypoint"] } tokio = { workspace = true, features = ["rt", "macros"] } +rand = { workspace = true } [features] default = [] diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 493656af7..f3f2da5c3 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -2,19 +2,22 @@ use std::{ collections::{HashMap, HashSet}, sync::{Arc, Mutex}, }; -use futures_util::stream::FuturesUnordered; -use futures_util::StreamExt; + +use futures_util::{stream::FuturesUnordered, StreamExt}; use log::{error, info, trace, warn}; use magicblock_program::SentCommit; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; use solana_sdk::transaction::Transaction; -use tokio::sync::{ - broadcast, mpsc, mpsc::error::TryRecvError, Notify, OwnedSemaphorePermit, - Semaphore, +use tokio::{ + sync::{ + broadcast, mpsc, mpsc::error::TryRecvError, Notify, + OwnedSemaphorePermit, Semaphore, + }, + task::JoinHandle, }; -use tokio::task::JoinHandle; + use crate::{ commit_scheduler::{ commit_id_tracker::CommitIdTracker, @@ -33,6 +36,8 @@ use crate::{ }; const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; +// Number of executors that can send messages in parallel to L1 +const MAX_EXECUTORS: u8 = 50; // TODO(edwin): rename #[derive(Clone)] @@ -89,9 +94,6 @@ where l1_messages_persister: Option

, receiver: mpsc::Receiver, ) -> Self { - // Number of executors that can send messages in parallel to L1 - const NUM_OF_EXECUTORS: u8 = 50; - Self { db, l1_messages_persister, @@ -100,7 +102,7 @@ where receiver, running_executors: FuturesUnordered::new(), executors_semaphore: Arc::new(Semaphore::new( - NUM_OF_EXECUTORS as usize, + MAX_EXECUTORS as usize, )), inner: Arc::new(Mutex::new(CommitSchedulerInner::new())), } @@ -237,7 +239,7 @@ where /// Returns [`ScheduledL1Message`] from external channel async fn get_new_message( receiver: &mut mpsc::Receiver, - db: &Arc + db: &Arc, ) -> Result { match receiver.try_recv() { Ok(val) => Ok(val), @@ -341,14 +343,19 @@ where /// Worker tests #[cfg(test)] mod tests { - use std::sync::Arc; - use tokio::time::sleep; - use std::time::Duration; + use std::{ + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::Duration, + }; + use async_trait::async_trait; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::pubkey; use solana_sdk::{signature::Signature, signer::SignerError}; - use tokio::sync::mpsc; + use tokio::{sync::mpsc, time::sleep}; use super::*; use crate::{ @@ -369,11 +376,13 @@ mod tests { MockMessageExecutorFactory, MockCommitIdTracker, >; - fn setup_worker(should_fail: bool) -> ( + fn setup_worker( + should_fail: bool, + ) -> ( mpsc::Sender, MockCommitSchedulerWorker, ) { - let (sender, receiver) = mpsc::channel(10); + let (sender, receiver) = mpsc::channel(1000); let db = Arc::new(DummyDB::new()); let executor_factory = if !should_fail { @@ -484,18 +493,210 @@ mod tests { assert_eq!(result.unwrap().id, 1); } + /// Tests multiple blocking messages being sent at the same time + #[tokio::test] + async fn test_high_throughput_message_processing() { + const NUM_MESSAGES: usize = 20; + + let (sender, mut worker) = setup_worker(false); + + let active_tasks = Arc::new(AtomicUsize::new(0)); + let max_concurrent = Arc::new(AtomicUsize::new(0)); + worker + .executor_factory + .with_concurrency_tracking(&active_tasks, &max_concurrent); + + let result_subscriber = worker.spawn(); + let mut result_receiver = result_subscriber.subscribe(); + + // Send a flood of messages + for i in 0..NUM_MESSAGES { + let msg = create_test_message( + i as u64, + &[pubkey!("1111111111111111111111111111111111111111111")], + ); + sender.send(msg).await.unwrap(); + } + + // Process results and verify constraints + let mut completed = 0; + while completed < NUM_MESSAGES { + let result = result_receiver.recv().await.unwrap(); + assert!(result.is_ok()); + // Tasks are blocking so will complete sequentially + assert_eq!(result.unwrap().id, completed as u64); + completed += 1; + } + + // Verify we didn't exceed concurrency limits + let max_observed = max_concurrent.load(Ordering::SeqCst); + assert_eq!( + max_observed, 1, + "Blocking messages can't execute in parallel!" + ); + } + + /// Tests that errors from executor propagated gracefully + #[tokio::test] + async fn test_multiple_failures() { + let (sender, worker) = setup_worker(true); // Worker that always fails + let result_subscriber = worker.spawn(); + let mut result_receiver = result_subscriber.subscribe(); + + // Send several messages that will fail + const NUM_FAILURES: usize = 10; + for i in 0..NUM_FAILURES { + let msg = create_test_message( + i as u64, + &[pubkey!("1111111111111111111111111111111111111111111")], + ); + sender.send(msg).await.unwrap(); + } + + // Verify all failures are processed and semaphore slots released + for _ in 0..NUM_FAILURES { + let result = result_receiver.recv().await.unwrap(); + assert!(result.is_err()); + } + } + + #[tokio::test] + async fn test_non_blocking_messages() { + const NUM_MESSAGES: u64 = 200; + + let (sender, mut worker) = setup_worker(false); + + let active_tasks = Arc::new(AtomicUsize::new(0)); + let max_concurrent = Arc::new(AtomicUsize::new(0)); + worker + .executor_factory + .with_concurrency_tracking(&active_tasks, &max_concurrent); + + let result_subscriber = worker.spawn(); + let mut result_receiver = result_subscriber.subscribe(); + + // Send messages with unique keys (non-blocking) + let mut received_ids = HashSet::new(); + for i in 0..NUM_MESSAGES { + let unique_pubkey = Pubkey::new_unique(); // Each message gets unique key + let msg = create_test_message(i, &[unique_pubkey]); + + received_ids.insert(i); + sender.send(msg).await.unwrap(); + } + + // Process results + let mut completed = 0; + while completed < NUM_MESSAGES { + let result = result_receiver.recv().await.unwrap(); + assert!(result.is_ok()); + + // Message has to be present in set + let id = result.unwrap().id; + assert!(received_ids.remove(&id)); + + completed += 1; + } + // Set has to be empty + assert!(received_ids.is_empty()); + + // Verify concurrency + let max_observed = max_concurrent.load(Ordering::SeqCst); + assert!( + max_observed <= MAX_EXECUTORS as usize, + "Max concurrency {} exceeded limit {}", + max_observed, + MAX_EXECUTORS + ); + println!("max_observed: {}", max_observed); + // Likely even max_observed == 50 + assert!( + max_observed > 1, + "Non-blocking messages should execute in parallel" + ); + } + + #[tokio::test] + async fn test_mixed_blocking_non_blocking() { + const NUM_MESSAGES: usize = 100; + // 30% blocking messages + const BLOCKING_RATIO: f32 = 0.3; + + let (sender, mut worker) = setup_worker(false); + + let active_tasks = Arc::new(AtomicUsize::new(0)); + let max_concurrent = Arc::new(AtomicUsize::new(0)); + worker + .executor_factory + .with_concurrency_tracking(&active_tasks, &max_concurrent); + + let result_subscriber = worker.spawn(); + let mut result_receiver = result_subscriber.subscribe(); + + // Shared key for blocking messages + let blocking_key = + pubkey!("1111111111111111111111111111111111111111111"); + // Send mixed messages + for i in 0..NUM_MESSAGES { + let is_blocking = rand::random::() < BLOCKING_RATIO; + let pubkeys = if is_blocking { + vec![blocking_key] + } else { + vec![Pubkey::new_unique()] + }; + + let msg = create_test_message(i as u64, &pubkeys); + sender.send(msg).await.unwrap(); + } + + // Process results + let mut completed = 0; + while completed < NUM_MESSAGES { + let result = result_receiver.recv().await.unwrap(); + assert!(result.is_ok()); + completed += 1; + } + + // Verify concurrency was between 1 and MAX_CONCURRENCY + let max_observed = max_concurrent.load(Ordering::SeqCst); + assert!( + max_observed >= 1 && max_observed <= MAX_EXECUTORS as usize, + "Concurrency {} outside expected range", + max_observed + ); + } + // Mock implementations for testing pub struct MockMessageExecutorFactory { should_fail: bool, + active_tasks: Option>, + max_concurrent: Option>, } impl MockMessageExecutorFactory { pub fn new() -> Self { - Self { should_fail: false } + Self { + should_fail: false, + active_tasks: None, + max_concurrent: None, + } } pub fn new_failing() -> Self { - Self { should_fail: true } + Self { + should_fail: true, + active_tasks: None, + max_concurrent: None, + } + } + + pub fn with_concurrency_tracking( + &mut self, + active_tasks: &Arc, + max_concurrent: &Arc, + ) { + self.active_tasks = Some(active_tasks.clone()); + self.max_concurrent = Some(max_concurrent.clone()); } } @@ -505,12 +706,47 @@ mod tests { fn create_instance(&self) -> Self::Executor { MockMessageExecutor { should_fail: self.should_fail, + active_tasks: self.active_tasks.clone(), + max_concurrent: self.max_concurrent.clone(), } } } pub struct MockMessageExecutor { should_fail: bool, + active_tasks: Option>, + max_concurrent: Option>, + } + + impl MockMessageExecutor { + fn on_task_started(&self) { + if let (Some(active), Some(max)) = + (&self.active_tasks, &self.max_concurrent) + { + // Increment active task count + let current = active.fetch_add(1, Ordering::SeqCst) + 1; + + // Update max concurrent if needed + let mut observed_max = max.load(Ordering::SeqCst); + while current > observed_max { + match max.compare_exchange_weak( + observed_max, + current, + Ordering::SeqCst, + Ordering::SeqCst, + ) { + Ok(_) => break, + Err(x) => observed_max = x, + } + } + } + } + + fn on_task_finished(&self) { + if let Some(active) = &self.active_tasks { + active.fetch_sub(1, Ordering::SeqCst); + } + } } #[async_trait] @@ -521,10 +757,12 @@ mod tests { _commit_ids: HashMap, _persister: Option

, ) -> MessageExecutorResult { + self.on_task_started(); + // Simulate some work sleep(Duration::from_millis(50)).await; - if self.should_fail { + let result = if self.should_fail { Err(ExecutorError::FailedToCommitError { err: InternalError::SignerError(SignerError::Custom( "oops".to_string(), @@ -536,7 +774,11 @@ mod tests { commit_signature: Signature::default(), finalize_signature: Signature::default(), }) - } + }; + + self.on_task_finished(); + + result } } From 9348ded1c022fbc44777455d8af25370d7e2436f Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 28 Jul 2025 13:25:11 +0900 Subject: [PATCH 125/199] refactor: some warning cleanup --- magicblock-committor-service/Cargo.toml | 1 - .../src/commit_scheduler.rs | 1 - .../commit_scheduler/commit_scheduler_worker.rs | 15 ++++++--------- .../src/commit_scheduler/executor_pool.rs | 17 ----------------- .../src/message_executor/message_executor.rs | 5 ++--- magicblock-committor-service/src/persist/db.rs | 8 ++++---- .../transaction_preparator.rs | 8 ++------ 7 files changed, 14 insertions(+), 41 deletions(-) delete mode 100644 magicblock-committor-service/src/commit_scheduler/executor_pool.rs diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index 79bd38040..1a4fe982a 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -48,7 +48,6 @@ lazy_static = { workspace = true } magicblock-table-mania = { workspace = true, features = [ "randomize_lookup_table_slot", ] } -# program-flexi-counter = { workspace = true, features = ["no-entrypoint"] } tokio = { workspace = true, features = ["rt", "macros"] } rand = { workspace = true } diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index 5d5b65977..0f98c9586 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -2,7 +2,6 @@ mod commit_id_tracker; pub(crate) mod commit_scheduler_inner; mod commit_scheduler_worker; pub(crate) mod db; // TODO(edwin): define visibility -mod executor_pool; use std::sync::Arc; diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index f3f2da5c3..88fc0797c 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -6,14 +6,12 @@ use std::{ use futures_util::{stream::FuturesUnordered, StreamExt}; use log::{error, info, trace, warn}; use magicblock_program::SentCommit; -use magicblock_rpc_client::MagicblockRpcClient; -use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; use solana_sdk::transaction::Transaction; use tokio::{ sync::{ - broadcast, mpsc, mpsc::error::TryRecvError, Notify, - OwnedSemaphorePermit, Semaphore, + broadcast, mpsc, mpsc::error::TryRecvError, OwnedSemaphorePermit, + Semaphore, }, task::JoinHandle, }; @@ -36,7 +34,7 @@ use crate::{ }; const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; -// Number of executors that can send messages in parallel to L1 +/// Max number of executors that can send messages in parallel to L1 const MAX_EXECUTORS: u8 = 50; // TODO(edwin): rename @@ -68,15 +66,14 @@ impl ResultSubscriber { pub(crate) struct CommitSchedulerWorker { db: Arc, - l1_messages_persister: Option

, executor_factory: F, commit_id_tracker: C, + l1_messages_persister: Option

, receiver: mpsc::Receiver, - // TODO(edwin): replace notify. issue: 2 simultaneous notifications + inner: Arc>, running_executors: FuturesUnordered>, executors_semaphore: Arc, - inner: Arc>, } impl CommitSchedulerWorker @@ -474,7 +471,7 @@ mod tests { #[tokio::test] async fn test_worker_falls_back_to_db_when_channel_empty() { - let (sender, worker) = setup_worker(false); + let (_, worker) = setup_worker(false); // Add a message to the DB let msg = create_test_message( diff --git a/magicblock-committor-service/src/commit_scheduler/executor_pool.rs b/magicblock-committor-service/src/commit_scheduler/executor_pool.rs deleted file mode 100644 index 20e014048..000000000 --- a/magicblock-committor-service/src/commit_scheduler/executor_pool.rs +++ /dev/null @@ -1,17 +0,0 @@ -// TODO: how executiong works? -// case - No available worker -// We can't process any messages - waiting - -// Say worker finished -// Messages still blocked by each other -// We move to get message from channel -// We stuck -// If we get worker without - -// Flow: -// 1. check if there's available message to be executed -// 2. Fetch it and wait for available worker to execute it - -// If no messages workers are idle -// If more tham one free, then we will launch woker and pick another -// on next iteration diff --git a/magicblock-committor-service/src/message_executor/message_executor.rs b/magicblock-committor-service/src/message_executor/message_executor.rs index d7039c985..76b56f021 100644 --- a/magicblock-committor-service/src/message_executor/message_executor.rs +++ b/magicblock-committor-service/src/message_executor/message_executor.rs @@ -6,15 +6,14 @@ use magicblock_program::{ validator::validator_authority, }; use magicblock_rpc_client::{ - MagicBlockRpcClientError, MagicBlockSendTransactionConfig, - MagicblockRpcClient, + MagicBlockSendTransactionConfig, MagicblockRpcClient, }; use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; use solana_sdk::{ message::VersionedMessage, signature::{Keypair, Signature}, - signer::{Signer, SignerError}, + signer::Signer, transaction::VersionedTransaction, }; diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 80052e765..f2c87ef01 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -590,7 +590,7 @@ mod tests { // Helper to create a test database fn setup_test_db() -> (CommittsDb, NamedTempFile) { let temp_file = NamedTempFile::new().unwrap(); - let mut db = CommittsDb::new(temp_file.path()).unwrap(); + let db = CommittsDb::new(temp_file.path()).unwrap(); db.create_commit_status_table().unwrap(); (db, temp_file) @@ -654,7 +654,7 @@ mod tests { #[test] fn test_set_commit_id() { let (mut db, _file) = setup_test_db(); - let mut row = create_test_row(1, 0); + let row = create_test_row(1, 0); db.insert_commit_status_rows(&[row.clone()]).unwrap(); // Update commit_id @@ -682,7 +682,7 @@ mod tests { #[test] fn test_update_status_by_commit() { let (mut db, _file) = setup_test_db(); - let mut row = create_test_row(1, 100); // Set commit_id to 100 + let row = create_test_row(1, 100); // Set commit_id to 100 db.insert_commit_status_rows(&[row.clone()]).unwrap(); let new_status = CommitStatus::Succeeded(( @@ -702,7 +702,7 @@ mod tests { #[test] fn test_set_commit_strategy() { let (mut db, _file) = setup_test_db(); - let mut row = create_test_row(1, 100); + let row = create_test_row(1, 100); db.insert_commit_status_rows(&[row.clone()]).unwrap(); let new_strategy = CommitStrategy::FromBuffer; diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index e428add72..2cdc86056 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -69,8 +69,6 @@ pub trait TransactionPreparator: Send + Sync + 'static { /// It creates TXs using current per account commit/finalize pub struct TransactionPreparatorV1 { delivery_preparator: DeliveryPreparator, - rpc_client: MagicblockRpcClient, - table_mania: TableMania, // TODO(edwin): Arc? } impl TransactionPreparatorV1 { @@ -80,13 +78,11 @@ impl TransactionPreparatorV1 { compute_budget_config: ComputeBudgetConfig, ) -> Self { let delivery_preparator = DeliveryPreparator::new( - rpc_client.clone(), - table_mania.clone(), + rpc_client, + table_mania, compute_budget_config, ); Self { - rpc_client, - table_mania, delivery_preparator, } } From c0a8da88f1a058aada8650b5ab64f4df6ed69b0e Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 28 Jul 2025 15:24:29 +0900 Subject: [PATCH 126/199] feat: finished implementation of CommitIdTracker --- magicblock-api/src/tickers.rs | 1 - .../src/commit_scheduler/commit_id_tracker.rs | 98 +++++++++++++++++-- .../src/magic_scheduled_l1_message.rs | 2 +- 3 files changed, 93 insertions(+), 8 deletions(-) diff --git a/magicblock-api/src/tickers.rs b/magicblock-api/src/tickers.rs index 8cccaae6f..bd778c6fa 100644 --- a/magicblock-api/src/tickers.rs +++ b/magicblock-api/src/tickers.rs @@ -12,7 +12,6 @@ use magicblock_accounts::{ AccountsManager, ScheduledCommitsProcessor, }; use magicblock_bank::bank::Bank; -use magicblock_committor_service::CommittorService; use magicblock_core::magic_program; use magicblock_ledger::Ledger; use magicblock_metrics::metrics; diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs index 5e2d2896b..cb77981c8 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs @@ -1,5 +1,9 @@ -use std::{collections::HashMap, num::NonZeroUsize}; +use std::{collections::HashMap, num::NonZeroUsize, time::Duration}; +use dlp::{ + delegation_metadata_seeds_from_delegated_account, state::DelegationMetadata, +}; +use log::{error, warn}; use lru::LruCache; use magicblock_rpc_client::{ MagicBlockRpcClientError, MagicBlockRpcClientResult, MagicblockRpcClient, @@ -32,13 +36,89 @@ impl CommitIdTrackerImpl { } } + /// Fetches commit_ids with some num of retries + pub async fn fetch_commit_ids_with_retries( + rpc_client: &MagicblockRpcClient, + pubkeys: &[Pubkey], + num_retries: NonZeroUsize, + ) -> CommitIdTrackerResult> { + if pubkeys.is_empty() { + return Ok(Vec::new()); + } + + let mut last_err = Error::MetadataNotFoundError(pubkeys[0]); + for i in 0..num_retries.get() { + match Self::fetch_commit_ids(rpc_client, pubkeys).await { + Ok(value) => return Ok(value), + err @ Err(Error::InvalidAccountDataError(_)) => return err, + err @ Err(Error::MetadataNotFoundError(_)) => return err, + Err(Error::MagicBlockRpcClientError(err)) => { + // TODO: RPC error handlings should be more robus + last_err = Error::MagicBlockRpcClientError(err) + } + }; + + warn!("Fetch commit last error: {}, attempt: {}", last_err, i); + tokio::time::sleep(Duration::from_millis(50)).await; + } + + Err(last_err) + } + /// Fetches commit_ids using RPC /// Note: remove duplicates prior to calling pub async fn fetch_commit_ids( rpc_client: &MagicblockRpcClient, pubkeys: &[Pubkey], - ) -> MagicBlockRpcClientResult> { - todo!() + ) -> CommitIdTrackerResult> { + // Early return if no pubkeys to process + if pubkeys.is_empty() { + return Ok(Vec::new()); + } + + // Find PDA accounts for each pubkey + let pda_accounts = pubkeys + .iter() + .map(|delegated_account| { + Pubkey::find_program_address( + delegation_metadata_seeds_from_delegated_account!( + delegated_account + ), + &dlp::id(), + ) + .0 + }) + .collect::>(); + + // Fetch account data for all PDAs + let accounts_data = rpc_client + .get_multiple_accounts(&pda_accounts, None) + .await?; + + // Process each account data to extract last_update_external_slot + let commit_ids = accounts_data + .into_iter() + .enumerate() + .map(|(i, account)| { + let pubkey = if let Some(pubkey) = pda_accounts.get(i) { + *pubkey + } else { + error!("invalid pubkey index in pda_accounts: {i}"); + Pubkey::new_unique() + }; + let account = account + .ok_or(Error::MetadataNotFoundError(pda_accounts[i]))?; + let metadata = + DelegationMetadata::try_from_bytes_with_discriminator( + &account.data, + ) + .map_err(Error::InvalidAccountDataError(pubkey))?; + + Ok(metadata.last_update_external_slot) + }) + .collect::, _>>()?; + + Ok(commit_ids) } } @@ -50,6 +130,9 @@ impl CommitIdTracker for CommitIdTrackerImpl { &mut self, pubkeys: &[Pubkey], ) -> CommitIdTrackerResult> { + const NUM_FETCH_RETRIES: NonZeroUsize = + unsafe { NonZeroUsize::new_unchecked(5) }; + let mut result = HashMap::new(); let mut to_request = Vec::new(); for pubkey in pubkeys { @@ -71,7 +154,8 @@ impl CommitIdTracker for CommitIdTrackerImpl { to_request.dedup(); let remaining_ids = - Self::fetch_commit_ids(&self.rpc_client, &to_request).await?; + Self::fetch_commit_ids_with_retries(&self.rpc_client, &to_request, NUM_FETCH_RETRIES) + .await?; to_request .iter() .zip(remaining_ids) @@ -91,8 +175,10 @@ impl CommitIdTracker for CommitIdTrackerImpl { #[derive(thiserror::Error, Debug)] pub enum Error { - #[error("Failed to get keys: {0:?}")] - GetCommitIdsError(Vec), + #[error("Metadata not found for: {0}")] + MetadataNotFoundError(Pubkey), + #[error("InvalidAccountDataError for: {0}")] + InvalidAccountDataError(Pubkey), #[error("MagicBlockRpcClientError: {0}")] MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), } diff --git a/programs/magicblock/src/magic_scheduled_l1_message.rs b/programs/magicblock/src/magic_scheduled_l1_message.rs index 9812b18f4..31247462a 100644 --- a/programs/magicblock/src/magic_scheduled_l1_message.rs +++ b/programs/magicblock/src/magic_scheduled_l1_message.rs @@ -216,7 +216,7 @@ impl L1Action { // We need to ensure that action was authorized by legit owner let authority_pubkey = get_instruction_pubkey_with_idx( context.transaction_context, - args.destination_program as u16, + args.escrow_authority as u16, )?; if !context.signers.contains(authority_pubkey) { ic_msg!( From 7be6f6bf89e8e6242b792b725d304d53a37447a6 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 28 Jul 2025 15:47:31 +0900 Subject: [PATCH 127/199] raw --- .../src/commit_scheduler/commit_id_tracker.rs | 23 ++++++++++++++----- .../commit_scheduler_worker.rs | 5 +--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs index cb77981c8..3ac9772a2 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs @@ -133,6 +133,10 @@ impl CommitIdTracker for CommitIdTrackerImpl { const NUM_FETCH_RETRIES: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(5) }; + if pubkeys.is_empty() { + return Ok(HashMap::new()); + } + let mut result = HashMap::new(); let mut to_request = Vec::new(); for pubkey in pubkeys { @@ -141,9 +145,8 @@ impl CommitIdTracker for CommitIdTrackerImpl { continue; } - if let Some(id) = self.cache.get_mut(pubkey) { - *id += 1; - result.insert(*pubkey, *id); + if let Some(id) = self.cache.get(pubkey) { + result.insert(*pubkey, *id + 1); } else { to_request.push(*pubkey); } @@ -153,9 +156,17 @@ impl CommitIdTracker for CommitIdTrackerImpl { to_request.sort(); to_request.dedup(); - let remaining_ids = - Self::fetch_commit_ids_with_retries(&self.rpc_client, &to_request, NUM_FETCH_RETRIES) - .await?; + let remaining_ids = Self::fetch_commit_ids_with_retries( + &self.rpc_client, + &to_request, + NUM_FETCH_RETRIES, + ) + .await?; + + // Avoid changes to LRU until all data is ready - atomic update + result.iter().for_each(|(pubkey, id)| { + self.cache.push(*pubkey, *id); + }); to_request .iter() .zip(remaining_ids) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 88fc0797c..a93ec2b72 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -151,10 +151,7 @@ where commit_ids .iter() .for_each(|(pubkey, commit_id) | { - let Some(persistor) = &self.l1_messages_persister else { - return; - }; - if let Err(err) = persistor.set_commit_id(l1_message.scheduled_l1_message.id, pubkey, *commit_id) { + if let Err(err) = self.l1_messages_persister.set_commit_id(l1_message.scheduled_l1_message.id, pubkey, *commit_id) { error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.scheduled_l1_message.id, pubkey, err); } }); From faa5dd654f5fb9c660e756adf80007d7c3a18a4f Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 28 Jul 2025 16:38:50 +0900 Subject: [PATCH 128/199] refactor: moved CommitIdTracker into executor --- .../src/commit_scheduler/commit_id_tracker.rs | 76 ++++++++++------ .../commit_scheduler_worker.rs | 87 ++++++++++++------- .../src/message_executor/message_executor.rs | 2 +- .../src/persist/types/commit_status.rs | 16 ++-- .../src/tasks/task_builder.rs | 27 ++++-- .../src/tasks/tasks.rs | 24 +++-- magicblock-committor-service/src/utils.rs | 21 +++++ 7 files changed, 171 insertions(+), 82 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs index 3ac9772a2..43deaec16 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs @@ -1,4 +1,9 @@ -use std::{collections::HashMap, num::NonZeroUsize, time::Duration}; +use std::{ + collections::HashMap, + num::NonZeroUsize, + sync::{Arc, Mutex}, + time::Duration, +}; use dlp::{ delegation_metadata_seeds_from_delegated_account, state::DelegationMetadata, @@ -17,12 +22,15 @@ pub trait CommitIdTracker { pubkeys: &[Pubkey], ) -> CommitIdTrackerResult>; - fn peek_commit_id(&self, pubkey: &Pubkey) -> Option<&u64>; + fn peek_commit_id(&self, pubkey: &Pubkey) -> Option; } +const MUTEX_POISONED_MSG: &str = "CommitIdTrackerImpl mutex poisoned!"; + +#[derive(Clone)] pub struct CommitIdTrackerImpl { rpc_client: MagicblockRpcClient, - cache: LruCache, + cache: Arc>>, } impl CommitIdTrackerImpl { @@ -32,7 +40,7 @@ impl CommitIdTrackerImpl { Self { rpc_client, - cache: LruCache::new(CACHE_SIZE), + cache: Arc::new(Mutex::new(LruCache::new(CACHE_SIZE))), } } @@ -112,9 +120,9 @@ impl CommitIdTrackerImpl { DelegationMetadata::try_from_bytes_with_discriminator( &account.data, ) - .map_err(Error::InvalidAccountDataError(pubkey))?; + .map_err(|_| Error::InvalidAccountDataError(pubkey))?; - Ok(metadata.last_update_external_slot) + Ok::<_, Error>(metadata.last_update_external_slot) }) .collect::, _>>()?; @@ -139,19 +147,28 @@ impl CommitIdTracker for CommitIdTrackerImpl { let mut result = HashMap::new(); let mut to_request = Vec::new(); - for pubkey in pubkeys { - // in case already inserted - if result.contains_key(pubkey) { - continue; - } + // Lock cache and extract whatever ids we can + { + let mut cache = self.cache.lock().expect(MUTEX_POISONED_MSG); + for pubkey in pubkeys { + // in case already inserted + if result.contains_key(pubkey) { + continue; + } - if let Some(id) = self.cache.get(pubkey) { - result.insert(*pubkey, *id + 1); - } else { - to_request.push(*pubkey); + if let Some(id) = cache.get(pubkey) { + result.insert(*pubkey, *id + 1); + } else { + to_request.push(*pubkey); + } } } + // If all in cache - great! return + if to_request.is_empty() { + return Ok(result); + } + // Remove duplicates to_request.sort(); to_request.dedup(); @@ -163,24 +180,29 @@ impl CommitIdTracker for CommitIdTrackerImpl { ) .await?; - // Avoid changes to LRU until all data is ready - atomic update - result.iter().for_each(|(pubkey, id)| { - self.cache.push(*pubkey, *id); - }); - to_request - .iter() - .zip(remaining_ids) - .for_each(|(pubkey, id)| { - result.insert(*pubkey, id + 1); - self.cache.push(*pubkey, id + 1); + // We don't care if anything changed in between with cache - just update and return our ids. + { + let mut cache = self.cache.lock().expect(MUTEX_POISONED_MSG); + // Avoid changes to LRU until all data is ready - atomic update + result.iter().for_each(|(pubkey, id)| { + cache.push(*pubkey, *id); }); + to_request + .iter() + .zip(remaining_ids) + .for_each(|(pubkey, id)| { + result.insert(*pubkey, id + 1); + cache.push(*pubkey, id + 1); + }); + } Ok(result) } /// Returns current commit id without raising priority - fn peek_commit_id(&self, pubkey: &Pubkey) -> Option<&u64> { - self.cache.peek(pubkey) + fn peek_commit_id(&self, pubkey: &Pubkey) -> Option { + let cache = self.cache.lock().expect(MUTEX_POISONED_MSG); + cache.peek(pubkey).copied() } } diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index a93ec2b72..f75473a8d 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -28,9 +28,9 @@ use crate::{ message_executor_factory::MessageExecutorFactory, ExecutionOutput, MessageExecutor, }, - persist::L1MessagesPersisterIface, + persist::{CommitStatus, L1MessagesPersisterIface}, types::{ScheduledL1MessageWrapper, TriggerType}, - utils::ScheduledMessageExt, + utils::{persist_status_update_by_message_set, ScheduledMessageExt}, }; const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; @@ -82,7 +82,7 @@ where P: L1MessagesPersisterIface, F: MessageExecutorFactory + Send + Sync + 'static, E: MessageExecutor, - C: CommitIdTracker + Send + Sync + 'static, + C: CommitIdTracker + Clone + Send + Sync + 'static, { pub fn new( db: Arc, @@ -138,40 +138,17 @@ where .await .expect(SEMAPHORE_CLOSED_MSG); - // Prepare data for execution - let commit_ids = if let Some(pubkeys) = - l1_message.scheduled_l1_message.get_committed_pubkeys() - { - let commit_ids = self - .commit_id_tracker - .next_commit_ids(&pubkeys) - .await - .unwrap(); - // Persist data - commit_ids - .iter() - .for_each(|(pubkey, commit_id) | { - if let Err(err) = self.l1_messages_persister.set_commit_id(l1_message.scheduled_l1_message.id, pubkey, *commit_id) { - error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.scheduled_l1_message.id, pubkey, err); - } - }); - - commit_ids - } else { - // Pure L1Action, no commit ids used - HashMap::new() - }; - // Spawn executor let executor = self.executor_factory.create_instance(); let persister = self.l1_messages_persister.clone(); + let commit_id_tracker = self.commit_id_tracker.clone(); let inner = self.inner.clone(); let handle = tokio::spawn(Self::execute( executor, persister, l1_message, - commit_ids, + commit_id_tracker, inner, permit, result_sender.clone(), @@ -255,11 +232,58 @@ where executor: E, persister: Option

, l1_message: ScheduledL1MessageWrapper, - commit_ids: HashMap, + mut commit_id_tracker: C, inner_scheduler: Arc>, execution_permit: OwnedSemaphorePermit, result_sender: broadcast::Sender, ) { + // Prepare commit ids for execution + let commit_ids = if let Some(pubkeys) = + l1_message.scheduled_l1_message.get_committed_pubkeys() + { + let commit_ids = commit_id_tracker.next_commit_ids(&pubkeys).await; + + match commit_ids { + Ok(value) => value, + Err(err) => { + // At this point this is unrecoverable. + // We just skip for now and pretend this message didn't exist + error!("Failed to fetch commit nonces for message: {:?}, error: {:?}", l1_message, err); + + let message_id = l1_message.scheduled_l1_message.id; + info!( + "Message has to be committed manually: {}", + message_id + ); + // Persist as Failed in DB + persist_status_update_by_message_set( + &persister, + message_id, + &pubkeys, + CommitStatus::Failed, + ); + inner_scheduler + .lock() + .expect(POISONED_INNER_MSG) + .complete(&l1_message.scheduled_l1_message); + drop(execution_permit); + return; + } + } + } else { + // Pure L1Action, no commit ids used + HashMap::new() + }; + + // Persist data + commit_ids + .iter() + .for_each(|(pubkey, commit_id) | { + if let Err(err) = persister.set_commit_id(l1_message.scheduled_l1_message.id, pubkey, *commit_id) { + error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.scheduled_l1_message.id, pubkey, err); + } + }); + let result = executor .execute( l1_message.scheduled_l1_message.clone(), @@ -468,7 +492,7 @@ mod tests { #[tokio::test] async fn test_worker_falls_back_to_db_when_channel_empty() { - let (_, worker) = setup_worker(false); + let (_sender, worker) = setup_worker(false); // Add a message to the DB let msg = create_test_message( @@ -776,6 +800,7 @@ mod tests { } } + #[derive(Clone)] pub struct MockCommitIdTracker; impl MockCommitIdTracker { pub fn new() -> Self { @@ -792,7 +817,7 @@ mod tests { Ok(pubkeys.iter().map(|&k| (k, 1)).collect()) } - fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option<&u64> { + fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option { None } } diff --git a/magicblock-committor-service/src/message_executor/message_executor.rs b/magicblock-committor-service/src/message_executor/message_executor.rs index 76b56f021..44f6af8dc 100644 --- a/magicblock-committor-service/src/message_executor/message_executor.rs +++ b/magicblock-committor-service/src/message_executor/message_executor.rs @@ -198,7 +198,7 @@ where Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::MissingCommitIdError(_))) => { commit_ids.iter().for_each(|(pubkey, commit_id)| { // Invalid task - let update_status = CommitStatus::Failed(*commit_id); + let update_status = CommitStatus::Failed; persist_status_update(persistor, pubkey, *commit_id, update_status) }); }, diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index 842f0b75a..04b15de2d 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -2,7 +2,7 @@ use std::fmt; use solana_sdk::signature::Signature; -use crate::persist::error::CommitPersistError; +use crate::persist::{error::CommitPersistError, CommitStatus::Failed}; /// The status of a committed account. #[derive(Debug, Clone, PartialEq, Eq)] @@ -11,7 +11,7 @@ pub enum CommitStatus { Pending, /// No part of the commit pipeline succeeded. /// The commit for this account needs to be restarted from scratch. - Failed(u64), + Failed, /// The buffer and chunks account were initialized, but could either not /// be retrieved or deserialized. It is recommended to fully re-initialize /// them on retry. @@ -42,8 +42,8 @@ impl fmt::Display for CommitStatus { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { CommitStatus::Pending => write!(f, "Pending"), - CommitStatus::Failed(bundle_id) => { - write!(f, "Failed({})", bundle_id) + CommitStatus::Failed => { + write!(f, "Failed") } CommitStatus::BufferAndChunkPartiallyInitialized(bundle_id) => { write!(f, "BufferAndChunkPartiallyInitialized({})", bundle_id) @@ -89,7 +89,7 @@ impl TryFrom<(&str, u64, Option)> for CommitStatus { use CommitStatus::*; match status { "Pending" => Ok(Pending), - "Failed" => Ok(Failed(commit_id)), + "Failed" => Ok(Failed), "BufferAndChunkPartiallyInitialized" => { Ok(BufferAndChunkPartiallyInitialized(commit_id)) } @@ -128,7 +128,7 @@ impl CommitStatus { use CommitStatus::*; match self { Pending => "Pending", - Failed(_) => "Failed", + Failed => "Failed", BufferAndChunkPartiallyInitialized(_) => { "BufferAndChunkPartiallyInitialized" } @@ -146,8 +146,7 @@ impl CommitStatus { pub fn bundle_id(&self) -> Option { use CommitStatus::*; match self { - Failed(bundle_id) - | BufferAndChunkPartiallyInitialized(bundle_id) + BufferAndChunkPartiallyInitialized(bundle_id) | BufferAndChunkInitialized(bundle_id) | BufferAndChunkFullyInitialized(bundle_id) | PartOfTooLargeBundleToProcess(bundle_id) @@ -155,6 +154,7 @@ impl CommitStatus { | FailedFinalize((bundle_id, _)) | Succeeded((bundle_id, _)) => Some(*bundle_id), Pending => None, + Failed => None, } } diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index d60c7d451..7be6e565b 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use dlp::args::Context; use magicblock_program::magic_scheduled_l1_message::{ CommitType, CommittedAccountV2, MagicL1Message, ScheduledL1Message, UndelegateType, @@ -7,7 +8,7 @@ use magicblock_program::magic_scheduled_l1_message::{ use solana_pubkey::Pubkey; use crate::tasks::tasks::{ - ArgsTask, CommitTask, FinalizeTask, L1Task, UndelegateTask, + ArgsTask, CommitTask, FinalizeTask, L1ActionTask, L1Task, UndelegateTask, }; pub trait TasksBuilder { @@ -38,8 +39,11 @@ impl TasksBuilder for TaskBuilderV1 { let tasks = actions .into_iter() .map(|el| { - Box::new(ArgsTask::L1Action(el.clone())) - as Box + let task = L1ActionTask { + context: Context::Standalone, + action: el.clone(), + }; + Box::new(ArgsTask::L1Action(task)) as Box }) .collect(); return Ok(tasks); @@ -106,9 +110,12 @@ impl TasksBuilder for TaskBuilderV1 { .iter() .map(finalize_task) .collect::>(); - tasks.extend(l1_actions.iter().map(|a| { - Box::new(ArgsTask::L1Action(a.clone())) - as Box + tasks.extend(l1_actions.iter().map(|action| { + let task = L1ActionTask { + context: Context::Commit, + action: action.clone(), + }; + Box::new(ArgsTask::L1Action(task)) as Box })); tasks } @@ -136,8 +143,12 @@ impl TasksBuilder for TaskBuilderV1 { undelegate_task(a, rent_reimbursement) }), ); - tasks.extend(actions.iter().map(|a| { - Box::new(ArgsTask::L1Action(a.clone())) + tasks.extend(actions.iter().map(|action| { + let task = L1ActionTask { + context: Context::Undelegate, + action: action.clone(), + }; + Box::new(ArgsTask::L1Action(task)) as Box })); } diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index 80bf3dadb..86a6f5712 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -1,4 +1,6 @@ -use dlp::args::{CallHandlerArgs, CommitStateArgs, CommitStateFromBufferArgs}; +use dlp::args::{ + CallHandlerArgs, CommitStateArgs, CommitStateFromBufferArgs, Context, +}; use magicblock_committor_program::{ instruction_builder::{ init_buffer::{create_init_ix, CreateInitIxArgs}, @@ -102,13 +104,19 @@ pub struct FinalizeTask { pub delegated_account: Pubkey, } +#[derive(Clone)] +pub struct L1ActionTask { + pub context: Context, + pub action: L1Action, +} + /// Task that will be executed on Base layer via arguments #[derive(Clone)] pub enum ArgsTask { Commit(CommitTask), Finalize(FinalizeTask), Undelegate(UndelegateTask), // Special action really - L1Action(L1Action), + L1Action(L1ActionTask), } impl L1Task for ArgsTask { @@ -139,7 +147,8 @@ impl L1Task for ArgsTask { value.rent_reimbursement, ), Self::L1Action(value) => { - let account_metas = value + let action = &value.action; + let account_metas = action .account_metas_per_program .iter() .map(|short_meta| AccountMeta { @@ -150,12 +159,13 @@ impl L1Task for ArgsTask { .collect(); dlp::instruction_builder::call_handler( *validator, - value.destination_program, - value.escrow_authority, + action.destination_program, + action.escrow_authority, account_metas, CallHandlerArgs { - data: value.data_per_program.data.clone(), - escrow_index: value.data_per_program.escrow_index, + context: value.context, + data: action.data_per_program.data.clone(), + escrow_index: action.data_per_program.escrow_index, }, ) } diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index 2150c06f3..b00afe888 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -92,3 +92,24 @@ pub(crate) fn persist_status_update_set( } }); } +pub(crate) fn persist_status_update_by_message_set< + P: L1MessagesPersisterIface, +>( + persister: &Option

, + message_id: u64, + pubkeys: &[Pubkey], + update_status: CommitStatus, +) { + let Some(persister) = persister else { + return; + }; + pubkeys.iter().for_each(|pubkey| { + if let Err(err) = persister.update_status_by_message( + message_id, + pubkey, + update_status.clone(), + ) { + error!("Failed to persist new status {}: {}", update_status, err); + } + }); +} From e65047f4c03e622ff334adcddc18e473fa01c413 Mon Sep 17 00:00:00 2001 From: Dodecahedr0x <90185028+Dodecahedr0x@users.noreply.github.com> Date: Mon, 28 Jul 2025 10:07:03 +0200 Subject: [PATCH 129/199] feat(config): derive merge (#476) Closes #471 Create a `Mergeable` derive trait that automatically merges the fields with default values with the non-default fields of another instance. It also handles nested Mergeable structs. Note: in order to handle nested Mergeable structs, it uses the heuristic that nested mergeable struct have a type name containing `Config`. This is not a very robust method, but it works as we only use it for internal config structs. --- .github/workflows/ci-test-unit.yml | 3 + Cargo.lock | 506 +++++++++++++++++- Cargo.toml | 5 + magicblock-config-helpers/Cargo.toml | 10 + magicblock-config-helpers/src/lib.rs | 3 + magicblock-config-macro/Cargo.toml | 6 + magicblock-config-macro/README.md | 65 +++ magicblock-config-macro/src/clap_prefix.rs | 2 +- magicblock-config-macro/src/lib.rs | 75 ++- magicblock-config-macro/src/merger.rs | 90 ++++ .../tests/fixtures/fail_merge_enum.rs | 9 + .../tests/fixtures/fail_merge_enum.stderr | 17 + .../tests/fixtures/fail_merge_union.rs | 9 + .../tests/fixtures/fail_merge_union.stderr | 56 ++ .../tests/fixtures/fail_merge_unnamed.rs | 6 + .../tests/fixtures/fail_merge_unnamed.stderr | 5 + .../tests/fixtures/pass_merge.expanded.rs | 55 ++ .../tests/fixtures/pass_merge.rs | 16 + magicblock-config-macro/tests/test_merger.rs | 82 +++ magicblock-config/Cargo.toml | 1 + magicblock-config/src/accounts.rs | 68 +-- magicblock-config/src/accounts_db.rs | 8 +- magicblock-config/src/cli.rs | 11 +- magicblock-config/src/ledger.rs | 24 +- magicblock-config/src/lib.rs | 27 +- magicblock-config/src/metrics.rs | 27 +- magicblock-config/src/rpc.rs | 24 +- magicblock-config/src/validator.rs | 36 +- test-integration/Cargo.lock | 5 + 29 files changed, 1079 insertions(+), 172 deletions(-) create mode 100644 magicblock-config-helpers/Cargo.toml create mode 100644 magicblock-config-helpers/src/lib.rs create mode 100644 magicblock-config-macro/src/merger.rs create mode 100644 magicblock-config-macro/tests/fixtures/fail_merge_enum.rs create mode 100644 magicblock-config-macro/tests/fixtures/fail_merge_enum.stderr create mode 100644 magicblock-config-macro/tests/fixtures/fail_merge_union.rs create mode 100644 magicblock-config-macro/tests/fixtures/fail_merge_union.stderr create mode 100644 magicblock-config-macro/tests/fixtures/fail_merge_unnamed.rs create mode 100644 magicblock-config-macro/tests/fixtures/fail_merge_unnamed.stderr create mode 100644 magicblock-config-macro/tests/fixtures/pass_merge.expanded.rs create mode 100644 magicblock-config-macro/tests/fixtures/pass_merge.rs create mode 100644 magicblock-config-macro/tests/test_merger.rs diff --git a/.github/workflows/ci-test-unit.yml b/.github/workflows/ci-test-unit.yml index 2a71550ea..65af25e6a 100644 --- a/.github/workflows/ci-test-unit.yml +++ b/.github/workflows/ci-test-unit.yml @@ -25,6 +25,9 @@ jobs: - uses: ./magicblock-validator/.github/actions/setup-solana + - name: Install cargo-expand + run: cargo install cargo-expand + - name: Run unit tests run: | sudo prlimit --pid $$ --nofile=1048576:1048576 diff --git a/Cargo.lock b/Cargo.lock index e68ed0375..a487d3459 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,6 +162,15 @@ dependencies = [ "libc", ] +[[package]] +name = "ansi_colours" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14eec43e0298190790f41679fe69ef7a829d2a2ddd78c8c00339e84710e435fe" +dependencies = [ + "rgb", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -620,6 +629,45 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "bat" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab792c2ad113a666f08856c88cdec0a62d732559b1f3982eedf0142571e669a" +dependencies = [ + "ansi_colours", + "anyhow", + "bincode", + "bytesize", + "clircle", + "console 0.15.11", + "content_inspector", + "encoding_rs", + "flate2", + "globset", + "grep-cli", + "home", + "indexmap 2.10.0", + "itertools 0.13.0", + "nu-ansi-term", + "once_cell", + "path_abs", + "plist", + "regex", + "semver", + "serde", + "serde_derive", + "serde_with", + "serde_yaml", + "shell-words", + "syntect", + "terminal-colorsaurus", + "thiserror 1.0.69", + "toml 0.8.23", + "unicode-width 0.1.14", + "walkdir", +] + [[package]] name = "bincode" version = "1.3.3" @@ -649,15 +697,30 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec 0.6.3", +] + [[package]] name = "bit-set" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" dependencies = [ - "bit-vec", + "bit-vec 0.8.0", ] +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bit-vec" version = "0.8.0" @@ -852,6 +915,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "234113d19d0d7d613b40e86fb654acf958910802bcceab913a4f9e7cda03b1a4" dependencies = [ "memchr", + "regex-automata 0.4.9", "serde", ] @@ -919,6 +983,12 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +[[package]] +name = "bytesize" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e93abca9e28e0a1b9877922aacb20576e05d4679ffa78c3d6dc22a26a216659" + [[package]] name = "bzip2" version = "0.4.4" @@ -949,6 +1019,34 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "cargo-expand" +version = "1.0.113" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cc7758391e465c46231206c889f32087f9374081f83a7c6e60e40cba32cd5eb" +dependencies = [ + "bat", + "cargo-subcommand-metadata", + "clap 4.5.40", + "clap-cargo", + "console 0.16.0", + "fs-err", + "home", + "prettyplease 0.2.35", + "proc-macro2", + "quote", + "semver", + "serde", + "shlex", + "syn 2.0.104", + "syn-select", + "tempfile", + "termcolor", + "toml 0.9.2", + "toolchain_find", + "windows-sys 0.60.2", +] + [[package]] name = "cargo-lock" version = "10.1.0" @@ -961,6 +1059,12 @@ dependencies = [ "url 2.5.4", ] +[[package]] +name = "cargo-subcommand-metadata" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33d3b80a8db16c4ad7676653766a8e59b5f95443c8823cb7cff587b90cb91ba" + [[package]] name = "cc" version = "1.2.27" @@ -1086,6 +1190,16 @@ dependencies = [ "clap_derive", ] +[[package]] +name = "clap-cargo" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6affd9fc8702a94172345c11fa913aa84601cd05e187af166dcd48deff27b8d" +dependencies = [ + "anstyle", + "clap 4.5.40", +] + [[package]] name = "clap_builder" version = "4.5.40" @@ -1116,6 +1230,16 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" +[[package]] +name = "clircle" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d9334f725b46fb9bed8580b9b47a932587e044fadb344ed7fa98774b067ac1a" +dependencies = [ + "cfg-if 1.0.1", + "windows 0.56.0", +] + [[package]] name = "colorchoice" version = "1.0.4" @@ -1312,6 +1436,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" +[[package]] +name = "content_inspector" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7bda66e858c683005a53a9a60c69a4aca7eeaa45d124526e389f7aec8e62f38" +dependencies = [ + "memchr", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -1615,6 +1748,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "difflib" version = "0.4.0" @@ -1928,6 +2067,16 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" +[[package]] +name = "fancy-regex" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2" +dependencies = [ + "bit-set 0.5.3", + "regex", +] + [[package]] name = "fast-math" version = "0.1.1" @@ -2084,6 +2233,15 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dd6caf6059519a65843af8fe2a3ae298b14b80179855aeb4adc2c1934ee619" +[[package]] +name = "fs-err" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d7be93788013f265201256d58f04936a8079ad5dc898743aa20525f503b683" +dependencies = [ + "autocfg", +] + [[package]] name = "fs_extra" version = "1.3.0" @@ -2390,6 +2548,20 @@ dependencies = [ "spinning_top", ] +[[package]] +name = "grep-cli" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47f1288f0e06f279f84926fa4c17e3fcd2a22b357927a82f2777f7be26e4cec0" +dependencies = [ + "bstr", + "globset", + "libc", + "log", + "termcolor", + "winapi-util", +] + [[package]] name = "h2" version = "0.3.26" @@ -2805,7 +2977,7 @@ dependencies = [ "js-sys", "log", "wasm-bindgen", - "windows-core", + "windows-core 0.61.2", ] [[package]] @@ -3007,6 +3179,7 @@ dependencies = [ "equivalent", "hashbrown 0.15.4", "rayon", + "serde", ] [[package]] @@ -3089,6 +3262,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.14.0" @@ -3600,6 +3782,23 @@ dependencies = [ "libc", ] +[[package]] +name = "macrotest" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0597a8d49ceeea5845b12d1970aa993261e68d4660b327eabab667b3e7ffd60" +dependencies = [ + "diff", + "fastrand", + "glob", + "prettyplease 0.2.35", + "serde", + "serde_derive", + "serde_json", + "syn 2.0.104", + "toml_edit", +] + [[package]] name = "magic-domain-program" version = "0.0.1" @@ -3883,6 +4082,7 @@ dependencies = [ "bs58 0.4.0", "clap 4.5.40", "isocountry", + "magicblock-config-helpers", "magicblock-config-macro", "serde", "solana-sdk", @@ -3893,16 +4093,24 @@ dependencies = [ "url 2.5.4", ] +[[package]] +name = "magicblock-config-helpers" +version = "0.1.7" + [[package]] name = "magicblock-config-macro" version = "0.1.7" dependencies = [ + "cargo-expand", "clap 4.5.40", "convert_case 0.8.0", + "macrotest", + "magicblock-config-helpers", "proc-macro2", "quote", "serde", "syn 2.0.104", + "trybuild", ] [[package]] @@ -4480,6 +4688,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "nu-ansi-term" +version = "0.50.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "num" version = "0.2.1" @@ -4827,6 +5044,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "path_abs" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ef02f6342ac01d8a93b65f96db53fe68a92a15f41144f97fb00a9e669633c3" +dependencies = [ + "std_prelude", +] + [[package]] name = "pbkdf2" version = "0.4.0" @@ -4967,6 +5193,19 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "plist" +version = "1.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af6b589e163c5a788fab00ce0c0366f6efbb9959c2f9874b224936af7fce7e1" +dependencies = [ + "base64 0.22.1", + "indexmap 2.10.0", + "quick-xml", + "serde", + "time", +] + [[package]] name = "polyval" version = "0.6.2" @@ -5064,6 +5303,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "prettyplease" +version = "0.2.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "061c1221631e079b26479d25bbf2275bfe5917ae8419cd7e34f13bfc2aa7539a" +dependencies = [ + "proc-macro2", + "syn 2.0.104", +] + [[package]] name = "proc-macro-crate" version = "0.1.5" @@ -5157,8 +5406,8 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fcdab19deb5195a31cf7726a210015ff1496ba1464fd42cb4f537b8b01b471f" dependencies = [ - "bit-set", - "bit-vec", + "bit-set 0.8.0", + "bit-vec 0.8.0", "bitflags 2.9.1", "lazy_static", "num-traits", @@ -5204,7 +5453,7 @@ dependencies = [ "log", "multimap", "petgraph", - "prettyplease", + "prettyplease 0.1.25", "prost 0.11.9", "prost-types 0.11.9", "regex", @@ -5313,6 +5562,15 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quick-xml" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8927b0664f5c5a98265138b7e3f90aa19a6b21353182469ace36d4ac527b7b1b" +dependencies = [ + "memchr", +] + [[package]] name = "quinn" version = "0.11.8" @@ -5585,7 +5843,7 @@ dependencies = [ "cfg-if 1.0.1", "libc", "rustix 1.0.7", - "windows", + "windows 0.61.3", ] [[package]] @@ -5694,6 +5952,15 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "rgb" +version = "0.8.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce" +dependencies = [ + "bytemuck", +] + [[package]] name = "ring" version = "0.17.14" @@ -6127,6 +6394,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40734c41988f7306bb04f0ecf60ec0f3f1caa34290e4e8ea471dcd3346483b83" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -10274,6 +10550,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "std_prelude" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8207e78455ffdf55661170876f88daf85356e4edd54e0a3dbc79586ca1e50cbe" + [[package]] name = "stream-cancel" version = "0.8.2" @@ -10377,6 +10659,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn-select" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea24402791e2625a28bcaf662046e09a48a7610f806688cf35901d78ba938bb4" +dependencies = [ + "syn 2.0.104", +] + [[package]] name = "sync_wrapper" version = "0.1.2" @@ -10406,6 +10697,26 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "syntect" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "874dcfa363995604333cf947ae9f751ca3af4522c60886774c4963943b4746b1" +dependencies = [ + "bincode", + "bitflags 1.3.2", + "fancy-regex", + "flate2", + "fnv", + "once_cell", + "regex-syntax 0.8.5", + "serde", + "serde_derive", + "serde_json", + "thiserror 1.0.69", + "walkdir", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -10447,6 +10758,12 @@ dependencies = [ "xattr", ] +[[package]] +name = "target-triple" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ac9aa371f599d22256307c24a9d748c041e548cbf599f35d890f9d365361790" + [[package]] name = "tarpc" version = "0.29.0" @@ -10513,6 +10830,32 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "terminal-colorsaurus" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7afe4c174a3cbfb52ebcb11b28965daf74fe9111d4e07e40689d05af06e26e8" +dependencies = [ + "cfg-if 1.0.1", + "libc", + "memchr", + "mio 1.0.4", + "terminal-trx", + "windows-sys 0.59.0", + "xterm-color", +] + +[[package]] +name = "terminal-trx" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "975b4233aefa1b02456d5e53b22c61653c743e308c51cf4181191d8ce41753ab" +dependencies = [ + "cfg-if 1.0.1", + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "termtree" version = "0.5.1" @@ -10845,12 +11188,28 @@ version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" dependencies = [ + "indexmap 2.10.0", "serde", - "serde_spanned", - "toml_datetime", + "serde_spanned 0.6.9", + "toml_datetime 0.6.11", "toml_edit", ] +[[package]] +name = "toml" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed0aee96c12fa71097902e0bb061a5e1ebd766a6636bb605ba401c45c1650eac" +dependencies = [ + "indexmap 2.10.0", + "serde", + "serde_spanned 1.0.0", + "toml_datetime 0.7.0", + "toml_parser", + "toml_writer", + "winnow", +] + [[package]] name = "toml_datetime" version = "0.6.11" @@ -10860,6 +11219,15 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_datetime" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bade1c3e902f58d73d3f294cd7f20391c1cb2fbcb643b73566bc773971df91e3" +dependencies = [ + "serde", +] + [[package]] name = "toml_edit" version = "0.22.27" @@ -10868,18 +11236,33 @@ checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap 2.10.0", "serde", - "serde_spanned", - "toml_datetime", + "serde_spanned 0.6.9", + "toml_datetime 0.6.11", "toml_write", "winnow", ] +[[package]] +name = "toml_parser" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97200572db069e74c512a14117b296ba0a80a30123fbbb5aa1f4a348f639ca30" +dependencies = [ + "winnow", +] + [[package]] name = "toml_write" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" +[[package]] +name = "toml_writer" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc842091f2def52017664b53082ecbbeb5c7731092bad69d2c63050401dfd64" + [[package]] name = "tonic" version = "0.9.2" @@ -10946,7 +11329,7 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6fdaae4c2c638bb70fe42803a26fbd6fc6ac8c72f5c59f67ecc2a2dcabf4b07" dependencies = [ - "prettyplease", + "prettyplease 0.1.25", "proc-macro2", "prost-build", "quote", @@ -10966,6 +11349,19 @@ dependencies = [ "tonic 0.9.2", ] +[[package]] +name = "toolchain_find" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc8c9a7f0a2966e1acdaf0461023d0b01471eeead645370cf4c3f5cff153f2a" +dependencies = [ + "home", + "once_cell", + "regex", + "semver", + "walkdir", +] + [[package]] name = "tower" version = "0.4.13" @@ -11071,6 +11467,21 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "trybuild" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65af40ad689f2527aebbd37a0a816aea88ff5f774ceabe99de5be02f2f91dae2" +dependencies = [ + "glob", + "serde", + "serde_derive", + "serde_json", + "target-triple", + "termcolor", + "toml 0.9.2", +] + [[package]] name = "tungstenite" version = "0.20.1" @@ -11529,6 +11940,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132" +dependencies = [ + "windows-core 0.56.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows" version = "0.61.3" @@ -11536,7 +11957,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" dependencies = [ "windows-collections", - "windows-core", + "windows-core 0.61.2", "windows-future", "windows-link", "windows-numerics", @@ -11548,7 +11969,19 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" dependencies = [ - "windows-core", + "windows-core 0.61.2", +] + +[[package]] +name = "windows-core" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4698e52ed2d08f8658ab0c39512a7c00ee5fe2688c65f8c0a4f06750d729f2a6" +dependencies = [ + "windows-implement 0.56.0", + "windows-interface 0.56.0", + "windows-result 0.1.2", + "windows-targets 0.52.6", ] [[package]] @@ -11557,10 +11990,10 @@ version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ - "windows-implement", - "windows-interface", + "windows-implement 0.60.0", + "windows-interface 0.59.1", "windows-link", - "windows-result", + "windows-result 0.3.4", "windows-strings", ] @@ -11570,11 +12003,22 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" dependencies = [ - "windows-core", + "windows-core 0.61.2", "windows-link", "windows-threading", ] +[[package]] +name = "windows-implement" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", +] + [[package]] name = "windows-implement" version = "0.60.0" @@ -11586,6 +12030,17 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "windows-interface" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", +] + [[package]] name = "windows-interface" version = "0.59.1" @@ -11609,10 +12064,19 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" dependencies = [ - "windows-core", + "windows-core 0.61.2", "windows-link", ] +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-result" version = "0.3.4" @@ -11999,6 +12463,12 @@ dependencies = [ "rustix 1.0.7", ] +[[package]] +name = "xterm-color" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4de5f056fb9dc8b7908754867544e26145767187aaac5a98495e88ad7cb8a80f" + [[package]] name = "yoke" version = "0.8.0" diff --git a/Cargo.toml b/Cargo.toml index a5a87e392..8d5a92fb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ members = [ "magicblock-committor-program", "magicblock-committor-service", "magicblock-config", + "magicblock-config-helpers", "magicblock-config-macro", "magicblock-core", "magicblock-geyser-plugin", @@ -65,6 +66,7 @@ borsh-derive = "1.5.1" bs58 = "0.4.0" byteorder = "1.5.0" cargo-lock = "10.0.0" +cargo-expand = "1" clap = "4.5.40" convert_case = "0.8.0" conjunto-transwise = { git = "https://github.com/magicblock-labs/conjunto.git", rev = "bf82b45" } @@ -96,6 +98,7 @@ lazy_static = "1.4.0" libc = "0.2.153" libloading = "0.7.4" log = "0.4.20" +macrotest = "1" magicblock-account-cloner = { path = "./magicblock-account-cloner" } magicblock-account-dumper = { path = "./magicblock-account-dumper" } magicblock-account-fetcher = { path = "./magicblock-account-fetcher" } @@ -110,6 +113,7 @@ magicblock-committor-program = { path = "./magicblock-committor-program", featur ] } magicblock-committor-service = { path = "./magicblock-committor-service" } magicblock-config = { path = "./magicblock-config" } +magicblock-config-helpers = { path = "./magicblock-config-helpers" } magicblock-config-macro = { path = "./magicblock-config-macro" } magicblock-core = { path = "./magicblock-core" } magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "4af7f1c" } @@ -203,6 +207,7 @@ toml = "0.8.13" tonic = "0.9.2" tonic-build = "0.9.2" tonic-health = "0.9.2" +trybuild = "1.0" url = "2.5.0" vergen = "8.3.1" diff --git a/magicblock-config-helpers/Cargo.toml b/magicblock-config-helpers/Cargo.toml new file mode 100644 index 000000000..312d70acd --- /dev/null +++ b/magicblock-config-helpers/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "magicblock-config-helpers" +version.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true +license.workspace = true +edition.workspace = true + +[dependencies] diff --git a/magicblock-config-helpers/src/lib.rs b/magicblock-config-helpers/src/lib.rs new file mode 100644 index 000000000..ba3644575 --- /dev/null +++ b/magicblock-config-helpers/src/lib.rs @@ -0,0 +1,3 @@ +pub trait Merge: Default { + fn merge(&mut self, other: Self); +} diff --git a/magicblock-config-macro/Cargo.toml b/magicblock-config-macro/Cargo.toml index b81b6264e..aac457e22 100644 --- a/magicblock-config-macro/Cargo.toml +++ b/magicblock-config-macro/Cargo.toml @@ -17,3 +17,9 @@ quote = { workspace = true } syn = { workspace = true, features = ["full", "visit-mut"] } clap = { workspace = true, features = ["derive", "env"] } serde = { workspace = true, features = ["derive"] } + +[dev-dependencies] +magicblock-config-helpers = { workspace = true } +trybuild = { workspace = true } +macrotest = { workspace = true } +cargo-expand = { workspace = true } diff --git a/magicblock-config-macro/README.md b/magicblock-config-macro/README.md index d5140e155..a2b2dc3c4 100644 --- a/magicblock-config-macro/README.md +++ b/magicblock-config-macro/README.md @@ -2,6 +2,10 @@ A set of macro helpers to keep the config DRY (Don't Repeat Yourself). It contains two attributes meant to be used on struct that need to derive `serde::Deserialize` and `clap::Args`. +## Tests + +If the implementation changes, `tests/fixtures/*.expanded.rs` files must be removed. Re-running tests will regenerate them with the implementation changes included. + ## `clap_prefix` This macro will update existing `#[arg]` (or create one if needed) and add a `long`, `name`, and `env` constructed from the prefix and the name of each field in annotated struct. @@ -71,4 +75,65 @@ struct RpcConfig { #[command(flatten)] config: SomeOtherConfig, } +``` + +## `derive(Mergeable)` + +This macro will implement the `magicblock_config_helpers::Merge` trait for annotated struct. + +### Example + +```rust +use magicblock_config_macro::Mergeable; + +#[derive(Default, Mergeable)] +struct SomeOtherConfig { + field1: u32, + field2: String, +} + +#[derive(Default, Mergeable)] +struct MyConfig { + field1: u32, + field2: SomeOtherConfig, +} +``` + +Will become: +```rust +use magicblock_config_helpers::Merge; + +#[derive(Default)] +struct SomeOtherConfig { + field1: u32, + field2: String, +} + +impl Merge for SomeOtherConfig { + fn merge(&mut self, other: Self) { + let default = Self::default(); + if self.field1 == default.field1 { + self.field1 = other.field1; + } + if self.field2 == default.field2 { + self.field2 = other.field2; + } + } +} + +#[derive(Default)] +struct MyConfig { + field1: u32, + field2: SomeOtherConfig, +} + +impl Merge for MyConfig { + fn merge(&mut self, other: Self) { + let default = Self::default(); + if self.field1 == default.field1 { + self.field1 = other.field1; + } + self.field2.merge(other.field2); + } +} ``` \ No newline at end of file diff --git a/magicblock-config-macro/src/clap_prefix.rs b/magicblock-config-macro/src/clap_prefix.rs index 57e2f3c81..8bdc49cde 100644 --- a/magicblock-config-macro/src/clap_prefix.rs +++ b/magicblock-config-macro/src/clap_prefix.rs @@ -43,7 +43,7 @@ impl VisitMut for ClapPrefix { ident.to_string(), kebab_str, constant_str, - vec!["long".to_string(), "name".to_string()], + vec!["long".to_string(), "id".to_string()], ); replacer.visit_attributes_mut(&mut field.attrs); self.compile_errors.extend(replacer.compile_errors); diff --git a/magicblock-config-macro/src/lib.rs b/magicblock-config-macro/src/lib.rs index 97060bcb2..4f5db5a34 100644 --- a/magicblock-config-macro/src/lib.rs +++ b/magicblock-config-macro/src/lib.rs @@ -1,10 +1,13 @@ mod clap_from_serde; mod clap_prefix; +mod merger; + use clap_from_serde::*; use clap_prefix::*; +use merger::*; use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, visit_mut::VisitMut, ItemStruct}; +use syn::{parse_macro_input, visit_mut::VisitMut, DeriveInput, ItemStruct}; /// Prefixes the fields of the annotated struct with the given prefix. /// @@ -158,3 +161,73 @@ pub fn clap_from_serde(_attr: TokenStream, item: TokenStream) -> TokenStream { } .into() } + +/// Derives the `Merge` trait for the annotated struct. +/// +/// **ASSUMES THAT FIELDS WITH NAMES CONTAINING "Config" HAVE A `merge` METHOD** +/// +/// This macro is used to derive the `Merge` trait for a struct. +/// The `Merge` trait is used to merge two instances of the struct. +/// +/// # Example +/// ```rust +/// use magicblock_config_macro::Mergeable; +/// +/// #[derive(Default, Mergeable)] +/// struct SomeOtherConfig { +/// field1: u32, +/// field2: String, +/// } +/// +/// #[derive(Default, Mergeable)] +/// struct MyConfig { +/// field1: u32, +/// field2: SomeOtherConfig, +/// } +/// ``` +/// +/// Will become: +/// ```rust +/// use magicblock_config_helpers::Merge; +/// +/// #[derive(Default)] +/// struct SomeOtherConfig { +/// field1: u32, +/// field2: String, +/// } +/// +/// impl Merge for SomeOtherConfig { +/// fn merge(&mut self, other: Self) { +/// let default = Self::default(); +/// if self.field1 == default.field1 { +/// self.field1 = other.field1; +/// } +/// if self.field2 == default.field2 { +/// self.field2 = other.field2; +/// } +/// } +/// } +/// +/// #[derive(Default)] +/// struct MyConfig { +/// field1: u32, +/// field2: SomeOtherConfig, +/// } +/// +/// impl Merge for MyConfig { +/// fn merge(&mut self, other: Self) { +/// let default = Self::default(); +/// if self.field1 == default.field1 { +/// self.field1 = other.field1; +/// } +/// self.field2.merge(other.field2); +/// } +/// } +/// ``` +#[proc_macro_derive(Mergeable)] +pub fn derive_merge(input: TokenStream) -> TokenStream { + let mut input = parse_macro_input!(input as DeriveInput); + + let mut merger = Merger; + merger.add_impl(&mut input) +} diff --git a/magicblock-config-macro/src/merger.rs b/magicblock-config-macro/src/merger.rs new file mode 100644 index 000000000..ad1fa5727 --- /dev/null +++ b/magicblock-config-macro/src/merger.rs @@ -0,0 +1,90 @@ +use proc_macro::TokenStream; +use quote::quote; +use syn::{Data, DeriveInput, Fields, Type}; + +pub struct Merger; + +impl Merger { + fn type_has_merge_method(ty: &Type) -> bool { + match ty { + Type::Path(type_path) => { + let path = &type_path.path; + let segments: Vec = path + .segments + .iter() + .map(|seg| seg.ident.to_string()) + .collect(); + + // NOTE: this assumes that all mergeable config structs have a "Config" suffix + segments.iter().any(|seg| seg.contains("Config")) + } + _ => false, + } + } +} + +impl Merger { + pub fn add_impl(&mut self, input: &mut DeriveInput) -> TokenStream { + let struct_name = &input.ident; + let generics = &input.generics; + let (impl_generics, ty_generics, where_clause) = + generics.split_for_impl(); + + let mut compile_errors = Vec::new(); + + let fields = match &input.data { + Data::Struct(data_struct) => match &data_struct.fields { + Fields::Named(fields_named) => &fields_named.named, + other_fields => { + compile_errors.push(syn::Error::new_spanned( + other_fields, + "Merge can only be derived for structs with named fields", + ).to_compile_error()); + &syn::punctuated::Punctuated::new() + } + }, + _ => { + compile_errors.push( + syn::Error::new_spanned( + &input, + "Merge can only be derived for structs", + ) + .to_compile_error(), + ); + &syn::punctuated::Punctuated::new() + } + }; + + let merge_fields = fields.iter().map(|f| { + let name = &f.ident; + let field_type = &f.ty; + + if Self::type_has_merge_method(field_type) { + // If the field type likely has a merge method, call it + quote! { + self.#name.merge(other.#name); + } + } else { + // Otherwise, overwrite the field if it has the default value + quote! { + if self.#name == default.#name { + self.#name = other.#name; + } + } + } + }); + + quote! { + #(#compile_errors)* + + impl #impl_generics ::magicblock_config_helpers::Merge for #struct_name #ty_generics #where_clause { + fn merge(&mut self, other: #struct_name #ty_generics) { + let default = Self::default(); + + #(#merge_fields)* + } + } + } + .into() + } +} diff --git a/magicblock-config-macro/tests/fixtures/fail_merge_enum.rs b/magicblock-config-macro/tests/fixtures/fail_merge_enum.rs new file mode 100644 index 000000000..0de23de8d --- /dev/null +++ b/magicblock-config-macro/tests/fixtures/fail_merge_enum.rs @@ -0,0 +1,9 @@ +use magicblock_config_macro::Mergeable; + +#[derive(Default, Mergeable)] +enum TestEnum { + A(u32), + B(String), +} + +fn main() {} diff --git a/magicblock-config-macro/tests/fixtures/fail_merge_enum.stderr b/magicblock-config-macro/tests/fixtures/fail_merge_enum.stderr new file mode 100644 index 000000000..ffddea340 --- /dev/null +++ b/magicblock-config-macro/tests/fixtures/fail_merge_enum.stderr @@ -0,0 +1,17 @@ +error: no default declared + --> tests/fixtures/fail_merge_enum.rs:3:10 + | +3 | #[derive(Default, Mergeable)] + | ^^^^^^^ + | + = help: make a unit variant default by placing `#[default]` above it + = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: Merge can only be derived for structs + --> tests/fixtures/fail_merge_enum.rs:4:1 + | +4 | / enum TestEnum { +5 | | A(u32), +6 | | B(String), +7 | | } + | |_^ diff --git a/magicblock-config-macro/tests/fixtures/fail_merge_union.rs b/magicblock-config-macro/tests/fixtures/fail_merge_union.rs new file mode 100644 index 000000000..e793fa348 --- /dev/null +++ b/magicblock-config-macro/tests/fixtures/fail_merge_union.rs @@ -0,0 +1,9 @@ +use magicblock_config_macro::Mergeable; + +#[derive(Default, Mergeable)] +union TestUnion { + a: u32, + b: String, +} + +fn main() {} diff --git a/magicblock-config-macro/tests/fixtures/fail_merge_union.stderr b/magicblock-config-macro/tests/fixtures/fail_merge_union.stderr new file mode 100644 index 000000000..83b7cc31d --- /dev/null +++ b/magicblock-config-macro/tests/fixtures/fail_merge_union.stderr @@ -0,0 +1,56 @@ +error: this trait cannot be derived for unions + --> tests/fixtures/fail_merge_union.rs:3:10 + | +3 | #[derive(Default, Mergeable)] + | ^^^^^^^ + +error: Merge can only be derived for structs + --> tests/fixtures/fail_merge_union.rs:4:1 + | +4 | / union TestUnion { +5 | | a: u32, +6 | | b: String, +7 | | } + | |_^ + +error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union + --> tests/fixtures/fail_merge_union.rs:6:5 + | +6 | b: String, + | ^^^^^^^^^ + | + = note: union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>` +help: wrap the field type in `ManuallyDrop<...>` + | +6 | b: std::mem::ManuallyDrop, + | +++++++++++++++++++++++ + + +error[E0277]: the trait bound `TestUnion: Default` is not satisfied + --> tests/fixtures/fail_merge_union.rs:4:7 + | +4 | union TestUnion { + | ^^^^^^^^^ the trait `Default` is not implemented for `TestUnion` + | +note: required by a bound in `Merge` + --> $WORKSPACE/magicblock-config-helpers/src/lib.rs + | + | pub trait Merge: Default { + | ^^^^^^^ required by this bound in `Merge` +help: consider annotating `TestUnion` with `#[derive(Default)]` + | +4 + #[derive(Default)] +5 | union TestUnion { + | + +error[E0599]: no function or associated item named `default` found for union `TestUnion` in the current scope + --> tests/fixtures/fail_merge_union.rs:3:19 + | +3 | #[derive(Default, Mergeable)] + | ^^^^^^^^^ function or associated item not found in `TestUnion` +4 | union TestUnion { + | --------------- function or associated item `default` not found for this union + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `default`, perhaps you need to implement it: + candidate #1: `Default` + = note: this error originates in the derive macro `Mergeable` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/magicblock-config-macro/tests/fixtures/fail_merge_unnamed.rs b/magicblock-config-macro/tests/fixtures/fail_merge_unnamed.rs new file mode 100644 index 000000000..e11aa10c6 --- /dev/null +++ b/magicblock-config-macro/tests/fixtures/fail_merge_unnamed.rs @@ -0,0 +1,6 @@ +use magicblock_config_macro::Mergeable; + +#[derive(Default, Mergeable)] +struct TestConfig(u64, String); + +fn main() {} diff --git a/magicblock-config-macro/tests/fixtures/fail_merge_unnamed.stderr b/magicblock-config-macro/tests/fixtures/fail_merge_unnamed.stderr new file mode 100644 index 000000000..0b9bb18cf --- /dev/null +++ b/magicblock-config-macro/tests/fixtures/fail_merge_unnamed.stderr @@ -0,0 +1,5 @@ +error: Merge can only be derived for structs with named fields + --> tests/fixtures/fail_merge_unnamed.rs:4:18 + | +4 | struct TestConfig(u64, String); + | ^^^^^^^^^^^^^ diff --git a/magicblock-config-macro/tests/fixtures/pass_merge.expanded.rs b/magicblock-config-macro/tests/fixtures/pass_merge.expanded.rs new file mode 100644 index 000000000..3ed6252f3 --- /dev/null +++ b/magicblock-config-macro/tests/fixtures/pass_merge.expanded.rs @@ -0,0 +1,55 @@ +use magicblock_config_macro::Mergeable; +struct TestConfig { + field1: u32, + field2: String, + field3: Option, + nested: NestedConfig, +} +#[automatically_derived] +impl ::core::default::Default for TestConfig { + #[inline] + fn default() -> TestConfig { + TestConfig { + field1: ::core::default::Default::default(), + field2: ::core::default::Default::default(), + field3: ::core::default::Default::default(), + nested: ::core::default::Default::default(), + } + } +} +impl ::magicblock_config_helpers::Merge for TestConfig { + fn merge(&mut self, other: TestConfig) { + let default = Self::default(); + if self.field1 == default.field1 { + self.field1 = other.field1; + } + if self.field2 == default.field2 { + self.field2 = other.field2; + } + if self.field3 == default.field3 { + self.field3 = other.field3; + } + self.nested.merge(other.nested); + } +} +struct NestedConfig { + value: u32, +} +#[automatically_derived] +impl ::core::default::Default for NestedConfig { + #[inline] + fn default() -> NestedConfig { + NestedConfig { + value: ::core::default::Default::default(), + } + } +} +impl ::magicblock_config_helpers::Merge for NestedConfig { + fn merge(&mut self, other: NestedConfig) { + let default = Self::default(); + if self.value == default.value { + self.value = other.value; + } + } +} +fn main() {} diff --git a/magicblock-config-macro/tests/fixtures/pass_merge.rs b/magicblock-config-macro/tests/fixtures/pass_merge.rs new file mode 100644 index 000000000..c7f12d493 --- /dev/null +++ b/magicblock-config-macro/tests/fixtures/pass_merge.rs @@ -0,0 +1,16 @@ +use magicblock_config_macro::Mergeable; + +#[derive(Default, Mergeable)] +struct TestConfig { + field1: u32, + field2: String, + field3: Option, + nested: NestedConfig, +} + +#[derive(Default, Mergeable)] +struct NestedConfig { + value: u32, +} + +fn main() {} diff --git a/magicblock-config-macro/tests/test_merger.rs b/magicblock-config-macro/tests/test_merger.rs new file mode 100644 index 000000000..70df8a68f --- /dev/null +++ b/magicblock-config-macro/tests/test_merger.rs @@ -0,0 +1,82 @@ +use macrotest::expand; +use magicblock_config_helpers::Merge; +use magicblock_config_macro::Mergeable; + +// Test struct with fields that have merge methods +#[derive(Debug, Clone, PartialEq, Eq, Default, Mergeable)] +struct TestConfig { + field1: u32, + field2: String, + field3: Option, + nested: NestedConfig, +} + +// Nested config that has a merge method +#[derive(Debug, Clone, PartialEq, Eq, Default, Mergeable)] +struct NestedConfig { + value: u32, +} + +#[test] +fn test_merge_macro() { + let mut config = TestConfig { + field1: 0, + field2: "".to_string(), + field3: None, + nested: NestedConfig { value: 0 }, + }; + + let other = TestConfig { + field1: 42, + field2: "test".to_string(), + field3: Some("test".to_string()), + nested: NestedConfig { value: 100 }, + }; + + config.merge(other); + + // field1 and field2 should use default-based merging + assert_eq!(config.field1, 42); + assert_eq!(config.field2, "test"); + + // nested should use its own merge method + assert_eq!(config.nested.value, 100); +} + +#[test] +fn test_merge_macro_with_non_default_values() { + let mut config = TestConfig { + field1: 10, + field2: "original".to_string(), + field3: None, + nested: NestedConfig { value: 50 }, + }; + + let other = TestConfig { + field1: 42, + field2: "test".to_string(), + field3: Some("test".to_string()), + nested: NestedConfig { value: 100 }, + }; + + config.merge(other); + + // field1 and field2 should preserve original values since they're not default + assert_eq!(config.field1, 10); + assert_eq!(config.field2, "original"); + assert_eq!(config.field3, Some("test".to_string())); + + // nested should use its own merge method (preserves original since both are non-default) + assert_eq!(config.nested.value, 50); +} + +#[test] +fn test_merge_macro_codegen() { + let t = trybuild::TestCases::new(); + t.pass("tests/fixtures/pass_merge.rs"); + t.compile_fail("tests/fixtures/fail_merge_enum.rs"); + t.compile_fail("tests/fixtures/fail_merge_union.rs"); + t.compile_fail("tests/fixtures/fail_merge_unnamed.rs"); + + expand("tests/fixtures/pass_merge.rs"); +} diff --git a/magicblock-config/Cargo.toml b/magicblock-config/Cargo.toml index 6b8833422..4943f7e3d 100644 --- a/magicblock-config/Cargo.toml +++ b/magicblock-config/Cargo.toml @@ -17,6 +17,7 @@ toml = { workspace = true } url = { workspace = true, features = ["serde"] } # strum_macros = { workspace = true } strum = { workspace = true, features = ["derive"] } +magicblock-config-helpers = { workspace = true } magicblock-config-macro = { workspace = true } isocountry = { workspace = true } diff --git a/magicblock-config/src/accounts.rs b/magicblock-config/src/accounts.rs index 4a8ae455a..980b6b4a3 100644 --- a/magicblock-config/src/accounts.rs +++ b/magicblock-config/src/accounts.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use clap::{Args, ValueEnum}; -use magicblock_config_macro::{clap_from_serde, clap_prefix}; +use magicblock_config_macro::{clap_from_serde, clap_prefix, Mergeable}; use serde::{Deserialize, Serialize}; use solana_sdk::pubkey::Pubkey; use strum::{Display, EnumString}; @@ -14,7 +14,9 @@ use crate::accounts_db::AccountsDbConfig; // ----------------- #[clap_prefix("accounts")] #[clap_from_serde] -#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args)] +#[derive( + Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args, Mergeable, +)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] pub struct AccountsConfig { #[serde(default)] @@ -42,40 +44,6 @@ pub struct AccountsConfig { pub max_monitored_accounts: usize, } -impl AccountsConfig { - pub fn merge(&mut self, other: AccountsConfig) { - let default = Self::default(); - - if self.remote == default.remote && other.remote != default.remote { - self.remote = other.remote; - } - if self.lifecycle == default.lifecycle - && other.lifecycle != default.lifecycle - { - self.lifecycle = other.lifecycle; - } - if self.commit == default.commit && other.commit != default.commit { - self.commit = other.commit; - } - if self.allowed_programs == default.allowed_programs - && other.allowed_programs != default.allowed_programs - { - self.allowed_programs = other.allowed_programs; - } - if self.db == default.db && other.db != default.db { - self.db = other.db; - } - if self.clone == default.clone && other.clone != default.clone { - self.clone = other.clone; - } - if self.max_monitored_accounts == default.max_monitored_accounts - && other.max_monitored_accounts != default.max_monitored_accounts - { - self.max_monitored_accounts = other.max_monitored_accounts; - } - } -} - impl Default for AccountsConfig { fn default() -> Self { Self { @@ -95,7 +63,15 @@ impl Default for AccountsConfig { #[clap_prefix("remote")] #[clap_from_serde] #[derive( - Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize, Args, + Debug, + Default, + Clone, + PartialEq, + Eq, + Deserialize, + Serialize, + Args, + Mergeable, )] #[serde(deny_unknown_fields)] pub struct RemoteConfig { @@ -130,7 +106,7 @@ pub struct RemoteConfig { )] #[serde(rename_all = "kebab-case")] #[strum(serialize_all = "kebab-case")] -#[clap(rename_all = "kebab-case")] +#[value(rename_all = "kebab-case")] pub enum RemoteCluster { #[default] Devnet, @@ -162,7 +138,7 @@ pub enum RemoteCluster { )] #[serde(rename_all = "kebab-case")] #[strum(serialize_all = "kebab-case")] -#[clap(rename_all = "kebab-case")] +#[value(rename_all = "kebab-case")] pub enum LifecycleMode { Replica, #[default] @@ -229,7 +205,7 @@ impl Default for CommitStrategy { )] #[serde(rename_all = "kebab-case")] #[strum(serialize_all = "kebab-case")] -#[clap(rename_all = "kebab-case")] +#[value(rename_all = "kebab-case")] pub enum PrepareLookupTables { Always, #[default] @@ -239,7 +215,15 @@ pub enum PrepareLookupTables { #[clap_prefix("clone")] #[clap_from_serde] #[derive( - Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize, Args, + Debug, + Default, + Clone, + PartialEq, + Eq, + Deserialize, + Serialize, + Args, + Mergeable, )] #[serde(deny_unknown_fields)] pub struct AccountsCloneConfig { @@ -285,6 +269,8 @@ where #[cfg(test)] mod tests { + use magicblock_config_helpers::Merge; + use super::*; use crate::BlockSize; diff --git a/magicblock-config/src/accounts_db.rs b/magicblock-config/src/accounts_db.rs index bbcb3c45a..d90230d2b 100644 --- a/magicblock-config/src/accounts_db.rs +++ b/magicblock-config/src/accounts_db.rs @@ -1,11 +1,13 @@ use clap::{Args, ValueEnum}; -use magicblock_config_macro::{clap_from_serde, clap_prefix}; +use magicblock_config_macro::{clap_from_serde, clap_prefix, Mergeable}; use serde::{Deserialize, Serialize}; use strum::Display; #[clap_prefix("db")] #[clap_from_serde] -#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args)] +#[derive( + Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args, Mergeable, +)] #[serde(rename_all = "kebab-case")] pub struct AccountsDbConfig { /// size of the main storage, we have to preallocate in advance @@ -64,7 +66,7 @@ impl Default for AccountsDbConfig { )] #[serde(rename_all = "kebab-case")] #[strum(serialize_all = "kebab-case")] -#[clap(rename_all = "kebab-case")] +#[value(rename_all = "kebab-case")] #[repr(u32)] pub enum BlockSize { Block128 = 128, diff --git a/magicblock-config/src/cli.rs b/magicblock-config/src/cli.rs index 53d294718..975c7115b 100644 --- a/magicblock-config/src/cli.rs +++ b/magicblock-config/src/cli.rs @@ -1,16 +1,17 @@ use std::path::PathBuf; use clap::{Error, Parser}; +use magicblock_config_helpers::Merge; use solana_sdk::signature::Keypair; use crate::EphemeralConfig; #[derive(Debug, Clone, Parser)] pub struct MagicBlockConfig { - #[clap(help = "Path to the config file")] + #[arg(help = "Path to the config file")] pub config_file: Option, - #[clap( + #[arg( short, long, help = "The keypair to use for the validator. DO NOT PROVIDE THIS VALUE VIA THE CLI IN PROD! The default keypair has the pubkey mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev.", @@ -19,7 +20,7 @@ pub struct MagicBlockConfig { )] pub validator_keypair: String, - #[clap( + #[arg( long, help = "The comma separated list of geyser cache features to disable. Valid values are 'accounts' and 'transactions'.", env = "GEYSER_CACHE_DISABLE", @@ -27,7 +28,7 @@ pub struct MagicBlockConfig { )] pub geyser_cache_disable: String, - #[clap( + #[arg( long, help = "The comma separated list of geyser notifications features to disable. Valid values are 'accounts' and 'transactions'.", env = "GEYSER_DISABLE", @@ -35,7 +36,7 @@ pub struct MagicBlockConfig { )] pub geyser_disable: String, - #[clap(flatten)] + #[command(flatten)] pub config: EphemeralConfig, } diff --git a/magicblock-config/src/ledger.rs b/magicblock-config/src/ledger.rs index ece842137..a5c098f60 100644 --- a/magicblock-config/src/ledger.rs +++ b/magicblock-config/src/ledger.rs @@ -1,5 +1,5 @@ use clap::Args; -use magicblock_config_macro::{clap_from_serde, clap_prefix}; +use magicblock_config_macro::{clap_from_serde, clap_prefix, Mergeable}; use serde::{Deserialize, Serialize}; use crate::helpers::serde_defaults::bool_true; @@ -9,7 +9,9 @@ pub const DEFAULT_LEDGER_SIZE_BYTES: u64 = 100 * 1024 * 1024 * 1024; #[clap_prefix("ledger")] #[clap_from_serde] -#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args)] +#[derive( + Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args, Mergeable, +)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] pub struct LedgerConfig { /// If a previous ledger is found it is removed before starting the validator @@ -34,22 +36,6 @@ pub struct LedgerConfig { pub size: u64, } -impl LedgerConfig { - pub fn merge(&mut self, other: LedgerConfig) { - if self.reset == bool_true() && other.reset != bool_true() { - self.reset = other.reset; - } - if self.path == Default::default() && other.path != Default::default() { - self.path = other.path; - } - if self.size == default_ledger_size() - && other.size != default_ledger_size() - { - self.size = other.size; - } - } -} - impl Default for LedgerConfig { fn default() -> Self { Self { @@ -66,6 +52,8 @@ const fn default_ledger_size() -> u64 { #[cfg(test)] mod tests { + use magicblock_config_helpers::Merge; + use super::*; #[test] diff --git a/magicblock-config/src/lib.rs b/magicblock-config/src/lib.rs index 416dc0b78..85a026d33 100644 --- a/magicblock-config/src/lib.rs +++ b/magicblock-config/src/lib.rs @@ -2,6 +2,7 @@ use std::{fmt, fs, path::PathBuf, str::FromStr}; use clap::Args; use errors::{ConfigError, ConfigResult}; +use magicblock_config_macro::Mergeable; use serde::{Deserialize, Serialize}; use solana_sdk::pubkey::Pubkey; @@ -27,7 +28,15 @@ pub use rpc::*; pub use validator::*; #[derive( - Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize, Args, + Debug, + Default, + Clone, + PartialEq, + Eq, + Deserialize, + Serialize, + Args, + Mergeable, )] #[serde(deny_unknown_fields)] pub struct EphemeralConfig { @@ -101,21 +110,6 @@ impl EphemeralConfig { Ok(config) } - pub fn merge(&mut self, other: EphemeralConfig) { - // If other differs from the default but not self, use the value from other - // Otherwise, use the value from self - self.accounts.merge(other.accounts); - self.rpc.merge(other.rpc); - self.geyser_grpc.merge(other.geyser_grpc.clone()); - self.validator.merge(other.validator.clone()); - self.ledger.merge(other.ledger.clone()); - self.metrics.merge(other.metrics.clone()); - - if self.programs.is_empty() && !other.programs.is_empty() { - self.programs = other.programs.clone(); - } - } - pub fn post_parse(&mut self) { if self.accounts.remote.url.is_some() { match &self.accounts.remote.ws_url { @@ -162,6 +156,7 @@ mod tests { use std::net::{IpAddr, Ipv4Addr}; use isocountry::CountryCode; + use magicblock_config_helpers::Merge; use solana_sdk::pubkey::Pubkey; use url::Url; diff --git a/magicblock-config/src/metrics.rs b/magicblock-config/src/metrics.rs index 5a396f8fa..856062e39 100644 --- a/magicblock-config/src/metrics.rs +++ b/magicblock-config/src/metrics.rs @@ -1,5 +1,5 @@ use clap::Args; -use magicblock_config_macro::{clap_from_serde, clap_prefix}; +use magicblock_config_macro::{clap_from_serde, clap_prefix, Mergeable}; use serde::{Deserialize, Serialize}; use crate::helpers; @@ -13,7 +13,9 @@ helpers::socket_addr_config! { #[clap_prefix("metrics")] #[clap_from_serde] -#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args)] +#[derive( + Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args, Mergeable, +)] pub struct MetricsConfig { #[derive_env_var] #[arg(help = "Whether to enable metrics.")] @@ -30,25 +32,6 @@ pub struct MetricsConfig { pub service: MetricsServiceConfig, } -impl MetricsConfig { - pub fn merge(&mut self, other: MetricsConfig) { - if self.enabled == helpers::serde_defaults::bool_true() - && other.enabled != helpers::serde_defaults::bool_true() - { - self.enabled = other.enabled; - } - if self.system_metrics_tick_interval_secs - == default_system_metrics_tick_interval_secs() - && other.system_metrics_tick_interval_secs - != default_system_metrics_tick_interval_secs() - { - self.system_metrics_tick_interval_secs = - other.system_metrics_tick_interval_secs; - } - self.service.merge(other.service); - } -} - impl Default for MetricsConfig { fn default() -> Self { Self { @@ -68,6 +51,8 @@ fn default_system_metrics_tick_interval_secs() -> u64 { mod tests { use std::net::{IpAddr, Ipv4Addr}; + use magicblock_config_helpers::Merge; + use super::*; #[test] diff --git a/magicblock-config/src/rpc.rs b/magicblock-config/src/rpc.rs index ea83bce09..618890d22 100644 --- a/magicblock-config/src/rpc.rs +++ b/magicblock-config/src/rpc.rs @@ -1,12 +1,14 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use clap::Args; -use magicblock_config_macro::{clap_from_serde, clap_prefix}; +use magicblock_config_macro::{clap_from_serde, clap_prefix, Mergeable}; use serde::{Deserialize, Serialize}; #[clap_prefix("rpc")] #[clap_from_serde] -#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args)] +#[derive( + Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args, Mergeable, +)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] pub struct RpcConfig { #[derive_env_var] @@ -26,22 +28,6 @@ pub struct RpcConfig { pub max_ws_connections: usize, } -impl RpcConfig { - pub fn merge(&mut self, other: RpcConfig) { - if self.addr == default_addr() && other.addr != default_addr() { - self.addr = other.addr; - } - if self.port == default_port() && other.port != default_port() { - self.port = other.port; - } - if self.max_ws_connections == default_max_ws_connections() - && other.max_ws_connections != default_max_ws_connections() - { - self.max_ws_connections = other.max_ws_connections; - } - } -} - impl Default for RpcConfig { fn default() -> Self { Self { @@ -97,6 +83,8 @@ fn default_max_ws_connections() -> usize { #[cfg(test)] mod tests { + use magicblock_config_helpers::Merge; + use super::*; #[test] diff --git a/magicblock-config/src/validator.rs b/magicblock-config/src/validator.rs index 55eb0590a..5440a5415 100644 --- a/magicblock-config/src/validator.rs +++ b/magicblock-config/src/validator.rs @@ -1,11 +1,13 @@ use clap::Args; use isocountry::CountryCode; -use magicblock_config_macro::{clap_from_serde, clap_prefix}; +use magicblock_config_macro::{clap_from_serde, clap_prefix, Mergeable}; use serde::{Deserialize, Serialize}; #[clap_prefix("validator")] #[clap_from_serde] -#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args)] +#[derive( + Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args, Mergeable, +)] #[serde(deny_unknown_fields)] pub struct ValidatorConfig { #[derive_env_var] @@ -46,34 +48,6 @@ pub struct ValidatorConfig { pub country_code: CountryCode, } -impl ValidatorConfig { - pub fn merge(&mut self, other: ValidatorConfig) { - if self.millis_per_slot == default_millis_per_slot() - && other.millis_per_slot != default_millis_per_slot() - { - self.millis_per_slot = other.millis_per_slot; - } - if self.sigverify == default_sigverify() - && other.sigverify != default_sigverify() - { - self.sigverify = other.sigverify; - } - if self.fqdn == default_fqdn() && other.fqdn != default_fqdn() { - self.fqdn = other.fqdn; - } - if self.base_fees == default_base_fees() - && other.base_fees != default_base_fees() - { - self.base_fees = other.base_fees; - } - if self.country_code == default_country_code() - && other.country_code != default_country_code() - { - self.country_code = other.country_code; - } - } -} - impl Default for ValidatorConfig { fn default() -> Self { Self { @@ -118,6 +92,8 @@ fn parse_country_code(s: &str) -> Result { #[cfg(test)] mod tests { + use magicblock_config_helpers::Merge; + use super::*; #[test] diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 9602bdfa4..4f0574064 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -3813,6 +3813,7 @@ dependencies = [ "bs58 0.4.0", "clap 4.5.41", "isocountry", + "magicblock-config-helpers", "magicblock-config-macro", "serde", "solana-sdk", @@ -3822,6 +3823,10 @@ dependencies = [ "url 2.5.4", ] +[[package]] +name = "magicblock-config-helpers" +version = "0.1.7" + [[package]] name = "magicblock-config-macro" version = "0.1.7" From 42bfd2386c7cba5797661e40996bbd128109cb99 Mon Sep 17 00:00:00 2001 From: Dodecahedr0x <90185028+Dodecahedr0x@users.noreply.github.com> Date: Mon, 28 Jul 2025 10:23:25 +0200 Subject: [PATCH 130/199] refactor: rename entrypoint (#481) Closes #459 Renames the `test-bins` crate into `magicblock-validator` and the binary from `rpc` to `magicblock-validator` --- Cargo.lock | 32 +++++++++---------- Cargo.toml | 2 +- .../Cargo.toml | 8 ++--- .../src/main.rs | 0 .../src/shutdown.rs | 0 5 files changed, 19 insertions(+), 23 deletions(-) rename {test-bins => magicblock-validator}/Cargo.toml (89%) rename test-bins/src/rpc.rs => magicblock-validator/src/main.rs (100%) rename {test-bins => magicblock-validator}/src/shutdown.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index a487d3459..cd5ad49db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4394,6 +4394,22 @@ dependencies = [ "solana-transaction-status", ] +[[package]] +name = "magicblock-validator" +version = "0.1.7" +dependencies = [ + "clap 4.5.40", + "console-subscriber", + "env_logger 0.11.8", + "git-version", + "log", + "magicblock-api", + "magicblock-config", + "solana-sdk", + "test-tools", + "tokio", +] + [[package]] name = "magicblock-version" version = "0.1.7" @@ -10862,22 +10878,6 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" -[[package]] -name = "test-bins" -version = "0.1.7" -dependencies = [ - "clap 4.5.40", - "console-subscriber", - "env_logger 0.11.8", - "git-version", - "log", - "magicblock-api", - "magicblock-config", - "solana-sdk", - "test-tools", - "tokio", -] - [[package]] name = "test-tools" version = "0.1.7" diff --git a/Cargo.toml b/Cargo.toml index 8d5a92fb4..a4200ef61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,8 +33,8 @@ members = [ "magicblock-table-mania", "magicblock-tokens", "magicblock-transaction-status", + "magicblock-validator", "magicblock-version", - "test-bins", "test-tools", "test-tools-core", "utils/expiring-hashmap", diff --git a/test-bins/Cargo.toml b/magicblock-validator/Cargo.toml similarity index 89% rename from test-bins/Cargo.toml rename to magicblock-validator/Cargo.toml index 8c966ffb2..dda0eefe3 100644 --- a/test-bins/Cargo.toml +++ b/magicblock-validator/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "test-bins" +name = "magicblock-validator" version.workspace = true authors.workspace = true repository.workspace = true homepage.workspace = true license.workspace = true edition.workspace = true -default-run = "rpc" +default-run = "magicblock-validator" [dependencies] clap = { workspace = true, features = ["derive", "env"] } @@ -20,10 +20,6 @@ test-tools = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread"] } git-version = { workspace = true } -[[bin]] -name = "rpc" -path = "src/rpc.rs" - [features] default = [] tokio-console = ["console-subscriber", "tokio/tracing"] diff --git a/test-bins/src/rpc.rs b/magicblock-validator/src/main.rs similarity index 100% rename from test-bins/src/rpc.rs rename to magicblock-validator/src/main.rs diff --git a/test-bins/src/shutdown.rs b/magicblock-validator/src/shutdown.rs similarity index 100% rename from test-bins/src/shutdown.rs rename to magicblock-validator/src/shutdown.rs From 26a4004787af4c5f3de754a3011931dd4d013b97 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 28 Jul 2025 18:55:46 +0900 Subject: [PATCH 131/199] refactor: error handling + removed some unwraps --- .../src/commit_scheduler/commit_id_tracker.rs | 2 +- .../commit_scheduler_worker.rs | 10 ++++- .../src/committor_processor.rs | 4 +- .../src/persist/commit_persister.rs | 2 +- .../src/tasks/task_strategist.rs | 38 ++++++++++++------- .../src/tasks/tasks.rs | 9 +++-- .../src/tasks/utils.rs | 17 +++++---- .../transaction_preparator.rs | 4 ++ 8 files changed, 55 insertions(+), 31 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs index 43deaec16..c7be9c2c3 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs @@ -61,7 +61,7 @@ impl CommitIdTrackerImpl { err @ Err(Error::InvalidAccountDataError(_)) => return err, err @ Err(Error::MetadataNotFoundError(_)) => return err, Err(Error::MagicBlockRpcClientError(err)) => { - // TODO: RPC error handlings should be more robus + // TODO: RPC error handlings should be more robust last_err = Error::MagicBlockRpcClientError(err) } }; diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index f75473a8d..86a738d63 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -122,8 +122,13 @@ where result_sender: broadcast::Sender, ) { loop { - // TODO: unwraps - let l1_message = self.next_scheduled_message().await.unwrap(); + let l1_message = match self.next_scheduled_message().await { + Ok(value) => value, + Err(err) => { + error!("Failed to get next message: {}", err); + break; + } + }; let Some(l1_message) = l1_message else { // Messages are blocked, skipping info!("Could not schedule any messages, as all of them are blocked!"); @@ -246,6 +251,7 @@ where match commit_ids { Ok(value) => value, Err(err) => { + // TODO(edwin): support contract and send result via receiver as well // At this point this is unrecoverable. // We just skip for now and pretend this message didn't exist error!("Failed to fetch commit nonces for message: {:?}, error: {:?}", l1_message, err); diff --git a/magicblock-committor-service/src/committor_processor.rs b/magicblock-committor-service/src/committor_processor.rs index 93cd4ea16..8d90ff1b5 100644 --- a/magicblock-committor-service/src/committor_processor.rs +++ b/magicblock-committor-service/src/committor_processor.rs @@ -146,8 +146,8 @@ impl CommittorProcessor { }; if let Err(err) = self.commits_scheduler.schedule(l1_messages).await { - error!("Failed to schedule L1 message: {}", err); - // TODO(edwin): handsle + // CommittorService broken + panic!("Failed to schedule L1 message: {}", err); } } diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 84215e6bc..7bf49afc2 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -70,7 +70,7 @@ pub trait L1MessagesPersisterIface: Send + Sync + Clone + 'static { pub struct L1MessagePersister { // DB that tracks lifespan of Commit intents commits_db: Arc>, - // TODO(edwin): something like + // TODO: add something like // actions_db: Arc> } diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index eee1c0809..7ec86ec4f 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -99,7 +99,9 @@ impl TaskStrategist { &instructions, &budget_instructions, &dummy_lookup_tables, - ); + ) + .map_err(|_| Error::FailedToFitError)?; + let encoded_alt_tx = serialize_and_encode_base64(&alt_tx); if encoded_alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE { Ok(unique_involved_pubkeys) @@ -112,9 +114,14 @@ impl TaskStrategist { /// Returns size of tx after optimizations fn optimize_strategy(tasks: &mut [Box]) -> usize { // Get initial transaction size - let tx = - TransactionUtils::assemble_tasks_tx(&Keypair::new(), &tasks, &[]); - let mut current_tx_length = serialize_and_encode_base64(&tx).len(); + let current_tx_length = match TransactionUtils::assemble_tasks_tx( + &Keypair::new(), + &tasks, + &[], + ) { + Ok(tx) => serialize_and_encode_base64(&tx).len(), + Err(_) => usize::MAX, + }; // Create heap size -> index // TODO(edwin): OPTIMIZATION. update ixs arr, since we know index, coul then reuse for tx creation @@ -156,21 +163,24 @@ impl TaskStrategist { // 3. Update overall tx size Ok(optimized_task) => { tasks[index] = optimized_task; - // TODO(edwin): this is expensive let new_ix = tasks[index].instruction(&Pubkey::new_unique()); let new_ix_size = bincode::serialized_size(&new_ix) .expect("instruction serialization") - as usize; // TODO(edwin): unwrap - let new_tx = TransactionUtils::assemble_tasks_tx( - &Keypair::new(), - &tasks, - &[], - ); - + as usize; + + let current_tx_length = + match TransactionUtils::assemble_tasks_tx( + &Keypair::new(), + &tasks, + &[], + ) { + Ok(new_tx) => { + serialize_and_encode_base64(&new_tx).len() + } + Err(_) => usize::MAX, + }; map.push((new_ix_size, index)); - current_tx_length = - serialize_and_encode_base64(&new_tx).len(); } // That means el-t can't be optimized further // We move it back with oldest state diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index 86a6f5712..22cb37caa 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -87,6 +87,7 @@ pub trait L1Task: Send + Sync { #[derive(Clone)] pub struct CommitTask { + // TODO: rename to commit_nonce? pub commit_id: u64, pub allow_undelegation: bool, pub committed_account: CommittedAccountV2, @@ -124,10 +125,10 @@ impl L1Task for ArgsTask { match self { Self::Commit(value) => { let args = CommitStateArgs { - slot: value.commit_id, // TODO(edwin): change slot, + slot: value.commit_id, lamports: value.committed_account.account.lamports, data: value.committed_account.account.data.clone(), - allow_undelegation: value.allow_undelegation, // TODO(edwin): + allow_undelegation: value.allow_undelegation, }; dlp::instruction_builder::commit_state( *validator, @@ -204,7 +205,7 @@ impl L1Task for ArgsTask { #[derive(Clone)] pub enum BufferTask { Commit(CommitTask), - // TODO(edwin): Action in the future + // Action in the future } impl L1Task for BufferTask { @@ -224,7 +225,7 @@ impl L1Task for BufferTask { value.committed_account.account.owner, commit_buffer_pubkey, CommitStateFromBufferArgs { - slot: value.commit_id, //TODO(edwin): change to commit_id + slot: value.commit_id, lamports: value.committed_account.account.lamports, allow_undelegation: value.allow_undelegation, }, diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index fddefe615..a3c93c56f 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -4,7 +4,9 @@ use solana_pubkey::Pubkey; use solana_sdk::{ hash::Hash, instruction::Instruction, - message::{v0::Message, AddressLookupTableAccount, VersionedMessage}, + message::{ + v0::Message, AddressLookupTableAccount, CompileError, VersionedMessage, + }, signature::Keypair, signer::Signer, transaction::VersionedTransaction, @@ -75,7 +77,7 @@ impl TransactionUtils { authority: &Keypair, tasks: &[Box], lookup_tables: &[AddressLookupTableAccount], - ) -> VersionedTransaction { + ) -> Result { let budget_instructions = Self::budget_instructions(&Self::tasks_budgets(&tasks)); let ixs = Self::tasks_instructions(&authority.pubkey(), &tasks); @@ -92,20 +94,21 @@ impl TransactionUtils { instructions: &[Instruction], budget_instructions: &[Instruction], lookup_tables: &[AddressLookupTableAccount], - ) -> VersionedTransaction { + ) -> Result { let message = Message::try_compile( &authority.pubkey(), &[budget_instructions, instructions].concat(), &lookup_tables, Hash::new_unique(), - ) - .unwrap(); // TODO(edwin): unwrap + )?; + // SignerError is critical let tx = VersionedTransaction::try_new( VersionedMessage::V0(message), &[authority], ) - .unwrap(); - tx + .expect("Signing transaction has to be non-failing"); + + Ok(tx) } pub fn tasks_budgets( diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 2cdc86056..b75aff70d 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -127,7 +127,9 @@ impl TransactionPreparator for TransactionPreparatorV1 { &tx_strategy.optimized_tasks, &lookup_tables, ) + .expect("TaskStrategist had to fail prior. This shouldn't be reachable") .message; + Ok(message) } @@ -163,7 +165,9 @@ impl TransactionPreparator for TransactionPreparatorV1 { &tx_strategy.optimized_tasks, &lookup_tables, ) + .expect("TaskStrategist had to fail prior. This shouldn't be reachable") .message; + Ok(message) } } From 1f509db801cafd5af331d19dd1ada0135112175a Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 28 Jul 2025 18:58:54 +0900 Subject: [PATCH 132/199] refactor: repeating function --- .../src/tasks/task_strategist.rs | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 7ec86ec4f..0586befa6 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -114,15 +114,20 @@ impl TaskStrategist { /// Returns size of tx after optimizations fn optimize_strategy(tasks: &mut [Box]) -> usize { // Get initial transaction size - let current_tx_length = match TransactionUtils::assemble_tasks_tx( - &Keypair::new(), - &tasks, - &[], - ) { - Ok(tx) => serialize_and_encode_base64(&tx).len(), - Err(_) => usize::MAX, + let calculate_tx_length = |tasks: &[Box] | { + match TransactionUtils::assemble_tasks_tx( + &Keypair::new(), + &tasks, + &[], + ) { + Ok(tx) => serialize_and_encode_base64(&tx).len(), + Err(_) => usize::MAX, + } }; + // Get initial transaction size + let mut current_tx_length = calculate_tx_length(tasks); + // Create heap size -> index // TODO(edwin): OPTIMIZATION. update ixs arr, since we know index, coul then reuse for tx creation let ixs = @@ -169,17 +174,7 @@ impl TaskStrategist { .expect("instruction serialization") as usize; - let current_tx_length = - match TransactionUtils::assemble_tasks_tx( - &Keypair::new(), - &tasks, - &[], - ) { - Ok(new_tx) => { - serialize_and_encode_base64(&new_tx).len() - } - Err(_) => usize::MAX, - }; + current_tx_length = calculate_tx_length(tasks); map.push((new_ix_size, index)); } // That means el-t can't be optimized further From cddc9cc86c8adb60d75326d05efb4cbc55e2ff4b Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 29 Jul 2025 17:17:44 +0900 Subject: [PATCH 133/199] feat: fixes + delivery preparator tests --- .../bin/magicblock_committor_program.so | Bin 0 -> 127320 bytes .../src/instruction_chunks.rs | 6 +- .../src/compute_budget.rs | 4 +- .../src/tasks/budget_calculator.rs | 76 ------ .../src/tasks/task_strategist.rs | 11 +- .../src/tasks/tasks.rs | 29 +-- .../src/tasks/utils.rs | 28 ++- .../delivery_preparator.rs | 34 +-- .../src/transaction_preperator/mod.rs | 2 +- .../transaction_preparator.rs | 6 +- magicblock-committor-service/tests/common.rs | 70 ++++++ .../tests/test_delivery_preparator.rs | 216 ++++++++++++++++++ programs/magicblock/src/args.rs | 1 + .../src/magic_scheduled_l1_message.rs | 2 + 14 files changed, 357 insertions(+), 128 deletions(-) create mode 100755 magicblock-committor-program/bin/magicblock_committor_program.so create mode 100644 magicblock-committor-service/tests/common.rs create mode 100644 magicblock-committor-service/tests/test_delivery_preparator.rs diff --git a/magicblock-committor-program/bin/magicblock_committor_program.so b/magicblock-committor-program/bin/magicblock_committor_program.so new file mode 100755 index 0000000000000000000000000000000000000000..5bbb574c068489f98f9b707b755010afeb06054d GIT binary patch literal 127320 zcmeFa37lO=aW8!C%v@~&MvIRn288Zt_rSndwy`bnV`N#jkO9lfMaDr`9b9${{&Nmt`y~zbh zThg0MO{OSpSzszwT#TQ6lm#9q(}@tdljPs=$5>vBd(R@A$8o(jDSGY*>lNeU-K^)a z*K3h%wAW+xit$sdmUukH()GpsQJ=~9X(>Rt`^pzLN30e#U4A0r<6DVK(CKm2BW?FkeEo%yj*HrsoK9?*rQD z9%M&~bY(Td*FCm&?~!qOs3%E^@ZJyS$7Esbu@fgwJdH*qbk8)ptnum;qiX@n=K%f= z{zjFwgpo;-b&_~q@YI)SQroqzEC0G@vH|b`sGpW<;5_IYsEnmE>m;6RD+$SN5I_mp z4a^6gRDOa_J-V0?hRdl}mp zGhPc7Oz}4HrIih>6Fkb7iw#a1ZQ{!^P(k@9^5xo0eL&2avZ%qk83pa)JE&qkQ0dmEfzd0Cw_W*^;sS20uW5ksrw4GJpL1 zpPm5zo+!WW<36)let>tW*z)n(`&`HP`RBAZ@^ic=k*C*3_+O43eNg%n%TaG(TyK%I z_v7WXQ!BLdjY2zfBl&qb?c7vo=i-81+#0px{VK+}{+fLVrk|5V{lr|K$W~I`s%;{G z62iG0|3VB=c}z&Z-Ldz%dOtbUgDi`0pnR3B{`n6na=STosDwC(`ofY z1+{&%YgN%RgwSd2=jBX0KQP}Q_`Krz9z!4NANk842h7plkDtg4AM(EuUO0^WPi_4D zM~n4y`97C^L@@iCw$Qh#w$RSyet_T;5|gLJnL(Vk(ZKlp1ATjJ9^`l_nv`-tA^jgG z5QlT{w^85m1{;rX4*Q+9zLs!oKDp&wK`KH07yV^^%_U4I^+Ws(j(WTGUgp)!PnmZf z)1V*WX~D1k5wnN5+x!@(t2&wV*Wat)$sEB$3fX@50Ic3vy0RMy@BUDo>`m%@mOscC z{Q9uyNw$etv+a^0A=}P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SES|M;IPwc#`26hQ$Y` zZS!N!(|UU>hW!jzF&tpHf#C?l35L%wJjC!Q!{ZE3GCalbd4>&j!G-iw9>W&Heuk?U z4lvxnaD?FjhKCp)Wq6$7Nrq<_KF@H@r}X~KW7yAd1;YV`k1-r!xR2pMhR-lO!tf}= z6AVu?YGgvQ2Zo|pJCWLuD6H2VNL0W3>lvR`V4=aUnCV9Vki8|d6$ld zZS)vF!tn6Q6uk@6uhsGNIvo$K*D*buh2>* z%-d5q4SrgGmBJqQ*>E<6aSV(Pq~ss*v9G7%)8XgHeW`ftQ==#r>WdjgO>um)DEQ)G z{7`!lJUw634L(H3*m#HVgB@*+Mp3jCsNv-*KoiC!vXDRFFV+hGVH?p|vYJVM;$130 zMkn__6*Q{g2U09l0WzE@@^%D|tLK2Oo3EMVD`p6>sX|FEJXPi03? rJRgMeLFwuF1oG+m1e8g1R6f( start_size: u16, ) { let mut total_size = start_size; - while total_size + IX_REALLOC_SIZE < MAX_INSTRUCTION_DATA_SIZE { + while total_size + IX_REALLOC_SIZE < MAX_INSTRUCTION_DATA_SIZE + && chunk.len() < MAX_INSTRUCTION_LENGTH as usize + { if let Some(realloc) = reallocs.pop() { chunk.push(realloc); total_size += IX_REALLOC_SIZE; diff --git a/magicblock-committor-service/src/compute_budget.rs b/magicblock-committor-service/src/compute_budget.rs index 1dacc425f..229cffbdb 100644 --- a/magicblock-committor-service/src/compute_budget.rs +++ b/magicblock-committor-service/src/compute_budget.rs @@ -74,6 +74,7 @@ impl BufferWriteChunkBudget { // ----------------- #[derive(Debug, Clone)] pub struct ComputeBudgetConfig { + pub compute_unit_price: u64, pub args_process: Budget, pub finalize: Budget, pub buffer_close: Budget, @@ -90,6 +91,7 @@ pub struct ComputeBudgetConfig { impl ComputeBudgetConfig { pub fn new(compute_unit_price: u64) -> Self { Self { + compute_unit_price, args_process: Budget { compute_unit_price, base_budget: 80_000, @@ -187,7 +189,7 @@ impl ComputeBudget { } } - fn compute_unit_price(&self) -> u64 { + pub fn compute_unit_price(&self) -> u64 { use ComputeBudget::*; match self { Process(budget) => budget.compute_unit_price, diff --git a/magicblock-committor-service/src/tasks/budget_calculator.rs b/magicblock-committor-service/src/tasks/budget_calculator.rs index 70eb97f83..1c23b23f5 100644 --- a/magicblock-committor-service/src/tasks/budget_calculator.rs +++ b/magicblock-committor-service/src/tasks/budget_calculator.rs @@ -11,79 +11,3 @@ pub struct ComputeBudgetV1 { pub compute_budget: u32, pub compute_unit_price: u64, } - -impl ComputeBudgetV1 { - /// Needed just to create dummy ixs, and evaluate size - fn dummy() -> Self { - Self { - compute_budget: 0, - compute_unit_price: 0, - } - } -} - -pub trait ComputeBudgetCalculator { - fn budget_instructions(budget: ComputeBudgetV1) -> [Instruction; 2]; - - /// Calculate budget for commit transaction - fn calculate_commit_budget( - &self, - l1_message: &ScheduledL1Message, - ) -> ComputeBudgetV1; - /// Calculate budget for finalze transaction - fn calculate_finalize_budget( - &self, - l1_message: &ScheduledL1Message, - ) -> ComputeBudgetV1; -} - -/// V1 implementation, works with TransactionPreparator V1 -/// Calculations for finalize may include cases for -pub struct ComputeBudgetCalculatorV1 { - compute_budget_config: ComputeBudgetConfig, -} - -impl ComputeBudgetCalculatorV1 { - pub fn new(config: ComputeBudgetConfig) -> Self { - Self { - compute_budget_config: config, - } - } -} - -impl ComputeBudgetCalculator for ComputeBudgetCalculatorV1 { - /// Calculate compute budget for V1 commit transaction - /// This includes only compute for account commits - fn calculate_commit_budget( - &self, - l1_message: &ScheduledL1Message, - ) -> ComputeBudgetV1 { - todo!() - } - - fn calculate_finalize_budget( - &self, - l1_message: &ScheduledL1Message, - ) -> ComputeBudgetV1 { - todo!() - } - - fn budget_instructions(budget: ComputeBudgetV1) -> [Instruction; 2] { - let compute_budget_ix = - ComputeBudgetInstruction::set_compute_unit_limit( - budget.compute_budget, - ); - let compute_unit_price_ix = - ComputeBudgetInstruction::set_compute_unit_price( - budget.compute_unit_price, - ); - - [compute_budget_ix, compute_unit_price_ix] - } -} - -// We need to create an optimal TX -// Optimal tx - [ComputeBudget, Args(acc1), Buffer(acc2), Args(Action))] -// Estimate actual budget -// Recreate TX -// diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 0586befa6..4c176ae0b 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -75,14 +75,14 @@ impl TaskStrategist { /// Attempt to use ALTs for ALL keys in tx /// TODO: optimize to use only necessary amount of pubkeys - fn attempt_lookup_tables( + pub fn attempt_lookup_tables( validator: &Pubkey, tasks: &[Box], ) -> TaskStrategistResult> { // Gather all involved keys in tx - let budgets = TransactionUtils::tasks_budgets(&tasks); + let budgets = TransactionUtils::tasks_compute_units(&tasks); let budget_instructions = - TransactionUtils::budget_instructions(&budgets); + TransactionUtils::budget_instructions(budgets, u64::default()); let unique_involved_pubkeys = TransactionUtils::unique_involved_pubkeys( &tasks, validator, @@ -114,10 +114,11 @@ impl TaskStrategist { /// Returns size of tx after optimizations fn optimize_strategy(tasks: &mut [Box]) -> usize { // Get initial transaction size - let calculate_tx_length = |tasks: &[Box] | { + let calculate_tx_length = |tasks: &[Box]| { match TransactionUtils::assemble_tasks_tx( - &Keypair::new(), + &Keypair::new(), // placeholder &tasks, + u64::default(), // placeholder &[], ) { Ok(tx) => serialize_and_encode_base64(&tx).len(), diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index 22cb37caa..f769fc14d 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -64,19 +64,7 @@ pub trait L1Task: Send + Sync { ) -> Option; /// Returns [`Task`] budget - fn budget(&self) -> ComputeBudgetV1; - - /// Returns Instructions per TX - // TODO(edwin): shall be here? - fn instructions_from_info( - &self, - info: &TaskPreparationInfo, - ) -> Vec> { - chunk_realloc_ixs( - info.realloc_instructions.clone(), - Some(info.init_instruction.clone()), - ) - } + fn compute_units(&self) -> u32; /// Returns current [`TaskStrategy`] fn strategy(&self) -> TaskStrategy; @@ -187,8 +175,13 @@ impl L1Task for ArgsTask { None } - fn budget(&self) -> ComputeBudgetV1 { - todo!() + fn compute_units(&self) -> u32 { + match self { + Self::Commit(_) => 35_000, + Self::L1Action(task) => task.action.compute_units, + Self::Undelegate(_) => 35_000, + Self::Finalize(_) => 25_000, + } } fn strategy(&self) -> TaskStrategy { @@ -295,8 +288,10 @@ impl L1Task for BufferTask { }) } - fn budget(&self) -> ComputeBudgetV1 { - todo!() + fn compute_units(&self) -> u32 { + match self { + Self::Commit(_) => 45_000, + } } fn strategy(&self) -> TaskStrategy { diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index a3c93c56f..45d425f1f 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -2,6 +2,7 @@ use std::collections::HashSet; use solana_pubkey::Pubkey; use solana_sdk::{ + compute_budget::ComputeBudgetInstruction, hash::Hash, instruction::Instruction, message::{ @@ -76,10 +77,13 @@ impl TransactionUtils { pub fn assemble_tasks_tx( authority: &Keypair, tasks: &[Box], + compute_unit_price: u64, lookup_tables: &[AddressLookupTableAccount], ) -> Result { - let budget_instructions = - Self::budget_instructions(&Self::tasks_budgets(&tasks)); + let budget_instructions = Self::budget_instructions( + Self::tasks_compute_units(&tasks), + compute_unit_price, + ); let ixs = Self::tasks_instructions(&authority.pubkey(), &tasks); Self::assemble_tx_raw( authority, @@ -111,18 +115,20 @@ impl TransactionUtils { Ok(tx) } - pub fn tasks_budgets( - tasks: &[impl AsRef], - ) -> Vec { - tasks - .iter() - .map(|task| task.as_ref().budget()) - .collect::>() + pub fn tasks_compute_units(tasks: &[impl AsRef]) -> u32 { + tasks.iter().map(|task| task.as_ref().compute_units()).sum() } pub fn budget_instructions( - budgets: &[ComputeBudgetV1], + compute_units: u32, + compute_unit_price: u64, ) -> [Instruction; 2] { - todo!() + let compute_budget_ix = + ComputeBudgetInstruction::set_compute_unit_limit(compute_units); + let compute_unit_price_ix = + ComputeBudgetInstruction::set_compute_unit_price( + compute_unit_price, + ); + [compute_budget_ix, compute_unit_price_ix] } } diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 65fc09dce..746e13d08 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -4,7 +4,9 @@ use anyhow::anyhow; use borsh::BorshDeserialize; use futures_util::future::{join, join_all}; use log::error; -use magicblock_committor_program::Chunks; +use magicblock_committor_program::{ + instruction_chunks::chunk_realloc_ixs, Chunks, +}; use magicblock_rpc_client::{ MagicBlockRpcClientError, MagicBlockSendTransactionConfig, MagicblockRpcClient, @@ -29,6 +31,7 @@ use crate::{ task_strategist::TransactionStrategy, tasks::{L1Task, TaskPreparationInfo}, }, + transactions::serialize_and_encode_base64, utils::persist_status_update, ComputeBudgetConfig, }; @@ -40,7 +43,7 @@ pub struct DeliveryPreparationResult { pub struct DeliveryPreparator { rpc_client: MagicblockRpcClient, table_mania: TableMania, - compute_budget_config: ComputeBudgetConfig, // TODO(edwin): needed? + compute_budget_config: ComputeBudgetConfig, } impl DeliveryPreparator { @@ -82,8 +85,7 @@ impl DeliveryPreparator { } /// Prepares necessary parts for TX if needed, otherwise returns immediately - // TODO(edwin): replace with interfaces - async fn prepare_task( + pub async fn prepare_task( &self, authority: &Keypair, task: &Box, @@ -143,11 +145,13 @@ impl DeliveryPreparator { async fn initialize_buffer_account( &self, authority: &Keypair, - task: &dyn L1Task, + _task: &dyn L1Task, preparation_info: &TaskPreparationInfo, ) -> DeliveryPreparatorResult<(), InternalError> { - let preparation_instructions = - task.instructions_from_info(&preparation_info); + let preparation_instructions = chunk_realloc_ixs( + preparation_info.realloc_instructions.clone(), + Some(preparation_info.init_instruction.clone()), + ); let preparation_instructions = preparation_instructions .into_iter() .enumerate() @@ -156,13 +160,13 @@ impl DeliveryPreparator { let init_budget_ixs = self .compute_budget_config .buffer_init - .instructions(ixs.len() - 1); + .instructions(ixs.len()); init_budget_ixs } else { let realloc_budget_ixs = self .compute_budget_config .buffer_realloc - .instructions(ixs.len() - 1); + .instructions(ixs.len()); realloc_budget_ixs }; ixs_with_budget.extend(ixs.into_iter()); @@ -270,7 +274,6 @@ impl DeliveryPreparator { Ok(()) } - // TODO(edwin): move somewhere appropritate // CommitProcessor::init_accounts analog async fn send_ixs_with_retry( &self, @@ -282,7 +285,10 @@ impl DeliveryPreparator { for _ in 0..MAX_RETRIES { match self.try_send_ixs(instructions, authority).await { Ok(()) => return Ok(()), - Err(err) => last_error = err, + Err(err) => { + println!("Failed attempt to send tx: {:?}", err); + last_error = err; + } } sleep(Duration::from_millis(200)).await; } @@ -341,9 +347,9 @@ impl DeliveryPreparator { } // TODO(edwin): cleanup - async fn clean() { - todo!() - } + // async fn clean() { + // todo!() + // } } #[derive(thiserror::Error, Debug)] diff --git a/magicblock-committor-service/src/transaction_preperator/mod.rs b/magicblock-committor-service/src/transaction_preperator/mod.rs index 029398737..f16fd819d 100644 --- a/magicblock-committor-service/src/transaction_preperator/mod.rs +++ b/magicblock-committor-service/src/transaction_preperator/mod.rs @@ -1,3 +1,3 @@ -mod delivery_preparator; +pub mod delivery_preparator; pub mod error; pub mod transaction_preparator; diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index b75aff70d..26a6d3236 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -69,6 +69,7 @@ pub trait TransactionPreparator: Send + Sync + 'static { /// It creates TXs using current per account commit/finalize pub struct TransactionPreparatorV1 { delivery_preparator: DeliveryPreparator, + compute_budget_config: ComputeBudgetConfig, } impl TransactionPreparatorV1 { @@ -80,10 +81,11 @@ impl TransactionPreparatorV1 { let delivery_preparator = DeliveryPreparator::new( rpc_client, table_mania, - compute_budget_config, + compute_budget_config.clone(), ); Self { delivery_preparator, + compute_budget_config, } } } @@ -125,6 +127,7 @@ impl TransactionPreparator for TransactionPreparatorV1 { let message = TransactionUtils::assemble_tasks_tx( authority, &tx_strategy.optimized_tasks, + self.compute_budget_config.compute_unit_price, &lookup_tables, ) .expect("TaskStrategist had to fail prior. This shouldn't be reachable") @@ -163,6 +166,7 @@ impl TransactionPreparator for TransactionPreparatorV1 { let message = TransactionUtils::assemble_tasks_tx( authority, &tx_strategy.optimized_tasks, + self.compute_budget_config.compute_unit_price, &lookup_tables, ) .expect("TaskStrategist had to fail prior. This shouldn't be reachable") diff --git a/magicblock-committor-service/tests/common.rs b/magicblock-committor-service/tests/common.rs new file mode 100644 index 000000000..2b5c00fef --- /dev/null +++ b/magicblock-committor-service/tests/common.rs @@ -0,0 +1,70 @@ +use std::sync::Arc; + +use magicblock_committor_service::{ + transaction_preperator::delivery_preparator::DeliveryPreparator, + ComputeBudgetConfig, +}; +use magicblock_rpc_client::MagicblockRpcClient; +use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; +use solana_rpc_client::nonblocking::rpc_client::RpcClient; +use solana_sdk::{ + commitment_config::{CommitmentConfig, CommitmentLevel}, + signature::Keypair, + signer::Signer, + system_program, +}; +use tempfile::TempDir; + +// Helper function to create a test RPC client +pub async fn create_test_client() -> MagicblockRpcClient { + let url = "http://localhost:8899".to_string(); + let rpc_client = + RpcClient::new_with_commitment(url, CommitmentConfig::confirmed()); + + MagicblockRpcClient::new(Arc::new(rpc_client)) +} + +// Test fixture structure +pub struct TestFixture { + pub rpc_client: MagicblockRpcClient, + table_mania: TableMania, + pub authority: Keypair, + compute_budget_config: ComputeBudgetConfig, +} + +impl TestFixture { + pub async fn new() -> Self { + let authority = Keypair::new(); + let rpc_client = create_test_client().await; + + // TableMania + let gc_config = GarbageCollectorConfig::default(); + let table_mania = + TableMania::new(rpc_client.clone(), &authority, Some(gc_config)); + + // Airdrop some SOL to the authority for testing + rpc_client + .request_airdrop( + &authority.pubkey(), + 100_000_000_000, // 100 SOL + ) + .await + .unwrap(); + + let compute_budget_config = ComputeBudgetConfig::new(1_000_000); + Self { + rpc_client, + table_mania, + authority, + compute_budget_config, + } + } + + pub fn create_preparator(&self) -> DeliveryPreparator { + DeliveryPreparator::new( + self.rpc_client.clone(), + self.table_mania.clone(), + self.compute_budget_config.clone(), + ) + } +} diff --git a/magicblock-committor-service/tests/test_delivery_preparator.rs b/magicblock-committor-service/tests/test_delivery_preparator.rs new file mode 100644 index 000000000..6ae52b8a4 --- /dev/null +++ b/magicblock-committor-service/tests/test_delivery_preparator.rs @@ -0,0 +1,216 @@ +use std::sync::atomic::{AtomicU64, Ordering}; + +use borsh::BorshDeserialize; +use futures_util::StreamExt; +use magicblock_committor_program::Chunks; +use magicblock_committor_service::{ + persist::L1MessagePersister, + tasks::{ + task_strategist::TransactionStrategy, + tasks::{BufferTask, CommitTask, L1Task}, + }, +}; +use magicblock_program::magic_scheduled_l1_message::CommittedAccountV2; +use solana_account::Account; +use solana_pubkey::Pubkey; +use solana_sdk::signer::Signer; +use magicblock_committor_service::tasks::task_strategist::TaskStrategist; +use magicblock_committor_service::tasks::tasks::ArgsTask; +use magicblock_committor_service::transaction_preperator::delivery_preparator::DeliveryPreparator; +use crate::common::TestFixture; + +mod common; + +pub fn generate_random_bytes(length: usize) -> Vec { + use rand::Rng; + + let mut rng = rand::thread_rng(); + (0..length).map(|_| rng.gen()).collect() +} + +fn create_commit_task(data: &[u8]) -> CommitTask { + static COMMIT_ID: AtomicU64 = AtomicU64::new(0); + CommitTask { + commit_id: COMMIT_ID.fetch_add(1, Ordering::Relaxed), + allow_undelegation: false, + committed_account: CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 1000, + data: data.to_vec(), + owner: dlp::id(), + executable: false, + rent_epoch: 0, + }, + }, + } +} + +#[tokio::test] +async fn test_prepare_10kb_buffer() { + let fixture = TestFixture::new().await; + let preparator = fixture.create_preparator(); + + let data = generate_random_bytes(10 * 1024); + let buffer_task = BufferTask::Commit(create_commit_task(&data)); + let strategy = TransactionStrategy { + optimized_tasks: vec![Box::new(buffer_task)], + lookup_tables_keys: vec![], + }; + + // Test preparation + let result = preparator + .prepare_for_delivery( + &fixture.authority, + &strategy, + &None::, + ) + .await; + + assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); + + // Verify the buffer account was created and initialized + let preparation_info = strategy.optimized_tasks[0] + .preparation_info(&fixture.authority.pubkey()) + .expect("Task should have preparation info"); + + // Check buffer account exists + let buffer_account = fixture + .rpc_client + .get_account(&preparation_info.buffer_pda) + .await + .unwrap() + .expect("Buffer account should exist"); + + assert_eq!(buffer_account.data, data, "Buffer account size mismatch"); + + // Check chunks account exists + let chunks_account = fixture + .rpc_client + .get_account(&preparation_info.chunks_pda) + .await + .unwrap() + .expect("Chunks account should exist"); + + let chunks = Chunks::try_from_slice(&chunks_account.data) + .expect("Failed to deserialize chunks"); + + assert!( + chunks.is_complete(), + "Chunks should be marked as complete after preparation" + ); +} + +#[tokio::test] +async fn test_prepare_multiple_buffers() { + let fixture = TestFixture::new().await; + let preparator = fixture.create_preparator(); + + let datas = vec![ + generate_random_bytes(10 * 1024), + generate_random_bytes(10), + generate_random_bytes(500 * 1024), + ]; + let buffer_tasks = datas + .iter() + .map(|data| { + let task = BufferTask::Commit(create_commit_task(data.as_slice())); + Box::new(task) as Box + }) + .collect(); + let strategy = TransactionStrategy { + optimized_tasks: buffer_tasks, + lookup_tables_keys: vec![], + }; + + // Test preparation + let result = preparator + .prepare_for_delivery( + &fixture.authority, + &strategy, + &None::, + ) + .await; + + assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); + + // Verify the buffer account was created and initialized + let preparation_infos = strategy.optimized_tasks.iter().map(|el| { + el.preparation_info(&fixture.authority.pubkey()) + .expect("Task should have preparation info") + }); + + for (i, preparation_info) in preparation_infos.enumerate() { + // Check buffer account exists + let buffer_account = fixture + .rpc_client + .get_account(&preparation_info.buffer_pda) + .await + .unwrap() + .expect("Buffer account should exist"); + + assert_eq!( + buffer_account.data, datas[i], + "Buffer account size mismatch" + ); + + // Check chunks account exists + let chunks_account = fixture + .rpc_client + .get_account(&preparation_info.chunks_pda) + .await + .unwrap() + .expect("Chunks account should exist"); + + let chunks = Chunks::try_from_slice(&chunks_account.data) + .expect("Failed to deserialize chunks"); + + assert!( + chunks.is_complete(), + "Chunks should be marked as complete after preparation" + ); + } +} + +#[tokio::test] +async fn test_lookup_tables() { + let fixture = TestFixture::new().await; + let preparator = fixture.create_preparator(); + + let datas = vec![ + generate_random_bytes(10), + generate_random_bytes(20), + generate_random_bytes(30), + ]; + let tasks = datas + .iter() + .map(|data| { + let task = ArgsTask::Commit(create_commit_task(data.as_slice())); + Box::new(task) as Box + }) + .collect::>(); + + let lookup_tables_keys = TaskStrategist::attempt_lookup_tables(&fixture.authority.pubkey(), &tasks).unwrap(); + let strategy = TransactionStrategy { + optimized_tasks: tasks, + lookup_tables_keys + }; + + let result = preparator.prepare_for_delivery(&fixture.authority, &strategy, &None::).await; + assert!(result.is_ok(), "Failed to prepare lookup tables"); + + let alts = result.unwrap(); + // Verify the ALTs were actually created + for alt in alts { + let alt_account = fixture.rpc_client + .get_account(&alt.key) + .await + .unwrap() + .expect("ALT account should exist"); + + assert!( + !alt_account.data.is_empty(), + "ALT account should have data" + ); + } +} \ No newline at end of file diff --git a/programs/magicblock/src/args.rs b/programs/magicblock/src/args.rs index 72d8df1f0..c247aeb1d 100644 --- a/programs/magicblock/src/args.rs +++ b/programs/magicblock/src/args.rs @@ -9,6 +9,7 @@ pub struct ActionArgs { #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct L1ActionArgs { pub args: ActionArgs, + pub compute_units: u32, // compute units your action will use pub escrow_authority: u8, // index of account authorizing action on actor pda pub destination_program: u8, // index of the account pub accounts: Vec, // indices of account diff --git a/programs/magicblock/src/magic_scheduled_l1_message.rs b/programs/magicblock/src/magic_scheduled_l1_message.rs index 31247462a..45358fa74 100644 --- a/programs/magicblock/src/magic_scheduled_l1_message.rs +++ b/programs/magicblock/src/magic_scheduled_l1_message.rs @@ -182,6 +182,7 @@ pub struct ShortAccountMeta { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct L1Action { + pub compute_units: u32, pub destination_program: Pubkey, pub escrow_authority: Pubkey, pub data_per_program: ProgramArgs, @@ -242,6 +243,7 @@ impl L1Action { .collect::, InstructionError>>()?; Ok(L1Action { + compute_units: args.compute_units, destination_program: destination_program_pubkey, escrow_authority: *authority_pubkey, data_per_program: args.args.clone().into(), From 0e40f410f3299d5773a26cf623d68dc595260fd4 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 29 Jul 2025 17:36:50 +0900 Subject: [PATCH 134/199] feat: added delivery preparator test with lookup tables --- .../src/tasks/task_strategist.rs | 81 ++++++++++++------- .../tests/test_delivery_preparator.rs | 34 ++++---- 2 files changed, 71 insertions(+), 44 deletions(-) diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 4c176ae0b..1408f0b3d 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -1,7 +1,7 @@ use std::{collections::BinaryHeap, ptr::NonNull}; use solana_pubkey::Pubkey; -use solana_sdk::signature::Keypair; +use solana_sdk::{signature::Keypair, signer::Signer}; use crate::{ persist::L1MessagesPersisterIface, @@ -48,44 +48,45 @@ impl TaskStrategist { optimized_tasks: tasks, lookup_tables_keys: vec![], }) - } else { - // In case task optimization didn't work - // attempt using lookup tables for all keys involved in tasks - let lookup_tables_keys = - Self::attempt_lookup_tables(&validator, &tasks)?; - + } + // In case task optimization didn't work + // attempt using lookup tables for all keys involved in tasks + else if Self::attempt_lookup_tables(&tasks) { // Persist tasks strategy - if let Some(persistor) = persistor { - let mut persistor_visitor = PersistorVisitor { - persistor, - context: PersistorContext::PersistStrategy { - uses_lookup_tables: true, - }, - }; - tasks - .iter() - .for_each(|task| task.visit(&mut persistor_visitor)); - } + let mut persistor_visitor = PersistorVisitor { + persistor, + context: PersistorContext::PersistStrategy { + uses_lookup_tables: true, + }, + }; + tasks + .iter() + .for_each(|task| task.visit(&mut persistor_visitor)); + + // Get lookup table keys + let lookup_tables_keys = + Self::collect_lookup_table_keys(&validator, &tasks); Ok(TransactionStrategy { optimized_tasks: tasks, lookup_tables_keys, }) + } else { + Err(Error::FailedToFitError) } } /// Attempt to use ALTs for ALL keys in tx + /// Returns `true` if ALTs make tx fit, otherwise `false` /// TODO: optimize to use only necessary amount of pubkeys - pub fn attempt_lookup_tables( - validator: &Pubkey, - tasks: &[Box], - ) -> TaskStrategistResult> { + pub fn attempt_lookup_tables(tasks: &[Box]) -> bool { + let placeholder = Keypair::new(); // Gather all involved keys in tx let budgets = TransactionUtils::tasks_compute_units(&tasks); let budget_instructions = TransactionUtils::budget_instructions(budgets, u64::default()); let unique_involved_pubkeys = TransactionUtils::unique_involved_pubkeys( &tasks, - validator, + &placeholder.pubkey(), &budget_instructions, ); let dummy_lookup_tables = @@ -93,23 +94,43 @@ impl TaskStrategist { // Create final tx let instructions = - TransactionUtils::tasks_instructions(validator, &tasks); - let alt_tx = TransactionUtils::assemble_tx_raw( - &Keypair::new(), + TransactionUtils::tasks_instructions(&placeholder.pubkey(), &tasks); + let alt_tx = if let Ok(tx) = TransactionUtils::assemble_tx_raw( + &placeholder, &instructions, &budget_instructions, &dummy_lookup_tables, - ) - .map_err(|_| Error::FailedToFitError)?; + ) { + tx + } else { + // Transaction doesn't fit, see CompileError + return false; + }; let encoded_alt_tx = serialize_and_encode_base64(&alt_tx); if encoded_alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE { - Ok(unique_involved_pubkeys) + true } else { - Err(Error::FailedToFitError) + false } } + pub fn collect_lookup_table_keys( + authority: &Pubkey, + tasks: &[Box], + ) -> Vec { + let budgets = TransactionUtils::tasks_compute_units(&tasks); + let budget_instructions = + TransactionUtils::budget_instructions(budgets, u64::default()); + let unique_involved_pubkeys = TransactionUtils::unique_involved_pubkeys( + &tasks, + authority, + &budget_instructions, + ); + + unique_involved_pubkeys + } + /// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`] /// Returns size of tx after optimizations fn optimize_strategy(tasks: &mut [Box]) -> usize { diff --git a/magicblock-committor-service/tests/test_delivery_preparator.rs b/magicblock-committor-service/tests/test_delivery_preparator.rs index 6ae52b8a4..ed5a8f3e6 100644 --- a/magicblock-committor-service/tests/test_delivery_preparator.rs +++ b/magicblock-committor-service/tests/test_delivery_preparator.rs @@ -6,17 +6,16 @@ use magicblock_committor_program::Chunks; use magicblock_committor_service::{ persist::L1MessagePersister, tasks::{ - task_strategist::TransactionStrategy, - tasks::{BufferTask, CommitTask, L1Task}, + task_strategist::{TaskStrategist, TransactionStrategy}, + tasks::{ArgsTask, BufferTask, CommitTask, L1Task}, }, + transaction_preperator::delivery_preparator::DeliveryPreparator, }; use magicblock_program::magic_scheduled_l1_message::CommittedAccountV2; use solana_account::Account; use solana_pubkey::Pubkey; use solana_sdk::signer::Signer; -use magicblock_committor_service::tasks::task_strategist::TaskStrategist; -use magicblock_committor_service::tasks::tasks::ArgsTask; -use magicblock_committor_service::transaction_preperator::delivery_preparator::DeliveryPreparator; + use crate::common::TestFixture; mod common; @@ -190,27 +189,34 @@ async fn test_lookup_tables() { }) .collect::>(); - let lookup_tables_keys = TaskStrategist::attempt_lookup_tables(&fixture.authority.pubkey(), &tasks).unwrap(); + let lookup_tables_keys = TaskStrategist::collect_lookup_table_keys( + &fixture.authority.pubkey(), + &tasks, + ); let strategy = TransactionStrategy { optimized_tasks: tasks, - lookup_tables_keys + lookup_tables_keys, }; - let result = preparator.prepare_for_delivery(&fixture.authority, &strategy, &None::).await; + let result = preparator + .prepare_for_delivery( + &fixture.authority, + &strategy, + &None::, + ) + .await; assert!(result.is_ok(), "Failed to prepare lookup tables"); let alts = result.unwrap(); // Verify the ALTs were actually created for alt in alts { - let alt_account = fixture.rpc_client + let alt_account = fixture + .rpc_client .get_account(&alt.key) .await .unwrap() .expect("ALT account should exist"); - assert!( - !alt_account.data.is_empty(), - "ALT account should have data" - ); + assert!(!alt_account.data.is_empty(), "ALT account should have data"); } -} \ No newline at end of file +} From deb46a596dc27ec8051066b9766afd36160abb77 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 29 Jul 2025 19:04:16 +0900 Subject: [PATCH 135/199] feat: tests for TaskStrategist --- .../src/tasks/task_strategist.rs | 202 +++++++++++++++++- 1 file changed, 191 insertions(+), 11 deletions(-) diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 1408f0b3d..4557845d4 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -9,7 +9,7 @@ use crate::{ task_visitors::persistor_visitor::{ PersistorContext, PersistorVisitor, }, - tasks::{ArgsTask, L1Task}, + tasks::{ArgsTask, FinalizeTask, L1Task}, utils::TransactionUtils, }, transactions::{serialize_and_encode_base64, MAX_ENCODED_TRANSACTION_SIZE}, @@ -149,6 +149,9 @@ impl TaskStrategist { // Get initial transaction size let mut current_tx_length = calculate_tx_length(tasks); + if current_tx_length <= MAX_ENCODED_TRANSACTION_SIZE { + return current_tx_length; + } // Create heap size -> index // TODO(edwin): OPTIMIZATION. update ixs arr, since we know index, coul then reuse for tx creation @@ -171,17 +174,13 @@ impl TaskStrategist { break; } - let task = &mut tasks[index]; let task = { - // SAFETY: - // 1. We create a dangling pointer purely for temporary storage during replace - // 2. The pointer is never dereferenced before being replaced - // 3. No memory allocated, hence no leakage - let dangling = NonNull::::dangling(); - let tmp_task = unsafe { Box::from_raw(dangling.as_ptr()) } - as Box; - - std::mem::replace(task, tmp_task) + // This is tmp task that will be replaced by old or optimized one + let tmp_task = ArgsTask::Finalize(FinalizeTask { + delegated_account: Pubkey::new_unique(), + }); + let tmp_task = Box::new(tmp_task) as Box; + std::mem::replace(&mut tasks[index], tmp_task) }; match task.optimize() { // If we can decrease: @@ -219,3 +218,184 @@ pub enum Error { } pub type TaskStrategistResult = Result; + +#[cfg(test)] +mod tests { + use dlp::args::Context; + use magicblock_program::magic_scheduled_l1_message::{ + CommittedAccountV2, L1Action, ProgramArgs, + }; + use solana_account::Account; + use solana_sdk::{signature::Keypair, system_program}; + + use super::*; + use crate::{ + persist::L1MessagePersister, + tasks::tasks::{CommitTask, L1ActionTask, TaskStrategy}, + }; + + // Helper to create a simple commit task + fn create_test_commit_task(commit_id: u64, data_size: usize) -> ArgsTask { + ArgsTask::Commit(CommitTask { + commit_id, + allow_undelegation: false, + committed_account: CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 1000, + data: vec![0; data_size], + owner: system_program::id(), + executable: false, + rent_epoch: 0, + }, + }, + }) + } + + // Helper to create an L1 action task + fn create_test_l1_action_task(len: usize) -> ArgsTask { + ArgsTask::L1Action(L1ActionTask { + context: Context::Commit, + action: L1Action { + destination_program: Pubkey::new_unique(), + escrow_authority: Pubkey::new_unique(), + account_metas_per_program: vec![], + data_per_program: ProgramArgs { + data: vec![0; len], + escrow_index: 0, + }, + compute_units: 30_000, + }, + }) + } + + #[test] + fn test_build_strategy_with_single_small_task() { + let validator = Pubkey::new_unique(); + let task = create_test_commit_task(1, 100); + let tasks = vec![Box::new(task) as Box]; + + let strategy = TaskStrategist::build_strategy( + tasks, + &validator, + &None::, + ) + .expect("Should build strategy"); + + assert_eq!(strategy.optimized_tasks.len(), 1); + assert!(strategy.lookup_tables_keys.is_empty()); + } + + #[test] + fn test_build_strategy_optimizes_to_buffer_when_needed() { + let validator = Pubkey::new_unique(); + + let task = create_test_commit_task(1, 1000); // Large task + let tasks = vec![Box::new(task) as Box]; + + let strategy = TaskStrategist::build_strategy( + tasks, + &validator, + &None::, + ) + .expect("Should build strategy with buffer optimization"); + + assert_eq!(strategy.optimized_tasks.len(), 1); + assert!(matches!( + strategy.optimized_tasks[0].strategy(), + TaskStrategy::Buffer + )); + } + + #[test] + fn test_build_strategy_creates_multiple_buffers() { + // TODO: ALSO MAX NUM WITH PURE BUFFER commits, no alts + const NUM_COMMITS: u64 = 3; + + let validator = Pubkey::new_unique(); + + let tasks = (0..NUM_COMMITS) + .map(|i| { + let task = create_test_commit_task(i, 500); // Large task + Box::new(task) as Box + }) + .collect(); + + let strategy = TaskStrategist::build_strategy( + tasks, + &validator, + &None::, + ) + .expect("Should build strategy with buffer optimization"); + + for optimized_task in strategy.optimized_tasks { + assert!(matches!(optimized_task.strategy(), TaskStrategy::Buffer)); + } + assert!(strategy.lookup_tables_keys.is_empty()); + } + + #[test] + fn test_build_strategy_with_lookup_tables_when_needed() { + // TODO: ALSO MAX NUMBER OF TASKS fit with ALTs! + const NUM_COMMITS: u64 = 22; + + let validator = Pubkey::new_unique(); + + let tasks = (0..NUM_COMMITS) + .map(|i| { + // Large task + let task = create_test_commit_task(i, 10000); + Box::new(task) as Box + }) + .collect(); + + let strategy = TaskStrategist::build_strategy( + tasks, + &validator, + &None::, + ) + .expect("Should build strategy with buffer optimization"); + + for optimized_task in strategy.optimized_tasks { + assert!(matches!(optimized_task.strategy(), TaskStrategy::Buffer)); + } + assert!(!strategy.lookup_tables_keys.is_empty()); + } + + #[test] + fn test_build_strategy_fails_when_cant_fit() { + const NUM_COMMITS: u64 = 23; + + let validator = Pubkey::new_unique(); + + let tasks = (0..NUM_COMMITS) + .map(|i| { + // Large task + let task = create_test_commit_task(i, 1000); + Box::new(task) as Box + }) + .collect(); + + let result = TaskStrategist::build_strategy( + tasks, + &validator, + &None::, + ); + assert!(matches!(result, Err(Error::FailedToFitError))); + } + + #[test] + fn test_optimize_strategy_prioritizes_largest_tasks() { + let validator = Pubkey::new_unique(); + let mut tasks = vec![ + Box::new(create_test_commit_task(1, 100)) as Box, + Box::new(create_test_commit_task(2, 1000)) as Box, // Larger task + Box::new(create_test_commit_task(3, 1000)) as Box, // Larger task + ]; + + let final_size = TaskStrategist::optimize_strategy(&mut tasks); + // The larger task should have been optimized first + assert!(matches!(tasks[0].strategy(), TaskStrategy::Args)); + assert!(matches!(tasks[1].strategy(), TaskStrategy::Buffer)); + } +} From 80763eb5295bf6dae367f000f01a4df7e2ef4a04 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 29 Jul 2025 19:12:01 +0900 Subject: [PATCH 136/199] feat: tests for Finalize, Undelegate + Action --- .../src/tasks/task_strategist.rs | 54 +++++++++++++++++++ .../src/tasks/tasks.rs | 1 + 2 files changed, 55 insertions(+) diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 4557845d4..fff90cabe 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -233,6 +233,7 @@ mod tests { persist::L1MessagePersister, tasks::tasks::{CommitTask, L1ActionTask, TaskStrategy}, }; + use crate::tasks::tasks::UndelegateTask; // Helper to create a simple commit task fn create_test_commit_task(commit_id: u64, data_size: usize) -> ArgsTask { @@ -269,6 +270,23 @@ mod tests { }) } + // Helper to create a finalize task + fn create_test_finalize_task() -> ArgsTask { + ArgsTask::Finalize(FinalizeTask { + delegated_account: Pubkey::new_unique(), + }) + } + + // Helper to create an undelegate task + fn create_test_undelegate_task() -> ArgsTask { + ArgsTask::Undelegate(UndelegateTask { + delegated_account: Pubkey::new_unique(), + owner_program: system_program::id(), + rent_reimbursement: Pubkey::new_unique(), + }) + } + + #[test] fn test_build_strategy_with_single_small_task() { let validator = Pubkey::new_unique(); @@ -398,4 +416,40 @@ mod tests { assert!(matches!(tasks[0].strategy(), TaskStrategy::Args)); assert!(matches!(tasks[1].strategy(), TaskStrategy::Buffer)); } + + #[test] + fn test_mixed_task_types_with_optimization() { + let validator = Pubkey::new_unique(); + let tasks = vec![ + Box::new(create_test_commit_task(1, 1000)) as Box, + Box::new(create_test_finalize_task()) as Box, + Box::new(create_test_l1_action_task(500)) as Box, + Box::new(create_test_undelegate_task()) as Box, + ]; + + let strategy = TaskStrategist::build_strategy( + tasks, + &validator, + &None::, + ) + .expect("Should build strategy"); + + assert_eq!(strategy.optimized_tasks.len(), 4); + + let strategies: Vec = strategy.optimized_tasks + .iter() + .map(|t| t.strategy()) + .collect(); + + assert_eq!(strategies, vec![ + TaskStrategy::Buffer, // Commit task optimized + TaskStrategy::Args, // Finalize stays + TaskStrategy::Args, // L1Action stays + TaskStrategy::Args, // Undelegate stays + ]); + // This means that couldn't squeeze task optimization + // So had to switch to ALTs + // As expected + assert!(!strategy.lookup_tables_keys.is_empty()); + } } diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index f769fc14d..478b25f75 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -23,6 +23,7 @@ use crate::{ tasks::{budget_calculator::ComputeBudgetV1, visitor::Visitor}, }; +#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum TaskStrategy { Args, Buffer, From f54bb6e7f427b56afe2c49b543b9c1a648e9eba1 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 29 Jul 2025 19:42:53 +0900 Subject: [PATCH 137/199] refactor: warning cleanup + some file removed --- .../src/external_accounts_manager.rs | 6 +---- .../src/remote_scheduled_commits_processor.rs | 8 ++---- magicblock-accounts/src/traits.rs | 9 ++----- magicblock-api/src/magic_validator.rs | 2 +- magicblock-api/src/tickers.rs | 5 +--- .../src/commit_scheduler/commit_id_tracker.rs | 4 +-- .../commit_scheduler_worker.rs | 1 - .../src/persist/db.rs | 2 +- .../src/persist/types/commit_status.rs | 2 +- .../src/tasks/budget_calculator.rs | 13 ---------- magicblock-committor-service/src/tasks/mod.rs | 1 - .../src/tasks/task_strategist.rs | 26 +++++++++++-------- .../src/tasks/tasks.rs | 5 +--- .../src/tasks/utils.rs | 2 +- 14 files changed, 27 insertions(+), 59 deletions(-) delete mode 100644 magicblock-committor-service/src/tasks/budget_calculator.rs diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 4fc7a9612..b6f9a8b74 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -28,7 +28,6 @@ use magicblock_committor_service::{ transactions::MAX_PROCESS_PER_TX, types::{ScheduledL1MessageWrapper, TriggerType}, utils::ScheduledMessageExt, - L1MessageCommittor, }; use magicblock_core::magic_program; use magicblock_program::{ @@ -47,11 +46,8 @@ use solana_sdk::{ use crate::{ errors::{AccountsError, AccountsResult}, - traits::AccountCommitter, utils::get_epoch, - AccountCommittee, CommitAccountsPayload, LifecycleMode, - PendingCommitTransaction, ScheduledCommitsProcessor, - SendableCommitAccountsPayload, + AccountCommittee, LifecycleMode, SendableCommitAccountsPayload, }; #[derive(Debug)] diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 43523555c..1efcba3fe 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -23,11 +23,7 @@ use solana_sdk::{ account::{Account, ReadableAccount}, pubkey::Pubkey, }; -use tokio::sync::{ - broadcast, - mpsc::{channel, Sender}, - oneshot, -}; +use tokio::sync::{broadcast, oneshot}; use crate::{errors::AccountsResult, ScheduledCommitsProcessor}; @@ -132,7 +128,7 @@ impl RemoteScheduledCommitsProcessor { bank: &self.bank, }; - /// Retains onlu account that are valid to be commited + // Retains onlu account that are valid to be commited committed_accounts.retain_mut(|account| { let pubkey = account.pubkey; let cloned_accounts = diff --git a/magicblock-accounts/src/traits.rs b/magicblock-accounts/src/traits.rs index 786443a60..630c1ad37 100644 --- a/magicblock-accounts/src/traits.rs +++ b/magicblock-accounts/src/traits.rs @@ -1,16 +1,11 @@ -use std::{collections::HashSet, sync::Arc}; +use std::collections::HashSet; use async_trait::async_trait; -use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::L1MessageCommittor; use magicblock_metrics::metrics::HistogramTimer; -use magicblock_program::magic_scheduled_l1_message::{ - CommittedAccountV2, ScheduledL1Message, -}; +use magicblock_program::magic_scheduled_l1_message::CommittedAccountV2; use solana_rpc_client::rpc_client::SerializableTransaction; use solana_sdk::{ account::{Account, AccountSharedData, ReadableAccount}, - clock::Epoch, pubkey::Pubkey, signature::Signature, transaction::Transaction, diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index c977a8aff..a0a4872b5 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -14,7 +14,7 @@ use conjunto_transwise::RpcProviderConfig; use log::*; use magicblock_account_cloner::{ map_committor_request_result, standard_blacklisted_accounts, - CloneOutputMap, RemoteAccountClonerClient, RemoteAccountClonerWorker, + RemoteAccountClonerClient, RemoteAccountClonerWorker, ValidatorCollectionMode, }; use magicblock_account_dumper::AccountDumperBank; diff --git a/magicblock-api/src/tickers.rs b/magicblock-api/src/tickers.rs index bd778c6fa..f41cc65f3 100644 --- a/magicblock-api/src/tickers.rs +++ b/magicblock-api/src/tickers.rs @@ -7,10 +7,7 @@ use std::{ }; use log::*; -use magicblock_accounts::{ - remote_scheduled_commits_processor::RemoteScheduledCommitsProcessor, - AccountsManager, ScheduledCommitsProcessor, -}; +use magicblock_accounts::{AccountsManager, ScheduledCommitsProcessor}; use magicblock_bank::bank::Bank; use magicblock_core::magic_program; use magicblock_ledger::Ledger; diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs index c7be9c2c3..d8ef26dca 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs @@ -10,9 +10,7 @@ use dlp::{ }; use log::{error, warn}; use lru::LruCache; -use magicblock_rpc_client::{ - MagicBlockRpcClientError, MagicBlockRpcClientResult, MagicblockRpcClient, -}; +use magicblock_rpc_client::{MagicBlockRpcClientError, MagicblockRpcClient}; use solana_pubkey::Pubkey; #[async_trait::async_trait] diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 86a738d63..164da5ffc 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -6,7 +6,6 @@ use std::{ use futures_util::{stream::FuturesUnordered, StreamExt}; use log::{error, info, trace, warn}; use magicblock_program::SentCommit; -use solana_pubkey::Pubkey; use solana_sdk::transaction::Transaction; use tokio::{ sync::{ diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index f2c87ef01..26e7ce2c8 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -1,6 +1,6 @@ use std::{fmt, path::Path, str::FromStr}; -use rusqlite::{params, Connection, OptionalExtension, Result, Transaction}; +use rusqlite::{params, Connection, Result, Transaction}; use solana_pubkey::Pubkey; use solana_sdk::{clock::Slot, hash::Hash, signature::Signature}; diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index 04b15de2d..8275cecb6 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -2,7 +2,7 @@ use std::fmt; use solana_sdk::signature::Signature; -use crate::persist::{error::CommitPersistError, CommitStatus::Failed}; +use crate::persist::error::CommitPersistError; /// The status of a committed account. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/magicblock-committor-service/src/tasks/budget_calculator.rs b/magicblock-committor-service/src/tasks/budget_calculator.rs deleted file mode 100644 index 1c23b23f5..000000000 --- a/magicblock-committor-service/src/tasks/budget_calculator.rs +++ /dev/null @@ -1,13 +0,0 @@ -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; -use solana_sdk::{ - compute_budget::ComputeBudgetInstruction, instruction::Instruction, -}; - -use crate::ComputeBudgetConfig; - -// TODO(edwin): rename -pub struct ComputeBudgetV1 { - /// Total compute budget - pub compute_budget: u32, - pub compute_unit_price: u64, -} diff --git a/magicblock-committor-service/src/tasks/mod.rs b/magicblock-committor-service/src/tasks/mod.rs index 4dcf91c12..053d47028 100644 --- a/magicblock-committor-service/src/tasks/mod.rs +++ b/magicblock-committor-service/src/tasks/mod.rs @@ -1,4 +1,3 @@ -mod budget_calculator; pub mod task_builder; pub mod task_strategist; pub(crate) mod task_visitors; diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index fff90cabe..24d5a754d 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -231,9 +231,10 @@ mod tests { use super::*; use crate::{ persist::L1MessagePersister, - tasks::tasks::{CommitTask, L1ActionTask, TaskStrategy}, + tasks::tasks::{ + CommitTask, L1ActionTask, TaskStrategy, UndelegateTask, + }, }; - use crate::tasks::tasks::UndelegateTask; // Helper to create a simple commit task fn create_test_commit_task(commit_id: u64, data_size: usize) -> ArgsTask { @@ -286,7 +287,6 @@ mod tests { }) } - #[test] fn test_build_strategy_with_single_small_task() { let validator = Pubkey::new_unique(); @@ -432,21 +432,25 @@ mod tests { &validator, &None::, ) - .expect("Should build strategy"); + .expect("Should build strategy"); assert_eq!(strategy.optimized_tasks.len(), 4); - let strategies: Vec = strategy.optimized_tasks + let strategies: Vec = strategy + .optimized_tasks .iter() .map(|t| t.strategy()) .collect(); - assert_eq!(strategies, vec![ - TaskStrategy::Buffer, // Commit task optimized - TaskStrategy::Args, // Finalize stays - TaskStrategy::Args, // L1Action stays - TaskStrategy::Args, // Undelegate stays - ]); + assert_eq!( + strategies, + vec![ + TaskStrategy::Buffer, // Commit task optimized + TaskStrategy::Args, // Finalize stays + TaskStrategy::Args, // L1Action stays + TaskStrategy::Args, // Undelegate stays + ] + ); // This means that couldn't squeeze task optimization // So had to switch to ALTs // As expected diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index 478b25f75..ae8dee1e4 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -18,10 +18,7 @@ use magicblock_program::magic_scheduled_l1_message::{ use solana_pubkey::Pubkey; use solana_sdk::instruction::{AccountMeta, Instruction}; -use crate::{ - consts::MAX_WRITE_CHUNK_SIZE, - tasks::{budget_calculator::ComputeBudgetV1, visitor::Visitor}, -}; +use crate::{consts::MAX_WRITE_CHUNK_SIZE, tasks::visitor::Visitor}; #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum TaskStrategy { diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index 45d425f1f..c4bb9f358 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -13,7 +13,7 @@ use solana_sdk::{ transaction::VersionedTransaction, }; -use crate::tasks::{budget_calculator::ComputeBudgetV1, tasks::L1Task}; +use crate::tasks::tasks::L1Task; /// Returns [`Vec`] where all TX accounts stored in ALT pub fn estimate_lookup_tables_for_tx( From e6b79d2419b4b88d2bb0de1dc21e201f7285f8fc Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 29 Jul 2025 20:58:39 +0900 Subject: [PATCH 138/199] fix: crash case when data.len() in instruction exceeds u16::MAX --- .../commit_scheduler_worker.rs | 2 +- .../src/tasks/utils.rs | 37 ++- magicblock-committor-service/tests/common.rs | 66 +++- .../tests/test_delivery_preparator.rs | 39 +-- .../tests/test_transaction_preparator.rs | 296 ++++++++++++++++++ 5 files changed, 395 insertions(+), 45 deletions(-) create mode 100644 magicblock-committor-service/tests/test_transaction_preparator.rs diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 164da5ffc..5a0e8d549 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -376,7 +376,7 @@ mod tests { use async_trait::async_trait; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; - use solana_pubkey::pubkey; + use solana_pubkey::{pubkey, Pubkey}; use solana_sdk::{signature::Signature, signer::SignerError}; use tokio::{sync::mpsc, time::sleep}; diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index c4bb9f358..2f80fefe5 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -9,11 +9,11 @@ use solana_sdk::{ v0::Message, AddressLookupTableAccount, CompileError, VersionedMessage, }, signature::Keypair, - signer::Signer, + signer::{Signer}, transaction::VersionedTransaction, }; -use crate::tasks::tasks::L1Task; +use crate::tasks::{task_strategist::TaskStrategistResult, tasks::L1Task}; /// Returns [`Vec`] where all TX accounts stored in ALT pub fn estimate_lookup_tables_for_tx( @@ -79,7 +79,7 @@ impl TransactionUtils { tasks: &[Box], compute_unit_price: u64, lookup_tables: &[AddressLookupTableAccount], - ) -> Result { + ) -> TaskStrategistResult { let budget_instructions = Self::budget_instructions( Self::tasks_compute_units(&tasks), compute_unit_price, @@ -98,13 +98,38 @@ impl TransactionUtils { instructions: &[Instruction], budget_instructions: &[Instruction], lookup_tables: &[AddressLookupTableAccount], - ) -> Result { - let message = Message::try_compile( + ) -> TaskStrategistResult { + // This is needed because VersionedMessage::serialize uses unwrap() ¯\_(ツ)_/¯ + instructions + .iter() + .map(|el| { + if el.data.len() > u16::MAX as usize { + Err(crate::tasks::task_strategist::Error::FailedToFitError) + } else { + Ok(()) + } + }) + .collect::>()?; + + let message = match Message::try_compile( &authority.pubkey(), &[budget_instructions, instructions].concat(), &lookup_tables, Hash::new_unique(), - )?; + ) { + Ok(message) => Ok(message), + Err(CompileError::AccountIndexOverflow) + | Err(CompileError::AddressTableLookupIndexOverflow) => { + Err(crate::tasks::task_strategist::Error::FailedToFitError) + } + Err(CompileError::UnknownInstructionKey(pubkey)) => { + panic!( + "Supplied instruction has to be valid: {}", + CompileError::UnknownInstructionKey(pubkey) + ); + } + }?; + // SignerError is critical let tx = VersionedTransaction::try_new( VersionedMessage::V0(message), diff --git a/magicblock-committor-service/tests/common.rs b/magicblock-committor-service/tests/common.rs index 2b5c00fef..85e1dfb41 100644 --- a/magicblock-committor-service/tests/common.rs +++ b/magicblock-committor-service/tests/common.rs @@ -1,11 +1,24 @@ -use std::sync::Arc; +use std::sync::{ + atomic::{AtomicU64, Ordering}, + Arc, +}; use magicblock_committor_service::{ - transaction_preperator::delivery_preparator::DeliveryPreparator, + tasks::tasks::CommitTask, + transaction_preperator::{ + delivery_preparator::DeliveryPreparator, + transaction_preparator::TransactionPreparatorV1, + }, + types::{ScheduledL1MessageWrapper, TriggerType}, ComputeBudgetConfig, }; +use magicblock_program::magic_scheduled_l1_message::{ + CommittedAccountV2, ScheduledL1Message, +}; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; +use solana_account::Account; +use solana_pubkey::Pubkey; use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ commitment_config::{CommitmentConfig, CommitmentLevel}, @@ -13,7 +26,6 @@ use solana_sdk::{ signer::Signer, system_program, }; -use tempfile::TempDir; // Helper function to create a test RPC client pub async fn create_test_client() -> MagicblockRpcClient { @@ -60,11 +72,57 @@ impl TestFixture { } } - pub fn create_preparator(&self) -> DeliveryPreparator { + pub fn create_delivery_preparator(&self) -> DeliveryPreparator { DeliveryPreparator::new( self.rpc_client.clone(), self.table_mania.clone(), self.compute_budget_config.clone(), ) } + + pub fn create_transaction_preparator(&self) -> TransactionPreparatorV1 { + TransactionPreparatorV1::new( + self.rpc_client.clone(), + self.table_mania.clone(), + self.compute_budget_config.clone(), + ) + } +} + +pub fn generate_random_bytes(length: usize) -> Vec { + use rand::Rng; + + let mut rng = rand::thread_rng(); + (0..length).map(|_| rng.gen()).collect() +} + +pub fn create_commit_task(data: &[u8]) -> CommitTask { + static COMMIT_ID: AtomicU64 = AtomicU64::new(0); + CommitTask { + commit_id: COMMIT_ID.fetch_add(1, Ordering::Relaxed), + allow_undelegation: false, + committed_account: CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 1000, + data: data.to_vec(), + owner: dlp::id(), + executable: false, + rent_epoch: 0, + }, + }, + } +} + +pub fn create_committed_account(data: &[u8]) -> CommittedAccountV2 { + CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 1000, + data: data.to_vec(), + owner: dlp::id(), + executable: false, + rent_epoch: 0, + }, + } } diff --git a/magicblock-committor-service/tests/test_delivery_preparator.rs b/magicblock-committor-service/tests/test_delivery_preparator.rs index ed5a8f3e6..a585949c9 100644 --- a/magicblock-committor-service/tests/test_delivery_preparator.rs +++ b/magicblock-committor-service/tests/test_delivery_preparator.rs @@ -7,48 +7,19 @@ use magicblock_committor_service::{ persist::L1MessagePersister, tasks::{ task_strategist::{TaskStrategist, TransactionStrategy}, - tasks::{ArgsTask, BufferTask, CommitTask, L1Task}, + tasks::{ArgsTask, BufferTask, L1Task}, }, - transaction_preperator::delivery_preparator::DeliveryPreparator, }; -use magicblock_program::magic_scheduled_l1_message::CommittedAccountV2; -use solana_account::Account; -use solana_pubkey::Pubkey; use solana_sdk::signer::Signer; -use crate::common::TestFixture; +use crate::common::{create_commit_task, generate_random_bytes, TestFixture}; mod common; -pub fn generate_random_bytes(length: usize) -> Vec { - use rand::Rng; - - let mut rng = rand::thread_rng(); - (0..length).map(|_| rng.gen()).collect() -} - -fn create_commit_task(data: &[u8]) -> CommitTask { - static COMMIT_ID: AtomicU64 = AtomicU64::new(0); - CommitTask { - commit_id: COMMIT_ID.fetch_add(1, Ordering::Relaxed), - allow_undelegation: false, - committed_account: CommittedAccountV2 { - pubkey: Pubkey::new_unique(), - account: Account { - lamports: 1000, - data: data.to_vec(), - owner: dlp::id(), - executable: false, - rent_epoch: 0, - }, - }, - } -} - #[tokio::test] async fn test_prepare_10kb_buffer() { let fixture = TestFixture::new().await; - let preparator = fixture.create_preparator(); + let preparator = fixture.create_delivery_preparator(); let data = generate_random_bytes(10 * 1024); let buffer_task = BufferTask::Commit(create_commit_task(&data)); @@ -103,7 +74,7 @@ async fn test_prepare_10kb_buffer() { #[tokio::test] async fn test_prepare_multiple_buffers() { let fixture = TestFixture::new().await; - let preparator = fixture.create_preparator(); + let preparator = fixture.create_delivery_preparator(); let datas = vec![ generate_random_bytes(10 * 1024), @@ -174,7 +145,7 @@ async fn test_prepare_multiple_buffers() { #[tokio::test] async fn test_lookup_tables() { let fixture = TestFixture::new().await; - let preparator = fixture.create_preparator(); + let preparator = fixture.create_delivery_preparator(); let datas = vec![ generate_random_bytes(10), diff --git a/magicblock-committor-service/tests/test_transaction_preparator.rs b/magicblock-committor-service/tests/test_transaction_preparator.rs new file mode 100644 index 000000000..120e04f8d --- /dev/null +++ b/magicblock-committor-service/tests/test_transaction_preparator.rs @@ -0,0 +1,296 @@ +use std::collections::HashMap; + +use magicblock_committor_service::{ + persist::L1MessagePersister, + transaction_preperator::transaction_preparator::TransactionPreparator, +}; +use magicblock_program::magic_scheduled_l1_message::{ + CommitAndUndelegate, CommitType, CommittedAccountV2, L1Action, + MagicL1Message, ProgramArgs, ScheduledL1Message, ShortAccountMeta, + UndelegateType, +}; +use solana_pubkey::Pubkey; +use solana_sdk::{ + account::Account, hash::Hash, signer::Signer, system_program, + transaction::Transaction, +}; + +use crate::common::{create_committed_account, TestFixture}; + +mod common; + +#[tokio::test] +async fn test_prepare_commit_tx_with_single_account() { + let fixture = TestFixture::new().await; + let preparator = fixture.create_transaction_preparator(); + + // Create test data + let account_data = vec![1, 2, 3, 4, 5]; + let committed_account = create_committed_account(&account_data); + let l1_message = ScheduledL1Message { + id: 1, + slot: 0, + blockhash: Hash::default(), + action_sent_transaction: Transaction::default(), + payer: fixture.authority.pubkey(), + l1_message: MagicL1Message::Commit(CommitType::Standalone(vec![ + committed_account.clone(), + ])), + }; + + let mut commit_ids = HashMap::new(); + commit_ids.insert(committed_account.pubkey, 1); + + // Test preparation + let result = preparator + .prepare_commit_tx( + &fixture.authority, + &l1_message, + &commit_ids, + &None::, + ) + .await; + + assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); +} + +#[tokio::test] +async fn test_prepare_commit_tx_with_multiple_accounts() { + let fixture = TestFixture::new().await; + let preparator = fixture.create_transaction_preparator(); + + // Create test data + let accounts = vec![ + CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 1000, + data: vec![1, 2, 3], + owner: system_program::id(), + executable: false, + rent_epoch: 0, + }, + }, + CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 2000, + data: vec![4, 5, 6], + owner: system_program::id(), + executable: false, + rent_epoch: 0, + }, + }, + ]; + + let l1_message = ScheduledL1Message { + id: 1, + slot: 0, + blockhash: Hash::default(), + action_sent_transaction: Transaction::default(), + payer: fixture.authority.pubkey(), + l1_message: MagicL1Message::Commit(CommitType::Standalone( + accounts.clone(), + )), + }; + + let commit_ids = accounts + .iter() + .enumerate() + .map(|(i, acc)| (acc.pubkey, i as u64 + 1)) + .collect(); + + // Test preparation + let result = preparator + .prepare_commit_tx( + &fixture.authority, + &l1_message, + &commit_ids, + &None::, + ) + .await; + + assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); +} + +#[tokio::test] +async fn test_prepare_commit_tx_with_l1_actions() { + let fixture = TestFixture::new().await; + let preparator = fixture.create_transaction_preparator(); + + // Create test data + let account = CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 1000, + data: vec![1, 2, 3], + owner: system_program::id(), + executable: false, + rent_epoch: 0, + }, + }; + + let l1_action = L1Action { + compute_units: 30_000, + destination_program: system_program::id(), + escrow_authority: fixture.authority.pubkey(), + data_per_program: ProgramArgs { + escrow_index: 0, + data: vec![4, 5, 6], + }, + account_metas_per_program: vec![ShortAccountMeta { + pubkey: Pubkey::new_unique(), + is_writable: true, + }], + }; + + let l1_message = ScheduledL1Message { + id: 1, + slot: 0, + blockhash: Hash::default(), + action_sent_transaction: Transaction::default(), + payer: fixture.authority.pubkey(), + l1_message: MagicL1Message::Commit(CommitType::WithL1Actions { + committed_accounts: vec![account.clone()], + l1_actions: vec![l1_action], + }), + }; + + let mut commit_ids = HashMap::new(); + commit_ids.insert(account.pubkey, 1); + + // Test preparation + let result = preparator + .prepare_commit_tx( + &fixture.authority, + &l1_message, + &commit_ids, + &None::, + ) + .await; + + assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); +} + +#[tokio::test] +async fn test_prepare_finalize_tx_with_undelegate() { + let fixture = TestFixture::new().await; + let preparator = fixture.create_transaction_preparator(); + + // Create test data + let rent_reimbursement = Pubkey::new_unique(); + let l1_message = ScheduledL1Message { + id: 1, + slot: 0, + blockhash: Hash::default(), + action_sent_transaction: Transaction::default(), + payer: fixture.authority.pubkey(), + l1_message: MagicL1Message::CommitAndUndelegate(CommitAndUndelegate { + commit_action: CommitType::Standalone(vec![]), + undelegate_action: UndelegateType::Standalone, + }), + }; + + // Test preparation + let result = preparator + .prepare_finalize_tx( + &fixture.authority, + &rent_reimbursement, + &l1_message, + &None::, + ) + .await; + + assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); +} + +#[tokio::test] +async fn test_prepare_finalize_tx_with_undelegate_and_actions() { + let fixture = TestFixture::new().await; + let preparator = fixture.create_transaction_preparator(); + + // Create test data + let rent_reimbursement = Pubkey::new_unique(); + let l1_action = L1Action { + compute_units: 30_000, + destination_program: system_program::id(), + escrow_authority: fixture.authority.pubkey(), + data_per_program: ProgramArgs { + escrow_index: 0, + data: vec![4, 5, 6], + }, + account_metas_per_program: vec![ShortAccountMeta { + pubkey: Pubkey::new_unique(), + is_writable: true, + }], + }; + + let l1_message = ScheduledL1Message { + id: 1, + slot: 0, + blockhash: Hash::default(), + action_sent_transaction: Transaction::default(), + payer: fixture.authority.pubkey(), + l1_message: MagicL1Message::CommitAndUndelegate(CommitAndUndelegate { + commit_action: CommitType::Standalone(vec![]), + undelegate_action: UndelegateType::WithL1Actions(vec![l1_action]), + }), + }; + + // Test preparation + let result = preparator + .prepare_finalize_tx( + &fixture.authority, + &rent_reimbursement, + &l1_message, + &None::, + ) + .await; + + assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); +} + +#[tokio::test] +async fn test_prepare_large_commit_tx_uses_buffers() { + let fixture = TestFixture::new().await; + let preparator = fixture.create_transaction_preparator(); + + // Create large account data (10KB) + let account_data = vec![0; u16::MAX as usize + 1]; + let committed_account = CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 1000, + data: account_data, + owner: system_program::id(), + executable: false, + rent_epoch: 0, + }, + }; + + let l1_message = ScheduledL1Message { + id: 1, + slot: 0, + blockhash: Hash::default(), + action_sent_transaction: Transaction::default(), + payer: fixture.authority.pubkey(), + l1_message: MagicL1Message::Commit(CommitType::Standalone(vec![ + committed_account.clone(), + ])), + }; + + let mut commit_ids = HashMap::new(); + commit_ids.insert(committed_account.pubkey, 1); + + // Test preparation + let result = preparator + .prepare_commit_tx( + &fixture.authority, + &l1_message, + &commit_ids, + &None::, + ) + .await; + + assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); +} From 9aac3cfcbb51023428a6898c794ca1cb846d8ee9 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 29 Jul 2025 21:19:25 +0900 Subject: [PATCH 139/199] fix: tests within committor_service fixed --- magicblock-committor-service/src/tasks/task_strategist.rs | 2 +- magicblock-committor-service/src/tasks/utils.rs | 2 +- magicblock-committor-service/src/transactions.rs | 6 +++--- .../tests/test_delivery_preparator.rs | 4 +++- magicblock-committor-service/tests/test_message_executor.rs | 0 5 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 magicblock-committor-service/tests/test_message_executor.rs diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 24d5a754d..c7437f73c 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -1,4 +1,4 @@ -use std::{collections::BinaryHeap, ptr::NonNull}; +use std::collections::BinaryHeap; use solana_pubkey::Pubkey; use solana_sdk::{signature::Keypair, signer::Signer}; diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index 2f80fefe5..6900e1f8d 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -9,7 +9,7 @@ use solana_sdk::{ v0::Message, AddressLookupTableAccount, CompileError, VersionedMessage, }, signature::Keypair, - signer::{Signer}, + signer::Signer, transaction::VersionedTransaction, }; diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs index f5d54e889..d09ff2385 100644 --- a/magicblock-committor-service/src/transactions.rs +++ b/magicblock-committor-service/src/transactions.rs @@ -35,13 +35,13 @@ pub const MAX_PROCESS_PER_TX_USING_LOOKUP: u8 = 12; /// How many close buffer instructions fit into a single transaction #[allow(unused)] // serves as documentation as well -pub const MAX_CLOSE_PER_TX: u8 = 7; +pub const MAX_CLOSE_PER_TX: u8 = 8; /// How many close buffer instructions fit into a single transaction /// when using address lookup tables but not including the buffer account /// nor chunk account in the lookup table #[allow(unused)] // serves as documentation as well -pub const MAX_CLOSE_PER_TX_USING_LOOKUP: u8 = 7; +pub const MAX_CLOSE_PER_TX_USING_LOOKUP: u8 = 8; /// How many process and commit buffer instructions combined with close buffer instructions /// fit into a single transaction @@ -52,7 +52,7 @@ pub const MAX_PROCESS_AND_CLOSE_PER_TX: u8 = 2; /// close buffer instructions fit into a single transaction when /// using lookup tables but not including the buffer account #[allow(unused)] // serves as documentation as well -pub const MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP: u8 = 4; +pub const MAX_PROCESS_AND_CLOSE_PER_TX_USING_LOOKUP: u8 = 5; /// How many finalize instructions fit into a single transaction #[allow(unused)] // serves as documentation as well diff --git a/magicblock-committor-service/tests/test_delivery_preparator.rs b/magicblock-committor-service/tests/test_delivery_preparator.rs index a585949c9..2660c0d9a 100644 --- a/magicblock-committor-service/tests/test_delivery_preparator.rs +++ b/magicblock-committor-service/tests/test_delivery_preparator.rs @@ -1,4 +1,6 @@ -use std::sync::atomic::{AtomicU64, Ordering}; +// solana-test-validator \ +// --bpf-program corabpNrkBEqbTZP7xfJgSWTdBmVdLf1PARWXZbcMcS \ +// ./magicblock-committor-program/bin/magicblock_committor_program.so use borsh::BorshDeserialize; use futures_util::StreamExt; diff --git a/magicblock-committor-service/tests/test_message_executor.rs b/magicblock-committor-service/tests/test_message_executor.rs new file mode 100644 index 000000000..e69de29bb From 5ca4ae7d71a20702875b995b8a8a3941ca3882ba Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 29 Jul 2025 21:48:30 +0900 Subject: [PATCH 140/199] fix: tests --- magicblock-accounts/src/traits.rs | 31 ---- magicblock-accounts/tests/commit_delegated.rs | 9 +- magicblock-accounts/tests/ensure_accounts.rs | 13 +- .../tests/stubs/account_committer_stub.rs | 96 ---------- magicblock-accounts/tests/stubs/mod.rs | 1 - .../src/persist/commit_persister.rs | 2 +- .../src/stubs/changeset_committor_stub.rs | 168 ++++++++++-------- .../tests/test_message_executor.rs | 4 + .../process_schedule_commit_tests.rs | 1 - 9 files changed, 106 insertions(+), 219 deletions(-) delete mode 100644 magicblock-accounts/tests/stubs/account_committer_stub.rs diff --git a/magicblock-accounts/src/traits.rs b/magicblock-accounts/src/traits.rs index 630c1ad37..6fba0767e 100644 --- a/magicblock-accounts/src/traits.rs +++ b/magicblock-accounts/src/traits.rs @@ -111,34 +111,3 @@ pub struct PendingCommitTransaction { /// the transaction is confirmed. pub timer: HistogramTimer, } - -#[async_trait] -pub trait AccountCommitter: Send + Sync + 'static { - /// Creates a transaction to commit each provided account unless it determines - /// that it isn't necessary, i.e. when the previously committed state is the same - /// as the [commit_state_data]. - /// Returns the transaction committing the accounts and the pubkeys of accounts - /// it did commit - async fn create_commit_accounts_transaction( - &self, - committees: Vec, - ) -> AccountsResult; - - /// Returns the main-chain signatures of the commit transactions - /// This will only fail due to network issues, not if the transaction failed. - /// Therefore we want to either fail all transactions or none which is why - /// we return a `Result` instead of a `Vec`. - async fn send_commit_transactions( - &self, - payloads: Vec, - ) -> AccountsResult>; - - /// Confirms all transactions for the given [pending_commits] with 'confirmed' - /// commitment level. - /// Updates the metrics for each transaction in order to record the time it took - /// to fully confirm it on chain. - async fn confirm_pending_commits( - &self, - pending_commits: Vec, - ); -} diff --git a/magicblock-accounts/tests/commit_delegated.rs b/magicblock-accounts/tests/commit_delegated.rs index a752011cc..6289682c9 100644 --- a/magicblock-accounts/tests/commit_delegated.rs +++ b/magicblock-accounts/tests/commit_delegated.rs @@ -16,10 +16,7 @@ use solana_sdk::{ pubkey::Pubkey, signature::Signature, }; -use stubs::{ - account_committer_stub::AccountCommitterStub, - scheduled_commits_processor_stub::ScheduledCommitsProcessorStub, -}; +use stubs::scheduled_commits_processor_stub::ScheduledCommitsProcessorStub; use test_tools_core::init_logger; mod stubs; @@ -27,7 +24,6 @@ mod stubs; type StubbedAccountsManager = ExternalAccountsManager< InternalAccountProviderStub, AccountClonerStub, - AccountCommitterStub, TransactionAccountsExtractorImpl, TransactionAccountsValidatorImpl, ScheduledCommitsProcessorStub, @@ -36,15 +32,12 @@ type StubbedAccountsManager = ExternalAccountsManager< fn setup( internal_account_provider: InternalAccountProviderStub, account_cloner: AccountClonerStub, - account_committer: AccountCommitterStub, ) -> StubbedAccountsManager { ExternalAccountsManager { internal_account_provider, account_cloner, - account_committer: Arc::new(account_committer), transaction_accounts_extractor: TransactionAccountsExtractorImpl, transaction_accounts_validator: TransactionAccountsValidatorImpl, - scheduled_commits_processor: ScheduledCommitsProcessorStub::default(), lifecycle: LifecycleMode::Ephemeral, external_commitable_accounts: Default::default(), } diff --git a/magicblock-accounts/tests/ensure_accounts.rs b/magicblock-accounts/tests/ensure_accounts.rs index 38ee4c541..82b774725 100644 --- a/magicblock-accounts/tests/ensure_accounts.rs +++ b/magicblock-accounts/tests/ensure_accounts.rs @@ -19,10 +19,7 @@ use magicblock_accounts::{ use magicblock_accounts_api::InternalAccountProviderStub; use magicblock_committor_service::stubs::ChangesetCommittorStub; use solana_sdk::pubkey::Pubkey; -use stubs::{ - account_committer_stub::AccountCommitterStub, - scheduled_commits_processor_stub::ScheduledCommitsProcessorStub, -}; +use stubs::scheduled_commits_processor_stub::ScheduledCommitsProcessorStub; use test_tools_core::init_logger; use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; @@ -32,10 +29,9 @@ mod stubs; type StubbedAccountsManager = ExternalAccountsManager< InternalAccountProviderStub, RemoteAccountClonerClient, - AccountCommitterStub, TransactionAccountsExtractorImpl, TransactionAccountsValidatorImpl, - ScheduledCommitsProcessorStub, + ChangesetCommittorStub, >; fn setup_with_lifecycle( @@ -53,7 +49,7 @@ fn setup_with_lifecycle( account_fetcher, account_updates, account_dumper, - changeset_committor_stub, + changeset_committor_stub.clone(), None, HashSet::new(), Some(1_000_000_000), @@ -75,10 +71,9 @@ fn setup_with_lifecycle( let external_account_manager = ExternalAccountsManager { internal_account_provider, account_cloner: remote_account_cloner_client, - account_committer: Arc::new(AccountCommitterStub::default()), transaction_accounts_extractor: TransactionAccountsExtractorImpl, transaction_accounts_validator: TransactionAccountsValidatorImpl, - scheduled_commits_processor: ScheduledCommitsProcessorStub::default(), + committor_service: changeset_committor_stub, lifecycle, external_commitable_accounts: Default::default(), }; diff --git a/magicblock-accounts/tests/stubs/account_committer_stub.rs b/magicblock-accounts/tests/stubs/account_committer_stub.rs deleted file mode 100644 index 691d6ca9b..000000000 --- a/magicblock-accounts/tests/stubs/account_committer_stub.rs +++ /dev/null @@ -1,96 +0,0 @@ -use std::{ - collections::{HashMap, HashSet}, - sync::{Arc, RwLock}, -}; - -use async_trait::async_trait; -use magicblock_accounts::{ - errors::AccountsResult, AccountCommittee, AccountCommitter, - CommitAccountsPayload, CommitAccountsTransaction, PendingCommitTransaction, - SendableCommitAccountsPayload, -}; -use magicblock_metrics::metrics; -use solana_sdk::{ - account::AccountSharedData, pubkey::Pubkey, signature::Signature, - transaction::Transaction, -}; - -#[derive(Debug, Default, Clone)] -pub struct AccountCommitterStub { - committed_accounts: Arc>>, - confirmed_transactions: Arc>>, -} - -#[allow(unused)] // used in tests -impl AccountCommitterStub { - pub fn len(&self) -> usize { - self.committed_accounts.read().unwrap().len() - } - pub fn committed(&self, pubkey: &Pubkey) -> Option { - self.committed_accounts.read().unwrap().get(pubkey).cloned() - } - pub fn confirmed(&self, signature: &Signature) -> bool { - self.confirmed_transactions - .read() - .unwrap() - .contains(signature) - } -} - -#[async_trait] -impl AccountCommitter for AccountCommitterStub { - async fn create_commit_accounts_transaction( - &self, - committees: Vec, - ) -> AccountsResult { - let transaction = Transaction::default(); - let payload = CommitAccountsPayload { - transaction: Some(CommitAccountsTransaction { - transaction, - undelegated_accounts: HashSet::new(), - committed_only_accounts: HashSet::new(), - }), - committees: committees - .iter() - .map(|x| (x.pubkey, x.account_data.clone())) - .collect(), - }; - Ok(payload) - } - - async fn send_commit_transactions( - &self, - payloads: Vec, - ) -> AccountsResult> { - let signatures = payloads - .iter() - .map(|_| PendingCommitTransaction { - signature: Signature::new_unique(), - undelegated_accounts: HashSet::new(), - committed_only_accounts: HashSet::new(), - timer: metrics::account_commit_start(), - }) - .collect(); - for payload in payloads { - for (pubkey, account) in payload.committees { - self.committed_accounts - .write() - .unwrap() - .insert(pubkey, account); - } - } - Ok(signatures) - } - - async fn confirm_pending_commits( - &self, - pending_commits: Vec, - ) { - for commit in pending_commits { - self.confirmed_transactions - .write() - .unwrap() - .insert(commit.signature); - } - } -} diff --git a/magicblock-accounts/tests/stubs/mod.rs b/magicblock-accounts/tests/stubs/mod.rs index 5d245cb19..6cc81b2d0 100644 --- a/magicblock-accounts/tests/stubs/mod.rs +++ b/magicblock-accounts/tests/stubs/mod.rs @@ -1,2 +1 @@ -pub mod account_committer_stub; pub mod scheduled_commits_processor_stub; diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 7bf49afc2..ad05117ff 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -87,7 +87,7 @@ impl L1MessagePersister { }) } - fn create_commit_rows( + pub fn create_commit_rows( l1_message: &ScheduledL1Message, ) -> Vec { let Some(committed_accounts) = l1_message.get_committed_accounts() diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index f2e484898..5fcab3f74 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -8,16 +8,24 @@ use std::{ }; use magicblock_committor_program::Changeset; +use magicblock_program::SentCommit; use solana_pubkey::Pubkey; -use solana_sdk::{hash::Hash, signature::Signature}; -use tokio::sync::oneshot; +use solana_sdk::{hash::Hash, signature::Signature, transaction::Transaction}; +use tokio::sync::{oneshot, oneshot::Receiver}; use crate::{ + commit_scheduler::{ + BroadcastedMessageExecutionResult, ExecutionOutputWrapper, + }, error::CommittorServiceResult, + message_executor::ExecutionOutput, persist::{ CommitStatus, CommitStatusRow, CommitStatusSignatures, CommitStrategy, - CommitType, MessageSignatures, + CommitType, L1MessagePersister, MessageSignatures, }, + service_ext::{L1MessageCommitorExtResult, L1MessageCommittorExt}, + types::{ScheduledL1MessageWrapper, TriggerType}, + utils::ScheduledMessageExt, L1MessageCommittor, }; @@ -25,113 +33,129 @@ use crate::{ pub struct ChangesetCommittorStub { reserved_pubkeys_for_committee: Arc>>, #[allow(clippy::type_complexity)] - committed_changesets: Arc>>, + committed_changesets: Arc>>, } impl L1MessageCommittor for ChangesetCommittorStub { - fn commit_l1_messages( + fn reserve_pubkeys_for_committee( &self, - changeset: Changeset, - ephemeral_blockhash: Hash, - finalize: bool, - ) -> oneshot::Receiver> { - static REQ_ID: AtomicU64 = AtomicU64::new(0); - let reqid = REQ_ID.fetch_add(1, Ordering::Relaxed); - let (tx, rx) = tokio::sync::oneshot::channel(); - self.committed_changesets + committee: Pubkey, + owner: Pubkey, + ) -> Receiver> { + let (tx, rx) = oneshot::channel::>(); + + self.reserved_pubkeys_for_committee .lock() .unwrap() - .insert(reqid, (changeset, ephemeral_blockhash, finalize)); - tx.send(Some(reqid.to_string())).unwrap_or_else(|_| { - log::error!("Failed to send commit changeset response"); + .insert(committee, owner); + + tx.send(Ok(())).unwrap_or_else(|_| { + log::error!("Failed to send response"); }); rx } + fn commit_l1_messages(&self, l1_messages: Vec) { + let mut changesets = self.committed_changesets.lock().unwrap(); + l1_messages.into_iter().for_each(|message| { + changesets.insert(message.scheduled_l1_message.id, message); + }); + } + + fn subscribe_for_results( + &self, + ) -> Receiver< + tokio::sync::broadcast::Receiver, + > { + let (_, receiver) = oneshot::channel(); + receiver + } + fn get_commit_statuses( &self, - reqid: String, + message_id: u64, ) -> oneshot::Receiver>> { - let reqid = reqid.parse::().unwrap(); - let commit = self.committed_changesets.lock().unwrap().remove(&reqid); - let (tx, rx) = tokio::sync::oneshot::channel(); - let Some((changeset, hash, finalize)) = commit else { + let (tx, rx) = oneshot::channel(); + + let commit = self + .committed_changesets + .lock() + .unwrap() + .remove(&message_id); + let Some(l1_message) = commit else { tx.send(Ok(vec![])).unwrap_or_else(|_| { log::error!("Failed to send commit status response"); }); return rx; }; - let status_rows = changeset - .accounts - .iter() - .map(|(pubkey, acc)| CommitStatusRow { - reqid: reqid.to_string(), - pubkey: *pubkey, - delegated_account_owner: acc.owner(), - slot: changeset.slot, - ephemeral_blockhash: hash, - undelegate: changeset.accounts_to_undelegate.contains(pubkey), - lamports: acc.lamports(), - finalize, - data: Some(acc.data().to_vec()), - commit_type: CommitType::DataAccount, - created_at: now(), - commit_status: CommitStatus::Succeeded(( - reqid, - CommitStrategy::FromBuffer, - CommitStatusSignatures { - process_signature: Signature::new_unique(), - finalize_signature: Some(Signature::new_unique()), - undelegate_signature: None, - }, - )), - last_retried_at: now(), - retries_count: 0, - }) - .collect(); + + let status_rows = L1MessagePersister::create_commit_rows( + &l1_message.scheduled_l1_message, + ); tx.send(Ok(status_rows)).unwrap_or_else(|_| { log::error!("Failed to send commit status response"); }); + rx } fn get_commit_signatures( &self, - bundle_id: u64, - ) -> tokio::sync::oneshot::Receiver< - crate::error::CommittorServiceResult>, - > { - let (tx, rx) = tokio::sync::oneshot::channel(); - let bundle_signature = MessageSignatures { - bundle_id, + commit_id: u64, + pubkey: Pubkey, + ) -> oneshot::Receiver>> + { + let (tx, rx) = oneshot::channel(); + let message_signature = MessageSignatures { processed_signature: Signature::new_unique(), finalized_signature: Some(Signature::new_unique()), - undelegate_signature: None, created_at: now(), }; - tx.send(Ok(Some(bundle_signature))).unwrap_or_else(|_| { + + tx.send(Ok(Some(message_signature))).unwrap_or_else(|_| { log::error!("Failed to send bundle signatures response"); }); + rx } +} - fn reserve_pubkeys_for_committee( +#[async_trait::async_trait] +impl L1MessageCommittorExt for ChangesetCommittorStub { + async fn commit_l1_messages_waiting( &self, - committee: Pubkey, - owner: Pubkey, - ) -> oneshot::Receiver> { - let (tx, rx) = - tokio::sync::oneshot::channel::>(); - self.reserved_pubkeys_for_committee - .lock() - .unwrap() - .insert(committee, owner); - tx.send(Ok(())).unwrap_or_else(|_| { - log::error!("Failed to send response"); - }); - rx + l1_messages: Vec, + ) -> L1MessageCommitorExtResult> + { + let res = l1_messages + .into_iter() + .map(|message| { + Ok(ExecutionOutputWrapper { + id: message.scheduled_l1_message.id, + output: ExecutionOutput { + commit_signature: Signature::new_unique(), + finalize_signature: Signature::new_unique(), + }, + action_sent_transaction: Transaction::default(), + trigger_type: TriggerType::OnChain, + sent_commit: SentCommit { + message_id: message.scheduled_l1_message.id, + slot: message.scheduled_l1_message.slot, + blockhash: message.scheduled_l1_message.blockhash, + payer: message.scheduled_l1_message.payer, + requested_undelegation: message + .scheduled_l1_message + .is_undelegate(), + ..SentCommit::default() + }, + }) + }) + .collect::>(); + + Ok(res) } } + fn now() -> u64 { SystemTime::now() .duration_since(UNIX_EPOCH) diff --git a/magicblock-committor-service/tests/test_message_executor.rs b/magicblock-committor-service/tests/test_message_executor.rs index e69de29bb..dba97238f 100644 --- a/magicblock-committor-service/tests/test_message_executor.rs +++ b/magicblock-committor-service/tests/test_message_executor.rs @@ -0,0 +1,4 @@ +// solana-test-validator \ +// --bpf-program corabpNrkBEqbTZP7xfJgSWTdBmVdLf1PARWXZbcMcS \ +// ./magicblock-committor-program/bin/magicblock_committor_program.so \ +// diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs index 3b03338f4..af6981272 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs @@ -24,7 +24,6 @@ use crate::{ schedule_transactions::transaction_scheduler::TransactionScheduler, test_utils::{ensure_started_validator, process_instruction}, utils::DELEGATION_PROGRAM_ID, - ScheduledCommit, }; // For the scheduling itself and the debit to fund the scheduled transaction From e1204b2d32126fc84a4a37fefc049dc2ebe22e4f Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 30 Jul 2025 13:23:04 +0900 Subject: [PATCH 141/199] fix: cargo test - passed --- .../tests/remote_account_updates.rs | 2 +- .../src/external_accounts_manager.rs | 1 - .../src/remote_scheduled_commits_processor.rs | 1 - magicblock-accounts/tests/commit_delegated.rs | 18 +++--- .../commit_scheduler_inner.rs | 2 +- .../commit_scheduler_worker.rs | 2 +- .../src/persist/commit_persister.rs | 1 - .../src/stubs/changeset_committor_stub.rs | 8 ++- magicblock-committor-service/src/utils.rs | 48 --------------- magicblock-committor-service/tests/common.rs | 2 +- .../src/magic_scheduled_l1_message.rs | 54 +++++++++++++++++ .../process_schedule_commit_tests.rs | 59 ++++++++----------- 12 files changed, 97 insertions(+), 101 deletions(-) diff --git a/magicblock-account-updates/tests/remote_account_updates.rs b/magicblock-account-updates/tests/remote_account_updates.rs index d5c0f7a77..2c4ff196d 100644 --- a/magicblock-account-updates/tests/remote_account_updates.rs +++ b/magicblock-account-updates/tests/remote_account_updates.rs @@ -21,7 +21,7 @@ async fn setup() -> ( ) { // Create account updates worker and client let mut worker = RemoteAccountUpdatesWorker::new( - vec![RpcProviderConfig::devnet().ws_url().into(); 2], + vec![RpcProviderConfig::devnet().ws_url().into(); 1], Some(solana_sdk::commitment_config::CommitmentLevel::Confirmed), Duration::from_secs(50 * 60), ); diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index b6f9a8b74..86576230b 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -27,7 +27,6 @@ use magicblock_committor_service::{ service_ext::L1MessageCommittorExt, transactions::MAX_PROCESS_PER_TX, types::{ScheduledL1MessageWrapper, TriggerType}, - utils::ScheduledMessageExt, }; use magicblock_core::magic_program; use magicblock_program::{ diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 1efcba3fe..9ff3e35e0 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -10,7 +10,6 @@ use magicblock_committor_service::{ BroadcastedMessageExecutionResult, ExecutionOutputWrapper, }, types::{ScheduledL1MessageWrapper, TriggerType}, - utils::ScheduledMessageExt, L1MessageCommittor, }; use magicblock_processor::execute_transaction::execute_legacy_transaction; diff --git a/magicblock-accounts/tests/commit_delegated.rs b/magicblock-accounts/tests/commit_delegated.rs index 6289682c9..691258eae 100644 --- a/magicblock-accounts/tests/commit_delegated.rs +++ b/magicblock-accounts/tests/commit_delegated.rs @@ -10,6 +10,8 @@ use conjunto_transwise::{ use magicblock_account_cloner::{AccountClonerOutput, AccountClonerStub}; use magicblock_accounts::{ExternalAccountsManager, LifecycleMode}; use magicblock_accounts_api::InternalAccountProviderStub; +use magicblock_committor_service::stubs::ChangesetCommittorStub; +use magicblock_program::validator::generate_validator_authority_if_needed; use solana_sdk::{ account::{Account, AccountSharedData}, native_token::LAMPORTS_PER_SOL, @@ -26,18 +28,20 @@ type StubbedAccountsManager = ExternalAccountsManager< AccountClonerStub, TransactionAccountsExtractorImpl, TransactionAccountsValidatorImpl, - ScheduledCommitsProcessorStub, + ChangesetCommittorStub, >; fn setup( internal_account_provider: InternalAccountProviderStub, account_cloner: AccountClonerStub, + committor_service: Arc, ) -> StubbedAccountsManager { ExternalAccountsManager { internal_account_provider, account_cloner, transaction_accounts_extractor: TransactionAccountsExtractorImpl, transaction_accounts_validator: TransactionAccountsValidatorImpl, + committor_service, lifecycle: LifecycleMode::Ephemeral, external_commitable_accounts: Default::default(), } @@ -80,6 +84,7 @@ fn generate_delegated_account_chain_snapshot( async fn test_commit_two_delegated_accounts_one_needs_commit() { init_logger!(); + generate_validator_authority_if_needed(); let commit_needed_pubkey = Pubkey::new_unique(); let commit_needed_account = generate_account(&commit_needed_pubkey); let commit_needed_account_shared = @@ -92,12 +97,12 @@ async fn test_commit_two_delegated_accounts_one_needs_commit() { let internal_account_provider = InternalAccountProviderStub::default(); let account_cloner = AccountClonerStub::default(); - let account_committer = AccountCommitterStub::default(); + let committor_service = Arc::new(ChangesetCommittorStub::default()); let manager = setup( internal_account_provider.clone(), account_cloner.clone(), - account_committer.clone(), + committor_service.clone(), ); // Clone the accounts through a dummy transaction @@ -153,12 +158,7 @@ async fn test_commit_two_delegated_accounts_one_needs_commit() { // Execute the commits of the accounts that needs it let result = manager.commit_delegated().await; // Ensure we committed the account that was due - assert_eq!(account_committer.len(), 1); - // with the current account data - assert_eq!( - account_committer.committed(&commit_needed_pubkey), - Some(commit_needed_account_shared) - ); + assert_eq!(committor_service.len(), 1); // and that we returned that transaction signature for it. assert_eq!(result.unwrap().len(), 1); diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs index 2a8bfe399..4c20c3639 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs @@ -4,7 +4,7 @@ use log::warn; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use solana_pubkey::Pubkey; -use crate::{types::ScheduledL1MessageWrapper, utils::ScheduledMessageExt}; +use crate::types::ScheduledL1MessageWrapper; pub(crate) const POISONED_INNER_MSG: &str = "Mutex on CommitSchedulerInner is poisoned."; diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 5a0e8d549..b2b71d77b 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -29,7 +29,7 @@ use crate::{ }, persist::{CommitStatus, L1MessagesPersisterIface}, types::{ScheduledL1MessageWrapper, TriggerType}, - utils::{persist_status_update_by_message_set, ScheduledMessageExt}, + utils::persist_status_update_by_message_set, }; const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index ad05117ff..ecdf683ce 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -10,7 +10,6 @@ use super::{ db::CommitStatusRow, error::CommitPersistResult, utils::now, CommitStatus, CommitStrategy, CommitType, CommittsDb, MessageSignatures, }; -use crate::utils::ScheduledMessageExt; const POISONED_MUTEX_MSG: &str = "Commitor Persister lock poisoned"; diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index 5fcab3f74..cf24db0a0 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -25,7 +25,6 @@ use crate::{ }, service_ext::{L1MessageCommitorExtResult, L1MessageCommittorExt}, types::{ScheduledL1MessageWrapper, TriggerType}, - utils::ScheduledMessageExt, L1MessageCommittor, }; @@ -36,6 +35,12 @@ pub struct ChangesetCommittorStub { committed_changesets: Arc>>, } +impl ChangesetCommittorStub { + pub fn len(&self) -> usize { + self.committed_changesets.lock().unwrap().len() + } +} + impl L1MessageCommittor for ChangesetCommittorStub { fn reserve_pubkeys_for_committee( &self, @@ -127,6 +132,7 @@ impl L1MessageCommittorExt for ChangesetCommittorStub { l1_messages: Vec, ) -> L1MessageCommitorExtResult> { + self.commit_l1_messages(l1_messages.clone()); let res = l1_messages .into_iter() .map(|message| { diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index b00afe888..19cd80906 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -8,54 +8,6 @@ use solana_pubkey::Pubkey; use crate::persist::{CommitStatus, L1MessagesPersisterIface}; -pub trait ScheduledMessageExt { - fn get_committed_accounts(&self) -> Option<&Vec>; - fn get_committed_pubkeys(&self) -> Option>; - fn get_committed_accounts_mut( - &mut self, - ) -> Option<&mut Vec>; - // TODO(edwin): ugly - fn is_undelegate(&self) -> bool; -} - -impl ScheduledMessageExt for ScheduledL1Message { - fn get_committed_accounts(&self) -> Option<&Vec> { - match &self.l1_message { - MagicL1Message::L1Actions(_) => None, - MagicL1Message::Commit(t) => Some(t.get_committed_accounts()), - MagicL1Message::CommitAndUndelegate(t) => { - Some(t.get_committed_accounts()) - } - } - } - - fn get_committed_accounts_mut( - &mut self, - ) -> Option<&mut Vec> { - match &mut self.l1_message { - MagicL1Message::L1Actions(_) => None, - MagicL1Message::Commit(t) => Some(t.get_committed_accounts_mut()), - MagicL1Message::CommitAndUndelegate(t) => { - Some(t.get_committed_accounts_mut()) - } - } - } - - fn get_committed_pubkeys(&self) -> Option> { - self.get_committed_accounts().map(|accounts| { - accounts.iter().map(|account| account.pubkey).collect() - }) - } - - fn is_undelegate(&self) -> bool { - match &self.l1_message { - MagicL1Message::L1Actions(_) => false, - MagicL1Message::Commit(_) => false, - MagicL1Message::CommitAndUndelegate(_) => true, - } - } -} - pub(crate) fn persist_status_update( persister: &Option

, pubkey: &Pubkey, diff --git a/magicblock-committor-service/tests/common.rs b/magicblock-committor-service/tests/common.rs index 85e1dfb41..e6754aa5c 100644 --- a/magicblock-committor-service/tests/common.rs +++ b/magicblock-committor-service/tests/common.rs @@ -29,7 +29,7 @@ use solana_sdk::{ // Helper function to create a test RPC client pub async fn create_test_client() -> MagicblockRpcClient { - let url = "http://localhost:8899".to_string(); + let url = "http://localhost:9002".to_string(); let rpc_client = RpcClient::new_with_commitment(url, CommitmentConfig::confirmed()); diff --git a/programs/magicblock/src/magic_scheduled_l1_message.rs b/programs/magicblock/src/magic_scheduled_l1_message.rs index 45358fa74..322db8b50 100644 --- a/programs/magicblock/src/magic_scheduled_l1_message.rs +++ b/programs/magicblock/src/magic_scheduled_l1_message.rs @@ -83,6 +83,24 @@ impl ScheduledL1Message { l1_message: action, }) } + + pub fn get_committed_accounts(&self) -> Option<&Vec> { + self.l1_message.get_committed_accounts() + } + + pub fn get_committed_accounts_mut( + &mut self, + ) -> Option<&mut Vec> { + self.l1_message.get_committed_accounts_mut() + } + + pub fn get_committed_pubkeys(&self) -> Option> { + self.l1_message.get_committed_pubkeys() + } + + pub fn is_undelegate(&self) -> bool { + self.l1_message.is_undelegate() + } } // L1Message user wants to send to base layer @@ -118,6 +136,42 @@ impl MagicL1Message { } } } + + pub fn is_undelegate(&self) -> bool { + match &self { + MagicL1Message::L1Actions(_) => false, + MagicL1Message::Commit(_) => false, + MagicL1Message::CommitAndUndelegate(_) => true, + } + } + + pub fn get_committed_accounts(&self) -> Option<&Vec> { + match self { + MagicL1Message::L1Actions(_) => None, + MagicL1Message::Commit(t) => Some(t.get_committed_accounts()), + MagicL1Message::CommitAndUndelegate(t) => { + Some(t.get_committed_accounts()) + } + } + } + + pub fn get_committed_accounts_mut( + &mut self, + ) -> Option<&mut Vec> { + match self { + MagicL1Message::L1Actions(_) => None, + MagicL1Message::Commit(t) => Some(t.get_committed_accounts_mut()), + MagicL1Message::CommitAndUndelegate(t) => { + Some(t.get_committed_accounts_mut()) + } + } + } + + pub fn get_committed_pubkeys(&self) -> Option> { + self.get_committed_accounts().map(|accounts| { + accounts.iter().map(|account| account.pubkey).collect() + }) + } } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs index af6981272..528c3ba9c 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs @@ -204,31 +204,30 @@ fn extend_transaction_accounts_from_ix_adding_magic_context( } fn assert_first_commit( - scheduled_commits: &[ScheduledCommit], + scheduled_l1_messages: &[ScheduledL1Message], payer: &Pubkey, committees: &[Pubkey], expected_request_undelegation: bool, ) { - let commit = &scheduled_commits[0]; + let scheduled_l1_message = &scheduled_l1_messages[0]; let test_clock = get_clock(); assert_matches!( - commit, - ScheduledCommit { + scheduled_l1_message, + ScheduledL1Message { id, slot, - accounts, - payer: p, + payer: actual_payer, blockhash: _, - commit_sent_transaction, - request_undelegation, + action_sent_transaction, + l1_message, } => { assert!(id >= &0); assert_eq!(slot, &test_clock.slot); - assert_eq!(p, payer); - assert_eq!(accounts.iter().map(|ca| ca.pubkey).collect::>().as_slice(), committees); + assert_eq!(actual_payer, payer); + assert_eq!(l1_message.get_committed_pubkeys().unwrap().as_slice(), committees); let instruction = MagicBlockInstruction::ScheduledCommitSent(*id); - assert_eq!(commit_sent_transaction.data(0), instruction.try_to_vec().unwrap()); - assert_eq!(*request_undelegation, expected_request_undelegation); + assert_eq!(action_sent_transaction.data(0), instruction.try_to_vec().unwrap()); + assert_eq!(l1_message.is_undelegate(), expected_request_undelegation); } ); } @@ -309,20 +308,14 @@ mod tests { ); // At this point the intended commits were accepted and moved to the global - let scheduled_commits = assert_accepted_actions( + let scheduled_messages = assert_accepted_actions( &processed_accepted, &payer.pubkey(), 1, ); - let scheduled_commits = scheduled_commits - .into_iter() - .map(|el| el.try_into()) - .collect::, MagicL1Message>>() - .expect("only commit action"); - assert_first_commit( - &scheduled_commits, + &scheduled_messages, &payer.pubkey(), &[committee], false, @@ -407,12 +400,6 @@ mod tests { 1, ); - let scheduled_commits = scheduled_commits - .into_iter() - .map(|el| el.try_into()) - .collect::, MagicL1Message>>() - .expect("only commit action"); - assert_first_commit( &scheduled_commits, &payer.pubkey(), @@ -519,11 +506,11 @@ mod tests { 1, ); - let scheduled_commits = scheduled_commits - .into_iter() - .map(|el| el.try_into()) - .collect::, MagicL1Message>>() - .expect("only commit action"); + // let scheduled_commits = scheduled_commits + // .into_iter() + // .map(|el| el.try_into()) + // .collect::, MagicL1Message>>() + // .expect("only commit action"); assert_first_commit( &scheduled_commits, @@ -634,11 +621,11 @@ mod tests { 1, ); - let scheduled_commits = scheduled_commits - .into_iter() - .map(|el| el.try_into()) - .collect::, MagicL1Message>>() - .expect("only commit action"); + // let scheduled_commits = scheduled_commits + // .into_iter() + // .map(|el| el.try_into()) + // .collect::, MagicL1Message>>() + // .expect("only commit action"); assert_first_commit( &scheduled_commits, From 59358097849abea80e52f2270997edf315552413 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 30 Jul 2025 17:43:07 +0900 Subject: [PATCH 142/199] fix: escrow commitment --- .../src/remote_scheduled_commits_processor.rs | 11 ++- .../src/tasks/tasks.rs | 4 +- test-integration/Cargo.lock | 17 +++-- test-integration/Cargo.toml | 3 +- .../programs/schedulecommit/Cargo.toml | 1 + .../programs/schedulecommit/src/api.rs | 63 +++--------------- test-integration/schedulecommit/elfs/dlp.so | Bin 319832 -> 322944 bytes 7 files changed, 29 insertions(+), 70 deletions(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 9ff3e35e0..1da4d7e2f 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -21,6 +21,7 @@ use magicblock_transaction_status::TransactionStatusSender; use solana_sdk::{ account::{Account, ReadableAccount}, pubkey::Pubkey, + system_program, }; use tokio::sync::{broadcast, oneshot}; @@ -88,28 +89,26 @@ impl RemoteScheduledCommitsProcessor { let pubkey = account.pubkey; let ephemeral_pubkey = AccountChainSnapshot::ephemeral_balance_pda(&pubkey); - self.feepayers.insert(FeePayerAccount { pubkey, delegated_pda: ephemeral_pubkey, }); - match self.bank.get_account(&ephemeral_pubkey) { + // We commit escrow, its data kept under FeePayer's address + match self.bank.get_account(&pubkey) { Some(account_data) => { - let ephemeral_owner = - AccountChainSnapshot::ephemeral_balance_pda_owner(); account.pubkey = ephemeral_pubkey; account.account = Account { lamports: account_data.lamports(), data: account_data.data().to_vec(), - owner: ephemeral_owner, + owner: system_program::id(), executable: account_data.executable(), rent_epoch: account_data.rent_epoch(), }; true } None => { - // TODO(edwin): shouldn't be possible panic? + // TODO(edwin): shouldn't be possible.. Should be a panic error!( "Scheduled commit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", pubkey diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index ae8dee1e4..576e7bb55 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -175,7 +175,7 @@ impl L1Task for ArgsTask { fn compute_units(&self) -> u32 { match self { - Self::Commit(_) => 35_000, + Self::Commit(_) => 50_000, Self::L1Action(task) => task.action.compute_units, Self::Undelegate(_) => 35_000, Self::Finalize(_) => 25_000, @@ -288,7 +288,7 @@ impl L1Task for BufferTask { fn compute_units(&self) -> u32 { match self { - Self::Commit(_) => 45_000, + Self::Commit(_) => 50_000, } } diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index dc8e32712..beff5f8ae 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1746,20 +1746,20 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk" -version = "0.2.5" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=c1fcb91#c1fcb917504751ab513c471e4381321d7d40bb91" +version = "0.2.6" dependencies = [ - "borsh 0.10.4", + "borsh 1.5.7", "ephemeral-rollups-sdk-attribute-commit", "ephemeral-rollups-sdk-attribute-delegate", "ephemeral-rollups-sdk-attribute-ephemeral", + "magicblock-delegation-program 1.0.0", + "magicblock-program", "solana-program", ] [[package]] name = "ephemeral-rollups-sdk-attribute-commit" -version = "0.2.5" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=c1fcb91#c1fcb917504751ab513c471e4381321d7d40bb91" +version = "0.2.6" dependencies = [ "quote", "syn 1.0.109", @@ -1767,8 +1767,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-delegate" -version = "0.2.5" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=c1fcb91#c1fcb917504751ab513c471e4381321d7d40bb91" +version = "0.2.6" dependencies = [ "proc-macro2", "quote", @@ -1777,8 +1776,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-ephemeral" -version = "0.2.5" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=c1fcb91#c1fcb917504751ab513c471e4381321d7d40bb91" +version = "0.2.6" dependencies = [ "proc-macro2", "quote", @@ -4924,6 +4922,7 @@ version = "0.0.0" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk", + "magicblock-delegation-program 1.0.0", "solana-program", ] diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 5d56b6fc6..cadd38f58 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -27,7 +27,8 @@ edition = "2021" anyhow = "1.0.86" borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" -ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "c1fcb91" } +ephemeral-rollups-sdk = { path = "../../ephemeral-rollups-sdk/rust/sdk" } +#ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "c1fcb91" } integration-test-tools = { path = "test-tools" } log = "0.4.20" magicblock-api = { path = "../magicblock-api" } diff --git a/test-integration/programs/schedulecommit/Cargo.toml b/test-integration/programs/schedulecommit/Cargo.toml index 04de1f1fb..d850f923f 100644 --- a/test-integration/programs/schedulecommit/Cargo.toml +++ b/test-integration/programs/schedulecommit/Cargo.toml @@ -7,6 +7,7 @@ edition.workspace = true borsh = { workspace = true } ephemeral-rollups-sdk = { workspace = true } solana-program = { workspace = true } +magicblock-delegation-program = { workspace = true } [lib] crate-type = ["cdylib", "lib"] diff --git a/test-integration/programs/schedulecommit/src/api.rs b/test-integration/programs/schedulecommit/src/api.rs index 2e3b2f4e8..0ac17052b 100644 --- a/test-integration/programs/schedulecommit/src/api.rs +++ b/test-integration/programs/schedulecommit/src/api.rs @@ -1,12 +1,8 @@ -use ephemeral_rollups_sdk::consts::BUFFER; +use dlp::args::{DelegateArgs, DelegateEphemeralBalanceArgs}; use ephemeral_rollups_sdk::delegate_args::{ DelegateAccountMetas, DelegateAccounts, }; -use ephemeral_rollups_sdk::pda::{ - delegation_metadata_pda_from_delegated_account, - delegation_record_pda_from_delegated_account, - ephemeral_balance_pda_from_payer, -}; +use ephemeral_rollups_sdk::pda::{delegate_buffer_pda_from_delegated_account_and_owner_program, delegation_metadata_pda_from_delegated_account, delegation_record_pda_from_delegated_account, ephemeral_balance_pda_from_payer}; use solana_program::{ instruction::{AccountMeta, Instruction}, pubkey::Pubkey, @@ -36,53 +32,16 @@ pub fn init_account_instruction( } pub fn init_payer_escrow(payer: Pubkey) -> [Instruction; 2] { - // Top-up Ix - let ephemeral_balance_pda = ephemeral_balance_pda_from_payer(&payer, 0); - let top_up_ix = Instruction { - program_id: ephemeral_rollups_sdk::id(), - accounts: vec![ - AccountMeta::new(payer, true), - AccountMeta::new_readonly(payer, false), - AccountMeta::new(ephemeral_balance_pda, false), - AccountMeta::new_readonly(system_program::id(), false), - ], - // discriminator + TopUpEphemeralBalanceArgs from the magicblock-delegation-program - data: [ - vec![9, 0, 0, 0, 0, 0, 0, 0], - vec![0, 163, 225, 17, 0, 0, 0, 0, 0], - ] - .concat(), - }; + let top_up_ix = dlp::instruction_builder::top_up_ephemeral_balance(payer, payer, Some(300_000_000), Some(0)); + let delegate_ix = dlp::instruction_builder::delegate_ephemeral_balance(payer, payer, DelegateEphemeralBalanceArgs { + index: 0, + delegate_args: DelegateArgs { + commit_frequency_ms: 0, + seeds: vec![], + validator: None, + } + }); - // Delegate ephemeral balance Ix - let buffer = Pubkey::find_program_address( - &[BUFFER, &ephemeral_balance_pda.to_bytes()], - &ephemeral_rollups_sdk::id(), - ); - let delegation_record_pda = - delegation_record_pda_from_delegated_account(&ephemeral_balance_pda); - let delegation_metadata_pda = - delegation_metadata_pda_from_delegated_account(&ephemeral_balance_pda); - - let delegate_ix = Instruction { - program_id: ephemeral_rollups_sdk::id(), - accounts: vec![ - AccountMeta::new(payer, true), - AccountMeta::new_readonly(payer, true), - AccountMeta::new(ephemeral_balance_pda, false), - AccountMeta::new(buffer.0, false), - AccountMeta::new(delegation_record_pda, false), - AccountMeta::new(delegation_metadata_pda, false), - AccountMeta::new_readonly(system_program::id(), false), - AccountMeta::new_readonly(ephemeral_rollups_sdk::id(), false), - ], - // discriminator + DelegateEphemeralBalanceArgs from the magicblock-delegation-program - data: [ - vec![10, 0, 0, 0, 0, 0, 0, 0], - vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - ] - .concat(), - }; [top_up_ix, delegate_ix] } diff --git a/test-integration/schedulecommit/elfs/dlp.so b/test-integration/schedulecommit/elfs/dlp.so index 748c0d84b4a07c530a2cc84390bb5ab5647d6303..bf743da8440acdd4dd83bacdb7be0e030a829b93 100755 GIT binary patch delta 54929 zcmbrn30&00`#8QcyNh^$$g$!oxL$~;NTx`nNM(qofF^_o2r7sdf(Nm#0-B88k~2!i)4wKFB#;J5x45$yLjqmr&dLlqG|!#+8`EjF zJ1aC6(iC^*?ovo&-PvZ$A`sWAkoHGP%(}RYKqwhHa{MmtvISxJjiSd>?SXJEcF_V=WUaxWJ`53FE$L7mxW z-p|spDJq1qL^#ID!rd@$$DhO%L%j&yDoi!hn! zYZF<$PXK*(lE|v8Q2Q>8>V9^)PG{6%9i>WjK8JZDyn?V zE-bFIYrYTVexcJ@JGhFx6;|g?W7Nqy91cOa6^eQXQ#_UYO9VC6^O7H|-i>$oC+njU zZe^78wh0oBH%d9Jk1Fj*y#9`D0{h62{D>^@ z8w|5EY1b*L;DZ&xAJGUtShmYuhbQX@MJ`qDN2T0Wi(&{xzgFB(%x_NTVc7wFL`~c5 zgF+%(qyTmCMj}kfEyR1?8lbd1L*kn`XJIi!BMTiwl-@-J=^F4k#o~bY=a(eeMJ^nw@QNQ4U$1`RJc2S zv@VbhwD*+d)@@Q?o2SxS+fKnFezboN>$Zb}^Fq&Vf^y-*7Lm7VE&bXC9`LWbJ|G`q zp11^F=<3zQ5>_SU4ToTnb(*$eY3hZZ()2CuNhh#w+oH5DyTZC{tJK)jA{wx6+b!U* z7RmQ31Skn68(RtQkns+A&mj>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- .../src/commit_scheduler/commit_id_tracker.rs | 17 +- .../commit_scheduler_worker.rs | 123 ++++++------- .../src/message_executor/message_executor.rs | 121 ++++++------- .../message_executor_factory.rs | 19 +- .../src/message_executor/mod.rs | 1 - .../src/persist/commit_persister.rs | 15 +- .../src/persist/db.rs | 24 +-- .../src/persist/types/commit_status.rs | 93 ++++------ .../src/tasks/task_builder.rs | 163 +++++++++++++----- .../delivery_preparator.rs | 11 +- .../src/transaction_preperator/error.rs | 14 +- .../transaction_preparator.rs | 33 ++-- magicblock-committor-service/tests/common.rs | 23 ++- .../tests/test_transaction_preparator.rs | 13 +- 15 files changed, 352 insertions(+), 327 deletions(-) diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/commit_scheduler.rs index 0f98c9586..4aeb2676b 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/commit_scheduler.rs @@ -1,4 +1,4 @@ -mod commit_id_tracker; +pub mod commit_id_tracker; pub(crate) mod commit_scheduler_inner; mod commit_scheduler_worker; pub(crate) mod db; // TODO(edwin): define visibility @@ -40,18 +40,19 @@ impl CommitScheduler { ) -> Self { let db = Arc::new(db); + let commit_id_tracker = + Arc::new(CommitIdTrackerImpl::new(rpc_client.clone())); let executor_factory = L1MessageExecutorFactory { - rpc_client: rpc_client.clone(), + rpc_client, table_mania, compute_budget_config, + commit_id_tracker, }; - let commit_id_tracker = CommitIdTrackerImpl::new(rpc_client); let (sender, receiver) = mpsc::channel(1000); let worker = CommitSchedulerWorker::new( db.clone(), executor_factory, - commit_id_tracker, l1_message_persister, receiver, ); diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs index d8ef26dca..bdbe694fc 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs @@ -14,9 +14,9 @@ use magicblock_rpc_client::{MagicBlockRpcClientError, MagicblockRpcClient}; use solana_pubkey::Pubkey; #[async_trait::async_trait] -pub trait CommitIdTracker { - async fn next_commit_ids( - &mut self, +pub trait CommitIdFetcher: Send + Sync + 'static { + async fn fetch_commit_ids( + &self, pubkeys: &[Pubkey], ) -> CommitIdTrackerResult>; @@ -112,8 +112,8 @@ impl CommitIdTrackerImpl { error!("invalid pubkey index in pda_accounts: {i}"); Pubkey::new_unique() }; - let account = account - .ok_or(Error::MetadataNotFoundError(pda_accounts[i]))?; + let account = + account.ok_or(Error::MetadataNotFoundError(pubkey))?; let metadata = DelegationMetadata::try_from_bytes_with_discriminator( &account.data, @@ -128,12 +128,13 @@ impl CommitIdTrackerImpl { } } +/// CommitFetcher implementation that also caches most used 1000 keys #[async_trait::async_trait] -impl CommitIdTracker for CommitIdTrackerImpl { +impl CommitIdFetcher for CommitIdTrackerImpl { /// Returns next ids for requested pubkeys /// If key isn't in cache, it will be requested - async fn next_commit_ids( - &mut self, + async fn fetch_commit_ids( + &self, pubkeys: &[Pubkey], ) -> CommitIdTrackerResult> { const NUM_FETCH_RETRIES: NonZeroUsize = diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index b2b71d77b..5a8c815fa 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -17,7 +17,7 @@ use tokio::{ use crate::{ commit_scheduler::{ - commit_id_tracker::CommitIdTracker, + commit_id_tracker::CommitIdFetcher, commit_scheduler_inner::{CommitSchedulerInner, POISONED_INNER_MSG}, db::DB, Error, @@ -63,10 +63,9 @@ impl ResultSubscriber { } } -pub(crate) struct CommitSchedulerWorker { +pub(crate) struct CommitSchedulerWorker { db: Arc, executor_factory: F, - commit_id_tracker: C, l1_messages_persister: Option

, receiver: mpsc::Receiver, @@ -75,18 +74,16 @@ pub(crate) struct CommitSchedulerWorker { executors_semaphore: Arc, } -impl CommitSchedulerWorker +impl CommitSchedulerWorker where D: DB, P: L1MessagesPersisterIface, F: MessageExecutorFactory + Send + Sync + 'static, E: MessageExecutor, - C: CommitIdTracker + Clone + Send + Sync + 'static, { pub fn new( db: Arc, executor_factory: F, - commit_id_tracker: C, l1_messages_persister: Option

, receiver: mpsc::Receiver, ) -> Self { @@ -94,7 +91,6 @@ where db, l1_messages_persister, executor_factory, - commit_id_tracker, receiver, running_executors: FuturesUnordered::new(), executors_semaphore: Arc::new(Semaphore::new( @@ -145,14 +141,12 @@ where // Spawn executor let executor = self.executor_factory.create_instance(); let persister = self.l1_messages_persister.clone(); - let commit_id_tracker = self.commit_id_tracker.clone(); let inner = self.inner.clone(); let handle = tokio::spawn(Self::execute( executor, persister, l1_message, - commit_id_tracker, inner, permit, result_sender.clone(), @@ -236,65 +230,60 @@ where executor: E, persister: Option

, l1_message: ScheduledL1MessageWrapper, - mut commit_id_tracker: C, inner_scheduler: Arc>, execution_permit: OwnedSemaphorePermit, result_sender: broadcast::Sender, ) { // Prepare commit ids for execution - let commit_ids = if let Some(pubkeys) = - l1_message.scheduled_l1_message.get_committed_pubkeys() - { - let commit_ids = commit_id_tracker.next_commit_ids(&pubkeys).await; - - match commit_ids { - Ok(value) => value, - Err(err) => { - // TODO(edwin): support contract and send result via receiver as well - // At this point this is unrecoverable. - // We just skip for now and pretend this message didn't exist - error!("Failed to fetch commit nonces for message: {:?}, error: {:?}", l1_message, err); - - let message_id = l1_message.scheduled_l1_message.id; - info!( - "Message has to be committed manually: {}", - message_id - ); - // Persist as Failed in DB - persist_status_update_by_message_set( - &persister, - message_id, - &pubkeys, - CommitStatus::Failed, - ); - inner_scheduler - .lock() - .expect(POISONED_INNER_MSG) - .complete(&l1_message.scheduled_l1_message); - drop(execution_permit); - return; - } - } - } else { - // Pure L1Action, no commit ids used - HashMap::new() - }; - - // Persist data - commit_ids - .iter() - .for_each(|(pubkey, commit_id) | { - if let Err(err) = persister.set_commit_id(l1_message.scheduled_l1_message.id, pubkey, *commit_id) { - error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.scheduled_l1_message.id, pubkey, err); - } - }); + // let commit_ids = if let Some(pubkeys) = + // l1_message.scheduled_l1_message.get_committed_pubkeys() + // { + // let commit_ids = commit_id_tracker.fetch_commit_ids(&pubkeys).await; + // + // match commit_ids { + // Ok(value) => value, + // Err(err) => { + // // TODO(edwin): support contract and send result via receiver as well + // // At this point this is unrecoverable. + // // We just skip for now and pretend this message didn't exist + // error!("Failed to fetch commit nonces for message: {:?}, error: {:?}", l1_message, err); + // + // let message_id = l1_message.scheduled_l1_message.id; + // info!( + // "Message has to be committed manually: {}", + // message_id + // ); + // // Persist as Failed in DB + // persist_status_update_by_message_set( + // &persister, + // message_id, + // &pubkeys, + // CommitStatus::Failed, + // ); + // inner_scheduler + // .lock() + // .expect(POISONED_INNER_MSG) + // .complete(&l1_message.scheduled_l1_message); + // drop(execution_permit); + // return; + // } + // } + // } else { + // // Pure L1Action, no commit ids used + // HashMap::new() + // }; + // + // // Persist data + // commit_ids + // .iter() + // .for_each(|(pubkey, commit_id) | { + // if let Err(err) = persister.set_commit_id(l1_message.scheduled_l1_message.id, pubkey, *commit_id) { + // error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.scheduled_l1_message.id, pubkey, err); + // } + // }); let result = executor - .execute( - l1_message.scheduled_l1_message.clone(), - commit_ids, - persister, - ) + .execute(l1_message.scheduled_l1_message.clone(), persister) .await .inspect_err(|err| error!("Failed to execute L1Message: {:?}", err)) .map(|raw_result| { @@ -383,7 +372,7 @@ mod tests { use super::*; use crate::{ commit_scheduler::{ - commit_id_tracker::{CommitIdTracker, CommitIdTrackerResult}, + commit_id_tracker::{CommitIdFetcher, CommitIdTrackerResult}, commit_scheduler_inner::create_test_message, db::{DummyDB, DB}, }, @@ -397,7 +386,6 @@ mod tests { DummyDB, L1MessagePersister, MockMessageExecutorFactory, - MockCommitIdTracker, >; fn setup_worker( should_fail: bool, @@ -413,11 +401,9 @@ mod tests { } else { MockMessageExecutorFactory::new_failing() }; - let commit_id_tracker = MockCommitIdTracker::new(); let worker = CommitSchedulerWorker::new( db.clone(), executor_factory, - commit_id_tracker, None::, receiver, ); @@ -777,7 +763,6 @@ mod tests { async fn execute( &self, l1_message: ScheduledL1Message, - _commit_ids: HashMap, _persister: Option

, ) -> MessageExecutorResult { self.on_task_started(); @@ -814,9 +799,9 @@ mod tests { } #[async_trait] - impl CommitIdTracker for MockCommitIdTracker { - async fn next_commit_ids( - &mut self, + impl CommitIdFetcher for MockCommitIdTracker { + async fn fetch_commit_ids( + &self, pubkeys: &[Pubkey], ) -> CommitIdTrackerResult> { Ok(pubkeys.iter().map(|&k| (k, 1)).collect()) diff --git a/magicblock-committor-service/src/message_executor/message_executor.rs b/magicblock-committor-service/src/message_executor/message_executor.rs index 44f6af8dc..fa8964c45 100644 --- a/magicblock-committor-service/src/message_executor/message_executor.rs +++ b/magicblock-committor-service/src/message_executor/message_executor.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap, sync::Arc}; use log::warn; use magicblock_program::{ @@ -18,6 +18,7 @@ use solana_sdk::{ }; use crate::{ + commit_scheduler::commit_id_tracker::CommitIdFetcher, message_executor::{ error::{Error, InternalError, MessageExecutorResult}, ExecutionOutput, MessageExecutor, @@ -26,7 +27,10 @@ use crate::{ transaction_preperator::transaction_preparator::{ TransactionPreparator, TransactionPreparatorV1, }, - utils::{persist_status_update, persist_status_update_set}, + utils::{ + persist_status_update, persist_status_update_by_message_set, + persist_status_update_set, + }, ComputeBudgetConfig, }; @@ -40,18 +44,12 @@ impl L1MessageExecutor where T: TransactionPreparator, { - pub fn new_v1( + pub fn new( rpc_client: MagicblockRpcClient, - table_mania: TableMania, - compute_budget_config: ComputeBudgetConfig, - ) -> L1MessageExecutor { + transaction_preparator: T, + ) -> Self { let authority = validator_authority(); - let transaction_preparator = TransactionPreparatorV1::new( - rpc_client.clone(), - table_mania, - compute_budget_config, - ); - L1MessageExecutor:: { + Self { authority, rpc_client, transaction_preparator, @@ -61,17 +59,16 @@ where async fn execute_inner( &self, l1_message: ScheduledL1Message, - commit_ids: &HashMap, persister: &Option

, ) -> MessageExecutorResult { // Update tasks status to Pending - let update_status = CommitStatus::Pending; - persist_status_update_set(&persister, &commit_ids, update_status); + // let update_status = CommitStatus::Pending; + // persist_status_update_set(&persister, &commit_ids, update_status); // Commit stage - let commit_signature = self - .execute_commit_stage(&l1_message, commit_ids, persister) - .await?; + let commit_signature = + self.execute_commit_stage(&l1_message, persister).await?; + // Finalize stage // At the moment validator finalizes right away // In the future there will be a challenge window @@ -88,17 +85,11 @@ where async fn execute_commit_stage( &self, l1_message: &ScheduledL1Message, - commit_ids: &HashMap, persister: &Option

, ) -> MessageExecutorResult { let prepared_message = self .transaction_preparator - .prepare_commit_tx( - &self.authority, - l1_message, - commit_ids, - persister, - ) + .prepare_commit_tx(&self.authority, l1_message, persister) .await .map_err(Error::FailedCommitPreparationError)?; @@ -113,15 +104,9 @@ where commit_signature: Signature, persister: &Option

, ) -> MessageExecutorResult { - let rent_reimbursement = self.authority.pubkey(); let prepared_message = self .transaction_preparator - .prepare_finalize_tx( - &self.authority, - &rent_reimbursement, - l1_message, - persister, - ) + .prepare_finalize_tx(&self.authority, l1_message, persister) .await .map_err(Error::FailedFinalizePreparationError)?; @@ -176,61 +161,49 @@ where fn persist_result( persistor: &Option

, result: &MessageExecutorResult, - commit_ids: &HashMap, + message_id: u64, + pubkeys: &[Pubkey], ) { match result { Ok(value) => { - commit_ids.iter().for_each(|(pubkey, commit_id)| { - let signatures = CommitStatusSignatures { - process_signature: value.commit_signature, - finalize_signature: Some(value.commit_signature) - }; - let update_status = CommitStatus::Succeeded((*commit_id, signatures)); - persist_status_update(persistor, pubkey, *commit_id, update_status) - }); + let signatures = CommitStatusSignatures { + process_signature: value.commit_signature, + finalize_signature: Some(value.commit_signature) + }; + let update_status = CommitStatus::Succeeded(signatures); + persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::FailedToFitError)) => { - commit_ids.iter().for_each(|(pubkey, commit_id)| { - let update_status = CommitStatus::PartOfTooLargeBundleToProcess(*commit_id); - persist_status_update(persistor, pubkey, *commit_id, update_status) - }); + let update_status = CommitStatus::PartOfTooLargeBundleToProcess; + persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } - Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::MissingCommitIdError(_))) => { - commit_ids.iter().for_each(|(pubkey, commit_id)| { - // Invalid task - let update_status = CommitStatus::Failed; - persist_status_update(persistor, pubkey, *commit_id, update_status) - }); + Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::TaskBuilderError(_))) => { + let update_status = CommitStatus::Failed; + persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); }, Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::DeliveryPreparationError(_))) => { // Persisted internally }, Err(Error::FailedToCommitError {err: _, signature}) => { // Commit is a single TX, so if it fails, all of commited accounts marked FailedProcess - commit_ids.iter().for_each(|(pubkey, commit_id)| { - // Invalid task - let status_signature = signature.map(|sig| CommitStatusSignatures { - process_signature: sig, - finalize_signature: None - }); - let update_status = CommitStatus::FailedProcess((*commit_id, status_signature)); - persist_status_update(persistor, pubkey, *commit_id, update_status) + let status_signature = signature.map(|sig| CommitStatusSignatures { + process_signature: sig, + finalize_signature: None }); + let update_status = CommitStatus::FailedProcess(status_signature); + persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } Err(Error::FailedFinalizePreparationError(_)) => { // Not supported in persistor }, Err(Error::FailedToFinalizeError {err: _, commit_signature, finalize_signature}) => { // Finalize is a single TX, so if it fails, all of commited accounts marked FailedFinalize - commit_ids.iter().for_each(|(pubkey, commit_id)| { - // Invalid task - let status_signature = CommitStatusSignatures { - process_signature: *commit_signature, - finalize_signature: *finalize_signature - }; - let update_status = CommitStatus::FailedFinalize((*commit_id, status_signature)); - persist_status_update(persistor, pubkey, *commit_id, update_status) - }); + let status_signature = CommitStatusSignatures { + process_signature: *commit_signature, + finalize_signature: *finalize_signature + }; + let update_status = CommitStatus::FailedFinalize( status_signature); + persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } } } @@ -246,13 +219,15 @@ where async fn execute( &self, l1_message: ScheduledL1Message, - commit_ids: HashMap, persister: Option

, ) -> MessageExecutorResult { - let result = self - .execute_inner(l1_message, &commit_ids, &persister) - .await; - Self::persist_result(&persister, &result, &commit_ids); + let message_id = l1_message.id; + let pubkeys = l1_message.get_committed_pubkeys(); + + let result = self.execute_inner(l1_message, &persister).await; + if let Some(pubkeys) = pubkeys { + Self::persist_result(&persister, &result, message_id, &pubkeys); + } result } diff --git a/magicblock-committor-service/src/message_executor/message_executor_factory.rs b/magicblock-committor-service/src/message_executor/message_executor_factory.rs index 48169536f..6234eee8f 100644 --- a/magicblock-committor-service/src/message_executor/message_executor_factory.rs +++ b/magicblock-committor-service/src/message_executor/message_executor_factory.rs @@ -1,7 +1,10 @@ +use std::sync::Arc; + use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; use crate::{ + commit_scheduler::commit_id_tracker::CommitIdTrackerImpl, message_executor::{L1MessageExecutor, MessageExecutor}, transaction_preperator::transaction_preparator::TransactionPreparatorV1, ComputeBudgetConfig, @@ -18,16 +21,24 @@ pub struct L1MessageExecutorFactory { pub rpc_client: MagicblockRpcClient, pub table_mania: TableMania, pub compute_budget_config: ComputeBudgetConfig, + pub commit_id_tracker: Arc, } impl MessageExecutorFactory for L1MessageExecutorFactory { - type Executor = L1MessageExecutor; + type Executor = + L1MessageExecutor>; fn create_instance(&self) -> Self::Executor { - L1MessageExecutor::::new_v1( + let transaction_preaparator = + TransactionPreparatorV1::::new( + self.rpc_client.clone(), + self.table_mania.clone(), + self.compute_budget_config.clone(), + self.commit_id_tracker.clone(), + ); + L1MessageExecutor::>::new( self.rpc_client.clone(), - self.table_mania.clone(), - self.compute_budget_config.clone(), + transaction_preaparator, ) } } diff --git a/magicblock-committor-service/src/message_executor/mod.rs b/magicblock-committor-service/src/message_executor/mod.rs index 87a100736..acc2a15e6 100644 --- a/magicblock-committor-service/src/message_executor/mod.rs +++ b/magicblock-committor-service/src/message_executor/mod.rs @@ -30,7 +30,6 @@ pub trait MessageExecutor: Send + Sync + 'static { async fn execute( &self, l1_message: ScheduledL1Message, - commit_ids: HashMap, persister: Option

, ) -> MessageExecutorResult; } diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index ecdf683ce..ff8af540f 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -496,7 +496,7 @@ mod tests { .update_status_by_commit( 100, &pubkey, - CommitStatus::BufferAndChunkInitialized(100), + CommitStatus::BufferAndChunkInitialized, ) .unwrap(); @@ -506,7 +506,7 @@ mod tests { .unwrap(); assert_eq!( updated.commit_status, - CommitStatus::BufferAndChunkInitialized(100) + CommitStatus::BufferAndChunkInitialized ); } @@ -542,13 +542,10 @@ mod tests { let process_sig = Signature::new_unique(); let finalize_sig = Signature::new_unique(); - let status = CommitStatus::Succeeded(( - 100, - CommitStatusSignatures { - process_signature: process_sig, - finalize_signature: Some(finalize_sig), - }, - )); + let status = CommitStatus::Succeeded(CommitStatusSignatures { + process_signature: process_sig, + finalize_signature: Some(finalize_sig), + }); persister .update_status_by_commit(100, &pubkey, status) diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 26e7ce2c8..275b3d7fd 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -549,7 +549,7 @@ fn extract_committor_row( process_signature: s, finalize_signature: finalized_signature, }); - CommitStatus::try_from((commit_status.as_str(), commit_id, sigs))? + CommitStatus::try_from((commit_status.as_str(), sigs))? }; let last_retried_at: u64 = { @@ -685,13 +685,10 @@ mod tests { let row = create_test_row(1, 100); // Set commit_id to 100 db.insert_commit_status_rows(&[row.clone()]).unwrap(); - let new_status = CommitStatus::Succeeded(( - 100, - CommitStatusSignatures { - process_signature: Signature::new_unique(), - finalize_signature: None, - }, - )); + let new_status = CommitStatus::Succeeded(CommitStatusSignatures { + process_signature: Signature::new_unique(), + finalize_signature: None, + }); db.update_status_by_commit(100, &row.pubkey, &new_status) .unwrap(); @@ -720,13 +717,10 @@ mod tests { let finalize_sig = Signature::new_unique(); let mut row = create_test_row(1, 100); - row.commit_status = CommitStatus::Succeeded(( - 100, - CommitStatusSignatures { - process_signature: process_sig, - finalize_signature: Some(finalize_sig), - }, - )); + row.commit_status = CommitStatus::Succeeded(CommitStatusSignatures { + process_signature: process_sig, + finalize_signature: Some(finalize_sig), + }); db.insert_commit_status_rows(&[row.clone()]).unwrap(); let sigs = db diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index 8275cecb6..197274b92 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -15,27 +15,27 @@ pub enum CommitStatus { /// The buffer and chunks account were initialized, but could either not /// be retrieved or deserialized. It is recommended to fully re-initialize /// them on retry. - BufferAndChunkPartiallyInitialized(u64), + BufferAndChunkPartiallyInitialized, /// The buffer and chunks accounts were initialized and could be /// deserialized, however we did not complete writing to them /// We can reuse them on retry, but need to rewrite all chunks. - BufferAndChunkInitialized(u64), + BufferAndChunkInitialized, /// The buffer and chunks accounts were initialized and all data was /// written to them (for data accounts). /// This means on retry we can skip that step and just try to process /// these buffers to complete the commit. - BufferAndChunkFullyInitialized(u64), + BufferAndChunkFullyInitialized, /// The commit is part of a bundle that contains too many commits to be included /// in a single transaction. Thus we cannot commit any of them. - PartOfTooLargeBundleToProcess(u64), + PartOfTooLargeBundleToProcess, /// The commit was properly initialized and added to a chunk of instructions to process /// commits via a transaction. For large commits the buffer and chunk accounts were properly /// prepared and haven't been closed. - FailedProcess((u64, Option)), + FailedProcess(Option), /// The commit was properly processed but the requested finalize transaction failed. - FailedFinalize((u64, CommitStatusSignatures)), + FailedFinalize(CommitStatusSignatures), /// The commit was successfully processed and finalized. - Succeeded((u64, CommitStatusSignatures)), + Succeeded(CommitStatusSignatures), } impl fmt::Display for CommitStatus { @@ -45,36 +45,36 @@ impl fmt::Display for CommitStatus { CommitStatus::Failed => { write!(f, "Failed") } - CommitStatus::BufferAndChunkPartiallyInitialized(bundle_id) => { - write!(f, "BufferAndChunkPartiallyInitialized({})", bundle_id) + CommitStatus::BufferAndChunkPartiallyInitialized => { + write!(f, "BufferAndChunkPartiallyInitialized") } - CommitStatus::BufferAndChunkInitialized(bundle_id) => { - write!(f, "BufferAndChunkInitialized({})", bundle_id) + CommitStatus::BufferAndChunkInitialized => { + write!(f, "BufferAndChunkInitialized") } - CommitStatus::BufferAndChunkFullyInitialized(bundle_id) => { - write!(f, "BufferAndChunkFullyInitialized({})", bundle_id) + CommitStatus::BufferAndChunkFullyInitialized => { + write!(f, "BufferAndChunkFullyInitialized") } - CommitStatus::PartOfTooLargeBundleToProcess(bundle_id) => { - write!(f, "PartOfTooLargeBundleToProcess({})", bundle_id) + CommitStatus::PartOfTooLargeBundleToProcess => { + write!(f, "PartOfTooLargeBundleToProcess") } - CommitStatus::FailedProcess((bundle_id, sigs)) => { - write!(f, "FailedProcess({}, {:?})", bundle_id, sigs) + CommitStatus::FailedProcess(sigs) => { + write!(f, "FailedProcess({:?})", sigs) } - CommitStatus::FailedFinalize((bundle_id, sigs)) => { - write!(f, "FailedFinalize({}, {:?})", bundle_id, sigs) + CommitStatus::FailedFinalize(sigs) => { + write!(f, "FailedFinalize({:?})", sigs) } - CommitStatus::Succeeded((bundle_id, sigs)) => { - write!(f, "Succeeded({}, {:?})", bundle_id, sigs) + CommitStatus::Succeeded(sigs) => { + write!(f, "Succeeded({:?})", sigs) } } } } -impl TryFrom<(&str, u64, Option)> for CommitStatus { +impl TryFrom<(&str, Option)> for CommitStatus { type Error = CommitPersistError; fn try_from( - (status, commit_id, sigs): (&str, u64, Option), + (status, sigs): (&str, Option), ) -> Result { let get_sigs = || { if let Some(sigs) = sigs.clone() { @@ -91,20 +91,18 @@ impl TryFrom<(&str, u64, Option)> for CommitStatus { "Pending" => Ok(Pending), "Failed" => Ok(Failed), "BufferAndChunkPartiallyInitialized" => { - Ok(BufferAndChunkPartiallyInitialized(commit_id)) - } - "BufferAndChunkInitialized" => { - Ok(BufferAndChunkInitialized(commit_id)) + Ok(BufferAndChunkPartiallyInitialized) } + "BufferAndChunkInitialized" => Ok(BufferAndChunkInitialized), "BufferAndChunkFullyInitialized" => { - Ok(BufferAndChunkFullyInitialized(commit_id)) + Ok(BufferAndChunkFullyInitialized) } "PartOfTooLargeBundleToProcess" => { - Ok(PartOfTooLargeBundleToProcess(commit_id)) + Ok(PartOfTooLargeBundleToProcess) } - "FailedProcess" => Ok(FailedProcess((commit_id, sigs))), - "FailedFinalize" => Ok(FailedFinalize((commit_id, get_sigs()?))), - "Succeeded" => Ok(Succeeded((commit_id, get_sigs()?))), + "FailedProcess" => Ok(FailedProcess(sigs)), + "FailedFinalize" => Ok(FailedFinalize(get_sigs()?)), + "Succeeded" => Ok(Succeeded(get_sigs()?)), _ => { Err(CommitPersistError::InvalidCommitStatus(status.to_string())) } @@ -129,41 +127,24 @@ impl CommitStatus { match self { Pending => "Pending", Failed => "Failed", - BufferAndChunkPartiallyInitialized(_) => { + BufferAndChunkPartiallyInitialized => { "BufferAndChunkPartiallyInitialized" } - BufferAndChunkInitialized(_) => "BufferAndChunkInitialized", - BufferAndChunkFullyInitialized(_) => { - "BufferAndChunkFullyInitialized" - } - PartOfTooLargeBundleToProcess(_) => "PartOfTooLargeBundleToProcess", + BufferAndChunkInitialized => "BufferAndChunkInitialized", + BufferAndChunkFullyInitialized => "BufferAndChunkFullyInitialized", + PartOfTooLargeBundleToProcess => "PartOfTooLargeBundleToProcess", FailedProcess(_) => "FailedProcess", FailedFinalize(_) => "FailedFinalize", Succeeded(_) => "Succeeded", } } - pub fn bundle_id(&self) -> Option { - use CommitStatus::*; - match self { - BufferAndChunkPartiallyInitialized(bundle_id) - | BufferAndChunkInitialized(bundle_id) - | BufferAndChunkFullyInitialized(bundle_id) - | PartOfTooLargeBundleToProcess(bundle_id) - | FailedProcess((bundle_id, _)) - | FailedFinalize((bundle_id, _)) - | Succeeded((bundle_id, _)) => Some(*bundle_id), - Pending => None, - Failed => None, - } - } - pub fn signatures(&self) -> Option { use CommitStatus::*; match self { - FailedProcess((_, sigs)) => sigs.as_ref().cloned(), - FailedFinalize((_, sigs)) => Some(sigs.clone()), - Succeeded((_, sigs)) => Some(sigs.clone()), + FailedProcess(sigs) => sigs.as_ref().cloned(), + FailedFinalize(sigs) => Some(sigs.clone()), + Succeeded(sigs) => Some(sigs.clone()), _ => None, } } diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 7be6e565b..143b0b42c 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -1,38 +1,92 @@ -use std::collections::HashMap; +use std::{collections::HashMap, sync::Arc}; -use dlp::args::Context; +use dlp::{args::Context, state::DelegationMetadata}; +use log::error; use magicblock_program::magic_scheduled_l1_message::{ CommitType, CommittedAccountV2, MagicL1Message, ScheduledL1Message, UndelegateType, }; +use magicblock_rpc_client::{MagicBlockRpcClientError, MagicblockRpcClient}; use solana_pubkey::Pubkey; -use crate::tasks::tasks::{ - ArgsTask, CommitTask, FinalizeTask, L1ActionTask, L1Task, UndelegateTask, +use crate::{ + commit_scheduler::commit_id_tracker::CommitIdFetcher, + tasks::tasks::{ + ArgsTask, CommitTask, FinalizeTask, L1ActionTask, L1Task, + UndelegateTask, + }, }; +#[async_trait::async_trait] pub trait TasksBuilder { // Creates tasks for commit stage - fn commit_tasks( + async fn commit_tasks( + commit_id_fetcher: &Arc, l1_message: &ScheduledL1Message, - commit_ids: &HashMap, ) -> TaskBuilderResult>>; // Create tasks for finalize stage - fn finalize_tasks( + async fn finalize_tasks( + rpc_client: &MagicblockRpcClient, l1_message: &ScheduledL1Message, - rent_reimbursement: &Pubkey, - ) -> Vec>; + ) -> TaskBuilderResult>>; } /// V1 Task builder /// V1: Actions are part of finalize tx pub struct TaskBuilderV1; + +impl TaskBuilderV1 { + async fn fetch_rent_reimbursements( + rpc_client: &MagicblockRpcClient, + pubkeys: &[Pubkey], + ) -> Result, FinalizedTasksBuildError> { + let pdas = pubkeys + .iter() + .map(|pubkey| { + dlp::pda::delegation_metadata_pda_from_delegated_account(pubkey) + }) + .collect::>(); + + let metadatas = rpc_client.get_multiple_accounts(&pdas, None).await?; + + let rent_reimbursments = pdas + .into_iter() + .enumerate() + .map(|(i, pda)| { + let account = if let Some(account) = metadatas.get(i) { + account + } else { + return Err( + FinalizedTasksBuildError::MetadataNotFoundError(pda), + ); + }; + + let account = account.as_ref().ok_or( + FinalizedTasksBuildError::MetadataNotFoundError(pda), + )?; + let metadata = + DelegationMetadata::try_from_bytes_with_discriminator( + &account.data, + ) + .map_err(|_| { + FinalizedTasksBuildError::InvalidAccountDataError(pda) + })?; + + Ok::<_, FinalizedTasksBuildError>(metadata.rent_payer) + }) + .collect::, _>>()?; + + Ok(rent_reimbursments) + } +} + +#[async_trait::async_trait] impl TasksBuilder for TaskBuilderV1 { /// Returns [`Task`]s for Commit stage - fn commit_tasks( + async fn commit_tasks( + commit_id_fetcher: &Arc, l1_message: &ScheduledL1Message, - commit_ids: &HashMap, ) -> TaskBuilderResult>> { let (accounts, allow_undelegation) = match &l1_message.l1_message { MagicL1Message::L1Actions(actions) => { @@ -46,6 +100,7 @@ impl TasksBuilder for TaskBuilderV1 { Box::new(ArgsTask::L1Action(task)) as Box }) .collect(); + return Ok(tasks); } MagicL1Message::Commit(t) => (t.get_committed_accounts(), false), @@ -54,29 +109,36 @@ impl TasksBuilder for TaskBuilderV1 { } }; + let committed_pubkeys = accounts + .iter() + .map(|account| account.pubkey) + .collect::>(); + let commit_ids = commit_id_fetcher + .fetch_commit_ids(&committed_pubkeys) + .await?; + let tasks = accounts .into_iter() .map(|account| { - if let Some(commit_id) = commit_ids.get(&account.pubkey) { - Ok(Box::new(ArgsTask::Commit(CommitTask { - commit_id: *commit_id + 1, - allow_undelegation, - committed_account: account.clone(), - })) as Box) - } else { - Err(Error::MissingCommitIdError(account.pubkey)) - } + let commit_id = commit_ids.get(&account.pubkey).expect("CommitIdFetcher provide commit ids for all listed pubkeys, or errors!"); + let task = ArgsTask::Commit(CommitTask { + commit_id: *commit_id + 1, + allow_undelegation, + committed_account: account.clone(), + }); + + Box::new(task) as Box }) - .collect::>()?; + .collect(); Ok(tasks) } /// Returns [`Task`]s for Finalize stage - fn finalize_tasks( + async fn finalize_tasks( + rpc_client: &MagicblockRpcClient, l1_message: &ScheduledL1Message, - rent_reimbursement: &Pubkey, - ) -> Vec> { + ) -> TaskBuilderResult>> { // Helper to create a finalize task fn finalize_task(account: &CommittedAccountV2) -> Box { Box::new(ArgsTask::Finalize(FinalizeTask { @@ -123,26 +185,29 @@ impl TasksBuilder for TaskBuilderV1 { } match &l1_message.l1_message { - MagicL1Message::L1Actions(_) => vec![], - MagicL1Message::Commit(commit) => process_commit(commit), + MagicL1Message::L1Actions(_) => Ok(vec![]), + MagicL1Message::Commit(commit) => Ok(process_commit(commit)), MagicL1Message::CommitAndUndelegate(t) => { let mut tasks = process_commit(&t.commit_action); + + // Get rent reimbursments for undelegated accounts let accounts = t.get_committed_accounts(); + let pubkeys = accounts + .iter() + .map(|account| account.pubkey) + .collect::>(); + let rent_reimbursments = + Self::fetch_rent_reimbursements(rpc_client, &pubkeys) + .await?; + tasks.extend(accounts.iter().zip(rent_reimbursments).map( + |(account, rent_reimbursement)| { + undelegate_task(account, &rent_reimbursement) + }, + )); match &t.undelegate_action { - UndelegateType::Standalone => { - tasks.extend( - accounts.iter().map(|a| { - undelegate_task(a, rent_reimbursement) - }), - ); - } + UndelegateType::Standalone => Ok(tasks), UndelegateType::WithL1Actions(actions) => { - tasks.extend( - accounts.iter().map(|a| { - undelegate_task(a, rent_reimbursement) - }), - ); tasks.extend(actions.iter().map(|action| { let task = L1ActionTask { context: Context::Undelegate, @@ -151,19 +216,33 @@ impl TasksBuilder for TaskBuilderV1 { Box::new(ArgsTask::L1Action(task)) as Box })); + + Ok(tasks) } } - - tasks } } } } +#[derive(thiserror::Error, Debug)] +pub enum FinalizedTasksBuildError { + #[error("Metadata not found for: {0}")] + MetadataNotFoundError(Pubkey), + #[error("InvalidAccountDataError for: {0}")] + InvalidAccountDataError(Pubkey), + #[error("MagicBlockRpcClientError: {0}")] + MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), +} + #[derive(thiserror::Error, Debug)] pub enum Error { - #[error("Missing commit id for pubkey: {0}")] - MissingCommitIdError(Pubkey), + #[error("CommitIdFetchError: {0}")] + CommitTasksBuildError( + #[from] crate::commit_scheduler::commit_id_tracker::Error, + ), + #[error("FinalizedTasksBuildError: {0}")] + FinalizedTasksBuildError(#[from] FinalizedTasksBuildError), } pub type TaskBuilderResult = Result; diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 746e13d08..d8827ab7f 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -97,9 +97,7 @@ impl DeliveryPreparator { }; // Persist as failed until rewritten - let update_status = CommitStatus::BufferAndChunkPartiallyInitialized( - preparation_info.commit_id, - ); + let update_status = CommitStatus::BufferAndChunkPartiallyInitialized; persist_status_update( persister, &preparation_info.pubkey, @@ -115,8 +113,7 @@ impl DeliveryPreparator { ) .await?; // Persist initialization success - let update_status = - CommitStatus::BufferAndChunkInitialized(preparation_info.commit_id); + let update_status = CommitStatus::BufferAndChunkInitialized; persist_status_update( persister, &preparation_info.pubkey, @@ -128,9 +125,7 @@ impl DeliveryPreparator { self.write_buffer_with_retries(authority, &preparation_info, 5) .await?; // Persist that buffer account initiated successfully - let update_status = CommitStatus::BufferAndChunkFullyInitialized( - preparation_info.commit_id, - ); + let update_status = CommitStatus::BufferAndChunkFullyInitialized; persist_status_update( persister, &preparation_info.pubkey, diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preperator/error.rs index 9a4ca5453..a63c91a2f 100644 --- a/magicblock-committor-service/src/transaction_preperator/error.rs +++ b/magicblock-committor-service/src/transaction_preperator/error.rs @@ -7,8 +7,8 @@ pub enum Error { // VersionError(PreparatorVersion), #[error("Failed to fit in single TX")] FailedToFitError, - #[error("Missing commit id for pubkey: {0}")] - MissingCommitIdError(Pubkey), + #[error("TaskBuilderError: {0}")] + TaskBuilderError(#[from] crate::tasks::task_builder::Error), #[error("DeliveryPreparationError: {0}")] DeliveryPreparationError( #[from] crate::transaction_preperator::delivery_preparator::Error, @@ -25,14 +25,4 @@ impl From for Error { } } -impl From for Error { - fn from(value: crate::tasks::task_builder::Error) -> Self { - match value { - crate::tasks::task_builder::Error::MissingCommitIdError(pubkey) => { - Self::MissingCommitIdError(pubkey) - } - } - } -} - pub type PreparatorResult = Result; diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 26a6d3236..d9a544a84 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, fmt::Formatter}; +use std::{collections::HashMap, fmt::Formatter, sync::Arc}; use async_trait::async_trait; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; @@ -10,6 +10,7 @@ use solana_sdk::{ }; use crate::{ + commit_scheduler::commit_id_tracker::CommitIdFetcher, persist::L1MessagesPersisterIface, tasks::{ task_builder::{TaskBuilderV1, TasksBuilder}, @@ -48,7 +49,6 @@ pub trait TransactionPreparator: Send + Sync + 'static { &self, authority: &Keypair, l1_message: &ScheduledL1Message, - commit_ids: &HashMap, l1_messages_persister: &Option

, ) -> PreparatorResult; @@ -58,7 +58,6 @@ pub trait TransactionPreparator: Send + Sync + 'static { async fn prepare_finalize_tx( &self, authority: &Keypair, - rent_reimbursement: &Pubkey, l1_message: &ScheduledL1Message, l1_messages_persister: &Option

, ) -> PreparatorResult; @@ -67,23 +66,32 @@ pub trait TransactionPreparator: Send + Sync + 'static { /// [`TransactionPreparatorV1`] first version of preparator /// It omits future commit_bundle/finalize_bundle logic /// It creates TXs using current per account commit/finalize -pub struct TransactionPreparatorV1 { +pub struct TransactionPreparatorV1 { + rpc_client: MagicblockRpcClient, + commit_id_fetcher: Arc, delivery_preparator: DeliveryPreparator, compute_budget_config: ComputeBudgetConfig, } -impl TransactionPreparatorV1 { +impl TransactionPreparatorV1 +where + C: CommitIdFetcher, +{ pub fn new( rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, + commit_id_fetcher: Arc, ) -> Self { let delivery_preparator = DeliveryPreparator::new( - rpc_client, + rpc_client.clone(), table_mania, compute_budget_config.clone(), ); + Self { + rpc_client, + commit_id_fetcher, delivery_preparator, compute_budget_config, } @@ -91,7 +99,10 @@ impl TransactionPreparatorV1 { } #[async_trait] -impl TransactionPreparator for TransactionPreparatorV1 { +impl TransactionPreparator for TransactionPreparatorV1 +where + C: CommitIdFetcher, +{ fn version(&self) -> PreparatorVersion { PreparatorVersion::V1 } @@ -102,11 +113,12 @@ impl TransactionPreparator for TransactionPreparatorV1 { &self, authority: &Keypair, l1_message: &ScheduledL1Message, - commit_ids: &HashMap, l1_messages_persister: &Option

, ) -> PreparatorResult { // create tasks - let tasks = TaskBuilderV1::commit_tasks(l1_message, commit_ids)?; + let tasks = + TaskBuilderV1::commit_tasks(&self.commit_id_fetcher, l1_message) + .await?; // optimize to fit tx size. aka Delivery Strategy let tx_strategy = TaskStrategist::build_strategy( tasks, @@ -140,13 +152,12 @@ impl TransactionPreparator for TransactionPreparatorV1 { async fn prepare_finalize_tx( &self, authority: &Keypair, - rent_reimbursement: &Pubkey, l1_message: &ScheduledL1Message, l1_messages_persister: &Option

, ) -> PreparatorResult { // create tasks let tasks = - TaskBuilderV1::finalize_tasks(l1_message, rent_reimbursement); + TaskBuilderV1::finalize_tasks(&self.rpc_client, l1_message).await?; // optimize to fit tx size. aka Delivery Strategy let tx_strategy = TaskStrategist::build_strategy( tasks, diff --git a/magicblock-committor-service/tests/common.rs b/magicblock-committor-service/tests/common.rs index e6754aa5c..4c6785f6e 100644 --- a/magicblock-committor-service/tests/common.rs +++ b/magicblock-committor-service/tests/common.rs @@ -1,8 +1,9 @@ +use std::collections::HashMap; use std::sync::{ atomic::{AtomicU64, Ordering}, Arc, }; - +use async_trait::async_trait; use magicblock_committor_service::{ tasks::tasks::CommitTask, transaction_preperator::{ @@ -26,6 +27,7 @@ use solana_sdk::{ signer::Signer, system_program, }; +use magicblock_committor_service::commit_scheduler::commit_id_tracker::{CommitIdFetcher, CommitIdTrackerResult}; // Helper function to create a test RPC client pub async fn create_test_client() -> MagicblockRpcClient { @@ -80,15 +82,30 @@ impl TestFixture { ) } - pub fn create_transaction_preparator(&self) -> TransactionPreparatorV1 { - TransactionPreparatorV1::new( + pub fn create_transaction_preparator(&self) -> TransactionPreparatorV1 { + TransactionPreparatorV1::::new( self.rpc_client.clone(), self.table_mania.clone(), self.compute_budget_config.clone(), + Arc::new(MockCommitIdFetcher) ) } } +pub struct MockCommitIdFetcher; + +#[async_trait::async_trait] +impl CommitIdFetcher for MockCommitIdFetcher { + async fn fetch_commit_ids(&self, pubkeys: &[Pubkey]) -> CommitIdTrackerResult> { + Ok(pubkeys.iter().map(|pubkey| (*pubkey, 0)).collect()) + } + + fn peek_commit_id(&self, pubkey: &Pubkey) -> Option { + None + } +} + + pub fn generate_random_bytes(length: usize) -> Vec { use rand::Rng; diff --git a/magicblock-committor-service/tests/test_transaction_preparator.rs b/magicblock-committor-service/tests/test_transaction_preparator.rs index 120e04f8d..bcbde2f0e 100644 --- a/magicblock-committor-service/tests/test_transaction_preparator.rs +++ b/magicblock-committor-service/tests/test_transaction_preparator.rs @@ -46,7 +46,6 @@ async fn test_prepare_commit_tx_with_single_account() { .prepare_commit_tx( &fixture.authority, &l1_message, - &commit_ids, &None::, ) .await; @@ -94,18 +93,11 @@ async fn test_prepare_commit_tx_with_multiple_accounts() { )), }; - let commit_ids = accounts - .iter() - .enumerate() - .map(|(i, acc)| (acc.pubkey, i as u64 + 1)) - .collect(); - // Test preparation let result = preparator .prepare_commit_tx( &fixture.authority, &l1_message, - &commit_ids, &None::, ) .await; @@ -164,7 +156,6 @@ async fn test_prepare_commit_tx_with_l1_actions() { .prepare_commit_tx( &fixture.authority, &l1_message, - &commit_ids, &None::, ) .await; @@ -172,6 +163,7 @@ async fn test_prepare_commit_tx_with_l1_actions() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } +#[ignore= "Implement MetadataFetcher for finaliztion"] #[tokio::test] async fn test_prepare_finalize_tx_with_undelegate() { let fixture = TestFixture::new().await; @@ -195,7 +187,6 @@ async fn test_prepare_finalize_tx_with_undelegate() { let result = preparator .prepare_finalize_tx( &fixture.authority, - &rent_reimbursement, &l1_message, &None::, ) @@ -241,7 +232,6 @@ async fn test_prepare_finalize_tx_with_undelegate_and_actions() { let result = preparator .prepare_finalize_tx( &fixture.authority, - &rent_reimbursement, &l1_message, &None::, ) @@ -287,7 +277,6 @@ async fn test_prepare_large_commit_tx_uses_buffers() { .prepare_commit_tx( &fixture.authority, &l1_message, - &commit_ids, &None::, ) .await; From 3b4312b05188d9a4256b906e5dcf8327c2a3c9dd Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 30 Jul 2025 22:04:53 +0900 Subject: [PATCH 144/199] fix: tests --- .../src/external_accounts_manager.rs | 4 +- .../commit_scheduler_worker.rs | 55 +------------------ .../src/message_executor/message_executor.rs | 28 ++++------ .../src/message_executor/mod.rs | 3 - .../src/persist/commit_persister.rs | 2 +- .../src/tasks/task_builder.rs | 18 +++++- .../src/tasks/task_strategist.rs | 2 +- .../src/tasks/utils.rs | 2 +- .../delivery_preparator.rs | 1 - .../src/transaction_preperator/error.rs | 1 - .../transaction_preparator.rs | 12 ++-- magicblock-committor-service/src/utils.rs | 3 - magicblock-committor-service/tests/common.rs | 27 ++++++--- .../tests/test_transaction_preparator.rs | 2 +- 14 files changed, 61 insertions(+), 99 deletions(-) diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 86576230b..36914d9ff 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -46,7 +46,7 @@ use solana_sdk::{ use crate::{ errors::{AccountsError, AccountsResult}, utils::get_epoch, - AccountCommittee, LifecycleMode, SendableCommitAccountsPayload, + AccountCommittee, LifecycleMode, }; #[derive(Debug)] @@ -397,7 +397,7 @@ where None }) }) - .filter(|(pubkey, _, prev_hash, acc)| { + .filter(|(_, _, prev_hash, acc)| { prev_hash.map_or(true, |hash| hash_account(acc) != hash) }) .map(|(pubkey, owner, _, acc)| AccountCommittee { diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs index 5a8c815fa..d42aa1dc0 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs @@ -1,5 +1,5 @@ use std::{ - collections::{HashMap, HashSet}, + collections::HashSet, sync::{Arc, Mutex}, }; @@ -17,7 +17,6 @@ use tokio::{ use crate::{ commit_scheduler::{ - commit_id_tracker::CommitIdFetcher, commit_scheduler_inner::{CommitSchedulerInner, POISONED_INNER_MSG}, db::DB, Error, @@ -27,9 +26,8 @@ use crate::{ message_executor_factory::MessageExecutorFactory, ExecutionOutput, MessageExecutor, }, - persist::{CommitStatus, L1MessagesPersisterIface}, + persist::L1MessagesPersisterIface, types::{ScheduledL1MessageWrapper, TriggerType}, - utils::persist_status_update_by_message_set, }; const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; @@ -234,54 +232,6 @@ where execution_permit: OwnedSemaphorePermit, result_sender: broadcast::Sender, ) { - // Prepare commit ids for execution - // let commit_ids = if let Some(pubkeys) = - // l1_message.scheduled_l1_message.get_committed_pubkeys() - // { - // let commit_ids = commit_id_tracker.fetch_commit_ids(&pubkeys).await; - // - // match commit_ids { - // Ok(value) => value, - // Err(err) => { - // // TODO(edwin): support contract and send result via receiver as well - // // At this point this is unrecoverable. - // // We just skip for now and pretend this message didn't exist - // error!("Failed to fetch commit nonces for message: {:?}, error: {:?}", l1_message, err); - // - // let message_id = l1_message.scheduled_l1_message.id; - // info!( - // "Message has to be committed manually: {}", - // message_id - // ); - // // Persist as Failed in DB - // persist_status_update_by_message_set( - // &persister, - // message_id, - // &pubkeys, - // CommitStatus::Failed, - // ); - // inner_scheduler - // .lock() - // .expect(POISONED_INNER_MSG) - // .complete(&l1_message.scheduled_l1_message); - // drop(execution_permit); - // return; - // } - // } - // } else { - // // Pure L1Action, no commit ids used - // HashMap::new() - // }; - // - // // Persist data - // commit_ids - // .iter() - // .for_each(|(pubkey, commit_id) | { - // if let Err(err) = persister.set_commit_id(l1_message.scheduled_l1_message.id, pubkey, *commit_id) { - // error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.scheduled_l1_message.id, pubkey, err); - // } - // }); - let result = executor .execute(l1_message.scheduled_l1_message.clone(), persister) .await @@ -356,6 +306,7 @@ where #[cfg(test)] mod tests { use std::{ + collections::HashMap, sync::{ atomic::{AtomicUsize, Ordering}, Arc, diff --git a/magicblock-committor-service/src/message_executor/message_executor.rs b/magicblock-committor-service/src/message_executor/message_executor.rs index fa8964c45..6e9cdbf67 100644 --- a/magicblock-committor-service/src/message_executor/message_executor.rs +++ b/magicblock-committor-service/src/message_executor/message_executor.rs @@ -1,5 +1,3 @@ -use std::{collections::HashMap, sync::Arc}; - use log::warn; use magicblock_program::{ magic_scheduled_l1_message::ScheduledL1Message, @@ -8,30 +6,21 @@ use magicblock_program::{ use magicblock_rpc_client::{ MagicBlockSendTransactionConfig, MagicblockRpcClient, }; -use magicblock_table_mania::TableMania; use solana_pubkey::Pubkey; use solana_sdk::{ message::VersionedMessage, signature::{Keypair, Signature}, - signer::Signer, transaction::VersionedTransaction, }; use crate::{ - commit_scheduler::commit_id_tracker::CommitIdFetcher, message_executor::{ error::{Error, InternalError, MessageExecutorResult}, ExecutionOutput, MessageExecutor, }, persist::{CommitStatus, CommitStatusSignatures, L1MessagesPersisterIface}, - transaction_preperator::transaction_preparator::{ - TransactionPreparator, TransactionPreparatorV1, - }, - utils::{ - persist_status_update, persist_status_update_by_message_set, - persist_status_update_set, - }, - ComputeBudgetConfig, + transaction_preperator::transaction_preparator::TransactionPreparator, + utils::persist_status_update_by_message_set, }; pub struct L1MessageExecutor { @@ -177,9 +166,16 @@ where let update_status = CommitStatus::PartOfTooLargeBundleToProcess; persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } - Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::TaskBuilderError(_))) => { - let update_status = CommitStatus::Failed; - persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); + Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::TaskBuilderError(err))) => { + match err { + crate::tasks::task_builder::Error::CommitTasksBuildError(_) => { + let update_status = CommitStatus::Failed; + persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); + } + crate::tasks::task_builder::Error::FinalizedTasksBuildError(_) => { + // TODO: commit signature to set this + } + } }, Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::DeliveryPreparationError(_))) => { // Persisted internally diff --git a/magicblock-committor-service/src/message_executor/mod.rs b/magicblock-committor-service/src/message_executor/mod.rs index acc2a15e6..9b1a0acc0 100644 --- a/magicblock-committor-service/src/message_executor/mod.rs +++ b/magicblock-committor-service/src/message_executor/mod.rs @@ -2,12 +2,9 @@ pub mod error; pub mod message_executor; pub(crate) mod message_executor_factory; -use std::collections::HashMap; - use async_trait::async_trait; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; pub use message_executor::L1MessageExecutor; -use solana_pubkey::Pubkey; use solana_sdk::signature::Signature; use crate::{ diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index ff8af540f..5139f2d85 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -381,7 +381,7 @@ mod tests { use tempfile::NamedTempFile; use super::*; - use crate::persist::{db, types, CommitStatusSignatures}; + use crate::persist::{types, CommitStatusSignatures}; fn create_test_persister() -> (L1MessagePersister, NamedTempFile) { let temp_file = NamedTempFile::new().unwrap(); diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 143b0b42c..2691d23b7 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, sync::Arc}; +use std::sync::Arc; use dlp::{args::Context, state::DelegationMetadata}; use log::error; @@ -11,6 +11,7 @@ use solana_pubkey::Pubkey; use crate::{ commit_scheduler::commit_id_tracker::CommitIdFetcher, + persist::L1MessagesPersisterIface, tasks::tasks::{ ArgsTask, CommitTask, FinalizeTask, L1ActionTask, L1Task, UndelegateTask, @@ -20,9 +21,10 @@ use crate::{ #[async_trait::async_trait] pub trait TasksBuilder { // Creates tasks for commit stage - async fn commit_tasks( + async fn commit_tasks( commit_id_fetcher: &Arc, l1_message: &ScheduledL1Message, + persister: &Option

, ) -> TaskBuilderResult>>; // Create tasks for finalize stage @@ -84,9 +86,10 @@ impl TaskBuilderV1 { #[async_trait::async_trait] impl TasksBuilder for TaskBuilderV1 { /// Returns [`Task`]s for Commit stage - async fn commit_tasks( + async fn commit_tasks( commit_id_fetcher: &Arc, l1_message: &ScheduledL1Message, + persister: &Option

, ) -> TaskBuilderResult>> { let (accounts, allow_undelegation) = match &l1_message.l1_message { MagicL1Message::L1Actions(actions) => { @@ -117,6 +120,15 @@ impl TasksBuilder for TaskBuilderV1 { .fetch_commit_ids(&committed_pubkeys) .await?; + // Persist commit ids for commitees + commit_ids + .iter() + .for_each(|(pubkey, commit_id) | { + if let Err(err) = persister.set_commit_id(l1_message.id, pubkey, *commit_id) { + error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.id, pubkey, err); + } + }); + let tasks = accounts .into_iter() .map(|account| { diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index c7437f73c..cd8ca194d 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -226,7 +226,7 @@ mod tests { CommittedAccountV2, L1Action, ProgramArgs, }; use solana_account::Account; - use solana_sdk::{signature::Keypair, system_program}; + use solana_sdk::system_program; use super::*; use crate::{ diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index 6900e1f8d..afbaa1829 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -109,7 +109,7 @@ impl TransactionUtils { Ok(()) } }) - .collect::>()?; + .collect::>()?; let message = match Message::try_compile( &authority.pubkey(), diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index d8827ab7f..7279d2df2 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -31,7 +31,6 @@ use crate::{ task_strategist::TransactionStrategy, tasks::{L1Task, TaskPreparationInfo}, }, - transactions::serialize_and_encode_base64, utils::persist_status_update, ComputeBudgetConfig, }; diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preperator/error.rs index a63c91a2f..8b56dd1a2 100644 --- a/magicblock-committor-service/src/transaction_preperator/error.rs +++ b/magicblock-committor-service/src/transaction_preperator/error.rs @@ -1,4 +1,3 @@ -use solana_pubkey::Pubkey; use thiserror::Error; #[derive(Error, Debug)] diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index d9a544a84..92a5b1680 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -1,10 +1,9 @@ -use std::{collections::HashMap, fmt::Formatter, sync::Arc}; +use std::{fmt::Formatter, sync::Arc}; use async_trait::async_trait; use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; -use solana_pubkey::Pubkey; use solana_sdk::{ message::VersionedMessage, signature::Keypair, signer::Signer, }; @@ -116,9 +115,12 @@ where l1_messages_persister: &Option

, ) -> PreparatorResult { // create tasks - let tasks = - TaskBuilderV1::commit_tasks(&self.commit_id_fetcher, l1_message) - .await?; + let tasks = TaskBuilderV1::commit_tasks( + &self.commit_id_fetcher, + l1_message, + l1_messages_persister, + ) + .await?; // optimize to fit tx size. aka Delivery Strategy let tx_strategy = TaskStrategist::build_strategy( tasks, diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index 19cd80906..b48938c47 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -1,9 +1,6 @@ use std::collections::HashMap; use log::error; -use magicblock_program::magic_scheduled_l1_message::{ - CommittedAccountV2, MagicL1Message, ScheduledL1Message, -}; use solana_pubkey::Pubkey; use crate::persist::{CommitStatus, L1MessagesPersisterIface}; diff --git a/magicblock-committor-service/tests/common.rs b/magicblock-committor-service/tests/common.rs index 4c6785f6e..2f1865ed1 100644 --- a/magicblock-committor-service/tests/common.rs +++ b/magicblock-committor-service/tests/common.rs @@ -1,10 +1,16 @@ -use std::collections::HashMap; -use std::sync::{ - atomic::{AtomicU64, Ordering}, - Arc, +use std::{ + collections::HashMap, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, + }, }; + use async_trait::async_trait; use magicblock_committor_service::{ + commit_scheduler::commit_id_tracker::{ + CommitIdFetcher, CommitIdTrackerResult, + }, tasks::tasks::CommitTask, transaction_preperator::{ delivery_preparator::DeliveryPreparator, @@ -27,7 +33,6 @@ use solana_sdk::{ signer::Signer, system_program, }; -use magicblock_committor_service::commit_scheduler::commit_id_tracker::{CommitIdFetcher, CommitIdTrackerResult}; // Helper function to create a test RPC client pub async fn create_test_client() -> MagicblockRpcClient { @@ -82,12 +87,14 @@ impl TestFixture { ) } - pub fn create_transaction_preparator(&self) -> TransactionPreparatorV1 { + pub fn create_transaction_preparator( + &self, + ) -> TransactionPreparatorV1 { TransactionPreparatorV1::::new( self.rpc_client.clone(), self.table_mania.clone(), self.compute_budget_config.clone(), - Arc::new(MockCommitIdFetcher) + Arc::new(MockCommitIdFetcher), ) } } @@ -96,7 +103,10 @@ pub struct MockCommitIdFetcher; #[async_trait::async_trait] impl CommitIdFetcher for MockCommitIdFetcher { - async fn fetch_commit_ids(&self, pubkeys: &[Pubkey]) -> CommitIdTrackerResult> { + async fn fetch_commit_ids( + &self, + pubkeys: &[Pubkey], + ) -> CommitIdTrackerResult> { Ok(pubkeys.iter().map(|pubkey| (*pubkey, 0)).collect()) } @@ -105,7 +115,6 @@ impl CommitIdFetcher for MockCommitIdFetcher { } } - pub fn generate_random_bytes(length: usize) -> Vec { use rand::Rng; diff --git a/magicblock-committor-service/tests/test_transaction_preparator.rs b/magicblock-committor-service/tests/test_transaction_preparator.rs index bcbde2f0e..dd8b27f40 100644 --- a/magicblock-committor-service/tests/test_transaction_preparator.rs +++ b/magicblock-committor-service/tests/test_transaction_preparator.rs @@ -163,7 +163,7 @@ async fn test_prepare_commit_tx_with_l1_actions() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } -#[ignore= "Implement MetadataFetcher for finaliztion"] +#[ignore = "Implement MetadataFetcher for finaliztion"] #[tokio::test] async fn test_prepare_finalize_tx_with_undelegate() { let fixture = TestFixture::new().await; From 322cbe6c60f5ca20628801fbbd712e42ab3163d8 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 30 Jul 2025 22:31:44 +0900 Subject: [PATCH 145/199] fixed versions of dlp & sdk --- Cargo.lock | 5 +- Cargo.toml | 3 +- test-integration/Cargo.lock | 104 ++++++++++++++++++++++++++---------- test-integration/Cargo.toml | 7 +-- 4 files changed, 84 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index abf5081bd..328855b1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3662,7 +3662,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3822,7 +3822,7 @@ dependencies = [ "log", "lru 0.16.0", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", @@ -3867,6 +3867,7 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c#374603f739a1b218b6b6f49dcd7f0ba60d662c7c" dependencies = [ "bincode", "borsh 1.5.5", diff --git a/Cargo.toml b/Cargo.toml index a42d9a170..be2c5ec65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,7 +108,8 @@ magicblock-committor-program = { path = "./magicblock-committor-program", featur magicblock-committor-service = { path = "./magicblock-committor-service" } magicblock-config = { path = "./magicblock-config" } magicblock-core = { path = "./magicblock-core" } -magicblock-delegation-program = { path = "../delegation-program" } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "374603f739a1b218b6b6f49dcd7f0ba60d662c7c", features = ["no-entrypoint"] } +#magicblock-delegation-program = { path = "../delegation-program" } magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" } magicblock-ledger = { path = "./magicblock-ledger" } magicblock-metrics = { path = "./magicblock-metrics" } diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index beff5f8ae..31b26d174 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1747,19 +1747,21 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk" version = "0.2.6" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e7daea58d672a22f1d221ef7c1607b14f900f029#e7daea58d672a22f1d221ef7c1607b14f900f029" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk-attribute-commit", "ephemeral-rollups-sdk-attribute-delegate", "ephemeral-rollups-sdk-attribute-ephemeral", - "magicblock-delegation-program 1.0.0", - "magicblock-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-program 0.1.2 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd)", "solana-program", ] [[package]] name = "ephemeral-rollups-sdk-attribute-commit" version = "0.2.6" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e7daea58d672a22f1d221ef7c1607b14f900f029#e7daea58d672a22f1d221ef7c1607b14f900f029" dependencies = [ "quote", "syn 1.0.109", @@ -1768,6 +1770,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-delegate" version = "0.2.6" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e7daea58d672a22f1d221ef7c1607b14f900f029#e7daea58d672a22f1d221ef7c1607b14f900f029" dependencies = [ "proc-macro2", "quote", @@ -1777,6 +1780,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-ephemeral" version = "0.2.6" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e7daea58d672a22f1d221ef7c1607b14f900f029#e7daea58d672a22f1d221ef7c1607b14f900f029" dependencies = [ "proc-macro2", "quote", @@ -2946,8 +2950,8 @@ dependencies = [ "borsh 1.5.7", "log", "magicblock-config", - "magicblock-core", - "magicblock-delegation-program 1.0.0", + "magicblock-core 0.1.2", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", "rayon", "serde", "solana-pubkey", @@ -3497,8 +3501,8 @@ dependencies = [ "magicblock-account-updates", "magicblock-accounts-api", "magicblock-committor-service", - "magicblock-core", - "magicblock-metrics", + "magicblock-core 0.1.2", + "magicblock-metrics 0.1.2", "magicblock-mutator", "solana-sdk", "thiserror 1.0.69", @@ -3527,7 +3531,7 @@ dependencies = [ "conjunto-transwise", "futures-util", "log", - "magicblock-metrics", + "magicblock-metrics 0.1.2", "solana-sdk", "thiserror 1.0.69", "tokio", @@ -3542,7 +3546,7 @@ dependencies = [ "conjunto-transwise", "futures-util", "log", - "magicblock-metrics", + "magicblock-metrics 0.1.2", "solana-account-decoder", "solana-pubsub-client", "solana-rpc-client-api", @@ -3568,12 +3572,12 @@ dependencies = [ "magicblock-accounts-api", "magicblock-bank", "magicblock-committor-service", - "magicblock-core", - "magicblock-delegation-program 1.0.0", - "magicblock-metrics", + "magicblock-core 0.1.2", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-metrics 0.1.2", "magicblock-mutator", "magicblock-processor", - "magicblock-program", + "magicblock-program 0.1.2", "magicblock-transaction-status", "solana-rpc-client", "solana-rpc-client-api", @@ -3631,13 +3635,13 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-config", - "magicblock-core", + "magicblock-core 0.1.2", "magicblock-geyser-plugin", "magicblock-ledger", - "magicblock-metrics", + "magicblock-metrics 0.1.2", "magicblock-perf-service", "magicblock-processor", - "magicblock-program", + "magicblock-program 0.1.2", "magicblock-pubsub", "magicblock-rpc", "magicblock-transaction-status", @@ -3661,8 +3665,8 @@ dependencies = [ "bincode", "log", "magicblock-accounts-db", - "magicblock-core", - "magicblock-program", + "magicblock-core 0.1.2", + "magicblock-program 0.1.2", "rand 0.8.5", "serde", "solana-accounts-db", @@ -3715,8 +3719,8 @@ dependencies = [ "log", "lru 0.16.0", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0", - "magicblock-program", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-program 0.1.2", "magicblock-rpc-client", "magicblock-table-mania", "rusqlite", @@ -3755,9 +3759,18 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "magicblock-core" +version = "0.1.2" +source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd#3b4312b05188d9a4256b906e5dcf8327c2a3c9dd" +dependencies = [ + "solana-sdk", +] + [[package]] name = "magicblock-delegation-program" version = "1.0.0" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c#374603f739a1b218b6b6f49dcd7f0ba60d662c7c" dependencies = [ "bincode", "borsh 1.5.7", @@ -3826,7 +3839,7 @@ dependencies = [ "log", "magicblock-accounts-db", "magicblock-bank", - "magicblock-core", + "magicblock-core 0.1.2", "num-format", "num_cpus", "prost", @@ -3859,13 +3872,28 @@ dependencies = [ "tokio-util 0.7.13", ] +[[package]] +name = "magicblock-metrics" +version = "0.1.2" +source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd#3b4312b05188d9a4256b906e5dcf8327c2a3c9dd" +dependencies = [ + "http-body-util", + "hyper 1.6.0", + "hyper-util", + "lazy_static", + "log", + "prometheus", + "tokio", + "tokio-util 0.7.13", +] + [[package]] name = "magicblock-mutator" version = "0.1.2" dependencies = [ "bincode", "log", - "magicblock-program", + "magicblock-program 0.1.2", "solana-rpc-client", "solana-rpc-client-api", "solana-sdk", @@ -3908,8 +3936,26 @@ version = "0.1.2" dependencies = [ "bincode", "lazy_static", - "magicblock-core", - "magicblock-metrics", + "magicblock-core 0.1.2", + "magicblock-metrics 0.1.2", + "num-derive", + "num-traits", + "serde", + "solana-log-collector", + "solana-program-runtime", + "solana-sdk", + "thiserror 1.0.69", +] + +[[package]] +name = "magicblock-program" +version = "0.1.2" +source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd#3b4312b05188d9a4256b906e5dcf8327c2a3c9dd" +dependencies = [ + "bincode", + "lazy_static", + "magicblock-core 0.1.2 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd)", + "magicblock-metrics 0.1.2 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd)", "num-derive", "num-traits", "serde", @@ -3956,7 +4002,7 @@ dependencies = [ "magicblock-accounts", "magicblock-bank", "magicblock-ledger", - "magicblock-metrics", + "magicblock-metrics 0.1.2", "magicblock-processor", "magicblock-tokens", "magicblock-transaction-status", @@ -4922,7 +4968,7 @@ version = "0.0.0" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", "solana-program", ] @@ -5742,7 +5788,7 @@ dependencies = [ "anyhow", "borsh 1.5.7", "integration-test-tools", - "magicblock-core", + "magicblock-core 0.1.2", "program-schedulecommit", "solana-program", "solana-rpc-client", @@ -5757,7 +5803,7 @@ dependencies = [ "log", "magicblock-committor-program", "magicblock-committor-service", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", "magicblock-rpc-client", "program-flexi-counter", "solana-account", @@ -5776,7 +5822,7 @@ dependencies = [ "ephemeral-rollups-sdk", "integration-test-tools", "log", - "magicblock-core", + "magicblock-core 0.1.2", "program-schedulecommit", "schedulecommit-client", "solana-program", @@ -5791,7 +5837,7 @@ name = "schedulecommit-test-security" version = "0.0.0" dependencies = [ "integration-test-tools", - "magicblock-core", + "magicblock-core 0.1.2", "program-schedulecommit", "program-schedulecommit-security", "schedulecommit-client", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index cadd38f58..50bba6922 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -27,8 +27,8 @@ edition = "2021" anyhow = "1.0.86" borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" -ephemeral-rollups-sdk = { path = "../../ephemeral-rollups-sdk/rust/sdk" } -#ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "c1fcb91" } +#ephemeral-rollups-sdk = { path = "../../ephemeral-rollups-sdk/rust/sdk" } +ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "e7daea58d672a22f1d221ef7c1607b14f900f029" } integration-test-tools = { path = "test-tools" } log = "0.4.20" magicblock-api = { path = "../magicblock-api" } @@ -39,7 +39,8 @@ magicblock-core = { path = "../magicblock-core" } magicblock-committor-program = { path = "../magicblock-committor-program", features = [ "no-entrypoint", ] } -magicblock-delegation-program = { path = "../../delegation-program" } +#magicblock-delegation-program = { path = "../../delegation-program" } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "374603f739a1b218b6b6f49dcd7f0ba60d662c7c", features = ["no-entrypoint"] } magicblock-committor-service = { path = "../magicblock-committor-service" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } magicblock-table-mania = { path = "../magicblock-table-mania" } From 972cb0c42650ef80e7fb464eac6977845fca0e89 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 30 Jul 2025 22:41:58 +0900 Subject: [PATCH 146/199] refactor: file cleanup --- .../src/bundle_strategy.rs | 205 ------ magicblock-committor-service/src/bundles.rs | 275 -------- .../src/commit_strategist/commit_strategy.rs | 633 ------------------ .../src/commit_strategist/mod.rs | 2 - .../src/commit_strategist/report_builder.rs | 6 - magicblock-committor-service/src/finalize.rs | 66 -- magicblock-committor-service/src/lib.rs | 5 - .../src/tasks/tasks.rs | 1 - .../src/transactions.rs | 368 ++++------ .../src/undelegate.rs | 103 --- 10 files changed, 125 insertions(+), 1539 deletions(-) delete mode 100644 magicblock-committor-service/src/bundle_strategy.rs delete mode 100644 magicblock-committor-service/src/bundles.rs delete mode 100644 magicblock-committor-service/src/commit_strategist/commit_strategy.rs delete mode 100644 magicblock-committor-service/src/commit_strategist/mod.rs delete mode 100644 magicblock-committor-service/src/commit_strategist/report_builder.rs delete mode 100644 magicblock-committor-service/src/finalize.rs delete mode 100644 magicblock-committor-service/src/undelegate.rs diff --git a/magicblock-committor-service/src/bundle_strategy.rs b/magicblock-committor-service/src/bundle_strategy.rs deleted file mode 100644 index 0f7a0f3bb..000000000 --- a/magicblock-committor-service/src/bundle_strategy.rs +++ /dev/null @@ -1,205 +0,0 @@ -use std::collections::HashMap; - -use log::*; - -use crate::CommitInfo; - -/// Tries to merge bundles into chunks to leverage the max amount of commits -/// we can have in a single transaction. -pub(crate) fn efficient_bundle_chunks( - mut bundles: HashMap>, - max_per_chunk: usize, -) -> Vec> { - let lens = bundles - .iter() - .map(|(id, commits)| Len { - id: *id, - len: commits.len(), - }) - .collect::>(); - - let chunked_ids = efficient_merge_strategy(lens, max_per_chunk); - - let mut chunked_bundles = Vec::new(); - for chunk in chunked_ids { - let mut bundle_chunk = Vec::::new(); - for id in chunk { - if let Some(bundles) = bundles.remove(&id) { - bundle_chunk.extend(bundles); - } else { - debug_assert!(false, "BUG: bundle not found for id {}", id); - continue; - } - } - chunked_bundles.push(bundle_chunk); - } - - debug_assert!(bundles.is_empty()); - - chunked_bundles -} - -#[derive(PartialEq, Eq, Debug, Clone, Copy)] -struct Len { - id: u64, - len: usize, -} - -/// Returns the most efficient merge strategy for the given lens and max size. -/// WARN: Requires that no len is larger than max_size, otherwise this method will -/// get stuck -fn efficient_merge_strategy( - mut lens: Vec, - max_size: usize, -) -> Vec> { - // NOTE: crash in dev, use escape hatch in release - debug_assert!(lens.iter().all(|len| len.len <= max_size)); - - for len in lens.iter() { - if len.len > max_size { - // NOTE: This is an escape hatch, if we have a len that is larger - // than the max size since we can't merge it. - // This is caused by a programmer error in the calling code. - // It will most likely cause an issue higher in the call stack - // but handling it this way is better than crashing or getting - // stuck. - error!( - "BUG: len {} is too large for the max_size {}", - len.len, max_size - ); - return lens.iter().map(|len| vec![len.id]).collect(); - } - } - - lens.sort_by_key(|len| len.len); - - let mut chunks: Vec> = Vec::new(); - let Some(next_len) = lens.pop() else { - return vec![]; - }; - let mut current_chunk = vec![next_len.id]; - let mut current_size = next_len.len; - 'outer: loop { - let mut remaining_lens = vec![]; - for len in lens.iter().rev() { - if current_size + len.len <= max_size { - current_chunk.push(len.id); - current_size += len.len; - } else { - remaining_lens.push(*len); - continue; - } - } - - lens = lens - .drain(..) - .filter(|len| remaining_lens.contains(len)) - .collect(); - - if lens.is_empty() { - chunks.push(current_chunk); - break; - } - - if lens - .first() - .map(|len| current_size < len.len) - .unwrap_or(false) - { - continue 'outer; - } - - // If we have no more lens to add to the current chunk create a new one - chunks.push(current_chunk); - - // No more lens to process, we are done with the entire process - let Some(next_len) = lens.pop() else { - break 'outer; - }; - current_chunk = vec![next_len.id]; - current_size = next_len.len; - } - - chunks -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_efficient_merge_strategy() { - let lens = vec![ - Len { id: 1, len: 1 }, - Len { id: 2, len: 2 }, - Len { id: 3, len: 3 }, - Len { id: 4, len: 4 }, - Len { id: 5, len: 5 }, - Len { id: 6, len: 6 }, - Len { id: 7, len: 7 }, - Len { id: 8, len: 8 }, - Len { id: 9, len: 9 }, - Len { id: 10, len: 10 }, - ]; - - let res = efficient_merge_strategy(lens.clone(), 10); - assert_eq!( - res, - vec![ - vec![10], - vec![9, 1], - vec![8, 2], - vec![7, 3], - vec![6, 4], - vec![5] - ] - ); - - let res = efficient_merge_strategy(lens.clone(), 20); - assert_eq!(res, vec![vec![10, 9, 1], vec![8, 7, 5], vec![6, 4, 3, 2]]); - - let lens = vec![ - Len { id: 1, len: 1 }, - Len { id: 2, len: 2 }, - Len { id: 3, len: 3 }, - Len { id: 4, len: 4 }, - Len { id: 5, len: 5 }, - Len { id: 6, len: 6 }, - Len { id: 7, len: 7 }, - Len { id: 8, len: 8 }, - ]; - let res = efficient_merge_strategy(lens.clone(), 8); - assert_eq!( - res, - vec![vec![8], vec![7, 1], vec![6, 2], vec![5, 3], vec![4]] - ); - let lens = vec![ - Len { id: 1, len: 1 }, - Len { id: 2, len: 2 }, - Len { id: 3, len: 2 }, - Len { id: 4, len: 2 }, - Len { id: 5, len: 2 }, - Len { id: 6, len: 6 }, - Len { id: 7, len: 6 }, - Len { id: 8, len: 8 }, - ]; - let res = efficient_merge_strategy(lens.clone(), 8); - assert_eq!(res, vec![vec![8], vec![7, 5], vec![6, 4], vec![3, 2, 1]]); - - let lens = vec![ - Len { id: 1, len: 1 }, - Len { id: 3, len: 2 }, - Len { id: 4, len: 2 }, - Len { id: 5, len: 2 }, - Len { id: 6, len: 6 }, - Len { id: 7, len: 6 }, - Len { id: 8, len: 8 }, - Len { id: 9, len: 8 }, - ]; - let res = efficient_merge_strategy(lens.clone(), 8); - assert_eq!( - res, - vec![vec![9], vec![8], vec![7, 5], vec![6, 4], vec![3, 1]] - ); - } -} diff --git a/magicblock-committor-service/src/bundles.rs b/magicblock-committor-service/src/bundles.rs deleted file mode 100644 index ee778658e..000000000 --- a/magicblock-committor-service/src/bundles.rs +++ /dev/null @@ -1,275 +0,0 @@ -use std::collections::HashMap; - -use crate::{bundle_strategy::efficient_bundle_chunks, CommitInfo}; - -#[derive(Debug, Default)] -pub struct BundleChunksResult { - /// The valid chunks - pub chunks: Vec>, - /// Commit infos that were not included in any chunk since not all infos in - /// a bundle could fit into a single chunk. - /// key: bundle_id - /// value: commit infos - pub unchunked: HashMap>, -} - -/// Creates chunks that respect the following requirements: -/// 1. A chunk cannot be larger than [max_per_chunk]. -/// 2. All commit infos with the same bundle_id must be in the same chunk. -pub(crate) fn bundle_chunks( - mut commit_infos: Vec, - max_per_chunk: usize, -) -> BundleChunksResult { - if commit_infos.is_empty() { - return BundleChunksResult::default(); - } - - // Group commit infos by bundle_id - let mut bundles: HashMap> = HashMap::new(); - let mut not_bundled: Vec = Vec::new(); - for commit_info in commit_infos.drain(..) { - bundles - .entry(commit_info.bundle_id()) - .or_default() - .push(commit_info); - } - - // Remove bundles that are too large to fit into a single chunk - let (bundles, unbundled) = bundles.into_iter().fold( - (HashMap::new(), HashMap::new()), - |(mut bundles, mut unbundled), (key, bundle)| { - if bundle.len() > max_per_chunk { - unbundled.insert(key, bundle); - } else { - bundles.insert(key, bundle); - } - (bundles, unbundled) - }, - ); - - // Merge small bundles - let mut chunks = efficient_bundle_chunks(bundles, max_per_chunk); - - // Add any commits that were not bundled to any of the bundles that still - // have some room - for chunk in chunks.iter_mut() { - let remaining_space = max_per_chunk - chunk.len(); - if remaining_space > 0 { - let range_end = remaining_space.min(not_bundled.len()); - chunk.extend(&mut not_bundled.drain(..range_end)); - } - } - - // If we still have unbundled commits then add chunks for those - while !not_bundled.is_empty() { - let range_end = max_per_chunk.min(not_bundled.len()); - chunks.push(not_bundled.drain(..range_end).collect()); - } - - BundleChunksResult { - chunks, - unchunked: unbundled, - } -} - -/// Use this for operations on commit infos that don't have to run atomically for a bundle. -/// As an example closing buffers needed for the commit can be done without respecting -/// bundles. -pub(crate) fn bundle_chunks_ignoring_bundle_id( - commit_infos: &[CommitInfo], - max_per_chunk: usize, -) -> BundleChunksResult { - if commit_infos.is_empty() { - return BundleChunksResult::default(); - } - let chunks = commit_infos - .chunks(max_per_chunk) - .map(|chunk| chunk.to_vec()) - .collect::>(); - - BundleChunksResult { - chunks, - unchunked: HashMap::new(), - } -} - -#[cfg(test)] -mod test { - use std::collections::HashSet; - - use solana_sdk::{hash::Hash, pubkey::Pubkey}; - - use super::*; - - fn commit_info(bundle_id: u64) -> crate::CommitInfo { - CommitInfo::BufferedDataAccount { - pubkey: Pubkey::new_unique(), - delegated_account_owner: Pubkey::new_unique(), - slot: 0, - ephemeral_blockhash: Hash::new_unique(), - undelegate: false, - buffer_pda: Pubkey::new_unique(), - chunks_pda: Pubkey::new_unique(), - commit_state: Pubkey::new_unique(), - lamports: 0, - bundle_id, - finalize: false, - } - } - - macro_rules! chunk_and_verify { - ($commit_infos:ident, $max_per_chunk:expr) => {{ - let res = bundle_chunks($commit_infos.clone(), $max_per_chunk); - - // 1. All commit infos are accounted for - let bundled_commit_infos = - res.chunks.iter().flatten().cloned().collect::>(); - let unbundled_commit_infos = res - .unchunked - .values() - .flatten() - .cloned() - .collect::>(); - - for commit_info in $commit_infos { - assert!( - bundled_commit_infos.contains(&commit_info), - "{:#?} was not bundled in {:#?}", - commit_info, - bundled_commit_infos - ); - } - assert!( - unbundled_commit_infos.is_empty(), - "Unbundled: {:#?}", - unbundled_commit_infos - ); - - // 2. Chunk size is within limits - for chunk in res.chunks.iter() { - assert!(chunk.len() <= $max_per_chunk); - } - - // 3. All commit infos with the same bundle_id are in the same chunk - // If a chunk has a bundle id then no other chunk should have it - let bundle_ids = bundled_commit_infos - .iter() - .map(|commit_info| commit_info.bundle_id()) - .collect::>(); - for id in bundle_ids { - let mut count = 0; - for chunk in res.chunks.iter() { - let mut in_chunk = false; - for commit_info in chunk { - if commit_info.bundle_id() == id { - in_chunk = true - } - } - if in_chunk { - count += 1; - } - } - assert_eq!( - count, 1, - "Bundle id {} is in {} chunks. {:#?}", - id, count, res.chunks - ); - } - res - }}; - } - - const MAX_PER_CHUNK: usize = 3; - - #[test] - fn test_empty_bundle() { - let res = bundle_chunks(Vec::new(), MAX_PER_CHUNK); - assert!(res.chunks.is_empty()); - assert!(res.unchunked.is_empty()); - } - - #[test] - fn test_single_bundle_single_commit() { - let commit_infos = vec![commit_info(0)]; - chunk_and_verify!(commit_infos, MAX_PER_CHUNK); - } - - #[test] - fn test_single_bundle() { - let commit_infos = vec![commit_info(0), commit_info(0), commit_info(0)]; - chunk_and_verify!(commit_infos, MAX_PER_CHUNK); - } - - #[test] - fn test_single_bundle_too_large() { - let commit_infos = vec![ - commit_info(0), - commit_info(0), - commit_info(0), - commit_info(0), - ]; - let res = bundle_chunks(commit_infos.clone(), MAX_PER_CHUNK); - assert!(res.chunks.is_empty()); - assert_eq!(res.unchunked.len(), 1); - assert_eq!(res.unchunked.get(&0).unwrap(), &commit_infos); - } - - #[test] - fn test_multiple_bundles() { - let commit_infos = vec![ - // Bundle 0 - commit_info(0), - commit_info(0), - // Bundle 1 - commit_info(1), - commit_info(1), - commit_info(1), - // Bundle 2 - commit_info(2), - commit_info(2), - ]; - chunk_and_verify!(commit_infos, MAX_PER_CHUNK); - } - - #[test] - fn test_multiple_bundles_with_unbundled() { - let commit_infos = vec![ - // Bundle 0 - commit_info(0), - commit_info(0), - // Bundle 1 - commit_info(1), - commit_info(5), - commit_info(1), - commit_info(6), - commit_info(1), - // Bundle 2 - commit_info(2), - commit_info(2), - commit_info(7), - ]; - chunk_and_verify!(commit_infos, MAX_PER_CHUNK); - } - - #[test] - fn test_multiple_bundles_efficiency() { - let commit_infos = vec![ - // Bundle 0 - commit_info(0), - commit_info(0), - commit_info(0), - // Bundle 1 - commit_info(1), - commit_info(1), - commit_info(1), - // Bundle 2 - commit_info(2), - commit_info(2), - // Bundle 3 - commit_info(3), - commit_info(3), - ]; - let res = chunk_and_verify!(commit_infos, 5); - assert_eq!(res.chunks.len(), 2); - } -} diff --git a/magicblock-committor-service/src/commit_strategist/commit_strategy.rs b/magicblock-committor-service/src/commit_strategist/commit_strategy.rs deleted file mode 100644 index 28e64257e..000000000 --- a/magicblock-committor-service/src/commit_strategist/commit_strategy.rs +++ /dev/null @@ -1,633 +0,0 @@ -use std::collections::HashSet; - -use magicblock_committor_program::{ChangedBundle, Changeset}; -use solana_pubkey::Pubkey; - -use crate::{ - error::{CommittorServiceError, CommittorServiceResult}, - transactions::{ - commit_tx_report, CommitTxReport, MAX_ENCODED_TRANSACTION_SIZE, - }, -}; - -/// These are the commit strategies we can use to commit a changeset in order -/// of preference. We use lookup tables only as last resort since they are -/// slow to prepare. -#[derive(Debug)] -pub enum CommitBundleStrategy { - ArgsIncludeFinalize(ChangedBundle), - Args(ChangedBundle), - FromBuffer(ChangedBundle), - ArgsIncludeFinalizeWithLookupTable(ChangedBundle), - ArgsWithLookupTable(ChangedBundle), - FromBufferWithLookupTable(ChangedBundle), -} - -impl TryFrom<(ChangedBundle, bool)> for CommitBundleStrategy { - type Error = CommittorServiceError; - - /// Try to find the fastest/efficient commit strategy for the given bundle. - /// Order of preference: - /// 1. [CommitBundleStrategy::ArgsIncludeFinalize] - /// 2. [CommitBundleStrategy::Args] - /// 3. [CommitBundleStrategy::FromBuffer] - /// 4. [CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable] - /// 5. [CommitBundleStrategy::ArgsWithLookupTable] - /// 6. [CommitBundleStrategy::FromBufferWithLookupTable] - fn try_from( - (bundle, finalize): (ChangedBundle, bool), - ) -> Result { - let CommitTxReport { - size_args_including_finalize, - size_args, - fits_buffer, - size_args_with_lookup_including_finalize, - size_args_with_lookup, - fits_buffer_using_lookup, - } = commit_tx_report(&bundle, finalize)?; - // Try to combine process and finalize if finalize is true - if let Some(size_including_finalize) = size_args_including_finalize { - if size_including_finalize < MAX_ENCODED_TRANSACTION_SIZE { - return Ok(CommitBundleStrategy::ArgsIncludeFinalize(bundle)); - } - } - // Next still using args but with separate finalize if needed - if size_args < MAX_ENCODED_TRANSACTION_SIZE { - return Ok(CommitBundleStrategy::Args(bundle)); - } - - // Last option to avoid lookup tables - if fits_buffer { - return Ok(CommitBundleStrategy::FromBuffer(bundle)); - } - - // All the below use lookup tables and will be a lot slower - - // Combining finalize and process - if let Some(size_with_lookup_including_finalize) = - size_args_with_lookup_including_finalize - { - if size_with_lookup_including_finalize - < MAX_ENCODED_TRANSACTION_SIZE - { - return Ok( - CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable( - bundle, - ), - ); - } - } - // Using lookup tables but separate finalize - if let Some(size_with_lookup) = size_args_with_lookup { - if size_with_lookup < MAX_ENCODED_TRANSACTION_SIZE { - return Ok(CommitBundleStrategy::ArgsWithLookupTable(bundle)); - } - } - - // Worst case try to use a buffer with lookup tables - if fits_buffer_using_lookup { - return Ok(CommitBundleStrategy::FromBufferWithLookupTable(bundle)); - } - - // If none of the strategies work then we need to error - let bundle_id = bundle - .first() - .map(|(_, acc)| acc.bundle_id()) - .unwrap_or_default(); - Err(CommittorServiceError::CouldNotFindCommitStrategyForBundle( - bundle_id, - )) - } -} - -#[derive(Debug)] -pub struct SplitChangesets { - /// This changeset can be committed in one processing step, passing account data as args - pub args_changeset: Changeset, - /// This changeset can be committed in one processing step, passing account data as args - /// and the finalize instruction fits into the same transaction - pub args_including_finalize_changeset: Changeset, - /// This changeset can be committed in one processing step, passing account data as args - /// but needs to use lookup tables for the accounts - pub args_with_lookup_changeset: Changeset, - /// This changeset can be committed in one processing step, passing account data as args - /// and the finalize instruction fits into the same transaction. - /// It needs to use lookup tables for the accounts. - pub args_including_finalize_with_lookup_changeset: Changeset, - /// This changeset needs to be committed in two steps: - /// 1. Prepare the buffer account - /// 2. Process the buffer account - pub from_buffer_changeset: Changeset, - /// This changeset needs to be committed in three steps: - /// 1. Prepare the buffer account - /// 2. Prepare lookup table - /// 3. Process the buffer account - pub from_buffer_with_lookup_changeset: Changeset, -} - -pub fn split_changesets_by_commit_strategy( - changeset: Changeset, - finalize: bool, -) -> CommittorServiceResult { - fn add_to_changeset( - changeset: &mut Changeset, - accounts_to_undelegate: &HashSet, - bundle: ChangedBundle, - ) { - for (pubkey, acc) in bundle { - changeset.add(pubkey, acc); - if accounts_to_undelegate.contains(&pubkey) { - changeset.accounts_to_undelegate.insert(pubkey); - } - } - } - - let mut args_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - let mut args_including_finalize_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - let mut args_with_lookup_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - let mut args_including_finalize_with_lookup_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - let mut from_buffer_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - let mut from_buffer_with_lookup_changeset = Changeset { - slot: changeset.slot, - ..Default::default() - }; - - let accounts_to_undelegate = changeset.accounts_to_undelegate.clone(); - let changeset_bundles = changeset.into_small_changeset_bundles(); - for bundle in changeset_bundles.bundles.into_iter() { - let commit_strategy = - CommitBundleStrategy::try_from((bundle, finalize))?; - match commit_strategy { - CommitBundleStrategy::Args(bundle) => { - add_to_changeset( - &mut args_changeset, - &accounts_to_undelegate, - bundle, - ); - } - CommitBundleStrategy::ArgsIncludeFinalize(bundle) => { - add_to_changeset( - &mut args_including_finalize_changeset, - &accounts_to_undelegate, - bundle, - ); - } - CommitBundleStrategy::ArgsWithLookupTable(bundle) => { - add_to_changeset( - &mut args_with_lookup_changeset, - &accounts_to_undelegate, - bundle, - ); - } - CommitBundleStrategy::ArgsIncludeFinalizeWithLookupTable( - bundle, - ) => { - add_to_changeset( - &mut args_including_finalize_with_lookup_changeset, - &accounts_to_undelegate, - bundle, - ); - } - CommitBundleStrategy::FromBuffer(bundle) => { - add_to_changeset( - &mut from_buffer_changeset, - &accounts_to_undelegate, - bundle, - ); - } - CommitBundleStrategy::FromBufferWithLookupTable(bundle) => { - add_to_changeset( - &mut from_buffer_with_lookup_changeset, - &accounts_to_undelegate, - bundle, - ); - } - } - } - - Ok(SplitChangesets { - args_changeset, - args_including_finalize_changeset, - args_with_lookup_changeset, - args_including_finalize_with_lookup_changeset, - from_buffer_changeset, - from_buffer_with_lookup_changeset, - }) -} - -#[cfg(test)] -mod test { - use log::*; - use magicblock_committor_program::ChangedAccount; - use solana_sdk::pubkey::Pubkey; - - use super::*; - - fn init_logger() { - let _ = env_logger::builder() - .format_timestamp(None) - .is_test(true) - .try_init(); - } - - fn add_changed_account( - changeset: &mut Changeset, - size: usize, - bundle_id: u64, - undelegate: bool, - ) -> Pubkey { - let pubkey = Pubkey::new_unique(); - changeset.add( - pubkey, - ChangedAccount::Full { - data: vec![1; size], - owner: Pubkey::new_unique(), - lamports: 0, - bundle_id, - }, - ); - if undelegate { - changeset.accounts_to_undelegate.insert(pubkey); - } - pubkey - } - - macro_rules! debug_counts { - ($label:expr, $changeset:ident, $split_changesets:ident) => { - debug!( - "{}: ({}) {{ -args_changeset: {} -args_including_finalize_changeset: {} -args_with_lookup_changeset: {} -args_including_finalize_with_lookup_changeset: {} -from_buffer_changeset: {} -from_buffer_with_lookup_changeset: {} -}}", - $label, - $changeset.accounts.len(), - $split_changesets.args_changeset.len(), - $split_changesets.args_including_finalize_changeset.len(), - $split_changesets.args_with_lookup_changeset.len(), - $split_changesets - .args_including_finalize_with_lookup_changeset - .len(), - $split_changesets.from_buffer_changeset.len(), - $split_changesets.from_buffer_with_lookup_changeset.len() - ); - }; - } - - macro_rules! assert_accounts_sum_matches { - ($changeset:ident, $split_changesets:ident) => { - assert_eq!( - $split_changesets.args_changeset.len() - + $split_changesets.args_including_finalize_changeset.len() - + $split_changesets.args_with_lookup_changeset.len() - + $split_changesets - .args_including_finalize_with_lookup_changeset - .len() - + $split_changesets.from_buffer_changeset.len() - + $split_changesets.from_buffer_with_lookup_changeset.len(), - $changeset.len() - ); - }; - } - - macro_rules! assert_undelegate_sum_matches { - ($changeset:ident, $split_changesets:ident) => { - assert_eq!( - $split_changesets - .args_changeset - .accounts_to_undelegate - .len() - + $split_changesets - .args_including_finalize_changeset - .accounts_to_undelegate - .len() - + $split_changesets - .args_with_lookup_changeset - .accounts_to_undelegate - .len() - + $split_changesets - .args_including_finalize_with_lookup_changeset - .accounts_to_undelegate - .len() - + $split_changesets - .from_buffer_changeset - .accounts_to_undelegate - .len() - + $split_changesets - .from_buffer_with_lookup_changeset - .accounts_to_undelegate - .len(), - $changeset.accounts_to_undelegate.len() - ); - }; - } - #[test] - fn test_split_small_changesets_by_commit_strategy() { - init_logger(); - - // Setup a changeset with different bundle/account sizes - let mut changeset = Changeset { - slot: 1, - ..Default::default() - }; - - let bundle_id = 1111; - - // 2 accounts bundle that can be handled via args - for idx in 1..=2 { - add_changed_account(&mut changeset, 10, bundle_id, idx % 2 == 0); - } - - // 8 accounts bundle that needs lookup - for idx in 1..=8 { - add_changed_account( - &mut changeset, - 10, - bundle_id * 10, - idx % 2 == 0, - ); - } - - // No Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), false) - .unwrap(); - debug_counts!("No Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_changeset.len(), 2,); - assert_eq!(split_changesets.args_with_lookup_changeset.len(), 8,); - - // Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), true) - .unwrap(); - - debug_counts!("Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_including_finalize_changeset.len(), 2,); - assert_eq!( - split_changesets - .args_including_finalize_with_lookup_changeset - .len(), - 8, - ); - } - - #[test] - fn test_split_medium_changesets_by_commit_strategy() { - init_logger(); - - // Setup a changeset with different bundle/account sizes - let mut changeset = Changeset { - slot: 1, - ..Default::default() - }; - let bundle_id = 2222; - - // 2 accounts bundle that can be handled via args and include the finalize instructions - for idx in 1..=2 { - add_changed_account(&mut changeset, 80, bundle_id, idx % 2 == 0); - } - - // 2 accounts bundle that can be handled via args, but cannot include finalize due - // to the size of the data - for idx in 1..=2 { - add_changed_account( - &mut changeset, - 100, - bundle_id + 1, - idx % 2 == 0, - ); - } - - // 3 accounts bundle that needs lookup buffer due to overall args size - for idx in 1..=3 { - add_changed_account( - &mut changeset, - 100, - bundle_id + 3, - idx % 2 == 0, - ); - } - - // No Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), false) - .unwrap(); - debug_counts!("No Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_changeset.len(), 4,); - assert_eq!(split_changesets.from_buffer_changeset.len(), 3,); - - // Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), true) - .unwrap(); - debug_counts!("Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_changeset.len(), 2,); - assert_eq!(split_changesets.args_including_finalize_changeset.len(), 2,); - assert_eq!(split_changesets.from_buffer_changeset.len(), 3,); - } - - #[test] - fn test_split_large_changesets_by_commit_strategy() { - init_logger(); - - // Setup a changeset with different bundle/account sizes - let mut changeset = Changeset { - slot: 1, - ..Default::default() - }; - - let bundle_id = 3333; - - // 5 accounts bundle that needs to be handled via lookup (buffer) - for idx in 1..=5 { - add_changed_account(&mut changeset, 400, bundle_id, idx % 2 == 0); - } - - // 2 accounts bundle that can be handled without lookup (buffer) - for idx in 1..=2 { - add_changed_account( - &mut changeset, - 600, - bundle_id * 10, - idx % 2 == 0, - ); - } - - // No Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), false) - .unwrap(); - debug_counts!("No Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.from_buffer_changeset.len(), 2,); - assert_eq!(split_changesets.from_buffer_with_lookup_changeset.len(), 5,); - - // Finalize - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), true) - .unwrap(); - debug_counts!("Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.from_buffer_changeset.len(), 2,); - assert_eq!(split_changesets.from_buffer_with_lookup_changeset.len(), 5,); - } - - #[test] - fn test_split_different_size_changesets_by_commit_strategy() { - // Combining the different changeset sizes we already test above into one changeset to - // split - init_logger(); - - // Setup a changeset with different bundle/account sizes - let mut changeset = Changeset { - slot: 1, - ..Default::default() - }; - - // Small sized bundles - { - let bundle_id = 1111; - - // 2 accounts bundle that can be handled via args - for idx in 1..=2 { - add_changed_account( - &mut changeset, - 10, - bundle_id, - idx % 2 == 0, - ); - } - - // 8 accounts bundle that needs lookup - for idx in 1..=8 { - add_changed_account( - &mut changeset, - 10, - bundle_id * 10, - idx % 2 == 0, - ); - } - }; - - // Medium sized bundles - { - let bundle_id = 2222; - - // 2 accounts bundle that can be handled via args - for idx in 1..=2 { - add_changed_account( - &mut changeset, - 100, - bundle_id, - idx % 2 == 0, - ); - } - }; - - // Large sized bundles - { - let bundle_id = 3333; - - // 5 accounts bundle that needs to be handled via lookup (buffer) - for idx in 1..=5 { - add_changed_account( - &mut changeset, - 400, - bundle_id, - idx % 2 == 0, - ); - } - - // 2 accounts bundle that can be handled without lookup (buffer) - for idx in 1..=2 { - add_changed_account( - &mut changeset, - 600, - bundle_id * 10, - idx % 2 == 0, - ); - } - }; - - // No Finalize - { - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), false) - .unwrap(); - - debug_counts!("No Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_changeset.len(), 4); - assert_eq!(split_changesets.args_with_lookup_changeset.len(), 8); - assert_eq!(split_changesets.from_buffer_changeset.len(), 2); - assert_eq!( - split_changesets.from_buffer_with_lookup_changeset.len(), - 5 - ); - } - - // Finalize - { - let split_changesets = - split_changesets_by_commit_strategy(changeset.clone(), true) - .unwrap(); - - debug_counts!("Finalize", changeset, split_changesets); - assert_accounts_sum_matches!(changeset, split_changesets); - assert_undelegate_sum_matches!(changeset, split_changesets); - - assert_eq!(split_changesets.args_changeset.len(), 2); - assert_eq!( - split_changesets.args_including_finalize_changeset.len(), - 2 - ); - assert_eq!( - split_changesets - .args_including_finalize_with_lookup_changeset - .len(), - 8 - ); - assert_eq!(split_changesets.from_buffer_changeset.len(), 2); - assert_eq!( - split_changesets.from_buffer_with_lookup_changeset.len(), - 5 - ); - } - } -} diff --git a/magicblock-committor-service/src/commit_strategist/mod.rs b/magicblock-committor-service/src/commit_strategist/mod.rs deleted file mode 100644 index a1ffe2992..000000000 --- a/magicblock-committor-service/src/commit_strategist/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub(crate) mod commit_strategy; -pub(crate) mod report_builder; diff --git a/magicblock-committor-service/src/commit_strategist/report_builder.rs b/magicblock-committor-service/src/commit_strategist/report_builder.rs deleted file mode 100644 index 20e3351dc..000000000 --- a/magicblock-committor-service/src/commit_strategist/report_builder.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub(crate) struct L1MessageReport { - /// Size of the transaction without lookup tables. - size_args: usize, -} - -pub(crate) struct L1MessageReportBuilder {} diff --git a/magicblock-committor-service/src/finalize.rs b/magicblock-committor-service/src/finalize.rs deleted file mode 100644 index b63341400..000000000 --- a/magicblock-committor-service/src/finalize.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::collections::HashMap; - -use log::*; -use solana_pubkey::Pubkey; - -use crate::{ - bundles::bundle_chunks, - transactions::{ - finalize_ix, MAX_FINALIZE_PER_TX, MAX_FINALIZE_PER_TX_USING_LOOKUP, - }, - types::{InstructionsForCommitable, InstructionsKind}, - CommitInfo, -}; - -fn finalize_commitable( - validator_auth: Pubkey, - commit_info: CommitInfo, -) -> InstructionsForCommitable { - debug!("Finalizing commitable: {:?}", commit_info); - let CommitInfo::BufferedDataAccount { pubkey, .. } = &commit_info else { - panic!("Only data accounts are supported for now"); - }; - - let ix = finalize_ix(validator_auth, pubkey); - InstructionsForCommitable { - instructions: vec![ix], - commit_info, - kind: InstructionsKind::Finalize, - } -} - -pub(crate) struct ChunkedIxsToFinalizeCommitablesResult { - pub chunked_ixs: Vec>, - pub unchunked: HashMap>, -} - -/// Finalizes the previously processed commits -/// Ensures that commitables with matching bundle id are in a single chunk -pub(crate) fn chunked_ixs_to_finalize_commitables( - validator_auth: Pubkey, - commit_infos: Vec, - use_lookup: bool, -) -> ChunkedIxsToFinalizeCommitablesResult { - let max_per_chunk = if use_lookup { - MAX_FINALIZE_PER_TX_USING_LOOKUP - } else { - MAX_FINALIZE_PER_TX - }; - let bundles = bundle_chunks(commit_infos, max_per_chunk as usize); - let chunked_ixs: Vec<_> = bundles - .chunks - .into_iter() - .map(|chunk| { - chunk - .into_iter() - .map(|commit_info| { - finalize_commitable(validator_auth, commit_info) - }) - .collect::>() - }) - .collect(); - ChunkedIxsToFinalizeCommitablesResult { - chunked_ixs, - unchunked: bundles.unchunked, - } -} diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 299a476fb..5136fe34b 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -1,19 +1,14 @@ -mod bundle_strategy; -mod bundles; mod commit_info; -mod commit_strategist; mod compute_budget; pub mod config; mod consts; pub mod error; -mod finalize; pub mod persist; mod pubkeys_provider; mod service; pub mod service_ext; pub mod transactions; pub mod types; -mod undelegate; pub mod commit_scheduler; // TODO(edwin): define visibility diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index 576e7bb55..c15625aae 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -9,7 +9,6 @@ use magicblock_committor_program::{ }, write_buffer::{create_write_ix, CreateWriteIxArgs}, }, - instruction_chunks::chunk_realloc_ixs, ChangesetChunks, Chunks, }; use magicblock_program::magic_scheduled_l1_message::{ diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs index d09ff2385..ce5ebf166 100644 --- a/magicblock-committor-service/src/transactions.rs +++ b/magicblock-committor-service/src/transactions.rs @@ -1,25 +1,7 @@ -use std::collections::HashSet; - use base64::{prelude::BASE64_STANDARD, Engine}; -use dlp::args::{CommitStateArgs, CommitStateFromBufferArgs}; -use magicblock_committor_program::{ - instruction_builder::close_buffer::{create_close_ix, CreateCloseIxArgs}, - ChangedBundle, -}; -use solana_pubkey::Pubkey; use solana_rpc_client::rpc_client::SerializableTransaction; -use solana_sdk::{ - hash::Hash, - instruction::Instruction, - message::{v0::Message, AddressLookupTableAccount, VersionedMessage}, - signature::Keypair, - signer::Signer, - transaction::VersionedTransaction, -}; use static_assertions::const_assert; -use crate::error::{CommittorServiceError, CommittorServiceResult}; - /// From agave rpc/src/rpc.rs [MAX_BASE64_SIZE] pub(crate) const MAX_ENCODED_TRANSACTION_SIZE: usize = 1644; @@ -84,217 +66,6 @@ const_assert!( MAX_PROCESS_PER_TX_USING_LOOKUP <= MAX_UNDELEGATE_PER_TX_USING_LOOKUP ); -// ----------------- -// Process Commitables using Args or Buffer -// ----------------- -pub(crate) struct CommitTxReport { - /// Size of the transaction without lookup tables. - pub size_args: usize, - - /// The size of the transaction including the finalize instruction - /// when not using lookup tables the `finalize` param of - /// [size_of_commit_with_args_tx] is `true`. - pub size_args_including_finalize: Option, - - /// If the bundle fits into a single transaction using buffers without - /// using lookup tables. - /// This does not depend on the size of the data, but only the number of - /// accounts in the bundle. - pub fits_buffer: bool, - - /// If the bundle fits into a single transaction using buffers using lookup tables. - /// This does not depend on the size of the data, but only the number of - /// accounts in the bundle. - pub fits_buffer_using_lookup: bool, - - /// Size of the transaction when using lookup tables. - /// This is only determined if the [SizeOfCommitWithArgs::size] is larger than - /// [MAX_ENCODED_TRANSACTION_SIZE]. - pub size_args_with_lookup: Option, - - /// The size of the transaction including the finalize instruction - /// when using lookup tables - /// This is only determined if the [SizeOfCommitWithArgs::size_including_finalize] - /// is larger than [MAX_ENCODED_TRANSACTION_SIZE]. - pub size_args_with_lookup_including_finalize: Option, -} - -pub(crate) fn commit_tx_report( - bundle: &ChangedBundle, - finalize: bool, -) -> CommittorServiceResult { - let auth = Keypair::new(); - - let ixs = bundle - .iter() - .map(|(_, account)| { - let args = CommitStateArgs { - // TODO(thlorenz): this is expensive, but seems unavoidable in order to reliably - // calculate the size of the transaction - data: account.data().to_vec(), - ..CommitStateArgs::default() - }; - dlp::instruction_builder::commit_state( - auth.pubkey(), - Pubkey::new_unique(), - Pubkey::new_unique(), - args, - ) - }) - .collect::>(); - - let size = encoded_tx_size(&auth, &ixs, &TransactionOpts::NoLookupTable)?; - let size_with_lookup = (size > MAX_ENCODED_TRANSACTION_SIZE) - .then(|| encoded_tx_size(&auth, &ixs, &TransactionOpts::UseLookupTable)) - .transpose()?; - - if finalize { - let mut ixs = ixs.clone(); - let finalize_ixs = bundle.iter().map(|(pubkey, _)| { - dlp::instruction_builder::finalize(auth.pubkey(), *pubkey) - }); - ixs.extend(finalize_ixs); - - let size_including_finalize = - encoded_tx_size(&auth, &ixs, &TransactionOpts::NoLookupTable)?; - let size_with_lookup_including_finalize = (size_including_finalize - > MAX_ENCODED_TRANSACTION_SIZE) - .then(|| { - encoded_tx_size(&auth, &ixs, &TransactionOpts::UseLookupTable) - }) - .transpose()?; - - Ok(CommitTxReport { - size_args: size, - fits_buffer: bundle.len() <= MAX_PROCESS_PER_TX as usize, - fits_buffer_using_lookup: bundle.len() - <= MAX_PROCESS_PER_TX_USING_LOOKUP as usize, - size_args_with_lookup: size_with_lookup, - size_args_including_finalize: Some(size_including_finalize), - size_args_with_lookup_including_finalize: - size_with_lookup_including_finalize, - }) - } else { - Ok(CommitTxReport { - size_args: size, - fits_buffer: bundle.len() <= MAX_PROCESS_PER_TX as usize, - fits_buffer_using_lookup: bundle.len() - <= MAX_PROCESS_PER_TX_USING_LOOKUP as usize, - size_args_including_finalize: None, - size_args_with_lookup: size_with_lookup, - size_args_with_lookup_including_finalize: None, - }) - } -} - -// ----------------- -// Process Commitables and Close Buffers -// ----------------- -pub(crate) fn process_commits_ix( - validator_auth: Pubkey, - pubkey: &Pubkey, - delegated_account_owner: &Pubkey, - buffer_pda: &Pubkey, - commit_args: CommitStateFromBufferArgs, -) -> Instruction { - dlp::instruction_builder::commit_state_from_buffer( - validator_auth, - *pubkey, - *delegated_account_owner, - *buffer_pda, - commit_args, - ) -} - -pub(crate) fn close_buffers_ix( - validator_auth: Pubkey, - pubkey: &Pubkey, - commit_id: u64, -) -> Instruction { - create_close_ix(CreateCloseIxArgs { - authority: validator_auth, - pubkey: *pubkey, - commit_id, - }) -} - -pub(crate) fn process_and_close_ixs( - validator_auth: Pubkey, - pubkey: &Pubkey, - delegated_account_owner: &Pubkey, - buffer_pda: &Pubkey, - commit_id: u64, - commit_args: CommitStateFromBufferArgs, -) -> Vec { - let process_ix = process_commits_ix( - validator_auth, - pubkey, - delegated_account_owner, - buffer_pda, - commit_args, - ); - let close_ix = close_buffers_ix(validator_auth, pubkey, commit_id); - - vec![process_ix, close_ix] -} - -// ----------------- -// Finalize -// ----------------- -pub(crate) fn finalize_ix( - validator_auth: Pubkey, - pubkey: &Pubkey, -) -> Instruction { - dlp::instruction_builder::finalize(validator_auth, *pubkey) -} - -// ----------------- -// Helpers -// ----------------- -#[allow(clippy::enum_variant_names)] -enum TransactionOpts { - NoLookupTable, - UseLookupTable, -} -fn encoded_tx_size( - auth: &Keypair, - ixs: &[Instruction], - opts: &TransactionOpts, -) -> CommittorServiceResult { - use CommittorServiceError::*; - use TransactionOpts::*; - let lookup_tables = match opts { - NoLookupTable => vec![], - UseLookupTable => get_lookup_tables(ixs), - }; - - let versioned_msg = Message::try_compile( - &auth.pubkey(), - ixs, - &lookup_tables, - Hash::default(), - ) - .map_err(|err| { - FailedToCompileTransactionMessage( - "Calculating transaction size".to_string(), - err, - ) - })?; - let versioned_tx = VersionedTransaction::try_new( - VersionedMessage::V0(versioned_msg), - &[&auth], - ) - .map_err(|err| { - FailedToCreateTransaction( - "Calculating transaction size".to_string(), - err, - ) - })?; - - let encoded = serialize_and_encode_base64(&versioned_tx); - Ok(encoded.len()) -} - pub fn serialize_and_encode_base64( transaction: &impl SerializableTransaction, ) -> String { @@ -303,19 +74,6 @@ pub fn serialize_and_encode_base64( BASE64_STANDARD.encode(serialized) } -fn get_lookup_tables(ixs: &[Instruction]) -> Vec { - let pubkeys = ixs - .iter() - .flat_map(|ix| ix.accounts.iter().map(|acc| acc.pubkey)) - .collect::>(); - - let lookup_table = AddressLookupTableAccount { - key: Pubkey::default(), - addresses: pubkeys.into_iter().collect(), - }; - vec![lookup_table] -} - #[cfg(test)] mod test { use dlp::args::{CommitStateArgs, CommitStateFromBufferArgs}; @@ -330,12 +88,136 @@ mod test { signer::Signer, transaction::VersionedTransaction, }; - + use magicblock_committor_program::instruction_builder::close_buffer::{create_close_ix, CreateCloseIxArgs}; use super::*; use crate::{ compute_budget::{Budget, ComputeBudget}, pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, }; + use crate::error::CommittorServiceError::{FailedToCompileTransactionMessage, FailedToCreateTransaction}; + use crate::error::CommittorServiceResult; + + fn get_lookup_tables(ixs: &[Instruction]) -> Vec { + let pubkeys = ixs + .iter() + .flat_map(|ix| ix.accounts.iter().map(|acc| acc.pubkey)) + .collect::>(); + + let lookup_table = AddressLookupTableAccount { + key: Pubkey::default(), + addresses: pubkeys.into_iter().collect(), + }; + vec![lookup_table] + } + + + // ----------------- + // Helpers + // ----------------- + #[allow(clippy::enum_variant_names)] + enum TransactionOpts { + NoLookupTable, + UseLookupTable, + } + fn encoded_tx_size( + auth: &Keypair, + ixs: &[Instruction], + opts: &TransactionOpts, + ) -> CommittorServiceResult { + use CommittorServiceError::*; + use TransactionOpts::*; + let lookup_tables = match opts { + NoLookupTable => vec![], + UseLookupTable => get_lookup_tables(ixs), + }; + + let versioned_msg = Message::try_compile( + &auth.pubkey(), + ixs, + &lookup_tables, + Hash::default(), + ) + .map_err(|err| { + FailedToCompileTransactionMessage( + "Calculating transaction size".to_string(), + err, + ) + })?; + let versioned_tx = VersionedTransaction::try_new( + VersionedMessage::V0(versioned_msg), + &[&auth], + ) + .map_err(|err| { + FailedToCreateTransaction( + "Calculating transaction size".to_string(), + err, + ) + })?; + + let encoded = serialize_and_encode_base64(&versioned_tx); + Ok(encoded.len()) + } + + // ----------------- + // Process Commitables and Close Buffers + // ----------------- + pub(crate) fn process_commits_ix( + validator_auth: Pubkey, + pubkey: &Pubkey, + delegated_account_owner: &Pubkey, + buffer_pda: &Pubkey, + commit_args: CommitStateFromBufferArgs, + ) -> Instruction { + dlp::instruction_builder::commit_state_from_buffer( + validator_auth, + *pubkey, + *delegated_account_owner, + *buffer_pda, + commit_args, + ) + } + + pub(crate) fn close_buffers_ix( + validator_auth: Pubkey, + pubkey: &Pubkey, + commit_id: u64, + ) -> Instruction { + create_close_ix(CreateCloseIxArgs { + authority: validator_auth, + pubkey: *pubkey, + commit_id, + }) + } + + pub(crate) fn process_and_close_ixs( + validator_auth: Pubkey, + pubkey: &Pubkey, + delegated_account_owner: &Pubkey, + buffer_pda: &Pubkey, + commit_id: u64, + commit_args: CommitStateFromBufferArgs, + ) -> Vec { + let process_ix = process_commits_ix( + validator_auth, + pubkey, + delegated_account_owner, + buffer_pda, + commit_args, + ); + let close_ix = close_buffers_ix(validator_auth, pubkey, commit_id); + + vec![process_ix, close_ix] + } + + // ----------------- + // Finalize + // ----------------- + pub(crate) fn finalize_ix( + validator_auth: Pubkey, + pubkey: &Pubkey, + ) -> Instruction { + dlp::instruction_builder::finalize(validator_auth, *pubkey) + } // These tests statically determine the optimal ix count to fit into a single // transaction and assert that the const we export in prod match those numbers. diff --git a/magicblock-committor-service/src/undelegate.rs b/magicblock-committor-service/src/undelegate.rs deleted file mode 100644 index 7064d5163..000000000 --- a/magicblock-committor-service/src/undelegate.rs +++ /dev/null @@ -1,103 +0,0 @@ -use std::collections::HashMap; - -use dlp::state::DelegationMetadata; -use magicblock_rpc_client::MagicblockRpcClient; -use solana_account::ReadableAccount; -use solana_pubkey::Pubkey; -use solana_sdk::instruction::Instruction; - -use crate::{ - error::{CommittorServiceError, CommittorServiceResult}, - transactions::{MAX_UNDELEGATE_PER_TX, MAX_UNDELEGATE_PER_TX_USING_LOOKUP}, - types::{InstructionsForCommitable, InstructionsKind}, - CommitInfo, -}; - -pub(crate) async fn undelegate_commitables_ixs( - rpc_client: &MagicblockRpcClient, - validator_auth: Pubkey, - accs: Vec<(Pubkey, Pubkey)>, -) -> CommittorServiceResult> { - let delegation_metadata_pubkeys = accs - .iter() - .map(|(delegated_account, _)| { - dlp::pda::delegation_metadata_pda_from_delegated_account( - delegated_account, - ) - }) - .collect::>(); - let metadata_accs = rpc_client - .get_multiple_accounts(&delegation_metadata_pubkeys, None) - .await?; - - let mut ixs = HashMap::new(); - - for (metadata_acc, (committee, owner)) in - metadata_accs.iter().zip(accs.iter()) - { - let Some(metadata_acc) = metadata_acc else { - return Err( - CommittorServiceError::FailedToFetchDelegationMetadata( - *committee, - ), - ); - }; - let metadata = DelegationMetadata::try_from_bytes_with_discriminator( - metadata_acc.data(), - ) - .map_err(|err| { - CommittorServiceError::FailedToDeserializeDelegationMetadata( - *committee, err, - ) - })?; - - ixs.insert( - *committee, - dlp::instruction_builder::undelegate( - validator_auth, - *committee, - *owner, - metadata.rent_payer, - ), - ); - } - Ok(ixs) -} - -pub(crate) fn chunked_ixs_to_undelegate_commitables( - mut ixs: HashMap, - commit_infos: Vec, - use_lookup: bool, -) -> Vec> { - let max_per_chunk = if use_lookup { - MAX_UNDELEGATE_PER_TX_USING_LOOKUP - } else { - MAX_UNDELEGATE_PER_TX - }; - - let chunks = commit_infos - .chunks(max_per_chunk as usize) - .map(|chunk| { - chunk - .iter() - .flat_map(|commit_info| { - ixs.remove(&commit_info.pubkey()).map(|ix| { - InstructionsForCommitable { - instructions: vec![ix], - commit_info: commit_info.clone(), - kind: InstructionsKind::Undelegate, - } - }) - }) - .collect::>() - }) - .collect::>(); - - debug_assert!( - ixs.is_empty(), - "BUG: Some undelegate instructions {:?} were not matched with a commit_info: {:?}", - ixs, commit_infos - ); - - chunks -} From bad27f2a0881bd940ceb0d8f7b6cb6d0e7072bc7 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 30 Jul 2025 22:45:27 +0900 Subject: [PATCH 147/199] refactor: cleanup --- magicblock-committor-service/src/error.rs | 38 +-------------- magicblock-committor-service/src/types.rs | 56 ----------------------- 2 files changed, 2 insertions(+), 92 deletions(-) diff --git a/magicblock-committor-service/src/error.rs b/magicblock-committor-service/src/error.rs index bf0555195..03efa2715 100644 --- a/magicblock-committor-service/src/error.rs +++ b/magicblock-committor-service/src/error.rs @@ -1,14 +1,8 @@ -use std::sync::Arc; - -use magicblock_rpc_client::MagicBlockRpcClientError; use solana_pubkey::Pubkey; use solana_sdk::signature::Signature; use thiserror::Error; -use crate::{persist::CommitStrategy, CommitInfo}; - -pub type CommittorServiceResult = - std::result::Result; +pub type CommittorServiceResult = Result; #[derive(Error, Debug)] pub enum CommittorServiceError { @@ -83,32 +77,4 @@ impl CommittorServiceError { _ => None, } } -} - -pub type CommitAccountResult = std::result::Result; -#[derive(Error, Debug)] -/// Specific error that always includes the commit info -pub enum CommitAccountError { - #[error("Failed to init buffer and chunk account: {0}")] - InitBufferAndChunkAccounts(String, Box, CommitStrategy), - - #[error("Failed to get chunks account: ({0:?})")] - GetChunksAccount( - Option, - Arc, - CommitStrategy, - ), - - #[error("Failed to deserialize chunks account: {0} ({0:?})")] - DeserializeChunksAccount(std::io::Error, Arc, CommitStrategy), - - #[error("Failed to affect remaining size via realloc buffer after max retries. Last error {0}")] - ReallocBufferRanOutOfRetries(String, Arc, CommitStrategy), - - #[error("Failed to write complete chunks of commit data after max retries. Last write error {0:?}")] - WriteChunksRanOutOfRetries( - Option, - Arc, - CommitStrategy, - ), -} +} \ No newline at end of file diff --git a/magicblock-committor-service/src/types.rs b/magicblock-committor-service/src/types.rs index d44c543ff..3bbd91ea3 100644 --- a/magicblock-committor-service/src/types.rs +++ b/magicblock-committor-service/src/types.rs @@ -1,64 +1,8 @@ -use std::fmt; - use magicblock_program::{ magic_scheduled_l1_message::ScheduledL1Message, FeePayerAccount, }; use solana_pubkey::Pubkey; -use solana_sdk::instruction::Instruction; - -use crate::CommitInfo; -/// The kind of instructions included for the particular [CommitInfo] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum InstructionsKind { - /// The commit is processed only and may include the finalize instruction - Process, - /// The buffers to facilitate are closed, but processing occurred as part - /// of another set of instructions - CloseBuffers, - /// The commit is processed and the buffers closed all as part of this set - /// of instructions - ProcessAndCloseBuffers, - /// The commit is processed previously and only finalized by this set of - /// instructions - Finalize, - /// The commit is processed and finalized previously and the committee is - /// undelegated by this set of instructions - Undelegate, -} - -impl InstructionsKind { - pub fn is_processing(&self) -> bool { - matches!( - self, - InstructionsKind::Process - | InstructionsKind::ProcessAndCloseBuffers - ) - } -} - -#[derive(Debug)] -pub struct InstructionsForCommitable { - pub instructions: Vec, - pub commit_info: CommitInfo, - pub kind: InstructionsKind, -} - -impl fmt::Display for InstructionsForCommitable { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "InstructionsForCommitable {{ - instructions.len: {}, - commit_info: {} - kind: {:?} -}}", - self.instructions.len(), - self.commit_info.pubkey(), - self.kind - ) - } -} // TODO: should be removed once cranks are supported // Ideally even now OffChain/"Manual" commits should be triggered via Tx From 40e9dc5721326c4154d00f9bd9d10742bd5d21c8 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 30 Jul 2025 22:48:55 +0900 Subject: [PATCH 148/199] refactor: cleanup --- .../src/commit_info.rs | 174 ------------------ magicblock-committor-service/src/error.rs | 2 +- magicblock-committor-service/src/lib.rs | 2 - .../src/stubs/changeset_committor_stub.rs | 17 +- .../src/transactions.rs | 49 +++-- magicblock-committor-service/src/types.rs | 1 - .../process_schedule_commit_tests.rs | 5 +- 7 files changed, 36 insertions(+), 214 deletions(-) delete mode 100644 magicblock-committor-service/src/commit_info.rs diff --git a/magicblock-committor-service/src/commit_info.rs b/magicblock-committor-service/src/commit_info.rs deleted file mode 100644 index 40b060cab..000000000 --- a/magicblock-committor-service/src/commit_info.rs +++ /dev/null @@ -1,174 +0,0 @@ -use dlp::pda::commit_state_pda_from_delegated_account; -use magicblock_committor_program::CommitableAccount; -use solana_pubkey::Pubkey; -use solana_sdk::{clock::Slot, hash::Hash}; - -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum CommitInfo { - /// A commit for an account that has no data. In this case we are trying to - /// commit changes to its lamports. - EmptyAccount { - /// The on chain address of the delegated account - pubkey: Pubkey, - /// The original owner of the delegated account on chain - delegated_account_owner: Pubkey, - /// The ephemeral slot at which those changes were requested - slot: Slot, - /// The ephemeral blockhash at which those changes were requested - ephemeral_blockhash: Hash, - /// If we also undelegate the account after committing it - undelegate: bool, - /// Lamports of the account in the ephemeral - lamports: u64, - /// This id will be the same for accounts whose commits need to - /// be applied atomically in a single transaction - /// For single account commits it is also set for consistency - bundle_id: u64, - /// If `true` the account commit is finalized after it was processed - finalize: bool, - }, - /// A commit for an account that is part of a bundle whose data is small enough - /// to fit into a single process commit instruction. - DataAccount { - /// The on chain address of the delegated account - pubkey: Pubkey, - /// The account where the delegated account state is committed and stored - /// until it is finalized - commit_state: Pubkey, - /// The original owner of the delegated account on chain - delegated_account_owner: Pubkey, - /// The ephemeral slot at which those changes were requested - slot: Slot, - /// The ephemeral blockhash at which those changes were requested - ephemeral_blockhash: Hash, - /// If we also undelegate the account after committing it - undelegate: bool, - /// Lamports of the account in the ephemeral - lamports: u64, - /// This id will be the same for accounts whose commits need to - /// be applied atomically in a single transaction - /// For single account commits it is also set for consistency - bundle_id: u64, - /// If `true` the account commit is finalized after it was processed - finalize: bool, - }, - /// A commit for an account that is part of a bundle whose total data is so large - /// that we send the data in chunks to a buffer account before processing the - /// commit. - BufferedDataAccount { - /// The on chain address of the delegated account - pubkey: Pubkey, - /// The account where the delegated account state is committed and stored - /// until it is finalized - commit_state: Pubkey, - /// The original owner of the delegated account on chain - delegated_account_owner: Pubkey, - /// The ephemeral slot at which those changes were requested - slot: Slot, - /// The ephemeral blockhash at which those changes were requested - ephemeral_blockhash: Hash, - /// If we also undelegate the account after committing it - undelegate: bool, - /// The account that tracked that all chunks got written to the [CommitInfo::buffer_pda] - chunks_pda: Pubkey, - /// The temporary address where the data of the account is stored - buffer_pda: Pubkey, - /// Lamports of the account in the ephemeral - lamports: u64, - /// This id will be the same for accounts whose commits need to - /// be applied atomically in a single transaction - /// For single account commits it is also set for consistency - bundle_id: u64, - /// If `true` the account commit is finalized after it was processed - finalize: bool, - }, -} - -impl CommitInfo { - pub fn from_small_data_account( - commitable: CommitableAccount, - ephemeral_blockhash: Hash, - finalize: bool, - ) -> Self { - Self::DataAccount { - pubkey: commitable.pubkey, - delegated_account_owner: commitable.delegated_account_owner, - slot: commitable.slot, - ephemeral_blockhash, - undelegate: commitable.undelegate, - lamports: commitable.lamports, - bundle_id: commitable.bundle_id, - finalize, - commit_state: commit_state_pda_from_delegated_account( - &commitable.pubkey, - ), - } - } - - pub fn pubkey(&self) -> Pubkey { - match self { - Self::EmptyAccount { pubkey, .. } => *pubkey, - Self::DataAccount { pubkey, .. } => *pubkey, - Self::BufferedDataAccount { pubkey, .. } => *pubkey, - } - } - - pub fn commit_state(&self) -> Option { - match self { - Self::BufferedDataAccount { commit_state, .. } => { - Some(*commit_state) - } - Self::DataAccount { commit_state, .. } => Some(*commit_state), - _ => None, - } - } - - pub fn lamports(&self) -> u64 { - match self { - Self::EmptyAccount { lamports, .. } => *lamports, - Self::DataAccount { lamports, .. } => *lamports, - Self::BufferedDataAccount { lamports, .. } => *lamports, - } - } - - pub fn bundle_id(&self) -> u64 { - match self { - Self::EmptyAccount { bundle_id, .. } => *bundle_id, - Self::DataAccount { bundle_id, .. } => *bundle_id, - Self::BufferedDataAccount { bundle_id, .. } => *bundle_id, - } - } - - pub fn undelegate(&self) -> bool { - match self { - Self::EmptyAccount { undelegate, .. } => *undelegate, - Self::DataAccount { undelegate, .. } => *undelegate, - Self::BufferedDataAccount { undelegate, .. } => *undelegate, - } - } - - pub fn chunks_pda(&self) -> Option { - match self { - Self::BufferedDataAccount { chunks_pda, .. } => Some(*chunks_pda), - _ => None, - } - } - - pub fn buffer_pda(&self) -> Option { - match self { - Self::BufferedDataAccount { buffer_pda, .. } => Some(*buffer_pda), - _ => None, - } - } - - pub fn pdas(&self) -> Option<(Pubkey, Pubkey)> { - match self { - Self::BufferedDataAccount { - chunks_pda, - buffer_pda, - .. - } => Some((*chunks_pda, *buffer_pda)), - _ => None, - } - } -} diff --git a/magicblock-committor-service/src/error.rs b/magicblock-committor-service/src/error.rs index 03efa2715..9833c6718 100644 --- a/magicblock-committor-service/src/error.rs +++ b/magicblock-committor-service/src/error.rs @@ -77,4 +77,4 @@ impl CommittorServiceError { _ => None, } } -} \ No newline at end of file +} diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 5136fe34b..7a5cc20bd 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -1,4 +1,3 @@ -mod commit_info; mod compute_budget; pub mod config; mod consts; @@ -21,7 +20,6 @@ pub mod transaction_preperator; pub mod utils; // TODO(edwin) pub(crate) -pub use commit_info::CommitInfo; pub use compute_budget::ComputeBudgetConfig; pub use magicblock_committor_program::{ ChangedAccount, Changeset, ChangesetMeta, diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index cf24db0a0..0a86724bf 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -1,16 +1,12 @@ use std::{ collections::HashMap, - sync::{ - atomic::{AtomicU64, Ordering}, - Arc, Mutex, - }, + sync::{Arc, Mutex}, time::{SystemTime, UNIX_EPOCH}, }; -use magicblock_committor_program::Changeset; use magicblock_program::SentCommit; use solana_pubkey::Pubkey; -use solana_sdk::{hash::Hash, signature::Signature, transaction::Transaction}; +use solana_sdk::{signature::Signature, transaction::Transaction}; use tokio::sync::{oneshot, oneshot::Receiver}; use crate::{ @@ -19,10 +15,7 @@ use crate::{ }, error::CommittorServiceResult, message_executor::ExecutionOutput, - persist::{ - CommitStatus, CommitStatusRow, CommitStatusSignatures, CommitStrategy, - CommitType, L1MessagePersister, MessageSignatures, - }, + persist::{CommitStatusRow, L1MessagePersister, MessageSignatures}, service_ext::{L1MessageCommitorExtResult, L1MessageCommittorExt}, types::{ScheduledL1MessageWrapper, TriggerType}, L1MessageCommittor, @@ -106,8 +99,8 @@ impl L1MessageCommittor for ChangesetCommittorStub { fn get_commit_signatures( &self, - commit_id: u64, - pubkey: Pubkey, + _commit_id: u64, + _pubkey: Pubkey, ) -> oneshot::Receiver>> { let (tx, rx) = oneshot::channel(); diff --git a/magicblock-committor-service/src/transactions.rs b/magicblock-committor-service/src/transactions.rs index ce5ebf166..d8d5e718f 100644 --- a/magicblock-committor-service/src/transactions.rs +++ b/magicblock-committor-service/src/transactions.rs @@ -76,8 +76,13 @@ pub fn serialize_and_encode_base64( #[cfg(test)] mod test { + use std::collections::HashSet; + use dlp::args::{CommitStateArgs, CommitStateFromBufferArgs}; use lazy_static::lazy_static; + use magicblock_committor_program::instruction_builder::close_buffer::{ + create_close_ix, CreateCloseIxArgs, + }; use solana_pubkey::Pubkey; use solana_sdk::{ address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES, @@ -88,16 +93,22 @@ mod test { signer::Signer, transaction::VersionedTransaction, }; - use magicblock_committor_program::instruction_builder::close_buffer::{create_close_ix, CreateCloseIxArgs}; + use super::*; use crate::{ compute_budget::{Budget, ComputeBudget}, + error::{ + CommittorServiceError::{ + FailedToCompileTransactionMessage, FailedToCreateTransaction, + }, + CommittorServiceResult, + }, pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, }; - use crate::error::CommittorServiceError::{FailedToCompileTransactionMessage, FailedToCreateTransaction}; - use crate::error::CommittorServiceResult; - fn get_lookup_tables(ixs: &[Instruction]) -> Vec { + fn get_lookup_tables( + ixs: &[Instruction], + ) -> Vec { let pubkeys = ixs .iter() .flat_map(|ix| ix.accounts.iter().map(|acc| acc.pubkey)) @@ -110,7 +121,6 @@ mod test { vec![lookup_table] } - // ----------------- // Helpers // ----------------- @@ -124,7 +134,6 @@ mod test { ixs: &[Instruction], opts: &TransactionOpts, ) -> CommittorServiceResult { - use CommittorServiceError::*; use TransactionOpts::*; let lookup_tables = match opts { NoLookupTable => vec![], @@ -137,22 +146,22 @@ mod test { &lookup_tables, Hash::default(), ) - .map_err(|err| { - FailedToCompileTransactionMessage( - "Calculating transaction size".to_string(), - err, - ) - })?; + .map_err(|err| { + FailedToCompileTransactionMessage( + "Calculating transaction size".to_string(), + err, + ) + })?; let versioned_tx = VersionedTransaction::try_new( VersionedMessage::V0(versioned_msg), &[&auth], ) - .map_err(|err| { - FailedToCreateTransaction( - "Calculating transaction size".to_string(), - err, - ) - })?; + .map_err(|err| { + FailedToCreateTransaction( + "Calculating transaction size".to_string(), + err, + ) + })?; let encoded = serialize_and_encode_base64(&versioned_tx); Ok(encoded.len()) @@ -480,14 +489,14 @@ mod test { pub(crate) static ref MAX_FINALIZE_PER_TX: u8 = { max_chunks_per_transaction("Max finalize per tx", |auth_pubkey| { let pubkey = Pubkey::new_unique(); - vec![super::finalize_ix(auth_pubkey, &pubkey)] + vec![finalize_ix(auth_pubkey, &pubkey)] }) }; pub(crate) static ref MAX_FINALIZE_PER_TX_USING_LOOKUP: u8 = { max_chunks_per_transaction_using_lookup_table( "Max finalize per tx using lookup", |auth_pubkey, committee, _| { - vec![super::finalize_ix(auth_pubkey, &committee)] + vec![finalize_ix(auth_pubkey, &committee)] }, Some(40), ) diff --git a/magicblock-committor-service/src/types.rs b/magicblock-committor-service/src/types.rs index 3bbd91ea3..5b81219c7 100644 --- a/magicblock-committor-service/src/types.rs +++ b/magicblock-committor-service/src/types.rs @@ -3,7 +3,6 @@ use magicblock_program::{ }; use solana_pubkey::Pubkey; - // TODO: should be removed once cranks are supported // Ideally even now OffChain/"Manual" commits should be triggered via Tx #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs index 528c3ba9c..5540d1eab 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs @@ -235,10 +235,7 @@ fn assert_first_commit( #[cfg(test)] mod tests { use super::*; - use crate::{ - magic_scheduled_l1_message::MagicL1Message, - utils::instruction_utils::InstructionUtils, - }; + use crate::utils::instruction_utils::InstructionUtils; #[test] fn test_schedule_commit_single_account_success() { From aed2b895daf720507ded57d63b277b0e95435f10 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 31 Jul 2025 13:17:40 +0900 Subject: [PATCH 149/199] refactor: renaming of L1Message -> BaseIntent --- .../src/remote_account_cloner_client.rs | 4 +- .../src/remote_account_cloner_worker.rs | 4 +- .../src/external_accounts_manager.rs | 50 +- .../src/remote_scheduled_commits_processor.rs | 52 +- magicblock-accounts/src/traits.rs | 2 +- .../stubs/scheduled_commits_processor_stub.rs | 2 +- .../commit_scheduler_inner.rs | 581 ------------------ .../src/committor_processor.rs | 35 +- ...heduler.rs => intent_execution_manager.rs} | 63 +- .../db.rs | 37 +- .../intent_execution_engine.rs} | 275 +++++---- .../intent_scheduler.rs | 578 +++++++++++++++++ .../commit_id_fetcher.rs} | 0 .../error.rs | 2 +- .../intent_executor.rs} | 50 +- .../intent_executor_factory.rs} | 18 +- .../src/intent_executor/mod.rs | 32 + magicblock-committor-service/src/lib.rs | 6 +- .../src/message_executor/mod.rs | 32 - .../src/persist/commit_persister.rs | 90 +-- .../src/persist/mod.rs | 2 +- magicblock-committor-service/src/service.rs | 35 +- .../src/service_ext.rs | 62 +- .../src/stubs/changeset_committor_stub.rs | 61 +- .../src/tasks/task_builder.rs | 68 +- .../src/tasks/task_strategist.rs | 64 +- .../tasks/task_visitors/persistor_visitor.rs | 4 +- .../src/tasks/tasks.rs | 24 +- .../src/tasks/utils.rs | 10 +- .../delivery_preparator.rs | 12 +- .../transaction_preparator.rs | 48 +- magicblock-committor-service/src/types.rs | 6 +- magicblock-committor-service/src/utils.rs | 10 +- magicblock-committor-service/tests/common.rs | 13 +- .../tests/test_delivery_preparator.rs | 14 +- .../tests/test_transaction_preparator.rs | 68 +- magicblock-rpc/src/traits/rpc_full.rs | 2 +- programs/magicblock/src/args.rs | 14 +- programs/magicblock/src/lib.rs | 2 +- programs/magicblock/src/magic_context.rs | 14 +- ...sage.rs => magic_scheduled_base_intent.rs} | 128 ++-- .../magicblock/src/magicblock_instruction.rs | 6 +- .../magicblock/src/magicblock_processor.rs | 8 +- .../src/schedule_transactions/mod.rs | 6 +- .../process_accept_scheduled_commits.rs | 4 +- ...age.rs => process_schedule_base_intent.rs} | 16 +- .../process_schedule_commit.rs | 20 +- .../process_schedule_commit_tests.rs | 38 +- ...r.rs => schedule_base_intent_processor.rs} | 16 +- .../transaction_scheduler.rs | 33 +- programs/magicblock/src/utils/accounts.rs | 2 +- .../tests/ix_commit_local.rs | 4 +- 52 files changed, 1359 insertions(+), 1368 deletions(-) delete mode 100644 magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs rename magicblock-committor-service/src/{commit_scheduler.rs => intent_execution_manager.rs} (55%) rename magicblock-committor-service/src/{commit_scheduler => intent_execution_manager}/db.rs (60%) rename magicblock-committor-service/src/{commit_scheduler/commit_scheduler_worker.rs => intent_execution_manager/intent_execution_engine.rs} (73%) create mode 100644 magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs rename magicblock-committor-service/src/{commit_scheduler/commit_id_tracker.rs => intent_executor/commit_id_fetcher.rs} (100%) rename magicblock-committor-service/src/{message_executor => intent_executor}/error.rs (94%) rename magicblock-committor-service/src/{message_executor/message_executor.rs => intent_executor/intent_executor.rs} (84%) rename magicblock-committor-service/src/{message_executor/message_executor_factory.rs => intent_executor/intent_executor_factory.rs} (69%) create mode 100644 magicblock-committor-service/src/intent_executor/mod.rs delete mode 100644 magicblock-committor-service/src/message_executor/mod.rs rename programs/magicblock/src/{magic_scheduled_l1_message.rs => magic_scheduled_base_intent.rs} (80%) rename programs/magicblock/src/schedule_transactions/{process_schedule_l1_message.rs => process_schedule_base_intent.rs} (92%) rename programs/magicblock/src/schedule_transactions/{schedule_l1_message_processor.rs => schedule_base_intent_processor.rs} (72%) diff --git a/magicblock-account-cloner/src/remote_account_cloner_client.rs b/magicblock-account-cloner/src/remote_account_cloner_client.rs index b98f6b3fb..c6e93d586 100644 --- a/magicblock-account-cloner/src/remote_account_cloner_client.rs +++ b/magicblock-account-cloner/src/remote_account_cloner_client.rs @@ -11,7 +11,7 @@ use magicblock_account_dumper::AccountDumper; use magicblock_account_fetcher::AccountFetcher; use magicblock_account_updates::AccountUpdates; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::L1MessageCommittor; +use magicblock_committor_service::BaseIntentCommittor; use solana_sdk::pubkey::Pubkey; use tokio::sync::{mpsc::UnboundedSender, oneshot::channel}; @@ -34,7 +34,7 @@ impl RemoteAccountClonerClient { AFE: AccountFetcher, AUP: AccountUpdates, ADU: AccountDumper, - CC: L1MessageCommittor, + CC: BaseIntentCommittor, { Self { clone_request_sender: worker.get_clone_request_sender(), diff --git a/magicblock-account-cloner/src/remote_account_cloner_worker.rs b/magicblock-account-cloner/src/remote_account_cloner_worker.rs index 161d0b0d3..c05792733 100644 --- a/magicblock-account-cloner/src/remote_account_cloner_worker.rs +++ b/magicblock-account-cloner/src/remote_account_cloner_worker.rs @@ -20,7 +20,7 @@ use magicblock_account_dumper::AccountDumper; use magicblock_account_fetcher::AccountFetcher; use magicblock_account_updates::{AccountUpdates, AccountUpdatesResult}; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::L1MessageCommittor; +use magicblock_committor_service::BaseIntentCommittor; use magicblock_metrics::metrics; use magicblock_mutator::idl::{get_pubkey_anchor_idl, get_pubkey_shank_idl}; use solana_sdk::{ @@ -138,7 +138,7 @@ where AFE: AccountFetcher, AUP: AccountUpdates, ADU: AccountDumper, - CC: L1MessageCommittor, + CC: BaseIntentCommittor, { #[allow(clippy::too_many_arguments)] pub fn new( diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 36914d9ff..a1385e66f 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -20,18 +20,18 @@ use log::*; use magicblock_account_cloner::{AccountCloner, AccountClonerOutput}; use magicblock_accounts_api::InternalAccountProvider; use magicblock_committor_service::{ - commit_scheduler::{ - BroadcastedMessageExecutionResult, ExecutionOutputWrapper, + intent_execution_manager::{ + BroadcastedIntentExecutionResult, ExecutionOutputWrapper, }, - message_executor::ExecutionOutput, - service_ext::L1MessageCommittorExt, + intent_executor::ExecutionOutput, + service_ext::BaseIntentCommittorExt, transactions::MAX_PROCESS_PER_TX, - types::{ScheduledL1MessageWrapper, TriggerType}, + types::{ScheduledBaseIntentWrapper, TriggerType}, }; use magicblock_core::magic_program; use magicblock_program::{ - magic_scheduled_l1_message::{ - CommitType, CommittedAccountV2, MagicL1Message, ScheduledL1Message, + magic_scheduled_base_intent::{ + CommitType, CommittedAccountV2, MagicBaseIntent, ScheduledBaseIntent, }, validator::validator_authority_id, }; @@ -100,7 +100,7 @@ where ACL: AccountCloner, TAE: TransactionAccountsExtractor, TAV: TransactionAccountsValidator, - CC: L1MessageCommittorExt, + CC: BaseIntentCommittorExt, { pub internal_account_provider: IAP, pub account_cloner: ACL, @@ -118,7 +118,7 @@ where ACL: AccountCloner, TAE: TransactionAccountsExtractor, TAV: TransactionAccountsValidator, - CC: L1MessageCommittorExt, + CC: BaseIntentCommittorExt, { pub async fn ensure_accounts( &self, @@ -285,14 +285,14 @@ where return Ok(vec![]); } - // Convert committees to L1Messages s + // Convert committees to BaseIntents s let scheduled_l1_messages = self.create_scheduled_l1_message(accounts_to_be_committed); - // Commit L1Messages + // Commit BaseIntents let results = self .committor_service - .commit_l1_messages_waiting(scheduled_l1_messages.clone()) + .schedule_base_intents_waiting(scheduled_l1_messages.clone()) .await?; // Process results @@ -307,8 +307,8 @@ where fn process_l1_messages_results( &self, now: &Duration, - results: Vec, - scheduled_l1_messages: &[ScheduledL1MessageWrapper], + results: Vec, + scheduled_l1_messages: &[ScheduledBaseIntentWrapper], ) -> Vec { // Filter failed l1 messages, log failed ones let outputs = results @@ -327,13 +327,9 @@ where let pubkeys_with_hashes = scheduled_l1_messages .iter() // Filter out unsuccessful messages - .filter(|message| { - outputs.contains_key(&message.scheduled_l1_message.id) - }) + .filter(|message| outputs.contains_key(&message.inner.id)) // Extract accounts that got committed - .filter_map(|message| { - message.scheduled_l1_message.get_committed_accounts() - }) + .filter_map(|message| message.inner.get_committed_accounts()) .flatten() // Calculate hash of committed accounts .map(|committed_account| { @@ -374,7 +370,7 @@ where fn create_scheduled_l1_message( &self, accounts_to_be_committed: Vec<(Pubkey, Pubkey, Option)>, - ) -> Vec { + ) -> Vec { // NOTE: the scheduled commits use the slot at which the commit was scheduled // However frequent commits run async and could be running before a slot is completed // Thus they really commit in between two slots instead of at the end of a particular slot. @@ -418,20 +414,20 @@ where .cloned() .map(|committee| CommittedAccountV2::from(committee)) .collect(); - ScheduledL1Message { + ScheduledBaseIntent { // isn't important but shall be unique id: MESSAGE_ID.fetch_sub(1, Ordering::Relaxed), slot, blockhash, action_sent_transaction: Transaction::default(), payer: validator_authority_id(), - l1_message: MagicL1Message::Commit(CommitType::Standalone( - committees, - )), + base_intent: MagicBaseIntent::Commit( + CommitType::Standalone(committees), + ), } }) - .map(|scheduled_l1_message| ScheduledL1MessageWrapper { - scheduled_l1_message, + .map(|scheduled_l1_message| ScheduledBaseIntentWrapper { + inner: scheduled_l1_message, excluded_pubkeys: vec![], feepayers: vec![], trigger_type: TriggerType::OffChain, diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 1da4d7e2f..e3327530f 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -6,15 +6,15 @@ use log::{debug, error, info}; use magicblock_account_cloner::{AccountClonerOutput, CloneOutputMap}; use magicblock_bank::bank::Bank; use magicblock_committor_service::{ - commit_scheduler::{ - BroadcastedMessageExecutionResult, ExecutionOutputWrapper, + intent_execution_manager::{ + BroadcastedIntentExecutionResult, ExecutionOutputWrapper, }, - types::{ScheduledL1MessageWrapper, TriggerType}, - L1MessageCommittor, + types::{ScheduledBaseIntentWrapper, TriggerType}, + BaseIntentCommittor, }; use magicblock_processor::execute_transaction::execute_legacy_transaction; use magicblock_program::{ - magic_scheduled_l1_message::{CommittedAccountV2, ScheduledL1Message}, + magic_scheduled_base_intent::{CommittedAccountV2, ScheduledBaseIntent}, register_scheduled_commit_sent, FeePayerAccount, TransactionScheduler, }; use magicblock_transaction_status::TransactionStatusSender; @@ -30,14 +30,14 @@ use crate::{errors::AccountsResult, ScheduledCommitsProcessor}; const POISONED_RWLOCK_MSG: &str = "RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned"; -pub struct RemoteScheduledCommitsProcessor { +pub struct RemoteScheduledCommitsProcessor { transaction_scheduler: TransactionScheduler, cloned_accounts: CloneOutputMap, bank: Arc, committor: Arc, } -impl RemoteScheduledCommitsProcessor { +impl RemoteScheduledCommitsProcessor { pub fn new( bank: Arc, cloned_accounts: CloneOutputMap, @@ -59,14 +59,14 @@ impl RemoteScheduledCommitsProcessor { } } - fn preprocess_message( + fn preprocess_intent( &self, - mut l1_message: ScheduledL1Message, - ) -> ScheduledL1MessageWrapper { - let Some(committed_accounts) = l1_message.get_committed_accounts_mut() + mut base_intent: ScheduledBaseIntent, + ) -> ScheduledBaseIntentWrapper { + let Some(committed_accounts) = base_intent.get_committed_accounts_mut() else { - return ScheduledL1MessageWrapper { - scheduled_l1_message: l1_message, + return ScheduledBaseIntentWrapper { + inner: base_intent, excluded_pubkeys: Vec::new(), feepayers: Vec::new(), trigger_type: TriggerType::OnChain, @@ -156,8 +156,8 @@ impl RemoteScheduledCommitsProcessor { } }); - ScheduledL1MessageWrapper { - scheduled_l1_message: l1_message, + ScheduledBaseIntentWrapper { + inner: base_intent, feepayers: processor.feepayers.into_iter().collect(), excluded_pubkeys: processor.excluded_pubkeys.into_iter().collect(), trigger_type: TriggerType::OnChain, @@ -167,19 +167,19 @@ impl RemoteScheduledCommitsProcessor { async fn result_processor( bank: Arc, result_subscriber: oneshot::Receiver< - broadcast::Receiver, + broadcast::Receiver, >, transaction_status_sender: TransactionStatusSender, ) { const SUBSCRIPTION_ERR_MSG: &str = - "Failed to get subscription of results of L1Messages execution"; + "Failed to get subscription of results of BaseIntents execution"; let mut result_receiver = result_subscriber.await.expect(SUBSCRIPTION_ERR_MSG); while let Ok(execution_result) = result_receiver.recv().await { match execution_result { Ok(value) => { - Self::process_message_result( + Self::process_intent_result( &bank, &transaction_status_sender, value, @@ -194,7 +194,7 @@ impl RemoteScheduledCommitsProcessor { } } - async fn process_message_result( + async fn process_intent_result( bank: &Arc, transaction_status_sender: &TransactionStatusSender, execution_outcome: ExecutionOutputWrapper, @@ -221,7 +221,7 @@ impl RemoteScheduledCommitsProcessor { } } else { info!( - "OffChain triggered L1Message executed: {}", + "OffChain triggered BaseIntent executed: {}", execution_outcome.sent_commit.message_id ); } @@ -229,23 +229,23 @@ impl RemoteScheduledCommitsProcessor { } #[async_trait] -impl ScheduledCommitsProcessor +impl ScheduledCommitsProcessor for RemoteScheduledCommitsProcessor { async fn process(&self) -> AccountsResult<()> { - let scheduled_l1_messages = + let scheduled_base_intent = self.transaction_scheduler.take_scheduled_actions(); - if scheduled_l1_messages.is_empty() { + if scheduled_base_intent.is_empty() { return Ok(()); } - let scheduled_l1_messages_wrapped = scheduled_l1_messages + let scheduled_base_intent_wrapped = scheduled_base_intent .into_iter() - .map(|message| self.preprocess_message(message)) + .map(|intent| self.preprocess_intent(intent)) .collect(); self.committor - .commit_l1_messages(scheduled_l1_messages_wrapped); + .commit_base_intent(scheduled_base_intent_wrapped); Ok(()) } diff --git a/magicblock-accounts/src/traits.rs b/magicblock-accounts/src/traits.rs index 6fba0767e..eb4de58a4 100644 --- a/magicblock-accounts/src/traits.rs +++ b/magicblock-accounts/src/traits.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use async_trait::async_trait; use magicblock_metrics::metrics::HistogramTimer; -use magicblock_program::magic_scheduled_l1_message::CommittedAccountV2; +use magicblock_program::magic_scheduled_base_intent::CommittedAccountV2; use solana_rpc_client::rpc_client::SerializableTransaction; use solana_sdk::{ account::{Account, AccountSharedData, ReadableAccount}, diff --git a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs index 30b21e02b..6989e4cd4 100644 --- a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs +++ b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use async_trait::async_trait; use magicblock_accounts::{errors::AccountsResult, ScheduledCommitsProcessor}; use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::L1MessageCommittor; +use magicblock_committor_service::BaseIntentCommittor; #[derive(Default)] pub struct ScheduledCommitsProcessorStub {} diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs b/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs deleted file mode 100644 index 4c20c3639..000000000 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_inner.rs +++ /dev/null @@ -1,581 +0,0 @@ -use std::collections::{hash_map::Entry, HashMap, VecDeque}; - -use log::warn; -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; -use solana_pubkey::Pubkey; - -use crate::types::ScheduledL1MessageWrapper; - -pub(crate) const POISONED_INNER_MSG: &str = - "Mutex on CommitSchedulerInner is poisoned."; - -type MessageID = u64; -struct MessageMeta { - num_keys: usize, - message: ScheduledL1MessageWrapper, -} - -/// A scheduler that ensures mutually exclusive access to pubkeys across messages -/// -/// # Data Structures -/// -/// 1. `blocked_keys`: Maintains FIFO queues of messages waiting for each pubkey -/// - Key: Pubkey -/// - Value: Queue of MessageIDs in arrival order -/// -/// 2. `blocked_messages`: Stores metadata for all blocked messages -/// - Key: MessageID -/// - Value: Message metadata including original message -/// -/// # Scheduling Logic -/// -/// 1. On message arrival: -/// - Check if any required pubkey exists in `blocked_keys` -/// - If conflicted: Add message to all relevant pubkey queues -/// - Else: Start executing immediately -/// -/// 2. On message completion: -/// - Pop 1st el-t from corresponding to Message `blocked_keys` queues, -/// Note: `blocked_keys[msg.keys]` == msg.id -/// - This moves forward other messages that were blocked by this one. -/// -/// 3. On popping next message to be executed: -/// - Find the first message in `blocked_messages` which -/// has all of its pubkeys unblocked, -/// i.e they are first at corresponding queues -/// -/// Some examples/edge cases: -/// (1) Assume `t1`: -/// executing: `[a1, a2, a3] [b1, b2, b3]` - 1 -/// blocked: `[a1, b1]` - 2 -/// arriving: `[a1, a3]` - 3 -/// -/// `t2`: -/// executing: `[b1, b2, b3]` -/// blocked: `[a1, b1]` -/// `[a1, a3]` - CAN't be executed, since `[a1, b1]` needs to be sent first, it has earlier state. -/// -/// (2) Assume: -/// executing: `[a1, a2, a3]` -/// blocked: `[c1, a1]` -/// arriving: `[c2, c1]` -/// `[c2, c1]` - Even there's no overlaps with executing -/// we can't proceed since blocked message has [c1] that has to be executed first -pub(crate) struct CommitSchedulerInner { - blocked_keys: HashMap>, - blocked_messages: HashMap, -} - -impl CommitSchedulerInner { - pub fn new() -> Self { - Self { - blocked_keys: HashMap::new(), - blocked_messages: HashMap::new(), - } - } - - /// Returns [`ScheduledL1Message`] if message can be executed, - /// otherwise consumes it and enqueues - /// - /// CRITICAL: MessageIds should be unique - /// Message should be scheduled once! - pub fn schedule( - &mut self, - l1_message: ScheduledL1MessageWrapper, - ) -> Option { - let message_id = l1_message.scheduled_l1_message.id; - if self.blocked_messages.contains_key(&message_id) { - warn!("Attempt to schedule already scheduled message!"); - return None; - } - - let Some(pubkeys) = - l1_message.scheduled_l1_message.get_committed_pubkeys() - else { - return Some(l1_message); - }; - - // Check if there are any conflicting keys - let is_conflicting = pubkeys - .iter() - .any(|pubkey| self.blocked_keys.contains_key(pubkey)); - // In any case block the corresponding accounts - pubkeys.iter().for_each(|pubkey| { - self.blocked_keys - .entry(*pubkey) - .or_default() - .push_back(message_id) - }); - - if is_conflicting { - // Enqueue incoming message - self.blocked_messages.insert( - message_id, - MessageMeta { - num_keys: pubkeys.len(), - message: l1_message, - }, - ); - None - } else { - Some(l1_message) - } - } - - /// Completes Message, cleaning up data after itself and allowing Messages to move forward - /// NOTE: This doesn't unblock message, hence Self::messages_blocked will return old value. - /// NOTE: this shall be called on executing messages to finilize their execution. - /// Calling on incorrect `pubkeys` set will result in panic - pub fn complete(&mut self, l1_message: &ScheduledL1Message) { - // Release data for completed message - let message_id = l1_message.id; - let Some(pubkeys) = l1_message.get_committed_pubkeys() else { - // This means L1Action, it doesn't have to be scheduled - return; - }; - - pubkeys - .iter() - .for_each(|pubkey| { - let mut occupied = match self.blocked_keys.entry(*pubkey) { - Entry::Vacant(_) => unreachable!("Invariant: queue for conflicting tasks shall exist"), - Entry::Occupied(value) => value - }; - - let blocked_messages: &mut VecDeque = occupied.get_mut(); - let front = blocked_messages.pop_front(); - assert_eq!( - message_id, - front.expect("Invariant: if message executing, queue for each account is non-empty"), - "Invariant: executing message must be first at qeueue" - ); - - if blocked_messages.is_empty() { - occupied.remove(); - } - }); - } - - // Returns [`ScheduledL1Message`] that can be executed - pub fn pop_next_scheduled_message( - &mut self, - ) -> Option { - // TODO(edwin): optimize. Create counter im MessageMeta & update - let mut execute_candidates: HashMap = HashMap::new(); - self.blocked_keys.iter().for_each(|(_, queue)| { - let message_id = queue - .front() - .expect("Invariant: we maintain ony non-empty queues"); - *execute_candidates.entry(*message_id).or_default() += 1; - }); - - // NOTE: - // Not all self.blocked_messages would be in execute_candidates - // t1: - // 1: [a, b] - // 2: [a, b] - // 3: [b] - // t2: - // 1: [a, b] - completed - // 2: [a, b] - // 3: [b] - // now 3 is in blocked messages but not in execute candidate - // NOTE: - // Other way around is also true, since execute_candidates also include - // currently executing messages - let candidate = - execute_candidates.iter().find_map(|(id, ready_keys)| { - if let Some(candidate) = self.blocked_messages.get(id) { - if candidate.num_keys.eq(ready_keys) { - Some(id) - } else { - // Not enough keys are ready - None - } - } else { - // This means that this message id is currently executing & not blocked - None - } - }); - - if let Some(next) = candidate { - Some(self.blocked_messages.remove(next).unwrap().message) - } else { - None - } - } - - /// Returns number of blocked messages - /// Note: this doesn't include "executing" messages - pub fn messages_blocked(&self) -> usize { - self.blocked_messages.len() - } -} - -/// Set of simple tests -#[cfg(test)] -mod simple_test { - use solana_pubkey::pubkey; - - use super::*; - - #[test] - fn test_empty_scheduler() { - let mut scheduler = CommitSchedulerInner::new(); - assert_eq!(scheduler.messages_blocked(), 0); - assert!(scheduler.pop_next_scheduled_message().is_none()); - } - - /// Ensure messages with non-conflicting set of keys can run in parallel - #[test] - fn test_non_conflicting_messages() { - let mut scheduler = CommitSchedulerInner::new(); - let msg1 = create_test_message( - 1, - &[pubkey!("1111111111111111111111111111111111111111111")], - ); - let msg2 = create_test_message( - 2, - &[pubkey!("22222222222222222222222222222222222222222222")], - ); - - // First message should execute immediately - assert!(scheduler.schedule(msg1.clone()).is_some()); - // Second message should also execute immediately - assert!(scheduler.schedule(msg2.clone()).is_some()); - // No messages are blocked - assert_eq!(scheduler.messages_blocked(), 0); - } - - /// Ensure messages conflicting messages get blocked - #[test] - fn test_conflicting_messages() { - const NUM_MESSAGES: u64 = 10; - - let mut scheduler = CommitSchedulerInner::new(); - let pubkey = pubkey!("1111111111111111111111111111111111111111111"); - let msg1 = create_test_message(1, &[pubkey]); - - // First message executes immediately - assert!(scheduler.schedule(msg1).is_some()); - for id in 2..=NUM_MESSAGES { - let msg = create_test_message(id, &[pubkey]); - // Message gets blocked - assert!(scheduler.schedule(msg).is_none()); - } - - // 1 message executing, NUM_MESSAGES - 1 are blocked - assert_eq!(scheduler.messages_blocked() as u64, NUM_MESSAGES - 1); - } -} - -/// Set of simple completion tests -#[cfg(test)] -mod completion_simple_test { - use solana_pubkey::pubkey; - - use super::*; - - #[test] - fn test_completion_unblocks_messages() { - let mut scheduler = CommitSchedulerInner::new(); - let pubkey = pubkey!("1111111111111111111111111111111111111111111"); - let msg1 = create_test_message(1, &[pubkey]); - let msg2 = create_test_message(2, &[pubkey]); - - // First message executes immediately - let executed = scheduler.schedule(msg1.clone()).unwrap(); - // Second message gets blocked - assert!(scheduler.schedule(msg2.clone()).is_none()); - assert_eq!(scheduler.messages_blocked(), 1); - - // Complete first message - scheduler.complete(&executed.scheduled_l1_message); - - let next = scheduler.pop_next_scheduled_message().unwrap(); - assert_eq!(next, msg2); - assert_eq!(scheduler.messages_blocked(), 0); - } - - #[test] - fn test_multiple_blocked_messages() { - let mut scheduler = CommitSchedulerInner::new(); - let pubkey = pubkey!("1111111111111111111111111111111111111111111"); - let msg1 = create_test_message(1, &[pubkey]); - let msg2 = create_test_message(2, &[pubkey]); - let msg3 = create_test_message(3, &[pubkey]); - - // First message executes immediately - let executed = scheduler.schedule(msg1.clone()).unwrap(); - // Others get blocked - assert!(scheduler.schedule(msg2.clone()).is_none()); - assert!(scheduler.schedule(msg3.clone()).is_none()); - assert_eq!(scheduler.messages_blocked(), 2); - - // Complete first message - scheduler.complete(&executed.scheduled_l1_message); - - // Second message should now be available - let expected_msg2 = scheduler.pop_next_scheduled_message().unwrap(); - assert_eq!(expected_msg2, msg2); - assert_eq!(scheduler.messages_blocked(), 1); - - // Complete second message - scheduler.complete(&expected_msg2.scheduled_l1_message); - - // Third message should now be available - let expected_msg3 = scheduler.pop_next_scheduled_message().unwrap(); - assert_eq!(expected_msg3, msg3); - assert_eq!(scheduler.messages_blocked(), 0); - } -} - -#[cfg(test)] -mod complex_blocking_test { - use solana_pubkey::pubkey; - - use super::*; - - /// Case: - /// executing: `[a1, a2, a3] [b1, b2, b3]` - 1 - /// blocked: `[a1, b1]` - 2 - /// arriving: `[a1, a3]` - 3 - #[test] - fn test_edge_case_1_earlier_message_blocks_later_overlapping() { - let mut scheduler = CommitSchedulerInner::new(); - let a1 = pubkey!("1111111111111111111111111111111111111111111"); - let a2 = pubkey!("21111111111111111111111111111111111111111111"); - let a3 = pubkey!("31111111111111111111111111111111111111111111"); - let b1 = pubkey!("41111111111111111111111111111111111111111111"); - let b2 = pubkey!("51111111111111111111111111111111111111111111"); - let b3 = pubkey!("61111111111111111111111111111111111111111111"); - - // Message 1: [a1, a2, a3] - let msg1_keys = vec![a1, a2, a3]; - let msg1 = create_test_message(1, &msg1_keys); - assert!(scheduler.schedule(msg1.clone()).is_some()); - assert_eq!(scheduler.messages_blocked(), 0); - - // Message 2: [b1, b2, b3] - let msg2_keys = vec![b1, b2, b3]; - let msg2 = create_test_message(2, &msg2_keys); - assert!(scheduler.schedule(msg2.clone()).is_some()); - assert_eq!(scheduler.messages_blocked(), 0); - - // Message 3: [a1, b1] - blocked by msg1 & msg2 - let msg3_keys = vec![a1, b1]; - let msg3 = create_test_message(3, &msg3_keys); - assert!(scheduler.schedule(msg3.clone()).is_none()); - assert_eq!(scheduler.messages_blocked(), 1); - - // Message 4: [a1, a3] - blocked by msg1 & msg3 - let msg4_keys = vec![a1, a3]; - let msg4 = create_test_message(4, &msg4_keys); - assert!(scheduler.schedule(msg4.clone()).is_none()); - assert_eq!(scheduler.messages_blocked(), 2); - - // Complete msg1 - scheduler.complete(&msg1.scheduled_l1_message); - // None of the messages can execute yet - // msg3 is blocked msg2 - // msg4 is blocked by msg3 - assert!(scheduler.pop_next_scheduled_message().is_none()); - - // Complete msg2 - scheduler.complete(&msg2.scheduled_l1_message); - // Now msg3 is unblocked - let next = scheduler.pop_next_scheduled_message().unwrap(); - assert_eq!(next, msg3); - assert_eq!(scheduler.messages_blocked(), 1); - // Complete msg3 - scheduler.complete(&next.scheduled_l1_message); - - // Now msg4 should be available - let next = scheduler.pop_next_scheduled_message().unwrap(); - assert_eq!(next, msg4); - assert_eq!(scheduler.messages_blocked(), 0); - } - - /// Case: - /// executing: `[a1, a2, a3]` - /// blocked: `[c1, a1]` - /// arriving: `[c2, c1]` - /// `[c2, c1]` - Even there's no overlaps with executing - #[test] - fn test_edge_case_2_indirect_blocking_through_shared_key() { - let mut scheduler = CommitSchedulerInner::new(); - let a1 = pubkey!("1111111111111111111111111111111111111111111"); - let a2 = pubkey!("21111111111111111111111111111111111111111111"); - let a3 = pubkey!("31111111111111111111111111111111111111111111"); - let c1 = pubkey!("41111111111111111111111111111111111111111111"); - let c2 = pubkey!("51111111111111111111111111111111111111111111"); - - // Message 1: [a1, a2, a3] (executing) - let msg1_keys = vec![a1, a2, a3]; - let msg1 = create_test_message(1, &msg1_keys); - - // Message 2: [c1, a1] (blocked by msg1) - let msg2_keys = vec![c1, a1]; - let msg2 = create_test_message(2, &msg2_keys); - - // Message 3: [c2, c1] (arriving later) - let msg3_keys = vec![c2, c1]; - let msg3 = create_test_message(3, &msg3_keys); - - // Schedule msg1 (executes immediately) - let executed_msg1 = scheduler.schedule(msg1.clone()).unwrap(); - assert_eq!(executed_msg1, msg1); - - // Schedule msg2 (gets blocked) - assert!(scheduler.schedule(msg2.clone()).is_none()); - assert_eq!(scheduler.messages_blocked(), 1); - - // Schedule msg3 (gets blocked, even though c2 is available) - assert!(scheduler.schedule(msg3.clone()).is_none()); - assert_eq!(scheduler.messages_blocked(), 2); - - // Complete msg1 - scheduler.complete(&executed_msg1.scheduled_l1_message); - - // Now only msg2 should be available (not msg3) - let expected_msg2 = scheduler.pop_next_scheduled_message().unwrap(); - assert_eq!(expected_msg2, msg2); - assert_eq!(scheduler.messages_blocked(), 1); - // msg 3 still should be blocked - assert_eq!(scheduler.pop_next_scheduled_message(), None); - - // Complete msg2 - scheduler.complete(&expected_msg2.scheduled_l1_message); - - // Now msg3 should be available - let expected_msg3 = scheduler.pop_next_scheduled_message().unwrap(); - assert_eq!(expected_msg3, msg3); - assert_eq!(scheduler.messages_blocked(), 0); - } - - #[test] - fn test_complex_contention_scenario() { - let mut scheduler = CommitSchedulerInner::new(); - let a = pubkey!("1111111111111111111111111111111111111111111"); - let b = pubkey!("21111111111111111111111111111111111111111111"); - let c = pubkey!("31111111111111111111111111111111111111111111"); - - // Messages with various key combinations - let msg1 = create_test_message(1, &[a, b]); - let msg2 = create_test_message(2, &[a, c]); - let msg3 = create_test_message(3, &[c]); - let msg4 = create_test_message(4, &[b]); - let msg5 = create_test_message(5, &[a]); - - // msg1 executes immediately - let executed1 = scheduler.schedule(msg1.clone()).unwrap(); - // Others get blocked - assert!(scheduler.schedule(msg2.clone()).is_none()); - assert!(scheduler.schedule(msg3.clone()).is_none()); - assert!(scheduler.schedule(msg4.clone()).is_none()); - assert!(scheduler.schedule(msg5.clone()).is_none()); - assert_eq!(scheduler.messages_blocked(), 4); - - // Complete msg1 - scheduler.complete(&executed1.scheduled_l1_message); - - // msg2 and msg4 should be available (they don't conflict) - let next_msgs = [ - scheduler.pop_next_scheduled_message().unwrap(), - scheduler.pop_next_scheduled_message().unwrap(), - ]; - assert!(next_msgs.contains(&msg2)); - assert!(next_msgs.contains(&msg4)); - assert_eq!(scheduler.messages_blocked(), 2); - - // Complete msg2 - scheduler.complete(&msg2.scheduled_l1_message); - // msg2 and msg4 should be available (they don't conflict) - let next_messages = [ - scheduler.pop_next_scheduled_message().unwrap(), - scheduler.pop_next_scheduled_message().unwrap(), - ]; - assert!(next_messages.contains(&msg3)); - assert!(next_messages.contains(&msg5)); - assert_eq!(scheduler.messages_blocked(), 0); - } -} - -#[cfg(test)] -mod edge_cases_test { - use magicblock_program::magic_scheduled_l1_message::MagicL1Message; - use solana_pubkey::pubkey; - - use super::*; - - #[test] - fn test_message_without_pubkeys() { - let mut scheduler = CommitSchedulerInner::new(); - let mut msg = create_test_message(1, &[]); - msg.scheduled_l1_message.l1_message = MagicL1Message::L1Actions(vec![]); - - // Should execute immediately since it has no pubkeys - assert!(scheduler.schedule(msg.clone()).is_some()); - assert_eq!(scheduler.messages_blocked(), 0); - } - - #[test] - fn test_completion_without_scheduling() { - let mut scheduler = CommitSchedulerInner::new(); - let msg = create_test_message( - 1, - &[pubkey!("11111111111111111111111111111111")], - ); - - // Completing a message that wasn't scheduled should panic - let result = std::panic::catch_unwind(move || { - scheduler.complete(&msg.scheduled_l1_message) - }); - assert!(result.is_err()); - } -} - -// Helper function to create test messages -#[cfg(test)] -pub(crate) fn create_test_message( - id: u64, - pubkeys: &[Pubkey], -) -> ScheduledL1MessageWrapper { - use magicblock_program::magic_scheduled_l1_message::{ - CommitType, CommittedAccountV2, MagicL1Message, - }; - use solana_account::Account; - use solana_sdk::{hash::Hash, transaction::Transaction}; - - use crate::types::TriggerType; - - let mut message = ScheduledL1Message { - id, - slot: 0, - blockhash: Hash::default(), - action_sent_transaction: Transaction::default(), - payer: Pubkey::default(), - l1_message: MagicL1Message::L1Actions(vec![]), - }; - - // Only set pubkeys if provided - if !pubkeys.is_empty() { - let committed_accounts = pubkeys - .iter() - .map(|&pubkey| CommittedAccountV2 { - pubkey, - account: Account::default(), - }) - .collect(); - - message.l1_message = - MagicL1Message::Commit(CommitType::Standalone(committed_accounts)); - } - - ScheduledL1MessageWrapper { - scheduled_l1_message: message, - feepayers: vec![], - excluded_pubkeys: vec![], - trigger_type: TriggerType::OffChain, - } -} diff --git a/magicblock-committor-service/src/committor_processor.rs b/magicblock-committor-service/src/committor_processor.rs index 8d90ff1b5..65093a672 100644 --- a/magicblock-committor-service/src/committor_processor.rs +++ b/magicblock-committor-service/src/committor_processor.rs @@ -11,17 +11,17 @@ use solana_sdk::{ use tokio::sync::broadcast; use crate::{ - commit_scheduler::{ - db::DummyDB, BroadcastedMessageExecutionResult, CommitScheduler, - }, compute_budget::ComputeBudgetConfig, config::ChainConfig, error::CommittorServiceResult, + intent_execution_manager::{ + db::DummyDB, BroadcastedIntentExecutionResult, IntentExecutionManager, + }, persist::{ - CommitStatusRow, L1MessagePersister, L1MessagesPersisterIface, + CommitStatusRow, IntentPersister, IntentPersisterImpl, MessageSignatures, }, - types::ScheduledL1MessageWrapper, + types::ScheduledBaseIntentWrapper, }; pub(crate) struct CommittorProcessor { @@ -29,8 +29,8 @@ pub(crate) struct CommittorProcessor { pub(crate) table_mania: TableMania, pub(crate) authority: Keypair, pub(crate) compute_budget_config: ComputeBudgetConfig, - persister: L1MessagePersister, - commits_scheduler: CommitScheduler, + persister: IntentPersisterImpl, + commits_scheduler: IntentExecutionManager, } impl CommittorProcessor { @@ -60,10 +60,10 @@ impl CommittorProcessor { ); // Create commit persister - let persister = L1MessagePersister::try_new(persist_file)?; + let persister = IntentPersisterImpl::try_new(persist_file)?; // Create commit scheduler - let commits_scheduler = CommitScheduler::new( + let commits_scheduler = IntentExecutionManager::new( magic_block_rpc_client.clone(), DummyDB::new(), Some(persister.clone()), @@ -127,15 +127,16 @@ impl CommittorProcessor { Ok(signatures) } - pub async fn commit_l1_messages( + pub async fn schedule_base_intents( &self, - l1_messages: Vec, + base_intents: Vec, ) { - let l1_messages_inner = l1_messages + let intents = base_intents .iter() - .map(|l1_message| l1_message.scheduled_l1_message.clone()) + .map(|l1_message| l1_message.inner.clone()) .collect::>(); - if let Err(err) = self.persister.start_l1_messages(&l1_messages_inner) { + if let Err(err) = self.persister.start_base_intents(&intents) + { // We will still try to perform the commits, but the fact that we cannot // persist the intent is very serious and we should probably restart the // valiator @@ -145,16 +146,16 @@ impl CommittorProcessor { ); }; - if let Err(err) = self.commits_scheduler.schedule(l1_messages).await { + if let Err(err) = self.commits_scheduler.schedule(base_intents).await { // CommittorService broken panic!("Failed to schedule L1 message: {}", err); } } - /// Creates a subscription for results of L1Message execution + /// Creates a subscription for results of BaseIntent execution pub fn subscribe_for_results( &self, - ) -> broadcast::Receiver { + ) -> broadcast::Receiver { self.commits_scheduler.subscribe_for_results() } } diff --git a/magicblock-committor-service/src/commit_scheduler.rs b/magicblock-committor-service/src/intent_execution_manager.rs similarity index 55% rename from magicblock-committor-service/src/commit_scheduler.rs rename to magicblock-committor-service/src/intent_execution_manager.rs index 4aeb2676b..a09202d99 100644 --- a/magicblock-committor-service/src/commit_scheduler.rs +++ b/magicblock-committor-service/src/intent_execution_manager.rs @@ -1,40 +1,41 @@ -pub mod commit_id_tracker; -pub(crate) mod commit_scheduler_inner; -mod commit_scheduler_worker; -pub(crate) mod db; // TODO(edwin): define visibility +pub(crate) mod db; +mod intent_execution_engine; +pub(crate) mod intent_scheduler; // TODO(edwin): define visibility use std::sync::Arc; -pub use commit_scheduler_worker::{ - BroadcastedMessageExecutionResult, ExecutionOutputWrapper, +pub use intent_execution_engine::{ + BroadcastedIntentExecutionResult, ExecutionOutputWrapper, }; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; use tokio::sync::{broadcast, mpsc, mpsc::error::TrySendError}; use crate::{ - commit_scheduler::{ - commit_id_tracker::CommitIdTrackerImpl, - commit_scheduler_worker::{CommitSchedulerWorker, ResultSubscriber}, + intent_execution_manager::{ db::DB, + intent_execution_engine::{IntentExecutionEngine, ResultSubscriber}, }, - message_executor::message_executor_factory::L1MessageExecutorFactory, - persist::L1MessagesPersisterIface, - types::ScheduledL1MessageWrapper, + intent_executor::{ + commit_id_fetcher::CommitIdTrackerImpl, + intent_executor_factory::IntentExecutorFactoryImpl, + }, + persist::IntentPersister, + types::ScheduledBaseIntentWrapper, ComputeBudgetConfig, }; -pub struct CommitScheduler { +pub struct IntentExecutionManager { db: Arc, result_subscriber: ResultSubscriber, - message_sender: mpsc::Sender, + intent_sender: mpsc::Sender, } -impl CommitScheduler { - pub fn new( +impl IntentExecutionManager { + pub fn new( rpc_client: MagicblockRpcClient, db: D, - l1_message_persister: Option

, + intent_persister: Option

, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, ) -> Self { @@ -42,7 +43,7 @@ impl CommitScheduler { let commit_id_tracker = Arc::new(CommitIdTrackerImpl::new(rpc_client.clone())); - let executor_factory = L1MessageExecutorFactory { + let executor_factory = IntentExecutorFactoryImpl { rpc_client, table_mania, compute_budget_config, @@ -50,10 +51,10 @@ impl CommitScheduler { }; let (sender, receiver) = mpsc::channel(1000); - let worker = CommitSchedulerWorker::new( + let worker = IntentExecutionEngine::new( db.clone(), executor_factory, - l1_message_persister, + intent_persister, receiver, ); // TODO(edwin): add concellation logic @@ -61,29 +62,29 @@ impl CommitScheduler { Self { db, - message_sender: sender, + intent_sender: sender, result_subscriber, } } - /// Schedules [`ScheduledL1Message`] message to be executed - /// In case the channel is full we write message to DB - /// Messages will be extracted and handled in the [`CommitSchedulerWorker`] + /// Schedules [`ScheduledBaseIntent`] intent to be executed + /// In case the channel is full we write intent to DB + /// Intents will be extracted and handled in the [`IntentExecutionEngine`] pub async fn schedule( &self, - l1_messages: Vec, + base_intents: Vec, ) -> Result<(), Error> { // If db not empty push el-t there // This means that at some point channel got full // Worker first will clean-up channel, and then DB. // Pushing into channel would break order of commits if !self.db.is_empty() { - self.db.store_l1_messages(l1_messages).await?; + self.db.store_base_intents(base_intents).await?; return Ok(()); } - for el in l1_messages { - let err = if let Err(err) = self.message_sender.try_send(el) { + for el in base_intents { + let err = if let Err(err) = self.intent_sender.try_send(el) { err } else { continue; @@ -92,7 +93,7 @@ impl CommitScheduler { match err { TrySendError::Closed(_) => Err(Error::ChannelClosed), TrySendError::Full(el) => { - self.db.store_l1_message(el).await.map_err(Error::from) + self.db.store_base_intent(el).await.map_err(Error::from) } }?; } @@ -100,10 +101,10 @@ impl CommitScheduler { Ok(()) } - /// Creates a subscription for results of L1Message execution + /// Creates a subscription for results of BaseIntent execution pub fn subscribe_for_results( &self, - ) -> broadcast::Receiver { + ) -> broadcast::Receiver { self.result_subscriber.subscribe() } } diff --git a/magicblock-committor-service/src/commit_scheduler/db.rs b/magicblock-committor-service/src/intent_execution_manager/db.rs similarity index 60% rename from magicblock-committor-service/src/commit_scheduler/db.rs rename to magicblock-committor-service/src/intent_execution_manager/db.rs index 1a232defa..429285e68 100644 --- a/magicblock-committor-service/src/commit_scheduler/db.rs +++ b/magicblock-committor-service/src/intent_execution_manager/db.rs @@ -1,31 +1,32 @@ use std::{collections::VecDeque, sync::Mutex}; -/// DB for storing messages that overflow committor channel +/// DB for storing intents that overflow committor channel use async_trait::async_trait; -use crate::types::ScheduledL1MessageWrapper; +use crate::types::ScheduledBaseIntentWrapper; const POISONED_MUTEX_MSG: &str = "Mutex poisoned"; #[async_trait] pub trait DB: Send + Sync + 'static { - async fn store_l1_message( + async fn store_base_intent( &self, - l1_message: ScheduledL1MessageWrapper, + base_intent: ScheduledBaseIntentWrapper, ) -> DBResult<()>; - async fn store_l1_messages( + async fn store_base_intents( &self, - l1_messages: Vec, + base_intents: Vec, ) -> DBResult<()>; - /// Return message with smallest bundle_id - async fn pop_l1_message( + + /// Returns intent with smallest id + async fn pop_base_intent( &self, - ) -> DBResult>; + ) -> DBResult>; fn is_empty(&self) -> bool; } pub(crate) struct DummyDB { - db: Mutex>, + db: Mutex>, } impl DummyDB { @@ -38,31 +39,31 @@ impl DummyDB { #[async_trait] impl DB for DummyDB { - async fn store_l1_message( + async fn store_base_intent( &self, - l1_message: ScheduledL1MessageWrapper, + base_intent: ScheduledBaseIntentWrapper, ) -> DBResult<()> { self.db .lock() .expect(POISONED_MUTEX_MSG) - .push_back(l1_message); + .push_back(base_intent); Ok(()) } - async fn store_l1_messages( + async fn store_base_intents( &self, - l1_messages: Vec, + base_intents: Vec, ) -> DBResult<()> { self.db .lock() .expect(POISONED_MUTEX_MSG) - .extend(l1_messages.into_iter()); + .extend(base_intents.into_iter()); Ok(()) } - async fn pop_l1_message( + async fn pop_base_intent( &self, - ) -> DBResult> { + ) -> DBResult> { Ok(self.db.lock().expect(POISONED_MUTEX_MSG).pop_front()) } diff --git a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs similarity index 73% rename from magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs rename to magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index d42aa1dc0..4da7ee16e 100644 --- a/magicblock-committor-service/src/commit_scheduler/commit_scheduler_worker.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -16,22 +16,22 @@ use tokio::{ }; use crate::{ - commit_scheduler::{ - commit_scheduler_inner::{CommitSchedulerInner, POISONED_INNER_MSG}, + intent_execution_manager::{ db::DB, + intent_scheduler::{IntentScheduler, POISONED_INNER_MSG}, Error, }, - message_executor::{ - error::MessageExecutorResult, - message_executor_factory::MessageExecutorFactory, ExecutionOutput, - MessageExecutor, + intent_executor::{ + error::IntentExecutorResult, + intent_executor_factory::IntentExecutorFactory, ExecutionOutput, + IntentExecutor, }, - persist::L1MessagesPersisterIface, - types::{ScheduledL1MessageWrapper, TriggerType}, + persist::IntentPersister, + types::{ScheduledBaseIntentWrapper, TriggerType}, }; const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; -/// Max number of executors that can send messages in parallel to L1 +/// Max number of executors that can send messages in parallel to Base layer const MAX_EXECUTORS: u8 = 50; // TODO(edwin): rename @@ -44,57 +44,57 @@ pub struct ExecutionOutputWrapper { pub trigger_type: TriggerType, } -pub type BroadcastedError = (u64, Arc); +pub type BroadcastedError = (u64, Arc); -pub type BroadcastedMessageExecutionResult = - MessageExecutorResult; +pub type BroadcastedIntentExecutionResult = + IntentExecutorResult; /// Struct that exposes only `subscribe` method of `broadcast::Sender` for better isolation pub struct ResultSubscriber( - broadcast::Sender, + broadcast::Sender, ); impl ResultSubscriber { pub fn subscribe( &self, - ) -> broadcast::Receiver { + ) -> broadcast::Receiver { self.0.subscribe() } } -pub(crate) struct CommitSchedulerWorker { +pub(crate) struct IntentExecutionEngine { db: Arc, executor_factory: F, - l1_messages_persister: Option

, - receiver: mpsc::Receiver, + intents_persister: Option

, + receiver: mpsc::Receiver, - inner: Arc>, + inner: Arc>, running_executors: FuturesUnordered>, executors_semaphore: Arc, } -impl CommitSchedulerWorker +impl IntentExecutionEngine where D: DB, - P: L1MessagesPersisterIface, - F: MessageExecutorFactory + Send + Sync + 'static, - E: MessageExecutor, + P: IntentPersister, + F: IntentExecutorFactory + Send + Sync + 'static, + E: IntentExecutor, { pub fn new( db: Arc, executor_factory: F, - l1_messages_persister: Option

, - receiver: mpsc::Receiver, + intents_persister: Option

, + receiver: mpsc::Receiver, ) -> Self { Self { db, - l1_messages_persister, + intents_persister, executor_factory, receiver, running_executors: FuturesUnordered::new(), executors_semaphore: Arc::new(Semaphore::new( MAX_EXECUTORS as usize, )), - inner: Arc::new(Mutex::new(CommitSchedulerInner::new())), + inner: Arc::new(Mutex::new(IntentScheduler::new())), } } @@ -107,24 +107,24 @@ where } /// Main loop that: - /// 1. Handles & schedules incoming message + /// 1. Handles & schedules incoming intents /// 2. Finds available executor - /// 3. Spawns execution of scheduled message + /// 3. Spawns execution of scheduled intent async fn main_loop( mut self, - result_sender: broadcast::Sender, + result_sender: broadcast::Sender, ) { loop { - let l1_message = match self.next_scheduled_message().await { + let intent = match self.next_scheduled_intent().await { Ok(value) => value, Err(err) => { - error!("Failed to get next message: {}", err); + error!("Failed to get next intent: {}", err); break; } }; - let Some(l1_message) = l1_message else { - // Messages are blocked, skipping - info!("Could not schedule any messages, as all of them are blocked!"); + let Some(intent) = intent else { + // intents are blocked, skipping + info!("Could not schedule any intents, as all of them are blocked!"); continue; }; @@ -138,13 +138,13 @@ where // Spawn executor let executor = self.executor_factory.create_instance(); - let persister = self.l1_messages_persister.clone(); + let persister = self.intents_persister.clone(); let inner = self.inner.clone(); let handle = tokio::spawn(Self::execute( executor, persister, - l1_message, + intent, inner, permit, result_sender.clone(), @@ -154,23 +154,23 @@ where } } - /// Returns [`ScheduledL1MessageWrapper`] or None if all messages are blocked - async fn next_scheduled_message( + /// Returns [`ScheduledBaseIntentWrapper`] or None if all intents are blocked + async fn next_scheduled_intent( &mut self, - ) -> Result, Error> { - // Limit on number of messages that can be stored in scheduler + ) -> Result, Error> { + // Limit on number of intents that can be stored in scheduler const SCHEDULER_CAPACITY: usize = 1000; let can_receive = || { - let num_blocked_messages = self + let num_blocked_intents = self .inner .lock() .expect(POISONED_INNER_MSG) - .messages_blocked(); - if num_blocked_messages < SCHEDULER_CAPACITY { + .intents_blocked(); + if num_blocked_intents < SCHEDULER_CAPACITY { true } else { - warn!("Scheduler capacity exceeded: {}", num_blocked_messages); + warn!("Scheduler capacity exceeded: {}", num_blocked_intents); false } }; @@ -178,43 +178,43 @@ where let running_executors = &mut self.running_executors; let receiver = &mut self.receiver; let db = &self.db; - let message = tokio::select! { - // Notify polled first to prioritize unblocked messages over new one + let intent = tokio::select! { + // Notify polled first to prioritize unblocked intents over new one biased; Some(result) = running_executors.next() => { if let Err(err) = result { error!("Executor failed to complete: {}", err); }; - trace!("Worker executed L1Message, fetching new available one"); - self.inner.lock().expect(POISONED_INNER_MSG).pop_next_scheduled_message() + trace!("Worker executed BaseIntent, fetching new available one"); + self.inner.lock().expect(POISONED_INNER_MSG).pop_next_scheduled_intent() }, - result = Self::get_new_message(receiver, db), if can_receive() => { - let l1_message = result?; - self.inner.lock().expect(POISONED_INNER_MSG).schedule(l1_message) + result = Self::get_new_intent(receiver, db), if can_receive() => { + let intent = result?; + self.inner.lock().expect(POISONED_INNER_MSG).schedule(intent) }, else => { // Shouldn't be possible // If no executors spawned -> we can receive // If can't receive -> there are running executors - unreachable!("next_scheduled_message") + unreachable!("next_scheduled_intent") } }; - Ok(message) + Ok(intent) } - /// Returns [`ScheduledL1Message`] from external channel - async fn get_new_message( - receiver: &mut mpsc::Receiver, + /// Returns [`ScheduledBaseIntentWrapper`] from external channel + async fn get_new_intent( + receiver: &mut mpsc::Receiver, db: &Arc, - ) -> Result { + ) -> Result { match receiver.try_recv() { Ok(val) => Ok(val), Err(TryRecvError::Empty) => { // Worker either cleaned-up congested channel and now need to clean-up DB // or we're just waiting on empty channel - if let Some(l1_message) = db.pop_l1_message().await? { - Ok(l1_message) + if let Some(base_intent) = db.pop_base_intent().await? { + Ok(base_intent) } else { receiver.recv().await.ok_or(Error::ChannelClosed) } @@ -223,66 +223,65 @@ where } } - /// Wrapper on [`L1MessageExecutor`] that handles its results and drops execution permit + /// Wrapper on [`IntentExecutor`] that handles its results and drops execution permit async fn execute( executor: E, persister: Option

, - l1_message: ScheduledL1MessageWrapper, - inner_scheduler: Arc>, + intent: ScheduledBaseIntentWrapper, + inner_scheduler: Arc>, execution_permit: OwnedSemaphorePermit, - result_sender: broadcast::Sender, + result_sender: broadcast::Sender, ) { let result = executor - .execute(l1_message.scheduled_l1_message.clone(), persister) + .execute(intent.inner.clone(), persister) .await - .inspect_err(|err| error!("Failed to execute L1Message: {:?}", err)) - .map(|raw_result| { - Self::map_execution_outcome(&l1_message, raw_result) + .inspect_err(|err| { + error!("Failed to execute BaseIntent: {:?}", err) }) - .map_err(|err| (l1_message.scheduled_l1_message.id, Arc::new(err))); + .map(|raw_result| Self::map_execution_outcome(&intent, raw_result)) + .map_err(|err| (intent.inner.id, Arc::new(err))); // Broadcast result to subscribers if let Err(err) = result_sender.send(result) { error!("Failed to broadcast result: {}", err); } - // Remove executed task from Scheduler to unblock other messages + // Remove executed task from Scheduler to unblock other intents inner_scheduler .lock() .expect(POISONED_INNER_MSG) - .complete(&l1_message.scheduled_l1_message); + .complete(&intent.inner); // Free worker drop(execution_permit); } - /// Maps output of `L1MessageExecutor` to final result + /// Maps output of `IntentExecutor` to final result fn map_execution_outcome( - l1_message: &ScheduledL1MessageWrapper, + intent: &ScheduledBaseIntentWrapper, raw_outcome: ExecutionOutput, ) -> ExecutionOutputWrapper { - let ScheduledL1MessageWrapper { - scheduled_l1_message, + let ScheduledBaseIntentWrapper { + inner, feepayers, excluded_pubkeys, trigger_type, - } = l1_message; - let included_pubkeys = if let Some(included_pubkeys) = - scheduled_l1_message.get_committed_pubkeys() - { - included_pubkeys - } else { - // Case with standalone actions - vec![] - }; - let requested_undelegation = scheduled_l1_message.is_undelegate(); + } = intent; + let included_pubkeys = + if let Some(included_pubkeys) = inner.get_committed_pubkeys() { + included_pubkeys + } else { + // Case with standalone actions + vec![] + }; + let requested_undelegation = inner.is_undelegate(); let chain_signatures = vec![raw_outcome.commit_signature, raw_outcome.finalize_signature]; let sent_commit = SentCommit { - message_id: scheduled_l1_message.id, - slot: scheduled_l1_message.slot, - blockhash: scheduled_l1_message.blockhash, - payer: scheduled_l1_message.payer, + message_id: inner.id, + slot: inner.slot, + blockhash: inner.blockhash, + payer: inner.payer, included_pubkeys, excluded_pubkeys: excluded_pubkeys.clone(), feepayers: HashSet::from_iter(feepayers.iter().cloned()), @@ -291,11 +290,9 @@ where }; ExecutionOutputWrapper { - id: scheduled_l1_message.id, + id: inner.id, output: raw_outcome, - action_sent_transaction: scheduled_l1_message - .action_sent_transaction - .clone(), + action_sent_transaction: inner.action_sent_transaction.clone(), trigger_type: *trigger_type, sent_commit, } @@ -315,47 +312,49 @@ mod tests { }; use async_trait::async_trait; - use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; + use magicblock_program::magic_scheduled_base_intent::ScheduledBaseIntent; use solana_pubkey::{pubkey, Pubkey}; use solana_sdk::{signature::Signature, signer::SignerError}; use tokio::{sync::mpsc, time::sleep}; use super::*; use crate::{ - commit_scheduler::{ - commit_id_tracker::{CommitIdFetcher, CommitIdTrackerResult}, - commit_scheduler_inner::create_test_message, + intent_execution_manager::{ db::{DummyDB, DB}, + intent_scheduler::create_test_intent, }, - message_executor::error::{ - Error as ExecutorError, InternalError, MessageExecutorResult, + intent_executor::{ + commit_id_fetcher::{CommitIdFetcher, CommitIdTrackerResult}, + error::{ + Error as ExecutorError, IntentExecutorResult, InternalError, + }, }, - persist::L1MessagePersister, + persist::IntentPersisterImpl, }; - type MockCommitSchedulerWorker = CommitSchedulerWorker< + type MockIntentExecutionEngine = IntentExecutionEngine< DummyDB, - L1MessagePersister, - MockMessageExecutorFactory, + IntentPersisterImpl, + MockIntentExecutorFactory, >; - fn setup_worker( + fn setup_engine( should_fail: bool, ) -> ( - mpsc::Sender, - MockCommitSchedulerWorker, + mpsc::Sender, + MockIntentExecutionEngine, ) { let (sender, receiver) = mpsc::channel(1000); let db = Arc::new(DummyDB::new()); let executor_factory = if !should_fail { - MockMessageExecutorFactory::new() + MockIntentExecutorFactory::new() } else { - MockMessageExecutorFactory::new_failing() + MockIntentExecutorFactory::new_failing() }; - let worker = CommitSchedulerWorker::new( + let worker = IntentExecutionEngine::new( db.clone(), executor_factory, - None::, + None::, receiver, ); @@ -364,12 +363,12 @@ mod tests { #[tokio::test] async fn test_worker_processes_messages() { - let (sender, worker) = setup_worker(false); + let (sender, worker) = setup_engine(false); let result_subscriber = worker.spawn(); let mut result_receiver = result_subscriber.subscribe(); // Send a test message - let msg = create_test_message( + let msg = create_test_intent( 1, &[pubkey!("1111111111111111111111111111111111111111111")], ); @@ -384,14 +383,14 @@ mod tests { #[tokio::test] async fn test_worker_handles_conflicting_messages() { - let (sender, worker) = setup_worker(false); + let (sender, worker) = setup_engine(false); let result_subscriber = worker.spawn(); let mut result_receiver = result_subscriber.subscribe(); // Send two conflicting messages let pubkey = pubkey!("1111111111111111111111111111111111111111111"); - let msg1 = create_test_message(1, &[pubkey]); - let msg2 = create_test_message(2, &[pubkey]); + let msg1 = create_test_intent(1, &[pubkey]); + let msg2 = create_test_intent(2, &[pubkey]); sender.send(msg1.clone()).await.unwrap(); sender.send(msg2.clone()).await.unwrap(); @@ -409,12 +408,12 @@ mod tests { #[tokio::test] async fn test_worker_handles_executor_failure() { - let (sender, worker) = setup_worker(true); + let (sender, worker) = setup_engine(true); let result_subscriber = worker.spawn(); let mut result_receiver = result_subscriber.subscribe(); // Send a test message that will fail - let msg = create_test_message( + let msg = create_test_intent( 1, &[pubkey!("1111111111111111111111111111111111111111111")], ); @@ -434,14 +433,14 @@ mod tests { #[tokio::test] async fn test_worker_falls_back_to_db_when_channel_empty() { - let (_sender, worker) = setup_worker(false); + let (_sender, worker) = setup_engine(false); // Add a message to the DB - let msg = create_test_message( + let msg = create_test_intent( 1, &[pubkey!("1111111111111111111111111111111111111111111")], ); - worker.db.store_l1_message(msg.clone()).await.unwrap(); + worker.db.store_base_intent(msg.clone()).await.unwrap(); // Start worker let result_subscriber = worker.spawn(); @@ -458,7 +457,7 @@ mod tests { async fn test_high_throughput_message_processing() { const NUM_MESSAGES: usize = 20; - let (sender, mut worker) = setup_worker(false); + let (sender, mut worker) = setup_engine(false); let active_tasks = Arc::new(AtomicUsize::new(0)); let max_concurrent = Arc::new(AtomicUsize::new(0)); @@ -471,7 +470,7 @@ mod tests { // Send a flood of messages for i in 0..NUM_MESSAGES { - let msg = create_test_message( + let msg = create_test_intent( i as u64, &[pubkey!("1111111111111111111111111111111111111111111")], ); @@ -499,14 +498,14 @@ mod tests { /// Tests that errors from executor propagated gracefully #[tokio::test] async fn test_multiple_failures() { - let (sender, worker) = setup_worker(true); // Worker that always fails + let (sender, worker) = setup_engine(true); // Worker that always fails let result_subscriber = worker.spawn(); let mut result_receiver = result_subscriber.subscribe(); // Send several messages that will fail const NUM_FAILURES: usize = 10; for i in 0..NUM_FAILURES { - let msg = create_test_message( + let msg = create_test_intent( i as u64, &[pubkey!("1111111111111111111111111111111111111111111")], ); @@ -524,7 +523,7 @@ mod tests { async fn test_non_blocking_messages() { const NUM_MESSAGES: u64 = 200; - let (sender, mut worker) = setup_worker(false); + let (sender, mut worker) = setup_engine(false); let active_tasks = Arc::new(AtomicUsize::new(0)); let max_concurrent = Arc::new(AtomicUsize::new(0)); @@ -539,7 +538,7 @@ mod tests { let mut received_ids = HashSet::new(); for i in 0..NUM_MESSAGES { let unique_pubkey = Pubkey::new_unique(); // Each message gets unique key - let msg = create_test_message(i, &[unique_pubkey]); + let msg = create_test_intent(i, &[unique_pubkey]); received_ids.insert(i); sender.send(msg).await.unwrap(); @@ -582,7 +581,7 @@ mod tests { // 30% blocking messages const BLOCKING_RATIO: f32 = 0.3; - let (sender, mut worker) = setup_worker(false); + let (sender, mut worker) = setup_engine(false); let active_tasks = Arc::new(AtomicUsize::new(0)); let max_concurrent = Arc::new(AtomicUsize::new(0)); @@ -605,7 +604,7 @@ mod tests { vec![Pubkey::new_unique()] }; - let msg = create_test_message(i as u64, &pubkeys); + let msg = create_test_intent(i as u64, &pubkeys); sender.send(msg).await.unwrap(); } @@ -627,13 +626,13 @@ mod tests { } // Mock implementations for testing - pub struct MockMessageExecutorFactory { + pub struct MockIntentExecutorFactory { should_fail: bool, active_tasks: Option>, max_concurrent: Option>, } - impl MockMessageExecutorFactory { + impl MockIntentExecutorFactory { pub fn new() -> Self { Self { should_fail: false, @@ -660,11 +659,11 @@ mod tests { } } - impl MessageExecutorFactory for MockMessageExecutorFactory { - type Executor = MockMessageExecutor; + impl IntentExecutorFactory for MockIntentExecutorFactory { + type Executor = MockIntentExecutor; fn create_instance(&self) -> Self::Executor { - MockMessageExecutor { + MockIntentExecutor { should_fail: self.should_fail, active_tasks: self.active_tasks.clone(), max_concurrent: self.max_concurrent.clone(), @@ -672,13 +671,13 @@ mod tests { } } - pub struct MockMessageExecutor { + pub struct MockIntentExecutor { should_fail: bool, active_tasks: Option>, max_concurrent: Option>, } - impl MockMessageExecutor { + impl MockIntentExecutor { fn on_task_started(&self) { if let (Some(active), Some(max)) = (&self.active_tasks, &self.max_concurrent) @@ -710,12 +709,12 @@ mod tests { } #[async_trait] - impl MessageExecutor for MockMessageExecutor { - async fn execute( + impl IntentExecutor for MockIntentExecutor { + async fn execute( &self, - l1_message: ScheduledL1Message, + base_intent: ScheduledBaseIntent, _persister: Option

, - ) -> MessageExecutorResult { + ) -> IntentExecutorResult { self.on_task_started(); // Simulate some work diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs new file mode 100644 index 000000000..c960651bd --- /dev/null +++ b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs @@ -0,0 +1,578 @@ +use std::collections::{hash_map::Entry, HashMap, VecDeque}; + +use log::warn; +use magicblock_program::magic_scheduled_base_intent::ScheduledBaseIntent; +use solana_pubkey::Pubkey; + +use crate::types::ScheduledBaseIntentWrapper; + +pub(crate) const POISONED_INNER_MSG: &str = + "Mutex on CommitSchedulerInner is poisoned."; + +type IntentID = u64; +struct IntentMeta { + num_keys: usize, + intent: ScheduledBaseIntentWrapper, +} + +/// A scheduler that ensures mutually exclusive access to pubkeys across intents +/// +/// # Data Structures +/// +/// 1. `blocked_keys`: Maintains FIFO queues of intents waiting for each pubkey +/// - Key: Pubkey +/// - Value: Queue of IntentIDs in arrival order +/// +/// 2. `blocked_intents`: Stores metadata for all blocked intents +/// - Key: IntentID +/// - Value: Intent metadata including original intent +/// +/// # Scheduling Logic +/// +/// 1. On intent arrival: +/// - Check if any required pubkey exists in `blocked_keys` +/// - If conflicted: Add intent to all relevant pubkey queues +/// - Else: Start executing immediately +/// +/// 2. On intent completion: +/// - Pop 1st el-t from corresponding to Intent `blocked_keys` queues, +/// Note: `blocked_keys[msg.keys]` == msg.id +/// - This moves forward other intents that were blocked by this one. +/// +/// 3. On popping next intent to be executed: +/// - Find the first intent in `blocked_intents` which +/// has all of its pubkeys unblocked, +/// i.e they are first at corresponding queues +/// +/// Some examples/edge cases: +/// (1) Assume `t1`: +/// executing: `[a1, a2, a3] [b1, b2, b3]` - 1 +/// blocked: `[a1, b1]` - 2 +/// arriving: `[a1, a3]` - 3 +/// +/// `t2`: +/// executing: `[b1, b2, b3]` +/// blocked: `[a1, b1]` +/// `[a1, a3]` - CAN't be executed, since `[a1, b1]` needs to be sent first, it has earlier state. +/// +/// (2) Assume: +/// executing: `[a1, a2, a3]` +/// blocked: `[c1, a1]` +/// arriving: `[c2, c1]` +/// `[c2, c1]` - Even there's no overlaps with executing +/// we can't proceed since blocked intent has [c1] that has to be executed first +pub(crate) struct IntentScheduler { + blocked_keys: HashMap>, + blocked_intents: HashMap, +} + +impl IntentScheduler { + pub fn new() -> Self { + Self { + blocked_keys: HashMap::new(), + blocked_intents: HashMap::new(), + } + } + + /// Returns [`ScheduledBaseIntent`] if intent can be executed, + /// otherwise consumes it and enqueues + /// + /// CRITICAL: IntentIds should be unique + /// Intent should be scheduled once! + pub fn schedule( + &mut self, + base_intent: ScheduledBaseIntentWrapper, + ) -> Option { + let intent_id = base_intent.inner.id; + if self.blocked_intents.contains_key(&intent_id) { + warn!("Attempt to schedule already scheduled intent!"); + return None; + } + + let Some(pubkeys) = base_intent.inner.get_committed_pubkeys() else { + return Some(base_intent); + }; + + // Check if there are any conflicting keys + let is_conflicting = pubkeys + .iter() + .any(|pubkey| self.blocked_keys.contains_key(pubkey)); + // In any case block the corresponding accounts + pubkeys.iter().for_each(|pubkey| { + self.blocked_keys + .entry(*pubkey) + .or_default() + .push_back(intent_id) + }); + + if is_conflicting { + // Enqueue incoming intent + self.blocked_intents.insert( + intent_id, + IntentMeta { + num_keys: pubkeys.len(), + intent: base_intent, + }, + ); + None + } else { + Some(base_intent) + } + } + + /// Completes Intent, cleaning up data after itself and allowing Intents to move forward + /// NOTE: This doesn't unblock intent, hence Self::intents_blocked will return old value. + /// NOTE: this shall be called on executing intents to finilize their execution. + /// Calling on incorrect `pubkeys` set will result in panic + pub fn complete(&mut self, base_intent: &ScheduledBaseIntent) { + // Release data for completed intent + let intent_id = base_intent.id; + let Some(pubkeys) = base_intent.get_committed_pubkeys() else { + // This means BaseAction, it doesn't have to be scheduled + return; + }; + + pubkeys + .iter() + .for_each(|pubkey| { + let mut occupied = match self.blocked_keys.entry(*pubkey) { + Entry::Vacant(_) => unreachable!("Invariant: queue for conflicting tasks shall exist"), + Entry::Occupied(value) => value + }; + + let blocked_intents: &mut VecDeque = occupied.get_mut(); + let front = blocked_intents.pop_front(); + assert_eq!( + intent_id, + front.expect("Invariant: if intent executing, queue for each account is non-empty"), + "Invariant: executing intent must be first at qeueue" + ); + + if blocked_intents.is_empty() { + occupied.remove(); + } + }); + } + + // Returns [`ScheduledBaseIntent`] that can be executed + pub fn pop_next_scheduled_intent( + &mut self, + ) -> Option { + // TODO(edwin): optimize. Create counter im IntentMeta & update + let mut execute_candidates: HashMap = HashMap::new(); + self.blocked_keys.iter().for_each(|(_, queue)| { + let intent_id = queue + .front() + .expect("Invariant: we maintain ony non-empty queues"); + *execute_candidates.entry(*intent_id).or_default() += 1; + }); + + // NOTE: + // Not all self.blocked_intents would be in execute_candidates + // t1: + // 1: [a, b] + // 2: [a, b] + // 3: [b] + // t2: + // 1: [a, b] - completed + // 2: [a, b] + // 3: [b] + // now 3 is in blocked intents but not in execute candidate + // NOTE: + // Other way around is also true, since execute_candidates also include + // currently executing intents + let candidate = + execute_candidates.iter().find_map(|(id, ready_keys)| { + if let Some(candidate) = self.blocked_intents.get(id) { + if candidate.num_keys.eq(ready_keys) { + Some(id) + } else { + // Not enough keys are ready + None + } + } else { + // This means that this intent id is currently executing & not blocked + None + } + }); + + if let Some(next) = candidate { + Some(self.blocked_intents.remove(next).unwrap().intent) + } else { + None + } + } + + /// Returns number of blocked intents + /// Note: this doesn't include "executing" intents + pub fn intents_blocked(&self) -> usize { + self.blocked_intents.len() + } +} + +/// Set of simple tests +#[cfg(test)] +mod simple_test { + use solana_pubkey::pubkey; + + use super::*; + + #[test] + fn test_empty_scheduler() { + let mut scheduler = IntentScheduler::new(); + assert_eq!(scheduler.intents_blocked(), 0); + assert!(scheduler.pop_next_scheduled_intent().is_none()); + } + + /// Ensure intents with non-conflicting set of keys can run in parallel + #[test] + fn test_non_conflicting_intents() { + let mut scheduler = IntentScheduler::new(); + let msg1 = create_test_intent( + 1, + &[pubkey!("1111111111111111111111111111111111111111111")], + ); + let msg2 = create_test_intent( + 2, + &[pubkey!("22222222222222222222222222222222222222222222")], + ); + + // First intent should execute immediately + assert!(scheduler.schedule(msg1.clone()).is_some()); + // Second intent should also execute immediately + assert!(scheduler.schedule(msg2.clone()).is_some()); + // No intents are blocked + assert_eq!(scheduler.intents_blocked(), 0); + } + + /// Ensure intents conflicting intents get blocked + #[test] + fn test_conflicting_intents() { + const NUM_INTENTS: u64 = 10; + + let mut scheduler = IntentScheduler::new(); + let pubkey = pubkey!("1111111111111111111111111111111111111111111"); + let msg1 = create_test_intent(1, &[pubkey]); + + // First message executes immediately + assert!(scheduler.schedule(msg1).is_some()); + for id in 2..=NUM_INTENTS { + let msg = create_test_intent(id, &[pubkey]); + // intent gets blocked + assert!(scheduler.schedule(msg).is_none()); + } + + // 1 intent executing, NUM_INTENTS - 1 are blocked + assert_eq!(scheduler.intents_blocked() as u64, NUM_INTENTS - 1); + } +} + +/// Set of simple completion tests +#[cfg(test)] +mod completion_simple_test { + use solana_pubkey::pubkey; + + use super::*; + + #[test] + fn test_completion_unblocks_intents() { + let mut scheduler = IntentScheduler::new(); + let pubkey = pubkey!("1111111111111111111111111111111111111111111"); + let msg1 = create_test_intent(1, &[pubkey]); + let msg2 = create_test_intent(2, &[pubkey]); + + // First intent executes immediately + let executed = scheduler.schedule(msg1.clone()).unwrap(); + // Second intent gets blocked + assert!(scheduler.schedule(msg2.clone()).is_none()); + assert_eq!(scheduler.intents_blocked(), 1); + + // Complete first intent + scheduler.complete(&executed.inner); + + let next = scheduler.pop_next_scheduled_intent().unwrap(); + assert_eq!(next, msg2); + assert_eq!(scheduler.intents_blocked(), 0); + } + + #[test] + fn test_multiple_blocked_intents() { + let mut scheduler = IntentScheduler::new(); + let pubkey = pubkey!("1111111111111111111111111111111111111111111"); + let msg1 = create_test_intent(1, &[pubkey]); + let msg2 = create_test_intent(2, &[pubkey]); + let msg3 = create_test_intent(3, &[pubkey]); + + // First intent executes immediately + let executed = scheduler.schedule(msg1.clone()).unwrap(); + // Others get blocked + assert!(scheduler.schedule(msg2.clone()).is_none()); + assert!(scheduler.schedule(msg3.clone()).is_none()); + assert_eq!(scheduler.intents_blocked(), 2); + + // Complete first intent + scheduler.complete(&executed.inner); + + // Second intent should now be available + let expected_msg2 = scheduler.pop_next_scheduled_intent().unwrap(); + assert_eq!(expected_msg2, msg2); + assert_eq!(scheduler.intents_blocked(), 1); + + // Complete second intent + scheduler.complete(&expected_msg2.inner); + + // Third intent should now be available + let expected_msg3 = scheduler.pop_next_scheduled_intent().unwrap(); + assert_eq!(expected_msg3, msg3); + assert_eq!(scheduler.intents_blocked(), 0); + } +} + +#[cfg(test)] +mod complex_blocking_test { + use solana_pubkey::pubkey; + + use super::*; + + /// Case: + /// executing: `[a1, a2, a3] [b1, b2, b3]` - 1 + /// blocked: `[a1, b1]` - 2 + /// arriving: `[a1, a3]` - 3 + #[test] + fn test_edge_case_1_earlier_intent_blocks_later_overlapping() { + let mut scheduler = IntentScheduler::new(); + let a1 = pubkey!("1111111111111111111111111111111111111111111"); + let a2 = pubkey!("21111111111111111111111111111111111111111111"); + let a3 = pubkey!("31111111111111111111111111111111111111111111"); + let b1 = pubkey!("41111111111111111111111111111111111111111111"); + let b2 = pubkey!("51111111111111111111111111111111111111111111"); + let b3 = pubkey!("61111111111111111111111111111111111111111111"); + + // intent 1: [a1, a2, a3] + let msg1_keys = vec![a1, a2, a3]; + let msg1 = create_test_intent(1, &msg1_keys); + assert!(scheduler.schedule(msg1.clone()).is_some()); + assert_eq!(scheduler.intents_blocked(), 0); + + // intent 2: [b1, b2, b3] + let msg2_keys = vec![b1, b2, b3]; + let msg2 = create_test_intent(2, &msg2_keys); + assert!(scheduler.schedule(msg2.clone()).is_some()); + assert_eq!(scheduler.intents_blocked(), 0); + + // intent 3: [a1, b1] - blocked by msg1 & msg2 + let msg3_keys = vec![a1, b1]; + let msg3 = create_test_intent(3, &msg3_keys); + assert!(scheduler.schedule(msg3.clone()).is_none()); + assert_eq!(scheduler.intents_blocked(), 1); + + // intent 4: [a1, a3] - blocked by msg1 & msg3 + let msg4_keys = vec![a1, a3]; + let msg4 = create_test_intent(4, &msg4_keys); + assert!(scheduler.schedule(msg4.clone()).is_none()); + assert_eq!(scheduler.intents_blocked(), 2); + + // Complete msg1 + scheduler.complete(&msg1.inner); + // None of the intents can execute yet + // msg3 is blocked msg2 + // msg4 is blocked by msg3 + assert!(scheduler.pop_next_scheduled_intent().is_none()); + + // Complete msg2 + scheduler.complete(&msg2.inner); + // Now msg3 is unblocked + let next = scheduler.pop_next_scheduled_intent().unwrap(); + assert_eq!(next, msg3); + assert_eq!(scheduler.intents_blocked(), 1); + // Complete msg3 + scheduler.complete(&next.inner); + + // Now msg4 should be available + let next = scheduler.pop_next_scheduled_intent().unwrap(); + assert_eq!(next, msg4); + assert_eq!(scheduler.intents_blocked(), 0); + } + + /// Case: + /// executing: `[a1, a2, a3]` + /// blocked: `[c1, a1]` + /// arriving: `[c2, c1]` + /// `[c2, c1]` - Even there's no overlaps with executing + #[test] + fn test_edge_case_2_indirect_blocking_through_shared_key() { + let mut scheduler = IntentScheduler::new(); + let a1 = pubkey!("1111111111111111111111111111111111111111111"); + let a2 = pubkey!("21111111111111111111111111111111111111111111"); + let a3 = pubkey!("31111111111111111111111111111111111111111111"); + let c1 = pubkey!("41111111111111111111111111111111111111111111"); + let c2 = pubkey!("51111111111111111111111111111111111111111111"); + + // intent 1: [a1, a2, a3] (executing) + let msg1_keys = vec![a1, a2, a3]; + let msg1 = create_test_intent(1, &msg1_keys); + + // intent 2: [c1, a1] (blocked by msg1) + let msg2_keys = vec![c1, a1]; + let msg2 = create_test_intent(2, &msg2_keys); + + // intent 3: [c2, c1] (arriving later) + let msg3_keys = vec![c2, c1]; + let msg3 = create_test_intent(3, &msg3_keys); + + // Schedule msg1 (executes immediately) + let executed_msg1 = scheduler.schedule(msg1.clone()).unwrap(); + assert_eq!(executed_msg1, msg1); + + // Schedule msg2 (gets blocked) + assert!(scheduler.schedule(msg2.clone()).is_none()); + assert_eq!(scheduler.intents_blocked(), 1); + + // Schedule msg3 (gets blocked, even though c2 is available) + assert!(scheduler.schedule(msg3.clone()).is_none()); + assert_eq!(scheduler.intents_blocked(), 2); + + // Complete msg1 + scheduler.complete(&executed_msg1.inner); + + // Now only msg2 should be available (not msg3) + let expected_msg2 = scheduler.pop_next_scheduled_intent().unwrap(); + assert_eq!(expected_msg2, msg2); + assert_eq!(scheduler.intents_blocked(), 1); + // msg 3 still should be blocked + assert_eq!(scheduler.pop_next_scheduled_intent(), None); + + // Complete msg2 + scheduler.complete(&expected_msg2.inner); + + // Now msg3 should be available + let expected_msg3 = scheduler.pop_next_scheduled_intent().unwrap(); + assert_eq!(expected_msg3, msg3); + assert_eq!(scheduler.intents_blocked(), 0); + } + + #[test] + fn test_complex_contention_scenario() { + let mut scheduler = IntentScheduler::new(); + let a = pubkey!("1111111111111111111111111111111111111111111"); + let b = pubkey!("21111111111111111111111111111111111111111111"); + let c = pubkey!("31111111111111111111111111111111111111111111"); + + // intents with various key combinations + let msg1 = create_test_intent(1, &[a, b]); + let msg2 = create_test_intent(2, &[a, c]); + let msg3 = create_test_intent(3, &[c]); + let msg4 = create_test_intent(4, &[b]); + let msg5 = create_test_intent(5, &[a]); + + // msg1 executes immediately + let executed1 = scheduler.schedule(msg1.clone()).unwrap(); + // Others get blocked + assert!(scheduler.schedule(msg2.clone()).is_none()); + assert!(scheduler.schedule(msg3.clone()).is_none()); + assert!(scheduler.schedule(msg4.clone()).is_none()); + assert!(scheduler.schedule(msg5.clone()).is_none()); + assert_eq!(scheduler.intents_blocked(), 4); + + // Complete msg1 + scheduler.complete(&executed1.inner); + + // msg2 and msg4 should be available (they don't conflict) + let next_msgs = [ + scheduler.pop_next_scheduled_intent().unwrap(), + scheduler.pop_next_scheduled_intent().unwrap(), + ]; + assert!(next_msgs.contains(&msg2)); + assert!(next_msgs.contains(&msg4)); + assert_eq!(scheduler.intents_blocked(), 2); + + // Complete msg2 + scheduler.complete(&msg2.inner); + // msg2 and msg4 should be available (they don't conflict) + let next_intents = [ + scheduler.pop_next_scheduled_intent().unwrap(), + scheduler.pop_next_scheduled_intent().unwrap(), + ]; + assert!(next_intents.contains(&msg3)); + assert!(next_intents.contains(&msg5)); + assert_eq!(scheduler.intents_blocked(), 0); + } +} + +#[cfg(test)] +mod edge_cases_test { + use magicblock_program::magic_scheduled_base_intent::MagicBaseIntent; + use solana_pubkey::pubkey; + + use super::*; + + #[test] + fn test_intent_without_pubkeys() { + let mut scheduler = IntentScheduler::new(); + let mut msg = create_test_intent(1, &[]); + msg.inner.base_intent = MagicBaseIntent::BaseActions(vec![]); + + // Should execute immediately since it has no pubkeys + assert!(scheduler.schedule(msg.clone()).is_some()); + assert_eq!(scheduler.intents_blocked(), 0); + } + + #[test] + fn test_completion_without_scheduling() { + let mut scheduler = IntentScheduler::new(); + let msg = create_test_intent( + 1, + &[pubkey!("11111111111111111111111111111111")], + ); + + // Completing a intent that wasn't scheduled should panic + let result = + std::panic::catch_unwind(move || scheduler.complete(&msg.inner)); + assert!(result.is_err()); + } +} + +// Helper function to create test intents +#[cfg(test)] +pub(crate) fn create_test_intent( + id: u64, + pubkeys: &[Pubkey], +) -> ScheduledBaseIntentWrapper { + use magicblock_program::magic_scheduled_base_intent::{ + CommitType, CommittedAccountV2, MagicBaseIntent, + }; + use solana_account::Account; + use solana_sdk::{hash::Hash, transaction::Transaction}; + + use crate::types::TriggerType; + + let mut intent = ScheduledBaseIntent { + id, + slot: 0, + blockhash: Hash::default(), + action_sent_transaction: Transaction::default(), + payer: Pubkey::default(), + base_intent: MagicBaseIntent::BaseActions(vec![]), + }; + + // Only set pubkeys if provided + if !pubkeys.is_empty() { + let committed_accounts = pubkeys + .iter() + .map(|&pubkey| CommittedAccountV2 { + pubkey, + account: Account::default(), + }) + .collect(); + + intent.base_intent = + MagicBaseIntent::Commit(CommitType::Standalone(committed_accounts)); + } + + ScheduledBaseIntentWrapper { + inner: intent, + feepayers: vec![], + excluded_pubkeys: vec![], + trigger_type: TriggerType::OffChain, + } +} diff --git a/magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs b/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs similarity index 100% rename from magicblock-committor-service/src/commit_scheduler/commit_id_tracker.rs rename to magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs diff --git a/magicblock-committor-service/src/message_executor/error.rs b/magicblock-committor-service/src/intent_executor/error.rs similarity index 94% rename from magicblock-committor-service/src/message_executor/error.rs rename to magicblock-committor-service/src/intent_executor/error.rs index 73d17b64b..b89f98fea 100644 --- a/magicblock-committor-service/src/message_executor/error.rs +++ b/magicblock-committor-service/src/intent_executor/error.rs @@ -34,4 +34,4 @@ pub enum Error { ), } -pub type MessageExecutorResult = Result; +pub type IntentExecutorResult = Result; diff --git a/magicblock-committor-service/src/message_executor/message_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs similarity index 84% rename from magicblock-committor-service/src/message_executor/message_executor.rs rename to magicblock-committor-service/src/intent_executor/intent_executor.rs index 6e9cdbf67..725db5bef 100644 --- a/magicblock-committor-service/src/message_executor/message_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -1,6 +1,6 @@ use log::warn; use magicblock_program::{ - magic_scheduled_l1_message::ScheduledL1Message, + magic_scheduled_base_intent::ScheduledBaseIntent, validator::validator_authority, }; use magicblock_rpc_client::{ @@ -14,22 +14,22 @@ use solana_sdk::{ }; use crate::{ - message_executor::{ - error::{Error, InternalError, MessageExecutorResult}, - ExecutionOutput, MessageExecutor, + intent_executor::{ + error::{Error, IntentExecutorResult, InternalError}, + ExecutionOutput, IntentExecutor, }, - persist::{CommitStatus, CommitStatusSignatures, L1MessagesPersisterIface}, + persist::{CommitStatus, CommitStatusSignatures, IntentPersister}, transaction_preperator::transaction_preparator::TransactionPreparator, utils::persist_status_update_by_message_set, }; -pub struct L1MessageExecutor { +pub struct IntentExecutorImpl { authority: Keypair, rpc_client: MagicblockRpcClient, transaction_preparator: T, } -impl L1MessageExecutor +impl IntentExecutorImpl where T: TransactionPreparator, { @@ -45,24 +45,24 @@ where } } - async fn execute_inner( + async fn execute_inner( &self, - l1_message: ScheduledL1Message, + base_intent: ScheduledBaseIntent, persister: &Option

, - ) -> MessageExecutorResult { + ) -> IntentExecutorResult { // Update tasks status to Pending // let update_status = CommitStatus::Pending; // persist_status_update_set(&persister, &commit_ids, update_status); // Commit stage let commit_signature = - self.execute_commit_stage(&l1_message, persister).await?; + self.execute_commit_stage(&base_intent, persister).await?; // Finalize stage // At the moment validator finalizes right away // In the future there will be a challenge window let finalize_signature = self - .execute_finalize_stage(&l1_message, commit_signature, persister) + .execute_finalize_stage(&base_intent, commit_signature, persister) .await?; Ok(ExecutionOutput { @@ -71,11 +71,11 @@ where }) } - async fn execute_commit_stage( + async fn execute_commit_stage( &self, - l1_message: &ScheduledL1Message, + l1_message: &ScheduledBaseIntent, persister: &Option

, - ) -> MessageExecutorResult { + ) -> IntentExecutorResult { let prepared_message = self .transaction_preparator .prepare_commit_tx(&self.authority, l1_message, persister) @@ -87,12 +87,12 @@ where ) } - async fn execute_finalize_stage( + async fn execute_finalize_stage( &self, - l1_message: &ScheduledL1Message, + l1_message: &ScheduledBaseIntent, commit_signature: Signature, persister: &Option

, - ) -> MessageExecutorResult { + ) -> IntentExecutorResult { let prepared_message = self .transaction_preparator .prepare_finalize_tx(&self.authority, l1_message, persister) @@ -112,7 +112,7 @@ where async fn send_prepared_message( &self, mut prepared_message: VersionedMessage, - ) -> MessageExecutorResult)> + ) -> IntentExecutorResult)> { let latest_blockhash = self .rpc_client @@ -147,9 +147,9 @@ where Ok(result.into_signature()) } - fn persist_result( + fn persist_result( persistor: &Option

, - result: &MessageExecutorResult, + result: &IntentExecutorResult, message_id: u64, pubkeys: &[Pubkey], ) { @@ -206,17 +206,17 @@ where } #[async_trait::async_trait] -impl MessageExecutor for L1MessageExecutor +impl IntentExecutor for IntentExecutorImpl where T: TransactionPreparator, { /// Executes Message on Base layer /// Returns `ExecutionOutput` or an `Error` - async fn execute( + async fn execute( &self, - l1_message: ScheduledL1Message, + l1_message: ScheduledBaseIntent, persister: Option

, - ) -> MessageExecutorResult { + ) -> IntentExecutorResult { let message_id = l1_message.id; let pubkeys = l1_message.get_committed_pubkeys(); diff --git a/magicblock-committor-service/src/message_executor/message_executor_factory.rs b/magicblock-committor-service/src/intent_executor/intent_executor_factory.rs similarity index 69% rename from magicblock-committor-service/src/message_executor/message_executor_factory.rs rename to magicblock-committor-service/src/intent_executor/intent_executor_factory.rs index 6234eee8f..70d3b78fc 100644 --- a/magicblock-committor-service/src/message_executor/message_executor_factory.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor_factory.rs @@ -4,29 +4,31 @@ use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; use crate::{ - commit_scheduler::commit_id_tracker::CommitIdTrackerImpl, - message_executor::{L1MessageExecutor, MessageExecutor}, + intent_executor::{ + commit_id_fetcher::CommitIdTrackerImpl, IntentExecutor, + IntentExecutorImpl, + }, transaction_preperator::transaction_preparator::TransactionPreparatorV1, ComputeBudgetConfig, }; -pub trait MessageExecutorFactory { - type Executor: MessageExecutor; +pub trait IntentExecutorFactory { + type Executor: IntentExecutor; fn create_instance(&self) -> Self::Executor; } /// Dummy struct to simplify signature of CommitSchedulerWorker -pub struct L1MessageExecutorFactory { +pub struct IntentExecutorFactoryImpl { pub rpc_client: MagicblockRpcClient, pub table_mania: TableMania, pub compute_budget_config: ComputeBudgetConfig, pub commit_id_tracker: Arc, } -impl MessageExecutorFactory for L1MessageExecutorFactory { +impl IntentExecutorFactory for IntentExecutorFactoryImpl { type Executor = - L1MessageExecutor>; + IntentExecutorImpl>; fn create_instance(&self) -> Self::Executor { let transaction_preaparator = @@ -36,7 +38,7 @@ impl MessageExecutorFactory for L1MessageExecutorFactory { self.compute_budget_config.clone(), self.commit_id_tracker.clone(), ); - L1MessageExecutor::>::new( + IntentExecutorImpl::>::new( self.rpc_client.clone(), transaction_preaparator, ) diff --git a/magicblock-committor-service/src/intent_executor/mod.rs b/magicblock-committor-service/src/intent_executor/mod.rs new file mode 100644 index 000000000..d60429dae --- /dev/null +++ b/magicblock-committor-service/src/intent_executor/mod.rs @@ -0,0 +1,32 @@ +pub mod commit_id_fetcher; +pub mod error; +pub mod intent_executor; +pub(crate) mod intent_executor_factory; + +use async_trait::async_trait; +pub use intent_executor::IntentExecutorImpl; +use magicblock_program::magic_scheduled_base_intent::ScheduledBaseIntent; +use solana_sdk::signature::Signature; + +use crate::{ + intent_executor::error::IntentExecutorResult, persist::IntentPersister, +}; + +#[derive(Clone, Debug)] +pub struct ExecutionOutput { + /// Commit stage signature + pub commit_signature: Signature, + /// Finalize stage signature + pub finalize_signature: Signature, +} + +#[async_trait] +pub trait IntentExecutor: Send + Sync + 'static { + /// Executes Message on Base layer + /// Returns `ExecutionOutput` or an `Error` + async fn execute( + &self, + l1_message: ScheduledBaseIntent, + persister: Option

, + ) -> IntentExecutorResult; +} diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 7a5cc20bd..bb7ef1370 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -9,10 +9,10 @@ pub mod service_ext; pub mod transactions; pub mod types; -pub mod commit_scheduler; +pub mod intent_execution_manager; // TODO(edwin): define visibility mod committor_processor; -pub mod message_executor; +pub mod intent_executor; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; pub mod tasks; @@ -24,7 +24,7 @@ pub use compute_budget::ComputeBudgetConfig; pub use magicblock_committor_program::{ ChangedAccount, Changeset, ChangesetMeta, }; -pub use service::{CommittorService, L1MessageCommittor}; +pub use service::{BaseIntentCommittor, CommittorService}; pub fn changeset_for_slot(slot: u64) -> Changeset { Changeset { slot, diff --git a/magicblock-committor-service/src/message_executor/mod.rs b/magicblock-committor-service/src/message_executor/mod.rs deleted file mode 100644 index 9b1a0acc0..000000000 --- a/magicblock-committor-service/src/message_executor/mod.rs +++ /dev/null @@ -1,32 +0,0 @@ -pub mod error; -pub mod message_executor; -pub(crate) mod message_executor_factory; - -use async_trait::async_trait; -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; -pub use message_executor::L1MessageExecutor; -use solana_sdk::signature::Signature; - -use crate::{ - message_executor::error::MessageExecutorResult, - persist::L1MessagesPersisterIface, -}; - -#[derive(Clone, Debug)] -pub struct ExecutionOutput { - /// Commit stage signature - pub commit_signature: Signature, - /// Finalize stage signature - pub finalize_signature: Signature, -} - -#[async_trait] -pub trait MessageExecutor: Send + Sync + 'static { - /// Executes Message on Base layer - /// Returns `ExecutionOutput` or an `Error` - async fn execute( - &self, - l1_message: ScheduledL1Message, - persister: Option

, - ) -> MessageExecutorResult; -} diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 5139f2d85..b6103c3d7 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -3,7 +3,7 @@ use std::{ sync::{Arc, Mutex}, }; -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; +use magicblock_program::magic_scheduled_base_intent::ScheduledBaseIntent; use solana_sdk::pubkey::Pubkey; use super::{ @@ -13,16 +13,16 @@ use super::{ const POISONED_MUTEX_MSG: &str = "Commitor Persister lock poisoned"; -/// Records lifespan pf L1Message -pub trait L1MessagesPersisterIface: Send + Sync + Clone + 'static { - /// Starts persisting L1Message - fn start_l1_messages( +/// Records lifespan pf BaseIntent +pub trait IntentPersister: Send + Sync + Clone + 'static { + /// Starts persisting BaseIntent + fn start_base_intents( &self, - l1_message: &[ScheduledL1Message], + base_intent: &[ScheduledBaseIntent], ) -> CommitPersistResult<()>; - fn start_l1_message( + fn start_base_intent( &self, - l1_message: &ScheduledL1Message, + base_intent: &ScheduledBaseIntent, ) -> CommitPersistResult<()>; fn set_commit_id( &self, @@ -66,14 +66,14 @@ pub trait L1MessagesPersisterIface: Send + Sync + Clone + 'static { } #[derive(Clone)] -pub struct L1MessagePersister { +pub struct IntentPersisterImpl { // DB that tracks lifespan of Commit intents commits_db: Arc>, // TODO: add something like // actions_db: Arc> } -impl L1MessagePersister { +impl IntentPersisterImpl { pub fn try_new

(db_file: P) -> CommitPersistResult where P: AsRef, @@ -87,15 +87,15 @@ impl L1MessagePersister { } pub fn create_commit_rows( - l1_message: &ScheduledL1Message, + base_intent: &ScheduledBaseIntent, ) -> Vec { - let Some(committed_accounts) = l1_message.get_committed_accounts() + let Some(committed_accounts) = base_intent.get_committed_accounts() else { // We don't persist standalone actions return vec![]; }; - let undelegate = l1_message.is_undelegate(); + let undelegate = base_intent.is_undelegate(); let created_at = now(); committed_accounts .iter() @@ -115,12 +115,12 @@ impl L1MessagePersister { // Create a commit status row for this account CommitStatusRow { - message_id: l1_message.id, + message_id: base_intent.id, commit_id: 0, // Not known at creation, set later pubkey: account.pubkey, delegated_account_owner: account.account.owner, - slot: l1_message.slot, - ephemeral_blockhash: l1_message.blockhash, + slot: base_intent.slot, + ephemeral_blockhash: base_intent.blockhash, undelegate, lamports: account.account.lamports, data, @@ -136,10 +136,10 @@ impl L1MessagePersister { } } -impl L1MessagesPersisterIface for L1MessagePersister { - fn start_l1_messages( +impl IntentPersister for IntentPersisterImpl { + fn start_base_intents( &self, - l1_message: &[ScheduledL1Message], + l1_message: &[ScheduledBaseIntent], ) -> CommitPersistResult<()> { let commit_rows = l1_message .iter() @@ -154,9 +154,9 @@ impl L1MessagesPersisterIface for L1MessagePersister { Ok(()) } - fn start_l1_message( + fn start_base_intent( &self, - l1_message: &ScheduledL1Message, + l1_message: &ScheduledBaseIntent, ) -> CommitPersistResult<()> { let commit_row = Self::create_commit_rows(l1_message); self.commits_db @@ -253,23 +253,23 @@ impl L1MessagesPersisterIface for L1MessagePersister { } /// Blanket implementation for Option -impl L1MessagesPersisterIface for Option { - fn start_l1_messages( +impl IntentPersister for Option { + fn start_base_intents( &self, - l1_messages: &[ScheduledL1Message], + l1_messages: &[ScheduledBaseIntent], ) -> CommitPersistResult<()> { match self { - Some(persister) => persister.start_l1_messages(l1_messages), + Some(persister) => persister.start_base_intents(l1_messages), None => Ok(()), } } - fn start_l1_message( + fn start_base_intent( &self, - l1_message: &ScheduledL1Message, + l1_message: &ScheduledBaseIntent, ) -> CommitPersistResult<()> { match self { - Some(persister) => persister.start_l1_message(l1_message), + Some(persister) => persister.start_base_intent(l1_message), None => Ok(()), } } @@ -371,8 +371,8 @@ impl L1MessagesPersisterIface for Option { #[cfg(test)] mod tests { - use magicblock_program::magic_scheduled_l1_message::{ - CommitType, CommittedAccountV2, MagicL1Message, + use magicblock_program::magic_scheduled_base_intent::{ + CommitType, CommittedAccountV2, MagicBaseIntent, }; use solana_sdk::{ account::Account, hash::Hash, pubkey::Pubkey, signature::Signature, @@ -383,13 +383,13 @@ mod tests { use super::*; use crate::persist::{types, CommitStatusSignatures}; - fn create_test_persister() -> (L1MessagePersister, NamedTempFile) { + fn create_test_persister() -> (IntentPersisterImpl, NamedTempFile) { let temp_file = NamedTempFile::new().unwrap(); - let persister = L1MessagePersister::try_new(temp_file.path()).unwrap(); + let persister = IntentPersisterImpl::try_new(temp_file.path()).unwrap(); (persister, temp_file) } - fn create_test_message(id: u64) -> ScheduledL1Message { + fn create_test_message(id: u64) -> ScheduledBaseIntent { let account1 = Account { lamports: 1000, owner: Pubkey::new_unique(), @@ -405,13 +405,13 @@ mod tests { rent_epoch: 0, }; - ScheduledL1Message { + ScheduledBaseIntent { id, slot: 100, blockhash: Hash::new_unique(), action_sent_transaction: Transaction::default(), payer: Pubkey::new_unique(), - l1_message: MagicL1Message::Commit(CommitType::Standalone(vec![ + base_intent: MagicBaseIntent::Commit(CommitType::Standalone(vec![ CommittedAccountV2 { pubkey: Pubkey::new_unique(), account: account1, @@ -427,7 +427,7 @@ mod tests { #[test] fn test_create_commit_rows() { let message = create_test_message(1); - let rows = L1MessagePersister::create_commit_rows(&message); + let rows = IntentPersisterImpl::create_commit_rows(&message); assert_eq!(rows.len(), 2); @@ -446,10 +446,10 @@ mod tests { let (persister, _temp_file) = create_test_persister(); let message = create_test_message(1); - persister.start_l1_message(&message).unwrap(); + persister.start_base_intent(&message).unwrap(); let expected_statuses = - L1MessagePersister::create_commit_rows(&message); + IntentPersisterImpl::create_commit_rows(&message); let statuses = persister.get_commit_statuses_by_message(1).unwrap(); assert_eq!(statuses.len(), 2); @@ -463,7 +463,7 @@ mod tests { let message1 = create_test_message(1); let message2 = create_test_message(2); - persister.start_l1_messages(&[message1, message2]).unwrap(); + persister.start_base_intents(&[message1, message2]).unwrap(); let statuses1 = persister.get_commit_statuses_by_message(1).unwrap(); let statuses2 = persister.get_commit_statuses_by_message(2).unwrap(); @@ -475,7 +475,7 @@ mod tests { fn test_update_status() { let (persister, _temp_file) = create_test_persister(); let message = create_test_message(1); - persister.start_l1_message(&message).unwrap(); + persister.start_base_intent(&message).unwrap(); let pubkey = message.get_committed_pubkeys().unwrap()[0]; @@ -514,7 +514,7 @@ mod tests { fn test_set_commit_strategy() { let (persister, _temp_file) = create_test_persister(); let message = create_test_message(1); - persister.start_l1_message(&message).unwrap(); + persister.start_base_intent(&message).unwrap(); let pubkey = message.get_committed_pubkeys().unwrap()[0]; persister.set_commit_id(1, &pubkey, 100).unwrap(); @@ -534,7 +534,7 @@ mod tests { fn test_get_signatures() { let (persister, _temp_file) = create_test_persister(); let message = create_test_message(1); - persister.start_l1_message(&message).unwrap(); + persister.start_base_intent(&message).unwrap(); let statuses = persister.get_commit_statuses_by_message(1).unwrap(); let pubkey = statuses[0].pubkey; @@ -562,12 +562,12 @@ mod tests { #[test] fn test_empty_accounts_not_persisted() { let (persister, _temp_file) = create_test_persister(); - let message = ScheduledL1Message { - l1_message: MagicL1Message::L1Actions(vec![]), // No committed accounts + let message = ScheduledBaseIntent { + base_intent: MagicBaseIntent::BaseActions(vec![]), // No committed accounts ..create_test_message(1) }; - persister.start_l1_message(&message).unwrap(); + persister.start_base_intent(&message).unwrap(); let statuses = persister.get_commit_statuses_by_message(1).unwrap(); assert_eq!(statuses.len(), 0); // No rows should be persisted diff --git a/magicblock-committor-service/src/persist/mod.rs b/magicblock-committor-service/src/persist/mod.rs index 5256de6e5..6d7083055 100644 --- a/magicblock-committor-service/src/persist/mod.rs +++ b/magicblock-committor-service/src/persist/mod.rs @@ -4,7 +4,7 @@ pub mod error; mod types; mod utils; -pub use commit_persister::{L1MessagePersister, L1MessagesPersisterIface}; +pub use commit_persister::{IntentPersister, IntentPersisterImpl}; pub use db::{CommitStatusRow, CommittsDb, MessageSignatures}; pub use types::{ CommitStatus, CommitStatusSignatures, CommitStrategy, CommitType, diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index d594d12de..ca8f5f1ae 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -14,13 +14,13 @@ use tokio::{ use tokio_util::sync::CancellationToken; use crate::{ - commit_scheduler::BroadcastedMessageExecutionResult, committor_processor::CommittorProcessor, config::ChainConfig, error::CommittorServiceResult, + intent_execution_manager::BroadcastedIntentExecutionResult, persist::{CommitStatusRow, MessageSignatures}, pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, - types::ScheduledL1MessageWrapper, + types::ScheduledBaseIntentWrapper, }; #[derive(Debug)] @@ -48,9 +48,9 @@ pub enum CommittorMessage { /// Called once the pubkeys have been released respond_to: oneshot::Sender<()>, }, - CommitChangeset { - /// The [`ScheduledL1Message`]s to commit - l1_messages: Vec, + ScheduleBaseIntents { + /// The [`ScheduledBaseIntent`]s to commit + base_intents: Vec, }, GetCommitStatuses { respond_to: @@ -68,7 +68,7 @@ pub enum CommittorMessage { }, SubscribeForResults { respond_to: oneshot::Sender< - broadcast::Receiver, + broadcast::Receiver, >, }, } @@ -130,8 +130,8 @@ impl CommittorActor { error!("Failed to send response {:?}", e); } } - CommitChangeset { l1_messages } => { - self.processor.commit_l1_messages(l1_messages).await; + ScheduleBaseIntents { base_intents } => { + self.processor.schedule_base_intents(base_intents).await; } GetCommitStatuses { message_id, @@ -289,7 +289,7 @@ impl CommittorService { } } -impl L1MessageCommittor for CommittorService { +impl BaseIntentCommittor for CommittorService { fn reserve_pubkeys_for_committee( &self, committee: Pubkey, @@ -304,8 +304,11 @@ impl L1MessageCommittor for CommittorService { rx } - fn commit_l1_messages(&self, l1_messages: Vec) { - self.try_send(CommittorMessage::CommitChangeset { l1_messages }); + fn commit_base_intent( + &self, + base_intents: Vec, + ) { + self.try_send(CommittorMessage::ScheduleBaseIntents { base_intents }); } fn get_commit_statuses( @@ -337,7 +340,7 @@ impl L1MessageCommittor for CommittorService { fn subscribe_for_results( &self, - ) -> oneshot::Receiver> + ) -> oneshot::Receiver> { let (tx, rx) = oneshot::channel(); self.try_send(CommittorMessage::SubscribeForResults { respond_to: tx }); @@ -345,7 +348,7 @@ impl L1MessageCommittor for CommittorService { } } -pub trait L1MessageCommittor: Send + Sync + 'static { +pub trait BaseIntentCommittor: Send + Sync + 'static { /// Reserves pubkeys used in most commits in a lookup table fn reserve_pubkeys_for_committee( &self, @@ -354,12 +357,12 @@ pub trait L1MessageCommittor: Send + Sync + 'static { ) -> oneshot::Receiver>; /// Commits the changeset and returns - fn commit_l1_messages(&self, l1_messages: Vec); + fn commit_base_intent(&self, l1_messages: Vec); - /// Subscribes for results of L1Message execution + /// Subscribes for results of BaseIntent execution fn subscribe_for_results( &self, - ) -> oneshot::Receiver>; + ) -> oneshot::Receiver>; /// Gets statuses of accounts that were committed as part of a request with provided message_id fn get_commit_statuses( diff --git a/magicblock-committor-service/src/service_ext.rs b/magicblock-committor-service/src/service_ext.rs index a57de0745..5a8f65523 100644 --- a/magicblock-committor-service/src/service_ext.rs +++ b/magicblock-committor-service/src/service_ext.rs @@ -11,32 +11,32 @@ use solana_pubkey::Pubkey; use tokio::sync::{broadcast, oneshot, oneshot::error::RecvError}; use crate::{ - commit_scheduler::BroadcastedMessageExecutionResult, error::CommittorServiceResult, + intent_execution_manager::BroadcastedIntentExecutionResult, persist::{CommitStatusRow, MessageSignatures}, - types::ScheduledL1MessageWrapper, - L1MessageCommittor, + types::ScheduledBaseIntentWrapper, + BaseIntentCommittor, }; const POISONED_MUTEX_MSG: &str = "CommittorServiceExt pending messages mutex poisoned!"; #[async_trait] -pub trait L1MessageCommittorExt: L1MessageCommittor { - /// Schedules l1 messages and waits for their results - async fn commit_l1_messages_waiting( +pub trait BaseIntentCommittorExt: BaseIntentCommittor { + /// Schedules Base Intents and waits for their results + async fn schedule_base_intents_waiting( &self, - l1_messages: Vec, - ) -> L1MessageCommitorExtResult>; + base_intents: Vec, + ) -> BaseIntentCommitorExtResult>; } -type MessageResultListener = oneshot::Sender; +type MessageResultListener = oneshot::Sender; pub struct CommittorServiceExt { inner: Arc, pending_messages: Arc>>, } -impl CommittorServiceExt { +impl CommittorServiceExt { pub fn new(inner: Arc) -> Self { let pending_messages = Arc::new(Mutex::new(HashMap::new())); let results_subscription = inner.subscribe_for_results(); @@ -53,7 +53,7 @@ impl CommittorServiceExt { async fn dispatcher( results_subscription: oneshot::Receiver< - broadcast::Receiver, + broadcast::Receiver, >, pending_message: Arc>>, ) { @@ -75,39 +75,37 @@ impl CommittorServiceExt { }; if let Err(_) = sender.send(execution_result) { - error!("Failed to send L1Message execution result to listener"); + error!("Failed to send BaseIntent execution result to listener"); } } } } #[async_trait] -impl L1MessageCommittorExt for CommittorServiceExt { - async fn commit_l1_messages_waiting( +impl BaseIntentCommittorExt + for CommittorServiceExt +{ + async fn schedule_base_intents_waiting( &self, - l1_messages: Vec, - ) -> L1MessageCommitorExtResult> + base_intents: Vec, + ) -> BaseIntentCommitorExtResult> { let receivers = { let mut pending_messages = self.pending_messages.lock().expect(POISONED_MUTEX_MSG); - l1_messages + base_intents .iter() - .map(|l1_message| { + .map(|intent| { let (sender, receiver) = oneshot::channel(); - match pending_messages - .entry(l1_message.scheduled_l1_message.id) - { + match pending_messages.entry(intent.inner.id) { Entry::Vacant(vacant) => { vacant.insert(sender); Ok(receiver) } - Entry::Occupied(_) => { - Err(Error::RepeatingMessageError( - l1_message.scheduled_l1_message.id, - )) - } + Entry::Occupied(_) => Err( + Error::RepeatingMessageError(intent.inner.id), + ), } }) .collect::, _>>()? @@ -122,7 +120,7 @@ impl L1MessageCommittorExt for CommittorServiceExt { } } -impl L1MessageCommittor for CommittorServiceExt { +impl BaseIntentCommittor for CommittorServiceExt { fn reserve_pubkeys_for_committee( &self, committee: Pubkey, @@ -131,13 +129,13 @@ impl L1MessageCommittor for CommittorServiceExt { self.inner.reserve_pubkeys_for_committee(committee, owner) } - fn commit_l1_messages(&self, l1_messages: Vec) { - self.inner.commit_l1_messages(l1_messages) + fn commit_base_intent(&self, base_intents: Vec) { + self.inner.commit_base_intent(base_intents) } fn subscribe_for_results( &self, - ) -> oneshot::Receiver> + ) -> oneshot::Receiver> { self.inner.subscribe_for_results() } @@ -159,7 +157,7 @@ impl L1MessageCommittor for CommittorServiceExt { } } -impl Deref for CommittorServiceExt { +impl Deref for CommittorServiceExt { type Target = Arc; fn deref(&self) -> &Self::Target { @@ -175,4 +173,4 @@ pub enum Error { RecvError(#[from] RecvError), } -pub type L1MessageCommitorExtResult = Result; +pub type BaseIntentCommitorExtResult = Result; diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index 0a86724bf..2fe717913 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -10,22 +10,22 @@ use solana_sdk::{signature::Signature, transaction::Transaction}; use tokio::sync::{oneshot, oneshot::Receiver}; use crate::{ - commit_scheduler::{ - BroadcastedMessageExecutionResult, ExecutionOutputWrapper, - }, error::CommittorServiceResult, - message_executor::ExecutionOutput, - persist::{CommitStatusRow, L1MessagePersister, MessageSignatures}, - service_ext::{L1MessageCommitorExtResult, L1MessageCommittorExt}, - types::{ScheduledL1MessageWrapper, TriggerType}, - L1MessageCommittor, + intent_execution_manager::{ + BroadcastedIntentExecutionResult, ExecutionOutputWrapper, + }, + intent_executor::ExecutionOutput, + persist::{CommitStatusRow, IntentPersisterImpl, MessageSignatures}, + service_ext::{BaseIntentCommitorExtResult, BaseIntentCommittorExt}, + types::{ScheduledBaseIntentWrapper, TriggerType}, + BaseIntentCommittor, }; #[derive(Default)] pub struct ChangesetCommittorStub { reserved_pubkeys_for_committee: Arc>>, #[allow(clippy::type_complexity)] - committed_changesets: Arc>>, + committed_changesets: Arc>>, } impl ChangesetCommittorStub { @@ -34,7 +34,7 @@ impl ChangesetCommittorStub { } } -impl L1MessageCommittor for ChangesetCommittorStub { +impl BaseIntentCommittor for ChangesetCommittorStub { fn reserve_pubkeys_for_committee( &self, committee: Pubkey, @@ -53,17 +53,17 @@ impl L1MessageCommittor for ChangesetCommittorStub { rx } - fn commit_l1_messages(&self, l1_messages: Vec) { + fn commit_base_intent(&self, base_intents: Vec) { let mut changesets = self.committed_changesets.lock().unwrap(); - l1_messages.into_iter().for_each(|message| { - changesets.insert(message.scheduled_l1_message.id, message); + base_intents.into_iter().for_each(|intent| { + changesets.insert(intent.inner.id, intent); }); } fn subscribe_for_results( &self, ) -> Receiver< - tokio::sync::broadcast::Receiver, + tokio::sync::broadcast::Receiver, > { let (_, receiver) = oneshot::channel(); receiver @@ -72,7 +72,7 @@ impl L1MessageCommittor for ChangesetCommittorStub { fn get_commit_statuses( &self, message_id: u64, - ) -> oneshot::Receiver>> { + ) -> Receiver>> { let (tx, rx) = oneshot::channel(); let commit = self @@ -80,16 +80,15 @@ impl L1MessageCommittor for ChangesetCommittorStub { .lock() .unwrap() .remove(&message_id); - let Some(l1_message) = commit else { + let Some(base_intent) = commit else { tx.send(Ok(vec![])).unwrap_or_else(|_| { log::error!("Failed to send commit status response"); }); return rx; }; - let status_rows = L1MessagePersister::create_commit_rows( - &l1_message.scheduled_l1_message, - ); + let status_rows = + IntentPersisterImpl::create_commit_rows(&base_intent.inner); tx.send(Ok(status_rows)).unwrap_or_else(|_| { log::error!("Failed to send commit status response"); }); @@ -119,18 +118,18 @@ impl L1MessageCommittor for ChangesetCommittorStub { } #[async_trait::async_trait] -impl L1MessageCommittorExt for ChangesetCommittorStub { - async fn commit_l1_messages_waiting( +impl BaseIntentCommittorExt for ChangesetCommittorStub { + async fn schedule_base_intents_waiting( &self, - l1_messages: Vec, - ) -> L1MessageCommitorExtResult> + l1_messages: Vec, + ) -> BaseIntentCommitorExtResult> { - self.commit_l1_messages(l1_messages.clone()); + self.commit_base_intent(l1_messages.clone()); let res = l1_messages .into_iter() .map(|message| { Ok(ExecutionOutputWrapper { - id: message.scheduled_l1_message.id, + id: message.inner.id, output: ExecutionOutput { commit_signature: Signature::new_unique(), finalize_signature: Signature::new_unique(), @@ -138,13 +137,11 @@ impl L1MessageCommittorExt for ChangesetCommittorStub { action_sent_transaction: Transaction::default(), trigger_type: TriggerType::OnChain, sent_commit: SentCommit { - message_id: message.scheduled_l1_message.id, - slot: message.scheduled_l1_message.slot, - blockhash: message.scheduled_l1_message.blockhash, - payer: message.scheduled_l1_message.payer, - requested_undelegation: message - .scheduled_l1_message - .is_undelegate(), + message_id: message.inner.id, + slot: message.inner.slot, + blockhash: message.inner.blockhash, + payer: message.inner.payer, + requested_undelegation: message.inner.is_undelegate(), ..SentCommit::default() }, }) diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 2691d23b7..57917badf 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -2,18 +2,18 @@ use std::sync::Arc; use dlp::{args::Context, state::DelegationMetadata}; use log::error; -use magicblock_program::magic_scheduled_l1_message::{ - CommitType, CommittedAccountV2, MagicL1Message, ScheduledL1Message, +use magicblock_program::magic_scheduled_base_intent::{ + CommitType, CommittedAccountV2, MagicBaseIntent, ScheduledBaseIntent, UndelegateType, }; use magicblock_rpc_client::{MagicBlockRpcClientError, MagicblockRpcClient}; use solana_pubkey::Pubkey; use crate::{ - commit_scheduler::commit_id_tracker::CommitIdFetcher, - persist::L1MessagesPersisterIface, + intent_executor::commit_id_fetcher::CommitIdFetcher, + persist::IntentPersister, tasks::tasks::{ - ArgsTask, CommitTask, FinalizeTask, L1ActionTask, L1Task, + ArgsTask, BaseTask, CommitTask, FinalizeTask, L1ActionTask, UndelegateTask, }, }; @@ -21,17 +21,17 @@ use crate::{ #[async_trait::async_trait] pub trait TasksBuilder { // Creates tasks for commit stage - async fn commit_tasks( + async fn commit_tasks( commit_id_fetcher: &Arc, - l1_message: &ScheduledL1Message, + l1_message: &ScheduledBaseIntent, persister: &Option

, - ) -> TaskBuilderResult>>; + ) -> TaskBuilderResult>>; // Create tasks for finalize stage async fn finalize_tasks( rpc_client: &MagicblockRpcClient, - l1_message: &ScheduledL1Message, - ) -> TaskBuilderResult>>; + l1_message: &ScheduledBaseIntent, + ) -> TaskBuilderResult>>; } /// V1 Task builder @@ -86,13 +86,13 @@ impl TaskBuilderV1 { #[async_trait::async_trait] impl TasksBuilder for TaskBuilderV1 { /// Returns [`Task`]s for Commit stage - async fn commit_tasks( + async fn commit_tasks( commit_id_fetcher: &Arc, - l1_message: &ScheduledL1Message, + l1_message: &ScheduledBaseIntent, persister: &Option

, - ) -> TaskBuilderResult>> { - let (accounts, allow_undelegation) = match &l1_message.l1_message { - MagicL1Message::L1Actions(actions) => { + ) -> TaskBuilderResult>> { + let (accounts, allow_undelegation) = match &l1_message.base_intent { + MagicBaseIntent::BaseActions(actions) => { let tasks = actions .into_iter() .map(|el| { @@ -100,14 +100,14 @@ impl TasksBuilder for TaskBuilderV1 { context: Context::Standalone, action: el.clone(), }; - Box::new(ArgsTask::L1Action(task)) as Box + Box::new(ArgsTask::L1Action(task)) as Box }) .collect(); return Ok(tasks); } - MagicL1Message::Commit(t) => (t.get_committed_accounts(), false), - MagicL1Message::CommitAndUndelegate(t) => { + MagicBaseIntent::Commit(t) => (t.get_committed_accounts(), false), + MagicBaseIntent::CommitAndUndelegate(t) => { (t.commit_action.get_committed_accounts(), true) } }; @@ -139,7 +139,7 @@ impl TasksBuilder for TaskBuilderV1 { committed_account: account.clone(), }); - Box::new(task) as Box + Box::new(task) as Box }) .collect(); @@ -149,10 +149,10 @@ impl TasksBuilder for TaskBuilderV1 { /// Returns [`Task`]s for Finalize stage async fn finalize_tasks( rpc_client: &MagicblockRpcClient, - l1_message: &ScheduledL1Message, - ) -> TaskBuilderResult>> { + l1_message: &ScheduledBaseIntent, + ) -> TaskBuilderResult>> { // Helper to create a finalize task - fn finalize_task(account: &CommittedAccountV2) -> Box { + fn finalize_task(account: &CommittedAccountV2) -> Box { Box::new(ArgsTask::Finalize(FinalizeTask { delegated_account: account.pubkey, })) @@ -162,7 +162,7 @@ impl TasksBuilder for TaskBuilderV1 { fn undelegate_task( account: &CommittedAccountV2, rent_reimbursement: &Pubkey, - ) -> Box { + ) -> Box { Box::new(ArgsTask::Undelegate(UndelegateTask { delegated_account: account.pubkey, owner_program: account.account.owner, @@ -171,14 +171,14 @@ impl TasksBuilder for TaskBuilderV1 { } // Helper to process commit types - fn process_commit(commit: &CommitType) -> Vec> { + fn process_commit(commit: &CommitType) -> Vec> { match commit { CommitType::Standalone(accounts) => { accounts.iter().map(finalize_task).collect() } - CommitType::WithL1Actions { + CommitType::WithBaseActions { committed_accounts, - l1_actions, + base_actions: l1_actions, } => { let mut tasks = committed_accounts .iter() @@ -189,17 +189,17 @@ impl TasksBuilder for TaskBuilderV1 { context: Context::Commit, action: action.clone(), }; - Box::new(ArgsTask::L1Action(task)) as Box + Box::new(ArgsTask::L1Action(task)) as Box })); tasks } } } - match &l1_message.l1_message { - MagicL1Message::L1Actions(_) => Ok(vec![]), - MagicL1Message::Commit(commit) => Ok(process_commit(commit)), - MagicL1Message::CommitAndUndelegate(t) => { + match &l1_message.base_intent { + MagicBaseIntent::BaseActions(_) => Ok(vec![]), + MagicBaseIntent::Commit(commit) => Ok(process_commit(commit)), + MagicBaseIntent::CommitAndUndelegate(t) => { let mut tasks = process_commit(&t.commit_action); // Get rent reimbursments for undelegated accounts @@ -219,14 +219,14 @@ impl TasksBuilder for TaskBuilderV1 { match &t.undelegate_action { UndelegateType::Standalone => Ok(tasks), - UndelegateType::WithL1Actions(actions) => { + UndelegateType::WithBaseActions(actions) => { tasks.extend(actions.iter().map(|action| { let task = L1ActionTask { context: Context::Undelegate, action: action.clone(), }; Box::new(ArgsTask::L1Action(task)) - as Box + as Box })); Ok(tasks) @@ -251,7 +251,7 @@ pub enum FinalizedTasksBuildError { pub enum Error { #[error("CommitIdFetchError: {0}")] CommitTasksBuildError( - #[from] crate::commit_scheduler::commit_id_tracker::Error, + #[from] crate::intent_executor::commit_id_fetcher::Error, ), #[error("FinalizedTasksBuildError: {0}")] FinalizedTasksBuildError(#[from] FinalizedTasksBuildError), diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index cd8ca194d..86c3e6b6a 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -4,19 +4,19 @@ use solana_pubkey::Pubkey; use solana_sdk::{signature::Keypair, signer::Signer}; use crate::{ - persist::L1MessagesPersisterIface, + persist::IntentPersister, tasks::{ task_visitors::persistor_visitor::{ PersistorContext, PersistorVisitor, }, - tasks::{ArgsTask, FinalizeTask, L1Task}, + tasks::{ArgsTask, BaseTask, FinalizeTask}, utils::TransactionUtils, }, transactions::{serialize_and_encode_base64, MAX_ENCODED_TRANSACTION_SIZE}, }; pub struct TransactionStrategy { - pub optimized_tasks: Vec>, + pub optimized_tasks: Vec>, pub lookup_tables_keys: Vec, } @@ -24,8 +24,8 @@ pub struct TaskStrategist; impl TaskStrategist { /// Returns [`TaskDeliveryStrategy`] for every [`Task`] /// Returns Error if all optimizations weren't enough - pub fn build_strategy( - mut tasks: Vec>, + pub fn build_strategy( + mut tasks: Vec>, validator: &Pubkey, persistor: &Option

, ) -> TaskStrategistResult { @@ -78,7 +78,7 @@ impl TaskStrategist { /// Attempt to use ALTs for ALL keys in tx /// Returns `true` if ALTs make tx fit, otherwise `false` /// TODO: optimize to use only necessary amount of pubkeys - pub fn attempt_lookup_tables(tasks: &[Box]) -> bool { + pub fn attempt_lookup_tables(tasks: &[Box]) -> bool { let placeholder = Keypair::new(); // Gather all involved keys in tx let budgets = TransactionUtils::tasks_compute_units(&tasks); @@ -117,7 +117,7 @@ impl TaskStrategist { pub fn collect_lookup_table_keys( authority: &Pubkey, - tasks: &[Box], + tasks: &[Box], ) -> Vec { let budgets = TransactionUtils::tasks_compute_units(&tasks); let budget_instructions = @@ -133,9 +133,9 @@ impl TaskStrategist { /// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`] /// Returns size of tx after optimizations - fn optimize_strategy(tasks: &mut [Box]) -> usize { + fn optimize_strategy(tasks: &mut [Box]) -> usize { // Get initial transaction size - let calculate_tx_length = |tasks: &[Box]| { + let calculate_tx_length = |tasks: &[Box]| { match TransactionUtils::assemble_tasks_tx( &Keypair::new(), // placeholder &tasks, @@ -179,7 +179,7 @@ impl TaskStrategist { let tmp_task = ArgsTask::Finalize(FinalizeTask { delegated_account: Pubkey::new_unique(), }); - let tmp_task = Box::new(tmp_task) as Box; + let tmp_task = Box::new(tmp_task) as Box; std::mem::replace(&mut tasks[index], tmp_task) }; match task.optimize() { @@ -222,15 +222,15 @@ pub type TaskStrategistResult = Result; #[cfg(test)] mod tests { use dlp::args::Context; - use magicblock_program::magic_scheduled_l1_message::{ - CommittedAccountV2, L1Action, ProgramArgs, + use magicblock_program::magic_scheduled_base_intent::{ + BaseAction, CommittedAccountV2, ProgramArgs, }; use solana_account::Account; use solana_sdk::system_program; use super::*; use crate::{ - persist::L1MessagePersister, + persist::IntentPersisterImpl, tasks::tasks::{ CommitTask, L1ActionTask, TaskStrategy, UndelegateTask, }, @@ -258,7 +258,7 @@ mod tests { fn create_test_l1_action_task(len: usize) -> ArgsTask { ArgsTask::L1Action(L1ActionTask { context: Context::Commit, - action: L1Action { + action: BaseAction { destination_program: Pubkey::new_unique(), escrow_authority: Pubkey::new_unique(), account_metas_per_program: vec![], @@ -291,12 +291,12 @@ mod tests { fn test_build_strategy_with_single_small_task() { let validator = Pubkey::new_unique(); let task = create_test_commit_task(1, 100); - let tasks = vec![Box::new(task) as Box]; + let tasks = vec![Box::new(task) as Box]; let strategy = TaskStrategist::build_strategy( tasks, &validator, - &None::, + &None::, ) .expect("Should build strategy"); @@ -309,12 +309,12 @@ mod tests { let validator = Pubkey::new_unique(); let task = create_test_commit_task(1, 1000); // Large task - let tasks = vec![Box::new(task) as Box]; + let tasks = vec![Box::new(task) as Box]; let strategy = TaskStrategist::build_strategy( tasks, &validator, - &None::, + &None::, ) .expect("Should build strategy with buffer optimization"); @@ -335,14 +335,14 @@ mod tests { let tasks = (0..NUM_COMMITS) .map(|i| { let task = create_test_commit_task(i, 500); // Large task - Box::new(task) as Box + Box::new(task) as Box }) .collect(); let strategy = TaskStrategist::build_strategy( tasks, &validator, - &None::, + &None::, ) .expect("Should build strategy with buffer optimization"); @@ -363,14 +363,14 @@ mod tests { .map(|i| { // Large task let task = create_test_commit_task(i, 10000); - Box::new(task) as Box + Box::new(task) as Box }) .collect(); let strategy = TaskStrategist::build_strategy( tasks, &validator, - &None::, + &None::, ) .expect("Should build strategy with buffer optimization"); @@ -390,14 +390,14 @@ mod tests { .map(|i| { // Large task let task = create_test_commit_task(i, 1000); - Box::new(task) as Box + Box::new(task) as Box }) .collect(); let result = TaskStrategist::build_strategy( tasks, &validator, - &None::, + &None::, ); assert!(matches!(result, Err(Error::FailedToFitError))); } @@ -406,9 +406,9 @@ mod tests { fn test_optimize_strategy_prioritizes_largest_tasks() { let validator = Pubkey::new_unique(); let mut tasks = vec![ - Box::new(create_test_commit_task(1, 100)) as Box, - Box::new(create_test_commit_task(2, 1000)) as Box, // Larger task - Box::new(create_test_commit_task(3, 1000)) as Box, // Larger task + Box::new(create_test_commit_task(1, 100)) as Box, + Box::new(create_test_commit_task(2, 1000)) as Box, // Larger task + Box::new(create_test_commit_task(3, 1000)) as Box, // Larger task ]; let final_size = TaskStrategist::optimize_strategy(&mut tasks); @@ -421,16 +421,16 @@ mod tests { fn test_mixed_task_types_with_optimization() { let validator = Pubkey::new_unique(); let tasks = vec![ - Box::new(create_test_commit_task(1, 1000)) as Box, - Box::new(create_test_finalize_task()) as Box, - Box::new(create_test_l1_action_task(500)) as Box, - Box::new(create_test_undelegate_task()) as Box, + Box::new(create_test_commit_task(1, 1000)) as Box, + Box::new(create_test_finalize_task()) as Box, + Box::new(create_test_l1_action_task(500)) as Box, + Box::new(create_test_undelegate_task()) as Box, ]; let strategy = TaskStrategist::build_strategy( tasks, &validator, - &None::, + &None::, ) .expect("Should build strategy"); diff --git a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs index d55ebdf70..43e783bfc 100644 --- a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs +++ b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs @@ -1,7 +1,7 @@ use log::error; use crate::{ - persist::{CommitStrategy, L1MessagesPersisterIface}, + persist::{CommitStrategy, IntentPersister}, tasks::{ tasks::{ArgsTask, BufferTask}, visitor::Visitor, @@ -20,7 +20,7 @@ pub struct PersistorVisitor<'a, P> { impl<'a, P> Visitor for PersistorVisitor<'a, P> where - P: L1MessagesPersisterIface, + P: IntentPersister, { fn visit_args_task(&mut self, task: &ArgsTask) { match self.context { diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index c15625aae..4a0e59e78 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -11,8 +11,8 @@ use magicblock_committor_program::{ }, ChangesetChunks, Chunks, }; -use magicblock_program::magic_scheduled_l1_message::{ - CommittedAccountV2, L1Action, +use magicblock_program::magic_scheduled_base_intent::{ + BaseAction, CommittedAccountV2, }; use solana_pubkey::Pubkey; use solana_sdk::instruction::{AccountMeta, Instruction}; @@ -37,7 +37,7 @@ pub struct TaskPreparationInfo { } /// A trait representing a task that can be executed on Base layer -pub trait L1Task: Send + Sync { +pub trait BaseTask: Send + Sync { /// Gets all pubkeys that involved in Task's instruction fn involved_accounts(&self, validator: &Pubkey) -> Vec { self.instruction(validator) @@ -51,7 +51,9 @@ pub trait L1Task: Send + Sync { fn instruction(&self, validator: &Pubkey) -> Instruction; /// Optimizes Task strategy if possible, otherwise returns itself - fn optimize(self: Box) -> Result, Box>; + fn optimize( + self: Box, + ) -> Result, Box>; /// Returns [`TaskPreparationInfo`] if task needs to be prepared before executing, /// otherwise returns None @@ -93,7 +95,7 @@ pub struct FinalizeTask { #[derive(Clone)] pub struct L1ActionTask { pub context: Context, - pub action: L1Action, + pub action: BaseAction, } /// Task that will be executed on Base layer via arguments @@ -105,7 +107,7 @@ pub enum ArgsTask { L1Action(L1ActionTask), } -impl L1Task for ArgsTask { +impl BaseTask for ArgsTask { fn instruction(&self, validator: &Pubkey) -> Instruction { match self { Self::Commit(value) => { @@ -158,7 +160,9 @@ impl L1Task for ArgsTask { } } - fn optimize(self: Box) -> Result, Box> { + fn optimize( + self: Box, + ) -> Result, Box> { match *self { Self::Commit(value) => Ok(Box::new(BufferTask::Commit(value))), Self::L1Action(_) | Self::Finalize(_) | Self::Undelegate(_) => { @@ -198,7 +202,7 @@ pub enum BufferTask { // Action in the future } -impl L1Task for BufferTask { +impl BaseTask for BufferTask { fn instruction(&self, validator: &Pubkey) -> Instruction { let Self::Commit(value) = self; let commit_id_slice = value.commit_id.to_le_bytes(); @@ -223,7 +227,9 @@ impl L1Task for BufferTask { } /// No further optimizations - fn optimize(self: Box) -> Result, Box> { + fn optimize( + self: Box, + ) -> Result, Box> { Err(self) } diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index afbaa1829..5def2fa73 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -13,7 +13,7 @@ use solana_sdk::{ transaction::VersionedTransaction, }; -use crate::tasks::{task_strategist::TaskStrategistResult, tasks::L1Task}; +use crate::tasks::{task_strategist::TaskStrategistResult, tasks::BaseTask}; /// Returns [`Vec`] where all TX accounts stored in ALT pub fn estimate_lookup_tables_for_tx( @@ -45,7 +45,7 @@ impl TransactionUtils { } pub fn unique_involved_pubkeys( - tasks: &[Box], + tasks: &[Box], validator: &Pubkey, budget_instructions: &[Instruction], ) -> Vec { @@ -66,7 +66,7 @@ impl TransactionUtils { pub fn tasks_instructions( validator: &Pubkey, - tasks: &[Box], + tasks: &[Box], ) -> Vec { tasks .iter() @@ -76,7 +76,7 @@ impl TransactionUtils { pub fn assemble_tasks_tx( authority: &Keypair, - tasks: &[Box], + tasks: &[Box], compute_unit_price: u64, lookup_tables: &[AddressLookupTableAccount], ) -> TaskStrategistResult { @@ -140,7 +140,7 @@ impl TransactionUtils { Ok(tx) } - pub fn tasks_compute_units(tasks: &[impl AsRef]) -> u32 { + pub fn tasks_compute_units(tasks: &[impl AsRef]) -> u32 { tasks.iter().map(|task| task.as_ref().compute_units()).sum() } diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 7279d2df2..863a9c917 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -26,10 +26,10 @@ use solana_sdk::{ use tokio::time::sleep; use crate::{ - persist::{CommitStatus, L1MessagesPersisterIface}, + persist::{CommitStatus, IntentPersister}, tasks::{ task_strategist::TransactionStrategy, - tasks::{L1Task, TaskPreparationInfo}, + tasks::{BaseTask, TaskPreparationInfo}, }, utils::persist_status_update, ComputeBudgetConfig, @@ -59,7 +59,7 @@ impl DeliveryPreparator { } /// Prepares buffers and necessary pieces for optimized TX - pub async fn prepare_for_delivery( + pub async fn prepare_for_delivery( &self, authority: &Keypair, strategy: &TransactionStrategy, @@ -84,10 +84,10 @@ impl DeliveryPreparator { } /// Prepares necessary parts for TX if needed, otherwise returns immediately - pub async fn prepare_task( + pub async fn prepare_task( &self, authority: &Keypair, - task: &Box, + task: &Box, persister: &Option

, ) -> DeliveryPreparatorResult<(), InternalError> { let Some(preparation_info) = task.preparation_info(&authority.pubkey()) @@ -139,7 +139,7 @@ impl DeliveryPreparator { async fn initialize_buffer_account( &self, authority: &Keypair, - _task: &dyn L1Task, + _task: &dyn BaseTask, preparation_info: &TaskPreparationInfo, ) -> DeliveryPreparatorResult<(), InternalError> { let preparation_instructions = chunk_realloc_ixs( diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 92a5b1680..0de4ae2e6 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -1,7 +1,7 @@ use std::{fmt::Formatter, sync::Arc}; use async_trait::async_trait; -use magicblock_program::magic_scheduled_l1_message::ScheduledL1Message; +use magicblock_program::magic_scheduled_base_intent::ScheduledBaseIntent; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; use solana_sdk::{ @@ -9,8 +9,8 @@ use solana_sdk::{ }; use crate::{ - commit_scheduler::commit_id_tracker::CommitIdFetcher, - persist::L1MessagesPersisterIface, + intent_executor::commit_id_fetcher::CommitIdFetcher, + persist::IntentPersister, tasks::{ task_builder::{TaskBuilderV1, TasksBuilder}, task_strategist::TaskStrategist, @@ -41,24 +41,24 @@ impl std::fmt::Display for PreparatorVersion { pub trait TransactionPreparator: Send + Sync + 'static { fn version(&self) -> PreparatorVersion; - /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks + /// Returns [`VersionedMessage`] corresponding to [`ScheduledBaseIntent`] tasks /// Handles all necessary preparations for Message to be valid /// NOTE: [`VersionedMessage`] contains dummy recent_block_hash that should be replaced - async fn prepare_commit_tx( + async fn prepare_commit_tx( &self, authority: &Keypair, - l1_message: &ScheduledL1Message, - l1_messages_persister: &Option

, + base_intent: &ScheduledBaseIntent, + intent_persister: &Option

, ) -> PreparatorResult; - /// Returns [`VersionedMessage`] corresponding to [`ScheduledL1Message`] tasks + /// Returns [`VersionedMessage`] corresponding to [`ScheduledBaseIntent`] tasks /// Handles all necessary preparations for Message to be valid // NOTE: [`VersionedMessage`] contains dummy recent_block_hash that should be replaced - async fn prepare_finalize_tx( + async fn prepare_finalize_tx( &self, authority: &Keypair, - l1_message: &ScheduledL1Message, - l1_messages_persister: &Option

, + base_intent: &ScheduledBaseIntent, + intent_persister: &Option

, ) -> PreparatorResult; } @@ -108,24 +108,24 @@ where /// In V1: prepares TX with commits for every account in message /// For pure actions message - outputs Tx that runs actions - async fn prepare_commit_tx( + async fn prepare_commit_tx( &self, authority: &Keypair, - l1_message: &ScheduledL1Message, - l1_messages_persister: &Option

, + base_intent: &ScheduledBaseIntent, + intent_persister: &Option

, ) -> PreparatorResult { // create tasks let tasks = TaskBuilderV1::commit_tasks( &self.commit_id_fetcher, - l1_message, - l1_messages_persister, + base_intent, + intent_persister, ) .await?; // optimize to fit tx size. aka Delivery Strategy let tx_strategy = TaskStrategist::build_strategy( tasks, &authority.pubkey(), - l1_messages_persister, + intent_persister, )?; // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self @@ -133,7 +133,7 @@ where .prepare_for_delivery( authority, &tx_strategy, - l1_messages_persister, + intent_persister, ) .await?; @@ -151,20 +151,20 @@ where } /// In V1: prepares single TX with finalize, undelegation + actions - async fn prepare_finalize_tx( + async fn prepare_finalize_tx( &self, authority: &Keypair, - l1_message: &ScheduledL1Message, - l1_messages_persister: &Option

, + base_intent: &ScheduledBaseIntent, + intent_presister: &Option

, ) -> PreparatorResult { // create tasks let tasks = - TaskBuilderV1::finalize_tasks(&self.rpc_client, l1_message).await?; + TaskBuilderV1::finalize_tasks(&self.rpc_client, base_intent).await?; // optimize to fit tx size. aka Delivery Strategy let tx_strategy = TaskStrategist::build_strategy( tasks, &authority.pubkey(), - l1_messages_persister, + intent_presister, )?; // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self @@ -172,7 +172,7 @@ where .prepare_for_delivery( authority, &tx_strategy, - l1_messages_persister, + intent_presister, ) .await?; diff --git a/magicblock-committor-service/src/types.rs b/magicblock-committor-service/src/types.rs index 5b81219c7..8fa628b3a 100644 --- a/magicblock-committor-service/src/types.rs +++ b/magicblock-committor-service/src/types.rs @@ -1,5 +1,5 @@ use magicblock_program::{ - magic_scheduled_l1_message::ScheduledL1Message, FeePayerAccount, + magic_scheduled_base_intent::ScheduledBaseIntent, FeePayerAccount, }; use solana_pubkey::Pubkey; @@ -12,8 +12,8 @@ pub enum TriggerType { } #[derive(Clone, Debug, PartialEq, Eq)] -pub struct ScheduledL1MessageWrapper { - pub scheduled_l1_message: ScheduledL1Message, +pub struct ScheduledBaseIntentWrapper { + pub inner: ScheduledBaseIntent, pub feepayers: Vec, pub excluded_pubkeys: Vec, pub trigger_type: TriggerType, diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index b48938c47..fb702a2b9 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -3,9 +3,9 @@ use std::collections::HashMap; use log::error; use solana_pubkey::Pubkey; -use crate::persist::{CommitStatus, L1MessagesPersisterIface}; +use crate::persist::{CommitStatus, IntentPersister}; -pub(crate) fn persist_status_update( +pub(crate) fn persist_status_update( persister: &Option

, pubkey: &Pubkey, commit_id: u64, @@ -23,7 +23,7 @@ pub(crate) fn persist_status_update( } } -pub(crate) fn persist_status_update_set( +pub(crate) fn persist_status_update_set( persister: &Option

, commit_ids_map: &HashMap, update_status: CommitStatus, @@ -41,9 +41,7 @@ pub(crate) fn persist_status_update_set( } }); } -pub(crate) fn persist_status_update_by_message_set< - P: L1MessagesPersisterIface, ->( +pub(crate) fn persist_status_update_by_message_set( persister: &Option

, message_id: u64, pubkeys: &[Pubkey], diff --git a/magicblock-committor-service/tests/common.rs b/magicblock-committor-service/tests/common.rs index 2f1865ed1..8553adbc9 100644 --- a/magicblock-committor-service/tests/common.rs +++ b/magicblock-committor-service/tests/common.rs @@ -6,9 +6,8 @@ use std::{ }, }; -use async_trait::async_trait; use magicblock_committor_service::{ - commit_scheduler::commit_id_tracker::{ + intent_executor::commit_id_fetcher::{ CommitIdFetcher, CommitIdTrackerResult, }, tasks::tasks::CommitTask, @@ -16,22 +15,16 @@ use magicblock_committor_service::{ delivery_preparator::DeliveryPreparator, transaction_preparator::TransactionPreparatorV1, }, - types::{ScheduledL1MessageWrapper, TriggerType}, ComputeBudgetConfig, }; -use magicblock_program::magic_scheduled_l1_message::{ - CommittedAccountV2, ScheduledL1Message, -}; +use magicblock_program::magic_scheduled_base_intent::CommittedAccountV2; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; use solana_account::Account; use solana_pubkey::Pubkey; use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ - commitment_config::{CommitmentConfig, CommitmentLevel}, - signature::Keypair, - signer::Signer, - system_program, + commitment_config::CommitmentConfig, signature::Keypair, signer::Signer, }; // Helper function to create a test RPC client diff --git a/magicblock-committor-service/tests/test_delivery_preparator.rs b/magicblock-committor-service/tests/test_delivery_preparator.rs index 2660c0d9a..0bc8d3f9d 100644 --- a/magicblock-committor-service/tests/test_delivery_preparator.rs +++ b/magicblock-committor-service/tests/test_delivery_preparator.rs @@ -6,10 +6,10 @@ use borsh::BorshDeserialize; use futures_util::StreamExt; use magicblock_committor_program::Chunks; use magicblock_committor_service::{ - persist::L1MessagePersister, + persist::IntentPersisterImpl, tasks::{ task_strategist::{TaskStrategist, TransactionStrategy}, - tasks::{ArgsTask, BufferTask, L1Task}, + tasks::{ArgsTask, BaseTask, BufferTask}, }, }; use solana_sdk::signer::Signer; @@ -35,7 +35,7 @@ async fn test_prepare_10kb_buffer() { .prepare_for_delivery( &fixture.authority, &strategy, - &None::, + &None::, ) .await; @@ -87,7 +87,7 @@ async fn test_prepare_multiple_buffers() { .iter() .map(|data| { let task = BufferTask::Commit(create_commit_task(data.as_slice())); - Box::new(task) as Box + Box::new(task) as Box }) .collect(); let strategy = TransactionStrategy { @@ -100,7 +100,7 @@ async fn test_prepare_multiple_buffers() { .prepare_for_delivery( &fixture.authority, &strategy, - &None::, + &None::, ) .await; @@ -158,7 +158,7 @@ async fn test_lookup_tables() { .iter() .map(|data| { let task = ArgsTask::Commit(create_commit_task(data.as_slice())); - Box::new(task) as Box + Box::new(task) as Box }) .collect::>(); @@ -175,7 +175,7 @@ async fn test_lookup_tables() { .prepare_for_delivery( &fixture.authority, &strategy, - &None::, + &None::, ) .await; assert!(result.is_ok(), "Failed to prepare lookup tables"); diff --git a/magicblock-committor-service/tests/test_transaction_preparator.rs b/magicblock-committor-service/tests/test_transaction_preparator.rs index dd8b27f40..804047649 100644 --- a/magicblock-committor-service/tests/test_transaction_preparator.rs +++ b/magicblock-committor-service/tests/test_transaction_preparator.rs @@ -1,12 +1,12 @@ use std::collections::HashMap; use magicblock_committor_service::{ - persist::L1MessagePersister, + persist::IntentPersisterImpl, transaction_preperator::transaction_preparator::TransactionPreparator, }; -use magicblock_program::magic_scheduled_l1_message::{ - CommitAndUndelegate, CommitType, CommittedAccountV2, L1Action, - MagicL1Message, ProgramArgs, ScheduledL1Message, ShortAccountMeta, +use magicblock_program::magic_scheduled_base_intent::{ + BaseAction, CommitAndUndelegate, CommitType, CommittedAccountV2, + MagicBaseIntent, ProgramArgs, ScheduledBaseIntent, ShortAccountMeta, UndelegateType, }; use solana_pubkey::Pubkey; @@ -27,13 +27,13 @@ async fn test_prepare_commit_tx_with_single_account() { // Create test data let account_data = vec![1, 2, 3, 4, 5]; let committed_account = create_committed_account(&account_data); - let l1_message = ScheduledL1Message { + let l1_message = ScheduledBaseIntent { id: 1, slot: 0, blockhash: Hash::default(), action_sent_transaction: Transaction::default(), payer: fixture.authority.pubkey(), - l1_message: MagicL1Message::Commit(CommitType::Standalone(vec![ + base_intent: MagicBaseIntent::Commit(CommitType::Standalone(vec![ committed_account.clone(), ])), }; @@ -46,7 +46,7 @@ async fn test_prepare_commit_tx_with_single_account() { .prepare_commit_tx( &fixture.authority, &l1_message, - &None::, + &None::, ) .await; @@ -82,13 +82,13 @@ async fn test_prepare_commit_tx_with_multiple_accounts() { }, ]; - let l1_message = ScheduledL1Message { + let l1_message = ScheduledBaseIntent { id: 1, slot: 0, blockhash: Hash::default(), action_sent_transaction: Transaction::default(), payer: fixture.authority.pubkey(), - l1_message: MagicL1Message::Commit(CommitType::Standalone( + base_intent: MagicBaseIntent::Commit(CommitType::Standalone( accounts.clone(), )), }; @@ -98,7 +98,7 @@ async fn test_prepare_commit_tx_with_multiple_accounts() { .prepare_commit_tx( &fixture.authority, &l1_message, - &None::, + &None::, ) .await; @@ -122,7 +122,7 @@ async fn test_prepare_commit_tx_with_l1_actions() { }, }; - let l1_action = L1Action { + let l1_action = BaseAction { compute_units: 30_000, destination_program: system_program::id(), escrow_authority: fixture.authority.pubkey(), @@ -136,15 +136,15 @@ async fn test_prepare_commit_tx_with_l1_actions() { }], }; - let l1_message = ScheduledL1Message { + let l1_message = ScheduledBaseIntent { id: 1, slot: 0, blockhash: Hash::default(), action_sent_transaction: Transaction::default(), payer: fixture.authority.pubkey(), - l1_message: MagicL1Message::Commit(CommitType::WithL1Actions { + base_intent: MagicBaseIntent::Commit(CommitType::WithBaseActions { committed_accounts: vec![account.clone()], - l1_actions: vec![l1_action], + base_actions: vec![l1_action], }), }; @@ -156,7 +156,7 @@ async fn test_prepare_commit_tx_with_l1_actions() { .prepare_commit_tx( &fixture.authority, &l1_message, - &None::, + &None::, ) .await; @@ -171,16 +171,18 @@ async fn test_prepare_finalize_tx_with_undelegate() { // Create test data let rent_reimbursement = Pubkey::new_unique(); - let l1_message = ScheduledL1Message { + let l1_message = ScheduledBaseIntent { id: 1, slot: 0, blockhash: Hash::default(), action_sent_transaction: Transaction::default(), payer: fixture.authority.pubkey(), - l1_message: MagicL1Message::CommitAndUndelegate(CommitAndUndelegate { - commit_action: CommitType::Standalone(vec![]), - undelegate_action: UndelegateType::Standalone, - }), + base_intent: MagicBaseIntent::CommitAndUndelegate( + CommitAndUndelegate { + commit_action: CommitType::Standalone(vec![]), + undelegate_action: UndelegateType::Standalone, + }, + ), }; // Test preparation @@ -188,7 +190,7 @@ async fn test_prepare_finalize_tx_with_undelegate() { .prepare_finalize_tx( &fixture.authority, &l1_message, - &None::, + &None::, ) .await; @@ -202,7 +204,7 @@ async fn test_prepare_finalize_tx_with_undelegate_and_actions() { // Create test data let rent_reimbursement = Pubkey::new_unique(); - let l1_action = L1Action { + let l1_action = BaseAction { compute_units: 30_000, destination_program: system_program::id(), escrow_authority: fixture.authority.pubkey(), @@ -216,16 +218,20 @@ async fn test_prepare_finalize_tx_with_undelegate_and_actions() { }], }; - let l1_message = ScheduledL1Message { + let l1_message = ScheduledBaseIntent { id: 1, slot: 0, blockhash: Hash::default(), action_sent_transaction: Transaction::default(), payer: fixture.authority.pubkey(), - l1_message: MagicL1Message::CommitAndUndelegate(CommitAndUndelegate { - commit_action: CommitType::Standalone(vec![]), - undelegate_action: UndelegateType::WithL1Actions(vec![l1_action]), - }), + base_intent: MagicBaseIntent::CommitAndUndelegate( + CommitAndUndelegate { + commit_action: CommitType::Standalone(vec![]), + undelegate_action: UndelegateType::WithBaseActions(vec![ + l1_action, + ]), + }, + ), }; // Test preparation @@ -233,7 +239,7 @@ async fn test_prepare_finalize_tx_with_undelegate_and_actions() { .prepare_finalize_tx( &fixture.authority, &l1_message, - &None::, + &None::, ) .await; @@ -258,13 +264,13 @@ async fn test_prepare_large_commit_tx_uses_buffers() { }, }; - let l1_message = ScheduledL1Message { + let l1_message = ScheduledBaseIntent { id: 1, slot: 0, blockhash: Hash::default(), action_sent_transaction: Transaction::default(), payer: fixture.authority.pubkey(), - l1_message: MagicL1Message::Commit(CommitType::Standalone(vec![ + base_intent: MagicBaseIntent::Commit(CommitType::Standalone(vec![ committed_account.clone(), ])), }; @@ -277,7 +283,7 @@ async fn test_prepare_large_commit_tx_uses_buffers() { .prepare_commit_tx( &fixture.authority, &l1_message, - &None::, + &None::, ) .await; diff --git a/magicblock-rpc/src/traits/rpc_full.rs b/magicblock-rpc/src/traits/rpc_full.rs index 618627cfc..6b83acce1 100644 --- a/magicblock-rpc/src/traits/rpc_full.rs +++ b/magicblock-rpc/src/traits/rpc_full.rs @@ -187,7 +187,7 @@ pub trait Full { } // ideally -// 1. We add all of ScheduledL1Message on baselayer +// 1. We add all of ScheduledBaseIntent on baselayer // 2. We finalize them: // 1. Runs committs per account // 2. Runs actions(undelegate one actions) diff --git a/programs/magicblock/src/args.rs b/programs/magicblock/src/args.rs index c247aeb1d..06d7892bd 100644 --- a/programs/magicblock/src/args.rs +++ b/programs/magicblock/src/args.rs @@ -7,7 +7,7 @@ pub struct ActionArgs { } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub struct L1ActionArgs { +pub struct BaseActionArgs { pub args: ActionArgs, pub compute_units: u32, // compute units your action will use pub escrow_authority: u8, // index of account authorizing action on actor pda @@ -18,9 +18,9 @@ pub struct L1ActionArgs { #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum CommitTypeArgs { Standalone(Vec), // indices on accounts - WithL1Actions { + WithBaseActions { committed_accounts: Vec, // indices of accounts - l1_actions: Vec, + base_actions: Vec, }, } @@ -28,7 +28,7 @@ impl CommitTypeArgs { pub fn committed_accounts_indices(&self) -> &Vec { match self { Self::Standalone(value) => value, - Self::WithL1Actions { + Self::WithBaseActions { committed_accounts, .. } => committed_accounts, } @@ -38,7 +38,7 @@ impl CommitTypeArgs { #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum UndelegateTypeArgs { Standalone, - WithL1Actions { l1_actions: Vec }, + WithBaseActions { base_actions: Vec }, } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] @@ -54,8 +54,8 @@ impl CommitAndUndelegateArgs { } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] -pub enum MagicL1MessageArgs { - L1Actions(Vec), +pub enum MagicBaseIntentArgs { + BaseActions(Vec), Commit(CommitTypeArgs), CommitAndUndelegate(CommitAndUndelegateArgs), } diff --git a/programs/magicblock/src/lib.rs b/programs/magicblock/src/lib.rs index a53b70ccd..287e92482 100644 --- a/programs/magicblock/src/lib.rs +++ b/programs/magicblock/src/lib.rs @@ -4,7 +4,7 @@ mod mutate_accounts; mod schedule_transactions; pub use magic_context::{FeePayerAccount, MagicContext}; pub mod args; -pub mod magic_scheduled_l1_message; +pub mod magic_scheduled_base_intent; pub mod magicblock_instruction; // TODO(edwin): isolate with features pub mod magicblock_processor; diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index f245e1904..2a67bc6cc 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -7,7 +7,7 @@ use solana_sdk::{ pubkey::Pubkey, }; -use crate::magic_scheduled_l1_message::ScheduledL1Message; +use crate::magic_scheduled_base_intent::ScheduledBaseIntent; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FeePayerAccount { @@ -17,7 +17,7 @@ pub struct FeePayerAccount { #[derive(Debug, Default, Serialize, Deserialize)] pub struct MagicContext { - pub scheduled_commits: Vec, + pub scheduled_base_intents: Vec, } impl MagicContext { @@ -35,13 +35,15 @@ impl MagicContext { pub(crate) fn add_scheduled_action( &mut self, - l1_message: ScheduledL1Message, + base_intent: ScheduledBaseIntent, ) { - self.scheduled_commits.push(l1_message); + self.scheduled_base_intents.push(base_intent); } - pub(crate) fn take_scheduled_commits(&mut self) -> Vec { - mem::take(&mut self.scheduled_commits) + pub(crate) fn take_scheduled_commits( + &mut self, + ) -> Vec { + mem::take(&mut self.scheduled_base_intents) } pub fn has_scheduled_commits(data: &[u8]) -> bool { diff --git a/programs/magicblock/src/magic_scheduled_l1_message.rs b/programs/magicblock/src/magic_scheduled_base_intent.rs similarity index 80% rename from programs/magicblock/src/magic_scheduled_l1_message.rs rename to programs/magicblock/src/magic_scheduled_base_intent.rs index 322db8b50..498d62db4 100644 --- a/programs/magicblock/src/magic_scheduled_l1_message.rs +++ b/programs/magicblock/src/magic_scheduled_base_intent.rs @@ -14,8 +14,8 @@ use solana_sdk::{ use crate::{ args::{ - ActionArgs, CommitAndUndelegateArgs, CommitTypeArgs, L1ActionArgs, - MagicL1MessageArgs, UndelegateTypeArgs, + ActionArgs, BaseActionArgs, CommitAndUndelegateArgs, CommitTypeArgs, + MagicBaseIntentArgs, UndelegateTypeArgs, }, instruction_utils::InstructionUtils, utils::accounts::{ @@ -51,105 +51,105 @@ impl<'a, 'ic> ConstructionContext<'a, 'ic> { /// Scheduled action to be executed on base layer #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ScheduledL1Message { +pub struct ScheduledBaseIntent { pub id: u64, pub slot: Slot, pub blockhash: Hash, pub action_sent_transaction: Transaction, pub payer: Pubkey, // Scheduled action - pub l1_message: MagicL1Message, + pub base_intent: MagicBaseIntent, } -impl ScheduledL1Message { +impl ScheduledBaseIntent { pub fn try_new<'a>( - args: &MagicL1MessageArgs, + args: &MagicBaseIntentArgs, commit_id: u64, slot: Slot, payer_pubkey: &Pubkey, context: &ConstructionContext<'a, '_>, - ) -> Result { - let action = MagicL1Message::try_from_args(args, &context)?; + ) -> Result { + let action = MagicBaseIntent::try_from_args(args, &context)?; let blockhash = context.invoke_context.environment_config.blockhash; let action_sent_transaction = InstructionUtils::scheduled_commit_sent(commit_id, blockhash); - Ok(ScheduledL1Message { + Ok(ScheduledBaseIntent { id: commit_id, slot, blockhash, payer: *payer_pubkey, action_sent_transaction, - l1_message: action, + base_intent: action, }) } pub fn get_committed_accounts(&self) -> Option<&Vec> { - self.l1_message.get_committed_accounts() + self.base_intent.get_committed_accounts() } pub fn get_committed_accounts_mut( &mut self, ) -> Option<&mut Vec> { - self.l1_message.get_committed_accounts_mut() + self.base_intent.get_committed_accounts_mut() } pub fn get_committed_pubkeys(&self) -> Option> { - self.l1_message.get_committed_pubkeys() + self.base_intent.get_committed_pubkeys() } pub fn is_undelegate(&self) -> bool { - self.l1_message.is_undelegate() + self.base_intent.is_undelegate() } } -// L1Message user wants to send to base layer +// BaseIntent user wants to send to base layer #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub enum MagicL1Message { +pub enum MagicBaseIntent { /// Actions without commitment or undelegation - L1Actions(Vec), + BaseActions(Vec), Commit(CommitType), CommitAndUndelegate(CommitAndUndelegate), } -impl MagicL1Message { +impl MagicBaseIntent { pub fn try_from_args<'a>( - args: &MagicL1MessageArgs, + args: &MagicBaseIntentArgs, context: &ConstructionContext<'a, '_>, - ) -> Result { + ) -> Result { match args { - MagicL1MessageArgs::L1Actions(l1_actions) => { - let l1_actions = l1_actions + MagicBaseIntentArgs::BaseActions(base_actions) => { + let base_actions = base_actions .iter() - .map(|args| L1Action::try_from_args(args, context)) - .collect::, InstructionError>>()?; - Ok(MagicL1Message::L1Actions(l1_actions)) + .map(|args| BaseAction::try_from_args(args, context)) + .collect::, InstructionError>>()?; + Ok(MagicBaseIntent::BaseActions(base_actions)) } - MagicL1MessageArgs::Commit(type_) => { + MagicBaseIntentArgs::Commit(type_) => { let commit = CommitType::try_from_args(type_, context)?; - Ok(MagicL1Message::Commit(commit)) + Ok(MagicBaseIntent::Commit(commit)) } - MagicL1MessageArgs::CommitAndUndelegate(type_) => { + MagicBaseIntentArgs::CommitAndUndelegate(type_) => { let commit_and_undelegate = CommitAndUndelegate::try_from_args(type_, context)?; - Ok(MagicL1Message::CommitAndUndelegate(commit_and_undelegate)) + Ok(MagicBaseIntent::CommitAndUndelegate(commit_and_undelegate)) } } } pub fn is_undelegate(&self) -> bool { match &self { - MagicL1Message::L1Actions(_) => false, - MagicL1Message::Commit(_) => false, - MagicL1Message::CommitAndUndelegate(_) => true, + MagicBaseIntent::BaseActions(_) => false, + MagicBaseIntent::Commit(_) => false, + MagicBaseIntent::CommitAndUndelegate(_) => true, } } pub fn get_committed_accounts(&self) -> Option<&Vec> { match self { - MagicL1Message::L1Actions(_) => None, - MagicL1Message::Commit(t) => Some(t.get_committed_accounts()), - MagicL1Message::CommitAndUndelegate(t) => { + MagicBaseIntent::BaseActions(_) => None, + MagicBaseIntent::Commit(t) => Some(t.get_committed_accounts()), + MagicBaseIntent::CommitAndUndelegate(t) => { Some(t.get_committed_accounts()) } } @@ -159,9 +159,9 @@ impl MagicL1Message { &mut self, ) -> Option<&mut Vec> { match self { - MagicL1Message::L1Actions(_) => None, - MagicL1Message::Commit(t) => Some(t.get_committed_accounts_mut()), - MagicL1Message::CommitAndUndelegate(t) => { + MagicBaseIntent::BaseActions(_) => None, + MagicBaseIntent::Commit(t) => Some(t.get_committed_accounts_mut()), + MagicBaseIntent::CommitAndUndelegate(t) => { Some(t.get_committed_accounts_mut()) } } @@ -235,7 +235,7 @@ pub struct ShortAccountMeta { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct L1Action { +pub struct BaseAction { pub compute_units: u32, pub destination_program: Pubkey, pub escrow_authority: Pubkey, @@ -243,11 +243,11 @@ pub struct L1Action { pub account_metas_per_program: Vec, } -impl L1Action { +impl BaseAction { pub fn try_from_args<'a>( - args: &L1ActionArgs, + args: &BaseActionArgs, context: &ConstructionContext<'a, '_>, - ) -> Result { + ) -> Result { let destination_program_pubkey = *get_instruction_pubkey_with_idx( context.transaction_context, args.destination_program as u16, @@ -260,14 +260,14 @@ impl L1Action { ic_msg!( context.invoke_context, &format!( - "L1Action: destination_program must be an executable. got: {}", + "BaseAction: destination_program must be an executable. got: {}", destination_program_pubkey ) ); return Err(InstructionError::AccountNotExecutable); } - // Since action on L1 performed on behalf of some escrow + // Since action on Base layer performed on behalf of some escrow // We need to ensure that action was authorized by legit owner let authority_pubkey = get_instruction_pubkey_with_idx( context.transaction_context, @@ -277,7 +277,7 @@ impl L1Action { ic_msg!( context.invoke_context, &format!( - "L1Action: authority pubkey must sign transaction: {}", + "BaseAction: authority pubkey must sign transaction: {}", authority_pubkey ) ); @@ -296,7 +296,7 @@ impl L1Action { }) .collect::, InstructionError>>()?; - Ok(L1Action { + Ok(BaseAction { compute_units: args.compute_units, destination_program: destination_program_pubkey, escrow_authority: *authority_pubkey, @@ -328,9 +328,9 @@ pub enum CommitType { /// TODO: feels like ShortMeta isn't needed Standalone(Vec), // accounts to commit /// Commits accounts and runs actions - WithL1Actions { + WithBaseActions { committed_accounts: Vec, - l1_actions: Vec, + base_actions: Vec, }, } @@ -422,9 +422,9 @@ impl CommitType { Ok(CommitType::Standalone(committed_accounts)) } - CommitTypeArgs::WithL1Actions { + CommitTypeArgs::WithBaseActions { committed_accounts, - l1_actions, + base_actions, } => { let committed_accounts_ref = Self::extract_commit_accounts( committed_accounts, @@ -432,10 +432,10 @@ impl CommitType { )?; Self::validate_accounts(&committed_accounts_ref, context)?; - let l1_actions = l1_actions + let base_actions = base_actions .iter() - .map(|args| L1Action::try_from_args(args, context)) - .collect::, InstructionError>>()?; + .map(|args| BaseAction::try_from_args(args, context)) + .collect::, InstructionError>>()?; let committed_accounts = committed_accounts_ref .into_iter() .map(|el| { @@ -449,9 +449,9 @@ impl CommitType { }) .collect(); - Ok(CommitType::WithL1Actions { + Ok(CommitType::WithBaseActions { committed_accounts, - l1_actions, + base_actions, }) } } @@ -460,7 +460,7 @@ impl CommitType { pub fn get_committed_accounts(&self) -> &Vec { match self { Self::Standalone(committed_accounts) => committed_accounts, - Self::WithL1Actions { + Self::WithBaseActions { committed_accounts, .. } => committed_accounts, } @@ -471,7 +471,7 @@ impl CommitType { ) -> &mut Vec { match self { Self::Standalone(committed_accounts) => committed_accounts, - Self::WithL1Actions { + Self::WithBaseActions { committed_accounts, .. } => committed_accounts, } @@ -482,7 +482,7 @@ impl CommitType { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum UndelegateType { Standalone, - WithL1Actions(Vec), + WithBaseActions(Vec), } impl UndelegateType { @@ -492,14 +492,14 @@ impl UndelegateType { ) -> Result { match args { UndelegateTypeArgs::Standalone => Ok(UndelegateType::Standalone), - UndelegateTypeArgs::WithL1Actions { l1_actions } => { - let l1_actions = l1_actions + UndelegateTypeArgs::WithBaseActions { base_actions } => { + let base_actions = base_actions .iter() - .map(|l1_actions| { - L1Action::try_from_args(l1_actions, context) + .map(|base_action| { + BaseAction::try_from_args(base_action, context) }) - .collect::, InstructionError>>()?; - Ok(UndelegateType::WithL1Actions(l1_actions)) + .collect::, InstructionError>>()?; + Ok(UndelegateType::WithBaseActions(base_actions)) } } } diff --git a/programs/magicblock/src/magicblock_instruction.rs b/programs/magicblock/src/magicblock_instruction.rs index 8ab48537c..009aaf768 100644 --- a/programs/magicblock/src/magicblock_instruction.rs +++ b/programs/magicblock/src/magicblock_instruction.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; use solana_sdk::{account::Account, pubkey::Pubkey}; -use crate::args::MagicL1MessageArgs; +use crate::args::MagicBaseIntentArgs; #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum MagicBlockInstruction { @@ -67,7 +67,7 @@ pub enum MagicBlockInstruction { /// We implement it this way so we can log the signature of this transaction /// as part of the [MagicBlockInstruction::ScheduleCommit] instruction. ScheduledCommitSent(u64), - ScheduleL1Message(MagicL1MessageArgs), + ScheduleBaseIntent(MagicBaseIntentArgs), } // TODO: why that exists? @@ -81,7 +81,7 @@ impl MagicBlockInstruction { ScheduleCommitAndUndelegate => 2, AcceptScheduleCommits => 3, ScheduledCommitSent(_) => 4, - ScheduleL1Message(_) => 5, + ScheduleBaseIntent(_) => 5, } } diff --git a/programs/magicblock/src/magicblock_processor.rs b/programs/magicblock/src/magicblock_processor.rs index 0207e3ec2..3066192c4 100644 --- a/programs/magicblock/src/magicblock_processor.rs +++ b/programs/magicblock/src/magicblock_processor.rs @@ -6,8 +6,8 @@ use crate::{ mutate_accounts::process_mutate_accounts, process_scheduled_commit_sent, schedule_transactions::{ - process_accept_scheduled_commits, process_schedule_commit, - process_schedule_l1_message, ProcessScheduleCommitOptions, + process_accept_scheduled_commits, process_schedule_base_intent, + process_schedule_commit, ProcessScheduleCommitOptions, }, }; @@ -60,8 +60,8 @@ declare_process_instruction!( id, ) } - MagicBlockInstruction::ScheduleL1Message(args) => { - process_schedule_l1_message(signers, invoke_context, args) + MagicBlockInstruction::ScheduleBaseIntent(args) => { + process_schedule_base_intent(signers, invoke_context, args) } } } diff --git a/programs/magicblock/src/schedule_transactions/mod.rs b/programs/magicblock/src/schedule_transactions/mod.rs index 38b4eae5f..9d12a295a 100644 --- a/programs/magicblock/src/schedule_transactions/mod.rs +++ b/programs/magicblock/src/schedule_transactions/mod.rs @@ -1,18 +1,18 @@ mod process_accept_scheduled_commits; +mod process_schedule_base_intent; mod process_schedule_commit; #[cfg(test)] mod process_schedule_commit_tests; -mod process_schedule_l1_message; mod process_scheduled_commit_sent; -mod schedule_l1_message_processor; +mod schedule_base_intent_processor; pub(crate) mod transaction_scheduler; use std::sync::atomic::AtomicU64; use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; pub(crate) use process_accept_scheduled_commits::*; +pub(crate) use process_schedule_base_intent::*; pub(crate) use process_schedule_commit::*; -pub(crate) use process_schedule_l1_message::*; pub use process_scheduled_commit_sent::{ process_scheduled_commit_sent, register_scheduled_commit_sent, SentCommit, }; diff --git a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs index fe4d7801e..4adf8d04b 100644 --- a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs +++ b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs @@ -45,7 +45,7 @@ pub fn process_accept_scheduled_commits( ); InstructionError::InvalidAccountData })?; - if magic_context.scheduled_commits.is_empty() { + if magic_context.scheduled_base_intents.is_empty() { ic_msg!( invoke_context, "AcceptScheduledCommits: no scheduled commits to accept" @@ -86,7 +86,7 @@ pub fn process_accept_scheduled_commits( scheduled_commits.len() ); TransactionScheduler::default() - .accept_scheduled_l1_message(scheduled_commits); + .accept_scheduled_base_intent(scheduled_commits); // 4. Serialize and store the updated `MagicContext` account // Zero fill account before updating data diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs b/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs similarity index 92% rename from programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs rename to programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs index fcc016630..b714fdfed 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_l1_message.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs @@ -8,11 +8,11 @@ use solana_sdk::{ }; use crate::{ - args::MagicL1MessageArgs, - magic_scheduled_l1_message::{ConstructionContext, ScheduledL1Message}, + args::MagicBaseIntentArgs, + magic_scheduled_base_intent::{ConstructionContext, ScheduledBaseIntent}, schedule_transactions::{ check_magic_context_id, - schedule_l1_message_processor::schedule_l1_message_processor, + schedule_base_intent_processor::schedule_base_intent_processor, MESSAGE_ID, }, utils::accounts::{ @@ -26,10 +26,10 @@ const MAGIC_CONTEXT_IDX: u16 = PAYER_IDX + 1; const ACTION_ACCOUNTS_OFFSET: usize = MAGIC_CONTEXT_IDX as usize + 1; const ACTIONS_SUPPORTED: bool = false; -pub(crate) fn process_schedule_l1_message( +pub(crate) fn process_schedule_base_intent( signers: HashSet, invoke_context: &mut InvokeContext, - args: MagicL1MessageArgs, + args: MagicBaseIntentArgs, ) -> Result<(), InstructionError> { // TODO: remove once actions are supported if !ACTIONS_SUPPORTED { @@ -104,7 +104,7 @@ pub(crate) fn process_schedule_l1_message( transaction_context, invoke_context, ); - let scheduled_action = ScheduledL1Message::try_new( + let scheduled_action = ScheduledBaseIntent::try_new( &args, message_id, clock.slot, @@ -113,7 +113,7 @@ pub(crate) fn process_schedule_l1_message( )?; // TODO: move all logic to some Processor // Rn this just locks accounts - schedule_l1_message_processor(&construction_context, &args)?; + schedule_base_intent_processor(&construction_context, &args)?; let action_sent_signature = scheduled_action.action_sent_transaction.signatures[0]; @@ -122,7 +122,7 @@ pub(crate) fn process_schedule_l1_message( transaction_context, MAGIC_CONTEXT_IDX, )?; - TransactionScheduler::schedule_l1_message( + TransactionScheduler::schedule_base_intent( invoke_context, context_acc, scheduled_action, diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs index cdc3d33e3..e1044798d 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs @@ -9,9 +9,9 @@ use solana_sdk::{ }; use crate::{ - magic_scheduled_l1_message::{ - CommitAndUndelegate, CommitType, CommittedAccountV2, MagicL1Message, - ScheduledL1Message, UndelegateType, + magic_scheduled_base_intent::{ + CommitAndUndelegate, CommitType, CommittedAccountV2, MagicBaseIntent, + ScheduledBaseIntent, UndelegateType, }, schedule_transactions, schedule_transactions::{ @@ -205,22 +205,22 @@ pub(crate) fn process_schedule_commit( let commit_sent_sig = commit_sent_transaction.signatures[0]; - let l1_message = if opts.request_undelegation { - MagicL1Message::CommitAndUndelegate(CommitAndUndelegate { + let base_intent = if opts.request_undelegation { + MagicBaseIntent::CommitAndUndelegate(CommitAndUndelegate { commit_action: CommitType::Standalone(committed_accounts), undelegate_action: UndelegateType::Standalone, }) } else { - MagicL1Message::Commit(CommitType::Standalone(committed_accounts)) + MagicBaseIntent::Commit(CommitType::Standalone(committed_accounts)) }; - let scheduled_l1_message = ScheduledL1Message { + let scheduled_base_intent = ScheduledBaseIntent { id: commit_id, slot: clock.slot, blockhash, action_sent_transaction: commit_sent_transaction, payer: *payer_pubkey, - l1_message, + base_intent, }; // NOTE: this is only protected by all the above checks however if the @@ -230,10 +230,10 @@ pub(crate) fn process_schedule_commit( transaction_context, MAGIC_CONTEXT_IDX, )?; - TransactionScheduler::schedule_l1_message( + TransactionScheduler::schedule_base_intent( invoke_context, context_acc, - scheduled_l1_message, + scheduled_base_intent, ) .map_err(|err| { ic_msg!( diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs index 5540d1eab..941717023 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs @@ -19,7 +19,7 @@ use test_tools_core::init_logger; use crate::{ magic_context::MagicContext, - magic_scheduled_l1_message::ScheduledL1Message, + magic_scheduled_base_intent::ScheduledBaseIntent, magicblock_instruction::MagicBlockInstruction, schedule_transactions::transaction_scheduler::TransactionScheduler, test_utils::{ensure_started_validator, process_instruction}, @@ -146,7 +146,7 @@ fn assert_non_accepted_actions<'a>( let accepted_scheduled_actions = TransactionScheduler::default().get_scheduled_actions_by_payer(payer); assert_eq!( - magic_context.scheduled_commits.len(), + magic_context.scheduled_base_intents.len(), expected_non_accepted_commits ); assert_eq!(accepted_scheduled_actions.len(), 0); @@ -158,7 +158,7 @@ fn assert_accepted_actions( processed_accepted: &[AccountSharedData], payer: &Pubkey, expected_scheduled_actions: usize, -) -> Vec { +) -> Vec { let magic_context_acc = find_magic_context_account(processed_accepted) .expect("magic context account not found"); let magic_context = @@ -167,7 +167,7 @@ fn assert_accepted_actions( let scheduled_actions = TransactionScheduler::default().get_scheduled_actions_by_payer(payer); - assert_eq!(magic_context.scheduled_commits.len(), 0); + assert_eq!(magic_context.scheduled_base_intents.len(), 0); assert_eq!(scheduled_actions.len(), expected_scheduled_actions); scheduled_actions @@ -204,30 +204,30 @@ fn extend_transaction_accounts_from_ix_adding_magic_context( } fn assert_first_commit( - scheduled_l1_messages: &[ScheduledL1Message], + scheduled_base_intents: &[ScheduledBaseIntent], payer: &Pubkey, committees: &[Pubkey], expected_request_undelegation: bool, ) { - let scheduled_l1_message = &scheduled_l1_messages[0]; + let scheduled_base_intent = &scheduled_base_intents[0]; let test_clock = get_clock(); assert_matches!( - scheduled_l1_message, - ScheduledL1Message { + scheduled_base_intent, + ScheduledBaseIntent { id, slot, payer: actual_payer, blockhash: _, action_sent_transaction, - l1_message, + base_intent, } => { assert!(id >= &0); assert_eq!(slot, &test_clock.slot); assert_eq!(actual_payer, payer); - assert_eq!(l1_message.get_committed_pubkeys().unwrap().as_slice(), committees); + assert_eq!(base_intent.get_committed_pubkeys().unwrap().as_slice(), committees); let instruction = MagicBlockInstruction::ScheduledCommitSent(*id); assert_eq!(action_sent_transaction.data(0), instruction.try_to_vec().unwrap()); - assert_eq!(l1_message.is_undelegate(), expected_request_undelegation); + assert_eq!(base_intent.is_undelegate(), expected_request_undelegation); } ); } @@ -305,14 +305,14 @@ mod tests { ); // At this point the intended commits were accepted and moved to the global - let scheduled_messages = assert_accepted_actions( + let scheduled_intents = assert_accepted_actions( &processed_accepted, &payer.pubkey(), 1, ); assert_first_commit( - &scheduled_messages, + &scheduled_intents, &payer.pubkey(), &[committee], false, @@ -503,12 +503,6 @@ mod tests { 1, ); - // let scheduled_commits = scheduled_commits - // .into_iter() - // .map(|el| el.try_into()) - // .collect::, MagicL1Message>>() - // .expect("only commit action"); - assert_first_commit( &scheduled_commits, &payer.pubkey(), @@ -618,12 +612,6 @@ mod tests { 1, ); - // let scheduled_commits = scheduled_commits - // .into_iter() - // .map(|el| el.try_into()) - // .collect::, MagicL1Message>>() - // .expect("only commit action"); - assert_first_commit( &scheduled_commits, &payer.pubkey(), diff --git a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs similarity index 72% rename from programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs rename to programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs index 85beb5e12..fed81d608 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_l1_message_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs @@ -1,24 +1,26 @@ use solana_sdk::instruction::InstructionError; use crate::{ - args::MagicL1MessageArgs, - magic_scheduled_l1_message::{CommitType, ConstructionContext}, + args::MagicBaseIntentArgs, + magic_scheduled_base_intent::{CommitType, ConstructionContext}, utils::account_actions::set_account_owner_to_delegation_program, }; -pub fn schedule_l1_message_processor<'a, 'ic>( +pub fn schedule_base_intent_processor<'a, 'ic>( construction_context: &ConstructionContext<'a, 'ic>, - args: &MagicL1MessageArgs, + args: &MagicBaseIntentArgs, ) -> Result<(), InstructionError> { let commited_accounts_ref = match args { - MagicL1MessageArgs::Commit(commit_type) => { + MagicBaseIntentArgs::Commit(commit_type) => { let accounts_indices = commit_type.committed_accounts_indices(); CommitType::extract_commit_accounts( accounts_indices, construction_context.transaction_context, )? } - MagicL1MessageArgs::CommitAndUndelegate(commit_and_undelegate_type) => { + MagicBaseIntentArgs::CommitAndUndelegate( + commit_and_undelegate_type, + ) => { let accounts_indices = commit_and_undelegate_type.committed_accounts_indices(); CommitType::extract_commit_accounts( @@ -26,7 +28,7 @@ pub fn schedule_l1_message_processor<'a, 'ic>( construction_context.transaction_context, )? } - MagicL1MessageArgs::L1Actions(_) => return Ok(()), + MagicBaseIntentArgs::BaseActions(_) => return Ok(()), }; // TODO: proper explanation diff --git a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs index b5551c101..19aeb5bf8 100644 --- a/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs +++ b/programs/magicblock/src/schedule_transactions/transaction_scheduler.rs @@ -13,12 +13,13 @@ use solana_sdk::{ }; use crate::{ - magic_context::MagicContext, magic_scheduled_l1_message::ScheduledL1Message, + magic_context::MagicContext, + magic_scheduled_base_intent::ScheduledBaseIntent, }; #[derive(Clone)] pub struct TransactionScheduler { - scheduled_l1_message: Arc>>, + scheduled_base_intents: Arc>>, } impl Default for TransactionScheduler { @@ -27,20 +28,20 @@ impl Default for TransactionScheduler { /// This vec tracks commits that went through the entire process of first /// being scheduled into the MagicContext, and then being moved /// over to this global. - static ref SCHEDULED_ACTION: Arc>> = + static ref SCHEDULED_ACTION: Arc>> = Default::default(); } Self { - scheduled_l1_message: SCHEDULED_ACTION.clone(), + scheduled_base_intents: SCHEDULED_ACTION.clone(), } } } impl TransactionScheduler { - pub fn schedule_l1_message( + pub fn schedule_base_intent( invoke_context: &InvokeContext, context_account: &RefCell, - action: ScheduledL1Message, + action: ScheduledBaseIntent, ) -> Result<(), InstructionError> { let context_data = &mut context_account.borrow_mut(); let mut context = @@ -57,22 +58,22 @@ impl TransactionScheduler { Ok(()) } - pub fn accept_scheduled_l1_message( + pub fn accept_scheduled_base_intent( &self, - commits: Vec, + base_intents: Vec, ) { - self.scheduled_l1_message + self.scheduled_base_intents .write() .expect("scheduled_action lock poisoned") - .extend(commits); + .extend(base_intents); } pub fn get_scheduled_actions_by_payer( &self, payer: &Pubkey, - ) -> Vec { + ) -> Vec { let commits = self - .scheduled_l1_message + .scheduled_base_intents .read() .expect("scheduled_action lock poisoned"); @@ -83,9 +84,9 @@ impl TransactionScheduler { .collect::>() } - pub fn take_scheduled_actions(&self) -> Vec { + pub fn take_scheduled_actions(&self) -> Vec { let mut lock = self - .scheduled_l1_message + .scheduled_base_intents .write() .expect("scheduled_action lock poisoned"); mem::take(&mut *lock) @@ -93,7 +94,7 @@ impl TransactionScheduler { pub fn scheduled_actions_len(&self) -> usize { let lock = self - .scheduled_l1_message + .scheduled_base_intents .read() .expect("scheduled_action lock poisoned"); @@ -102,7 +103,7 @@ impl TransactionScheduler { pub fn clear_scheduled_actions(&self) { let mut lock = self - .scheduled_l1_message + .scheduled_base_intents .write() .expect("scheduled_action lock poisoned"); lock.clear(); diff --git a/programs/magicblock/src/utils/accounts.rs b/programs/magicblock/src/utils/accounts.rs index a161d79de..42f5debf2 100644 --- a/programs/magicblock/src/utils/accounts.rs +++ b/programs/magicblock/src/utils/accounts.rs @@ -11,7 +11,7 @@ use solana_sdk::{ transaction_context::TransactionContext, }; -use crate::magic_scheduled_l1_message::ShortAccountMeta; +use crate::magic_scheduled_base_intent::ShortAccountMeta; pub(crate) fn find_tx_index_of_instruction_account( invoke_context: &InvokeContext, diff --git a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs index a1e9eb7a9..05edd205d 100644 --- a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs +++ b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs @@ -1,5 +1,5 @@ use log::*; -use magicblock_committor_service::{L1MessageCommittor, ComputeBudgetConfig}; +use magicblock_committor_service::{BaseIntentCommittor, ComputeBudgetConfig}; use magicblock_rpc_client::MagicblockRpcClient; use std::collections::{HashMap, HashSet}; use std::time::{Duration, Instant}; @@ -659,7 +659,7 @@ async fn ix_commit_local( let ephemeral_blockhash = Hash::default(); let reqid = service - .commit_l1_messages(changeset.clone(), ephemeral_blockhash, finalize) + .commit_base_intent(changeset.clone(), ephemeral_blockhash, finalize) .await .unwrap() .unwrap(); From 50b05dd2c1e2e6b2b349bf990656ed24d95fd74d Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 31 Jul 2025 13:31:55 +0900 Subject: [PATCH 150/199] feat: updated sdk --- test-integration/Cargo.lock | 20 ++++++++++---------- test-integration/Cargo.toml | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 31b26d174..53487ce08 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1747,21 +1747,21 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e7daea58d672a22f1d221ef7c1607b14f900f029#e7daea58d672a22f1d221ef7c1607b14f900f029" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=63f624f#63f624f3e24007a77a06c1c223e07d6a351244f1" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk-attribute-commit", "ephemeral-rollups-sdk-attribute-delegate", "ephemeral-rollups-sdk-attribute-ephemeral", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", - "magicblock-program 0.1.2 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd)", + "magicblock-program 0.1.2 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=aed2b895daf720507ded57d63b277b0e95435f10)", "solana-program", ] [[package]] name = "ephemeral-rollups-sdk-attribute-commit" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e7daea58d672a22f1d221ef7c1607b14f900f029#e7daea58d672a22f1d221ef7c1607b14f900f029" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=63f624f#63f624f3e24007a77a06c1c223e07d6a351244f1" dependencies = [ "quote", "syn 1.0.109", @@ -1770,7 +1770,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-delegate" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e7daea58d672a22f1d221ef7c1607b14f900f029#e7daea58d672a22f1d221ef7c1607b14f900f029" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=63f624f#63f624f3e24007a77a06c1c223e07d6a351244f1" dependencies = [ "proc-macro2", "quote", @@ -1780,7 +1780,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-ephemeral" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e7daea58d672a22f1d221ef7c1607b14f900f029#e7daea58d672a22f1d221ef7c1607b14f900f029" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=63f624f#63f624f3e24007a77a06c1c223e07d6a351244f1" dependencies = [ "proc-macro2", "quote", @@ -3762,7 +3762,7 @@ dependencies = [ [[package]] name = "magicblock-core" version = "0.1.2" -source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd#3b4312b05188d9a4256b906e5dcf8327c2a3c9dd" +source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=aed2b895daf720507ded57d63b277b0e95435f10#aed2b895daf720507ded57d63b277b0e95435f10" dependencies = [ "solana-sdk", ] @@ -3875,7 +3875,7 @@ dependencies = [ [[package]] name = "magicblock-metrics" version = "0.1.2" -source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd#3b4312b05188d9a4256b906e5dcf8327c2a3c9dd" +source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=aed2b895daf720507ded57d63b277b0e95435f10#aed2b895daf720507ded57d63b277b0e95435f10" dependencies = [ "http-body-util", "hyper 1.6.0", @@ -3950,12 +3950,12 @@ dependencies = [ [[package]] name = "magicblock-program" version = "0.1.2" -source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd#3b4312b05188d9a4256b906e5dcf8327c2a3c9dd" +source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=aed2b895daf720507ded57d63b277b0e95435f10#aed2b895daf720507ded57d63b277b0e95435f10" dependencies = [ "bincode", "lazy_static", - "magicblock-core 0.1.2 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd)", - "magicblock-metrics 0.1.2 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=3b4312b05188d9a4256b906e5dcf8327c2a3c9dd)", + "magicblock-core 0.1.2 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=aed2b895daf720507ded57d63b277b0e95435f10)", + "magicblock-metrics 0.1.2 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=aed2b895daf720507ded57d63b277b0e95435f10)", "num-derive", "num-traits", "serde", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 50bba6922..56788d7b1 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -28,7 +28,7 @@ anyhow = "1.0.86" borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" #ephemeral-rollups-sdk = { path = "../../ephemeral-rollups-sdk/rust/sdk" } -ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "e7daea58d672a22f1d221ef7c1607b14f900f029" } +ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "63f624f" } integration-test-tools = { path = "test-tools" } log = "0.4.20" magicblock-api = { path = "../magicblock-api" } From 9ff9009f414aa028ef4ce97b8186f6e90953305f Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 31 Jul 2025 15:22:18 +0900 Subject: [PATCH 151/199] fix: fixed failing tests due to low specified compute untis --- .../src/intent_executor/intent_executor.rs | 10 +++++++--- magicblock-committor-service/src/tasks/tasks.rs | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index 725db5bef..2a8709d84 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -1,4 +1,4 @@ -use log::warn; +use log::{info, warn}; use magicblock_program::{ magic_scheduled_base_intent::ScheduledBaseIntent, validator::validator_authority, @@ -51,12 +51,15 @@ where persister: &Option

, ) -> IntentExecutorResult { // Update tasks status to Pending - // let update_status = CommitStatus::Pending; - // persist_status_update_set(&persister, &commit_ids, update_status); + if let Some(pubkeys) = base_intent.get_committed_pubkeys() { + let update_status = CommitStatus::Pending; + persist_status_update_by_message_set(&persister, base_intent.id, &pubkeys, update_status); + } // Commit stage let commit_signature = self.execute_commit_stage(&base_intent, persister).await?; + info!("Commit stage succeeded: {}", commit_signature); // Finalize stage // At the moment validator finalizes right away @@ -64,6 +67,7 @@ where let finalize_signature = self .execute_finalize_stage(&base_intent, commit_signature, persister) .await?; + info!("Finalize stage succeeded: {}", finalize_signature); Ok(ExecutionOutput { commit_signature, diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index 4a0e59e78..dccbfb26b 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -178,10 +178,10 @@ impl BaseTask for ArgsTask { fn compute_units(&self) -> u32 { match self { - Self::Commit(_) => 50_000, + Self::Commit(_) => 45_000, Self::L1Action(task) => task.action.compute_units, - Self::Undelegate(_) => 35_000, - Self::Finalize(_) => 25_000, + Self::Undelegate(_) => 50_000, + Self::Finalize(_) => 40_000, } } @@ -293,7 +293,7 @@ impl BaseTask for BufferTask { fn compute_units(&self) -> u32 { match self { - Self::Commit(_) => 50_000, + Self::Commit(_) => 45_000, } } From 04a33f53aeb7a5f33b3d947dfafee4dbae0459fd Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 31 Jul 2025 18:23:17 +0900 Subject: [PATCH 152/199] fix: committor tests --- .../src/committor_processor.rs | 3 +- .../src/intent_executor/intent_executor.rs | 7 +- magicblock-committor-service/src/lib.rs | 6 - .../src/service_ext.rs | 15 +- .../src/stubs/changeset_committor_stub.rs | 5 +- .../transaction_preparator.rs | 15 +- magicblock-committor-service/src/types.rs | 10 + test-integration/Cargo.lock | 1 + test-integration/Cargo.toml | 1 + .../committor-service/Cargo.toml | 1 + .../tests/ix_commit_local.rs | 415 ++++++++---------- 11 files changed, 223 insertions(+), 256 deletions(-) diff --git a/magicblock-committor-service/src/committor_processor.rs b/magicblock-committor-service/src/committor_processor.rs index 65093a672..07924f8fc 100644 --- a/magicblock-committor-service/src/committor_processor.rs +++ b/magicblock-committor-service/src/committor_processor.rs @@ -135,8 +135,7 @@ impl CommittorProcessor { .iter() .map(|l1_message| l1_message.inner.clone()) .collect::>(); - if let Err(err) = self.persister.start_base_intents(&intents) - { + if let Err(err) = self.persister.start_base_intents(&intents) { // We will still try to perform the commits, but the fact that we cannot // persist the intent is very serious and we should probably restart the // valiator diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index 2a8709d84..8e4200abe 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -53,7 +53,12 @@ where // Update tasks status to Pending if let Some(pubkeys) = base_intent.get_committed_pubkeys() { let update_status = CommitStatus::Pending; - persist_status_update_by_message_set(&persister, base_intent.id, &pubkeys, update_status); + persist_status_update_by_message_set( + &persister, + base_intent.id, + &pubkeys, + update_status, + ); } // Commit stage diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index bb7ef1370..c0d8f2400 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -25,9 +25,3 @@ pub use magicblock_committor_program::{ ChangedAccount, Changeset, ChangesetMeta, }; pub use service::{BaseIntentCommittor, CommittorService}; -pub fn changeset_for_slot(slot: u64) -> Changeset { - Changeset { - slot, - ..Changeset::default() - } -} diff --git a/magicblock-committor-service/src/service_ext.rs b/magicblock-committor-service/src/service_ext.rs index 5a8f65523..7f6ea8dcb 100644 --- a/magicblock-committor-service/src/service_ext.rs +++ b/magicblock-committor-service/src/service_ext.rs @@ -75,7 +75,9 @@ impl CommittorServiceExt { }; if let Err(_) = sender.send(execution_result) { - error!("Failed to send BaseIntent execution result to listener"); + error!( + "Failed to send BaseIntent execution result to listener" + ); } } } @@ -103,9 +105,9 @@ impl BaseIntentCommittorExt vacant.insert(sender); Ok(receiver) } - Entry::Occupied(_) => Err( - Error::RepeatingMessageError(intent.inner.id), - ), + Entry::Occupied(_) => { + Err(Error::RepeatingMessageError(intent.inner.id)) + } } }) .collect::, _>>()? @@ -129,7 +131,10 @@ impl BaseIntentCommittor for CommittorServiceExt { self.inner.reserve_pubkeys_for_committee(committee, owner) } - fn commit_base_intent(&self, base_intents: Vec) { + fn commit_base_intent( + &self, + base_intents: Vec, + ) { self.inner.commit_base_intent(base_intents) } diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index 2fe717913..0fd8000fc 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -53,7 +53,10 @@ impl BaseIntentCommittor for ChangesetCommittorStub { rx } - fn commit_base_intent(&self, base_intents: Vec) { + fn commit_base_intent( + &self, + base_intents: Vec, + ) { let mut changesets = self.committed_changesets.lock().unwrap(); base_intents.into_iter().for_each(|intent| { changesets.insert(intent.inner.id, intent); diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs index 0de4ae2e6..10a0e62d4 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs @@ -130,11 +130,7 @@ where // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self .delivery_preparator - .prepare_for_delivery( - authority, - &tx_strategy, - intent_persister, - ) + .prepare_for_delivery(authority, &tx_strategy, intent_persister) .await?; // Build resulting TX to be executed @@ -159,7 +155,8 @@ where ) -> PreparatorResult { // create tasks let tasks = - TaskBuilderV1::finalize_tasks(&self.rpc_client, base_intent).await?; + TaskBuilderV1::finalize_tasks(&self.rpc_client, base_intent) + .await?; // optimize to fit tx size. aka Delivery Strategy let tx_strategy = TaskStrategist::build_strategy( tasks, @@ -169,11 +166,7 @@ where // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self .delivery_preparator - .prepare_for_delivery( - authority, - &tx_strategy, - intent_presister, - ) + .prepare_for_delivery(authority, &tx_strategy, intent_presister) .await?; let message = TransactionUtils::assemble_tasks_tx( diff --git a/magicblock-committor-service/src/types.rs b/magicblock-committor-service/src/types.rs index 8fa628b3a..87b1bddf9 100644 --- a/magicblock-committor-service/src/types.rs +++ b/magicblock-committor-service/src/types.rs @@ -1,3 +1,5 @@ +use std::ops::Deref; + use magicblock_program::{ magic_scheduled_base_intent::ScheduledBaseIntent, FeePayerAccount, }; @@ -18,3 +20,11 @@ pub struct ScheduledBaseIntentWrapper { pub excluded_pubkeys: Vec, pub trigger_type: TriggerType, } + +impl Deref for ScheduledBaseIntentWrapper { + type Target = ScheduledBaseIntent; + + fn deref(&self) -> &Self::Target { + &self.inner + } +} diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 53487ce08..b6834eee8 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -5804,6 +5804,7 @@ dependencies = [ "magicblock-committor-program", "magicblock-committor-service", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-program 0.1.2", "magicblock-rpc-client", "program-flexi-counter", "solana-account", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 56788d7b1..1e6230815 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -44,6 +44,7 @@ magicblock-delegation-program = { git = "https://github.com/magicblock-labs/dele magicblock-committor-service = { path = "../magicblock-committor-service" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } magicblock-table-mania = { path = "../magicblock-table-mania" } +magicblock-program = { path = "../programs/magicblock" } paste = "1.0" program-flexi-counter = { path = "./programs/flexi-counter" } program-schedulecommit = { path = "programs/schedulecommit" } diff --git a/test-integration/schedulecommit/committor-service/Cargo.toml b/test-integration/schedulecommit/committor-service/Cargo.toml index 7667e32ce..e9e5902c3 100644 --- a/test-integration/schedulecommit/committor-service/Cargo.toml +++ b/test-integration/schedulecommit/committor-service/Cargo.toml @@ -14,6 +14,7 @@ magicblock-delegation-program = { workspace = true, features = [ magicblock-committor-service = { workspace = true, features = [ "dev-context-only-utils", ] } +magicblock-program = { workspace = true } magicblock-rpc-client = { workspace = true } program-flexi-counter = { workspace = true, features = ["no-entrypoint"] } solana-account = { workspace = true } diff --git a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs index 05edd205d..7055a42af 100644 --- a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs +++ b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs @@ -2,18 +2,28 @@ use log::*; use magicblock_committor_service::{BaseIntentCommittor, ComputeBudgetConfig}; use magicblock_rpc_client::MagicblockRpcClient; use std::collections::{HashMap, HashSet}; +use std::sync::Arc; use std::time::{Duration, Instant}; use test_tools_core::init_logger; use tokio::task::JoinSet; use utils::transactions::tx_logs_contain; use magicblock_committor_program::{ChangedAccount, Changeset}; +use magicblock_committor_service::service_ext::{ + BaseIntentCommittorExt, CommittorServiceExt, +}; +use magicblock_committor_service::types::{ + ScheduledBaseIntentWrapper, TriggerType, +}; use magicblock_committor_service::{ - changeset_for_slot, config::ChainConfig, persist::{CommitStatus, CommitStrategy}, CommittorService, }; +use magicblock_program::magic_scheduled_base_intent::{ + CommitAndUndelegate, CommitType, CommittedAccountV2, MagicBaseIntent, + ScheduledBaseIntent, UndelegateType, +}; use solana_account::{Account, AccountSharedData, ReadableAccount}; use solana_pubkey::Pubkey; use solana_rpc_client::nonblocking::rpc_client::RpcClient; @@ -219,15 +229,21 @@ async fn init_and_delegate_account_on_chain( } debug!("Reallocs done"); - // 4. Delegate account - rpc_client + // 1. Create the transaction first + let transaction = Transaction::new_signed_with_payer( + &[delegate_ix], + Some(&counter_auth.pubkey()), + &[&counter_auth], + latest_block_hash, + ); + + // Get the signature before sending + let tx_signature = transaction.signatures[0]; // The first signature is the transaction ID + + // 2. Send and confirm + match rpc_client .send_and_confirm_transaction_with_spinner_and_config( - &Transaction::new_signed_with_payer( - &[delegate_ix], - Some(&counter_auth.pubkey()), - &[&counter_auth], - latest_block_hash, - ), + &transaction, CommitmentConfig::confirmed(), RpcSendTransactionConfig { skip_preflight: true, @@ -235,7 +251,14 @@ async fn init_and_delegate_account_on_chain( }, ) .await - .expect("Failed to delegate"); + { + Ok(_) => println!("Transaction successful: {}", tx_signature), + Err(e) => { + println!("Transaction failed but signature is: {}", tx_signature); + println!("Error: {:?}", e); + // You can now use tx_signature to look up the transaction details + } + } debug!("Delegated account: {:?}", pda); let pda_acc = get_account!(rpc_client, pda, "pda"); @@ -251,38 +274,34 @@ async fn init_and_delegate_account_on_chain( // ----------------- #[tokio::test] async fn test_ix_commit_single_account_100_bytes() { - commit_single_account(100, CommitStrategy::Args, false).await; + commit_single_account(100, false).await; } #[tokio::test] async fn test_ix_commit_single_account_100_bytes_and_undelegate() { - commit_single_account(100, CommitStrategy::Args, true).await; + commit_single_account(100, true).await; } #[tokio::test] async fn test_ix_commit_single_account_800_bytes() { - commit_single_account(800, CommitStrategy::FromBuffer, false).await; + commit_single_account(800, false).await; } #[tokio::test] async fn test_ix_commit_single_account_800_bytes_and_undelegate() { - commit_single_account(800, CommitStrategy::FromBuffer, true).await; + commit_single_account(800, true).await; } #[tokio::test] async fn test_ix_commit_single_account_one_kb() { - commit_single_account(1024, CommitStrategy::FromBuffer, false).await; + commit_single_account(1024, false).await; } #[tokio::test] async fn test_ix_commit_single_account_ten_kb() { - commit_single_account(10 * 1024, CommitStrategy::FromBuffer, false).await; + commit_single_account(10 * 1024, false).await; } -async fn commit_single_account( - bytes: usize, - expected_strategy: CommitStrategy, - undelegate: bool, -) { +async fn commit_single_account(bytes: usize, undelegate: bool) { init_logger!(); let slot = 10; let validator_auth = utils::get_validator_auth(); @@ -290,46 +309,44 @@ async fn commit_single_account( fund_validator_auth_and_ensure_validator_fees_vault(&validator_auth).await; // Run each test with and without finalizing - for (idx, finalize) in [false, true].into_iter().enumerate() { - let service = CommittorService::try_start( - validator_auth.insecure_clone(), - ":memory:", - ChainConfig::local(ComputeBudgetConfig::new(1_000_000)), - ) - .unwrap(); - - let (changeset, chain_lamports) = { - let mut changeset = changeset_for_slot(slot); - let mut chain_lamports = HashMap::new(); - let counter_auth = Keypair::new(); - let (pda, pda_acc) = - init_and_delegate_account_on_chain(&counter_auth, bytes as u64) - .await; - let account = Account { - lamports: LAMPORTS_PER_SOL, - data: vec![8; bytes], - owner: program_flexi_counter::id(), - ..Account::default() - }; - let account_shared = AccountSharedData::from(account); - let bundle_id = idx as u64; - changeset.add(pda, (account_shared, bundle_id)); - if undelegate { - changeset.request_undelegation(pda); - } - chain_lamports.insert(pda, pda_acc.lamports()); - (changeset, chain_lamports) - }; - - ix_commit_local( - service, - changeset.clone(), - chain_lamports.clone(), - finalize, - expect_strategies(&[(expected_strategy, 1)]), - ) - .await; - } + let service = CommittorService::try_start( + validator_auth.insecure_clone(), + ":memory:", + ChainConfig::local(ComputeBudgetConfig::new(1_000_000)), + ) + .unwrap(); + let service = CommittorServiceExt::new(Arc::new(service)); + + let counter_auth = Keypair::new(); + let (pubkey, account) = + init_and_delegate_account_on_chain(&counter_auth, bytes as u64) + .await; + + let account = CommittedAccountV2 { pubkey, account }; + let base_intent = if undelegate { + MagicBaseIntent::CommitAndUndelegate(CommitAndUndelegate { + commit_action: CommitType::Standalone(vec![account]), + undelegate_action: UndelegateType::Standalone, + }) + } else { + MagicBaseIntent::Commit(CommitType::Standalone(vec![account])) + }; + + let intent = ScheduledBaseIntentWrapper { + excluded_pubkeys: vec![], + feepayers: vec![], + trigger_type: TriggerType::OnChain, + inner: ScheduledBaseIntent { + id: 0, + slot, + blockhash: Hash::new_unique(), + action_sent_transaction: Transaction::default(), + payer: counter_auth.pubkey(), + base_intent, + }, + }; + + ix_commit_local(service, vec![intent]).await; } // TODO(thlorenz): once delegation program supports larger commits @@ -521,22 +538,18 @@ async fn commit_multiple_accounts( fund_validator_auth_and_ensure_validator_fees_vault(&validator_auth).await; - for finalize in [false, true] { - let mut changeset = changeset_for_slot(slot); - + { let service = CommittorService::try_start( validator_auth.insecure_clone(), ":memory:", ChainConfig::local(ComputeBudgetConfig::new(1_000_000)), ) .unwrap(); + let service = CommittorServiceExt::new(Arc::new(service)); let committees = bytess.iter().map(|_| Keypair::new()).collect::>(); - let mut chain_lamports = HashMap::new(); - let expected_strategies = expected_strategies.clone(); - let mut join_set = JoinSet::new(); let mut bundle_id = 0; @@ -555,67 +568,72 @@ async fn commit_multiple_accounts( ) .await; - let account = Account { - lamports: LAMPORTS_PER_SOL, - data: vec![idx as u8; bytes], - owner: program_flexi_counter::id(), - ..Account::default() - }; - let account_shared = AccountSharedData::from(account); - let changed_account = - ChangedAccount::from((account_shared, bundle_id as u64)); - - // We can only undelegate accounts that are finalized - let request_undelegation = - finalize && (undelegate_all || idx % 2 == 0); - ( - pda, - pda_acc, - changed_account, - counter_auth.pubkey(), - request_undelegation, - ) + let request_undelegation = (undelegate_all || idx % 2 == 0); + (pda, pda_acc, request_undelegation) }); } - for ( - pda, - pda_acc, - changed_account, - counter_pubkey, - request_undelegation, - ) in join_set.join_all().await - { - changeset.add(pda, changed_account); - if request_undelegation { - changeset.request_undelegation(counter_pubkey); - } - chain_lamports.insert(pda, pda_acc.lamports()); - } - - if uses_lookup(&expected_strategies) { - let mut join_set = JoinSet::new(); - join_set.spawn(service.reserve_common_pubkeys()); - let owners = changeset.owners(); - for committee in changeset.account_keys().iter() { - join_set.spawn(service.reserve_pubkeys_for_committee( - **committee, - *owners.get(committee).unwrap(), - )); - } - debug!( - "Registering lookup tables for {} committees", - changeset.account_keys().len() + let (committed, commmitted_and_undelegated): (Vec<_>, Vec<_>) = + join_set.join_all().await.into_iter().partition( + |(_, _, request_undelegation)| !request_undelegation, ); - join_set.join_all().await; - } + + let committed_accounts = committed + .into_iter() + .map(|(pda, pda_acc, _)| CommittedAccountV2 { + pubkey: pda, + account: pda_acc, + }) + .collect::>(); + + let commit_intent = ScheduledBaseIntentWrapper { + excluded_pubkeys: vec![], + feepayers: vec![], + trigger_type: TriggerType::OnChain, + inner: ScheduledBaseIntent { + id: 1, + slot: 0, + blockhash: Hash::new_unique(), + action_sent_transaction: Transaction::default(), + payer: Pubkey::new_unique(), + base_intent: MagicBaseIntent::Commit(CommitType::Standalone( + committed_accounts, + )), + }, + }; + + let committed_and_undelegated_accounts = commmitted_and_undelegated + .into_iter() + .map(|(pda, pda_acc, _)| CommittedAccountV2 { + pubkey: pda, + account: pda_acc, + }) + .collect::>(); + + let commit_and_undelegate_intent = ScheduledBaseIntentWrapper { + excluded_pubkeys: vec![], + feepayers: vec![], + trigger_type: TriggerType::OnChain, + inner: ScheduledBaseIntent { + id: 1, + slot: 0, + blockhash: Hash::new_unique(), + action_sent_transaction: Transaction::default(), + payer: Pubkey::new_unique(), + base_intent: MagicBaseIntent::CommitAndUndelegate( + CommitAndUndelegate { + commit_action: CommitType::Standalone( + committed_and_undelegated_accounts, + ), + undelegate_action: UndelegateType::Standalone, + }, + ), + }, + }; ix_commit_local( service, - changeset.clone(), - chain_lamports.clone(), - finalize, - expected_strategies, + vec![commit_intent, commit_and_undelegate_intent], ) .await; } @@ -649,107 +667,72 @@ async fn commit_multiple_accounts( // Test Executor // ----------------- async fn ix_commit_local( - service: CommittorService, - changeset: Changeset, - chain_lamports: HashMap, - finalize: bool, - expected_strategies: ExpectedStrategies, + service: CommittorServiceExt, + base_intents: Vec, ) { - let rpc_client = RpcClient::new("http://localhost:7799".to_string()); - - let ephemeral_blockhash = Hash::default(); - let reqid = service - .commit_base_intent(changeset.clone(), ephemeral_blockhash, finalize) + let execution_outputs = service + .schedule_base_intents_waiting(base_intents.clone()) .await .unwrap() - .unwrap(); - let statuses = service.get_commit_statuses(reqid).await.unwrap().unwrap(); - service.release_common_pubkeys().await.unwrap(); - - debug!( - "{}", - statuses - .iter() - .map(|x| x.to_string()) - .collect::>() - .join("\n") - ); - assert_eq!(statuses.len(), changeset.accounts.len()); - assert!(CommitStatus::all_completed( - &statuses - .iter() - .map(|x| x.commit_status.clone()) - .collect::>() - )); - let mut strategies = ExpectedStrategies::new(); - for res in statuses { - let change = changeset.accounts.get(&res.pubkey).cloned().unwrap(); - let lamports = if finalize { - change.lamports() - } else { - // The commit state account will hold only the lamports needed - // to be rent exempt and debit the delegated account to reach the - // lamports of the account as changed in the ephemeral - change.lamports() - chain_lamports[&res.pubkey] - }; + .into_iter() + .collect::, _>>() + .expect("Some commits failed"); - // Track the strategy used - let strategy = res.commit_status.commit_strategy(); - let strategy_count = strategies.entry(strategy).or_insert(0); - *strategy_count += 1; + // Assert that all completed + assert_eq!(execution_outputs.len(), base_intents.len()); + service.release_common_pubkeys().await.unwrap(); + let rpc_client = RpcClient::new("http://localhost:7799".to_string()); + for (execution_output, intent) in + execution_outputs.into_iter().zip(base_intents) + { // Ensure that the signatures are pointing to the correct transactions - let signatures = - res.commit_status.signatures().expect("Missing signatures"); - + let signatures = execution_output.output; + // Execution output presents of complete stages, both commit & finalize + // Since finalization isn't optional and is a part of the flow + // Assert that both indeed happened assert!( tx_logs_contain( &rpc_client, - &signatures.process_signature, + &signatures.commit_signature, "CommitState" ) .await ); + assert!( + tx_logs_contain( + &rpc_client, + &signatures.finalize_signature, + "Finalize" + ) + .await + ); - // If we finalized the commit then the delegate account should have the - // committed state, otherwise it is still held in the commit state account - // NOTE: that we verify data/lamports via the get_account! condition - if finalize { - assert!( - signatures.finalize_signature.is_some(), - "Missing finalize signature" - ); + let is_undelegate = intent.is_undelegate(); + if is_undelegate { + // Undelegate is part of atomic Finalization Stage assert!( tx_logs_contain( &rpc_client, - &signatures.finalize_signature.unwrap(), - "Finalize" + &signatures.finalize_signature, + "Undelegate" ) .await ); - if res.undelegate { - assert!( - signatures.undelegate_signature.is_some(), - "Missing undelegate signature" - ); - assert!( - tx_logs_contain( - &rpc_client, - &signatures.undelegate_signature.unwrap(), - "Undelegate" - ) - .await - ); - } + } + let committed_accounts = intent.get_committed_accounts().unwrap(); + + for account in committed_accounts { + let lamports = account.account.lamports; get_account!( rpc_client, - res.pubkey, + account.pubkey, "delegated state", |acc: &Account, remaining_tries: u8| { - let matches_data = acc.data() == change.data() + let matches_data = acc.data() == account.account.data() && acc.lamports() == lamports; // When we finalize it is possible to also undelegate the account - let expected_owner = if res.undelegate { + let expected_owner = if is_undelegate { program_flexi_counter::id() } else { dlp::id() @@ -761,9 +744,9 @@ async fn ix_commit_local( if !matches_data { trace!( "Account ({}) data {} != {} || {} != {}", - res.pubkey, + account.pubkey, acc.data().len(), - change.data().len(), + account.account.data().len(), acc.lamports(), lamports ); @@ -771,8 +754,8 @@ async fn ix_commit_local( if !matches_undelegation { trace!( "Account ({}) is {} but should be. Owner {} != {}", - res.pubkey, - if res.undelegate { + account.pubkey, + if is_undelegate { "not undelegated" } else { "undelegated" @@ -784,38 +767,10 @@ async fn ix_commit_local( } matches_all } - ) - } else { - let commit_state_pda = - dlp::pda::commit_state_pda_from_delegated_account(&res.pubkey); - get_account!( - rpc_client, - commit_state_pda, - "commit state", - |acc: &Account, remaining_tries: u8| { - if remaining_tries % 4 == 0 { - trace!( - "Commit state ({}) {} == {}? {} == {}?", - commit_state_pda, - acc.data().len(), - change.data().len(), - acc.lamports(), - lamports - ); - } - acc.data() == change.data() && acc.lamports() == lamports - } - ) - }; + ); + } } - // Compare the strategies used with the expected ones - debug!("Strategies used: {:?}", strategies); - assert_eq!( - strategies, expected_strategies, - "Strategies used do not match expected ones" - ); - let expect_empty_lookup_tables = false; // changeset.accounts.len() == changeset.accounts_to_undelegate.len(); if expect_empty_lookup_tables { From 1390309295dd9fd8ced2eccbf9d19b369c87f0f4 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 31 Jul 2025 18:25:51 +0900 Subject: [PATCH 153/199] upd .lock --- Cargo.lock | 388 ++++++++++++++++++++++++++++------------------------- 1 file changed, 204 insertions(+), 184 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 328855b1d..021ac13f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,9 +65,9 @@ dependencies = [ [[package]] name = "agave-geyser-plugin-interface" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cc05bb1556871f5a726d43913cebf405061743274c3efd065d29802ababd795" +checksum = "df63ffb691b27f0253e893d083126cbe98a6b1ace29108992310f323f1ac50b0" dependencies = [ "log", "solana-clock", @@ -79,9 +79,9 @@ dependencies = [ [[package]] name = "agave-transaction-view" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f29ce15c77af7a2f010d1fafe51ccff6799f9c0ceea8c762f81a71babf5661b" +checksum = "aba2aec0682aa448f93db9b93df8fb331c119cb4d66fe9ba61d6b42dd3a91105" dependencies = [ "solana-hash", "solana-message", @@ -106,15 +106,15 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" dependencies = [ "cfg-if 1.0.0", - "getrandom 0.2.15", + "getrandom 0.3.1", "once_cell", "version_check", - "zerocopy", + "zerocopy 0.8.26", ] [[package]] @@ -1078,9 +1078,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.23" +version = "4.5.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882" dependencies = [ "clap_builder", "clap_derive", @@ -1088,9 +1088,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.23" +version = "4.5.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966" dependencies = [ "anstream", "anstyle", @@ -1100,9 +1100,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.18" +version = "4.5.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -2189,7 +2189,7 @@ name = "genx" version = "0.0.0" dependencies = [ "base64 0.21.7", - "clap 4.5.23", + "clap 4.5.42", "magicblock-accounts-db", "serde_json", "solana-rpc-client", @@ -2387,7 +2387,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.11", + "ahash 0.8.12", ] [[package]] @@ -2396,7 +2396,7 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "ahash 0.8.11", + "ahash 0.8.12", "allocator-api2", ] @@ -3515,9 +3515,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.26" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "lru" @@ -4965,7 +4965,7 @@ version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" dependencies = [ - "zerocopy", + "zerocopy 0.7.35", ] [[package]] @@ -6279,9 +6279,9 @@ dependencies = [ [[package]] name = "solana-account-decoder" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e32d6bb3088a606b60b75666dc96618cd26a60d69dd723668a6213a441bebe4b" +checksum = "c472eebf9ec7ee72c8d25e990a2eaf6b0b783619ef84d7954c408d6442ad5e57" dependencies = [ "Inflector", "base64 0.22.1", @@ -6318,9 +6318,9 @@ dependencies = [ [[package]] name = "solana-account-decoder-client-types" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9687660f80f15827f585d6a3dc1087987c22398ba9a1dd26395d4193152176" +checksum = "9b3485b583fcc58b5fa121fa0b4acb90061671fb1a9769493e8b4ad586581f47" dependencies = [ "base64 0.22.1", "bs58 0.5.1", @@ -6347,11 +6347,11 @@ dependencies = [ [[package]] name = "solana-accounts-db" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "845f01b47fa764b421ec06637f061ebdf507014dbc464fb0eb5342ea9d262375" +checksum = "d65a1a23a53cae19cb92bab2cbdd9e289e5210bb12175ce27642c94adf74b220" dependencies = [ - "ahash 0.8.11", + "ahash 0.8.12", "bincode", "blake3", "bv", @@ -6413,9 +6413,9 @@ dependencies = [ [[package]] name = "solana-address-lookup-table-program" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692f61425647168a357cb7ad8a9e3af0fb63dd4058a8fcce01708e37a331d61b" +checksum = "c758a82a60e5fcc93b3ee00615b0e244295aa8b2308475ea2b48f4900862a2e0" dependencies = [ "bincode", "bytemuck", @@ -6447,9 +6447,9 @@ dependencies = [ [[package]] name = "solana-banks-client" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01364483db3a7ad3546695df73eeec869fdb7399e8734b9a4d9ec5426d4bc932" +checksum = "420dc40674f4a4df1527277033554b1a1b84a47e780cdb7dad151426f5292e55" dependencies = [ "borsh 1.5.5", "futures 0.3.31", @@ -6464,9 +6464,9 @@ dependencies = [ [[package]] name = "solana-banks-interface" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d185017c022a9bc7b9b4709fdb15d4a3a4875548bb53d95d49f696476497879" +checksum = "02f8a6b6dc15262f14df6da7332e7dc7eb5fa04c86bf4dfe69385b71c2860d19" dependencies = [ "serde", "serde_derive", @@ -6476,9 +6476,9 @@ dependencies = [ [[package]] name = "solana-banks-server" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f72a966c0ebb198a16db924b4377f1b04dc8040afe0815ccee29cf852b4a0cc" +checksum = "8ea32797f631ff60b3eb3c793b0fddd104f5ffdf534bf6efcc59fbe30cd23b15" dependencies = [ "bincode", "crossbeam-channel", @@ -6532,9 +6532,9 @@ dependencies = [ [[package]] name = "solana-bloom" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7031d57828d75e507a574ea90605e1d57a110d4f8897332d65cb4279a3662961" +checksum = "eaf4babf9225c318efa34d7017eb3b881ed530732ad4dc59dfbde07f6144f27a" dependencies = [ "bv", "fnv", @@ -6573,9 +6573,9 @@ dependencies = [ [[package]] name = "solana-bpf-loader-program" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "840cc68b1d7de5457e644b8e94bfa1db2c42031da0f711c27d8a35d730522ff3" +checksum = "0cbc2581d0f39cd7698e46baa06fc5e8928b323a85ed3a4fdbdfe0d7ea9fc152" dependencies = [ "bincode", "libsecp256k1", @@ -6622,9 +6622,9 @@ dependencies = [ [[package]] name = "solana-bucket-map" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6880da18ce6345ea483a355e243c99a36adbf0fd30cf1c1add2fc3c7d4c980c0" +checksum = "12484b98db9e154d8189a7f632fe0766440abe4e58c5426f47157ece5b8730f3" dependencies = [ "bv", "bytemuck", @@ -6642,9 +6642,9 @@ dependencies = [ [[package]] name = "solana-builtins" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aee934db1ddbcd5cfd281c27d5016125fae9afc20b31e82b8bc89136d0287bb5" +checksum = "9ab1c09b653992c685c56c611004a1c96e80e76b31a2a2ecc06c47690646b98a" dependencies = [ "solana-address-lookup-table-program", "solana-bpf-loader-program", @@ -6664,11 +6664,11 @@ dependencies = [ [[package]] name = "solana-builtins-default-costs" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef0f2f438b282ebbbae55e87771df06db02cd226271835d42e04c83f6d2f1fb4" +checksum = "c4ee734c35b736e632aa3b1367f933d93ee7b4129dd1e20ca942205d4834054e" dependencies = [ - "ahash 0.8.11", + "ahash 0.8.12", "lazy_static", "log", "qualifier_attr", @@ -6687,9 +6687,9 @@ dependencies = [ [[package]] name = "solana-clap-utils" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffd0f771329b16b13af828bee4c1a86463af10fd8d14a35472e9a0dfea67415" +checksum = "0f9ef7be5c7a6fde4ae6864279a98d48a9454f70b0d3026bc37329e7f632fba6" dependencies = [ "chrono", "clap 2.34.0", @@ -6716,9 +6716,9 @@ dependencies = [ [[package]] name = "solana-cli-config" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a0d5c56076ed19ff17d904ed3a3d05c052dbb56cc27afb798eb0e99f6b117aa" +checksum = "8cdfa01757b1e6016028ad3bb35eb8efd022aadab0155621aedd71f0c566f03a" dependencies = [ "dirs-next", "lazy_static", @@ -6732,9 +6732,9 @@ dependencies = [ [[package]] name = "solana-client" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de78ee6ad972ace9fe203ad676dbc80be97c88037d90f9646456985ed8d65f33" +checksum = "1e25b7073890561a6b7875a921572fc4a9a2c78b3e60fb8e0a7ee4911961f8bd" dependencies = [ "async-trait", "bincode", @@ -6833,9 +6833,9 @@ dependencies = [ [[package]] name = "solana-compute-budget" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee76dd9a0487ead82839a42c68e1946c9eda4e922f86c02e651802bf2b713e7" +checksum = "eab40b24943ca51f1214fcf7979807640ea82a8387745f864cf3cd93d1337b01" dependencies = [ "solana-fee-structure", "solana-program-entrypoint", @@ -6843,9 +6843,9 @@ dependencies = [ [[package]] name = "solana-compute-budget-instruction" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "669312a7a34afdc4a7f138b0483318db47eeac9a18397fc62cd58f5feae897c7" +checksum = "0a6ef2a514cde8dce77495aefd23671dc46f638f504765910424436bc745dc04" dependencies = [ "log", "solana-borsh", @@ -6877,9 +6877,9 @@ dependencies = [ [[package]] name = "solana-compute-budget-program" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50e25aeefe198031238e16a7834b7526f346ebf4bac5f5f4b7c8eb4c5211d643" +checksum = "5ba922073c64647fe62f032787d34d50a8152533b5a5c85608ae1b2afb00ab63" dependencies = [ "qualifier_attr", "solana-program-runtime", @@ -6887,9 +6887,9 @@ dependencies = [ [[package]] name = "solana-config-program" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc58706f6c20146620328aea1c4e448532dc2fa58839b45983003d8ae81f04ed" +checksum = "0ab5647203179631940e0659a635e5d3f514ba60f6457251f8f8fbf3830e56b0" dependencies = [ "bincode", "chrono", @@ -6911,9 +6911,9 @@ dependencies = [ [[package]] name = "solana-connection-cache" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2f74fa34fb961983700c2cba2fe0fbfef7d449ed5a13f8e5909162708dcb4a6" +checksum = "0392439ea05772166cbce3bebf7816bdcc3088967039c7ce050cea66873b1c50" dependencies = [ "async-trait", "bincode", @@ -6935,11 +6935,11 @@ dependencies = [ [[package]] name = "solana-cost-model" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718b4d19a3ef1c25ca7a347dd98656960be3bb31f8c104b844a84dff059552ea" +checksum = "a675ead1473b32a7a5735801608b35cbd8d3f5057ca8dbafdd5976146bb7e9e4" dependencies = [ - "ahash 0.8.11", + "ahash 0.8.12", "lazy_static", "log", "solana-bincode", @@ -6978,9 +6978,9 @@ dependencies = [ [[package]] name = "solana-curve25519" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47aa7c95eb487628d2f3ca723c27923ba564844b04d3a7ad920000008ce250b0" +checksum = "f213e3a853a23814dee39d730cd3a5583b7b1e6b37b2cd4d940bbe62df7acc16" dependencies = [ "bytemuck", "bytemuck_derive", @@ -7033,9 +7033,9 @@ dependencies = [ [[package]] name = "solana-entry" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c36f8bed5963116d5c27fc5aa3b320b95119e1919fcf3ecf92965543731140d3" +checksum = "17eeec2852ad402887e80aa59506eee7d530d27b8c321f4824f8e2e7fe3e8cb2" dependencies = [ "bincode", "crossbeam-channel", @@ -7129,9 +7129,9 @@ dependencies = [ [[package]] name = "solana-faucet" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26e2dd04ef859ae2b35fbaab17cb028b8a70fb49edf28f8c2888706cb5438295" +checksum = "ca8bd25a809e1763794de4c28d699d859d77947fd7c6b11883c781d2cdfb3cf2" dependencies = [ "bincode", "clap 2.34.0", @@ -7185,7 +7185,7 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89e1d3b52b4a014efeaaab67f14e40af3972a4be61c523d612860db8e3145529" dependencies = [ - "ahash 0.8.11", + "ahash 0.8.12", "lazy_static", "solana-epoch-schedule", "solana-hash", @@ -7195,9 +7195,9 @@ dependencies = [ [[package]] name = "solana-fee" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "114ac80676fff79f90af16c6cc5f344363021d224d7b8046ed15b576b5bd8276" +checksum = "ee323b500b445d45624ad99a08b12b37c9964ac12debf2cde9ddfad9b06e0073" dependencies = [ "solana-feature-set", "solana-fee-structure", @@ -7271,9 +7271,9 @@ dependencies = [ [[package]] name = "solana-geyser-plugin-manager" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcfa51c97a24ac770821fcde2fc0da72d6849c0ea5be2348690417e2ebd9256" +checksum = "ce8287469a6f059411a3940bbc1b0a428b27104827ae1a80e465a1139f8b0773" dependencies = [ "agave-geyser-plugin-interface", "bs58 0.5.1", @@ -7302,9 +7302,9 @@ dependencies = [ [[package]] name = "solana-gossip" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08a8d5e714864cc14084a35ee6b01ca5a963c5d33ed2a415750c10eb41caf7e8" +checksum = "587f7e73d3ee7173f1f66392f1aeb4e582c055ad30f4e40f3a4b2cf9bce434fe" dependencies = [ "assert_matches", "bincode", @@ -7394,9 +7394,9 @@ dependencies = [ [[package]] name = "solana-inline-spl" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65da526a7865872c225d133c1a536649b81f2bfdd26ddf74b6cedc73b1687c3c" +checksum = "951545bd7d0ab4a878cfc7375ac9f1a475cb6936626677b2ba1d25e7b9f3910b" dependencies = [ "bytemuck", "solana-pubkey", @@ -7483,9 +7483,9 @@ dependencies = [ [[package]] name = "solana-lattice-hash" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b812714922fa24c87579c6678c5100089d9d624be4e9a035b9e0f635b21fe34" +checksum = "5fff3aab7ad7578d0bd2ac32d232015e535dfe268e35d45881ab22db0ba61c1e" dependencies = [ "base64 0.22.1", "blake3", @@ -7495,9 +7495,9 @@ dependencies = [ [[package]] name = "solana-ledger" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c48d1308e77cf63e90d7d335b74a4c9cbcfae629d3fe94f9c0be70b784f9c8f" +checksum = "25ef5ef594139afbf9db0dd0468a4d904d3275ce07f3afdb3a9b68d38676a75e" dependencies = [ "assert_matches", "bincode", @@ -7548,7 +7548,7 @@ dependencies = [ "solana-sdk", "solana-stake-program", "solana-storage-bigtable", - "solana-storage-proto 2.2.2", + "solana-storage-proto 2.2.1", "solana-svm", "solana-svm-transaction", "solana-timings", @@ -7614,9 +7614,9 @@ dependencies = [ [[package]] name = "solana-loader-v4-program" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177112e81d3599cfa29beb5f634abf26abb59d912d42759e9356f7daa9a98255" +checksum = "81b24999844b09096c79567c1298617efe084860149d875b702ef76e2faa2462" dependencies = [ "log", "qualifier_attr", @@ -7640,9 +7640,9 @@ dependencies = [ [[package]] name = "solana-log-collector" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39668a9a5069641e46342b0e73baa3a55f666ebdcd15e2b1142d388ce4618134" +checksum = "4aa28cd428e0af919d2fafd31c646835622abfd7ed4dba4df68e3c00f461bc66" dependencies = [ "log", ] @@ -7660,15 +7660,15 @@ dependencies = [ [[package]] name = "solana-measure" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbbaeb3fade08dfa27797d64dcff7e24b9e70ce92d61923ddfbe59495c38ae5e" +checksum = "8f1fced2cfeff80f0214af86bc27bc6e798465a45b70329c3b468bb75957c082" [[package]] name = "solana-merkle-tree" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c6750ae65ae848ace682aa144641cd32ce6ea13ba070d38e1eef9f2e8ad7570" +checksum = "fd38db9705b15ff57ddbd9d172c48202dcba078cfc867fe87f01c01d8633fd55" dependencies = [ "fast-math", "solana-hash", @@ -7700,9 +7700,9 @@ dependencies = [ [[package]] name = "solana-metrics" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ede5c7aefb1f8876f6b87af7755d52a75667e3cafeaad076759be705bd4c65e" +checksum = "89db46736ae1929db9629d779485052647117f3fcc190755519853b705f6dba5" dependencies = [ "crossbeam-channel", "gethostname", @@ -7733,9 +7733,9 @@ checksum = "33e9de00960197412e4be3902a6cd35e60817c511137aca6c34c66cd5d4017ec" [[package]] name = "solana-net-utils" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4721cc7485d9aa8f64ae900e5991f64b5986233139d7f6ac312d0396627cdb16" +checksum = "0752a7103c1a5bdbda04aa5abc78281232f2eda286be6edf8e44e27db0cca2a1" dependencies = [ "anyhow", "bincode", @@ -7817,11 +7817,11 @@ dependencies = [ [[package]] name = "solana-perf" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a6981ceefea5d81336839e7cebee9210049ace176a632dc35bb30f26b32de3d" +checksum = "3f0962d3818fc942a888f7c2d530896aeaf6f2da2187592a67bbdc8cf8a54192" dependencies = [ - "ahash 0.8.11", + "ahash 0.8.12", "bincode", "bv", "caps", @@ -7849,9 +7849,9 @@ dependencies = [ [[package]] name = "solana-poh" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9bf9b7c73d5ba7daf360e6760fced816b05a96685846d0e671b8952f6e1ee0" +checksum = "7e3abf53e6af2bc7f3ebd455112a0eb960378882d780e85b62ff3a70b69e02e6" dependencies = [ "core_affinity", "crossbeam-channel", @@ -7882,9 +7882,9 @@ dependencies = [ [[package]] name = "solana-poseidon" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "945b4c27ea947ec6a664e11ef82f70c0344c6941d6c9262485e8aa5bcf13d2c6" +checksum = "8ad1ea160d08dc423c35021fa3e437a5783eb256f5ab8bc3024e27db913acf42" dependencies = [ "ark-bn254", "light-poseidon", @@ -8065,9 +8065,9 @@ dependencies = [ [[package]] name = "solana-program-runtime" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36cbc1d18139003f1fbbc42fb3efb1332f6dcc034d7e95d36727c9ec4b2f1010" +checksum = "6c3d36fed5548b1a8625eb071df6031a95aa69f884e29bf244821e53c49372bc" dependencies = [ "base64 0.22.1", "bincode", @@ -8106,9 +8106,9 @@ dependencies = [ [[package]] name = "solana-program-test" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02f25b19e0f8ef1f4e30f9aa5d986238edfd68bb35ef66131d8992cb941286f0" +checksum = "ef6caec3df83d39b8da9fd6e80a7847d788b3b869c646fbb8776c3e989e98c0c" dependencies = [ "assert_matches", "async-trait", @@ -8170,9 +8170,9 @@ dependencies = [ [[package]] name = "solana-pubsub-client" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83eebfd6d9edebba132fb67503079815f407da3c7918e894dade5ddef1c652ce" +checksum = "0bd251d37c932105a684415db44bee52e75ad818dfecbf963a605289b5aaecc5" dependencies = [ "crossbeam-channel", "futures-util", @@ -8197,9 +8197,9 @@ dependencies = [ [[package]] name = "solana-quic-client" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82a1a746e301f26c4d18c148770288413b94ba26e732a54dea8a0408f99c7d7" +checksum = "0d072e6787b6fa9da86591bcf870823b0d6f87670df3c92628505db7a9131e44" dependencies = [ "async-lock", "async-trait", @@ -8237,9 +8237,9 @@ dependencies = [ [[package]] name = "solana-rayon-threadlimit" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d65d09a08feb7dace6e3a946f03be315ebca08d4164228fcf3f5ff35075dac" +checksum = "17f7b65ddd8ac75efcc31b627d4f161046312994313a4520b65a8b14202ab5d6" dependencies = [ "lazy_static", "num_cpus", @@ -8247,9 +8247,9 @@ dependencies = [ [[package]] name = "solana-remote-wallet" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c792c3170081252849d79db224a83159e895f536b1026b722388f46bb47437ce" +checksum = "fa3c1e6ec719021564b034c550f808778507db54b6a5de99f00799d9ec86168d" dependencies = [ "console", "dialoguer", @@ -8333,9 +8333,9 @@ dependencies = [ [[package]] name = "solana-rpc" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f44888cf457396e5ca3fc97f4a13fbf5c26b3fc04cd31c1f671d66172641dca9" +checksum = "b978303a9d6f3270ab83fa28ad07a2f4f3181a65ce332b4b5f5d06de5f2a46c5" dependencies = [ "base64 0.22.1", "bincode", @@ -8395,9 +8395,9 @@ dependencies = [ [[package]] name = "solana-rpc-client" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d66169715bc2ee029ef7418304de952ab5c840667d4b740fea34b8dd1591327" +checksum = "7cb874b757d9d3c646f031132b20d43538309060a32d02b4aebb0f8fc2cd159a" dependencies = [ "async-trait", "base64 0.22.1", @@ -8433,9 +8433,9 @@ dependencies = [ [[package]] name = "solana-rpc-client-api" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5e3f23480685f26102c23d414ed1f39bd94bbf79dd3e04fc307022e67ffe7c" +checksum = "f7105452c4f039fd2c07e6fda811ff23bd270c99f91ac160308f02701eb19043" dependencies = [ "anyhow", "base64 0.22.1", @@ -8464,9 +8464,9 @@ dependencies = [ [[package]] name = "solana-rpc-client-nonce-utils" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b04770650f1d56a9df2d95215a2e51abdf065b15feb44c66989afeaede9c12ae" +checksum = "0244e2bf439ec424179414173cdc8b43e34371608752799c5610bf17430eee18" dependencies = [ "solana-account", "solana-commitment-config", @@ -8481,11 +8481,11 @@ dependencies = [ [[package]] name = "solana-runtime" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21ab71cd56643279fc6b5e8868fb42b5dc3c5381df7568aee797981b7e1815ab" +checksum = "5335e7925f6dc8d2fdcdc6ead3b190aca65f191a11cef74709a7a6ab5d0d5877" dependencies = [ - "ahash 0.8.11", + "ahash 0.8.12", "aquamarine", "arrayref", "base64 0.22.1", @@ -8567,9 +8567,9 @@ dependencies = [ [[package]] name = "solana-runtime-transaction" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f81f6ab570d50ae2c81c72e83ffa9a6bba97e2a079a32489035b656ff1ad3ec" +checksum = "92ffec9b80cf744d36696b28ca089bef8058475a79a11b1cee9322a5aab1fa00" dependencies = [ "agave-transaction-view", "log", @@ -8773,9 +8773,9 @@ dependencies = [ [[package]] name = "solana-send-transaction-service" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5df52444e25b638f163e43a3d63006468f17f98af3709d0d4cf9a82961ad9631" +checksum = "e51fb0567093cc4edbd701b995870fc41592fd90e8bc2965ef9f5ce214af22e7" dependencies = [ "crossbeam-channel", "itertools 0.12.1", @@ -8935,9 +8935,9 @@ dependencies = [ [[package]] name = "solana-stake-program" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "015af0e4f42876829bab42ea332c724687b644d0144fad4cc1f6fa51ad1b102f" +checksum = "dabc713c25ff999424ec68ac4572f2ff6bfd6317922c7864435ccaf9c76504a8" dependencies = [ "bincode", "log", @@ -8964,9 +8964,9 @@ dependencies = [ [[package]] name = "solana-storage-bigtable" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6df82e017944ba888dc807e31fd51cea3de056051c5b6a525d69bf6c0605cbd9" +checksum = "11114c617be52001af7413ee9715b4942d80a0c3de6296061df10da532f6b192" dependencies = [ "backoff", "bincode", @@ -8993,7 +8993,7 @@ dependencies = [ "solana-reserved-account-keys", "solana-serde", "solana-signature", - "solana-storage-proto 2.2.2", + "solana-storage-proto 2.2.1", "solana-time-utils", "solana-transaction", "solana-transaction-error", @@ -9022,9 +9022,9 @@ dependencies = [ [[package]] name = "solana-storage-proto" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3abff22a9edde3d4f79c64133db172f6ecb7bc8bcebc2d303eba0008a221098" +checksum = "45ed614e38d7327a6a399a17afb3b56c9b7b53fb7222eecdacd9bb73bf8a94d9" dependencies = [ "bincode", "bs58 0.5.1", @@ -9047,9 +9047,9 @@ dependencies = [ [[package]] name = "solana-streamer" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edcda7696d32a4a3b49aef007cf2cfc988662b23aaaa0210a608a5fc2b7b6e9a" +checksum = "68441234b1235afb242e7482cabf3e32eb29554e4c4159d5d58e19e54ccfd424" dependencies = [ "async-channel", "bytes 1.10.1", @@ -9094,11 +9094,11 @@ dependencies = [ [[package]] name = "solana-svm" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad0d99cd5d880aa58861c5bebe77ff5f2a335163060b09c1e59504fa2c3b039" +checksum = "0850baf834aba4a94a7558fa6cf6ca93fad284abf0363dec5fb9cab173a11fc4" dependencies = [ - "ahash 0.8.11", + "ahash 0.8.12", "itertools 0.12.1", "log", "percentage", @@ -9140,18 +9140,18 @@ dependencies = [ [[package]] name = "solana-svm-rent-collector" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d49828f4092bea62aae785ff0c62786d8e12d0cf2b0d21383960551bd759310" +checksum = "aa59aea7bfbadb4be9704a6f99c86dbdf48d6204c9291df79ecd6a4f1cc90b59" dependencies = [ "solana-sdk", ] [[package]] name = "solana-svm-transaction" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03ce09eb3c2c0f62720f57bea50f0a49094d279e361ae76d8b05dfda0a3489c9" +checksum = "4fc4392f0eed412141a376e99dfb052069b96f13697a9abb335504babe29387a" dependencies = [ "solana-hash", "solana-message", @@ -9179,9 +9179,9 @@ dependencies = [ [[package]] name = "solana-system-program" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36f1bfbb8ed48b165a5ad69f76869199a0ab6428e730b801cca83493e11f4e9e" +checksum = "43c8f684977e4439031b3a27b954ab05a6bdf697d581692aaf8888cf92b73b9e" dependencies = [ "bincode", "log", @@ -9267,9 +9267,9 @@ dependencies = [ [[package]] name = "solana-thin-client" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7a3ef7ddcb5326b882f642b20eb3a2b868ac45422ddc96a4384d9b0d9b1afb1" +checksum = "721a034e94fcfaf8bde1ae4980e7eb58bfeb0c9a243b032b0761fdd19018afbf" dependencies = [ "bincode", "log", @@ -9302,9 +9302,9 @@ checksum = "6af261afb0e8c39252a04d026e3ea9c405342b08c871a2ad8aa5448e068c784c" [[package]] name = "solana-timings" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7044c3bac381f1a1b27fbc126d29e7d128c96c69a087d4c3cd136afd4253453" +checksum = "49d9eabdce318cb07c60a23f1cc367b43e177c79225b5c2a081869ad182172ad" dependencies = [ "eager", "enum-iterator", @@ -9313,9 +9313,9 @@ dependencies = [ [[package]] name = "solana-tls-utils" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea91251b2f22b0e1a98090e3d6a79f19c2e6f1c66492a74b0e67974bcbec77d" +checksum = "a228df037e560a02aac132193f492bdd761e2f90188cd16a440f149882f589b1" dependencies = [ "rustls 0.23.23", "solana-keypair", @@ -9326,9 +9326,9 @@ dependencies = [ [[package]] name = "solana-tpu-client" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eb41b71dc6d332104fdca2219d1db1535a9fcd1cfa98978d7921bdc8a9a90eb" +checksum = "aaceb9e9349de58740021f826ae72319513eca84ebb6d30326e2604fdad4cefb" dependencies = [ "async-trait", "bincode", @@ -9416,9 +9416,9 @@ dependencies = [ [[package]] name = "solana-transaction-metrics-tracker" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a651cf35caa262fa182a9241d9b00199d4bbd3908f7cd570e9eda77ebe2bee" +checksum = "e9256ea8a6cead9e03060fd8fdc24d400a57a719364db48a3e4d1776b09c2365" dependencies = [ "base64 0.22.1", "bincode", @@ -9433,9 +9433,9 @@ dependencies = [ [[package]] name = "solana-transaction-status" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20360d75040a77635ea77a000a3bb58837c9123c43e22dc34fe852b19efc0dda" +checksum = "64f739fb4230787b010aa4a49d3feda8b53aac145a9bc3ac2dd44337c6ecb544" dependencies = [ "Inflector", "base64 0.22.1", @@ -9474,9 +9474,9 @@ dependencies = [ [[package]] name = "solana-transaction-status-client-types" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c42014a3b7d718bbac962a2c327d8d869254fd3a7da6da563fa89da44f7fe4" +checksum = "d5ac91c8f0465c566164044ad7b3d18d15dfabab1b8b4a4a01cb83c047efdaae" dependencies = [ "base64 0.22.1", "bincode", @@ -9497,9 +9497,9 @@ dependencies = [ [[package]] name = "solana-type-overrides" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86260c63187d21a631e0f1bfb79b126faee1812adb204595b8e266c8b6a82b9" +checksum = "d39dc2e501edfea7ce1cec2fe2a2428aedfea1cc9c31747931e0d90d5c57b020" dependencies = [ "lazy_static", "rand 0.8.5", @@ -9507,9 +9507,9 @@ dependencies = [ [[package]] name = "solana-udp-client" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10083b8daef46ecf33a130c32078d5245870651ac32472ec369581766a1a8f84" +checksum = "85085c0aa14ebb8e26219386fb7f4348d159f5a67858c2fdefef3cc5f4ce090c" dependencies = [ "async-trait", "solana-connection-cache", @@ -9523,9 +9523,9 @@ dependencies = [ [[package]] name = "solana-unified-scheduler-logic" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b190bb6cedc57173818c5d3e1732cac22f58166182fa5ef53a3b476acbb89197" +checksum = "fe7e48cbf4e70c05199f50d5f14aafc58331ad39229747c795320bcb362ed063" dependencies = [ "assert_matches", "solana-pubkey", @@ -9542,9 +9542,9 @@ checksum = "7bbf6d7a3c0b28dd5335c52c0e9eae49d0ae489a8f324917faf0ded65a812c1d" [[package]] name = "solana-version" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "564df3091572519f4b595e705101ed221c8bab33a1b21fc2a6a97cf50174410b" +checksum = "4f60a01e2721bfd2e094b465440ae461d75acd363e9653565a73d2c586becb3b" dependencies = [ "semver", "serde", @@ -9556,9 +9556,9 @@ dependencies = [ [[package]] name = "solana-vote" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9b8a8954997c987f82752231b27e0239f73e67a019a9aedde44f1d71c3e5e23" +checksum = "b6cfd22290c8e63582acd8d8d10670f4de2f81a967b5e9821e2988b4a4d58c54" dependencies = [ "itertools 0.12.1", "log", @@ -9605,9 +9605,9 @@ dependencies = [ [[package]] name = "solana-vote-program" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb50bf827b2fa2ce25d29120dc70fc4d58ed00b8c29fe7245518a7f30fd185c" +checksum = "ab654bb2622d85b2ca0c36cb89c99fa1286268e0d784efec03a3d42e9c6a55f4" dependencies = [ "bincode", "log", @@ -9638,9 +9638,9 @@ dependencies = [ [[package]] name = "solana-zk-elgamal-proof-program" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1521a89536c68bc82a9ee8ce93931f90371c11a4237ff15a706ca104443f7f0a" +checksum = "4d241af6328b3e0e20695bb705c850119ec5881b386c338783b8c8bc79e76c65" dependencies = [ "bytemuck", "num-derive", @@ -9654,9 +9654,9 @@ dependencies = [ [[package]] name = "solana-zk-sdk" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1df0ded0d71d09a79f6fcc9d6c0bd5aee7a14fc343f027d36d09c0eebdd09d7" +checksum = "d8318220b73552a2765c6545a4be04fc87fe21b6dd0cb8c2b545a66121bf5b8a" dependencies = [ "aes-gcm-siv", "base64 0.22.1", @@ -9691,9 +9691,9 @@ dependencies = [ [[package]] name = "solana-zk-token-proof-program" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e056f5cb4ddd28f1fcb6627e75685c678a9ad06ef0b65681a1bed461689a1688" +checksum = "123b7c7d2f9e68190630b216781ca832af0ed78b69acd89a2ad2766cc460c312" dependencies = [ "bytemuck", "num-derive", @@ -9708,9 +9708,9 @@ dependencies = [ [[package]] name = "solana-zk-token-sdk" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8fe694ac9c88fdb7d4dc3e32d63d7b5ad0d521155a8e15f017aa022df86c74e" +checksum = "b3cf301f8d8e02ef58fc2ce85868f5c760720e1ce74ee4b3c3dcb64c8da7bcff" dependencies = [ "aes-gcm-siv", "base64 0.22.1", @@ -11736,7 +11736,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "byteorder", - "zerocopy-derive", + "zerocopy-derive 0.7.35", +] + +[[package]] +name = "zerocopy" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +dependencies = [ + "zerocopy-derive 0.8.26", ] [[package]] @@ -11750,6 +11759,17 @@ dependencies = [ "syn 2.0.95", ] +[[package]] +name = "zerocopy-derive" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.95", +] + [[package]] name = "zerofrom" version = "0.1.5" From 1e5d6a480f9400e710fe46cfec6c785d6a543fe7 Mon Sep 17 00:00:00 2001 From: Dodecahedr0x <90185028+Dodecahedr0x@users.noreply.github.com> Date: Fri, 1 Aug 2025 18:05:53 +0200 Subject: [PATCH 154/199] feat: option to skip ledger replay (#460) Solves #418 This PR: - Adds a config parameter to skip ledger replay when starting a validator, discarding the old ledger but preserving accountsDB and the validator keypair. - Adds a test that checks that the state is still there but not the ledger ## Snippets TOML: ```toml [ledger] resume-strategy = "replay-and-resume" path = "ledger.example.com" size = 1000000000 ``` CLI: ```bash cargo run -- --ledger-resume-strategy replay-and-resume LEDGER_RESUME_STRATEGY=replay-and-resume cargo run ``` ## Migration Old config: ```toml [ledger] reset = true ``` Becomes: ```toml [ledger] resume-strategy = "reset" ``` --- Old config: ```toml [ledger] reset = false ``` Becomes: ```toml [ledger] resume-strategy = "replay" ``` --- Cargo.lock | 21 ++++ Cargo.toml | 1 + magicblock-accounts-db/Cargo.toml | 1 + magicblock-accounts-db/src/lib.rs | 4 +- magicblock-api/src/fund_account.rs | 5 +- magicblock-api/src/ledger.rs | 89 +++++++++++--- magicblock-api/src/lib.rs | 1 - magicblock-api/src/magic_validator.rs | 36 +++--- magicblock-api/src/utils/fs.rs | 18 --- magicblock-api/src/utils/mod.rs | 1 - magicblock-config/src/accounts.rs | 18 +-- magicblock-config/src/geyser_grpc.rs | 2 + magicblock-config/src/helpers/socket_addr.rs | 10 +- magicblock-config/src/ledger.rs | 114 ++++++++++++++++-- magicblock-config/src/lib.rs | 18 +-- .../tests/fixtures/02_defaults.toml | 2 +- .../tests/fixtures/05_all-goes.toml | 2 +- magicblock-config/tests/parse_config.rs | 12 +- magicblock-config/tests/read_config.rs | 16 +-- test-integration/Cargo.lock | 21 ++++ .../test-ledger-restore/src/lib.rs | 16 ++- .../tests/01_single_airdrop.rs | 17 ++- .../tests/02_two_airdrops.rs | 25 +++- .../tests/03_single_block_tx_order.rs | 17 ++- .../tests/04_flexi-counter.rs | 6 +- .../tests/05_program_deploy.rs | 17 ++- ...12_two_airdrops_one_after_account_flush.rs | 18 ++- .../tests/15_skip_replay.rs | 100 +++++++++++++++ .../src/integration_test_context.rs | 15 +++ 29 files changed, 476 insertions(+), 147 deletions(-) delete mode 100644 magicblock-api/src/utils/fs.rs delete mode 100644 magicblock-api/src/utils/mod.rs create mode 100644 test-integration/test-ledger-restore/tests/15_skip_replay.rs diff --git a/Cargo.lock b/Cargo.lock index cd5ad49db..fda98f74c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1430,6 +1430,26 @@ dependencies = [ "web-sys", ] +[[package]] +name = "const_format" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126f97965c8ad46d6d9163268ff28432e8f6a1196a55578867832e3049df63dd" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "constant_time_eq" version = "0.3.1" @@ -3928,6 +3948,7 @@ dependencies = [ name = "magicblock-accounts-db" version = "0.1.7" dependencies = [ + "const_format", "env_logger 0.11.8", "lmdb-rkv", "log", diff --git a/Cargo.toml b/Cargo.toml index a4200ef61..2c3a104dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,6 +72,7 @@ convert_case = "0.8.0" conjunto-transwise = { git = "https://github.com/magicblock-labs/conjunto.git", rev = "bf82b45" } console-subscriber = "0.2.0" crossbeam-channel = "0.5.11" +const_format = "0.2.34" ed25519-dalek = "1.0.1" enum-iterator = "1.5.0" env_logger = "0.11.2" diff --git a/magicblock-accounts-db/Cargo.toml b/magicblock-accounts-db/Cargo.toml index a2bd0907e..34a25d666 100644 --- a/magicblock-accounts-db/Cargo.toml +++ b/magicblock-accounts-db/Cargo.toml @@ -21,6 +21,7 @@ solana-account = { workspace = true } parking_lot = "0.12" # misc +const_format = { workspace = true } serde = { workspace = true, features = ["derive"] } thiserror = { workspace = true } log = { workspace = true } diff --git a/magicblock-accounts-db/src/lib.rs b/magicblock-accounts-db/src/lib.rs index 638b048e4..c22c1e774 100644 --- a/magicblock-accounts-db/src/lib.rs +++ b/magicblock-accounts-db/src/lib.rs @@ -1,5 +1,6 @@ use std::{path::Path, sync::Arc}; +use const_format::concatcp; use error::AccountsDbError; use index::AccountsDbIndex; use log::{error, warn}; @@ -19,7 +20,8 @@ pub type AdbResult = Result; /// some critical operation is in action, e.g. snapshotting pub type StWLock = Arc>; -const ACCOUNTSDB_SUB_DIR: &str = "accountsdb/main"; +pub const ACCOUNTSDB_DIR: &str = "accountsdb"; +const ACCOUNTSDB_SUB_DIR: &str = concatcp!(ACCOUNTSDB_DIR, "/main"); pub struct AccountsDb { /// Main accounts storage, where actual account records are kept diff --git a/magicblock-api/src/fund_account.rs b/magicblock-api/src/fund_account.rs index 4926ea762..f30a27e3a 100644 --- a/magicblock-api/src/fund_account.rs +++ b/magicblock-api/src/fund_account.rs @@ -1,6 +1,7 @@ use std::path::Path; use magicblock_bank::bank::Bank; +use magicblock_config::LedgerResumeStrategy; use magicblock_core::magic_program; use solana_sdk::{ account::Account, clock::Epoch, pubkey::Pubkey, signature::Keypair, @@ -56,9 +57,9 @@ pub(crate) fn fund_validator_identity(bank: &Bank, validator_id: &Pubkey) { pub(crate) fn funded_faucet( bank: &Bank, ledger_path: &Path, - create_new: bool, + resume_strategy: &LedgerResumeStrategy, ) -> ApiResult { - let faucet_keypair = if create_new { + let faucet_keypair = if resume_strategy.is_removing_ledger() { let faucet_keypair = Keypair::new(); write_faucet_keypair_to_ledger(ledger_path, &faucet_keypair)?; faucet_keypair diff --git a/magicblock-api/src/ledger.rs b/magicblock-api/src/ledger.rs index b88d00204..ed6aba446 100644 --- a/magicblock-api/src/ledger.rs +++ b/magicblock-api/src/ledger.rs @@ -6,36 +6,48 @@ use std::{ use fd_lock::{RwLock, RwLockWriteGuard}; use log::*; +use magicblock_accounts_db::ACCOUNTSDB_DIR; +use magicblock_config::LedgerResumeStrategy; use magicblock_ledger::Ledger; -use solana_sdk::{signature::Keypair, signer::EncodableKey}; +use solana_sdk::{clock::Slot, signature::Keypair, signer::EncodableKey}; -use crate::{ - errors::{ApiError, ApiResult}, - utils::fs::remove_directory_contents_if_exists, -}; +use crate::errors::{ApiError, ApiResult}; // ----------------- // Init // ----------------- -pub(crate) fn init(ledger_path: PathBuf, reset: bool) -> ApiResult { - if reset { - remove_directory_contents_if_exists(ledger_path.as_path()).map_err( - |err| { - error!( - "Error: Unable to remove {}: {}", - ledger_path.display(), - err - ); - ApiError::UnableToCleanLedgerDirectory( - ledger_path.display().to_string(), - ) - }, - )?; +pub(crate) fn init( + ledger_path: PathBuf, + resume_strategy: &LedgerResumeStrategy, +) -> ApiResult<(Ledger, Slot)> { + // Save the last slot from the previous ledger to restart from it + let last_slot = if resume_strategy.is_resuming() { + let previous_ledger = Ledger::open(ledger_path.as_path())?; + previous_ledger.get_max_blockhash().map(|(slot, _)| slot)? + } else { + Slot::default() + }; + + if resume_strategy.is_removing_ledger() { + remove_ledger_directory_if_exists( + ledger_path.as_path(), + resume_strategy, + ) + .map_err(|err| { + error!( + "Error: Unable to remove {}: {}", + ledger_path.display(), + err + ); + ApiError::UnableToCleanLedgerDirectory( + ledger_path.display().to_string(), + ) + })?; } fs::create_dir_all(&ledger_path)?; - Ok(Ledger::open(ledger_path.as_path())?) + Ok((Ledger::open(ledger_path.as_path())?, last_slot)) } // ----------------- @@ -165,3 +177,40 @@ pub(crate) fn ledger_parent_dir(ledger_path: &Path) -> ApiResult { })?; Ok(parent.to_path_buf()) } + +fn remove_ledger_directory_if_exists( + dir: &Path, + resume_strategy: &LedgerResumeStrategy, +) -> Result<(), std::io::Error> { + if !dir.exists() { + return Ok(()); + } + for entry in fs::read_dir(dir)? { + let entry = entry?; + + // When resuming, keep the accounts db + if entry.file_name() == ACCOUNTSDB_DIR && resume_strategy.is_resuming() + { + continue; + } + + // When resuming, keep the validator keypair + if let Ok(validator_keypair_path) = validator_keypair_path(dir) { + if resume_strategy.is_resuming() + && validator_keypair_path + .file_name() + .map(|key_path| key_path == entry.file_name()) + .unwrap_or(false) + { + continue; + } + } + + if entry.metadata()?.is_dir() { + fs::remove_dir_all(entry.path())? + } else { + fs::remove_file(entry.path())? + } + } + Ok(()) +} diff --git a/magicblock-api/src/lib.rs b/magicblock-api/src/lib.rs index 2826cf03e..a79c7f50d 100644 --- a/magicblock-api/src/lib.rs +++ b/magicblock-api/src/lib.rs @@ -8,7 +8,6 @@ pub mod ledger; pub mod magic_validator; mod slot; mod tickers; -mod utils; pub use init_geyser_service::InitGeyserServiceConfig; pub use magicblock_config::EphemeralConfig; diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 079b32e12..e658d90f7 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -40,8 +40,8 @@ use magicblock_committor_service::{ config::ChainConfig, CommittorService, ComputeBudgetConfig, }; use magicblock_config::{ - AccountsDbConfig, EphemeralConfig, LifecycleMode, PrepareLookupTables, - ProgramConfig, + AccountsDbConfig, EphemeralConfig, LedgerConfig, LedgerResumeStrategy, + LifecycleMode, PrepareLookupTables, ProgramConfig, }; use magicblock_geyser_plugin::rpc::GeyserRpcService; use magicblock_ledger::{ @@ -196,14 +196,12 @@ impl MagicValidator { config.validator_config.validator.base_fees, ); - let ledger = Self::init_ledger( - config.validator_config.ledger.path.as_ref(), - config.validator_config.ledger.reset, - )?; + let (ledger, last_slot) = + Self::init_ledger(&config.validator_config.ledger)?; Self::sync_validator_keypair_with_ledger( ledger.ledger_path(), &identity_keypair, - config.validator_config.ledger.reset, + &config.validator_config.ledger.resume_strategy, )?; // SAFETY: @@ -223,7 +221,7 @@ impl MagicValidator { config.validator_config.validator.millis_per_slot, validator_pubkey, ledger_parent_path, - ledger.get_max_blockhash().map(|(slot, _)| slot)?, + last_slot, )?; let ledger_truncator = LedgerTruncator::new( @@ -238,7 +236,7 @@ impl MagicValidator { let faucet_keypair = funded_faucet( &bank, ledger.ledger_path().as_path(), - config.validator_config.ledger.reset, + &config.validator_config.ledger.resume_strategy, )?; load_programs_into_bank( @@ -520,28 +518,28 @@ impl MagicValidator { } fn init_ledger( - ledger_path: Option<&String>, - reset: bool, - ) -> ApiResult> { - let ledger_path = match ledger_path { + ledger_config: &LedgerConfig, + ) -> ApiResult<(Arc, Slot)> { + let ledger_path = match &ledger_config.path { Some(ledger_path) => PathBuf::from(ledger_path), None => { let ledger_path = TempDir::new()?; ledger_path.path().to_path_buf() } }; - let ledger = ledger::init(ledger_path, reset)?; + let (ledger, last_slot) = + ledger::init(ledger_path, &ledger_config.resume_strategy)?; let ledger_shared = Arc::new(ledger); init_persister(ledger_shared.clone()); - Ok(ledger_shared) + Ok((ledger_shared, last_slot)) } fn sync_validator_keypair_with_ledger( ledger_path: &Path, validator_keypair: &Keypair, - reset_ledger: bool, + resume_strategy: &LedgerResumeStrategy, ) -> ApiResult<()> { - if reset_ledger { + if !resume_strategy.is_resuming() { write_validator_keypair_to_ledger(ledger_path, validator_keypair)?; } else { let ledger_validator_keypair = @@ -581,7 +579,7 @@ impl MagicValidator { // Start/Stop // ----------------- fn maybe_process_ledger(&self) -> ApiResult<()> { - if self.config.ledger.reset { + if !self.config.ledger.resume_strategy.is_replaying() { return Ok(()); } let slot_to_continue_at = process_ledger(&self.ledger, &self.bank)?; @@ -814,7 +812,7 @@ impl MagicValidator { } } - if !self.config.ledger.reset { + if self.config.ledger.resume_strategy.is_replaying() { let remote_account_cloner_worker = remote_account_cloner_worker.clone(); tokio::spawn(async move { diff --git a/magicblock-api/src/utils/fs.rs b/magicblock-api/src/utils/fs.rs deleted file mode 100644 index 09f7c4785..000000000 --- a/magicblock-api/src/utils/fs.rs +++ /dev/null @@ -1,18 +0,0 @@ -use std::{fs, path::Path}; - -pub fn remove_directory_contents_if_exists( - dir: &Path, -) -> Result<(), std::io::Error> { - if !dir.exists() { - return Ok(()); - } - for entry in fs::read_dir(dir)? { - let entry = entry?; - if entry.metadata()?.is_dir() { - fs::remove_dir_all(entry.path())? - } else { - fs::remove_file(entry.path())? - } - } - Ok(()) -} diff --git a/magicblock-api/src/utils/mod.rs b/magicblock-api/src/utils/mod.rs deleted file mode 100644 index aabc2afc5..000000000 --- a/magicblock-api/src/utils/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub(crate) mod fs; diff --git a/magicblock-config/src/accounts.rs b/magicblock-config/src/accounts.rs index 980b6b4a3..c74736d75 100644 --- a/magicblock-config/src/accounts.rs +++ b/magicblock-config/src/accounts.rs @@ -28,7 +28,7 @@ pub struct AccountsConfig { pub lifecycle: LifecycleMode, #[serde(default)] #[command(flatten)] - pub commit: CommitStrategy, + pub commit: CommitStrategyConfig, #[clap_from_serde_skip] #[arg(help = "The list of allowed programs to load.")] #[serde(default)] @@ -152,9 +152,11 @@ pub enum LifecycleMode { // ----------------- #[clap_prefix("commit")] #[clap_from_serde] -#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args)] +#[derive( + Debug, Clone, PartialEq, Eq, Deserialize, Serialize, Args, Mergeable, +)] #[serde(deny_unknown_fields)] -pub struct CommitStrategy { +pub struct CommitStrategyConfig { #[derive_env_var] #[serde(default = "default_frequency_millis")] pub frequency_millis: u64, @@ -179,7 +181,7 @@ fn default_compute_unit_price() -> u64 { 1_000_000 // 1_000_000 micro-lamports == 1 Lamport } -impl Default for CommitStrategy { +impl Default for CommitStrategyConfig { fn default() -> Self { Self { frequency_millis: default_frequency_millis(), @@ -283,7 +285,7 @@ mod tests { ws_url: None, }, lifecycle: LifecycleMode::Ephemeral, - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 123, compute_unit_price: 123, }, @@ -315,7 +317,7 @@ mod tests { ws_url: None, }, lifecycle: LifecycleMode::Ephemeral, - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 123, compute_unit_price: 123, }, @@ -344,7 +346,7 @@ mod tests { ws_url: Some(vec![Url::parse("wss://0.0.0.0:7999").unwrap()]), }, lifecycle: LifecycleMode::Offline, - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 1234, compute_unit_price: 1234, }, @@ -372,7 +374,7 @@ mod tests { ws_url: None, }, lifecycle: LifecycleMode::Ephemeral, - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 123, compute_unit_price: 123, }, diff --git a/magicblock-config/src/geyser_grpc.rs b/magicblock-config/src/geyser_grpc.rs index 3398f20ea..cd39d6277 100644 --- a/magicblock-config/src/geyser_grpc.rs +++ b/magicblock-config/src/geyser_grpc.rs @@ -11,6 +11,8 @@ helpers::socket_addr_config! { mod tests { use std::net::{IpAddr, Ipv4Addr}; + use magicblock_config_helpers::Merge; + use super::*; #[test] diff --git a/magicblock-config/src/helpers/socket_addr.rs b/magicblock-config/src/helpers/socket_addr.rs index bee70e3cb..20c5d858f 100644 --- a/magicblock-config/src/helpers/socket_addr.rs +++ b/magicblock-config/src/helpers/socket_addr.rs @@ -10,6 +10,7 @@ macro_rules! socket_addr_config { ::serde::Deserialize, ::serde::Serialize, ::clap::Args, + ::magicblock_config_macro::Mergeable, )] #[serde(deny_unknown_fields)] pub struct $struct_name { @@ -40,15 +41,6 @@ macro_rules! socket_addr_config { pub fn socket_addr(&self) -> ::std::net::SocketAddr { ::std::net::SocketAddr::new(self.addr, self.port) } - - pub fn merge(&mut self, other: $struct_name) { - if self.addr == default_addr() && other.addr != default_addr() { - self.addr = other.addr; - } - if self.port == default_port() && other.port != default_port() { - self.port = other.port; - } - } } fn default_port() -> u16 { diff --git a/magicblock-config/src/ledger.rs b/magicblock-config/src/ledger.rs index a5c098f60..bd9cf9405 100644 --- a/magicblock-config/src/ledger.rs +++ b/magicblock-config/src/ledger.rs @@ -1,8 +1,7 @@ -use clap::Args; +use clap::{Args, ValueEnum}; use magicblock_config_macro::{clap_from_serde, clap_prefix, Mergeable}; use serde::{Deserialize, Serialize}; - -use crate::helpers::serde_defaults::bool_true; +use strum::Display; // Default desired ledger size 100 GiB pub const DEFAULT_LEDGER_SIZE_BYTES: u64 = 100 * 1024 * 1024 * 1024; @@ -14,12 +13,13 @@ pub const DEFAULT_LEDGER_SIZE_BYTES: u64 = 100 * 1024 * 1024 * 1024; )] #[serde(deny_unknown_fields, rename_all = "kebab-case")] pub struct LedgerConfig { - /// If a previous ledger is found it is removed before starting the validator - /// This can be disabled by setting [Self::reset] to `false`. + /// The strategy to use for resuming the ledger. + /// Reset will remove the existing ledger. + /// Resume only will remove the ledger and resume from the last slot. + /// Replay and resume will preserve the existing ledger and replay it and then resume. #[derive_env_var] - #[arg(help = "Whether to reset the ledger before starting the validator.")] - #[serde(default = "bool_true")] - pub reset: bool, + #[serde(default)] + pub resume_strategy: LedgerResumeStrategy, /// The file system path onto which the ledger should be written at /// If left empty it will be auto-generated to a temporary folder #[derive_env_var] @@ -39,13 +39,48 @@ pub struct LedgerConfig { impl Default for LedgerConfig { fn default() -> Self { Self { - reset: bool_true(), + resume_strategy: LedgerResumeStrategy::default(), path: Default::default(), size: DEFAULT_LEDGER_SIZE_BYTES, } } } +#[derive( + Debug, + Display, + Clone, + Default, + PartialEq, + Eq, + Deserialize, + Serialize, + ValueEnum, +)] +#[serde(rename_all = "kebab-case")] +#[strum(serialize_all = "kebab-case")] +#[value(rename_all = "kebab-case")] +pub enum LedgerResumeStrategy { + #[default] + Reset, + ResumeOnly, + Replay, +} + +impl LedgerResumeStrategy { + pub fn is_resuming(&self) -> bool { + self != &Self::Reset + } + + pub fn is_removing_ledger(&self) -> bool { + self != &Self::Replay + } + + pub fn is_replaying(&self) -> bool { + self == &Self::Replay + } +} + const fn default_ledger_size() -> u64 { DEFAULT_LEDGER_SIZE_BYTES } @@ -55,11 +90,12 @@ mod tests { use magicblock_config_helpers::Merge; use super::*; + use crate::EphemeralConfig; #[test] fn test_merge_with_default() { let mut config = LedgerConfig { - reset: false, + resume_strategy: LedgerResumeStrategy::Replay, path: Some("ledger.example.com".to_string()), size: 1000000000, }; @@ -75,7 +111,7 @@ mod tests { fn test_merge_default_with_non_default() { let mut config = LedgerConfig::default(); let other = LedgerConfig { - reset: false, + resume_strategy: LedgerResumeStrategy::Replay, path: Some("ledger.example.com".to_string()), size: 1000000000, }; @@ -88,13 +124,13 @@ mod tests { #[test] fn test_merge_non_default() { let mut config = LedgerConfig { - reset: false, + resume_strategy: LedgerResumeStrategy::Replay, path: Some("ledger.example.com".to_string()), size: 1000000000, }; let original_config = config.clone(); let other = LedgerConfig { - reset: true, + resume_strategy: LedgerResumeStrategy::ResumeOnly, path: Some("ledger2.example.com".to_string()), size: 10000, }; @@ -103,4 +139,56 @@ mod tests { assert_eq!(config, original_config); } + + #[test] + fn test_serde() { + let toml_str = r#" +[ledger] +resume-strategy = "replay" +path = "ledger.example.com" +size = 1000000000 +"#; + + let config: EphemeralConfig = toml::from_str(toml_str).unwrap(); + assert_eq!( + config.ledger, + LedgerConfig { + resume_strategy: LedgerResumeStrategy::Replay, + path: Some("ledger.example.com".to_string()), + size: 1000000000, + } + ); + + let toml_str = r#" +[ledger] +resume-strategy = "resume-only" +size = 1000000000 +"#; + + let config: EphemeralConfig = toml::from_str(toml_str).unwrap(); + assert_eq!( + config.ledger, + LedgerConfig { + resume_strategy: LedgerResumeStrategy::ResumeOnly, + path: None, + size: 1000000000, + } + ); + + let toml_str = r#" +[ledger] +resume-strategy = "reset" +size = 1000000000 +"#; + + let config: EphemeralConfig = toml::from_str(toml_str).unwrap(); + assert_eq!( + config.ledger, + LedgerConfig { + resume_strategy: LedgerResumeStrategy::Reset, + path: None, + size: 1000000000, + } + ); + } } diff --git a/magicblock-config/src/lib.rs b/magicblock-config/src/lib.rs index 85a026d33..bd23c7472 100644 --- a/magicblock-config/src/lib.rs +++ b/magicblock-config/src/lib.rs @@ -206,7 +206,7 @@ mod tests { .unwrap()]), }, lifecycle: LifecycleMode::Offline, - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 123, compute_unit_price: 123, }, @@ -242,7 +242,7 @@ mod tests { country_code: CountryCode::for_alpha2("FR").unwrap(), }, ledger: LedgerConfig { - reset: false, + resume_strategy: LedgerResumeStrategy::Replay, path: Some("ledger.example.com".to_string()), size: 1000000000, }, @@ -285,7 +285,7 @@ mod tests { .unwrap()]), }, lifecycle: LifecycleMode::Offline, - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 123, compute_unit_price: 123, }, @@ -321,7 +321,7 @@ mod tests { country_code: CountryCode::for_alpha2("FR").unwrap(), }, ledger: LedgerConfig { - reset: false, + resume_strategy: LedgerResumeStrategy::Replay, path: Some("ledger.example.com".to_string()), size: 1000000000, }, @@ -361,7 +361,7 @@ mod tests { .unwrap()]), }, lifecycle: LifecycleMode::Offline, - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 12365, compute_unit_price: 123665, }, @@ -397,7 +397,7 @@ mod tests { country_code: CountryCode::for_alpha2("DE").unwrap(), }, ledger: LedgerConfig { - reset: false, + resume_strategy: LedgerResumeStrategy::ResumeOnly, path: Some("ledger2.example.com".to_string()), size: 100000, }, @@ -430,7 +430,7 @@ mod tests { .unwrap()]), }, lifecycle: LifecycleMode::Offline, - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 123, compute_unit_price: 123, }, @@ -466,7 +466,7 @@ mod tests { country_code: CountryCode::for_alpha2("FR").unwrap(), }, ledger: LedgerConfig { - reset: false, + resume_strategy: LedgerResumeStrategy::Replay, path: Some("ledger.example.com".to_string()), size: 1000000000, }, @@ -502,7 +502,7 @@ mod tests { ws_url: None, }, lifecycle: LifecycleMode::Offline, - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 9_000_000_000_000, compute_unit_price: 1_000_000, }, diff --git a/magicblock-config/tests/fixtures/02_defaults.toml b/magicblock-config/tests/fixtures/02_defaults.toml index 074594a34..fc0288a93 100644 --- a/magicblock-config/tests/fixtures/02_defaults.toml +++ b/magicblock-config/tests/fixtures/02_defaults.toml @@ -24,4 +24,4 @@ millis_per_slot = 50 sigverify = true [ledger] -reset = true +resume-strategy = "reset" diff --git a/magicblock-config/tests/fixtures/05_all-goes.toml b/magicblock-config/tests/fixtures/05_all-goes.toml index 451a8babf..05576c624 100644 --- a/magicblock-config/tests/fixtures/05_all-goes.toml +++ b/magicblock-config/tests/fixtures/05_all-goes.toml @@ -10,4 +10,4 @@ lifecycle = "replica" sigverify = false [ledger] -reset = false +resume-strategy = "replay" diff --git a/magicblock-config/tests/parse_config.rs b/magicblock-config/tests/parse_config.rs index a9263d26e..555032bf3 100644 --- a/magicblock-config/tests/parse_config.rs +++ b/magicblock-config/tests/parse_config.rs @@ -2,10 +2,10 @@ use std::net::{IpAddr, Ipv4Addr}; use isocountry::CountryCode; use magicblock_config::{ - AccountsConfig, AllowedProgram, CommitStrategy, EphemeralConfig, - GeyserGrpcConfig, LedgerConfig, LifecycleMode, MetricsConfig, - MetricsServiceConfig, ProgramConfig, RemoteConfig, RpcConfig, - ValidatorConfig, + AccountsConfig, AllowedProgram, CommitStrategyConfig, EphemeralConfig, + GeyserGrpcConfig, LedgerConfig, LedgerResumeStrategy, LifecycleMode, + MetricsConfig, MetricsServiceConfig, ProgramConfig, RemoteConfig, + RpcConfig, ValidatorConfig, }; use solana_sdk::pubkey; use url::Url; @@ -67,7 +67,7 @@ fn test_all_goes_toml() { ..Default::default() }, ledger: LedgerConfig { - reset: false, + resume_strategy: LedgerResumeStrategy::Replay, ..Default::default() }, ..Default::default() @@ -84,7 +84,7 @@ fn test_local_dev_with_programs_toml() { config, EphemeralConfig { accounts: AccountsConfig { - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 600_000, compute_unit_price: 0, }, diff --git a/magicblock-config/tests/read_config.rs b/magicblock-config/tests/read_config.rs index 027a2cc73..bec462d47 100644 --- a/magicblock-config/tests/read_config.rs +++ b/magicblock-config/tests/read_config.rs @@ -6,10 +6,10 @@ use std::{ use isocountry::CountryCode; use magicblock_config::{ - AccountsConfig, CommitStrategy, EphemeralConfig, GeyserGrpcConfig, - LedgerConfig, LifecycleMode, MagicBlockConfig, MetricsConfig, - MetricsServiceConfig, ProgramConfig, RemoteCluster, RemoteConfig, - RpcConfig, ValidatorConfig, + AccountsConfig, CommitStrategyConfig, EphemeralConfig, GeyserGrpcConfig, + LedgerConfig, LedgerResumeStrategy, LifecycleMode, MagicBlockConfig, + MetricsConfig, MetricsServiceConfig, ProgramConfig, RemoteCluster, + RemoteConfig, RpcConfig, ValidatorConfig, }; use solana_sdk::pubkey; use test_tools_core::paths::cargo_workspace_dir; @@ -50,7 +50,7 @@ fn test_load_local_dev_with_programs_toml() { config, EphemeralConfig { accounts: AccountsConfig { - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 600_000, compute_unit_price: 0, }, @@ -117,11 +117,13 @@ fn test_load_local_dev_with_programs_toml_envs_override() { env::set_var("VALIDATOR_COUNTRY_CODE", "CY"); env::set_var("VALIDATOR_FQDN", "magicblock.er.com"); env::set_var("LEDGER_RESET", "false"); + env::set_var("LEDGER_SKIP_REPLAY", "true"); env::set_var("LEDGER_PATH", "/hello/world"); env::set_var("METRICS_ENABLED", "false"); env::set_var("METRICS_PORT", "1234"); env::set_var("METRICS_SYSTEM_METRICS_TICK_INTERVAL_SECS", "10"); env::set_var("LEDGER_SIZE", "123123"); + env::set_var("LEDGER_RESUME_STRATEGY", "resume-only"); let config = parse_config_with_file(&config_file_dir); @@ -130,7 +132,7 @@ fn test_load_local_dev_with_programs_toml_envs_override() { EphemeralConfig { accounts: AccountsConfig { lifecycle: LifecycleMode::Ephemeral, - commit: CommitStrategy { + commit: CommitStrategyConfig { frequency_millis: 123, compute_unit_price: 1, }, @@ -164,7 +166,7 @@ fn test_load_local_dev_with_programs_toml_envs_override() { ..Default::default() }, ledger: LedgerConfig { - reset: false, + resume_strategy: LedgerResumeStrategy::ResumeOnly, path: Some("/hello/world".to_string()), size: 123123 }, diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 4f0574064..dcca76031 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1275,6 +1275,26 @@ dependencies = [ "web-sys", ] +[[package]] +name = "const_format" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126f97965c8ad46d6d9163268ff28432e8f6a1196a55578867832e3049df63dd" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "constant_time_eq" version = "0.3.1" @@ -3671,6 +3691,7 @@ dependencies = [ name = "magicblock-accounts-db" version = "0.1.7" dependencies = [ + "const_format", "lmdb-rkv", "log", "magicblock-config", diff --git a/test-integration/test-ledger-restore/src/lib.rs b/test-integration/test-ledger-restore/src/lib.rs index c68c60288..3d4610142 100644 --- a/test-integration/test-ledger-restore/src/lib.rs +++ b/test-integration/test-ledger-restore/src/lib.rs @@ -10,8 +10,8 @@ use integration_test_tools::{ IntegrationTestContext, }; use magicblock_config::{ - AccountsConfig, EphemeralConfig, LedgerConfig, LifecycleMode, - ProgramConfig, RemoteCluster, RemoteConfig, ValidatorConfig, + AccountsConfig, EphemeralConfig, LedgerConfig, LedgerResumeStrategy, + LifecycleMode, ProgramConfig, RemoteCluster, RemoteConfig, ValidatorConfig, DEFAULT_LEDGER_SIZE_BYTES, }; use program_flexi_counter::state::FlexiCounter; @@ -37,7 +37,7 @@ pub fn setup_offline_validator( ledger_path: &Path, programs: Option>, millis_per_slot: Option, - reset: bool, + resume_strategy: LedgerResumeStrategy, ) -> (TempDir, Child, IntegrationTestContext) { let mut accounts_config = AccountsConfig { lifecycle: LifecycleMode::Offline, @@ -56,7 +56,7 @@ pub fn setup_offline_validator( let config = EphemeralConfig { ledger: LedgerConfig { - reset, + resume_strategy, path: Some(ledger_path.display().to_string()), size: DEFAULT_LEDGER_SIZE_BYTES, }, @@ -100,11 +100,17 @@ pub fn setup_validator_with_local_remote( let programs = resolve_programs(programs); + let resume_strategy = if reset { + LedgerResumeStrategy::Reset + } else { + LedgerResumeStrategy::Replay + }; let config = EphemeralConfig { ledger: LedgerConfig { - reset, + resume_strategy, path: Some(ledger_path.display().to_string()), size: DEFAULT_LEDGER_SIZE_BYTES, + ..Default::default() }, accounts: accounts_config.clone(), programs, diff --git a/test-integration/test-ledger-restore/tests/01_single_airdrop.rs b/test-integration/test-ledger-restore/tests/01_single_airdrop.rs index 08f62708d..81084c2d6 100644 --- a/test-integration/test-ledger-restore/tests/01_single_airdrop.rs +++ b/test-integration/test-ledger-restore/tests/01_single_airdrop.rs @@ -1,4 +1,5 @@ use cleanass::{assert, assert_eq}; +use magicblock_config::LedgerResumeStrategy; use std::{path::Path, process::Child}; use integration_test_tools::{ @@ -29,8 +30,12 @@ fn write_ledger( pubkey1: &Pubkey, ) -> (Child, Signature, u64) { // Launch a validator and airdrop to an account - let (_, mut validator, ctx) = - setup_offline_validator(ledger_path, None, None, true); + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Reset, + ); let sig = expect!(ctx.airdrop_ephem(pubkey1, 1_111_111), validator); @@ -49,8 +54,12 @@ fn read_ledger( airdrop_sig1: Option<&Signature>, ) -> Child { // Launch another validator reusing ledger - let (_, mut validator, ctx) = - setup_offline_validator(ledger_path, None, None, false); + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Replay, + ); let acc = expect!( expect!(ctx.try_ephem_client(), validator).get_account(pubkey1), diff --git a/test-integration/test-ledger-restore/tests/02_two_airdrops.rs b/test-integration/test-ledger-restore/tests/02_two_airdrops.rs index 244d5675e..199f7e051 100644 --- a/test-integration/test-ledger-restore/tests/02_two_airdrops.rs +++ b/test-integration/test-ledger-restore/tests/02_two_airdrops.rs @@ -1,4 +1,5 @@ use cleanass::{assert, assert_eq}; +use magicblock_config::LedgerResumeStrategy; use std::{path::Path, process::Child}; use integration_test_tools::{ @@ -59,8 +60,12 @@ fn write( pubkey2: &Pubkey, separate_slot: bool, ) -> (Child, Signature, Signature, u64) { - let (_, mut validator, ctx) = - setup_offline_validator(ledger_path, None, None, true); + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Reset, + ); let mut slot = 5; expect!(ctx.wait_for_slot_ephem(slot), validator); @@ -92,8 +97,12 @@ fn read( airdrop_sig1: Option<&Signature>, airdrop_sig2: Option<&Signature>, ) -> Child { - let (_, mut validator, ctx) = - setup_offline_validator(ledger_path, None, None, false); + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Replay, + ); let ephem_client = expect!(ctx.try_ephem_client(), validator); let acc1 = expect!(ephem_client.get_account(pubkey1), validator); @@ -169,6 +178,10 @@ fn _diagnose_read() { eprintln!("{}", pubkey1); eprintln!("{}", pubkey2); - let (_, mut _validator, _ctx) = - setup_offline_validator(&ledger_path, None, None, false); + let (_, mut _validator, _ctx) = setup_offline_validator( + &ledger_path, + None, + None, + LedgerResumeStrategy::Replay, + ); } diff --git a/test-integration/test-ledger-restore/tests/03_single_block_tx_order.rs b/test-integration/test-ledger-restore/tests/03_single_block_tx_order.rs index 11f844592..305fcc3fb 100644 --- a/test-integration/test-ledger-restore/tests/03_single_block_tx_order.rs +++ b/test-integration/test-ledger-restore/tests/03_single_block_tx_order.rs @@ -1,4 +1,5 @@ use cleanass::{assert, assert_eq}; +use magicblock_config::LedgerResumeStrategy; use std::{path::Path, process::Child}; use integration_test_tools::{ @@ -77,8 +78,12 @@ fn write( assert!(confirmed, cleanup(validator)); } - let (_, mut validator, ctx) = - setup_offline_validator(ledger_path, None, Some(SLOT_MS), true); + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + Some(SLOT_MS), + LedgerResumeStrategy::Reset, + ); let mut slot = 1; expect!(ctx.wait_for_slot_ephem(slot), validator); @@ -151,8 +156,12 @@ fn write( } fn read(ledger_path: &Path, keypairs: &[Keypair]) -> Child { - let (_, mut validator, ctx) = - setup_offline_validator(ledger_path, None, Some(SLOT_MS), false); + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + Some(SLOT_MS), + LedgerResumeStrategy::Replay, + ); for keypair in keypairs { let acc = expect!( diff --git a/test-integration/test-ledger-restore/tests/04_flexi-counter.rs b/test-integration/test-ledger-restore/tests/04_flexi-counter.rs index 93b8adebb..6eb998ace 100644 --- a/test-integration/test-ledger-restore/tests/04_flexi-counter.rs +++ b/test-integration/test-ledger-restore/tests/04_flexi-counter.rs @@ -4,7 +4,7 @@ use std::{path::Path, process::Child}; use integration_test_tools::{ expect, tmpdir::resolve_tmp_dir, validator::cleanup, }; -use magicblock_config::ProgramConfig; +use magicblock_config::{LedgerResumeStrategy, ProgramConfig}; use program_flexi_counter::{ instruction::{create_add_ix, create_init_ix, create_mul_ix}, state::FlexiCounter, @@ -85,7 +85,7 @@ fn write( ledger_path, Some(programs), Some(SLOT_MS), - true, + LedgerResumeStrategy::Reset, ); expect!(ctx.wait_for_slot_ephem(1), validator); @@ -240,7 +240,7 @@ fn read(ledger_path: &Path, payer1: &Pubkey, payer2: &Pubkey) -> Child { ledger_path, Some(programs), Some(SLOT_MS), - false, + LedgerResumeStrategy::Replay, ); let counter1_decoded = fetch_counter_ephem(payer1, &mut validator); diff --git a/test-integration/test-ledger-restore/tests/05_program_deploy.rs b/test-integration/test-ledger-restore/tests/05_program_deploy.rs index cffd0acfe..c9961cde3 100644 --- a/test-integration/test-ledger-restore/tests/05_program_deploy.rs +++ b/test-integration/test-ledger-restore/tests/05_program_deploy.rs @@ -1,4 +1,5 @@ use cleanass::assert_eq; +use magicblock_config::LedgerResumeStrategy; use std::{ io::{self, Write}, path::Path, @@ -62,8 +63,12 @@ fn write( ) -> (Child, u64) { let authority = read_authority_pubkey(flexi_counter_paths); - let (_, mut validator, ctx) = - setup_offline_validator(ledger_path, None, None, true); + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Reset, + ); expect!(ctx.wait_for_slot_ephem(1), validator); @@ -120,8 +125,12 @@ fn write( } fn read(ledger_path: &Path, payer: &Pubkey) -> Child { - let (_, mut validator, _) = - setup_offline_validator(ledger_path, None, None, false); + let (_, mut validator, _) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Replay, + ); let counter_decoded = fetch_counter_ephem(payer, &mut validator); assert_eq!( diff --git a/test-integration/test-ledger-restore/tests/12_two_airdrops_one_after_account_flush.rs b/test-integration/test-ledger-restore/tests/12_two_airdrops_one_after_account_flush.rs index 56066a527..f354fdccc 100644 --- a/test-integration/test-ledger-restore/tests/12_two_airdrops_one_after_account_flush.rs +++ b/test-integration/test-ledger-restore/tests/12_two_airdrops_one_after_account_flush.rs @@ -1,5 +1,5 @@ use cleanass::assert_eq; -use magicblock_config::TEST_SNAPSHOT_FREQUENCY; +use magicblock_config::{LedgerResumeStrategy, TEST_SNAPSHOT_FREQUENCY}; use std::{path::Path, process::Child}; use integration_test_tools::{ @@ -34,8 +34,12 @@ fn restore_ledger_with_two_airdrops_with_account_flush_in_between() { } fn write(ledger_path: &Path, pubkey: &Pubkey) -> (Child, u64) { - let (_, mut validator, ctx) = - setup_offline_validator(ledger_path, None, None, true); + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Reset, + ); // First airdrop followed by wait until account is flushed { @@ -66,8 +70,12 @@ fn write(ledger_path: &Path, pubkey: &Pubkey) -> (Child, u64) { fn read(ledger_path: &Path, pubkey: &Pubkey) -> Child { // Measure time let _ = std::time::Instant::now(); - let (_, mut validator, ctx) = - setup_offline_validator(ledger_path, None, None, false); + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Replay, + ); eprintln!( "Validator started in {:?}", std::time::Instant::now().elapsed() diff --git a/test-integration/test-ledger-restore/tests/15_skip_replay.rs b/test-integration/test-ledger-restore/tests/15_skip_replay.rs new file mode 100644 index 000000000..8a95bfb96 --- /dev/null +++ b/test-integration/test-ledger-restore/tests/15_skip_replay.rs @@ -0,0 +1,100 @@ +use cleanass::{assert, assert_eq}; +use magicblock_config::{LedgerResumeStrategy, TEST_SNAPSHOT_FREQUENCY}; +use solana_transaction_status::UiTransactionEncoding; +use std::{path::Path, process::Child}; + +use integration_test_tools::{ + expect, tmpdir::resolve_tmp_dir, validator::cleanup, +}; +use solana_sdk::{ + signature::{Keypair, Signature}, + signer::Signer, +}; +use test_ledger_restore::{setup_offline_validator, TMP_DIR_LEDGER}; + +// In this test we ensure that we can optionally skip the replay of the ledger +// when restoring, restarting at the last slot. +#[test] +fn restore_ledger_skip_replay() { + let (_, ledger_path) = resolve_tmp_dir(TMP_DIR_LEDGER); + + let keypairs = (0..10).map(|_| Keypair::new()).collect::>(); + + // Make some transactions + let (mut validator, slot, signatures) = write(&ledger_path, &keypairs); + validator.kill().unwrap(); + + // Check that we're at the last slot and that the state is still there + let mut validator = read(&ledger_path, &keypairs, &signatures, slot); + validator.kill().unwrap(); +} + +fn write( + ledger_path: &Path, + keypairs: &[Keypair], +) -> (Child, u64, Vec) { + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Reset, + ); + + let mut signatures = Vec::with_capacity(keypairs.len()); + for pubkey in keypairs.iter().map(|kp| kp.pubkey()) { + let signature = + expect!(ctx.airdrop_ephem(&pubkey, 1_111_111), validator); + signatures.push(signature); + + let lamports = + expect!(ctx.fetch_ephem_account_balance(&pubkey), validator); + assert_eq!(lamports, 1_111_111, cleanup(&mut validator)); + } + + // NOTE: This slows the test down a lot (500 * 50ms = 25s) and will + // be improved once we can configure `FLUSH_ACCOUNTS_SLOT_FREQ` + let slot = expect!( + ctx.wait_for_delta_slot_ephem(TEST_SNAPSHOT_FREQUENCY), + validator + ); + + (validator, slot, signatures) +} + +fn read( + ledger_path: &Path, + keypairs: &[Keypair], + signatures: &[Signature], + slot: u64, +) -> Child { + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::ResumeOnly, + ); + + // Current slot of the new validator should be at least the last slot of the previous validator + let validator_slot = expect!(ctx.get_slot_ephem(), validator); + assert!(validator_slot >= slot, cleanup(&mut validator)); + + // Transactions should exist even without replay + for (kp, signature) in keypairs.iter().zip(signatures) { + // The state remains the same + let lamports = + expect!(ctx.fetch_ephem_account_balance(&kp.pubkey()), validator); + assert_eq!(lamports, 1_111_111, cleanup(&mut validator)); + + // Past transactions are lost + assert!( + ctx.try_ephem_client() + .and_then(|client| client + .get_transaction(signature, UiTransactionEncoding::Base58) + .map_err(|e| anyhow::anyhow!("{}", e))) + .is_err(), + cleanup(&mut validator) + ); + } + + validator +} diff --git a/test-integration/test-tools/src/integration_test_context.rs b/test-integration/test-tools/src/integration_test_context.rs index 0473d60ed..8ae8c190e 100644 --- a/test-integration/test-tools/src/integration_test_context.rs +++ b/test-integration/test-tools/src/integration_test_context.rs @@ -752,6 +752,21 @@ impl IntegrationTestContext { // ----------------- // Slot // ----------------- + pub fn get_slot_ephem(&self) -> Result { + self.try_ephem_client().and_then(|ephem_client| { + ephem_client + .get_slot() + .map_err(|e| anyhow::anyhow!("{}", e)) + }) + } + + pub fn get_slot_chain(&self) -> Result { + self.try_chain_client().and_then(|chain_client| { + chain_client + .get_slot() + .map_err(|e| anyhow::anyhow!("{}", e)) + }) + } pub fn wait_for_next_slot_ephem(&self) -> Result { self.try_ephem_client().and_then(Self::wait_for_next_slot) } From c5278340a949eac4ec4523c9071b9e889bd341e1 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 4 Aug 2025 13:51:57 +0900 Subject: [PATCH 155/199] feat: extracted parts from magicblock-program into magicblock-core for use in sdk. Programs don't compile otherwise due to invalid for smart contracts dependencies in magicblock-program --- Cargo.lock | 4 +- .../src/account_dumper_bank.rs | 23 ++-- magicblock-accounts/tests/ensure_accounts.rs | 2 +- magicblock-api/src/errors.rs | 2 +- magicblock-bank/src/geyser.rs | 2 +- .../src/utils/asserts.rs | 6 +- magicblock-committor-service/src/service.rs | 3 +- .../src/stubs/changeset_committor_stub.rs | 7 +- magicblock-core/Cargo.toml | 4 +- magicblock-core/src/lib.rs | 18 +-- magicblock-core/src/magic_program.rs | 16 +++ .../src/magic_program}/args.rs | 0 .../src/magic_program/instruction.rs | 32 +++--- magicblock-mutator/src/fetch.rs | 2 +- magicblock-mutator/src/idl.rs | 11 +- magicblock-mutator/src/lib.rs | 2 +- magicblock-mutator/src/program.rs | 54 +++++---- magicblock-mutator/src/transactions.rs | 13 ++- programs/magicblock/src/errors.rs | 7 -- programs/magicblock/src/lib.rs | 3 - .../src/magic_scheduled_base_intent.rs | 10 +- .../magicblock/src/magicblock_processor.rs | 2 +- .../process_mutate_accounts.rs | 4 +- .../process_accept_scheduled_commits.rs | 3 +- .../process_schedule_base_intent.rs | 2 +- .../process_schedule_commit_tests.rs | 5 +- .../schedule_base_intent_processor.rs | 2 +- .../magicblock/src/utils/instruction_utils.rs | 14 ++- test-integration/Cargo.lock | 108 +++++++----------- test-integration/Cargo.toml | 4 +- 30 files changed, 182 insertions(+), 183 deletions(-) create mode 100644 magicblock-core/src/magic_program.rs rename {programs/magicblock/src => magicblock-core/src/magic_program}/args.rs (100%) rename programs/magicblock/src/magicblock_instruction.rs => magicblock-core/src/magic_program/instruction.rs (88%) diff --git a/Cargo.lock b/Cargo.lock index ddd94f7a5..f77745adc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4133,7 +4133,9 @@ dependencies = [ name = "magicblock-core" version = "0.1.7" dependencies = [ - "solana-sdk", + "bincode", + "serde", + "solana-program", ] [[package]] diff --git a/magicblock-account-dumper/src/account_dumper_bank.rs b/magicblock-account-dumper/src/account_dumper_bank.rs index d91352d13..ecaee8bba 100644 --- a/magicblock-account-dumper/src/account_dumper_bank.rs +++ b/magicblock-account-dumper/src/account_dumper_bank.rs @@ -146,10 +146,14 @@ impl AccountDumper for AccountDumperBank { .map_err(AccountDumperError::MutatorModificationError)?; let program_idl_modification = program_idl.map(|(program_idl_pubkey, program_idl_account)| { - AccountModification::from(( - &program_idl_pubkey, - &program_idl_account, - )) + AccountModification { + pubkey: program_idl_pubkey, + lamports: Some(program_idl_account.lamports), + owner: Some(program_idl_account.owner), + rent_epoch: Some(program_idl_account.rent_epoch), + data: Some(program_idl_account.data), + executable: Some(program_idl_account.executable), + } }); let needs_upgrade = self.bank.has_account(program_id_pubkey); let transaction = transaction_to_clone_program( @@ -179,9 +183,14 @@ impl AccountDumper for AccountDumperBank { slot, ); - let mut program_id_modification = - AccountModification::from((program_pubkey, program_account)); - + let mut program_id_modification = AccountModification { + pubkey: *program_pubkey, + lamports: Some(program_account.lamports), + owner: Some(program_account.owner), + rent_epoch: Some(program_account.rent_epoch), + data: Some(program_account.data.to_owned()), + executable: Some(program_account.executable), + }; // point program account to the derived program data account address let program_id_state = bincode::serialize(&UpgradeableLoaderState::Program { diff --git a/magicblock-accounts/tests/ensure_accounts.rs b/magicblock-accounts/tests/ensure_accounts.rs index b115379e3..01f8e8112 100644 --- a/magicblock-accounts/tests/ensure_accounts.rs +++ b/magicblock-accounts/tests/ensure_accounts.rs @@ -18,12 +18,12 @@ use magicblock_accounts::{ }; use magicblock_accounts_api::InternalAccountProviderStub; use magicblock_committor_service::stubs::ChangesetCommittorStub; +use magicblock_config::AccountsCloneConfig; use solana_sdk::pubkey::Pubkey; use stubs::scheduled_commits_processor_stub::ScheduledCommitsProcessorStub; use test_tools_core::init_logger; use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; -use magicblock_config::AccountsCloneConfig; mod stubs; diff --git a/magicblock-api/src/errors.rs b/magicblock-api/src/errors.rs index 0404bb374..523dedc9a 100644 --- a/magicblock-api/src/errors.rs +++ b/magicblock-api/src/errors.rs @@ -1,5 +1,5 @@ use magicblock_accounts_db::error::AccountsDbError; -use magicblock_program::Pubkey; +use solana_sdk::pubkey::Pubkey; use thiserror::Error; pub type ApiResult = std::result::Result; diff --git a/magicblock-bank/src/geyser.rs b/magicblock-bank/src/geyser.rs index b2a42f75a..8d05d727f 100644 --- a/magicblock-bank/src/geyser.rs +++ b/magicblock-bank/src/geyser.rs @@ -1,9 +1,9 @@ // TODO(bmuddha): get rid of geyser plugins in validator // copied from agave-geyser-plugin-manager src/transaction_notifier.rs +use solana_sdk::pubkey::Pubkey; /// Module responsible for notifying plugins of transactions use { - magicblock_program::Pubkey, solana_accounts_db::{ account_storage::meta::StoredAccountMeta, accounts_update_notifier_interface::AccountsUpdateNotifierInterface, diff --git a/magicblock-committor-program/src/utils/asserts.rs b/magicblock-committor-program/src/utils/asserts.rs index 2e6dc77b4..28c2973c4 100644 --- a/magicblock-committor-program/src/utils/asserts.rs +++ b/magicblock-committor-program/src/utils/asserts.rs @@ -51,7 +51,11 @@ pub fn assert_is_signer( pub fn assert_program_id(program_id: &Pubkey) -> ProgramResult { if program_id != &crate::id() { - msg!("Err: invalid program id, expected: {}, got: {}", crate::id(), program_id); + msg!( + "Err: invalid program id, expected: {}, got: {}", + crate::id(), + program_id + ); Err(ProgramError::IncorrectProgramId) } else { Ok(()) diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 338fb1ca1..4dd580fa0 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -1,7 +1,6 @@ use std::{path::Path, sync::Arc, time::Instant}; use log::*; -use magicblock_rpc_client::MagicblockRpcClient; use solana_pubkey::Pubkey; use solana_sdk::signature::{Keypair, Signature}; use solana_transaction_status_client_types::EncodedConfirmedTransactionWithStatusMeta; @@ -18,7 +17,7 @@ use tokio_util::sync::CancellationToken; use crate::{ committor_processor::CommittorProcessor, config::ChainConfig, - error::{CommittorServiceError, CommittorServiceResult}, + error::CommittorServiceResult, intent_execution_manager::BroadcastedIntentExecutionResult, persist::{CommitStatusRow, MessageSignatures}, pubkeys_provider::{provide_committee_pubkeys, provide_common_pubkeys}, diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index 15e808a2e..9a4d9bb95 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -1,9 +1,9 @@ use std::{ collections::HashMap, sync::{Arc, Mutex}, - time::{SystemTime, UNIX_EPOCH}, + time::{Instant, SystemTime, UNIX_EPOCH}, }; -use std::time::Instant; + use magicblock_program::SentCommit; use solana_pubkey::Pubkey; use solana_sdk::{signature::Signature, transaction::Transaction}; @@ -45,8 +45,7 @@ impl BaseIntentCommittor for ChangesetCommittorStub { owner: Pubkey, ) -> oneshot::Receiver> { let initiated = Instant::now(); - let (tx, rx) = - oneshot::channel::>(); + let (tx, rx) = oneshot::channel::>(); self.reserved_pubkeys_for_committee .lock() .unwrap() diff --git a/magicblock-core/Cargo.toml b/magicblock-core/Cargo.toml index 33b3cf08f..62d184e1e 100644 --- a/magicblock-core/Cargo.toml +++ b/magicblock-core/Cargo.toml @@ -8,4 +8,6 @@ license.workspace = true edition.workspace = true [dependencies] -solana-sdk = { workspace = true } +solana-program = { workspace = true } +bincode = { workspace = true } +serde = { workspace = true, features = ["derive"] } diff --git a/magicblock-core/src/lib.rs b/magicblock-core/src/lib.rs index 4e81af930..1d12afedf 100644 --- a/magicblock-core/src/lib.rs +++ b/magicblock-core/src/lib.rs @@ -1,22 +1,6 @@ +pub mod magic_program; pub mod traits; -pub mod magic_program { - use solana_sdk::pubkey; - pub use solana_sdk::pubkey::Pubkey; - - solana_sdk::declare_id!("Magic11111111111111111111111111111111111111"); - - pub const MAGIC_CONTEXT_PUBKEY: Pubkey = - pubkey!("MagicContext1111111111111111111111111111111"); - - /// We believe 5MB should be enough to store all scheduled commits within a - /// slot. Once we store more data in the magic context we need to reconsicer - /// this size. - /// NOTE: the default max accumulated account size per transaction is 64MB. - /// See: MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES inside program-runtime/src/compute_budget_processor.rs - pub const MAGIC_CONTEXT_SIZE: usize = 1024 * 1024 * 5; // 5 MB -} - /// A macro that panics when running a debug build and logs the panic message /// instead when running in release mode. #[macro_export] diff --git a/magicblock-core/src/magic_program.rs b/magicblock-core/src/magic_program.rs new file mode 100644 index 000000000..48b8b292e --- /dev/null +++ b/magicblock-core/src/magic_program.rs @@ -0,0 +1,16 @@ +use solana_program::{declare_id, pubkey, pubkey::Pubkey}; + +pub mod args; +pub mod instruction; + +declare_id!("Magic11111111111111111111111111111111111111"); + +pub const MAGIC_CONTEXT_PUBKEY: Pubkey = + pubkey!("MagicContext1111111111111111111111111111111"); + +/// We believe 5MB should be enough to store all scheduled commits within a +/// slot. Once we store more data in the magic context we need to reconsicer +/// this size. +/// NOTE: the default max accumulated account size per transaction is 64MB. +/// See: MAX_LOADED_ACCOUNTS_DATA_SIZE_BYTES inside program-runtime/src/compute_budget_processor.rs +pub const MAGIC_CONTEXT_SIZE: usize = 1024 * 1024 * 5; // 5 MB diff --git a/programs/magicblock/src/args.rs b/magicblock-core/src/magic_program/args.rs similarity index 100% rename from programs/magicblock/src/args.rs rename to magicblock-core/src/magic_program/args.rs diff --git a/programs/magicblock/src/magicblock_instruction.rs b/magicblock-core/src/magic_program/instruction.rs similarity index 88% rename from programs/magicblock/src/magicblock_instruction.rs rename to magicblock-core/src/magic_program/instruction.rs index 009aaf768..1ac31482d 100644 --- a/programs/magicblock/src/magicblock_instruction.rs +++ b/magicblock-core/src/magic_program/instruction.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; -use solana_sdk::{account::Account, pubkey::Pubkey}; +use solana_program::pubkey::Pubkey; -use crate::args::MagicBaseIntentArgs; +use crate::magic_program::args::MagicBaseIntentArgs; #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum MagicBlockInstruction { @@ -105,20 +105,20 @@ pub struct AccountModification { pub rent_epoch: Option, } -impl From<(&Pubkey, &Account)> for AccountModification { - fn from( - (account_pubkey, account): (&Pubkey, &Account), - ) -> AccountModification { - AccountModification { - pubkey: *account_pubkey, - lamports: Some(account.lamports), - owner: Some(account.owner), - executable: Some(account.executable), - data: Some(account.data.clone()), - rent_epoch: Some(account.rent_epoch), - } - } -} +// impl From<(&Pubkey, &)> for AccountModification { +// fn from( +// (account_pubkey, account): (&Pubkey, &Accoun), +// ) -> AccountModification { +// AccountModification { +// pubkey: *account_pubkey, +// lamports: Some(account.lamports), +// owner: Some(account.owner), +// executable: Some(account.executable), +// data: Some(account.data.clone()), +// rent_epoch: Some(account.rent_epoch), +// } +// } +// } #[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct AccountModificationForInstruction { diff --git a/magicblock-mutator/src/fetch.rs b/magicblock-mutator/src/fetch.rs index 3e5b03060..a75e92282 100644 --- a/magicblock-mutator/src/fetch.rs +++ b/magicblock-mutator/src/fetch.rs @@ -1,4 +1,4 @@ -use magicblock_program::magicblock_instruction::AccountModification; +use magicblock_program::instruction::AccountModification; use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ account::Account, bpf_loader_upgradeable::get_program_data_address, diff --git a/magicblock-mutator/src/idl.rs b/magicblock-mutator/src/idl.rs index 2eae9d632..cf8cc6857 100644 --- a/magicblock-mutator/src/idl.rs +++ b/magicblock-mutator/src/idl.rs @@ -1,4 +1,4 @@ -use magicblock_program::magicblock_instruction::AccountModification; +use magicblock_program::instruction::AccountModification; use solana_sdk::pubkey::Pubkey; use crate::{fetch::fetch_account_from_cluster, Cluster}; @@ -51,7 +51,14 @@ async fn try_fetch_program_idl_modification_from_cluster( if let Some(pubkey) = pubkey { if let Ok(account) = fetch_account_from_cluster(cluster, &pubkey).await { - return Some(AccountModification::from((&pubkey, &account))); + return Some(AccountModification { + pubkey, + lamports: Some(account.lamports), + owner: Some(account.owner), + executable: Some(account.executable), + data: Some(account.data.clone()), + rent_epoch: Some(account.rent_epoch), + }); } } None diff --git a/magicblock-mutator/src/lib.rs b/magicblock-mutator/src/lib.rs index a0044f733..bbce6be52 100644 --- a/magicblock-mutator/src/lib.rs +++ b/magicblock-mutator/src/lib.rs @@ -7,4 +7,4 @@ pub mod transactions; pub use cluster::*; pub use fetch::transaction_to_clone_pubkey_from_cluster; -pub use magicblock_program::magicblock_instruction::AccountModification; +pub use magicblock_program::instruction::AccountModification; diff --git a/magicblock-mutator/src/program.rs b/magicblock-mutator/src/program.rs index adab41201..1ff3c2ded 100644 --- a/magicblock-mutator/src/program.rs +++ b/magicblock-mutator/src/program.rs @@ -1,6 +1,4 @@ -use magicblock_program::{ - magicblock_instruction::AccountModification, validator, -}; +use magicblock_program::{instruction::AccountModification, validator}; use solana_sdk::{ account::Account, bpf_loader_upgradeable::{self, UpgradeableLoaderState}, @@ -48,8 +46,14 @@ pub fn create_program_modifications( let program_data_bytecode = &program_data_account.data[program_data_bytecode_index..]; // We'll need to edit the main program account - let program_id_modification = - AccountModification::from((program_id_pubkey, program_id_account)); + let program_id_modification = AccountModification { + pubkey: *program_id_pubkey, + lamports: Some(program_id_account.lamports), + owner: Some(program_id_account.owner), + rent_epoch: Some(program_id_account.rent_epoch), + data: Some(program_id_account.data.to_owned()), + executable: Some(program_id_account.executable), + }; // Build the proper program_data that we will want to upgrade later let program_data_modification = create_program_data_modification( program_data_pubkey, @@ -79,18 +83,18 @@ pub fn create_program_data_modification( }) .unwrap(); program_data_data.extend_from_slice(program_data_bytecode); - AccountModification::from(( - program_data_pubkey, - &Account { - lamports: Rent::default() + AccountModification { + pubkey: *program_data_pubkey, + lamports: Some( + Rent::default() .minimum_balance(program_data_data.len()) .max(1), - data: program_data_data, - owner: bpf_loader_upgradeable::id(), - executable: false, - rent_epoch: u64::MAX, - }, - )) + ), + data: Some(program_data_data), + owner: Some(bpf_loader_upgradeable::id()), + executable: Some(false), + rent_epoch: Some(u64::MAX), + } } pub fn create_program_buffer_modification( @@ -102,16 +106,16 @@ pub fn create_program_buffer_modification( }) .unwrap(); program_buffer_data.extend_from_slice(program_data_bytecode); - AccountModification::from(( - &Keypair::new().pubkey(), - &Account { - lamports: Rent::default() + AccountModification { + pubkey: Keypair::new().pubkey(), + lamports: Some( + Rent::default() .minimum_balance(program_buffer_data.len()) .max(1), - data: program_buffer_data, - owner: bpf_loader_upgradeable::id(), - executable: false, - rent_epoch: u64::MAX, - }, - )) + ), + data: Some(program_buffer_data), + owner: Some(bpf_loader_upgradeable::id()), + executable: Some(false), + rent_epoch: Some(u64::MAX), + } } diff --git a/magicblock-mutator/src/transactions.rs b/magicblock-mutator/src/transactions.rs index 8af6f6943..f1d0079c5 100644 --- a/magicblock-mutator/src/transactions.rs +++ b/magicblock-mutator/src/transactions.rs @@ -1,6 +1,6 @@ use magicblock_program::{ - instruction_utils::InstructionUtils, - magicblock_instruction::AccountModification, validator, + instruction::AccountModification, instruction_utils::InstructionUtils, + validator, }; use solana_sdk::{ account::Account, bpf_loader_upgradeable, hash::Hash, pubkey::Pubkey, @@ -14,7 +14,14 @@ pub fn transaction_to_clone_regular_account( recent_blockhash: Hash, ) -> Transaction { // Just a single mutation for regular accounts, just dump the data directly, while applying overrides - let mut account_modification = AccountModification::from((pubkey, account)); + let mut account_modification = AccountModification { + pubkey: *pubkey, + lamports: Some(account.lamports), + owner: Some(account.owner), + rent_epoch: Some(account.rent_epoch), + data: Some(account.data.to_owned()), + executable: Some(account.executable), + }; if let Some(overrides) = overrides { if let Some(lamports) = overrides.lamports { account_modification.lamports = Some(lamports); diff --git a/programs/magicblock/src/errors.rs b/programs/magicblock/src/errors.rs index 532c5cf1c..367c1739f 100644 --- a/programs/magicblock/src/errors.rs +++ b/programs/magicblock/src/errors.rs @@ -1,6 +1,5 @@ use num_derive::{FromPrimitive, ToPrimitive}; use serde::Serialize; -use solana_sdk::decode_error::DecodeError; use thiserror::Error; // ----------------- @@ -49,9 +48,3 @@ pub enum MagicBlockProgramError { #[error("Encountered an error when persisting account modification data.")] FailedToPersistAccountModData, } - -impl DecodeError for MagicBlockProgramError { - fn type_of() -> &'static str { - "MagicBlockProgramError" - } -} diff --git a/programs/magicblock/src/lib.rs b/programs/magicblock/src/lib.rs index 287e92482..41e7d9cb7 100644 --- a/programs/magicblock/src/lib.rs +++ b/programs/magicblock/src/lib.rs @@ -3,10 +3,7 @@ mod magic_context; mod mutate_accounts; mod schedule_transactions; pub use magic_context::{FeePayerAccount, MagicContext}; -pub mod args; pub mod magic_scheduled_base_intent; -pub mod magicblock_instruction; -// TODO(edwin): isolate with features pub mod magicblock_processor; #[cfg(test)] mod test_utils; diff --git a/programs/magicblock/src/magic_scheduled_base_intent.rs b/programs/magicblock/src/magic_scheduled_base_intent.rs index 498d62db4..aec01bc03 100644 --- a/programs/magicblock/src/magic_scheduled_base_intent.rs +++ b/programs/magicblock/src/magic_scheduled_base_intent.rs @@ -1,5 +1,9 @@ use std::{cell::RefCell, collections::HashSet}; +use magicblock_core::magic_program::args::{ + ActionArgs, BaseActionArgs, CommitAndUndelegateArgs, CommitTypeArgs, + MagicBaseIntentArgs, UndelegateTypeArgs, +}; use serde::{Deserialize, Serialize}; use solana_log_collector::ic_msg; use solana_program_runtime::{ @@ -9,20 +13,16 @@ use solana_program_runtime::{ use solana_sdk::{ account::{Account, AccountSharedData}, clock::Slot, + pubkey::Pubkey, transaction::Transaction, }; use crate::{ - args::{ - ActionArgs, BaseActionArgs, CommitAndUndelegateArgs, CommitTypeArgs, - MagicBaseIntentArgs, UndelegateTypeArgs, - }, instruction_utils::InstructionUtils, utils::accounts::{ get_instruction_account_short_meta_with_idx, get_instruction_account_with_idx, get_instruction_pubkey_with_idx, }, - Pubkey, }; /// Context necessary for construction of Schedule Action diff --git a/programs/magicblock/src/magicblock_processor.rs b/programs/magicblock/src/magicblock_processor.rs index 3066192c4..945bfae9b 100644 --- a/programs/magicblock/src/magicblock_processor.rs +++ b/programs/magicblock/src/magicblock_processor.rs @@ -1,8 +1,8 @@ +use magicblock_core::magic_program::instruction::MagicBlockInstruction; use solana_program_runtime::declare_process_instruction; use solana_sdk::program_utils::limited_deserialize; use crate::{ - magicblock_instruction::MagicBlockInstruction, mutate_accounts::process_mutate_accounts, process_scheduled_commit_sent, schedule_transactions::{ diff --git a/programs/magicblock/src/mutate_accounts/process_mutate_accounts.rs b/programs/magicblock/src/mutate_accounts/process_mutate_accounts.rs index 7ec81b5a7..392cb1c45 100644 --- a/programs/magicblock/src/mutate_accounts/process_mutate_accounts.rs +++ b/programs/magicblock/src/mutate_accounts/process_mutate_accounts.rs @@ -1,5 +1,6 @@ use std::collections::{HashMap, HashSet}; +use magicblock_core::magic_program::instruction::AccountModificationForInstruction; use solana_log_collector::ic_msg; use solana_program_runtime::invoke_context::InvokeContext; use solana_sdk::{ @@ -12,7 +13,6 @@ use solana_sdk::{ use crate::{ errors::MagicBlockProgramError, - magicblock_instruction::AccountModificationForInstruction, mutate_accounts::account_mod_data::resolve_account_mod_data, validator::validator_authority_id, }; @@ -268,6 +268,7 @@ mod tests { use std::collections::HashMap; use assert_matches::assert_matches; + use magicblock_core::magic_program::instruction::AccountModification; use solana_sdk::{ account::{Account, AccountSharedData}, pubkey::Pubkey, @@ -277,7 +278,6 @@ mod tests { use super::*; use crate::{ instruction_utils::InstructionUtils, - magicblock_instruction::AccountModification, test_utils::{ ensure_started_validator, process_instruction, AUTHORITY_BALANCE, }, diff --git a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs index 4adf8d04b..60303b341 100644 --- a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs +++ b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs @@ -5,6 +5,7 @@ use solana_program_runtime::{ __private::{InstructionError, ReadableAccount}, invoke_context::InvokeContext, }; +use solana_sdk::pubkey::Pubkey; use crate::{ schedule_transactions, @@ -12,7 +13,7 @@ use crate::{ get_instruction_account_with_idx, get_instruction_pubkey_with_idx, }, validator::validator_authority_id, - MagicContext, Pubkey, TransactionScheduler, + MagicContext, TransactionScheduler, }; pub fn process_accept_scheduled_commits( diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs b/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs index b714fdfed..e02d09c93 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs @@ -1,5 +1,6 @@ use std::{collections::HashSet, sync::atomic::Ordering}; +use magicblock_core::magic_program::args::MagicBaseIntentArgs; use solana_log_collector::ic_msg; use solana_program_runtime::invoke_context::InvokeContext; use solana_sdk::{ @@ -8,7 +9,6 @@ use solana_sdk::{ }; use crate::{ - args::MagicBaseIntentArgs, magic_scheduled_base_intent::{ConstructionContext, ScheduledBaseIntent}, schedule_transactions::{ check_magic_context_id, diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs index 941717023..4c2209e95 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit_tests.rs @@ -1,7 +1,9 @@ use std::collections::HashMap; use assert_matches::assert_matches; -use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; +use magicblock_core::magic_program::{ + instruction::MagicBlockInstruction, MAGIC_CONTEXT_PUBKEY, +}; use solana_sdk::{ account::{ create_account_shared_data_for_test, AccountSharedData, ReadableAccount, @@ -20,7 +22,6 @@ use test_tools_core::init_logger; use crate::{ magic_context::MagicContext, magic_scheduled_base_intent::ScheduledBaseIntent, - magicblock_instruction::MagicBlockInstruction, schedule_transactions::transaction_scheduler::TransactionScheduler, test_utils::{ensure_started_validator, process_instruction}, utils::DELEGATION_PROGRAM_ID, diff --git a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs index fed81d608..b7bb02ae0 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs @@ -1,7 +1,7 @@ +use magicblock_core::magic_program::args::MagicBaseIntentArgs; use solana_sdk::instruction::InstructionError; use crate::{ - args::MagicBaseIntentArgs, magic_scheduled_base_intent::{CommitType, ConstructionContext}, utils::account_actions::set_account_owner_to_delegation_program, }; diff --git a/programs/magicblock/src/utils/instruction_utils.rs b/programs/magicblock/src/utils/instruction_utils.rs index 60e9e5e2b..a9b25a432 100644 --- a/programs/magicblock/src/utils/instruction_utils.rs +++ b/programs/magicblock/src/utils/instruction_utils.rs @@ -1,21 +1,23 @@ use std::collections::HashMap; -use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; +use magicblock_core::magic_program::{ + instruction::{ + AccountModification, AccountModificationForInstruction, + MagicBlockInstruction, + }, + MAGIC_CONTEXT_PUBKEY, +}; use solana_program_runtime::__private::Hash; use solana_sdk::{ instruction::{AccountMeta, Instruction}, + pubkey::Pubkey, signature::{Keypair, Signer}, transaction::Transaction, }; use crate::{ - magicblock_instruction::{ - AccountModification, AccountModificationForInstruction, - MagicBlockInstruction, - }, mutate_accounts::set_account_mod_data, validator::{validator_authority, validator_authority_id}, - Pubkey, }; pub struct InstructionUtils; diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 8b497a50b..847e3d1d6 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1810,21 +1810,19 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=63f624f#63f624f3e24007a77a06c1c223e07d6a351244f1" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk-attribute-commit", "ephemeral-rollups-sdk-attribute-delegate", "ephemeral-rollups-sdk-attribute-ephemeral", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", - "magicblock-program 0.1.2", + "magicblock-core", + "magicblock-delegation-program 1.0.0", "solana-program", ] [[package]] name = "ephemeral-rollups-sdk-attribute-commit" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=63f624f#63f624f3e24007a77a06c1c223e07d6a351244f1" dependencies = [ "quote", "syn 1.0.109", @@ -1833,7 +1831,6 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-delegate" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=63f624f#63f624f3e24007a77a06c1c223e07d6a351244f1" dependencies = [ "proc-macro2", "quote", @@ -1843,7 +1840,6 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-ephemeral" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=63f624f#63f624f3e24007a77a06c1c223e07d6a351244f1" dependencies = [ "proc-macro2", "quote", @@ -3000,7 +2996,7 @@ dependencies = [ "borsh 1.5.7", "log", "magicblock-config", - "magicblock-core 0.1.7", + "magicblock-core", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", "rayon", "serde", @@ -3584,8 +3580,8 @@ dependencies = [ "magicblock-accounts-api", "magicblock-committor-service", "magicblock-config", - "magicblock-core 0.1.7", - "magicblock-metrics 0.1.7", + "magicblock-core", + "magicblock-metrics", "magicblock-mutator", "magicblock-rpc-client", "solana-sdk", @@ -3615,7 +3611,7 @@ dependencies = [ "conjunto-transwise", "futures-util", "log", - "magicblock-metrics 0.1.7", + "magicblock-metrics", "solana-sdk", "thiserror 1.0.69", "tokio", @@ -3630,7 +3626,7 @@ dependencies = [ "conjunto-transwise", "futures-util", "log", - "magicblock-metrics 0.1.7", + "magicblock-metrics", "solana-account-decoder", "solana-pubsub-client", "solana-rpc-client-api", @@ -3656,12 +3652,12 @@ dependencies = [ "magicblock-accounts-api", "magicblock-bank", "magicblock-committor-service", - "magicblock-core 0.1.7", + "magicblock-core", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", - "magicblock-metrics 0.1.7", + "magicblock-metrics", "magicblock-mutator", "magicblock-processor", - "magicblock-program 0.1.7", + "magicblock-program", "magicblock-transaction-status", "solana-rpc-client", "solana-rpc-client-api", @@ -3720,13 +3716,13 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-config", - "magicblock-core 0.1.7", + "magicblock-core", "magicblock-geyser-plugin", "magicblock-ledger", - "magicblock-metrics 0.1.7", + "magicblock-metrics", "magicblock-perf-service", "magicblock-processor", - "magicblock-program 0.1.7", + "magicblock-program", "magicblock-pubsub", "magicblock-rpc", "magicblock-transaction-status", @@ -3751,8 +3747,8 @@ dependencies = [ "log", "magicblock-accounts-db", "magicblock-config", - "magicblock-core 0.1.7", - "magicblock-program 0.1.7", + "magicblock-core", + "magicblock-program", "rand 0.8.5", "serde", "solana-accounts-db", @@ -3806,7 +3802,7 @@ dependencies = [ "lru 0.16.0", "magicblock-committor-program", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", - "magicblock-program 0.1.7", + "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", "rusqlite", @@ -3858,17 +3854,26 @@ dependencies = [ [[package]] name = "magicblock-core" -version = "0.1.2" -source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=aed2b895daf720507ded57d63b277b0e95435f10#aed2b895daf720507ded57d63b277b0e95435f10" +version = "0.1.7" dependencies = [ - "solana-sdk", + "bincode", + "serde", + "solana-program", ] [[package]] -name = "magicblock-core" -version = "0.1.7" +name = "magicblock-delegation-program" +version = "1.0.0" dependencies = [ - "solana-sdk", + "bincode", + "borsh 1.5.7", + "bytemuck", + "num_enum", + "paste", + "solana-curve25519", + "solana-program", + "solana-security-txt", + "thiserror 1.0.69", ] [[package]] @@ -3943,7 +3948,7 @@ dependencies = [ "log", "magicblock-accounts-db", "magicblock-bank", - "magicblock-core 0.1.7", + "magicblock-core", "num-format", "num_cpus", "prost", @@ -3962,21 +3967,6 @@ dependencies = [ "tokio-util 0.7.15", ] -[[package]] -name = "magicblock-metrics" -version = "0.1.2" -source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=aed2b895daf720507ded57d63b277b0e95435f10#aed2b895daf720507ded57d63b277b0e95435f10" -dependencies = [ - "http-body-util", - "hyper 1.6.0", - "hyper-util", - "lazy_static", - "log", - "prometheus", - "tokio", - "tokio-util 0.7.15", -] - [[package]] name = "magicblock-metrics" version = "0.1.7" @@ -3997,7 +3987,7 @@ version = "0.1.7" dependencies = [ "bincode", "log", - "magicblock-program 0.1.7", + "magicblock-program", "solana-rpc-client", "solana-rpc-client-api", "solana-sdk", @@ -4034,32 +4024,14 @@ dependencies = [ "spl-token-2022 6.0.0", ] -[[package]] -name = "magicblock-program" -version = "0.1.2" -source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=aed2b895daf720507ded57d63b277b0e95435f10#aed2b895daf720507ded57d63b277b0e95435f10" -dependencies = [ - "bincode", - "lazy_static", - "magicblock-core 0.1.2", - "magicblock-metrics 0.1.2", - "num-derive", - "num-traits", - "serde", - "solana-log-collector", - "solana-program-runtime", - "solana-sdk", - "thiserror 1.0.69", -] - [[package]] name = "magicblock-program" version = "0.1.7" dependencies = [ "bincode", "lazy_static", - "magicblock-core 0.1.7", - "magicblock-metrics 0.1.7", + "magicblock-core", + "magicblock-metrics", "num-derive", "num-traits", "serde", @@ -4106,7 +4078,7 @@ dependencies = [ "magicblock-accounts", "magicblock-bank", "magicblock-ledger", - "magicblock-metrics 0.1.7", + "magicblock-metrics", "magicblock-processor", "magicblock-tokens", "magicblock-transaction-status", @@ -5920,7 +5892,7 @@ dependencies = [ "anyhow", "borsh 1.5.7", "integration-test-tools", - "magicblock-core 0.1.7", + "magicblock-core", "program-schedulecommit", "solana-program", "solana-rpc-client", @@ -5936,7 +5908,7 @@ dependencies = [ "magicblock-committor-program", "magicblock-committor-service", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", - "magicblock-program 0.1.7", + "magicblock-program", "magicblock-rpc-client", "program-flexi-counter", "solana-account", @@ -5955,7 +5927,7 @@ dependencies = [ "ephemeral-rollups-sdk", "integration-test-tools", "log", - "magicblock-core 0.1.7", + "magicblock-core", "program-schedulecommit", "schedulecommit-client", "solana-program", @@ -5970,7 +5942,7 @@ name = "schedulecommit-test-security" version = "0.0.0" dependencies = [ "integration-test-tools", - "magicblock-core 0.1.7", + "magicblock-core", "program-schedulecommit", "program-schedulecommit-security", "schedulecommit-client", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 6f904024c..8948cdfbe 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -28,8 +28,8 @@ edition = "2021" anyhow = "1.0.86" borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" -#ephemeral-rollups-sdk = { path = "../../ephemeral-rollups-sdk/rust/sdk" } -ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "63f624f" } +ephemeral-rollups-sdk = { path = "../../ephemeral-rollups-sdk/rust/sdk" } +#ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "63f624f" } integration-test-tools = { path = "test-tools" } log = "0.4.20" magicblock-api = { path = "../magicblock-api" } From 706ff3ccf60e316b6d9fb8b967115ae8bd905674 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 4 Aug 2025 14:49:01 +0900 Subject: [PATCH 156/199] fix: integration tests compilation --- .../tests/test_delivery_preparator.rs | 3 +++ .../tests/test_message_executor.rs | 4 ---- .../tests/test_transaction_preparator.rs | 5 +++++ .../src/magic_program/instruction.rs | 21 +++---------------- .../tests/utils/instructions.rs | 1 + .../test-scenarios/tests/01_commits.rs | 9 ++++---- .../tests/02_commit_and_undelegate.rs | 18 ++++++++-------- .../tests/03_commits_fee_payer.rs | 9 ++++---- .../test-security/tests/01_invocations.rs | 17 +++++++-------- .../test-security/tests/utils/mod.rs | 9 ++++---- .../test-tools/src/conversions.rs | 4 ---- 11 files changed, 41 insertions(+), 59 deletions(-) delete mode 100644 magicblock-committor-service/tests/test_message_executor.rs diff --git a/magicblock-committor-service/tests/test_delivery_preparator.rs b/magicblock-committor-service/tests/test_delivery_preparator.rs index 0bc8d3f9d..dd962ee76 100644 --- a/magicblock-committor-service/tests/test_delivery_preparator.rs +++ b/magicblock-committor-service/tests/test_delivery_preparator.rs @@ -18,6 +18,7 @@ use crate::common::{create_commit_task, generate_random_bytes, TestFixture}; mod common; +#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_10kb_buffer() { let fixture = TestFixture::new().await; @@ -73,6 +74,7 @@ async fn test_prepare_10kb_buffer() { ); } +#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_multiple_buffers() { let fixture = TestFixture::new().await; @@ -144,6 +146,7 @@ async fn test_prepare_multiple_buffers() { } } +#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_lookup_tables() { let fixture = TestFixture::new().await; diff --git a/magicblock-committor-service/tests/test_message_executor.rs b/magicblock-committor-service/tests/test_message_executor.rs deleted file mode 100644 index dba97238f..000000000 --- a/magicblock-committor-service/tests/test_message_executor.rs +++ /dev/null @@ -1,4 +0,0 @@ -// solana-test-validator \ -// --bpf-program corabpNrkBEqbTZP7xfJgSWTdBmVdLf1PARWXZbcMcS \ -// ./magicblock-committor-program/bin/magicblock_committor_program.so \ -// diff --git a/magicblock-committor-service/tests/test_transaction_preparator.rs b/magicblock-committor-service/tests/test_transaction_preparator.rs index 804047649..41466b1a6 100644 --- a/magicblock-committor-service/tests/test_transaction_preparator.rs +++ b/magicblock-committor-service/tests/test_transaction_preparator.rs @@ -19,6 +19,7 @@ use crate::common::{create_committed_account, TestFixture}; mod common; +#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_commit_tx_with_single_account() { let fixture = TestFixture::new().await; @@ -53,6 +54,7 @@ async fn test_prepare_commit_tx_with_single_account() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } +#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_commit_tx_with_multiple_accounts() { let fixture = TestFixture::new().await; @@ -105,6 +107,7 @@ async fn test_prepare_commit_tx_with_multiple_accounts() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } +#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_commit_tx_with_l1_actions() { let fixture = TestFixture::new().await; @@ -197,6 +200,7 @@ async fn test_prepare_finalize_tx_with_undelegate() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } +#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_finalize_tx_with_undelegate_and_actions() { let fixture = TestFixture::new().await; @@ -246,6 +250,7 @@ async fn test_prepare_finalize_tx_with_undelegate_and_actions() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } +#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_large_commit_tx_uses_buffers() { let fixture = TestFixture::new().await; diff --git a/magicblock-core/src/magic_program/instruction.rs b/magicblock-core/src/magic_program/instruction.rs index 1ac31482d..d367e8a66 100644 --- a/magicblock-core/src/magic_program/instruction.rs +++ b/magicblock-core/src/magic_program/instruction.rs @@ -73,7 +73,7 @@ pub enum MagicBlockInstruction { // TODO: why that exists? #[allow(unused)] impl MagicBlockInstruction { - pub(crate) fn index(&self) -> u8 { + pub fn index(&self) -> u8 { use MagicBlockInstruction::*; match self { ModifyAccounts(_) => 0, @@ -85,12 +85,12 @@ impl MagicBlockInstruction { } } - pub(crate) fn discriminant(&self) -> [u8; 4] { + pub fn discriminant(&self) -> [u8; 4] { let idx = self.index(); [idx, 0, 0, 0] } - pub(crate) fn try_to_vec(&self) -> Result, bincode::Error> { + pub fn try_to_vec(&self) -> Result, bincode::Error> { bincode::serialize(self) } } @@ -105,21 +105,6 @@ pub struct AccountModification { pub rent_epoch: Option, } -// impl From<(&Pubkey, &)> for AccountModification { -// fn from( -// (account_pubkey, account): (&Pubkey, &Accoun), -// ) -> AccountModification { -// AccountModification { -// pubkey: *account_pubkey, -// lamports: Some(account.lamports), -// owner: Some(account.owner), -// executable: Some(account.executable), -// data: Some(account.data.clone()), -// rent_epoch: Some(account.rent_epoch), -// } -// } -// } - #[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct AccountModificationForInstruction { pub lamports: Option, diff --git a/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs b/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs index 1b9510c0a..92db3ee32 100644 --- a/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs +++ b/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs @@ -23,6 +23,7 @@ pub fn init_account_and_delegate_ixs( ) -> InitAccountAndDelegateIxs { use program_flexi_counter::instruction::*; use program_flexi_counter::state::*; + let init_counter_ix = create_init_ix(payer, "COUNTER".to_string()); let rent_exempt = Rent::default().minimum_balance(bytes as usize); let mut realloc_ixs = vec![]; diff --git a/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs b/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs index b678dba3e..0f34c1b05 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs @@ -1,7 +1,6 @@ use integration_test_tools::run_test; use log::*; -use integration_test_tools::conversions::pubkey_from_magic_program; use magicblock_core::magic_program; use program_schedulecommit::api::schedule_commit_cpi_instruction; use schedulecommit_client::{verify, ScheduleCommitTestContextFields}; @@ -43,8 +42,8 @@ fn test_committing_one_account() { let ix = schedule_commit_cpi_instruction( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &committees .iter() .map(|(player, _)| player.pubkey()) @@ -93,8 +92,8 @@ fn test_committing_two_accounts() { let ix = schedule_commit_cpi_instruction( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &committees .iter() .map(|(player, _)| player.pubkey()) diff --git a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs index bd9f3f8d8..64476a73a 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs @@ -1,6 +1,6 @@ use integration_test_tools::scheduled_commits::extract_scheduled_commit_sent_signature_from_logs; use integration_test_tools::{ - conversions::pubkey_from_magic_program, run_test, + run_test, }; use log::*; use magicblock_core::magic_program; @@ -60,8 +60,8 @@ fn commit_and_undelegate_one_account( let ix = if modify_after { schedule_commit_and_undelegate_cpi_with_mod_after_instruction( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &committees .iter() .map(|(player, _)| player.pubkey()) @@ -71,8 +71,8 @@ fn commit_and_undelegate_one_account( } else { schedule_commit_and_undelegate_cpi_instruction( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &committees .iter() .map(|(player, _)| player.pubkey()) @@ -121,8 +121,8 @@ fn commit_and_undelegate_two_accounts( let ix = if modify_after { schedule_commit_and_undelegate_cpi_with_mod_after_instruction( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &committees .iter() .map(|(player, _)| player.pubkey()) @@ -132,8 +132,8 @@ fn commit_and_undelegate_two_accounts( } else { schedule_commit_and_undelegate_cpi_instruction( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &committees .iter() .map(|(player, _)| player.pubkey()) diff --git a/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs b/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs index 8d606114f..30f41dc6e 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs @@ -5,7 +5,6 @@ use crate::utils::{ assert_feepayer_was_committed, get_context_with_delegated_committees_without_payer_escrow, }; -use integration_test_tools::conversions::pubkey_from_magic_program; use magicblock_core::magic_program; use program_schedulecommit::api::schedule_commit_with_payer_cpi_instruction; use schedulecommit_client::{verify, ScheduleCommitTestContextFields}; @@ -41,8 +40,8 @@ fn test_committing_fee_payer_without_escrowing_lamports() { let ix = schedule_commit_with_payer_cpi_instruction( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &committees .iter() .map(|(player, _)| player.pubkey()) @@ -94,8 +93,8 @@ fn test_committing_fee_payer_escrowing_lamports() { let ix = schedule_commit_with_payer_cpi_instruction( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &committees .iter() .map(|(player, _)| player.pubkey()) diff --git a/test-integration/schedulecommit/test-security/tests/01_invocations.rs b/test-integration/schedulecommit/test-security/tests/01_invocations.rs index e84dee4ae..9e5fb1208 100644 --- a/test-integration/schedulecommit/test-security/tests/01_invocations.rs +++ b/test-integration/schedulecommit/test-security/tests/01_invocations.rs @@ -3,7 +3,6 @@ use crate::utils::{ create_sibling_non_cpi_instruction, create_sibling_schedule_cpis_instruction, }; -use integration_test_tools::conversions::pubkey_from_magic_program; use magicblock_core::magic_program; use program_schedulecommit::api::schedule_commit_cpi_instruction; use schedulecommit_client::{ @@ -82,8 +81,8 @@ fn test_schedule_commit_directly_with_single_ix() { } = ctx.fields(); let ix = create_schedule_commit_ix( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &committees.iter().map(|(_, pda)| *pda).collect::>(), ); @@ -122,8 +121,8 @@ fn test_schedule_commit_directly_mapped_signing_feepayer() { let ix = create_schedule_commit_ix( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &[payer.pubkey()], ); @@ -184,8 +183,8 @@ fn test_schedule_commit_directly_with_commit_ix_sandwiched() { // 2. Schedule commit let ix = create_schedule_commit_ix( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, &committees.iter().map(|(_, pda)| *pda).collect::>(), ); @@ -296,8 +295,8 @@ fn test_schedule_commit_via_direct_and_from_other_program_indirect_cpi_including let cpi_ix = schedule_commit_cpi_instruction( payer.pubkey(), - pubkey_from_magic_program(magic_program::id()), - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY), + magic_program::id(), + magic_program::MAGIC_CONTEXT_PUBKEY, players, pdas, ); diff --git a/test-integration/schedulecommit/test-security/tests/utils/mod.rs b/test-integration/schedulecommit/test-security/tests/utils/mod.rs index ed5992f88..e222a3884 100644 --- a/test-integration/schedulecommit/test-security/tests/utils/mod.rs +++ b/test-integration/schedulecommit/test-security/tests/utils/mod.rs @@ -1,4 +1,3 @@ -use integration_test_tools::conversions::pubkey_from_magic_program; use magicblock_core::magic_program; use program_schedulecommit_security::ScheduleCommitSecurityInstruction; use solana_sdk::{ @@ -14,9 +13,9 @@ pub fn create_sibling_schedule_cpis_instruction( pdas: &[Pubkey], player_pubkeys: &[Pubkey], ) -> Instruction { - let magic_program = pubkey_from_magic_program(magic_program::id()); + let magic_program = magic_program::id(); let magic_context = - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY); + magic_program::MAGIC_CONTEXT_PUBKEY; let mut account_metas = vec![ AccountMeta::new(payer, true), AccountMeta::new(magic_context, false), @@ -48,9 +47,9 @@ pub fn create_nested_schedule_cpis_instruction( pdas: &[Pubkey], player_pubkeys: &[Pubkey], ) -> Instruction { - let magic_program = pubkey_from_magic_program(magic_program::id()); + let magic_program = magic_program::id(); let magic_context = - pubkey_from_magic_program(magic_program::MAGIC_CONTEXT_PUBKEY); + magic_program::MAGIC_CONTEXT_PUBKEY; let mut account_metas = vec![ AccountMeta::new(payer, true), AccountMeta::new(magic_context, false), diff --git a/test-integration/test-tools/src/conversions.rs b/test-integration/test-tools/src/conversions.rs index fc898016a..01e08e785 100644 --- a/test-integration/test-tools/src/conversions.rs +++ b/test-integration/test-tools/src/conversions.rs @@ -2,10 +2,6 @@ use magicblock_core::magic_program; use solana_rpc_client_api::client_error; use solana_sdk::pubkey::Pubkey; -pub fn pubkey_from_magic_program(pubkey: magic_program::Pubkey) -> Pubkey { - Pubkey::from(pubkey.to_bytes()) -} - pub fn get_rpc_transwise_error_msg(err: &anyhow::Error) -> Option { err.source() .and_then(|err| err.downcast_ref::()) From 251b2da6fb044902077961efe19b3491934cd8c2 Mon Sep 17 00:00:00 2001 From: Dodecahedr0x <90185028+Dodecahedr0x@users.noreply.github.com> Date: Mon, 4 Aug 2025 14:10:56 +0200 Subject: [PATCH 157/199] fix: timestamps mismatch (#454) Closes #468 and closes #469 Explorer was showing the transaction timestamp because it uses `getBlockTime`, which was returning an estimate of the slot time based on the slot period and the number of slots between the current slot and the requested slot. This is fixed by returning the timestamp of the block from the ledger. The timestamp written in the ledger was a different system time from the one used for the clock. This is fixed by writing in the ledger the latest value of the clock, which should also fix replay. ## Greptile Summary This PR fixes a critical timestamp synchronization issue across the validator system. The core problem was that different parts of the system were using different sources for timestamps: 1. The explorer was using `getBlockTime` which estimated timestamps based on slot periods 2. The ledger was using raw system time 3. The clock sysvar had its own timestamp The fix ensures all components use the bank's clock timestamp as the single source of truth, specifically: - Modified `magicblock-api/src/slot.rs` to use `bank.clock().unix_timestamp` instead of system time - Updated `magicblock-rpc/src/json_rpc_request_processor.rs` to prioritize actual block timestamps over estimates - Added comprehensive tests in `test_clocks_match.rs` to verify timestamp consistency This change is particularly important for: - Accurate transaction replay - Consistent timestamp reporting between explorer and ledger - Proper clock sysvar behavior ## Confidence score: 4.5/5 1. This PR is safe to merge as it fixes a critical timestamp consistency issue without introducing new risks 2. High confidence due to comprehensive test coverage and the straightforward nature of the fix - using a single source of truth 3. Files needing attention: - `magicblock-api/src/slot.rs`: Verify no edge cases in timestamp handling - `test_clocks_match.rs`: Ensure all critical timestamp scenarios are covered 3 files reviewed, 2 comments [Edit PR Review Bot Settings](https://app.greptile.com/review/github) | [Greptile](https://greptile.com?utm_source=greptile_expert&utm_medium=github&utm_campaign=code_reviews&utm_content=magicblock-validator_454) --- magicblock-api/src/slot.rs | 16 +-- magicblock-bank/src/bank.rs | 4 + .../src/json_rpc_request_processor.rs | 23 ++-- magicblock-table-mania/src/compute_budget.rs | 2 +- test-integration/Cargo.lock | 4 + test-integration/Cargo.toml | 1 + .../configs/validator-api-offline.devnet.toml | 34 ++++++ .../13_timestamps_match_during_replay.rs | 95 ++++++++++++++++ .../test-magicblock-api/Cargo.toml | 15 +-- .../test-magicblock-api/src/lib.rs | 68 ++++++++++++ .../tests/test_clocks_match.rs | 96 +++++++++++++++++ .../tests/test_domain_registry.rs | 102 ++++-------------- .../test_get_block_timestamp_stability.rs | 25 +++++ test-integration/test-runner/bin/run_tests.rs | 29 +++++ 14 files changed, 404 insertions(+), 110 deletions(-) create mode 100644 test-integration/configs/validator-api-offline.devnet.toml create mode 100644 test-integration/test-ledger-restore/tests/13_timestamps_match_during_replay.rs create mode 100644 test-integration/test-magicblock-api/src/lib.rs create mode 100644 test-integration/test-magicblock-api/tests/test_clocks_match.rs create mode 100644 test-integration/test-magicblock-api/tests/test_get_block_timestamp_stability.rs diff --git a/magicblock-api/src/slot.rs b/magicblock-api/src/slot.rs index 032cff53b..fcc6bf9de 100644 --- a/magicblock-api/src/slot.rs +++ b/magicblock-api/src/slot.rs @@ -1,5 +1,3 @@ -use std::time::{SystemTime, UNIX_EPOCH}; - use magicblock_bank::bank::Bank; use magicblock_ledger::{errors::LedgerResult, Ledger}; use solana_sdk::clock::Slot; @@ -22,17 +20,7 @@ pub fn advance_slot_and_update_ledger( let next_slot = bank.advance_slot(); // Update ledger with previous block's metas - let ledger_result = ledger.write_block( - prev_slot, - timestamp_in_secs() as i64, - prev_blockhash, - ); + let ledger_result = + ledger.write_block(prev_slot, bank.slot_timestamp(), prev_blockhash); (ledger_result, next_slot) } - -fn timestamp_in_secs() -> u64 { - let now = SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("create timestamp in timing"); - now.as_secs() -} diff --git a/magicblock-bank/src/bank.rs b/magicblock-bank/src/bank.rs index 71c93697b..27f7d5854 100644 --- a/magicblock-bank/src/bank.rs +++ b/magicblock-bank/src/bank.rs @@ -1033,6 +1033,10 @@ impl Bank { .unwrap_or_default() } + pub fn slot_timestamp(&self) -> UnixTimestamp { + self.clock().unix_timestamp + } + fn update_clock( &self, epoch_start_timestamp: UnixTimestamp, diff --git a/magicblock-rpc/src/json_rpc_request_processor.rs b/magicblock-rpc/src/json_rpc_request_processor.rs index c220559a2..bad4cd99a 100644 --- a/magicblock-rpc/src/json_rpc_request_processor.rs +++ b/magicblock-rpc/src/json_rpc_request_processor.rs @@ -384,15 +384,20 @@ impl JsonRpcRequestProcessor { data: None, }) } else { - // Expressed as Unix time (i.e. seconds since the Unix epoch). - let current_time = self.bank.clock().unix_timestamp; - let slot_diff = current_slot - slot; - let secs_diff = (slot_diff as u128 - * self.config.slot_duration.as_millis()) - / 1_000; - let timestamp = current_time - secs_diff as i64; - - Ok(Some(timestamp)) + // Try to get the time from the block itself + let timestamp = if let Ok(block) = self.ledger.get_block(slot) { + block.and_then(|b| b.block_time) + } else { + // Expressed as Unix time (i.e. seconds since the Unix epoch). + let current_time = self.bank.clock().unix_timestamp; + let slot_diff = current_slot - slot; + let secs_diff = (slot_diff as u128 + * self.config.slot_duration.as_millis()) + / 1_000; + Some(current_time - secs_diff as i64) + }; + + Ok(timestamp) } } diff --git a/magicblock-table-mania/src/compute_budget.rs b/magicblock-table-mania/src/compute_budget.rs index bb4b1f9f8..7ceb5f250 100644 --- a/magicblock-table-mania/src/compute_budget.rs +++ b/magicblock-table-mania/src/compute_budget.rs @@ -8,7 +8,7 @@ use solana_sdk::{ /// This would make table management even slower, but is an option to consider for the future. /// The multiplier is based on the observation that [CREATE_AND_EXTEND_TABLE_CUS] were _safe_ at /// 16K-17K CUs which we slightly exceed if we multiply by this multiplier. -const SAFETY_MULTIPLIER: u32 = 7; +const SAFETY_MULTIPLIER: u32 = 12; /// Compute units required to create and extend a lookup table, with the initial /// pubkeys. This is the same no matter how many pubkeys are added to the table diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index dcca76031..883f9054d 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -10352,13 +10352,17 @@ dependencies = [ name = "test-magicblock-api" version = "0.0.0" dependencies = [ + "cleanass", "integration-test-tools", "isocountry", "lazy_static", "magic-domain-program", "magicblock-api", + "magicblock-config", "solana-rpc-client", + "solana-rpc-client-api", "solana-sdk", + "solana-transaction-status", "tokio", ] diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 98735c4c2..6bb44932c 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -30,6 +30,7 @@ borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "c1fcb91" } integration-test-tools = { path = "test-tools" } +isocountry = "0.3.2" log = "0.4.20" magicblock-api = { path = "../magicblock-api" } magicblock-accounts-db = { path = "../magicblock-accounts-db", features = [ diff --git a/test-integration/configs/validator-api-offline.devnet.toml b/test-integration/configs/validator-api-offline.devnet.toml new file mode 100644 index 000000000..8a43332e6 --- /dev/null +++ b/test-integration/configs/validator-api-offline.devnet.toml @@ -0,0 +1,34 @@ +[accounts] +remote.cluster = "devnet" +lifecycle = "offline" +commit = { frequency_millis = 9_000_000_000_000, compute_unit_price = 1_000_000 } + +[accounts.db] +# size of the main storage, we have to preallocate in advance +# it's advised to set this value based on formula 1KB * N * 3, +# where N is the number of accounts expected to be stored in +# database, e.g. for million accounts this would be 3GB +db-size = 1048576000 # 1GB +# minimal indivisible unit of addressing in main storage +# offsets are calculated in terms of blocks +block-size = "block256" # possible values block128 | block256 | block512 +# size of index file, we have to preallocate, +# can be as low as 1% of main storage size, but setting it to higher values won't hurt +index-map-size = 2048576 +# max number of snapshots to keep around +max-snapshots = 7 +# how frequently (slot-wise) we should take snapshots +snapshot-frequency = 1024 + +[validator] +millis_per_slot = 50 +sigverify = true + +[rpc] +port = 8899 + +[geyser_grpc] +port = 10001 + +[metrics] +enabled = false diff --git a/test-integration/test-ledger-restore/tests/13_timestamps_match_during_replay.rs b/test-integration/test-ledger-restore/tests/13_timestamps_match_during_replay.rs new file mode 100644 index 000000000..df2fcae4b --- /dev/null +++ b/test-integration/test-ledger-restore/tests/13_timestamps_match_during_replay.rs @@ -0,0 +1,95 @@ +use cleanass::assert_eq; +use magicblock_config::{LedgerResumeStrategy, TEST_SNAPSHOT_FREQUENCY}; +use solana_transaction_status::UiTransactionEncoding; +use std::{path::Path, process::Child}; + +use integration_test_tools::{ + expect, tmpdir::resolve_tmp_dir, validator::cleanup, +}; +use solana_sdk::{pubkey::Pubkey, signature::Signature}; +use test_ledger_restore::{ + setup_offline_validator, wait_for_ledger_persist, TMP_DIR_LEDGER, +}; + +// In this test we ensure that the timestamps of the blocks in the restored +// ledger match the timestamps of the blocks in the original ledger. + +#[test] +fn restore_preserves_timestamps() { + let (_, ledger_path) = resolve_tmp_dir(TMP_DIR_LEDGER); + + let pubkey = Pubkey::new_unique(); + + let (mut validator, slot, signature, block_time) = + write(&ledger_path, &pubkey); + validator.kill().unwrap(); + + assert!(slot > TEST_SNAPSHOT_FREQUENCY); + + let mut validator = read(&ledger_path, signature, block_time); + validator.kill().unwrap(); +} + +fn write(ledger_path: &Path, pubkey: &Pubkey) -> (Child, u64, Signature, i64) { + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Reset, + ); + + // First airdrop followed by wait until account is flushed + let signature = expect!(ctx.airdrop_ephem(pubkey, 1_111_111), validator); + + // NOTE: This slows the test down a lot (500 * 50ms = 25s) and will + // be improved once we can configure `FLUSH_ACCOUNTS_SLOT_FREQ` + expect!( + ctx.wait_for_delta_slot_ephem(TEST_SNAPSHOT_FREQUENCY), + validator + ); + + let slot = wait_for_ledger_persist(&mut validator); + + let block_time = expect!( + ctx.try_ephem_client().and_then(|client| { + client + .get_transaction(&signature, UiTransactionEncoding::Base58) + .map_err(|e| anyhow::anyhow!("Get transaction failed: {}", e)) + .and_then(|tx| { + tx.block_time.ok_or(anyhow::anyhow!("No block time")) + }) + }), + validator + ); + + (validator, slot, signature, block_time) +} + +fn read(ledger_path: &Path, signature: Signature, block_time: i64) -> Child { + // Measure time + let _ = std::time::Instant::now(); + let (_, mut validator, ctx) = setup_offline_validator( + ledger_path, + None, + None, + LedgerResumeStrategy::Replay, + ); + eprintln!( + "Validator started in {:?}", + std::time::Instant::now().elapsed() + ); + + let restored_block_time = expect!( + ctx.try_ephem_client().and_then(|client| { + client + .get_transaction(&signature, UiTransactionEncoding::Base58) + .map_err(|e| anyhow::anyhow!("Get transaction failed: {}", e)) + .and_then(|tx| { + tx.block_time.ok_or(anyhow::anyhow!("No block time")) + }) + }), + validator + ); + assert_eq!(restored_block_time, block_time, cleanup(&mut validator)); + validator +} diff --git a/test-integration/test-magicblock-api/Cargo.toml b/test-integration/test-magicblock-api/Cargo.toml index 93e8be418..18ea7cf59 100644 --- a/test-integration/test-magicblock-api/Cargo.toml +++ b/test-integration/test-magicblock-api/Cargo.toml @@ -3,17 +3,18 @@ name = "test-magicblock-api" version.workspace = true edition.workspace = true +[dependencies] +integration-test-tools = { workspace = true } + [dev-dependencies] +cleanass = { workspace = true } magicblock-api = { workspace = true } +magicblock-config = { workspace = true } tokio = { workspace = true } lazy_static = { workspace = true } magic-domain-program = { workspace = true } solana-rpc-client = { workspace = true } +solana-rpc-client-api = { workspace = true } solana-sdk = { workspace = true } -integration-test-tools = { workspace = true } -isocountry = "0.3.2" - -[[test]] -name = "test-domain-registry" -path = "tests/test_domain_registry.rs" -harness = false +solana-transaction-status = { workspace = true } +isocountry = { workspace = true } diff --git a/test-integration/test-magicblock-api/src/lib.rs b/test-integration/test-magicblock-api/src/lib.rs new file mode 100644 index 000000000..623abbea0 --- /dev/null +++ b/test-integration/test-magicblock-api/src/lib.rs @@ -0,0 +1,68 @@ +use std::{path::PathBuf, process::Child}; + +use integration_test_tools::{ + loaded_accounts::LoadedAccounts, + validator::{ + start_magic_block_validator_with_config, + start_test_validator_with_config, TestRunnerPaths, + }, +}; + +pub fn start_devnet_validator_with_config(config_name: &str) -> Child { + let manifest_dir_raw = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let manifest_dir = PathBuf::from(&manifest_dir_raw); + + let config_path = manifest_dir.join("../configs/").join(config_name); + let workspace_dir = manifest_dir.join("../"); + let root_dir = workspace_dir.join("../"); + let test_paths = TestRunnerPaths { + config_path, + root_dir, + workspace_dir, + }; + match start_test_validator_with_config( + &test_paths, + None, + &Default::default(), + "CHAIN", + ) { + Some(validator) => validator, + None => { + panic!("Failed to start ephemeral validator properly"); + } + } +} + +pub fn start_magicblock_validator_with_config( + config_name: &str, + loaded_accounts: &LoadedAccounts, +) -> Child { + let manifest_dir_raw = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let manifest_dir = PathBuf::from(&manifest_dir_raw); + + let config_path = manifest_dir.join("../configs/").join(config_name); + let workspace_dir = manifest_dir.join("../"); + let root_dir = workspace_dir.join("../"); + let test_paths = TestRunnerPaths { + config_path, + root_dir, + workspace_dir, + }; + match start_magic_block_validator_with_config( + &test_paths, + "EPHEM", + loaded_accounts, + true, + ) { + Some(validator) => validator, + None => { + panic!("Failed to start ephemeral validator properly"); + } + } +} + +pub fn cleanup(validator: &mut Child) { + let _ = validator.kill().inspect_err(|e| { + eprintln!("ERR: Failed to kill validator: {:?}", e); + }); +} diff --git a/test-integration/test-magicblock-api/tests/test_clocks_match.rs b/test-integration/test-magicblock-api/tests/test_clocks_match.rs new file mode 100644 index 000000000..0a4dada1f --- /dev/null +++ b/test-integration/test-magicblock-api/tests/test_clocks_match.rs @@ -0,0 +1,96 @@ +use std::time::Duration; + +use solana_rpc_client::nonblocking::rpc_client::RpcClient; +use solana_sdk::{ + native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, signature::Keypair, + signer::Signer, system_instruction, transaction::Transaction, +}; +use solana_transaction_status::UiTransactionEncoding; + +const EPHEM_URL: &str = "http://localhost:8899"; + +/// Test that verifies transaction timestamps, block timestamps, and ledger block timestamps all match +#[tokio::test] +async fn test_clocks_match() { + let iterations = 10; + let millis_per_slot = 50; + + let from_keypair = Keypair::new(); + let to_pubkey = Pubkey::new_unique(); + + let rpc_client = RpcClient::new(EPHEM_URL.to_string()); + rpc_client + .request_airdrop(&from_keypair.pubkey(), LAMPORTS_PER_SOL) + .await + .unwrap(); + + // Test multiple slots to ensure consistency + for _ in 0..iterations { + let blockhash = rpc_client.get_latest_blockhash().await.unwrap(); + let transfer_tx = Transaction::new_signed_with_payer( + &[system_instruction::transfer( + &from_keypair.pubkey(), + &to_pubkey, + 1000000, + )], + Some(&from_keypair.pubkey()), + &[&from_keypair], + blockhash, + ); + + let tx_result = rpc_client + .send_and_confirm_transaction(&transfer_tx) + .await + .unwrap(); + + let mut tx = rpc_client + .get_transaction(&tx_result, UiTransactionEncoding::Base64) + .await + .unwrap(); + // Wait until we're sure the slot is written to the ledger + while rpc_client.get_slot().await.unwrap() < tx.slot + 10 { + tx = rpc_client + .get_transaction(&tx_result, UiTransactionEncoding::Base64) + .await + .unwrap(); + tokio::time::sleep(Duration::from_millis(millis_per_slot)).await; + } + + let ledger_timestamp = + rpc_client.get_block_time(tx.slot).await.unwrap(); + let block_timestamp = rpc_client.get_block(tx.slot).await.unwrap(); + let block_timestamp = block_timestamp.block_time; + + // Verify timestamps match + assert_eq!( + block_timestamp, + Some(ledger_timestamp), + "Timestamps should match for slot {}", + tx.slot, + ); + assert_eq!( + tx.block_time, + Some(ledger_timestamp), + "Timestamps should match for slot {}: {:?} != {:?}", + tx.slot, + tx.block_time, + Some(ledger_timestamp), + ); + + // Also verify that the timestamp is not 0 and not in the future + assert!( + tx.block_time.map(|t| t > 0).unwrap_or(false), + "Timestamp should be positive", + ); + let current_time = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_secs() as i64; + assert!( + tx.block_time.map(|t| t <= current_time).unwrap_or(false), + "Timestamp should be in the past: {:?} > {}", + tx.block_time, + current_time, + ); + } +} diff --git a/test-integration/test-magicblock-api/tests/test_domain_registry.rs b/test-integration/test-magicblock-api/tests/test_domain_registry.rs index 6577f855a..cbc286511 100644 --- a/test-integration/test-magicblock-api/tests/test_domain_registry.rs +++ b/test-integration/test-magicblock-api/tests/test_domain_registry.rs @@ -1,6 +1,3 @@ -use integration_test_tools::validator::{ - start_test_validator_with_config, TestRunnerPaths, -}; use integration_test_tools::IntegrationTestContext; use lazy_static::lazy_static; use magicblock_api::domain_registry_manager::DomainRegistryManager; @@ -10,9 +7,8 @@ use mdp::state::version::v0::RecordV0; use mdp::state::{features::FeaturesSet, record::ErRecord}; use solana_rpc_client::rpc_client::RpcClient; use solana_sdk::commitment_config::CommitmentConfig; +use solana_sdk::native_token::LAMPORTS_PER_SOL; use solana_sdk::signature::{Keypair, Signer}; -use std::path::PathBuf; -use std::process::Child; use std::{ net::{Ipv4Addr, SocketAddrV4}, sync::Arc, @@ -22,22 +18,7 @@ lazy_static! { static ref VALIDATOR_KEYPAIR: Arc = Arc::new(Keypair::new()); } -const DEVNET_URL: &str = "http://127.0.0.1:7799"; - -fn test_registration() { - let validator_info = get_validator_info(); - let domain_manager = DomainRegistryManager::new(DEVNET_URL); - domain_manager - .handle_registration(&VALIDATOR_KEYPAIR, validator_info.clone()) - .expect("Failed to register"); - - let actual = domain_manager - .fetch_validator_info(&validator_info.pda().0) - .expect("Failed to fetch ") - .expect("ValidatorInfo doesn't exist"); - - assert_eq!(actual, validator_info); -} +const DEVNET_URL: &str = "http://localhost:7799"; fn get_validator_info() -> ErRecord { ErRecord::V0(RecordV0 { @@ -54,6 +35,20 @@ fn get_validator_info() -> ErRecord { }) } +fn test_registration() { + let validator_info = get_validator_info(); + let domain_manager = DomainRegistryManager::new(DEVNET_URL); + domain_manager + .handle_registration(&VALIDATOR_KEYPAIR, validator_info.clone()) + .expect("Failed to register"); + + let actual = domain_manager + .fetch_validator_info(&validator_info.pda().0) + .expect("Failed to fetch validator info"); + + assert_eq!(actual, Some(validator_info.clone())); +} + fn test_sync() { let mut validator_info = get_validator_info(); match validator_info { @@ -71,10 +66,9 @@ fn test_sync() { let actual = domain_manager .fetch_validator_info(&validator_info.pda().0) - .expect("Failed to fetch ") - .expect("ValidatorInfo doesn't exist"); + .expect("Failed to fetch validator info"); - assert_eq!(actual, validator_info); + assert_eq!(actual, Some(validator_info.clone())); } fn test_unregister() { @@ -88,54 +82,11 @@ fn test_unregister() { .fetch_validator_info(&pda) .expect("Failed to fetch validator info"); - assert!(actual.is_none()) + assert!(actual.is_none()); } -struct TestValidator { - process: Child, -} - -impl TestValidator { - fn start() -> Self { - let manifest_dir_raw = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let manifest_dir = PathBuf::from(&manifest_dir_raw); - - let config_path = - manifest_dir.join("../configs/schedulecommit-conf.devnet.toml"); - let workspace_dir = manifest_dir.join("../"); - let root_dir = workspace_dir.join("../"); - - let paths = TestRunnerPaths { - config_path, - root_dir, - workspace_dir, - }; - let process = start_test_validator_with_config( - &paths, - None, - &Default::default(), - "CHAIN", - ) - .expect("Failed to start devnet process"); - - Self { process } - } -} - -impl Drop for TestValidator { - fn drop(&mut self) { - self.process - .kill() - .expect("Failed to stop solana-test-validator"); - self.process - .wait() - .expect("Failed to wait for solana-test-validator"); - } -} - -fn main() { - let _devnet = TestValidator::start(); - +#[test] +fn test_domain_registry() { let client = RpcClient::new_with_commitment( DEVNET_URL, CommitmentConfig::confirmed(), @@ -143,19 +94,12 @@ fn main() { IntegrationTestContext::airdrop( &client, &VALIDATOR_KEYPAIR.pubkey(), - 5000000000, + LAMPORTS_PER_SOL, CommitmentConfig::confirmed(), ) - .expect("Failed to airdrop"); + .expect("Airdrop failed"); - println!("Testing validator info registration..."); test_registration(); - - println!("Testing validator info sync..."); test_sync(); - - println!("Testing validator info unregistration..."); test_unregister(); - - println!("Passed") } diff --git a/test-integration/test-magicblock-api/tests/test_get_block_timestamp_stability.rs b/test-integration/test-magicblock-api/tests/test_get_block_timestamp_stability.rs new file mode 100644 index 000000000..efa589252 --- /dev/null +++ b/test-integration/test-magicblock-api/tests/test_get_block_timestamp_stability.rs @@ -0,0 +1,25 @@ +use std::time::Duration; + +use solana_rpc_client::nonblocking::rpc_client::RpcClient; + +const EPHEM_URL: &str = "http://localhost:8899"; + +#[tokio::test] +async fn test_get_block_timestamp_stability() { + let millis_per_slot = 50; + + // Wait for a few slots to pass + let skipped_slots = 10; + tokio::time::sleep(Duration::from_millis( + 100 + millis_per_slot * skipped_slots, // 100ms to start the validator + )) + .await; + + let rpc_client = RpcClient::new(EPHEM_URL.to_string()); + + let current_slot = rpc_client.get_slot().await.unwrap(); + let block_time = rpc_client.get_block_time(current_slot - 1).await.unwrap(); + let ledger_block = rpc_client.get_block(current_slot - 1).await.unwrap(); + + assert_eq!(ledger_block.block_time, Some(block_time)); +} diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index 95763ce46..68ac1be0f 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -399,14 +399,43 @@ fn run_magicblock_api_tests( if !should_run_test("magicblock_api") { return Ok(success_output()); } + + eprintln!("======== RUNNING MAGICBLOCK API TESTS ========"); + + let mut devnet_validator = match start_validator( + "schedulecommit-conf.devnet.toml", + ValidatorCluster::Chain(None), + &LoadedAccounts::default(), + ) { + Some(validator) => validator, + None => { + panic!("Failed to start devnet validator properly"); + } + }; + let mut ephem_validator = match start_validator( + "validator-api-offline.devnet.toml", + ValidatorCluster::Ephem, + &LoadedAccounts::with_delegation_program_test_authority(), + ) { + Some(validator) => validator, + None => { + devnet_validator + .kill() + .expect("Failed to kill devnet validator"); + panic!("Failed to start ephemeral validator properly"); + } + }; + let test_dir = format!("{}/../{}", manifest_dir, "test-magicblock-api"); eprintln!("Running magicblock-api tests in {}", test_dir); let output = run_test(test_dir, Default::default()).map_err(|err| { eprintln!("Failed to magicblock api tests: {:?}", err); + cleanup_validators(&mut ephem_validator, &mut devnet_validator); err })?; + cleanup_validators(&mut ephem_validator, &mut devnet_validator); Ok(output) } From dca74ee4cc8187458d92fc0faf711e5fad135c5d Mon Sep 17 00:00:00 2001 From: Dodecahedr0x <90185028+Dodecahedr0x@users.noreply.github.com> Date: Mon, 4 Aug 2025 18:35:40 +0200 Subject: [PATCH 158/199] feat(ledger): remove requirement to use the same keypair during replay (#458) Closes #299 Add a parameter in the configuration to disable verification of the validator's pubkey during replay, enabling anyone to replay the ledger ## Snippets TOML ```toml [ledger] skip-keypair-match-check = false # Defaults to true ``` CLI ```bash cargo run -- --ledger-skip-keypair-match-check LEDGER_SKIP_KEYPAIR_MATCH_CHECK=FALSE cargo run ``` --- magicblock-api/src/magic_validator.rs | 13 +- magicblock-config/src/ledger.rs | 16 +++ magicblock-config/src/lib.rs | 4 + magicblock-config/tests/read_config.rs | 8 +- .../configs/restore-ledger-conf.devnet.toml | 4 + test-integration/programs/memo/memo.so | Bin 0 -> 74800 bytes .../test-ledger-restore/src/lib.rs | 11 +- .../tests/00_empty_validator.rs | 22 ++- .../tests/01_single_airdrop.rs | 2 + .../tests/02_two_airdrops.rs | 3 + .../tests/03_single_block_tx_order.rs | 2 + .../tests/04_flexi-counter.rs | 2 + .../tests/05_program_deploy.rs | 4 +- .../tests/06_delegated_account.rs | 19 ++- .../tests/07_commit_delegated_account.rs | 19 ++- .../tests/08_commit_update.rs | 19 ++- ...store_different_accounts_multiple_times.rs | 19 ++- .../tests/10_readonly_update_after.rs | 19 ++- .../tests/11_undelegate_before_restart.rs | 28 +++- ...12_two_airdrops_one_after_account_flush.rs | 2 + .../13_timestamps_match_during_replay.rs | 2 + .../tests/14_restore_with_new_keypair.rs | 131 ++++++++++++++++++ .../tests/15_skip_replay.rs | 2 + .../test-tools/src/loaded_accounts.rs | 9 ++ 24 files changed, 315 insertions(+), 45 deletions(-) create mode 100644 test-integration/programs/memo/memo.so create mode 100644 test-integration/test-ledger-restore/tests/14_restore_with_new_keypair.rs diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index e658d90f7..1a2cab707 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -198,11 +198,14 @@ impl MagicValidator { let (ledger, last_slot) = Self::init_ledger(&config.validator_config.ledger)?; - Self::sync_validator_keypair_with_ledger( - ledger.ledger_path(), - &identity_keypair, - &config.validator_config.ledger.resume_strategy, - )?; + + if !config.validator_config.ledger.skip_keypair_match_check { + Self::sync_validator_keypair_with_ledger( + ledger.ledger_path(), + &identity_keypair, + &config.validator_config.ledger.resume_strategy, + )?; + } // SAFETY: // this code will never panic as the ledger_path always appends the diff --git a/magicblock-config/src/ledger.rs b/magicblock-config/src/ledger.rs index bd9cf9405..4698febbc 100644 --- a/magicblock-config/src/ledger.rs +++ b/magicblock-config/src/ledger.rs @@ -20,6 +20,13 @@ pub struct LedgerConfig { #[derive_env_var] #[serde(default)] pub resume_strategy: LedgerResumeStrategy, + /// Checks that the validator keypair matches the one in the ledger. + #[derive_env_var] + #[arg( + help = "Whether to check that the validator keypair matches the one in the ledger." + )] + #[serde(default)] + pub skip_keypair_match_check: bool, /// The file system path onto which the ledger should be written at /// If left empty it will be auto-generated to a temporary folder #[derive_env_var] @@ -40,6 +47,7 @@ impl Default for LedgerConfig { fn default() -> Self { Self { resume_strategy: LedgerResumeStrategy::default(), + skip_keypair_match_check: false, path: Default::default(), size: DEFAULT_LEDGER_SIZE_BYTES, } @@ -96,6 +104,7 @@ mod tests { fn test_merge_with_default() { let mut config = LedgerConfig { resume_strategy: LedgerResumeStrategy::Replay, + skip_keypair_match_check: true, path: Some("ledger.example.com".to_string()), size: 1000000000, }; @@ -112,6 +121,7 @@ mod tests { let mut config = LedgerConfig::default(); let other = LedgerConfig { resume_strategy: LedgerResumeStrategy::Replay, + skip_keypair_match_check: true, path: Some("ledger.example.com".to_string()), size: 1000000000, }; @@ -125,12 +135,14 @@ mod tests { fn test_merge_non_default() { let mut config = LedgerConfig { resume_strategy: LedgerResumeStrategy::Replay, + skip_keypair_match_check: true, path: Some("ledger.example.com".to_string()), size: 1000000000, }; let original_config = config.clone(); let other = LedgerConfig { resume_strategy: LedgerResumeStrategy::ResumeOnly, + skip_keypair_match_check: true, path: Some("ledger2.example.com".to_string()), size: 10000, }; @@ -145,6 +157,7 @@ mod tests { let toml_str = r#" [ledger] resume-strategy = "replay" +skip-keypair-match-check = true path = "ledger.example.com" size = 1000000000 "#; @@ -154,6 +167,7 @@ size = 1000000000 config.ledger, LedgerConfig { resume_strategy: LedgerResumeStrategy::Replay, + skip_keypair_match_check: true, path: Some("ledger.example.com".to_string()), size: 1000000000, } @@ -170,6 +184,7 @@ size = 1000000000 config.ledger, LedgerConfig { resume_strategy: LedgerResumeStrategy::ResumeOnly, + skip_keypair_match_check: false, path: None, size: 1000000000, } @@ -186,6 +201,7 @@ size = 1000000000 config.ledger, LedgerConfig { resume_strategy: LedgerResumeStrategy::Reset, + skip_keypair_match_check: false, path: None, size: 1000000000, } diff --git a/magicblock-config/src/lib.rs b/magicblock-config/src/lib.rs index bd23c7472..7d58d3e7e 100644 --- a/magicblock-config/src/lib.rs +++ b/magicblock-config/src/lib.rs @@ -243,6 +243,7 @@ mod tests { }, ledger: LedgerConfig { resume_strategy: LedgerResumeStrategy::Replay, + skip_keypair_match_check: true, path: Some("ledger.example.com".to_string()), size: 1000000000, }, @@ -322,6 +323,7 @@ mod tests { }, ledger: LedgerConfig { resume_strategy: LedgerResumeStrategy::Replay, + skip_keypair_match_check: true, path: Some("ledger.example.com".to_string()), size: 1000000000, }, @@ -398,6 +400,7 @@ mod tests { }, ledger: LedgerConfig { resume_strategy: LedgerResumeStrategy::ResumeOnly, + skip_keypair_match_check: true, path: Some("ledger2.example.com".to_string()), size: 100000, }, @@ -467,6 +470,7 @@ mod tests { }, ledger: LedgerConfig { resume_strategy: LedgerResumeStrategy::Replay, + skip_keypair_match_check: true, path: Some("ledger.example.com".to_string()), size: 1000000000, }, diff --git a/magicblock-config/tests/read_config.rs b/magicblock-config/tests/read_config.rs index bec462d47..789aed13b 100644 --- a/magicblock-config/tests/read_config.rs +++ b/magicblock-config/tests/read_config.rs @@ -116,14 +116,13 @@ fn test_load_local_dev_with_programs_toml_envs_override() { env::set_var("VALIDATOR_MILLIS_PER_SLOT", "100"); env::set_var("VALIDATOR_COUNTRY_CODE", "CY"); env::set_var("VALIDATOR_FQDN", "magicblock.er.com"); - env::set_var("LEDGER_RESET", "false"); - env::set_var("LEDGER_SKIP_REPLAY", "true"); + env::set_var("LEDGER_SIZE", "123123"); + env::set_var("LEDGER_RESUME_STRATEGY", "resume-only"); + env::set_var("LEDGER_SKIP_KEYPAIR_MATCH_CHECK", "true"); env::set_var("LEDGER_PATH", "/hello/world"); env::set_var("METRICS_ENABLED", "false"); env::set_var("METRICS_PORT", "1234"); env::set_var("METRICS_SYSTEM_METRICS_TICK_INTERVAL_SECS", "10"); - env::set_var("LEDGER_SIZE", "123123"); - env::set_var("LEDGER_RESUME_STRATEGY", "resume-only"); let config = parse_config_with_file(&config_file_dir); @@ -167,6 +166,7 @@ fn test_load_local_dev_with_programs_toml_envs_override() { }, ledger: LedgerConfig { resume_strategy: LedgerResumeStrategy::ResumeOnly, + skip_keypair_match_check: true, path: Some("/hello/world".to_string()), size: 123123 }, diff --git a/test-integration/configs/restore-ledger-conf.devnet.toml b/test-integration/configs/restore-ledger-conf.devnet.toml index acf726463..c37399453 100644 --- a/test-integration/configs/restore-ledger-conf.devnet.toml +++ b/test-integration/configs/restore-ledger-conf.devnet.toml @@ -36,6 +36,10 @@ path = "../target/deploy/program_flexi_counter.so" id = "DmnRGfyyftzacFb1XadYhWF6vWqXwtQk5tbr6XgR3BA1" path = "../schedulecommit/elfs/mdp.so" +[[program]] +id = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" +path = "../programs/memo/memo.so" + [rpc] port = 7799 diff --git a/test-integration/programs/memo/memo.so b/test-integration/programs/memo/memo.so new file mode 100644 index 0000000000000000000000000000000000000000..88385a01dec7b2f375cc33959fc8ee06e6eef409 GIT binary patch literal 74800 zcmeFa31D1TbvORBj3p~}Bs(745m7XXH${nJ$*ZiyL|N=8Az+0tu@hpfv8>omVq2SI zKR+NNXLCXUCD33@DUzMo3be(1e8p~|jQCR;Qz(d*#S|zi%ZF)M#8%7}{m<_#Z|*!v zi4#)#wg3OMHFwUv=bn4+x#ymH?(*K;zvkw(`FVMsg#z!F9-xy`C8bF->Z-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b-vwYhNX>vG}5ZMksqrd)Vf*JnomOjmAxpRRW-|KNSO`GarDg-6w2H2j8iZvFxF zk1T&k{U3vi)!#9=IRc+KkV~&l{hJU!0-yS$T>LWKJ2w0}^#=?detRzd@yB!FgS01& zVEEf~zA?C2=NE&wMd0DT&n@5lxd^QG*2?#(ef@tsyLO$1VJK=LDitBrd;mj+BC%k> z#N3sMKLA$*GBk~p28sRwpU{C1V&oe@LLHfzdQW^#NTN=+8d%_a}Wh>GXH#(~gX--4P>naV3v?z=tO94ZhCoGqZnKFYV`8 zhM^9=$`-yVU4y2G+I8Xl)AHHpVU;_d<#&%&D6&Qu3fqkKtK2NqVQ#z zf^YG4{!MsJz5q75;lc#_JL^(>ore=nSy<0k{$=CT5*Qld>wKS3=lh0y-M=g2Vr+=7 g^LN5a(;>, millis_per_slot: Option, resume_strategy: LedgerResumeStrategy, + skip_keypair_match_check: bool, ) -> (TempDir, Child, IntegrationTestContext) { let mut accounts_config = AccountsConfig { lifecycle: LifecycleMode::Offline, @@ -57,8 +58,10 @@ pub fn setup_offline_validator( let config = EphemeralConfig { ledger: LedgerConfig { resume_strategy, + skip_keypair_match_check, path: Some(ledger_path.display().to_string()), size: DEFAULT_LEDGER_SIZE_BYTES, + ..Default::default() }, accounts: accounts_config.clone(), programs, @@ -86,6 +89,8 @@ pub fn setup_validator_with_local_remote( ledger_path: &Path, programs: Option>, reset: bool, + skip_keypair_match_check: bool, + loaded_accounts: &LoadedAccounts, ) -> (TempDir, Child, IntegrationTestContext) { let mut accounts_config = AccountsConfig { lifecycle: LifecycleMode::Ephemeral, @@ -108,6 +113,7 @@ pub fn setup_validator_with_local_remote( let config = EphemeralConfig { ledger: LedgerConfig { resume_strategy, + skip_keypair_match_check, path: Some(ledger_path.display().to_string()), size: DEFAULT_LEDGER_SIZE_BYTES, ..Default::default() @@ -118,10 +124,7 @@ pub fn setup_validator_with_local_remote( }; let (default_tmpdir_config, Some(mut validator)) = - start_magicblock_validator_with_config_struct( - config, - &LoadedAccounts::with_delegation_program_test_authority(), - ) + start_magicblock_validator_with_config_struct(config, &loaded_accounts) else { panic!("validator should set up correctly"); }; diff --git a/test-integration/test-ledger-restore/tests/00_empty_validator.rs b/test-integration/test-ledger-restore/tests/00_empty_validator.rs index 93969fd70..6075aa2f1 100644 --- a/test-integration/test-ledger-restore/tests/00_empty_validator.rs +++ b/test-integration/test-ledger-restore/tests/00_empty_validator.rs @@ -1,6 +1,8 @@ use std::{path::Path, process::Child}; -use integration_test_tools::tmpdir::resolve_tmp_dir; +use integration_test_tools::{ + loaded_accounts::LoadedAccounts, tmpdir::resolve_tmp_dir, +}; use test_ledger_restore::{ setup_validator_with_local_remote, wait_for_ledger_persist, TMP_DIR_LEDGER, }; @@ -22,8 +24,13 @@ fn restore_ledger_empty_validator() { fn write(ledger_path: &Path) -> (Child, u64) { // Launch a validator and airdrop to an account - let (_, mut validator, _) = - setup_validator_with_local_remote(ledger_path, None, true); + let (_, mut validator, _) = setup_validator_with_local_remote( + ledger_path, + None, + true, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); let slot = wait_for_ledger_persist(&mut validator); @@ -33,8 +40,13 @@ fn write(ledger_path: &Path) -> (Child, u64) { fn read(ledger_path: &Path) -> Child { // Launch another validator reusing ledger - let (_, validator, _) = - setup_validator_with_local_remote(ledger_path, None, false); + let (_, validator, _) = setup_validator_with_local_remote( + ledger_path, + None, + false, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); validator } diff --git a/test-integration/test-ledger-restore/tests/01_single_airdrop.rs b/test-integration/test-ledger-restore/tests/01_single_airdrop.rs index 81084c2d6..0d057cf75 100644 --- a/test-integration/test-ledger-restore/tests/01_single_airdrop.rs +++ b/test-integration/test-ledger-restore/tests/01_single_airdrop.rs @@ -35,6 +35,7 @@ fn write_ledger( None, None, LedgerResumeStrategy::Reset, + false, ); let sig = expect!(ctx.airdrop_ephem(pubkey1, 1_111_111), validator); @@ -59,6 +60,7 @@ fn read_ledger( None, None, LedgerResumeStrategy::Replay, + false, ); let acc = expect!( diff --git a/test-integration/test-ledger-restore/tests/02_two_airdrops.rs b/test-integration/test-ledger-restore/tests/02_two_airdrops.rs index 199f7e051..eab01ae75 100644 --- a/test-integration/test-ledger-restore/tests/02_two_airdrops.rs +++ b/test-integration/test-ledger-restore/tests/02_two_airdrops.rs @@ -65,6 +65,7 @@ fn write( None, None, LedgerResumeStrategy::Reset, + false, ); let mut slot = 5; @@ -102,6 +103,7 @@ fn read( None, None, LedgerResumeStrategy::Replay, + false, ); let ephem_client = expect!(ctx.try_ephem_client(), validator); @@ -183,5 +185,6 @@ fn _diagnose_read() { None, None, LedgerResumeStrategy::Replay, + false, ); } diff --git a/test-integration/test-ledger-restore/tests/03_single_block_tx_order.rs b/test-integration/test-ledger-restore/tests/03_single_block_tx_order.rs index 305fcc3fb..18b93a484 100644 --- a/test-integration/test-ledger-restore/tests/03_single_block_tx_order.rs +++ b/test-integration/test-ledger-restore/tests/03_single_block_tx_order.rs @@ -83,6 +83,7 @@ fn write( None, Some(SLOT_MS), LedgerResumeStrategy::Reset, + false, ); let mut slot = 1; @@ -161,6 +162,7 @@ fn read(ledger_path: &Path, keypairs: &[Keypair]) -> Child { None, Some(SLOT_MS), LedgerResumeStrategy::Replay, + false, ); for keypair in keypairs { diff --git a/test-integration/test-ledger-restore/tests/04_flexi-counter.rs b/test-integration/test-ledger-restore/tests/04_flexi-counter.rs index 6eb998ace..a3c38cd2b 100644 --- a/test-integration/test-ledger-restore/tests/04_flexi-counter.rs +++ b/test-integration/test-ledger-restore/tests/04_flexi-counter.rs @@ -86,6 +86,7 @@ fn write( Some(programs), Some(SLOT_MS), LedgerResumeStrategy::Reset, + false, ); expect!(ctx.wait_for_slot_ephem(1), validator); @@ -241,6 +242,7 @@ fn read(ledger_path: &Path, payer1: &Pubkey, payer2: &Pubkey) -> Child { Some(programs), Some(SLOT_MS), LedgerResumeStrategy::Replay, + false, ); let counter1_decoded = fetch_counter_ephem(payer1, &mut validator); diff --git a/test-integration/test-ledger-restore/tests/05_program_deploy.rs b/test-integration/test-ledger-restore/tests/05_program_deploy.rs index c9961cde3..69a74e9a8 100644 --- a/test-integration/test-ledger-restore/tests/05_program_deploy.rs +++ b/test-integration/test-ledger-restore/tests/05_program_deploy.rs @@ -68,6 +68,7 @@ fn write( None, None, LedgerResumeStrategy::Reset, + false, ); expect!(ctx.wait_for_slot_ephem(1), validator); @@ -129,7 +130,8 @@ fn read(ledger_path: &Path, payer: &Pubkey) -> Child { ledger_path, None, None, - LedgerResumeStrategy::Replay, + LedgerResumeStrategy::Reset, + false, ); let counter_decoded = fetch_counter_ephem(payer, &mut validator); diff --git a/test-integration/test-ledger-restore/tests/06_delegated_account.rs b/test-integration/test-ledger-restore/tests/06_delegated_account.rs index 292973001..45e7259ba 100644 --- a/test-integration/test-ledger-restore/tests/06_delegated_account.rs +++ b/test-integration/test-ledger-restore/tests/06_delegated_account.rs @@ -1,4 +1,5 @@ use cleanass::assert_eq; +use integration_test_tools::loaded_accounts::LoadedAccounts; use integration_test_tools::validator::cleanup; use std::{path::Path, process::Child}; @@ -50,8 +51,13 @@ fn write(ledger_path: &Path, payer: &Keypair) -> (Child, u64) { // NOTE: in this test we preload the counter program in the ephemeral instead // of relying on it being cloned from the remote - let (_, mut validator, ctx) = - setup_validator_with_local_remote(ledger_path, Some(programs), true); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + true, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); // Airdrop to payer on chain expect!( @@ -105,8 +111,13 @@ fn write(ledger_path: &Path, payer: &Keypair) -> (Child, u64) { fn read(ledger_path: &Path, payer: &Pubkey) -> Child { let programs = get_programs(); - let (_, mut validator, _) = - setup_validator_with_local_remote(ledger_path, Some(programs), false); + let (_, mut validator, _) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + false, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); wait_for_cloned_accounts_hydration(); diff --git a/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs b/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs index cbcb0edd7..ee155da4b 100644 --- a/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs +++ b/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs @@ -1,4 +1,5 @@ use cleanass::assert_eq; +use integration_test_tools::loaded_accounts::LoadedAccounts; use integration_test_tools::validator::cleanup; use std::{path::Path, process::Child}; @@ -47,8 +48,13 @@ fn restore_ledger_containing_delegated_and_committed_account() { fn write(ledger_path: &Path, payer: &Keypair) -> (Child, u64) { let programs = get_programs_with_flexi_counter(); - let (_, mut validator, ctx) = - setup_validator_with_local_remote(ledger_path, Some(programs), true); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + true, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); // Airdrop to payer on chain expect!( @@ -168,8 +174,13 @@ fn write(ledger_path: &Path, payer: &Keypair) -> (Child, u64) { fn read(ledger_path: &Path, payer: &Pubkey) -> Child { let programs = get_programs_with_flexi_counter(); - let (_, mut validator, ctx) = - setup_validator_with_local_remote(ledger_path, Some(programs), false); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + false, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); wait_for_cloned_accounts_hydration(); diff --git a/test-integration/test-ledger-restore/tests/08_commit_update.rs b/test-integration/test-ledger-restore/tests/08_commit_update.rs index 9f90c9fad..d91da7343 100644 --- a/test-integration/test-ledger-restore/tests/08_commit_update.rs +++ b/test-integration/test-ledger-restore/tests/08_commit_update.rs @@ -1,4 +1,5 @@ use cleanass::assert_eq; +use integration_test_tools::loaded_accounts::LoadedAccounts; use integration_test_tools::validator::cleanup; use std::{path::Path, process::Child}; @@ -50,8 +51,13 @@ fn restore_ledger_committed_and_updated_account() { fn write(ledger_path: &Path, payer: &Keypair) -> (Child, u64) { let programs = get_programs_with_flexi_counter(); - let (_, mut validator, ctx) = - setup_validator_with_local_remote(ledger_path, Some(programs), true); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + true, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); // Airdrop to payer on chain expect!( @@ -159,8 +165,13 @@ fn read(ledger_path: &Path, payer_kp: &Keypair) -> Child { let payer = &payer_kp.pubkey(); let programs = get_programs_with_flexi_counter(); - let (_, mut validator, ctx) = - setup_validator_with_local_remote(ledger_path, Some(programs), false); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + false, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); wait_for_cloned_accounts_hydration(); diff --git a/test-integration/test-ledger-restore/tests/09_restore_different_accounts_multiple_times.rs b/test-integration/test-ledger-restore/tests/09_restore_different_accounts_multiple_times.rs index f77f25e3f..fbf6e47fc 100644 --- a/test-integration/test-ledger-restore/tests/09_restore_different_accounts_multiple_times.rs +++ b/test-integration/test-ledger-restore/tests/09_restore_different_accounts_multiple_times.rs @@ -1,4 +1,5 @@ use cleanass::assert_eq; +use integration_test_tools::loaded_accounts::LoadedAccounts; use integration_test_tools::validator::cleanup; use std::{path::Path, process::Child}; @@ -64,8 +65,13 @@ fn write( ) -> (Child, u64, u64) { let programs = get_programs_with_flexi_counter(); - let (_, mut validator, ctx) = - setup_validator_with_local_remote(ledger_path, Some(programs), true); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + true, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); // Airdrop to payers on chain expect!( @@ -170,8 +176,13 @@ fn read( let payer_readonly = &payer_readonly_kp.pubkey(); let programs = get_programs_with_flexi_counter(); - let (_, mut validator, ctx) = - setup_validator_with_local_remote(ledger_path, Some(programs), false); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + false, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); wait_for_cloned_accounts_hydration(); diff --git a/test-integration/test-ledger-restore/tests/10_readonly_update_after.rs b/test-integration/test-ledger-restore/tests/10_readonly_update_after.rs index 7575d9e63..4a8220c8f 100644 --- a/test-integration/test-ledger-restore/tests/10_readonly_update_after.rs +++ b/test-integration/test-ledger-restore/tests/10_readonly_update_after.rs @@ -1,4 +1,5 @@ use cleanass::assert_eq; +use integration_test_tools::loaded_accounts::LoadedAccounts; use std::{path::Path, process::Child}; use integration_test_tools::{ @@ -144,8 +145,13 @@ fn write( ) -> (Child, u64) { let programs = get_programs_with_flexi_counter(); - let (_, mut validator, ctx) = - setup_validator_with_local_remote(ledger_path, Some(programs), true); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + true, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); // Airdrop to payers on chain expect!( @@ -263,8 +269,13 @@ fn read( let payer_readonly = &payer_readonly_kp.pubkey(); let programs = get_programs_with_flexi_counter(); - let (_, mut validator, _) = - setup_validator_with_local_remote(ledger_path, Some(programs), false); + let (_, mut validator, _) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + false, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); wait_for_cloned_accounts_hydration(); diff --git a/test-integration/test-ledger-restore/tests/11_undelegate_before_restart.rs b/test-integration/test-ledger-restore/tests/11_undelegate_before_restart.rs index 877175e8a..d254dc0ad 100644 --- a/test-integration/test-ledger-restore/tests/11_undelegate_before_restart.rs +++ b/test-integration/test-ledger-restore/tests/11_undelegate_before_restart.rs @@ -1,5 +1,6 @@ use cleanass::assert; use integration_test_tools::conversions::get_rpc_transwise_error_msg; +use integration_test_tools::loaded_accounts::LoadedAccounts; use integration_test_tools::validator::cleanup; use integration_test_tools::{expect, tmpdir::resolve_tmp_dir}; use integration_test_tools::{expect_err, unwrap, IntegrationTestContext}; @@ -59,8 +60,13 @@ fn restore_ledger_with_account_undelegated_before_restart() { fn write(ledger_path: &Path, payer: &Keypair) -> (Child, u64) { let programs = get_programs_with_flexi_counter(); - let (_, mut validator, ctx) = - setup_validator_with_local_remote(ledger_path, Some(programs), true); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + true, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); // Airdrop to payer on chain expect!( @@ -113,8 +119,13 @@ fn update_counter_between_restarts(payer: &Keypair) -> Child { // before restarting the validator let (_, ledger_path) = resolve_tmp_dir("FORCE_UNIQUE_TMP_DIR_AND_IGNORE_THIS_ENV_VAR"); - let (_, mut validator, ctx) = - setup_validator_with_local_remote(&ledger_path, None, true); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + &ledger_path, + None, + true, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); let ix = create_add_and_schedule_commit_ix(payer.pubkey(), 3, true); let sig = confirm_tx_with_payer_ephem(ix, payer, &mut validator); @@ -149,8 +160,13 @@ fn update_counter_between_restarts(payer: &Keypair) -> Child { fn read(ledger_path: &Path, payer: &Keypair) -> Child { let programs = get_programs_with_flexi_counter(); - let (_, mut validator, _) = - setup_validator_with_local_remote(ledger_path, Some(programs), false); + let (_, mut validator, _) = setup_validator_with_local_remote( + ledger_path, + Some(programs), + false, + false, + &LoadedAccounts::with_delegation_program_test_authority(), + ); let ix = create_add_ix(payer.pubkey(), 1); let ctx = expect!(IntegrationTestContext::try_new_ephem_only(), validator); diff --git a/test-integration/test-ledger-restore/tests/12_two_airdrops_one_after_account_flush.rs b/test-integration/test-ledger-restore/tests/12_two_airdrops_one_after_account_flush.rs index f354fdccc..ff99a36b3 100644 --- a/test-integration/test-ledger-restore/tests/12_two_airdrops_one_after_account_flush.rs +++ b/test-integration/test-ledger-restore/tests/12_two_airdrops_one_after_account_flush.rs @@ -39,6 +39,7 @@ fn write(ledger_path: &Path, pubkey: &Pubkey) -> (Child, u64) { None, None, LedgerResumeStrategy::Reset, + false, ); // First airdrop followed by wait until account is flushed @@ -75,6 +76,7 @@ fn read(ledger_path: &Path, pubkey: &Pubkey) -> Child { None, None, LedgerResumeStrategy::Replay, + false, ); eprintln!( "Validator started in {:?}", diff --git a/test-integration/test-ledger-restore/tests/13_timestamps_match_during_replay.rs b/test-integration/test-ledger-restore/tests/13_timestamps_match_during_replay.rs index df2fcae4b..fa927996c 100644 --- a/test-integration/test-ledger-restore/tests/13_timestamps_match_during_replay.rs +++ b/test-integration/test-ledger-restore/tests/13_timestamps_match_during_replay.rs @@ -36,6 +36,7 @@ fn write(ledger_path: &Path, pubkey: &Pubkey) -> (Child, u64, Signature, i64) { None, None, LedgerResumeStrategy::Reset, + false, ); // First airdrop followed by wait until account is flushed @@ -73,6 +74,7 @@ fn read(ledger_path: &Path, signature: Signature, block_time: i64) -> Child { None, None, LedgerResumeStrategy::Replay, + false, ); eprintln!( "Validator started in {:?}", diff --git a/test-integration/test-ledger-restore/tests/14_restore_with_new_keypair.rs b/test-integration/test-ledger-restore/tests/14_restore_with_new_keypair.rs new file mode 100644 index 000000000..ecea74751 --- /dev/null +++ b/test-integration/test-ledger-restore/tests/14_restore_with_new_keypair.rs @@ -0,0 +1,131 @@ +use cleanass::assert_eq; +use solana_rpc_client::rpc_client::RpcClient; +use std::{path::Path, process::Child}; + +use integration_test_tools::{ + expect, loaded_accounts::LoadedAccounts, tmpdir::resolve_tmp_dir, + validator::cleanup, +}; +use solana_sdk::{ + account::Account, bpf_loader_upgradeable, instruction::Instruction, + native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, signature::Keypair, + signer::Signer, transaction::Transaction, +}; +use test_ledger_restore::{ + setup_validator_with_local_remote, wait_for_ledger_persist, TMP_DIR_LEDGER, +}; + +const MEMO_PROGRAM_PK: Pubkey = Pubkey::new_from_array([ + 5, 74, 83, 90, 153, 41, 33, 6, 77, 36, 232, 113, 96, 218, 56, 124, 124, 53, + 181, 221, 188, 146, 187, 129, 228, 31, 168, 64, 65, 5, 68, 141, +]); + +// In this test we ensure that restoring from a ledger with a new validator +// authority works. +// This assumes a solana-test-validator is running on port 7799. + +#[test] +fn restore_ledger_with_new_validator_authority() { + let (_, ledger_path) = resolve_tmp_dir(TMP_DIR_LEDGER); + + // Write a transaction that clones the memo program + let (mut validator, _) = write(&ledger_path); + validator.kill().unwrap(); + + // Read the ledger and verify that the memo program is cloned + let mut validator = read(&ledger_path); + validator.kill().unwrap(); +} + +fn write(ledger_path: &Path) -> (Child, u64) { + let loaded_chain_accounts = + LoadedAccounts::new_with_new_validator_authority(); + // Airdrop to the new validator authority + RpcClient::new("http://localhost:7799") + .request_airdrop( + &loaded_chain_accounts.validator_authority(), + 10 * LAMPORTS_PER_SOL, + ) + .unwrap(); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + None, + true, + false, + &loaded_chain_accounts, + ); + + let payer = Keypair::new(); + expect!( + ctx.airdrop_chain(&payer.pubkey(), LAMPORTS_PER_SOL), + validator + ); + + // This transaction will clone the memo program + let memo_ix = Instruction::new_with_bytes( + MEMO_PROGRAM_PK, + &[ + 0x39, 0x34, 0x32, 0x32, 0x38, 0x30, 0x37, 0x2e, 0x35, 0x34, 0x30, + 0x30, 0x30, 0x32, + ], + vec![], + ); + let mut tx = Transaction::new_with_payer(&[memo_ix], Some(&payer.pubkey())); + expect!( + ctx.send_and_confirm_transaction_ephem(&mut tx, &[&payer]), + validator + ); + + let account = expect!( + ctx.try_ephem_client() + .map_err(|e| anyhow::anyhow!("{}", e)) + .and_then(|client| client + .get_account(&MEMO_PROGRAM_PK) + .map_err(|e| anyhow::anyhow!("{}", e))), + validator + ); + let Account { + owner, executable, .. + } = account; + assert_eq!(owner, bpf_loader_upgradeable::ID, cleanup(&mut validator)); + assert_eq!(executable, true, cleanup(&mut validator)); + + let slot = wait_for_ledger_persist(&mut validator); + + (validator, slot) +} + +fn read(ledger_path: &Path) -> Child { + let loaded_chain_accounts = + LoadedAccounts::new_with_new_validator_authority(); + // Airdrop to the new validator authority + RpcClient::new("http://localhost:7799") + .request_airdrop( + &loaded_chain_accounts.validator_authority(), + 10 * LAMPORTS_PER_SOL, + ) + .unwrap(); + let (_, mut validator, ctx) = setup_validator_with_local_remote( + ledger_path, + None, + false, + true, + &loaded_chain_accounts, + ); + + let account = expect!( + ctx.try_ephem_client() + .map_err(|e| anyhow::anyhow!("{}", e)) + .and_then(|client| client + .get_account(&MEMO_PROGRAM_PK) + .map_err(|e| anyhow::anyhow!("{}", e))), + validator + ); + let Account { + owner, executable, .. + } = account; + assert_eq!(owner, bpf_loader_upgradeable::ID, cleanup(&mut validator)); + assert_eq!(executable, true, cleanup(&mut validator)); + + validator +} diff --git a/test-integration/test-ledger-restore/tests/15_skip_replay.rs b/test-integration/test-ledger-restore/tests/15_skip_replay.rs index 8a95bfb96..59117f42c 100644 --- a/test-integration/test-ledger-restore/tests/15_skip_replay.rs +++ b/test-integration/test-ledger-restore/tests/15_skip_replay.rs @@ -38,6 +38,7 @@ fn write( None, None, LedgerResumeStrategy::Reset, + false, ); let mut signatures = Vec::with_capacity(keypairs.len()); @@ -72,6 +73,7 @@ fn read( None, None, LedgerResumeStrategy::ResumeOnly, + false, ); // Current slot of the new validator should be at least the last slot of the previous validator diff --git a/test-integration/test-tools/src/loaded_accounts.rs b/test-integration/test-tools/src/loaded_accounts.rs index 5c9203b03..b1f6e757c 100644 --- a/test-integration/test-tools/src/loaded_accounts.rs +++ b/test-integration/test-tools/src/loaded_accounts.rs @@ -35,6 +35,15 @@ impl Default for LoadedAccounts { } impl LoadedAccounts { + pub fn new_with_new_validator_authority() -> Self { + Self { + validator_authority_kp: Keypair::new(), + luzid_authority: pubkey!( + "LUzidNSiPNjYNkxZcUm5hYHwnWPwsUfh2US1cpWwaBm" + ), + } + } + /// This use the test authority used in the delegation program as the validator /// authority. /// https://github.com/magicblock-labs/delegation-program/blob/7fc0ae9a59e48bea5b046b173ea0e34fd433c3c7/tests/fixtures/accounts.rs#L46 From e2065409f2586afd653367ca56bc4c7796297a29 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 5 Aug 2025 16:58:29 +0900 Subject: [PATCH 159/199] fix: commit via buffer bug, commit ids + some test fixes --- Cargo.lock | 5 +- Cargo.toml | 4 +- .../intent_execution_engine.rs | 4 +- .../src/intent_executor/commit_id_fetcher.rs | 14 ++- .../src/service_ext.rs | 1 + .../src/tasks/task_builder.rs | 6 +- .../src/tasks/tasks.rs | 2 +- .../delivery_preparator.rs | 1 - magicblock-committor-service/tests/common.rs | 2 +- test-integration/Cargo.lock | 26 +--- test-integration/Cargo.toml | 4 +- .../programs/flexi-counter/src/processor.rs | 2 +- .../tests/ix_commit_local.rs | 117 +++++++++++------- .../tests/utils/instructions.rs | 25 ++-- test-integration/schedulecommit/elfs/dlp.so | Bin 322944 -> 323312 bytes 15 files changed, 111 insertions(+), 102 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f77745adc..191511aec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3910,7 +3910,7 @@ dependencies = [ "magicblock-committor-service", "magicblock-config", "magicblock-core", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-delegation-program 1.0.0", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -4072,7 +4072,7 @@ dependencies = [ "log", "lru 0.16.0", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-delegation-program 1.0.0", "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", @@ -4141,7 +4141,6 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c#374603f739a1b218b6b6f49dcd7f0ba60d662c7c" dependencies = [ "bincode", "borsh 1.5.7", diff --git a/Cargo.toml b/Cargo.toml index 660ba3b79..d5eafd3fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,8 +116,8 @@ magicblock-config = { path = "./magicblock-config" } magicblock-config-helpers = { path = "./magicblock-config-helpers" } magicblock-config-macro = { path = "./magicblock-config-macro" } magicblock-core = { path = "./magicblock-core" } -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "374603f739a1b218b6b6f49dcd7f0ba60d662c7c", features = ["no-entrypoint"] } -#magicblock-delegation-program = { path = "../delegation-program" } +#magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "374603f739a1b218b6b6f49dcd7f0ba60d662c7c", features = ["no-entrypoint"] } +magicblock-delegation-program = { path = "../delegation-program", features = ["no-entrypoint"] } magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "ea04d46", default-features = false } magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" } magicblock-ledger = { path = "./magicblock-ledger" } diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index 4da7ee16e..e8677064b 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -35,7 +35,7 @@ const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; const MAX_EXECUTORS: u8 = 50; // TODO(edwin): rename -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ExecutionOutputWrapper { pub id: u64, pub output: ExecutionOutput, @@ -750,7 +750,7 @@ mod tests { #[async_trait] impl CommitIdFetcher for MockCommitIdTracker { - async fn fetch_commit_ids( + async fn fetch_next_commit_ids( &self, pubkeys: &[Pubkey], ) -> CommitIdTrackerResult> { diff --git a/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs b/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs index bdbe694fc..1a6bce099 100644 --- a/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs +++ b/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs @@ -15,7 +15,9 @@ use solana_pubkey::Pubkey; #[async_trait::async_trait] pub trait CommitIdFetcher: Send + Sync + 'static { - async fn fetch_commit_ids( + // Fetches correct next ids for pubkeys + // Those ids can be used as correct commit_id during Commit + async fn fetch_next_commit_ids( &self, pubkeys: &[Pubkey], ) -> CommitIdTrackerResult>; @@ -43,7 +45,7 @@ impl CommitIdTrackerImpl { } /// Fetches commit_ids with some num of retries - pub async fn fetch_commit_ids_with_retries( + pub async fn rpc_fetch_commit_ids_with_retries( rpc_client: &MagicblockRpcClient, pubkeys: &[Pubkey], num_retries: NonZeroUsize, @@ -54,7 +56,7 @@ impl CommitIdTrackerImpl { let mut last_err = Error::MetadataNotFoundError(pubkeys[0]); for i in 0..num_retries.get() { - match Self::fetch_commit_ids(rpc_client, pubkeys).await { + match Self::rpc_fetch_commit_ids(rpc_client, pubkeys).await { Ok(value) => return Ok(value), err @ Err(Error::InvalidAccountDataError(_)) => return err, err @ Err(Error::MetadataNotFoundError(_)) => return err, @@ -73,7 +75,7 @@ impl CommitIdTrackerImpl { /// Fetches commit_ids using RPC /// Note: remove duplicates prior to calling - pub async fn fetch_commit_ids( + pub async fn rpc_fetch_commit_ids( rpc_client: &MagicblockRpcClient, pubkeys: &[Pubkey], ) -> CommitIdTrackerResult> { @@ -133,7 +135,7 @@ impl CommitIdTrackerImpl { impl CommitIdFetcher for CommitIdTrackerImpl { /// Returns next ids for requested pubkeys /// If key isn't in cache, it will be requested - async fn fetch_commit_ids( + async fn fetch_next_commit_ids( &self, pubkeys: &[Pubkey], ) -> CommitIdTrackerResult> { @@ -172,7 +174,7 @@ impl CommitIdFetcher for CommitIdTrackerImpl { to_request.sort(); to_request.dedup(); - let remaining_ids = Self::fetch_commit_ids_with_retries( + let remaining_ids = Self::rpc_fetch_commit_ids_with_retries( &self.rpc_client, &to_request, NUM_FETCH_RETRIES, diff --git a/magicblock-committor-service/src/service_ext.rs b/magicblock-committor-service/src/service_ext.rs index 702e741a3..b4a5ee0a6 100644 --- a/magicblock-committor-service/src/service_ext.rs +++ b/magicblock-committor-service/src/service_ext.rs @@ -116,6 +116,7 @@ impl BaseIntentCommittorExt .collect::, _>>()? }; + self.commit_base_intent(base_intents); let results = join_all(receivers.into_iter()) .await .into_iter() diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 57917badf..4da7e37c1 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -117,7 +117,7 @@ impl TasksBuilder for TaskBuilderV1 { .map(|account| account.pubkey) .collect::>(); let commit_ids = commit_id_fetcher - .fetch_commit_ids(&committed_pubkeys) + .fetch_next_commit_ids(&committed_pubkeys) .await?; // Persist commit ids for commitees @@ -132,9 +132,9 @@ impl TasksBuilder for TaskBuilderV1 { let tasks = accounts .into_iter() .map(|account| { - let commit_id = commit_ids.get(&account.pubkey).expect("CommitIdFetcher provide commit ids for all listed pubkeys, or errors!"); + let commit_id = *commit_ids.get(&account.pubkey).expect("CommitIdFetcher provide commit ids for all listed pubkeys, or errors!"); let task = ArgsTask::Commit(CommitTask { - commit_id: *commit_id + 1, + commit_id, allow_undelegation, committed_account: account.clone(), }); diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index dccbfb26b..e1910a041 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -207,7 +207,7 @@ impl BaseTask for BufferTask { let Self::Commit(value) = self; let commit_id_slice = value.commit_id.to_le_bytes(); let (commit_buffer_pubkey, _) = - magicblock_committor_program::pdas::chunks_pda( + magicblock_committor_program::pdas::buffer_pda( validator, &value.committed_account.pubkey, &commit_id_slice, diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 2f1c462fd..2ee8654b4 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -124,7 +124,6 @@ impl DeliveryPreparator { // Writing chunks with some retries. Stol self.write_buffer_with_retries(authority, &preparation_info, 5) .await?; - println!("asd2"); // Persist that buffer account initiated successfully let update_status = CommitStatus::BufferAndChunkFullyInitialized; persist_status_update( diff --git a/magicblock-committor-service/tests/common.rs b/magicblock-committor-service/tests/common.rs index 8553adbc9..2bcb354e6 100644 --- a/magicblock-committor-service/tests/common.rs +++ b/magicblock-committor-service/tests/common.rs @@ -96,7 +96,7 @@ pub struct MockCommitIdFetcher; #[async_trait::async_trait] impl CommitIdFetcher for MockCommitIdFetcher { - async fn fetch_commit_ids( + async fn fetch_next_commit_ids( &self, pubkeys: &[Pubkey], ) -> CommitIdTrackerResult> { diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 847e3d1d6..12bc00e2d 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -2997,7 +2997,7 @@ dependencies = [ "log", "magicblock-config", "magicblock-core", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-delegation-program 1.0.0", "rayon", "serde", "solana-pubkey", @@ -3653,7 +3653,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-delegation-program 1.0.0", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3801,7 +3801,7 @@ dependencies = [ "log", "lru 0.16.0", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-delegation-program 1.0.0", "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", @@ -3876,22 +3876,6 @@ dependencies = [ "thiserror 1.0.69", ] -[[package]] -name = "magicblock-delegation-program" -version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c#374603f739a1b218b6b6f49dcd7f0ba60d662c7c" -dependencies = [ - "bincode", - "borsh 1.5.7", - "bytemuck", - "num_enum", - "paste", - "solana-curve25519", - "solana-program", - "solana-security-txt", - "thiserror 1.0.69", -] - [[package]] name = "magicblock-delegation-program" version = "1.0.0" @@ -5062,7 +5046,7 @@ version = "0.0.0" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-delegation-program 1.0.0", "solana-program", ] @@ -5907,7 +5891,7 @@ dependencies = [ "log", "magicblock-committor-program", "magicblock-committor-service", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=374603f739a1b218b6b6f49dcd7f0ba60d662c7c)", + "magicblock-delegation-program 1.0.0", "magicblock-program", "magicblock-rpc-client", "program-flexi-counter", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 8948cdfbe..afde28aba 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -42,8 +42,8 @@ magicblock-core = { path = "../magicblock-core" } magicblock-committor-program = { path = "../magicblock-committor-program", features = [ "no-entrypoint", ] } -#magicblock-delegation-program = { path = "../../delegation-program" } -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "374603f739a1b218b6b6f49dcd7f0ba60d662c7c", features = ["no-entrypoint"] } +magicblock-delegation-program = { path = "../../delegation-program", features = ["no-entrypoint"] } +#magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "374603f739a1b218b6b6f49dcd7f0ba60d662c7c", features = ["no-entrypoint"] } magicblock-committor-service = { path = "../magicblock-committor-service" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } magicblock-table-mania = { path = "../magicblock-table-mania" } diff --git a/test-integration/programs/flexi-counter/src/processor.rs b/test-integration/programs/flexi-counter/src/processor.rs index 922e25870..cddbd03ad 100644 --- a/test-integration/programs/flexi-counter/src/processor.rs +++ b/test-integration/programs/flexi-counter/src/processor.rs @@ -228,10 +228,10 @@ fn process_delegate( DelegateAccounts { payer, pda: delegate_account_pda, + owner_program, buffer, delegation_record, delegation_metadata, - owner_program, delegation_program, system_program, }, diff --git a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs index e9a164c98..3ebc30251 100644 --- a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs +++ b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs @@ -2,7 +2,7 @@ use log::*; use magicblock_committor_service::{BaseIntentCommittor, ComputeBudgetConfig}; use magicblock_rpc_client::MagicblockRpcClient; use std::collections::{HashMap, HashSet}; -use std::sync::Arc; +use std::sync::{Arc, Once}; use std::time::{Duration, Instant}; use test_tools_core::init_logger; use tokio::task::JoinSet; @@ -34,6 +34,7 @@ use solana_sdk::transaction::Transaction; use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, }; +use magicblock_program::validator::{init_validator_authority, validator_authority}; use utils::instructions::{ init_account_and_delegate_ixs, init_validator_fees_vault_ix, InitAccountAndDelegateIxs, @@ -56,6 +57,17 @@ fn expect_strategies( expected_strategies } +fn ensure_validator_authority() -> Keypair { + static ONCE: Once = Once::new(); + + ONCE.call_once(|| { + let validator_auth = utils::get_validator_auth(); + init_validator_authority(validator_auth.insecure_clone()); + }); + + validator_authority() +} + fn uses_lookup(expected: &ExpectedStrategies) -> bool { expected.iter().any(|(strategy, _)| strategy.uses_lookup()) } @@ -290,9 +302,8 @@ async fn test_ix_commit_single_account_ten_kb() { async fn commit_single_account(bytes: usize, undelegate: bool) { init_logger!(); - let slot = 10; - let validator_auth = utils::get_validator_auth(); + let validator_auth = ensure_validator_authority(); fund_validator_auth_and_ensure_validator_fees_vault(&validator_auth).await; // Run each test with and without finalizing @@ -305,9 +316,11 @@ async fn commit_single_account(bytes: usize, undelegate: bool) { let service = CommittorServiceExt::new(Arc::new(service)); let counter_auth = Keypair::new(); - let (pubkey, account) = + let (pubkey, mut account) = init_and_delegate_account_on_chain(&counter_auth, bytes as u64) .await; + account.owner = program_flexi_counter::id(); + account.data = vec![101 as u8; bytes]; let account = CommittedAccountV2 { pubkey, account }; let base_intent = if undelegate { @@ -325,7 +338,7 @@ async fn commit_single_account(bytes: usize, undelegate: bool) { trigger_type: TriggerType::OnChain, inner: ScheduledBaseIntent { id: 0, - slot, + slot: 10, blockhash: Hash::new_unique(), action_sent_transaction: Transaction::default(), payer: counter_auth.pubkey(), @@ -556,9 +569,8 @@ async fn commit_multiple_accounts( undelegate_all: bool, ) { init_logger!(); - let slot = 10; - let validator_auth = utils::get_validator_auth(); + let validator_auth = ensure_validator_authority(); fund_validator_auth_and_ensure_validator_fees_vault(&validator_auth).await; { @@ -567,7 +579,7 @@ async fn commit_multiple_accounts( ":memory:", ChainConfig::local(ComputeBudgetConfig::new(1_000_000)), ) - .unwrap(); + .unwrap(); let service = CommittorServiceExt::new(Arc::new(service)); let committees = @@ -585,11 +597,14 @@ async fn commit_multiple_accounts( let bytes = *bytes; join_set.spawn(async move { - let (pda, pda_acc) = init_and_delegate_account_on_chain( + let (pda, mut pda_acc) = init_and_delegate_account_on_chain( &counter_auth, bytes as u64, ) - .await; + .await; + + pda_acc.owner = program_flexi_counter::id(); + pda_acc.data = vec![idx as u8; bytes]; let request_undelegation = (undelegate_all || idx % 2 == 0); (pda, pda_acc, request_undelegation) @@ -601,6 +616,7 @@ async fn commit_multiple_accounts( |(_, _, request_undelegation)| !request_undelegation, ); + let mut base_intents = vec![]; let committed_accounts = committed .into_iter() .map(|(pda, pda_acc, _)| CommittedAccountV2 { @@ -609,21 +625,25 @@ async fn commit_multiple_accounts( }) .collect::>(); - let commit_intent = ScheduledBaseIntentWrapper { - excluded_pubkeys: vec![], - feepayers: vec![], - trigger_type: TriggerType::OnChain, - inner: ScheduledBaseIntent { - id: 1, - slot: 0, - blockhash: Hash::new_unique(), - action_sent_transaction: Transaction::default(), - payer: Pubkey::new_unique(), - base_intent: MagicBaseIntent::Commit(CommitType::Standalone( - committed_accounts, - )), - }, - }; + if !committed_accounts.is_empty() { + let commit_intent = ScheduledBaseIntentWrapper { + excluded_pubkeys: vec![], + feepayers: vec![], + trigger_type: TriggerType::OnChain, + inner: ScheduledBaseIntent { + id: 0, + slot: 0, + blockhash: Hash::new_unique(), + action_sent_transaction: Transaction::default(), + payer: Pubkey::new_unique(), + base_intent: MagicBaseIntent::Commit(CommitType::Standalone( + committed_accounts, + )), + }, + }; + + base_intents.push(commit_intent); + } let committed_and_undelegated_accounts = commmitted_and_undelegated .into_iter() @@ -633,30 +653,35 @@ async fn commit_multiple_accounts( }) .collect::>(); - let commit_and_undelegate_intent = ScheduledBaseIntentWrapper { - excluded_pubkeys: vec![], - feepayers: vec![], - trigger_type: TriggerType::OnChain, - inner: ScheduledBaseIntent { - id: 1, - slot: 0, - blockhash: Hash::new_unique(), - action_sent_transaction: Transaction::default(), - payer: Pubkey::new_unique(), - base_intent: MagicBaseIntent::CommitAndUndelegate( - CommitAndUndelegate { - commit_action: CommitType::Standalone( - committed_and_undelegated_accounts, - ), - undelegate_action: UndelegateType::Standalone, - }, - ), - }, - }; + if !committed_and_undelegated_accounts.is_empty() { + let commit_and_undelegate_intent = ScheduledBaseIntentWrapper { + excluded_pubkeys: vec![], + feepayers: vec![], + trigger_type: TriggerType::OnChain, + inner: ScheduledBaseIntent { + id: 1, + slot: 0, + blockhash: Hash::new_unique(), + action_sent_transaction: Transaction::default(), + payer: Pubkey::new_unique(), + base_intent: MagicBaseIntent::CommitAndUndelegate( + CommitAndUndelegate { + commit_action: CommitType::Standalone( + committed_and_undelegated_accounts, + ), + undelegate_action: UndelegateType::Standalone, + }, + ), + }, + }; + + base_intents.push(commit_and_undelegate_intent); + } + ix_commit_local( service, - vec![commit_intent, commit_and_undelegate_intent], + base_intents ) .await; } diff --git a/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs b/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs index 92db3ee32..c55272f4e 100644 --- a/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs +++ b/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs @@ -21,24 +21,23 @@ pub fn init_account_and_delegate_ixs( payer: Pubkey, bytes: u64, ) -> InitAccountAndDelegateIxs { + const MAX_ALLOC: u64 = magicblock_committor_program::consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64; + use program_flexi_counter::instruction::*; use program_flexi_counter::state::*; let init_counter_ix = create_init_ix(payer, "COUNTER".to_string()); let rent_exempt = Rent::default().minimum_balance(bytes as usize); - let mut realloc_ixs = vec![]; - if bytes - > magicblock_committor_program::consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE - as u64 - { - // TODO: we may have to chunk those - let reallocs = bytes - / magicblock_committor_program::consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE - as u64; - for i in 0..reallocs { - realloc_ixs.push(create_realloc_ix(payer, bytes, i as u16)); - } - } + + let num_reallocs = (bytes + MAX_ALLOC -1) / MAX_ALLOC; + let realloc_ixs = if num_reallocs == 0 { + vec![] + } else { + (0..num_reallocs).map(|i| { + create_realloc_ix(payer, bytes, i as u16) + }).collect() + }; + let delegate_ix = create_delegate_ix(payer); let pda = FlexiCounter::pda(&payer).0; InitAccountAndDelegateIxs { diff --git a/test-integration/schedulecommit/elfs/dlp.so b/test-integration/schedulecommit/elfs/dlp.so index bf743da8440acdd4dd83bacdb7be0e030a829b93..34334a5088630989928a0ef0cba5ac169420fe0e 100755 GIT binary patch delta 35449 zcmbuod0bW1_y2$Qz8A$A8~{-UCqPrA-if4%REk)N5-8krJJMuYf!?R)NlyLY|6pFe)*@sM?&Ypp$xXPVnLn)$o3Of945QC6Z&>=i>pvUv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qLOyjn4|mGwUJ=yLWD#7ar6Rzv6+sjoK5rgNA@wjXq{;OVRnXFU^WZzRjfz_e zhbbIGzatvOd}DU^C{}b;)}`N=hl~FY^8Ify<;3W6(g_NuE1aP)?&E)p+OD8(7f}PX zinf976=K)Tawa}BPl)k{qr^t7WwA`AwGfM;auMFwUPL`q(RUD8>J`iD3Ts>Bl-v~# zP&iECD23x>?yM!t0xg}^UP9AWT!N29bQr&TR4FDk^xY-%Sp2=((U(!E1X?PB9C||p z74#JXp3#}kTrr0}R9I!aM<_lK69p;0C9_7xvrUIS%YL)p!8x7j;RbV_#ohj;m5_@M zDVr2dwSQ^l&{x^Nta7ks|4hii`S#C*9GqkS8ppvQ16ut=eikijh$PTlhss=K|FpxA zK=Na(0ys9=-`#fT zQ|+&2J2>of**?|&hO$jBw!K;QSCkzQ;_R;;J2=(;&as2D?C%&mILH1@v4bP*?+!cI z$Np}xgTv0ZI%E-TUSxkc*kMp%e+$^bahF;n2>T5CTfGi_ll>)L2Vb|pl#eJK@!1#9A_4QU3nWlyslZW_S{L8n$dn0}qAD2cAXw`QF7Y%G>@%5`~n4M|H zkLI`ARgW=Hv;7SK8h90d@S!2rkU7F@j_>RZnBhRot85Zy>Qh$xP5(r5wpI4 yj$Ac|x6dbo@ik}rMsQQ1!T754VQ|aGppK711L%cD^U!up-y3EzG_KLy^Zx-Pzwdbf From 44f535a4dedcec5b208d6546dd625fa0111b71fd Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 5 Aug 2025 17:29:26 +0900 Subject: [PATCH 160/199] feat: fix commits of dlp --- Cargo.lock | 7 ++++--- Cargo.toml | 3 +-- test-integration/Cargo.lock | 31 ++++++++++++++++++++++++------- test-integration/Cargo.toml | 3 +-- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 191511aec..99e153388 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3910,7 +3910,7 @@ dependencies = [ "magicblock-committor-service", "magicblock-config", "magicblock-core", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -4072,7 +4072,7 @@ dependencies = [ "log", "lru 0.16.0", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", @@ -4141,6 +4141,7 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c#4af7f1cefe0915f0760ed5c38b25b7d41c31a474" dependencies = [ "bincode", "borsh 1.5.7", @@ -4156,7 +4157,7 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c#4af7f1cefe0915f0760ed5c38b25b7d41c31a474" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00#6edfe006d2726643065d769cc98fa713b2661dab" dependencies = [ "bincode", "borsh 1.5.7", diff --git a/Cargo.toml b/Cargo.toml index d5eafd3fb..34e160861 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -116,8 +116,7 @@ magicblock-config = { path = "./magicblock-config" } magicblock-config-helpers = { path = "./magicblock-config-helpers" } magicblock-config-macro = { path = "./magicblock-config-macro" } magicblock-core = { path = "./magicblock-core" } -#magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "374603f739a1b218b6b6f49dcd7f0ba60d662c7c", features = ["no-entrypoint"] } -magicblock-delegation-program = { path = "../delegation-program", features = ["no-entrypoint"] } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "6edfe00", features = ["no-entrypoint"] } magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "ea04d46", default-features = false } magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" } magicblock-ledger = { path = "./magicblock-ledger" } diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 12bc00e2d..ad3c98ef1 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1816,7 +1816,7 @@ dependencies = [ "ephemeral-rollups-sdk-attribute-delegate", "ephemeral-rollups-sdk-attribute-ephemeral", "magicblock-core", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=b149f8a)", "solana-program", ] @@ -2997,7 +2997,7 @@ dependencies = [ "log", "magicblock-config", "magicblock-core", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", "rayon", "serde", "solana-pubkey", @@ -3653,7 +3653,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3801,7 +3801,7 @@ dependencies = [ "log", "lru 0.16.0", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", @@ -3864,6 +3864,7 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c#4af7f1cefe0915f0760ed5c38b25b7d41c31a474" dependencies = [ "bincode", "borsh 1.5.7", @@ -3879,7 +3880,23 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c#4af7f1cefe0915f0760ed5c38b25b7d41c31a474" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00#6edfe006d2726643065d769cc98fa713b2661dab" +dependencies = [ + "bincode", + "borsh 1.5.7", + "bytemuck", + "num_enum", + "paste", + "solana-curve25519", + "solana-program", + "solana-security-txt", + "thiserror 1.0.69", +] + +[[package]] +name = "magicblock-delegation-program" +version = "1.0.0" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=b149f8a#b149f8ae8f0d16b779e5974e65b5edbb94e520de" dependencies = [ "bincode", "borsh 1.5.7", @@ -5046,7 +5063,7 @@ version = "0.0.0" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", "solana-program", ] @@ -5891,7 +5908,7 @@ dependencies = [ "log", "magicblock-committor-program", "magicblock-committor-service", - "magicblock-delegation-program 1.0.0", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", "magicblock-program", "magicblock-rpc-client", "program-flexi-counter", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index afde28aba..1d474b9d8 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -42,8 +42,7 @@ magicblock-core = { path = "../magicblock-core" } magicblock-committor-program = { path = "../magicblock-committor-program", features = [ "no-entrypoint", ] } -magicblock-delegation-program = { path = "../../delegation-program", features = ["no-entrypoint"] } -#magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "374603f739a1b218b6b6f49dcd7f0ba60d662c7c", features = ["no-entrypoint"] } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "6edfe00", features = ["no-entrypoint"] } magicblock-committor-service = { path = "../magicblock-committor-service" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } magicblock-table-mania = { path = "../magicblock-table-mania" } From 40787fe14357e4fb728e8d1068df2680ada57c80 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 5 Aug 2025 17:33:46 +0900 Subject: [PATCH 161/199] feat: fixed sdk version on latest commit --- test-integration/Cargo.lock | 36 +++++++++++++++++++++++++----------- test-integration/Cargo.toml | 3 +-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index ad3c98ef1..5f0de9f58 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1810,12 +1810,13 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk" version = "0.2.6" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=ec0308c#ec0308c179f3cf56c3662e5fc3bfbf371e1e7e98" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk-attribute-commit", "ephemeral-rollups-sdk-attribute-delegate", "ephemeral-rollups-sdk-attribute-ephemeral", - "magicblock-core", + "magicblock-core 0.1.7 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=44f535a)", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=b149f8a)", "solana-program", ] @@ -1823,6 +1824,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-commit" version = "0.2.6" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=ec0308c#ec0308c179f3cf56c3662e5fc3bfbf371e1e7e98" dependencies = [ "quote", "syn 1.0.109", @@ -1831,6 +1833,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-delegate" version = "0.2.6" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=ec0308c#ec0308c179f3cf56c3662e5fc3bfbf371e1e7e98" dependencies = [ "proc-macro2", "quote", @@ -1840,6 +1843,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-ephemeral" version = "0.2.6" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=ec0308c#ec0308c179f3cf56c3662e5fc3bfbf371e1e7e98" dependencies = [ "proc-macro2", "quote", @@ -2996,7 +3000,7 @@ dependencies = [ "borsh 1.5.7", "log", "magicblock-config", - "magicblock-core", + "magicblock-core 0.1.7", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", "rayon", "serde", @@ -3580,7 +3584,7 @@ dependencies = [ "magicblock-accounts-api", "magicblock-committor-service", "magicblock-config", - "magicblock-core", + "magicblock-core 0.1.7", "magicblock-metrics", "magicblock-mutator", "magicblock-rpc-client", @@ -3652,7 +3656,7 @@ dependencies = [ "magicblock-accounts-api", "magicblock-bank", "magicblock-committor-service", - "magicblock-core", + "magicblock-core 0.1.7", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", "magicblock-metrics", "magicblock-mutator", @@ -3716,7 +3720,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-config", - "magicblock-core", + "magicblock-core 0.1.7", "magicblock-geyser-plugin", "magicblock-ledger", "magicblock-metrics", @@ -3747,7 +3751,7 @@ dependencies = [ "log", "magicblock-accounts-db", "magicblock-config", - "magicblock-core", + "magicblock-core 0.1.7", "magicblock-program", "rand 0.8.5", "serde", @@ -3861,6 +3865,16 @@ dependencies = [ "solana-program", ] +[[package]] +name = "magicblock-core" +version = "0.1.7" +source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=44f535a#44f535a4dedcec5b208d6546dd625fa0111b71fd" +dependencies = [ + "bincode", + "serde", + "solana-program", +] + [[package]] name = "magicblock-delegation-program" version = "1.0.0" @@ -3949,7 +3963,7 @@ dependencies = [ "log", "magicblock-accounts-db", "magicblock-bank", - "magicblock-core", + "magicblock-core 0.1.7", "num-format", "num_cpus", "prost", @@ -4031,7 +4045,7 @@ version = "0.1.7" dependencies = [ "bincode", "lazy_static", - "magicblock-core", + "magicblock-core 0.1.7", "magicblock-metrics", "num-derive", "num-traits", @@ -5893,7 +5907,7 @@ dependencies = [ "anyhow", "borsh 1.5.7", "integration-test-tools", - "magicblock-core", + "magicblock-core 0.1.7", "program-schedulecommit", "solana-program", "solana-rpc-client", @@ -5928,7 +5942,7 @@ dependencies = [ "ephemeral-rollups-sdk", "integration-test-tools", "log", - "magicblock-core", + "magicblock-core 0.1.7", "program-schedulecommit", "schedulecommit-client", "solana-program", @@ -5943,7 +5957,7 @@ name = "schedulecommit-test-security" version = "0.0.0" dependencies = [ "integration-test-tools", - "magicblock-core", + "magicblock-core 0.1.7", "program-schedulecommit", "program-schedulecommit-security", "schedulecommit-client", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 1d474b9d8..63504f10c 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -28,8 +28,7 @@ edition = "2021" anyhow = "1.0.86" borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" -ephemeral-rollups-sdk = { path = "../../ephemeral-rollups-sdk/rust/sdk" } -#ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "63f624f" } +ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "ec0308c" } integration-test-tools = { path = "test-tools" } log = "0.4.20" magicblock-api = { path = "../magicblock-api" } From f25584db731e7cf44fc2d0b5ffe94a48adef6b09 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 5 Aug 2025 19:08:29 +0900 Subject: [PATCH 162/199] fix: ledger-restore tests - account for finalize tx --- .../test-ledger-restore/tests/07_commit_delegated_account.rs | 5 +++-- .../test-ledger-restore/tests/08_commit_update.rs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs b/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs index ee155da4b..9d5a7a10a 100644 --- a/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs +++ b/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs @@ -165,7 +165,8 @@ fn write(ledger_path: &Path, payer: &Keypair) -> (Child, u64) { // - init // - delegate // - commit (original from while validator was running) - assert_counter_commits_on_chain(&ctx, &mut validator, &payer.pubkey(), 3); + // - finalize + assert_counter_commits_on_chain(&ctx, &mut validator, &payer.pubkey(), 4); let slot = wait_for_ledger_persist(&mut validator); (validator, slot) @@ -208,7 +209,7 @@ fn read(ledger_path: &Path, payer: &Pubkey) -> Child { // Ensure that at this point we still only have three chain transactions // for the counter, showing that the commits didn't get sent to chain again. - assert_counter_commits_on_chain(&ctx, &mut validator, payer, 3); + assert_counter_commits_on_chain(&ctx, &mut validator, payer, 4); validator } diff --git a/test-integration/test-ledger-restore/tests/08_commit_update.rs b/test-integration/test-ledger-restore/tests/08_commit_update.rs index d91da7343..353339369 100644 --- a/test-integration/test-ledger-restore/tests/08_commit_update.rs +++ b/test-integration/test-ledger-restore/tests/08_commit_update.rs @@ -155,7 +155,7 @@ fn write(ledger_path: &Path, payer: &Keypair) -> (Child, u64) { ); } - assert_counter_commits_on_chain(&ctx, &mut validator, &payer.pubkey(), 3); + assert_counter_commits_on_chain(&ctx, &mut validator, &payer.pubkey(), 4); let slot = wait_for_ledger_persist(&mut validator); (validator, slot) @@ -211,7 +211,7 @@ fn read(ledger_path: &Path, payer_kp: &Keypair) -> Child { ); // Ensure we did not commit during ledger replay - assert_counter_commits_on_chain(&ctx, &mut validator, payer, 3); + assert_counter_commits_on_chain(&ctx, &mut validator, payer, 4); validator } From fe67df58a532364b7d7041422bb158c215c1f64f Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 5 Aug 2025 19:40:37 +0900 Subject: [PATCH 163/199] fix: tests failing due to insufficient compute units --- magicblock-committor-service/src/tasks/tasks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index e1910a041..aad1d4d8b 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -178,7 +178,7 @@ impl BaseTask for ArgsTask { fn compute_units(&self) -> u32 { match self { - Self::Commit(_) => 45_000, + Self::Commit(_) => 55_000, Self::L1Action(task) => task.action.compute_units, Self::Undelegate(_) => 50_000, Self::Finalize(_) => 40_000, @@ -293,7 +293,7 @@ impl BaseTask for BufferTask { fn compute_units(&self) -> u32 { match self { - Self::Commit(_) => 45_000, + Self::Commit(_) => 55_000, } } From cc3653a5424b5b19fe7416331475f5ada7d85cbf Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 6 Aug 2025 13:49:58 +0900 Subject: [PATCH 164/199] fix: make committor optional for !can_clone cases --- .../src/remote_account_cloner_worker.rs | 56 ++++++------ .../tests/remote_account_cloner.rs | 2 +- magicblock-accounts/src/accounts_manager.rs | 2 +- .../src/external_accounts_manager.rs | 9 +- magicblock-accounts/tests/commit_delegated.rs | 2 +- magicblock-accounts/tests/ensure_accounts.rs | 4 +- magicblock-api/src/magic_validator.rs | 85 +++++++++++-------- magicblock-api/src/tickers.rs | 67 +++++++++------ .../src/committor_processor.rs | 3 - .../delivery_preparator.rs | 4 - magicblock-committor-service/src/utils.rs | 1 + .../programs/schedulecommit/src/api.rs | 1 - 12 files changed, 129 insertions(+), 107 deletions(-) diff --git a/magicblock-account-cloner/src/remote_account_cloner_worker.rs b/magicblock-account-cloner/src/remote_account_cloner_worker.rs index 1044ed878..05df8f942 100644 --- a/magicblock-account-cloner/src/remote_account_cloner_worker.rs +++ b/magicblock-account-cloner/src/remote_account_cloner_worker.rs @@ -97,7 +97,7 @@ pub struct RemoteAccountClonerWorker { account_fetcher: AFE, account_updates: AUP, account_dumper: ADU, - changeset_committor: Arc, + changeset_committor: Option>, allowed_program_ids: Option>, blacklisted_accounts: HashSet, validator_charges_fees: ValidatorCollectionMode, @@ -141,7 +141,7 @@ where account_fetcher: AFE, account_updates: AUP, account_dumper: ADU, - changeset_committor: Arc, + changeset_committor: Option>, allowed_program_ids: Option>, blacklisted_accounts: HashSet, validator_charges_fees: ValidatorCollectionMode, @@ -714,31 +714,33 @@ where // Allow the committer service to reserve pubkeys in lookup tables // that could be needed when we commit this account - if self.clone_config.prepare_lookup_tables - == PrepareLookupTables::Always - { - let committor = self.changeset_committor.clone(); - let pubkey = *pubkey; - let owner = delegation_record.owner; - tokio::spawn(async move { - match map_committor_request_result( - committor - .reserve_pubkeys_for_committee(pubkey, owner), - committor, - ) - .await - { - Ok(initiated) => { - trace!( - "Reserving lookup keys for {pubkey} took {:?}", - initiated.elapsed() - ); - } - Err(err) => { - error!("Failed to reserve lookup keys for {pubkey}: {err:?}"); - } - }; - }); + if let Some(committor) = self.changeset_committor.clone() { + if self.clone_config.prepare_lookup_tables + == PrepareLookupTables::Always + { + let pubkey = *pubkey; + let owner = delegation_record.owner; + tokio::spawn(async move { + match map_committor_request_result( + committor.reserve_pubkeys_for_committee( + pubkey, owner, + ), + committor, + ) + .await + { + Ok(initiated) => { + trace!( + "Reserving lookup keys for {pubkey} took {:?}", + initiated.elapsed() + ); + } + Err(err) => { + error!("Failed to reserve lookup keys for {pubkey}: {err:?}"); + } + }; + }); + } } self.do_clone_delegated_account( diff --git a/magicblock-account-cloner/tests/remote_account_cloner.rs b/magicblock-account-cloner/tests/remote_account_cloner.rs index bd2d767af..c19e90693 100644 --- a/magicblock-account-cloner/tests/remote_account_cloner.rs +++ b/magicblock-account-cloner/tests/remote_account_cloner.rs @@ -43,7 +43,7 @@ fn setup_custom( account_fetcher, account_updates, account_dumper, - changeset_committor, + Some(changeset_committor), allowed_program_ids, blacklisted_accounts, ValidatorCollectionMode::NoFees, diff --git a/magicblock-accounts/src/accounts_manager.rs b/magicblock-accounts/src/accounts_manager.rs index 4b6cff83f..bb7af8c09 100644 --- a/magicblock-accounts/src/accounts_manager.rs +++ b/magicblock-accounts/src/accounts_manager.rs @@ -26,7 +26,7 @@ pub type AccountsManager = ExternalAccountsManager< impl AccountsManager { pub fn try_new( bank: &Arc, - committor_service: Arc>, + committor_service: Option>>, remote_account_cloner_client: RemoteAccountClonerClient, config: AccountsConfig, ) -> AccountsResult { diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index a1385e66f..2dda5369f 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -106,7 +106,7 @@ where pub account_cloner: ACL, pub transaction_accounts_extractor: TAE, pub transaction_accounts_validator: TAV, - pub committor_service: Arc, + pub committor_service: Option>, pub lifecycle: LifecycleMode, pub external_commitable_accounts: RwLock>, @@ -264,6 +264,10 @@ where pub async fn commit_delegated( &self, ) -> AccountsResult> { + let Some(committor_service) = &self.committor_service else { + return Ok(vec![]); + }; + let now = get_epoch(); // Find all accounts that are due to be committed let accounts_to_be_committed = self let accounts_to_be_committed = self @@ -290,8 +294,7 @@ where self.create_scheduled_l1_message(accounts_to_be_committed); // Commit BaseIntents - let results = self - .committor_service + let results = committor_service .schedule_base_intents_waiting(scheduled_l1_messages.clone()) .await?; diff --git a/magicblock-accounts/tests/commit_delegated.rs b/magicblock-accounts/tests/commit_delegated.rs index 691258eae..e5467437a 100644 --- a/magicblock-accounts/tests/commit_delegated.rs +++ b/magicblock-accounts/tests/commit_delegated.rs @@ -41,7 +41,7 @@ fn setup( account_cloner, transaction_accounts_extractor: TransactionAccountsExtractorImpl, transaction_accounts_validator: TransactionAccountsValidatorImpl, - committor_service, + committor_service: Some(committor_service), lifecycle: LifecycleMode::Ephemeral, external_commitable_accounts: Default::default(), } diff --git a/magicblock-accounts/tests/ensure_accounts.rs b/magicblock-accounts/tests/ensure_accounts.rs index 01f8e8112..dcb10ede4 100644 --- a/magicblock-accounts/tests/ensure_accounts.rs +++ b/magicblock-accounts/tests/ensure_accounts.rs @@ -50,7 +50,7 @@ fn setup_with_lifecycle( account_fetcher, account_updates, account_dumper, - changeset_committor_stub.clone(), + Some(changeset_committor_stub.clone()), None, HashSet::new(), ValidatorCollectionMode::NoFees, @@ -75,7 +75,7 @@ fn setup_with_lifecycle( account_cloner: remote_account_cloner_client, transaction_accounts_extractor: TransactionAccountsExtractorImpl, transaction_accounts_validator: TransactionAccountsValidatorImpl, - committor_service: changeset_committor_stub, + committor_service: Some(changeset_committor_stub), lifecycle, external_commitable_accounts: Default::default(), }; diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 2ba45bd40..960c8ae29 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -27,7 +27,6 @@ use magicblock_account_updates::{ use magicblock_accounts::{ remote_scheduled_commits_processor::RemoteScheduledCommitsProcessor, utils::try_rpc_cluster_from_cluster, AccountsManager, - ScheduledCommitsProcessor, }; use magicblock_accounts_api::BankAccountProvider; use magicblock_accounts_db::error::AccountsDbError; @@ -57,6 +56,7 @@ use magicblock_perf_service::SamplePerformanceService; use magicblock_processor::execute_transaction::TRANSACTION_INDEX_LOCK; use magicblock_program::{ init_persister, validator, validator::validator_authority, + TransactionScheduler, }; use magicblock_pubsub::pubsub_service::{ PubsubConfig, PubsubService, PubsubServiceCloseHandle, @@ -147,7 +147,7 @@ pub struct MagicValidator { sample_performance_service: Option, commit_accounts_ticker: Option>, remote_scheduled_commits_processor: - Arc>, + Option>>, remote_account_fetcher_worker: Option, remote_account_fetcher_handle: Option>, remote_account_updates_worker: Option, @@ -166,7 +166,7 @@ pub struct MagicValidator { >, remote_account_cloner_handle: Option>, accounts_manager: Arc, - committor_service: Arc, + committor_service: Option>, transaction_listener: GeyserTransactionNotifyListener, rpc_service: JsonRpcService, _metrics: Option<(MetricsService, tokio::task::JoinHandle<()>)>, @@ -326,21 +326,26 @@ impl MagicValidator { let clone_permissions = accounts_config.lifecycle.to_account_cloner_permissions(); - let committor_service = Arc::new(CommittorService::try_start( - identity_keypair.insecure_clone(), - committor_persist_path, - ChainConfig { - rpc_uri: remote_rpc_config.url().to_string(), - commitment: remote_rpc_config - .commitment() - .unwrap_or(CommitmentLevel::Confirmed), - compute_budget_config: ComputeBudgetConfig::new( - accounts_config.commit_compute_unit_price, - ), - }, - )?); - let committor_service_ext = - Arc::new(CommittorServiceExt::new(committor_service.clone())); + let can_clone = clone_permissions.can_clone(); + let committor_service = if can_clone { + let committor_service = Arc::new(CommittorService::try_start( + identity_keypair.insecure_clone(), + committor_persist_path, + ChainConfig { + rpc_uri: remote_rpc_config.url().to_string(), + commitment: remote_rpc_config + .commitment() + .unwrap_or(CommitmentLevel::Confirmed), + compute_budget_config: ComputeBudgetConfig::new( + accounts_config.commit_compute_unit_price, + ), + }, + )?); + + Some(committor_service) + } else { + None + }; let remote_account_cloner_worker = RemoteAccountClonerWorker::new( bank_account_provider, @@ -361,17 +366,22 @@ impl MagicValidator { config.validator_config.accounts.clone.clone(), ); - let remote_scheduled_commits_processor = - Arc::new(RemoteScheduledCommitsProcessor::new( + let remote_scheduled_commits_processor = if can_clone { + Some(Arc::new(RemoteScheduledCommitsProcessor::new( bank.clone(), remote_account_cloner_worker.get_last_clone_output(), - committor_service.clone(), + committor_service + .clone() + .expect("When clone enabled committor has to exist!"), transaction_status_sender.clone(), - )); + ))) + } else { + None + }; let accounts_manager = Self::init_accounts_manager( &bank, - &committor_service_ext, + &committor_service, RemoteAccountClonerClient::new(&remote_account_cloner_worker), &config.validator_config, ); @@ -463,7 +473,7 @@ impl MagicValidator { fn init_accounts_manager( bank: &Arc, - commitor_service: &Arc>, + commitor_service: &Option>, remote_account_cloner_client: RemoteAccountClonerClient, config: &EphemeralConfig, ) -> Arc { @@ -471,9 +481,12 @@ impl MagicValidator { .expect( "Failed to derive accounts config from provided magicblock config", ); + let committor_ext = commitor_service + .clone() + .map(|inner| Arc::new(CommittorServiceExt::new(inner))); let accounts_manager = AccountsManager::try_new( bank, - commitor_service.clone(), + committor_ext, remote_account_cloner_client, accounts_config, ) @@ -593,15 +606,13 @@ impl MagicValidator { // Thus while the ledger is processed we don't yet run the machinery to handle // scheduled commits and we clear all scheduled commits before fully starting the // validator. - let scheduled_commits = self - .remote_scheduled_commits_processor - .scheduled_commits_len(); + let scheduled_commits = + TransactionScheduler::default().scheduled_actions_len(); debug!( "Found {} scheduled commits while processing ledger, clearing them", scheduled_commits ); - self.remote_scheduled_commits_processor - .clear_scheduled_commits(); + TransactionScheduler::default().clear_scheduled_actions(); // We want the next transaction either due to hydrating of cloned accounts or // user request to be processed in the next slot such that it doesn't become @@ -805,12 +816,14 @@ impl MagicValidator { if let Some(remote_account_cloner_worker) = self.remote_account_cloner_worker.take() { - debug!("Reserving common pubkeys for committor service"); - map_committor_request_result( - self.committor_service.reserve_common_pubkeys(), - self.committor_service.clone(), - ) - .await?; + if let Some(committor_service) = &self.committor_service { + debug!("Reserving common pubkeys for committor service"); + map_committor_request_result( + committor_service.reserve_common_pubkeys(), + committor_service.clone(), + ) + .await?; + } if self.config.ledger.resume_strategy.is_replaying() { let remote_account_cloner_worker = diff --git a/magicblock-api/src/tickers.rs b/magicblock-api/src/tickers.rs index ef5c4d9c0..4a72ab908 100644 --- a/magicblock-api/src/tickers.rs +++ b/magicblock-api/src/tickers.rs @@ -22,7 +22,7 @@ use crate::slot::advance_slot_and_update_ledger; pub fn init_slot_ticker( bank: &Arc, - committor_processor: &Arc, + committor_processor: &Option>, transaction_status_sender: TransactionStatusSender, ledger: Arc, tick_duration: Duration, @@ -42,35 +42,23 @@ pub fn init_slot_ticker( error!("Failed to write block: {:?}", err); } - // If accounts were scheduled to be committed, we accept them here - // and processs the commits - let magic_context_acc = bank.get_account(&magic_program::MAGIC_CONTEXT_PUBKEY) - .expect("Validator found to be running without MagicContext account!"); - - if MagicContext::has_scheduled_commits(magic_context_acc.data()) { - // 1. Send the transaction to move the scheduled commits from the MagicContext - // to the global ScheduledCommit store - let tx = InstructionUtils::accept_scheduled_commits( - bank.last_blockhash(), - ); - if let Err(err) = execute_legacy_transaction( - tx, - &bank, - Some(&transaction_status_sender), - ) { - error!("Failed to accept scheduled commits: {:?}", err); - } else { - // 2. Process those scheduled commits - // TODO: fix the possible delay here - // https://github.com/magicblock-labs/magicblock-validator/issues/104 - if let Err(err) = committor_processor.process().await { - error!( - "Failed to process scheduled commits: {:?}", - err - ); - } + // Handle intents if such feature enabled + if let Some(committor_processor) = &committor_processor { + // If accounts were scheduled to be committed, we accept them here + // and processs the commits + let magic_context_acc = bank.get_account(&magic_program::MAGIC_CONTEXT_PUBKEY) + .expect("Validator found to be running without MagicContext account!"); + if MagicContext::has_scheduled_commits(magic_context_acc.data()) + { + handle_scheduled_commits( + &bank, + committor_processor, + &transaction_status_sender, + ) + .await; } } + if log { info!("Advanced to slot {}", next_slot); } @@ -79,6 +67,29 @@ pub fn init_slot_ticker( }) } +async fn handle_scheduled_commits( + bank: &Arc, + committor_processor: &Arc, + transaction_status_sender: &TransactionStatusSender, +) { + // 1. Send the transaction to move the scheduled commits from the MagicContext + // to the global ScheduledCommit store + let tx = InstructionUtils::accept_scheduled_commits(bank.last_blockhash()); + if let Err(err) = + execute_legacy_transaction(tx, &bank, Some(transaction_status_sender)) + { + error!("Failed to accept scheduled commits: {:?}", err); + return; + } + + // 2. Process those scheduled commits + // TODO: fix the possible delay here + // https://github.com/magicblock-labs/magicblock-validator/issues/104 + if let Err(err) = committor_processor.process().await { + error!("Failed to process scheduled commits: {:?}", err); + } +} + pub fn init_commit_accounts_ticker( manager: &Arc, tick_duration: Duration, diff --git a/magicblock-committor-service/src/committor_processor.rs b/magicblock-committor-service/src/committor_processor.rs index 07924f8fc..2673041e6 100644 --- a/magicblock-committor-service/src/committor_processor.rs +++ b/magicblock-committor-service/src/committor_processor.rs @@ -11,7 +11,6 @@ use solana_sdk::{ use tokio::sync::broadcast; use crate::{ - compute_budget::ComputeBudgetConfig, config::ChainConfig, error::CommittorServiceResult, intent_execution_manager::{ @@ -28,7 +27,6 @@ pub(crate) struct CommittorProcessor { pub(crate) magicblock_rpc_client: MagicblockRpcClient, pub(crate) table_mania: TableMania, pub(crate) authority: Keypair, - pub(crate) compute_budget_config: ComputeBudgetConfig, persister: IntentPersisterImpl, commits_scheduler: IntentExecutionManager, } @@ -77,7 +75,6 @@ impl CommittorProcessor { table_mania, commits_scheduler, persister, - compute_budget_config: chain_config.compute_budget_config, }) } diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 2ee8654b4..60ef4d94b 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -35,10 +35,6 @@ use crate::{ ComputeBudgetConfig, }; -pub struct DeliveryPreparationResult { - lookup_tables: Vec, -} - pub struct DeliveryPreparator { rpc_client: MagicblockRpcClient, table_mania: TableMania, diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index fb702a2b9..9ece547b7 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -23,6 +23,7 @@ pub(crate) fn persist_status_update( } } +#[allow(unused)] pub(crate) fn persist_status_update_set( persister: &Option

, commit_ids_map: &HashMap, diff --git a/test-integration/programs/schedulecommit/src/api.rs b/test-integration/programs/schedulecommit/src/api.rs index 0ac17052b..7307880ea 100644 --- a/test-integration/programs/schedulecommit/src/api.rs +++ b/test-integration/programs/schedulecommit/src/api.rs @@ -2,7 +2,6 @@ use dlp::args::{DelegateArgs, DelegateEphemeralBalanceArgs}; use ephemeral_rollups_sdk::delegate_args::{ DelegateAccountMetas, DelegateAccounts, }; -use ephemeral_rollups_sdk::pda::{delegate_buffer_pda_from_delegated_account_and_owner_program, delegation_metadata_pda_from_delegated_account, delegation_record_pda_from_delegated_account, ephemeral_balance_pda_from_payer}; use solana_program::{ instruction::{AccountMeta, Instruction}, pubkey::Pubkey, From 01685ebc940c0b3729b9998c7f51daa507ee3389 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 6 Aug 2025 17:33:05 +0900 Subject: [PATCH 165/199] refactor: remove some todos + some struct field cleaning --- .../src/external_accounts_manager.rs | 4 +- .../src/remote_scheduled_commits_processor.rs | 246 ++++++++++++++---- magicblock-accounts/tests/commit_delegated.rs | 1 - magicblock-accounts/tests/ensure_accounts.rs | 1 - .../stubs/scheduled_commits_processor_stub.rs | 4 - .../intent_execution_engine.rs | 70 +---- .../intent_scheduler.rs | 2 - .../src/intent_executor/error.rs | 2 + .../src/intent_executor/intent_executor.rs | 16 +- .../src/stubs/changeset_committor_stub.rs | 9 - magicblock-committor-service/src/types.rs | 7 +- .../src/magic_scheduled_base_intent.rs | 27 ++ 12 files changed, 253 insertions(+), 136 deletions(-) diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 2dda5369f..c0632f195 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -319,7 +319,7 @@ where .filter_map(|execution_result| match execution_result { Ok(value) => Some(value), Err(err) => { - error!("Failed to send l1 message: {}", err.1); + error!("Failed to send l1 message: {}", err.2); None } }) @@ -431,8 +431,6 @@ where }) .map(|scheduled_l1_message| ScheduledBaseIntentWrapper { inner: scheduled_l1_message, - excluded_pubkeys: vec![], - feepayers: vec![], trigger_type: TriggerType::OffChain, }) .collect() diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index e3327530f..03143e5a0 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -1,8 +1,11 @@ -use std::{collections::HashSet, sync::Arc}; +use std::{ + collections::{HashMap, HashSet}, + sync::{Arc, Mutex}, +}; use async_trait::async_trait; use conjunto_transwise::AccountChainSnapshot; -use log::{debug, error, info}; +use log::{debug, error, info, warn}; use magicblock_account_cloner::{AccountClonerOutput, CloneOutputMap}; use magicblock_bank::bank::Bank; use magicblock_committor_service::{ @@ -15,13 +18,17 @@ use magicblock_committor_service::{ use magicblock_processor::execute_transaction::execute_legacy_transaction; use magicblock_program::{ magic_scheduled_base_intent::{CommittedAccountV2, ScheduledBaseIntent}, - register_scheduled_commit_sent, FeePayerAccount, TransactionScheduler, + register_scheduled_commit_sent, FeePayerAccount, SentCommit, + TransactionScheduler, }; use magicblock_transaction_status::TransactionStatusSender; use solana_sdk::{ account::{Account, ReadableAccount}, + hash::Hash, pubkey::Pubkey, + signature::Signature, system_program, + transaction::Transaction, }; use tokio::sync::{broadcast, oneshot}; @@ -29,12 +36,15 @@ use crate::{errors::AccountsResult, ScheduledCommitsProcessor}; const POISONED_RWLOCK_MSG: &str = "RwLock of RemoteAccountClonerWorker.last_clone_output is poisoned"; +const POISONED_MUTEX_MSG: &str = + "Mutex of RemoteScheduledCommitsProcessor.intents_meta_map is poisoned"; pub struct RemoteScheduledCommitsProcessor { - transaction_scheduler: TransactionScheduler, - cloned_accounts: CloneOutputMap, bank: Arc, committor: Arc, + intents_meta_map: Arc>>, + cloned_accounts: CloneOutputMap, + transaction_scheduler: TransactionScheduler, } impl RemoteScheduledCommitsProcessor { @@ -45,16 +55,19 @@ impl RemoteScheduledCommitsProcessor { transaction_status_sender: TransactionStatusSender, ) -> Self { let result_subscriber = committor.subscribe_for_results(); + let intents_meta_map = Arc::new(Mutex::default()); tokio::spawn(Self::result_processor( bank.clone(), result_subscriber, + intents_meta_map.clone(), transaction_status_sender, )); Self { bank, - cloned_accounts, committor, + intents_meta_map, + cloned_accounts, transaction_scheduler: TransactionScheduler::default(), } } @@ -62,15 +75,18 @@ impl RemoteScheduledCommitsProcessor { fn preprocess_intent( &self, mut base_intent: ScheduledBaseIntent, - ) -> ScheduledBaseIntentWrapper { + ) -> ( + ScheduledBaseIntentWrapper, + Vec, + HashSet, + ) { let Some(committed_accounts) = base_intent.get_committed_accounts_mut() else { - return ScheduledBaseIntentWrapper { + let intent = ScheduledBaseIntentWrapper { inner: base_intent, - excluded_pubkeys: Vec::new(), - feepayers: Vec::new(), trigger_type: TriggerType::OnChain, }; + return (intent, vec![], HashSet::new()); }; struct Processor<'a> { @@ -137,10 +153,13 @@ impl RemoteScheduledCommitsProcessor { .. }) => account_chain_snapshot, Some(AccountClonerOutput::Unclonable { .. }) => { - todo!() + error!("Unclonable account as part of commit"); + return false; + } + None => { + error!("Account snapshot is absent during commit!"); + return false; } - // TODO(edwin): hmm - None => return true, }; if account_chain_snapshot.chain_state.is_feepayer() { @@ -156,12 +175,14 @@ impl RemoteScheduledCommitsProcessor { } }); - ScheduledBaseIntentWrapper { + let feepayers = processor.feepayers; + let excluded_pubkeys = processor.excluded_pubkeys.into_iter().collect(); + let intent = ScheduledBaseIntentWrapper { inner: base_intent, - feepayers: processor.feepayers.into_iter().collect(), - excluded_pubkeys: processor.excluded_pubkeys.into_iter().collect(), trigger_type: TriggerType::OnChain, - } + }; + + (intent, excluded_pubkeys, feepayers) } async fn result_processor( @@ -169,61 +190,135 @@ impl RemoteScheduledCommitsProcessor { result_subscriber: oneshot::Receiver< broadcast::Receiver, >, + intents_meta_map: Arc>>, transaction_status_sender: TransactionStatusSender, ) { const SUBSCRIPTION_ERR_MSG: &str = "Failed to get subscription of results of BaseIntents execution"; + const META_ABSENT_ERR_MSG: &str = + "Absent meta for executed intent should not be possible!"; let mut result_receiver = result_subscriber.await.expect(SUBSCRIPTION_ERR_MSG); while let Ok(execution_result) = result_receiver.recv().await { + let (intent_id, trigger_type) = execution_result + .as_ref() + .map(|output| (output.id, output.trigger_type)) + .unwrap_or_else(|(id, trigger_type, _)| (*id, *trigger_type)); + + // Here we handle on OnChain triggered intent + // TODO: should be removed once crank supported + if matches!(trigger_type, TriggerType::OffChain) { + info!("OffChain triggered BaseIntent executed: {}", intent_id); + continue; + } + + // Remove intent from metas + let intent_meta = intents_meta_map + .lock() + .expect(POISONED_MUTEX_MSG) + .remove(&intent_id) + .expect(META_ABSENT_ERR_MSG); match execution_result { Ok(value) => { Self::process_intent_result( + intent_id, &bank, &transaction_status_sender, value, + intent_meta, ) - .await + .await; } - Err(err) => { - error!("Failed to commit: {:?}", err); - todo!() + Err((_, _, err)) => { + match err.as_ref() { + &magicblock_committor_service::intent_executor::error::Error::EmptyIntentError => { + warn!("Empty intent was scheduled!"); + Self::process_empty_intent( + intent_id, + &bank, + &transaction_status_sender, + intent_meta + ).await; + } + _ => { + error!("Failed to commit: {:?}", err); + todo!() + } + } } } } } async fn process_intent_result( + intent_id: u64, bank: &Arc, transaction_status_sender: &TransactionStatusSender, execution_outcome: ExecutionOutputWrapper, + intent_meta: ScheduledBaseIntentMeta, ) { - // We don't trigger sent tx for `TriggerType::OffChain` - // TODO: should be removed once crank supported - if matches!(execution_outcome.trigger_type, TriggerType::OnChain) { - register_scheduled_commit_sent(execution_outcome.sent_commit); - match execute_legacy_transaction( - execution_outcome.action_sent_transaction, - bank, - Some(transaction_status_sender), - ) { - Ok(signature) => debug!( - "Signaled sent commit with internal signature: {:?}", - signature - ), - Err(err) => { - error!( - "Failed to signal sent commit via transaction: {}", - err - ); - } + let chain_signatures = vec![ + execution_outcome.output.commit_signature, + execution_outcome.output.finalize_signature, + ]; + let sent_commit = + Self::build_sent_commit(intent_id, chain_signatures, &intent_meta); + register_scheduled_commit_sent(sent_commit); + match execute_legacy_transaction( + intent_meta.intent_sent_transaction, + bank, + Some(transaction_status_sender), + ) { + Ok(signature) => debug!( + "Signaled sent commit with internal signature: {:?}", + signature + ), + Err(err) => { + error!("Failed to signal sent commit via transaction: {}", err); } - } else { - info!( - "OffChain triggered BaseIntent executed: {}", - execution_outcome.sent_commit.message_id - ); + } + } + + async fn process_empty_intent( + intent_id: u64, + bank: &Arc, + transaction_status_sender: &TransactionStatusSender, + intent_meta: ScheduledBaseIntentMeta, + ) { + let sent_commit = + Self::build_sent_commit(intent_id, vec![], &intent_meta); + register_scheduled_commit_sent(sent_commit); + match execute_legacy_transaction( + intent_meta.intent_sent_transaction, + bank, + Some(transaction_status_sender), + ) { + Ok(signature) => debug!( + "Signaled sent commit with internal signature: {:?}", + signature + ), + Err(err) => { + error!("Failed to signal sent commit via transaction: {}", err); + } + } + } + + fn build_sent_commit( + intent_id: u64, + chain_signatures: Vec, + intent_meta: &ScheduledBaseIntentMeta, + ) -> SentCommit { + SentCommit { + message_id: intent_id, + slot: intent_meta.slot, + blockhash: intent_meta.blockhash, + payer: intent_meta.payer, + chain_signatures, + included_pubkeys: intent_meta.included_pubkeys.clone(), + excluded_pubkeys: intent_meta.excluded_pubkeys.clone(), + feepayers: intent_meta.feepayers.clone(), + requested_undelegation: intent_meta.requested_undelegation, } } } @@ -240,13 +335,32 @@ impl ScheduledCommitsProcessor return Ok(()); } - let scheduled_base_intent_wrapped = scheduled_base_intent + let intents = scheduled_base_intent .into_iter() - .map(|intent| self.preprocess_intent(intent)) - .collect(); - self.committor - .commit_base_intent(scheduled_base_intent_wrapped); + .map(|intent| self.preprocess_intent(intent)); + + // Add metas for intent we schedule + let intents = { + let mut intent_metas = + self.intents_meta_map.lock().expect(POISONED_MUTEX_MSG); + + intents + .map(|(intent, excluded_pubkeys, feepayers)| { + intent_metas.insert( + intent.id, + ScheduledBaseIntentMeta::new( + &intent, + excluded_pubkeys, + feepayers, + ), + ); + intent + }) + .collect() + }; + + self.committor.commit_base_intent(intents); Ok(()) } @@ -258,3 +372,35 @@ impl ScheduledCommitsProcessor self.transaction_scheduler.clear_scheduled_actions(); } } + +struct ScheduledBaseIntentMeta { + slot: u64, + blockhash: Hash, + payer: Pubkey, + included_pubkeys: Vec, + excluded_pubkeys: Vec, + feepayers: HashSet, + intent_sent_transaction: Transaction, + requested_undelegation: bool, +} + +impl ScheduledBaseIntentMeta { + fn new( + intent: &ScheduledBaseIntent, + excluded_pubkeys: Vec, + feepayers: HashSet, + ) -> Self { + Self { + slot: intent.slot, + blockhash: intent.blockhash, + payer: intent.payer, + included_pubkeys: intent + .get_committed_pubkeys() + .unwrap_or_default(), + excluded_pubkeys, + feepayers, + intent_sent_transaction: intent.action_sent_transaction.clone(), + requested_undelegation: intent.is_undelegate(), + } + } +} diff --git a/magicblock-accounts/tests/commit_delegated.rs b/magicblock-accounts/tests/commit_delegated.rs index e5467437a..ea9f7173a 100644 --- a/magicblock-accounts/tests/commit_delegated.rs +++ b/magicblock-accounts/tests/commit_delegated.rs @@ -18,7 +18,6 @@ use solana_sdk::{ pubkey::Pubkey, signature::Signature, }; -use stubs::scheduled_commits_processor_stub::ScheduledCommitsProcessorStub; use test_tools_core::init_logger; mod stubs; diff --git a/magicblock-accounts/tests/ensure_accounts.rs b/magicblock-accounts/tests/ensure_accounts.rs index dcb10ede4..f13410e98 100644 --- a/magicblock-accounts/tests/ensure_accounts.rs +++ b/magicblock-accounts/tests/ensure_accounts.rs @@ -20,7 +20,6 @@ use magicblock_accounts_api::InternalAccountProviderStub; use magicblock_committor_service::stubs::ChangesetCommittorStub; use magicblock_config::AccountsCloneConfig; use solana_sdk::pubkey::Pubkey; -use stubs::scheduled_commits_processor_stub::ScheduledCommitsProcessorStub; use test_tools_core::init_logger; use tokio::task::JoinHandle; use tokio_util::sync::CancellationToken; diff --git a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs index 6989e4cd4..dd179721d 100644 --- a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs +++ b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs @@ -1,9 +1,5 @@ -use std::sync::Arc; - use async_trait::async_trait; use magicblock_accounts::{errors::AccountsResult, ScheduledCommitsProcessor}; -use magicblock_accounts_api::InternalAccountProvider; -use magicblock_committor_service::BaseIntentCommittor; #[derive(Default)] pub struct ScheduledCommitsProcessorStub {} diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index e8677064b..e6f15ba45 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -1,12 +1,7 @@ -use std::{ - collections::HashSet, - sync::{Arc, Mutex}, -}; +use std::sync::{Arc, Mutex}; use futures_util::{stream::FuturesUnordered, StreamExt}; use log::{error, info, trace, warn}; -use magicblock_program::SentCommit; -use solana_sdk::transaction::Transaction; use tokio::{ sync::{ broadcast, mpsc, mpsc::error::TryRecvError, OwnedSemaphorePermit, @@ -39,12 +34,11 @@ const MAX_EXECUTORS: u8 = 50; pub struct ExecutionOutputWrapper { pub id: u64, pub output: ExecutionOutput, - pub action_sent_transaction: Transaction, - pub sent_commit: SentCommit, pub trigger_type: TriggerType, } -pub type BroadcastedError = (u64, Arc); +pub type BroadcastedError = + (u64, TriggerType, Arc); pub type BroadcastedIntentExecutionResult = IntentExecutorResult; @@ -238,8 +232,14 @@ where .inspect_err(|err| { error!("Failed to execute BaseIntent: {:?}", err) }) - .map(|raw_result| Self::map_execution_outcome(&intent, raw_result)) - .map_err(|err| (intent.inner.id, Arc::new(err))); + .map(|output| ExecutionOutputWrapper { + id: intent.id, + trigger_type: intent.trigger_type, + output, + }) + .map_err(|err| { + (intent.inner.id, intent.trigger_type, Arc::new(err)) + }); // Broadcast result to subscribers if let Err(err) = result_sender.send(result) { @@ -254,56 +254,13 @@ where // Free worker drop(execution_permit); } - - /// Maps output of `IntentExecutor` to final result - fn map_execution_outcome( - intent: &ScheduledBaseIntentWrapper, - raw_outcome: ExecutionOutput, - ) -> ExecutionOutputWrapper { - let ScheduledBaseIntentWrapper { - inner, - feepayers, - excluded_pubkeys, - trigger_type, - } = intent; - let included_pubkeys = - if let Some(included_pubkeys) = inner.get_committed_pubkeys() { - included_pubkeys - } else { - // Case with standalone actions - vec![] - }; - let requested_undelegation = inner.is_undelegate(); - let chain_signatures = - vec![raw_outcome.commit_signature, raw_outcome.finalize_signature]; - - let sent_commit = SentCommit { - message_id: inner.id, - slot: inner.slot, - blockhash: inner.blockhash, - payer: inner.payer, - included_pubkeys, - excluded_pubkeys: excluded_pubkeys.clone(), - feepayers: HashSet::from_iter(feepayers.iter().cloned()), - requested_undelegation, - chain_signatures, - }; - - ExecutionOutputWrapper { - id: inner.id, - output: raw_outcome, - action_sent_transaction: inner.action_sent_transaction.clone(), - trigger_type: *trigger_type, - sent_commit, - } - } } /// Worker tests #[cfg(test)] mod tests { use std::{ - collections::HashMap, + collections::{HashMap, HashSet}, sync::{ atomic::{AtomicUsize, Ordering}, Arc, @@ -421,10 +378,11 @@ mod tests { // Verify the failure was properly reported let result = result_receiver.recv().await.unwrap(); - let Err((id, err)) = result else { + let Err((id, trigger_type, err)) = result else { panic!(); }; assert_eq!(id, 1); + assert_eq!(trigger_type, TriggerType::OffChain); assert_eq!( err.to_string(), "FailedToCommitError: SignerError: custom error: oops" diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs index c960651bd..c343e1904 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs @@ -571,8 +571,6 @@ pub(crate) fn create_test_intent( ScheduledBaseIntentWrapper { inner: intent, - feepayers: vec![], - excluded_pubkeys: vec![], trigger_type: TriggerType::OffChain, } } diff --git a/magicblock-committor-service/src/intent_executor/error.rs b/magicblock-committor-service/src/intent_executor/error.rs index b89f98fea..23449b21c 100644 --- a/magicblock-committor-service/src/intent_executor/error.rs +++ b/magicblock-committor-service/src/intent_executor/error.rs @@ -11,6 +11,8 @@ pub enum InternalError { #[derive(thiserror::Error, Debug)] pub enum Error { + #[error("EmptyIntentError")] + EmptyIntentError, #[error("FailedToCommitError: {err}")] FailedToCommitError { #[source] diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index 8e4200abe..f2c7ebea7 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -50,6 +50,10 @@ where base_intent: ScheduledBaseIntent, persister: &Option

, ) -> IntentExecutorResult { + if base_intent.is_empty() { + return Err(Error::EmptyIntentError); + } + // Update tasks status to Pending if let Some(pubkeys) = base_intent.get_committed_pubkeys() { let update_status = CommitStatus::Pending; @@ -171,6 +175,10 @@ where let update_status = CommitStatus::Succeeded(signatures); persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } + Err(Error::EmptyIntentError) => { + let update_status = CommitStatus::Failed; + persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); + } Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::FailedToFitError)) => { let update_status = CommitStatus::PartOfTooLargeBundleToProcess; persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); @@ -223,13 +231,13 @@ where /// Returns `ExecutionOutput` or an `Error` async fn execute( &self, - l1_message: ScheduledBaseIntent, + base_intent: ScheduledBaseIntent, persister: Option

, ) -> IntentExecutorResult { - let message_id = l1_message.id; - let pubkeys = l1_message.get_committed_pubkeys(); + let message_id = base_intent.id; + let pubkeys = base_intent.get_committed_pubkeys(); - let result = self.execute_inner(l1_message, &persister).await; + let result = self.execute_inner(base_intent, &persister).await; if let Some(pubkeys) = pubkeys { Self::persist_result(&persister, &result, message_id, &pubkeys); } diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index 9a4d9bb95..33f634dc8 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -167,16 +167,7 @@ impl BaseIntentCommittorExt for ChangesetCommittorStub { commit_signature: Signature::new_unique(), finalize_signature: Signature::new_unique(), }, - action_sent_transaction: Transaction::default(), trigger_type: TriggerType::OnChain, - sent_commit: SentCommit { - message_id: message.inner.id, - slot: message.inner.slot, - blockhash: message.inner.blockhash, - payer: message.inner.payer, - requested_undelegation: message.inner.is_undelegate(), - ..SentCommit::default() - }, }) }) .collect::>(); diff --git a/magicblock-committor-service/src/types.rs b/magicblock-committor-service/src/types.rs index 87b1bddf9..5c10b7e68 100644 --- a/magicblock-committor-service/src/types.rs +++ b/magicblock-committor-service/src/types.rs @@ -1,9 +1,6 @@ use std::ops::Deref; -use magicblock_program::{ - magic_scheduled_base_intent::ScheduledBaseIntent, FeePayerAccount, -}; -use solana_pubkey::Pubkey; +use magicblock_program::magic_scheduled_base_intent::ScheduledBaseIntent; // TODO: should be removed once cranks are supported // Ideally even now OffChain/"Manual" commits should be triggered via Tx @@ -16,8 +13,6 @@ pub enum TriggerType { #[derive(Clone, Debug, PartialEq, Eq)] pub struct ScheduledBaseIntentWrapper { pub inner: ScheduledBaseIntent, - pub feepayers: Vec, - pub excluded_pubkeys: Vec, pub trigger_type: TriggerType, } diff --git a/programs/magicblock/src/magic_scheduled_base_intent.rs b/programs/magicblock/src/magic_scheduled_base_intent.rs index aec01bc03..7b66b0082 100644 --- a/programs/magicblock/src/magic_scheduled_base_intent.rs +++ b/programs/magicblock/src/magic_scheduled_base_intent.rs @@ -101,6 +101,10 @@ impl ScheduledBaseIntent { pub fn is_undelegate(&self) -> bool { self.base_intent.is_undelegate() } + + pub fn is_empty(&self) -> bool { + self.base_intent.is_empty() + } } // BaseIntent user wants to send to base layer @@ -172,6 +176,14 @@ impl MagicBaseIntent { accounts.iter().map(|account| account.pubkey).collect() }) } + + pub fn is_empty(&self) -> bool { + match self { + MagicBaseIntent::BaseActions(actions) => actions.is_empty(), + MagicBaseIntent::Commit(t) => t.is_empty(), + MagicBaseIntent::CommitAndUndelegate(t) => t.is_empty(), + } + } } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -205,6 +217,10 @@ impl CommitAndUndelegate { ) -> &mut Vec { self.commit_action.get_committed_accounts_mut() } + + pub fn is_empty(&self) -> bool { + self.commit_action.is_empty() + } } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -476,6 +492,17 @@ impl CommitType { } => committed_accounts, } } + + pub fn is_empty(&self) -> bool { + match self { + Self::Standalone(committed_accounts) => { + committed_accounts.is_empty() + } + Self::WithBaseActions { + committed_accounts, .. + } => committed_accounts.is_empty(), + } + } } /// No CommitedAccounts since it is only used with CommitAction. From af871b8b29cb340f1f5928aaefb9911f1990cd97 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 6 Aug 2025 17:58:42 +0900 Subject: [PATCH 166/199] fix: clippy errors --- .../src/external_accounts_manager.rs | 10 ++---- .../src/remote_scheduled_commits_processor.rs | 2 +- .../src/instruction_builder/realloc_buffer.rs | 6 ++-- .../src/state/chunks.rs | 5 ++- .../tests/prog_init_write_and_close.rs | 5 ++- .../intent_execution_engine.rs | 8 +---- .../src/intent_executor/intent_executor.rs | 2 +- .../src/intent_executor/mod.rs | 1 + .../src/persist/commit_persister.rs | 3 +- .../src/persist/db.rs | 3 +- .../src/persist/types/commit_status.rs | 4 +-- .../src/service_ext.rs | 2 +- .../src/stubs/changeset_committor_stub.rs | 6 ++-- magicblock-committor-service/src/tasks/mod.rs | 1 + .../src/tasks/task_builder.rs | 4 +-- .../src/tasks/task_strategist.rs | 33 ++++++++----------- .../tasks/task_visitors/persistor_visitor.rs | 2 +- .../src/tasks/utils.rs | 23 ++++++------- .../delivery_preparator.rs | 15 ++++----- magicblock-committor-service/tests/common.rs | 7 +++- .../tests/test_delivery_preparator.rs | 5 ++- .../tests/test_transaction_preparator.rs | 2 -- .../src/magic_scheduled_base_intent.rs | 30 ++++++++--------- .../process_schedule_base_intent.rs | 4 +-- .../schedule_base_intent_processor.rs | 4 +-- 25 files changed, 82 insertions(+), 105 deletions(-) diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index c0632f195..75cf108b0 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -353,7 +353,7 @@ where ) .get_mut(&pubkey) { - acc.mark_as_committed(&now, &hash); + acc.mark_as_committed(now, &hash); } else { // This should never happen @@ -364,10 +364,7 @@ where } } - outputs - .into_iter() - .map(|(_, output)| output.output) - .collect() + outputs.into_values().map(|output| output.output).collect() } fn create_scheduled_l1_message( @@ -410,12 +407,11 @@ where committees .chunks(MAX_PROCESS_PER_TX as usize) - .into_iter() .map(|committees| { let committees = committees .iter() .cloned() - .map(|committee| CommittedAccountV2::from(committee)) + .map(CommittedAccountV2::from) .collect(); ScheduledBaseIntent { // isn't important but shall be unique diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index 03143e5a0..d87492090 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -95,7 +95,7 @@ impl RemoteScheduledCommitsProcessor { bank: &'a Bank, } - impl<'a> Processor<'a> { + impl Processor<'_> { /// Handles case when committed account is feepayer /// Returns `true` if account should be retained, `false` otherwise fn process_feepayer( diff --git a/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs b/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs index a1f5a9d95..d5529b7ea 100644 --- a/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs +++ b/magicblock-committor-program/src/instruction_builder/realloc_buffer.rs @@ -39,7 +39,7 @@ pub fn create_realloc_buffer_ixs( // B) We need to realloc multiple times // SAFETY; remaining size > consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE - create_realloc_buffer_ixs_to_add_remaining(&args, remaining_size as u64) + create_realloc_buffer_ixs_to_add_remaining(&args, remaining_size) } pub fn create_realloc_buffer_ixs_to_add_remaining( @@ -47,9 +47,7 @@ pub fn create_realloc_buffer_ixs_to_add_remaining( remaining_size: u64, ) -> Vec { let remaining_invocation_count = - (remaining_size + MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64 - 1) - / MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64; - + remaining_size.div_ceil(MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64); // Generate one instruction per needed allocation (1..=remaining_invocation_count) .map(|i| create_realloc_buffer_ix(args.clone(), i as u16)) diff --git a/magicblock-committor-program/src/state/chunks.rs b/magicblock-committor-program/src/state/chunks.rs index 5ed93a648..536e19aa5 100644 --- a/magicblock-committor-program/src/state/chunks.rs +++ b/magicblock-committor-program/src/state/chunks.rs @@ -44,8 +44,7 @@ impl Chunks { } pub fn from_data_length(data_len: usize, chunk_size: u16) -> Self { - let chunk_count = - (data_len + chunk_size as usize - 1) / chunk_size as usize; + let chunk_count = data_len.div_ceil(chunk_size as usize); Self::new(chunk_count, chunk_size) } @@ -54,7 +53,7 @@ impl Chunks { /// Each boolean is stored as a single bit, packing 8 booleans per byte. /// Returns the number of bytes needed to store all flags, rounding up if necessary. fn count_to_bitfield_bytes(count: usize) -> usize { - (count + BITS_PER_BYTE - 1) / BITS_PER_BYTE + count.div_ceil(BITS_PER_BYTE) } /// Returns how many bytes [`Chunks`] will occupy certain count diff --git a/magicblock-committor-program/tests/prog_init_write_and_close.rs b/magicblock-committor-program/tests/prog_init_write_and_close.rs index 4f9537105..b5f8f6663 100644 --- a/magicblock-committor-program/tests/prog_init_write_and_close.rs +++ b/magicblock-committor-program/tests/prog_init_write_and_close.rs @@ -282,8 +282,7 @@ async fn init_write_and_close(changeset: Changeset) { } assert!(!chunks.is_complete()); - let buffer_data = - get_buffer_data(&banks_client, &&buffer_pda).await; + let buffer_data = get_buffer_data(&banks_client, &buffer_pda).await; assert_eq!( buffer_data[third_chunk.offset as usize ..third_chunk.offset as usize @@ -315,7 +314,7 @@ async fn init_write_and_close(changeset: Changeset) { } assert!(chunks.is_complete()); - let buffer = get_buffer_data(&banks_client, &&buffer_pda).await; + let buffer = get_buffer_data(&banks_client, &buffer_pda).await; assert_eq!(buffer, commitable.data); } diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index e6f15ba45..fc7e21230 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -670,7 +670,7 @@ mod tests { impl IntentExecutor for MockIntentExecutor { async fn execute( &self, - base_intent: ScheduledBaseIntent, + _base_intent: ScheduledBaseIntent, _persister: Option

, ) -> IntentExecutorResult { self.on_task_started(); @@ -700,12 +700,6 @@ mod tests { #[derive(Clone)] pub struct MockCommitIdTracker; - impl MockCommitIdTracker { - pub fn new() -> Self { - Self - } - } - #[async_trait] impl CommitIdFetcher for MockCommitIdTracker { async fn fetch_next_commit_ids( diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index f2c7ebea7..b8021c38f 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -58,7 +58,7 @@ where if let Some(pubkeys) = base_intent.get_committed_pubkeys() { let update_status = CommitStatus::Pending; persist_status_update_by_message_set( - &persister, + persister, base_intent.id, &pubkeys, update_status, diff --git a/magicblock-committor-service/src/intent_executor/mod.rs b/magicblock-committor-service/src/intent_executor/mod.rs index d60429dae..2663ef641 100644 --- a/magicblock-committor-service/src/intent_executor/mod.rs +++ b/magicblock-committor-service/src/intent_executor/mod.rs @@ -1,5 +1,6 @@ pub mod commit_id_fetcher; pub mod error; +#[allow(clippy::module_inception)] pub mod intent_executor; pub(crate) mod intent_executor_factory; diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index b6103c3d7..2c6671065 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -143,8 +143,7 @@ impl IntentPersister for IntentPersisterImpl { ) -> CommitPersistResult<()> { let commit_rows = l1_message .iter() - .map(Self::create_commit_rows) - .flatten() + .flat_map(Self::create_commit_rows) .collect::>(); // Insert all commit rows into the database self.commits_db diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 275b3d7fd..0e3d13ae9 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -375,6 +375,7 @@ impl CommittsDb { } #[cfg(test)] + #[allow(dead_code)] fn get_commit_statuses_by_pubkey( &self, pubkey: &Pubkey, @@ -435,7 +436,7 @@ impl CommittsDb { WHERE commit_id = ?1 AND pubkey = ?2 LIMIT 1"; - let mut stmt = self.conn.prepare(&query)?; + let mut stmt = self.conn.prepare(query)?; let mut rows = stmt.query(params![commit_id, pubkey.to_string()])?; let result = rows diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index 197274b92..ddd22a944 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -80,9 +80,9 @@ impl TryFrom<(&str, Option)> for CommitStatus { if let Some(sigs) = sigs.clone() { Ok(sigs) } else { - return Err(CommitPersistError::CommitStatusNeedsSignatures( + Err(CommitPersistError::CommitStatusNeedsSignatures( status.to_string(), - )); + )) } }; diff --git a/magicblock-committor-service/src/service_ext.rs b/magicblock-committor-service/src/service_ext.rs index b4a5ee0a6..506730efe 100644 --- a/magicblock-committor-service/src/service_ext.rs +++ b/magicblock-committor-service/src/service_ext.rs @@ -77,7 +77,7 @@ impl CommittorServiceExt { continue; }; - if let Err(_) = sender.send(execution_result) { + if sender.send(execution_result).is_err() { error!( "Failed to send BaseIntent execution result to listener" ); diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index 33f634dc8..bf16ba8d3 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -4,9 +4,8 @@ use std::{ time::{Instant, SystemTime, UNIX_EPOCH}, }; -use magicblock_program::SentCommit; use solana_pubkey::Pubkey; -use solana_sdk::{signature::Signature, transaction::Transaction}; +use solana_sdk::signature::Signature; use solana_transaction_status_client_types::{ EncodedConfirmedTransactionWithStatusMeta, EncodedTransaction, EncodedTransactionWithStatusMeta, @@ -33,6 +32,7 @@ pub struct ChangesetCommittorStub { } impl ChangesetCommittorStub { + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { self.committed_changesets.lock().unwrap().len() } @@ -130,7 +130,7 @@ impl BaseIntentCommittor for ChangesetCommittorStub { CommittorServiceResult, > { let (tx, rx) = oneshot::channel(); - if let Err(err) = + if let Err(_err) = tx.send(Ok(EncodedConfirmedTransactionWithStatusMeta { slot: 0, transaction: EncodedTransactionWithStatusMeta { diff --git a/magicblock-committor-service/src/tasks/mod.rs b/magicblock-committor-service/src/tasks/mod.rs index 053d47028..e142eae0f 100644 --- a/magicblock-committor-service/src/tasks/mod.rs +++ b/magicblock-committor-service/src/tasks/mod.rs @@ -1,6 +1,7 @@ pub mod task_builder; pub mod task_strategist; pub(crate) mod task_visitors; +#[allow(clippy::module_inception)] pub mod tasks; pub mod utils; pub mod visitor; diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 4da7e37c1..6c6d7112a 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -94,7 +94,7 @@ impl TasksBuilder for TaskBuilderV1 { let (accounts, allow_undelegation) = match &l1_message.base_intent { MagicBaseIntent::BaseActions(actions) => { let tasks = actions - .into_iter() + .iter() .map(|el| { let task = L1ActionTask { context: Context::Standalone, @@ -130,7 +130,7 @@ impl TasksBuilder for TaskBuilderV1 { }); let tasks = accounts - .into_iter() + .iter() .map(|account| { let commit_id = *commit_ids.get(&account.pubkey).expect("CommitIdFetcher provide commit ids for all listed pubkeys, or errors!"); let task = ArgsTask::Commit(CommitTask { diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 86c3e6b6a..f971e0848 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -65,7 +65,7 @@ impl TaskStrategist { // Get lookup table keys let lookup_tables_keys = - Self::collect_lookup_table_keys(&validator, &tasks); + Self::collect_lookup_table_keys(validator, &tasks); Ok(TransactionStrategy { optimized_tasks: tasks, lookup_tables_keys, @@ -81,11 +81,11 @@ impl TaskStrategist { pub fn attempt_lookup_tables(tasks: &[Box]) -> bool { let placeholder = Keypair::new(); // Gather all involved keys in tx - let budgets = TransactionUtils::tasks_compute_units(&tasks); + let budgets = TransactionUtils::tasks_compute_units(tasks); let budget_instructions = TransactionUtils::budget_instructions(budgets, u64::default()); let unique_involved_pubkeys = TransactionUtils::unique_involved_pubkeys( - &tasks, + tasks, &placeholder.pubkey(), &budget_instructions, ); @@ -94,7 +94,7 @@ impl TaskStrategist { // Create final tx let instructions = - TransactionUtils::tasks_instructions(&placeholder.pubkey(), &tasks); + TransactionUtils::tasks_instructions(&placeholder.pubkey(), tasks); let alt_tx = if let Ok(tx) = TransactionUtils::assemble_tx_raw( &placeholder, &instructions, @@ -108,27 +108,22 @@ impl TaskStrategist { }; let encoded_alt_tx = serialize_and_encode_base64(&alt_tx); - if encoded_alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE { - true - } else { - false - } + encoded_alt_tx.len() <= MAX_ENCODED_TRANSACTION_SIZE } pub fn collect_lookup_table_keys( authority: &Pubkey, tasks: &[Box], ) -> Vec { - let budgets = TransactionUtils::tasks_compute_units(&tasks); + let budgets = TransactionUtils::tasks_compute_units(tasks); let budget_instructions = TransactionUtils::budget_instructions(budgets, u64::default()); - let unique_involved_pubkeys = TransactionUtils::unique_involved_pubkeys( - &tasks, + + TransactionUtils::unique_involved_pubkeys( + tasks, authority, &budget_instructions, - ); - - unique_involved_pubkeys + ) } /// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`] @@ -138,7 +133,7 @@ impl TaskStrategist { let calculate_tx_length = |tasks: &[Box]| { match TransactionUtils::assemble_tasks_tx( &Keypair::new(), // placeholder - &tasks, + tasks, u64::default(), // placeholder &[], ) { @@ -156,7 +151,7 @@ impl TaskStrategist { // Create heap size -> index // TODO(edwin): OPTIMIZATION. update ixs arr, since we know index, coul then reuse for tx creation let ixs = - TransactionUtils::tasks_instructions(&Pubkey::new_unique(), &tasks); + TransactionUtils::tasks_instructions(&Pubkey::new_unique(), tasks); let sizes = ixs .iter() .map(|ix| bincode::serialized_size(ix).map(|size| size as usize)) @@ -404,14 +399,12 @@ mod tests { #[test] fn test_optimize_strategy_prioritizes_largest_tasks() { - let validator = Pubkey::new_unique(); - let mut tasks = vec![ + let tasks = [ Box::new(create_test_commit_task(1, 100)) as Box, Box::new(create_test_commit_task(2, 1000)) as Box, // Larger task Box::new(create_test_commit_task(3, 1000)) as Box, // Larger task ]; - let final_size = TaskStrategist::optimize_strategy(&mut tasks); // The larger task should have been optimized first assert!(matches!(tasks[0].strategy(), TaskStrategy::Args)); assert!(matches!(tasks[1].strategy(), TaskStrategy::Buffer)); diff --git a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs index 43e783bfc..71f2dc596 100644 --- a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs +++ b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs @@ -18,7 +18,7 @@ pub struct PersistorVisitor<'a, P> { pub context: PersistorContext, } -impl<'a, P> Visitor for PersistorVisitor<'a, P> +impl

Visitor for PersistorVisitor<'_, P> where P: IntentPersister, { diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index 5def2fa73..bdbe3a466 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -81,10 +81,10 @@ impl TransactionUtils { lookup_tables: &[AddressLookupTableAccount], ) -> TaskStrategistResult { let budget_instructions = Self::budget_instructions( - Self::tasks_compute_units(&tasks), + Self::tasks_compute_units(tasks), compute_unit_price, ); - let ixs = Self::tasks_instructions(&authority.pubkey(), &tasks); + let ixs = Self::tasks_instructions(&authority.pubkey(), tasks); Self::assemble_tx_raw( authority, &ixs, @@ -100,21 +100,18 @@ impl TransactionUtils { lookup_tables: &[AddressLookupTableAccount], ) -> TaskStrategistResult { // This is needed because VersionedMessage::serialize uses unwrap() ¯\_(ツ)_/¯ - instructions - .iter() - .map(|el| { - if el.data.len() > u16::MAX as usize { - Err(crate::tasks::task_strategist::Error::FailedToFitError) - } else { - Ok(()) - } - }) - .collect::>()?; + instructions.iter().try_for_each(|el| { + if el.data.len() > u16::MAX as usize { + Err(crate::tasks::task_strategist::Error::FailedToFitError) + } else { + Ok(()) + } + })?; let message = match Message::try_compile( &authority.pubkey(), &[budget_instructions, instructions].concat(), - &lookup_tables, + lookup_tables, Hash::new_unique(), ) { Ok(message) => Ok(message), diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs index 60ef4d94b..59482cc6a 100644 --- a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs @@ -64,7 +64,7 @@ impl DeliveryPreparator { let preparation_futures = strategy .optimized_tasks .iter() - .map(|task| self.prepare_task(authority, task, persister)); + .map(|task| self.prepare_task(authority, task.as_ref(), persister)); let task_preparations = join_all(preparation_futures); let alts_preparations = @@ -83,7 +83,7 @@ impl DeliveryPreparator { pub async fn prepare_task( &self, authority: &Keypair, - task: &Box, + task: &dyn BaseTask, persister: &Option

, ) -> DeliveryPreparatorResult<(), InternalError> { let Some(preparation_info) = task.preparation_info(&authority.pubkey()) @@ -101,12 +101,8 @@ impl DeliveryPreparator { ); // Initialize buffer account. Init + reallocs - self.initialize_buffer_account( - authority, - task.as_ref(), - &preparation_info, - ) - .await?; + self.initialize_buffer_account(authority, task, &preparation_info) + .await?; // Persist initialization success let update_status = CommitStatus::BufferAndChunkInitialized; @@ -133,6 +129,7 @@ impl DeliveryPreparator { } /// Initializes buffer account for future writes + #[allow(clippy::let_and_return)] async fn initialize_buffer_account( &self, authority: &Keypair, @@ -296,7 +293,7 @@ impl DeliveryPreparator { let message = Message::try_compile( &authority.pubkey(), instructions, - &vec![], + &[], latest_block_hash, )?; let transaction = VersionedTransaction::try_new( diff --git a/magicblock-committor-service/tests/common.rs b/magicblock-committor-service/tests/common.rs index 2bcb354e6..d08e34a47 100644 --- a/magicblock-committor-service/tests/common.rs +++ b/magicblock-committor-service/tests/common.rs @@ -72,6 +72,7 @@ impl TestFixture { } } + #[allow(dead_code)] pub fn create_delivery_preparator(&self) -> DeliveryPreparator { DeliveryPreparator::new( self.rpc_client.clone(), @@ -80,6 +81,7 @@ impl TestFixture { ) } + #[allow(dead_code)] pub fn create_transaction_preparator( &self, ) -> TransactionPreparatorV1 { @@ -103,11 +105,12 @@ impl CommitIdFetcher for MockCommitIdFetcher { Ok(pubkeys.iter().map(|pubkey| (*pubkey, 0)).collect()) } - fn peek_commit_id(&self, pubkey: &Pubkey) -> Option { + fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option { None } } +#[allow(dead_code)] pub fn generate_random_bytes(length: usize) -> Vec { use rand::Rng; @@ -115,6 +118,7 @@ pub fn generate_random_bytes(length: usize) -> Vec { (0..length).map(|_| rng.gen()).collect() } +#[allow(dead_code)] pub fn create_commit_task(data: &[u8]) -> CommitTask { static COMMIT_ID: AtomicU64 = AtomicU64::new(0); CommitTask { @@ -133,6 +137,7 @@ pub fn create_commit_task(data: &[u8]) -> CommitTask { } } +#[allow(dead_code)] pub fn create_committed_account(data: &[u8]) -> CommittedAccountV2 { CommittedAccountV2 { pubkey: Pubkey::new_unique(), diff --git a/magicblock-committor-service/tests/test_delivery_preparator.rs b/magicblock-committor-service/tests/test_delivery_preparator.rs index dd962ee76..92a7711e5 100644 --- a/magicblock-committor-service/tests/test_delivery_preparator.rs +++ b/magicblock-committor-service/tests/test_delivery_preparator.rs @@ -3,7 +3,6 @@ // ./magicblock-committor-program/bin/magicblock_committor_program.so use borsh::BorshDeserialize; -use futures_util::StreamExt; use magicblock_committor_program::Chunks; use magicblock_committor_service::{ persist::IntentPersisterImpl, @@ -80,7 +79,7 @@ async fn test_prepare_multiple_buffers() { let fixture = TestFixture::new().await; let preparator = fixture.create_delivery_preparator(); - let datas = vec![ + let datas = [ generate_random_bytes(10 * 1024), generate_random_bytes(10), generate_random_bytes(500 * 1024), @@ -152,7 +151,7 @@ async fn test_lookup_tables() { let fixture = TestFixture::new().await; let preparator = fixture.create_delivery_preparator(); - let datas = vec![ + let datas = [ generate_random_bytes(10), generate_random_bytes(20), generate_random_bytes(30), diff --git a/magicblock-committor-service/tests/test_transaction_preparator.rs b/magicblock-committor-service/tests/test_transaction_preparator.rs index 41466b1a6..62a3e2289 100644 --- a/magicblock-committor-service/tests/test_transaction_preparator.rs +++ b/magicblock-committor-service/tests/test_transaction_preparator.rs @@ -173,7 +173,6 @@ async fn test_prepare_finalize_tx_with_undelegate() { let preparator = fixture.create_transaction_preparator(); // Create test data - let rent_reimbursement = Pubkey::new_unique(); let l1_message = ScheduledBaseIntent { id: 1, slot: 0, @@ -207,7 +206,6 @@ async fn test_prepare_finalize_tx_with_undelegate_and_actions() { let preparator = fixture.create_transaction_preparator(); // Create test data - let rent_reimbursement = Pubkey::new_unique(); let l1_action = BaseAction { compute_units: 30_000, destination_program: system_program::id(), diff --git a/programs/magicblock/src/magic_scheduled_base_intent.rs b/programs/magicblock/src/magic_scheduled_base_intent.rs index 7b66b0082..ab59d65ab 100644 --- a/programs/magicblock/src/magic_scheduled_base_intent.rs +++ b/programs/magicblock/src/magic_scheduled_base_intent.rs @@ -62,14 +62,14 @@ pub struct ScheduledBaseIntent { } impl ScheduledBaseIntent { - pub fn try_new<'a>( + pub fn try_new( args: &MagicBaseIntentArgs, commit_id: u64, slot: Slot, payer_pubkey: &Pubkey, - context: &ConstructionContext<'a, '_>, + context: &ConstructionContext<'_, '_>, ) -> Result { - let action = MagicBaseIntent::try_from_args(args, &context)?; + let action = MagicBaseIntent::try_from_args(args, context)?; let blockhash = context.invoke_context.environment_config.blockhash; let action_sent_transaction = @@ -117,9 +117,9 @@ pub enum MagicBaseIntent { } impl MagicBaseIntent { - pub fn try_from_args<'a>( + pub fn try_from_args( args: &MagicBaseIntentArgs, - context: &ConstructionContext<'a, '_>, + context: &ConstructionContext<'_, '_>, ) -> Result { match args { MagicBaseIntentArgs::BaseActions(base_actions) => { @@ -193,9 +193,9 @@ pub struct CommitAndUndelegate { } impl CommitAndUndelegate { - pub fn try_from_args<'a>( + pub fn try_from_args( args: &CommitAndUndelegateArgs, - context: &ConstructionContext<'a, '_>, + context: &ConstructionContext<'_, '_>, ) -> Result { let commit_action = CommitType::try_from_args(&args.commit_type, context)?; @@ -260,9 +260,9 @@ pub struct BaseAction { } impl BaseAction { - pub fn try_from_args<'a>( + pub fn try_from_args( args: &BaseActionArgs, - context: &ConstructionContext<'a, '_>, + context: &ConstructionContext<'_, '_>, ) -> Result { let destination_program_pubkey = *get_instruction_pubkey_with_idx( context.transaction_context, @@ -352,9 +352,9 @@ pub enum CommitType { impl CommitType { // TODO: move to processor - fn validate_accounts<'a>( + fn validate_accounts( accounts: &[CommittedAccountRef], - context: &ConstructionContext<'a, '_>, + context: &ConstructionContext<'_, '_>, ) -> Result<(), InstructionError> { accounts.iter().try_for_each(|(pubkey, account)| { let owner = *account.borrow().owner(); @@ -412,9 +412,9 @@ impl CommitType { .collect::>() } - pub fn try_from_args<'a>( + pub fn try_from_args( args: &CommitTypeArgs, - context: &ConstructionContext<'a, '_>, + context: &ConstructionContext<'_, '_>, ) -> Result { match args { CommitTypeArgs::Standalone(accounts) => { @@ -513,9 +513,9 @@ pub enum UndelegateType { } impl UndelegateType { - pub fn try_from_args<'a>( + pub fn try_from_args( args: &UndelegateTypeArgs, - context: &ConstructionContext<'a, '_>, + context: &ConstructionContext<'_, '_>, ) -> Result { match args { UndelegateTypeArgs::Standalone => Ok(UndelegateType::Standalone), diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs b/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs index e02d09c93..704f74d12 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs @@ -161,7 +161,7 @@ fn get_parent_program_id( .map_or_else(|| "None".to_string(), |id| id.to_string()) ); - Ok(parent_program_id.map(Clone::clone)) + Ok(parent_program_id.copied()) } #[cfg(test)] @@ -180,5 +180,5 @@ fn get_parent_program_id( .borrow() .owner(); - Ok(Some(first_committee_owner.clone())) + Ok(Some(first_committee_owner)) } diff --git a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs index b7bb02ae0..b2e25827d 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs @@ -6,8 +6,8 @@ use crate::{ utils::account_actions::set_account_owner_to_delegation_program, }; -pub fn schedule_base_intent_processor<'a, 'ic>( - construction_context: &ConstructionContext<'a, 'ic>, +pub fn schedule_base_intent_processor( + construction_context: &ConstructionContext<'_, '_>, args: &MagicBaseIntentArgs, ) -> Result<(), InstructionError> { let commited_accounts_ref = match args { From d5836825f63c132d9bee41732bcd2a85cf1b7f63 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 6 Aug 2025 18:09:19 +0900 Subject: [PATCH 167/199] fix: compilation --- magicblock-api/src/tickers.rs | 2 +- .../tests/ix_commit_local.rs | 105 ++---------------- .../test-tools/src/conversions.rs | 2 - 3 files changed, 9 insertions(+), 100 deletions(-) diff --git a/magicblock-api/src/tickers.rs b/magicblock-api/src/tickers.rs index 4a72ab908..fef4bdc85 100644 --- a/magicblock-api/src/tickers.rs +++ b/magicblock-api/src/tickers.rs @@ -76,7 +76,7 @@ async fn handle_scheduled_commits( // to the global ScheduledCommit store let tx = InstructionUtils::accept_scheduled_commits(bank.last_blockhash()); if let Err(err) = - execute_legacy_transaction(tx, &bank, Some(transaction_status_sender)) + execute_legacy_transaction(tx, bank, Some(transaction_status_sender)) { error!("Failed to accept scheduled commits: {:?}", err); return; diff --git a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs index 3ebc30251..6da3f2847 100644 --- a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs +++ b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs @@ -1,14 +1,13 @@ use log::*; -use magicblock_committor_service::{BaseIntentCommittor, ComputeBudgetConfig}; +use magicblock_committor_service::{ComputeBudgetConfig}; use magicblock_rpc_client::MagicblockRpcClient; -use std::collections::{HashMap, HashSet}; +use std::collections::{HashSet}; use std::sync::{Arc, Once}; use std::time::{Duration, Instant}; use test_tools_core::init_logger; use tokio::task::JoinSet; use utils::transactions::tx_logs_contain; -use magicblock_committor_program::{ChangedAccount, Changeset}; use magicblock_committor_service::service_ext::{ BaseIntentCommittorExt, CommittorServiceExt, }; @@ -17,14 +16,13 @@ use magicblock_committor_service::types::{ }; use magicblock_committor_service::{ config::ChainConfig, - persist::{CommitStatus, CommitStrategy}, CommittorService, }; use magicblock_program::magic_scheduled_base_intent::{ CommitAndUndelegate, CommitType, CommittedAccountV2, MagicBaseIntent, ScheduledBaseIntent, UndelegateType, }; -use solana_account::{Account, AccountSharedData, ReadableAccount}; +use solana_account::{Account, ReadableAccount}; use solana_pubkey::Pubkey; use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_rpc_client_api::config::RpcSendTransactionConfig; @@ -45,17 +43,6 @@ mod utils; // ----------------- // Utilities and Setup // ----------------- -type ExpectedStrategies = HashMap; - -fn expect_strategies( - strategies: &[(CommitStrategy, u8)], -) -> ExpectedStrategies { - let mut expected_strategies = HashMap::new(); - for (strategy, count) in strategies { - *expected_strategies.entry(*strategy).or_insert(0) += count; - } - expected_strategies -} fn ensure_validator_authority() -> Keypair { static ONCE: Once = Once::new(); @@ -68,10 +55,6 @@ fn ensure_validator_authority() -> Keypair { validator_authority() } -fn uses_lookup(expected: &ExpectedStrategies) -> bool { - expected.iter().any(|(strategy, _)| strategy.uses_lookup()) -} - macro_rules! get_account { ($rpc_client:ident, $pubkey:expr, $label:literal, $predicate:expr) => {{ const GET_ACCOUNT_RETRIES: u8 = 12; @@ -333,8 +316,6 @@ async fn commit_single_account(bytes: usize, undelegate: bool) { }; let intent = ScheduledBaseIntentWrapper { - excluded_pubkeys: vec![], - feepayers: vec![], trigger_type: TriggerType::OnChain, inner: ScheduledBaseIntent { id: 0, @@ -360,8 +341,6 @@ async fn test_ix_commit_two_accounts_1kb_2kb() { init_logger!(); commit_multiple_accounts( &[1024, 2048], - 1, - expect_strategies(&[(CommitStrategy::FromBuffer, 2)]), false, ) .await; @@ -372,8 +351,6 @@ async fn test_ix_commit_two_accounts_512kb() { init_logger!(); commit_multiple_accounts( &[512, 512], - 1, - expect_strategies(&[(CommitStrategy::Args, 2)]), false, ) .await; @@ -384,8 +361,6 @@ async fn test_ix_commit_three_accounts_512kb() { init_logger!(); commit_multiple_accounts( &[512, 512, 512], - 1, - expect_strategies(&[(CommitStrategy::Args, 3)]), false, ) .await; @@ -396,8 +371,6 @@ async fn test_ix_commit_six_accounts_512kb() { init_logger!(); commit_multiple_accounts( &[512, 512, 512, 512, 512, 512], - 1, - expect_strategies(&[(CommitStrategy::Args, 6)]), false, ) .await; @@ -408,8 +381,6 @@ async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() { init_logger!(); commit_multiple_accounts( &[1024, 2 * 1024, 5 * 1024, 10 * 1024], - 1, - expect_strategies(&[(CommitStrategy::FromBuffer, 4)]), false, ) .await; @@ -418,8 +389,6 @@ async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() { #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_2() { commit_20_accounts_1kb( - 2, - expect_strategies(&[(CommitStrategy::FromBuffer, 20)]), ) .await; } @@ -427,8 +396,6 @@ async fn test_commit_20_accounts_1kb_bundle_size_2() { #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_3() { commit_5_accounts_1kb( - 3, - expect_strategies(&[(CommitStrategy::FromBuffer, 5)]), false, ) .await; @@ -437,8 +404,6 @@ async fn test_commit_5_accounts_1kb_bundle_size_3() { #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() { commit_5_accounts_1kb( - 3, - expect_strategies(&[(CommitStrategy::FromBuffer, 5)]), true, ) .await; @@ -447,11 +412,6 @@ async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() { #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_4() { commit_5_accounts_1kb( - 4, - expect_strategies(&[ - (CommitStrategy::FromBuffer, 1), - (CommitStrategy::FromBufferWithLookupTable, 4), - ]), false, ) .await; @@ -460,11 +420,6 @@ async fn test_commit_5_accounts_1kb_bundle_size_4() { #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() { commit_5_accounts_1kb( - 4, - expect_strategies(&[ - (CommitStrategy::FromBuffer, 1), - (CommitStrategy::FromBufferWithLookupTable, 4), - ]), true, ) .await; @@ -473,8 +428,6 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() { #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_3() { commit_20_accounts_1kb( - 3, - expect_strategies(&[(CommitStrategy::FromBuffer, 20)]), ) .await; } @@ -482,8 +435,6 @@ async fn test_commit_20_accounts_1kb_bundle_size_3() { #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_4() { commit_20_accounts_1kb( - 4, - expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]), ) .await; } @@ -491,81 +442,51 @@ async fn test_commit_20_accounts_1kb_bundle_size_4() { #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_6() { commit_20_accounts_1kb( - 6, - expect_strategies(&[ - (CommitStrategy::FromBufferWithLookupTable, 18), - // Two accounts don't make it into the bundles of size 6 - (CommitStrategy::FromBuffer, 2), - ]), ) .await; } #[tokio::test] async fn test_commit_8_accounts_1kb_bundle_size_8() { - commit_8_accounts_1kb( - 8, - expect_strategies(&[ - // Four accounts don't make it into the bundles of size 8, but - // that bundle also needs lookup tables - (CommitStrategy::FromBufferWithLookupTable, 8), - ]), - ) + commit_8_accounts_1kb() .await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_8() { - commit_20_accounts_1kb( - 8, - expect_strategies(&[ - // Four accounts don't make it into the bundles of size 8, but - // that bundle also needs lookup tables - (CommitStrategy::FromBufferWithLookupTable, 20), - ]), - ) + commit_20_accounts_1kb() .await; } async fn commit_5_accounts_1kb( - bundle_size: usize, - expected_strategies: ExpectedStrategies, undelegate_all: bool, ) { init_logger!(); let accs = (0..5).map(|_| 1024).collect::>(); commit_multiple_accounts( &accs, - bundle_size, - expected_strategies, undelegate_all, ) .await; } async fn commit_8_accounts_1kb( - bundle_size: usize, - expected_strategies: ExpectedStrategies, ) { init_logger!(); let accs = (0..8).map(|_| 1024).collect::>(); - commit_multiple_accounts(&accs, bundle_size, expected_strategies, false) + commit_multiple_accounts(&accs, false) .await; } async fn commit_20_accounts_1kb( - bundle_size: usize, - expected_strategies: ExpectedStrategies, ) { init_logger!(); let accs = (0..20).map(|_| 1024).collect::>(); - commit_multiple_accounts(&accs, bundle_size, expected_strategies, false) + commit_multiple_accounts(&accs, false) .await; } async fn commit_multiple_accounts( bytess: &[usize], - bundle_size: usize, - expected_strategies: ExpectedStrategies, undelegate_all: bool, ) { init_logger!(); @@ -586,15 +507,9 @@ async fn commit_multiple_accounts( bytess.iter().map(|_| Keypair::new()).collect::>(); let mut join_set = JoinSet::new(); - let mut bundle_id = 0; - for (idx, (bytes, counter_auth)) in bytess.iter().zip(committees.into_iter()).enumerate() { - if idx % bundle_size == 0 { - bundle_id += 1; - } - let bytes = *bytes; join_set.spawn(async move { let (pda, mut pda_acc) = init_and_delegate_account_on_chain( @@ -606,7 +521,7 @@ async fn commit_multiple_accounts( pda_acc.owner = program_flexi_counter::id(); pda_acc.data = vec![idx as u8; bytes]; - let request_undelegation = (undelegate_all || idx % 2 == 0); + let request_undelegation = undelegate_all || idx % 2 == 0; (pda, pda_acc, request_undelegation) }); } @@ -627,8 +542,6 @@ async fn commit_multiple_accounts( if !committed_accounts.is_empty() { let commit_intent = ScheduledBaseIntentWrapper { - excluded_pubkeys: vec![], - feepayers: vec![], trigger_type: TriggerType::OnChain, inner: ScheduledBaseIntent { id: 0, @@ -655,8 +568,6 @@ async fn commit_multiple_accounts( if !committed_and_undelegated_accounts.is_empty() { let commit_and_undelegate_intent = ScheduledBaseIntentWrapper { - excluded_pubkeys: vec![], - feepayers: vec![], trigger_type: TriggerType::OnChain, inner: ScheduledBaseIntent { id: 1, diff --git a/test-integration/test-tools/src/conversions.rs b/test-integration/test-tools/src/conversions.rs index 01e08e785..389d404e1 100644 --- a/test-integration/test-tools/src/conversions.rs +++ b/test-integration/test-tools/src/conversions.rs @@ -1,6 +1,4 @@ -use magicblock_core::magic_program; use solana_rpc_client_api::client_error; -use solana_sdk::pubkey::Pubkey; pub fn get_rpc_transwise_error_msg(err: &anyhow::Error) -> Option { err.source() From 31a94ea34aac92f6b24c3f5453c1777643631033 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 6 Aug 2025 18:20:48 +0900 Subject: [PATCH 168/199] fix: unit tests --- magicblock-committor-service/src/tasks/task_strategist.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index f971e0848..b8600ec99 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -399,12 +399,13 @@ mod tests { #[test] fn test_optimize_strategy_prioritizes_largest_tasks() { - let tasks = [ + let mut tasks = [ Box::new(create_test_commit_task(1, 100)) as Box, Box::new(create_test_commit_task(2, 1000)) as Box, // Larger task Box::new(create_test_commit_task(3, 1000)) as Box, // Larger task ]; + let _ = TaskStrategist::optimize_strategy(&mut tasks); // The larger task should have been optimized first assert!(matches!(tasks[0].strategy(), TaskStrategy::Args)); assert!(matches!(tasks[1].strategy(), TaskStrategy::Buffer)); From 4bad7a5047d66539b252581cb9e4b75eba7efa26 Mon Sep 17 00:00:00 2001 From: Arthur Bretas <158767751+BretasArthur1@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:05:25 -0300 Subject: [PATCH 169/199] feat: Add validator fee claiming (#475) Implements fee claiming on validator startup, closes #303. - Adds `claim_fees method` to build/send delegation program's ValidatorClaimFees instruction - Added integration test `test_validator_claim_fees` --------- Co-authored-by: Dodecahedr0x --- Cargo.lock | 24 ++ Cargo.toml | 2 + magicblock-api/Cargo.toml | 2 + magicblock-api/src/errors.rs | 2 +- magicblock-api/src/magic_validator.rs | 7 + magicblock-config/src/lib.rs | 4 + magicblock-config/src/validator.rs | 20 ++ magicblock-validator-admin/Cargo.toml | 26 ++ magicblock-validator-admin/src/claim_fees.rs | 109 +++++++ .../src/external_config.rs | 41 +++ magicblock-validator-admin/src/lib.rs | 2 + test-integration/Cargo.lock | 27 ++ test-integration/configs/claim-fees-test.toml | 22 ++ .../test-magicblock-api/Cargo.toml | 9 +- .../tests/test_validator_claim_fees.rs | 288 ++++++++++++++++++ 15 files changed, 580 insertions(+), 5 deletions(-) create mode 100644 magicblock-validator-admin/Cargo.toml create mode 100644 magicblock-validator-admin/src/claim_fees.rs create mode 100644 magicblock-validator-admin/src/external_config.rs create mode 100644 magicblock-validator-admin/src/lib.rs create mode 100644 test-integration/configs/claim-fees-test.toml create mode 100644 test-integration/test-magicblock-api/tests/test_validator_claim_fees.rs diff --git a/Cargo.lock b/Cargo.lock index fda98f74c..109b926cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3988,6 +3988,7 @@ dependencies = [ "magicblock-committor-service", "magicblock-config", "magicblock-core", + "magicblock-delegation-program", "magicblock-geyser-plugin", "magicblock-ledger", "magicblock-metrics", @@ -3997,6 +3998,7 @@ dependencies = [ "magicblock-pubsub", "magicblock-rpc", "magicblock-transaction-status", + "magicblock-validator-admin", "paste", "solana-geyser-plugin-manager", "solana-rpc", @@ -4431,6 +4433,25 @@ dependencies = [ "tokio", ] +[[package]] +name = "magicblock-validator-admin" +version = "0.1.7" +dependencies = [ + "anyhow", + "log", + "magicblock-accounts", + "magicblock-config", + "magicblock-delegation-program", + "magicblock-program", + "magicblock-rpc-client", + "solana-rpc-client", + "solana-sdk", + "thiserror 1.0.69", + "tokio", + "tokio-util 0.7.15", + "url 2.5.4", +] + [[package]] name = "magicblock-version" version = "0.1.7" @@ -11190,7 +11211,10 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", + "futures-util", + "hashbrown 0.15.4", "pin-project-lite", + "slab", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 2c3a104dc..c99c9e1c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ members = [ "magicblock-transaction-status", "magicblock-validator", "magicblock-version", + "magicblock-validator-admin", "test-tools", "test-tools-core", "utils/expiring-hashmap", @@ -132,6 +133,7 @@ magicblock-rpc-client = { path = "./magicblock-rpc-client" } magicblock-table-mania = { path = "./magicblock-table-mania" } magicblock-tokens = { path = "./magicblock-tokens" } magicblock-transaction-status = { path = "./magicblock-transaction-status" } +magicblock-validator-admin = { path = "./magicblock-validator-admin" } magicblock-version = { path = "./magicblock-version" } num-derive = "0.4" num-format = "0.4.4" diff --git a/magicblock-api/Cargo.toml b/magicblock-api/Cargo.toml index 5687eb0ff..0e647753c 100644 --- a/magicblock-api/Cargo.toml +++ b/magicblock-api/Cargo.toml @@ -35,6 +35,7 @@ magicblock-program = { workspace = true } magicblock-pubsub = { workspace = true } magicblock-rpc = { workspace = true } magicblock-transaction-status = { workspace = true } +magicblock-validator-admin = { workspace = true } magic-domain-program = { workspace = true } solana-geyser-plugin-interface = { workspace = true } solana-rpc-client = { workspace = true } @@ -46,6 +47,7 @@ tempfile = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true } tokio-util = { workspace = true } +magicblock-delegation-program = { workspace = true } libloading = "0.7.4" borsh = "1.5.3" diff --git a/magicblock-api/src/errors.rs b/magicblock-api/src/errors.rs index 0404bb374..4edbbf888 100644 --- a/magicblock-api/src/errors.rs +++ b/magicblock-api/src/errors.rs @@ -89,5 +89,5 @@ pub enum ApiError { #[error("Accounts Database couldn't be initialized" )] - AccountsDbError(#[from] AccountsDbError) + AccountsDbError(#[from] AccountsDbError), } diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 1a2cab707..e6d34b9ad 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -64,6 +64,7 @@ use magicblock_rpc::{ use magicblock_transaction_status::{ TransactionStatusMessage, TransactionStatusSender, }; +use magicblock_validator_admin::claim_fees::ClaimFeesTask; use mdp::state::{ features::FeaturesSet, record::{CountryCode, ErRecord}, @@ -168,6 +169,7 @@ pub struct MagicValidator { geyser_rpc_service: Arc, pubsub_config: PubsubConfig, pub transaction_status_sender: TransactionStatusSender, + claim_fees_task: ClaimFeesTask, } impl MagicValidator { @@ -415,6 +417,7 @@ impl MagicValidator { accounts_manager, transaction_listener, transaction_status_sender, + claim_fees_task: ClaimFeesTask::new(), }) } @@ -709,6 +712,8 @@ impl MagicValidator { self.maybe_process_ledger()?; + self.claim_fees_task.start(self.config.clone()); + self.transaction_listener.run(true, self.bank.clone()); self.slot_ticker = Some(init_slot_ticker( @@ -850,6 +855,8 @@ impl MagicValidator { self.token.cancel(); self.ledger_truncator.stop(); + self.claim_fees_task.stop(); + // wait a bit for services to stop thread::sleep(Duration::from_secs(1)); diff --git a/magicblock-config/src/lib.rs b/magicblock-config/src/lib.rs index 7d58d3e7e..d256ed81a 100644 --- a/magicblock-config/src/lib.rs +++ b/magicblock-config/src/lib.rs @@ -240,6 +240,7 @@ mod tests { fqdn: Some("validator.example.com".to_string()), base_fees: Some(1000000000), country_code: CountryCode::for_alpha2("FR").unwrap(), + claim_fees_interval_secs: DEFAULT_CLAIM_FEES_INTERVAL_SECS, }, ledger: LedgerConfig { resume_strategy: LedgerResumeStrategy::Replay, @@ -320,6 +321,7 @@ mod tests { fqdn: Some("validator.example.com".to_string()), base_fees: Some(1000000000), country_code: CountryCode::for_alpha2("FR").unwrap(), + claim_fees_interval_secs: DEFAULT_CLAIM_FEES_INTERVAL_SECS, }, ledger: LedgerConfig { resume_strategy: LedgerResumeStrategy::Replay, @@ -397,6 +399,7 @@ mod tests { fqdn: Some("validator2.example.com".to_string()), base_fees: Some(9999), country_code: CountryCode::for_alpha2("DE").unwrap(), + claim_fees_interval_secs: DEFAULT_CLAIM_FEES_INTERVAL_SECS, }, ledger: LedgerConfig { resume_strategy: LedgerResumeStrategy::ResumeOnly, @@ -467,6 +470,7 @@ mod tests { fqdn: Some("validator.example.com".to_string()), base_fees: Some(1000000000), country_code: CountryCode::for_alpha2("FR").unwrap(), + claim_fees_interval_secs: DEFAULT_CLAIM_FEES_INTERVAL_SECS, }, ledger: LedgerConfig { resume_strategy: LedgerResumeStrategy::Replay, diff --git a/magicblock-config/src/validator.rs b/magicblock-config/src/validator.rs index 5440a5415..895758eb2 100644 --- a/magicblock-config/src/validator.rs +++ b/magicblock-config/src/validator.rs @@ -3,6 +3,8 @@ use isocountry::CountryCode; use magicblock_config_macro::{clap_from_serde, clap_prefix, Mergeable}; use serde::{Deserialize, Serialize}; +pub const DEFAULT_CLAIM_FEES_INTERVAL_SECS: u64 = 3600; + #[clap_prefix("validator")] #[clap_from_serde] #[derive( @@ -46,6 +48,15 @@ pub struct ValidatorConfig { )] #[serde(default = "default_country_code")] pub country_code: CountryCode, + + /// The interval in seconds at which the validator will claim fees. + /// default: 3600 (1 hour) + #[derive_env_var] + #[arg( + help = "The interval in seconds at which the validator will claim fees." + )] + #[serde(default = "default_claim_fees_interval_secs")] + pub claim_fees_interval_secs: u64, } impl Default for ValidatorConfig { @@ -56,6 +67,7 @@ impl Default for ValidatorConfig { fqdn: default_fqdn(), base_fees: default_base_fees(), country_code: default_country_code(), + claim_fees_interval_secs: default_claim_fees_interval_secs(), } } } @@ -80,6 +92,10 @@ fn default_country_code() -> CountryCode { CountryCode::for_alpha2("US").unwrap() } +fn default_claim_fees_interval_secs() -> u64 { + DEFAULT_CLAIM_FEES_INTERVAL_SECS +} + fn parse_country_code(s: &str) -> Result { if let Ok(code) = CountryCode::for_alpha2(s) { Ok(code) @@ -104,6 +120,7 @@ mod tests { fqdn: Some("validator.example.com".to_string()), base_fees: Some(1000000000), country_code: CountryCode::for_alpha2("FR").unwrap(), + claim_fees_interval_secs: DEFAULT_CLAIM_FEES_INTERVAL_SECS, }; let original_config = config.clone(); let other = ValidatorConfig::default(); @@ -122,6 +139,7 @@ mod tests { fqdn: Some("validator.example.com".to_string()), base_fees: Some(1000000000), country_code: CountryCode::for_alpha2("FR").unwrap(), + claim_fees_interval_secs: DEFAULT_CLAIM_FEES_INTERVAL_SECS, }; config.merge(other.clone()); @@ -137,6 +155,7 @@ mod tests { fqdn: Some("validator2.example.com".to_string()), base_fees: Some(9999), country_code: CountryCode::for_alpha2("DE").unwrap(), + claim_fees_interval_secs: DEFAULT_CLAIM_FEES_INTERVAL_SECS, }; let original_config = config.clone(); let other = ValidatorConfig { @@ -145,6 +164,7 @@ mod tests { fqdn: Some("validator.example.com".to_string()), base_fees: Some(1000000000), country_code: CountryCode::for_alpha2("FR").unwrap(), + claim_fees_interval_secs: DEFAULT_CLAIM_FEES_INTERVAL_SECS, }; config.merge(other); diff --git a/magicblock-validator-admin/Cargo.toml b/magicblock-validator-admin/Cargo.toml new file mode 100644 index 000000000..731095c92 --- /dev/null +++ b/magicblock-validator-admin/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "magicblock-validator-admin" +version.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true +license.workspace = true +edition.workspace = true + +[dependencies] +anyhow = { workspace = true } +log = { workspace = true } +thiserror = { workspace = true } +url = { workspace = true } +magicblock-accounts = { workspace = true } + +magicblock-config = { workspace = true } +magicblock-delegation-program = { workspace = true } +magicblock-program = { workspace = true } +magicblock-rpc-client = { workspace = true } + + +solana-rpc-client = { workspace = true } +solana-sdk = { workspace = true } +tokio = { workspace = true, features = ["full"] } +tokio-util = { workspace = true, features = ["full"] } diff --git a/magicblock-validator-admin/src/claim_fees.rs b/magicblock-validator-admin/src/claim_fees.rs new file mode 100644 index 000000000..e9bf0f642 --- /dev/null +++ b/magicblock-validator-admin/src/claim_fees.rs @@ -0,0 +1,109 @@ +use std::time::Duration; + +use dlp::instruction_builder::validator_claim_fees; +use log::{error, info}; +use magicblock_config::EphemeralConfig; +use magicblock_program::validator::validator_authority; +use magicblock_rpc_client::MagicBlockRpcClientError; +use solana_rpc_client::nonblocking::rpc_client::RpcClient; +use solana_sdk::{ + commitment_config::CommitmentConfig, signature::Signer, + transaction::Transaction, +}; +use tokio::task::JoinHandle; +use tokio_util::sync::CancellationToken; + +use crate::external_config::cluster_from_remote; + +pub struct ClaimFeesTask { + pub handle: Option>, + token: CancellationToken, +} + +impl ClaimFeesTask { + pub fn new() -> Self { + Self { + handle: None, + token: CancellationToken::new(), + } + } + + pub fn start(&mut self, config: EphemeralConfig) { + if self.handle.is_some() { + error!("Claim fees task already started"); + return; + } + + let token = self.token.clone(); + let handle = tokio::spawn(async move { + info!("Starting claim fees task"); + let mut interval = tokio::time::interval(Duration::from_secs( + config.validator.claim_fees_interval_secs, + )); + loop { + tokio::select! { + _ = interval.tick() => { + if let Err(err) = claim_fees(config.clone()).await { + error!("Failed to claim fees: {:?}", err); + } + }, + _ = token.cancelled() => break, + } + } + info!("Claim fees task stopped"); + }); + self.handle = Some(handle); + } + + pub fn stop(&mut self) { + if let Some(handle) = self.handle.take() { + info!("Stopping claim fees task"); + self.token.cancel(); + handle.abort(); + } + } +} + +impl Default for ClaimFeesTask { + fn default() -> Self { + Self::new() + } +} + +async fn claim_fees( + config: EphemeralConfig, +) -> Result<(), MagicBlockRpcClientError> { + info!("Claiming validator fees"); + + let url = cluster_from_remote(&config.accounts.remote); + let rpc_client = RpcClient::new_with_commitment( + url.url().to_string(), + CommitmentConfig::confirmed(), + ); + + let keypair_ref = &validator_authority(); + let validator = keypair_ref.pubkey(); + + let ix = validator_claim_fees(validator, None); + + let latest_blockhash = rpc_client + .get_latest_blockhash() + .await + .map_err(MagicBlockRpcClientError::GetLatestBlockhash)?; + + let tx = Transaction::new_signed_with_payer( + &[ix], + Some(&validator), + &[keypair_ref], + latest_blockhash, + ); + + rpc_client + .send_and_confirm_transaction(&tx) + .await + .map_err(MagicBlockRpcClientError::SendTransaction)?; + + info!("Successfully claimed validator fees"); + + Ok(()) +} diff --git a/magicblock-validator-admin/src/external_config.rs b/magicblock-validator-admin/src/external_config.rs new file mode 100644 index 000000000..8dd32d365 --- /dev/null +++ b/magicblock-validator-admin/src/external_config.rs @@ -0,0 +1,41 @@ +use magicblock_accounts::Cluster; +use solana_sdk::genesis_config::ClusterType; + +pub(crate) fn cluster_from_remote( + remote: &magicblock_config::RemoteConfig, +) -> Cluster { + use magicblock_config::RemoteCluster::*; + + match remote.cluster { + Devnet => Cluster::Known(ClusterType::Devnet), + Mainnet => Cluster::Known(ClusterType::MainnetBeta), + Testnet => Cluster::Known(ClusterType::Testnet), + Development => Cluster::Known(ClusterType::Development), + Custom => Cluster::Custom( + remote.url.clone().expect("Custom remote must have a url"), + ), + CustomWithWs => Cluster::CustomWithWs( + remote + .url + .clone() + .expect("CustomWithWs remote must have a url"), + remote + .ws_url + .clone() + .expect("CustomWithWs remote must have a ws_url") + .first() + .expect("CustomWithWs remote must have at least one ws_url") + .clone(), + ), + CustomWithMultipleWs => Cluster::CustomWithMultipleWs { + http: remote + .url + .clone() + .expect("CustomWithMultipleWs remote must have a url"), + ws: remote + .ws_url + .clone() + .expect("CustomWithMultipleWs remote must have a ws_url"), + }, + } +} diff --git a/magicblock-validator-admin/src/lib.rs b/magicblock-validator-admin/src/lib.rs new file mode 100644 index 000000000..1ac233fb3 --- /dev/null +++ b/magicblock-validator-admin/src/lib.rs @@ -0,0 +1,2 @@ +pub mod claim_fees; +pub mod external_config; diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 883f9054d..e93b37fa8 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -3730,6 +3730,7 @@ dependencies = [ "magicblock-committor-service", "magicblock-config", "magicblock-core", + "magicblock-delegation-program", "magicblock-geyser-plugin", "magicblock-ledger", "magicblock-metrics", @@ -3739,6 +3740,7 @@ dependencies = [ "magicblock-pubsub", "magicblock-rpc", "magicblock-transaction-status", + "magicblock-validator-admin", "paste", "solana-geyser-plugin-manager", "solana-rpc", @@ -4130,6 +4132,25 @@ dependencies = [ "solana-transaction-status", ] +[[package]] +name = "magicblock-validator-admin" +version = "0.1.7" +dependencies = [ + "anyhow", + "log", + "magicblock-accounts", + "magicblock-config", + "magicblock-delegation-program", + "magicblock-program", + "magicblock-rpc-client", + "solana-rpc-client", + "solana-sdk", + "thiserror 1.0.69", + "tokio", + "tokio-util 0.7.15", + "url 2.5.4", +] + [[package]] name = "magicblock-version" version = "0.1.7" @@ -10359,6 +10380,9 @@ dependencies = [ "magic-domain-program", "magicblock-api", "magicblock-config", + "magicblock-delegation-program", + "magicblock-program", + "magicblock-validator-admin", "solana-rpc-client", "solana-rpc-client-api", "solana-sdk", @@ -10645,7 +10669,10 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", + "futures-util", + "hashbrown 0.15.4", "pin-project-lite", + "slab", "tokio", ] diff --git a/test-integration/configs/claim-fees-test.toml b/test-integration/configs/claim-fees-test.toml new file mode 100644 index 000000000..e5831fb7e --- /dev/null +++ b/test-integration/configs/claim-fees-test.toml @@ -0,0 +1,22 @@ +[accounts] +remote.cluster = "devnet" +lifecycle = "offline" +commit = { frequency_millis = 9_000_000_000_000, compute_unit_price = 1_000_000 } + +[accounts.db] +db-size = 1048576000 +block-size = "block256" +index-map-size = 2048576 +max-snapshots = 7 +snapshot-frequency = 1024 + +[validator] +millis_per_slot = 50 +sigverify = true + +[[program]] +id = "DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh" +path = "../schedulecommit/elfs/dlp.so" + +[rpc] +port = 7799 diff --git a/test-integration/test-magicblock-api/Cargo.toml b/test-integration/test-magicblock-api/Cargo.toml index 18ea7cf59..b0e4e4bfb 100644 --- a/test-integration/test-magicblock-api/Cargo.toml +++ b/test-integration/test-magicblock-api/Cargo.toml @@ -2,19 +2,20 @@ name = "test-magicblock-api" version.workspace = true edition.workspace = true - [dependencies] integration-test-tools = { workspace = true } - [dev-dependencies] cleanass = { workspace = true } magicblock-api = { workspace = true } magicblock-config = { workspace = true } -tokio = { workspace = true } -lazy_static = { workspace = true } +magicblock-delegation-program = { workspace = true } +magicblock-program = { path = "../../programs/magicblock" } +magicblock-validator-admin = { path = "../../magicblock-validator-admin" } magic-domain-program = { workspace = true } solana-rpc-client = { workspace = true } solana-rpc-client-api = { workspace = true } solana-sdk = { workspace = true } solana-transaction-status = { workspace = true } +tokio = { workspace = true } +lazy_static = { workspace = true } isocountry = { workspace = true } diff --git a/test-integration/test-magicblock-api/tests/test_validator_claim_fees.rs b/test-integration/test-magicblock-api/tests/test_validator_claim_fees.rs new file mode 100644 index 000000000..60f9a8b5c --- /dev/null +++ b/test-integration/test-magicblock-api/tests/test_validator_claim_fees.rs @@ -0,0 +1,288 @@ +use dlp::instruction_builder::{ + init_validator_fees_vault, validator_claim_fees, +}; +use integration_test_tools::validator::{ + start_test_validator_with_config, TestRunnerPaths, +}; +use integration_test_tools::{ + loaded_accounts::LoadedAccounts, IntegrationTestContext, +}; +use lazy_static::lazy_static; +use magicblock_program::validator; +use magicblock_validator_admin::claim_fees::ClaimFeesTask; +use solana_rpc_client::rpc_client::RpcClient; +use solana_sdk::{ + commitment_config::CommitmentConfig, + signature::{Keypair, Signer}, + transaction::Transaction, +}; +use std::path::PathBuf; +use std::process::Child; +use std::sync::Arc; +use std::thread::sleep; +use std::time::Duration; + +// Test constants +const DEVNET_URL: &str = "http://127.0.0.1:7799"; +const TEST_FEE_AMOUNT: u64 = 1_000_000; +const INITIAL_AIRDROP_AMOUNT: u64 = 5_000_000_000; +const CONFIRMATION_WAIT_MS: u64 = 500; +const SETUP_WAIT_MS: u64 = 1000; + +lazy_static! { + static ref VALIDATOR_KEYPAIR: Arc = Arc::new({ + let loaded_accounts = + LoadedAccounts::with_delegation_program_test_authority(); + loaded_accounts + .validator_authority_keypair() + .insecure_clone() + }); +} + +/// Test that claim fees instruction +fn test_claim_fees_instruction() { + println!("Testing claim fees instruction creation..."); + + let validator_pubkey = VALIDATOR_KEYPAIR.pubkey(); + let instruction = validator_claim_fees(validator_pubkey, None); + + assert!( + !instruction.accounts.is_empty(), + "Instruction should have accounts" + ); + assert_eq!( + instruction.program_id, + dlp::id(), + "Instruction should target delegation program" + ); + + println!("✓ Claim fees instruction created successfully"); +} + +/// Initialize the validator fees vault +fn test_init_validator_fees_vault() { + println!("Testing validator fees vault initialization..."); + + let rpc_client = RpcClient::new_with_commitment( + DEVNET_URL, + CommitmentConfig::confirmed(), + ); + + let validator_keypair = validator::validator_authority(); + let validator_pubkey = validator_keypair.pubkey(); + + let init_instruction = init_validator_fees_vault( + validator_pubkey, + validator_pubkey, + validator_pubkey, + ); + + let blockhash = rpc_client.get_latest_blockhash().unwrap(); + let transaction = Transaction::new_signed_with_payer( + &[init_instruction], + Some(&validator_pubkey), + &[&validator_keypair], + blockhash, + ); + + rpc_client + .send_and_confirm_transaction(&transaction) + .unwrap(); + println!("✓ Successfully initialized validator fees vault!"); +} + +/// Add test fees to the vault +fn test_add_fees_to_vault() { + println!("Adding test fees to vault..."); + + let rpc_client = RpcClient::new_with_commitment( + DEVNET_URL, + CommitmentConfig::confirmed(), + ); + + let loaded_accounts = + LoadedAccounts::with_delegation_program_test_authority(); + let validator_fees_vault = loaded_accounts.validator_fees_vault(); + + println!(" Target vault: {}", validator_fees_vault); + + rpc_client + .request_airdrop(&validator_fees_vault, TEST_FEE_AMOUNT) + .unwrap(); + sleep(Duration::from_millis(SETUP_WAIT_MS)); + + let balance = rpc_client.get_balance(&validator_fees_vault).unwrap(); + assert!( + balance >= TEST_FEE_AMOUNT, + "Vault should have at least the test fee amount" + ); + println!("✓ Added {} lamports test fees to vault", TEST_FEE_AMOUNT); +} + +/// Test the ClaimFeesTask struct +fn test_claim_fees_task() { + println!("Testing ClaimFeesTask struct..."); + + + let task = ClaimFeesTask::new(); + + // Test that the task starts in the correct state + assert!(task.handle.is_none(), "Task should start with no handle"); + + println!("✓ ClaimFeesTask created successfully"); + + + let default_task = ClaimFeesTask::default(); + assert!( + default_task.handle.is_none(), + "Default task should have no handle" + ); + + println!("✓ ClaimFeesTask default implementation works"); +} + +/// Test the actual fee claiming transaction +fn test_claim_fees_transaction() { + println!("Testing actual claim fees transaction..."); + + let rpc_client = RpcClient::new_with_commitment( + DEVNET_URL, + CommitmentConfig::confirmed(), + ); + + let validator_keypair = validator::validator_authority(); + let validator_pubkey = validator_keypair.pubkey(); + + let loaded_accounts = + LoadedAccounts::with_delegation_program_test_authority(); + let validator_fees_vault = loaded_accounts.validator_fees_vault(); + + println!(" Validator: {}", validator_pubkey); + println!(" Fees vault: {}", validator_fees_vault); + + let balance_before = rpc_client.get_balance(&validator_fees_vault).unwrap(); + let instruction = validator_claim_fees(validator_pubkey, None); + let blockhash = rpc_client.get_latest_blockhash().unwrap(); + let transaction = Transaction::new_signed_with_payer( + &[instruction], + Some(&validator_pubkey), + &[&validator_keypair], + blockhash, + ); + + rpc_client + .send_and_confirm_transaction(&transaction) + .unwrap(); + sleep(Duration::from_millis(CONFIRMATION_WAIT_MS)); + + let balance_after = rpc_client.get_balance(&validator_fees_vault).unwrap(); + let vault_difference = balance_before.saturating_sub(balance_after); + + println!( + "✓ Successfully claimed {} lamports in fees!", + vault_difference + ); + assert!(vault_difference > 0, "Should have claimed some fees"); +} + +/// Test RPC connectivity for fee claiming operations +fn test_claim_fees_rpc_connection() { + println!("Testing RPC connection..."); + + let rpc_client = RpcClient::new_with_commitment( + DEVNET_URL, + CommitmentConfig::confirmed(), + ); + + rpc_client.get_latest_blockhash().unwrap(); + println!("✓ RPC connection successful"); +} + +struct TestValidator { + process: Child, +} + +impl TestValidator { + fn start() -> Self { + let manifest_dir_raw = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + let manifest_dir = PathBuf::from(&manifest_dir_raw); + + let config_path = manifest_dir.join("../configs/claim-fees-test.toml"); + let workspace_dir = manifest_dir.join("../"); + let root_dir = workspace_dir.join("../"); + + let paths = TestRunnerPaths { + config_path, + root_dir, + workspace_dir, + }; + let process = start_test_validator_with_config( + &paths, + None, + &Default::default(), + "CHAIN", + ) + .expect("Failed to start devnet process"); + + Self { process } + } +} + +impl Drop for TestValidator { + fn drop(&mut self) { + self.process + .kill() + .expect("Failed to stop solana-test-validator"); + self.process + .wait() + .expect("Failed to wait for solana-test-validator"); + } +} + +#[test] +fn test_validator_claim_fees() { + println!("Starting Validator Fee Claiming Integration Test\n"); + + // 1. Start test infrastructure + let _devnet = TestValidator::start(); + + // 2. Initialize validator authority + validator::init_validator_authority( + VALIDATOR_KEYPAIR.as_ref().insecure_clone(), + ); + + // 3. Fund the validator for transaction fees + let client = RpcClient::new_with_commitment( + DEVNET_URL, + CommitmentConfig::confirmed(), + ); + IntegrationTestContext::airdrop( + &client, + &VALIDATOR_KEYPAIR.pubkey(), + INITIAL_AIRDROP_AMOUNT, + CommitmentConfig::confirmed(), + ) + .expect("Failed to airdrop initial funds to validator"); + + // 4. Run test sequence + println!("=== Test 1: Instruction Creation ==="); + test_claim_fees_instruction(); + + println!("\n=== Test 2: ClaimFeesTask Struct ==="); + test_claim_fees_task(); + + println!("\n=== Test 3: Vault Initialization ==="); + test_init_validator_fees_vault(); + sleep(Duration::from_millis(SETUP_WAIT_MS)); + + println!("\n=== Test 4: Add Test Fees ==="); + test_add_fees_to_vault(); + + println!("\n=== Test 5: Claim Fees Transaction ==="); + test_claim_fees_transaction(); + + println!("\n=== Test 6: RPC Connection ==="); + test_claim_fees_rpc_connection(); + + println!("\nAll tests completed successfully!"); +} From da875125aa2d2f9ba8203be1b4aa590843aa6935 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 7 Aug 2025 13:10:57 +0900 Subject: [PATCH 170/199] fix: test-config --- magicblock-api/src/magic_validator.rs | 18 ++-- test-integration/test-runner/bin/run_tests.rs | 94 +++++++++---------- 2 files changed, 58 insertions(+), 54 deletions(-) diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index 960c8ae29..1cf43ede4 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -43,7 +43,7 @@ use magicblock_committor_service::{ }; use magicblock_config::{ AccountsDbConfig, EphemeralConfig, LedgerConfig, LedgerResumeStrategy, - LifecycleMode, ProgramConfig, + LifecycleMode, PrepareLookupTables, ProgramConfig, }; use magicblock_geyser_plugin::rpc::GeyserRpcService; use magicblock_ledger::{ @@ -817,12 +817,16 @@ impl MagicValidator { self.remote_account_cloner_worker.take() { if let Some(committor_service) = &self.committor_service { - debug!("Reserving common pubkeys for committor service"); - map_committor_request_result( - committor_service.reserve_common_pubkeys(), - committor_service.clone(), - ) - .await?; + if self.config.accounts.clone.prepare_lookup_tables + == PrepareLookupTables::Always + { + debug!("Reserving common pubkeys for committor service"); + map_committor_request_result( + committor_service.reserve_common_pubkeys(), + committor_service.clone(), + ) + .await?; + } } if self.config.ledger.resume_strategy.is_replaying() { diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index 68ac1be0f..c3a106503 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -20,59 +20,59 @@ use test_runner::cleanup::{ pub fn main() { let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let Ok((security_output, scenarios_output)) = - run_schedule_commit_tests(&manifest_dir) - else { - // If any test run panics (i.e. not just a failing test) then we bail - return; - }; - let Ok(issues_frequent_commits_output) = - run_issues_frequent_commmits_tests(&manifest_dir) - else { - return; - }; - let Ok(cloning_output) = run_cloning_tests(&manifest_dir) else { - return; - }; - - let Ok(restore_ledger_output) = run_restore_ledger_tests(&manifest_dir) - else { - return; - }; - - let Ok(magicblock_api_output) = run_magicblock_api_tests(&manifest_dir) - else { - return; - }; - - let Ok((table_mania_output, committor_output)) = - run_table_mania_and_committor_tests(&manifest_dir) - else { - return; - }; - let Ok(magicblock_pubsub_output) = - run_magicblock_pubsub_tests(&manifest_dir) - else { - return; - }; + // let Ok((security_output, scenarios_output)) = + // run_schedule_commit_tests(&manifest_dir) + // else { + // // If any test run panics (i.e. not just a failing test) then we bail + // return; + // }; + // let Ok(issues_frequent_commits_output) = + // run_issues_frequent_commmits_tests(&manifest_dir) + // else { + // return; + // }; + // let Ok(cloning_output) = run_cloning_tests(&manifest_dir) else { + // return; + // }; + // + // let Ok(restore_ledger_output) = run_restore_ledger_tests(&manifest_dir) + // else { + // return; + // }; + // + // let Ok(magicblock_api_output) = run_magicblock_api_tests(&manifest_dir) + // else { + // return; + // }; + // + // let Ok((table_mania_output, committor_output)) = + // run_table_mania_and_committor_tests(&manifest_dir) + // else { + // return; + // }; + // let Ok(magicblock_pubsub_output) = + // run_magicblock_pubsub_tests(&manifest_dir) + // else { + // return; + // }; let Ok(config_output) = run_config_tests(&manifest_dir) else { return; }; // Assert that all tests passed - assert_cargo_tests_passed(security_output, "security"); - assert_cargo_tests_passed(scenarios_output, "scenarios"); - assert_cargo_tests_passed(cloning_output, "cloning"); - assert_cargo_tests_passed( - issues_frequent_commits_output, - "issues_frequent_commits", - ); - assert_cargo_tests_passed(restore_ledger_output, "restore_ledger"); - assert_cargo_tests_passed(magicblock_api_output, "magicblock_api"); - assert_cargo_tests_passed(table_mania_output, "table_mania"); - assert_cargo_tests_passed(committor_output, "committor"); - assert_cargo_tests_passed(magicblock_pubsub_output, "magicblock_pubsub"); + // assert_cargo_tests_passed(security_output, "security"); + // assert_cargo_tests_passed(scenarios_output, "scenarios"); + // assert_cargo_tests_passed(cloning_output, "cloning"); + // assert_cargo_tests_passed( + // issues_frequent_commits_output, + // "issues_frequent_commits", + // ); + // assert_cargo_tests_passed(restore_ledger_output, "restore_ledger"); + // assert_cargo_tests_passed(magicblock_api_output, "magicblock_api"); + // assert_cargo_tests_passed(table_mania_output, "table_mania"); + // assert_cargo_tests_passed(committor_output, "committor"); + // assert_cargo_tests_passed(magicblock_pubsub_output, "magicblock_pubsub"); assert_cargo_tests_passed(config_output, "config"); } From f08144a02d9f4742a3db0a02211feeb03d0c77f2 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 7 Aug 2025 17:06:29 +0900 Subject: [PATCH 171/199] feat: fix latest dlp version --- Cargo.lock | 12 ++++++------ Cargo.toml | 2 +- test-integration/Cargo.lock | 20 ++++++++++---------- test-integration/Cargo.toml | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2179a5c3e..08e3c3460 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3930,7 +3930,7 @@ dependencies = [ "magicblock-committor-service", "magicblock-config", "magicblock-core", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3998,7 +3998,7 @@ dependencies = [ "magicblock-committor-service", "magicblock-config", "magicblock-core", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-geyser-plugin", "magicblock-ledger", "magicblock-metrics", @@ -4095,7 +4095,7 @@ dependencies = [ "log", "lru 0.16.0", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", @@ -4164,7 +4164,7 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c#4af7f1cefe0915f0760ed5c38b25b7d41c31a474" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720#00d72053093a9ca10f1812b4448b807a7e4036c8" dependencies = [ "bincode", "borsh 1.5.7", @@ -4180,7 +4180,7 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00#6edfe006d2726643065d769cc98fa713b2661dab" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c#4af7f1cefe0915f0760ed5c38b25b7d41c31a474" dependencies = [ "bincode", "borsh 1.5.7", @@ -4475,7 +4475,7 @@ dependencies = [ "log", "magicblock-accounts", "magicblock-config", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-program", "magicblock-rpc-client", "solana-rpc-client", diff --git a/Cargo.toml b/Cargo.toml index 0f83e7a2f..aca7dc4f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,7 +118,7 @@ magicblock-config = { path = "./magicblock-config" } magicblock-config-helpers = { path = "./magicblock-config-helpers" } magicblock-config-macro = { path = "./magicblock-config-macro" } magicblock-core = { path = "./magicblock-core" } -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "6edfe00", features = ["no-entrypoint"] } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "00d720", features = ["no-entrypoint"] } magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "ea04d46", default-features = false } magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" } magicblock-ledger = { path = "./magicblock-ledger" } diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index c18dd9b50..ec39f419a 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -3021,7 +3021,7 @@ dependencies = [ "log", "magicblock-config", "magicblock-core 0.1.7", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "rayon", "serde", "solana-pubkey", @@ -3677,7 +3677,7 @@ dependencies = [ "magicblock-bank", "magicblock-committor-service", "magicblock-core 0.1.7", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-metrics", "magicblock-mutator", "magicblock-processor", @@ -3742,7 +3742,7 @@ dependencies = [ "magicblock-committor-service", "magicblock-config", "magicblock-core 0.1.7", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-geyser-plugin", "magicblock-ledger", "magicblock-metrics", @@ -3828,7 +3828,7 @@ dependencies = [ "log", "lru 0.16.0", "magicblock-committor-program", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", @@ -3901,7 +3901,7 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c#4af7f1cefe0915f0760ed5c38b25b7d41c31a474" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720#00d72053093a9ca10f1812b4448b807a7e4036c8" dependencies = [ "bincode", "borsh 1.5.7", @@ -3917,7 +3917,7 @@ dependencies = [ [[package]] name = "magicblock-delegation-program" version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00#6edfe006d2726643065d769cc98fa713b2661dab" +source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=4af7f1c#4af7f1cefe0915f0760ed5c38b25b7d41c31a474" dependencies = [ "bincode", "borsh 1.5.7", @@ -4201,7 +4201,7 @@ dependencies = [ "log", "magicblock-accounts", "magicblock-config", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-program", "magicblock-rpc-client", "solana-rpc-client", @@ -5119,7 +5119,7 @@ version = "0.0.0" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "solana-program", ] @@ -5964,7 +5964,7 @@ dependencies = [ "log", "magicblock-committor-program", "magicblock-committor-service", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-program", "magicblock-rpc-client", "program-flexi-counter", @@ -10443,7 +10443,7 @@ dependencies = [ "magic-domain-program", "magicblock-api", "magicblock-config", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=6edfe00)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-program", "magicblock-validator-admin", "solana-rpc-client", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 2a69c04e8..7821ecd0a 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -42,7 +42,7 @@ magicblock-core = { path = "../magicblock-core" } magicblock-committor-program = { path = "../magicblock-committor-program", features = [ "no-entrypoint", ] } -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "6edfe00", features = ["no-entrypoint"] } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "00d720", features = ["no-entrypoint"] } magicblock-committor-service = { path = "../magicblock-committor-service" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } magicblock-table-mania = { path = "../magicblock-table-mania" } From 1c871f53be810343864dd818564396f6372fefcf Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 7 Aug 2025 17:09:42 +0900 Subject: [PATCH 172/199] feat: fix latest er-sdk version --- test-integration/Cargo.lock | 30 +++++++----------------------- test-integration/Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index ec39f419a..fbea8d2a8 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1830,21 +1830,21 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=ec0308c#ec0308c179f3cf56c3662e5fc3bfbf371e1e7e98" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=69c555#69c555f788a6758bde55495e58d028f6e64e5cf4" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk-attribute-commit", "ephemeral-rollups-sdk-attribute-delegate", "ephemeral-rollups-sdk-attribute-ephemeral", - "magicblock-core 0.1.7 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=44f535a)", - "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=b149f8a)", + "magicblock-core 0.1.7 (git+https://github.com/magicblock-labs/magicblock-validator.git?rev=f08144)", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "solana-program", ] [[package]] name = "ephemeral-rollups-sdk-attribute-commit" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=ec0308c#ec0308c179f3cf56c3662e5fc3bfbf371e1e7e98" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=69c555#69c555f788a6758bde55495e58d028f6e64e5cf4" dependencies = [ "quote", "syn 1.0.109", @@ -1853,7 +1853,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-delegate" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=ec0308c#ec0308c179f3cf56c3662e5fc3bfbf371e1e7e98" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=69c555#69c555f788a6758bde55495e58d028f6e64e5cf4" dependencies = [ "proc-macro2", "quote", @@ -1863,7 +1863,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-ephemeral" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=ec0308c#ec0308c179f3cf56c3662e5fc3bfbf371e1e7e98" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=69c555#69c555f788a6758bde55495e58d028f6e64e5cf4" dependencies = [ "proc-macro2", "quote", @@ -3891,7 +3891,7 @@ dependencies = [ [[package]] name = "magicblock-core" version = "0.1.7" -source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=44f535a#44f535a4dedcec5b208d6546dd625fa0111b71fd" +source = "git+https://github.com/magicblock-labs/magicblock-validator.git?rev=f08144#f08144a02d9f4742a3db0a02211feeb03d0c77f2" dependencies = [ "bincode", "serde", @@ -3930,22 +3930,6 @@ dependencies = [ "thiserror 1.0.69", ] -[[package]] -name = "magicblock-delegation-program" -version = "1.0.0" -source = "git+https://github.com/magicblock-labs/delegation-program.git?rev=b149f8a#b149f8ae8f0d16b779e5974e65b5edbb94e520de" -dependencies = [ - "bincode", - "borsh 1.5.7", - "bytemuck", - "num_enum", - "paste", - "solana-curve25519", - "solana-program", - "solana-security-txt", - "thiserror 1.0.69", -] - [[package]] name = "magicblock-geyser-plugin" version = "0.1.7" diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 7821ecd0a..63e1317aa 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -28,7 +28,7 @@ edition = "2021" anyhow = "1.0.86" borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" -ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "ec0308c" } +ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "69c555" } integration-test-tools = { path = "test-tools" } isocountry = "0.3.2" log = "0.4.20" From adf342860ac2fd935c8fede3f0bc6f4a7941b061 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 8 Aug 2025 17:20:02 +0900 Subject: [PATCH 173/199] feat: add action test + fmt integration tests --- .../process_schedule_base_intent.rs | 6 - test-integration/Cargo.lock | 23 ++- test-integration/Cargo.toml | 5 +- .../programs/flexi-counter/src/args.rs | 12 ++ .../programs/flexi-counter/src/instruction.rs | 48 ++++++ .../programs/flexi-counter/src/lib.rs | 1 + .../programs/flexi-counter/src/processor.rs | 24 ++- .../src/processor/call_handler.rs | 103 +++++++++++++ .../src/processor/create_intent.rs | 96 ++++++++++++ .../programs/schedulecommit/src/api.rs | 27 ++-- .../tests/ix_commit_local.rs | 133 +++++------------ .../tests/utils/instructions.rs | 8 +- .../tests/02_commit_and_undelegate.rs | 4 +- .../test-security/tests/utils/mod.rs | 6 +- .../tests/test_validator_claim_fees.rs | 2 - .../test-schedule-intent/Cargo.toml | 17 +++ .../test-schedule-intent/src/main.rs | 3 + .../tests/test_schedule_intents.rs | 137 ++++++++++++++++++ .../src/integration_test_context.rs | 60 ++++++++ 19 files changed, 583 insertions(+), 132 deletions(-) create mode 100644 test-integration/programs/flexi-counter/src/args.rs create mode 100644 test-integration/programs/flexi-counter/src/processor/call_handler.rs create mode 100644 test-integration/programs/flexi-counter/src/processor/create_intent.rs create mode 100644 test-integration/test-schedule-intent/Cargo.toml create mode 100644 test-integration/test-schedule-intent/src/main.rs create mode 100644 test-integration/test-schedule-intent/tests/test_schedule_intents.rs diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs b/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs index 704f74d12..c6365d6fd 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs @@ -24,18 +24,12 @@ use crate::{ const PAYER_IDX: u16 = 0; const MAGIC_CONTEXT_IDX: u16 = PAYER_IDX + 1; const ACTION_ACCOUNTS_OFFSET: usize = MAGIC_CONTEXT_IDX as usize + 1; -const ACTIONS_SUPPORTED: bool = false; pub(crate) fn process_schedule_base_intent( signers: HashSet, invoke_context: &mut InvokeContext, args: MagicBaseIntentArgs, ) -> Result<(), InstructionError> { - // TODO: remove once actions are supported - if !ACTIONS_SUPPORTED { - return Err(InstructionError::InvalidInstructionData); - } - check_magic_context_id(invoke_context, MAGIC_CONTEXT_IDX)?; let transaction_context = &invoke_context.transaction_context.clone(); diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index fbea8d2a8..9f722a72e 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1830,7 +1830,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=69c555#69c555f788a6758bde55495e58d028f6e64e5cf4" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=7fe62f9#7fe62f9e2d3d4e16b0b4f4f1be5a588651742f08" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk-attribute-commit", @@ -1844,7 +1844,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-commit" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=69c555#69c555f788a6758bde55495e58d028f6e64e5cf4" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=7fe62f9#7fe62f9e2d3d4e16b0b4f4f1be5a588651742f08" dependencies = [ "quote", "syn 1.0.109", @@ -1853,7 +1853,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-delegate" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=69c555#69c555f788a6758bde55495e58d028f6e64e5cf4" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=7fe62f9#7fe62f9e2d3d4e16b0b4f4f1be5a588651742f08" dependencies = [ "proc-macro2", "quote", @@ -1863,7 +1863,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-ephemeral" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=69c555#69c555f788a6758bde55495e58d028f6e64e5cf4" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=7fe62f9#7fe62f9e2d3d4e16b0b4f4f1be5a588651742f08" dependencies = [ "proc-macro2", "quote", @@ -10457,6 +10457,21 @@ dependencies = [ "teepee", ] +[[package]] +name = "test-schedule-intent" +version = "0.0.0" +dependencies = [ + "ephemeral-rollups-sdk", + "integration-test-tools", + "magicblock-config", + "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", + "program-flexi-counter", + "solana-rpc-client-api", + "solana-sdk", + "tempfile", + "test-ledger-restore", +] + [[package]] name = "test-table-mania" version = "0.0.0" diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 63e1317aa..6f6b3fe2c 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -17,6 +17,7 @@ members = [ "test-tools", "test-pubsub", "test-config", + "test-schedule-intent", ] resolver = "2" @@ -25,10 +26,12 @@ version = "0.0.0" edition = "2021" [workspace.dependencies] +test-ledger-restore = { path = "./test-ledger-restore" } + anyhow = "1.0.86" borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" -ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "69c555" } +ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "7fe62f9" } integration-test-tools = { path = "test-tools" } isocountry = "0.3.2" log = "0.4.20" diff --git a/test-integration/programs/flexi-counter/src/args.rs b/test-integration/programs/flexi-counter/src/args.rs new file mode 100644 index 000000000..ff239c410 --- /dev/null +++ b/test-integration/programs/flexi-counter/src/args.rs @@ -0,0 +1,12 @@ +use borsh::{BorshDeserialize, BorshSerialize}; + +#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)] +pub struct CommitActionData { + pub transfer_amount: u64, +} + +#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)] +pub struct UndelegateActionData { + pub counter_diff: i64, + pub transfer_amount: u64, +} diff --git a/test-integration/programs/flexi-counter/src/instruction.rs b/test-integration/programs/flexi-counter/src/instruction.rs index 391f19529..ac8f58734 100644 --- a/test-integration/programs/flexi-counter/src/instruction.rs +++ b/test-integration/programs/flexi-counter/src/instruction.rs @@ -98,6 +98,23 @@ pub enum FlexiCounterInstruction { /// 1. `[write]` The target PDA account of the payer that will be updated. /// 2. `[]` The source PDA account whose count will be added. AddCounter, + + /// Creates intent that will schedule intent with some action + /// Actions will call back our program + /// + /// Accounts: + /// 0. `[signer]` Escrow authority + /// 1. `[write]` Counter pda + /// 2. `[]` Destination program + /// 2. `[]` MagicContext (used to record scheduled commit) + /// 3. `[]` MagicBlock Program (used to schedule commit) + /// 4. `[write]` Transfer destination during action + /// 5. `[]` system program + CreateIntent { + counter_diff: i64, + is_undelegate: bool, + compute_units: u32, + }, } pub fn create_init_ix(payer: Pubkey, label: String) -> Instruction { @@ -228,3 +245,34 @@ pub fn create_add_counter_ix( accounts, ) } + +pub fn create_intent_ix( + payer: Pubkey, + transfer_destination: Pubkey, + counter_diff: i64, + is_undelegate: bool, + compute_units: u32, +) -> Instruction { + let program_id = &crate::id(); + let (counter, _) = FlexiCounter::pda(&payer); + let accounts = vec![ + AccountMeta::new(payer, true), + AccountMeta::new(counter, false), + AccountMeta::new_readonly(crate::id(), false), + AccountMeta::new(MAGIC_CONTEXT_ID, false), + AccountMeta::new_readonly(MAGIC_PROGRAM_ID, false), + AccountMeta::new(transfer_destination, false), + AccountMeta::new_readonly(system_program::id(), false), + ]; + + Instruction::new_with_borsh( + *program_id, + &FlexiCounterInstruction::CreateIntent { + // Has no effect in non-undelegate case + counter_diff, + is_undelegate, + compute_units, + }, + accounts, + ) +} diff --git a/test-integration/programs/flexi-counter/src/lib.rs b/test-integration/programs/flexi-counter/src/lib.rs index 455d7a5f6..42bf8eac5 100644 --- a/test-integration/programs/flexi-counter/src/lib.rs +++ b/test-integration/programs/flexi-counter/src/lib.rs @@ -1,5 +1,6 @@ use solana_program::declare_id; +mod args; pub mod instruction; mod processor; pub mod state; diff --git a/test-integration/programs/flexi-counter/src/processor.rs b/test-integration/programs/flexi-counter/src/processor.rs index cddbd03ad..5666f4f7d 100644 --- a/test-integration/programs/flexi-counter/src/processor.rs +++ b/test-integration/programs/flexi-counter/src/processor.rs @@ -1,4 +1,8 @@ +mod call_handler; +mod create_intent; + use borsh::{to_vec, BorshDeserialize}; +use ephemeral_rollups_sdk::consts::EXTERNAL_CALL_HANDLER_DISCRIMINATOR; use ephemeral_rollups_sdk::cpi::{DelegateAccounts, DelegateConfig}; use ephemeral_rollups_sdk::{ consts::EXTERNAL_UNDELEGATE_DISCRIMINATOR, @@ -18,6 +22,8 @@ use solana_program::{ }; use crate::instruction::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE; +use crate::processor::call_handler::process_call_handler; +use crate::processor::create_intent::process_create_intent; use crate::{ instruction::{DelegateArgs, FlexiCounterInstruction}, state::FlexiCounter, @@ -30,11 +36,15 @@ pub fn process( instruction_data: &[u8], ) -> ProgramResult { if instruction_data.len() >= EXTERNAL_UNDELEGATE_DISCRIMINATOR.len() { - let (disc, seeds_data) = + let (disc, data) = instruction_data.split_at(EXTERNAL_UNDELEGATE_DISCRIMINATOR.len()); if disc == EXTERNAL_UNDELEGATE_DISCRIMINATOR { - return process_undelegate_request(accounts, seeds_data); + return process_undelegate_request(accounts, data); + } + + if disc == EXTERNAL_CALL_HANDLER_DISCRIMINATOR { + return process_call_handler(accounts, data); } } @@ -54,6 +64,16 @@ pub fn process( process_add_and_schedule_commit(accounts, count, undelegate) } AddCounter => process_add_counter(accounts), + CreateIntent { + counter_diff, + is_undelegate, + compute_units, + } => process_create_intent( + accounts, + counter_diff, + is_undelegate, + compute_units, + ), }?; Ok(()) } diff --git a/test-integration/programs/flexi-counter/src/processor/call_handler.rs b/test-integration/programs/flexi-counter/src/processor/call_handler.rs new file mode 100644 index 000000000..b02d6282f --- /dev/null +++ b/test-integration/programs/flexi-counter/src/processor/call_handler.rs @@ -0,0 +1,103 @@ +use crate::args::{CommitActionData, UndelegateActionData}; +use crate::state::FlexiCounter; +use borsh::{to_vec, BorshDeserialize}; +use ephemeral_rollups_sdk::pda::ephemeral_balance_pda_from_payer; +use ephemeral_rollups_sdk::{CallHandlerArgs, Context}; +use solana_program::account_info::{next_account_info, AccountInfo}; +use solana_program::entrypoint::ProgramResult; +use solana_program::msg; +use solana_program::program::invoke; +use solana_program::program_error::ProgramError; +use solana_program::system_instruction::transfer; + +pub fn process_call_handler( + accounts: &[AccountInfo], + call_data: &[u8], +) -> ProgramResult { + msg!("Call handler"); + let account_info_iter = &mut accounts.iter(); + let escrow_authority = next_account_info(account_info_iter)?; + let escrow_account = next_account_info(account_info_iter)?; + + let call_handler = CallHandlerArgs::try_from_slice(call_data)?; + let expected_escrow = ephemeral_balance_pda_from_payer( + escrow_authority.key, + call_handler.escrow_index, + ); + if &expected_escrow != escrow_account.key { + msg!("Escrow mismatch"); + return Err(ProgramError::InvalidAccountData); + } + if !escrow_account.is_signer { + msg!("Escrow account shall be a signer"); + return Err(ProgramError::MissingRequiredSignature); + } + + let delegated_account = next_account_info(account_info_iter)?; + let transfer_destination = next_account_info(account_info_iter)?; + let system_program = next_account_info(account_info_iter)?; + match call_handler.context { + Context::Commit => { + msg!("Commit context"); + if delegated_account.owner != &ephemeral_rollups_sdk::id() { + msg!("account not owned by dlp"); + return Err(ProgramError::InvalidAccountOwner); + } + + let commit_action_data = + CommitActionData::try_from_slice(&call_handler.data)?; + invoke( + &transfer( + escrow_account.key, + transfer_destination.key, + commit_action_data.transfer_amount, + ), + &[ + escrow_account.clone(), + transfer_destination.clone(), + system_program.clone(), + ], + ) + } + Context::Undelegate => { + msg!("Undelegate context"); + if delegated_account.owner == &ephemeral_rollups_sdk::id() { + msg!("account still owned by dlp!"); + return Err(ProgramError::InvalidAccountOwner); + } + + let undelegation_action_data = + UndelegateActionData::try_from_slice(&call_handler.data)?; + + let mut counter = + FlexiCounter::try_from_slice(&delegated_account.data.borrow())?; + + counter.count = (counter.count as i64 + + undelegation_action_data.counter_diff) + as u64; + counter.updates += 1; + + let size = delegated_account.data_len(); + let counter_data = to_vec(&counter)?; + delegated_account.data.borrow_mut()[..size] + .copy_from_slice(&counter_data); + + invoke( + &transfer( + escrow_account.key, + transfer_destination.key, + undelegation_action_data.transfer_amount, + ), + &[ + escrow_account.clone(), + transfer_destination.clone(), + system_program.clone(), + ], + ) + } + Context::Standalone => { + msg!("Standalone"); + Ok(()) + } + } +} diff --git a/test-integration/programs/flexi-counter/src/processor/create_intent.rs b/test-integration/programs/flexi-counter/src/processor/create_intent.rs new file mode 100644 index 000000000..37f856025 --- /dev/null +++ b/test-integration/programs/flexi-counter/src/processor/create_intent.rs @@ -0,0 +1,96 @@ +use crate::args::{CommitActionData, UndelegateActionData}; +use borsh::to_vec; +use ephemeral_rollups_sdk::ephem::{ + CallHandler, CommitAndUndelegate, CommitType, MagicAction, + MagicInstructionBuilder, UndelegateType, +}; +use ephemeral_rollups_sdk::ActionArgs; +use solana_program::account_info::{next_account_info, AccountInfo}; +use solana_program::entrypoint::ProgramResult; +use solana_program::msg; +use solana_program::program_error::ProgramError; + +pub const ACTOR_ESCROW_INDEX: u8 = 1; + +pub fn process_create_intent( + accounts: &[AccountInfo], + counter_diff: i64, + is_undelegate: bool, + compute_units: u32, +) -> ProgramResult { + const PRIZE: u64 = 1_000_000; + + msg!("Process create intent!"); + let account_info_iter = &mut accounts.iter(); + + let payer = next_account_info(account_info_iter)?; + let counter = next_account_info(account_info_iter)?; + let destination_program = next_account_info(account_info_iter)?; + let magic_context = next_account_info(account_info_iter)?; + let magic_program = next_account_info(account_info_iter)?; + + if !payer.is_signer { + msg!("escrow authority required to sign tx"); + return Err(ProgramError::MissingRequiredSignature); + } + + let commit_action = CommitActionData { + transfer_amount: PRIZE, + }; + let other_accounts = vec![ + // counter account + counter.clone(), + // transfer destination from escrow + next_account_info(account_info_iter)?.clone(), + // system_program + next_account_info(account_info_iter)?.clone(), + ]; + + let commit_type_action = CommitType::WithHandler { + commited_accounts: vec![counter.clone()], + call_handlers: vec![CallHandler { + args: ActionArgs { + data: to_vec(&commit_action)?, + escrow_index: ACTOR_ESCROW_INDEX, + }, + compute_untis: compute_units, + escrow_authority: payer.clone(), + destination_program: destination_program.clone(), + accounts: other_accounts.clone(), + }], + }; + + let magic_action = if is_undelegate { + let undelegate_action_data = UndelegateActionData { + counter_diff, + transfer_amount: PRIZE, + }; + let undelegate_action = + UndelegateType::WithHandler(vec![CallHandler { + args: ActionArgs { + data: to_vec(&undelegate_action_data)?, + escrow_index: ACTOR_ESCROW_INDEX, + }, + compute_untis: compute_units, + escrow_authority: payer.clone(), + destination_program: destination_program.clone(), + accounts: other_accounts, + }]); + let undelegate_type_action = CommitAndUndelegate { + commit_type: commit_type_action, + undelegate_type: undelegate_action, + }; + MagicAction::CommitAndUndelegate(undelegate_type_action) + } else { + MagicAction::Commit(commit_type_action) + }; + + msg!("calling magic!"); + MagicInstructionBuilder { + payer: payer.clone(), + magic_context: magic_context.clone(), + magic_program: magic_program.clone(), + magic_action, + } + .build_and_invoke() +} diff --git a/test-integration/programs/schedulecommit/src/api.rs b/test-integration/programs/schedulecommit/src/api.rs index 7307880ea..7987d701e 100644 --- a/test-integration/programs/schedulecommit/src/api.rs +++ b/test-integration/programs/schedulecommit/src/api.rs @@ -31,15 +31,24 @@ pub fn init_account_instruction( } pub fn init_payer_escrow(payer: Pubkey) -> [Instruction; 2] { - let top_up_ix = dlp::instruction_builder::top_up_ephemeral_balance(payer, payer, Some(300_000_000), Some(0)); - let delegate_ix = dlp::instruction_builder::delegate_ephemeral_balance(payer, payer, DelegateEphemeralBalanceArgs { - index: 0, - delegate_args: DelegateArgs { - commit_frequency_ms: 0, - seeds: vec![], - validator: None, - } - }); + let top_up_ix = dlp::instruction_builder::top_up_ephemeral_balance( + payer, + payer, + Some(300_000_000), + Some(0), + ); + let delegate_ix = dlp::instruction_builder::delegate_ephemeral_balance( + payer, + payer, + DelegateEphemeralBalanceArgs { + index: 0, + delegate_args: DelegateArgs { + commit_frequency_ms: 0, + seeds: vec![], + validator: None, + }, + }, + ); [top_up_ix, delegate_ix] } diff --git a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs index 6da3f2847..bcfad7e50 100644 --- a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs +++ b/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs @@ -1,7 +1,7 @@ use log::*; -use magicblock_committor_service::{ComputeBudgetConfig}; +use magicblock_committor_service::ComputeBudgetConfig; use magicblock_rpc_client::MagicblockRpcClient; -use std::collections::{HashSet}; +use std::collections::HashSet; use std::sync::{Arc, Once}; use std::time::{Duration, Instant}; use test_tools_core::init_logger; @@ -14,14 +14,14 @@ use magicblock_committor_service::service_ext::{ use magicblock_committor_service::types::{ ScheduledBaseIntentWrapper, TriggerType, }; -use magicblock_committor_service::{ - config::ChainConfig, - CommittorService, -}; +use magicblock_committor_service::{config::ChainConfig, CommittorService}; use magicblock_program::magic_scheduled_base_intent::{ CommitAndUndelegate, CommitType, CommittedAccountV2, MagicBaseIntent, ScheduledBaseIntent, UndelegateType, }; +use magicblock_program::validator::{ + init_validator_authority, validator_authority, +}; use solana_account::{Account, ReadableAccount}; use solana_pubkey::Pubkey; use solana_rpc_client::nonblocking::rpc_client::RpcClient; @@ -32,7 +32,6 @@ use solana_sdk::transaction::Transaction; use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, }; -use magicblock_program::validator::{init_validator_authority, validator_authority}; use utils::instructions::{ init_account_and_delegate_ixs, init_validator_fees_vault_ix, InitAccountAndDelegateIxs, @@ -300,8 +299,7 @@ async fn commit_single_account(bytes: usize, undelegate: bool) { let counter_auth = Keypair::new(); let (pubkey, mut account) = - init_and_delegate_account_on_chain(&counter_auth, bytes as u64) - .await; + init_and_delegate_account_on_chain(&counter_auth, bytes as u64).await; account.owner = program_flexi_counter::id(); account.data = vec![101 as u8; bytes]; @@ -339,156 +337,102 @@ async fn commit_single_account(bytes: usize, undelegate: bool) { #[tokio::test] async fn test_ix_commit_two_accounts_1kb_2kb() { init_logger!(); - commit_multiple_accounts( - &[1024, 2048], - false, - ) - .await; + commit_multiple_accounts(&[1024, 2048], false).await; } #[tokio::test] async fn test_ix_commit_two_accounts_512kb() { init_logger!(); - commit_multiple_accounts( - &[512, 512], - false, - ) - .await; + commit_multiple_accounts(&[512, 512], false).await; } #[tokio::test] async fn test_ix_commit_three_accounts_512kb() { init_logger!(); - commit_multiple_accounts( - &[512, 512, 512], - false, - ) - .await; + commit_multiple_accounts(&[512, 512, 512], false).await; } #[tokio::test] async fn test_ix_commit_six_accounts_512kb() { init_logger!(); - commit_multiple_accounts( - &[512, 512, 512, 512, 512, 512], - false, - ) - .await; + commit_multiple_accounts(&[512, 512, 512, 512, 512, 512], false).await; } #[tokio::test] async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() { init_logger!(); - commit_multiple_accounts( - &[1024, 2 * 1024, 5 * 1024, 10 * 1024], - false, - ) - .await; + commit_multiple_accounts(&[1024, 2 * 1024, 5 * 1024, 10 * 1024], false) + .await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_2() { - commit_20_accounts_1kb( - ) - .await; + commit_20_accounts_1kb().await; } #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_3() { - commit_5_accounts_1kb( - false, - ) - .await; + commit_5_accounts_1kb(false).await; } #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() { - commit_5_accounts_1kb( - true, - ) - .await; + commit_5_accounts_1kb(true).await; } #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_4() { - commit_5_accounts_1kb( - false, - ) - .await; + commit_5_accounts_1kb(false).await; } #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() { - commit_5_accounts_1kb( - true, - ) - .await; + commit_5_accounts_1kb(true).await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_3() { - commit_20_accounts_1kb( - ) - .await; + commit_20_accounts_1kb().await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_4() { - commit_20_accounts_1kb( - ) - .await; + commit_20_accounts_1kb().await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_6() { - commit_20_accounts_1kb( - ) - .await; + commit_20_accounts_1kb().await; } #[tokio::test] async fn test_commit_8_accounts_1kb_bundle_size_8() { - commit_8_accounts_1kb() - .await; + commit_8_accounts_1kb().await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_8() { - commit_20_accounts_1kb() - .await; + commit_20_accounts_1kb().await; } -async fn commit_5_accounts_1kb( - undelegate_all: bool, -) { +async fn commit_5_accounts_1kb(undelegate_all: bool) { init_logger!(); let accs = (0..5).map(|_| 1024).collect::>(); - commit_multiple_accounts( - &accs, - undelegate_all, - ) - .await; + commit_multiple_accounts(&accs, undelegate_all).await; } -async fn commit_8_accounts_1kb( -) { +async fn commit_8_accounts_1kb() { init_logger!(); let accs = (0..8).map(|_| 1024).collect::>(); - commit_multiple_accounts(&accs, false) - .await; + commit_multiple_accounts(&accs, false).await; } -async fn commit_20_accounts_1kb( -) { +async fn commit_20_accounts_1kb() { init_logger!(); let accs = (0..20).map(|_| 1024).collect::>(); - commit_multiple_accounts(&accs, false) - .await; + commit_multiple_accounts(&accs, false).await; } -async fn commit_multiple_accounts( - bytess: &[usize], - undelegate_all: bool, -) { +async fn commit_multiple_accounts(bytess: &[usize], undelegate_all: bool) { init_logger!(); let validator_auth = ensure_validator_authority(); @@ -500,7 +444,7 @@ async fn commit_multiple_accounts( ":memory:", ChainConfig::local(ComputeBudgetConfig::new(1_000_000)), ) - .unwrap(); + .unwrap(); let service = CommittorServiceExt::new(Arc::new(service)); let committees = @@ -516,7 +460,7 @@ async fn commit_multiple_accounts( &counter_auth, bytes as u64, ) - .await; + .await; pda_acc.owner = program_flexi_counter::id(); pda_acc.data = vec![idx as u8; bytes]; @@ -549,9 +493,9 @@ async fn commit_multiple_accounts( blockhash: Hash::new_unique(), action_sent_transaction: Transaction::default(), payer: Pubkey::new_unique(), - base_intent: MagicBaseIntent::Commit(CommitType::Standalone( - committed_accounts, - )), + base_intent: MagicBaseIntent::Commit( + CommitType::Standalone(committed_accounts), + ), }, }; @@ -589,12 +533,7 @@ async fn commit_multiple_accounts( base_intents.push(commit_and_undelegate_intent); } - - ix_commit_local( - service, - base_intents - ) - .await; + ix_commit_local(service, base_intents).await; } } diff --git a/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs b/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs index c55272f4e..abc640e4b 100644 --- a/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs +++ b/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs @@ -29,13 +29,13 @@ pub fn init_account_and_delegate_ixs( let init_counter_ix = create_init_ix(payer, "COUNTER".to_string()); let rent_exempt = Rent::default().minimum_balance(bytes as usize); - let num_reallocs = (bytes + MAX_ALLOC -1) / MAX_ALLOC; + let num_reallocs = (bytes + MAX_ALLOC - 1) / MAX_ALLOC; let realloc_ixs = if num_reallocs == 0 { vec![] } else { - (0..num_reallocs).map(|i| { - create_realloc_ix(payer, bytes, i as u16) - }).collect() + (0..num_reallocs) + .map(|i| create_realloc_ix(payer, bytes, i as u16)) + .collect() }; let delegate_ix = create_delegate_ix(payer); diff --git a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs index 64476a73a..6865c9707 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs @@ -1,7 +1,5 @@ +use integration_test_tools::run_test; use integration_test_tools::scheduled_commits::extract_scheduled_commit_sent_signature_from_logs; -use integration_test_tools::{ - run_test, -}; use log::*; use magicblock_core::magic_program; use program_schedulecommit::api::{ diff --git a/test-integration/schedulecommit/test-security/tests/utils/mod.rs b/test-integration/schedulecommit/test-security/tests/utils/mod.rs index e222a3884..57395629c 100644 --- a/test-integration/schedulecommit/test-security/tests/utils/mod.rs +++ b/test-integration/schedulecommit/test-security/tests/utils/mod.rs @@ -14,8 +14,7 @@ pub fn create_sibling_schedule_cpis_instruction( player_pubkeys: &[Pubkey], ) -> Instruction { let magic_program = magic_program::id(); - let magic_context = - magic_program::MAGIC_CONTEXT_PUBKEY; + let magic_context = magic_program::MAGIC_CONTEXT_PUBKEY; let mut account_metas = vec![ AccountMeta::new(payer, true), AccountMeta::new(magic_context, false), @@ -48,8 +47,7 @@ pub fn create_nested_schedule_cpis_instruction( player_pubkeys: &[Pubkey], ) -> Instruction { let magic_program = magic_program::id(); - let magic_context = - magic_program::MAGIC_CONTEXT_PUBKEY; + let magic_context = magic_program::MAGIC_CONTEXT_PUBKEY; let mut account_metas = vec![ AccountMeta::new(payer, true), AccountMeta::new(magic_context, false), diff --git a/test-integration/test-magicblock-api/tests/test_validator_claim_fees.rs b/test-integration/test-magicblock-api/tests/test_validator_claim_fees.rs index 60f9a8b5c..d449e59f1 100644 --- a/test-integration/test-magicblock-api/tests/test_validator_claim_fees.rs +++ b/test-integration/test-magicblock-api/tests/test_validator_claim_fees.rs @@ -123,7 +123,6 @@ fn test_add_fees_to_vault() { fn test_claim_fees_task() { println!("Testing ClaimFeesTask struct..."); - let task = ClaimFeesTask::new(); // Test that the task starts in the correct state @@ -131,7 +130,6 @@ fn test_claim_fees_task() { println!("✓ ClaimFeesTask created successfully"); - let default_task = ClaimFeesTask::default(); assert!( default_task.handle.is_none(), diff --git a/test-integration/test-schedule-intent/Cargo.toml b/test-integration/test-schedule-intent/Cargo.toml new file mode 100644 index 000000000..c12d313e2 --- /dev/null +++ b/test-integration/test-schedule-intent/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "test-schedule-intent" +version.workspace = true +edition.workspace = true + +[dependencies] + +[dev-dependencies] +tempfile = { workspace = true } +test-ledger-restore = { workspace = true } +magicblock-config = { workspace = true } +program-flexi-counter = { workspace = true, features = ["no-entrypoint"] } +integration-test-tools = { workspace = true } +solana-sdk = { workspace = true } +ephemeral-rollups-sdk = { workspace = true } +magicblock-delegation-program = { workspace = true, features = ["no-entrypoint"] } +solana-rpc-client-api = { workspace = true } diff --git a/test-integration/test-schedule-intent/src/main.rs b/test-integration/test-schedule-intent/src/main.rs new file mode 100644 index 000000000..e7a11a969 --- /dev/null +++ b/test-integration/test-schedule-intent/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs new file mode 100644 index 000000000..20e434b06 --- /dev/null +++ b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs @@ -0,0 +1,137 @@ +use dlp::pda::ephemeral_balance_pda_from_payer; +use integration_test_tools::{expect, IntegrationTestContext}; +use program_flexi_counter::delegation_program_id; +use program_flexi_counter::instruction::{ + create_add_ix, create_delegate_ix, create_init_ix, create_intent_ix, +}; +use program_flexi_counter::state::FlexiCounter; +use solana_sdk::native_token::LAMPORTS_PER_SOL; +use solana_sdk::rent::Rent; +use solana_sdk::signature::Keypair; +use solana_sdk::signer::Signer; + +const SLOT_MS: u64 = 150; + +#[test] +fn test_schedule_intent() { + const LABEL: &str = "I am label"; + + // Init context + let ctx = IntegrationTestContext::try_new().unwrap(); + let payer = setup_payer(&ctx); + + // Init counter + { + let ix = create_init_ix(payer.pubkey(), LABEL.to_string()); + let (_, confirmed) = ctx.send_and_confirm_instructions_with_payer_chain(&[ix], &payer) + .unwrap(); + assert!(confirmed, "Should confirm transaction"); + + let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; + let counter = ctx.fetch_chain_account_struct::(counter_pda).unwrap(); + assert_eq!( + counter, + FlexiCounter { + count: 0, + updates: 0, + label: LABEL.to_string() + }, + ) + } + + let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; + // Delegate counter + { + ctx.wait_for_next_slot_ephem().unwrap(); + let ix = create_delegate_ix(payer.pubkey()); + ctx.send_and_confirm_instructions_with_payer_chain(&[ix], &payer) + .unwrap(); + + // Confirm delegated + let owner = ctx.fetch_chain_account_owner(counter_pda).unwrap(); + assert_eq!(owner, delegation_program_id()); + } + + // Set counter to 101 + { + ctx.wait_for_next_slot_ephem().unwrap(); + let ix = create_add_ix(payer.pubkey(), 101); + ctx.send_and_confirm_instructions_with_payer_ephem(&[ix], &payer) + .unwrap(); + + let counter = ctx + .fetch_ephem_account_struct::(counter_pda) + .unwrap(); + assert_eq!( + counter, + FlexiCounter { + count: 101, + updates: 1, + label: LABEL.to_string() + }, + ) + } + + // Schedule Intent + { + ctx.wait_for_next_slot_ephem().unwrap(); + + let transfer_destination = Keypair::new(); + let ix = create_intent_ix(payer.pubkey(), transfer_destination.pubkey(), 0, false, 100_000); + + let (sig, confirmed) = ctx.send_and_confirm_instructions_with_payer_ephem(&[ix], &payer).unwrap(); + assert!(confirmed); + + // Confirm was sent on Base Layer + let commit_result = ctx + .fetch_schedule_commit_result::(sig) + .unwrap(); + commit_result + .confirm_commit_transactions_on_chain(&ctx) + .unwrap(); + + // Confirm results on base lauer + let counter = ctx + .fetch_chain_account_struct::(counter_pda) + .unwrap(); + assert_eq!( + counter, + FlexiCounter { + count: 101, + updates: 1, + label: LABEL.to_string() + }, + ); + + // ensure Prize = 10_000 is transferred + let transfer_destination_balance = ctx.fetch_chain_account_balance(&transfer_destination.pubkey()).unwrap(); + assert_eq!(transfer_destination_balance, 1_000_000); + } +} + +fn setup_payer(ctx: &IntegrationTestContext) -> Keypair { + let payer = Keypair::new(); + ctx.airdrop_chain(&payer.pubkey(), LAMPORTS_PER_SOL) + .unwrap(); + + // Create actor escrow + let ix = dlp::instruction_builder::top_up_ephemeral_balance( + payer.pubkey(), + payer.pubkey(), + Some(LAMPORTS_PER_SOL / 2), + Some(1), + ); + ctx.send_and_confirm_instructions_with_payer_chain(&[ix], &payer) + .unwrap(); + + // Confirm actor escrow + let escrow_pda = ephemeral_balance_pda_from_payer(&payer.pubkey(), 1); + let rent = Rent::default().minimum_balance(0); + println!("rent: {}", rent); + assert_eq!( + ctx.fetch_chain_account(escrow_pda).unwrap().lamports, + LAMPORTS_PER_SOL / 2 + rent + ); + + payer +} diff --git a/test-integration/test-tools/src/integration_test_context.rs b/test-integration/test-tools/src/integration_test_context.rs index 8ae8c190e..c2101c4bf 100644 --- a/test-integration/test-tools/src/integration_test_context.rs +++ b/test-integration/test-tools/src/integration_test_context.rs @@ -2,6 +2,7 @@ use log::*; use std::{str::FromStr, thread::sleep, time::Duration}; use anyhow::{Context, Result}; +use borsh::BorshDeserialize; use solana_rpc_client::rpc_client::{ GetConfirmedSignaturesForAddress2Config, RpcClient, }; @@ -268,6 +269,65 @@ impl IntegrationTestContext { }) } + pub fn fetch_chain_account_struct(&self, pubkey: Pubkey) -> Result + where + T: BorshDeserialize, + { + self.try_chain_client().and_then(|chain_client| { + Self::fetch_account_struct( + chain_client, + pubkey, + self.commitment, + "chain", + ) + }) + } + + pub fn fetch_ephem_account_struct(&self, pubkey: Pubkey) -> Result + where + T: BorshDeserialize, + { + self.try_ephem_client().and_then(|chain_client| { + Self::fetch_account_struct( + chain_client, + pubkey, + self.commitment, + "ephem", + ) + }) + } + + fn fetch_account_struct( + rpc_client: &RpcClient, + pubkey: Pubkey, + commitment: CommitmentConfig, + cluster: &str, + ) -> Result + where + T: BorshDeserialize, + { + let account = rpc_client + .get_account_with_commitment(&pubkey, commitment) + .with_context(|| { + format!( + "Failed to fetch {} account data for '{:?}'", + cluster, pubkey + ) + })? + .value + .ok_or_else(|| { + anyhow::anyhow!("Account '{}' not found on {}", pubkey, cluster) + })?; + + T::try_from_slice(&account.data).with_context(|| { + anyhow::anyhow!( + "Failed to deserialize account: {}, cluster: {}", + pubkey, + cluster + ) + }) + } + fn fetch_account( rpc_client: &RpcClient, pubkey: Pubkey, From 44bfb2d670929a053562159e331fd5a7ffc87453 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 8 Aug 2025 20:12:37 +0900 Subject: [PATCH 174/199] feat: change entrypoint to commit multiple accs + actions --- .../programs/flexi-counter/src/instruction.rs | 60 +++- .../programs/flexi-counter/src/processor.rs | 10 +- .../src/processor/create_intent.rs | 96 ------ .../src/processor/schedule_intent.rs | 132 +++++++++ test-integration/test-runner/bin/run_tests.rs | 147 +++++++--- .../tests/test_schedule_intents.rs | 274 ++++++++++++------ 6 files changed, 473 insertions(+), 246 deletions(-) delete mode 100644 test-integration/programs/flexi-counter/src/processor/create_intent.rs create mode 100644 test-integration/programs/flexi-counter/src/processor/schedule_intent.rs diff --git a/test-integration/programs/flexi-counter/src/instruction.rs b/test-integration/programs/flexi-counter/src/instruction.rs index ac8f58734..b969ccdbd 100644 --- a/test-integration/programs/flexi-counter/src/instruction.rs +++ b/test-integration/programs/flexi-counter/src/instruction.rs @@ -103,15 +103,18 @@ pub enum FlexiCounterInstruction { /// Actions will call back our program /// /// Accounts: - /// 0. `[signer]` Escrow authority - /// 1. `[write]` Counter pda - /// 2. `[]` Destination program - /// 2. `[]` MagicContext (used to record scheduled commit) - /// 3. `[]` MagicBlock Program (used to schedule commit) - /// 4. `[write]` Transfer destination during action - /// 5. `[]` system program + /// 0. `[]` Destination program + /// 1. `[]` MagicContext (used to record scheduled commit) + /// 2. `[]` MagicBlock Program (used to schedule commit) + /// 3. `[write]` Transfer destination during action + /// 4. `[]` system program + /// 5. `[signer]` Escrow authority + /// 5+n-1 `[signer]` Escrow authority` + /// 5+n `[write]` Counter pda + /// 5+2n `[write]` Counter pda CreateIntent { - counter_diff: i64, + num_committees: u8, + counter_diffs: Vec, is_undelegate: bool, compute_units: u32, }, @@ -246,7 +249,7 @@ pub fn create_add_counter_ix( ) } -pub fn create_intent_ix( +pub fn create_intent_single_committee_ix( payer: Pubkey, transfer_destination: Pubkey, counter_diff: i64, @@ -256,20 +259,57 @@ pub fn create_intent_ix( let program_id = &crate::id(); let (counter, _) = FlexiCounter::pda(&payer); let accounts = vec![ + AccountMeta::new_readonly(crate::id(), false), + AccountMeta::new(MAGIC_CONTEXT_ID, false), + AccountMeta::new_readonly(MAGIC_PROGRAM_ID, false), + AccountMeta::new(transfer_destination, false), + AccountMeta::new_readonly(system_program::id(), false), AccountMeta::new(payer, true), AccountMeta::new(counter, false), + ]; + + Instruction::new_with_borsh( + *program_id, + &FlexiCounterInstruction::CreateIntent { + num_committees: 1, + // Has no effect in non-undelegate case + counter_diffs: vec![counter_diff], + is_undelegate, + compute_units, + }, + accounts, + ) +} + +pub fn create_intent_ix( + payers: Vec, + transfer_destination: Pubkey, + counter_diffs: Vec, + is_undelegate: bool, + compute_units: u32, +) -> Instruction { + let program_id = &crate::id(); + + let payers_meta = payers.iter().map(|payer| AccountMeta::new(*payer, true)); + let counter_metas = payers + .iter() + .map(|payer| AccountMeta::new(FlexiCounter::pda(payer).0, false)); + let mut accounts = vec![ AccountMeta::new_readonly(crate::id(), false), AccountMeta::new(MAGIC_CONTEXT_ID, false), AccountMeta::new_readonly(MAGIC_PROGRAM_ID, false), AccountMeta::new(transfer_destination, false), AccountMeta::new_readonly(system_program::id(), false), ]; + accounts.extend(payers_meta); + accounts.extend(counter_metas); Instruction::new_with_borsh( *program_id, &FlexiCounterInstruction::CreateIntent { + num_committees: payers.len() as u8, // Has no effect in non-undelegate case - counter_diff, + counter_diffs, is_undelegate, compute_units, }, diff --git a/test-integration/programs/flexi-counter/src/processor.rs b/test-integration/programs/flexi-counter/src/processor.rs index 5666f4f7d..a0e2bb045 100644 --- a/test-integration/programs/flexi-counter/src/processor.rs +++ b/test-integration/programs/flexi-counter/src/processor.rs @@ -1,5 +1,5 @@ mod call_handler; -mod create_intent; +mod schedule_intent; use borsh::{to_vec, BorshDeserialize}; use ephemeral_rollups_sdk::consts::EXTERNAL_CALL_HANDLER_DISCRIMINATOR; @@ -23,7 +23,7 @@ use solana_program::{ use crate::instruction::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE; use crate::processor::call_handler::process_call_handler; -use crate::processor::create_intent::process_create_intent; +use crate::processor::schedule_intent::process_create_intent; use crate::{ instruction::{DelegateArgs, FlexiCounterInstruction}, state::FlexiCounter, @@ -65,12 +65,14 @@ pub fn process( } AddCounter => process_add_counter(accounts), CreateIntent { - counter_diff, + num_committees, + counter_diffs, is_undelegate, compute_units, } => process_create_intent( accounts, - counter_diff, + num_committees, + counter_diffs, is_undelegate, compute_units, ), diff --git a/test-integration/programs/flexi-counter/src/processor/create_intent.rs b/test-integration/programs/flexi-counter/src/processor/create_intent.rs deleted file mode 100644 index 37f856025..000000000 --- a/test-integration/programs/flexi-counter/src/processor/create_intent.rs +++ /dev/null @@ -1,96 +0,0 @@ -use crate::args::{CommitActionData, UndelegateActionData}; -use borsh::to_vec; -use ephemeral_rollups_sdk::ephem::{ - CallHandler, CommitAndUndelegate, CommitType, MagicAction, - MagicInstructionBuilder, UndelegateType, -}; -use ephemeral_rollups_sdk::ActionArgs; -use solana_program::account_info::{next_account_info, AccountInfo}; -use solana_program::entrypoint::ProgramResult; -use solana_program::msg; -use solana_program::program_error::ProgramError; - -pub const ACTOR_ESCROW_INDEX: u8 = 1; - -pub fn process_create_intent( - accounts: &[AccountInfo], - counter_diff: i64, - is_undelegate: bool, - compute_units: u32, -) -> ProgramResult { - const PRIZE: u64 = 1_000_000; - - msg!("Process create intent!"); - let account_info_iter = &mut accounts.iter(); - - let payer = next_account_info(account_info_iter)?; - let counter = next_account_info(account_info_iter)?; - let destination_program = next_account_info(account_info_iter)?; - let magic_context = next_account_info(account_info_iter)?; - let magic_program = next_account_info(account_info_iter)?; - - if !payer.is_signer { - msg!("escrow authority required to sign tx"); - return Err(ProgramError::MissingRequiredSignature); - } - - let commit_action = CommitActionData { - transfer_amount: PRIZE, - }; - let other_accounts = vec![ - // counter account - counter.clone(), - // transfer destination from escrow - next_account_info(account_info_iter)?.clone(), - // system_program - next_account_info(account_info_iter)?.clone(), - ]; - - let commit_type_action = CommitType::WithHandler { - commited_accounts: vec![counter.clone()], - call_handlers: vec![CallHandler { - args: ActionArgs { - data: to_vec(&commit_action)?, - escrow_index: ACTOR_ESCROW_INDEX, - }, - compute_untis: compute_units, - escrow_authority: payer.clone(), - destination_program: destination_program.clone(), - accounts: other_accounts.clone(), - }], - }; - - let magic_action = if is_undelegate { - let undelegate_action_data = UndelegateActionData { - counter_diff, - transfer_amount: PRIZE, - }; - let undelegate_action = - UndelegateType::WithHandler(vec![CallHandler { - args: ActionArgs { - data: to_vec(&undelegate_action_data)?, - escrow_index: ACTOR_ESCROW_INDEX, - }, - compute_untis: compute_units, - escrow_authority: payer.clone(), - destination_program: destination_program.clone(), - accounts: other_accounts, - }]); - let undelegate_type_action = CommitAndUndelegate { - commit_type: commit_type_action, - undelegate_type: undelegate_action, - }; - MagicAction::CommitAndUndelegate(undelegate_type_action) - } else { - MagicAction::Commit(commit_type_action) - }; - - msg!("calling magic!"); - MagicInstructionBuilder { - payer: payer.clone(), - magic_context: magic_context.clone(), - magic_program: magic_program.clone(), - magic_action, - } - .build_and_invoke() -} diff --git a/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs b/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs new file mode 100644 index 000000000..a4467b062 --- /dev/null +++ b/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs @@ -0,0 +1,132 @@ +use crate::args::{CommitActionData, UndelegateActionData}; +use borsh::to_vec; +use ephemeral_rollups_sdk::ephem::{ + CallHandler, CommitAndUndelegate, CommitType, MagicAction, + MagicInstructionBuilder, UndelegateType, +}; +use ephemeral_rollups_sdk::ActionArgs; +use solana_program::account_info::{ + next_account_info, next_account_infos, AccountInfo, +}; +use solana_program::entrypoint::ProgramResult; +use solana_program::msg; +use solana_program::program_error::ProgramError; + +pub const ACTOR_ESCROW_INDEX: u8 = 1; +const PRIZE: u64 = 1_000_000; + +pub fn process_create_intent( + accounts: &[AccountInfo], + num_committees: u8, + counter_diffs: Vec, + is_undelegate: bool, + compute_units: u32, +) -> ProgramResult { + msg!("Process create intent for {} committees!", num_committees); + + let num_committees = num_committees as usize; + let expected_accounts = 2 * num_committees + 5; + let actual_accounts = accounts.len(); + if accounts.len() != 2 * num_committees + 5 { + msg!( + "Invalid number of accounts expected: {}, got: {}", + expected_accounts, + actual_accounts + ); + return Err(ProgramError::NotEnoughAccountKeys); + } + + let account_info_iter = &mut accounts.iter(); + + let destination_program = next_account_info(account_info_iter)?; + let magic_context = next_account_info(account_info_iter)?; + let magic_program = next_account_info(account_info_iter)?; + // other accounts + let transfer_destination = next_account_info(account_info_iter)?; + let system_program = next_account_info(account_info_iter)?; + + let escrow_authorities = + next_account_infos(account_info_iter, num_committees)?; + let committees = next_account_infos(account_info_iter, num_committees)?; + + // Create commit actions + let commit_action = CommitActionData { + transfer_amount: PRIZE, + }; + let commit_action_data = to_vec(&commit_action)?; + let call_handlers = committees + .iter() + .zip(escrow_authorities.iter().cloned()) + .map(|(committee, escrow_authority)| { + let other_accounts = vec![ + // counter account + committee.clone(), + transfer_destination.clone(), + system_program.clone(), + ]; + + CallHandler { + args: ActionArgs { + data: commit_action_data.clone(), + escrow_index: ACTOR_ESCROW_INDEX, + }, + compute_untis: compute_units, + escrow_authority, + destination_program: destination_program.clone(), + accounts: other_accounts, + } + }) + .collect::>(); + let commit_action = CommitType::WithHandler { + commited_accounts: committees.to_vec(), + call_handlers, + }; + + let magic_action = if is_undelegate { + let call_handlers = committees + .iter() + .zip(escrow_authorities.iter().cloned()) + .zip(counter_diffs.iter().copied()) + .map(|((committee, escrow_authority), counter_diff)| { + let undelegate_action_data = UndelegateActionData { + counter_diff, + transfer_amount: PRIZE, + }; + + let other_accounts = vec![ + // counter account + committee.clone(), + transfer_destination.clone(), + system_program.clone(), + ]; + + Ok(CallHandler { + args: ActionArgs { + data: to_vec(&undelegate_action_data)?, + escrow_index: ACTOR_ESCROW_INDEX, + }, + compute_untis: compute_units, + escrow_authority, + destination_program: destination_program.clone(), + accounts: other_accounts, + }) + }) + .collect::, ProgramError>>()?; + let undelegate_action = UndelegateType::WithHandler(call_handlers); + let undelegate_type_action = CommitAndUndelegate { + commit_type: commit_action, + undelegate_type: undelegate_action, + }; + MagicAction::CommitAndUndelegate(undelegate_type_action) + } else { + MagicAction::Commit(commit_action) + }; + + MagicInstructionBuilder { + payer: escrow_authorities[0].clone(), + magic_context: magic_context.clone(), + magic_program: magic_program.clone(), + magic_action, + } + .build_and_invoke() +} diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index c3a106503..c57fddc60 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -20,60 +20,66 @@ use test_runner::cleanup::{ pub fn main() { let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - // let Ok((security_output, scenarios_output)) = - // run_schedule_commit_tests(&manifest_dir) - // else { - // // If any test run panics (i.e. not just a failing test) then we bail - // return; - // }; - // let Ok(issues_frequent_commits_output) = - // run_issues_frequent_commmits_tests(&manifest_dir) - // else { - // return; - // }; - // let Ok(cloning_output) = run_cloning_tests(&manifest_dir) else { - // return; - // }; - // - // let Ok(restore_ledger_output) = run_restore_ledger_tests(&manifest_dir) - // else { - // return; - // }; - // - // let Ok(magicblock_api_output) = run_magicblock_api_tests(&manifest_dir) - // else { - // return; - // }; - // - // let Ok((table_mania_output, committor_output)) = - // run_table_mania_and_committor_tests(&manifest_dir) - // else { - // return; - // }; - // let Ok(magicblock_pubsub_output) = - // run_magicblock_pubsub_tests(&manifest_dir) - // else { - // return; - // }; + let Ok((security_output, scenarios_output)) = + run_schedule_commit_tests(&manifest_dir) + else { + // If any test run panics (i.e. not just a failing test) then we bail + return; + }; + let Ok(issues_frequent_commits_output) = + run_issues_frequent_commmits_tests(&manifest_dir) + else { + return; + }; + let Ok(cloning_output) = run_cloning_tests(&manifest_dir) else { + return; + }; + + let Ok(restore_ledger_output) = run_restore_ledger_tests(&manifest_dir) + else { + return; + }; + + let Ok(magicblock_api_output) = run_magicblock_api_tests(&manifest_dir) + else { + return; + }; + + let Ok((table_mania_output, committor_output)) = + run_table_mania_and_committor_tests(&manifest_dir) + else { + return; + }; + let Ok(magicblock_pubsub_output) = + run_magicblock_pubsub_tests(&manifest_dir) + else { + return; + }; let Ok(config_output) = run_config_tests(&manifest_dir) else { return; }; + let Ok(schedule_intents_output) = run_schedule_intents_tests(&manifest_dir) + else { + return; + }; + // Assert that all tests passed - // assert_cargo_tests_passed(security_output, "security"); - // assert_cargo_tests_passed(scenarios_output, "scenarios"); - // assert_cargo_tests_passed(cloning_output, "cloning"); - // assert_cargo_tests_passed( - // issues_frequent_commits_output, - // "issues_frequent_commits", - // ); - // assert_cargo_tests_passed(restore_ledger_output, "restore_ledger"); - // assert_cargo_tests_passed(magicblock_api_output, "magicblock_api"); - // assert_cargo_tests_passed(table_mania_output, "table_mania"); - // assert_cargo_tests_passed(committor_output, "committor"); - // assert_cargo_tests_passed(magicblock_pubsub_output, "magicblock_pubsub"); + assert_cargo_tests_passed(security_output, "security"); + assert_cargo_tests_passed(scenarios_output, "scenarios"); + assert_cargo_tests_passed(cloning_output, "cloning"); + assert_cargo_tests_passed( + issues_frequent_commits_output, + "issues_frequent_commits", + ); + assert_cargo_tests_passed(restore_ledger_output, "restore_ledger"); + assert_cargo_tests_passed(magicblock_api_output, "magicblock_api"); + assert_cargo_tests_passed(table_mania_output, "table_mania"); + assert_cargo_tests_passed(committor_output, "committor"); + assert_cargo_tests_passed(magicblock_pubsub_output, "magicblock_pubsub"); assert_cargo_tests_passed(config_output, "config"); + assert_cargo_tests_passed(schedule_intents_output, "test-schedule-intent"); } fn should_run_test(test_name: &str) -> bool { @@ -506,6 +512,53 @@ fn run_config_tests(manifest_dir: &str) -> Result> { Ok(output) } +fn run_schedule_intents_tests( + manifest_dir: &str, +) -> Result> { + if !should_run_test("schedule_intents") { + return Ok(success_output()); + } + + eprintln!("======== RUNNING ISSUES TESTS - Schedule Intents ========"); + let loaded_chain_accounts = + LoadedAccounts::with_delegation_program_test_authority(); + let mut devnet_validator = match start_validator( + "config-conf.devnet.toml", + ValidatorCluster::Chain(None), + &loaded_chain_accounts, + ) { + Some(validator) => validator, + None => { + panic!("Failed to start devnet validator properly"); + } + }; + let mut ephem_validator = match start_validator( + "schedulecommit-conf.ephem.frequent-commits.toml", + ValidatorCluster::Ephem, + &loaded_chain_accounts, + ) { + Some(validator) => validator, + None => { + devnet_validator + .kill() + .expect("Failed to kill devnet validator"); + panic!("Failed to start ephemeral validator properly"); + } + }; + let test_issues_dir = + format!("{}/../{}", manifest_dir, "test-schedule-intent"); + let test_output = match run_test(test_issues_dir, Default::default()) { + Ok(output) => output, + Err(err) => { + eprintln!("Failed to run issues: {:?}", err); + cleanup_validators(&mut ephem_validator, &mut devnet_validator); + return Err(err.into()); + } + }; + cleanup_validators(&mut ephem_validator, &mut devnet_validator); + Ok(test_output) +} + // ----------------- // Configs/Checks // ----------------- diff --git a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs index 20e434b06..fcc33020c 100644 --- a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs +++ b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs @@ -1,112 +1,62 @@ use dlp::pda::ephemeral_balance_pda_from_payer; -use integration_test_tools::{expect, IntegrationTestContext}; +use integration_test_tools::IntegrationTestContext; use program_flexi_counter::delegation_program_id; use program_flexi_counter::instruction::{ create_add_ix, create_delegate_ix, create_init_ix, create_intent_ix, }; use program_flexi_counter::state::FlexiCounter; +use solana_sdk::commitment_config::CommitmentConfig; use solana_sdk::native_token::LAMPORTS_PER_SOL; use solana_sdk::rent::Rent; use solana_sdk::signature::Keypair; use solana_sdk::signer::Signer; +use solana_sdk::transaction::Transaction; -const SLOT_MS: u64 = 150; +const LABEL: &str = "I am label"; #[test] fn test_schedule_intent() { - const LABEL: &str = "I am label"; - // Init context let ctx = IntegrationTestContext::try_new().unwrap(); let payer = setup_payer(&ctx); // Init counter - { - let ix = create_init_ix(payer.pubkey(), LABEL.to_string()); - let (_, confirmed) = ctx.send_and_confirm_instructions_with_payer_chain(&[ix], &payer) - .unwrap(); - assert!(confirmed, "Should confirm transaction"); - - let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; - let counter = ctx.fetch_chain_account_struct::(counter_pda).unwrap(); - assert_eq!( - counter, - FlexiCounter { - count: 0, - updates: 0, - label: LABEL.to_string() - }, - ) - } - - let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; + init_counter(&ctx, &payer); // Delegate counter - { - ctx.wait_for_next_slot_ephem().unwrap(); - let ix = create_delegate_ix(payer.pubkey()); - ctx.send_and_confirm_instructions_with_payer_chain(&[ix], &payer) - .unwrap(); - - // Confirm delegated - let owner = ctx.fetch_chain_account_owner(counter_pda).unwrap(); - assert_eq!(owner, delegation_program_id()); - } - - // Set counter to 101 - { - ctx.wait_for_next_slot_ephem().unwrap(); - let ix = create_add_ix(payer.pubkey(), 101); - ctx.send_and_confirm_instructions_with_payer_ephem(&[ix], &payer) - .unwrap(); - - let counter = ctx - .fetch_ephem_account_struct::(counter_pda) - .unwrap(); - assert_eq!( - counter, - FlexiCounter { - count: 101, - updates: 1, - label: LABEL.to_string() - }, - ) - } + delegate_counter(&ctx, &payer); + add_to_counter(&ctx, &payer, 101); + schedule_intent(&ctx, &[&payer], vec![-100], false); +} - // Schedule Intent - { - ctx.wait_for_next_slot_ephem().unwrap(); - - let transfer_destination = Keypair::new(); - let ix = create_intent_ix(payer.pubkey(), transfer_destination.pubkey(), 0, false, 100_000); - - let (sig, confirmed) = ctx.send_and_confirm_instructions_with_payer_ephem(&[ix], &payer).unwrap(); - assert!(confirmed); - - // Confirm was sent on Base Layer - let commit_result = ctx - .fetch_schedule_commit_result::(sig) - .unwrap(); - commit_result - .confirm_commit_transactions_on_chain(&ctx) - .unwrap(); - - // Confirm results on base lauer - let counter = ctx - .fetch_chain_account_struct::(counter_pda) - .unwrap(); - assert_eq!( - counter, - FlexiCounter { - count: 101, - updates: 1, - label: LABEL.to_string() - }, - ); - - // ensure Prize = 10_000 is transferred - let transfer_destination_balance = ctx.fetch_chain_account_balance(&transfer_destination.pubkey()).unwrap(); - assert_eq!(transfer_destination_balance, 1_000_000); - } +#[ignore] +#[test] +fn test_multiple_payers_multiple_counters() { + // Init context + let ctx = IntegrationTestContext::try_new().unwrap(); + let payer1 = setup_payer(&ctx); + let payer2 = setup_payer(&ctx); + let payer3 = setup_payer(&ctx); + + // Init and setup counters for each payer + init_counter(&ctx, &payer1); + delegate_counter(&ctx, &payer1); + add_to_counter(&ctx, &payer1, 100); + + init_counter(&ctx, &payer2); + delegate_counter(&ctx, &payer2); + add_to_counter(&ctx, &payer2, 200); + + init_counter(&ctx, &payer3); + delegate_counter(&ctx, &payer3); + add_to_counter(&ctx, &payer3, 201); + + // Schedule intent affecting all counters + schedule_intent( + &ctx, + &[&payer1, &payer2, &payer3], + vec![-50, 25, -75], + false, + ); } fn setup_payer(ctx: &IntegrationTestContext) -> Keypair { @@ -127,7 +77,6 @@ fn setup_payer(ctx: &IntegrationTestContext) -> Keypair { // Confirm actor escrow let escrow_pda = ephemeral_balance_pda_from_payer(&payer.pubkey(), 1); let rent = Rent::default().minimum_balance(0); - println!("rent: {}", rent); assert_eq!( ctx.fetch_chain_account(escrow_pda).unwrap().lamports, LAMPORTS_PER_SOL / 2 + rent @@ -135,3 +84,150 @@ fn setup_payer(ctx: &IntegrationTestContext) -> Keypair { payer } + +fn init_counter(ctx: &IntegrationTestContext, payer: &Keypair) { + let ix = create_init_ix(payer.pubkey(), LABEL.to_string()); + let (_, confirmed) = ctx + .send_and_confirm_instructions_with_payer_chain(&[ix], &payer) + .unwrap(); + assert!(confirmed, "Should confirm transaction"); + + let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; + let counter = ctx + .fetch_chain_account_struct::(counter_pda) + .unwrap(); + assert_eq!( + counter, + FlexiCounter { + count: 0, + updates: 0, + label: LABEL.to_string() + }, + ) +} + +// ER action +fn delegate_counter(ctx: &IntegrationTestContext, payer: &Keypair) { + ctx.wait_for_next_slot_ephem().unwrap(); + + let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; + let ix = create_delegate_ix(payer.pubkey()); + ctx.send_and_confirm_instructions_with_payer_chain(&[ix], &payer) + .unwrap(); + + // Confirm delegated + let owner = ctx.fetch_chain_account_owner(counter_pda).unwrap(); + assert_eq!(owner, delegation_program_id()); +} + +// ER action +fn add_to_counter(ctx: &IntegrationTestContext, payer: &Keypair, value: u8) { + ctx.wait_for_next_slot_ephem().unwrap(); + + let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; + let counter_before = ctx + .fetch_ephem_account_struct::(counter_pda) + .unwrap_or(FlexiCounter { + count: 0, + updates: 0, + label: LABEL.to_string(), + }); + + // Add value to counter + let ix = create_add_ix(payer.pubkey(), value); + ctx.send_and_confirm_instructions_with_payer_ephem(&[ix], &payer) + .unwrap(); + + let counter = ctx + .fetch_ephem_account_struct::(counter_pda) + .unwrap(); + assert_eq!( + counter, + FlexiCounter { + count: counter_before.count + value as u64, + updates: counter_before.updates + 1, + label: LABEL.to_string() + }, + ) +} + +fn schedule_intent( + ctx: &IntegrationTestContext, + payers: &[&Keypair], + counter_diffs: Vec, + is_undelegate: bool, +) { + ctx.wait_for_next_slot_ephem().unwrap(); + + let counters_before = payers + .iter() + .map(|payer| { + let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; + ctx.fetch_ephem_account_struct::(counter_pda) + .unwrap() + }) + .collect::>(); + + let transfer_destination = Keypair::new(); + let payers_pubkeys = payers.iter().map(|payer| payer.pubkey()).collect(); + let ix = create_intent_ix( + payers_pubkeys, + transfer_destination.pubkey(), + counter_diffs.clone(), + is_undelegate, + 100_000, + ); + + let rpc_client = ctx.try_ephem_client().unwrap(); + let mut tx = Transaction::new_with_payer(&[ix], None); + let (sig, confirmed) = + IntegrationTestContext::send_and_confirm_transaction( + rpc_client, + &mut tx, + payers, + CommitmentConfig::confirmed(), + ) + .unwrap(); + assert!(confirmed); + + // Confirm was sent on Base Layer + let commit_result = ctx + .fetch_schedule_commit_result::(sig) + .unwrap(); + commit_result + .confirm_commit_transactions_on_chain(&ctx) + .unwrap(); + + // Confirm results on base lauer + let counters_after = payers + .iter() + .map(|payer| { + let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; + ctx.fetch_ephem_account_struct::(counter_pda) + .unwrap() + }) + .collect::>(); + + for i in 0..counter_diffs.len() { + let counter_before = &counters_before[i]; + let counter_after = &counters_after[i]; + let counter_diff = counter_diffs[i]; + if is_undelegate { + assert_eq!( + counter_before.count as i64 + counter_diff, + counter_after.count as i64 + ) + } else { + assert_eq!(counter_before.count, counter_after.count) + } + } + + // ensure Prize = 1_000_000 is transferred + let transfer_destination_balance = ctx + .fetch_chain_account_balance(&transfer_destination.pubkey()) + .unwrap(); + assert_eq!( + transfer_destination_balance, + payers.len() as u64 * 1_000_000 + ); +} From 3785e7efe349fd0b1b472db97bcab833c1dc47c3 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 8 Aug 2025 20:13:38 +0900 Subject: [PATCH 175/199] refactor: remove todo!() --- magicblock-accounts/src/remote_scheduled_commits_processor.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/remote_scheduled_commits_processor.rs index d87492090..971db8ece 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/remote_scheduled_commits_processor.rs @@ -243,7 +243,6 @@ impl RemoteScheduledCommitsProcessor { } _ => { error!("Failed to commit: {:?}", err); - todo!() } } } From f126f6b98f9685ef43c4e73fbc7da77ab5af8f63 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 8 Aug 2025 20:54:58 +0900 Subject: [PATCH 176/199] fix: intent tests --- test-integration/Cargo.lock | 8 ++--- test-integration/Cargo.toml | 2 +- .../tests/test_schedule_intents.rs | 32 ++++++++++++------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 9f722a72e..a20e0b7bc 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1830,7 +1830,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=7fe62f9#7fe62f9e2d3d4e16b0b4f4f1be5a588651742f08" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e461a07#e461a07ee8145dbb2bba242f69545737f4475e0e" dependencies = [ "borsh 1.5.7", "ephemeral-rollups-sdk-attribute-commit", @@ -1844,7 +1844,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-commit" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=7fe62f9#7fe62f9e2d3d4e16b0b4f4f1be5a588651742f08" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e461a07#e461a07ee8145dbb2bba242f69545737f4475e0e" dependencies = [ "quote", "syn 1.0.109", @@ -1853,7 +1853,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-delegate" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=7fe62f9#7fe62f9e2d3d4e16b0b4f4f1be5a588651742f08" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e461a07#e461a07ee8145dbb2bba242f69545737f4475e0e" dependencies = [ "proc-macro2", "quote", @@ -1863,7 +1863,7 @@ dependencies = [ [[package]] name = "ephemeral-rollups-sdk-attribute-ephemeral" version = "0.2.6" -source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=7fe62f9#7fe62f9e2d3d4e16b0b4f4f1be5a588651742f08" +source = "git+https://github.com/magicblock-labs/ephemeral-rollups-sdk.git?rev=e461a07#e461a07ee8145dbb2bba242f69545737f4475e0e" dependencies = [ "proc-macro2", "quote", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index 6f6b3fe2c..d7066723b 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -31,7 +31,7 @@ test-ledger-restore = { path = "./test-ledger-restore" } anyhow = "1.0.86" borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" -ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "7fe62f9" } +ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "e461a07" } integration-test-tools = { path = "test-tools" } isocountry = "0.3.2" log = "0.4.20" diff --git a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs index fcc33020c..8bba41c92 100644 --- a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs +++ b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs @@ -5,6 +5,7 @@ use program_flexi_counter::instruction::{ create_add_ix, create_delegate_ix, create_init_ix, create_intent_ix, }; use program_flexi_counter::state::FlexiCounter; +use solana_rpc_client_api::config::RpcSendTransactionConfig; use solana_sdk::commitment_config::CommitmentConfig; use solana_sdk::native_token::LAMPORTS_PER_SOL; use solana_sdk::rent::Rent; @@ -28,7 +29,6 @@ fn test_schedule_intent() { schedule_intent(&ctx, &[&payer], vec![-100], false); } -#[ignore] #[test] fn test_multiple_payers_multiple_counters() { // Init context @@ -55,7 +55,7 @@ fn test_multiple_payers_multiple_counters() { &ctx, &[&payer1, &payer2, &payer3], vec![-50, 25, -75], - false, + true, ); } @@ -179,15 +179,23 @@ fn schedule_intent( ); let rpc_client = ctx.try_ephem_client().unwrap(); - let mut tx = Transaction::new_with_payer(&[ix], None); - let (sig, confirmed) = - IntegrationTestContext::send_and_confirm_transaction( - rpc_client, - &mut tx, - payers, - CommitmentConfig::confirmed(), + let blockhash = rpc_client.get_latest_blockhash().unwrap(); + let tx = Transaction::new_signed_with_payer(&[ix], None, payers, blockhash); + let sig = rpc_client + .send_transaction_with_config( + &tx, + RpcSendTransactionConfig { + skip_preflight: true, + ..Default::default() + }, ) .unwrap(); + let confirmed = IntegrationTestContext::confirm_transaction( + &sig, + rpc_client, + CommitmentConfig::confirmed(), + ) + .unwrap(); assert!(confirmed); // Confirm was sent on Base Layer @@ -203,7 +211,7 @@ fn schedule_intent( .iter() .map(|payer| { let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; - ctx.fetch_ephem_account_struct::(counter_pda) + ctx.fetch_chain_account_struct::(counter_pda) .unwrap() }) .collect::>(); @@ -226,8 +234,10 @@ fn schedule_intent( let transfer_destination_balance = ctx .fetch_chain_account_balance(&transfer_destination.pubkey()) .unwrap(); + + let mutiplier = if is_undelegate { 2 } else { 1 }; assert_eq!( transfer_destination_balance, - payers.len() as u64 * 1_000_000 + mutiplier * payers.len() as u64 * 1_000_000 ); } From 1923bb98475ae259b15ffb4ba8f16046da4978c3 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 11 Aug 2025 14:25:11 +0900 Subject: [PATCH 177/199] fix: used port during test_validator_claim_fees --- magicblock-api/src/magic_validator.rs | 4 +- test-integration/schedulecommit/elfs/dlp.so | Bin 323312 -> 333272 bytes .../tests/test_validator_claim_fees.rs | 44 ------------------ 3 files changed, 3 insertions(+), 45 deletions(-) diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index b1eca76ca..c58ad9d5f 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -870,7 +870,9 @@ impl MagicValidator { self.ledger_truncator.stop(); self.claim_fees_task.stop(); - + if let Some(committor_service) = &self.committor_service { + committor_service.stop(); + } // wait a bit for services to stop thread::sleep(Duration::from_secs(1)); diff --git a/test-integration/schedulecommit/elfs/dlp.so b/test-integration/schedulecommit/elfs/dlp.so index 34334a5088630989928a0ef0cba5ac169420fe0e..da2583060601f9cc2d4cc1e805b50b58158dd189 100755 GIT binary patch delta 55250 zcmb5X30zgh`#*kX?ge*1gsY<9RTL2w%@oZNcU(#&7bF!F1>E4W3L*(EiMWw@)W-+irPp_Ce^DOf`&pb2p%yN!5 zFSWV&ipQpQZT#1BgLsCie+`E1ZJeI#IUwiGLX%pcrv^6(XGom!f4g`IcT8`FN<2Na zrxO&%-;i{U>Go-oPD_0aI-!tGRM=D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`AVb2`VVsGE!2OALudU5ICKuP|Kf(uu@WcfY%gEQ&?B_+75$f1^b86ld6C5W zFP!N5`Y(;>+$iZQ_MZT0U;p*r1kn>%>)+|5bATlOe_h=_h|_Qs2k;=)>m7H{`v)Ba z>z3ivf^Y_>jyD_{!69SZGIk7y(2N~~OZ}JNARR{QHF@8IyY%z>z2ujqNmIDI7Yl5I9k2`bwDtSX1N0%l2M6FGI0R3?2{=_=9e=z6 z83ZiA1-MCd=Xw4X*aY{$_BmYtT?p{O0eA=w!DBE#V}VyVJBRE49A@Ck`aDB3lt+07 zY=LdC2Mz|%zz;v*0Tbv?!8v#dZjIy$o8UnY8XRyRJOq!yQ*Z`eNUP)Tsa(T0xC=f3 zyI>z2g85Me!Ls*aQ3E5FCRi;A!R6_(oPW=<$s?cmZC5n=j-Rw!tRYTDu(IaMlg0 z@eL0gfQR4^9D@^Z%BJy+oEysVjRI`Elv~&Wcfeh64{Vdy*MAoR`rrT@g2&(lJOgK? ztLuLb0R>n+V|ul3__S<+JK!$(1njP?_CGJshky_~0nfm5Z~=Dd79w4|O6QHG*VP~W z{_6(4Z6O^D?EXcWUd9gpNiQh*fcw4L0D5_S@RaJ<=y-i6i2IJd|8s*yb!6C%t{JF) z*aek&VUMY53w!oS#)ry?3`k7{DD-JNQW z=`A*nq@Ck|Y{>6O$5hsU7ic|{{mVzvbIPvg_?U9p*?}+PCj-g_=YWt>x!IkOoFRWD zJ*8Y{j_-|SfAgz!j}mn`e&BqQ0VXBdazKv~Y1t0t$+F$=a{dVEB~B z$}@zNx5_quiWv<1mvlyHryQSB7Ae~*vpm Self { - let manifest_dir_raw = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let manifest_dir = PathBuf::from(&manifest_dir_raw); - - let config_path = manifest_dir.join("../configs/claim-fees-test.toml"); - let workspace_dir = manifest_dir.join("../"); - let root_dir = workspace_dir.join("../"); - - let paths = TestRunnerPaths { - config_path, - root_dir, - workspace_dir, - }; - let process = start_test_validator_with_config( - &paths, - None, - &Default::default(), - "CHAIN", - ) - .expect("Failed to start devnet process"); - - Self { process } - } -} - -impl Drop for TestValidator { - fn drop(&mut self) { - self.process - .kill() - .expect("Failed to stop solana-test-validator"); - self.process - .wait() - .expect("Failed to wait for solana-test-validator"); - } -} - #[test] fn test_validator_claim_fees() { println!("Starting Validator Fee Claiming Integration Test\n"); - // 1. Start test infrastructure - let _devnet = TestValidator::start(); - // 2. Initialize validator authority validator::init_validator_authority( VALIDATOR_KEYPAIR.as_ref().insecure_clone(), From 5f8d3f68f1ffeb77ab4c18b5f0ab03bb46907b72 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 11 Aug 2025 15:23:10 +0900 Subject: [PATCH 178/199] feat: removed TODOs + moved tests into test-integration. added test-schedule-intents to Makefile --- Cargo.lock | 1 - magicblock-committor-service/Cargo.toml | 5 ----- .../src/intent_execution_manager.rs | 3 +-- magicblock-committor-service/src/lib.rs | 6 ++---- magicblock-committor-service/src/tasks/task_strategist.rs | 1 - magicblock-committor-service/src/tasks/tasks.rs | 1 - test-integration/Cargo.lock | 4 ++++ test-integration/Cargo.toml | 4 +++- test-integration/Makefile | 5 +++++ .../Cargo.toml | 7 +++++++ .../src/lib.rs | 0 .../test-committor-service}/tests/common.rs | 2 +- .../tests/test_delivery_preparator.rs | 7 ------- .../tests/test_ix_commit_local.rs} | 0 .../tests/test_transaction_preparator.rs | 6 ------ .../tests/utils/instructions.rs | 0 .../tests/utils/mod.rs | 0 .../tests/utils/transactions.rs | 0 test-integration/test-runner/bin/run_tests.rs | 4 ++-- 19 files changed, 25 insertions(+), 31 deletions(-) rename test-integration/{schedulecommit/committor-service => test-committor-service}/Cargo.toml (82%) rename test-integration/{schedulecommit/committor-service => test-committor-service}/src/lib.rs (100%) rename {magicblock-committor-service => test-integration/test-committor-service}/tests/common.rs (98%) rename {magicblock-committor-service => test-integration/test-committor-service}/tests/test_delivery_preparator.rs (95%) rename test-integration/{schedulecommit/committor-service/tests/ix_commit_local.rs => test-committor-service/tests/test_ix_commit_local.rs} (100%) rename {magicblock-committor-service => test-integration/test-committor-service}/tests/test_transaction_preparator.rs (97%) rename test-integration/{schedulecommit/committor-service => test-committor-service}/tests/utils/instructions.rs (100%) rename test-integration/{schedulecommit/committor-service => test-committor-service}/tests/utils/mod.rs (100%) rename test-integration/{schedulecommit/committor-service => test-committor-service}/tests/utils/transactions.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 08e3c3460..5eeaef1d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4089,7 +4089,6 @@ dependencies = [ "base64 0.21.7", "bincode", "borsh 1.5.7", - "env_logger 0.11.8", "futures-util", "lazy_static", "log", diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index 1a4fe982a..fe78d808c 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -43,12 +43,7 @@ tokio-util = { workspace = true } tempfile = { workspace = true } [dev-dependencies] -env_logger = { workspace = true } lazy_static = { workspace = true } -magicblock-table-mania = { workspace = true, features = [ - "randomize_lookup_table_slot", -] } -tokio = { workspace = true, features = ["rt", "macros"] } rand = { workspace = true } [features] diff --git a/magicblock-committor-service/src/intent_execution_manager.rs b/magicblock-committor-service/src/intent_execution_manager.rs index a09202d99..3f0318cb4 100644 --- a/magicblock-committor-service/src/intent_execution_manager.rs +++ b/magicblock-committor-service/src/intent_execution_manager.rs @@ -1,6 +1,6 @@ pub(crate) mod db; mod intent_execution_engine; -pub(crate) mod intent_scheduler; // TODO(edwin): define visibility +pub mod intent_scheduler; use std::sync::Arc; @@ -57,7 +57,6 @@ impl IntentExecutionManager { intent_persister, receiver, ); - // TODO(edwin): add concellation logic let result_subscriber = worker.spawn(); Self { diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index c0d8f2400..178842bbc 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -9,16 +9,14 @@ pub mod service_ext; pub mod transactions; pub mod types; -pub mod intent_execution_manager; -// TODO(edwin): define visibility mod committor_processor; +pub mod intent_execution_manager; pub mod intent_executor; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; pub mod tasks; pub mod transaction_preperator; -pub mod utils; -// TODO(edwin) pub(crate) +pub(crate) mod utils; pub use compute_budget::ComputeBudgetConfig; pub use magicblock_committor_program::{ diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index b8600ec99..7bbcd6620 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -149,7 +149,6 @@ impl TaskStrategist { } // Create heap size -> index - // TODO(edwin): OPTIMIZATION. update ixs arr, since we know index, coul then reuse for tx creation let ixs = TransactionUtils::tasks_instructions(&Pubkey::new_unique(), tasks); let sizes = ixs diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index aad1d4d8b..137980c9e 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -74,7 +74,6 @@ pub trait BaseTask: Send + Sync { #[derive(Clone)] pub struct CommitTask { - // TODO: rename to commit_nonce? pub commit_id: u64, pub allow_undelegation: bool, pub committed_account: CommittedAccountV2, diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index a20e0b7bc..df7c96d4a 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -5945,13 +5945,17 @@ dependencies = [ name = "schedulecommit-committor-service" version = "0.0.0" dependencies = [ + "async-trait", + "borsh 1.5.7", "log", "magicblock-committor-program", "magicblock-committor-service", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", "magicblock-program", "magicblock-rpc-client", + "magicblock-table-mania", "program-flexi-counter", + "rand 0.8.5", "solana-account", "solana-pubkey", "solana-rpc-client", diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index d7066723b..bf5eba265 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -5,7 +5,7 @@ members = [ "programs/schedulecommit-security", "programs/sysvars", "schedulecommit/client", - "schedulecommit/committor-service", + "test-committor-service", "schedulecommit/test-scenarios", "schedulecommit/test-security", "test-cloning", @@ -28,6 +28,7 @@ edition = "2021" [workspace.dependencies] test-ledger-restore = { path = "./test-ledger-restore" } +async-trait = "0.1.77" anyhow = "1.0.86" borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" @@ -73,6 +74,7 @@ test-tools-core = { path = "../test-tools-core" } toml = "0.8.13" lazy_static = "1.4.0" tokio = "1.0" +rand = "0.8.5" [patch.crates-io] # some solana dependencies have solana-storage-proto as dependency diff --git a/test-integration/Makefile b/test-integration/Makefile index 11d6f15c8..2922b55d0 100644 --- a/test-integration/Makefile +++ b/test-integration/Makefile @@ -72,6 +72,11 @@ test-config: RUN_TESTS=config \ $(MAKE) test +test-schedule-intents: + RUN_TESTS=schedule_intents \ + $(MAKE) test + + $(FLEXI_COUNTER_SO): $(FLEXI_COUNTER_SRC) cargo build-sbf --manifest-path $(FLEXI_COUNTER_DIR)/Cargo.toml $(SCHEDULECOMMIT_SO): $(SCHEDULECOMMIT_SRC) diff --git a/test-integration/schedulecommit/committor-service/Cargo.toml b/test-integration/test-committor-service/Cargo.toml similarity index 82% rename from test-integration/schedulecommit/committor-service/Cargo.toml rename to test-integration/test-committor-service/Cargo.toml index e9e5902c3..4db726273 100644 --- a/test-integration/schedulecommit/committor-service/Cargo.toml +++ b/test-integration/test-committor-service/Cargo.toml @@ -14,9 +14,15 @@ magicblock-delegation-program = { workspace = true, features = [ magicblock-committor-service = { workspace = true, features = [ "dev-context-only-utils", ] } +magicblock-table-mania = { workspace = true, features = [ + "randomize_lookup_table_slot", +] } magicblock-program = { workspace = true } magicblock-rpc-client = { workspace = true } program-flexi-counter = { workspace = true, features = ["no-entrypoint"] } + +async-trait = { workspace = true } +borsh = { workspace = true } solana-account = { workspace = true } solana-pubkey = { workspace = true } solana-rpc-client = { workspace = true } @@ -24,6 +30,7 @@ solana-rpc-client-api = { workspace = true } solana-sdk = { workspace = true } test-tools-core = { workspace = true } tokio = { workspace = true } +rand = { workspace = true } [features] test_table_close = [] diff --git a/test-integration/schedulecommit/committor-service/src/lib.rs b/test-integration/test-committor-service/src/lib.rs similarity index 100% rename from test-integration/schedulecommit/committor-service/src/lib.rs rename to test-integration/test-committor-service/src/lib.rs diff --git a/magicblock-committor-service/tests/common.rs b/test-integration/test-committor-service/tests/common.rs similarity index 98% rename from magicblock-committor-service/tests/common.rs rename to test-integration/test-committor-service/tests/common.rs index d08e34a47..a1d15b03c 100644 --- a/magicblock-committor-service/tests/common.rs +++ b/test-integration/test-committor-service/tests/common.rs @@ -29,7 +29,7 @@ use solana_sdk::{ // Helper function to create a test RPC client pub async fn create_test_client() -> MagicblockRpcClient { - let url = "http://localhost:9002".to_string(); + let url = "http://localhost:7799".to_string(); let rpc_client = RpcClient::new_with_commitment(url, CommitmentConfig::confirmed()); diff --git a/magicblock-committor-service/tests/test_delivery_preparator.rs b/test-integration/test-committor-service/tests/test_delivery_preparator.rs similarity index 95% rename from magicblock-committor-service/tests/test_delivery_preparator.rs rename to test-integration/test-committor-service/tests/test_delivery_preparator.rs index 92a7711e5..d5e6bd06f 100644 --- a/magicblock-committor-service/tests/test_delivery_preparator.rs +++ b/test-integration/test-committor-service/tests/test_delivery_preparator.rs @@ -1,7 +1,3 @@ -// solana-test-validator \ -// --bpf-program corabpNrkBEqbTZP7xfJgSWTdBmVdLf1PARWXZbcMcS \ -// ./magicblock-committor-program/bin/magicblock_committor_program.so - use borsh::BorshDeserialize; use magicblock_committor_program::Chunks; use magicblock_committor_service::{ @@ -17,7 +13,6 @@ use crate::common::{create_commit_task, generate_random_bytes, TestFixture}; mod common; -#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_10kb_buffer() { let fixture = TestFixture::new().await; @@ -73,7 +68,6 @@ async fn test_prepare_10kb_buffer() { ); } -#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_multiple_buffers() { let fixture = TestFixture::new().await; @@ -145,7 +139,6 @@ async fn test_prepare_multiple_buffers() { } } -#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_lookup_tables() { let fixture = TestFixture::new().await; diff --git a/test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs b/test-integration/test-committor-service/tests/test_ix_commit_local.rs similarity index 100% rename from test-integration/schedulecommit/committor-service/tests/ix_commit_local.rs rename to test-integration/test-committor-service/tests/test_ix_commit_local.rs diff --git a/magicblock-committor-service/tests/test_transaction_preparator.rs b/test-integration/test-committor-service/tests/test_transaction_preparator.rs similarity index 97% rename from magicblock-committor-service/tests/test_transaction_preparator.rs rename to test-integration/test-committor-service/tests/test_transaction_preparator.rs index 62a3e2289..5cf0faafe 100644 --- a/magicblock-committor-service/tests/test_transaction_preparator.rs +++ b/test-integration/test-committor-service/tests/test_transaction_preparator.rs @@ -19,7 +19,6 @@ use crate::common::{create_committed_account, TestFixture}; mod common; -#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_commit_tx_with_single_account() { let fixture = TestFixture::new().await; @@ -54,7 +53,6 @@ async fn test_prepare_commit_tx_with_single_account() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } -#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_commit_tx_with_multiple_accounts() { let fixture = TestFixture::new().await; @@ -107,7 +105,6 @@ async fn test_prepare_commit_tx_with_multiple_accounts() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } -#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_commit_tx_with_l1_actions() { let fixture = TestFixture::new().await; @@ -166,7 +163,6 @@ async fn test_prepare_commit_tx_with_l1_actions() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } -#[ignore = "Implement MetadataFetcher for finaliztion"] #[tokio::test] async fn test_prepare_finalize_tx_with_undelegate() { let fixture = TestFixture::new().await; @@ -199,7 +195,6 @@ async fn test_prepare_finalize_tx_with_undelegate() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } -#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_finalize_tx_with_undelegate_and_actions() { let fixture = TestFixture::new().await; @@ -248,7 +243,6 @@ async fn test_prepare_finalize_tx_with_undelegate_and_actions() { assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); } -#[ignore = "TODO: startup validator"] #[tokio::test] async fn test_prepare_large_commit_tx_uses_buffers() { let fixture = TestFixture::new().await; diff --git a/test-integration/schedulecommit/committor-service/tests/utils/instructions.rs b/test-integration/test-committor-service/tests/utils/instructions.rs similarity index 100% rename from test-integration/schedulecommit/committor-service/tests/utils/instructions.rs rename to test-integration/test-committor-service/tests/utils/instructions.rs diff --git a/test-integration/schedulecommit/committor-service/tests/utils/mod.rs b/test-integration/test-committor-service/tests/utils/mod.rs similarity index 100% rename from test-integration/schedulecommit/committor-service/tests/utils/mod.rs rename to test-integration/test-committor-service/tests/utils/mod.rs diff --git a/test-integration/schedulecommit/committor-service/tests/utils/transactions.rs b/test-integration/test-committor-service/tests/utils/transactions.rs similarity index 100% rename from test-integration/schedulecommit/committor-service/tests/utils/transactions.rs rename to test-integration/test-committor-service/tests/utils/transactions.rs diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index c57fddc60..2a9df4525 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -79,7 +79,7 @@ pub fn main() { assert_cargo_tests_passed(committor_output, "committor"); assert_cargo_tests_passed(magicblock_pubsub_output, "magicblock_pubsub"); assert_cargo_tests_passed(config_output, "config"); - assert_cargo_tests_passed(schedule_intents_output, "test-schedule-intent"); + assert_cargo_tests_passed(schedule_intents_output, "schedule_intents"); } fn should_run_test(test_name: &str) -> bool { @@ -206,7 +206,7 @@ fn run_table_mania_and_committor_tests( let committor_test_output = if run_committor { let test_committor_dir = format!( "{}/../{}", - manifest_dir, "schedulecommit/committor-service" + manifest_dir, "test-committor-service" ); eprintln!("Running committor tests in {}", test_committor_dir); match run_test(test_committor_dir, Default::default()) { From cb511db786e3201dfb4ac47f8f51d470affd5e2b Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 13 Aug 2025 17:33:16 +0900 Subject: [PATCH 179/199] feat: addressing comments: more verbose messages, changes to log level + introduced cancellation logic to some of the services --- magicblock-accounts/Cargo.toml | 1 + magicblock-accounts/src/lib.rs | 2 +- ...ssor.rs => scheduled_commits_processor.rs} | 71 ++++++++++--------- magicblock-accounts/src/traits.rs | 4 ++ .../stubs/scheduled_commits_processor_stub.rs | 1 + magicblock-api/src/magic_validator.rs | 36 ++++++---- .../src/intent_execution_manager/db.rs | 2 +- .../intent_execution_engine.rs | 7 +- .../intent_scheduler.rs | 34 ++++----- .../src/intent_executor/commit_id_fetcher.rs | 10 +-- .../src/intent_executor/intent_executor.rs | 10 ++- magicblock-committor-service/src/service.rs | 27 +++++-- .../src/service_ext.rs | 36 ++++++++-- .../src/stubs/changeset_committor_stub.rs | 14 +++- test-integration/Cargo.lock | 1 + test-integration/test-runner/bin/run_tests.rs | 6 +- 16 files changed, 165 insertions(+), 97 deletions(-) rename magicblock-accounts/src/{remote_scheduled_commits_processor.rs => scheduled_commits_processor.rs} (88%) diff --git a/magicblock-accounts/Cargo.toml b/magicblock-accounts/Cargo.toml index eaa47093d..c5f5945e1 100644 --- a/magicblock-accounts/Cargo.toml +++ b/magicblock-accounts/Cargo.toml @@ -30,6 +30,7 @@ solana-rpc-client = { workspace = true } solana-rpc-client-api = { workspace = true } solana-sdk = { workspace = true } tokio = { workspace = true } +tokio-util = { workspace = true } thiserror = { workspace = true } url = { workspace = true } diff --git a/magicblock-accounts/src/lib.rs b/magicblock-accounts/src/lib.rs index 22352c1f2..e0b44a20f 100644 --- a/magicblock-accounts/src/lib.rs +++ b/magicblock-accounts/src/lib.rs @@ -2,7 +2,7 @@ mod accounts_manager; mod config; pub mod errors; mod external_accounts_manager; -pub mod remote_scheduled_commits_processor; +pub mod scheduled_commits_processor; mod traits; pub mod utils; diff --git a/magicblock-accounts/src/remote_scheduled_commits_processor.rs b/magicblock-accounts/src/scheduled_commits_processor.rs similarity index 88% rename from magicblock-accounts/src/remote_scheduled_commits_processor.rs rename to magicblock-accounts/src/scheduled_commits_processor.rs index 971db8ece..97af3f592 100644 --- a/magicblock-accounts/src/remote_scheduled_commits_processor.rs +++ b/magicblock-accounts/src/scheduled_commits_processor.rs @@ -23,14 +23,10 @@ use magicblock_program::{ }; use magicblock_transaction_status::TransactionStatusSender; use solana_sdk::{ - account::{Account, ReadableAccount}, - hash::Hash, - pubkey::Pubkey, - signature::Signature, - system_program, - transaction::Transaction, + hash::Hash, pubkey::Pubkey, signature::Signature, transaction::Transaction, }; use tokio::sync::{broadcast, oneshot}; +use tokio_util::sync::CancellationToken; use crate::{errors::AccountsResult, ScheduledCommitsProcessor}; @@ -39,15 +35,16 @@ const POISONED_RWLOCK_MSG: &str = const POISONED_MUTEX_MSG: &str = "Mutex of RemoteScheduledCommitsProcessor.intents_meta_map is poisoned"; -pub struct RemoteScheduledCommitsProcessor { +pub struct ScheduledCommitsProcessorImpl { bank: Arc, committor: Arc, + cancellation_token: CancellationToken, intents_meta_map: Arc>>, cloned_accounts: CloneOutputMap, transaction_scheduler: TransactionScheduler, } -impl RemoteScheduledCommitsProcessor { +impl ScheduledCommitsProcessorImpl { pub fn new( bank: Arc, cloned_accounts: CloneOutputMap, @@ -56,9 +53,11 @@ impl RemoteScheduledCommitsProcessor { ) -> Self { let result_subscriber = committor.subscribe_for_results(); let intents_meta_map = Arc::new(Mutex::default()); + let cancellation_token = CancellationToken::new(); tokio::spawn(Self::result_processor( bank.clone(), result_subscriber, + cancellation_token.clone(), intents_meta_map.clone(), transaction_status_sender, )); @@ -66,6 +65,7 @@ impl RemoteScheduledCommitsProcessor { Self { bank, committor, + cancellation_token, intents_meta_map, cloned_accounts, transaction_scheduler: TransactionScheduler::default(), @@ -111,27 +111,18 @@ impl RemoteScheduledCommitsProcessor { }); // We commit escrow, its data kept under FeePayer's address - match self.bank.get_account(&pubkey) { - Some(account_data) => { - account.pubkey = ephemeral_pubkey; - account.account = Account { - lamports: account_data.lamports(), - data: account_data.data().to_vec(), - owner: system_program::id(), - executable: account_data.executable(), - rent_epoch: account_data.rent_epoch(), - }; - true - } - None => { - // TODO(edwin): shouldn't be possible.. Should be a panic - error!( - "Scheduled commit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", - pubkey - ); - self.excluded_pubkeys.insert(pubkey); - false - } + if let Some(account_data) = self.bank.get_account(&pubkey) { + account.pubkey = ephemeral_pubkey; + account.account = account_data.into(); + true + } else { + // TODO(edwin): shouldn't be possible.. Should be a panic + error!( + "Scheduled commit account '{}' not found. It must have gotten undelegated and removed since it was scheduled.", + pubkey + ); + self.excluded_pubkeys.insert(pubkey); + false } } } @@ -190,6 +181,7 @@ impl RemoteScheduledCommitsProcessor { result_subscriber: oneshot::Receiver< broadcast::Receiver, >, + cancellation_token: CancellationToken, intents_meta_map: Arc>>, transaction_status_sender: TransactionStatusSender, ) { @@ -200,7 +192,18 @@ impl RemoteScheduledCommitsProcessor { let mut result_receiver = result_subscriber.await.expect(SUBSCRIPTION_ERR_MSG); - while let Ok(execution_result) = result_receiver.recv().await { + loop { + let execution_result = tokio::select! { + biased; + _ = cancellation_token.cancelled() => { + info!("ScheduledCommitsProcessorImpl stopped."); + return; + } + execution_result = result_receiver.recv() => { + execution_result.expect("Intents results should be available") + } + }; + let (intent_id, trigger_type) = execution_result .as_ref() .map(|output| (output.id, output.trigger_type)) @@ -324,7 +327,7 @@ impl RemoteScheduledCommitsProcessor { #[async_trait] impl ScheduledCommitsProcessor - for RemoteScheduledCommitsProcessor + for ScheduledCommitsProcessorImpl { async fn process(&self) -> AccountsResult<()> { let scheduled_base_intent = @@ -359,7 +362,7 @@ impl ScheduledCommitsProcessor .collect() }; - self.committor.commit_base_intent(intents); + self.committor.schedule_base_intent(intents); Ok(()) } @@ -370,6 +373,10 @@ impl ScheduledCommitsProcessor fn clear_scheduled_commits(&self) { self.transaction_scheduler.clear_scheduled_actions(); } + + fn stop(&self) { + self.cancellation_token.cancel(); + } } struct ScheduledBaseIntentMeta { diff --git a/magicblock-accounts/src/traits.rs b/magicblock-accounts/src/traits.rs index eb4de58a4..9a3b1942d 100644 --- a/magicblock-accounts/src/traits.rs +++ b/magicblock-accounts/src/traits.rs @@ -20,8 +20,12 @@ pub trait ScheduledCommitsProcessor: Send + Sync + 'static { /// Returns the number of commits that were scheduled and accepted fn scheduled_commits_len(&self) -> usize; + /// Clears all scheduled commits fn clear_scheduled_commits(&self); + + /// Stop processor + fn stop(&self); } // TODO(edwin): remove this diff --git a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs index dd179721d..5a446767e 100644 --- a/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs +++ b/magicblock-accounts/tests/stubs/scheduled_commits_processor_stub.rs @@ -13,4 +13,5 @@ impl ScheduledCommitsProcessor for ScheduledCommitsProcessorStub { 0 } fn clear_scheduled_commits(&self) {} + fn stop(&self) {} } diff --git a/magicblock-api/src/magic_validator.rs b/magicblock-api/src/magic_validator.rs index c58ad9d5f..f9c3fa863 100644 --- a/magicblock-api/src/magic_validator.rs +++ b/magicblock-api/src/magic_validator.rs @@ -25,8 +25,9 @@ use magicblock_account_updates::{ RemoteAccountUpdatesClient, RemoteAccountUpdatesWorker, }; use magicblock_accounts::{ - remote_scheduled_commits_processor::RemoteScheduledCommitsProcessor, + scheduled_commits_processor::ScheduledCommitsProcessorImpl, utils::try_rpc_cluster_from_cluster, AccountsManager, + ScheduledCommitsProcessor, }; use magicblock_accounts_api::BankAccountProvider; use magicblock_accounts_db::error::AccountsDbError; @@ -38,8 +39,8 @@ use magicblock_bank::{ transaction_logs::TransactionLogCollectorFilter, }; use magicblock_committor_service::{ - config::ChainConfig, service_ext::CommittorServiceExt, CommittorService, - ComputeBudgetConfig, + config::ChainConfig, service_ext::CommittorServiceExt, BaseIntentCommittor, + CommittorService, ComputeBudgetConfig, }; use magicblock_config::{ AccountsDbConfig, EphemeralConfig, LedgerConfig, LedgerResumeStrategy, @@ -147,8 +148,8 @@ pub struct MagicValidator { pubsub_close_handle: PubsubServiceCloseHandle, sample_performance_service: Option, commit_accounts_ticker: Option>, - remote_scheduled_commits_processor: - Option>>, + scheduled_commits_processor: + Option>>, remote_account_fetcher_worker: Option, remote_account_fetcher_handle: Option>, remote_account_updates_worker: Option, @@ -368,8 +369,8 @@ impl MagicValidator { config.validator_config.accounts.clone.clone(), ); - let remote_scheduled_commits_processor = if can_clone { - Some(Arc::new(RemoteScheduledCommitsProcessor::new( + let scheduled_commits_processor = if can_clone { + Some(Arc::new(ScheduledCommitsProcessorImpl::new( bank.clone(), remote_account_cloner_worker.get_last_clone_output(), committor_service @@ -416,7 +417,7 @@ impl MagicValidator { geyser_rpc_service, slot_ticker: None, commit_accounts_ticker: None, - remote_scheduled_commits_processor, + scheduled_commits_processor, remote_account_fetcher_worker: Some(remote_account_fetcher_worker), remote_account_fetcher_handle: None, remote_account_updates_worker: Some(remote_account_updates_worker), @@ -733,7 +734,7 @@ impl MagicValidator { self.slot_ticker = Some(init_slot_ticker( &self.bank, - &self.remote_scheduled_commits_processor, + &self.scheduled_commits_processor, self.transaction_status_sender.clone(), self.ledger.clone(), Duration::from_millis(self.config.validator.millis_per_slot), @@ -866,13 +867,22 @@ impl MagicValidator { self.exit.store(true, Ordering::Relaxed); self.rpc_service.close(); PubsubService::close(&self.pubsub_close_handle); - self.token.cancel(); - self.ledger_truncator.stop(); - self.claim_fees_task.stop(); - if let Some(committor_service) = &self.committor_service { + // Ordering is important here + // Commitor service shall be stopped last + self.token.cancel(); + if let Some(ref scheduled_commits_processor) = + self.scheduled_commits_processor + { + scheduled_commits_processor.stop(); + } + if let Some(ref committor_service) = self.committor_service { committor_service.stop(); } + + self.ledger_truncator.stop(); + self.claim_fees_task.stop(); + // wait a bit for services to stop thread::sleep(Duration::from_secs(1)); diff --git a/magicblock-committor-service/src/intent_execution_manager/db.rs b/magicblock-committor-service/src/intent_execution_manager/db.rs index 429285e68..38364b1f6 100644 --- a/magicblock-committor-service/src/intent_execution_manager/db.rs +++ b/magicblock-committor-service/src/intent_execution_manager/db.rs @@ -5,7 +5,7 @@ use async_trait::async_trait; use crate::types::ScheduledBaseIntentWrapper; -const POISONED_MUTEX_MSG: &str = "Mutex poisoned"; +const POISONED_MUTEX_MSG: &str = "Dummy db mutex poisoned"; #[async_trait] pub trait DB: Send + Sync + 'static { diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index fc7e21230..92cba8a6f 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -111,10 +111,13 @@ where loop { let intent = match self.next_scheduled_intent().await { Ok(value) => value, - Err(err) => { - error!("Failed to get next intent: {}", err); + Err(Error::ChannelClosed) => { + error!("Channel closed, exiting IntentExecutionEngine::main_loop"); break; } + Err(Error::DBError(err)) => { + panic!("Failed to fetch intent from db: {:?}", err); + } }; let Some(intent) = intent else { // intents are blocked, skipping diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs index c343e1904..d611353c8 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs @@ -135,23 +135,23 @@ impl IntentScheduler { pubkeys .iter() .for_each(|pubkey| { - let mut occupied = match self.blocked_keys.entry(*pubkey) { - Entry::Vacant(_) => unreachable!("Invariant: queue for conflicting tasks shall exist"), - Entry::Occupied(value) => value - }; - - let blocked_intents: &mut VecDeque = occupied.get_mut(); - let front = blocked_intents.pop_front(); - assert_eq!( - intent_id, - front.expect("Invariant: if intent executing, queue for each account is non-empty"), - "Invariant: executing intent must be first at qeueue" - ); - - if blocked_intents.is_empty() { - occupied.remove(); - } - }); + let mut occupied = match self.blocked_keys.entry(*pubkey) { + Entry::Vacant(_) => unreachable!("Invariant: queue for conflicting tasks shall exist"), + Entry::Occupied(value) => value + }; + + let blocked_intents: &mut VecDeque = occupied.get_mut(); + let front = blocked_intents.pop_front(); + assert_eq!( + intent_id, + front.expect("Invariant: if intent executing, queue for each account is non-empty"), + "Invariant: executing intent must be first at qeueue" + ); + + if blocked_intents.is_empty() { + occupied.remove(); + } + }); } // Returns [`ScheduledBaseIntent`] that can be executed diff --git a/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs b/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs index 1a6bce099..c5f98537c 100644 --- a/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs +++ b/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs @@ -1,8 +1,5 @@ use std::{ - collections::HashMap, - num::NonZeroUsize, - sync::{Arc, Mutex}, - time::Duration, + collections::HashMap, num::NonZeroUsize, sync::Mutex, time::Duration, }; use dlp::{ @@ -27,10 +24,9 @@ pub trait CommitIdFetcher: Send + Sync + 'static { const MUTEX_POISONED_MSG: &str = "CommitIdTrackerImpl mutex poisoned!"; -#[derive(Clone)] pub struct CommitIdTrackerImpl { rpc_client: MagicblockRpcClient, - cache: Arc>>, + cache: Mutex>, } impl CommitIdTrackerImpl { @@ -40,7 +36,7 @@ impl CommitIdTrackerImpl { Self { rpc_client, - cache: Arc::new(Mutex::new(LruCache::new(CACHE_SIZE))), + cache: Mutex::new(LruCache::new(CACHE_SIZE)), } } diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index b8021c38f..656e2d286 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -1,4 +1,4 @@ -use log::{info, warn}; +use log::{debug, warn}; use magicblock_program::{ magic_scheduled_base_intent::ScheduledBaseIntent, validator::validator_authority, @@ -68,7 +68,7 @@ where // Commit stage let commit_signature = self.execute_commit_stage(&base_intent, persister).await?; - info!("Commit stage succeeded: {}", commit_signature); + debug!("Commit stage succeeded: {}", commit_signature); // Finalize stage // At the moment validator finalizes right away @@ -76,7 +76,7 @@ where let finalize_signature = self .execute_finalize_stage(&base_intent, commit_signature, persister) .await?; - info!("Finalize stage succeeded: {}", finalize_signature); + debug!("Finalize stage succeeded: {}", finalize_signature); Ok(ExecutionOutput { commit_signature, @@ -189,9 +189,7 @@ where let update_status = CommitStatus::Failed; persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } - crate::tasks::task_builder::Error::FinalizedTasksBuildError(_) => { - // TODO: commit signature to set this - } + crate::tasks::task_builder::Error::FinalizedTasksBuildError(_) => {} } }, Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::DeliveryPreparationError(_))) => { diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 4dd580fa0..80a3ce40b 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -12,7 +12,7 @@ use tokio::{ oneshot, }, }; -use tokio_util::sync::CancellationToken; +use tokio_util::sync::{CancellationToken, WaitForCancellationFutureOwned}; use crate::{ committor_processor::CommittorProcessor, @@ -316,10 +316,6 @@ impl CommittorService { rx } - pub fn stop(&self) { - self.cancel_token.cancel(); - } - fn try_send(&self, msg: CommittorMessage) { if let Err(e) = self.sender.try_send(msg) { match e { @@ -352,7 +348,7 @@ impl BaseIntentCommittor for CommittorService { rx } - fn commit_base_intent( + fn schedule_base_intent( &self, base_intents: Vec, ) { @@ -409,6 +405,14 @@ impl BaseIntentCommittor for CommittorService { rx } + + fn stop(&self) { + self.cancel_token.cancel(); + } + + fn stopped(&self) -> WaitForCancellationFutureOwned { + self.cancel_token.clone().cancelled_owned() + } } pub trait BaseIntentCommittor: Send + Sync + 'static { @@ -420,7 +424,10 @@ pub trait BaseIntentCommittor: Send + Sync + 'static { ) -> oneshot::Receiver>; /// Commits the changeset and returns - fn commit_base_intent(&self, l1_messages: Vec); + fn schedule_base_intent( + &self, + l1_messages: Vec, + ); /// Subscribes for results of BaseIntent execution fn subscribe_for_results( @@ -446,4 +453,10 @@ pub trait BaseIntentCommittor: Send + Sync + 'static { ) -> oneshot::Receiver< CommittorServiceResult, >; + + /// Stops Committor service + fn stop(&self); + + /// Returns future which resolves once committor `stop` got called + fn stopped(&self) -> WaitForCancellationFutureOwned; } diff --git a/magicblock-committor-service/src/service_ext.rs b/magicblock-committor-service/src/service_ext.rs index 506730efe..c2cca8c60 100644 --- a/magicblock-committor-service/src/service_ext.rs +++ b/magicblock-committor-service/src/service_ext.rs @@ -7,11 +7,12 @@ use std::{ use async_trait::async_trait; use futures_util::future::join_all; -use log::error; +use log::{error, info}; use solana_pubkey::Pubkey; use solana_sdk::signature::Signature; use solana_transaction_status_client_types::EncodedConfirmedTransactionWithStatusMeta; use tokio::sync::{broadcast, oneshot, oneshot::error::RecvError}; +use tokio_util::sync::WaitForCancellationFutureOwned; use crate::{ error::CommittorServiceResult, @@ -43,7 +44,9 @@ impl CommittorServiceExt { pub fn new(inner: Arc) -> Self { let pending_messages = Arc::new(Mutex::new(HashMap::new())); let results_subscription = inner.subscribe_for_results(); + let committor_stopped = inner.stopped(); tokio::spawn(Self::dispatcher( + committor_stopped, results_subscription, pending_messages.clone(), )); @@ -55,13 +58,28 @@ impl CommittorServiceExt { } async fn dispatcher( + committor_stopped: WaitForCancellationFutureOwned, results_subscription: oneshot::Receiver< broadcast::Receiver, >, pending_message: Arc>>, ) { let mut results_subscription = results_subscription.await.unwrap(); - while let Ok(execution_result) = results_subscription.recv().await { + + tokio::pin!(committor_stopped); + loop { + // let committor_stopped = Pin::new(&mut committor_stopped); + let execution_result = tokio::select! { + biased; + _ = &mut committor_stopped => { + info!(""); + return; + } + execution_result = results_subscription.recv() => { + execution_result.expect("Intent results channel has to be alive!") + } + }; + let id = match &execution_result { Ok(value) => value.id, Err(err) => err.0, @@ -116,7 +134,7 @@ impl BaseIntentCommittorExt .collect::, _>>()? }; - self.commit_base_intent(base_intents); + self.schedule_base_intent(base_intents); let results = join_all(receivers.into_iter()) .await .into_iter() @@ -135,11 +153,11 @@ impl BaseIntentCommittor for CommittorServiceExt { self.inner.reserve_pubkeys_for_committee(committee, owner) } - fn commit_base_intent( + fn schedule_base_intent( &self, base_intents: Vec, ) { - self.inner.commit_base_intent(base_intents) + self.inner.schedule_base_intent(base_intents) } fn subscribe_for_results( @@ -173,6 +191,14 @@ impl BaseIntentCommittor for CommittorServiceExt { > { self.inner.get_transaction(signature) } + + fn stop(&self) { + self.inner.stop(); + } + + fn stopped(&self) -> WaitForCancellationFutureOwned { + self.inner.stopped() + } } impl Deref for CommittorServiceExt { diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index bf16ba8d3..741d3b338 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -11,6 +11,7 @@ use solana_transaction_status_client_types::{ EncodedTransactionWithStatusMeta, }; use tokio::sync::oneshot; +use tokio_util::sync::{CancellationToken, WaitForCancellationFutureOwned}; use crate::{ error::CommittorServiceResult, @@ -26,6 +27,7 @@ use crate::{ #[derive(Default)] pub struct ChangesetCommittorStub { + cancellation_token: CancellationToken, reserved_pubkeys_for_committee: Arc>>, #[allow(clippy::type_complexity)] committed_changesets: Arc>>, @@ -57,7 +59,7 @@ impl BaseIntentCommittor for ChangesetCommittorStub { rx } - fn commit_base_intent( + fn schedule_base_intent( &self, base_intents: Vec, ) { @@ -148,6 +150,14 @@ impl BaseIntentCommittor for ChangesetCommittorStub { rx } + + fn stop(&self) { + self.cancellation_token.cancel(); + } + + fn stopped(&self) -> WaitForCancellationFutureOwned { + self.cancellation_token.clone().cancelled_owned() + } } #[async_trait::async_trait] @@ -157,7 +167,7 @@ impl BaseIntentCommittorExt for ChangesetCommittorStub { l1_messages: Vec, ) -> BaseIntentCommitorExtResult> { - self.commit_base_intent(l1_messages.clone()); + self.schedule_base_intent(l1_messages.clone()); let res = l1_messages .into_iter() .map(|message| { diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index df7c96d4a..4646649d7 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -3688,6 +3688,7 @@ dependencies = [ "solana-sdk", "thiserror 1.0.69", "tokio", + "tokio-util 0.7.15", "url 2.5.4", ] diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index 2a9df4525..911465b0c 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -204,10 +204,8 @@ fn run_table_mania_and_committor_tests( }; let committor_test_output = if run_committor { - let test_committor_dir = format!( - "{}/../{}", - manifest_dir, "test-committor-service" - ); + let test_committor_dir = + format!("{}/../{}", manifest_dir, "test-committor-service"); eprintln!("Running committor tests in {}", test_committor_dir); match run_test(test_committor_dir, Default::default()) { Ok(output) => output, From 89a6d0c5f1f023ed1b658424e9252886ecace32e Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 14 Aug 2025 15:43:01 +0900 Subject: [PATCH 180/199] feat: improved error handling in IntentScheduler --- .../intent_execution_engine.rs | 12 +- .../intent_scheduler.rs | 250 +++++++++++++++--- .../src/intent_executor/error.rs | 4 +- .../src/intent_executor/intent_executor.rs | 8 +- .../intent_executor_factory.rs | 2 +- magicblock-committor-service/src/lib.rs | 2 +- .../delivery_preparator.rs | 0 .../error.rs | 2 +- .../mod.rs | 1 + .../transaction_preparator.rs | 2 +- .../test-committor-service/tests/common.rs | 2 +- .../tests/test_transaction_preparator.rs | 2 +- 12 files changed, 232 insertions(+), 55 deletions(-) rename magicblock-committor-service/src/{transaction_preperator => transaction_preparator}/delivery_preparator.rs (100%) rename magicblock-committor-service/src/{transaction_preperator => transaction_preparator}/error.rs (92%) rename magicblock-committor-service/src/{transaction_preperator => transaction_preparator}/mod.rs (68%) rename magicblock-committor-service/src/{transaction_preperator => transaction_preparator}/transaction_preparator.rs (99%) diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index 92cba8a6f..74a30b410 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Mutex}; use futures_util::{stream::FuturesUnordered, StreamExt}; -use log::{error, info, trace, warn}; +use log::{error, trace, warn}; use tokio::{ sync::{ broadcast, mpsc, mpsc::error::TryRecvError, OwnedSemaphorePermit, @@ -29,7 +29,6 @@ const SEMAPHORE_CLOSED_MSG: &str = "Executors semaphore closed!"; /// Max number of executors that can send messages in parallel to Base layer const MAX_EXECUTORS: u8 = 50; -// TODO(edwin): rename #[derive(Clone, Debug)] pub struct ExecutionOutputWrapper { pub id: u64, @@ -120,8 +119,10 @@ where } }; let Some(intent) = intent else { - // intents are blocked, skipping - info!("Could not schedule any intents, as all of them are blocked!"); + // We couldn't pick up intent for execution due to: + // 1. All executors are currently busy + // 2. All intents are blocked and none could be executed at the moment + trace!("Could not schedule any intents"); continue; }; @@ -252,7 +253,8 @@ where inner_scheduler .lock() .expect(POISONED_INNER_MSG) - .complete(&intent.inner); + .complete(&intent.inner) + .expect("Valid completion of priviously scheduled message"); // Free worker drop(execution_permit); diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs index d611353c8..531e25824 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs @@ -3,6 +3,7 @@ use std::collections::{hash_map::Entry, HashMap, VecDeque}; use log::warn; use magicblock_program::magic_scheduled_base_intent::ScheduledBaseIntent; use solana_pubkey::Pubkey; +use thiserror::Error; use crate::types::ScheduledBaseIntentWrapper; @@ -61,6 +62,7 @@ struct IntentMeta { /// arriving: `[c2, c1]` /// `[c2, c1]` - Even there's no overlaps with executing /// we can't proceed since blocked intent has [c1] that has to be executed first +/// For tests on those edge-cases refer to complex_blocking_test module pub(crate) struct IntentScheduler { blocked_keys: HashMap>, blocked_intents: HashMap, @@ -123,35 +125,85 @@ impl IntentScheduler { /// Completes Intent, cleaning up data after itself and allowing Intents to move forward /// NOTE: This doesn't unblock intent, hence Self::intents_blocked will return old value. /// NOTE: this shall be called on executing intents to finilize their execution. - /// Calling on incorrect `pubkeys` set will result in panic - pub fn complete(&mut self, base_intent: &ScheduledBaseIntent) { + pub fn complete( + &mut self, + base_intent: &ScheduledBaseIntent, + ) -> IntentSchedulerResult<()> { // Release data for completed intent let intent_id = base_intent.id; let Some(pubkeys) = base_intent.get_committed_pubkeys() else { // This means BaseAction, it doesn't have to be scheduled - return; + return Ok(()); }; - pubkeys - .iter() - .for_each(|pubkey| { - let mut occupied = match self.blocked_keys.entry(*pubkey) { - Entry::Vacant(_) => unreachable!("Invariant: queue for conflicting tasks shall exist"), - Entry::Occupied(value) => value - }; - - let blocked_intents: &mut VecDeque = occupied.get_mut(); - let front = blocked_intents.pop_front(); - assert_eq!( - intent_id, - front.expect("Invariant: if intent executing, queue for each account is non-empty"), - "Invariant: executing intent must be first at qeueue" - ); + if self.blocked_intents.contains_key(&intent_id) { + return Err(IntentSchedulerError::CompletingBlockedIntentError); + } - if blocked_intents.is_empty() { - occupied.remove(); + // All front of queues contain current intent id + let mut all_front = true; + // Some of front queues contain intent id + let mut some_front = false; + for pubkey in &pubkeys { + if let Some(blocked_intents) = self.blocked_keys.get(pubkey) { + // SAFETY: if entry exists it means that queue not empty + // This is ensured during scheduling as we always insert el-t in the queue + // Other state is not supposed to be possible + let front = blocked_intents.front().expect( + "Invariant: if entry is occupied, queue is non-empty", + ); + if front != &intent_id { + // This intent isn't executing + all_front = false; + } else { + some_front = true; } - }); + } else { + // This intent isn't executing since queue for it doesn't exist + all_front = false; + } + } + + // Intent is indeed executing - can complete it + if all_front { + Ok(()) + } else if some_front { + // Only some part of pubkeys is executing - corrupted intent + Err(IntentSchedulerError::CorruptedIntentError) + } else { + // Intent was never scheduled before + Err(IntentSchedulerError::NonScheduledMessageError) + }?; + + // The last check for corrupted intent + // Say some keys got account got deleted from intent: + // We will have all_front = true since number of keys is less than was initially + let found_in_front = self + .blocked_keys + .iter() + .filter(|(_, queue)| queue.front() == Some(&intent_id)) + .count(); + if found_in_front != pubkeys.len() { + return Err(IntentSchedulerError::CorruptedIntentError); + } + + // After all the checks we may safely complete + pubkeys.iter().for_each(|pubkey| { + let mut occupied = match self.blocked_keys.entry(*pubkey) { + Entry::Vacant(_) => unreachable!( + "entry exists since following was checked beforehand" + ), + Entry::Occupied(value) => value, + }; + + let blocked_intents: &mut VecDeque = occupied.get_mut(); + blocked_intents.pop_front(); + if blocked_intents.is_empty() { + occupied.remove(); + } + }); + + Ok(()) } // Returns [`ScheduledBaseIntent`] that can be executed @@ -161,6 +213,9 @@ impl IntentScheduler { // TODO(edwin): optimize. Create counter im IntentMeta & update let mut execute_candidates: HashMap = HashMap::new(); self.blocked_keys.iter().for_each(|(_, queue)| { + // SAFETY: if entry exists it means that queue not empty + // This is ensured during scheduling as we always insert el-t in the queue + // Other state is not supposed to be possible let intent_id = queue .front() .expect("Invariant: we maintain ony non-empty queues"); @@ -210,6 +265,18 @@ impl IntentScheduler { } } +#[derive(Error, Debug)] +pub enum IntentSchedulerError { + #[error("Attempt to complete non-scheduled message")] + NonScheduledMessageError, + #[error("Attempt to complete corrupted intent")] + CorruptedIntentError, + #[error("Attempt to complete blocked message")] + CompletingBlockedIntentError, +} + +pub type IntentSchedulerResult = Result; + /// Set of simple tests #[cfg(test)] mod simple_test { @@ -288,7 +355,7 @@ mod completion_simple_test { assert_eq!(scheduler.intents_blocked(), 1); // Complete first intent - scheduler.complete(&executed.inner); + assert!(scheduler.complete(&executed.inner).is_ok()); let next = scheduler.pop_next_scheduled_intent().unwrap(); assert_eq!(next, msg2); @@ -311,7 +378,7 @@ mod completion_simple_test { assert_eq!(scheduler.intents_blocked(), 2); // Complete first intent - scheduler.complete(&executed.inner); + assert!(scheduler.complete(&executed.inner).is_ok()); // Second intent should now be available let expected_msg2 = scheduler.pop_next_scheduled_intent().unwrap(); @@ -319,7 +386,7 @@ mod completion_simple_test { assert_eq!(scheduler.intents_blocked(), 1); // Complete second intent - scheduler.complete(&expected_msg2.inner); + assert!(scheduler.complete(&expected_msg2.inner).is_ok()); // Third intent should now be available let expected_msg3 = scheduler.pop_next_scheduled_intent().unwrap(); @@ -373,20 +440,20 @@ mod complex_blocking_test { assert_eq!(scheduler.intents_blocked(), 2); // Complete msg1 - scheduler.complete(&msg1.inner); + assert!(scheduler.complete(&msg1.inner).is_ok()); // None of the intents can execute yet // msg3 is blocked msg2 // msg4 is blocked by msg3 assert!(scheduler.pop_next_scheduled_intent().is_none()); // Complete msg2 - scheduler.complete(&msg2.inner); + assert!(scheduler.complete(&msg2.inner).is_ok()); // Now msg3 is unblocked let next = scheduler.pop_next_scheduled_intent().unwrap(); assert_eq!(next, msg3); assert_eq!(scheduler.intents_blocked(), 1); // Complete msg3 - scheduler.complete(&next.inner); + assert!(scheduler.complete(&next.inner).is_ok()); // Now msg4 should be available let next = scheduler.pop_next_scheduled_intent().unwrap(); @@ -433,7 +500,7 @@ mod complex_blocking_test { assert_eq!(scheduler.intents_blocked(), 2); // Complete msg1 - scheduler.complete(&executed_msg1.inner); + assert!(scheduler.complete(&executed_msg1.inner).is_ok()); // Now only msg2 should be available (not msg3) let expected_msg2 = scheduler.pop_next_scheduled_intent().unwrap(); @@ -443,7 +510,7 @@ mod complex_blocking_test { assert_eq!(scheduler.pop_next_scheduled_intent(), None); // Complete msg2 - scheduler.complete(&expected_msg2.inner); + assert!(scheduler.complete(&expected_msg2.inner).is_ok()); // Now msg3 should be available let expected_msg3 = scheduler.pop_next_scheduled_intent().unwrap(); @@ -475,7 +542,7 @@ mod complex_blocking_test { assert_eq!(scheduler.intents_blocked(), 4); // Complete msg1 - scheduler.complete(&executed1.inner); + assert!(scheduler.complete(&executed1.inner).is_ok()); // msg2 and msg4 should be available (they don't conflict) let next_msgs = [ @@ -487,7 +554,7 @@ mod complex_blocking_test { assert_eq!(scheduler.intents_blocked(), 2); // Complete msg2 - scheduler.complete(&msg2.inner); + assert!(scheduler.complete(&msg2.inner).is_ok()); // msg2 and msg4 should be available (they don't conflict) let next_intents = [ scheduler.pop_next_scheduled_intent().unwrap(), @@ -502,7 +569,6 @@ mod complex_blocking_test { #[cfg(test)] mod edge_cases_test { use magicblock_program::magic_scheduled_base_intent::MagicBaseIntent; - use solana_pubkey::pubkey; use super::*; @@ -516,19 +582,127 @@ mod edge_cases_test { assert!(scheduler.schedule(msg.clone()).is_some()); assert_eq!(scheduler.intents_blocked(), 0); } +} + +#[cfg(test)] +mod complete_error_test { + use magicblock_program::magic_scheduled_base_intent::CommittedAccountV2; + use solana_account::Account; + use solana_pubkey::pubkey; + + use super::*; #[test] - fn test_completion_without_scheduling() { + fn test_complete_non_scheduled_message() { let mut scheduler = IntentScheduler::new(); let msg = create_test_intent( 1, - &[pubkey!("11111111111111111111111111111111")], + &[pubkey!("1111111111111111111111111111111111111111111")], ); - // Completing a intent that wasn't scheduled should panic - let result = - std::panic::catch_unwind(move || scheduler.complete(&msg.inner)); - assert!(result.is_err()); + // Attempt to complete message that was never scheduled + let result = scheduler.complete(&msg.inner); + assert!(matches!( + result, + Err(IntentSchedulerError::NonScheduledMessageError) + )); + } + + #[test] + fn test_corrupted_intent_state_more_keys_initially() { + let mut scheduler = IntentScheduler::new(); + let pubkey1 = pubkey!("1111111111111111111111111111111111111111111"); + let pubkey2 = pubkey!("21111111111111111111111111111111111111111111"); + + // Schedule first intent + let mut msg1 = create_test_intent(1, &[pubkey1, pubkey2]); + assert!(scheduler.schedule(msg1.clone()).is_some()); + + // Schedule second intent that conflicts with first + let msg2 = create_test_intent(2, &[pubkey1]); + assert!(scheduler.schedule(msg2.clone()).is_none()); + + msg1.inner.get_committed_accounts_mut().unwrap().pop(); + + // Attempt to complete msg1 - should detect corrupted state + let result = scheduler.complete(&msg1.inner); + assert!(matches!( + result, + Err(IntentSchedulerError::CorruptedIntentError) + )); + } + + #[test] + fn test_corrupted_intent_state_less_keys_initially() { + let mut scheduler = IntentScheduler::new(); + let pubkey1 = pubkey!("1111111111111111111111111111111111111111111"); + let pubkey2 = pubkey!("21111111111111111111111111111111111111111111"); + let pubkey3 = pubkey!("31111111111111111111111111111111111111111111"); + + // Schedule first intent + let mut msg1 = create_test_intent(1, &[pubkey1, pubkey2]); + assert!(scheduler.schedule(msg1.clone()).is_some()); + + msg1.inner + .base_intent + .get_committed_accounts_mut() + .unwrap() + .push(CommittedAccountV2 { + pubkey: pubkey3, + account: Account::default(), + }); + + // Attempt to complete msg1 - should detect corrupted state + let result = scheduler.complete(&msg1.inner); + assert!(matches!( + result, + Err(IntentSchedulerError::CorruptedIntentError) + )); + } + + #[test] + fn test_completing_blocked_message_complex() { + let mut scheduler = IntentScheduler::new(); + let pubkey1 = pubkey!("1111111111111111111111111111111111111111111"); + let pubkey2 = pubkey!("21111111111111111111111111111111111111111111"); + + // Schedule first intent for pubkey1 only + let msg1 = create_test_intent(1, &[pubkey1]); + assert!(scheduler.schedule(msg1.clone()).is_some()); + + // Create second intent using both pubkeys + let msg2 = create_test_intent(2, &[pubkey1, pubkey2]); + // Manually add to blocked_keys without proper scheduling + scheduler.schedule(msg2.clone()); + + // Attempt to complete - should detect corrupted state + let result = scheduler.complete(&msg2.inner); + assert!(matches!( + result, + Err(IntentSchedulerError::CompletingBlockedIntentError) + )); + } + + #[test] + fn test_completing_blocked_message() { + let mut scheduler = IntentScheduler::new(); + let pubkey = pubkey!("1111111111111111111111111111111111111111111"); + + // Schedule two intents for same pubkey + let msg1 = create_test_intent(1, &[pubkey]); + let msg2 = create_test_intent(2, &[pubkey]); + + // First executes immediately + assert!(scheduler.schedule(msg1.clone()).is_some()); + // Second gets blocked + assert!(scheduler.schedule(msg2.clone()).is_none()); + + // Attempt to complete msg2 before msg1 - should detect corrupted state + let result = scheduler.complete(&msg2.inner); + assert!(matches!( + result, + Err(IntentSchedulerError::CompletingBlockedIntentError) + )); } } diff --git a/magicblock-committor-service/src/intent_executor/error.rs b/magicblock-committor-service/src/intent_executor/error.rs index 23449b21c..bd4b514a1 100644 --- a/magicblock-committor-service/src/intent_executor/error.rs +++ b/magicblock-committor-service/src/intent_executor/error.rs @@ -28,11 +28,11 @@ pub enum Error { }, #[error("FailedCommitPreparationError: {0}")] FailedCommitPreparationError( - #[source] crate::transaction_preperator::error::Error, + #[source] crate::transaction_preparator::error::Error, ), #[error("FailedFinalizePreparationError: {0}")] FailedFinalizePreparationError( - #[source] crate::transaction_preperator::error::Error, + #[source] crate::transaction_preparator::error::Error, ), } diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index 656e2d286..a16a84eac 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -19,7 +19,7 @@ use crate::{ ExecutionOutput, IntentExecutor, }, persist::{CommitStatus, CommitStatusSignatures, IntentPersister}, - transaction_preperator::transaction_preparator::TransactionPreparator, + transaction_preparator::transaction_preparator::TransactionPreparator, utils::persist_status_update_by_message_set, }; @@ -179,11 +179,11 @@ where let update_status = CommitStatus::Failed; persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } - Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::FailedToFitError)) => { + Err(Error::FailedCommitPreparationError(crate::transaction_preparator::error::Error::FailedToFitError)) => { let update_status = CommitStatus::PartOfTooLargeBundleToProcess; persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } - Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::TaskBuilderError(err))) => { + Err(Error::FailedCommitPreparationError(crate::transaction_preparator::error::Error::TaskBuilderError(err))) => { match err { crate::tasks::task_builder::Error::CommitTasksBuildError(_) => { let update_status = CommitStatus::Failed; @@ -192,7 +192,7 @@ where crate::tasks::task_builder::Error::FinalizedTasksBuildError(_) => {} } }, - Err(Error::FailedCommitPreparationError(crate::transaction_preperator::error::Error::DeliveryPreparationError(_))) => { + Err(Error::FailedCommitPreparationError(crate::transaction_preparator::error::Error::DeliveryPreparationError(_))) => { // Persisted internally }, Err(Error::FailedToCommitError {err: _, signature}) => { diff --git a/magicblock-committor-service/src/intent_executor/intent_executor_factory.rs b/magicblock-committor-service/src/intent_executor/intent_executor_factory.rs index 70d3b78fc..e07163e39 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor_factory.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor_factory.rs @@ -8,7 +8,7 @@ use crate::{ commit_id_fetcher::CommitIdTrackerImpl, IntentExecutor, IntentExecutorImpl, }, - transaction_preperator::transaction_preparator::TransactionPreparatorV1, + transaction_preparator::transaction_preparator::TransactionPreparatorV1, ComputeBudgetConfig, }; diff --git a/magicblock-committor-service/src/lib.rs b/magicblock-committor-service/src/lib.rs index 178842bbc..680e209c2 100644 --- a/magicblock-committor-service/src/lib.rs +++ b/magicblock-committor-service/src/lib.rs @@ -15,7 +15,7 @@ pub mod intent_executor; #[cfg(feature = "dev-context-only-utils")] pub mod stubs; pub mod tasks; -pub mod transaction_preperator; +pub mod transaction_preparator; pub(crate) mod utils; pub use compute_budget::ComputeBudgetConfig; diff --git a/magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs similarity index 100% rename from magicblock-committor-service/src/transaction_preperator/delivery_preparator.rs rename to magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs diff --git a/magicblock-committor-service/src/transaction_preperator/error.rs b/magicblock-committor-service/src/transaction_preparator/error.rs similarity index 92% rename from magicblock-committor-service/src/transaction_preperator/error.rs rename to magicblock-committor-service/src/transaction_preparator/error.rs index 8b56dd1a2..0d50e2a51 100644 --- a/magicblock-committor-service/src/transaction_preperator/error.rs +++ b/magicblock-committor-service/src/transaction_preparator/error.rs @@ -10,7 +10,7 @@ pub enum Error { TaskBuilderError(#[from] crate::tasks::task_builder::Error), #[error("DeliveryPreparationError: {0}")] DeliveryPreparationError( - #[from] crate::transaction_preperator::delivery_preparator::Error, + #[from] crate::transaction_preparator::delivery_preparator::Error, ), } diff --git a/magicblock-committor-service/src/transaction_preperator/mod.rs b/magicblock-committor-service/src/transaction_preparator/mod.rs similarity index 68% rename from magicblock-committor-service/src/transaction_preperator/mod.rs rename to magicblock-committor-service/src/transaction_preparator/mod.rs index f16fd819d..da4dbd3cb 100644 --- a/magicblock-committor-service/src/transaction_preperator/mod.rs +++ b/magicblock-committor-service/src/transaction_preparator/mod.rs @@ -1,3 +1,4 @@ pub mod delivery_preparator; pub mod error; +#[allow(clippy::module_inception)] pub mod transaction_preparator; diff --git a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs similarity index 99% rename from magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs rename to magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs index 10a0e62d4..4994cbaa1 100644 --- a/magicblock-committor-service/src/transaction_preperator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs @@ -16,7 +16,7 @@ use crate::{ task_strategist::TaskStrategist, utils::TransactionUtils, }, - transaction_preperator::{ + transaction_preparator::{ delivery_preparator::DeliveryPreparator, error::PreparatorResult, }, ComputeBudgetConfig, diff --git a/test-integration/test-committor-service/tests/common.rs b/test-integration/test-committor-service/tests/common.rs index a1d15b03c..157f95adc 100644 --- a/test-integration/test-committor-service/tests/common.rs +++ b/test-integration/test-committor-service/tests/common.rs @@ -11,7 +11,7 @@ use magicblock_committor_service::{ CommitIdFetcher, CommitIdTrackerResult, }, tasks::tasks::CommitTask, - transaction_preperator::{ + transaction_preparator::{ delivery_preparator::DeliveryPreparator, transaction_preparator::TransactionPreparatorV1, }, diff --git a/test-integration/test-committor-service/tests/test_transaction_preparator.rs b/test-integration/test-committor-service/tests/test_transaction_preparator.rs index 5cf0faafe..3c364c9bb 100644 --- a/test-integration/test-committor-service/tests/test_transaction_preparator.rs +++ b/test-integration/test-committor-service/tests/test_transaction_preparator.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use magicblock_committor_service::{ persist::IntentPersisterImpl, - transaction_preperator::transaction_preparator::TransactionPreparator, + transaction_preparator::transaction_preparator::TransactionPreparator, }; use magicblock_program::magic_scheduled_base_intent::{ BaseAction, CommitAndUndelegate, CommitType, CommittedAccountV2, From 14845dd89cc241524f488f02edc9f6b7dcaeb30b Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 14 Aug 2025 16:45:35 +0900 Subject: [PATCH 181/199] refactor: avoid unnecessary cloning --- .../src/scheduled_commits_processor.rs | 22 ++++++++++--------- .../src/intent_executor/intent_executor.rs | 7 ++++-- .../src/persist/commit_persister.rs | 7 +----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/magicblock-accounts/src/scheduled_commits_processor.rs b/magicblock-accounts/src/scheduled_commits_processor.rs index 97af3f592..5597970a4 100644 --- a/magicblock-accounts/src/scheduled_commits_processor.rs +++ b/magicblock-accounts/src/scheduled_commits_processor.rs @@ -258,17 +258,18 @@ impl ScheduledCommitsProcessorImpl { bank: &Arc, transaction_status_sender: &TransactionStatusSender, execution_outcome: ExecutionOutputWrapper, - intent_meta: ScheduledBaseIntentMeta, + mut intent_meta: ScheduledBaseIntentMeta, ) { let chain_signatures = vec![ execution_outcome.output.commit_signature, execution_outcome.output.finalize_signature, ]; + let intent_sent_transaction = std::mem::take(&mut intent_meta.intent_sent_transaction); let sent_commit = - Self::build_sent_commit(intent_id, chain_signatures, &intent_meta); + Self::build_sent_commit(intent_id, chain_signatures, intent_meta); register_scheduled_commit_sent(sent_commit); match execute_legacy_transaction( - intent_meta.intent_sent_transaction, + intent_sent_transaction, bank, Some(transaction_status_sender), ) { @@ -286,13 +287,14 @@ impl ScheduledCommitsProcessorImpl { intent_id: u64, bank: &Arc, transaction_status_sender: &TransactionStatusSender, - intent_meta: ScheduledBaseIntentMeta, + mut intent_meta: ScheduledBaseIntentMeta, ) { + let intent_sent_transaction = std::mem::take(&mut intent_meta.intent_sent_transaction); let sent_commit = - Self::build_sent_commit(intent_id, vec![], &intent_meta); + Self::build_sent_commit(intent_id, vec![], intent_meta); register_scheduled_commit_sent(sent_commit); match execute_legacy_transaction( - intent_meta.intent_sent_transaction, + intent_sent_transaction, bank, Some(transaction_status_sender), ) { @@ -309,7 +311,7 @@ impl ScheduledCommitsProcessorImpl { fn build_sent_commit( intent_id: u64, chain_signatures: Vec, - intent_meta: &ScheduledBaseIntentMeta, + intent_meta: ScheduledBaseIntentMeta, ) -> SentCommit { SentCommit { message_id: intent_id, @@ -317,9 +319,9 @@ impl ScheduledCommitsProcessorImpl { blockhash: intent_meta.blockhash, payer: intent_meta.payer, chain_signatures, - included_pubkeys: intent_meta.included_pubkeys.clone(), - excluded_pubkeys: intent_meta.excluded_pubkeys.clone(), - feepayers: intent_meta.feepayers.clone(), + included_pubkeys: intent_meta.included_pubkeys, + excluded_pubkeys: intent_meta.excluded_pubkeys, + feepayers: intent_meta.feepayers, requested_undelegation: intent_meta.requested_undelegation, } } diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index a16a84eac..dea4ca964 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -189,11 +189,14 @@ where let update_status = CommitStatus::Failed; persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } - crate::tasks::task_builder::Error::FinalizedTasksBuildError(_) => {} + crate::tasks::task_builder::Error::FinalizedTasksBuildError(_) => { + // During commit preparation we don't encounter following error + // so no need to persist it + } } }, Err(Error::FailedCommitPreparationError(crate::transaction_preparator::error::Error::DeliveryPreparationError(_))) => { - // Persisted internally + // Intermediate commit preparation progress recorded by DeliveryPreparator }, Err(Error::FailedToCommitError {err: _, signature}) => { // Commit is a single TX, so if it fails, all of commited accounts marked FailedProcess diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 2c6671065..13b3843f9 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -62,14 +62,13 @@ pub trait IntentPersister: Send + Sync + Clone + 'static { commit_id: u64, pubkey: &Pubkey, ) -> CommitPersistResult>; - // fn finalize_l1_message(&self blockhash: Hash) -> CommitPersistResult<()>; } #[derive(Clone)] pub struct IntentPersisterImpl { // DB that tracks lifespan of Commit intents commits_db: Arc>, - // TODO: add something like + // TODO(edwin): add something like // actions_db: Arc> } @@ -245,10 +244,6 @@ impl IntentPersister for IntentPersisterImpl { .expect(POISONED_MUTEX_MSG) .get_signatures_by_commit(commit_id, pubkey) } - - // fn finalize_l1_message(&self, blockhash: Hash) -> CommitPersistResult<()> { - // self.db.lock().expect(POISONED_MUTEX_MSG). - // } } /// Blanket implementation for Option From 73c924d776f9fc57f61a23f0bd30f5d4ecda1c1a Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 15 Aug 2025 14:49:45 +0900 Subject: [PATCH 182/199] refactor: more comments, SAFETY comments + some panics removed --- Cargo.lock | 1 + .../src/account_dumper_bank.rs | 22 ++++-------- .../src/scheduled_commits_processor.rs | 6 ++-- .../src/state/chunks.rs | 2 +- .../intent_execution_engine.rs | 4 +++ .../intent_scheduler.rs | 36 +++++++++---------- .../src/intent_executor/intent_executor.rs | 2 +- magicblock-committor-service/src/utils.rs | 7 ++-- magicblock-core/Cargo.toml | 1 + .../src/magic_program/instruction.rs | 16 +++++++++ test-integration/Cargo.lock | 1 + 11 files changed, 55 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5eeaef1d8..3ea552dca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4157,6 +4157,7 @@ version = "0.1.7" dependencies = [ "bincode", "serde", + "solana-account", "solana-program", ] diff --git a/magicblock-account-dumper/src/account_dumper_bank.rs b/magicblock-account-dumper/src/account_dumper_bank.rs index ecaee8bba..fcefefc08 100644 --- a/magicblock-account-dumper/src/account_dumper_bank.rs +++ b/magicblock-account-dumper/src/account_dumper_bank.rs @@ -146,14 +146,10 @@ impl AccountDumper for AccountDumperBank { .map_err(AccountDumperError::MutatorModificationError)?; let program_idl_modification = program_idl.map(|(program_idl_pubkey, program_idl_account)| { - AccountModification { - pubkey: program_idl_pubkey, - lamports: Some(program_idl_account.lamports), - owner: Some(program_idl_account.owner), - rent_epoch: Some(program_idl_account.rent_epoch), - data: Some(program_idl_account.data), - executable: Some(program_idl_account.executable), - } + AccountModification::from(( + &program_idl_pubkey, + &program_idl_account, + )) }); let needs_upgrade = self.bank.has_account(program_id_pubkey); let transaction = transaction_to_clone_program( @@ -183,14 +179,8 @@ impl AccountDumper for AccountDumperBank { slot, ); - let mut program_id_modification = AccountModification { - pubkey: *program_pubkey, - lamports: Some(program_account.lamports), - owner: Some(program_account.owner), - rent_epoch: Some(program_account.rent_epoch), - data: Some(program_account.data.to_owned()), - executable: Some(program_account.executable), - }; + let mut program_id_modification = + AccountModification::from((program_pubkey, program_account)); // point program account to the derived program data account address let program_id_state = bincode::serialize(&UpgradeableLoaderState::Program { diff --git a/magicblock-accounts/src/scheduled_commits_processor.rs b/magicblock-accounts/src/scheduled_commits_processor.rs index 5597970a4..7fa007d99 100644 --- a/magicblock-accounts/src/scheduled_commits_processor.rs +++ b/magicblock-accounts/src/scheduled_commits_processor.rs @@ -264,7 +264,8 @@ impl ScheduledCommitsProcessorImpl { execution_outcome.output.commit_signature, execution_outcome.output.finalize_signature, ]; - let intent_sent_transaction = std::mem::take(&mut intent_meta.intent_sent_transaction); + let intent_sent_transaction = + std::mem::take(&mut intent_meta.intent_sent_transaction); let sent_commit = Self::build_sent_commit(intent_id, chain_signatures, intent_meta); register_scheduled_commit_sent(sent_commit); @@ -289,7 +290,8 @@ impl ScheduledCommitsProcessorImpl { transaction_status_sender: &TransactionStatusSender, mut intent_meta: ScheduledBaseIntentMeta, ) { - let intent_sent_transaction = std::mem::take(&mut intent_meta.intent_sent_transaction); + let intent_sent_transaction = + std::mem::take(&mut intent_meta.intent_sent_transaction); let sent_commit = Self::build_sent_commit(intent_id, vec![], intent_meta); register_scheduled_commit_sent(sent_commit); diff --git a/magicblock-committor-program/src/state/chunks.rs b/magicblock-committor-program/src/state/chunks.rs index 536e19aa5..c31629f8b 100644 --- a/magicblock-committor-program/src/state/chunks.rs +++ b/magicblock-committor-program/src/state/chunks.rs @@ -59,7 +59,7 @@ impl Chunks { /// Returns how many bytes [`Chunks`] will occupy certain count pub fn struct_size(count: usize) -> usize { // bits: Vec, - Self::count_to_bitfield_bytes(count) * std::mem::size_of::() + Self::count_to_bitfield_bytes(count) // count: usize, + std::mem::size_of::() // chunk_size: u16, diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index 74a30b410..51fc8da6d 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -249,7 +249,11 @@ where if let Err(err) = result_sender.send(result) { error!("Failed to broadcast result: {}", err); } + // Remove executed task from Scheduler to unblock other intents + // SAFETY: Self::execute is called ONLY after IntentScheduler + // successfully is able to schedule execution of some Intent + // that means that the same Intent is SAFE to complete inner_scheduler .lock() .expect(POISONED_INNER_MSG) diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs index 531e25824..a20f5e49b 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs @@ -190,9 +190,13 @@ impl IntentScheduler { // After all the checks we may safely complete pubkeys.iter().for_each(|pubkey| { let mut occupied = match self.blocked_keys.entry(*pubkey) { - Entry::Vacant(_) => unreachable!( - "entry exists since following was checked beforehand" - ), + Entry::Vacant(_) => { + // SAFETY: prior to this we iterated all pubkeys + // and ensured that they all exist, so we never will reach this point + unreachable!( + "entry exists since following was checked beforehand" + ) + } Entry::Occupied(value) => value, }; @@ -236,26 +240,20 @@ impl IntentScheduler { // NOTE: // Other way around is also true, since execute_candidates also include // currently executing intents - let candidate = - execute_candidates.iter().find_map(|(id, ready_keys)| { - if let Some(candidate) = self.blocked_intents.get(id) { - if candidate.num_keys.eq(ready_keys) { - Some(id) + + // Find and process the first eligible intent + execute_candidates.into_iter().find_map(|(id, ready_keys)| { + match self.blocked_intents.entry(id) { + Entry::Occupied(entry) => { + if entry.get().num_keys == ready_keys { + Some(entry.remove().intent) } else { - // Not enough keys are ready None } - } else { - // This means that this intent id is currently executing & not blocked - None } - }); - - if let Some(next) = candidate { - Some(self.blocked_intents.remove(next).unwrap().intent) - } else { - None - } + _ => None, + } + }) } /// Returns number of blocked intents diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index dea4ca964..aea9f79f1 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -161,7 +161,7 @@ where } fn persist_result( - persistor: &Option

, + persistor: &P, result: &IntentExecutorResult, message_id: u64, pubkeys: &[Pubkey], diff --git a/magicblock-committor-service/src/utils.rs b/magicblock-committor-service/src/utils.rs index 9ece547b7..6fc12ab19 100644 --- a/magicblock-committor-service/src/utils.rs +++ b/magicblock-committor-service/src/utils.rs @@ -42,15 +42,14 @@ pub(crate) fn persist_status_update_set( } }); } + +/// Persists update by message/intent id pub(crate) fn persist_status_update_by_message_set( - persister: &Option

, + persister: &P, message_id: u64, pubkeys: &[Pubkey], update_status: CommitStatus, ) { - let Some(persister) = persister else { - return; - }; pubkeys.iter().for_each(|pubkey| { if let Err(err) = persister.update_status_by_message( message_id, diff --git a/magicblock-core/Cargo.toml b/magicblock-core/Cargo.toml index 62d184e1e..0520c91cc 100644 --- a/magicblock-core/Cargo.toml +++ b/magicblock-core/Cargo.toml @@ -11,3 +11,4 @@ edition.workspace = true solana-program = { workspace = true } bincode = { workspace = true } serde = { workspace = true, features = ["derive"] } +solana-account = { workspace = true } \ No newline at end of file diff --git a/magicblock-core/src/magic_program/instruction.rs b/magicblock-core/src/magic_program/instruction.rs index d367e8a66..098e4f0d3 100644 --- a/magicblock-core/src/magic_program/instruction.rs +++ b/magicblock-core/src/magic_program/instruction.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; +use solana_account::Account; use solana_program::pubkey::Pubkey; use crate::magic_program::args::MagicBaseIntentArgs; @@ -105,6 +106,21 @@ pub struct AccountModification { pub rent_epoch: Option, } +impl From<(&Pubkey, &Account)> for AccountModification { + fn from( + (account_pubkey, account): (&Pubkey, &Account), + ) -> AccountModification { + AccountModification { + pubkey: *account_pubkey, + lamports: Some(account.lamports), + owner: Some(account.owner), + executable: Some(account.executable), + data: Some(account.data.clone()), + rent_epoch: Some(account.rent_epoch), + } + } +} + #[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct AccountModificationForInstruction { pub lamports: Option, diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 4646649d7..e65bb2511 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -3886,6 +3886,7 @@ version = "0.1.7" dependencies = [ "bincode", "serde", + "solana-account", "solana-program", ] From 60b88c729603a497ea29827d59a33b357543f381 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 18 Aug 2025 15:39:41 +0900 Subject: [PATCH 183/199] fix: race-condition refactor: remove MESSAGE_ID atomic and moved id generation into MagicContext. Addressed comments feat: introduced proper filtering of duplicate intents in IntentScheduler::schedule --- .../src/scheduled_commits_processor.rs | 32 ++++- magicblock-bank/src/bank.rs | 2 +- .../intent_execution_engine.rs | 8 +- .../intent_scheduler.rs | 23 ++- .../src/intent_executor/commit_id_fetcher.rs | 5 + .../src/service_ext.rs | 17 ++- .../src/tasks/task_strategist.rs | 39 +++++- .../src/tasks/tasks.rs | 131 ++++++++++++++++++ programs/magicblock/src/magic_context.rs | 8 ++ .../src/schedule_transactions/mod.rs | 5 - .../process_schedule_base_intent.rs | 64 +++++---- .../process_schedule_commit.rs | 67 +++++---- .../schedule_base_intent_processor.rs | 2 +- 13 files changed, 310 insertions(+), 93 deletions(-) diff --git a/magicblock-accounts/src/scheduled_commits_processor.rs b/magicblock-accounts/src/scheduled_commits_processor.rs index 7fa007d99..06ba3aded 100644 --- a/magicblock-accounts/src/scheduled_commits_processor.rs +++ b/magicblock-accounts/src/scheduled_commits_processor.rs @@ -187,8 +187,6 @@ impl ScheduledCommitsProcessorImpl { ) { const SUBSCRIPTION_ERR_MSG: &str = "Failed to get subscription of results of BaseIntents execution"; - const META_ABSENT_ERR_MSG: &str = - "Absent meta for executed intent should not be possible!"; let mut result_receiver = result_subscriber.await.expect(SUBSCRIPTION_ERR_MSG); @@ -200,7 +198,19 @@ impl ScheduledCommitsProcessorImpl { return; } execution_result = result_receiver.recv() => { - execution_result.expect("Intents results should be available") + match execution_result { + Ok(result) => result, + Err(broadcast::error::RecvError::Closed) => { + info!("Intent execution got shutdown, shutting down result processor!"); + break; + } + Err(broadcast::error::RecvError::Lagged(skipped)) => { + // SAFETY: This shouldn't happen as our tx execution is faster than Intent execution on Base layer + // If this ever happens it requires investigation + error!("ScheduledCommitsProcessorImpl lags behind Intent execution! skipped: {}", skipped); + continue; + } + } } }; @@ -217,11 +227,23 @@ impl ScheduledCommitsProcessorImpl { } // Remove intent from metas - let intent_meta = intents_meta_map + let intent_meta = if let Some(intent_meta) = intents_meta_map .lock() .expect(POISONED_MUTEX_MSG) .remove(&intent_id) - .expect(META_ABSENT_ERR_MSG); + { + intent_meta + } else { + // Possible if we have duplicate Intents + // First one will remove id from map and second could fail. + // This should not happen and needs investigation! + error!( + "CRITICAL! Failed to find IntentMeta for id: {}!", + intent_id + ); + continue; + }; + match execution_result { Ok(value) => { Self::process_intent_result( diff --git a/magicblock-bank/src/bank.rs b/magicblock-bank/src/bank.rs index 27f7d5854..9678f0f65 100644 --- a/magicblock-bank/src/bank.rs +++ b/magicblock-bank/src/bank.rs @@ -1534,7 +1534,7 @@ impl Bank { let sanitized_output = self .transaction_processor - .read() + .write() .unwrap() .load_and_execute_sanitized_transactions( self, diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index 51fc8da6d..6a22c7f26 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Mutex}; use futures_util::{stream::FuturesUnordered, StreamExt}; -use log::{error, trace, warn}; +use log::{error, info, trace, warn}; use tokio::{ sync::{ broadcast, mpsc, mpsc::error::TryRecvError, OwnedSemaphorePermit, @@ -111,7 +111,7 @@ where let intent = match self.next_scheduled_intent().await { Ok(value) => value, Err(Error::ChannelClosed) => { - error!("Channel closed, exiting IntentExecutionEngine::main_loop"); + info!("Channel closed, exiting IntentExecutionEngine::main_loop"); break; } Err(Error::DBError(err)) => { @@ -247,7 +247,7 @@ where // Broadcast result to subscribers if let Err(err) = result_sender.send(result) { - error!("Failed to broadcast result: {}", err); + warn!("No result listeners of intent execution: {}", err); } // Remove executed task from Scheduler to unblock other intents @@ -258,7 +258,7 @@ where .lock() .expect(POISONED_INNER_MSG) .complete(&intent.inner) - .expect("Valid completion of priviously scheduled message"); + .expect("Valid completion of previously scheduled message"); // Free worker drop(execution_permit); diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs index a20f5e49b..9a905fd80 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs @@ -1,6 +1,6 @@ use std::collections::{hash_map::Entry, HashMap, VecDeque}; -use log::warn; +use log::error; use magicblock_program::magic_scheduled_base_intent::ScheduledBaseIntent; use solana_pubkey::Pubkey; use thiserror::Error; @@ -86,8 +86,27 @@ impl IntentScheduler { base_intent: ScheduledBaseIntentWrapper, ) -> Option { let intent_id = base_intent.inner.id; + + // To check duplicate scheduling its enough to check: + // 1. currently blocked + // 2. currently executing if self.blocked_intents.contains_key(&intent_id) { - warn!("Attempt to schedule already scheduled intent!"); + // This is critical error as we shouldn't schedule duplicate Intents! + // this requires investigation + error!("CRITICAL! Attempt to schedule already scheduled intent!"); + return None; + } + let duplicate_executing = self.blocked_keys.iter().any(|(_, queue)| { + if let Some(executing_id) = queue.front() { + &intent_id == executing_id + } else { + false + } + }); + if duplicate_executing { + // This is critical error as we shouldn't schedule duplicate Intents! + // this requires investigation + error!("CRITICAL! Attempt to schedule already scheduled intent!"); return None; } diff --git a/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs b/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs index c5f98537c..90d73b0da 100644 --- a/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs +++ b/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs @@ -163,6 +163,11 @@ impl CommitIdFetcher for CommitIdTrackerImpl { // If all in cache - great! return if to_request.is_empty() { + let mut cache = self.cache.lock().expect(MUTEX_POISONED_MSG); + result.iter().for_each(|(pubkey, id)| { + cache.push(*pubkey, *id); + }); + return Ok(result); } diff --git a/magicblock-committor-service/src/service_ext.rs b/magicblock-committor-service/src/service_ext.rs index c2cca8c60..2c229a685 100644 --- a/magicblock-committor-service/src/service_ext.rs +++ b/magicblock-committor-service/src/service_ext.rs @@ -68,15 +68,26 @@ impl CommittorServiceExt { tokio::pin!(committor_stopped); loop { - // let committor_stopped = Pin::new(&mut committor_stopped); let execution_result = tokio::select! { biased; _ = &mut committor_stopped => { - info!(""); + info!("Committor service stopped, stopping Committor extension"); return; } execution_result = results_subscription.recv() => { - execution_result.expect("Intent results channel has to be alive!") + match execution_result { + Ok(result) => result, + Err(broadcast::error::RecvError::Closed) => { + info!("Intent execution got shutdown, shutting down result Committor extension!"); + break; + } + Err(broadcast::error::RecvError::Lagged(skipped)) => { + // SAFETY: not really feasible to happen as this function is way faster than Intent execution + // requires investigation if ever happens! + error!("CommittorServiceExt lags behind Intent execution! skipped: {}", skipped); + continue; + } + } } }; diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 7bbcd6620..2f857288e 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -151,11 +151,13 @@ impl TaskStrategist { // Create heap size -> index let ixs = TransactionUtils::tasks_instructions(&Pubkey::new_unique(), tasks); + // Possible serialization failures are possible only due to size in our case + // In that case we set size to max let sizes = ixs .iter() - .map(|ix| bincode::serialized_size(ix).map(|size| size as usize)) - .collect::, _>>() - .unwrap(); + .map(|ix| bincode::serialized_size(ix).unwrap_or(u64::MAX)) + .map(|size| usize::try_from(size).unwrap_or(usize::MAX)) + .collect::>(); let mut map = sizes .into_iter() .enumerate() @@ -185,10 +187,12 @@ impl TaskStrategist { tasks[index] = optimized_task; let new_ix = tasks[index].instruction(&Pubkey::new_unique()); - let new_ix_size = bincode::serialized_size(&new_ix) - .expect("instruction serialization") - as usize; - + // Possible serialization failures are possible only due to size in our case + // In that case we set size to max + let new_ix_size = + bincode::serialized_size(&new_ix).unwrap_or(u64::MAX); + let new_ix_size = + usize::try_from(new_ix_size).unwrap_or(usize::MAX); current_tx_length = calculate_tx_length(tasks); map.push((new_ix_size, index)); } @@ -319,6 +323,27 @@ mod tests { )); } + #[test] + fn test_build_strategy_optimizes_to_buffer_u16_exceeded() { + let validator = Pubkey::new_unique(); + + let task = create_test_commit_task(1, 66_000); // Large task + let tasks = vec![Box::new(task) as Box]; + + let strategy = TaskStrategist::build_strategy( + tasks, + &validator, + &None::, + ) + .expect("Should build strategy with buffer optimization"); + + assert_eq!(strategy.optimized_tasks.len(), 1); + assert!(matches!( + strategy.optimized_tasks[0].strategy(), + TaskStrategy::Buffer + )); + } + #[test] fn test_build_strategy_creates_multiple_buffers() { // TODO: ALSO MAX NUM WITH PURE BUFFER commits, no alts diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index 137980c9e..587f354b2 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -243,6 +243,11 @@ impl BaseTask for BufferTask { committed_account.account.data.len(), MAX_WRITE_CHUNK_SIZE, ); + + // SAFETY: as object_length internally uses only already allocated or static buffers, + // and we don't use any fs writers, so the only error that may occur here is of kind + // OutOfMemory or WriteZero. This is impossible due to: + // Chunks::new panics if its size exceeds MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE or 10_240 let chunks_account_size = borsh::object_length(&chunks).unwrap() as u64; let buffer_account_size = committed_account.account.data.len() as u64; @@ -305,3 +310,129 @@ impl BaseTask for BufferTask { visitor.visit_buffer_task(self); } } + +#[cfg(test)] +mod serialization_safety_test { + use magicblock_program::magic_scheduled_base_intent::{ + ProgramArgs, ShortAccountMeta, + }; + use solana_account::Account; + + use super::*; + + // Test all ArgsTask variants + #[test] + fn test_args_task_instruction_serialization() { + let validator = Pubkey::new_unique(); + + // Test Commit variant + let commit_task = ArgsTask::Commit(CommitTask { + commit_id: 123, + allow_undelegation: true, + committed_account: CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 1000, + data: vec![1, 2, 3], + owner: Pubkey::new_unique(), + executable: false, + rent_epoch: 0, + }, + }, + }); + assert_serializable(&commit_task.instruction(&validator)); + + // Test Finalize variant + let finalize_task = ArgsTask::Finalize(FinalizeTask { + delegated_account: Pubkey::new_unique(), + }); + assert_serializable(&finalize_task.instruction(&validator)); + + // Test Undelegate variant + let undelegate_task = ArgsTask::Undelegate(UndelegateTask { + delegated_account: Pubkey::new_unique(), + owner_program: Pubkey::new_unique(), + rent_reimbursement: Pubkey::new_unique(), + }); + assert_serializable(&undelegate_task.instruction(&validator)); + + // Test L1Action variant + let l1_action = ArgsTask::L1Action(L1ActionTask { + context: Context::Undelegate, + action: BaseAction { + destination_program: Pubkey::new_unique(), + escrow_authority: Pubkey::new_unique(), + account_metas_per_program: vec![ShortAccountMeta { + pubkey: Pubkey::new_unique(), + is_writable: true, + }], + data_per_program: ProgramArgs { + data: vec![4, 5, 6], + escrow_index: 1, + }, + compute_units: 10_000, + }, + }); + assert_serializable(&l1_action.instruction(&validator)); + } + + // Test BufferTask variants + #[test] + fn test_buffer_task_instruction_serialization() { + let validator = Pubkey::new_unique(); + + let buffer_task = BufferTask::Commit(CommitTask { + commit_id: 456, + allow_undelegation: false, + committed_account: CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 2000, + data: vec![7, 8, 9], + owner: Pubkey::new_unique(), + executable: false, + rent_epoch: 0, + }, + }, + }); + assert_serializable(&buffer_task.instruction(&validator)); + } + + // Test preparation instructions + #[test] + fn test_preparation_instructions_serialization() { + let authority = Pubkey::new_unique(); + + // Test BufferTask preparation + let buffer_task = BufferTask::Commit(CommitTask { + commit_id: 789, + allow_undelegation: true, + committed_account: CommittedAccountV2 { + pubkey: Pubkey::new_unique(), + account: Account { + lamports: 3000, + data: vec![0; 1024], // Larger data to test chunking + owner: Pubkey::new_unique(), + executable: false, + rent_epoch: 0, + }, + }, + }); + + let prep_info = buffer_task.preparation_info(&authority).unwrap(); + assert_serializable(&prep_info.init_instruction); + for ix in prep_info.realloc_instructions { + assert_serializable(&ix); + } + for ix in prep_info.write_instructions { + assert_serializable(&ix); + } + } + + // Helper function to assert serialization succeeds + fn assert_serializable(ix: &Instruction) { + bincode::serialize(ix).unwrap_or_else(|e| { + panic!("Failed to serialize instruction {:?}: {}", ix, e) + }); + } +} diff --git a/programs/magicblock/src/magic_context.rs b/programs/magicblock/src/magic_context.rs index 2a67bc6cc..616d3d3a9 100644 --- a/programs/magicblock/src/magic_context.rs +++ b/programs/magicblock/src/magic_context.rs @@ -17,6 +17,7 @@ pub struct FeePayerAccount { #[derive(Debug, Default, Serialize, Deserialize)] pub struct MagicContext { + pub intent_id: u64, pub scheduled_base_intents: Vec, } @@ -33,6 +34,13 @@ impl MagicContext { } } + pub(crate) fn next_intent_id(&mut self) -> u64 { + let output = self.intent_id; + self.intent_id = self.intent_id.wrapping_add(1); + + output + } + pub(crate) fn add_scheduled_action( &mut self, base_intent: ScheduledBaseIntent, diff --git a/programs/magicblock/src/schedule_transactions/mod.rs b/programs/magicblock/src/schedule_transactions/mod.rs index 9d12a295a..f3503ed4a 100644 --- a/programs/magicblock/src/schedule_transactions/mod.rs +++ b/programs/magicblock/src/schedule_transactions/mod.rs @@ -7,8 +7,6 @@ mod process_scheduled_commit_sent; mod schedule_base_intent_processor; pub(crate) mod transaction_scheduler; -use std::sync::atomic::AtomicU64; - use magicblock_core::magic_program::MAGIC_CONTEXT_PUBKEY; pub(crate) use process_accept_scheduled_commits::*; pub(crate) use process_schedule_base_intent::*; @@ -23,9 +21,6 @@ use solana_program_runtime::{ use crate::utils::accounts::get_instruction_pubkey_with_idx; -// TODO(edwin): is reset on restart -pub(crate) static MESSAGE_ID: AtomicU64 = AtomicU64::new(0); - pub fn check_magic_context_id( invoke_context: &InvokeContext, idx: u16, diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs b/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs index c6365d6fd..5e71a501f 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_base_intent.rs @@ -1,10 +1,10 @@ -use std::{collections::HashSet, sync::atomic::Ordering}; +use std::collections::HashSet; use magicblock_core::magic_program::args::MagicBaseIntentArgs; use solana_log_collector::ic_msg; use solana_program_runtime::invoke_context::InvokeContext; use solana_sdk::{ - instruction::InstructionError, pubkey::Pubkey, + account_utils::StateMut, instruction::InstructionError, pubkey::Pubkey, transaction_context::TransactionContext, }; @@ -12,13 +12,12 @@ use crate::{ magic_scheduled_base_intent::{ConstructionContext, ScheduledBaseIntent}, schedule_transactions::{ check_magic_context_id, - schedule_base_intent_processor::schedule_base_intent_processor, - MESSAGE_ID, + schedule_base_intent_processor::change_owner_for_undelegated_accounts, }, utils::accounts::{ get_instruction_account_with_idx, get_instruction_pubkey_with_idx, }, - TransactionScheduler, + MagicContext, }; const PAYER_IDX: u16 = 0; @@ -90,46 +89,51 @@ pub(crate) fn process_schedule_base_intent( InstructionError::UnsupportedSysvar })?; + // NOTE: this is only protected by all the above checks however if the + // instruction fails for other reasons detected afterward then the commit + // stays scheduled + let context_acc = get_instruction_account_with_idx( + transaction_context, + MAGIC_CONTEXT_IDX, + )?; + let context_data = &mut context_acc.borrow_mut(); + let mut context = + MagicContext::deserialize(context_data).map_err(|err| { + ic_msg!( + invoke_context, + "Failed to deserialize MagicContext: {}", + err + ); + InstructionError::GenericError + })?; + + // Get next intent id + let intent_id = context.next_intent_id(); + // Determine id and slot - let message_id = MESSAGE_ID.fetch_add(1, Ordering::Relaxed); let construction_context = ConstructionContext::new( parent_program_id, &signers, transaction_context, invoke_context, ); - let scheduled_action = ScheduledBaseIntent::try_new( + let scheduled_intent = ScheduledBaseIntent::try_new( &args, - message_id, + intent_id, clock.slot, payer_pubkey, &construction_context, )?; - // TODO: move all logic to some Processor - // Rn this just locks accounts - schedule_base_intent_processor(&construction_context, &args)?; + + change_owner_for_undelegated_accounts(&construction_context, &args)?; let action_sent_signature = - scheduled_action.action_sent_transaction.signatures[0]; + scheduled_intent.action_sent_transaction.signatures[0]; - let context_acc = get_instruction_account_with_idx( - transaction_context, - MAGIC_CONTEXT_IDX, - )?; - TransactionScheduler::schedule_base_intent( - invoke_context, - context_acc, - scheduled_action, - ) - .map_err(|err| { - ic_msg!( - invoke_context, - "ScheduleAction ERR: failed to schedule action: {}", - err - ); - InstructionError::GenericError - })?; - ic_msg!(invoke_context, "Scheduled commit with ID: {}", message_id); + context.add_scheduled_action(scheduled_intent); + context_data.set_state(&context)?; + + ic_msg!(invoke_context, "Scheduled commit with ID: {}", intent_id); ic_msg!( invoke_context, "ScheduledCommitSent signature: {}", diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs index e1044798d..0243121f0 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs @@ -1,9 +1,10 @@ -use std::{collections::HashSet, sync::atomic::Ordering}; +use std::collections::HashSet; use solana_log_collector::ic_msg; use solana_program_runtime::invoke_context::InvokeContext; use solana_sdk::{ account::{Account, ReadableAccount}, + account_utils::StateMut, instruction::InstructionError, pubkey::Pubkey, }; @@ -14,9 +15,6 @@ use crate::{ ScheduledBaseIntent, UndelegateType, }, schedule_transactions, - schedule_transactions::{ - transaction_scheduler::TransactionScheduler, MESSAGE_ID, - }, utils::{ account_actions::set_account_owner_to_delegation_program, accounts::{ @@ -24,6 +22,7 @@ use crate::{ }, instruction_utils::InstructionUtils, }, + MagicContext, }; #[derive(Default)] @@ -185,8 +184,26 @@ pub(crate) fn process_schedule_commit( } } - // Determine id and slot - let commit_id = MESSAGE_ID.fetch_add(1, Ordering::Relaxed); + // NOTE: this is only protected by all the above checks however if the + // instruction fails for other reasons detected afterward then the commit + // stays scheduled + let context_acc = get_instruction_account_with_idx( + transaction_context, + MAGIC_CONTEXT_IDX, + )?; + let context_data = &mut context_acc.borrow_mut(); + let mut context = + MagicContext::deserialize(context_data).map_err(|err| { + ic_msg!( + invoke_context, + "Failed to deserialize MagicContext: {}", + err + ); + InstructionError::GenericError + })?; + + // Get next intent id + let intent_id = context.next_intent_id(); // It appears that in builtin programs `Clock::get` doesn't work as expected, thus // we have to get it directly from the sysvar cache. @@ -198,12 +215,10 @@ pub(crate) fn process_schedule_commit( ic_msg!(invoke_context, "Failed to get clock sysvar: {}", err); InstructionError::UnsupportedSysvar })?; - let blockhash = invoke_context.environment_config.blockhash; - let commit_sent_transaction = - InstructionUtils::scheduled_commit_sent(commit_id, blockhash); - - let commit_sent_sig = commit_sent_transaction.signatures[0]; + let action_sent_transaction = + InstructionUtils::scheduled_commit_sent(intent_id, blockhash); + let commit_sent_sig = action_sent_transaction.signatures[0]; let base_intent = if opts.request_undelegation { MagicBaseIntent::CommitAndUndelegate(CommitAndUndelegate { @@ -213,37 +228,19 @@ pub(crate) fn process_schedule_commit( } else { MagicBaseIntent::Commit(CommitType::Standalone(committed_accounts)) }; - let scheduled_base_intent = ScheduledBaseIntent { - id: commit_id, + id: intent_id, slot: clock.slot, blockhash, - action_sent_transaction: commit_sent_transaction, + action_sent_transaction, payer: *payer_pubkey, base_intent, }; - // NOTE: this is only protected by all the above checks however if the - // instruction fails for other reasons detected afterward then the commit - // stays scheduled - let context_acc = get_instruction_account_with_idx( - transaction_context, - MAGIC_CONTEXT_IDX, - )?; - TransactionScheduler::schedule_base_intent( - invoke_context, - context_acc, - scheduled_base_intent, - ) - .map_err(|err| { - ic_msg!( - invoke_context, - "ScheduleCommit ERR: failed to schedule commit: {}", - err - ); - InstructionError::GenericError - })?; - ic_msg!(invoke_context, "Scheduled commit with ID: {}", commit_id,); + context.add_scheduled_action(scheduled_base_intent); + context_data.set_state(&context)?; + + ic_msg!(invoke_context, "Scheduled commit with ID: {}", intent_id); ic_msg!( invoke_context, "ScheduledCommitSent signature: {}", diff --git a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs index b2e25827d..a669de20c 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs @@ -6,7 +6,7 @@ use crate::{ utils::account_actions::set_account_owner_to_delegation_program, }; -pub fn schedule_base_intent_processor( +pub fn change_owner_for_undelegated_accounts( construction_context: &ConstructionContext<'_, '_>, args: &MagicBaseIntentArgs, ) -> Result<(), InstructionError> { From f9d735d154950e71232d961c6dcb574eb75ad37f Mon Sep 17 00:00:00 2001 From: taco-paco Date: Mon, 18 Aug 2025 20:19:05 +0900 Subject: [PATCH 184/199] feat: remove local script --- .../configs/run-test-validator-new.sh | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100755 test-integration/configs/run-test-validator-new.sh diff --git a/test-integration/configs/run-test-validator-new.sh b/test-integration/configs/run-test-validator-new.sh deleted file mode 100755 index 6d05859a7..000000000 --- a/test-integration/configs/run-test-validator-new.sh +++ /dev/null @@ -1,35 +0,0 @@ -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -solana-test-validator \ - --log \ - --rpc-port 7799 \ - -r \ - --account mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev \ - $DIR/accounts/validator-authority.json \ - --account EpJnX7ueXk7fKojBymqmVuCuwyhDQsYcLVL1XMsBbvDX \ - $DIR/accounts/validator-fees-vault.json \ - --account 7JrkjmZPprHwtuvtuGTXp9hwfGYFAQLnLeFM52kqAgXg \ - $DIR/accounts/protocol-fees-vault.json \ - --account LUzidNSiPNjYNkxZcUm5hYHwnWPwsUfh2US1cpWwaBm \ - $DIR/accounts/luzid-authority.json \ - --limit-ledger-size \ - 1000000 \ - --bpf-program \ - DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh \ - $DIR/../schedulecommit/elfs/dlp.so \ - --bpf-program \ - DmnRGfyyftzacFb1XadYhWF6vWqXwtQk5tbr6XgR3BA1 \ - $DIR/../schedulecommit/elfs/mdp.so \ - --bpf-program \ - 9hgprgZiRWmy8KkfvUuaVkDGrqo9GzeXMohwq6BazgUY \ - $DIR/../target/deploy/program_schedulecommit.so \ - --bpf-program \ - 4RaQH3CUBMSMQsSHPVaww2ifeNEEuaDZjF9CUdFwr3xr \ - $DIR/../target/deploy/program_schedulecommit_security.so \ - --bpf-program \ - 3JnJ727jWEmPVU8qfXwtH63sCNDX7nMgsLbg8qy8aaPX \ - /Users/edwinpaco/Documents/work/MagicBlock/redline/target/deploy/redline.so \ - --bpf-program \ - CoMtrr6j336NSB5PAoAWpLe5hPgkcShWKbPgHhZxaxh \ - $DIR/../../target/deploy/magicblock_committor_program.so - From cecc12d5891116f89d1bc4211faac2d3d928911c Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 20 Aug 2025 13:01:59 +0900 Subject: [PATCH 185/199] feat: returned bundle_signature table --- .../src/intent_executor/commit_id_fetcher.rs | 5 +- .../src/intent_executor/intent_executor.rs | 21 +- .../src/intent_executor/mod.rs | 2 +- .../src/persist/commit_persister.rs | 98 +++++- .../src/persist/db.rs | 317 ++++++++++++++---- .../src/persist/types/commit_status.rs | 12 +- .../src/stubs/changeset_committor_stub.rs | 7 +- .../src/tasks/task_builder.rs | 5 +- .../test-committor-service/tests/common.rs | 4 +- 9 files changed, 379 insertions(+), 92 deletions(-) diff --git a/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs b/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs index 90d73b0da..6ab6af045 100644 --- a/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs +++ b/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs @@ -2,6 +2,7 @@ use std::{ collections::HashMap, num::NonZeroUsize, sync::Mutex, time::Duration, }; +use async_trait::async_trait; use dlp::{ delegation_metadata_seeds_from_delegated_account, state::DelegationMetadata, }; @@ -10,7 +11,7 @@ use lru::LruCache; use magicblock_rpc_client::{MagicBlockRpcClientError, MagicblockRpcClient}; use solana_pubkey::Pubkey; -#[async_trait::async_trait] +#[async_trait] pub trait CommitIdFetcher: Send + Sync + 'static { // Fetches correct next ids for pubkeys // Those ids can be used as correct commit_id during Commit @@ -127,7 +128,7 @@ impl CommitIdTrackerImpl { } /// CommitFetcher implementation that also caches most used 1000 keys -#[async_trait::async_trait] +#[async_trait] impl CommitIdFetcher for CommitIdTrackerImpl { /// Returns next ids for requested pubkeys /// If key isn't in cache, it will be requested diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index aea9f79f1..2cc10a46b 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -1,4 +1,5 @@ -use log::{debug, warn}; +use async_trait::async_trait; +use log::{debug, error, warn}; use magicblock_program::{ magic_scheduled_base_intent::ScheduledBaseIntent, validator::validator_authority, @@ -169,11 +170,15 @@ where match result { Ok(value) => { let signatures = CommitStatusSignatures { - process_signature: value.commit_signature, - finalize_signature: Some(value.commit_signature) + commit_stage_signature: value.commit_signature, + finalize_stage_signature: Some(value.commit_signature) }; let update_status = CommitStatus::Succeeded(signatures); persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); + + if let Err(err) = persistor.finalize_base_intent(message_id, *value) { + error!("Failed to persist ExecutionOutput: {}", err); + } } Err(Error::EmptyIntentError) => { let update_status = CommitStatus::Failed; @@ -201,8 +206,8 @@ where Err(Error::FailedToCommitError {err: _, signature}) => { // Commit is a single TX, so if it fails, all of commited accounts marked FailedProcess let status_signature = signature.map(|sig| CommitStatusSignatures { - process_signature: sig, - finalize_signature: None + commit_stage_signature: sig, + finalize_stage_signature: None }); let update_status = CommitStatus::FailedProcess(status_signature); persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); @@ -213,8 +218,8 @@ where Err(Error::FailedToFinalizeError {err: _, commit_signature, finalize_signature}) => { // Finalize is a single TX, so if it fails, all of commited accounts marked FailedFinalize let status_signature = CommitStatusSignatures { - process_signature: *commit_signature, - finalize_signature: *finalize_signature + commit_stage_signature: *commit_signature, + finalize_stage_signature: *finalize_signature }; let update_status = CommitStatus::FailedFinalize( status_signature); persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); @@ -223,7 +228,7 @@ where } } -#[async_trait::async_trait] +#[async_trait] impl IntentExecutor for IntentExecutorImpl where T: TransactionPreparator, diff --git a/magicblock-committor-service/src/intent_executor/mod.rs b/magicblock-committor-service/src/intent_executor/mod.rs index 2663ef641..068aa8341 100644 --- a/magicblock-committor-service/src/intent_executor/mod.rs +++ b/magicblock-committor-service/src/intent_executor/mod.rs @@ -13,7 +13,7 @@ use crate::{ intent_executor::error::IntentExecutorResult, persist::IntentPersister, }; -#[derive(Clone, Debug)] +#[derive(Clone, Copy, Debug)] pub struct ExecutionOutput { /// Commit stage signature pub commit_signature: Signature, diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 13b3843f9..0ef9a730e 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -10,16 +10,20 @@ use super::{ db::CommitStatusRow, error::CommitPersistResult, utils::now, CommitStatus, CommitStrategy, CommitType, CommittsDb, MessageSignatures, }; +use crate::{ + intent_executor::ExecutionOutput, persist::db::BundleSignatureRow, +}; const POISONED_MUTEX_MSG: &str = "Commitor Persister lock poisoned"; /// Records lifespan pf BaseIntent pub trait IntentPersister: Send + Sync + Clone + 'static { - /// Starts persisting BaseIntent + /// Starts persisting BaseIntents fn start_base_intents( &self, base_intent: &[ScheduledBaseIntent], ) -> CommitPersistResult<()>; + /// Starts persisting BaseIntent fn start_base_intent( &self, base_intent: &ScheduledBaseIntent, @@ -62,6 +66,15 @@ pub trait IntentPersister: Send + Sync + Clone + 'static { commit_id: u64, pubkey: &Pubkey, ) -> CommitPersistResult>; + fn get_bundle_signatures( + &self, + message_id: u64, + ) -> CommitPersistResult>; + fn finalize_base_intent( + &self, + message_id: u64, + execution_output: ExecutionOutput, + ) -> CommitPersistResult<()>; } #[derive(Clone)] @@ -79,6 +92,7 @@ impl IntentPersisterImpl { { let db = CommittsDb::new(db_file)?; db.create_commit_status_table()?; + db.create_bundle_signature_table()?; Ok(Self { commits_db: Arc::new(Mutex::new(db)), @@ -244,6 +258,32 @@ impl IntentPersister for IntentPersisterImpl { .expect(POISONED_MUTEX_MSG) .get_signatures_by_commit(commit_id, pubkey) } + + fn get_bundle_signatures( + &self, + message_id: u64, + ) -> CommitPersistResult> { + self.commits_db + .lock() + .expect(POISONED_MUTEX_MSG) + .get_bundle_signature_by_bundle_id(message_id) + } + + fn finalize_base_intent( + &self, + message_id: u64, + execution_output: ExecutionOutput, + ) -> CommitPersistResult<()> { + let bundle_signature_row = BundleSignatureRow::new( + message_id, + execution_output.commit_signature, + execution_output.finalize_signature, + ); + + let commits_db = self.commits_db.lock().expect(POISONED_MUTEX_MSG); + commits_db.insert_bundle_signature_row(&bundle_signature_row)?; + Ok(()) + } } /// Blanket implementation for Option @@ -361,6 +401,29 @@ impl IntentPersister for Option { None => Ok(None), } } + + fn get_bundle_signatures( + &self, + message_id: u64, + ) -> CommitPersistResult> { + match self { + Some(persister) => persister.get_bundle_signatures(message_id), + None => Ok(None), + } + } + + fn finalize_base_intent( + &self, + message_id: u64, + execution_output: ExecutionOutput, + ) -> CommitPersistResult<()> { + match self { + Some(persister) => { + persister.finalize_base_intent(message_id, execution_output) + } + None => Ok(()), + } + } } #[cfg(test)] @@ -537,8 +600,8 @@ mod tests { let process_sig = Signature::new_unique(); let finalize_sig = Signature::new_unique(); let status = CommitStatus::Succeeded(CommitStatusSignatures { - process_signature: process_sig, - finalize_signature: Some(finalize_sig), + commit_stage_signature: process_sig, + finalize_stage_signature: Some(finalize_sig), }); persister @@ -549,8 +612,33 @@ mod tests { .get_signatures_by_commit(100, &pubkey) .unwrap() .unwrap(); - assert_eq!(sigs.processed_signature, process_sig); - assert_eq!(sigs.finalized_signature, Some(finalize_sig)); + assert_eq!(sigs.commit_stage_signature, process_sig); + assert_eq!(sigs.finalize_stage_signature, Some(finalize_sig)); + } + + #[test] + fn test_finalize_base_intent() { + let (persister, _temp_file) = create_test_persister(); + let message_id = 1; + + let commit_sig = Signature::new_unique(); + let finalize_sig = Signature::new_unique(); + let execution_output = ExecutionOutput { + commit_signature: commit_sig, + finalize_signature: finalize_sig, + }; + + persister + .finalize_base_intent(message_id, execution_output) + .unwrap(); + + let bundle_sig = persister + .get_bundle_signatures(message_id) + .unwrap() + .unwrap(); + assert_eq!(bundle_sig.bundle_id, message_id); + assert_eq!(bundle_sig.commit_stage_signature, commit_sig); + assert_eq!(bundle_sig.finalize_stage_signature, finalize_sig); } #[test] diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index 0e3d13ae9..c65df44cb 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -9,7 +9,7 @@ use super::{ utils::{i64_into_u64, u64_into_i64}, CommitStatus, CommitStatusSignatures, CommitStrategy, CommitType, }; -use crate::persist::error::CommitPersistError; +use crate::persist::{error::CommitPersistError, utils::now}; // ----------------- // CommitStatusRow @@ -55,11 +55,11 @@ pub struct CommitStatusRow { #[derive(Debug)] pub struct MessageSignatures { - /// The signature of the transaction on chain that processed the commit - pub processed_signature: Signature, - /// The signature of the transaction on chain that finalized the commit - /// if applicable - pub finalized_signature: Option, + /// The signature of the transaction on chain that executed Commit Stage + pub commit_stage_signature: Signature, + /// The signature of the transaction on chain that executed Finalize Stage + /// if they were executed in 1 tx it is the same as [Self::commit_stage_signature]. + pub finalize_stage_signature: Option, /// Time since epoch at which the bundle signature was created pub created_at: u64, } @@ -118,8 +118,8 @@ const ALL_COMMIT_STATUS_COLUMNS: &str = " created_at, commit_strategy, commit_status, - processed_signature, - finalized_signature, + commit_stage_signature, + finalize_stage_signature, last_retried_at, retries_count "; @@ -139,13 +139,68 @@ SELECT created_at, commit_strategy, commit_status, - processed_signature, - finalized_signature, + commit_stage_signature, + finalize_stage_signature, last_retried_at, retries_count FROM commit_status "#; +// ----------------- +// Bundle Signature +// ----------------- +// The BundleSignature table exists to store mappings from bundle_id to the signatures used +// to commit/finalize these bundles. +// The signatures are repeated in the commit_status table, however the rows in there have a +// different lifetime than the bundle signature rows. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct BundleSignatureRow { + /// The id of the bundle that was commited + /// If an account was not part of a bundle it is treated as a single account bundle + /// for consistency. + /// The bundle_id is unique + pub bundle_id: u64, + /// The signature of the transaction that executed Commit stage + pub commit_stage_signature: Signature, + /// The signature of the transaction that executed Finalize stage + /// if Commit & Finalize stages this will equal [Self::commit_stage_signature] + pub finalize_stage_signature: Signature, + /// Time since epoch at which the bundle signature was created + pub created_at: u64, +} + +impl BundleSignatureRow { + pub fn new( + bundle_id: u64, + commit_stage_signature: Signature, + finalize_stage_signature: Signature, + ) -> Self { + let created_at = now(); + Self { + bundle_id, + commit_stage_signature, + finalize_stage_signature, + created_at, + } + } +} + +const ALL_BUNDLE_SIGNATURE_COLUMNS: &str = r#" + bundle_id, + commit_stage_signature, + finalize_stage_signature, + created_at +"#; + +const SELECT_ALL_BUNDLE_SIGNATURE_COLUMNS: &str = r#" +SELECT + bundle_id, + commit_stage_signature, + finalize_stage_signature, + created_at +FROM bundle_signature +"#; + // ----------------- // CommittorDb // ----------------- @@ -178,18 +233,20 @@ impl CommittsDb { let query = "UPDATE commit_status SET commit_status = ?1, - processed_signature = ?2, - finalized_signature = ?3 + commit_stage_signature = ?2, + finalize_stage_signature = ?3 WHERE pubkey = ?4 AND message_id = ?5"; let tx = self.conn.transaction()?; tx.prepare(query)?.execute(params![ status.as_str(), - status.signatures().map(|s| s.process_signature.to_string()), status .signatures() - .and_then(|s| s.finalize_signature) + .map(|s| s.commit_stage_signature.to_string()), + status + .signatures() + .and_then(|s| s.finalize_stage_signature) .map(|s| s.to_string()), pubkey.to_string(), message_id @@ -208,18 +265,20 @@ impl CommittsDb { let query = "UPDATE commit_status SET commit_status = ?1, - processed_signature = ?2, - finalized_signature = ?3 + commit_stage_signature = ?2, + finalize_stage_signature = ?3 WHERE pubkey = ?4 AND commit_id = ?5"; let tx = self.conn.transaction()?; tx.prepare(query)?.execute(params![ status.as_str(), - status.signatures().map(|s| s.process_signature.to_string()), status .signatures() - .and_then(|s| s.finalize_signature) + .map(|s| s.commit_stage_signature.to_string()), + status + .signatures() + .and_then(|s| s.finalize_stage_signature) .map(|s| s.to_string()), pubkey.to_string(), commit_id @@ -283,23 +342,23 @@ impl CommittsDb { " BEGIN; CREATE TABLE IF NOT EXISTS commit_status ( - message_id INTEGER NOT NULL, - pubkey TEXT NOT NULL, - commit_id INTEGER NOT NULL, - delegated_account_owner TEXT NOT NULL, - slot INTEGER NOT NULL, - ephemeral_blockhash TEXT NOT NULL, - undelegate INTEGER NOT NULL, - lamports INTEGER NOT NULL, - data BLOB, - commit_type TEXT NOT NULL, - created_at INTEGER NOT NULL, - commit_strategy TEXT NOT NULL, - commit_status TEXT NOT NULL, - processed_signature TEXT, - finalized_signature TEXT, - last_retried_at INTEGER NOT NULL, - retries_count INTEGER NOT NULL, + message_id INTEGER NOT NULL, + pubkey TEXT NOT NULL, + commit_id INTEGER NOT NULL, + delegated_account_owner TEXT NOT NULL, + slot INTEGER NOT NULL, + ephemeral_blockhash TEXT NOT NULL, + undelegate INTEGER NOT NULL, + lamports INTEGER NOT NULL, + data BLOB, + commit_type TEXT NOT NULL, + created_at INTEGER NOT NULL, + commit_strategy TEXT NOT NULL, + commit_status TEXT NOT NULL, + commit_stage_signature TEXT, + finalize_stage_signature TEXT, + last_retried_at INTEGER NOT NULL, + retries_count INTEGER NOT NULL, PRIMARY KEY (message_id, commit_id, pubkey) ); CREATE INDEX IF NOT EXISTS idx_commits_pubkey ON commit_status (pubkey); @@ -315,6 +374,96 @@ impl CommittsDb { } } + // ----------------- + // Bundle Signature + // ----------------- + pub fn create_bundle_signature_table(&self) -> Result<()> { + match self.conn.execute_batch( + " + BEGIN; + CREATE TABLE IF NOT EXISTS bundle_signature ( + bundle_id INTEGER NOT NULL PRIMARY KEY, + commit_stage_signature TEXT NOT NULL, + finalize_stage_signature TEXT, + created_at INTEGER NOT NULL + ); + CREATE INDEX IF NOT EXISTS idx_bundle_signature ON bundle_signature (bundle_id); + COMMIT;", + ) { + Ok(_) => Ok(()), + Err(err) => { + eprintln!("Error creating bundle_signature table: {}", err); + Err(err) + } + } + } + + pub fn insert_bundle_signature_row( + &self, + bundle_signature: &BundleSignatureRow, + ) -> CommitPersistResult<()> { + let query = format!("INSERT OR REPLACE INTO bundle_signature ({ALL_BUNDLE_SIGNATURE_COLUMNS}) + VALUES (?1, ?2, ?3, ?4)"); + + self.conn.execute( + &query, + params![ + bundle_signature.bundle_id, + bundle_signature.commit_stage_signature.to_string(), + bundle_signature.finalize_stage_signature.to_string(), + u64_into_i64(bundle_signature.created_at) + ], + )?; + + Ok(()) + } + + pub fn get_bundle_signature_by_bundle_id( + &self, + bundle_id: u64, + ) -> CommitPersistResult> { + let query = format!( + "{SELECT_ALL_BUNDLE_SIGNATURE_COLUMNS} WHERE bundle_id = ?1" + ); + let stmt = &mut self.conn.prepare(&query)?; + let mut rows = stmt.query(params![bundle_id])?; + + if let Some(row) = rows.next()? { + let bundle_signature_row = Self::extract_bundle_signature_row(row)?; + Ok(Some(bundle_signature_row)) + } else { + Ok(None) + } + } + + fn extract_bundle_signature_row( + row: &rusqlite::Row, + ) -> CommitPersistResult { + let bundle_id: u64 = { + let bundle_id: i64 = row.get(0)?; + i64_into_u64(bundle_id) + }; + let commit_stage_signature = { + let processed_signature: String = row.get(1)?; + Signature::from_str(processed_signature.as_str())? + }; + let finalize_stage_signature = { + let finalized_signature: String = row.get(2)?; + Signature::from_str(finalized_signature.as_str())? + }; + let created_at: u64 = { + let created_at: i64 = row.get(3)?; + i64_into_u64(created_at) + }; + + Ok(BundleSignatureRow { + bundle_id, + commit_stage_signature, + finalize_stage_signature, + created_at, + }) + } + pub fn insert_commit_status_rows( &mut self, commit_rows: &[CommitStatusRow], @@ -335,11 +484,12 @@ impl CommittsDb { tx: &Transaction<'_>, commit: &CommitStatusRow, ) -> CommitPersistResult<()> { - let (processed_signature, finalized_signature) = + let (commit_stage_signature, finalize_stage_signature) = match commit.commit_status.signatures() { - Some(sigs) => { - (Some(sigs.process_signature), sigs.finalize_signature) - } + Some(sigs) => ( + Some(sigs.commit_stage_signature), + sigs.finalize_stage_signature, + ), None => (None, None), }; tx.execute( @@ -361,10 +511,10 @@ impl CommittsDb { u64_into_i64(commit.created_at), commit.commit_strategy.as_str(), commit.commit_status.as_str(), - processed_signature + commit_stage_signature .as_ref() .map(|s| s.to_string()), - finalized_signature + finalize_stage_signature .as_ref() .map(|s| s.to_string()), u64_into_i64(commit.last_retried_at), @@ -431,7 +581,7 @@ impl CommittsDb { ) -> CommitPersistResult> { let query = " SELECT - processed_signature, finalized_signature, created_at + commit_stage_signature, finalize_stage_signature, created_at FROM commit_status WHERE commit_id = ?1 AND pubkey = ?2 LIMIT 1"; @@ -442,15 +592,15 @@ impl CommittsDb { let result = rows .next()? .map(|row| { - let processed_signature: String = row.get(0)?; - let finalized_signature: Option = row.get(1)?; + let commit_stage_signature: String = row.get(0)?; + let finalize_stage_signature: Option = row.get(1)?; let created_at: i64 = row.get(2)?; Ok::<_, CommitPersistError>(MessageSignatures { - processed_signature: Signature::from_str( - &processed_signature, + commit_stage_signature: Signature::from_str( + &commit_stage_signature, )?, - finalized_signature: finalized_signature + finalize_stage_signature: finalize_stage_signature .map(|s| Signature::from_str(&s)) .transpose()?, created_at: i64_into_u64(created_at), @@ -534,21 +684,21 @@ fn extract_committor_row( let commit_status = { let commit_status: String = row.get(12)?; - let processed_signature = { - let processed_signature: Option = row.get(13)?; - processed_signature + let commit_stage_signature = { + let commit_stage_signature: Option = row.get(13)?; + commit_stage_signature .map(|s| Signature::from_str(s.as_str())) .transpose()? }; - let finalized_signature = { - let finalized_signature: Option = row.get(14)?; - finalized_signature + let finalize_stage_signature = { + let finalize_stage_signature: Option = row.get(14)?; + finalize_stage_signature .map(|s| Signature::from_str(s.as_str())) .transpose()? }; - let sigs = processed_signature.map(|s| CommitStatusSignatures { - process_signature: s, - finalize_signature: finalized_signature, + let sigs = commit_stage_signature.map(|s| CommitStatusSignatures { + commit_stage_signature: s, + finalize_stage_signature, }); CommitStatus::try_from((commit_status.as_str(), sigs))? }; @@ -593,6 +743,7 @@ mod tests { let temp_file = NamedTempFile::new().unwrap(); let db = CommittsDb::new(temp_file.path()).unwrap(); db.create_commit_status_table().unwrap(); + db.create_bundle_signature_table().unwrap(); (db, temp_file) } @@ -631,6 +782,19 @@ mod tests { assert!(table_exists); } + #[test] + fn test_bundle_signature_table_creation() { + let (db, _) = setup_test_db(); + + // Verify bundle_signature table exists + let table_exists: bool = db.conn.query_row( + "SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='bundle_signature')", + [], + |row| row.get(0), + ).unwrap(); + assert!(table_exists); + } + #[test] fn test_insert_and_retrieve_rows() { let (mut db, _file) = setup_test_db(); @@ -652,6 +816,33 @@ mod tests { assert_eq!(retrieved, row1); } + #[test] + fn test_insert_and_retrieve_bundle_signature() { + let (db, _file) = setup_test_db(); + let bundle_id = 123; + let commit_sig = Signature::new_unique(); + let finalize_sig = Signature::new_unique(); + + let bundle_row = + BundleSignatureRow::new(bundle_id, commit_sig, finalize_sig); + db.insert_bundle_signature_row(&bundle_row).unwrap(); + + let retrieved = db + .get_bundle_signature_by_bundle_id(bundle_id) + .unwrap() + .unwrap(); + assert_eq!(retrieved.bundle_id, bundle_id); + assert_eq!(retrieved.commit_stage_signature, commit_sig); + assert_eq!(retrieved.finalize_stage_signature, finalize_sig); + } + + #[test] + fn test_get_nonexistent_bundle_signature() { + let (db, _file) = setup_test_db(); + let result = db.get_bundle_signature_by_bundle_id(999).unwrap(); + assert!(result.is_none()); + } + #[test] fn test_set_commit_id() { let (mut db, _file) = setup_test_db(); @@ -687,8 +878,8 @@ mod tests { db.insert_commit_status_rows(&[row.clone()]).unwrap(); let new_status = CommitStatus::Succeeded(CommitStatusSignatures { - process_signature: Signature::new_unique(), - finalize_signature: None, + commit_stage_signature: Signature::new_unique(), + finalize_stage_signature: None, }); db.update_status_by_commit(100, &row.pubkey, &new_status) .unwrap(); @@ -714,13 +905,13 @@ mod tests { #[test] fn test_get_signatures_by_commit() { let (mut db, _file) = setup_test_db(); - let process_sig = Signature::new_unique(); + let commit_stage_signature = Signature::new_unique(); let finalize_sig = Signature::new_unique(); let mut row = create_test_row(1, 100); row.commit_status = CommitStatus::Succeeded(CommitStatusSignatures { - process_signature: process_sig, - finalize_signature: Some(finalize_sig), + commit_stage_signature, + finalize_stage_signature: Some(finalize_sig), }); db.insert_commit_status_rows(&[row.clone()]).unwrap(); @@ -728,8 +919,8 @@ mod tests { .get_signatures_by_commit(100, &row.pubkey) .unwrap() .unwrap(); - assert_eq!(sigs.processed_signature, process_sig); - assert_eq!(sigs.finalized_signature, Some(finalize_sig)); + assert_eq!(sigs.commit_stage_signature, commit_stage_signature); + assert_eq!(sigs.finalize_stage_signature, Some(finalize_sig)); } #[test] diff --git a/magicblock-committor-service/src/persist/types/commit_status.rs b/magicblock-committor-service/src/persist/types/commit_status.rs index ddd22a944..595c9ec61 100644 --- a/magicblock-committor-service/src/persist/types/commit_status.rs +++ b/magicblock-committor-service/src/persist/types/commit_status.rs @@ -112,13 +112,13 @@ impl TryFrom<(&str, Option)> for CommitStatus { #[derive(Debug, Clone, PartialEq, Eq)] pub struct CommitStatusSignatures { - /// The signature of the transaction processing the commit - pub process_signature: Signature, - /// The signature of the transaction finalizing the commit. + /// The signature of the transaction processing Commit stage + pub commit_stage_signature: Signature, + /// The signature of the transaction processing Finalize Stage. /// If the account was not finalized or it failed then this is `None`. - /// If the finalize instruction was part of the process transaction then - /// this signature is the same as [Self::process_signature]. - pub finalize_signature: Option, + /// If the finalize instruction was part of the Commit stage transaction then + /// this signature is the same as [Self::commit_stage_signature]. + pub finalize_stage_signature: Option, } impl CommitStatus { diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index 741d3b338..db90ec119 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -4,6 +4,7 @@ use std::{ time::{Instant, SystemTime, UNIX_EPOCH}, }; +use async_trait::async_trait; use solana_pubkey::Pubkey; use solana_sdk::signature::Signature; use solana_transaction_status_client_types::{ @@ -113,8 +114,8 @@ impl BaseIntentCommittor for ChangesetCommittorStub { { let (tx, rx) = oneshot::channel(); let message_signature = MessageSignatures { - processed_signature: Signature::new_unique(), - finalized_signature: Some(Signature::new_unique()), + commit_stage_signature: Signature::new_unique(), + finalize_stage_signature: Some(Signature::new_unique()), created_at: now(), }; @@ -160,7 +161,7 @@ impl BaseIntentCommittor for ChangesetCommittorStub { } } -#[async_trait::async_trait] +#[async_trait] impl BaseIntentCommittorExt for ChangesetCommittorStub { async fn schedule_base_intents_waiting( &self, diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 6c6d7112a..fccd03911 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use async_trait::async_trait; use dlp::{args::Context, state::DelegationMetadata}; use log::error; use magicblock_program::magic_scheduled_base_intent::{ @@ -18,7 +19,7 @@ use crate::{ }, }; -#[async_trait::async_trait] +#[async_trait] pub trait TasksBuilder { // Creates tasks for commit stage async fn commit_tasks( @@ -83,7 +84,7 @@ impl TaskBuilderV1 { } } -#[async_trait::async_trait] +#[async_trait] impl TasksBuilder for TaskBuilderV1 { /// Returns [`Task`]s for Commit stage async fn commit_tasks( diff --git a/test-integration/test-committor-service/tests/common.rs b/test-integration/test-committor-service/tests/common.rs index 157f95adc..336a7c925 100644 --- a/test-integration/test-committor-service/tests/common.rs +++ b/test-integration/test-committor-service/tests/common.rs @@ -5,7 +5,7 @@ use std::{ Arc, }, }; - +use async_trait::async_trait; use magicblock_committor_service::{ intent_executor::commit_id_fetcher::{ CommitIdFetcher, CommitIdTrackerResult, @@ -96,7 +96,7 @@ impl TestFixture { pub struct MockCommitIdFetcher; -#[async_trait::async_trait] +#[async_trait] impl CommitIdFetcher for MockCommitIdFetcher { async fn fetch_next_commit_ids( &self, From a8ff298aadbf7c13d6d66c99449ac535c986def2 Mon Sep 17 00:00:00 2001 From: edwin <102215563+taco-paco@users.noreply.github.com> Date: Wed, 20 Aug 2025 15:16:43 +0900 Subject: [PATCH 186/199] Optimization: executing Commit & Finalize stages in one tx (#510) feat: executing Commit & Finalize stages in one tx. Some code restructuring as well, IntentExecutor now has control over tasks directly, which will be useful for retry logic. ## Greptile Summary This PR implements a significant performance optimization that combines the Commit and Finalize stages into a single transaction when possible, reducing on-chain transaction costs and improving efficiency. The change introduces an `ExecutionOutput` enum with `SingleStage` and `TwoStage` variants to support both the optimized single-transaction execution and maintain backward compatibility with the traditional two-stage approach. The architectural refactoring gives the `IntentExecutor` direct control over task creation and execution strategies. A new unified transaction preparation system replaces the previous separate commit/finalize methods, allowing the executor to attempt combining operations when they fit within transaction limits (hardcoded at 22 tasks to avoid CPI limits). The system falls back to two-stage execution when the single transaction would be too large. Key components were renamed and expanded: `CommitIdFetcher` became `TaskInfoFetcher` with additional capabilities to fetch rent reimbursements, and `TransactionPreparatorV1` was simplified to work with unified `TransactionStrategy` objects. The changes also include updates to test infrastructure, integration tests, and configuration files to support the new execution model. The `dyn-clone` dependency was added to enable cloning of trait objects, which is necessary for the optimization logic that tests different execution strategies. This optimization is designed as a temporary solution until challenge windows are implemented, which will require proper two-stage protocol execution. ## Confidence score: 3/5 - This PR introduces significant architectural changes that could affect transaction execution reliability - Score lowered due to hardcoded limits (22 tasks) and complex fallback logic that may not handle all edge cases - Pay close attention to `intent_executor.rs`, `transaction_preparator.rs`, and test files for potential transaction size or CPI depth issues --- Cargo.lock | 7 + Cargo.toml | 1 + .../src/scheduled_commits_processor.rs | 12 +- magicblock-committor-service/Cargo.toml | 1 + .../bin/magicblock_committor_program.so | Bin 127312 -> 0 bytes .../src/intent_execution_manager.rs | 4 +- .../intent_execution_engine.rs | 17 +- .../src/intent_executor/error.rs | 14 +- .../src/intent_executor/intent_executor.rs | 312 ++++++++++++--- .../intent_executor_factory.rs | 23 +- .../src/intent_executor/mod.rs | 18 +- ...mit_id_fetcher.rs => task_info_fetcher.rs} | 91 +++-- .../src/persist/commit_persister.rs | 15 +- .../src/persist/db.rs | 80 ++-- .../src/stubs/changeset_committor_stub.rs | 2 +- .../src/tasks/task_builder.rs | 107 ++--- .../src/tasks/tasks.rs | 5 +- .../src/tasks/utils.rs | 4 + .../src/transaction_preparator/error.rs | 4 - .../transaction_preparator.rs | 122 ++---- test-integration/Cargo.lock | 7 + .../configs/run-test-validator.sh | 5 +- .../test-scenarios/tests/utils/mod.rs | 14 +- .../test-committor-service/tests/common.rs | 41 +- .../tests/test_ix_commit_local.rs | 100 ++--- .../tests/test_transaction_preparator.rs | 375 +++++++++--------- test-integration/test-config/src/lib.rs | 2 +- .../tests/auto_airdrop_feepayer.rs | 34 +- .../tests/07_commit_delegated_account.rs | 5 +- .../tests/08_commit_update.rs | 4 +- .../tests/test_claim_fees.rs | 2 +- test-integration/test-runner/bin/run_tests.rs | 11 +- .../tests/test_schedule_intents.rs | 65 ++- 33 files changed, 847 insertions(+), 657 deletions(-) delete mode 100755 magicblock-committor-service/bin/magicblock_committor_program.so rename magicblock-committor-service/src/intent_executor/{commit_id_fetcher.rs => task_info_fetcher.rs} (72%) diff --git a/Cargo.lock b/Cargo.lock index 3ea552dca..70eaf4477 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1879,6 +1879,12 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + [[package]] name = "eager" version = "0.1.0" @@ -4089,6 +4095,7 @@ dependencies = [ "base64 0.21.7", "bincode", "borsh 1.5.7", + "dyn-clone", "futures-util", "lazy_static", "log", diff --git a/Cargo.toml b/Cargo.toml index aca7dc4f3..75d3a7fc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,6 +74,7 @@ conjunto-transwise = { git = "https://github.com/magicblock-labs/conjunto.git", console-subscriber = "0.2.0" crossbeam-channel = "0.5.11" const_format = "0.2.34" +dyn-clone = "1.0.20" ed25519-dalek = "1.0.1" enum-iterator = "1.5.0" env_logger = "0.11.2" diff --git a/magicblock-accounts/src/scheduled_commits_processor.rs b/magicblock-accounts/src/scheduled_commits_processor.rs index 06ba3aded..37a1922f4 100644 --- a/magicblock-accounts/src/scheduled_commits_processor.rs +++ b/magicblock-accounts/src/scheduled_commits_processor.rs @@ -12,6 +12,7 @@ use magicblock_committor_service::{ intent_execution_manager::{ BroadcastedIntentExecutionResult, ExecutionOutputWrapper, }, + intent_executor::ExecutionOutput, types::{ScheduledBaseIntentWrapper, TriggerType}, BaseIntentCommittor, }; @@ -282,10 +283,13 @@ impl ScheduledCommitsProcessorImpl { execution_outcome: ExecutionOutputWrapper, mut intent_meta: ScheduledBaseIntentMeta, ) { - let chain_signatures = vec![ - execution_outcome.output.commit_signature, - execution_outcome.output.finalize_signature, - ]; + let chain_signatures = match execution_outcome.output { + ExecutionOutput::SingleStage(signature) => vec![signature], + ExecutionOutput::TwoStage { + commit_signature, + finalize_signature, + } => vec![commit_signature, finalize_signature], + }; let intent_sent_transaction = std::mem::take(&mut intent_meta.intent_sent_transaction); let sent_commit = diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index fe78d808c..4ad6482e5 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -26,6 +26,7 @@ anyhow = { workspace = true } base64 = { workspace = true } bincode = { workspace = true } borsh = { workspace = true } +dyn-clone = { workspace = true } futures-util = { workspace = true } log = { workspace = true } lru = { workspace = true } diff --git a/magicblock-committor-service/bin/magicblock_committor_program.so b/magicblock-committor-service/bin/magicblock_committor_program.so deleted file mode 100755 index 6ac2d9e3a2df3ad2d5c6e949b91e90c5117a664d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 127312 zcmeFa37lO=aW8!CjIOo-V@p1k7!bOnbv!UImN!|!VPsjh5fIDEWsHNc#^XV<92;Ga zvD7-r=aFS>*^kA$g#tk{BTFK{4`t!AcpkgYKMA5FJSofoW!=k2 zAJPcbGSl@%Oat$cJNX-U(^fXrCwPttzWT)mCxz4aGXY%pGW?Zx1RZF6QmW0B_MeF8DYM2-2ULY}U_UUVRng`2&p6 z4g%=acAfvL*uXgcUqE>Di#=yM-9zk1k*=&p_`1i|F8FY3&*c4Ze&q5Y?ICo}GPU5^-3t2u+E=ndBQeWl5tK7?Z6qYSfpU@E!2A=9|Gs$q z4IcbBTiWq)>|c1UBC0b=AlGQ2I)w_+C*%sa$UXaC7K?%aJYRZ4l9W{{nEu4;ktQ6< z|3cC(e=kLQpDeWZRk0y)doPRH^KtTa!z}a){U#ql-*uf0`eJ>*{c-jI@J~wrpReKD1cr>b4PACt^zc0!MzLyEU`buCY-3^5lZpWX)&mwlQwbkk^w0e2D)tl9;6~pPv8P6`@Ih*MmkI|X8bGG5>uzI3` z+P=+KRnaqq&|&T8njPz=962_6{He$e%4={H^U`NDD}hq4UT%d^Uw^xTCvyc4DYSWe5LRzIUD=IC<#Wu2{dE3~0WQtG~g|pueP_Xl|GZ<+E~4#-C&)_024s-@`cPv!GZ0ZYDpUWOGUG zf7p1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>CZjI}BisL)< z@Tz`>|BsHx7@m2X9^PB+;c|v+7;a^_ zkKqA^hZr7Z_$x!k1;&S@HvLhGo15R zdVPEhmor?$a4W-o3=c3o#PA5iV+@~Vc#7e344-G%`?OxaJcfM?mor?&@G*v48SZ0v zkl`VQM;RVtc#`2MhG!T)&v1^q@Iv#eJcfM?mor?&@G*v48BQ=f#PBG?V+>C+e2(E6 zhP|KF+c$?{AHxBLs~E0fxRv1u!vhQtGCacYD8pwNo@V$w!#SVR>+54Uz;G4AH4L{h z9AP-Y@DRhJ44-9qlHqd<8+3P8%xYns&v5c?tqLz^;gt*@W4M9gR)!-C_c5Gcc!1$S zhKCp)Wq6F?NrtBwo?-Yr!#U6B`jE$PfZ-~Jk1^cJaDw3hh6foQVt9n%35KT_o@V$w z!`?6G_4P4a&TtjO4Ggz3+{f?`!y^n&FnpHbNrvg0ykw7OSh)9Dy?z$M0fs9Xu3@-= z;RwSCh6foQW_Xn035F*bo@RK4VPjmcZw|v2!vTgX8LnZtf#C?l^zC|Tk6{*0-zuT- zNfv&NVPitC4}H6u;tv}#JOk_*{yM)%8aBjE_?Pp39go=fF?^Kak(DWa7yKMtt>c+O z9a~#;JW!(Jv8_6uEYk>Q>SB}y6;5!8Mo-+eYfh^YGC-dj?Xpf*l5>rUYCw1dUQN= zQpc0MI>6Ao4%pE&z7gc-SBhf-6@;~KdnDaVGsOlIFrKI z2POtm`j7b7OQ~>pG{G3XFBOh5H#WyYeKBKmQygE63ch#}Kh(Y%9-ZIZ4L$_O(0GUN zgB@*+#^z`%aKoEbfG3PmWF~*WUn~{=!#bj~WHFQe7 zO!((enC|zJ@0H1kJn$#Q&r|%U3z#>>r~CipKcx7`Q^^q&&j+D?P<(nmfqZ&C0d*1` aF>*JMsrb|U=d`Tsw5cky!o diff --git a/magicblock-committor-service/src/intent_execution_manager.rs b/magicblock-committor-service/src/intent_execution_manager.rs index 3f0318cb4..6b8ec5d1b 100644 --- a/magicblock-committor-service/src/intent_execution_manager.rs +++ b/magicblock-committor-service/src/intent_execution_manager.rs @@ -17,8 +17,8 @@ use crate::{ intent_execution_engine::{IntentExecutionEngine, ResultSubscriber}, }, intent_executor::{ - commit_id_fetcher::CommitIdTrackerImpl, intent_executor_factory::IntentExecutorFactoryImpl, + task_info_fetcher::CacheTaskInfoFetcher, }, persist::IntentPersister, types::ScheduledBaseIntentWrapper, @@ -42,7 +42,7 @@ impl IntentExecutionManager { let db = Arc::new(db); let commit_id_tracker = - Arc::new(CommitIdTrackerImpl::new(rpc_client.clone())); + Arc::new(CacheTaskInfoFetcher::new(rpc_client.clone())); let executor_factory = IntentExecutorFactoryImpl { rpc_client, table_mania, diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index 6a22c7f26..6076fba02 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -290,10 +290,10 @@ mod tests { intent_scheduler::create_test_intent, }, intent_executor::{ - commit_id_fetcher::{CommitIdFetcher, CommitIdTrackerResult}, error::{ Error as ExecutorError, IntentExecutorResult, InternalError, }, + task_info_fetcher::{TaskInfoFetcher, TaskInfoFetcherResult}, }, persist::IntentPersisterImpl, }; @@ -695,7 +695,7 @@ mod tests { signature: None, }) } else { - Ok(ExecutionOutput { + Ok(ExecutionOutput::TwoStage { commit_signature: Signature::default(), finalize_signature: Signature::default(), }) @@ -708,16 +708,23 @@ mod tests { } #[derive(Clone)] - pub struct MockCommitIdTracker; + pub struct MockInfoFetcher; #[async_trait] - impl CommitIdFetcher for MockCommitIdTracker { + impl TaskInfoFetcher for MockInfoFetcher { async fn fetch_next_commit_ids( &self, pubkeys: &[Pubkey], - ) -> CommitIdTrackerResult> { + ) -> TaskInfoFetcherResult> { Ok(pubkeys.iter().map(|&k| (k, 1)).collect()) } + async fn fetch_rent_reimbursements( + &self, + pubkeys: &[Pubkey], + ) -> TaskInfoFetcherResult> { + Ok(pubkeys.iter().map(|_| Pubkey::new_unique()).collect()) + } + fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option { None } diff --git a/magicblock-committor-service/src/intent_executor/error.rs b/magicblock-committor-service/src/intent_executor/error.rs index bd4b514a1..5985cd1b0 100644 --- a/magicblock-committor-service/src/intent_executor/error.rs +++ b/magicblock-committor-service/src/intent_executor/error.rs @@ -13,6 +13,11 @@ pub enum InternalError { pub enum Error { #[error("EmptyIntentError")] EmptyIntentError, + #[error("Failed to fit in single TX")] + FailedToFitError, + // TODO: remove once proper retries introduced + #[error("TaskBuilderError: {0}")] + TaskBuilderError(#[from] crate::tasks::task_builder::Error), #[error("FailedToCommitError: {err}")] FailedToCommitError { #[source] @@ -23,7 +28,7 @@ pub enum Error { FailedToFinalizeError { #[source] err: InternalError, - commit_signature: Signature, + commit_signature: Option, finalize_signature: Option, }, #[error("FailedCommitPreparationError: {0}")] @@ -36,4 +41,11 @@ pub enum Error { ), } +impl From for Error { + fn from(value: crate::tasks::task_strategist::Error) -> Self { + let crate::tasks::task_strategist::Error::FailedToFitError = value; + Self::FailedToFitError + } +} + pub type IntentExecutorResult = Result; diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index 2cc10a46b..bbe602580 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use async_trait::async_trait; use log::{debug, error, warn}; use magicblock_program::{ @@ -11,38 +13,82 @@ use solana_pubkey::Pubkey; use solana_sdk::{ message::VersionedMessage, signature::{Keypair, Signature}, + signer::Signer, transaction::VersionedTransaction, }; use crate::{ intent_executor::{ error::{Error, IntentExecutorResult, InternalError}, + task_info_fetcher::TaskInfoFetcher, ExecutionOutput, IntentExecutor, }, persist::{CommitStatus, CommitStatusSignatures, IntentPersister}, + tasks::{ + task_builder::{TaskBuilderV1, TasksBuilder}, + task_strategist::{TaskStrategist, TransactionStrategy}, + tasks::BaseTask, + }, transaction_preparator::transaction_preparator::TransactionPreparator, utils::persist_status_update_by_message_set, }; -pub struct IntentExecutorImpl { +pub struct IntentExecutorImpl { authority: Keypair, rpc_client: MagicblockRpcClient, transaction_preparator: T, + task_info_fetcher: Arc, } -impl IntentExecutorImpl +impl IntentExecutorImpl where T: TransactionPreparator, + F: TaskInfoFetcher, { pub fn new( rpc_client: MagicblockRpcClient, transaction_preparator: T, + task_info_fetcher: Arc, ) -> Self { let authority = validator_authority(); Self { authority, rpc_client, transaction_preparator, + task_info_fetcher, + } + } + + /// Checks if it is possible to unite Commit & Finalize stages in 1 transaction + /// Returns corresponding `TransactionStrategy` if possible, otherwise `None` + fn try_unite_tasks( + commit_tasks: &[Box], + finalize_task: &[Box], + authority: &Pubkey, + persister: &Option

, + ) -> Option { + const MAX_UNITED_TASKS_LEN: usize = 22; + + // We can unite in 1 tx a lot of commits + // but then there's a possibility of hitting CPI limit, aka + // MaxInstructionTraceLengthExceeded error. + // So we limit tasks len with 22 total tasks + // In case this fails as well, it will be retried with TwoStage approach + // on retry, once retries are introduced + if commit_tasks.len() + finalize_task.len() > MAX_UNITED_TASKS_LEN { + return None; + } + + // Clone tasks since strategies applied to united case maybe suboptimal for regular one + let mut commit_tasks = commit_tasks.to_owned(); + let finalize_task = finalize_task.to_owned(); + + // Unite tasks to attempt running as single tx + commit_tasks.extend(finalize_task); + match TaskStrategist::build_strategy(commit_tasks, authority, persister) + { + Ok(strategy) => Some(strategy), + Err(crate::tasks::task_strategist::Error::FailedToFitError) => None, } } @@ -66,60 +112,130 @@ where ); } - // Commit stage - let commit_signature = - self.execute_commit_stage(&base_intent, persister).await?; - debug!("Commit stage succeeded: {}", commit_signature); + // Build tasks for Commit & Finalize stages + let commit_tasks = TaskBuilderV1::commit_tasks( + &self.task_info_fetcher, + &base_intent, + persister, + ) + .await?; + let finalize_tasks = TaskBuilderV1::finalize_tasks( + &self.task_info_fetcher, + &base_intent, + ) + .await?; - // Finalize stage - // At the moment validator finalizes right away - // In the future there will be a challenge window - let finalize_signature = self - .execute_finalize_stage(&base_intent, commit_signature, persister) - .await?; - debug!("Finalize stage succeeded: {}", finalize_signature); + // See if we can squeeze them in one tx + if let Some(single_tx_strategy) = Self::try_unite_tasks( + &commit_tasks, + &finalize_tasks, + &self.authority.pubkey(), + persister, + ) { + debug!("Executing intent in single stage"); + self.execute_single_stage(&single_tx_strategy, persister) + .await + } else { + debug!("Executing intent in two stages"); + // Build strategy for Commit stage + let commit_strategy = TaskStrategist::build_strategy( + commit_tasks, + &self.authority.pubkey(), + persister, + )?; - Ok(ExecutionOutput { - commit_signature, - finalize_signature, - }) + // Build strategy for Finalize stage + let finalize_strategy = TaskStrategist::build_strategy( + finalize_tasks, + &self.authority.pubkey(), + persister, + )?; + + self.execute_two_stages( + &commit_strategy, + &finalize_strategy, + persister, + ) + .await + } } - async fn execute_commit_stage( + /// Optimization: executes Intent in single stage + /// where Commit & Finalize are united + // TODO: remove once challenge window introduced + async fn execute_single_stage( &self, - l1_message: &ScheduledBaseIntent, + transaction_strategy: &TransactionStrategy, persister: &Option

, - ) -> IntentExecutorResult { + ) -> IntentExecutorResult { let prepared_message = self .transaction_preparator - .prepare_commit_tx(&self.authority, l1_message, persister) + .prepare_for_strategy( + &self.authority, + transaction_strategy, + persister, + ) .await - .map_err(Error::FailedCommitPreparationError)?; + .map_err(Error::FailedFinalizePreparationError)?; - self.send_prepared_message(prepared_message).await.map_err( - |(err, signature)| Error::FailedToCommitError { err, signature }, - ) + let signature = self + .send_prepared_message(prepared_message) + .await + .map_err(|(err, signature)| Error::FailedToCommitError { + err, + signature, + })?; + + debug!("Single stage intent executed: {}", signature); + Ok(ExecutionOutput::SingleStage(signature)) } - async fn execute_finalize_stage( + /// Executes Intent in 2 stage: Commit & Finalize + async fn execute_two_stages( &self, - l1_message: &ScheduledBaseIntent, - commit_signature: Signature, + commit_strategy: &TransactionStrategy, + finalize_strategy: &TransactionStrategy, persister: &Option

, - ) -> IntentExecutorResult { - let prepared_message = self + ) -> IntentExecutorResult { + // Prepare everything for Commit stage execution + let prepared_commit_message = self .transaction_preparator - .prepare_finalize_tx(&self.authority, l1_message, persister) + .prepare_for_strategy(&self.authority, commit_strategy, persister) .await - .map_err(Error::FailedFinalizePreparationError)?; + .map_err(Error::FailedCommitPreparationError)?; - self.send_prepared_message(prepared_message).await.map_err( - |(err, finalize_signature)| Error::FailedToFinalizeError { + let commit_signature = self + .send_prepared_message(prepared_commit_message) + .await + .map_err(|(err, signature)| Error::FailedToCommitError { err, - commit_signature, - finalize_signature, - }, - ) + signature, + })?; + debug!("Commit stage succeeded: {}", commit_signature); + + // Prepare everything for Finalize stage execution + let prepared_finalize_message = self + .transaction_preparator + .prepare_for_strategy(&self.authority, finalize_strategy, persister) + .await + .map_err(Error::FailedFinalizePreparationError)?; + + let finalize_signature = self + .send_prepared_message(prepared_finalize_message) + .await + .map_err(|(err, finalize_signature)| { + Error::FailedToFinalizeError { + err, + commit_signature: Some(commit_signature), + finalize_signature, + } + })?; + debug!("Finalize stage succeeded: {}", finalize_signature); + + Ok(ExecutionOutput::TwoStage { + commit_signature, + finalize_signature, + }) } /// Shared helper for sending transactions @@ -169,9 +285,17 @@ where ) { match result { Ok(value) => { - let signatures = CommitStatusSignatures { - commit_stage_signature: value.commit_signature, - finalize_stage_signature: Some(value.commit_signature) + let signatures = match *value { + ExecutionOutput::SingleStage(signature) => CommitStatusSignatures { + commit_stage_signature: signature, + finalize_stage_signature: Some(signature) + }, + ExecutionOutput::TwoStage { + commit_signature, finalize_signature + } => CommitStatusSignatures { + commit_stage_signature: commit_signature, + finalize_stage_signature: Some(finalize_signature) + } }; let update_status = CommitStatus::Succeeded(signatures); persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); @@ -179,8 +303,12 @@ where if let Err(err) = persistor.finalize_base_intent(message_id, *value) { error!("Failed to persist ExecutionOutput: {}", err); } + }, + Err(Error::EmptyIntentError) | Err(Error::FailedToFitError) => { + let update_status = CommitStatus::Failed; + persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } - Err(Error::EmptyIntentError) => { + Err(Error::TaskBuilderError(_)) => { let update_status = CommitStatus::Failed; persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } @@ -188,18 +316,6 @@ where let update_status = CommitStatus::PartOfTooLargeBundleToProcess; persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } - Err(Error::FailedCommitPreparationError(crate::transaction_preparator::error::Error::TaskBuilderError(err))) => { - match err { - crate::tasks::task_builder::Error::CommitTasksBuildError(_) => { - let update_status = CommitStatus::Failed; - persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); - } - crate::tasks::task_builder::Error::FinalizedTasksBuildError(_) => { - // During commit preparation we don't encounter following error - // so no need to persist it - } - } - }, Err(Error::FailedCommitPreparationError(crate::transaction_preparator::error::Error::DeliveryPreparationError(_))) => { // Intermediate commit preparation progress recorded by DeliveryPreparator }, @@ -217,11 +333,15 @@ where }, Err(Error::FailedToFinalizeError {err: _, commit_signature, finalize_signature}) => { // Finalize is a single TX, so if it fails, all of commited accounts marked FailedFinalize - let status_signature = CommitStatusSignatures { - commit_stage_signature: *commit_signature, - finalize_stage_signature: *finalize_signature + let update_status = if let Some(commit_signature) = commit_signature { + let signatures = CommitStatusSignatures { + commit_stage_signature: *commit_signature, + finalize_stage_signature: *finalize_signature + }; + CommitStatus::FailedFinalize(signatures) + } else { + CommitStatus::FailedProcess(None) }; - let update_status = CommitStatus::FailedFinalize( status_signature); persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); } } @@ -229,9 +349,10 @@ where } #[async_trait] -impl IntentExecutor for IntentExecutorImpl +impl IntentExecutor for IntentExecutorImpl where T: TransactionPreparator, + C: TaskInfoFetcher, { /// Executes Message on Base layer /// Returns `ExecutionOutput` or an `Error` @@ -251,3 +372,76 @@ where result } } + +#[cfg(test)] +mod tests { + use std::{collections::HashMap, sync::Arc}; + + use solana_pubkey::Pubkey; + + use crate::{ + intent_execution_manager::intent_scheduler::create_test_intent, + intent_executor::{ + task_info_fetcher::{TaskInfoFetcher, TaskInfoFetcherResult}, + IntentExecutorImpl, + }, + persist::IntentPersisterImpl, + tasks::task_builder::{TaskBuilderV1, TasksBuilder}, + transaction_preparator::transaction_preparator::TransactionPreparatorV1, + }; + + struct MockInfoFetcher; + #[async_trait::async_trait] + impl TaskInfoFetcher for MockInfoFetcher { + fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option { + Some(0) + } + + async fn fetch_next_commit_ids( + &self, + pubkeys: &[Pubkey], + ) -> TaskInfoFetcherResult> { + Ok(pubkeys.iter().map(|pubkey| (*pubkey, 0)).collect()) + } + + async fn fetch_rent_reimbursements( + &self, + pubkeys: &[Pubkey], + ) -> TaskInfoFetcherResult> { + Ok(pubkeys.iter().map(|_| Pubkey::new_unique()).collect()) + } + } + + #[tokio::test] + async fn test_try_unite() { + let pubkey = [Pubkey::new_unique()]; + let intent = create_test_intent(0, &pubkey); + + let info_fetcher = Arc::new(MockInfoFetcher); + let commit_task = TaskBuilderV1::commit_tasks( + &info_fetcher, + &intent, + &None::, + ) + .await + .unwrap(); + let finalize_task = + TaskBuilderV1::finalize_tasks(&info_fetcher, &intent) + .await + .unwrap(); + + let result = IntentExecutorImpl::< + TransactionPreparatorV1, + MockInfoFetcher, + >::try_unite_tasks( + &commit_task, + &finalize_task, + &Pubkey::new_unique(), + &None::, + ); + assert!(result.is_some()); + + let strategy = result.unwrap(); + assert!(strategy.lookup_tables_keys.is_empty()); + } +} diff --git a/magicblock-committor-service/src/intent_executor/intent_executor_factory.rs b/magicblock-committor-service/src/intent_executor/intent_executor_factory.rs index e07163e39..565e8722e 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor_factory.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor_factory.rs @@ -5,7 +5,7 @@ use magicblock_table_mania::TableMania; use crate::{ intent_executor::{ - commit_id_fetcher::CommitIdTrackerImpl, IntentExecutor, + task_info_fetcher::CacheTaskInfoFetcher, IntentExecutor, IntentExecutorImpl, }, transaction_preparator::transaction_preparator::TransactionPreparatorV1, @@ -23,24 +23,23 @@ pub struct IntentExecutorFactoryImpl { pub rpc_client: MagicblockRpcClient, pub table_mania: TableMania, pub compute_budget_config: ComputeBudgetConfig, - pub commit_id_tracker: Arc, + pub commit_id_tracker: Arc, } impl IntentExecutorFactory for IntentExecutorFactoryImpl { type Executor = - IntentExecutorImpl>; + IntentExecutorImpl; fn create_instance(&self) -> Self::Executor { - let transaction_preaparator = - TransactionPreparatorV1::::new( - self.rpc_client.clone(), - self.table_mania.clone(), - self.compute_budget_config.clone(), - self.commit_id_tracker.clone(), - ); - IntentExecutorImpl::>::new( + let transaction_preparator = TransactionPreparatorV1::new( self.rpc_client.clone(), - transaction_preaparator, + self.table_mania.clone(), + self.compute_budget_config.clone(), + ); + IntentExecutorImpl::::new( + self.rpc_client.clone(), + transaction_preparator, + self.commit_id_tracker.clone(), ) } } diff --git a/magicblock-committor-service/src/intent_executor/mod.rs b/magicblock-committor-service/src/intent_executor/mod.rs index 068aa8341..673287805 100644 --- a/magicblock-committor-service/src/intent_executor/mod.rs +++ b/magicblock-committor-service/src/intent_executor/mod.rs @@ -1,8 +1,8 @@ -pub mod commit_id_fetcher; pub mod error; #[allow(clippy::module_inception)] pub mod intent_executor; pub(crate) mod intent_executor_factory; +pub mod task_info_fetcher; use async_trait::async_trait; pub use intent_executor::IntentExecutorImpl; @@ -14,11 +14,17 @@ use crate::{ }; #[derive(Clone, Copy, Debug)] -pub struct ExecutionOutput { - /// Commit stage signature - pub commit_signature: Signature, - /// Finalize stage signature - pub finalize_signature: Signature, +pub enum ExecutionOutput { + // TODO: with arrival of challenge window remove SingleStage + // Protocol requires 2 stage: Commit, Finalize + // SingleStage - optimization for timebeing + SingleStage(Signature), + TwoStage { + /// Commit stage signature + commit_signature: Signature, + /// Finalize stage signature + finalize_signature: Signature, + }, } #[async_trait] diff --git a/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs b/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs similarity index 72% rename from magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs rename to magicblock-committor-service/src/intent_executor/task_info_fetcher.rs index 6ab6af045..0bf6117fe 100644 --- a/magicblock-committor-service/src/intent_executor/commit_id_fetcher.rs +++ b/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs @@ -12,25 +12,34 @@ use magicblock_rpc_client::{MagicBlockRpcClientError, MagicblockRpcClient}; use solana_pubkey::Pubkey; #[async_trait] -pub trait CommitIdFetcher: Send + Sync + 'static { +pub trait TaskInfoFetcher: Send + Sync + 'static { // Fetches correct next ids for pubkeys // Those ids can be used as correct commit_id during Commit async fn fetch_next_commit_ids( &self, pubkeys: &[Pubkey], - ) -> CommitIdTrackerResult>; + ) -> TaskInfoFetcherResult>; + // Fetches rent reimbursement address for pubkeys + async fn fetch_rent_reimbursements( + &self, + pubkeys: &[Pubkey], + ) -> TaskInfoFetcherResult>; + + // Peeks current commit ids for pubkeys fn peek_commit_id(&self, pubkey: &Pubkey) -> Option; } -const MUTEX_POISONED_MSG: &str = "CommitIdTrackerImpl mutex poisoned!"; +const NUM_FETCH_RETRIES: NonZeroUsize = + unsafe { NonZeroUsize::new_unchecked(5) }; +const MUTEX_POISONED_MSG: &str = "CacheTaskInfoFetcher mutex poisoned!"; -pub struct CommitIdTrackerImpl { +pub struct CacheTaskInfoFetcher { rpc_client: MagicblockRpcClient, cache: Mutex>, } -impl CommitIdTrackerImpl { +impl CacheTaskInfoFetcher { pub fn new(rpc_client: MagicblockRpcClient) -> Self { const CACHE_SIZE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(1000) }; @@ -41,19 +50,19 @@ impl CommitIdTrackerImpl { } } - /// Fetches commit_ids with some num of retries - pub async fn rpc_fetch_commit_ids_with_retries( + /// Fetches [`DelegationMetadata`]s with some num of retries + pub async fn fetch_metadata_with_retries( rpc_client: &MagicblockRpcClient, pubkeys: &[Pubkey], num_retries: NonZeroUsize, - ) -> CommitIdTrackerResult> { + ) -> TaskInfoFetcherResult> { if pubkeys.is_empty() { return Ok(Vec::new()); } let mut last_err = Error::MetadataNotFoundError(pubkeys[0]); for i in 0..num_retries.get() { - match Self::rpc_fetch_commit_ids(rpc_client, pubkeys).await { + match Self::fetch_metadata(rpc_client, pubkeys).await { Ok(value) => return Ok(value), err @ Err(Error::InvalidAccountDataError(_)) => return err, err @ Err(Error::MetadataNotFoundError(_)) => return err, @@ -72,16 +81,15 @@ impl CommitIdTrackerImpl { /// Fetches commit_ids using RPC /// Note: remove duplicates prior to calling - pub async fn rpc_fetch_commit_ids( + pub async fn fetch_metadata( rpc_client: &MagicblockRpcClient, pubkeys: &[Pubkey], - ) -> CommitIdTrackerResult> { + ) -> TaskInfoFetcherResult> { // Early return if no pubkeys to process if pubkeys.is_empty() { return Ok(Vec::new()); } - // Find PDA accounts for each pubkey let pda_accounts = pubkeys .iter() .map(|delegated_account| { @@ -95,50 +103,46 @@ impl CommitIdTrackerImpl { }) .collect::>(); - // Fetch account data for all PDAs let accounts_data = rpc_client .get_multiple_accounts(&pda_accounts, None) .await?; - // Process each account data to extract last_update_external_slot - let commit_ids = accounts_data + let metadatas = pda_accounts .into_iter() .enumerate() - .map(|(i, account)| { - let pubkey = if let Some(pubkey) = pda_accounts.get(i) { - *pubkey + .map(|(i, pda)| { + let account = if let Some(account) = accounts_data.get(i) { + account } else { - error!("invalid pubkey index in pda_accounts: {i}"); - Pubkey::new_unique() + return Err(Error::MetadataNotFoundError(pda)); }; - let account = - account.ok_or(Error::MetadataNotFoundError(pubkey))?; + + let account = account + .as_ref() + .ok_or(Error::MetadataNotFoundError(pda))?; let metadata = DelegationMetadata::try_from_bytes_with_discriminator( &account.data, ) - .map_err(|_| Error::InvalidAccountDataError(pubkey))?; + .map_err(|_| Error::InvalidAccountDataError(pda))?; - Ok::<_, Error>(metadata.last_update_external_slot) + Ok(metadata) }) .collect::, _>>()?; - Ok(commit_ids) + Ok(metadatas) } } -/// CommitFetcher implementation that also caches most used 1000 keys +/// TaskInfoFetcher implementation that also caches most used 1000 keys #[async_trait] -impl CommitIdFetcher for CommitIdTrackerImpl { +impl TaskInfoFetcher for CacheTaskInfoFetcher { /// Returns next ids for requested pubkeys /// If key isn't in cache, it will be requested async fn fetch_next_commit_ids( &self, pubkeys: &[Pubkey], - ) -> CommitIdTrackerResult> { - const NUM_FETCH_RETRIES: NonZeroUsize = - unsafe { NonZeroUsize::new_unchecked(5) }; - + ) -> TaskInfoFetcherResult> { if pubkeys.is_empty() { return Ok(HashMap::new()); } @@ -176,12 +180,14 @@ impl CommitIdFetcher for CommitIdTrackerImpl { to_request.sort(); to_request.dedup(); - let remaining_ids = Self::rpc_fetch_commit_ids_with_retries( + let remaining_ids = Self::fetch_metadata_with_retries( &self.rpc_client, &to_request, NUM_FETCH_RETRIES, ) - .await?; + .await? + .into_iter() + .map(|metadata| metadata.last_update_external_slot); // We don't care if anything changed in between with cache - just update and return our ids. { @@ -202,6 +208,23 @@ impl CommitIdFetcher for CommitIdTrackerImpl { Ok(result) } + async fn fetch_rent_reimbursements( + &self, + pubkeys: &[Pubkey], + ) -> TaskInfoFetcherResult> { + let rent_reimbursements = Self::fetch_metadata_with_retries( + &self.rpc_client, + pubkeys, + NUM_FETCH_RETRIES, + ) + .await? + .into_iter() + .map(|metadata| metadata.rent_payer) + .collect(); + + Ok(rent_reimbursements) + } + /// Returns current commit id without raising priority fn peek_commit_id(&self, pubkey: &Pubkey) -> Option { let cache = self.cache.lock().expect(MUTEX_POISONED_MSG); @@ -219,4 +242,4 @@ pub enum Error { MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), } -pub type CommitIdTrackerResult = Result; +pub type TaskInfoFetcherResult = Result; diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 0ef9a730e..e60710c42 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -274,12 +274,19 @@ impl IntentPersister for IntentPersisterImpl { message_id: u64, execution_output: ExecutionOutput, ) -> CommitPersistResult<()> { + let (commit_signature, finalize_signature) = match execution_output { + ExecutionOutput::SingleStage(signature) => (signature, signature), + ExecutionOutput::TwoStage { + commit_signature, + finalize_signature, + } => (commit_signature, finalize_signature), + }; + let bundle_signature_row = BundleSignatureRow::new( message_id, - execution_output.commit_signature, - execution_output.finalize_signature, + commit_signature, + finalize_signature, ); - let commits_db = self.commits_db.lock().expect(POISONED_MUTEX_MSG); commits_db.insert_bundle_signature_row(&bundle_signature_row)?; Ok(()) @@ -623,7 +630,7 @@ mod tests { let commit_sig = Signature::new_unique(); let finalize_sig = Signature::new_unique(); - let execution_output = ExecutionOutput { + let execution_output = ExecutionOutput::TwoStage { commit_signature: commit_sig, finalize_signature: finalize_sig, }; diff --git a/magicblock-committor-service/src/persist/db.rs b/magicblock-committor-service/src/persist/db.rs index c65df44cb..d690643c6 100644 --- a/magicblock-committor-service/src/persist/db.rs +++ b/magicblock-committor-service/src/persist/db.rs @@ -238,20 +238,21 @@ impl CommittsDb { WHERE pubkey = ?4 AND message_id = ?5"; - let tx = self.conn.transaction()?; - tx.prepare(query)?.execute(params![ - status.as_str(), - status - .signatures() - .map(|s| s.commit_stage_signature.to_string()), - status - .signatures() - .and_then(|s| s.finalize_stage_signature) - .map(|s| s.to_string()), - pubkey.to_string(), - message_id - ])?; - tx.commit()?; + self.conn.execute( + query, + params![ + status.as_str(), + status + .signatures() + .map(|s| s.commit_stage_signature.to_string()), + status + .signatures() + .and_then(|s| s.finalize_stage_signature) + .map(|s| s.to_string()), + pubkey.to_string(), + message_id + ], + )?; Ok(()) } @@ -270,20 +271,21 @@ impl CommittsDb { WHERE pubkey = ?4 AND commit_id = ?5"; - let tx = self.conn.transaction()?; - tx.prepare(query)?.execute(params![ - status.as_str(), - status - .signatures() - .map(|s| s.commit_stage_signature.to_string()), - status - .signatures() - .and_then(|s| s.finalize_stage_signature) - .map(|s| s.to_string()), - pubkey.to_string(), - commit_id - ])?; - tx.commit()?; + self.conn.execute( + query, + params![ + status.as_str(), + status + .signatures() + .map(|s| s.commit_stage_signature.to_string()), + status + .signatures() + .and_then(|s| s.finalize_stage_signature) + .map(|s| s.to_string()), + pubkey.to_string(), + commit_id + ], + )?; Ok(()) } @@ -300,13 +302,10 @@ impl CommittsDb { WHERE pubkey = ?2 AND commit_id = ?3"; - let tx = self.conn.transaction()?; - tx.prepare(query)?.execute(params![ - value.as_str(), - pubkey.to_string(), - commit_id - ])?; - tx.commit()?; + self.conn.execute( + query, + params![value.as_str(), pubkey.to_string(), commit_id], + )?; Ok(()) } @@ -323,14 +322,11 @@ impl CommittsDb { WHERE pubkey = ?2 AND message_id = ?3"; - let tx = self.conn.transaction()?; - tx.prepare(query)?.execute(params![ - commit_id, - pubkey.to_string(), - message_id - ])?; + self.conn.execute( + query, + params![commit_id, pubkey.to_string(), message_id], + )?; - tx.commit()?; Ok(()) } diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index db90ec119..dd726488f 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -174,7 +174,7 @@ impl BaseIntentCommittorExt for ChangesetCommittorStub { .map(|message| { Ok(ExecutionOutputWrapper { id: message.inner.id, - output: ExecutionOutput { + output: ExecutionOutput::TwoStage { commit_signature: Signature::new_unique(), finalize_signature: Signature::new_unique(), }, diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index fccd03911..9772c7e57 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -1,17 +1,16 @@ use std::sync::Arc; use async_trait::async_trait; -use dlp::{args::Context, state::DelegationMetadata}; +use dlp::args::Context; use log::error; use magicblock_program::magic_scheduled_base_intent::{ CommitType, CommittedAccountV2, MagicBaseIntent, ScheduledBaseIntent, UndelegateType, }; -use magicblock_rpc_client::{MagicBlockRpcClientError, MagicblockRpcClient}; use solana_pubkey::Pubkey; use crate::{ - intent_executor::commit_id_fetcher::CommitIdFetcher, + intent_executor::task_info_fetcher::TaskInfoFetcher, persist::IntentPersister, tasks::tasks::{ ArgsTask, BaseTask, CommitTask, FinalizeTask, L1ActionTask, @@ -22,16 +21,16 @@ use crate::{ #[async_trait] pub trait TasksBuilder { // Creates tasks for commit stage - async fn commit_tasks( + async fn commit_tasks( commit_id_fetcher: &Arc, - l1_message: &ScheduledBaseIntent, + base_intent: &ScheduledBaseIntent, persister: &Option

, ) -> TaskBuilderResult>>; // Create tasks for finalize stage - async fn finalize_tasks( - rpc_client: &MagicblockRpcClient, - l1_message: &ScheduledBaseIntent, + async fn finalize_tasks( + info_fetcher: &Arc, + base_intent: &ScheduledBaseIntent, ) -> TaskBuilderResult>>; } @@ -39,60 +38,15 @@ pub trait TasksBuilder { /// V1: Actions are part of finalize tx pub struct TaskBuilderV1; -impl TaskBuilderV1 { - async fn fetch_rent_reimbursements( - rpc_client: &MagicblockRpcClient, - pubkeys: &[Pubkey], - ) -> Result, FinalizedTasksBuildError> { - let pdas = pubkeys - .iter() - .map(|pubkey| { - dlp::pda::delegation_metadata_pda_from_delegated_account(pubkey) - }) - .collect::>(); - - let metadatas = rpc_client.get_multiple_accounts(&pdas, None).await?; - - let rent_reimbursments = pdas - .into_iter() - .enumerate() - .map(|(i, pda)| { - let account = if let Some(account) = metadatas.get(i) { - account - } else { - return Err( - FinalizedTasksBuildError::MetadataNotFoundError(pda), - ); - }; - - let account = account.as_ref().ok_or( - FinalizedTasksBuildError::MetadataNotFoundError(pda), - )?; - let metadata = - DelegationMetadata::try_from_bytes_with_discriminator( - &account.data, - ) - .map_err(|_| { - FinalizedTasksBuildError::InvalidAccountDataError(pda) - })?; - - Ok::<_, FinalizedTasksBuildError>(metadata.rent_payer) - }) - .collect::, _>>()?; - - Ok(rent_reimbursments) - } -} - #[async_trait] impl TasksBuilder for TaskBuilderV1 { /// Returns [`Task`]s for Commit stage - async fn commit_tasks( + async fn commit_tasks( commit_id_fetcher: &Arc, - l1_message: &ScheduledBaseIntent, + base_intent: &ScheduledBaseIntent, persister: &Option

, ) -> TaskBuilderResult>> { - let (accounts, allow_undelegation) = match &l1_message.base_intent { + let (accounts, allow_undelegation) = match &base_intent.base_intent { MagicBaseIntent::BaseActions(actions) => { let tasks = actions .iter() @@ -119,14 +73,15 @@ impl TasksBuilder for TaskBuilderV1 { .collect::>(); let commit_ids = commit_id_fetcher .fetch_next_commit_ids(&committed_pubkeys) - .await?; + .await + .map_err(Error::CommitTasksBuildError)?; // Persist commit ids for commitees commit_ids .iter() .for_each(|(pubkey, commit_id) | { - if let Err(err) = persister.set_commit_id(l1_message.id, pubkey, *commit_id) { - error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, l1_message.id, pubkey, err); + if let Err(err) = persister.set_commit_id(base_intent.id, pubkey, *commit_id) { + error!("Failed to persist commit id: {}, for message id: {} with pubkey {}: {}", commit_id, base_intent.id, pubkey, err); } }); @@ -148,9 +103,9 @@ impl TasksBuilder for TaskBuilderV1 { } /// Returns [`Task`]s for Finalize stage - async fn finalize_tasks( - rpc_client: &MagicblockRpcClient, - l1_message: &ScheduledBaseIntent, + async fn finalize_tasks( + info_fetcher: &Arc, + base_intent: &ScheduledBaseIntent, ) -> TaskBuilderResult>> { // Helper to create a finalize task fn finalize_task(account: &CommittedAccountV2) -> Box { @@ -197,7 +152,7 @@ impl TasksBuilder for TaskBuilderV1 { } } - match &l1_message.base_intent { + match &base_intent.base_intent { MagicBaseIntent::BaseActions(_) => Ok(vec![]), MagicBaseIntent::Commit(commit) => Ok(process_commit(commit)), MagicBaseIntent::CommitAndUndelegate(t) => { @@ -209,10 +164,12 @@ impl TasksBuilder for TaskBuilderV1 { .iter() .map(|account| account.pubkey) .collect::>(); - let rent_reimbursments = - Self::fetch_rent_reimbursements(rpc_client, &pubkeys) - .await?; - tasks.extend(accounts.iter().zip(rent_reimbursments).map( + let rent_reimbursements = info_fetcher + .fetch_rent_reimbursements(&pubkeys) + .await + .map_err(Error::FinalizedTasksBuildError)?; + + tasks.extend(accounts.iter().zip(rent_reimbursements).map( |(account, rent_reimbursement)| { undelegate_task(account, &rent_reimbursement) }, @@ -238,24 +195,16 @@ impl TasksBuilder for TaskBuilderV1 { } } -#[derive(thiserror::Error, Debug)] -pub enum FinalizedTasksBuildError { - #[error("Metadata not found for: {0}")] - MetadataNotFoundError(Pubkey), - #[error("InvalidAccountDataError for: {0}")] - InvalidAccountDataError(Pubkey), - #[error("MagicBlockRpcClientError: {0}")] - MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), -} - #[derive(thiserror::Error, Debug)] pub enum Error { #[error("CommitIdFetchError: {0}")] CommitTasksBuildError( - #[from] crate::intent_executor::commit_id_fetcher::Error, + #[source] crate::intent_executor::task_info_fetcher::Error, ), #[error("FinalizedTasksBuildError: {0}")] - FinalizedTasksBuildError(#[from] FinalizedTasksBuildError), + FinalizedTasksBuildError( + #[source] crate::intent_executor::task_info_fetcher::Error, + ), } pub type TaskBuilderResult = Result; diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index 587f354b2..ec3960755 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -1,6 +1,7 @@ use dlp::args::{ CallHandlerArgs, CommitStateArgs, CommitStateFromBufferArgs, Context, }; +use dyn_clone::DynClone; use magicblock_committor_program::{ instruction_builder::{ init_buffer::{create_init_ix, CreateInitIxArgs}, @@ -37,7 +38,7 @@ pub struct TaskPreparationInfo { } /// A trait representing a task that can be executed on Base layer -pub trait BaseTask: Send + Sync { +pub trait BaseTask: Send + Sync + DynClone { /// Gets all pubkeys that involved in Task's instruction fn involved_accounts(&self, validator: &Pubkey) -> Vec { self.instruction(validator) @@ -72,6 +73,8 @@ pub trait BaseTask: Send + Sync { fn visit(&self, visitor: &mut dyn Visitor); } +dyn_clone::clone_trait_object!(BaseTask); + #[derive(Clone)] pub struct CommitTask { pub commit_id: u64, diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index bdbe3a466..649d29a0b 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -120,6 +120,10 @@ impl TransactionUtils { Err(crate::tasks::task_strategist::Error::FailedToFitError) } Err(CompileError::UnknownInstructionKey(pubkey)) => { + // SAFETY: this may occur in utility AccountKeys::try_compile_instructions + // when User's pubkeys in Instruction doesn't exist in AccountKeys. + // This is impossible in our case since AccountKeys created on keys of our Ixs + // that means that all keys from out ixs exist in AccountKeys panic!( "Supplied instruction has to be valid: {}", CompileError::UnknownInstructionKey(pubkey) diff --git a/magicblock-committor-service/src/transaction_preparator/error.rs b/magicblock-committor-service/src/transaction_preparator/error.rs index 0d50e2a51..6ff3e2f7b 100644 --- a/magicblock-committor-service/src/transaction_preparator/error.rs +++ b/magicblock-committor-service/src/transaction_preparator/error.rs @@ -2,12 +2,8 @@ use thiserror::Error; #[derive(Error, Debug)] pub enum Error { - // #[error("Invalid action for TransactionPreparator version: {0}")] - // VersionError(PreparatorVersion), #[error("Failed to fit in single TX")] FailedToFitError, - #[error("TaskBuilderError: {0}")] - TaskBuilderError(#[from] crate::tasks::task_builder::Error), #[error("DeliveryPreparationError: {0}")] DeliveryPreparationError( #[from] crate::transaction_preparator::delivery_preparator::Error, diff --git a/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs index 4994cbaa1..8e026b1d0 100644 --- a/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs @@ -1,21 +1,13 @@ -use std::{fmt::Formatter, sync::Arc}; +use std::fmt::Formatter; use async_trait::async_trait; -use magicblock_program::magic_scheduled_base_intent::ScheduledBaseIntent; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; -use solana_sdk::{ - message::VersionedMessage, signature::Keypair, signer::Signer, -}; +use solana_sdk::{message::VersionedMessage, signature::Keypair}; use crate::{ - intent_executor::commit_id_fetcher::CommitIdFetcher, persist::IntentPersister, - tasks::{ - task_builder::{TaskBuilderV1, TasksBuilder}, - task_strategist::TaskStrategist, - utils::TransactionUtils, - }, + tasks::{task_strategist::TransactionStrategy, utils::TransactionUtils}, transaction_preparator::{ delivery_preparator::DeliveryPreparator, error::PreparatorResult, }, @@ -41,23 +33,12 @@ impl std::fmt::Display for PreparatorVersion { pub trait TransactionPreparator: Send + Sync + 'static { fn version(&self) -> PreparatorVersion; - /// Returns [`VersionedMessage`] corresponding to [`ScheduledBaseIntent`] tasks - /// Handles all necessary preparations for Message to be valid - /// NOTE: [`VersionedMessage`] contains dummy recent_block_hash that should be replaced - async fn prepare_commit_tx( - &self, - authority: &Keypair, - base_intent: &ScheduledBaseIntent, - intent_persister: &Option

, - ) -> PreparatorResult; - - /// Returns [`VersionedMessage`] corresponding to [`ScheduledBaseIntent`] tasks - /// Handles all necessary preparations for Message to be valid - // NOTE: [`VersionedMessage`] contains dummy recent_block_hash that should be replaced - async fn prepare_finalize_tx( + /// Return [`VersionedMessage`] corresponding to [`TransactionStrategy`] + /// Handles all necessary preparation needed for successful [`BaseTask`] execution + async fn prepare_for_strategy( &self, authority: &Keypair, - base_intent: &ScheduledBaseIntent, + transaction_strategy: &TransactionStrategy, intent_persister: &Option

, ) -> PreparatorResult; } @@ -65,22 +46,16 @@ pub trait TransactionPreparator: Send + Sync + 'static { /// [`TransactionPreparatorV1`] first version of preparator /// It omits future commit_bundle/finalize_bundle logic /// It creates TXs using current per account commit/finalize -pub struct TransactionPreparatorV1 { - rpc_client: MagicblockRpcClient, - commit_id_fetcher: Arc, +pub struct TransactionPreparatorV1 { delivery_preparator: DeliveryPreparator, compute_budget_config: ComputeBudgetConfig, } -impl TransactionPreparatorV1 -where - C: CommitIdFetcher, -{ +impl TransactionPreparatorV1 { pub fn new( rpc_client: MagicblockRpcClient, table_mania: TableMania, compute_budget_config: ComputeBudgetConfig, - commit_id_fetcher: Arc, ) -> Self { let delivery_preparator = DeliveryPreparator::new( rpc_client.clone(), @@ -89,8 +64,6 @@ where ); Self { - rpc_client, - commit_id_fetcher, delivery_preparator, compute_budget_config, } @@ -98,75 +71,36 @@ where } #[async_trait] -impl TransactionPreparator for TransactionPreparatorV1 -where - C: CommitIdFetcher, -{ +impl TransactionPreparator for TransactionPreparatorV1 { fn version(&self) -> PreparatorVersion { PreparatorVersion::V1 } - /// In V1: prepares TX with commits for every account in message - /// For pure actions message - outputs Tx that runs actions - async fn prepare_commit_tx( + async fn prepare_for_strategy( &self, authority: &Keypair, - base_intent: &ScheduledBaseIntent, + tx_strategy: &TransactionStrategy, intent_persister: &Option

, ) -> PreparatorResult { - // create tasks - let tasks = TaskBuilderV1::commit_tasks( - &self.commit_id_fetcher, - base_intent, - intent_persister, - ) - .await?; - // optimize to fit tx size. aka Delivery Strategy - let tx_strategy = TaskStrategist::build_strategy( - tasks, - &authority.pubkey(), - intent_persister, - )?; - // Pre tx preparations. Create buffer accs + lookup tables - let lookup_tables = self - .delivery_preparator - .prepare_for_delivery(authority, &tx_strategy, intent_persister) - .await?; - - // Build resulting TX to be executed - let message = TransactionUtils::assemble_tasks_tx( - authority, - &tx_strategy.optimized_tasks, - self.compute_budget_config.compute_unit_price, - &lookup_tables, - ) - .expect("TaskStrategist had to fail prior. This shouldn't be reachable") - .message; - - Ok(message) - } + // If message won't fit, there's no reason to prepare anything + // Fail early + { + let dummy_lookup_tables = TransactionUtils::dummy_lookup_table( + &tx_strategy.lookup_tables_keys, + ); + let _ = TransactionUtils::assemble_tasks_tx( + authority, + &tx_strategy.optimized_tasks, + self.compute_budget_config.compute_unit_price, + &dummy_lookup_tables, + )? + .message; + } - /// In V1: prepares single TX with finalize, undelegation + actions - async fn prepare_finalize_tx( - &self, - authority: &Keypair, - base_intent: &ScheduledBaseIntent, - intent_presister: &Option

, - ) -> PreparatorResult { - // create tasks - let tasks = - TaskBuilderV1::finalize_tasks(&self.rpc_client, base_intent) - .await?; - // optimize to fit tx size. aka Delivery Strategy - let tx_strategy = TaskStrategist::build_strategy( - tasks, - &authority.pubkey(), - intent_presister, - )?; // Pre tx preparations. Create buffer accs + lookup tables let lookup_tables = self .delivery_preparator - .prepare_for_delivery(authority, &tx_strategy, intent_presister) + .prepare_for_delivery(authority, tx_strategy, intent_persister) .await?; let message = TransactionUtils::assemble_tasks_tx( @@ -175,7 +109,7 @@ where self.compute_budget_config.compute_unit_price, &lookup_tables, ) - .expect("TaskStrategist had to fail prior. This shouldn't be reachable") + .expect("Possibility to assemble checked above") .message; Ok(message) diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 097f0a2a6..8995fab67 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -1719,6 +1719,12 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + [[package]] name = "eager" version = "0.1.0" @@ -3835,6 +3841,7 @@ dependencies = [ "base64 0.21.7", "bincode", "borsh 1.5.7", + "dyn-clone", "futures-util", "log", "lru 0.16.0", diff --git a/test-integration/configs/run-test-validator.sh b/test-integration/configs/run-test-validator.sh index 23d3be225..b99d53913 100755 --- a/test-integration/configs/run-test-validator.sh +++ b/test-integration/configs/run-test-validator.sh @@ -16,7 +16,10 @@ solana-test-validator \ 1000000 \ --bpf-program \ CoMtrr6j336NSB5PAoAWpLe5hPgkcShWKbPgHhZxaxh \ - $DIR/../../target/deploy/magicblock_committor_program.so \ \ + $DIR/../../target/deploy/magicblock_committor_program.so \ + --bpf-program \ + f1exzKGtdeVX3d6UXZ89cY7twiNJe9S5uq84RTA4Rq4 \ + $DIR/../target/deploy/program_flexi_counter.so \ --bpf-program \ DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh \ $DIR/../schedulecommit/elfs/dlp.so \ diff --git a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs index 81f61477a..6f691562c 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs @@ -52,7 +52,7 @@ fn get_context_with_delegated_committees_impl( pub fn assert_one_committee_was_committed( ctx: &ScheduleCommitTestContext, res: &ScheduledCommitResult, - finalize: bool, + is_single_stage: bool, ) { let pda = ctx.committees[0].1; @@ -62,7 +62,9 @@ pub fn assert_one_committee_was_committed( let commit = res.included.get(&pda); assert!(commit.is_some(), "should have committed pda"); - let sig_len = if finalize { 2 } else { 1 }; + // SingleStage Commit & Finalize result in 1 tx + // TwoStage results in 2 signatures on base layer + let sig_len = if !is_single_stage { 2 } else { 1 }; assert_eq!( res.sigs.len(), sig_len, @@ -75,7 +77,7 @@ pub fn assert_one_committee_was_committed( pub fn assert_two_committees_were_committed( ctx: &ScheduleCommitTestContext, res: &ScheduledCommitResult, - finalize: bool, + is_single_stage: bool, ) { let pda1 = ctx.committees[0].1; let pda2 = ctx.committees[1].1; @@ -88,7 +90,7 @@ pub fn assert_two_committees_were_committed( assert!(commit1.is_some(), "should have committed pda1"); assert!(commit2.is_some(), "should have committed pda2"); - let sig_len = if finalize { 2 } else { 1 }; + let sig_len = if !is_single_stage { 2 } else { 1 }; assert_eq!( res.sigs.len(), sig_len, @@ -101,7 +103,7 @@ pub fn assert_two_committees_were_committed( pub fn assert_feepayer_was_committed( ctx: &ScheduleCommitTestContext, res: &ScheduledCommitResult, - finalize: bool, + is_single_stage: bool, ) { let payer = ctx.payer.pubkey(); @@ -110,7 +112,7 @@ pub fn assert_feepayer_was_committed( let commit_payer = res.feepayers.iter().find(|(p, _)| p == &payer); assert!(commit_payer.is_some(), "should have committed payer"); - let sig_len = if finalize { 2 } else { 1 }; + let sig_len = if !is_single_stage { 2 } else { 1 }; assert_eq!( res.sigs.len(), sig_len, diff --git a/test-integration/test-committor-service/tests/common.rs b/test-integration/test-committor-service/tests/common.rs index 336a7c925..5ca9a93f5 100644 --- a/test-integration/test-committor-service/tests/common.rs +++ b/test-integration/test-committor-service/tests/common.rs @@ -6,9 +6,10 @@ use std::{ }, }; use async_trait::async_trait; +use magicblock_committor_service::intent_executor::IntentExecutorImpl; use magicblock_committor_service::{ - intent_executor::commit_id_fetcher::{ - CommitIdFetcher, CommitIdTrackerResult, + intent_executor::task_info_fetcher::{ + TaskInfoFetcher, TaskInfoFetcherResult, }, tasks::tasks::CommitTask, transaction_preparator::{ @@ -41,7 +42,7 @@ pub struct TestFixture { pub rpc_client: MagicblockRpcClient, table_mania: TableMania, pub authority: Keypair, - compute_budget_config: ComputeBudgetConfig, + pub compute_budget_config: ComputeBudgetConfig, } impl TestFixture { @@ -82,29 +83,47 @@ impl TestFixture { } #[allow(dead_code)] - pub fn create_transaction_preparator( - &self, - ) -> TransactionPreparatorV1 { - TransactionPreparatorV1::::new( + pub fn create_transaction_preparator(&self) -> TransactionPreparatorV1 { + TransactionPreparatorV1::new( self.rpc_client.clone(), self.table_mania.clone(), self.compute_budget_config.clone(), - Arc::new(MockCommitIdFetcher), + ) + } + + #[allow(dead_code)] + pub fn create_intent_executor( + &self, + ) -> IntentExecutorImpl { + let transaction_preparator = self.create_transaction_preparator(); + let task_info_fetcher = Arc::new(MockTaskInfoFetcher); + + IntentExecutorImpl::new( + self.rpc_client.clone(), + transaction_preparator, + task_info_fetcher, ) } } -pub struct MockCommitIdFetcher; +pub struct MockTaskInfoFetcher; #[async_trait] -impl CommitIdFetcher for MockCommitIdFetcher { +impl TaskInfoFetcher for MockTaskInfoFetcher { async fn fetch_next_commit_ids( &self, pubkeys: &[Pubkey], - ) -> CommitIdTrackerResult> { + ) -> TaskInfoFetcherResult> { Ok(pubkeys.iter().map(|pubkey| (*pubkey, 0)).collect()) } + async fn fetch_rent_reimbursements( + &self, + pubkeys: &[Pubkey], + ) -> TaskInfoFetcherResult> { + Ok(pubkeys.to_vec()) + } + fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option { None } diff --git a/test-integration/test-committor-service/tests/test_ix_commit_local.rs b/test-integration/test-committor-service/tests/test_ix_commit_local.rs index bcfad7e50..c8583bfe4 100644 --- a/test-integration/test-committor-service/tests/test_ix_commit_local.rs +++ b/test-integration/test-committor-service/tests/test_ix_commit_local.rs @@ -32,6 +32,7 @@ use solana_sdk::transaction::Transaction; use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, }; +use magicblock_committor_service::intent_executor::ExecutionOutput; use utils::instructions::{ init_account_and_delegate_ixs, init_validator_fees_vault_ix, InitAccountAndDelegateIxs, @@ -277,6 +278,7 @@ async fn test_ix_commit_single_account_800_bytes_and_undelegate() { async fn test_ix_commit_single_account_one_kb() { commit_single_account(1024, false).await; } + #[tokio::test] async fn test_ix_commit_single_account_ten_kb() { commit_single_account(10 * 1024, false).await; @@ -325,7 +327,8 @@ async fn commit_single_account(bytes: usize, undelegate: bool) { }, }; - ix_commit_local(service, vec![intent]).await; + /// We should always be able to Commit & Finalize 1 account either with Args or Buffers + ix_commit_local(service, vec![intent], true).await; } // TODO(thlorenz): once delegation program supports larger commits @@ -337,31 +340,31 @@ async fn commit_single_account(bytes: usize, undelegate: bool) { #[tokio::test] async fn test_ix_commit_two_accounts_1kb_2kb() { init_logger!(); - commit_multiple_accounts(&[1024, 2048], false).await; + commit_multiple_accounts(&[1024, 2048], false, true).await; } #[tokio::test] async fn test_ix_commit_two_accounts_512kb() { init_logger!(); - commit_multiple_accounts(&[512, 512], false).await; + commit_multiple_accounts(&[512, 512], false, true).await; } #[tokio::test] async fn test_ix_commit_three_accounts_512kb() { init_logger!(); - commit_multiple_accounts(&[512, 512, 512], false).await; + commit_multiple_accounts(&[512, 512, 512], false, true).await; } #[tokio::test] async fn test_ix_commit_six_accounts_512kb() { init_logger!(); - commit_multiple_accounts(&[512, 512, 512, 512, 512, 512], false).await; + commit_multiple_accounts(&[512, 512, 512, 512, 512, 512], false, true).await; } #[tokio::test] async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() { init_logger!(); - commit_multiple_accounts(&[1024, 2 * 1024, 5 * 1024, 10 * 1024], false) + commit_multiple_accounts(&[1024, 2 * 1024, 5 * 1024, 10 * 1024], false, true) .await; } @@ -417,22 +420,25 @@ async fn test_commit_20_accounts_1kb_bundle_size_8() { async fn commit_5_accounts_1kb(undelegate_all: bool) { init_logger!(); let accs = (0..5).map(|_| 1024).collect::>(); - commit_multiple_accounts(&accs, undelegate_all).await; + // Let's see + commit_multiple_accounts(&accs, undelegate_all, true).await; } async fn commit_8_accounts_1kb() { init_logger!(); let accs = (0..8).map(|_| 1024).collect::>(); - commit_multiple_accounts(&accs, false).await; + // We can't commit 8 accs in single stage, expecting Commit & Finalize stages + commit_multiple_accounts(&accs, false, true).await; } async fn commit_20_accounts_1kb() { init_logger!(); let accs = (0..20).map(|_| 1024).collect::>(); - commit_multiple_accounts(&accs, false).await; + // We can't commit 20 accs in single stage, expecting Commit & Finalize stages + commit_multiple_accounts(&accs, false, false).await; } -async fn commit_multiple_accounts(bytess: &[usize], undelegate_all: bool) { +async fn commit_multiple_accounts(bytess: &[usize], undelegate_all: bool, single_stage: bool) { init_logger!(); let validator_auth = ensure_validator_authority(); @@ -464,27 +470,20 @@ async fn commit_multiple_accounts(bytess: &[usize], undelegate_all: bool) { pda_acc.owner = program_flexi_counter::id(); pda_acc.data = vec![idx as u8; bytes]; - - let request_undelegation = undelegate_all || idx % 2 == 0; - (pda, pda_acc, request_undelegation) + (pda, pda_acc) }); } - let (committed, commmitted_and_undelegated): (Vec<_>, Vec<_>) = - join_set.join_all().await.into_iter().partition( - |(_, _, request_undelegation)| !request_undelegation, - ); - - let mut base_intents = vec![]; + let committed= join_set.join_all().await; let committed_accounts = committed .into_iter() - .map(|(pda, pda_acc, _)| CommittedAccountV2 { + .map(|(pda, pda_acc)| CommittedAccountV2 { pubkey: pda, account: pda_acc, }) .collect::>(); - if !committed_accounts.is_empty() { + let base_intent = if !undelegate_all { let commit_intent = ScheduledBaseIntentWrapper { trigger_type: TriggerType::OnChain, inner: ScheduledBaseIntent { @@ -499,18 +498,8 @@ async fn commit_multiple_accounts(bytess: &[usize], undelegate_all: bool) { }, }; - base_intents.push(commit_intent); - } - - let committed_and_undelegated_accounts = commmitted_and_undelegated - .into_iter() - .map(|(pda, pda_acc, _)| CommittedAccountV2 { - pubkey: pda, - account: pda_acc, - }) - .collect::>(); - - if !committed_and_undelegated_accounts.is_empty() { + commit_intent + } else { let commit_and_undelegate_intent = ScheduledBaseIntentWrapper { trigger_type: TriggerType::OnChain, inner: ScheduledBaseIntent { @@ -522,7 +511,7 @@ async fn commit_multiple_accounts(bytess: &[usize], undelegate_all: bool) { base_intent: MagicBaseIntent::CommitAndUndelegate( CommitAndUndelegate { commit_action: CommitType::Standalone( - committed_and_undelegated_accounts, + committed_accounts, ), undelegate_action: UndelegateType::Standalone, }, @@ -530,10 +519,10 @@ async fn commit_multiple_accounts(bytess: &[usize], undelegate_all: bool) { }, }; - base_intents.push(commit_and_undelegate_intent); - } + commit_and_undelegate_intent + }; - ix_commit_local(service, base_intents).await; + ix_commit_local(service, vec![base_intent], single_stage).await; } } @@ -567,6 +556,7 @@ async fn commit_multiple_accounts(bytess: &[usize], undelegate_all: bool) { async fn ix_commit_local( service: CommittorServiceExt, base_intents: Vec, + is_single_stage: bool ) { let execution_outputs = service .schedule_base_intents_waiting(base_intents.clone()) @@ -585,25 +575,43 @@ async fn ix_commit_local( execution_outputs.into_iter().zip(base_intents) { // Ensure that the signatures are pointing to the correct transactions - let signatures = execution_output.output; - // Execution output presents of complete stages, both commit & finalize - // Since finalization isn't optional and is a part of the flow - // Assert that both indeed happened + let execution_output = execution_output.output; + let (commit_signature, finalize_signature) = if is_single_stage { + let ExecutionOutput::SingleStage(signature) = execution_output else { + panic!("Expected SingleStage execution, actual: TwoStage"); + }; + + // Commit & Finalize happened in 1 tx + (signature, signature) + } else { + let ExecutionOutput::TwoStage { + commit_signature, + finalize_signature + } = execution_output else { + panic!("Expected TwoStage execution, actual: SingleStage"); + }; + + // Execution output presents of complete stages, both commit & finalize + // Since finalization isn't optional and is a part of the flow + // Assert that both indeed happened + (commit_signature, finalize_signature) + }; + assert!( tx_logs_contain( &rpc_client, - &signatures.commit_signature, + &commit_signature, "CommitState" ) - .await + .await ); assert!( tx_logs_contain( &rpc_client, - &signatures.finalize_signature, + &finalize_signature, "Finalize" ) - .await + .await ); let is_undelegate = intent.is_undelegate(); @@ -612,7 +620,7 @@ async fn ix_commit_local( assert!( tx_logs_contain( &rpc_client, - &signatures.finalize_signature, + &finalize_signature, "Undelegate" ) .await diff --git a/test-integration/test-committor-service/tests/test_transaction_preparator.rs b/test-integration/test-committor-service/tests/test_transaction_preparator.rs index 3c364c9bb..b3f7f2e98 100644 --- a/test-integration/test-committor-service/tests/test_transaction_preparator.rs +++ b/test-integration/test-committor-service/tests/test_transaction_preparator.rs @@ -1,21 +1,22 @@ -use std::collections::HashMap; - +use borsh::BorshDeserialize; +use dlp::args::Context; +use crate::common::{ + create_committed_account, generate_random_bytes, TestFixture, +}; +use magicblock_committor_service::tasks::task_strategist::{TaskStrategist, TransactionStrategy}; +use magicblock_committor_service::tasks::tasks::{ArgsTask, BaseTask, BufferTask, CommitTask, FinalizeTask, L1ActionTask, UndelegateTask}; +use magicblock_committor_service::tasks::utils::TransactionUtils; use magicblock_committor_service::{ persist::IntentPersisterImpl, transaction_preparator::transaction_preparator::TransactionPreparator, }; use magicblock_program::magic_scheduled_base_intent::{ - BaseAction, CommitAndUndelegate, CommitType, CommittedAccountV2, - MagicBaseIntent, ProgramArgs, ScheduledBaseIntent, ShortAccountMeta, - UndelegateType, + BaseAction, + ProgramArgs, ShortAccountMeta, }; use solana_pubkey::Pubkey; -use solana_sdk::{ - account::Account, hash::Hash, signer::Signer, system_program, - transaction::Transaction, -}; - -use crate::common::{create_committed_account, TestFixture}; +use solana_sdk::{signer::Signer, system_program, }; +use magicblock_committor_program::Chunks; mod common; @@ -27,30 +28,49 @@ async fn test_prepare_commit_tx_with_single_account() { // Create test data let account_data = vec![1, 2, 3, 4, 5]; let committed_account = create_committed_account(&account_data); - let l1_message = ScheduledBaseIntent { - id: 1, - slot: 0, - blockhash: Hash::default(), - action_sent_transaction: Transaction::default(), - payer: fixture.authority.pubkey(), - base_intent: MagicBaseIntent::Commit(CommitType::Standalone(vec![ - committed_account.clone(), - ])), - }; - let mut commit_ids = HashMap::new(); - commit_ids.insert(committed_account.pubkey, 1); + let tasks = vec![ + Box::new(ArgsTask::Commit(CommitTask { + commit_id: 1, + committed_account: committed_account.clone(), + allow_undelegation: true, + })) as Box, + Box::new(ArgsTask::Finalize(FinalizeTask { + delegated_account: committed_account.pubkey, + })), + ]; + let tx_strategy = TransactionStrategy { + optimized_tasks: tasks, + lookup_tables_keys: vec![], + }; // Test preparation let result = preparator - .prepare_commit_tx( + .prepare_for_strategy( &fixture.authority, - &l1_message, + &tx_strategy, &None::, ) .await; assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); + + // For such strategy there's no preparation + // expected messsage is just assembled tx from Args task with no ALTs + let mut actual_message = result.unwrap(); + let expected_message = TransactionUtils::assemble_tasks_tx( + &fixture.authority, + &tx_strategy.optimized_tasks, + fixture.compute_budget_config.compute_unit_price, + &[], + ) + .unwrap() + .message; + + // Block hash is random in result of prepare_for_strategy + // should be set be caller, so here we just set value of expected for test + actual_message.set_recent_blockhash(*expected_message.recent_blockhash()); + assert_eq!(actual_message, expected_message) } #[tokio::test] @@ -58,51 +78,72 @@ async fn test_prepare_commit_tx_with_multiple_accounts() { let fixture = TestFixture::new().await; let preparator = fixture.create_transaction_preparator(); + let account1_data = generate_random_bytes(20); + let committed_account1 = create_committed_account(&account1_data); + + let account2_data = generate_random_bytes(12); + let committed_account2 = create_committed_account(&account2_data); + + let buffer_commit_task = BufferTask::Commit(CommitTask { + commit_id: 1, + committed_account: committed_account2.clone(), + allow_undelegation: true, + }); // Create test data - let accounts = vec![ - CommittedAccountV2 { - pubkey: Pubkey::new_unique(), - account: Account { - lamports: 1000, - data: vec![1, 2, 3], - owner: system_program::id(), - executable: false, - rent_epoch: 0, - }, - }, - CommittedAccountV2 { - pubkey: Pubkey::new_unique(), - account: Account { - lamports: 2000, - data: vec![4, 5, 6], - owner: system_program::id(), - executable: false, - rent_epoch: 0, - }, - }, + let tasks = vec![ + // account 1 + Box::new(ArgsTask::Commit(CommitTask { + commit_id: 1, + committed_account: committed_account1.clone(), + allow_undelegation: true, + })) as Box, + // account 2 + Box::new(buffer_commit_task.clone()), + // finalize account 1 + Box::new(ArgsTask::Finalize(FinalizeTask { + delegated_account: committed_account1.pubkey, + })), + // finalize account 2 + Box::new(ArgsTask::Finalize(FinalizeTask { + delegated_account: committed_account2.pubkey, + })), ]; - - let l1_message = ScheduledBaseIntent { - id: 1, - slot: 0, - blockhash: Hash::default(), - action_sent_transaction: Transaction::default(), - payer: fixture.authority.pubkey(), - base_intent: MagicBaseIntent::Commit(CommitType::Standalone( - accounts.clone(), - )), + let tx_strategy = TransactionStrategy { + optimized_tasks: tasks, + lookup_tables_keys: vec![], }; // Test preparation - let result = preparator - .prepare_commit_tx( + let mut actual_message = preparator + .prepare_for_strategy( &fixture.authority, - &l1_message, + &tx_strategy, &None::, ) - .await; - - assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); + .await + .unwrap(); + + let expected_message = TransactionUtils::assemble_tasks_tx( + &fixture.authority, + &tx_strategy.optimized_tasks, + fixture.compute_budget_config.compute_unit_price, + &[], + ) + .unwrap() + .message; + + // Block hash is random in result of prepare_for_strategy + // should be set be caller, so here we just set value of expected for test + actual_message.set_recent_blockhash(*expected_message.recent_blockhash()); + assert_eq!(actual_message, expected_message); + + // Now we verify that buffers were created + let preparation_info = buffer_commit_task.preparation_info(&fixture.authority.pubkey()).unwrap(); + + let chunks_account = fixture.rpc_client.get_account(&preparation_info.chunks_pda).await.unwrap().unwrap(); + let chunks = Chunks::try_from_slice(&chunks_account.data).unwrap(); + + assert!(chunks.is_complete()); } #[tokio::test] @@ -111,18 +152,8 @@ async fn test_prepare_commit_tx_with_l1_actions() { let preparator = fixture.create_transaction_preparator(); // Create test data - let account = CommittedAccountV2 { - pubkey: Pubkey::new_unique(), - account: Account { - lamports: 1000, - data: vec![1, 2, 3], - owner: system_program::id(), - executable: false, - rent_epoch: 0, - }, - }; - - let l1_action = BaseAction { + let committed_account = create_committed_account(&[1, 2, 3]); + let base_action = BaseAction { compute_units: 30_000, destination_program: system_program::id(), escrow_authority: fixture.authority.pubkey(), @@ -136,153 +167,101 @@ async fn test_prepare_commit_tx_with_l1_actions() { }], }; - let l1_message = ScheduledBaseIntent { - id: 1, - slot: 0, - blockhash: Hash::default(), - action_sent_transaction: Transaction::default(), - payer: fixture.authority.pubkey(), - base_intent: MagicBaseIntent::Commit(CommitType::WithBaseActions { - committed_accounts: vec![account.clone()], - base_actions: vec![l1_action], - }), - }; - - let mut commit_ids = HashMap::new(); - commit_ids.insert(account.pubkey, 1); + let buffer_commit_task = BufferTask::Commit(CommitTask { + commit_id: 1, + committed_account: committed_account.clone(), + allow_undelegation: true, + }); + let tasks = vec![ + // commit account + Box::new(buffer_commit_task.clone()) as Box, + // finalize account + Box::new(ArgsTask::Finalize(FinalizeTask { + delegated_account: committed_account.pubkey, + })), + // L1Action + Box::new(ArgsTask::L1Action(L1ActionTask { + context: Context::Commit, + action: base_action + })) + ]; // Test preparation - let result = preparator - .prepare_commit_tx( - &fixture.authority, - &l1_message, - &None::, - ) - .await; - - assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); -} - -#[tokio::test] -async fn test_prepare_finalize_tx_with_undelegate() { - let fixture = TestFixture::new().await; - let preparator = fixture.create_transaction_preparator(); - - // Create test data - let l1_message = ScheduledBaseIntent { - id: 1, - slot: 0, - blockhash: Hash::default(), - action_sent_transaction: Transaction::default(), - payer: fixture.authority.pubkey(), - base_intent: MagicBaseIntent::CommitAndUndelegate( - CommitAndUndelegate { - commit_action: CommitType::Standalone(vec![]), - undelegate_action: UndelegateType::Standalone, - }, - ), + let tx_strategy = TransactionStrategy { + optimized_tasks: tasks, + lookup_tables_keys: vec![], }; // Test preparation - let result = preparator - .prepare_finalize_tx( + let mut actual_message = preparator + .prepare_for_strategy( &fixture.authority, - &l1_message, + &tx_strategy, &None::, ) - .await; - - assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); + .await + .unwrap(); + + let expected_message = TransactionUtils::assemble_tasks_tx( + &fixture.authority, + &tx_strategy.optimized_tasks, + fixture.compute_budget_config.compute_unit_price, + &[], + ) + .unwrap() + .message; + + // Block hash is random in result of prepare_for_strategy + // should be set be caller, so here we just set value of expected for test + actual_message.set_recent_blockhash(*expected_message.recent_blockhash()); + assert_eq!(actual_message, expected_message); + + // Now we verify that buffers were created + let preparation_info = buffer_commit_task.preparation_info(&fixture.authority.pubkey()).unwrap(); + + let chunks_account = fixture.rpc_client.get_account(&preparation_info.chunks_pda).await.unwrap().unwrap(); + let chunks = Chunks::try_from_slice(&chunks_account.data).unwrap(); + + assert!(chunks.is_complete()); } #[tokio::test] -async fn test_prepare_finalize_tx_with_undelegate_and_actions() { +async fn test_prepare_finalize_tx_with_undelegate_with_atls() { let fixture = TestFixture::new().await; let preparator = fixture.create_transaction_preparator(); // Create test data - let l1_action = BaseAction { - compute_units: 30_000, - destination_program: system_program::id(), - escrow_authority: fixture.authority.pubkey(), - data_per_program: ProgramArgs { - escrow_index: 0, - data: vec![4, 5, 6], - }, - account_metas_per_program: vec![ShortAccountMeta { - pubkey: Pubkey::new_unique(), - is_writable: true, - }], - }; - - let l1_message = ScheduledBaseIntent { - id: 1, - slot: 0, - blockhash: Hash::default(), - action_sent_transaction: Transaction::default(), - payer: fixture.authority.pubkey(), - base_intent: MagicBaseIntent::CommitAndUndelegate( - CommitAndUndelegate { - commit_action: CommitType::Standalone(vec![]), - undelegate_action: UndelegateType::WithBaseActions(vec![ - l1_action, - ]), - }, - ), - }; - - // Test preparation - let result = preparator - .prepare_finalize_tx( - &fixture.authority, - &l1_message, - &None::, - ) - .await; - - assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); -} - -#[tokio::test] -async fn test_prepare_large_commit_tx_uses_buffers() { - let fixture = TestFixture::new().await; - let preparator = fixture.create_transaction_preparator(); - - // Create large account data (10KB) - let account_data = vec![0; u16::MAX as usize + 1]; - let committed_account = CommittedAccountV2 { - pubkey: Pubkey::new_unique(), - account: Account { - lamports: 1000, - data: account_data, - owner: system_program::id(), - executable: false, - rent_epoch: 0, - }, - }; + let committed_account = create_committed_account(&[1,2,3]); + let tasks: Vec> = vec![ + // finalize account + Box::new(ArgsTask::Finalize(FinalizeTask { + delegated_account: committed_account.pubkey, + })), + // L1Action + Box::new(ArgsTask::Undelegate(UndelegateTask { + delegated_account: committed_account.pubkey, + owner_program: Pubkey::new_unique(), + rent_reimbursement: Pubkey::new_unique() + })) + ]; - let l1_message = ScheduledBaseIntent { - id: 1, - slot: 0, - blockhash: Hash::default(), - action_sent_transaction: Transaction::default(), - payer: fixture.authority.pubkey(), - base_intent: MagicBaseIntent::Commit(CommitType::Standalone(vec![ - committed_account.clone(), - ])), + let lookup_tables_keys = TaskStrategist::collect_lookup_table_keys( + &fixture.authority.pubkey(), + &tasks, + ); + let tx_strategy = TransactionStrategy { + optimized_tasks: tasks, + lookup_tables_keys, }; - let mut commit_ids = HashMap::new(); - commit_ids.insert(committed_account.pubkey, 1); - // Test preparation let result = preparator - .prepare_commit_tx( + .prepare_for_strategy( &fixture.authority, - &l1_message, + &tx_strategy, &None::, ) .await; - assert!(result.is_ok(), "Preparation failed: {:?}", result.err()); + assert!(result.is_ok()); } diff --git a/test-integration/test-config/src/lib.rs b/test-integration/test-config/src/lib.rs index 34508c267..511577be6 100644 --- a/test-integration/test-config/src/lib.rs +++ b/test-integration/test-config/src/lib.rs @@ -52,7 +52,7 @@ pub fn start_validator_with_clone_config( lifecycle: LifecycleMode::Ephemeral, clone: AccountsCloneConfig { prepare_lookup_tables, - auto_airdrop_lamports: 0 + auto_airdrop_lamports: 0, }, ..Default::default() }, diff --git a/test-integration/test-config/tests/auto_airdrop_feepayer.rs b/test-integration/test-config/tests/auto_airdrop_feepayer.rs index 4ebe98bef..edbc16957 100644 --- a/test-integration/test-config/tests/auto_airdrop_feepayer.rs +++ b/test-integration/test-config/tests/auto_airdrop_feepayer.rs @@ -1,6 +1,5 @@ use integration_test_tools::{ - expect, - loaded_accounts::LoadedAccounts, + expect, loaded_accounts::LoadedAccounts, validator::start_magicblock_validator_with_config_struct, IntegrationTestContext, }; @@ -8,11 +7,7 @@ use magicblock_config::{ AccountsCloneConfig, AccountsConfig, EphemeralConfig, LifecycleMode, RemoteCluster, RemoteConfig, }; -use solana_sdk::{ - signature::Keypair, - signer::Signer, - system_instruction, -}; +use solana_sdk::{signature::Keypair, signer::Signer, system_instruction}; use test_tools_core::init_logger; #[test] @@ -24,7 +19,9 @@ fn test_auto_airdrop_feepayer_balance_after_tx() { accounts: AccountsConfig { remote: RemoteConfig { cluster: RemoteCluster::Custom, - url: Some(IntegrationTestContext::url_chain().try_into().unwrap()), + url: Some( + IntegrationTestContext::url_chain().try_into().unwrap(), + ), ws_url: Some(vec![IntegrationTestContext::ws_url_chain() .try_into() .unwrap()]), @@ -40,10 +37,12 @@ fn test_auto_airdrop_feepayer_balance_after_tx() { }; // Start the validator - let (_tmpdir, Some(mut validator)) = start_magicblock_validator_with_config_struct( - config, - &LoadedAccounts::with_delegation_program_test_authority(), - ) else { + let (_tmpdir, Some(mut validator)) = + start_magicblock_validator_with_config_struct( + config, + &LoadedAccounts::with_delegation_program_test_authority(), + ) + else { panic!("validator should set up correctly"); }; @@ -57,17 +56,16 @@ fn test_auto_airdrop_feepayer_balance_after_tx() { // Send a 0-lamport transfer to trigger account creation/cloning for the new fee payer // This should cause the validator to auto-airdrop 1 SOL to the payer - let ix = system_instruction::transfer(&payer.pubkey(), &recipient.pubkey(), 0); + let ix = + system_instruction::transfer(&payer.pubkey(), &recipient.pubkey(), 0); let _sig = expect!( ctx.send_and_confirm_instructions_with_payer_ephem(&[ix], &payer), validator ); - // Fetch the payer balance from the ephemeral validator and assert it equals 100_000 - let balance = expect!( - ctx.fetch_ephem_account_balance(&payer.pubkey()), - validator - ); + // Fetch the payer balance from the ephemeral validator and assert it equals 1_000_000_000 + let balance = + expect!(ctx.fetch_ephem_account_balance(&payer.pubkey()), validator); assert_eq!(balance, 1_000_000_000); // Cleanup validator process diff --git a/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs b/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs index 9d5a7a10a..ee155da4b 100644 --- a/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs +++ b/test-integration/test-ledger-restore/tests/07_commit_delegated_account.rs @@ -165,8 +165,7 @@ fn write(ledger_path: &Path, payer: &Keypair) -> (Child, u64) { // - init // - delegate // - commit (original from while validator was running) - // - finalize - assert_counter_commits_on_chain(&ctx, &mut validator, &payer.pubkey(), 4); + assert_counter_commits_on_chain(&ctx, &mut validator, &payer.pubkey(), 3); let slot = wait_for_ledger_persist(&mut validator); (validator, slot) @@ -209,7 +208,7 @@ fn read(ledger_path: &Path, payer: &Pubkey) -> Child { // Ensure that at this point we still only have three chain transactions // for the counter, showing that the commits didn't get sent to chain again. - assert_counter_commits_on_chain(&ctx, &mut validator, payer, 4); + assert_counter_commits_on_chain(&ctx, &mut validator, payer, 3); validator } diff --git a/test-integration/test-ledger-restore/tests/08_commit_update.rs b/test-integration/test-ledger-restore/tests/08_commit_update.rs index 353339369..d91da7343 100644 --- a/test-integration/test-ledger-restore/tests/08_commit_update.rs +++ b/test-integration/test-ledger-restore/tests/08_commit_update.rs @@ -155,7 +155,7 @@ fn write(ledger_path: &Path, payer: &Keypair) -> (Child, u64) { ); } - assert_counter_commits_on_chain(&ctx, &mut validator, &payer.pubkey(), 4); + assert_counter_commits_on_chain(&ctx, &mut validator, &payer.pubkey(), 3); let slot = wait_for_ledger_persist(&mut validator); (validator, slot) @@ -211,7 +211,7 @@ fn read(ledger_path: &Path, payer_kp: &Keypair) -> Child { ); // Ensure we did not commit during ledger replay - assert_counter_commits_on_chain(&ctx, &mut validator, payer, 4); + assert_counter_commits_on_chain(&ctx, &mut validator, payer, 3); validator } diff --git a/test-integration/test-magicblock-api/tests/test_claim_fees.rs b/test-integration/test-magicblock-api/tests/test_claim_fees.rs index 768989e55..6b0a8d97f 100644 --- a/test-integration/test-magicblock-api/tests/test_claim_fees.rs +++ b/test-integration/test-magicblock-api/tests/test_claim_fees.rs @@ -4,6 +4,7 @@ use integration_test_tools::{ }; use magicblock_validator_admin::claim_fees::ClaimFeesTask; use solana_rpc_client::rpc_client::RpcClient; +use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::Keypair; use solana_sdk::{ commitment_config::CommitmentConfig, signature::Signer, @@ -11,7 +12,6 @@ use solana_sdk::{ }; use std::thread::sleep; use std::time::Duration; -use solana_sdk::pubkey::Pubkey; // Test constants const DEVNET_URL: &str = "http://127.0.0.1:7799"; diff --git a/test-integration/test-runner/bin/run_tests.rs b/test-integration/test-runner/bin/run_tests.rs index 9ce064f40..a8db60510 100644 --- a/test-integration/test-runner/bin/run_tests.rs +++ b/test-integration/test-runner/bin/run_tests.rs @@ -65,7 +65,8 @@ pub fn main() { return; }; - let Ok(schedule_intents_output) = run_schedule_intents_tests(&manifest_dir, &config) + let Ok(schedule_intents_output) = + run_schedule_intents_tests(&manifest_dir, &config) else { return; }; @@ -209,10 +210,8 @@ fn run_table_mania_and_committor_tests( }; let committor_test_output = if run_committor { - let test_committor_dir = format!( - "{}/../{}", - manifest_dir, "schedulecommit/committor-service" - ); + let test_committor_dir = + format!("{}/../{}", manifest_dir, "test-committor-service"); eprintln!("Running committor tests in {}", test_committor_dir); match run_test(test_committor_dir, Default::default()) { Ok(output) => output, @@ -635,7 +634,7 @@ fn run_schedule_intents_tests( panic!("Failed to start devnet validator properly"); } }; - let start_ephem_validator = || match start_validator( + let start_ephem_validator = || match start_validator( "schedulecommit-conf.ephem.frequent-commits.toml", ValidatorCluster::Ephem, &loaded_chain_accounts, diff --git a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs index 8bba41c92..8059dcf84 100644 --- a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs +++ b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs @@ -12,9 +12,11 @@ use solana_sdk::rent::Rent; use solana_sdk::signature::Keypair; use solana_sdk::signer::Signer; use solana_sdk::transaction::Transaction; +use std::time::Duration; const LABEL: &str = "I am label"; +#[ignore] #[test] fn test_schedule_intent() { // Init context @@ -26,36 +28,60 @@ fn test_schedule_intent() { // Delegate counter delegate_counter(&ctx, &payer); add_to_counter(&ctx, &payer, 101); - schedule_intent(&ctx, &[&payer], vec![-100], false); + schedule_intent(&ctx, &[&payer], vec![-100], false, None); } #[test] -fn test_multiple_payers_multiple_counters() { +fn test_3_payers_intent_with_undelegation() { + const PAYERS: usize = 3; + // Init context let ctx = IntegrationTestContext::try_new().unwrap(); - let payer1 = setup_payer(&ctx); - let payer2 = setup_payer(&ctx); - let payer3 = setup_payer(&ctx); + let payers = (0..PAYERS).map(|_| setup_payer(&ctx)).collect::>(); // Init and setup counters for each payer - init_counter(&ctx, &payer1); - delegate_counter(&ctx, &payer1); - add_to_counter(&ctx, &payer1, 100); + let values: [u8; PAYERS] = [100, 200, 201]; + payers.iter().enumerate().for_each(|(i, payer)| { + init_counter(&ctx, &payer); + delegate_counter(&ctx, &payer); + add_to_counter(&ctx, &payer, values[i]); + }); - init_counter(&ctx, &payer2); - delegate_counter(&ctx, &payer2); - add_to_counter(&ctx, &payer2, 200); + // Schedule intent affecting all counters + schedule_intent( + &ctx, + payers.iter().collect::>().as_slice(), + vec![-50, 25, -75], + true, + Some(Duration::from_secs(50)), + ); +} - init_counter(&ctx, &payer3); - delegate_counter(&ctx, &payer3); - add_to_counter(&ctx, &payer3, 201); +#[ignore] +#[test] +fn test_5_payers_intent_only_commit() { + const PAYERS: usize = 5; + // Init context + let ctx = IntegrationTestContext::try_new().unwrap(); + let payers = (0..PAYERS).map(|_| setup_payer(&ctx)).collect::>(); + + // Init and setup counters for each payer + let values: [u8; PAYERS] = std::array::from_fn(|i| 180 + i as u8); + payers.iter().enumerate().for_each(|(i, payer)| { + init_counter(&ctx, &payer); + delegate_counter(&ctx, &payer); + add_to_counter(&ctx, &payer, values[i]); + }); + + let counter_diffs: [i64; PAYERS] = [0; PAYERS]; // Schedule intent affecting all counters schedule_intent( &ctx, - &[&payer1, &payer2, &payer3], - vec![-50, 25, -75], + payers.iter().collect::>().as_slice(), + counter_diffs.to_vec(), // not used true, + Some(Duration::from_secs(25)), ); } @@ -156,6 +182,7 @@ fn schedule_intent( payers: &[&Keypair], counter_diffs: Vec, is_undelegate: bool, + confirmation_wait: Option, ) { ctx.wait_for_next_slot_ephem().unwrap(); @@ -190,6 +217,12 @@ fn schedule_intent( }, ) .unwrap(); + + // In some cases it takes longer for tx to make it to baselayer + // we need an additional wait time + if let Some(confirmation_wait) = confirmation_wait { + std::thread::sleep(confirmation_wait); + } let confirmed = IntegrationTestContext::confirm_transaction( &sig, rpc_client, From 46fef4aec190eb926e82e58b0107208c38fd996c Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 20 Aug 2025 17:26:11 +0900 Subject: [PATCH 187/199] fix: revert tests in ix_commit_local. asserting strategies returned --- .../tasks/task_visitors/persistor_visitor.rs | 8 +- .../test-committor-service/tests/common.rs | 14 +- .../tests/test_ix_commit_local.rs | 560 ++++++++++++------ .../tests/test_transaction_preparator.rs | 56 +- 4 files changed, 414 insertions(+), 224 deletions(-) diff --git a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs index 71f2dc596..931d4efc1 100644 --- a/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs +++ b/magicblock-committor-service/src/tasks/task_visitors/persistor_visitor.rs @@ -30,9 +30,9 @@ where }; let commit_strategy = if uses_lookup_tables { - CommitStrategy::Args - } else { CommitStrategy::ArgsWithLookupTable + } else { + CommitStrategy::Args }; if let Err(err) = self.persistor.set_commit_strategy( @@ -55,9 +55,9 @@ where PersistorContext::PersistStrategy { uses_lookup_tables } => { let BufferTask::Commit(commit_task) = task; let commit_strategy = if uses_lookup_tables { - CommitStrategy::FromBuffer - } else { CommitStrategy::FromBufferWithLookupTable + } else { + CommitStrategy::FromBuffer }; if let Err(err) = self.persistor.set_commit_strategy( diff --git a/test-integration/test-committor-service/tests/common.rs b/test-integration/test-committor-service/tests/common.rs index 5ca9a93f5..24ce24ab6 100644 --- a/test-integration/test-committor-service/tests/common.rs +++ b/test-integration/test-committor-service/tests/common.rs @@ -1,10 +1,3 @@ -use std::{ - collections::HashMap, - sync::{ - atomic::{AtomicU64, Ordering}, - Arc, - }, -}; use async_trait::async_trait; use magicblock_committor_service::intent_executor::IntentExecutorImpl; use magicblock_committor_service::{ @@ -27,6 +20,13 @@ use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ commitment_config::CommitmentConfig, signature::Keypair, signer::Signer, }; +use std::{ + collections::HashMap, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, + }, +}; // Helper function to create a test RPC client pub async fn create_test_client() -> MagicblockRpcClient { diff --git a/test-integration/test-committor-service/tests/test_ix_commit_local.rs b/test-integration/test-committor-service/tests/test_ix_commit_local.rs index c8583bfe4..089d09e3b 100644 --- a/test-integration/test-committor-service/tests/test_ix_commit_local.rs +++ b/test-integration/test-committor-service/tests/test_ix_commit_local.rs @@ -1,13 +1,15 @@ use log::*; -use magicblock_committor_service::ComputeBudgetConfig; +use magicblock_committor_service::{BaseIntentCommittor, ComputeBudgetConfig}; use magicblock_rpc_client::MagicblockRpcClient; -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::sync::{Arc, Once}; use std::time::{Duration, Instant}; use test_tools_core::init_logger; use tokio::task::JoinSet; use utils::transactions::tx_logs_contain; +use magicblock_committor_service::intent_executor::ExecutionOutput; +use magicblock_committor_service::persist::CommitStrategy; use magicblock_committor_service::service_ext::{ BaseIntentCommittorExt, CommittorServiceExt, }; @@ -32,7 +34,6 @@ use solana_sdk::transaction::Transaction; use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::Keypair, signer::Signer, }; -use magicblock_committor_service::intent_executor::ExecutionOutput; use utils::instructions::{ init_account_and_delegate_ixs, init_validator_fees_vault_ix, InitAccountAndDelegateIxs, @@ -43,6 +44,17 @@ mod utils; // ----------------- // Utilities and Setup // ----------------- +type ExpectedStrategies = HashMap; + +fn expect_strategies( + strategies: &[(CommitStrategy, u8)], +) -> ExpectedStrategies { + let mut expected_strategies = HashMap::new(); + for (strategy, count) in strategies { + *expected_strategies.entry(*strategy).or_insert(0) += count; + } + expected_strategies +} fn ensure_validator_authority() -> Keypair { static ONCE: Once = Once::new(); @@ -256,35 +268,39 @@ async fn init_and_delegate_account_on_chain( // ----------------- #[tokio::test] async fn test_ix_commit_single_account_100_bytes() { - commit_single_account(100, false).await; + commit_single_account(100, CommitStrategy::Args, false).await; } #[tokio::test] async fn test_ix_commit_single_account_100_bytes_and_undelegate() { - commit_single_account(100, true).await; + commit_single_account(100, CommitStrategy::Args, true).await; } #[tokio::test] async fn test_ix_commit_single_account_800_bytes() { - commit_single_account(800, false).await; + commit_single_account(800, CommitStrategy::FromBuffer, false).await; } #[tokio::test] async fn test_ix_commit_single_account_800_bytes_and_undelegate() { - commit_single_account(800, true).await; + commit_single_account(800, CommitStrategy::FromBuffer, true).await; } #[tokio::test] async fn test_ix_commit_single_account_one_kb() { - commit_single_account(1024, false).await; + commit_single_account(1024, CommitStrategy::FromBuffer, false).await; } #[tokio::test] async fn test_ix_commit_single_account_ten_kb() { - commit_single_account(10 * 1024, false).await; + commit_single_account(10 * 1024, CommitStrategy::FromBuffer, false).await; } -async fn commit_single_account(bytes: usize, undelegate: bool) { +async fn commit_single_account( + bytes: usize, + expected_strategy: CommitStrategy, + undelegate: bool, +) { init_logger!(); let validator_auth = ensure_validator_authority(); @@ -328,7 +344,12 @@ async fn commit_single_account(bytes: usize, undelegate: bool) { }; /// We should always be able to Commit & Finalize 1 account either with Args or Buffers - ix_commit_local(service, vec![intent], true).await; + ix_commit_local( + service, + vec![intent], + expect_strategies(&[(expected_strategy, 1)]), + ) + .await; } // TODO(thlorenz): once delegation program supports larger commits @@ -340,190 +361,319 @@ async fn commit_single_account(bytes: usize, undelegate: bool) { #[tokio::test] async fn test_ix_commit_two_accounts_1kb_2kb() { init_logger!(); - commit_multiple_accounts(&[1024, 2048], false, true).await; + commit_multiple_accounts( + &[1024, 2048], + 1, + false, + expect_strategies(&[(CommitStrategy::FromBuffer, 2)]), + ) + .await; } #[tokio::test] async fn test_ix_commit_two_accounts_512kb() { init_logger!(); - commit_multiple_accounts(&[512, 512], false, true).await; + commit_multiple_accounts( + &[512, 512], + 1, + false, + expect_strategies(&[(CommitStrategy::Args, 2)]), + ) + .await; } #[tokio::test] async fn test_ix_commit_three_accounts_512kb() { init_logger!(); - commit_multiple_accounts(&[512, 512, 512], false, true).await; + commit_multiple_accounts( + &[512, 512, 512], + 1, + false, + expect_strategies(&[(CommitStrategy::Args, 3)]), + ) + .await; } #[tokio::test] async fn test_ix_commit_six_accounts_512kb() { init_logger!(); - commit_multiple_accounts(&[512, 512, 512, 512, 512, 512], false, true).await; + commit_multiple_accounts( + &[512, 512, 512, 512, 512, 512], + 1, + false, + expect_strategies(&[(CommitStrategy::Args, 6)]), + ) + .await; } #[tokio::test] async fn test_ix_commit_four_accounts_1kb_2kb_5kb_10kb_single_bundle() { init_logger!(); - commit_multiple_accounts(&[1024, 2 * 1024, 5 * 1024, 10 * 1024], false, true) - .await; + commit_multiple_accounts( + &[1024, 2 * 1024, 5 * 1024, 10 * 1024], + 1, + false, + expect_strategies(&[(CommitStrategy::FromBuffer, 4)]), + ) + .await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_2() { - commit_20_accounts_1kb().await; + commit_20_accounts_1kb( + 2, + expect_strategies(&[(CommitStrategy::FromBuffer, 20)]), + ) + .await; } #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_3() { - commit_5_accounts_1kb(false).await; + commit_5_accounts_1kb( + 3, + expect_strategies(&[(CommitStrategy::FromBuffer, 5)]), + false, + ) + .await; } #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() { - commit_5_accounts_1kb(true).await; + commit_5_accounts_1kb( + 3, + expect_strategies(&[ + // Intent fits in 1 TX only with ALT, see IntentExecutorImpl::try_unite_tasks + (CommitStrategy::FromBufferWithLookupTable, 3), + (CommitStrategy::FromBuffer, 2) + ]), + true, + ) + .await; } #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_4() { - commit_5_accounts_1kb(false).await; + commit_5_accounts_1kb( + 4, + expect_strategies(&[ + (CommitStrategy::FromBuffer, 1), + (CommitStrategy::FromBufferWithLookupTable, 4), + ]), + false, + ) + .await; } #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() { - commit_5_accounts_1kb(true).await; + commit_5_accounts_1kb( + 4, + expect_strategies(&[ + (CommitStrategy::FromBuffer, 1), + (CommitStrategy::FromBufferWithLookupTable, 4), + ]), + true, + ) + .await; +} + + +#[tokio::test] +async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() { + commit_5_accounts_1kb( + 5, + expect_strategies(&[ + (CommitStrategy::FromBufferWithLookupTable, 5), + ]), + true, + ) + .await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_3() { - commit_20_accounts_1kb().await; + commit_20_accounts_1kb( + 3, + expect_strategies(&[(CommitStrategy::FromBuffer, 20)]), + ) + .await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_4() { - commit_20_accounts_1kb().await; + commit_20_accounts_1kb( + 4, + expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]), + ) + .await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_6() { - commit_20_accounts_1kb().await; + commit_20_accounts_1kb( + 6, + expect_strategies(&[ + (CommitStrategy::FromBufferWithLookupTable, 18), + // Two accounts don't make it into the bundles of size 6 + (CommitStrategy::FromBuffer, 2), + ]), + ) + .await; +} + +#[tokio::test] +async fn test_commit_20_accounts_1kb_bundle_size_20() { + commit_20_accounts_1kb( + 20, + expect_strategies(&[ + (CommitStrategy::FromBufferWithLookupTable, 20), + ]), + ) + .await; } #[tokio::test] async fn test_commit_8_accounts_1kb_bundle_size_8() { - commit_8_accounts_1kb().await; + commit_8_accounts_1kb( + 8, + expect_strategies(&[ + // Four accounts don't make it into the bundles of size 8, but + // that bundle also needs lookup tables + (CommitStrategy::FromBufferWithLookupTable, 8), + ]), + ) + .await; } + #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_8() { - commit_20_accounts_1kb().await; + commit_20_accounts_1kb( + 8, + expect_strategies(&[ + // Four accounts don't make it into the bundles of size 8, but + // that bundle also needs lookup tables + (CommitStrategy::FromBufferWithLookupTable, 20), + ]), + ) + .await; } -async fn commit_5_accounts_1kb(undelegate_all: bool) { +async fn commit_5_accounts_1kb( + bundle_size: usize, + expected_strategies: ExpectedStrategies, + undelegate_all: bool, +) { init_logger!(); let accs = (0..5).map(|_| 1024).collect::>(); - // Let's see - commit_multiple_accounts(&accs, undelegate_all, true).await; + commit_multiple_accounts( + &accs, + bundle_size, + undelegate_all, + expected_strategies, + ) + .await; } -async fn commit_8_accounts_1kb() { +async fn commit_8_accounts_1kb( + bundle_size: usize, + expected_strategies: ExpectedStrategies, +) { init_logger!(); let accs = (0..8).map(|_| 1024).collect::>(); - // We can't commit 8 accs in single stage, expecting Commit & Finalize stages - commit_multiple_accounts(&accs, false, true).await; + commit_multiple_accounts(&accs, bundle_size, false, expected_strategies) + .await; } -async fn commit_20_accounts_1kb() { +async fn commit_20_accounts_1kb( + bundle_size: usize, + expected_strategies: ExpectedStrategies, +) { init_logger!(); let accs = (0..20).map(|_| 1024).collect::>(); - // We can't commit 20 accs in single stage, expecting Commit & Finalize stages - commit_multiple_accounts(&accs, false, false).await; + commit_multiple_accounts(&accs, bundle_size, false, expected_strategies) + .await; } -async fn commit_multiple_accounts(bytess: &[usize], undelegate_all: bool, single_stage: bool) { +async fn create_bundles( + bundle_size: usize, + bytess: &[usize], +) -> Vec> { + let mut join_set = JoinSet::new(); + for bytes in bytess { + let bytes = *bytes; + join_set.spawn(async move { + let counter_auth = Keypair::new(); + let (pda, mut pda_acc) = + init_and_delegate_account_on_chain(&counter_auth, bytes as u64) + .await; + + pda_acc.owner = program_flexi_counter::id(); + pda_acc.data = vec![0u8; bytes]; + CommittedAccountV2 { + pubkey: pda, + account: pda_acc, + } + }); + } + + // Wait for all tasks to complete + let committed = join_set.join_all().await; + committed + .chunks(bundle_size) + .map(|chunk| chunk.to_vec()) + .collect() +} + +async fn commit_multiple_accounts( + bytess: &[usize], + bundle_size: usize, + undelegate_all: bool, + expected_strategies: ExpectedStrategies, +) { init_logger!(); let validator_auth = ensure_validator_authority(); fund_validator_auth_and_ensure_validator_fees_vault(&validator_auth).await; - { - let service = CommittorService::try_start( - validator_auth.insecure_clone(), - ":memory:", - ChainConfig::local(ComputeBudgetConfig::new(1_000_000)), - ) - .unwrap(); - let service = CommittorServiceExt::new(Arc::new(service)); - - let committees = - bytess.iter().map(|_| Keypair::new()).collect::>(); - - let mut join_set = JoinSet::new(); - for (idx, (bytes, counter_auth)) in - bytess.iter().zip(committees.into_iter()).enumerate() - { - let bytes = *bytes; - join_set.spawn(async move { - let (pda, mut pda_acc) = init_and_delegate_account_on_chain( - &counter_auth, - bytes as u64, - ) - .await; - - pda_acc.owner = program_flexi_counter::id(); - pda_acc.data = vec![idx as u8; bytes]; - (pda, pda_acc) - }); - } - - let committed= join_set.join_all().await; - let committed_accounts = committed - .into_iter() - .map(|(pda, pda_acc)| CommittedAccountV2 { - pubkey: pda, - account: pda_acc, - }) - .collect::>(); - - let base_intent = if !undelegate_all { - let commit_intent = ScheduledBaseIntentWrapper { - trigger_type: TriggerType::OnChain, - inner: ScheduledBaseIntent { - id: 0, - slot: 0, - blockhash: Hash::new_unique(), - action_sent_transaction: Transaction::default(), - payer: Pubkey::new_unique(), - base_intent: MagicBaseIntent::Commit( - CommitType::Standalone(committed_accounts), - ), - }, - }; - - commit_intent - } else { - let commit_and_undelegate_intent = ScheduledBaseIntentWrapper { - trigger_type: TriggerType::OnChain, - inner: ScheduledBaseIntent { - id: 1, - slot: 0, - blockhash: Hash::new_unique(), - action_sent_transaction: Transaction::default(), - payer: Pubkey::new_unique(), - base_intent: MagicBaseIntent::CommitAndUndelegate( - CommitAndUndelegate { - commit_action: CommitType::Standalone( - committed_accounts, - ), - undelegate_action: UndelegateType::Standalone, - }, - ), - }, - }; + let service = CommittorService::try_start( + validator_auth.insecure_clone(), + ":memory:", + ChainConfig::local(ComputeBudgetConfig::new(1_000_000)), + ) + .unwrap(); + let service = CommittorServiceExt::new(Arc::new(service)); - commit_and_undelegate_intent - }; + // Create bundles of committed accounts + let bundles_of_committees = create_bundles(bundle_size, bytess).await; + // Create intent for each bundle + let intents = bundles_of_committees + .into_iter() + .map(|committees| { + if undelegate_all { + MagicBaseIntent::CommitAndUndelegate(CommitAndUndelegate { + commit_action: CommitType::Standalone(committees), + undelegate_action: UndelegateType::Standalone, + }) + } else { + MagicBaseIntent::Commit(CommitType::Standalone(committees)) + } + }) + .enumerate() + .map(|(id, base_intent)| ScheduledBaseIntent { + id: id as u64, + slot: 0, + blockhash: Hash::new_unique(), + action_sent_transaction: Transaction::default(), + payer: Pubkey::new_unique(), + base_intent, + }) + .map(|intent| ScheduledBaseIntentWrapper { + trigger_type: TriggerType::OnChain, + inner: intent, + }) + .collect::>(); - ix_commit_local(service, vec![base_intent], single_stage).await; - } + ix_commit_local(service, intents, expected_strategies).await; } // TODO(thlorenz): once delegation program supports larger commits add the following @@ -556,7 +706,7 @@ async fn commit_multiple_accounts(bytess: &[usize], undelegate_all: bool, single async fn ix_commit_local( service: CommittorServiceExt, base_intents: Vec, - is_single_stage: bool + expected_strategies: ExpectedStrategies, ) { let execution_outputs = service .schedule_base_intents_waiting(base_intents.clone()) @@ -571,112 +721,92 @@ async fn ix_commit_local( service.release_common_pubkeys().await.unwrap(); let rpc_client = RpcClient::new("http://localhost:7799".to_string()); - for (execution_output, intent) in - execution_outputs.into_iter().zip(base_intents) + let mut strategies = ExpectedStrategies::new(); + for (execution_output, base_intent) in + execution_outputs.into_iter().zip(base_intents.into_iter()) { - // Ensure that the signatures are pointing to the correct transactions let execution_output = execution_output.output; - let (commit_signature, finalize_signature) = if is_single_stage { - let ExecutionOutput::SingleStage(signature) = execution_output else { - panic!("Expected SingleStage execution, actual: TwoStage"); - }; - - // Commit & Finalize happened in 1 tx - (signature, signature) - } else { - let ExecutionOutput::TwoStage { + let (commit_signature, finalize_signature) = match execution_output { + ExecutionOutput::SingleStage(signature) => (signature, signature), + ExecutionOutput::TwoStage { commit_signature, - finalize_signature - } = execution_output else { - panic!("Expected TwoStage execution, actual: SingleStage"); - }; - - // Execution output presents of complete stages, both commit & finalize - // Since finalization isn't optional and is a part of the flow - // Assert that both indeed happened - (commit_signature, finalize_signature) + finalize_signature, + } => (commit_signature, finalize_signature), }; assert!( - tx_logs_contain( - &rpc_client, - &commit_signature, - "CommitState" - ) + tx_logs_contain(&rpc_client, &commit_signature, "CommitState") .await ); assert!( - tx_logs_contain( - &rpc_client, - &finalize_signature, - "Finalize" - ) - .await + tx_logs_contain(&rpc_client, &finalize_signature, "Finalize").await ); - let is_undelegate = intent.is_undelegate(); + let is_undelegate = base_intent.is_undelegate(); if is_undelegate { // Undelegate is part of atomic Finalization Stage assert!( - tx_logs_contain( - &rpc_client, - &finalize_signature, - "Undelegate" - ) - .await + tx_logs_contain(&rpc_client, &finalize_signature, "Undelegate") + .await ); } - let committed_accounts = intent.get_committed_accounts().unwrap(); - for account in committed_accounts { + let mut committed_accounts = base_intent + .get_committed_accounts() + .unwrap() + .into_iter() + .map(|el| (el.pubkey, el.clone())) + .collect::>(); + let statuses = service + .get_commit_statuses(base_intent.id) + .await + .unwrap() + .unwrap(); + + // When we finalize it is possible to also undelegate the account + let expected_owner = if is_undelegate { + program_flexi_counter::id() + } else { + dlp::id() + }; + + assert_eq!(statuses.len(), committed_accounts.len()); + for commit_status in statuses { + let account = committed_accounts + .remove(&commit_status.pubkey) + .expect("Account should be persisted"); let lamports = account.account.lamports; get_account!( rpc_client, account.pubkey, "delegated state", |acc: &Account, remaining_tries: u8| { - let matches_data = acc.data() == account.account.data() - && acc.lamports() == lamports; - // When we finalize it is possible to also undelegate the account - let expected_owner = if is_undelegate { - program_flexi_counter::id() - } else { - dlp::id() - }; - let matches_undelegation = acc.owner().eq(&expected_owner); - let matches_all = matches_data && matches_undelegation; - - if !matches_all && remaining_tries % 4 == 0 { - if !matches_data { - trace!( - "Account ({}) data {} != {} || {} != {}", - account.pubkey, - acc.data().len(), - account.account.data().len(), - acc.lamports(), - lamports - ); - } - if !matches_undelegation { - trace!( - "Account ({}) is {} but should be. Owner {} != {}", - account.pubkey, - if is_undelegate { - "not undelegated" - } else { - "undelegated" - }, - acc.owner(), - expected_owner, - ); - } - } - matches_all + validate_account( + acc, + remaining_tries, + &account.account.data, + lamports, + expected_owner, + account.pubkey, + is_undelegate, + ) } ); + + // Track the strategy used + let strategy = commit_status.commit_strategy; + let strategy_count = strategies.entry(strategy).or_insert(0); + *strategy_count += 1; } } + // Compare the strategies used with the expected ones + debug!("Strategies used: {:?}", strategies); + assert_eq!( + strategies, expected_strategies, + "Strategies used do not match expected ones" + ); + let expect_empty_lookup_tables = false; // changeset.accounts.len() == changeset.accounts_to_undelegate.len(); if expect_empty_lookup_tables { @@ -747,3 +877,45 @@ async fn ix_commit_local( } } } + +fn validate_account( + acc: &Account, + remaining_tries: u8, + expected_data: &[u8], + expected_lamports: u64, + expected_owner: Pubkey, + account_pubkey: Pubkey, + is_undelegate: bool, +) -> bool { + let matches_data = + acc.data() == expected_data && acc.lamports() == expected_lamports; + let matches_undelegation = acc.owner().eq(&expected_owner); + let matches_all = matches_data && matches_undelegation; + + if !matches_all && remaining_tries % 4 == 0 { + if !matches_data { + trace!( + "Account ({}) data {} != {} || {} != {}", + account_pubkey, + acc.data().len(), + expected_data.len(), + acc.lamports(), + expected_lamports + ); + } + if !matches_undelegation { + trace!( + "Account ({}) is {} but should be. Owner {} != {}", + account_pubkey, + if is_undelegate { + "not undelegated" + } else { + "undelegated" + }, + acc.owner(), + expected_owner, + ); + } + } + matches_all +} diff --git a/test-integration/test-committor-service/tests/test_transaction_preparator.rs b/test-integration/test-committor-service/tests/test_transaction_preparator.rs index b3f7f2e98..9cc9e92e2 100644 --- a/test-integration/test-committor-service/tests/test_transaction_preparator.rs +++ b/test-integration/test-committor-service/tests/test_transaction_preparator.rs @@ -1,22 +1,26 @@ -use borsh::BorshDeserialize; -use dlp::args::Context; use crate::common::{ create_committed_account, generate_random_bytes, TestFixture, }; -use magicblock_committor_service::tasks::task_strategist::{TaskStrategist, TransactionStrategy}; -use magicblock_committor_service::tasks::tasks::{ArgsTask, BaseTask, BufferTask, CommitTask, FinalizeTask, L1ActionTask, UndelegateTask}; +use borsh::BorshDeserialize; +use dlp::args::Context; +use magicblock_committor_program::Chunks; +use magicblock_committor_service::tasks::task_strategist::{ + TaskStrategist, TransactionStrategy, +}; +use magicblock_committor_service::tasks::tasks::{ + ArgsTask, BaseTask, BufferTask, CommitTask, FinalizeTask, L1ActionTask, + UndelegateTask, +}; use magicblock_committor_service::tasks::utils::TransactionUtils; use magicblock_committor_service::{ persist::IntentPersisterImpl, transaction_preparator::transaction_preparator::TransactionPreparator, }; use magicblock_program::magic_scheduled_base_intent::{ - BaseAction, - ProgramArgs, ShortAccountMeta, + BaseAction, ProgramArgs, ShortAccountMeta, }; use solana_pubkey::Pubkey; -use solana_sdk::{signer::Signer, system_program, }; -use magicblock_committor_program::Chunks; +use solana_sdk::{signer::Signer, system_program}; mod common; @@ -138,9 +142,16 @@ async fn test_prepare_commit_tx_with_multiple_accounts() { assert_eq!(actual_message, expected_message); // Now we verify that buffers were created - let preparation_info = buffer_commit_task.preparation_info(&fixture.authority.pubkey()).unwrap(); + let preparation_info = buffer_commit_task + .preparation_info(&fixture.authority.pubkey()) + .unwrap(); - let chunks_account = fixture.rpc_client.get_account(&preparation_info.chunks_pda).await.unwrap().unwrap(); + let chunks_account = fixture + .rpc_client + .get_account(&preparation_info.chunks_pda) + .await + .unwrap() + .unwrap(); let chunks = Chunks::try_from_slice(&chunks_account.data).unwrap(); assert!(chunks.is_complete()); @@ -182,8 +193,8 @@ async fn test_prepare_commit_tx_with_l1_actions() { // L1Action Box::new(ArgsTask::L1Action(L1ActionTask { context: Context::Commit, - action: base_action - })) + action: base_action, + })), ]; // Test preparation @@ -208,8 +219,8 @@ async fn test_prepare_commit_tx_with_l1_actions() { fixture.compute_budget_config.compute_unit_price, &[], ) - .unwrap() - .message; + .unwrap() + .message; // Block hash is random in result of prepare_for_strategy // should be set be caller, so here we just set value of expected for test @@ -217,9 +228,16 @@ async fn test_prepare_commit_tx_with_l1_actions() { assert_eq!(actual_message, expected_message); // Now we verify that buffers were created - let preparation_info = buffer_commit_task.preparation_info(&fixture.authority.pubkey()).unwrap(); + let preparation_info = buffer_commit_task + .preparation_info(&fixture.authority.pubkey()) + .unwrap(); - let chunks_account = fixture.rpc_client.get_account(&preparation_info.chunks_pda).await.unwrap().unwrap(); + let chunks_account = fixture + .rpc_client + .get_account(&preparation_info.chunks_pda) + .await + .unwrap() + .unwrap(); let chunks = Chunks::try_from_slice(&chunks_account.data).unwrap(); assert!(chunks.is_complete()); @@ -231,7 +249,7 @@ async fn test_prepare_finalize_tx_with_undelegate_with_atls() { let preparator = fixture.create_transaction_preparator(); // Create test data - let committed_account = create_committed_account(&[1,2,3]); + let committed_account = create_committed_account(&[1, 2, 3]); let tasks: Vec> = vec![ // finalize account Box::new(ArgsTask::Finalize(FinalizeTask { @@ -241,8 +259,8 @@ async fn test_prepare_finalize_tx_with_undelegate_with_atls() { Box::new(ArgsTask::Undelegate(UndelegateTask { delegated_account: committed_account.pubkey, owner_program: Pubkey::new_unique(), - rent_reimbursement: Pubkey::new_unique() - })) + rent_reimbursement: Pubkey::new_unique(), + })), ]; let lookup_tables_keys = TaskStrategist::collect_lookup_table_keys( From b2914581b88ba3465a9fea380e8f395bf254f2c6 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Wed, 20 Aug 2025 19:26:38 +0900 Subject: [PATCH 188/199] refactor: Error -> Error --- .../src/scheduled_commits_processor.rs | 2 +- .../src/intent_execution_manager.rs | 14 +- .../intent_execution_engine.rs | 32 ++-- .../src/intent_executor/error.rs | 27 +-- .../src/intent_executor/intent_executor.rs | 155 ++++++++++++------ .../src/intent_executor/task_info_fetcher.rs | 30 ++-- .../src/stubs/changeset_committor_stub.rs | 7 +- .../src/tasks/task_builder.rs | 20 +-- .../src/tasks/task_strategist.rs | 8 +- .../src/tasks/utils.rs | 4 +- .../src/transaction_preparator/error.rs | 12 +- 11 files changed, 192 insertions(+), 119 deletions(-) diff --git a/magicblock-accounts/src/scheduled_commits_processor.rs b/magicblock-accounts/src/scheduled_commits_processor.rs index 37a1922f4..ecdbd48b3 100644 --- a/magicblock-accounts/src/scheduled_commits_processor.rs +++ b/magicblock-accounts/src/scheduled_commits_processor.rs @@ -258,7 +258,7 @@ impl ScheduledCommitsProcessorImpl { } Err((_, _, err)) => { match err.as_ref() { - &magicblock_committor_service::intent_executor::error::Error::EmptyIntentError => { + &magicblock_committor_service::intent_executor::error::IntentExecutorError::EmptyIntentError => { warn!("Empty intent was scheduled!"); Self::process_empty_intent( intent_id, diff --git a/magicblock-committor-service/src/intent_execution_manager.rs b/magicblock-committor-service/src/intent_execution_manager.rs index 6b8ec5d1b..57b5f377a 100644 --- a/magicblock-committor-service/src/intent_execution_manager.rs +++ b/magicblock-committor-service/src/intent_execution_manager.rs @@ -72,7 +72,7 @@ impl IntentExecutionManager { pub async fn schedule( &self, base_intents: Vec, - ) -> Result<(), Error> { + ) -> Result<(), IntentExecutionManagerError> { // If db not empty push el-t there // This means that at some point channel got full // Worker first will clean-up channel, and then DB. @@ -90,10 +90,14 @@ impl IntentExecutionManager { }; match err { - TrySendError::Closed(_) => Err(Error::ChannelClosed), - TrySendError::Full(el) => { - self.db.store_base_intent(el).await.map_err(Error::from) + TrySendError::Closed(_) => { + Err(IntentExecutionManagerError::ChannelClosed) } + TrySendError::Full(el) => self + .db + .store_base_intent(el) + .await + .map_err(IntentExecutionManagerError::from), }?; } @@ -109,7 +113,7 @@ impl IntentExecutionManager { } #[derive(thiserror::Error, Debug)] -pub enum Error { +pub enum IntentExecutionManagerError { #[error("Channel was closed")] ChannelClosed, #[error("DBError: {0}")] diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index 6076fba02..79c0f7476 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -14,12 +14,12 @@ use crate::{ intent_execution_manager::{ db::DB, intent_scheduler::{IntentScheduler, POISONED_INNER_MSG}, - Error, + IntentExecutionManagerError, }, intent_executor::{ - error::IntentExecutorResult, - intent_executor_factory::IntentExecutorFactory, ExecutionOutput, - IntentExecutor, + error::{IntentExecutorError, IntentExecutorResult}, + intent_executor_factory::IntentExecutorFactory, + ExecutionOutput, IntentExecutor, }, persist::IntentPersister, types::{ScheduledBaseIntentWrapper, TriggerType}, @@ -36,8 +36,7 @@ pub struct ExecutionOutputWrapper { pub trigger_type: TriggerType, } -pub type BroadcastedError = - (u64, TriggerType, Arc); +pub type BroadcastedError = (u64, TriggerType, Arc); pub type BroadcastedIntentExecutionResult = IntentExecutorResult; @@ -110,11 +109,11 @@ where loop { let intent = match self.next_scheduled_intent().await { Ok(value) => value, - Err(Error::ChannelClosed) => { + Err(IntentExecutionManagerError::ChannelClosed) => { info!("Channel closed, exiting IntentExecutionEngine::main_loop"); break; } - Err(Error::DBError(err)) => { + Err(IntentExecutionManagerError::DBError(err)) => { panic!("Failed to fetch intent from db: {:?}", err); } }; @@ -155,7 +154,8 @@ where /// Returns [`ScheduledBaseIntentWrapper`] or None if all intents are blocked async fn next_scheduled_intent( &mut self, - ) -> Result, Error> { + ) -> Result, IntentExecutionManagerError> + { // Limit on number of intents that can be stored in scheduler const SCHEDULER_CAPACITY: usize = 1000; @@ -205,7 +205,7 @@ where async fn get_new_intent( receiver: &mut mpsc::Receiver, db: &Arc, - ) -> Result { + ) -> Result { match receiver.try_recv() { Ok(val) => Ok(val), Err(TryRecvError::Empty) => { @@ -214,10 +214,15 @@ where if let Some(base_intent) = db.pop_base_intent().await? { Ok(base_intent) } else { - receiver.recv().await.ok_or(Error::ChannelClosed) + receiver + .recv() + .await + .ok_or(IntentExecutionManagerError::ChannelClosed) } } - Err(TryRecvError::Disconnected) => Err(Error::ChannelClosed), + Err(TryRecvError::Disconnected) => { + Err(IntentExecutionManagerError::ChannelClosed) + } } } @@ -291,7 +296,8 @@ mod tests { }, intent_executor::{ error::{ - Error as ExecutorError, IntentExecutorResult, InternalError, + IntentExecutorError as ExecutorError, IntentExecutorResult, + InternalError, }, task_info_fetcher::{TaskInfoFetcher, TaskInfoFetcherResult}, }, diff --git a/magicblock-committor-service/src/intent_executor/error.rs b/magicblock-committor-service/src/intent_executor/error.rs index 5985cd1b0..7a40d4627 100644 --- a/magicblock-committor-service/src/intent_executor/error.rs +++ b/magicblock-committor-service/src/intent_executor/error.rs @@ -1,6 +1,13 @@ use magicblock_rpc_client::MagicBlockRpcClientError; use solana_sdk::signature::{Signature, SignerError}; +use crate::{ + tasks::{ + task_builder::TaskBuilderError, task_strategist::TaskStrategistError, + }, + transaction_preparator::error::TransactionPreparatorError, +}; + #[derive(thiserror::Error, Debug)] pub enum InternalError { #[error("SignerError: {0}")] @@ -10,14 +17,14 @@ pub enum InternalError { } #[derive(thiserror::Error, Debug)] -pub enum Error { +pub enum IntentExecutorError { #[error("EmptyIntentError")] EmptyIntentError, #[error("Failed to fit in single TX")] FailedToFitError, // TODO: remove once proper retries introduced #[error("TaskBuilderError: {0}")] - TaskBuilderError(#[from] crate::tasks::task_builder::Error), + TaskBuilderError(#[from] TaskBuilderError), #[error("FailedToCommitError: {err}")] FailedToCommitError { #[source] @@ -32,20 +39,16 @@ pub enum Error { finalize_signature: Option, }, #[error("FailedCommitPreparationError: {0}")] - FailedCommitPreparationError( - #[source] crate::transaction_preparator::error::Error, - ), + FailedCommitPreparationError(#[source] TransactionPreparatorError), #[error("FailedFinalizePreparationError: {0}")] - FailedFinalizePreparationError( - #[source] crate::transaction_preparator::error::Error, - ), + FailedFinalizePreparationError(#[source] TransactionPreparatorError), } -impl From for Error { - fn from(value: crate::tasks::task_strategist::Error) -> Self { - let crate::tasks::task_strategist::Error::FailedToFitError = value; +impl From for IntentExecutorError { + fn from(value: TaskStrategistError) -> Self { + let TaskStrategistError::FailedToFitError = value; Self::FailedToFitError } } -pub type IntentExecutorResult = Result; +pub type IntentExecutorResult = Result; diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index bbe602580..af57fe961 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -19,7 +19,7 @@ use solana_sdk::{ use crate::{ intent_executor::{ - error::{Error, IntentExecutorResult, InternalError}, + error::{IntentExecutorError, IntentExecutorResult, InternalError}, task_info_fetcher::TaskInfoFetcher, ExecutionOutput, IntentExecutor, }, @@ -29,7 +29,10 @@ use crate::{ task_strategist::{TaskStrategist, TransactionStrategy}, tasks::BaseTask, }, - transaction_preparator::transaction_preparator::TransactionPreparator, + transaction_preparator::{ + error::TransactionPreparatorError, + transaction_preparator::TransactionPreparator, + }, utils::persist_status_update_by_message_set, }; @@ -88,7 +91,7 @@ where match TaskStrategist::build_strategy(commit_tasks, authority, persister) { Ok(strategy) => Some(strategy), - Err(crate::tasks::task_strategist::Error::FailedToFitError) => None, + Err(crate::tasks::task_strategist::TaskStrategistError::FailedToFitError) => None, } } @@ -98,7 +101,7 @@ where persister: &Option

, ) -> IntentExecutorResult { if base_intent.is_empty() { - return Err(Error::EmptyIntentError); + return Err(IntentExecutorError::EmptyIntentError); } // Update tasks status to Pending @@ -176,14 +179,13 @@ where persister, ) .await - .map_err(Error::FailedFinalizePreparationError)?; + .map_err(IntentExecutorError::FailedFinalizePreparationError)?; let signature = self .send_prepared_message(prepared_message) .await - .map_err(|(err, signature)| Error::FailedToCommitError { - err, - signature, + .map_err(|(err, signature)| { + IntentExecutorError::FailedToCommitError { err, signature } })?; debug!("Single stage intent executed: {}", signature); @@ -202,14 +204,13 @@ where .transaction_preparator .prepare_for_strategy(&self.authority, commit_strategy, persister) .await - .map_err(Error::FailedCommitPreparationError)?; + .map_err(IntentExecutorError::FailedCommitPreparationError)?; let commit_signature = self .send_prepared_message(prepared_commit_message) .await - .map_err(|(err, signature)| Error::FailedToCommitError { - err, - signature, + .map_err(|(err, signature)| { + IntentExecutorError::FailedToCommitError { err, signature } })?; debug!("Commit stage succeeded: {}", commit_signature); @@ -218,13 +219,13 @@ where .transaction_preparator .prepare_for_strategy(&self.authority, finalize_strategy, persister) .await - .map_err(Error::FailedFinalizePreparationError)?; + .map_err(IntentExecutorError::FailedFinalizePreparationError)?; let finalize_signature = self .send_prepared_message(prepared_finalize_message) .await .map_err(|(err, finalize_signature)| { - Error::FailedToFinalizeError { + IntentExecutorError::FailedToFinalizeError { err, commit_signature: Some(commit_signature), finalize_signature, @@ -286,63 +287,113 @@ where match result { Ok(value) => { let signatures = match *value { - ExecutionOutput::SingleStage(signature) => CommitStatusSignatures { - commit_stage_signature: signature, - finalize_stage_signature: Some(signature) - }, + ExecutionOutput::SingleStage(signature) => { + CommitStatusSignatures { + commit_stage_signature: signature, + finalize_stage_signature: Some(signature), + } + } ExecutionOutput::TwoStage { - commit_signature, finalize_signature + commit_signature, + finalize_signature, } => CommitStatusSignatures { commit_stage_signature: commit_signature, - finalize_stage_signature: Some(finalize_signature) - } + finalize_stage_signature: Some(finalize_signature), + }, }; let update_status = CommitStatus::Succeeded(signatures); - persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); - - if let Err(err) = persistor.finalize_base_intent(message_id, *value) { + persist_status_update_by_message_set( + persistor, + message_id, + pubkeys, + update_status, + ); + + if let Err(err) = + persistor.finalize_base_intent(message_id, *value) + { error!("Failed to persist ExecutionOutput: {}", err); } - }, - Err(Error::EmptyIntentError) | Err(Error::FailedToFitError) => { + } + Err(IntentExecutorError::EmptyIntentError) + | Err(IntentExecutorError::FailedToFitError) => { let update_status = CommitStatus::Failed; - persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); + persist_status_update_by_message_set( + persistor, + message_id, + pubkeys, + update_status, + ); } - Err(Error::TaskBuilderError(_)) => { + Err(IntentExecutorError::TaskBuilderError(_)) => { let update_status = CommitStatus::Failed; - persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); + persist_status_update_by_message_set( + persistor, + message_id, + pubkeys, + update_status, + ); } - Err(Error::FailedCommitPreparationError(crate::transaction_preparator::error::Error::FailedToFitError)) => { + Err(IntentExecutorError::FailedCommitPreparationError( + TransactionPreparatorError::FailedToFitError, + )) => { let update_status = CommitStatus::PartOfTooLargeBundleToProcess; - persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); + persist_status_update_by_message_set( + persistor, + message_id, + pubkeys, + update_status, + ); } - Err(Error::FailedCommitPreparationError(crate::transaction_preparator::error::Error::DeliveryPreparationError(_))) => { + Err(IntentExecutorError::FailedCommitPreparationError( + TransactionPreparatorError::DeliveryPreparationError(_), + )) => { // Intermediate commit preparation progress recorded by DeliveryPreparator - }, - Err(Error::FailedToCommitError {err: _, signature}) => { + } + Err(IntentExecutorError::FailedToCommitError { + err: _, + signature, + }) => { // Commit is a single TX, so if it fails, all of commited accounts marked FailedProcess - let status_signature = signature.map(|sig| CommitStatusSignatures { - commit_stage_signature: sig, - finalize_stage_signature: None - }); - let update_status = CommitStatus::FailedProcess(status_signature); - persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); + let status_signature = + signature.map(|sig| CommitStatusSignatures { + commit_stage_signature: sig, + finalize_stage_signature: None, + }); + let update_status = + CommitStatus::FailedProcess(status_signature); + persist_status_update_by_message_set( + persistor, + message_id, + pubkeys, + update_status, + ); } - Err(Error::FailedFinalizePreparationError(_)) => { + Err(IntentExecutorError::FailedFinalizePreparationError(_)) => { // Not supported in persistor - }, - Err(Error::FailedToFinalizeError {err: _, commit_signature, finalize_signature}) => { + } + Err(IntentExecutorError::FailedToFinalizeError { + err: _, + commit_signature, + finalize_signature, + }) => { // Finalize is a single TX, so if it fails, all of commited accounts marked FailedFinalize - let update_status = if let Some(commit_signature) = commit_signature { - let signatures = CommitStatusSignatures { - commit_stage_signature: *commit_signature, - finalize_stage_signature: *finalize_signature + let update_status = + if let Some(commit_signature) = commit_signature { + let signatures = CommitStatusSignatures { + commit_stage_signature: *commit_signature, + finalize_stage_signature: *finalize_signature, + }; + CommitStatus::FailedFinalize(signatures) + } else { + CommitStatus::FailedProcess(None) }; - CommitStatus::FailedFinalize(signatures) - } else { - CommitStatus::FailedProcess(None) - }; - persist_status_update_by_message_set(persistor, message_id, pubkeys, update_status); + persist_status_update_by_message_set( + persistor, + message_id, + pubkeys, + update_status, + ); } } } diff --git a/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs b/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs index 0bf6117fe..83b5d34a5 100644 --- a/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs +++ b/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs @@ -60,15 +60,21 @@ impl CacheTaskInfoFetcher { return Ok(Vec::new()); } - let mut last_err = Error::MetadataNotFoundError(pubkeys[0]); + let mut last_err = + TaskInfoFetcherError::MetadataNotFoundError(pubkeys[0]); for i in 0..num_retries.get() { match Self::fetch_metadata(rpc_client, pubkeys).await { Ok(value) => return Ok(value), - err @ Err(Error::InvalidAccountDataError(_)) => return err, - err @ Err(Error::MetadataNotFoundError(_)) => return err, - Err(Error::MagicBlockRpcClientError(err)) => { + err @ Err(TaskInfoFetcherError::InvalidAccountDataError(_)) => { + return err + } + err @ Err(TaskInfoFetcherError::MetadataNotFoundError(_)) => { + return err + } + Err(TaskInfoFetcherError::MagicBlockRpcClientError(err)) => { // TODO: RPC error handlings should be more robust - last_err = Error::MagicBlockRpcClientError(err) + last_err = + TaskInfoFetcherError::MagicBlockRpcClientError(err) } }; @@ -114,17 +120,21 @@ impl CacheTaskInfoFetcher { let account = if let Some(account) = accounts_data.get(i) { account } else { - return Err(Error::MetadataNotFoundError(pda)); + return Err(TaskInfoFetcherError::MetadataNotFoundError( + pda, + )); }; let account = account .as_ref() - .ok_or(Error::MetadataNotFoundError(pda))?; + .ok_or(TaskInfoFetcherError::MetadataNotFoundError(pda))?; let metadata = DelegationMetadata::try_from_bytes_with_discriminator( &account.data, ) - .map_err(|_| Error::InvalidAccountDataError(pda))?; + .map_err(|_| { + TaskInfoFetcherError::InvalidAccountDataError(pda) + })?; Ok(metadata) }) @@ -233,7 +243,7 @@ impl TaskInfoFetcher for CacheTaskInfoFetcher { } #[derive(thiserror::Error, Debug)] -pub enum Error { +pub enum TaskInfoFetcherError { #[error("Metadata not found for: {0}")] MetadataNotFoundError(Pubkey), #[error("InvalidAccountDataError for: {0}")] @@ -242,4 +252,4 @@ pub enum Error { MagicBlockRpcClientError(#[from] MagicBlockRpcClientError), } -pub type TaskInfoFetcherResult = Result; +pub type TaskInfoFetcherResult = Result; diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index dd726488f..60137b570 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -11,7 +11,7 @@ use solana_transaction_status_client_types::{ EncodedConfirmedTransactionWithStatusMeta, EncodedTransaction, EncodedTransactionWithStatusMeta, }; -use tokio::sync::oneshot; +use tokio::sync::{broadcast, oneshot}; use tokio_util::sync::{CancellationToken, WaitForCancellationFutureOwned}; use crate::{ @@ -72,9 +72,8 @@ impl BaseIntentCommittor for ChangesetCommittorStub { fn subscribe_for_results( &self, - ) -> oneshot::Receiver< - tokio::sync::broadcast::Receiver, - > { + ) -> oneshot::Receiver> + { let (_, receiver) = oneshot::channel(); receiver } diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 9772c7e57..698cea478 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -10,7 +10,9 @@ use magicblock_program::magic_scheduled_base_intent::{ use solana_pubkey::Pubkey; use crate::{ - intent_executor::task_info_fetcher::TaskInfoFetcher, + intent_executor::task_info_fetcher::{ + TaskInfoFetcher, TaskInfoFetcherError, + }, persist::IntentPersister, tasks::tasks::{ ArgsTask, BaseTask, CommitTask, FinalizeTask, L1ActionTask, @@ -74,7 +76,7 @@ impl TasksBuilder for TaskBuilderV1 { let commit_ids = commit_id_fetcher .fetch_next_commit_ids(&committed_pubkeys) .await - .map_err(Error::CommitTasksBuildError)?; + .map_err(TaskBuilderError::CommitTasksBuildError)?; // Persist commit ids for commitees commit_ids @@ -167,7 +169,7 @@ impl TasksBuilder for TaskBuilderV1 { let rent_reimbursements = info_fetcher .fetch_rent_reimbursements(&pubkeys) .await - .map_err(Error::FinalizedTasksBuildError)?; + .map_err(TaskBuilderError::FinalizedTasksBuildError)?; tasks.extend(accounts.iter().zip(rent_reimbursements).map( |(account, rent_reimbursement)| { @@ -196,15 +198,11 @@ impl TasksBuilder for TaskBuilderV1 { } #[derive(thiserror::Error, Debug)] -pub enum Error { +pub enum TaskBuilderError { #[error("CommitIdFetchError: {0}")] - CommitTasksBuildError( - #[source] crate::intent_executor::task_info_fetcher::Error, - ), + CommitTasksBuildError(#[source] TaskInfoFetcherError), #[error("FinalizedTasksBuildError: {0}")] - FinalizedTasksBuildError( - #[source] crate::intent_executor::task_info_fetcher::Error, - ), + FinalizedTasksBuildError(#[source] TaskInfoFetcherError), } -pub type TaskBuilderResult = Result; +pub type TaskBuilderResult = Result; diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 2f857288e..f2ad2a4f2 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -71,7 +71,7 @@ impl TaskStrategist { lookup_tables_keys, }) } else { - Err(Error::FailedToFitError) + Err(TaskStrategistError::FailedToFitError) } } @@ -210,12 +210,12 @@ impl TaskStrategist { } #[derive(thiserror::Error, Debug)] -pub enum Error { +pub enum TaskStrategistError { #[error("Failed to fit in single TX")] FailedToFitError, } -pub type TaskStrategistResult = Result; +pub type TaskStrategistResult = Result; #[cfg(test)] mod tests { @@ -418,7 +418,7 @@ mod tests { &validator, &None::, ); - assert!(matches!(result, Err(Error::FailedToFitError))); + assert!(matches!(result, Err(TaskStrategistError::FailedToFitError))); } #[test] diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index 649d29a0b..cd9e82fa5 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -102,7 +102,7 @@ impl TransactionUtils { // This is needed because VersionedMessage::serialize uses unwrap() ¯\_(ツ)_/¯ instructions.iter().try_for_each(|el| { if el.data.len() > u16::MAX as usize { - Err(crate::tasks::task_strategist::Error::FailedToFitError) + Err(crate::tasks::task_strategist::TaskStrategistError::FailedToFitError) } else { Ok(()) } @@ -117,7 +117,7 @@ impl TransactionUtils { Ok(message) => Ok(message), Err(CompileError::AccountIndexOverflow) | Err(CompileError::AddressTableLookupIndexOverflow) => { - Err(crate::tasks::task_strategist::Error::FailedToFitError) + Err(crate::tasks::task_strategist::TaskStrategistError::FailedToFitError) } Err(CompileError::UnknownInstructionKey(pubkey)) => { // SAFETY: this may occur in utility AccountKeys::try_compile_instructions diff --git a/magicblock-committor-service/src/transaction_preparator/error.rs b/magicblock-committor-service/src/transaction_preparator/error.rs index 6ff3e2f7b..8359a9b83 100644 --- a/magicblock-committor-service/src/transaction_preparator/error.rs +++ b/magicblock-committor-service/src/transaction_preparator/error.rs @@ -1,7 +1,7 @@ use thiserror::Error; #[derive(Error, Debug)] -pub enum Error { +pub enum TransactionPreparatorError { #[error("Failed to fit in single TX")] FailedToFitError, #[error("DeliveryPreparationError: {0}")] @@ -10,14 +10,16 @@ pub enum Error { ), } -impl From for Error { - fn from(value: crate::tasks::task_strategist::Error) -> Self { +impl From + for TransactionPreparatorError +{ + fn from(value: crate::tasks::task_strategist::TaskStrategistError) -> Self { match value { - crate::tasks::task_strategist::Error::FailedToFitError => { + crate::tasks::task_strategist::TaskStrategistError::FailedToFitError => { Self::FailedToFitError } } } } -pub type PreparatorResult = Result; +pub type PreparatorResult = Result; From 99ea5c8488f7a0159529120ca3810bc0b7cd3b4d Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 21 Aug 2025 19:22:44 +0900 Subject: [PATCH 189/199] refactor: some comments addressed feat: added redelegation logic, which isn't supported for now :( --- magicblock-api/src/tickers.rs | 35 +++--- .../intent_execution_engine.rs | 3 +- .../schedule_base_intent_processor.rs | 8 +- .../programs/flexi-counter/src/args.rs | 19 ++++ .../programs/flexi-counter/src/instruction.rs | 45 ++++++++ .../programs/flexi-counter/src/processor.rs | 5 + .../src/processor/call_handler.rs | 100 +++++++++++++++++- .../src/processor/schedule_intent.rs | 16 ++- .../processor/schedule_redelegation_intent.rs | 73 +++++++++++++ .../tests/test_ix_commit_local.rs | 33 +++--- .../tests/test_schedule_intents.rs | 85 +++++++++++++-- 11 files changed, 365 insertions(+), 57 deletions(-) create mode 100644 test-integration/programs/flexi-counter/src/processor/schedule_redelegation_intent.rs diff --git a/magicblock-api/src/tickers.rs b/magicblock-api/src/tickers.rs index 3b339b2cf..e235bf8a4 100644 --- a/magicblock-api/src/tickers.rs +++ b/magicblock-api/src/tickers.rs @@ -42,27 +42,28 @@ pub fn init_slot_ticker( error!("Failed to write block: {:?}", err); } - // Handle intents if such feature enabled - if let Some(committor_processor) = &committor_processor { - // If accounts were scheduled to be committed, we accept them here - // and processs the commits - let magic_context_acc = bank.get_account(&magic_program::MAGIC_CONTEXT_PUBKEY) - .expect("Validator found to be running without MagicContext account!"); - if MagicContext::has_scheduled_commits(magic_context_acc.data()) - { - handle_scheduled_commits( - &bank, - committor_processor, - &transaction_status_sender, - ) - .await; - } - } - if log { info!("Advanced to slot {}", next_slot); } metrics::inc_slot(); + + // Handle intents if such feature enabled + let Some(committor_processor) = &committor_processor else { + continue; + }; + + // If accounts were scheduled to be committed, we accept them here + // and processs the commits + let magic_context_acc = bank.get_account(&magic_program::MAGIC_CONTEXT_PUBKEY) + .expect("Validator found to be running without MagicContext account!"); + if MagicContext::has_scheduled_commits(magic_context_acc.data()) { + handle_scheduled_commits( + &bank, + committor_processor, + &transaction_status_sender, + ) + .await; + } } }) } diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index 79c0f7476..471b26510 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -114,7 +114,8 @@ where break; } Err(IntentExecutionManagerError::DBError(err)) => { - panic!("Failed to fetch intent from db: {:?}", err); + error!("Failed to fetch intent from db: {:?}", err); + break; } }; let Some(intent) = intent else { diff --git a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs index a669de20c..f532fa77a 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs @@ -11,12 +11,8 @@ pub fn change_owner_for_undelegated_accounts( args: &MagicBaseIntentArgs, ) -> Result<(), InstructionError> { let commited_accounts_ref = match args { - MagicBaseIntentArgs::Commit(commit_type) => { - let accounts_indices = commit_type.committed_accounts_indices(); - CommitType::extract_commit_accounts( - accounts_indices, - construction_context.transaction_context, - )? + MagicBaseIntentArgs::Commit(_) => { + return Ok(()); } MagicBaseIntentArgs::CommitAndUndelegate( commit_and_undelegate_type, diff --git a/test-integration/programs/flexi-counter/src/args.rs b/test-integration/programs/flexi-counter/src/args.rs index ff239c410..eaa1b1470 100644 --- a/test-integration/programs/flexi-counter/src/args.rs +++ b/test-integration/programs/flexi-counter/src/args.rs @@ -10,3 +10,22 @@ pub struct UndelegateActionData { pub counter_diff: i64, pub transfer_amount: u64, } + +pub enum CallHandlerDiscriminator { + Simple = 0, + // On post-undelegation we delegate account back + ReDelegate = 1, +} + +impl CallHandlerDiscriminator { + pub fn to_array(&self) -> [u8; 4] { + match self { + Self::Simple => [0, 0, 0, 0], + Self::ReDelegate => [0, 0, 0, 1], + } + } + + pub fn to_vec(&self) -> Vec { + self.to_array().to_vec() + } +} diff --git a/test-integration/programs/flexi-counter/src/instruction.rs b/test-integration/programs/flexi-counter/src/instruction.rs index b969ccdbd..d0fdc5bfc 100644 --- a/test-integration/programs/flexi-counter/src/instruction.rs +++ b/test-integration/programs/flexi-counter/src/instruction.rs @@ -118,6 +118,23 @@ pub enum FlexiCounterInstruction { is_undelegate: bool, compute_units: u32, }, + + /// Creates intent that will undelegate an account, + /// and delegate is back in an Action + /// NOTE: This will be abled in the future and left as an example for now + /// + /// Accounts: + /// 0. `[signer]` The payer that is delegating the account. Escrow authority + /// 1. `[write]` The counter PDA account that will be delegated. + /// 2. `[]` The owner program of the delegated account + /// 3. `[write]` The buffer account of the delegated account + /// 4. `[write]` The delegation record account of the delegated account + /// 5. `[write]` The delegation metadata account of the delegated account + /// 6. `[]` The delegation program + /// 7. `[]` The system program + /// 8. `[write]` The Magic Context + /// 9. `[]` The Magic Program + CreateRedelegationIntont, } pub fn create_init_ix(payer: Pubkey, label: String) -> Instruction { @@ -316,3 +333,31 @@ pub fn create_intent_ix( accounts, ) } + +pub fn create_redelegation_intent_ix(payer: Pubkey) -> Instruction { + let program_id = &crate::id(); + let (pda, _) = FlexiCounter::pda(&payer); + + let delegate_accounts = DelegateAccounts::new(pda, *program_id); + // NOTE: accounts like: buffer, delegation_record & delegation_metadata can't be writable + // The reason is - ER accepts only delegated account as writable + // There will be a functionality in sdk that will allow to specify overwrites for Base Layer execution + let account_metas = vec![ + AccountMeta::new(payer, true), + AccountMeta::new(delegate_accounts.delegated_account, false), + AccountMeta::new_readonly(delegate_accounts.owner_program, false), + AccountMeta::new_readonly(delegate_accounts.delegate_buffer, false), + AccountMeta::new_readonly(delegate_accounts.delegation_record, false), + AccountMeta::new_readonly(delegate_accounts.delegation_metadata, false), + AccountMeta::new_readonly(delegate_accounts.delegation_program, false), + AccountMeta::new_readonly(delegate_accounts.system_program, false), + AccountMeta::new(MAGIC_CONTEXT_ID, false), + AccountMeta::new_readonly(MAGIC_PROGRAM_ID, false), + ]; + + Instruction::new_with_borsh( + *program_id, + &FlexiCounterInstruction::CreateRedelegationIntont, + account_metas, + ) +} diff --git a/test-integration/programs/flexi-counter/src/processor.rs b/test-integration/programs/flexi-counter/src/processor.rs index a0e2bb045..77f914947 100644 --- a/test-integration/programs/flexi-counter/src/processor.rs +++ b/test-integration/programs/flexi-counter/src/processor.rs @@ -1,5 +1,6 @@ mod call_handler; mod schedule_intent; +mod schedule_redelegation_intent; use borsh::{to_vec, BorshDeserialize}; use ephemeral_rollups_sdk::consts::EXTERNAL_CALL_HANDLER_DISCRIMINATOR; @@ -24,6 +25,7 @@ use solana_program::{ use crate::instruction::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE; use crate::processor::call_handler::process_call_handler; use crate::processor::schedule_intent::process_create_intent; +use crate::processor::schedule_redelegation_intent::process_create_redelegation_intent; use crate::{ instruction::{DelegateArgs, FlexiCounterInstruction}, state::FlexiCounter, @@ -76,6 +78,9 @@ pub fn process( is_undelegate, compute_units, ), + CreateRedelegationIntont => { + process_create_redelegation_intent(accounts) + } }?; Ok(()) } diff --git a/test-integration/programs/flexi-counter/src/processor/call_handler.rs b/test-integration/programs/flexi-counter/src/processor/call_handler.rs index b02d6282f..aca3667dc 100644 --- a/test-integration/programs/flexi-counter/src/processor/call_handler.rs +++ b/test-integration/programs/flexi-counter/src/processor/call_handler.rs @@ -1,6 +1,11 @@ -use crate::args::{CommitActionData, UndelegateActionData}; +use crate::args::{ + CallHandlerDiscriminator, CommitActionData, UndelegateActionData, +}; use crate::state::FlexiCounter; use borsh::{to_vec, BorshDeserialize}; +use ephemeral_rollups_sdk::cpi::{ + delegate_account, DelegateAccounts, DelegateConfig, +}; use ephemeral_rollups_sdk::pda::ephemeral_balance_pda_from_payer; use ephemeral_rollups_sdk::{CallHandlerArgs, Context}; use solana_program::account_info::{next_account_info, AccountInfo}; @@ -9,17 +14,53 @@ use solana_program::msg; use solana_program::program::invoke; use solana_program::program_error::ProgramError; use solana_program::system_instruction::transfer; +use std::slice::Iter; pub fn process_call_handler( accounts: &[AccountInfo], call_data: &[u8], ) -> ProgramResult { msg!("Call handler"); - let account_info_iter = &mut accounts.iter(); - let escrow_authority = next_account_info(account_info_iter)?; - let escrow_account = next_account_info(account_info_iter)?; - let call_handler = CallHandlerArgs::try_from_slice(call_data)?; + let mut account_info_iter = accounts.iter(); + let escrow_authority = next_account_info(&mut account_info_iter)?; + let escrow_account = next_account_info(&mut account_info_iter)?; + + let mut call_handler = CallHandlerArgs::try_from_slice(call_data)?; + let discriminator = &call_handler.data.as_slice()[0..4]; + if discriminator == &CallHandlerDiscriminator::Simple.to_array() { + call_handler.data.drain(0..4); + process_simple_call_handler( + escrow_authority, + escrow_account, + account_info_iter, + &call_handler, + ) + } else if discriminator == &CallHandlerDiscriminator::ReDelegate.to_array() + { + call_handler.data.drain(0..4); + process_redelegation_call_handler( + escrow_authority, + escrow_account, + account_info_iter, + &call_handler, + ) + } else { + Err(ProgramError::InvalidArgument) + } +} + +fn process_simple_call_handler<'a, 'b>( + escrow_authority: &AccountInfo<'a>, + escrow_account: &AccountInfo<'a>, + mut account_info_iter: Iter<'b, AccountInfo<'a>>, + call_handler: &CallHandlerArgs, +) -> ProgramResult +where + 'a: 'b, +{ + msg!("Simple call handler"); + let expected_escrow = ephemeral_balance_pda_from_payer( escrow_authority.key, call_handler.escrow_index, @@ -33,6 +74,7 @@ pub fn process_call_handler( return Err(ProgramError::MissingRequiredSignature); } + let account_info_iter = &mut account_info_iter; let delegated_account = next_account_info(account_info_iter)?; let transfer_destination = next_account_info(account_info_iter)?; let system_program = next_account_info(account_info_iter)?; @@ -101,3 +143,51 @@ pub fn process_call_handler( } } } + +fn process_redelegation_call_handler<'a, 'b>( + escrow_authority: &AccountInfo<'a>, + escrow: &AccountInfo<'a>, + mut account_info_iter: Iter<'b, AccountInfo<'a>>, + call_handler: &CallHandlerArgs, +) -> ProgramResult +where + 'a: 'b, +{ + msg!("Redelegation call handler"); + + let account_info_iter = &mut account_info_iter; + let delegated_account = next_account_info(account_info_iter)?; + let destination_program = next_account_info(account_info_iter)?; + let delegated_buffer = next_account_info(account_info_iter)?; + let delegation_record = next_account_info(account_info_iter)?; + let delegation_metadata = next_account_info(account_info_iter)?; + let delegation_program = next_account_info(account_info_iter)?; + let system_program = next_account_info(account_info_iter)?; + + let Context::Undelegate = call_handler.context else { + return Err(ProgramError::InvalidArgument); + }; + + // In our case escrow authority is creator, this could be handled in many other way + let seeds_no_bump = FlexiCounter::seeds(escrow_authority.key); + delegate_account( + DelegateAccounts { + payer: escrow, + pda: delegated_account, + owner_program: destination_program, + buffer: delegated_buffer, + delegation_record, + delegation_metadata, + delegation_program, + system_program, + }, + &seeds_no_bump, + // Could be passed in CallHandlerArgs::data + DelegateConfig { + commit_frequency_ms: 1000, + validator: None, + }, + )?; + + Ok(()) +} diff --git a/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs b/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs index a4467b062..ec1169b01 100644 --- a/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs +++ b/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs @@ -1,4 +1,6 @@ -use crate::args::{CommitActionData, UndelegateActionData}; +use crate::args::{ + CallHandlerDiscriminator, CommitActionData, UndelegateActionData, +}; use borsh::to_vec; use ephemeral_rollups_sdk::ephem::{ CallHandler, CommitAndUndelegate, CommitType, MagicAction, @@ -67,7 +69,11 @@ pub fn process_create_intent( CallHandler { args: ActionArgs { - data: commit_action_data.clone(), + data: [ + CallHandlerDiscriminator::Simple.to_vec(), + commit_action_data.clone(), + ] + .concat(), escrow_index: ACTOR_ESCROW_INDEX, }, compute_untis: compute_units, @@ -102,7 +108,11 @@ pub fn process_create_intent( Ok(CallHandler { args: ActionArgs { - data: to_vec(&undelegate_action_data)?, + data: [ + CallHandlerDiscriminator::Simple.to_vec(), + to_vec(&undelegate_action_data)?, + ] + .concat(), escrow_index: ACTOR_ESCROW_INDEX, }, compute_untis: compute_units, diff --git a/test-integration/programs/flexi-counter/src/processor/schedule_redelegation_intent.rs b/test-integration/programs/flexi-counter/src/processor/schedule_redelegation_intent.rs new file mode 100644 index 000000000..57e4ce63b --- /dev/null +++ b/test-integration/programs/flexi-counter/src/processor/schedule_redelegation_intent.rs @@ -0,0 +1,73 @@ +use crate::args::CallHandlerDiscriminator; +use ephemeral_rollups_sdk::ephem::{ + CallHandler, CommitAndUndelegate, CommitType, MagicAction, + MagicInstructionBuilder, UndelegateType, +}; +use ephemeral_rollups_sdk::ActionArgs; +use solana_program::account_info::{next_account_info, AccountInfo}; +use solana_program::entrypoint::ProgramResult; +use solana_program::msg; + +pub const ACTOR_ESCROW_INDEX: u8 = 1; + +/// Can't be used as for now. Awaiting PR with custom AccountMeta overwrites +pub fn process_create_redelegation_intent( + accounts: &[AccountInfo], +) -> ProgramResult { + msg!("Creating redelegation intent"); + + let account_info_iter = &mut accounts.iter(); + // Accounts for redelegation + let escrow_authority = next_account_info(account_info_iter)?; + let delegated_account = next_account_info(account_info_iter)?; + let destination_program = next_account_info(account_info_iter)?; + let delegated_buffer = next_account_info(account_info_iter)?; + let delegation_record = next_account_info(account_info_iter)?; + let delegation_metadata = next_account_info(account_info_iter)?; + let delegation_program = next_account_info(account_info_iter)?; + let system_program = next_account_info(account_info_iter)?; + + // Our special accounts + let magic_context = next_account_info(account_info_iter)?; + let magic_program = next_account_info(account_info_iter)?; + + // Set proper writable data + let other_accounts = vec![ + // Undelegated account at that point + delegated_account.clone(), + // Payer is escrow an included by dlp::call_handler + // .. , + // Owner + destination_program.clone(), + // records and such + delegated_buffer.clone(), + delegation_record.clone(), + delegation_metadata.clone(), + delegation_program.clone(), + system_program.clone(), + ]; + + let call_handler = CallHandler { + args: ActionArgs { + data: [CallHandlerDiscriminator::ReDelegate.to_vec()].concat(), + escrow_index: ACTOR_ESCROW_INDEX, + }, + compute_untis: 150_000, + escrow_authority: escrow_authority.clone(), + destination_program: destination_program.clone(), + accounts: other_accounts, + }; + + let magic_action = MagicAction::CommitAndUndelegate(CommitAndUndelegate { + commit_type: CommitType::Standalone(vec![delegated_account.clone()]), + undelegate_type: UndelegateType::WithHandler(vec![call_handler]), + }); + + MagicInstructionBuilder { + payer: escrow_authority.clone(), + magic_context: magic_context.clone(), + magic_program: magic_program.clone(), + magic_action, + } + .build_and_invoke() +} diff --git a/test-integration/test-committor-service/tests/test_ix_commit_local.rs b/test-integration/test-committor-service/tests/test_ix_commit_local.rs index 089d09e3b..831121ec6 100644 --- a/test-integration/test-committor-service/tests/test_ix_commit_local.rs +++ b/test-integration/test-committor-service/tests/test_ix_commit_local.rs @@ -434,7 +434,7 @@ async fn test_commit_5_accounts_1kb_bundle_size_3() { expect_strategies(&[(CommitStrategy::FromBuffer, 5)]), false, ) - .await; + .await; } #[tokio::test] @@ -444,11 +444,11 @@ async fn test_commit_5_accounts_1kb_bundle_size_3_undelegate_all() { expect_strategies(&[ // Intent fits in 1 TX only with ALT, see IntentExecutorImpl::try_unite_tasks (CommitStrategy::FromBufferWithLookupTable, 3), - (CommitStrategy::FromBuffer, 2) + (CommitStrategy::FromBuffer, 2), ]), true, ) - .await; + .await; } #[tokio::test] @@ -461,7 +461,7 @@ async fn test_commit_5_accounts_1kb_bundle_size_4() { ]), false, ) - .await; + .await; } #[tokio::test] @@ -474,20 +474,17 @@ async fn test_commit_5_accounts_1kb_bundle_size_4_undelegate_all() { ]), true, ) - .await; + .await; } - #[tokio::test] async fn test_commit_5_accounts_1kb_bundle_size_5_undelegate_all() { commit_5_accounts_1kb( 5, - expect_strategies(&[ - (CommitStrategy::FromBufferWithLookupTable, 5), - ]), + expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 5)]), true, ) - .await; + .await; } #[tokio::test] @@ -496,7 +493,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_3() { 3, expect_strategies(&[(CommitStrategy::FromBuffer, 20)]), ) - .await; + .await; } #[tokio::test] @@ -505,7 +502,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_4() { 4, expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]), ) - .await; + .await; } #[tokio::test] @@ -518,18 +515,16 @@ async fn test_commit_20_accounts_1kb_bundle_size_6() { (CommitStrategy::FromBuffer, 2), ]), ) - .await; + .await; } #[tokio::test] async fn test_commit_20_accounts_1kb_bundle_size_20() { commit_20_accounts_1kb( 20, - expect_strategies(&[ - (CommitStrategy::FromBufferWithLookupTable, 20), - ]), + expect_strategies(&[(CommitStrategy::FromBufferWithLookupTable, 20)]), ) - .await; + .await; } #[tokio::test] @@ -542,7 +537,7 @@ async fn test_commit_8_accounts_1kb_bundle_size_8() { (CommitStrategy::FromBufferWithLookupTable, 8), ]), ) - .await; + .await; } #[tokio::test] @@ -555,7 +550,7 @@ async fn test_commit_20_accounts_1kb_bundle_size_8() { (CommitStrategy::FromBufferWithLookupTable, 20), ]), ) - .await; + .await; } async fn commit_5_accounts_1kb( diff --git a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs index 8059dcf84..d66d9b7d8 100644 --- a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs +++ b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs @@ -3,6 +3,7 @@ use integration_test_tools::IntegrationTestContext; use program_flexi_counter::delegation_program_id; use program_flexi_counter::instruction::{ create_add_ix, create_delegate_ix, create_init_ix, create_intent_ix, + create_redelegation_intent_ix, }; use program_flexi_counter::state::FlexiCounter; use solana_rpc_client_api::config::RpcSendTransactionConfig; @@ -14,9 +15,8 @@ use solana_sdk::signer::Signer; use solana_sdk::transaction::Transaction; use std::time::Duration; -const LABEL: &str = "I am label"; +const LABEL: &str = "I am a label"; -#[ignore] #[test] fn test_schedule_intent() { // Init context @@ -28,6 +28,41 @@ fn test_schedule_intent() { // Delegate counter delegate_counter(&ctx, &payer); add_to_counter(&ctx, &payer, 101); + schedule_intent( + &ctx, + &[&payer], + vec![-100], + false, + Some(Duration::from_secs(10)), + ); +} + +#[test] +fn test_schedule_intent_and_undelegate() { + // Init context + let ctx = IntegrationTestContext::try_new().unwrap(); + let payer = setup_payer(&ctx); + + // Init counter + init_counter(&ctx, &payer); + // Delegate counter + delegate_counter(&ctx, &payer); + add_to_counter(&ctx, &payer, 101); + schedule_intent(&ctx, &[&payer], vec![-100], true, None); +} + +#[test] +fn test_schedule_intent_2_commits() { + // Init context + let ctx = IntegrationTestContext::try_new().unwrap(); + let payer = setup_payer(&ctx); + + // Init counter + init_counter(&ctx, &payer); + // Delegate counter + delegate_counter(&ctx, &payer); + add_to_counter(&ctx, &payer, 101); + schedule_intent(&ctx, &[&payer], vec![-100], false, None); schedule_intent(&ctx, &[&payer], vec![-100], false, None); } @@ -57,7 +92,6 @@ fn test_3_payers_intent_with_undelegation() { ); } -#[ignore] #[test] fn test_5_payers_intent_only_commit() { const PAYERS: usize = 5; @@ -74,17 +108,32 @@ fn test_5_payers_intent_only_commit() { add_to_counter(&ctx, &payer, values[i]); }); - let counter_diffs: [i64; PAYERS] = [0; PAYERS]; + let counter_diffs: [i64; PAYERS] = [-2; PAYERS]; // Schedule intent affecting all counters schedule_intent( &ctx, payers.iter().collect::>().as_slice(), - counter_diffs.to_vec(), // not used + counter_diffs.to_vec(), true, - Some(Duration::from_secs(25)), + Some(Duration::from_secs(20)), ); } +#[ignore = "Will be enabled once MagicProgram support overrides of AccountMeta. Followup PR"] +#[test] +fn test_redelegation_intent() { + // Init context + let ctx = IntegrationTestContext::try_new().unwrap(); + let payer = setup_payer(&ctx); + + // Init counter + init_counter(&ctx, &payer); + // Delegate counter + delegate_counter(&ctx, &payer); + add_to_counter(&ctx, &payer, 101); + redelegate_intent(&ctx, &payer); +} + fn setup_payer(ctx: &IntegrationTestContext) -> Keypair { let payer = Keypair::new(); ctx.airdrop_chain(&payer.pubkey(), LAMPORTS_PER_SOL) @@ -218,6 +267,7 @@ fn schedule_intent( ) .unwrap(); + println!("sigtrtr: {}", sig); // In some cases it takes longer for tx to make it to baselayer // we need an additional wait time if let Some(confirmation_wait) = confirmation_wait { @@ -274,3 +324,26 @@ fn schedule_intent( mutiplier * payers.len() as u64 * 1_000_000 ); } + +fn redelegate_intent(ctx: &IntegrationTestContext, payer: &Keypair) { + ctx.wait_for_next_slot_ephem().unwrap(); + + let (pda, _) = FlexiCounter::pda(&payer.pubkey()); + let ix = create_redelegation_intent_ix(payer.pubkey()); + let (sig, confirmed) = ctx + .send_and_confirm_instructions_with_payer_ephem(&[ix], payer) + .unwrap(); + assert!(confirmed); + + // Confirm was sent on Base Layer + let commit_result = ctx + .fetch_schedule_commit_result::(sig) + .unwrap(); + commit_result + .confirm_commit_transactions_on_chain(&ctx) + .unwrap(); + + // Confirm that it got delegated back + let owner = ctx.fetch_chain_account_owner(pda).unwrap(); + assert_eq!(owner, dlp::id()); +} From e730924edd30643cfa3ca9c153397dd96a30427e Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 21 Aug 2025 19:23:07 +0900 Subject: [PATCH 190/199] feat: architecture doc of Intent execution flow --- magicblock-committor-service/README.md | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 magicblock-committor-service/README.md diff --git a/magicblock-committor-service/README.md b/magicblock-committor-service/README.md new file mode 100644 index 000000000..2a5dbe7e2 --- /dev/null +++ b/magicblock-committor-service/README.md @@ -0,0 +1,47 @@ +# Architecture of Intent Execution +Here the flow of Intent Execution is explained. After its creation by User it +makes it to CommittorService. The main responsibility of CommittorService - execution of Intents. + + +Due to blocking nature of intents, where one intent can block execution of another, +we introduce **Schedulers** + +## Schedulers +We can't directly spawn a bunch of **IntentExecutor**s. The reason is that one message can block execution of another message. To handle this the messages have to go through Scheduling. + +Details: Once message make it to `CommittorProcessor::schedule_base_intents` it outsources intent to tokio task `IntentExecutionEngine` which figures out a scheduling. + +## IntentExecutionEngine +Accepts new messages, schedules them, and spawns up to `MAX_EXECUTORS`(50) parallel **IntentExecutor**s for each Intent. Once a particular **IntentExecutor** finishes execution we broadcast result to subscribers, like: `RemoteScheduledCommitsProcessor` or `ExternalAccountsManager` + +Details: For scheduling logic see **IntentScheduler**. Number of parallel **IntentExecutor** is controller by Semaphore. + +## IntentExecutor +IntentExecutor - responsible for execution of Intent. Calls **TransactionPreparator** and then executes a transaction returning as result necessary signatures + +## TransactionPreparator +TransactionPreparator - is an entity that handles all of the above "Transaction preparation" calling **TaskBuilderV1**, **TaskStrategist**, **DeliveryPreparator** and then assempling it all and passing to **MessageExecutor** + +## DeliveryPreparator +After our **L1Task**s are ready we need to prepare eveything for their successful execution. **DeliveryPreparator** - handles ALTs and commit buffers + +## TaskBuilder +First, lets build atomic tasks from scheduled message/intent. + +High level: TaskBuilder responsible for creating L1Tasks(to be renamed...) from ScheduledL1Message(to be renamed...). +Details: To do that is requires additional information from DelegationMetadata, it is provided **CommitIdFetcher** + +### BaseTask +High level: BaseTask - is an atomic operation that is to be performed on the Base layer, like: Commit, Undelegate, Finalize, Action. + +Details: There's to implementation of BaseTask: ArgsTask, BufferTask. ArgsTask - gives instruction using args. BufferTask - gives instruction using buffer. BufferTask at the moment supports only commits + +### TaskInfoFetcher +High level: for account to be accepted by `dlp` it needs to have incremental commit ids. TaskInfoFetcher provides a user with the correct ids/nonces for set of committees + +Details: CacheTaskInfoFetcher - implementation of TaskInfoFetcher, that caches and locally increments commit ids using LruCache + +## TaskStrategist +After our tasks were built with **TaskBuilder**, they need to be optimized to fit into transaction. That what TaskStrategist does. + +Details: Initially **TaskBuilder** builds ArgsTasks, **TaskStrategist** if needed optimzes them to BufferTask. From 8c72b1fd907f3e2843580aa8419cc529372904e4 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 26 Aug 2025 15:10:11 +0900 Subject: [PATCH 191/199] feat: introduce SignerError handling --- .../src/intent_executor/error.rs | 8 +- .../src/intent_executor/intent_executor.rs | 91 ++++++++----------- .../src/tasks/task_strategist.rs | 27 ++++-- .../src/tasks/utils.rs | 3 +- .../src/transaction_preparator/error.rs | 16 ++-- 5 files changed, 74 insertions(+), 71 deletions(-) diff --git a/magicblock-committor-service/src/intent_executor/error.rs b/magicblock-committor-service/src/intent_executor/error.rs index 7a40d4627..bb472203c 100644 --- a/magicblock-committor-service/src/intent_executor/error.rs +++ b/magicblock-committor-service/src/intent_executor/error.rs @@ -22,6 +22,8 @@ pub enum IntentExecutorError { EmptyIntentError, #[error("Failed to fit in single TX")] FailedToFitError, + #[error("SignerError: {0}")] + SignerError(#[from] SignerError), // TODO: remove once proper retries introduced #[error("TaskBuilderError: {0}")] TaskBuilderError(#[from] TaskBuilderError), @@ -46,8 +48,10 @@ pub enum IntentExecutorError { impl From for IntentExecutorError { fn from(value: TaskStrategistError) -> Self { - let TaskStrategistError::FailedToFitError = value; - Self::FailedToFitError + match value { + TaskStrategistError::FailedToFitError => Self::FailedToFitError, + TaskStrategistError::SignerError(err) => Self::SignerError(err), + } } } diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index af57fe961..9d7011888 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -13,7 +13,7 @@ use solana_pubkey::Pubkey; use solana_sdk::{ message::VersionedMessage, signature::{Keypair, Signature}, - signer::Signer, + signer::{Signer, SignerError}, transaction::VersionedTransaction, }; @@ -26,7 +26,9 @@ use crate::{ persist::{CommitStatus, CommitStatusSignatures, IntentPersister}, tasks::{ task_builder::{TaskBuilderV1, TasksBuilder}, - task_strategist::{TaskStrategist, TransactionStrategy}, + task_strategist::{ + TaskStrategist, TaskStrategistError, TransactionStrategy, + }, tasks::BaseTask, }, transaction_preparator::{ @@ -69,7 +71,7 @@ where finalize_task: &[Box], authority: &Pubkey, persister: &Option

, - ) -> Option { + ) -> Result, SignerError> { const MAX_UNITED_TASKS_LEN: usize = 22; // We can unite in 1 tx a lot of commits @@ -79,7 +81,7 @@ where // In case this fails as well, it will be retried with TwoStage approach // on retry, once retries are introduced if commit_tasks.len() + finalize_task.len() > MAX_UNITED_TASKS_LEN { - return None; + return Ok(None); } // Clone tasks since strategies applied to united case maybe suboptimal for regular one @@ -90,8 +92,9 @@ where commit_tasks.extend(finalize_task); match TaskStrategist::build_strategy(commit_tasks, authority, persister) { - Ok(strategy) => Some(strategy), - Err(crate::tasks::task_strategist::TaskStrategistError::FailedToFitError) => None, + Ok(strategy) => Ok(Some(strategy)), + Err(TaskStrategistError::FailedToFitError) => Ok(None), + Err(TaskStrategistError::SignerError(err)) => Err(err), } } @@ -134,7 +137,7 @@ where &finalize_tasks, &self.authority.pubkey(), persister, - ) { + )? { debug!("Executing intent in single stage"); self.execute_single_stage(&single_tx_strategy, persister) .await @@ -284,7 +287,7 @@ where message_id: u64, pubkeys: &[Pubkey], ) { - match result { + let update_status = match result { Ok(value) => { let signatures = match *value { ExecutionOutput::SingleStage(signature) => { @@ -314,41 +317,26 @@ where { error!("Failed to persist ExecutionOutput: {}", err); } + + return; } Err(IntentExecutorError::EmptyIntentError) - | Err(IntentExecutorError::FailedToFitError) => { - let update_status = CommitStatus::Failed; - persist_status_update_by_message_set( - persistor, - message_id, - pubkeys, - update_status, - ); - } - Err(IntentExecutorError::TaskBuilderError(_)) => { - let update_status = CommitStatus::Failed; - persist_status_update_by_message_set( - persistor, - message_id, - pubkeys, - update_status, - ); - } + | Err(IntentExecutorError::FailedToFitError) + | Err(IntentExecutorError::TaskBuilderError(_)) + | Err(IntentExecutorError::FailedCommitPreparationError( + TransactionPreparatorError::SignerError(_), + )) + | Err(IntentExecutorError::FailedFinalizePreparationError( + TransactionPreparatorError::SignerError(_), + )) => Some(CommitStatus::Failed), Err(IntentExecutorError::FailedCommitPreparationError( TransactionPreparatorError::FailedToFitError, - )) => { - let update_status = CommitStatus::PartOfTooLargeBundleToProcess; - persist_status_update_by_message_set( - persistor, - message_id, - pubkeys, - update_status, - ); - } + )) => Some(CommitStatus::PartOfTooLargeBundleToProcess), Err(IntentExecutorError::FailedCommitPreparationError( TransactionPreparatorError::DeliveryPreparationError(_), )) => { // Intermediate commit preparation progress recorded by DeliveryPreparator + None } Err(IntentExecutorError::FailedToCommitError { err: _, @@ -360,17 +348,11 @@ where commit_stage_signature: sig, finalize_stage_signature: None, }); - let update_status = - CommitStatus::FailedProcess(status_signature); - persist_status_update_by_message_set( - persistor, - message_id, - pubkeys, - update_status, - ); + Some(CommitStatus::FailedProcess(status_signature)) } Err(IntentExecutorError::FailedFinalizePreparationError(_)) => { // Not supported in persistor + None } Err(IntentExecutorError::FailedToFinalizeError { err: _, @@ -388,13 +370,21 @@ where } else { CommitStatus::FailedProcess(None) }; - persist_status_update_by_message_set( - persistor, - message_id, - pubkeys, - update_status, - ); + + Some(update_status) + } + Err(IntentExecutorError::SignerError(_)) => { + Some(CommitStatus::Failed) } + }; + + if let Some(update_status) = update_status { + persist_status_update_by_message_set( + persistor, + message_id, + pubkeys, + update_status, + ); } } } @@ -490,9 +480,8 @@ mod tests { &Pubkey::new_unique(), &None::, ); - assert!(result.is_some()); - let strategy = result.unwrap(); + let strategy = result.unwrap().unwrap(); assert!(strategy.lookup_tables_keys.is_empty()); } } diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index f2ad2a4f2..ba771df20 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -1,7 +1,10 @@ use std::collections::BinaryHeap; use solana_pubkey::Pubkey; -use solana_sdk::{signature::Keypair, signer::Signer}; +use solana_sdk::{ + signature::Keypair, + signer::{Signer, SignerError}, +}; use crate::{ persist::IntentPersister, @@ -30,7 +33,8 @@ impl TaskStrategist { persistor: &Option

, ) -> TaskStrategistResult { // Attempt optimizing tasks themselves(using buffers) - if Self::optimize_strategy(&mut tasks) <= MAX_ENCODED_TRANSACTION_SIZE { + if Self::optimize_strategy(&mut tasks)? <= MAX_ENCODED_TRANSACTION_SIZE + { // Persist tasks strategy if let Some(persistor) = persistor { let mut persistor_visitor = PersistorVisitor { @@ -128,7 +132,9 @@ impl TaskStrategist { /// Optimizes set of [`TaskDeliveryStrategy`] to fit [`MAX_ENCODED_TRANSACTION_SIZE`] /// Returns size of tx after optimizations - fn optimize_strategy(tasks: &mut [Box]) -> usize { + fn optimize_strategy( + tasks: &mut [Box], + ) -> Result { // Get initial transaction size let calculate_tx_length = |tasks: &[Box]| { match TransactionUtils::assemble_tasks_tx( @@ -137,15 +143,16 @@ impl TaskStrategist { u64::default(), // placeholder &[], ) { - Ok(tx) => serialize_and_encode_base64(&tx).len(), - Err(_) => usize::MAX, + Ok(tx) => Ok(serialize_and_encode_base64(&tx).len()), + Err(TaskStrategistError::FailedToFitError) => Ok(usize::MAX), + Err(TaskStrategistError::SignerError(err)) => Err(err), } }; // Get initial transaction size - let mut current_tx_length = calculate_tx_length(tasks); + let mut current_tx_length = calculate_tx_length(tasks)?; if current_tx_length <= MAX_ENCODED_TRANSACTION_SIZE { - return current_tx_length; + return Ok(current_tx_length); } // Create heap size -> index @@ -193,7 +200,7 @@ impl TaskStrategist { bincode::serialized_size(&new_ix).unwrap_or(u64::MAX); let new_ix_size = usize::try_from(new_ix_size).unwrap_or(usize::MAX); - current_tx_length = calculate_tx_length(tasks); + current_tx_length = calculate_tx_length(tasks)?; map.push((new_ix_size, index)); } // That means el-t can't be optimized further @@ -205,7 +212,7 @@ impl TaskStrategist { } } - current_tx_length + Ok(current_tx_length) } } @@ -213,6 +220,8 @@ impl TaskStrategist { pub enum TaskStrategistError { #[error("Failed to fit in single TX")] FailedToFitError, + #[error("SignerError: {0}")] + SignerError(#[from] SignerError), } pub type TaskStrategistResult = Result; diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index cd9e82fa5..93b8afa1d 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -135,8 +135,7 @@ impl TransactionUtils { let tx = VersionedTransaction::try_new( VersionedMessage::V0(message), &[authority], - ) - .expect("Signing transaction has to be non-failing"); + )?; Ok(tx) } diff --git a/magicblock-committor-service/src/transaction_preparator/error.rs b/magicblock-committor-service/src/transaction_preparator/error.rs index 8359a9b83..72ceb7380 100644 --- a/magicblock-committor-service/src/transaction_preparator/error.rs +++ b/magicblock-committor-service/src/transaction_preparator/error.rs @@ -1,23 +1,25 @@ +use solana_sdk::signer::SignerError; use thiserror::Error; +use crate::tasks::task_strategist::TaskStrategistError; + #[derive(Error, Debug)] pub enum TransactionPreparatorError { #[error("Failed to fit in single TX")] FailedToFitError, + #[error("SignerError: {0}")] + SignerError(#[from] SignerError), #[error("DeliveryPreparationError: {0}")] DeliveryPreparationError( #[from] crate::transaction_preparator::delivery_preparator::Error, ), } -impl From - for TransactionPreparatorError -{ - fn from(value: crate::tasks::task_strategist::TaskStrategistError) -> Self { +impl From for TransactionPreparatorError { + fn from(value: TaskStrategistError) -> Self { match value { - crate::tasks::task_strategist::TaskStrategistError::FailedToFitError => { - Self::FailedToFitError - } + TaskStrategistError::FailedToFitError => Self::FailedToFitError, + TaskStrategistError::SignerError(err) => Self::SignerError(err), } } } From 71d620d24b69ae3d1dace0c14a4b719928636849 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 26 Aug 2025 15:19:42 +0900 Subject: [PATCH 192/199] fix: fmt + lint --- test-integration/Makefile | 3 ++ .../programs/flexi-counter/src/processor.rs | 13 +++-- .../src/processor/call_handler.rs | 38 ++++++++------- .../src/processor/schedule_intent.rs | 27 ++++++----- .../processor/schedule_redelegation_intent.rs | 21 +++++---- .../test-scenarios/tests/01_commits.rs | 1 - .../tests/02_commit_and_undelegate.rs | 6 ++- .../tests/03_commits_fee_payer.rs | 10 ++-- .../test-security/tests/01_invocations.rs | 11 +++-- .../test-committor-service/tests/common.rs | 21 +++++---- .../tests/test_ix_commit_local.rs | 46 +++++++++--------- .../tests/test_transaction_preparator.rs | 23 ++++----- .../tests/utils/instructions.rs | 5 +- .../test-ledger-restore/src/lib.rs | 1 - .../tests/test_claim_fees.rs | 2 +- .../tests/test_schedule_intents.rs | 47 ++++++++++--------- 16 files changed, 148 insertions(+), 127 deletions(-) diff --git a/test-integration/Makefile b/test-integration/Makefile index b9a7a6bb9..77ccb4962 100644 --- a/test-integration/Makefile +++ b/test-integration/Makefile @@ -145,6 +145,9 @@ deploy-flexi-counter: $(FLEXI_COUNTER_SO) --program-id $(DIR)/programs/flexi-counter/keys/f1exzKGtdeVX3d6UXZ89cY7twiNJe9S5uq84RTA4Rq4.json \ $(DIR)/target/deploy/program_flexi_counter.so +fmt: + cargo +nightly fmt -- --config-path ../rustfmt-nightly.toml + ci-fmt: cargo +nightly fmt --check -- --config-path ../rustfmt-nightly.toml diff --git a/test-integration/programs/flexi-counter/src/processor.rs b/test-integration/programs/flexi-counter/src/processor.rs index 591dc40dd..aded65901 100644 --- a/test-integration/programs/flexi-counter/src/processor.rs +++ b/test-integration/programs/flexi-counter/src/processor.rs @@ -3,9 +3,10 @@ mod schedule_intent; mod schedule_redelegation_intent; use borsh::{to_vec, BorshDeserialize}; -use ephemeral_rollups_sdk::consts::EXTERNAL_CALL_HANDLER_DISCRIMINATOR; use ephemeral_rollups_sdk::{ - consts::EXTERNAL_UNDELEGATE_DISCRIMINATOR, + consts::{ + EXTERNAL_CALL_HANDLER_DISCRIMINATOR, EXTERNAL_UNDELEGATE_DISCRIMINATOR, + }, cpi::{ delegate_account, undelegate_account, DelegateAccounts, DelegateConfig, }, @@ -23,14 +24,16 @@ use solana_program::{ sysvar::Sysvar, }; -use crate::processor::call_handler::process_call_handler; -use crate::processor::schedule_intent::process_create_intent; -use crate::processor::schedule_redelegation_intent::process_create_redelegation_intent; use crate::{ instruction::{ DelegateArgs, FlexiCounterInstruction, MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE, }, + processor::{ + call_handler::process_call_handler, + schedule_intent::process_create_intent, + schedule_redelegation_intent::process_create_redelegation_intent, + }, state::FlexiCounter, utils::assert_keys_equal, }; diff --git a/test-integration/programs/flexi-counter/src/processor/call_handler.rs b/test-integration/programs/flexi-counter/src/processor/call_handler.rs index aca3667dc..71e74b6c8 100644 --- a/test-integration/programs/flexi-counter/src/processor/call_handler.rs +++ b/test-integration/programs/flexi-counter/src/processor/call_handler.rs @@ -1,20 +1,24 @@ -use crate::args::{ - CallHandlerDiscriminator, CommitActionData, UndelegateActionData, -}; -use crate::state::FlexiCounter; +use std::slice::Iter; + use borsh::{to_vec, BorshDeserialize}; -use ephemeral_rollups_sdk::cpi::{ - delegate_account, DelegateAccounts, DelegateConfig, +use ephemeral_rollups_sdk::{ + cpi::{delegate_account, DelegateAccounts, DelegateConfig}, + pda::ephemeral_balance_pda_from_payer, + CallHandlerArgs, Context, +}; +use solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + msg, + program::invoke, + program_error::ProgramError, + system_instruction::transfer, +}; + +use crate::{ + args::{CallHandlerDiscriminator, CommitActionData, UndelegateActionData}, + state::FlexiCounter, }; -use ephemeral_rollups_sdk::pda::ephemeral_balance_pda_from_payer; -use ephemeral_rollups_sdk::{CallHandlerArgs, Context}; -use solana_program::account_info::{next_account_info, AccountInfo}; -use solana_program::entrypoint::ProgramResult; -use solana_program::msg; -use solana_program::program::invoke; -use solana_program::program_error::ProgramError; -use solana_program::system_instruction::transfer; -use std::slice::Iter; pub fn process_call_handler( accounts: &[AccountInfo], @@ -28,7 +32,7 @@ pub fn process_call_handler( let mut call_handler = CallHandlerArgs::try_from_slice(call_data)?; let discriminator = &call_handler.data.as_slice()[0..4]; - if discriminator == &CallHandlerDiscriminator::Simple.to_array() { + if discriminator == CallHandlerDiscriminator::Simple.to_array() { call_handler.data.drain(0..4); process_simple_call_handler( escrow_authority, @@ -36,7 +40,7 @@ pub fn process_call_handler( account_info_iter, &call_handler, ) - } else if discriminator == &CallHandlerDiscriminator::ReDelegate.to_array() + } else if discriminator == CallHandlerDiscriminator::ReDelegate.to_array() { call_handler.data.drain(0..4); process_redelegation_call_handler( diff --git a/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs b/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs index ec1169b01..288176576 100644 --- a/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs +++ b/test-integration/programs/flexi-counter/src/processor/schedule_intent.rs @@ -1,18 +1,21 @@ -use crate::args::{ - CallHandlerDiscriminator, CommitActionData, UndelegateActionData, -}; use borsh::to_vec; -use ephemeral_rollups_sdk::ephem::{ - CallHandler, CommitAndUndelegate, CommitType, MagicAction, - MagicInstructionBuilder, UndelegateType, +use ephemeral_rollups_sdk::{ + ephem::{ + CallHandler, CommitAndUndelegate, CommitType, MagicAction, + MagicInstructionBuilder, UndelegateType, + }, + ActionArgs, +}; +use solana_program::{ + account_info::{next_account_info, next_account_infos, AccountInfo}, + entrypoint::ProgramResult, + msg, + program_error::ProgramError, }; -use ephemeral_rollups_sdk::ActionArgs; -use solana_program::account_info::{ - next_account_info, next_account_infos, AccountInfo, + +use crate::args::{ + CallHandlerDiscriminator, CommitActionData, UndelegateActionData, }; -use solana_program::entrypoint::ProgramResult; -use solana_program::msg; -use solana_program::program_error::ProgramError; pub const ACTOR_ESCROW_INDEX: u8 = 1; const PRIZE: u64 = 1_000_000; diff --git a/test-integration/programs/flexi-counter/src/processor/schedule_redelegation_intent.rs b/test-integration/programs/flexi-counter/src/processor/schedule_redelegation_intent.rs index 57e4ce63b..bf0099e8c 100644 --- a/test-integration/programs/flexi-counter/src/processor/schedule_redelegation_intent.rs +++ b/test-integration/programs/flexi-counter/src/processor/schedule_redelegation_intent.rs @@ -1,12 +1,17 @@ -use crate::args::CallHandlerDiscriminator; -use ephemeral_rollups_sdk::ephem::{ - CallHandler, CommitAndUndelegate, CommitType, MagicAction, - MagicInstructionBuilder, UndelegateType, +use ephemeral_rollups_sdk::{ + ephem::{ + CallHandler, CommitAndUndelegate, CommitType, MagicAction, + MagicInstructionBuilder, UndelegateType, + }, + ActionArgs, +}; +use solana_program::{ + account_info::{next_account_info, AccountInfo}, + entrypoint::ProgramResult, + msg, }; -use ephemeral_rollups_sdk::ActionArgs; -use solana_program::account_info::{next_account_info, AccountInfo}; -use solana_program::entrypoint::ProgramResult; -use solana_program::msg; + +use crate::args::CallHandlerDiscriminator; pub const ACTOR_ESCROW_INDEX: u8 = 1; diff --git a/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs b/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs index 0f34c1b05..fca9b7ee0 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/01_commits.rs @@ -1,6 +1,5 @@ use integration_test_tools::run_test; use log::*; - use magicblock_core::magic_program; use program_schedulecommit::api::schedule_commit_cpi_instruction; use schedulecommit_client::{verify, ScheduleCommitTestContextFields}; diff --git a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs index 86ed5a375..a235f1c33 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/02_commit_and_undelegate.rs @@ -1,5 +1,7 @@ -use integration_test_tools::run_test; -use integration_test_tools::scheduled_commits::extract_scheduled_commit_sent_signature_from_logs; +use integration_test_tools::{ + run_test, + scheduled_commits::extract_scheduled_commit_sent_signature_from_logs, +}; use log::*; use magicblock_core::magic_program; use program_schedulecommit::api::{ diff --git a/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs b/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs index 30f41dc6e..887fc2a2a 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/03_commits_fee_payer.rs @@ -1,10 +1,5 @@ use integration_test_tools::run_test; use log::*; - -use crate::utils::{ - assert_feepayer_was_committed, - get_context_with_delegated_committees_without_payer_escrow, -}; use magicblock_core::magic_program; use program_schedulecommit::api::schedule_commit_with_payer_cpi_instruction; use schedulecommit_client::{verify, ScheduleCommitTestContextFields}; @@ -18,6 +13,11 @@ use utils::{ get_context_with_delegated_committees, }; +use crate::utils::{ + assert_feepayer_was_committed, + get_context_with_delegated_committees_without_payer_escrow, +}; + mod utils; #[test] diff --git a/test-integration/schedulecommit/test-security/tests/01_invocations.rs b/test-integration/schedulecommit/test-security/tests/01_invocations.rs index ad6a64b0a..3bb6cee2e 100644 --- a/test-integration/schedulecommit/test-security/tests/01_invocations.rs +++ b/test-integration/schedulecommit/test-security/tests/01_invocations.rs @@ -1,8 +1,3 @@ -use crate::utils::{ - create_nested_schedule_cpis_instruction, - create_sibling_non_cpi_instruction, - create_sibling_schedule_cpis_instruction, -}; use magicblock_core::magic_program; use program_schedulecommit::api::schedule_commit_cpi_instruction; use schedulecommit_client::{ @@ -15,6 +10,12 @@ use solana_sdk::{ signer::Signer, transaction::Transaction, }; + +use crate::utils::{ + create_nested_schedule_cpis_instruction, + create_sibling_non_cpi_instruction, + create_sibling_schedule_cpis_instruction, +}; mod utils; const _PROGRAM_ADDR: &str = "9hgprgZiRWmy8KkfvUuaVkDGrqo9GzeXMohwq6BazgUY"; diff --git a/test-integration/test-committor-service/tests/common.rs b/test-integration/test-committor-service/tests/common.rs index 24ce24ab6..bef3eb7a3 100644 --- a/test-integration/test-committor-service/tests/common.rs +++ b/test-integration/test-committor-service/tests/common.rs @@ -1,8 +1,16 @@ +use std::{ + collections::HashMap, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, + }, +}; + use async_trait::async_trait; -use magicblock_committor_service::intent_executor::IntentExecutorImpl; use magicblock_committor_service::{ - intent_executor::task_info_fetcher::{ - TaskInfoFetcher, TaskInfoFetcherResult, + intent_executor::{ + task_info_fetcher::{TaskInfoFetcher, TaskInfoFetcherResult}, + IntentExecutorImpl, }, tasks::tasks::CommitTask, transaction_preparator::{ @@ -20,13 +28,6 @@ use solana_rpc_client::nonblocking::rpc_client::RpcClient; use solana_sdk::{ commitment_config::CommitmentConfig, signature::Keypair, signer::Signer, }; -use std::{ - collections::HashMap, - sync::{ - atomic::{AtomicU64, Ordering}, - Arc, - }, -}; // Helper function to create a test RPC client pub async fn create_test_client() -> MagicblockRpcClient { diff --git a/test-integration/test-committor-service/tests/test_ix_commit_local.rs b/test-integration/test-committor-service/tests/test_ix_commit_local.rs index 8956da345..1a24f7f57 100644 --- a/test-integration/test-committor-service/tests/test_ix_commit_local.rs +++ b/test-integration/test-committor-service/tests/test_ix_commit_local.rs @@ -1,26 +1,26 @@ -use log::*; -use magicblock_committor_service::{BaseIntentCommittor, ComputeBudgetConfig}; -use magicblock_rpc_client::MagicblockRpcClient; -use std::collections::{HashMap, HashSet}; -use std::sync::{Arc, Once}; -use std::time::{Duration, Instant}; - -use magicblock_committor_service::intent_executor::ExecutionOutput; -use magicblock_committor_service::persist::CommitStrategy; -use magicblock_committor_service::service_ext::{ - BaseIntentCommittorExt, CommittorServiceExt, +use std::{ + collections::{HashMap, HashSet}, + sync::{Arc, Once}, + time::{Duration, Instant}, }; -use magicblock_committor_service::types::{ - ScheduledBaseIntentWrapper, TriggerType, -}; -use magicblock_committor_service::{config::ChainConfig, CommittorService}; -use magicblock_program::magic_scheduled_base_intent::{ - CommitAndUndelegate, CommitType, CommittedAccountV2, MagicBaseIntent, - ScheduledBaseIntent, UndelegateType, + +use log::*; +use magicblock_committor_service::{ + config::ChainConfig, + intent_executor::ExecutionOutput, + persist::CommitStrategy, + service_ext::{BaseIntentCommittorExt, CommittorServiceExt}, + types::{ScheduledBaseIntentWrapper, TriggerType}, + BaseIntentCommittor, CommittorService, ComputeBudgetConfig, }; -use magicblock_program::validator::{ - init_validator_authority, validator_authority, +use magicblock_program::{ + magic_scheduled_base_intent::{ + CommitAndUndelegate, CommitType, CommittedAccountV2, MagicBaseIntent, + ScheduledBaseIntent, UndelegateType, + }, + validator::{init_validator_authority, validator_authority}, }; +use magicblock_rpc_client::MagicblockRpcClient; use solana_account::{Account, ReadableAccount}; use solana_pubkey::Pubkey; use solana_rpc_client::nonblocking::rpc_client::RpcClient; @@ -320,7 +320,7 @@ async fn commit_single_account( let (pubkey, mut account) = init_and_delegate_account_on_chain(&counter_auth, bytes as u64).await; account.owner = program_flexi_counter::id(); - account.data = vec![101 as u8; bytes]; + account.data = vec![101_u8; bytes]; let account = CommittedAccountV2 { pubkey, account }; let base_intent = if undelegate { @@ -344,7 +344,7 @@ async fn commit_single_account( }, }; - /// We should always be able to Commit & Finalize 1 account either with Args or Buffers + // We should always be able to Commit & Finalize 1 account either with Args or Buffers ix_commit_local( service, vec![intent], @@ -750,7 +750,7 @@ async fn ix_commit_local( let mut committed_accounts = base_intent .get_committed_accounts() .unwrap() - .into_iter() + .iter() .map(|el| (el.pubkey, el.clone())) .collect::>(); let statuses = service diff --git a/test-integration/test-committor-service/tests/test_transaction_preparator.rs b/test-integration/test-committor-service/tests/test_transaction_preparator.rs index 9cc9e92e2..23029a8bf 100644 --- a/test-integration/test-committor-service/tests/test_transaction_preparator.rs +++ b/test-integration/test-committor-service/tests/test_transaction_preparator.rs @@ -1,19 +1,16 @@ -use crate::common::{ - create_committed_account, generate_random_bytes, TestFixture, -}; use borsh::BorshDeserialize; use dlp::args::Context; use magicblock_committor_program::Chunks; -use magicblock_committor_service::tasks::task_strategist::{ - TaskStrategist, TransactionStrategy, -}; -use magicblock_committor_service::tasks::tasks::{ - ArgsTask, BaseTask, BufferTask, CommitTask, FinalizeTask, L1ActionTask, - UndelegateTask, -}; -use magicblock_committor_service::tasks::utils::TransactionUtils; use magicblock_committor_service::{ persist::IntentPersisterImpl, + tasks::{ + task_strategist::{TaskStrategist, TransactionStrategy}, + tasks::{ + ArgsTask, BaseTask, BufferTask, CommitTask, FinalizeTask, + L1ActionTask, UndelegateTask, + }, + utils::TransactionUtils, + }, transaction_preparator::transaction_preparator::TransactionPreparator, }; use magicblock_program::magic_scheduled_base_intent::{ @@ -22,6 +19,10 @@ use magicblock_program::magic_scheduled_base_intent::{ use solana_pubkey::Pubkey; use solana_sdk::{signer::Signer, system_program}; +use crate::common::{ + create_committed_account, generate_random_bytes, TestFixture, +}; + mod common; #[tokio::test] diff --git a/test-integration/test-committor-service/tests/utils/instructions.rs b/test-integration/test-committor-service/tests/utils/instructions.rs index abc640e4b..4e90c0b7d 100644 --- a/test-integration/test-committor-service/tests/utils/instructions.rs +++ b/test-integration/test-committor-service/tests/utils/instructions.rs @@ -23,13 +23,12 @@ pub fn init_account_and_delegate_ixs( ) -> InitAccountAndDelegateIxs { const MAX_ALLOC: u64 = magicblock_committor_program::consts::MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE as u64; - use program_flexi_counter::instruction::*; - use program_flexi_counter::state::*; + use program_flexi_counter::{instruction::*, state::*}; let init_counter_ix = create_init_ix(payer, "COUNTER".to_string()); let rent_exempt = Rent::default().minimum_balance(bytes as usize); - let num_reallocs = (bytes + MAX_ALLOC - 1) / MAX_ALLOC; + let num_reallocs = bytes.div_ceil(MAX_ALLOC); let realloc_ixs = if num_reallocs == 0 { vec![] } else { diff --git a/test-integration/test-ledger-restore/src/lib.rs b/test-integration/test-ledger-restore/src/lib.rs index 589c3cd4b..58b3e9e94 100644 --- a/test-integration/test-ledger-restore/src/lib.rs +++ b/test-integration/test-ledger-restore/src/lib.rs @@ -123,7 +123,6 @@ pub fn setup_validator_with_local_remote( skip_keypair_match_check, path: Some(ledger_path.display().to_string()), size: DEFAULT_LEDGER_SIZE_BYTES, - ..Default::default() }, accounts: accounts_config.clone(), programs, diff --git a/test-integration/test-magicblock-api/tests/test_claim_fees.rs b/test-integration/test-magicblock-api/tests/test_claim_fees.rs index 4db04b9cc..5b7ffc8a9 100644 --- a/test-integration/test-magicblock-api/tests/test_claim_fees.rs +++ b/test-integration/test-magicblock-api/tests/test_claim_fees.rs @@ -6,9 +6,9 @@ use integration_test_tools::{ }; use magicblock_validator_admin::claim_fees::ClaimFeesTask; use solana_rpc_client::rpc_client::RpcClient; -use solana_sdk::pubkey::Pubkey; use solana_sdk::{ commitment_config::CommitmentConfig, + pubkey::Pubkey, signature::{Keypair, Signer}, transaction::Transaction, }; diff --git a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs index d66d9b7d8..5c580d43a 100644 --- a/test-integration/test-schedule-intent/tests/test_schedule_intents.rs +++ b/test-integration/test-schedule-intent/tests/test_schedule_intents.rs @@ -1,19 +1,20 @@ +use std::time::Duration; + use dlp::pda::ephemeral_balance_pda_from_payer; use integration_test_tools::IntegrationTestContext; -use program_flexi_counter::delegation_program_id; -use program_flexi_counter::instruction::{ - create_add_ix, create_delegate_ix, create_init_ix, create_intent_ix, - create_redelegation_intent_ix, +use program_flexi_counter::{ + delegation_program_id, + instruction::{ + create_add_ix, create_delegate_ix, create_init_ix, create_intent_ix, + create_redelegation_intent_ix, + }, + state::FlexiCounter, }; -use program_flexi_counter::state::FlexiCounter; use solana_rpc_client_api::config::RpcSendTransactionConfig; -use solana_sdk::commitment_config::CommitmentConfig; -use solana_sdk::native_token::LAMPORTS_PER_SOL; -use solana_sdk::rent::Rent; -use solana_sdk::signature::Keypair; -use solana_sdk::signer::Signer; -use solana_sdk::transaction::Transaction; -use std::time::Duration; +use solana_sdk::{ + commitment_config::CommitmentConfig, native_token::LAMPORTS_PER_SOL, + rent::Rent, signature::Keypair, signer::Signer, transaction::Transaction, +}; const LABEL: &str = "I am a label"; @@ -77,9 +78,9 @@ fn test_3_payers_intent_with_undelegation() { // Init and setup counters for each payer let values: [u8; PAYERS] = [100, 200, 201]; payers.iter().enumerate().for_each(|(i, payer)| { - init_counter(&ctx, &payer); - delegate_counter(&ctx, &payer); - add_to_counter(&ctx, &payer, values[i]); + init_counter(&ctx, payer); + delegate_counter(&ctx, payer); + add_to_counter(&ctx, payer, values[i]); }); // Schedule intent affecting all counters @@ -103,9 +104,9 @@ fn test_5_payers_intent_only_commit() { // Init and setup counters for each payer let values: [u8; PAYERS] = std::array::from_fn(|i| 180 + i as u8); payers.iter().enumerate().for_each(|(i, payer)| { - init_counter(&ctx, &payer); - delegate_counter(&ctx, &payer); - add_to_counter(&ctx, &payer, values[i]); + init_counter(&ctx, payer); + delegate_counter(&ctx, payer); + add_to_counter(&ctx, payer, values[i]); }); let counter_diffs: [i64; PAYERS] = [-2; PAYERS]; @@ -163,7 +164,7 @@ fn setup_payer(ctx: &IntegrationTestContext) -> Keypair { fn init_counter(ctx: &IntegrationTestContext, payer: &Keypair) { let ix = create_init_ix(payer.pubkey(), LABEL.to_string()); let (_, confirmed) = ctx - .send_and_confirm_instructions_with_payer_chain(&[ix], &payer) + .send_and_confirm_instructions_with_payer_chain(&[ix], payer) .unwrap(); assert!(confirmed, "Should confirm transaction"); @@ -187,7 +188,7 @@ fn delegate_counter(ctx: &IntegrationTestContext, payer: &Keypair) { let counter_pda = FlexiCounter::pda(&payer.pubkey()).0; let ix = create_delegate_ix(payer.pubkey()); - ctx.send_and_confirm_instructions_with_payer_chain(&[ix], &payer) + ctx.send_and_confirm_instructions_with_payer_chain(&[ix], payer) .unwrap(); // Confirm delegated @@ -210,7 +211,7 @@ fn add_to_counter(ctx: &IntegrationTestContext, payer: &Keypair, value: u8) { // Add value to counter let ix = create_add_ix(payer.pubkey(), value); - ctx.send_and_confirm_instructions_with_payer_ephem(&[ix], &payer) + ctx.send_and_confirm_instructions_with_payer_ephem(&[ix], payer) .unwrap(); let counter = ctx @@ -286,7 +287,7 @@ fn schedule_intent( .fetch_schedule_commit_result::(sig) .unwrap(); commit_result - .confirm_commit_transactions_on_chain(&ctx) + .confirm_commit_transactions_on_chain(ctx) .unwrap(); // Confirm results on base lauer @@ -340,7 +341,7 @@ fn redelegate_intent(ctx: &IntegrationTestContext, payer: &Keypair) { .fetch_schedule_commit_result::(sig) .unwrap(); commit_result - .confirm_commit_transactions_on_chain(&ctx) + .confirm_commit_transactions_on_chain(ctx) .unwrap(); // Confirm that it got delegated back From 491d30f608b41e6f0b64bc88d2c632cd0ad426dd Mon Sep 17 00:00:00 2001 From: taco-paco Date: Tue, 26 Aug 2025 15:20:56 +0900 Subject: [PATCH 193/199] fix: rm local sript --- .../configs/run-test-validator-new.sh | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100755 test-integration/configs/run-test-validator-new.sh diff --git a/test-integration/configs/run-test-validator-new.sh b/test-integration/configs/run-test-validator-new.sh deleted file mode 100755 index a1221a720..000000000 --- a/test-integration/configs/run-test-validator-new.sh +++ /dev/null @@ -1,38 +0,0 @@ -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -solana-test-validator \ - --log \ - --rpc-port 7799 \ - -r \ - --account mAGicPQYBMvcYveUZA5F5UNNwyHvfYh5xkLS2Fr1mev \ - $DIR/accounts/validator-authority.json \ - --account EpJnX7ueXk7fKojBymqmVuCuwyhDQsYcLVL1XMsBbvDX \ - $DIR/accounts/validator-fees-vault.json \ - --account 7JrkjmZPprHwtuvtuGTXp9hwfGYFAQLnLeFM52kqAgXg \ - $DIR/accounts/protocol-fees-vault.json \ - --account LUzidNSiPNjYNkxZcUm5hYHwnWPwsUfh2US1cpWwaBm \ - $DIR/accounts/luzid-authority.json \ - --limit-ledger-size \ - 1000000 \ - --bpf-program \ - DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh \ - $DIR/../schedulecommit/elfs/dlp.so \ - --bpf-program \ - DmnRGfyyftzacFb1XadYhWF6vWqXwtQk5tbr6XgR3BA1 \ - $DIR/../schedulecommit/elfs/mdp.so \ - --bpf-program \ - 9hgprgZiRWmy8KkfvUuaVkDGrqo9GzeXMohwq6BazgUY \ - $DIR/../target/deploy/program_schedulecommit.so \ - --bpf-program \ - f1exzKGtdeVX3d6UXZ89cY7twiNJe9S5uq84RTA4Rq4 \ - $DIR/../target/deploy/program_flexi_counter.so \ - --bpf-program \ - 4RaQH3CUBMSMQsSHPVaww2ifeNEEuaDZjF9CUdFwr3xr \ - $DIR/../target/deploy/program_schedulecommit_security.so \ - --bpf-program \ - 3JnJ727jWEmPVU8qfXwtH63sCNDX7nMgsLbg8qy8aaPX \ - /Users/edwinpaco/Documents/work/MagicBlock/redline/target/deploy/redline.so \ - --bpf-program \ - CoMtrr6j336NSB5PAoAWpLe5hPgkcShWKbPgHhZxaxh \ - $DIR/../../target/deploy/magicblock_committor_program.so - From e271454c654788f19322fed4e003b7ce8e9a1ae8 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 28 Aug 2025 14:34:44 +0900 Subject: [PATCH 194/199] refactor: remove "l1" menations --- .../src/external_accounts_manager.rs | 26 +++++++++---------- magicblock-committor-service/README.md | 4 +-- .../src/committor_processor.rs | 4 +-- .../src/intent_executor/mod.rs | 2 +- .../src/persist/commit_persister.rs | 20 +++++++------- magicblock-committor-service/src/service.rs | 2 +- .../src/stubs/changeset_committor_stub.rs | 6 ++--- .../src/tasks/task_builder.rs | 20 +++++++------- .../src/tasks/task_strategist.rs | 12 ++++----- .../src/tasks/tasks.rs | 16 ++++++------ .../tests/test_transaction_preparator.rs | 10 +++---- 11 files changed, 62 insertions(+), 60 deletions(-) diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 75cf108b0..112efedb4 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -290,36 +290,36 @@ where } // Convert committees to BaseIntents s - let scheduled_l1_messages = - self.create_scheduled_l1_message(accounts_to_be_committed); + let scheduled_base_intent = + self.create_scheduled_base_intents(accounts_to_be_committed); // Commit BaseIntents let results = committor_service - .schedule_base_intents_waiting(scheduled_l1_messages.clone()) + .schedule_base_intents_waiting(scheduled_base_intent.clone()) .await?; // Process results - let output = self.process_l1_messages_results( + let output = self.process_base_intents_results( &now, results, - &scheduled_l1_messages, + &scheduled_base_intent, ); Ok(output) } - fn process_l1_messages_results( + fn process_base_intents_results( &self, now: &Duration, results: Vec, - scheduled_l1_messages: &[ScheduledBaseIntentWrapper], + scheduled_base_intents: &[ScheduledBaseIntentWrapper], ) -> Vec { - // Filter failed l1 messages, log failed ones + // Filter failed base intents, log failed ones let outputs = results .into_iter() .filter_map(|execution_result| match execution_result { Ok(value) => Some(value), Err(err) => { - error!("Failed to send l1 message: {}", err.2); + error!("Failed to send base intent: {}", err.2); None } }) @@ -327,7 +327,7 @@ where .collect::>(); // For successfully committed accounts get their (pubkey, hash) - let pubkeys_with_hashes = scheduled_l1_messages + let pubkeys_with_hashes = scheduled_base_intents .iter() // Filter out unsuccessful messages .filter(|message| outputs.contains_key(&message.inner.id)) @@ -367,7 +367,7 @@ where outputs.into_values().map(|output| output.output).collect() } - fn create_scheduled_l1_message( + fn create_scheduled_base_intents( &self, accounts_to_be_committed: Vec<(Pubkey, Pubkey, Option)>, ) -> Vec { @@ -425,8 +425,8 @@ where ), } }) - .map(|scheduled_l1_message| ScheduledBaseIntentWrapper { - inner: scheduled_l1_message, + .map(|scheduled_base_intents| ScheduledBaseIntentWrapper { + inner: scheduled_base_intents, trigger_type: TriggerType::OffChain, }) .collect() diff --git a/magicblock-committor-service/README.md b/magicblock-committor-service/README.md index 2a5dbe7e2..714dfcb0e 100644 --- a/magicblock-committor-service/README.md +++ b/magicblock-committor-service/README.md @@ -23,12 +23,12 @@ IntentExecutor - responsible for execution of Intent. Calls **TransactionPrepar TransactionPreparator - is an entity that handles all of the above "Transaction preparation" calling **TaskBuilderV1**, **TaskStrategist**, **DeliveryPreparator** and then assempling it all and passing to **MessageExecutor** ## DeliveryPreparator -After our **L1Task**s are ready we need to prepare eveything for their successful execution. **DeliveryPreparator** - handles ALTs and commit buffers +After our **BaseTask**s are ready we need to prepare eveything for their successful execution. **DeliveryPreparator** - handles ALTs and commit buffers ## TaskBuilder First, lets build atomic tasks from scheduled message/intent. -High level: TaskBuilder responsible for creating L1Tasks(to be renamed...) from ScheduledL1Message(to be renamed...). +High level: TaskBuilder responsible for creating BaseTasks(to be renamed...) from ScheduledBaseIntent(to be renamed...). Details: To do that is requires additional information from DelegationMetadata, it is provided **CommitIdFetcher** ### BaseTask diff --git a/magicblock-committor-service/src/committor_processor.rs b/magicblock-committor-service/src/committor_processor.rs index 2673041e6..f3bf4066f 100644 --- a/magicblock-committor-service/src/committor_processor.rs +++ b/magicblock-committor-service/src/committor_processor.rs @@ -130,7 +130,7 @@ impl CommittorProcessor { ) { let intents = base_intents .iter() - .map(|l1_message| l1_message.inner.clone()) + .map(|base_intent| base_intent.inner.clone()) .collect::>(); if let Err(err) = self.persister.start_base_intents(&intents) { // We will still try to perform the commits, but the fact that we cannot @@ -144,7 +144,7 @@ impl CommittorProcessor { if let Err(err) = self.commits_scheduler.schedule(base_intents).await { // CommittorService broken - panic!("Failed to schedule L1 message: {}", err); + panic!("Failed to schedule base intent: {}", err); } } diff --git a/magicblock-committor-service/src/intent_executor/mod.rs b/magicblock-committor-service/src/intent_executor/mod.rs index 673287805..aa73fbf93 100644 --- a/magicblock-committor-service/src/intent_executor/mod.rs +++ b/magicblock-committor-service/src/intent_executor/mod.rs @@ -33,7 +33,7 @@ pub trait IntentExecutor: Send + Sync + 'static { /// Returns `ExecutionOutput` or an `Error` async fn execute( &self, - l1_message: ScheduledBaseIntent, + base_intent: ScheduledBaseIntent, persister: Option

, ) -> IntentExecutorResult; } diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index e60710c42..6eff5a853 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -152,9 +152,9 @@ impl IntentPersisterImpl { impl IntentPersister for IntentPersisterImpl { fn start_base_intents( &self, - l1_message: &[ScheduledBaseIntent], + base_intents: &[ScheduledBaseIntent], ) -> CommitPersistResult<()> { - let commit_rows = l1_message + let commit_rows = base_intents .iter() .flat_map(Self::create_commit_rows) .collect::>(); @@ -168,9 +168,9 @@ impl IntentPersister for IntentPersisterImpl { fn start_base_intent( &self, - l1_message: &ScheduledBaseIntent, + base_intents: &ScheduledBaseIntent, ) -> CommitPersistResult<()> { - let commit_row = Self::create_commit_rows(l1_message); + let commit_row = Self::create_commit_rows(base_intents); self.commits_db .lock() .expect(POISONED_MUTEX_MSG) @@ -297,20 +297,20 @@ impl IntentPersister for IntentPersisterImpl { impl IntentPersister for Option { fn start_base_intents( &self, - l1_messages: &[ScheduledBaseIntent], + base_intents: &[ScheduledBaseIntent], ) -> CommitPersistResult<()> { match self { - Some(persister) => persister.start_base_intents(l1_messages), + Some(persister) => persister.start_base_intents(base_intents), None => Ok(()), } } fn start_base_intent( &self, - l1_message: &ScheduledBaseIntent, + base_intents: &ScheduledBaseIntent, ) -> CommitPersistResult<()> { match self { - Some(persister) => persister.start_base_intent(l1_message), + Some(persister) => persister.start_base_intent(base_intents), None => Ok(()), } } @@ -506,7 +506,7 @@ mod tests { } #[test] - fn test_start_l1_message() { + fn test_start_base_message() { let (persister, _temp_file) = create_test_persister(); let message = create_test_message(1); @@ -522,7 +522,7 @@ mod tests { } #[test] - fn test_start_l1_messages() { + fn test_start_base_messages() { let (persister, _temp_file) = create_test_persister(); let message1 = create_test_message(1); let message2 = create_test_message(2); diff --git a/magicblock-committor-service/src/service.rs b/magicblock-committor-service/src/service.rs index 80a3ce40b..c298ed319 100644 --- a/magicblock-committor-service/src/service.rs +++ b/magicblock-committor-service/src/service.rs @@ -426,7 +426,7 @@ pub trait BaseIntentCommittor: Send + Sync + 'static { /// Commits the changeset and returns fn schedule_base_intent( &self, - l1_messages: Vec, + base_intents: Vec, ); /// Subscribes for results of BaseIntent execution diff --git a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs index 60137b570..4ffaa8d73 100644 --- a/magicblock-committor-service/src/stubs/changeset_committor_stub.rs +++ b/magicblock-committor-service/src/stubs/changeset_committor_stub.rs @@ -164,11 +164,11 @@ impl BaseIntentCommittor for ChangesetCommittorStub { impl BaseIntentCommittorExt for ChangesetCommittorStub { async fn schedule_base_intents_waiting( &self, - l1_messages: Vec, + base_intents: Vec, ) -> BaseIntentCommitorExtResult> { - self.schedule_base_intent(l1_messages.clone()); - let res = l1_messages + self.schedule_base_intent(base_intents.clone()); + let res = base_intents .into_iter() .map(|message| { Ok(ExecutionOutputWrapper { diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index 698cea478..a75a0b176 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -15,7 +15,7 @@ use crate::{ }, persist::IntentPersister, tasks::tasks::{ - ArgsTask, BaseTask, CommitTask, FinalizeTask, L1ActionTask, + ArgsTask, BaseActionTask, BaseTask, CommitTask, FinalizeTask, UndelegateTask, }, }; @@ -53,11 +53,12 @@ impl TasksBuilder for TaskBuilderV1 { let tasks = actions .iter() .map(|el| { - let task = L1ActionTask { + let task = BaseActionTask { context: Context::Standalone, action: el.clone(), }; - Box::new(ArgsTask::L1Action(task)) as Box + Box::new(ArgsTask::BaseAction(task)) + as Box }) .collect(); @@ -136,18 +137,19 @@ impl TasksBuilder for TaskBuilderV1 { } CommitType::WithBaseActions { committed_accounts, - base_actions: l1_actions, + base_actions, } => { let mut tasks = committed_accounts .iter() .map(finalize_task) .collect::>(); - tasks.extend(l1_actions.iter().map(|action| { - let task = L1ActionTask { + tasks.extend(base_actions.iter().map(|action| { + let task = BaseActionTask { context: Context::Commit, action: action.clone(), }; - Box::new(ArgsTask::L1Action(task)) as Box + Box::new(ArgsTask::BaseAction(task)) + as Box })); tasks } @@ -181,11 +183,11 @@ impl TasksBuilder for TaskBuilderV1 { UndelegateType::Standalone => Ok(tasks), UndelegateType::WithBaseActions(actions) => { tasks.extend(actions.iter().map(|action| { - let task = L1ActionTask { + let task = BaseActionTask { context: Context::Undelegate, action: action.clone(), }; - Box::new(ArgsTask::L1Action(task)) + Box::new(ArgsTask::BaseAction(task)) as Box })); diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index ba771df20..189b8712e 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -239,7 +239,7 @@ mod tests { use crate::{ persist::IntentPersisterImpl, tasks::tasks::{ - CommitTask, L1ActionTask, TaskStrategy, UndelegateTask, + BaseActionTask, CommitTask, TaskStrategy, UndelegateTask, }, }; @@ -261,9 +261,9 @@ mod tests { }) } - // Helper to create an L1 action task - fn create_test_l1_action_task(len: usize) -> ArgsTask { - ArgsTask::L1Action(L1ActionTask { + // Helper to create a Base action task + fn create_test_base_action_task(len: usize) -> ArgsTask { + ArgsTask::BaseAction(BaseActionTask { context: Context::Commit, action: BaseAction { destination_program: Pubkey::new_unique(), @@ -450,7 +450,7 @@ mod tests { let tasks = vec![ Box::new(create_test_commit_task(1, 1000)) as Box, Box::new(create_test_finalize_task()) as Box, - Box::new(create_test_l1_action_task(500)) as Box, + Box::new(create_test_base_action_task(500)) as Box, Box::new(create_test_undelegate_task()) as Box, ]; @@ -474,7 +474,7 @@ mod tests { vec![ TaskStrategy::Buffer, // Commit task optimized TaskStrategy::Args, // Finalize stays - TaskStrategy::Args, // L1Action stays + TaskStrategy::Args, // BaseAction stays TaskStrategy::Args, // Undelegate stays ] ); diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index ec3960755..d5cf35e85 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -95,7 +95,7 @@ pub struct FinalizeTask { } #[derive(Clone)] -pub struct L1ActionTask { +pub struct BaseActionTask { pub context: Context, pub action: BaseAction, } @@ -106,7 +106,7 @@ pub enum ArgsTask { Commit(CommitTask), Finalize(FinalizeTask), Undelegate(UndelegateTask), // Special action really - L1Action(L1ActionTask), + BaseAction(BaseActionTask), } impl BaseTask for ArgsTask { @@ -136,7 +136,7 @@ impl BaseTask for ArgsTask { value.owner_program, value.rent_reimbursement, ), - Self::L1Action(value) => { + Self::BaseAction(value) => { let action = &value.action; let account_metas = action .account_metas_per_program @@ -167,7 +167,7 @@ impl BaseTask for ArgsTask { ) -> Result, Box> { match *self { Self::Commit(value) => Ok(Box::new(BufferTask::Commit(value))), - Self::L1Action(_) | Self::Finalize(_) | Self::Undelegate(_) => { + Self::BaseAction(_) | Self::Finalize(_) | Self::Undelegate(_) => { Err(self) } } @@ -181,7 +181,7 @@ impl BaseTask for ArgsTask { fn compute_units(&self) -> u32 { match self { Self::Commit(_) => 55_000, - Self::L1Action(task) => task.action.compute_units, + Self::BaseAction(task) => task.action.compute_units, Self::Undelegate(_) => 50_000, Self::Finalize(_) => 40_000, } @@ -359,8 +359,8 @@ mod serialization_safety_test { }); assert_serializable(&undelegate_task.instruction(&validator)); - // Test L1Action variant - let l1_action = ArgsTask::L1Action(L1ActionTask { + // Test BaseAction variant + let base_action = ArgsTask::BaseAction(BaseActionTask { context: Context::Undelegate, action: BaseAction { destination_program: Pubkey::new_unique(), @@ -376,7 +376,7 @@ mod serialization_safety_test { compute_units: 10_000, }, }); - assert_serializable(&l1_action.instruction(&validator)); + assert_serializable(&base_action.instruction(&validator)); } // Test BufferTask variants diff --git a/test-integration/test-committor-service/tests/test_transaction_preparator.rs b/test-integration/test-committor-service/tests/test_transaction_preparator.rs index 23029a8bf..c4efa8755 100644 --- a/test-integration/test-committor-service/tests/test_transaction_preparator.rs +++ b/test-integration/test-committor-service/tests/test_transaction_preparator.rs @@ -7,7 +7,7 @@ use magicblock_committor_service::{ task_strategist::{TaskStrategist, TransactionStrategy}, tasks::{ ArgsTask, BaseTask, BufferTask, CommitTask, FinalizeTask, - L1ActionTask, UndelegateTask, + BaseActionTask, UndelegateTask, }, utils::TransactionUtils, }, @@ -159,7 +159,7 @@ async fn test_prepare_commit_tx_with_multiple_accounts() { } #[tokio::test] -async fn test_prepare_commit_tx_with_l1_actions() { +async fn test_prepare_commit_tx_with_base_actions() { let fixture = TestFixture::new().await; let preparator = fixture.create_transaction_preparator(); @@ -191,8 +191,8 @@ async fn test_prepare_commit_tx_with_l1_actions() { Box::new(ArgsTask::Finalize(FinalizeTask { delegated_account: committed_account.pubkey, })), - // L1Action - Box::new(ArgsTask::L1Action(L1ActionTask { + // BaseAction + Box::new(ArgsTask::BaseAction(BaseActionTask { context: Context::Commit, action: base_action, })), @@ -256,7 +256,7 @@ async fn test_prepare_finalize_tx_with_undelegate_with_atls() { Box::new(ArgsTask::Finalize(FinalizeTask { delegated_account: committed_account.pubkey, })), - // L1Action + // BaseAction Box::new(ArgsTask::Undelegate(UndelegateTask { delegated_account: committed_account.pubkey, owner_program: Pubkey::new_unique(), From 5519f28b1ad6ad1c62b7e0132d3e3788993c16ea Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 28 Aug 2025 17:55:29 +0900 Subject: [PATCH 195/199] refactoring: renamings + extra comments and minor fixes --- Cargo.lock | 1 + magicblock-accounts/Cargo.toml | 1 + .../src/external_accounts_manager.rs | 8 +- magicblock-accounts/src/traits.rs | 2 - magicblock-committor-service/CHANGES.md | 6 - .../intent_execution_engine.rs | 8 +- .../intent_scheduler.rs | 3 - .../src/intent_executor/error.rs | 2 +- .../src/intent_executor/intent_executor.rs | 16 +- .../src/intent_executor/task_info_fetcher.rs | 2 +- .../src/tasks/task_strategist.rs | 4 +- .../src/tasks/tasks.rs | 1 + .../src/tasks/utils.rs | 15 - .../delivery_preparator.rs | 5 +- .../transaction_preparator.rs | 3 +- .../src/magic_program/instruction.rs | 19 - magicblock-rpc/src/traits/rpc_full.rs | 15 - magicblock-table-mania/src/lookup_table.rs | 537 ------------------ .../src/magic_scheduled_base_intent.rs | 10 +- .../src/schedule_transactions/mod.rs | 5 +- .../process_accept_scheduled_commits.rs | 7 +- test-integration/Cargo.lock | 1 + 22 files changed, 40 insertions(+), 631 deletions(-) delete mode 100644 magicblock-committor-service/CHANGES.md delete mode 100644 magicblock-table-mania/src/lookup_table.rs diff --git a/Cargo.lock b/Cargo.lock index 70eaf4477..8c06ec924 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3926,6 +3926,7 @@ dependencies = [ "async-trait", "conjunto-transwise", "futures-util", + "itertools 0.14.0", "log", "magicblock-account-cloner", "magicblock-account-dumper", diff --git a/magicblock-accounts/Cargo.toml b/magicblock-accounts/Cargo.toml index c5f5945e1..ad8a8d945 100644 --- a/magicblock-accounts/Cargo.toml +++ b/magicblock-accounts/Cargo.toml @@ -12,6 +12,7 @@ async-trait = { workspace = true } conjunto-transwise = { workspace = true } magicblock-delegation-program = { workspace = true } futures-util = { workspace = true } +itertools = { workspace = true } log = { workspace = true } magicblock-account-fetcher = { workspace = true } magicblock-account-updates = { workspace = true } diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 112efedb4..9c76449a5 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -16,6 +16,7 @@ use conjunto_transwise::{ AccountChainSnapshotShared, AccountChainState, CommitFrequency, }; use futures_util::future::{try_join, try_join_all}; +use itertools::Itertools; use log::*; use magicblock_account_cloner::{AccountCloner, AccountClonerOutput}; use magicblock_accounts_api::InternalAccountProvider; @@ -406,13 +407,14 @@ where .collect::>(); committees + .into_iter() .chunks(MAX_PROCESS_PER_TX as usize) + .into_iter() .map(|committees| { let committees = committees - .iter() - .cloned() .map(CommittedAccountV2::from) - .collect(); + .collect::>(); + ScheduledBaseIntent { // isn't important but shall be unique id: MESSAGE_ID.fetch_sub(1, Ordering::Relaxed), diff --git a/magicblock-accounts/src/traits.rs b/magicblock-accounts/src/traits.rs index 9a3b1942d..707c57735 100644 --- a/magicblock-accounts/src/traits.rs +++ b/magicblock-accounts/src/traits.rs @@ -28,8 +28,6 @@ pub trait ScheduledCommitsProcessor: Send + Sync + 'static { fn stop(&self); } -// TODO(edwin): remove this -#[derive(Clone)] pub struct AccountCommittee { /// The pubkey of the account to be committed. pub pubkey: Pubkey, diff --git a/magicblock-committor-service/CHANGES.md b/magicblock-committor-service/CHANGES.md deleted file mode 100644 index ffb89c253..000000000 --- a/magicblock-committor-service/CHANGES.md +++ /dev/null @@ -1,6 +0,0 @@ -- Persister changed from reqid & bundle_id format to message_id. Meaning row created per message. A particular Row tracking lifespan of Intent -- Persister will be passed along into Executors & Scheduler for them to update Intent statuses during execution -- No notion of bundles anymore, we represent things by Intent id -- AccountsManager doesn't use custom `AccountCommitter` for periodic commits of accounts but instead uses CommittorService -- RemoteScheduledCommitsProcessor extracted from AccountsManager since has nothing to do with it -- \ No newline at end of file diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index 471b26510..fea5fb402 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -192,9 +192,11 @@ where self.inner.lock().expect(POISONED_INNER_MSG).schedule(intent) }, else => { - // Shouldn't be possible - // If no executors spawned -> we can receive - // If can't receive -> there are running executors + // Shouldn't be possible: + // 1. If no executors spawned -> we can receive + // 2. If can't receive -> there are MAX_EXECUTORS running executors + // We can't receive new message as there's no available Executor + // that could pick up the task. unreachable!("next_scheduled_intent") } }; diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs index 9a905fd80..ab6224336 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs @@ -78,9 +78,6 @@ impl IntentScheduler { /// Returns [`ScheduledBaseIntent`] if intent can be executed, /// otherwise consumes it and enqueues - /// - /// CRITICAL: IntentIds should be unique - /// Intent should be scheduled once! pub fn schedule( &mut self, base_intent: ScheduledBaseIntentWrapper, diff --git a/magicblock-committor-service/src/intent_executor/error.rs b/magicblock-committor-service/src/intent_executor/error.rs index bb472203c..f8aecbd16 100644 --- a/magicblock-committor-service/src/intent_executor/error.rs +++ b/magicblock-committor-service/src/intent_executor/error.rs @@ -24,7 +24,7 @@ pub enum IntentExecutorError { FailedToFitError, #[error("SignerError: {0}")] SignerError(#[from] SignerError), - // TODO: remove once proper retries introduced + // TODO(edwin): remove once proper retries introduced #[error("TaskBuilderError: {0}")] TaskBuilderError(#[from] TaskBuilderError), #[error("FailedToCommitError: {err}")] diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index 9d7011888..16ace2d5f 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use async_trait::async_trait; -use log::{debug, error, warn}; +use log::{error, trace, warn}; use magicblock_program::{ magic_scheduled_base_intent::ScheduledBaseIntent, validator::validator_authority, @@ -138,11 +138,11 @@ where &self.authority.pubkey(), persister, )? { - debug!("Executing intent in single stage"); + trace!("Executing intent in single stage"); self.execute_single_stage(&single_tx_strategy, persister) .await } else { - debug!("Executing intent in two stages"); + trace!("Executing intent in two stages"); // Build strategy for Commit stage let commit_strategy = TaskStrategist::build_strategy( commit_tasks, @@ -168,7 +168,7 @@ where /// Optimization: executes Intent in single stage /// where Commit & Finalize are united - // TODO: remove once challenge window introduced + // TODO(edwin): remove once challenge window introduced async fn execute_single_stage( &self, transaction_strategy: &TransactionStrategy, @@ -191,7 +191,7 @@ where IntentExecutorError::FailedToCommitError { err, signature } })?; - debug!("Single stage intent executed: {}", signature); + trace!("Single stage intent executed: {}", signature); Ok(ExecutionOutput::SingleStage(signature)) } @@ -215,7 +215,7 @@ where .map_err(|(err, signature)| { IntentExecutorError::FailedToCommitError { err, signature } })?; - debug!("Commit stage succeeded: {}", commit_signature); + trace!("Commit stage succeeded: {}", commit_signature); // Prepare everything for Finalize stage execution let prepared_finalize_message = self @@ -234,7 +234,7 @@ where finalize_signature, } })?; - debug!("Finalize stage succeeded: {}", finalize_signature); + trace!("Finalize stage succeeded: {}", finalize_signature); Ok(ExecutionOutput::TwoStage { commit_signature, @@ -281,6 +281,8 @@ where Ok(result.into_signature()) } + /// Flushes result into presistor + /// The result will be propagated down to callers fn persist_result( persistor: &P, result: &IntentExecutorResult, diff --git a/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs b/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs index 83b5d34a5..da080fbc1 100644 --- a/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs +++ b/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs @@ -72,7 +72,7 @@ impl CacheTaskInfoFetcher { return err } Err(TaskInfoFetcherError::MagicBlockRpcClientError(err)) => { - // TODO: RPC error handlings should be more robust + // TODO(edwin0: RPC error handlings should be more robust last_err = TaskInfoFetcherError::MagicBlockRpcClientError(err) } diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 189b8712e..379801186 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -81,7 +81,7 @@ impl TaskStrategist { /// Attempt to use ALTs for ALL keys in tx /// Returns `true` if ALTs make tx fit, otherwise `false` - /// TODO: optimize to use only necessary amount of pubkeys + /// TODO(edwin): optimize to use only necessary amount of pubkeys pub fn attempt_lookup_tables(tasks: &[Box]) -> bool { let placeholder = Keypair::new(); // Gather all involved keys in tx @@ -382,7 +382,7 @@ mod tests { #[test] fn test_build_strategy_with_lookup_tables_when_needed() { - // TODO: ALSO MAX NUMBER OF TASKS fit with ALTs! + // Also max number of committed accounts fit with ALTs! const NUM_COMMITS: u64 = 22; let validator = Pubkey::new_unique(); diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index d5cf35e85..ab3ef02a2 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -251,6 +251,7 @@ impl BaseTask for BufferTask { // and we don't use any fs writers, so the only error that may occur here is of kind // OutOfMemory or WriteZero. This is impossible due to: // Chunks::new panics if its size exceeds MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE or 10_240 + // https://github.com/near/borsh-rs/blob/f1b75a6b50740bfb6231b7d0b1bd93ea58ca5452/borsh/src/ser/helpers.rs#L59 let chunks_account_size = borsh::object_length(&chunks).unwrap() as u64; let buffer_account_size = committed_account.account.data.len() as u64; diff --git a/magicblock-committor-service/src/tasks/utils.rs b/magicblock-committor-service/src/tasks/utils.rs index 93b8afa1d..ebc5a4541 100644 --- a/magicblock-committor-service/src/tasks/utils.rs +++ b/magicblock-committor-service/src/tasks/utils.rs @@ -15,21 +15,6 @@ use solana_sdk::{ use crate::tasks::{task_strategist::TaskStrategistResult, tasks::BaseTask}; -/// Returns [`Vec`] where all TX accounts stored in ALT -pub fn estimate_lookup_tables_for_tx( - transaction: &VersionedTransaction, -) -> Vec { - transaction - .message - .static_account_keys() - .chunks(256) - .map(|addresses| AddressLookupTableAccount { - key: Pubkey::new_unique(), - addresses: addresses.to_vec(), - }) - .collect() -} - pub struct TransactionUtils; impl TransactionUtils { pub fn dummy_lookup_table( diff --git a/magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs b/magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs index 59482cc6a..7d9ac76a2 100644 --- a/magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs +++ b/magicblock-committor-service/src/transaction_preparator/delivery_preparator.rs @@ -101,7 +101,7 @@ impl DeliveryPreparator { ); // Initialize buffer account. Init + reallocs - self.initialize_buffer_account(authority, task, &preparation_info) + self.initialize_buffer_account(authority, &preparation_info) .await?; // Persist initialization success @@ -113,7 +113,7 @@ impl DeliveryPreparator { update_status, ); - // Writing chunks with some retries. Stol + // Writing chunks with some retries self.write_buffer_with_retries(authority, &preparation_info, 5) .await?; // Persist that buffer account initiated successfully @@ -133,7 +133,6 @@ impl DeliveryPreparator { async fn initialize_buffer_account( &self, authority: &Keypair, - _task: &dyn BaseTask, preparation_info: &TaskPreparationInfo, ) -> DeliveryPreparatorResult<(), InternalError> { let preparation_instructions = chunk_realloc_ixs( diff --git a/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs index 8e026b1d0..4bc5110d3 100644 --- a/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs @@ -93,8 +93,7 @@ impl TransactionPreparator for TransactionPreparatorV1 { &tx_strategy.optimized_tasks, self.compute_budget_config.compute_unit_price, &dummy_lookup_tables, - )? - .message; + )?; } // Pre tx preparations. Create buffer accs + lookup tables diff --git a/magicblock-core/src/magic_program/instruction.rs b/magicblock-core/src/magic_program/instruction.rs index 098e4f0d3..2da6e1558 100644 --- a/magicblock-core/src/magic_program/instruction.rs +++ b/magicblock-core/src/magic_program/instruction.rs @@ -71,26 +71,7 @@ pub enum MagicBlockInstruction { ScheduleBaseIntent(MagicBaseIntentArgs), } -// TODO: why that exists? -#[allow(unused)] impl MagicBlockInstruction { - pub fn index(&self) -> u8 { - use MagicBlockInstruction::*; - match self { - ModifyAccounts(_) => 0, - ScheduleCommit => 1, - ScheduleCommitAndUndelegate => 2, - AcceptScheduleCommits => 3, - ScheduledCommitSent(_) => 4, - ScheduleBaseIntent(_) => 5, - } - } - - pub fn discriminant(&self) -> [u8; 4] { - let idx = self.index(); - [idx, 0, 0, 0] - } - pub fn try_to_vec(&self) -> Result, bincode::Error> { bincode::serialize(self) } diff --git a/magicblock-rpc/src/traits/rpc_full.rs b/magicblock-rpc/src/traits/rpc_full.rs index 6b83acce1..2728e1051 100644 --- a/magicblock-rpc/src/traits/rpc_full.rs +++ b/magicblock-rpc/src/traits/rpc_full.rs @@ -185,18 +185,3 @@ pub trait Full { pubkey_strs: Option>, ) -> Result>; } - -// ideally -// 1. We add all of ScheduledBaseIntent on baselayer -// 2. We finalize them: -// 1. Runs committs per account -// 2. Runs actions(undelegate one actions) -// - -// That means -// Commits - shall be atomic(1 tx) -// Finalization - Shall be one per batch - -// Current solution: -// 1. We create a single commit tx, with multiple ixs -// 2. We create "finalize" tx diff --git a/magicblock-table-mania/src/lookup_table.rs b/magicblock-table-mania/src/lookup_table.rs deleted file mode 100644 index dd0f6b0f3..000000000 --- a/magicblock-table-mania/src/lookup_table.rs +++ /dev/null @@ -1,537 +0,0 @@ -use std::{fmt, sync::Mutex}; - -use log::*; -use magicblock_rpc_client::{ - MagicBlockRpcClientError, MagicBlockSendTransactionConfig, - MagicblockRpcClient, -}; -use solana_pubkey::Pubkey; -use solana_sdk::{ - address_lookup_table as alt, - address_lookup_table::state::{ - LookupTableMeta, LOOKUP_TABLE_MAX_ADDRESSES, - }, - clock::Slot, - commitment_config::CommitmentLevel, - signature::{Keypair, Signature}, - signer::Signer, - slot_hashes::MAX_ENTRIES, - transaction::Transaction, -}; - -use crate::{ - derive_keypair, - error::{TableManiaError, TableManiaResult}, -}; - -/// Determined via trial and error. The keys themselves take up -/// 27 * 32 bytes = 864 bytes. -pub const MAX_ENTRIES_AS_PART_OF_EXTEND: u64 = 27; - -#[derive(Debug)] -pub enum LookupTable { - Active { - derived_auth: Keypair, - table_address: Pubkey, - pubkeys: Mutex>, - creation_slot: u64, - creation_sub_slot: u64, - init_signature: Signature, - extend_signatures: Vec, - }, - Deactivated { - derived_auth: Keypair, - table_address: Pubkey, - deactivation_slot: u64, - deactivate_signature: Signature, - }, -} - -impl fmt::Display for LookupTable { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Active { - derived_auth, - table_address, - pubkeys, - creation_slot, - creation_sub_slot, - init_signature, - extend_signatures, - } => { - let comma_separated_pubkeys = pubkeys - .lock() - .expect("pubkeys mutex poisoned") - .iter() - .map(|x| x.to_string()) - .collect::>() - .join(", "); - let comma_separated_sigs = extend_signatures - .iter() - .map(|x| x.to_string()) - .collect::>() - .join(", "); - write!( - f, - "LookupTable: Active {{ - derived_auth: {} - table_address: {} - pubkeys: {} - creation_slot: {} - creation_sub_slot: {} - init_signature: {} - extend_signatures: {} -}}", - derived_auth.pubkey(), - table_address, - comma_separated_pubkeys, - creation_slot, - creation_sub_slot, - init_signature, - comma_separated_sigs - ) - } - Self::Deactivated { - derived_auth, - table_address, - deactivation_slot, - deactivate_signature, - } => { - write!( - f, - "LookupTable: Deactivated {{ derived_auth: {}, table_address: {}, deactivation_slot: {}, deactivate_signature: {} }}", - derived_auth.pubkey(), - table_address, - deactivation_slot, - deactivate_signature, - ) - } - } - } -} - -impl LookupTable { - pub fn derived_auth(&self) -> &Keypair { - match self { - Self::Active { derived_auth, .. } => derived_auth, - Self::Deactivated { derived_auth, .. } => derived_auth, - } - } - pub fn table_address(&self) -> &Pubkey { - match self { - Self::Active { table_address, .. } => table_address, - Self::Deactivated { table_address, .. } => table_address, - } - } - - /// All pubkeys requested, no matter of the `reqid`. - /// The same pubkey might be included twice if requested with different `reqid`. - pub fn pubkeys(&self) -> Option> { - match self { - Self::Active { pubkeys, .. } => { - Some(pubkeys.lock().expect("pubkeys mutex poisoned").to_vec()) - } - Self::Deactivated { .. } => None, - } - } - - pub fn creation_slot(&self) -> Option { - match self { - Self::Active { creation_slot, .. } => Some(*creation_slot), - Self::Deactivated { .. } => None, - } - } - - pub fn has_more_capacity(&self) -> bool { - self.pubkeys() - .is_some_and(|x| x.len() < LOOKUP_TABLE_MAX_ADDRESSES) - } - - pub fn contains(&self, pubkey: &Pubkey, _reqid: u64) -> bool { - match self { - Self::Active { pubkeys, .. } => pubkeys - .lock() - .expect("pubkeys mutex poisoned") - .contains(pubkey), - Self::Deactivated { .. } => false, - } - } - - /// Returns `true` if the we requested to deactivate this table. - /// NOTE: this doesn't mean that the deactivation period passed, thus - /// the table could still be considered _deactivating_ on chain. - pub fn deactivate_triggered(&self) -> bool { - use LookupTable::*; - matches!(self, Deactivated { .. }) - } - - pub fn is_active(&self) -> bool { - use LookupTable::*; - matches!(self, Active { .. }) - } - - pub fn derive_keypair( - authority: &Keypair, - slot: Slot, - sub_slot: Slot, - ) -> Keypair { - derive_keypair::derive_keypair(authority, slot, sub_slot) - } - - /// Initializes an address lookup table deriving its authority from the provided - /// [authority] keypair. The table is extended with the provided [pubkeys]. - /// The [authority] keypair pays for the transaction. - /// - /// - **rpc_client**: RPC client to use for sending transactions - /// - **authority**: Keypair to derive the authority of the lookup table - /// - **latest_slot**: the on chain slot at which we are creating the table - /// - **sub_slot**: a bump to allow creating multiple lookup tables with the same authority - /// at the same slot - /// - **pubkeys**: to extend the lookup table respecting - /// solana_sdk::address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES] - /// after it is initialized - /// - **reqid**: id of the request adding the pubkeys - pub async fn init( - rpc_client: &MagicblockRpcClient, - authority: &Keypair, - latest_slot: Slot, - sub_slot: Slot, - pubkeys: &[Pubkey], - _reqid: u64, - ) -> TableManiaResult { - check_max_pubkeys(pubkeys)?; - - let derived_auth = - Self::derive_keypair(authority, latest_slot, sub_slot); - - let (create_ix, table_address) = alt::instruction::create_lookup_table( - derived_auth.pubkey(), - authority.pubkey(), - latest_slot, - ); - - let end = pubkeys.len().min(LOOKUP_TABLE_MAX_ADDRESSES); - let extend_ix = alt::instruction::extend_lookup_table( - table_address, - derived_auth.pubkey(), - Some(authority.pubkey()), - pubkeys[..end].to_vec(), - ); - - let ixs = vec![create_ix, extend_ix]; - let latest_blockhash = rpc_client.get_latest_blockhash().await?; - let tx = Transaction::new_signed_with_payer( - &ixs, - Some(&authority.pubkey()), - &[authority, &derived_auth], - latest_blockhash, - ); - - let outcome = rpc_client - .send_transaction(&tx, &Self::get_commitment(rpc_client)) - .await?; - let (signature, error) = outcome.into_signature_and_error(); - if let Some(error) = &error { - error!( - "Error initializing lookup table: {:?} ({})", - error, signature - ); - return Err(MagicBlockRpcClientError::SentTransactionError( - error.clone(), - signature, - ) - .into()); - } - - Ok(Self::Active { - derived_auth, - table_address, - pubkeys: Mutex::new(pubkeys.to_vec()), - creation_slot: latest_slot, - creation_sub_slot: sub_slot, - init_signature: signature, - extend_signatures: vec![], - }) - } - - fn get_commitment( - rpc_client: &MagicblockRpcClient, - ) -> MagicBlockSendTransactionConfig { - use CommitmentLevel::*; - match rpc_client.commitment_level() { - Processed => MagicBlockSendTransactionConfig::ensure_processed(), - Confirmed | Finalized => { - MagicBlockSendTransactionConfig::ensure_committed() - } - } - } - - /// Extends this lookup table with the provided [pubkeys]. - /// The transaction is signed with the [Self::derived_auth]. - /// - /// - **rpc_client**: RPC client to use for sending the extend transaction - /// - **authority**: payer for the extend transaction - /// - **pubkeys**: to extend the lookup table with - /// - **reqid**: id of the request adding the pubkeys - pub async fn extend( - &self, - rpc_client: &MagicblockRpcClient, - authority: &Keypair, - extra_pubkeys: &[Pubkey], - _reqid: u64, - ) -> TableManiaResult<()> { - use LookupTable::*; - - check_max_pubkeys(extra_pubkeys)?; - - let pubkeys = match self { - Active { pubkeys, .. } => pubkeys, - Deactivated { .. } => { - return Err(TableManiaError::CannotExtendDeactivatedTable( - *self.table_address(), - )); - } - }; - let extend_ix = alt::instruction::extend_lookup_table( - *self.table_address(), - self.derived_auth().pubkey(), - Some(authority.pubkey()), - extra_pubkeys.to_vec(), - ); - - let ixs = vec![extend_ix]; - let latest_blockhash = rpc_client.get_latest_blockhash().await?; - let tx = Transaction::new_signed_with_payer( - &ixs, - Some(&authority.pubkey()), - &[authority, self.derived_auth()], - latest_blockhash, - ); - - let outcome = rpc_client - .send_transaction(&tx, &Self::get_commitment(rpc_client)) - .await?; - let (signature, error) = outcome.into_signature_and_error(); - if let Some(error) = &error { - error!("Error extending lookup table: {:?} ({})", error, signature); - return Err(MagicBlockRpcClientError::SentTransactionError( - error.clone(), - signature, - ) - .into()); - } else { - pubkeys - .lock() - .expect("pubkeys mutex poisoned") - .extend(extra_pubkeys); - } - - Ok(()) - } - - /// Extends this lookup table with the portion of the provided [pubkeys] that - /// fits into the table respecting [solana_sdk::address_lookup_table::state::LOOKUP_TABLE_MAX_ADDRESSES]. - /// - /// The transaction is signed with the [Self::derived_auth]. - /// - /// - **rpc_client**: RPC client to use for sending the extend transaction - /// - **authority**: payer for the extend transaction - /// - **pubkeys**: to extend the lookup table with - /// - **reqid**: id of the request adding the pubkeys - /// - /// Returns: the pubkeys that were added to the table - pub async fn extend_respecting_capacity( - &self, - rpc_client: &MagicblockRpcClient, - authority: &Keypair, - pubkeys: &[Pubkey], - reqid: u64, - ) -> TableManiaResult> { - let Some(len) = self.pubkeys().map(|x| x.len()) else { - return Err(TableManiaError::CannotExtendDeactivatedTable( - *self.table_address(), - )); - }; - let remaining_capacity = LOOKUP_TABLE_MAX_ADDRESSES.saturating_sub(len); - if remaining_capacity == 0 { - return Ok(vec![]); - } - - let storing = if pubkeys.len() >= remaining_capacity { - let (storing, _) = pubkeys.split_at(remaining_capacity); - storing - } else { - pubkeys - }; - - let res = self.extend(rpc_client, authority, storing, reqid).await; - res.map(|_| storing.to_vec()) - } - - /// Deactivates this lookup table. - /// - /// - **rpc_client**: RPC client to use for sending the deactivate transaction - /// - **authority**: pays for the deactivate transaction - pub async fn deactivate( - &mut self, - rpc_client: &MagicblockRpcClient, - authority: &Keypair, - ) -> TableManiaResult<()> { - let deactivate_ix = alt::instruction::deactivate_lookup_table( - *self.table_address(), - self.derived_auth().pubkey(), - ); - let ixs = vec![deactivate_ix]; - let latest_blockhash = rpc_client.get_latest_blockhash().await?; - let tx = Transaction::new_signed_with_payer( - &ixs, - Some(&authority.pubkey()), - &[authority, self.derived_auth()], - latest_blockhash, - ); - - let outcome = rpc_client - .send_transaction(&tx, &Self::get_commitment(rpc_client)) - .await?; - let (signature, error) = outcome.into_signature_and_error(); - if let Some(error) = &error { - error!( - "Error deactivating lookup table: {:?} ({})", - error, signature - ); - } - - let slot = rpc_client.get_slot().await?; - *self = Self::Deactivated { - derived_auth: self.derived_auth().insecure_clone(), - table_address: *self.table_address(), - deactivation_slot: slot, - deactivate_signature: signature, - }; - - Ok(()) - } - - /// Checks if this lookup table is deactivated via the following: - /// - /// 1. was [Self::deactivate] called - /// 2. is the [LookupTable::Deactivated::deactivation_slot] far enough in the past - pub async fn is_deactivated( - &self, - rpc_client: &MagicblockRpcClient, - current_slot: Option, - ) -> bool { - let Self::Deactivated { - deactivation_slot, .. - } = self - else { - return false; - }; - let slot = { - if let Some(slot) = current_slot { - slot - } else { - let Ok(slot) = rpc_client.get_slot().await else { - return false; - }; - slot - } - }; - // NOTE: the solana explorer will show an account as _deactivated_ once we deactivate it - // even though it is actually _deactivating_ - // I tried to shorten the wait here but found that this is the minimum time needed - // for the table to be considered fully _deactivated_ - let deactivated_slot = deactivation_slot + MAX_ENTRIES as u64; - trace!( - "'{}' deactivates in {} slots", - self.table_address(), - deactivated_slot.saturating_sub(slot), - ); - deactivated_slot <= slot - } - - pub async fn is_closed( - &self, - rpc_client: &MagicblockRpcClient, - ) -> TableManiaResult { - let acc = rpc_client.get_account(self.table_address()).await?; - Ok(acc.is_none()) - } - - /// Checks if the table was deactivated and if so closes the table account. - /// - /// - **rpc_client**: RPC client to use for sending the close transaction - /// - **authority**: pays for the close transaction and is refunded the - /// table account rent - /// - **current_slot**: the current slot to use for checking deactivation - pub async fn close( - &self, - rpc_client: &MagicblockRpcClient, - authority: &Keypair, - current_slot: Option, - ) -> TableManiaResult { - if !self.is_deactivated(rpc_client, current_slot).await { - return Ok(false); - } - - let close_ix = alt::instruction::close_lookup_table( - *self.table_address(), - self.derived_auth().pubkey(), - authority.pubkey(), - ); - let ixs = vec![close_ix]; - let latest_blockhash = rpc_client.get_latest_blockhash().await?; - let tx = Transaction::new_signed_with_payer( - &ixs, - Some(&authority.pubkey()), - &[authority, self.derived_auth()], - latest_blockhash, - ); - - let outcome = rpc_client - .send_transaction(&tx, &Self::get_commitment(rpc_client)) - .await?; - - let (signature, error) = outcome.into_signature_and_error(); - if let Some(error) = &error { - debug!( - "Error closing lookup table: {:?} ({}) - may need longer deactivation time", - error, signature - ); - } - self.is_closed(rpc_client).await - } - - pub async fn get_meta( - &self, - rpc_client: &MagicblockRpcClient, - ) -> TableManiaResult> { - Ok(rpc_client - .get_lookup_table_meta(self.table_address()) - .await?) - } - - pub async fn get_chain_pubkeys( - &self, - rpc_client: &MagicblockRpcClient, - ) -> TableManiaResult>> { - Self::get_chain_pubkeys_for(rpc_client, self.table_address()).await - } - - pub async fn get_chain_pubkeys_for( - rpc_client: &MagicblockRpcClient, - table_address: &Pubkey, - ) -> TableManiaResult>> { - Ok(rpc_client.get_lookup_table_addresses(table_address).await?) - } -} - -fn check_max_pubkeys(pubkeys: &[Pubkey]) -> TableManiaResult<()> { - if pubkeys.len() > MAX_ENTRIES_AS_PART_OF_EXTEND as usize { - return Err(TableManiaError::MaxExtendPubkeysExceeded( - MAX_ENTRIES_AS_PART_OF_EXTEND as usize, - pubkeys.len(), - )); - } - Ok(()) -} diff --git a/programs/magicblock/src/magic_scheduled_base_intent.rs b/programs/magicblock/src/magic_scheduled_base_intent.rs index ab59d65ab..520952220 100644 --- a/programs/magicblock/src/magic_scheduled_base_intent.rs +++ b/programs/magicblock/src/magic_scheduled_base_intent.rs @@ -6,15 +6,15 @@ use magicblock_core::magic_program::args::{ }; use serde::{Deserialize, Serialize}; use solana_log_collector::ic_msg; -use solana_program_runtime::{ - __private::{Hash, InstructionError, ReadableAccount, TransactionContext}, - invoke_context::InvokeContext, -}; +use solana_program_runtime::invoke_context::InvokeContext; use solana_sdk::{ - account::{Account, AccountSharedData}, + account::{Account, AccountSharedData, ReadableAccount}, clock::Slot, + hash::Hash, + instruction::InstructionError, pubkey::Pubkey, transaction::Transaction, + transaction_context::TransactionContext, }; use crate::{ diff --git a/programs/magicblock/src/schedule_transactions/mod.rs b/programs/magicblock/src/schedule_transactions/mod.rs index f3503ed4a..89fd6e981 100644 --- a/programs/magicblock/src/schedule_transactions/mod.rs +++ b/programs/magicblock/src/schedule_transactions/mod.rs @@ -15,9 +15,8 @@ pub use process_scheduled_commit_sent::{ process_scheduled_commit_sent, register_scheduled_commit_sent, SentCommit, }; use solana_log_collector::ic_msg; -use solana_program_runtime::{ - __private::InstructionError, invoke_context::InvokeContext, -}; +use solana_program_runtime::invoke_context::InvokeContext; +use solana_sdk::instruction::InstructionError; use crate::utils::accounts::get_instruction_pubkey_with_idx; diff --git a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs index 60303b341..48260f781 100644 --- a/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs +++ b/programs/magicblock/src/schedule_transactions/process_accept_scheduled_commits.rs @@ -1,11 +1,10 @@ use std::collections::HashSet; use solana_log_collector::ic_msg; -use solana_program_runtime::{ - __private::{InstructionError, ReadableAccount}, - invoke_context::InvokeContext, +use solana_program_runtime::invoke_context::InvokeContext; +use solana_sdk::{ + account::ReadableAccount, instruction::InstructionError, pubkey::Pubkey, }; -use solana_sdk::pubkey::Pubkey; use crate::{ schedule_transactions, diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index 5bdb1d7bc..a6c5a65bf 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -3685,6 +3685,7 @@ dependencies = [ "async-trait", "conjunto-transwise", "futures-util", + "itertools 0.14.0", "log", "magicblock-account-cloner", "magicblock-account-dumper", From 5b16f7eb6ce4283901bd10de37b3f75f8117d328 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 28 Aug 2025 20:11:32 +0900 Subject: [PATCH 196/199] refactor: cargo toml sort --- Cargo.toml | 20 ++++++++-------- magicblock-committor-service/Cargo.toml | 21 ++++++++--------- .../schedule_base_intent_processor.rs | 2 +- test-integration/Cargo.toml | 23 +++++++++---------- test-integration/Makefile | 9 +++++++- .../src/processor/call_handler.rs | 3 +-- .../tests/test_transaction_preparator.rs | 4 ++-- 7 files changed, 43 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 75d3a7fc0..d2fbadd5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,14 +66,14 @@ borsh = { version = "1.5.1", features = ["derive", "unstable__schema"] } borsh-derive = "1.5.1" bs58 = "0.4.0" byteorder = "1.5.0" -cargo-lock = "10.0.0" cargo-expand = "1" +cargo-lock = "10.0.0" clap = "4.5.40" -convert_case = "0.8.0" conjunto-transwise = { git = "https://github.com/magicblock-labs/conjunto.git", rev = "bf82b45" } console-subscriber = "0.2.0" -crossbeam-channel = "0.5.11" const_format = "0.2.34" +convert_case = "0.8.0" +crossbeam-channel = "0.5.11" dyn-clone = "1.0.20" ed25519-dalek = "1.0.1" enum-iterator = "1.5.0" @@ -101,7 +101,9 @@ lazy_static = "1.4.0" libc = "0.2.153" libloading = "0.7.4" log = "0.4.20" +lru = "0.16.0" macrotest = "1" +magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "ea04d46", default-features = false } magicblock-account-cloner = { path = "./magicblock-account-cloner" } magicblock-account-dumper = { path = "./magicblock-account-dumper" } magicblock-account-fetcher = { path = "./magicblock-account-fetcher" } @@ -120,7 +122,6 @@ magicblock-config-helpers = { path = "./magicblock-config-helpers" } magicblock-config-macro = { path = "./magicblock-config-macro" } magicblock-core = { path = "./magicblock-core" } magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "00d720", features = ["no-entrypoint"] } -magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "ea04d46", default-features = false } magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" } magicblock-ledger = { path = "./magicblock-ledger" } magicblock-metrics = { path = "./magicblock-metrics" } @@ -149,20 +150,20 @@ protobuf-src = "1.1" quote = "1.0" rand = "0.8.5" rayon = "1.10.0" -rustc_version = "0.4" rusqlite = { version = "0.34.0", features = ["bundled"] } # bundled sqlite 3.44 +rustc_version = "0.4" semver = "1.0.22" serde = "1.0.217" serde_derive = "1.0" serde_json = "1.0" sha3 = "0.10.8" solana-account = { git = "https://github.com/magicblock-labs/solana-account.git", rev = "176540a" } -solana-accounts-db = { version = "2.2" } solana-account-decoder = { version = "2.2" } +solana-accounts-db = { version = "2.2" } solana-address-lookup-table-program = { version = "2.2" } solana-bpf-loader-program = { version = "2.2" } -solana-compute-budget-program = { version = "2.2" } solana-compute-budget-instruction = { version = "2.2" } +solana-compute-budget-program = { version = "2.2" } solana-cost-model = { version = "2.2" } solana-frozen-abi-macro = { version = "2.2" } solana-geyser-plugin-interface = { version = "2.2", package = "agave-geyser-plugin-interface" } @@ -176,17 +177,17 @@ solana-program = "2.2" solana-program-runtime = { version = "2.2" } solana-program-test = "2.2" solana-pubkey = { version = "2.2" } -solana-rayon-threadlimit = { version = "2.2" } solana-pubsub-client = { version = "2.2" } +solana-rayon-threadlimit = { version = "2.2" } solana-rpc = "2.2" solana-rpc-client = { version = "2.2" } solana-rpc-client-api = { version = "2.2" } solana-sdk = { version = "2.2" } +solana-storage-proto = { path = "storage-proto" } solana-svm = { git = "https://github.com/magicblock-labs/magicblock-svm.git", rev = "e93eb57", features = [ "dev-context-only-utils", ] } solana-svm-transaction = { version = "2.2" } -solana-storage-proto = { path = "storage-proto" } solana-system-program = { version = "2.2" } solana-timings = "2.2" solana-transaction-status = { version = "2.2" } @@ -196,7 +197,6 @@ spl-token-2022 = "=6.0" static_assertions = "1.1.0" strum = "0.24" strum_macros = "0.24" -lru = "0.16.0" syn = "2.0" tempfile = "3.10.1" test-tools = { path = "./test-tools" } diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index 4ad6482e5..caf2f2a85 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -11,6 +11,15 @@ edition.workspace = true doctest = false [dependencies] +anyhow = { workspace = true } +async-trait = { workspace = true } +base64 = { workspace = true } +bincode = { workspace = true } +borsh = { workspace = true } +dyn-clone = { workspace = true } +futures-util = { workspace = true } +log = { workspace = true } +lru = { workspace = true } magicblock-committor-program = { workspace = true, features = [ "no-entrypoint", ] } @@ -20,16 +29,6 @@ magicblock-delegation-program = { workspace = true, features = [ magicblock-program = { workspace = true } magicblock-rpc-client = { workspace = true } magicblock-table-mania = { workspace = true } - -async-trait = { workspace = true } -anyhow = { workspace = true } -base64 = { workspace = true } -bincode = { workspace = true } -borsh = { workspace = true } -dyn-clone = { workspace = true } -futures-util = { workspace = true } -log = { workspace = true } -lru = { workspace = true } rusqlite = { workspace = true } solana-account = { workspace = true } solana-pubkey = { workspace = true } @@ -38,10 +37,10 @@ solana-rpc-client-api = { workspace = true } solana-sdk = { workspace = true } solana-transaction-status-client-types = { workspace = true } static_assertions = { workspace = true } +tempfile = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true } tokio-util = { workspace = true } -tempfile = { workspace = true } [dev-dependencies] lazy_static = { workspace = true } diff --git a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs index f532fa77a..6e11da074 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs @@ -27,8 +27,8 @@ pub fn change_owner_for_undelegated_accounts( MagicBaseIntentArgs::BaseActions(_) => return Ok(()), }; - // TODO: proper explanation // Change owner to dlp + // Undelegated it immediately becomes immutable in our validator. commited_accounts_ref .into_iter() .for_each(|(_, account_ref)| { diff --git a/test-integration/Cargo.toml b/test-integration/Cargo.toml index ff61c33c3..61262704c 100644 --- a/test-integration/Cargo.toml +++ b/test-integration/Cargo.toml @@ -26,36 +26,36 @@ version = "0.0.0" edition = "2021" [workspace.dependencies] -test-ledger-restore = { path = "./test-ledger-restore" } - -async-trait = "0.1.77" anyhow = "1.0.86" +async-trait = "0.1.77" borsh = { version = "1.2.1", features = ["derive", "unstable__schema"] } cleanass = "0.0.1" ctrlc = "3.4.7" ephemeral-rollups-sdk = { git = "https://github.com/magicblock-labs/ephemeral-rollups-sdk.git", rev = "e461a07" } integration-test-tools = { path = "test-tools" } isocountry = "0.3.2" +lazy_static = "1.4.0" log = "0.4.20" -magicblock-api = { path = "../magicblock-api" } +magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "ea04d46", default-features = false } magicblock-accounts-db = { path = "../magicblock-accounts-db", features = [ "dev-tools", ] } -magic-domain-program = { git = "https://github.com/magicblock-labs/magic-domain-program.git", rev = "ea04d46", default-features = false } -magicblock-config = { path = "../magicblock-config" } -magicblock-core = { path = "../magicblock-core" } +magicblock-api = { path = "../magicblock-api" } magicblock-committor-program = { path = "../magicblock-committor-program", features = [ "no-entrypoint", ] } -magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "00d720", features = ["no-entrypoint"] } magicblock-committor-service = { path = "../magicblock-committor-service" } +magicblock-config = { path = "../magicblock-config" } +magicblock-core = { path = "../magicblock-core" } +magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "00d720", features = ["no-entrypoint"] } +magicblock-program = { path = "../programs/magicblock" } magicblock-rpc-client = { path = "../magicblock-rpc-client" } magicblock-table-mania = { path = "../magicblock-table-mania" } -magicblock-program = { path = "../programs/magicblock" } paste = "1.0" program-flexi-counter = { path = "./programs/flexi-counter" } program-schedulecommit = { path = "programs/schedulecommit" } program-schedulecommit-security = { path = "programs/schedulecommit-security" } +rand = "0.8.5" rayon = "1.10.0" schedulecommit-client = { path = "schedulecommit/client" } serde = "1.0.217" @@ -71,11 +71,10 @@ solana-transaction-status = "2.2" teepee = "0.0.1" tempfile = "3.10.1" test-config = { path = "test-config" } +test-ledger-restore = { path = "./test-ledger-restore" } test-tools-core = { path = "../test-tools-core" } -toml = "0.8.13" -lazy_static = "1.4.0" tokio = "1.0" -rand = "0.8.5" +toml = "0.8.13" [patch.crates-io] # some solana dependencies have solana-storage-proto as dependency diff --git a/test-integration/Makefile b/test-integration/Makefile index 77ccb4962..67f433a9a 100644 --- a/test-integration/Makefile +++ b/test-integration/Makefile @@ -127,7 +127,14 @@ setup-config-devnet: test-schedule-intents: RUN_TESTS=schedule_intents \ $(MAKE) test - +setup-schedule-intents-devnet: + RUN_TESTS=schedule_intents \ + SETUP_ONLY=devnet \ + $(MAKE) test +setup-schedule-intents-both: + RUN_TESTS=schedule_intents \ + SETUP_ONLY=both \ + $(MAKE) test $(FLEXI_COUNTER_SO): $(FLEXI_COUNTER_SRC) cargo build-sbf --manifest-path $(FLEXI_COUNTER_DIR)/Cargo.toml diff --git a/test-integration/programs/flexi-counter/src/processor/call_handler.rs b/test-integration/programs/flexi-counter/src/processor/call_handler.rs index 71e74b6c8..8cf0ed274 100644 --- a/test-integration/programs/flexi-counter/src/processor/call_handler.rs +++ b/test-integration/programs/flexi-counter/src/processor/call_handler.rs @@ -40,8 +40,7 @@ pub fn process_call_handler( account_info_iter, &call_handler, ) - } else if discriminator == CallHandlerDiscriminator::ReDelegate.to_array() - { + } else if discriminator == CallHandlerDiscriminator::ReDelegate.to_array() { call_handler.data.drain(0..4); process_redelegation_call_handler( escrow_authority, diff --git a/test-integration/test-committor-service/tests/test_transaction_preparator.rs b/test-integration/test-committor-service/tests/test_transaction_preparator.rs index c4efa8755..a06775eb2 100644 --- a/test-integration/test-committor-service/tests/test_transaction_preparator.rs +++ b/test-integration/test-committor-service/tests/test_transaction_preparator.rs @@ -6,8 +6,8 @@ use magicblock_committor_service::{ tasks::{ task_strategist::{TaskStrategist, TransactionStrategy}, tasks::{ - ArgsTask, BaseTask, BufferTask, CommitTask, FinalizeTask, - BaseActionTask, UndelegateTask, + ArgsTask, BaseActionTask, BaseTask, BufferTask, CommitTask, + FinalizeTask, UndelegateTask, }, utils::TransactionUtils, }, From 04b3b28cb99264fd7071f274c913b75796c094fc Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 28 Aug 2025 20:22:17 +0900 Subject: [PATCH 197/199] refactor: cargo sort + CommittedAccountV2 -> CommittedAccount --- .../src/external_accounts_manager.rs | 7 ++-- .../src/scheduled_commits_processor.rs | 4 +-- magicblock-accounts/src/traits.rs | 6 ++-- .../intent_scheduler.rs | 8 ++--- .../src/persist/commit_persister.rs | 6 ++-- .../src/tasks/task_builder.rs | 6 ++-- .../src/tasks/task_strategist.rs | 4 +-- .../src/tasks/tasks.rs | 10 +++--- .../transaction_preparator.rs | 23 ------------- .../src/magic_scheduled_base_intent.rs | 34 ++++++++----------- .../process_schedule_commit.rs | 6 ++-- .../test-committor-service/Cargo.toml | 17 +++++----- .../test-committor-service/tests/common.rs | 8 ++--- .../tests/test_ix_commit_local.rs | 10 +++--- 14 files changed, 59 insertions(+), 90 deletions(-) diff --git a/magicblock-accounts/src/external_accounts_manager.rs b/magicblock-accounts/src/external_accounts_manager.rs index 9c76449a5..bfa080774 100644 --- a/magicblock-accounts/src/external_accounts_manager.rs +++ b/magicblock-accounts/src/external_accounts_manager.rs @@ -32,7 +32,7 @@ use magicblock_committor_service::{ use magicblock_core::magic_program; use magicblock_program::{ magic_scheduled_base_intent::{ - CommitType, CommittedAccountV2, MagicBaseIntent, ScheduledBaseIntent, + CommitType, CommittedAccount, MagicBaseIntent, ScheduledBaseIntent, }, validator::validator_authority_id, }; @@ -411,9 +411,8 @@ where .chunks(MAX_PROCESS_PER_TX as usize) .into_iter() .map(|committees| { - let committees = committees - .map(CommittedAccountV2::from) - .collect::>(); + let committees = + committees.map(CommittedAccount::from).collect::>(); ScheduledBaseIntent { // isn't important but shall be unique diff --git a/magicblock-accounts/src/scheduled_commits_processor.rs b/magicblock-accounts/src/scheduled_commits_processor.rs index ecdbd48b3..10445558a 100644 --- a/magicblock-accounts/src/scheduled_commits_processor.rs +++ b/magicblock-accounts/src/scheduled_commits_processor.rs @@ -18,7 +18,7 @@ use magicblock_committor_service::{ }; use magicblock_processor::execute_transaction::execute_legacy_transaction; use magicblock_program::{ - magic_scheduled_base_intent::{CommittedAccountV2, ScheduledBaseIntent}, + magic_scheduled_base_intent::{CommittedAccount, ScheduledBaseIntent}, register_scheduled_commit_sent, FeePayerAccount, SentCommit, TransactionScheduler, }; @@ -101,7 +101,7 @@ impl ScheduledCommitsProcessorImpl { /// Returns `true` if account should be retained, `false` otherwise fn process_feepayer( &mut self, - account: &mut CommittedAccountV2, + account: &mut CommittedAccount, ) -> bool { let pubkey = account.pubkey; let ephemeral_pubkey = diff --git a/magicblock-accounts/src/traits.rs b/magicblock-accounts/src/traits.rs index 707c57735..9c11e9ff8 100644 --- a/magicblock-accounts/src/traits.rs +++ b/magicblock-accounts/src/traits.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use async_trait::async_trait; use magicblock_metrics::metrics::HistogramTimer; -use magicblock_program::magic_scheduled_base_intent::CommittedAccountV2; +use magicblock_program::magic_scheduled_base_intent::CommittedAccount; use solana_rpc_client::rpc_client::SerializableTransaction; use solana_sdk::{ account::{Account, AccountSharedData, ReadableAccount}, @@ -43,9 +43,9 @@ pub struct AccountCommittee { pub undelegation_requested: bool, } -impl From for CommittedAccountV2 { +impl From for CommittedAccount { fn from(value: AccountCommittee) -> Self { - CommittedAccountV2 { + CommittedAccount { pubkey: value.pubkey, account: Account { lamports: value.account_data.lamports(), diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs index ab6224336..27eca6a0d 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_scheduler.rs @@ -600,7 +600,7 @@ mod edge_cases_test { #[cfg(test)] mod complete_error_test { - use magicblock_program::magic_scheduled_base_intent::CommittedAccountV2; + use magicblock_program::magic_scheduled_base_intent::CommittedAccount; use solana_account::Account; use solana_pubkey::pubkey; @@ -661,7 +661,7 @@ mod complete_error_test { .base_intent .get_committed_accounts_mut() .unwrap() - .push(CommittedAccountV2 { + .push(CommittedAccount { pubkey: pubkey3, account: Account::default(), }); @@ -727,7 +727,7 @@ pub(crate) fn create_test_intent( pubkeys: &[Pubkey], ) -> ScheduledBaseIntentWrapper { use magicblock_program::magic_scheduled_base_intent::{ - CommitType, CommittedAccountV2, MagicBaseIntent, + CommitType, CommittedAccount, MagicBaseIntent, }; use solana_account::Account; use solana_sdk::{hash::Hash, transaction::Transaction}; @@ -747,7 +747,7 @@ pub(crate) fn create_test_intent( if !pubkeys.is_empty() { let committed_accounts = pubkeys .iter() - .map(|&pubkey| CommittedAccountV2 { + .map(|&pubkey| CommittedAccount { pubkey, account: Account::default(), }) diff --git a/magicblock-committor-service/src/persist/commit_persister.rs b/magicblock-committor-service/src/persist/commit_persister.rs index 6eff5a853..3df48997f 100644 --- a/magicblock-committor-service/src/persist/commit_persister.rs +++ b/magicblock-committor-service/src/persist/commit_persister.rs @@ -436,7 +436,7 @@ impl IntentPersister for Option { #[cfg(test)] mod tests { use magicblock_program::magic_scheduled_base_intent::{ - CommitType, CommittedAccountV2, MagicBaseIntent, + CommitType, CommittedAccount, MagicBaseIntent, }; use solana_sdk::{ account::Account, hash::Hash, pubkey::Pubkey, signature::Signature, @@ -476,11 +476,11 @@ mod tests { action_sent_transaction: Transaction::default(), payer: Pubkey::new_unique(), base_intent: MagicBaseIntent::Commit(CommitType::Standalone(vec![ - CommittedAccountV2 { + CommittedAccount { pubkey: Pubkey::new_unique(), account: account1, }, - CommittedAccountV2 { + CommittedAccount { pubkey: Pubkey::new_unique(), account: account2, }, diff --git a/magicblock-committor-service/src/tasks/task_builder.rs b/magicblock-committor-service/src/tasks/task_builder.rs index a75a0b176..3bc2b8e6f 100644 --- a/magicblock-committor-service/src/tasks/task_builder.rs +++ b/magicblock-committor-service/src/tasks/task_builder.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use dlp::args::Context; use log::error; use magicblock_program::magic_scheduled_base_intent::{ - CommitType, CommittedAccountV2, MagicBaseIntent, ScheduledBaseIntent, + CommitType, CommittedAccount, MagicBaseIntent, ScheduledBaseIntent, UndelegateType, }; use solana_pubkey::Pubkey; @@ -111,7 +111,7 @@ impl TasksBuilder for TaskBuilderV1 { base_intent: &ScheduledBaseIntent, ) -> TaskBuilderResult>> { // Helper to create a finalize task - fn finalize_task(account: &CommittedAccountV2) -> Box { + fn finalize_task(account: &CommittedAccount) -> Box { Box::new(ArgsTask::Finalize(FinalizeTask { delegated_account: account.pubkey, })) @@ -119,7 +119,7 @@ impl TasksBuilder for TaskBuilderV1 { // Helper to create an undelegate task fn undelegate_task( - account: &CommittedAccountV2, + account: &CommittedAccount, rent_reimbursement: &Pubkey, ) -> Box { Box::new(ArgsTask::Undelegate(UndelegateTask { diff --git a/magicblock-committor-service/src/tasks/task_strategist.rs b/magicblock-committor-service/src/tasks/task_strategist.rs index 379801186..92a0d30ca 100644 --- a/magicblock-committor-service/src/tasks/task_strategist.rs +++ b/magicblock-committor-service/src/tasks/task_strategist.rs @@ -230,7 +230,7 @@ pub type TaskStrategistResult = Result; mod tests { use dlp::args::Context; use magicblock_program::magic_scheduled_base_intent::{ - BaseAction, CommittedAccountV2, ProgramArgs, + BaseAction, CommittedAccount, ProgramArgs, }; use solana_account::Account; use solana_sdk::system_program; @@ -248,7 +248,7 @@ mod tests { ArgsTask::Commit(CommitTask { commit_id, allow_undelegation: false, - committed_account: CommittedAccountV2 { + committed_account: CommittedAccount { pubkey: Pubkey::new_unique(), account: Account { lamports: 1000, diff --git a/magicblock-committor-service/src/tasks/tasks.rs b/magicblock-committor-service/src/tasks/tasks.rs index ab3ef02a2..c8f6d84b6 100644 --- a/magicblock-committor-service/src/tasks/tasks.rs +++ b/magicblock-committor-service/src/tasks/tasks.rs @@ -13,7 +13,7 @@ use magicblock_committor_program::{ ChangesetChunks, Chunks, }; use magicblock_program::magic_scheduled_base_intent::{ - BaseAction, CommittedAccountV2, + BaseAction, CommittedAccount, }; use solana_pubkey::Pubkey; use solana_sdk::instruction::{AccountMeta, Instruction}; @@ -79,7 +79,7 @@ dyn_clone::clone_trait_object!(BaseTask); pub struct CommitTask { pub commit_id: u64, pub allow_undelegation: bool, - pub committed_account: CommittedAccountV2, + pub committed_account: CommittedAccount, } #[derive(Clone)] @@ -333,7 +333,7 @@ mod serialization_safety_test { let commit_task = ArgsTask::Commit(CommitTask { commit_id: 123, allow_undelegation: true, - committed_account: CommittedAccountV2 { + committed_account: CommittedAccount { pubkey: Pubkey::new_unique(), account: Account { lamports: 1000, @@ -388,7 +388,7 @@ mod serialization_safety_test { let buffer_task = BufferTask::Commit(CommitTask { commit_id: 456, allow_undelegation: false, - committed_account: CommittedAccountV2 { + committed_account: CommittedAccount { pubkey: Pubkey::new_unique(), account: Account { lamports: 2000, @@ -411,7 +411,7 @@ mod serialization_safety_test { let buffer_task = BufferTask::Commit(CommitTask { commit_id: 789, allow_undelegation: true, - committed_account: CommittedAccountV2 { + committed_account: CommittedAccount { pubkey: Pubkey::new_unique(), account: Account { lamports: 3000, diff --git a/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs b/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs index 4bc5110d3..63ac4ee27 100644 --- a/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs +++ b/magicblock-committor-service/src/transaction_preparator/transaction_preparator.rs @@ -1,5 +1,3 @@ -use std::fmt::Formatter; - use async_trait::async_trait; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::TableMania; @@ -14,25 +12,8 @@ use crate::{ ComputeBudgetConfig, }; -/// Transaction Preparator version -/// Some actions maybe invalid per version -#[derive(Debug)] -pub enum PreparatorVersion { - V1, -} - -impl std::fmt::Display for PreparatorVersion { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match self { - Self::V1 => write!(f, "V1"), - } - } -} - #[async_trait] pub trait TransactionPreparator: Send + Sync + 'static { - fn version(&self) -> PreparatorVersion; - /// Return [`VersionedMessage`] corresponding to [`TransactionStrategy`] /// Handles all necessary preparation needed for successful [`BaseTask`] execution async fn prepare_for_strategy( @@ -72,10 +53,6 @@ impl TransactionPreparatorV1 { #[async_trait] impl TransactionPreparator for TransactionPreparatorV1 { - fn version(&self) -> PreparatorVersion { - PreparatorVersion::V1 - } - async fn prepare_for_strategy( &self, authority: &Keypair, diff --git a/programs/magicblock/src/magic_scheduled_base_intent.rs b/programs/magicblock/src/magic_scheduled_base_intent.rs index 520952220..6c5ae6954 100644 --- a/programs/magicblock/src/magic_scheduled_base_intent.rs +++ b/programs/magicblock/src/magic_scheduled_base_intent.rs @@ -84,13 +84,13 @@ impl ScheduledBaseIntent { }) } - pub fn get_committed_accounts(&self) -> Option<&Vec> { + pub fn get_committed_accounts(&self) -> Option<&Vec> { self.base_intent.get_committed_accounts() } pub fn get_committed_accounts_mut( &mut self, - ) -> Option<&mut Vec> { + ) -> Option<&mut Vec> { self.base_intent.get_committed_accounts_mut() } @@ -149,7 +149,7 @@ impl MagicBaseIntent { } } - pub fn get_committed_accounts(&self) -> Option<&Vec> { + pub fn get_committed_accounts(&self) -> Option<&Vec> { match self { MagicBaseIntent::BaseActions(_) => None, MagicBaseIntent::Commit(t) => Some(t.get_committed_accounts()), @@ -161,7 +161,7 @@ impl MagicBaseIntent { pub fn get_committed_accounts_mut( &mut self, - ) -> Option<&mut Vec> { + ) -> Option<&mut Vec> { match self { MagicBaseIntent::BaseActions(_) => None, MagicBaseIntent::Commit(t) => Some(t.get_committed_accounts_mut()), @@ -208,13 +208,11 @@ impl CommitAndUndelegate { }) } - pub fn get_committed_accounts(&self) -> &Vec { + pub fn get_committed_accounts(&self) -> &Vec { self.commit_action.get_committed_accounts() } - pub fn get_committed_accounts_mut( - &mut self, - ) -> &mut Vec { + pub fn get_committed_accounts_mut(&mut self) -> &mut Vec { self.commit_action.get_committed_accounts_mut() } @@ -324,12 +322,12 @@ impl BaseAction { type CommittedAccountRef<'a> = (Pubkey, &'a RefCell); #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CommittedAccountV2 { +pub struct CommittedAccount { pub pubkey: Pubkey, pub account: Account, } -impl<'a> From> for CommittedAccountV2 { +impl<'a> From> for CommittedAccount { fn from(value: CommittedAccountRef<'a>) -> Self { Self { pubkey: value.0, @@ -342,10 +340,10 @@ impl<'a> From> for CommittedAccountV2 { pub enum CommitType { /// Regular commit without actions /// TODO: feels like ShortMeta isn't needed - Standalone(Vec), // accounts to commit + Standalone(Vec), // accounts to commit /// Commits accounts and runs actions WithBaseActions { - committed_accounts: Vec, + committed_accounts: Vec, base_actions: Vec, }, } @@ -426,8 +424,7 @@ impl CommitType { let committed_accounts = committed_accounts_ref .into_iter() .map(|el| { - let mut committed_account: CommittedAccountV2 = - el.into(); + let mut committed_account: CommittedAccount = el.into(); committed_account.account.owner = context .parent_program_id .unwrap_or(committed_account.account.owner); @@ -455,8 +452,7 @@ impl CommitType { let committed_accounts = committed_accounts_ref .into_iter() .map(|el| { - let mut committed_account: CommittedAccountV2 = - el.into(); + let mut committed_account: CommittedAccount = el.into(); committed_account.account.owner = context .parent_program_id .unwrap_or(committed_account.account.owner); @@ -473,7 +469,7 @@ impl CommitType { } } - pub fn get_committed_accounts(&self) -> &Vec { + pub fn get_committed_accounts(&self) -> &Vec { match self { Self::Standalone(committed_accounts) => committed_accounts, Self::WithBaseActions { @@ -482,9 +478,7 @@ impl CommitType { } } - pub fn get_committed_accounts_mut( - &mut self, - ) -> &mut Vec { + pub fn get_committed_accounts_mut(&mut self) -> &mut Vec { match self { Self::Standalone(committed_accounts) => committed_accounts, Self::WithBaseActions { diff --git a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs index 0243121f0..aa990b807 100644 --- a/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs +++ b/programs/magicblock/src/schedule_transactions/process_schedule_commit.rs @@ -11,7 +11,7 @@ use solana_sdk::{ use crate::{ magic_scheduled_base_intent::{ - CommitAndUndelegate, CommitType, CommittedAccountV2, MagicBaseIntent, + CommitAndUndelegate, CommitType, CommittedAccount, MagicBaseIntent, ScheduledBaseIntent, UndelegateType, }, schedule_transactions, @@ -124,7 +124,7 @@ pub(crate) fn process_schedule_commit( // NOTE: we don't require PDAs to be signers as in our case verifying that the // program owning the PDAs invoked us via CPI is sufficient // Thus we can be `invoke`d unsigned and no seeds need to be provided - let mut committed_accounts: Vec = Vec::new(); + let mut committed_accounts: Vec = Vec::new(); for idx in COMMITTEES_START..ix_accs_len { let acc_pubkey = get_instruction_pubkey_with_idx(transaction_context, idx as u16)?; @@ -158,7 +158,7 @@ pub(crate) fn process_schedule_commit( account.owner = parent_program_id.cloned().unwrap_or(account.owner); #[allow(clippy::unnecessary_literal_unwrap)] - committed_accounts.push(CommittedAccountV2 { + committed_accounts.push(CommittedAccount { pubkey: *acc_pubkey, account, }); diff --git a/test-integration/test-committor-service/Cargo.toml b/test-integration/test-committor-service/Cargo.toml index 4db726273..60c867c27 100644 --- a/test-integration/test-committor-service/Cargo.toml +++ b/test-integration/test-committor-service/Cargo.toml @@ -4,25 +4,25 @@ version.workspace = true edition.workspace = true [dev-dependencies] +async-trait = { workspace = true } +borsh = { workspace = true } log = { workspace = true } magicblock-committor-program = { workspace = true, features = [ "no-entrypoint", ] } -magicblock-delegation-program = { workspace = true, features = [ - "no-entrypoint", -] } magicblock-committor-service = { workspace = true, features = [ "dev-context-only-utils", ] } -magicblock-table-mania = { workspace = true, features = [ - "randomize_lookup_table_slot", +magicblock-delegation-program = { workspace = true, features = [ + "no-entrypoint", ] } magicblock-program = { workspace = true } magicblock-rpc-client = { workspace = true } +magicblock-table-mania = { workspace = true, features = [ + "randomize_lookup_table_slot", +] } program-flexi-counter = { workspace = true, features = ["no-entrypoint"] } - -async-trait = { workspace = true } -borsh = { workspace = true } +rand = { workspace = true } solana-account = { workspace = true } solana-pubkey = { workspace = true } solana-rpc-client = { workspace = true } @@ -30,7 +30,6 @@ solana-rpc-client-api = { workspace = true } solana-sdk = { workspace = true } test-tools-core = { workspace = true } tokio = { workspace = true } -rand = { workspace = true } [features] test_table_close = [] diff --git a/test-integration/test-committor-service/tests/common.rs b/test-integration/test-committor-service/tests/common.rs index bef3eb7a3..a8abf6be1 100644 --- a/test-integration/test-committor-service/tests/common.rs +++ b/test-integration/test-committor-service/tests/common.rs @@ -19,7 +19,7 @@ use magicblock_committor_service::{ }, ComputeBudgetConfig, }; -use magicblock_program::magic_scheduled_base_intent::CommittedAccountV2; +use magicblock_program::magic_scheduled_base_intent::CommittedAccount; use magicblock_rpc_client::MagicblockRpcClient; use magicblock_table_mania::{GarbageCollectorConfig, TableMania}; use solana_account::Account; @@ -144,7 +144,7 @@ pub fn create_commit_task(data: &[u8]) -> CommitTask { CommitTask { commit_id: COMMIT_ID.fetch_add(1, Ordering::Relaxed), allow_undelegation: false, - committed_account: CommittedAccountV2 { + committed_account: CommittedAccount { pubkey: Pubkey::new_unique(), account: Account { lamports: 1000, @@ -158,8 +158,8 @@ pub fn create_commit_task(data: &[u8]) -> CommitTask { } #[allow(dead_code)] -pub fn create_committed_account(data: &[u8]) -> CommittedAccountV2 { - CommittedAccountV2 { +pub fn create_committed_account(data: &[u8]) -> CommittedAccount { + CommittedAccount { pubkey: Pubkey::new_unique(), account: Account { lamports: 1000, diff --git a/test-integration/test-committor-service/tests/test_ix_commit_local.rs b/test-integration/test-committor-service/tests/test_ix_commit_local.rs index 1a24f7f57..d04c5a6df 100644 --- a/test-integration/test-committor-service/tests/test_ix_commit_local.rs +++ b/test-integration/test-committor-service/tests/test_ix_commit_local.rs @@ -15,7 +15,7 @@ use magicblock_committor_service::{ }; use magicblock_program::{ magic_scheduled_base_intent::{ - CommitAndUndelegate, CommitType, CommittedAccountV2, MagicBaseIntent, + CommitAndUndelegate, CommitType, CommittedAccount, MagicBaseIntent, ScheduledBaseIntent, UndelegateType, }, validator::{init_validator_authority, validator_authority}, @@ -322,7 +322,7 @@ async fn commit_single_account( account.owner = program_flexi_counter::id(); account.data = vec![101_u8; bytes]; - let account = CommittedAccountV2 { pubkey, account }; + let account = CommittedAccount { pubkey, account }; let base_intent = if undelegate { MagicBaseIntent::CommitAndUndelegate(CommitAndUndelegate { commit_action: CommitType::Standalone(vec![account]), @@ -593,7 +593,7 @@ async fn commit_20_accounts_1kb( async fn create_bundles( bundle_size: usize, bytess: &[usize], -) -> Vec> { +) -> Vec> { let mut join_set = JoinSet::new(); for bytes in bytess { let bytes = *bytes; @@ -605,7 +605,7 @@ async fn create_bundles( pda_acc.owner = program_flexi_counter::id(); pda_acc.data = vec![0u8; bytes]; - CommittedAccountV2 { + CommittedAccount { pubkey: pda, account: pda_acc, } @@ -752,7 +752,7 @@ async fn ix_commit_local( .unwrap() .iter() .map(|el| (el.pubkey, el.clone())) - .collect::>(); + .collect::>(); let statuses = service .get_commit_statuses(base_intent.id) .await From a58f3e8e76a1dafec6eec2fcc57fdaa16257bcb4 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Thu, 28 Aug 2025 20:56:29 +0900 Subject: [PATCH 198/199] refactor: address leftovers --- magicblock-api/src/tickers.rs | 2 +- programs/magicblock/src/magic_scheduled_base_intent.rs | 5 +---- .../schedule_base_intent_processor.rs | 2 +- .../programs/flexi-counter/src/instruction.rs | 2 ++ .../schedulecommit/test-scenarios/tests/utils/mod.rs | 6 +++--- .../test-committor-service/tests/test_ix_commit_local.rs | 8 ++++++++ 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/magicblock-api/src/tickers.rs b/magicblock-api/src/tickers.rs index e235bf8a4..7b4f0c562 100644 --- a/magicblock-api/src/tickers.rs +++ b/magicblock-api/src/tickers.rs @@ -43,7 +43,7 @@ pub fn init_slot_ticker( } if log { - info!("Advanced to slot {}", next_slot); + debug!("Advanced to slot {}", next_slot); } metrics::inc_slot(); diff --git a/programs/magicblock/src/magic_scheduled_base_intent.rs b/programs/magicblock/src/magic_scheduled_base_intent.rs index 6c5ae6954..f90370a14 100644 --- a/programs/magicblock/src/magic_scheduled_base_intent.rs +++ b/programs/magicblock/src/magic_scheduled_base_intent.rs @@ -339,7 +339,6 @@ impl<'a> From> for CommittedAccount { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum CommitType { /// Regular commit without actions - /// TODO: feels like ShortMeta isn't needed Standalone(Vec), // accounts to commit /// Commits accounts and runs actions WithBaseActions { @@ -349,7 +348,6 @@ pub enum CommitType { } impl CommitType { - // TODO: move to processor fn validate_accounts( accounts: &[CommittedAccountRef], context: &ConstructionContext<'_, '_>, @@ -383,12 +381,11 @@ impl CommitType { // I delegated an account, now the owner is delegation program // parent_program_id != Some(&acc_owner) should fail. or any modification on ER // ER perceives owner as old one, hence for ER those are valid txs - // On commit_and_undelegate and commit we will set owner to DLP, for latter temparerily + // On commit_and_undelegate and commit we will set owner to DLP, for latter temporarily // The owner shall be real owner on chain // So first: // 1. Validate // 2. Fetch current account states - // TODO: 3. switch the ownership pub fn extract_commit_accounts<'a>( account_indices: &[u8], transaction_context: &'a TransactionContext, diff --git a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs index 6e11da074..1a1093eee 100644 --- a/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs +++ b/programs/magicblock/src/schedule_transactions/schedule_base_intent_processor.rs @@ -28,7 +28,7 @@ pub fn change_owner_for_undelegated_accounts( }; // Change owner to dlp - // Undelegated it immediately becomes immutable in our validator. + // Once account is undelegated we need to make it immutable in our validator. commited_accounts_ref .into_iter() .for_each(|(_, account_ref)| { diff --git a/test-integration/programs/flexi-counter/src/instruction.rs b/test-integration/programs/flexi-counter/src/instruction.rs index 75a553926..8a3d9ca0f 100644 --- a/test-integration/programs/flexi-counter/src/instruction.rs +++ b/test-integration/programs/flexi-counter/src/instruction.rs @@ -109,8 +109,10 @@ pub enum FlexiCounterInstruction { /// 3. `[write]` Transfer destination during action /// 4. `[]` system program /// 5. `[signer]` Escrow authority + /// ... /// 5+n-1 `[signer]` Escrow authority` /// 5+n `[write]` Counter pda + /// ... /// 5+2n `[write]` Counter pda CreateIntent { num_committees: u8, diff --git a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs index 1fc44a2c8..83a2b981f 100644 --- a/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs +++ b/test-integration/schedulecommit/test-scenarios/tests/utils/mod.rs @@ -63,7 +63,7 @@ pub fn assert_one_committee_was_committed( // SingleStage Commit & Finalize result in 1 tx // TwoStage results in 2 signatures on base layer - let sig_len = if !is_single_stage { 2 } else { 1 }; + let sig_len = if is_single_stage { 1 } else { 2 }; assert_eq!( res.sigs.len(), sig_len, @@ -89,7 +89,7 @@ pub fn assert_two_committees_were_committed( assert!(commit1.is_some(), "should have committed pda1"); assert!(commit2.is_some(), "should have committed pda2"); - let sig_len = if !is_single_stage { 2 } else { 1 }; + let sig_len = if is_single_stage { 1 } else { 2 }; assert_eq!( res.sigs.len(), sig_len, @@ -111,7 +111,7 @@ pub fn assert_feepayer_was_committed( let commit_payer = res.feepayers.iter().find(|(p, _)| p == &payer); assert!(commit_payer.is_some(), "should have committed payer"); - let sig_len = if !is_single_stage { 2 } else { 1 }; + let sig_len = if is_single_stage { 1 } else { 2 }; assert_eq!( res.sigs.len(), sig_len, diff --git a/test-integration/test-committor-service/tests/test_ix_commit_local.rs b/test-integration/test-committor-service/tests/test_ix_commit_local.rs index d04c5a6df..49a053543 100644 --- a/test-integration/test-committor-service/tests/test_ix_commit_local.rs +++ b/test-integration/test-committor-service/tests/test_ix_commit_local.rs @@ -758,6 +758,14 @@ async fn ix_commit_local( .await .unwrap() .unwrap(); + debug!( + "{}", + statuses + .iter() + .map(|x| x.to_string()) + .collect::>() + .join("\n") + ); // When we finalize it is possible to also undelegate the account let expected_owner = if is_undelegate { From b87e106ec7957ad798381521ed044209d1ca7979 Mon Sep 17 00:00:00 2001 From: taco-paco Date: Fri, 29 Aug 2025 18:20:26 +0900 Subject: [PATCH 199/199] feat: added metrics + some extra error handling on error - cleaning TaskInfoFetcher cache --- Cargo.lock | 1 + magicblock-committor-service/Cargo.toml | 1 + .../src/intent_execution_manager/db.rs | 23 ++++++++------ .../intent_execution_engine.rs | 9 ++++++ .../src/intent_executor/intent_executor.rs | 18 ++++++++--- .../src/intent_executor/task_info_fetcher.rs | 23 ++++++++++++++ magicblock-metrics/src/metrics/mod.rs | 30 +++++++++++++++++++ test-integration/Cargo.lock | 1 + .../test-committor-service/tests/common.rs | 7 +++-- 9 files changed, 98 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c06ec924..485568063 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4103,6 +4103,7 @@ dependencies = [ "lru 0.16.0", "magicblock-committor-program", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", + "magicblock-metrics", "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", diff --git a/magicblock-committor-service/Cargo.toml b/magicblock-committor-service/Cargo.toml index caf2f2a85..f62351606 100644 --- a/magicblock-committor-service/Cargo.toml +++ b/magicblock-committor-service/Cargo.toml @@ -26,6 +26,7 @@ magicblock-committor-program = { workspace = true, features = [ magicblock-delegation-program = { workspace = true, features = [ "no-entrypoint", ] } +magicblock-metrics = { workspace = true } magicblock-program = { workspace = true } magicblock-rpc-client = { workspace = true } magicblock-table-mania = { workspace = true } diff --git a/magicblock-committor-service/src/intent_execution_manager/db.rs b/magicblock-committor-service/src/intent_execution_manager/db.rs index 38364b1f6..6ba20cfc1 100644 --- a/magicblock-committor-service/src/intent_execution_manager/db.rs +++ b/magicblock-committor-service/src/intent_execution_manager/db.rs @@ -2,6 +2,7 @@ use std::{collections::VecDeque, sync::Mutex}; /// DB for storing intents that overflow committor channel use async_trait::async_trait; +use magicblock_metrics::metrics; use crate::types::ScheduledBaseIntentWrapper; @@ -43,10 +44,10 @@ impl DB for DummyDB { &self, base_intent: ScheduledBaseIntentWrapper, ) -> DBResult<()> { - self.db - .lock() - .expect(POISONED_MUTEX_MSG) - .push_back(base_intent); + let mut db = self.db.lock().expect(POISONED_MUTEX_MSG); + db.push_back(base_intent); + + metrics::set_committor_intents_backlog_count(db.len() as i64); Ok(()) } @@ -54,17 +55,21 @@ impl DB for DummyDB { &self, base_intents: Vec, ) -> DBResult<()> { - self.db - .lock() - .expect(POISONED_MUTEX_MSG) - .extend(base_intents.into_iter()); + let mut db = self.db.lock().expect(POISONED_MUTEX_MSG); + db.extend(base_intents.into_iter()); + + metrics::set_committor_intents_backlog_count(db.len() as i64); Ok(()) } async fn pop_base_intent( &self, ) -> DBResult> { - Ok(self.db.lock().expect(POISONED_MUTEX_MSG).pop_front()) + let mut db = self.db.lock().expect(POISONED_MUTEX_MSG); + let res = db.pop_front(); + + metrics::set_committor_intents_backlog_count(db.len() as i64); + Ok(res) } fn is_empty(&self) -> bool { diff --git a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs index fea5fb402..fb5294c5e 100644 --- a/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs +++ b/magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs @@ -2,6 +2,7 @@ use std::sync::{Arc, Mutex}; use futures_util::{stream::FuturesUnordered, StreamExt}; use log::{error, info, trace, warn}; +use magicblock_metrics::metrics; use tokio::{ sync::{ broadcast, mpsc, mpsc::error::TryRecvError, OwnedSemaphorePermit, @@ -149,6 +150,9 @@ where )); self.running_executors.push(handle); + metrics::set_committor_executors_busy_count( + self.running_executors.len() as i64, + ); } } @@ -250,6 +254,8 @@ where output, }) .map_err(|err| { + // Increase failed intents metric as well + metrics::inc_committor_failed_intents_count(); (intent.inner.id, intent.trigger_type, Arc::new(err)) }); @@ -306,6 +312,7 @@ mod tests { }, persist::IntentPersisterImpl, }; + use crate::intent_executor::task_info_fetcher::ResetType; type MockIntentExecutionEngine = IntentExecutionEngine< DummyDB, @@ -737,5 +744,7 @@ mod tests { fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option { None } + + fn reset(&self, _: ResetType) {} } } diff --git a/magicblock-committor-service/src/intent_executor/intent_executor.rs b/magicblock-committor-service/src/intent_executor/intent_executor.rs index 16ace2d5f..f8dca7ecf 100644 --- a/magicblock-committor-service/src/intent_executor/intent_executor.rs +++ b/magicblock-committor-service/src/intent_executor/intent_executor.rs @@ -37,6 +37,7 @@ use crate::{ }, utils::persist_status_update_by_message_set, }; +use crate::intent_executor::task_info_fetcher::ResetType; pub struct IntentExecutorImpl { authority: Keypair, @@ -409,6 +410,12 @@ where let result = self.execute_inner(base_intent, &persister).await; if let Some(pubkeys) = pubkeys { + // Reset TaskInfoFetcher, as cache could become invalid + if result.is_err() { + self.task_info_fetcher.reset(ResetType::Specific(&pubkeys)); + } + + // Write result of intent into Persister Self::persist_result(&persister, &result, message_id, &pubkeys); } @@ -432,14 +439,11 @@ mod tests { tasks::task_builder::{TaskBuilderV1, TasksBuilder}, transaction_preparator::transaction_preparator::TransactionPreparatorV1, }; + use crate::intent_executor::task_info_fetcher::ResetType; struct MockInfoFetcher; #[async_trait::async_trait] impl TaskInfoFetcher for MockInfoFetcher { - fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option { - Some(0) - } - async fn fetch_next_commit_ids( &self, pubkeys: &[Pubkey], @@ -453,6 +457,12 @@ mod tests { ) -> TaskInfoFetcherResult> { Ok(pubkeys.iter().map(|_| Pubkey::new_unique()).collect()) } + + fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option { + Some(0) + } + + fn reset(&self, _: ResetType) {} } #[tokio::test] diff --git a/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs b/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs index da080fbc1..bd50de71d 100644 --- a/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs +++ b/magicblock-committor-service/src/intent_executor/task_info_fetcher.rs @@ -28,6 +28,14 @@ pub trait TaskInfoFetcher: Send + Sync + 'static { // Peeks current commit ids for pubkeys fn peek_commit_id(&self, pubkey: &Pubkey) -> Option; + + /// Resets cache for some or all accounts + fn reset(&self, reset_type: ResetType); +} + +pub enum ResetType<'a> { + All, + Specific(&'a [Pubkey]), } const NUM_FETCH_RETRIES: NonZeroUsize = @@ -240,6 +248,21 @@ impl TaskInfoFetcher for CacheTaskInfoFetcher { let cache = self.cache.lock().expect(MUTEX_POISONED_MSG); cache.peek(pubkey).copied() } + + /// Reset cache + fn reset(&self, reset_type: ResetType) { + match reset_type { + ResetType::All => { + self.cache.lock().expect(MUTEX_POISONED_MSG).clear() + } + ResetType::Specific(pubkeys) => { + let mut cache = self.cache.lock().expect(MUTEX_POISONED_MSG); + pubkeys.iter().for_each(|pubkey| { + let _ = cache.pop(pubkey); + }); + } + } + } } #[derive(thiserror::Error, Debug)] diff --git a/magicblock-metrics/src/metrics/mod.rs b/magicblock-metrics/src/metrics/mod.rs index 71efb02d1..b0d807863 100644 --- a/magicblock-metrics/src/metrics/mod.rs +++ b/magicblock-metrics/src/metrics/mod.rs @@ -199,6 +199,21 @@ lazy_static::lazy_static! { "evicted_accounts", "number of accounts forcefully removed from monitored list and database", ).unwrap(); + + // ----------------- + // CommittorService + // ----------------- + static ref COMMITTOR_INTENTS_BACKLOG_COUNT: IntGauge = IntGauge::new( + "committor_intent_backlog_count", "Number of intents in backlog", + ).unwrap(); + + static ref COMMITTOR_FAILED_INTENTS_COUNT: IntCounter = IntCounter::new( + "committor_failed_intents_count", "Number of failed to be executed intents", + ).unwrap(); + + static ref COMMITTOR_EXECUTORS_BUSY_COUNT: IntGauge = IntGauge::new( + "committor_executors_busy_count", "Number of busy intent executors" + ).unwrap(); } pub(crate) fn register() { @@ -245,6 +260,9 @@ pub(crate) fn register() { register!(MONITORED_ACCOUNTS_GAUGE); register!(SUBSCRIPTIONS_COUNT_GAUGE); register!(EVICTED_ACCOUNTS_COUNT); + register!(COMMITTOR_INTENTS_BACKLOG_COUNT); + register!(COMMITTOR_FAILED_INTENTS_COUNT); + register!(COMMITTOR_EXECUTORS_BUSY_COUNT); }); } @@ -444,6 +462,18 @@ pub fn inc_evicted_accounts_count() { EVICTED_ACCOUNTS_COUNT.inc(); } +pub fn set_committor_intents_backlog_count(value: i64) { + COMMITTOR_INTENTS_BACKLOG_COUNT.set(value) +} + +pub fn inc_committor_failed_intents_count() { + COMMITTOR_FAILED_INTENTS_COUNT.inc() +} + +pub fn set_committor_executors_busy_count(value: i64) { + COMMITTOR_EXECUTORS_BUSY_COUNT.set(value) +} + pub fn observe_flush_accounts_time(f: F) -> T where F: FnOnce() -> T, diff --git a/test-integration/Cargo.lock b/test-integration/Cargo.lock index a6c5a65bf..73a8aa04d 100644 --- a/test-integration/Cargo.lock +++ b/test-integration/Cargo.lock @@ -3849,6 +3849,7 @@ dependencies = [ "lru 0.16.0", "magicblock-committor-program", "magicblock-delegation-program 1.0.0 (git+https://github.com/magicblock-labs/delegation-program.git?rev=00d720)", + "magicblock-metrics", "magicblock-program", "magicblock-rpc-client", "magicblock-table-mania", diff --git a/test-integration/test-committor-service/tests/common.rs b/test-integration/test-committor-service/tests/common.rs index a8abf6be1..8548bea04 100644 --- a/test-integration/test-committor-service/tests/common.rs +++ b/test-integration/test-committor-service/tests/common.rs @@ -9,7 +9,9 @@ use std::{ use async_trait::async_trait; use magicblock_committor_service::{ intent_executor::{ - task_info_fetcher::{TaskInfoFetcher, TaskInfoFetcherResult}, + task_info_fetcher::{ + ResetType, TaskInfoFetcher, TaskInfoFetcherResult, + }, IntentExecutorImpl, }, tasks::tasks::CommitTask, @@ -108,7 +110,6 @@ impl TestFixture { } pub struct MockTaskInfoFetcher; - #[async_trait] impl TaskInfoFetcher for MockTaskInfoFetcher { async fn fetch_next_commit_ids( @@ -128,6 +129,8 @@ impl TaskInfoFetcher for MockTaskInfoFetcher { fn peek_commit_id(&self, _pubkey: &Pubkey) -> Option { None } + + fn reset(&self, _: ResetType) {} } #[allow(dead_code)]