Skip to content

refactor: reorganize to move api functionalities to dlp_api#152

Merged
snawaz merged 1 commit intomainfrom
snawaz/restruct
Mar 17, 2026
Merged

refactor: reorganize to move api functionalities to dlp_api#152
snawaz merged 1 commit intomainfrom
snawaz/restruct

Conversation

@snawaz
Copy link
Contributor

@snawaz snawaz commented Mar 17, 2026

With this PR, now we have:

  • dlp_api that contains all user-facing types: args, state, ix builder, encryption/decryption, etc.
  • dlp contains the processors only (basically onchain-only specific stuff).

From now on, users (sdk, validator etc) will use dlp_api only.

Copy link
Contributor Author

snawaz commented Mar 17, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

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

The PR introduces a local dlp-api crate as a workspace dependency and updates Cargo features: root diff now references dlp-api/diff, sdk is extended, and unit_test_config (backed by dlp-api/unit_test_config) is added. dlp-api/Cargo.toml adds explicit public dependencies and new features (diff, unit_test_config, cpi, instruction) and updates defaults. Code changes: two Address constants no longer feature-gated, two pinocchio-related DlpError impls removed, many require_* helpers and a trait made public, numerous modules and re-exports added in dlp-api, and the program crate now re-exports from dlp_api. Several tests updated; some expected CU values raised from 1150 to 1200.

Suggested reviewers

  • GabrielePicco
  • taco-paco
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch snawaz/restruct
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

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

⚠️ Outside diff range comments (1)
Cargo.toml (1)

83-84: 🧹 Nitpick | 🔵 Trivial

Clarify feature differences between dev-dependencies.

In dev-dependencies, magicblock-delegation-program uses unit_test_config feature while dlp-api uses default features (including encryption). This is likely intentional for test coverage, but worth documenting if the test matrix relies on this distinction.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Cargo.toml` around lines 83 - 84, Add a brief comment in Cargo.toml (or the
repository README/tests docs) explaining why the dev-dependency entries differ:
that magicblock-delegation-program is included with the unit_test_config feature
enabled while dlp-api is pulled with default features (including encryption),
and note any test-matrix or coverage implications; reference the dev-dependency
entries named "magicblock-delegation-program" (feature: unit_test_config) and
"dlp-api" (default features/encryption) so readers understand this intentional
distinction.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@Cargo.toml`:
- Around line 83-84: Add a brief comment in Cargo.toml (or the repository
README/tests docs) explaining why the dev-dependency entries differ: that
magicblock-delegation-program is included with the unit_test_config feature
enabled while dlp-api is pulled with default features (including encryption),
and note any test-matrix or coverage implications; reference the dev-dependency
entries named "magicblock-delegation-program" (feature: unit_test_config) and
"dlp-api" (default features/encryption) so readers understand this intentional
distinction.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b61d89b6-ecfa-4369-90bf-bc56eb64df98

📥 Commits

Reviewing files that changed from the base of the PR and between 293e922 and 452c0b6.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (33)
  • Cargo.toml
  • dlp-api/Cargo.toml
  • dlp-api/src/account_size_class.rs
  • dlp-api/src/args/call_handler.rs
  • dlp-api/src/args/commit_state.rs
  • dlp-api/src/args/delegate.rs
  • dlp-api/src/args/delegate_ephemeral_balance.rs
  • dlp-api/src/args/delegate_with_actions.rs
  • dlp-api/src/args/mod.rs
  • dlp-api/src/args/top_up_ephemeral_balance.rs
  • dlp-api/src/args/types.rs
  • dlp-api/src/args/validator_claim_fees.rs
  • dlp-api/src/args/whitelist_validator_for_program.rs
  • dlp-api/src/compact/account_meta.rs
  • dlp-api/src/compact/instruction.rs
  • dlp-api/src/compact/mod.rs
  • dlp-api/src/consts.rs
  • dlp-api/src/discriminator.rs
  • dlp-api/src/error.rs
  • dlp-api/src/lib.rs
  • dlp-api/src/pda.rs
  • dlp-api/src/pod_view.rs
  • dlp-api/src/requires.rs
  • dlp-api/src/state/commit_record.rs
  • dlp-api/src/state/delegation_metadata.rs
  • dlp-api/src/state/delegation_record.rs
  • dlp-api/src/state/mod.rs
  • dlp-api/src/state/program_config.rs
  • dlp-api/src/state/utils/discriminator.rs
  • dlp-api/src/state/utils/mod.rs
  • dlp-api/src/state/utils/to_bytes.rs
  • dlp-api/src/state/utils/try_from_bytes.rs
  • src/lib.rs
💤 Files with no reviewable changes (2)
  • dlp-api/src/consts.rs
  • dlp-api/src/error.rs

@snawaz snawaz changed the title refactor: reorganize dlp_api and dlp such that all api-related functionalities are in api and dlp depends on it refactor: reorganize dlp_api and dlp such that all api-related functionalities are in api Mar 17, 2026
@snawaz snawaz changed the title refactor: reorganize dlp_api and dlp such that all api-related functionalities are in api refactor: reorganize such that all api-related functionalities are in dlp_api Mar 17, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Cargo.toml`:
- Line 49: The root Cargo.toml's unit_test_config feature is not forwarded to
the dlp-api dependency, so when magicblock-delegation-program enables
unit_test_config the dlp-api crate still builds without its unit_test_config
feature and its test-gated code (e.g., DEFAULT_VALIDATOR_IDENTITY in
dlp-api/src/consts.rs and require_authorization in dlp-api/src/requires.rs)
stays on production branches; fix this by updating the dependency entry for
dlp-api in Cargo.toml (the existing dlp-api = { package =
"magicblock-delegation-program-api", path = "dlp-api", default-features = false
} line) to include features = ["unit_test_config"] behind a conditional
forwarding of the root feature (i.e., forward the root unit_test_config to the
dependency) so enabling the root feature also enables dlp-api's
unit_test_config.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: b9cdcc78-4f9d-4a77-85b1-32a7300e1213

📥 Commits

Reviewing files that changed from the base of the PR and between 452c0b6 and 41390a4.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (33)
  • Cargo.toml
  • dlp-api/Cargo.toml
  • dlp-api/src/account_size_class.rs
  • dlp-api/src/args/call_handler.rs
  • dlp-api/src/args/commit_state.rs
  • dlp-api/src/args/delegate.rs
  • dlp-api/src/args/delegate_ephemeral_balance.rs
  • dlp-api/src/args/delegate_with_actions.rs
  • dlp-api/src/args/mod.rs
  • dlp-api/src/args/top_up_ephemeral_balance.rs
  • dlp-api/src/args/types.rs
  • dlp-api/src/args/validator_claim_fees.rs
  • dlp-api/src/args/whitelist_validator_for_program.rs
  • dlp-api/src/compact/account_meta.rs
  • dlp-api/src/compact/instruction.rs
  • dlp-api/src/compact/mod.rs
  • dlp-api/src/consts.rs
  • dlp-api/src/discriminator.rs
  • dlp-api/src/error.rs
  • dlp-api/src/lib.rs
  • dlp-api/src/pda.rs
  • dlp-api/src/pod_view.rs
  • dlp-api/src/requires.rs
  • dlp-api/src/state/commit_record.rs
  • dlp-api/src/state/delegation_metadata.rs
  • dlp-api/src/state/delegation_record.rs
  • dlp-api/src/state/mod.rs
  • dlp-api/src/state/program_config.rs
  • dlp-api/src/state/utils/discriminator.rs
  • dlp-api/src/state/utils/mod.rs
  • dlp-api/src/state/utils/to_bytes.rs
  • dlp-api/src/state/utils/try_from_bytes.rs
  • src/lib.rs
💤 Files with no reviewable changes (2)
  • dlp-api/src/error.rs
  • dlp-api/src/consts.rs

@snawaz snawaz changed the title refactor: reorganize such that all api-related functionalities are in dlp_api refactor: reorganize to move api functionalities to dlp_api Mar 17, 2026
@snawaz snawaz force-pushed the snawaz/restruct branch 2 times, most recently from 7f67404 to a40fa02 Compare March 17, 2026 12:36
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (4)
src/lib.rs (1)

49-54: 🛠️ Refactor suggestion | 🟠 Major

Use dlp_api::fast as the single source of truth.

The same Pinocchio program ID is now declared here and in dlp-api/src/lib.rs. Re-exporting the API crate’s fast module keeps the new crate boundary clean and removes a future drift point.

Suggested refactor
-#[cfg(any(feature = "processor", feature = "pinocchio-rt"))]
-pub mod fast {
-    pinocchio::address::declare_id!(
-        "DELeGGvXpWV2fqJUhqcF5ZSYMS4JTLjteaAMARRSaeSh"
-    );
-}
+#[cfg(any(feature = "processor", feature = "pinocchio-rt"))]
+pub use dlp_api::fast;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib.rs` around lines 49 - 54, Remove the local duplicate fast module and
its declare_id! invocation and instead re-export the API crate’s module so
dlp_api::fast is the single source of truth; replace the existing pub mod fast {
pinocchio::address::declare_id!(...); } block with a re-export like pub use
dlp_api::fast; so the program ID is maintained only in dlp_api and this crate
forwards that module.
dlp-api/src/instruction_builder/delegate_with_actions.rs (1)

29-35: ⚠️ Potential issue | 🟠 Major

Remove .expect() calls or encode preconditions in the function signature.

Line 31 panics when validator is None, but DelegateArgs.validator is Option<Pubkey>. Either require validator in the type signature or return Result<Instruction, _> to surface the error. Line 34 panics on encryption failure—propagate the EncryptionError instead of panicking.

(Line 71's to_vec().unwrap() is acceptable; serialization in instruction builders follows standard patterns.)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dlp-api/src/instruction_builder/delegate_with_actions.rs` around lines 29 -
35, The code currently panics via expect() when DelegateArgs.validator is None
and when actions.encrypt(...) fails; change delegate_with_actions.rs to surface
these failures instead: either make the function require a validator in its
signature (turn DelegateArgs.validator into Pubkey) or, preferably, change the
function return type to Result<Instruction, E> (or a crate error type) and
replace the expect on delegate.validator with an early-return Err when missing,
and replace the expect on actions.encrypt(...) to propagate the EncryptionError
(e.g., map or ?-return the error) so both missing validator and encryption
failures are returned to the caller instead of panicking. Ensure references to
delegate.validator and actions.encrypt are updated to use the new
error-returning control flow.
dlp-api/src/requires.rs (2)

835-845: 🧹 Nitpick | 🔵 Trivial

Consider adding a SAFETY comment for the raw pointer cast.

The bounds checking at line 831 ensures sufficient data length, but the unsafe block performing a raw pointer cast to &Address would benefit from an explicit SAFETY comment documenting the invariants being upheld (32-byte slice, alignment requirements for Address type).

📝 Suggested documentation
             let bytes = &data[offset_of_upgrade_authority_address + 1
                 ..offset_of_upgrade_authority_address + 33];
 
+            // SAFETY: `bytes` is exactly 32 bytes (verified by the length check above),
+            // and `Address` is a 32-byte array type with alignment of 1.
             let upgrade_authority_address =
                 unsafe { &*(bytes.as_ptr() as *const Address) };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dlp-api/src/requires.rs` around lines 835 - 845, Add a SAFETY comment
immediately above the unsafe cast that documents the invariants that make the
raw pointer cast safe: that the slice "bytes" is exactly 32 bytes (checked by
the earlier bounds check on data using offset_of_upgrade_authority_address),
that the memory is properly aligned for Address, that the lifetime of the
resulting &Address does not outlive data, and that the bytes represent a valid
Address bit pattern; reference the variables involved (bytes,
upgrade_authority_address, Address, data, offset_of_upgrade_authority_address,
admin.address(), and the require_eq_keys check) so future readers know why the
unsafe block is sound.

523-543: ⚠️ Potential issue | 🟡 Minor

Remove unused require_program function.

The #[allow(dead_code)] attribute indicates this function is never called. Verification confirms it has no usages anywhere in the codebase or tests. Dead code should be removed to reduce maintenance burden.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dlp-api/src/requires.rs` around lines 523 - 543, Remove the dead helper
function require_program and its attributes to eliminate unused code;
specifically delete the function signature and body that reference AccountView,
Address, and ProgramError (including the #[inline(always)] and
#[allow(dead_code)] annotations) from requires.rs, and run cargo check/tests to
confirm no references remain and nothing else needs adjustment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib.rs`:
- Around line 4-7: The crate's public API omits re-exporting check_id(),
breaking callers that expect dlp::check_id(...); update the pub use
dlp_api::{...} declaration to include check_id alongside ID and id so the root
crate re-exports the same symbols as solana_program::declare_id! (i.e., add
check_id to the list in the pub use dlp_api block that currently exports
account_size_class, args, ..., ID).

---

Outside diff comments:
In `@dlp-api/src/instruction_builder/delegate_with_actions.rs`:
- Around line 29-35: The code currently panics via expect() when
DelegateArgs.validator is None and when actions.encrypt(...) fails; change
delegate_with_actions.rs to surface these failures instead: either make the
function require a validator in its signature (turn DelegateArgs.validator into
Pubkey) or, preferably, change the function return type to Result<Instruction,
E> (or a crate error type) and replace the expect on delegate.validator with an
early-return Err when missing, and replace the expect on actions.encrypt(...) to
propagate the EncryptionError (e.g., map or ?-return the error) so both missing
validator and encryption failures are returned to the caller instead of
panicking. Ensure references to delegate.validator and actions.encrypt are
updated to use the new error-returning control flow.

In `@dlp-api/src/requires.rs`:
- Around line 835-845: Add a SAFETY comment immediately above the unsafe cast
that documents the invariants that make the raw pointer cast safe: that the
slice "bytes" is exactly 32 bytes (checked by the earlier bounds check on data
using offset_of_upgrade_authority_address), that the memory is properly aligned
for Address, that the lifetime of the resulting &Address does not outlive data,
and that the bytes represent a valid Address bit pattern; reference the
variables involved (bytes, upgrade_authority_address, Address, data,
offset_of_upgrade_authority_address, admin.address(), and the require_eq_keys
check) so future readers know why the unsafe block is sound.
- Around line 523-543: Remove the dead helper function require_program and its
attributes to eliminate unused code; specifically delete the function signature
and body that reference AccountView, Address, and ProgramError (including the
#[inline(always)] and #[allow(dead_code)] annotations) from requires.rs, and run
cargo check/tests to confirm no references remain and nothing else needs
adjustment.

In `@src/lib.rs`:
- Around line 49-54: Remove the local duplicate fast module and its declare_id!
invocation and instead re-export the API crate’s module so dlp_api::fast is the
single source of truth; replace the existing pub mod fast {
pinocchio::address::declare_id!(...); } block with a re-export like pub use
dlp_api::fast; so the program ID is maintained only in dlp_api and this crate
forwards that module.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: 99f76fd1-e601-4fd3-b3a8-19a9c30c7a31

📥 Commits

Reviewing files that changed from the base of the PR and between 41390a4 and a40fa02.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (40)
  • Cargo.toml
  • dlp-api/Cargo.toml
  • dlp-api/src/account_size_class.rs
  • dlp-api/src/args/call_handler.rs
  • dlp-api/src/args/commit_state.rs
  • dlp-api/src/args/delegate.rs
  • dlp-api/src/args/delegate_ephemeral_balance.rs
  • dlp-api/src/args/delegate_with_actions.rs
  • dlp-api/src/args/mod.rs
  • dlp-api/src/args/top_up_ephemeral_balance.rs
  • dlp-api/src/args/types.rs
  • dlp-api/src/args/validator_claim_fees.rs
  • dlp-api/src/args/whitelist_validator_for_program.rs
  • dlp-api/src/compact/account_meta.rs
  • dlp-api/src/compact/instruction.rs
  • dlp-api/src/compact/mod.rs
  • dlp-api/src/consts.rs
  • dlp-api/src/diff/algorithm.rs
  • dlp-api/src/diff/mod.rs
  • dlp-api/src/diff/types.rs
  • dlp-api/src/discriminator.rs
  • dlp-api/src/error.rs
  • dlp-api/src/instruction_builder/delegate_with_actions.rs
  • dlp-api/src/instruction_builder/mod.rs
  • dlp-api/src/lib.rs
  • dlp-api/src/pda.rs
  • dlp-api/src/pod_view.rs
  • dlp-api/src/requires.rs
  • dlp-api/src/state/commit_record.rs
  • dlp-api/src/state/delegation_metadata.rs
  • dlp-api/src/state/delegation_record.rs
  • dlp-api/src/state/mod.rs
  • dlp-api/src/state/program_config.rs
  • dlp-api/src/state/utils/discriminator.rs
  • dlp-api/src/state/utils/mod.rs
  • dlp-api/src/state/utils/to_bytes.rs
  • dlp-api/src/state/utils/try_from_bytes.rs
  • src/lib.rs
  • tests/test_commit_finalize.rs
  • tests/test_commit_finalize_from_buffer.rs
💤 Files with no reviewable changes (2)
  • dlp-api/src/consts.rs
  • dlp-api/src/error.rs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

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

⚠️ Outside diff range comments (1)
dlp-api/src/instruction_builder/delegate_with_actions.rs (1)

29-34: ⚠️ Potential issue | 🟠 Major

Avoid panic paths in the instruction builder.

Line 31, Line 34, and Line 71 use .expect()/.unwrap() in production code. These can abort callers on recoverable build failures (missing validator, encryption error, serialization error).

Proposed fix
-pub fn delegate_with_actions(
+pub fn delegate_with_actions(
     payer: Pubkey,
     delegated_account: Pubkey,
     owner: Option<Pubkey>,
     delegate: DelegateArgs,
     actions: Vec<PostDelegationInstruction>,
-) -> Instruction {
+) -> Result<Instruction, DelegateWithActionsBuildError> {
     let encrypt_key = delegate
         .validator
-        .expect("validator must be provided for encryption");
+        .ok_or(DelegateWithActionsBuildError::MissingValidator)?;
     let (actions, signers) = actions
         .encrypt(&encrypt_key)
-        .expect("post-delegation actions encryption failed");
+        .map_err(DelegateWithActionsBuildError::Encryption)?;
 
-    Instruction {
+    Ok(Instruction {
         program_id: dlp::id(),
         accounts: {
             let owner = owner.unwrap_or(system_program::id());
@@
         data: {
             let args = DelegateWithActionsArgs { delegate, actions };
             let mut data = DlpDiscriminator::DelegateWithActions.to_vec();
-            data.extend_from_slice(&to_vec(&args).unwrap());
+            let encoded = to_vec(&args)
+                .map_err(DelegateWithActionsBuildError::Serialization)?;
+            data.extend_from_slice(&encoded);
             data
         },
-    }
+    })
 }

As per coding guidelines {dlp-api,src}/**: Treat any usage of .unwrap() or .expect() in production Rust code as a MAJOR issue.

Also applies to: 71-71

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dlp-api/src/instruction_builder/delegate_with_actions.rs` around lines 29 -
34, The code currently panics by calling expect()/unwrap() when a validator is
missing, when actions.encrypt fails, and during serialization; change the
instruction builder (the function in delegate_with_actions.rs that constructs
post-delegation actions) to return a Result and propagate errors instead of
panicking: replace delegate.validator.expect(...) by matching the Option and
returning an Err variant (with a clear error enum/variant) when None, replace
actions.encrypt(...).expect(...) with actions.encrypt(&encrypt_key).map_err(|e|
/* convert to your function's error */)? so the error is propagated, and
similarly map or ? any serialization calls (the line around 71) to return errors
instead of unwrap(); update callers to handle the Result. Use the unique symbols
encrypt_key, delegate.validator, actions.encrypt, and the serialization call to
locate and change the code.
♻️ Duplicate comments (1)
src/lib.rs (1)

4-7: ⚠️ Potential issue | 🟠 Major

Re-export check_id to preserve root API compatibility.

Line 4-7 re-exports id/ID but omits check_id, which can break callers that previously used dlp::check_id(...).

Proposed fix
 pub use dlp_api::{
-    account_size_class, args, compact, consts, diff, discriminator, error, id,
+    account_size_class, args, check_id, compact, consts, diff, discriminator, error, id,
     pda, pod_view, requires, state, ID,
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib.rs` around lines 4 - 7, The crate currently re-exports id and ID from
dlp_api but omits check_id, breaking callers using dlp::check_id; update the
re-export statement that pulls from dlp_api (the existing `pub use dlp_api::{
... id, ... ID, };` line) to include check_id so callers retain the original API
surface: add check_id to the list of items exported from dlp_api (alongside id
and ID) so dlp::check_id(...) continues to resolve.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@dlp-api/src/instruction_builder/delegate_with_actions.rs`:
- Around line 29-34: The code currently panics by calling expect()/unwrap() when
a validator is missing, when actions.encrypt fails, and during serialization;
change the instruction builder (the function in delegate_with_actions.rs that
constructs post-delegation actions) to return a Result and propagate errors
instead of panicking: replace delegate.validator.expect(...) by matching the
Option and returning an Err variant (with a clear error enum/variant) when None,
replace actions.encrypt(...).expect(...) with
actions.encrypt(&encrypt_key).map_err(|e| /* convert to your function's error
*/)? so the error is propagated, and similarly map or ? any serialization calls
(the line around 71) to return errors instead of unwrap(); update callers to
handle the Result. Use the unique symbols encrypt_key, delegate.validator,
actions.encrypt, and the serialization call to locate and change the code.

---

Duplicate comments:
In `@src/lib.rs`:
- Around line 4-7: The crate currently re-exports id and ID from dlp_api but
omits check_id, breaking callers using dlp::check_id; update the re-export
statement that pulls from dlp_api (the existing `pub use dlp_api::{ ... id, ...
ID, };` line) to include check_id so callers retain the original API surface:
add check_id to the list of items exported from dlp_api (alongside id and ID) so
dlp::check_id(...) continues to resolve.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2d865c06-448b-426a-a2c8-15a85b3f0907

📥 Commits

Reviewing files that changed from the base of the PR and between a40fa02 and 73480dd.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (40)
  • Cargo.toml
  • dlp-api/Cargo.toml
  • dlp-api/src/account_size_class.rs
  • dlp-api/src/args/call_handler.rs
  • dlp-api/src/args/commit_state.rs
  • dlp-api/src/args/delegate.rs
  • dlp-api/src/args/delegate_ephemeral_balance.rs
  • dlp-api/src/args/delegate_with_actions.rs
  • dlp-api/src/args/mod.rs
  • dlp-api/src/args/top_up_ephemeral_balance.rs
  • dlp-api/src/args/types.rs
  • dlp-api/src/args/validator_claim_fees.rs
  • dlp-api/src/args/whitelist_validator_for_program.rs
  • dlp-api/src/compact/account_meta.rs
  • dlp-api/src/compact/instruction.rs
  • dlp-api/src/compact/mod.rs
  • dlp-api/src/consts.rs
  • dlp-api/src/diff/algorithm.rs
  • dlp-api/src/diff/mod.rs
  • dlp-api/src/diff/types.rs
  • dlp-api/src/discriminator.rs
  • dlp-api/src/error.rs
  • dlp-api/src/instruction_builder/delegate_with_actions.rs
  • dlp-api/src/instruction_builder/mod.rs
  • dlp-api/src/lib.rs
  • dlp-api/src/pda.rs
  • dlp-api/src/pod_view.rs
  • dlp-api/src/requires.rs
  • dlp-api/src/state/commit_record.rs
  • dlp-api/src/state/delegation_metadata.rs
  • dlp-api/src/state/delegation_record.rs
  • dlp-api/src/state/mod.rs
  • dlp-api/src/state/program_config.rs
  • dlp-api/src/state/utils/discriminator.rs
  • dlp-api/src/state/utils/mod.rs
  • dlp-api/src/state/utils/to_bytes.rs
  • dlp-api/src/state/utils/try_from_bytes.rs
  • src/lib.rs
  • tests/test_commit_finalize.rs
  • tests/test_commit_finalize_from_buffer.rs
💤 Files with no reviewable changes (2)
  • dlp-api/src/error.rs
  • dlp-api/src/consts.rs

@snawaz snawaz marked this pull request as ready for review March 17, 2026 13:21
@snawaz snawaz requested a review from GabrielePicco March 17, 2026 13:24
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (2)
tests/test_undelegate_without_commit.rs (1)

63-71: ⚠️ Potential issue | 🟡 Minor

Remove duplicate assertion block.

Lines 68-71 duplicate the assertion at lines 63-66 (same variable, same check, same comment). This appears to be a copy-paste oversight.

🧹 Proposed fix
     // Assert the delegation_record_pda was closed
     let delegation_record_account =
         banks.get_account(delegation_record_pda).await.unwrap();
     assert!(delegation_record_account.is_none());
 
-    // Assert the delegation_record_pda was closed
-    let delegation_record_account =
-        banks.get_account(delegation_record_pda).await.unwrap();
-    assert!(delegation_record_account.is_none());
-
     // Assert the delegated account seeds pda was closed
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_undelegate_without_commit.rs` around lines 63 - 71, Remove the
duplicated assertion block that checks the delegation_record_pda closure: keep a
single call to banks.get_account(delegation_record_pda).await.unwrap() assigned
to delegation_record_account and the
assert!(delegation_record_account.is_none()) check; delete the repeated lines
(duplicate comment, call, and assert) so the test only asserts the
delegation_record_pda was closed once.
dlp-api/src/instruction_builder/delegate_with_actions.rs (1)

22-34: ⚠️ Potential issue | 🟠 Major

Replace the panic paths in this public builder.

This API currently panics on missing delegate.validator, encryption failure, and serialization failure. Please make the validator requirement explicit in the signature or return Result<Instruction, _> so callers can handle these errors instead of aborting.

As per coding guidelines: {dlp-api,src}/**: Treat any usage of .unwrap() or .expect() in production Rust code as a MAJOR issue. These should not be categorized as trivial or nit-level concerns. Request proper error handling or explicit justification with invariants.

Also applies to: 69-71

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dlp-api/src/instruction_builder/delegate_with_actions.rs` around lines 22 -
34, The public builder delegate_with_actions currently panics on missing
delegate.validator and on encryption/serialization failures; change its
signature to return Result<Instruction, YourErrorType> (or a suitable error
enum) and propagate errors instead of calling expect, e.g., replace the
validator extraction with a match on delegate.validator returning an Err if
absent (or make validator a required Pubkey in the function signature or
DelegateArgs type), replace the .encrypt(...).expect(...) with a fallible call
using ? to propagate the error, and similarly propagate any serialization
failure (the later serialization calls referenced around lines 69-71) so callers
can handle errors rather than aborting. Ensure you update call sites to handle
the Result.
♻️ Duplicate comments (1)
src/lib.rs (1)

5-8: ⚠️ Potential issue | 🟠 Major

Root ID helpers are crate-private, which can break existing dlp::* callers

Line 22 makes id/ID internal (pub(crate)), and there is no public check_id re-export. If backward compatibility is required for the root crate, this is a breaking API change.

Suggested compatibility-preserving change
-pub(crate) use dlp_api::{id, ID};
+pub use dlp_api::{check_id, id, ID};
#!/bin/bash
set -euo pipefail

echo "Inspect ID helper re-exports in src/lib.rs"
rg -nP 'use\s+dlp_api::\{[^}]*\b(id|ID|check_id)\b[^}]*\}' src/lib.rs

echo
echo "Show the exact section around current visibility"
nl -ba src/lib.rs | sed -n '1,40p'

echo
echo "Check for any remaining in-repo callsites expecting root crate ID helpers"
rg -nP '\bdlp::(id|ID|check_id)\b' --type rust

Also applies to: 22-22

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib.rs` around lines 5 - 8, The crate currently makes the root ID helpers
internal (pub(crate)) which breaks external callers expecting dlp::id, dlp::ID,
or dlp::check_id; update the re-exports so these symbols are public again by
adding a public re-export or changing their visibility to pub (e.g., ensure id,
ID, and check_id are included in a pub use of dlp_api rather than pub(crate)),
and verify the module export list includes id, ID, and check_id so
backward-compatible callers of those helpers continue to work.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@dlp-api/Cargo.toml`:
- Around line 13-19: The crate declares a "diff" feature in Cargo.toml but
exposes the module unconditionally; update dlp-api/src/lib.rs to gate the diff
module with #[cfg(feature = "diff")] (e.g., change or wrap the `pub mod diff;`
declaration) so the feature actually toggles compilation, or alternatively
remove the "diff" feature from Cargo.toml's default/features list to reflect
that `pub mod diff;` is always compiled; ensure references to the module (uses
or tests) are also conditionally compiled with #[cfg(feature = "diff")] if you
choose the conditional-gating approach.

---

Outside diff comments:
In `@dlp-api/src/instruction_builder/delegate_with_actions.rs`:
- Around line 22-34: The public builder delegate_with_actions currently panics
on missing delegate.validator and on encryption/serialization failures; change
its signature to return Result<Instruction, YourErrorType> (or a suitable error
enum) and propagate errors instead of calling expect, e.g., replace the
validator extraction with a match on delegate.validator returning an Err if
absent (or make validator a required Pubkey in the function signature or
DelegateArgs type), replace the .encrypt(...).expect(...) with a fallible call
using ? to propagate the error, and similarly propagate any serialization
failure (the later serialization calls referenced around lines 69-71) so callers
can handle errors rather than aborting. Ensure you update call sites to handle
the Result.

In `@tests/test_undelegate_without_commit.rs`:
- Around line 63-71: Remove the duplicated assertion block that checks the
delegation_record_pda closure: keep a single call to
banks.get_account(delegation_record_pda).await.unwrap() assigned to
delegation_record_account and the assert!(delegation_record_account.is_none())
check; delete the repeated lines (duplicate comment, call, and assert) so the
test only asserts the delegation_record_pda was closed once.

---

Duplicate comments:
In `@src/lib.rs`:
- Around line 5-8: The crate currently makes the root ID helpers internal
(pub(crate)) which breaks external callers expecting dlp::id, dlp::ID, or
dlp::check_id; update the re-exports so these symbols are public again by adding
a public re-export or changing their visibility to pub (e.g., ensure id, ID, and
check_id are included in a pub use of dlp_api rather than pub(crate)), and
verify the module export list includes id, ID, and check_id so
backward-compatible callers of those helpers continue to work.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: 5cb67fbb-dda0-4478-b289-e8717d9481c9

📥 Commits

Reviewing files that changed from the base of the PR and between 73480dd and 2b7c092.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (69)
  • Cargo.toml
  • dlp-api/Cargo.toml
  • dlp-api/src/account_size_class.rs
  • dlp-api/src/args/call_handler.rs
  • dlp-api/src/args/commit_state.rs
  • dlp-api/src/args/delegate.rs
  • dlp-api/src/args/delegate_ephemeral_balance.rs
  • dlp-api/src/args/delegate_with_actions.rs
  • dlp-api/src/args/mod.rs
  • dlp-api/src/args/top_up_ephemeral_balance.rs
  • dlp-api/src/args/types.rs
  • dlp-api/src/args/validator_claim_fees.rs
  • dlp-api/src/args/whitelist_validator_for_program.rs
  • dlp-api/src/compact/account_meta.rs
  • dlp-api/src/compact/instruction.rs
  • dlp-api/src/compact/mod.rs
  • dlp-api/src/consts.rs
  • dlp-api/src/diff/algorithm.rs
  • dlp-api/src/diff/mod.rs
  • dlp-api/src/diff/types.rs
  • dlp-api/src/discriminator.rs
  • dlp-api/src/error.rs
  • dlp-api/src/instruction_builder/delegate_with_actions.rs
  • dlp-api/src/instruction_builder/mod.rs
  • dlp-api/src/lib.rs
  • dlp-api/src/pda.rs
  • dlp-api/src/pod_view.rs
  • dlp-api/src/requires.rs
  • dlp-api/src/state/commit_record.rs
  • dlp-api/src/state/delegation_metadata.rs
  • dlp-api/src/state/delegation_record.rs
  • dlp-api/src/state/mod.rs
  • dlp-api/src/state/program_config.rs
  • dlp-api/src/state/utils/discriminator.rs
  • dlp-api/src/state/utils/mod.rs
  • dlp-api/src/state/utils/to_bytes.rs
  • dlp-api/src/state/utils/try_from_bytes.rs
  • src/lib.rs
  • tests/fixtures/accounts.rs
  • tests/test_call_handler.rs
  • tests/test_call_handler_v2.rs
  • tests/test_cleartext_with_insertable_encrypted.rs
  • tests/test_close_validator_fees_vault.rs
  • tests/test_commit_fees_on_undelegation.rs
  • tests/test_commit_finalize.rs
  • tests/test_commit_finalize_from_buffer.rs
  • tests/test_commit_on_curve.rs
  • tests/test_commit_state.rs
  • tests/test_commit_state_from_buffer.rs
  • tests/test_commit_state_with_program_config.rs
  • tests/test_commit_undelegate_zero_lamports_system_owned.rs
  • tests/test_delegate.rs
  • tests/test_delegate_magic_fee_vault.rs
  • tests/test_delegate_on_curve.rs
  • tests/test_delegate_with_actions.rs
  • tests/test_delegation_confined_accounts.rs
  • tests/test_finalize.rs
  • tests/test_init_fees_vault.rs
  • tests/test_init_magic_fee_vault.rs
  • tests/test_init_validator_fees_vault.rs
  • tests/test_lamports_settlement.rs
  • tests/test_protocol_claim_fees.rs
  • tests/test_top_up.rs
  • tests/test_undelegate.rs
  • tests/test_undelegate_confined_account.rs
  • tests/test_undelegate_on_curve.rs
  • tests/test_undelegate_without_commit.rs
  • tests/test_validator_claim_fees.rs
  • tests/test_whitelist_validator_for_program.rs
💤 Files with no reviewable changes (2)
  • dlp-api/src/error.rs
  • dlp-api/src/consts.rs

@snawaz snawaz force-pushed the snawaz/restruct branch 5 times, most recently from a8c01ae to 2bf5382 Compare March 17, 2026 14:50
Copy link
Contributor

@GabrielePicco GabrielePicco left a comment

Choose a reason for hiding this comment

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

LGTM!

@snawaz snawaz merged commit 2be39bb into main Mar 17, 2026
5 checks passed
@snawaz snawaz deleted the snawaz/restruct branch March 17, 2026 16:05
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.

2 participants