Skip to content

Removed 7 redundant phase guard checks in InternalStatesOrchestrator.… - #102

Merged
matteoettam09 merged 2 commits into
mainfrom
issue-4
Nov 17, 2025
Merged

Removed 7 redundant phase guard checks in InternalStatesOrchestrator.…#102
matteoettam09 merged 2 commits into
mainfrom
issue-4

Conversation

@matteoettam09

@matteoettam09 matteoettam09 commented Nov 17, 2025

Copy link
Copy Markdown
Member

…sol: 4 checks removed from _preprocessTransparentMinibatch(), _buffer(), _postprocessTransparentMinibatch(), and _buildOrders()

LiquidityOrchestrator.sol: 3 checks removed from _processMinibatchSell(), _processMinibatchBuy(), and _processFulfillDepositAndRedeem() -> for gas optimsation

Summary by Sourcery

Optimize gas usage by removing redundant phase guard checks from orchestrator functions

Enhancements:

  • Remove phase guard checks in InternalStatesOrchestrator’s _preprocessTransparentMinibatch, _buffer, _postprocessTransparentMinibatch, and _buildOrders functions
  • Remove phase guard checks in LiquidityOrchestrator’s _processMinibatchSell, _processMinibatchBuy, and _processFulfillDepositAndRedeem functions

Summary by CodeRabbit

  • Refactor
    • Simplified internal state validation logic by removing redundant phase guard checks across orchestrator functions, delegating phase control to external dispatch mechanisms.
    • Removed unused error declarations from the contract interface.

…sol: 4 checks removed from _preprocessTransparentMinibatch(), _buffer(), _postprocessTransparentMinibatch(), and _buildOrders()

LiquidityOrchestrator.sol: 3 checks removed from _processMinibatchSell(), _processMinibatchBuy(), and _processFulfillDepositAndRedeem() -> for gas optimsation
@immunefi-magnus

Copy link
Copy Markdown

🛡️ Immunefi PR Reviews

We noticed that your project isn't set up for automatic code reviews. If you'd like this PR reviewed by the Immunefi team, you can request it manually using the link below:

🔗 Send this PR in for review

Once submitted, we'll take care of assigning a reviewer and follow up here.

@sourcery-ai

sourcery-ai Bot commented Nov 17, 2025

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Removed seven redundant phase guard checks across InternalStatesOrchestrator and LiquidityOrchestrator for gas optimization and updated corresponding artifacts.

Class diagram for updated InternalStatesOrchestrator and LiquidityOrchestrator phase guard logic

classDiagram
class InternalStatesOrchestrator {
    +_preprocessTransparentMinibatch()
    +_buffer()
    +_postprocessTransparentMinibatch()
    +_buildOrders()
    -currentPhase: InternalUpkeepPhase
    -currentMinibatchIndex: uint16
    -transparentMinibatchSize: uint16
    -transparentVaultsEpoch: array
    -_currentEpoch: Epoch
}
class LiquidityOrchestrator {
    +_processMinibatchSell()
    +_processMinibatchBuy()
    +_processFulfillDepositAndRedeem()
    -currentPhase: LiquidityUpkeepPhase
    -currentMinibatchIndex: uint16
    -executionMinibatchSize: uint16
    -config: Config
}
InternalStatesOrchestrator --|> Ownable
InternalStatesOrchestrator --|> ReentrancyGuard
InternalStatesOrchestrator --|> IInternalStateOrchestrator
LiquidityOrchestrator --|> Ownable
LiquidityOrchestrator --|> ReentrancyGuard
LiquidityOrchestrator --|> ILiquidityOrchestrator
Loading

Flow diagram for removed phase guard checks in minibatch processing functions

flowchart TD
    A["_preprocessTransparentMinibatch()"] --> B["Minibatch processing logic"]
    A -.-> C["Phase guard check (removed)"]
    D["_buffer()"] --> E["Buffering logic"]
    D -.-> F["Phase guard check (removed)"]
    G["_postprocessTransparentMinibatch()"] --> H["Postprocessing logic"]
    G -.-> I["Phase guard check (removed)"]
    J["_buildOrders()"] --> K["Order building logic"]
    J -.-> L["Phase guard check (removed)"]
    M["_processMinibatchSell()"] --> N["Sell logic"]
    M -.-> O["Phase guard check (removed)"]
    P["_processMinibatchBuy()"] --> Q["Buy logic"]
    P -.-> R["Phase guard check (removed)"]
    S["_processFulfillDepositAndRedeem()"] --> T["Fulfill deposit/redeem logic"]
    S -.-> U["Phase guard check (removed)"]
Loading

File-Level Changes

Change Details Files
Eliminate redundant phase checks in InternalStatesOrchestrator
  • Remove InvalidState revert in _preprocessTransparentMinibatch
  • Remove phase check in _buffer
  • Remove phase check in _postprocessTransparentMinibatch
  • Remove phase check in _buildOrders
contracts/orchestrators/InternalStatesOrchestrator.sol
Eliminate redundant phase checks in LiquidityOrchestrator
  • Remove phase check in _processMinibatchSell
  • Remove phase check in _processMinibatchBuy
  • Remove phase check in _processFulfillDepositAndRedeem
contracts/orchestrators/LiquidityOrchestrator.sol
Update artifacts to reflect removed checks
  • Regenerate InternalStatesOrchestrator JSON artifact
  • Regenerate LiquidityOrchestrator JSON artifact
artifacts/contracts/orchestrators/InternalStatesOrchestrator.sol/InternalStatesOrchestrator.json
artifacts/contracts/orchestrators/LiquidityOrchestrator.sol/LiquidityOrchestrator.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 17, 2025

Copy link
Copy Markdown

Warning

Rate limit exceeded

@matteoettam09 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between cfb87f1 and 907fef0.

📒 Files selected for processing (3)
  • artifacts/contracts/orchestrators/InternalStatesOrchestrator.sol/InternalStatesOrchestrator.json (0 hunks)
  • artifacts/contracts/orchestrators/LiquidityOrchestrator.sol/LiquidityOrchestrator.json (0 hunks)
  • contracts/orchestrators/InternalStatesOrchestrator.sol (0 hunks)

Walkthrough

This PR removes phase validation guards from internal state progression and upkeep handler functions in the orchestrator contracts, delegating phase control to external callers. The LiquidityOrchestrator artifact is updated with bytecode changes and the InvalidState error removed from the ABI.

Changes

Cohort / File(s) Summary
LiquidityOrchestrator Artifact
artifacts/contracts/orchestrators/LiquidityOrchestrator.sol/LiquidityOrchestrator.json
Removed InvalidState error from ABI exports; updated bytecode and deployedBytecode to reflect contract interface changes.
InternalStatesOrchestrator Phase Guard Removal
contracts/orchestrators/InternalStatesOrchestrator.sol
Removed currentPhase checks from _preprocessTransparentMinibatch, _buffer, _postprocessTransparentMinibatch, and _buildOrders. Phase transitions still occur internally; validation delegated to external caller.
LiquidityOrchestrator Phase Guard Removal
contracts/orchestrators/LiquidityOrchestrator.sol
Removed currentPhase enforcement from _processMinibatchSell, _processMinibatchBuy, and _processFulfillDepositAndRedeem. Functions retain minibatch index advancement and phase transitions; rely on performUpkeep dispatch for phase correctness.

Sequence Diagram(s)

sequenceDiagram
    participant ext as External Caller
    participant perf as performUpkeep
    participant handler as Internal Handler<br/>(_processMinibatchSell, etc.)
    participant state as State Machine

    Note over perf,state: Previous Flow (with phase guards)
    rect rgb(200, 220, 255)
        ext->>perf: Call performUpkeep()
        perf->>handler: Dispatch to handler
        handler->>handler: CHECK currentPhase<br/>(guard validation)
        alt Phase mismatch
            handler-->>perf: Revert
        else Phase correct
            handler->>state: Advance indices &<br/>transition phase
            handler-->>perf: Success
        end
    end

    Note over perf,state: New Flow (guards removed)
    rect rgb(220, 255, 220)
        ext->>perf: Call performUpkeep()
        perf->>handler: Dispatch to handler
        handler->>state: Advance indices &<br/>transition phase<br/>(no guard check)
        handler-->>perf: Success
    end
    
    Note over perf,state: Phase correctness now enforced<br/>entirely by performUpkeep dispatch logic
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Implications of phase guard removal: Verify that external performUpkeep dispatch logic correctly handles phase sequencing and that removal of internal checks doesn't create race conditions or invalid state transitions.
  • Artifact consistency: Confirm that ABI change (removal of InvalidState error) aligns with contract implementation and does not break external integrations.
  • State machine invariants: Ensure the relocated phase responsibility to the caller maintains the integrity of epoch/phase transitions across all orchestrator functions.

Possibly related PRs

  • Dev #77: Both PRs remove/relax phase checks and modify upkeep handlers in LiquidityOrchestrator and InternalStatesOrchestrator, implementing similar phase guard relaxation patterns.
  • fix: epoch vaults selection internal state orchestrator #76: Both PRs modify InternalStatesOrchestrator's phase and epoch handling logic, suggesting coordinated refactoring of state progression.
  • Dev #73: Both PRs modify orchestrator phase-guard logic and update the LiquidityOrchestrator ABI, indicating aligned control-flow changes.

Poem

🐰 No guards at the gates, just trust in the flow,
Phase checks drift away, let the caller know,
Internal transitions still dance and advance,
The orchestrators waltz without phase guard's stance!

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 accurately summarizes the main change: removal of 7 redundant phase guard checks across the specified functions in both orchestrator contracts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@sourcery-ai sourcery-ai 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.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov

codecov Bot commented Nov 17, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@matteoettam09
matteoettam09 merged commit 6e97f06 into main Nov 17, 2025
5 checks passed
@matteoettam09
matteoettam09 deleted the issue-4 branch November 17, 2025 23:21
@coderabbitai coderabbitai Bot mentioned this pull request Nov 20, 2025
Merged
@coderabbitai coderabbitai Bot mentioned this pull request Jan 12, 2026
Merged
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