Skip to content

feat: add customized solana-account crate - #13

Open
bmuddha wants to merge 1 commit into
solana-upstreamfrom
solana-account
Open

feat: add customized solana-account crate#13
bmuddha wants to merge 1 commit into
solana-upstreamfrom
solana-account

Conversation

@bmuddha

@bmuddha bmuddha commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

What changed

Customized the imported solana-account baseline with owned and copy-on-write
account representations, borrowed account layout helpers, codec helpers, sysvar
support, and focused tests.

Why

accountsdb needs an account representation that can borrow from mapped storage
and promote to owned storage only when writes require it.

Closes #5.

Impact

  • Replaces the upstream account representation with Account,
    AccountSharedData, and a borrowed/owned copy-on-write model.
  • Defines the borrowed in-memory layout used by storage-backed accounts.
  • Registers the customized crate in the workspace while keeping mutability and
    routing decisions above this crate.

Reviewer notes

The borrowed layout is layout-bound and must stay 8-byte aligned. This crate
should remain storage-source agnostic.

Follow-up

transaction-context, program-runtime, and svm adapt to this representation
in the next stack PRs; storage consumers arrive later.

@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new solana-account crate with owned and copy-on-write account representations, aligned borrowed storage, account traits, serialization and sysvar helpers, patch handling, test utilities, and extensive validation.

Changes

solana-account crate

Layer / File(s) Summary
Workspace and crate manifest setup
.gitattributes, .gitignore, Cargo.toml, solana/account/Cargo.toml, solana/account/README.md
Registers the crate, centralizes dependencies and features, updates repository metadata, and documents the borrowed storage layout.
Core account type and traits
solana/account/src/account.rs, solana/account/src/codec.rs, solana/account/src/traits.rs
Adds Account, serialization and account-info helpers, bincode codecs, and readable/writable account abstractions.
Borrowed zero-copy buffer layout
solana/account/src/cow/borrowed.rs
Adds aligned double-buffered account storage with sequence-based commit, reset, rollback, and mutable data operations.
Owned storage and shared account orchestration
solana/account/src/cow/owned.rs, solana/account/src/cow/mod.rs
Adds owned serialization, account building, copy-on-write promotion, dirty tracking, account modes, flags, conversions, and sequence-locked reads.
Patches, typed state, and sysvar helpers
solana/account/src/patch.rs, solana/account/src/state_traits.rs, solana/account/src/sysvar.rs
Adds account field patches, typed bincode state access, and sysvar account construction and conversion functions.
Crate wiring, testkit, and validation
solana/account/src/lib.rs, solana/account/src/testkit.rs, solana/account/src/tests/*, solana/account/src/cow/tests.rs
Wires modules and re-exports, provides aligned borrowed-account test utilities, and tests account mutations, serialization, copy-on-write behavior, borrowed image lifecycle, typed state, sysvar round trips, and sequence-lock reads.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant AccountSharedData
  participant CoWAccount
  participant BorrowedAccount
  participant AccountHeader
  Caller->>AccountSharedData: update account data
  AccountSharedData->>CoWAccount: request mutable backing
  CoWAccount->>BorrowedAccount: translate or promote
  BorrowedAccount->>AccountHeader: stage shadow image
  Caller->>BorrowedAccount: commit
  BorrowedAccount->>AccountHeader: publish sequence
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the requested solana-account fork and copy-on-write storage support for accountsdb.
Out of Scope Changes check ✅ Passed No clearly unrelated code changes stand out beyond the crate, helpers, tests, and supporting config.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title clearly summarizes the main change: a customized solana-account crate.
Description check ✅ Passed The description matches the changeset and explains the account model, helpers, tests, and purpose.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch solana-account

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.

@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: 3

🤖 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/account/src/lib.rs`:
- Around line 13-15: Update the cfg attribute on the test_utils module to expose
it during ordinary unit-test builds as well as when the dev-context-only-utils
feature is enabled. Preserve the existing feature-gated behavior and ensure
tests/account.rs can resolve crate::test_utils under cfg(test).

In `@solana/account/src/test_utils.rs`:
- Around line 43-57: Make init_borrowed_account, borrowed_shared_data, and
active_borrowed_data unsafe or otherwise bind returned views to owned storage,
preventing arbitrary buffers from creating lifetime-free borrowed-layout views.
Document explicit caller obligations to provide a valid BorrowedAccount layout
and keep the backing buffer alive for every returned view; preserve
active_borrowed_data’s validation requirement as well.

In `@solana/account/src/tests/account.rs`:
- Around line 277-285: Update solana/account/src/tests/account.rs lines 277-285
in test_account_cow_borrowed_extend_promotes to append capacity - len + 1 bytes
and assert shared.cow() matches CoWAccount::Owned(_); update lines 342-353 in
the related set_data_at promotion test to either force and assert promotion or
rename it to describe in-capacity behavior, keeping the test names and
assertions factually consistent.
🪄 Autofix (Beta)

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

Run ID: 094db5d7-ce72-45fb-be2a-717761c2f6eb

📥 Commits

Reviewing files that changed from the base of the PR and between 111e103 and 022b15c.

📒 Files selected for processing (22)
  • .gitattributes
  • .gitignore
  • Cargo.toml
  • solana/account/Cargo.toml
  • solana/account/README.md
  • solana/account/src/account.rs
  • solana/account/src/codec.rs
  • solana/account/src/cow/borrowed.rs
  • solana/account/src/cow/mod.rs
  • solana/account/src/cow/owned.rs
  • solana/account/src/cow/tests.rs
  • solana/account/src/lib.rs
  • solana/account/src/patch.rs
  • solana/account/src/state_traits.rs
  • solana/account/src/sysvar.rs
  • solana/account/src/test_utils.rs
  • solana/account/src/tests/account.rs
  • solana/account/src/tests/mod.rs
  • solana/account/src/tests/state_traits.rs
  • solana/account/src/tests/sysvar.rs
  • solana/account/src/traits.rs
  • src/lib.rs
💤 Files with no reviewable changes (1)
  • src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (17)
  • solana/account/src/tests/sysvar.rs
  • .gitignore
  • solana/account/src/tests/state_traits.rs
  • solana/account/src/tests/mod.rs
  • .gitattributes
  • solana/account/src/codec.rs
  • solana/account/src/cow/tests.rs
  • solana/account/Cargo.toml
  • Cargo.toml
  • solana/account/README.md
  • solana/account/src/state_traits.rs
  • solana/account/src/patch.rs
  • solana/account/src/cow/owned.rs
  • solana/account/src/cow/mod.rs
  • solana/account/src/traits.rs
  • solana/account/src/sysvar.rs
  • solana/account/src/account.rs

Comment thread solana/account/src/lib.rs Outdated
Comment on lines +13 to +15
/// Test-only helpers for borrowed account buffers.
#[cfg(feature = "dev-context-only-utils")]
pub mod test_utils;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Expose these helpers when compiling unit tests.

tests/account.rs imports crate::test_utils, but cfg(test) alone does not enable this feature, causing unresolved imports during ordinary unit-test builds.

Proposed fix
-#[cfg(feature = "dev-context-only-utils")]
+#[cfg(any(test, feature = "dev-context-only-utils"))]
 pub mod test_utils;

As per path instructions, Rust workspace reviews must prioritize API contract correctness.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Test-only helpers for borrowed account buffers.
#[cfg(feature = "dev-context-only-utils")]
pub mod test_utils;
/// Test-only helpers for borrowed account buffers.
#[cfg(any(test, feature = "dev-context-only-utils"))]
pub mod test_utils;
🤖 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/account/src/lib.rs` around lines 13 - 15, Update the cfg attribute on
the test_utils module to expose it during ordinary unit-test builds as well as
when the dev-context-only-utils feature is enabled. Preserve the existing
feature-gated behavior and ensure tests/account.rs can resolve crate::test_utils
under cfg(test).

Source: Path instructions

Comment thread solana/account/src/testkit.rs
Comment on lines +277 to +285
#[test]
// Writing past borrowed capacity should promote to owned storage.
fn test_account_cow_borrowed_extend_promotes() {
let (_buf, mut shared) = make_borrowed(vec![7, 8]);

shared.extend_from_slice(&[9]);

assert_eq!(shared.data(), &[7, 8, 9]);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make the promotion tests actually cross capacity and assert owned storage.

Both tests currently verify only resulting bytes, so they can pass while storage remains borrowed.

  • solana/account/src/tests/account.rs#L277-L285: append capacity - len + 1 bytes and assert matches!(shared.cow(), CoWAccount::Owned(_)).
  • solana/account/src/tests/account.rs#L342-L353: either force and assert one promotion or rename the test to describe in-capacity set_data_at behavior.

As per path instructions, Rust tests and documentation must remain factually consistent with behavior.

📍 Affects 1 file
  • solana/account/src/tests/account.rs#L277-L285 (this comment)
  • solana/account/src/tests/account.rs#L342-L353
🤖 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/account/src/tests/account.rs` around lines 277 - 285, Update
solana/account/src/tests/account.rs lines 277-285 in
test_account_cow_borrowed_extend_promotes to append capacity - len + 1 bytes and
assert shared.cow() matches CoWAccount::Owned(_); update lines 342-353 in the
related set_data_at promotion test to either force and assert promotion or
rename it to describe in-capacity behavior, keeping the test names and
assertions factually consistent.

Source: Path instructions

@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

🧹 Nitpick comments (1)
solana/account/Cargo.toml (1)

15-21: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Gate the serde feature for bitflags.

The bitflags dependency currently enables its serde feature unconditionally, which pulls serde into the dependency tree even when the crate's serde feature is disabled. Consider gating it behind this crate's serde feature to ensure true optionality.

♻️ Proposed refactor
 [features]
 bincode = ["dep:bincode", "dep:solana-sysvar", "serde"]
-serde = ["dep:serde", "dep:serde_bytes", "serde/rc", "solana-pubkey/serde"]
+serde = ["dep:serde", "dep:serde_bytes", "serde/rc", "solana-pubkey/serde", "bitflags/serde"]
 testkit = ["bincode"]
 wincode = ["bincode", "dep:wincode", "solana-pubkey/wincode"]
 
 [dependencies]
 bincode = { workspace = true, optional = true }
-bitflags = { workspace = true, features = ["serde"] }
+bitflags = { workspace = true }
 serde = { workspace = true, optional = true }
🤖 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/account/Cargo.toml` around lines 15 - 21, Update the bitflags
dependency declaration in the crate’s [dependencies] section to stop enabling
its serde feature unconditionally; gate bitflags’ serde support through this
crate’s serde feature while preserving the existing dependency and feature
behavior otherwise.
🤖 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/account/src/cow/mod.rs`:
- Around line 39-44: Update AccountSharedData and its CoWAccount implementations
so cloning a Borrowed value materializes an owned snapshot rather than sharing
external backing storage with independent DirtyMarkers. Restrict DerefMut for
borrowed representations to prevent aliased mutable AccountCore access, and
remove any Sync implementation or bound until backing-memory synchronization
guarantees data-race-free access.

---

Nitpick comments:
In `@solana/account/Cargo.toml`:
- Around line 15-21: Update the bitflags dependency declaration in the crate’s
[dependencies] section to stop enabling its serde feature unconditionally; gate
bitflags’ serde support through this crate’s serde feature while preserving the
existing dependency and feature behavior otherwise.
🪄 Autofix (Beta)

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

Run ID: 4b51a94e-77a8-4a0d-9eb9-e29e3dfc7a6f

📥 Commits

Reviewing files that changed from the base of the PR and between 022b15c and e3ae73f.

📒 Files selected for processing (22)
  • .gitattributes
  • .gitignore
  • Cargo.toml
  • solana/account/Cargo.toml
  • solana/account/README.md
  • solana/account/src/account.rs
  • solana/account/src/codec.rs
  • solana/account/src/cow/borrowed.rs
  • solana/account/src/cow/mod.rs
  • solana/account/src/cow/owned.rs
  • solana/account/src/cow/tests.rs
  • solana/account/src/lib.rs
  • solana/account/src/patch.rs
  • solana/account/src/state_traits.rs
  • solana/account/src/sysvar.rs
  • solana/account/src/testkit.rs
  • solana/account/src/tests/account.rs
  • solana/account/src/tests/mod.rs
  • solana/account/src/tests/state_traits.rs
  • solana/account/src/tests/sysvar.rs
  • solana/account/src/traits.rs
  • src/lib.rs
💤 Files with no reviewable changes (1)
  • src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (18)
  • .gitattributes
  • solana/account/src/codec.rs
  • solana/account/README.md
  • solana/account/src/tests/sysvar.rs
  • solana/account/src/tests/state_traits.rs
  • .gitignore
  • solana/account/src/lib.rs
  • Cargo.toml
  • solana/account/src/cow/tests.rs
  • solana/account/src/patch.rs
  • solana/account/src/tests/mod.rs
  • solana/account/src/traits.rs
  • solana/account/src/sysvar.rs
  • solana/account/src/cow/borrowed.rs
  • solana/account/src/state_traits.rs
  • solana/account/src/cow/owned.rs
  • solana/account/src/tests/account.rs
  • solana/account/src/account.rs

Comment thread solana/account/src/cow/mod.rs Outdated
Comment on lines +39 to +44
#[derive(PartialEq, Eq, Clone, Default)]
pub struct AccountSharedData {
/// Backing storage, borrowed until promotion or direct construction.
pub(crate) cow: CoWAccount,
/// Fields changed through the writable APIs.
pub(crate) dirty: DirtyMarkers,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🔴 Critical | 🏗️ Heavy lift

Do not make borrowed storage safely cloneable, mutable, and Sync.

A cloned Borrowed variant still targets the same external image but has independent dirty state. Two clean clones can therefore translate the same active image into the same shadow buffer, overwriting edits; DerefMut can also produce aliased &mut AccountCore references. Declaring this representation Sync further permits data races that sequence retries cannot make memory-safe.

Make borrowed clones produce owned snapshots, restrict direct DerefMut, and only implement Sync once the backing-memory synchronization contract guarantees data-race-free access.

As per path instructions, Rust workspace code must prioritize ownership, unsafe usage, concurrency, and API contract correctness.

Also applies to: 81-87, 408-414, 637-639

🤖 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/account/src/cow/mod.rs` around lines 39 - 44, Update AccountSharedData
and its CoWAccount implementations so cloning a Borrowed value materializes an
owned snapshot rather than sharing external backing storage with independent
DirtyMarkers. Restrict DerefMut for borrowed representations to prevent aliased
mutable AccountCore access, and remove any Sync implementation or bound until
backing-memory synchronization guarantees data-race-free access.

Source: Path instructions

@bmuddha
bmuddha force-pushed the solana-account branch 4 times, most recently from 9d337aa to 0905923 Compare July 21, 2026 19:46
@bmuddha
bmuddha force-pushed the solana-account branch 2 times, most recently from 28eacdd to 3b5ca59 Compare July 27, 2026 13:19
@bmuddha
bmuddha changed the base branch from master to graphite-base/13 July 27, 2026 13:32
@bmuddha
bmuddha changed the base branch from graphite-base/13 to solana-upstream July 27, 2026 13:32
@bmuddha
bmuddha force-pushed the solana-account branch 2 times, most recently from 54be71a to d1e8c56 Compare July 28, 2026 14:25
@bmuddha
bmuddha force-pushed the solana-account branch 3 times, most recently from f30b82c to 8af975f Compare July 31, 2026 13:48
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-account for copy-on-write account storage

1 participant