Skip to content

Commit fabd0f3

Browse files
authored
fix: cleanup slots on non-fresh ledger (#404)
On start of `LedgerTruncator` we initialize lowest_cleaup_slot <!-- greptile_comment --> ## Greptile Summary Added initialization of lowest_cleanup_slot in LedgerTruncator to prevent unintended truncation when starting with non-fresh ledgers. - Added new method `initialize_lowest_cleanup_slot` in `magicblock-ledger/src/store/api.rs` to scan blockhash CF for lowest available slot - Modified LedgerTruncator startup in `magicblock-ledger/src/ledger_truncator.rs` to properly initialize lowest cleanup slot - Default lowest cleanup slot to 0 if no slots are found in blockhash column family <!-- /greptile_comment -->
1 parent dfd627c commit fabd0f3

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

magicblock-ledger/src/ledger_truncator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ impl<T: FinalityProvider> LedgerTrunctationWorker<T> {
4747
}
4848

4949
pub async fn run(self) {
50+
self.ledger
51+
.initialize_lowest_cleanup_slot()
52+
.expect("Lowest cleanup slot initialization");
5053
let mut interval = interval(self.truncation_time_interval);
5154
loop {
5255
tokio::select! {

magicblock-ledger/src/store/api.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,26 @@ impl Ledger {
240240
.expect(Self::LOWEST_CLEANUP_SLOT_POISONED)
241241
}
242242

243+
/// Initializes lowest slot to cleanup from
244+
pub fn initialize_lowest_cleanup_slot(&self) -> Result<(), LedgerError> {
245+
match self.blockhash_cf.iter(IteratorMode::Start)?.next() {
246+
Some((lowest_slot, _)) => {
247+
*self
248+
.lowest_cleanup_slot
249+
.write()
250+
.expect(Self::LOWEST_CLEANUP_SLOT_POISONED) = lowest_slot;
251+
}
252+
None => {
253+
*self
254+
.lowest_cleanup_slot
255+
.write()
256+
.expect(Self::LOWEST_CLEANUP_SLOT_POISONED) = 0;
257+
}
258+
}
259+
260+
Ok(())
261+
}
262+
243263
// -----------------
244264
// Block time
245265
// -----------------

test-integration/Cargo.lock

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)