refactor: do not require system_program in instruction-accounts and add docs#102
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
93c1ee8 to
b636bd3
Compare
0baecae to
bb7816b
Compare
b636bd3 to
722724f
Compare
bb7816b to
8983221
Compare
722724f to
fcea18e
Compare
8983221 to
50c6c4c
Compare
fcea18e to
fd02f14
Compare
fc11e9d to
e74e4c2
Compare
fd02f14 to
92a6159
Compare
WalkthroughRemoves 8-byte discriminator conversion and uses first-byte discriminator in slow path. Eliminates system program validation across fast-path processors. Adjusts account destructuring accordingly, adding an unused system program placeholder where needed. Adds documentation comments. Updates undelegate function signature to accept an extra data slice. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Runtime
participant Program as Program::slow_process_instruction
participant Decoder as Discriminator::try_from(first_byte)
Runtime->>Program: Invoke with input data
Program->>Program: Read 8-byte tag
Program->>Decoder: try_from(tag[0])
alt valid discriminator
Program-->>Runtime: Dispatch to handler
else invalid
Program-->>Runtime: Err(InvalidInstructionData)
end
sequenceDiagram
autonumber
participant Runtime
participant FastProc as Fast-path Processor (delegate/commit_state/finalize/undelegate)
Runtime->>FastProc: Invoke with Accounts[], Data
FastProc->>FastProc: Destructure Accounts (includes _system_program placeholder)
note right of FastProc: System program not validated
FastProc->>FastProc: Load/verify required accounts
FastProc-->>Runtime: Perform action or return error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
GabrielePicco
left a comment
There was a problem hiding this comment.
LGTM, few suggested nits
e628872 to
592f54f
Compare
e74e4c2 to
1836012
Compare
592f54f to
6d0ac94
Compare
There was a problem hiding this comment.
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 (3)
src/processor/fast/delegate.rs (1)
55-57: System program account still mandatory.Pattern matching still expects a trailing
_system_program, so calls that omit it (per the new docs) will immediately fail withNotEnoughAccountKeys. Drop the extra binding.Apply this diff:
- let [payer, delegated_account, owner_program, delegate_buffer_account, delegation_record_account, delegation_metadata_account, _system_program] = + let [payer, delegated_account, owner_program, delegate_buffer_account, delegation_record_account, delegation_metadata_account] = accountssrc/processor/fast/finalize.rs (1)
56-60: Finalize still requires unused system program account.Even though the instruction no longer documents
system_program, the slice pattern still needs it, so a caller following the new spec will seeNotEnoughAccountKeys. Remove the extra slot.Apply this diff:
- let [validator, delegated_account, commit_state_account, commit_record_account, delegation_record_account, delegation_metadata_account, validator_fees_vault, _system_program] = + let [validator, delegated_account, commit_state_account, commit_record_account, delegation_record_account, delegation_metadata_account, validator_fees_vault] = accountssrc/processor/fast/commit_state.rs (1)
67-71: Commit-state fast path still demands_system_program.The account matcher keeps an unused
_system_program, so callers supplying only the documented eight accounts will fail withNotEnoughAccountKeys. Drop the unused binding.Apply this diff:
- let [validator, delegated_account, commit_state_account, commit_record_account, delegation_record_account, delegation_metadata_account, validator_fees_vault, program_config_account, _system_program] = + let [validator, delegated_account, commit_state_account, commit_record_account, delegation_record_account, delegation_metadata_account, validator_fees_vault, program_config_account] = accounts
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (7)
src/discriminator.rs(0 hunks)src/lib.rs(1 hunks)src/processor/fast/commit_state.rs(2 hunks)src/processor/fast/commit_state_from_buffer.rs(1 hunks)src/processor/fast/delegate.rs(1 hunks)src/processor/fast/finalize.rs(1 hunks)src/processor/fast/undelegate.rs(1 hunks)
💤 Files with no reviewable changes (1)
- src/discriminator.rs
🧰 Additional context used
🧬 Code graph analysis (3)
src/processor/fast/finalize.rs (2)
src/processor/fast/utils/requires.rs (3)
require_initialized_validator_fees_vault(223-244)require_owned_pda(33-44)require_signer(49-57)src/processor/fast/mod.rs (1)
to_pinocchio_program_error(14-18)
src/processor/fast/undelegate.rs (1)
src/processor/fast/utils/requires.rs (2)
require_owned_pda(33-44)require_signer(49-57)
src/processor/fast/commit_state.rs (2)
src/processor/fast/utils/requires.rs (5)
require_initialized_validator_fees_vault(223-244)require_owned_pda(33-44)require_program_config(248-269)require_signer(49-57)require_uninitialized_pda(135-152)src/processor/fast/mod.rs (1)
to_pinocchio_program_error(14-18)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: install
🔇 Additional comments (3)
src/processor/fast/undelegate.rs (3)
35-76: Excellent documentation!The comprehensive documentation clearly describes accounts, requirements, and the undelegation flow. The TODO comment on line 50 appropriately explains why the system program remains required (downstream API dependencies), which aligns with the PR objectives stating this is the one instruction where it couldn't be removed.
82-86: System program validation removed appropriately.The removal of the runtime
require_programcheck forsystem_programis appropriate. The system program is still required in the accounts array and used in CPI operations (lines 210, 252, 281-286, 316, 326). The Pinocchio/Solana runtime will validate it during CPI invocation, so the explicit upfront check is redundant. This reduces validation overhead while maintaining security, though it defers error detection until CPI time.
77-81: Verified call sites updated for new_dataparameter; no further action required.

This PR does the following things:
system_program: AccountInfoas it is not required by both Pinocchio SDK as well as Solana SDK, though this PR doesn't touch the older implementations that use Solana SDK).delegateinstruction using Pinocchio for lower CU consumption #94).[] the system programfor all, except one in which I couldn't remove it, because downstream APIs require it.TryFromfor discriminator, as it is automatically implemented byTryFromPrimitive.Summary by CodeRabbit
Refactor
Documentation
Style
Tests