Skip to content

feat: add confined flag#23

Merged
thlorenz merged 1 commit into
mainfrom
thlorenz/confined-flag
Nov 27, 2025
Merged

feat: add confined flag#23
thlorenz merged 1 commit into
mainfrom
thlorenz/confined-flag

Conversation

@thlorenz
Copy link
Copy Markdown
Contributor

@thlorenz thlorenz commented Nov 25, 2025

Summary

Add a new confined flag to the account type to indicate that an account's usage is limited. When this flag is set, operations like changing lamports or data size are restricted. This complements existing flags like delegated, compressed, and undelegating.

Details

The confined flag is implemented as a new bit in the existing flag structure:

  • Added CONFINED_FLAG_INDEX constant (index 5) in the flag hierarchy
  • Implemented set_confined() and confined() methods on AccountSharedData to manage the flag state
  • The flag properly handles both owned and borrowed account variants, with automatic conversion to owned when setting on borrowed accounts
  • Added comprehensive tests to verify flag persistence and independence from other flags
  • Updated the Debug implementation to include the confined flag state

Summary by CodeRabbit

  • New Features

    • Added confined state tracking capability for accounts with new methods to set and query confined status.
  • Tests

    • Added unit test coverage for confined flag persistence across state lifecycle.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 25, 2025

Walkthrough

This PR introduces a new confined flag to the account state system by adding a confined flag index to the bitfield, integrating it into copy-on-write account representations, and exposing public API methods on AccountSharedData to manage and query this flag state. A persistence test verifies the flag lifecycle through serialization cycles.

Changes

Cohort / File(s) Summary
Confined flag core implementation
src/cow.rs
Introduces confined flag index (5) to the bitfield, adds confined flag support to AccountBorrowed and AccountOwned struct flag fields, and adds unit test verifying flag persistence across CoW cycles
Public API exposure
src/lib.rs
Adds CONFINED_FLAG_INDEX to imports, introduces set_confined(bool) and confined() -> bool public methods on AccountSharedData, and updates debug representation to include the new confined field

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Homogeneous pattern: Changes follow the existing flag implementation model consistently across both files
  • Limited logic complexity: Straightforward accessor/mutator methods with no intricate logic
  • Test follows established persistence verification pattern

Possibly related PRs

  • PR #21: Adds the undelegating flag with parallel modifications to flag bitfield, CoW representations, and AccountSharedData API surface
  • PR #18: Modifies the same bit-packed flag system by adding a new flag with corresponding getter/setter methods

Suggested reviewers

  • bmuddha

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add confined flag' directly and accurately reflects the main change in the changeset, which introduces a new confined flag to account representations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch thlorenz/confined-flag

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5afcedc and 7390235.

📒 Files selected for processing (2)
  • src/cow.rs (4 hunks)
  • src/lib.rs (4 hunks)
🔇 Additional comments (8)
src/cow.rs (4)

82-82: LGTM! Flag index properly sequenced.

The CONFINED_FLAG_INDEX constant correctly continues the sequence at index 5, following the existing flags (0-4).


128-128: LGTM! Documentation updated correctly.

The flags comment properly documents the new confined flag at bit index 5.


290-290: LGTM! Flags comment updated consistently.

The AccountOwned flags comment correctly includes the confined flag at bit 5, matching the AccountBorrowed documentation.


1066-1073: LGTM! Persistence test follows established pattern.

The test correctly validates that the confined flag persists across serialization/deserialization cycles using the shared test helper.

src/lib.rs (4)

5-6: LGTM! Import added correctly.

The CONFINED_FLAG_INDEX constant is properly imported from the cow module.


480-480: LGTM! Debug output updated.

The Debug implementation correctly includes the confined flag in the output.


1368-1402: LGTM! Comprehensive flag test.

The test thoroughly validates the confined flag's default state, mutation behavior, and independence from other flags.


762-788: Based on my comprehensive verification of the codebase, I can now provide the rewritten review comment:


Confined flag is infrastructure-only; enforcement not yet implemented.

The code correctly implements the flag infrastructure (storage, getter, setter, CoW handling). However, the documentation at line 782 claims "we cannot change the lamports or data size of such an account," but no enforcement of these restrictions exists in the codebase. The confined flag is never checked in set_lamports(), set_data(), or related methods.

This appears to be intentional—the flag infrastructure is being added in this PR for future use, similar to how other flags (delegated, compressed, undelegating) exist but are also not enforced. Confirm this is the intended design (flag foundation now, enforcement later) or if enforcement should be added in this PR.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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 and usage tips.

@thlorenz thlorenz requested a review from bmuddha November 25, 2025 18:33
Copy link
Copy Markdown
Collaborator

@bmuddha bmuddha left a comment

Choose a reason for hiding this comment

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

LGTM

@thlorenz thlorenz merged commit 1beed4c into main Nov 27, 2025
2 checks passed
@thlorenz thlorenz deleted the thlorenz/confined-flag branch November 27, 2025 08:09
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.

3 participants