Skip to content

feat: multiple instructions per crank#6

Open
Dodecahedr0x wants to merge 3 commits into
mainfrom
dode/multiple-instructions
Open

feat: multiple instructions per crank#6
Dodecahedr0x wants to merge 3 commits into
mainfrom
dode/multiple-instructions

Conversation

@Dodecahedr0x

@Dodecahedr0x Dodecahedr0x commented Jun 22, 2026

Copy link
Copy Markdown

Enables having multiple instructions executed on every trigger.

Summary by CodeRabbit

Release Notes

  • New Features

    • Increased maximum scheduled instructions per crank from 2 to 16.
    • Added support for creating and firing cranks with multiple scheduled instructions placed contiguously immediately after Trigger.
  • Documentation

    • Updated README and API docs for the multi-instruction Create wire layout, validation constraints, and refreshed compute unit figures.
  • Tests

    • Expanded Create/Trigger coverage for multi-instruction scheduling, legacy compatibility, and additional failure cases.
  • Examples

    • Updated native and Anchor examples to use the new CreateArgs scheduled-slice format.
  • Chores

    • Adjusted example feature/lint configs and enabled unsafe account resizing for the Hydra program build.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Hydra now supports scheduling multiple instructions per crank. The client API, on-chain Create processor, cranker, examples, tests, and README are updated to use ScheduledIx slices and multi-instruction trigger handling.

Changes

Multi-instruction Hydra scheduling

Layer / File(s) Summary
ScheduledIx, CreateArgs, and client parsing
crates/hydra-api/src/consts.rs, crates/hydra-api/src/instruction.rs
Adds ScheduledIx<'a>, CREATE_IX_HEADER_LEN, multi-item CreateArgs, loop-based Create serialization, and scheduled_ixs_from_crank parsing into Vec<Instruction>.
Create processor validation and resize
programs/hydra/Cargo.toml, programs/hydra/src/processor/create.rs
Reworks Create to cursor through scheduled blobs, validate each entry, write the crank tail, over-provision with upper_region, and shrink to exact size.
Trigger assembly from crank data
crates/hydra-cranker/src/fire.rs
fire_trigger now parses multiple scheduled instructions, sizes the transaction from the parsed count, and appends all scheduled instructions after Trigger.
Example wiring and Cargo feature flags
examples/anchor/programs/hydra-example-anchor/src/lib.rs, examples/native/src/lib.rs, examples/native/Cargo.toml, examples/pinocchio/src/lib.rs, examples/pinocchio/Cargo.toml, tests/programs/noop/Cargo.toml
Example CPIs switch to ScheduledIx slices, Pinocchio buffer sizing adds CREATE_IX_HEADER_LEN, and the Cargo manifests add feature and lint configuration.
Test helpers and multi-instruction coverage
tests/lib.rs
Test helpers serialize multiple scheduled instructions, CU measurements add a multi-sibling trigger case, and coverage expands for parsing, trigger matching, and Create rejection paths.
README updates and examples
README.md
README text and tables are updated for the multi-instruction model, new CU figures, the ScheduledIx crank example, and table reformatting.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: supporting multiple instructions per crank trigger.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 dode/multiple-instructions

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.

Caution

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

⚠️ Outside diff range comments (1)
crates/hydra-api/src/instruction.rs (1)

141-143: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Validate before the lossy wire-format casts.

as u8 and as u16 silently truncate oversized metas/data lengths; the on-chain Create parser then advances using the truncated values while the full bytes remain in the payload, which can reject the Create or deserialize unintended scheduled siblings.

Proposed guard before serialization
+        assert!(
+            !args.scheduled.is_empty(),
+            "Create requires at least one scheduled instruction"
+        );
         for s in args.scheduled {
+            assert!(
+                s.metas.len() <= u8::MAX as usize,
+                "scheduled instruction has too many account metas"
+            );
+            assert!(
+                s.data.len() <= u16::MAX as usize,
+                "scheduled instruction data is too large"
+            );
             data.push(s.metas.len() as u8);
             data.extend_from_slice(&(s.data.len() as u16).to_le_bytes());
🤖 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 `@crates/hydra-api/src/instruction.rs` around lines 141 - 143, The Create
serialization in instruction.rs is casting scheduled payload lengths with lossy
conversions in the loop over args.scheduled, so validate each s.metas.len() and
s.data.len() before pushing them into data. Add explicit bounds checks in the
serialization path that uses args.scheduled, and fail early if either length
exceeds what u8 or u16 can represent, so the Create parser never sees truncated
lengths.
🤖 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.

Outside diff comments:
In `@crates/hydra-api/src/instruction.rs`:
- Around line 141-143: The Create serialization in instruction.rs is casting
scheduled payload lengths with lossy conversions in the loop over
args.scheduled, so validate each s.metas.len() and s.data.len() before pushing
them into data. Add explicit bounds checks in the serialization path that uses
args.scheduled, and fail early if either length exceeds what u8 or u16 can
represent, so the Create parser never sees truncated lengths.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 46c43eaa-5bd0-4ee1-af49-0cc44edb9d16

📥 Commits

Reviewing files that changed from the base of the PR and between e3a978a and 76a19d0.

📒 Files selected for processing (1)
  • crates/hydra-api/src/instruction.rs

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.

1 participant