-
Notifications
You must be signed in to change notification settings - Fork 18
fix: allow the ledger to rollback a state that has just been rolled forward on the volatile state #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughRefactors Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
Codecov Report❌ Patch coverage is
... and 5 files with indirect coverage changes 🚀 New features to boost your workflow:
|
7b31643 to
9f7535e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@crates/amaru-ledger/src/state/volatile_db.rs`:
- Around line 118-122: The tracing::error! call that logs rollback validation
uses the wrong word "last" in its message; update the message string in the
tracing::error! invocation (the call that includes %target_slot and first_slot =
?first.anchor.0.slot_or_default()) to replace "last known volatile state" with
"first known volatile state" so the log correctly reflects that the check is
against the first element.
🧹 Nitpick comments (1)
crates/amaru-ledger/src/state/volatile_db.rs (1)
428-536: Ripper test coverage!These tests are like a proper walkthrough guide - covering all the key scenarios: before, after, middle, exact, and between. The
test_rollback_to_exact_last_element_should_succeedtest specifically nails the bug described in the PR. Clean helpers too, very DRY.One optional consideration: you might want to add a test for rolling back on an empty
VolatileDB. Currently, both boundary checks would pass through (sinceback()andfront()returnNone), resulting in a no-opOk(()). That behaviour seems reasonable, but documenting it in a test would be like leaving a note at a Zelda shrine for future devs.💡 Optional: Test for empty VolatileDB
#[test] fn test_rollback_on_empty_db_succeeds() { let mut db = VolatileDB::default(); assert!(db.is_empty()); let rollback_point = Point::Specific(Slot::from(10), Hash::new([0u8; 32])); let result = db.rollback_to(&rollback_point, |_| "Point not found"); assert!(result.is_ok(), "Rolling back on empty DB should be a no-op"); assert!(db.is_empty()); }
9f7535e to
d11fb89
Compare
…orward in the volatile state Signed-off-by: etorreborre <etorreborre@yahoo.com>
d11fb89 to
e0359d0
Compare
This issue has been found when trying the reconnection behavior of the node where we happen to roll forward some blocks, and then try to rollback to the last block of the volatile sequence.
The previous function was not making the distinction between finding the last point of the sequence as the rollback point and not finding it at all.
Summary by CodeRabbit
Bug Fixes
Logging
Tests
✏️ Tip: You can customize this high-level summary in your review settings.