fix: v2 tree rollover balance check#2278
Conversation
📝 WalkthroughWalkthroughTwo rollover operation functions in the batched-merkle-tree library have updated their rent-exemption readiness checks. The address tree rollover now uses a threshold comparison instead of equality, and the state tree rollover uses a different inequality formulation. Both changes affect when the NotReadyForRollover error is triggered. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
program-libs/batched-merkle-tree/src/rollover_state_tree.rs (1)
98-106: 🧹 Nitpick | 🔵 TrivialConsider moving this check before
rollover_batched_state_treeto fail fast.In the address-tree file, you moved the balance gate before loading/mutating the old tree (line 22 of
rollover_address_tree.rs). Here, the rent values (merkle_tree_rent,queue_rent,additional_bytes_rent) are all known by line 79 — well before the rollover call on line 99. Moving the check earlier would short-circuit the transaction sooner, saving compute units on the unhappy path and keeping the two rollover functions structurally consistent.Suggested reorder
+ let reimbursement_for_rent = merkle_tree_rent + queue_rent + additional_bytes_rent; + // 5. Check that queue account has sufficient balance for rollover. + #[cfg(target_os = "solana")] + if old_output_queue.lamports() < reimbursement_for_rent.saturating_add(queue_rent) { + return Err(MerkleTreeMetadataError::NotReadyForRollover.into()); + } + let new_mt_data = &mut new_state_merkle_tree.try_borrow_mut_data()?; let params = RolloverBatchStateTreeParams { ... }; - // 5. Rollover the old Merkle tree and queue to new Merkle tree and queue. + // 6. Rollover the old Merkle tree and queue to new Merkle tree and queue. rollover_batched_state_tree(params)?; - let reimbursement_for_rent = merkle_tree_rent + queue_rent + additional_bytes_rent; - // 6. Check that queue account is rent exempt post rollover. - #[cfg(target_os = "solana")] - if old_output_queue.lamports() < reimbursement_for_rent.saturating_add(queue_rent) { - return Err(MerkleTreeMetadataError::NotReadyForRollover.into()); - } Ok(reimbursement_for_rent)
Summary by CodeRabbit