fix(l2): keep newest withdrawal messages in monitor widget#6197
fix(l2): keep newest withdrawal messages in monitor widget#6197avilagaston9 wants to merge 1 commit intomainfrom
Conversation
…ble widget. The on_tick method used truncate(50) which keeps the first (oldest) 50 items. After enough L2 test runs accumulate >50 withdrawal events, the newest withdrawal falls outside this window, causing find_withdrawal_with_widget to return None and the integration test to panic with unwrap on None. Replace truncate with drain to keep the last (newest) 50 items instead.
🤖 Kimi Code ReviewReview of PR #6197File: Issues Found:
Suggested Fix:// Keep only the 50 most recent messages
let mut new_l2_to_l1_messages = fetch_l2_to_l1_messages(
self.last_indexed_block,
current_block,
rollup_client,
)
.await?;
// Truncate to keep most recent 50
new_l2_to_l1_messages.truncate(50);
let n_new_messages = new_l2_to_l1_messages.len();
self.items.truncate(50.saturating_sub(n_new_messages));
self.items.extend(new_l2_to_l1_messages);This maintains the original behavior while fixing the performance and clarity issues. Automated review by Kimi (Moonshot AI) · custom prompt |
🤖 Codex Code ReviewLooks good overall. This change fixes a correctness bug and is idiomatic. Findings
No security, performance, or memory-safety issues found in this diff. Automated review by OpenAI Codex · custom prompt |
🤖 Claude Code ReviewNow I have a complete understanding of the PR. Let me prepare the review. PR Review: Fix L2 Monitor Widget to Keep Newest Withdrawal MessagesSummaryThis PR fixes a critical bug in the Code CorrectnessThe Fix is Correct ✓The change from Before: This aligns with line 182 ( Potential Issue: Logic ConsistencyFile: There's an inconsistency in how limits are applied:
This means:
Example scenario:
This creates a mixed window where the 10 newest and 40 oldest messages are shown, missing the 10 messages between them (A41-A50). For a monitoring UI showing recent activity, line 179 should likely keep the newest 40 items, not the oldest. Suggested fix: let n_new_latest_batches = new_l1_to_l2_messages.len();
let items_to_keep = 50usize.saturating_sub(n_new_latest_batches);
if self.items.len() > items_to_keep {
self.items.drain(..self.items.len() - items_to_keep);
}Style & Best PracticesVariable Naming IssueLine 166: Variable is named Edge Case Handling ✓The check Performance & SafetyMemory Safety ✓Using
Performance Note
TestingThe PR description clearly identifies the root cause of the test failure. The fix directly addresses the bug where VerdictApprove with suggestion: The core fix is correct and solves the reported bug. However, line 179 has a similar logic issue that should ideally be addressed to ensure the monitor UI consistently displays the most recent messages. Required ChangesNone (the PR fixes the immediate bug) Recommended Changes
Automated review by Claude (Anthropic) · custom prompt |
Motivation
The L2 integration test (
test_erc20_roundtrip) panics withunwrap() on a None valueatintegration_tests.rs:705after ~8 consecutive test runs against the same L1/L2 instance. Thefind_withdrawal_with_widgethelper creates a freshL2ToL1MessagesTable(starting from block 0), fetches all withdrawal logs, and searches for the latest withdrawal — buton_tickusestruncate(50)which keeps the oldest 50 items. After enough runs accumulate >50 withdrawal events, the newest withdrawal falls outside the window.Description
Replace
truncate(50)withdrain(..len - 50)inL2ToL1MessagesTable::on_tickso that the newest 50 messages are kept instead of the oldest. This is also the correct behavior for the monitor UI, which should show recent activity.Checklist
STORE_SCHEMA_VERSION(crates/storage/lib.rs) if the PR includes breaking changes to theStorerequiring a re-sync.