fix: use committed account size for buffer allocation to handle >10KB growth#943
fix: use committed account size for buffer allocation to handle >10KB growth#943vikions wants to merge 3 commits intomagicblock-labs:masterfrom
Conversation
…Add buffer_account_size field to PreparationTask- Use committed account size instead of diff size for realloc calculations- Ensures realloc instructions are generated when account growth > 10KB- Fixes magicblock-labs#878
📝 WalkthroughWalkthroughThe PR adds a new public field Assessment against linked issues
Suggested reviewers
✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@magicblock-committor-service/src/tasks/buffer_task.rs`:
- Around line 64-70: The code unnecessarily clones `data` when building
PreparationState::Required; instead compute let buffer_account_size = data.len()
as u64 before constructing the PreparationTask and then move `data` into the
committed_data field (committed_data: data) without cloning; update the
PreparationTask construction in the PreparationState::Required branch so it uses
the precomputed buffer_account_size and the moved `data` value, keeping
commit_id and pubkey the same.
|
@vikions... is this a complete work, or are there more changes coming? Please add some tests as well. I converted this into draft mode as the PR does not seem complete to me. |
I’ll add tests for the >10KB growth case! |
Description
Fixes #878
This PR addresses the issue where
CommitDifftasks would fail when account growth exceeded Solana's 10KB reallocation limit per instruction.Problem
Previously, the
CommitDiffflow used the diff size (diff.len()) to calculate buffer allocation size. When an account grew from 5KB to 16KB (11KB growth), the diff might only be 100 bytes, causing the realloc logic to skip generating multiple realloc instructions. This led to runtime failures when the commit instruction tried to reallocate more than 10KB at once.Solution
buffer_account_size: u64field toPreparationTaskto track the actual committed account size separately from the diff dataCommitDiffcase to usecommitted_account.account.data.len()for buffer allocation while keepingdiff.len()for write instructionsinit_instruction()andrealloc_instructions()to use the newbuffer_account_sizefieldThis ensures that when
(committed_account_datalen - base_account_datalen) > 10KB, the existing realloc splitting logic inrealloc_buffer.rscorrectly generates multiple realloc instructions before the commit instruction.Changes
magicblock-committor-service/src/tasks/mod.rs: Addedbuffer_account_sizefield toPreparationTaskmagicblock-committor-service/src/tasks/buffer_task.rs: UpdatedCommitDiffandCommitcases to properly set buffer sizeTesting
The existing realloc infrastructure (
MAX_ACCOUNT_ALLOC_PER_INSTRUCTION_SIZE = 10,240) will now correctly handle large account growth scenarios.Summary by CodeRabbit