Skip to content

feat: add transaction context crate - #19

Open
bmuddha wants to merge 2 commits into
transaction-viewfrom
transaction-context
Open

feat: add transaction context crate#19
bmuddha wants to merge 2 commits into
transaction-viewfrom
transaction-context

Conversation

@bmuddha

@bmuddha bmuddha commented May 28, 2026

Copy link
Copy Markdown
Collaborator

What changed

Customized the imported solana-transaction-context baseline for the engine's
account representation and patched the crate into the workspace.

Why

VM handlers need to remap account data on writes through a mapped region instead
of copying through a serialized input buffer.

Closes #10.

Impact

  • Reshapes TransactionContext, InstructionContext, and
    TransactionAccounts around AccountRef and AccountRefMut views.
  • Keeps accounts in UnsafeCell behind explicit borrow counters so borrows stay
    local to the context.
  • Returns keyed accounts, return data, touched-account count, and resize deltas
    through ExecutionRecord.

Reviewer notes

Borrow counters are released on drop; outstanding references must be gone before
a context is deconstructed. The mapped-account divergences are documented in
solana/README.md.

Follow-up

program-runtime and svm consume this customized context upstack.

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9edbdc96-cee0-4aa4-9e18-1d1760d94359

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Invalid input: expected boolean, received string at "reviews.auto_review.enabled"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

The forked solana-transaction-context crate is integrated into the workspace. It now uses unified account storage, direct account views, updated CPI trace accounting, explicit resize restrictions, and direct account-region remapping.

Changes

Transaction context fork

Layer / File(s) Summary
Workspace and crate integration
Cargo.toml, solana/transaction-context/Cargo.toml, solana/transaction-context/README.md, solana/transaction-context/src/lib.rs
The workspace registers the crate and updates Solana and Agave dependencies. Crate metadata, features, documentation, and lint settings now use workspace-compatible values.
Unified account storage and views
solana/transaction-context/src/transaction_accounts.rs
TransactionAccounts stores AccountSharedData directly. Immutable and mutable views use dereferencing and copy-on-write borrowing. Deconstruction preserves account metadata and dirty markers.
Account access and resize rules
solana/transaction-context/src/instruction.rs, solana/transaction-context/src/instruction_accounts.rs
Program ownership uses direct account borrowing. Borrowed CoW accounts count as shared. Ephemeral-account resizing returns InvalidRealloc.
Instruction trace and memory execution
solana/transaction-context/src/transaction.rs, solana/transaction-context/src/vm_slice.rs
Instruction execution uses placeholder frames, sequential trace indices, explicit CPI and total-trace limits, active-instruction counting, and direct remapping after account growth. Tests cover the revised trace and CPI behavior.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related issues

  • Issue 32 — The PR modifies the same imported solana/transaction-context crate described by the issue.

Possibly related PRs

  • magicblock-labs/magicblock-engine#31 — Both PRs modify solana/transaction-context; this PR further changes its account, instruction, memory, and transaction-context implementations.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: adding the customized transaction context crate.
Description check ✅ Passed The description explains the crate fork, engine account model changes, mapped writes, and workspace integration.
Linked Issues check ✅ Passed The changes fork and adapt solana-transaction-context for engine execution and its account representation as required by issue [#10].
Out of Scope Changes check ✅ Passed The workspace, documentation, dependency, account model, and transaction context changes support the linked issue objectives.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch transaction-context

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@bmuddha
bmuddha force-pushed the transaction-context branch from c4029f9 to e4a023f Compare May 29, 2026 09:08
@bmuddha
bmuddha force-pushed the transaction-context branch 2 times, most recently from 27ca11d to ff1197d Compare June 1, 2026 15:29
@bmuddha
bmuddha force-pushed the transaction-context branch 2 times, most recently from 7f5babf to b1bb9fd Compare June 5, 2026 12:10
@bmuddha
bmuddha force-pushed the transaction-context branch from b1bb9fd to f7c2bac Compare June 16, 2026 10:08
@bmuddha
bmuddha force-pushed the transaction-context branch from f7c2bac to 881f449 Compare June 22, 2026 19:14
@bmuddha
bmuddha force-pushed the transaction-context branch from 881f449 to 59ad79e Compare June 23, 2026 14:17
@bmuddha
bmuddha force-pushed the transaction-context branch from f8d3173 to 0ef24b5 Compare July 21, 2026 19:46
@bmuddha
bmuddha force-pushed the transaction-context branch from 0ef24b5 to a1c175f Compare July 26, 2026 13:14
@bmuddha
bmuddha force-pushed the transaction-context branch from a1c175f to cd9fd68 Compare July 27, 2026 13:19
@bmuddha
bmuddha force-pushed the transaction-context branch from cd9fd68 to 80378f1 Compare July 27, 2026 13:32
@bmuddha
bmuddha force-pushed the transaction-context branch from 80378f1 to e041528 Compare July 27, 2026 14:17
@bmuddha
bmuddha force-pushed the transaction-context branch from e041528 to e7b59e5 Compare July 28, 2026 14:25
@bmuddha
bmuddha force-pushed the transaction-context branch from e7b59e5 to f78da53 Compare July 28, 2026 20:16
@bmuddha
bmuddha changed the base branch from solana-account to graphite-base/19 July 30, 2026 17:51
@bmuddha
bmuddha force-pushed the transaction-context branch from f78da53 to 7125534 Compare July 30, 2026 17:51
@bmuddha
bmuddha changed the base branch from graphite-base/19 to transaction-view July 30, 2026 17:51
@bmuddha
bmuddha force-pushed the transaction-context branch from 7125534 to 2e0b538 Compare July 30, 2026 18:20
@bmuddha

bmuddha commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
solana/transaction-context/src/instruction_accounts.rs (1)

226-243: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use is_shared() with borrowed accounts and update the reserve behavior.

make_data_mut() currently skips borrowed accounts, so get_data_mut() and extend_from_slice() can trigger borrowed-to-owned promotion later. CoWAccount::reserve() keeps the borrowed image when spare() is enough, so replace AccountSharedData::is_shared() with self.is_shared() and update the stale “second-copy” comment unless the reserve path always promotes.

🔧 Proposed fix if borrowed images need the reserve
-        if self.account.is_shared() {
+        if self.is_shared() {
             self.account.reserve(MAX_ACCOUNT_DATA_GROWTH_PER_INSTRUCTION);
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@solana/transaction-context/src/instruction_accounts.rs` around lines 226 -
243, Update make_data_mut() to use the InstructionAccount::is_shared() helper,
so both shared buffers and borrowed CoWAccount variants enter the reserve path.
Revise the nearby comment to accurately describe the reserve behavior and remove
the stale claim about avoiding a second copy unless CoWAccount::reserve() is
guaranteed to promote borrowed images.
🧹 Nitpick comments (1)
solana/transaction-context/src/transaction_accounts.rs (1)

188-199: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Both deconstruct methods drain the same storage.

deconstruct_into_keyed_account_shared_data and deconstruct_into_account_shared_data both call std::mem::take(&mut self.accounts). After the first call the array is empty, so the second call returns an empty Vec without any error. borrow_counters and touched_flags keep their original length, so len() and index-based access become inconsistent with the storage.

Consider making the drain explicit at the type level, or add a debug assertion that the storage is still populated.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@solana/transaction-context/src/transaction_accounts.rs` around lines 188 -
199, Update deconstruct_into_keyed_account_shared_data and
deconstruct_into_account_shared_data to make draining self.accounts explicit and
prevent silent repeated deconstruction; ensure the second call cannot return an
empty result while borrow_counters and touched_flags retain stale lengths,
either through a consumed-state representation or a debug assertion before
draining.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@solana/transaction-context/src/transaction_accounts.rs`:
- Around line 152-156: Update try_borrow_mut so it projects directly to the
KeyedAccountSharedData tuple’s account field (.1) from the UnsafeCell pointer,
rather than first creating a mutable reference to the whole keyed account. Keep
AccountRefMut and borrow-counter behavior unchanged while ensuring the mutable
borrow excludes the key field.

---

Outside diff comments:
In `@solana/transaction-context/src/instruction_accounts.rs`:
- Around line 226-243: Update make_data_mut() to use the
InstructionAccount::is_shared() helper, so both shared buffers and borrowed
CoWAccount variants enter the reserve path. Revise the nearby comment to
accurately describe the reserve behavior and remove the stale claim about
avoiding a second copy unless CoWAccount::reserve() is guaranteed to promote
borrowed images.

---

Nitpick comments:
In `@solana/transaction-context/src/transaction_accounts.rs`:
- Around line 188-199: Update deconstruct_into_keyed_account_shared_data and
deconstruct_into_account_shared_data to make draining self.accounts explicit and
prevent silent repeated deconstruction; ensure the second call cannot return an
empty result while borrow_counters and touched_flags retain stale lengths,
either through a consumed-state representation or a debug assertion before
draining.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: cb022939-1ae9-4679-8c8f-61d29221d71e

📥 Commits

Reviewing files that changed from the base of the PR and between 86c2748 and 017643e.

📒 Files selected for processing (10)
  • Cargo.toml
  • solana/transaction-context/Cargo.toml
  • solana/transaction-context/README.md
  • solana/transaction-context/src/instruction.rs
  • solana/transaction-context/src/instruction_accounts.rs
  • solana/transaction-context/src/lib.rs
  • solana/transaction-context/src/transaction.rs
  • solana/transaction-context/src/transaction_accounts.rs
  • solana/transaction-context/src/vm_addresses.rs
  • solana/transaction-context/src/vm_slice.rs
💤 Files with no reviewable changes (1)
  • solana/transaction-context/src/vm_addresses.rs

Comment thread solana/transaction-context/src/transaction_accounts.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fork solana-transaction-context for engine execution

1 participant