Skip to main content

Overview

Commit instructions write account state from Ephemeral Rollups (ER) back to the Solana base layer. This page covers manual commit operations, combined increment+commit patterns, and undelegation.

Manual Commit Operations

Using commit_accounts Function

The commit_accounts function commits delegated account state back to the base layer without undelegating.
anchor-counter/programs/anchor-counter/src/lib.rs

Using commit_and_undelegate_accounts Function

The commit_and_undelegate_accounts function commits state and returns ownership to the original program.
anchor-counter/programs/anchor-counter/src/lib.rs

Commit Function Parameters

&Signer
required
The account paying for the commit transaction fees
Vec<&AccountInfo>
required
Vector of account references to commit. Can include multiple accounts in a single commit.
&AccountInfo
required
The MagicBlock context account containing ER state information
&AccountInfo
required
The MagicBlock program account that processes commits

The #[commit] Macro

Anchor Account Context

The #[commit] macro automatically adds the required MagicBlock accounts to your instruction context.
anchor-counter/programs/anchor-counter/src/lib.rs

Auto-Generated Accounts

The #[commit] macro adds these accounts to your context:
Program
The MagicBlock program account (auto-generated)
AccountInfo
The MagicBlock context account (auto-generated)

Increment and Commit Pattern

Combined Operation

The increment and commit pattern performs account updates and commits them in a single transaction:
anchor-counter/programs/anchor-counter/src/lib.rs
Call counter.exit(&crate::ID)? before committing to ensure Anchor account data is properly serialized.

Increment and Undelegate Pattern

Combine increment with commit and undelegation:
anchor-counter/programs/anchor-counter/src/lib.rs

Native Rust Commit Pattern

Commit Implementation

rust-counter/src/processor.rs

Commit and Undelegate Implementation

rust-counter/src/processor.rs

Native Rust Required Accounts

Signer
required
The payer and signer for the commit transaction. Must be a valid signer.
AccountInfo
required
The account(s) to commit. Can be any delegated account.
AccountInfo
required
The MagicBlock program account
AccountInfo
required
The MagicBlock context account

Increment and Commit (Native Rust)

Combined Increment and Commit

rust-counter/src/processor.rs

Combined Increment and Undelegate

rust-counter/src/processor.rs

Pinocchio Commit Pattern

Commit with Pinocchio

pinocchio-counter/src/processor.rs

Commit and Undelegate with Pinocchio

pinocchio-counter/src/processor.rs

Best Practices

  1. Always verify signers - Ensure the payer is a valid signer before committing
  2. Serialize Anchor accounts - Call exit() on Anchor accounts before committing
  3. Validate PDAs - Verify PDA derivation matches expected seeds
  4. Batch commits when possible - Pass multiple accounts in the vector to reduce transactions
  5. Choose commit vs undelegate wisely - Use commit_accounts to keep delegation active, commit_and_undelegate_accounts to return control

Common Patterns

Multi-Account Commit

Conditional Commit