Split KV restore/replay batches at epoch endings - #423
Open
sausagee wants to merge 1 commit into
Open
Conversation
KV-only replay previously grouped transactions only by size, so an epoch ending could sit in the middle of a batch. VersionData is written for the last version of each batch; later epochs read usage at the prior epoch ending. Seal each batch at NewEpochEvent (or the size cap) so that version always persists. Co-authored-by: Young Yang Liauw <sausagee@users.noreply.github.com>
sausagee
marked this pull request as ready for review
September 6, 2026 05:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Clean-room rewrite on
m1(not a cherry-pick, patch, or mechanical port from aptos-labs). Upstream intent was read only to identify the bug and the invariant (aptos-labs/aptos-corecommit message for KV replay splitting at epoch endings). Names, control flow, comments, and tests are original.Bug: KV-only restore/replay batched transactions by size only. Storage usage (
VersionData) is written for the last version of each batch. The first block of a new epoch reads usage at the previous epoch's last version (state_storage::on_new_block). When an epoch ending landed in the middle of a batch, that version had no usage row and later re-execution failed withVersionData at <version> is missing.Invariant:
BATCH_SIZE.What changed (crate
aptos-backup-clionly):seal_kv_replay_batchescloses a group atNewEpochEvent(same predicate as the chunk executor / replay-on-archive) or at the existing size cap.replay_kvflattens those sealed groups beforesave_transactions_and_replay_kv, sobase_versionstill advances in order.How Has This Been Tested?
27 passed; 0 failed; 1 ignored (
backup_types::tests::test_end_to_endwas already ignored).New coverage in
kv_replay_batch_tests:len <= max_len, and no epoch flag except at the tail of a groupCI:
rust-lints,rust-targeted-unit-tests,general-lints,rust-cargo-deny, and the license check are green on this revision.Key Areas to Review
seal_kv_replay_batches/kv_replay_item_ends_epochinstorage/backup/backup-cli/src/backup_types/transaction/restore.rsreplay_kvnowtry_flattens size-capped chunks after sealing at epoch endingsAikido / security notes (new code only)
Aikido MCP/CLI is not available in this environment. Manual review of the new code against
RUST_SECURE_CODING.md:unsafe.max_lenis the existingBATCH_SIZEconstant (2 in tests, 10000 otherwise);open.len() >= max_lenisusizecomparison with no wrapping math.debug_assert!(max_len > 0)is a programmer check; a zero cap would still emit one-item groups rather than panic in release.unwrap/expecton restore input; epoch detection uses the existingContractEvent::is_new_epoch_eventpredicate.Please run the project Aikido workflow on the PR if that is part of CI.
Type of Change
Which Components or Systems Does This Change Impact?
aptos-backup-cli)Checklist
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.