feat: auto-undelegate owner-requested accounts during commit#1413
feat: auto-undelegate owner-requested accounts during commit#1413snawaz wants to merge 3 commits into
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughFinalize task construction now adds Suggested reviewers: ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
5358558 to
f48681b
Compare
70fb7d7 to
f3499a6
Compare
f3499a6 to
b151e96
Compare
f48681b to
13222e9
Compare
b151e96 to
b2eefaa
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 (2)
magicblock-committor-service/src/tasks/task_builder.rs (2)
359-416: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMinor duplication between
create_undelegate_tasksandcreate_owner_program_undelegate_tasks.Both functions fetch metadata per account and branch on
undelegation_requester == UndelegationRequester::OwnerProgramto build anundelegate_task. Consider extracting a shared helper (e.g.,undelegate_task_for_account(account, metadata) -> BaseTaskImpl) to avoid the two near-identical code paths drifting apart over time.🤖 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 `@magicblock-committor-service/src/tasks/task_builder.rs` around lines 359 - 416, Extract the shared metadata lookup and undelegation-task construction from create_undelegate_tasks and create_owner_program_undelegate_tasks into a helper such as undelegate_task_for_account. Have the helper accept an account and its DelegationMetadata, derive the owner-program flag from undelegation_requester, and update both callers to use it while preserving their existing filtering and task ordering.
389-459: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winDelegation metadata is now required for every committed account
get_finalize_stage_metadata_pubkeys()fetchesget_all_committed_pubkeys(), andcreate_owner_program_undelegate_tasks()requires a metadata entry for every non-explicit committed account. If any committed account lacks delegation metadata, the whole finalize build fails withMissingDelegationMetadata, even for plaincommit/commit_finalizeintents. Narrow the fetch/lookup to accounts that can actually undelegate.🤖 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 `@magicblock-committor-service/src/tasks/task_builder.rs` around lines 389 - 459, The finalize builder currently requires delegation metadata for all committed accounts, causing plain commit flows to fail when metadata is absent. Narrow get_finalize_stage_metadata_pubkeys and the delegation_metadata_for_pubkey lookup in create_owner_program_undelegate_tasks to only accounts eligible for owner-program undelegation, while preserving explicit undelegation handling and allowing plain commit/commit_finalize intents without metadata.
🤖 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.
Inline comments:
In @.agents/context/crates/magicblock-committor-service.md:
- Line 58: Correct the path entry describing IntentExecutionService by prefixing
src/service.rs and src/service/intent_client.rs with the owning crate directory,
likely magicblock-services, instead of leaving them relative to
magicblock-committor-service. Keep the existing runtime responsibility
description unchanged and distinguish it from the CommittorService entry already
documented in the table.
---
Outside diff comments:
In `@magicblock-committor-service/src/tasks/task_builder.rs`:
- Around line 359-416: Extract the shared metadata lookup and undelegation-task
construction from create_undelegate_tasks and
create_owner_program_undelegate_tasks into a helper such as
undelegate_task_for_account. Have the helper accept an account and its
DelegationMetadata, derive the owner-program flag from undelegation_requester,
and update both callers to use it while preserving their existing filtering and
task ordering.
- Around line 389-459: The finalize builder currently requires delegation
metadata for all committed accounts, causing plain commit flows to fail when
metadata is absent. Narrow get_finalize_stage_metadata_pubkeys and the
delegation_metadata_for_pubkey lookup in create_owner_program_undelegate_tasks
to only accounts eligible for owner-program undelegation, while preserving
explicit undelegation handling and allowing plain commit/commit_finalize intents
without metadata.
🪄 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: fb1f43c4-29f4-447f-8d2e-e99b6aeb1316
📒 Files selected for processing (4)
.agents/context/crates/magicblock-committor-service.mdmagicblock-committor-service/src/intent_executor/mod.rsmagicblock-committor-service/src/tasks/task_builder.rsmagicblock-committor-service/src/tasks/task_strategist.rs
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
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)
magicblock-committor-service/src/tasks/task_builder.rs (2)
359-416: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMinor duplication between
create_undelegate_tasksandcreate_owner_program_undelegate_tasks.Both functions fetch metadata per account and branch on
undelegation_requester == UndelegationRequester::OwnerProgramto build anundelegate_task. Consider extracting a shared helper (e.g.,undelegate_task_for_account(account, metadata) -> BaseTaskImpl) to avoid the two near-identical code paths drifting apart over time.🤖 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 `@magicblock-committor-service/src/tasks/task_builder.rs` around lines 359 - 416, Extract the shared metadata lookup and undelegation-task construction from create_undelegate_tasks and create_owner_program_undelegate_tasks into a helper such as undelegate_task_for_account. Have the helper accept an account and its DelegationMetadata, derive the owner-program flag from undelegation_requester, and update both callers to use it while preserving their existing filtering and task ordering.
389-459: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winDelegation metadata is now required for every committed account
get_finalize_stage_metadata_pubkeys()fetchesget_all_committed_pubkeys(), andcreate_owner_program_undelegate_tasks()requires a metadata entry for every non-explicit committed account. If any committed account lacks delegation metadata, the whole finalize build fails withMissingDelegationMetadata, even for plaincommit/commit_finalizeintents. Narrow the fetch/lookup to accounts that can actually undelegate.🤖 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 `@magicblock-committor-service/src/tasks/task_builder.rs` around lines 389 - 459, The finalize builder currently requires delegation metadata for all committed accounts, causing plain commit flows to fail when metadata is absent. Narrow get_finalize_stage_metadata_pubkeys and the delegation_metadata_for_pubkey lookup in create_owner_program_undelegate_tasks to only accounts eligible for owner-program undelegation, while preserving explicit undelegation handling and allowing plain commit/commit_finalize intents without metadata.
🤖 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.
Inline comments:
In @.agents/context/crates/magicblock-committor-service.md:
- Line 58: Correct the path entry describing IntentExecutionService by prefixing
src/service.rs and src/service/intent_client.rs with the owning crate directory,
likely magicblock-services, instead of leaving them relative to
magicblock-committor-service. Keep the existing runtime responsibility
description unchanged and distinguish it from the CommittorService entry already
documented in the table.
---
Outside diff comments:
In `@magicblock-committor-service/src/tasks/task_builder.rs`:
- Around line 359-416: Extract the shared metadata lookup and undelegation-task
construction from create_undelegate_tasks and
create_owner_program_undelegate_tasks into a helper such as
undelegate_task_for_account. Have the helper accept an account and its
DelegationMetadata, derive the owner-program flag from undelegation_requester,
and update both callers to use it while preserving their existing filtering and
task ordering.
- Around line 389-459: The finalize builder currently requires delegation
metadata for all committed accounts, causing plain commit flows to fail when
metadata is absent. Narrow get_finalize_stage_metadata_pubkeys and the
delegation_metadata_for_pubkey lookup in create_owner_program_undelegate_tasks
to only accounts eligible for owner-program undelegation, while preserving
explicit undelegation handling and allowing plain commit/commit_finalize intents
without metadata.
🪄 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: fb1f43c4-29f4-447f-8d2e-e99b6aeb1316
📒 Files selected for processing (4)
.agents/context/crates/magicblock-committor-service.mdmagicblock-committor-service/src/intent_executor/mod.rsmagicblock-committor-service/src/tasks/task_builder.rsmagicblock-committor-service/src/tasks/task_strategist.rs
🛑 Comments failed to post (1)
.agents/context/crates/magicblock-committor-service.md (1)
58-58: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Ambiguous/likely-mislabeled path entry:
src/service.rscollides with row 45.This row (unprefixed
src/service.rsandsrc/service/intent_client.rs) follows the table's convention of unprefixed paths meaning "relative tomagicblock-committor-service/" — but Line 45 already documentssrc/service.rsas this crate's own actor-style service handle (CommittorService::try_start,CommittorMessage, etc.), a completely different responsibility than what's described here (consumingMagicContext, submittingScheduledCommitSent, pending-intent recovery). The content described (IntentExecutionService) appears to belong to a different crate (likelymagicblock-services, based on other references in this doc and cross-file evidence), so this row should be prefixed with the correct crate path to avoid confusing readers into thinking these are files withinmagicblock-committor-service.📝 Suggested fix
-| `src/service.rs` and `src/service/intent_client.rs` | Runtime producer/consumer: accepts scheduled intent bundles from `MagicContext`, schedules them with the committor, consumes result broadcasts, submits `ScheduledCommitSent`, and performs pending-intent recovery after ledger replay. | +| `magicblock-services/src/service.rs` and `magicblock-services/src/service/intent_client.rs` | Runtime producer/consumer: accepts scheduled intent bundles from `MagicContext`, schedules them with the committor, consumes result broadcasts, submits `ScheduledCommitSent`, and performs pending-intent recovery after ledger replay. |📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.| `magicblock-services/src/service.rs` and `magicblock-services/src/service/intent_client.rs` | Runtime producer/consumer: accepts scheduled intent bundles from `MagicContext`, schedules them with the committor, consumes result broadcasts, submits `ScheduledCommitSent`, and performs pending-intent recovery after ledger replay. |🤖 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 @.agents/context/crates/magicblock-committor-service.md at line 58, Correct the path entry describing IntentExecutionService by prefixing src/service.rs and src/service/intent_client.rs with the owning crate directory, likely magicblock-services, instead of leaving them relative to magicblock-committor-service. Keep the existing runtime responsibility description unchanged and distinguish it from the CommittorService entry already documented in the table.
13222e9 to
c5cf78b
Compare
b2eefaa to
ed6a818
Compare
taco-paco
left a comment
There was a problem hiding this comment.
I don't think we can modify user created intents implicitly like that. If user scheduled some intent simultaneously we shall fulfill it first and then execute UndelegationRequest intent
Why not? Softwares evolve. We only need to document the behavior. I'm more interested in the technical reasons for why this shouldn't be implemented. Is there a technical constraint I'm missing? Otherwise, it feels like an artificial restriction. |
|
I don't see how such behaviour is provable on L1 within a fraud proof, In classic L2 any state that surfaces is a result of transaction and hence is provable wether by ZK or challanged and resolved. Changes in intent in the following way is a result not of an ER transaction but of an L1 transaction. I see it is as very chalenging proving L1 state within L1 itself. It is a same problem we have with readonly cloned accounts. Now the flow that is standart in this case is:
In our context tx - undelegation request. Additionally, all of the current flows - AML undelegations, cloning and patching of intents(upcoming) is done via transaction. This goes ot of the standart way as say chainlink could also modify account in place but we schedule a transaction instead |
ed6a818 to
d9f4b79
Compare
6ef7468 to
5df5201
Compare
d9f4b79 to
2cbc040
Compare
5df5201 to
d48e2a6
Compare
2cbc040 to
89df398
Compare
d48e2a6 to
8df6616
Compare
7fee213 to
692b845
Compare
7df4dcf to
c90c4f4
Compare
692b845 to
6e74d4c
Compare
c90c4f4 to
a9d793e
Compare
6e74d4c to
9bb045d
Compare
9bb045d to
5a04453
Compare
a9d793e to
0e5845c
Compare
|
This also introduces a race condition:
Say Intent 2 had a critical action that expected to execute final transfers on Base and it also already settled final balances on ER. This Intent would never be able to execute now. With undelegation request being executed in separate tx it is not an issue as TXs attempting to schedule Intent for that account would fail as account marked as undelegated All in all I'm not in favor of this flow as it circles around proper rules of intent scheduling that happens during TX execution One of other edge cases: Intent may become impossible to fit in txs. User schedules an intent and we check during execution if it is possible to fit in 2 txs. We say it is and intent gets scheduled. We add UndelegateTask here which makes intent to large even with the split on 2 txs. |
0e5845c to
c3f6035
Compare
5a04453 to
217f35b
Compare

If the scheduled intent is only
Commit/CommitFinalize(without planned undelegate) for an account whose metadata saysundelegation_requesor == OwnerProgram, we commit/finalize and leave the account delegated even though the owner program is asking for undelegation!!So this PR automatically appends
undelegatetasks for owner-program undelegation requests in cases where undelegation is otherwise not planned.Summary by CodeRabbit
Bug Fixes
Tests
Documentation