Skip to content

fix: clean old txhashset snapshot zips on every zip_read#3888

Open
iho wants to merge 1 commit into
mimblewimble:stagingfrom
iho:fix/txhashset-zip-cleanup
Open

fix: clean old txhashset snapshot zips on every zip_read#3888
iho wants to merge 1 commit into
mimblewimble:stagingfrom
iho:fix/txhashset-zip-cleanup

Conversation

@iho

@iho iho commented Jul 9, 2026

Copy link
Copy Markdown

Summary

  • Fix disk growth from leftover txhashset_snapshot_*.zip files (Clean old txhashset_snapshot_*.zip periodically #3647).
  • On every zip_read (reuse and create), remove other snapshot zips and keep only the one for the requested header.
  • Previous behavior cleaned age-based (24h) files only when creating a new zip, so:
    • reusing the same zip never cleaned anything
    • multiple multi-GB zips could accumulate within 24 hours
  • Adds cleanup_old_txhashset_zips + unit test.

Test plan

  • cargo test -p grin_chain --test test_txhashset -- --test-threads=1 (2 passed)
  • CI on this PR

Keep only the snapshot for the header currently being served and remove
other txhashset_snapshot_*.zip files whenever a peer requests a zip.
Previously cleanup ran only when creating a new archive and retained
24h of multi-GB files, which could fill disks on low-end nodes.

Addresses mimblewimble#3647.
@wiesche89 wiesche89 self-requested a review July 11, 2026 09:33
Err(_) => continue,
};
// Match `txhashset_snapshot_<hash>.zip` only.
if !name.starts_with(&prefix) || !name.ends_with(".zip") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says .zip, but this matches any text between the prefix and .zip.

Generated snapshot names use a 12-character hex hash. Could we restrict cleanup to that exact format?

File::create(&unrelated).unwrap();
File::create(&not_zip).unwrap();

let removed = txhashset::cleanup_old_txhashset_zips(db_root, &keep);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this also exercise zip_read() with the current archive already present and one stale archive beside it? The original regression was specifically that the reuse path skipped cleanup, while this test only covers the helper directly.

}
match fs::remove_file(&path) {
Ok(()) => {
debug!("cleanup_old_txhashset_zips: removed {:?}", path);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zip_read() already logs the total number removed. Could this per file message be trace! or be dropped to avoid duplicate debug output during a rollover?

}
}

/// Remove other `txhashset_snapshot_*.zip` files in `data_dir`, keeping only

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we shorten this? The key detail here is that cleanup runs before both reuse and creation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants