Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ processor = { workspace = true }
derive_more = { workspace = true }
num_cpus = { workspace = true }
oneshot = { workspace = true }
rand = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["sync"] }
tracing = { workspace = true }
Expand Down
13 changes: 8 additions & 5 deletions engine/src/accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,14 @@ impl AccountAccessor<'_> {
let ix = MagicRootInstruction::PostFinalize(actions);
instructions.push(ix.compose(pubkey)?);
}
self.execute(&instructions, Some(mode)).await
self.execute(instructions, Some(mode)).await
}

/// Closes the account, releasing ownership after definitive completion.
/// Cancellation has the same ownership contract as [`Self::materialize`].
pub async fn delete(self) -> Result<()> {
let pubkey = self.pubkey();
let instruction = MagicRootInstruction::Delete.compose(pubkey)?;
self.execute(&[instruction], None).await
let instruction = MagicRootInstruction::Delete.compose(self.pubkey())?;
self.execute(vec![instruction], None).await
}

/// Keeps this accessor only for a present account that does not require persistence.
Expand All @@ -102,7 +101,11 @@ impl AccountAccessor<'_> {

/// Before submission, cancellation releases the lease without submitting work.
/// After submission, the task owns completion and success bookkeeping.
async fn execute(self, instructions: &[Instruction], mode: Option<AccountMode>) -> Result<()> {
async fn execute(
self,
instructions: Vec<Instruction>,
mode: Option<AccountMode>,
) -> Result<()> {
let txn = transaction::magicblock(instructions, self.engine)?;
let rx = self.engine.transaction(txn)?.submit().await?;
// No await may separate successful submission from this lease handoff.
Expand Down
27 changes: 15 additions & 12 deletions engine/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use agave_transaction_view::{
transaction_version::{MAGICBLOCK_PREFIX, TransactionVersion},
};
use keeper::TransactionView;
use magic_root_interface::MagicRootInstruction;
use solana_instruction::Instruction;
use solana_message::{
VersionedMessage,
Expand Down Expand Up @@ -141,27 +142,29 @@ pub(super) fn sigverify(view: &TransactionView) -> Result<()> {

/// Composes an Engine-private transaction and signs its final
/// Magicblock wire representation with the Engine authority.
pub(crate) fn magicblock(instructions: &[Instruction], engine: &Engine) -> Result<Vec<u8>> {
let message = v1::Message::try_compile(&engine.authority(), instructions, engine.blockhash())?;
let message = VersionedMessage::V1(message);
pub(crate) fn magicblock(mut instructions: Vec<Instruction>, engine: &Engine) -> Result<Vec<u8>> {
// Randomize the signed payload: repeated operations can share a blockhash.
instructions.push(MagicRootInstruction::Nonce(rand::random()).compose(engine.authority())?);
let message = v1::Message::try_compile(&engine.authority(), &instructions, engine.blockhash())?;
// Private transactions have larger payloads but still obey runtime
// instruction-trace and account-index limits.
if message.instructions().len() > MAGICBLOCK_INSTRUCTION_TRACE_LENGTH {
Err(TransactionError::SanitizeFailure)?;
} else if message.static_account_keys().len() > MAX_MAGICBLOCK_ACCOUNT_LOCKS {
Err(TransactionError::TooManyAccountLocks)?;
if message.instructions.len() > MAGICBLOCK_INSTRUCTION_TRACE_LENGTH {
return Err(TransactionError::SanitizeFailure.into());
}
for ix in message.instructions() {
if ix.accounts.len() > MAX_MAGICBLOCK_ACCOUNT_LOCKS {
Err(TransactionError::TooManyAccountLocks)?;
}
if message.account_keys.len() > MAX_MAGICBLOCK_ACCOUNT_LOCKS
|| message
.instructions
.iter()
.any(|ix| ix.accounts.len() > MAX_MAGICBLOCK_ACCOUNT_LOCKS)
{
return Err(TransactionError::TooManyAccountLocks.into());
}

// Reserve the trailing signature slot without signing the V1 prefix, which
// is replaced below before the only signing operation.
let transaction = VersionedTransaction {
signatures: vec![Default::default()],
message,
message: VersionedMessage::V1(message),
};
let mut data = wincode::serialize(&transaction).map_err(wincode::Error::from)?;
// Select the private wire format before signing; its payload limit exceeds V1's.
Expand Down
4 changes: 3 additions & 1 deletion programs/magic-root-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub enum MagicRootInstruction {
/// (e.g. initializing a freshly created account); each is invoked via CPI
/// against the accounts it declares.
PostFinalize(PostFinalize),
/// Distinguishes repeated private operations without changing account state.
Nonce(u64),
}

impl MagicRootInstruction {
Expand Down Expand Up @@ -79,7 +81,7 @@ impl MagicRootInstruction {
};
for ix in &post_finalize.actions {
accounts.push(AccountMeta::new_readonly(ix.program_id, false));
let metas = ix.accounts.clone().into_iter().map(|mut meta| {
let metas = ix.accounts.iter().cloned().map(|mut meta| {
meta.is_signer = false;
meta
});
Expand Down
1 change: 1 addition & 0 deletions programs/magic-root-program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fn dispatch(
MagicRootInstruction::Finalize(flags) => account::finalize(ctx, target, flags),
MagicRootInstruction::Delete => account::delete(ctx, target),
MagicRootInstruction::PostFinalize(actions) => post_finalize::process(ctx, actions),
MagicRootInstruction::Nonce(_) => Ok(()),
}
}

Expand Down
Loading