-
Notifications
You must be signed in to change notification settings - Fork 18
feat(consensus): add batched forward epoch sync #819
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
Merged
Lchangliang
merged 9 commits into
Galxe:main
from
Lchangliang:codex/forward-epoch-sync-batches
Aug 20, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d95dd94
feat(consensus): add batched forward epoch sync
Lchangliang efc06ea
fix(consensus): resume epoch transition after sync restart
Lchangliang 913a733
feat(consensus): gate forward epoch sync behind env flag
Lchangliang 1dad95a
fix(consensus): make forward epoch sync batches independent
Lchangliang 98ea378
fix(consensus): handle forward sync end of data
Lchangliang 3be752e
Merge branch 'main' into codex/forward-epoch-sync-batches
nekomoto911 1e6e4a8
fix(consensus): box forward sync manifest response
Lchangliang 4e4a285
Merge branch 'main' into codex/forward-epoch-sync-batches
nekomoto911 5c56a58
Merge branch 'main' into codex/forward-epoch-sync-batches
nekomoto911 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
aptos-core/consensus/consensus-types/src/forward_epoch_sync.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // Copyright © Aptos Foundation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Versioned messages for forward, block-number anchored epoch synchronization. | ||
| //! | ||
| //! The block number is only a lookup/cursor hint. Block IDs, parent links, quorum certificates, | ||
| //! and signed ledger infos remain the authenticated source of truth. | ||
|
|
||
| use crate::{block::Block, quorum_cert::QuorumCert}; | ||
| use gaptos::{aptos_crypto::HashValue, aptos_types::ledger_info::LedgerInfoWithSignatures}; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub enum ForwardEpochSyncRequest { | ||
| V1(ForwardEpochSyncRequestV1), | ||
| } | ||
|
|
||
| impl ForwardEpochSyncRequest { | ||
| pub fn epoch(&self) -> u64 { | ||
| match self { | ||
| Self::V1(request) => request.epoch(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub enum ForwardEpochSyncRequestV1 { | ||
| Prepare(ForwardEpochSyncPrepareRequest), | ||
| Fetch(ForwardEpochSyncFetchRequest), | ||
| } | ||
|
|
||
| impl ForwardEpochSyncRequestV1 { | ||
| pub fn epoch(&self) -> u64 { | ||
| match self { | ||
| Self::Prepare(request) => request.epoch, | ||
| Self::Fetch(request) => request.epoch, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub struct ForwardEpochSyncPrepareRequest { | ||
| pub epoch: u64, | ||
| pub anchor_block_number: u64, | ||
| pub anchor_block_id: HashValue, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub struct ForwardEpochSyncFetchRequest { | ||
| pub epoch: u64, | ||
| pub manifest_id: HashValue, | ||
| pub anchor_block_number: u64, | ||
| pub anchor_block_id: HashValue, | ||
| pub batch_size_blocks: u64, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub enum ForwardEpochSyncResponse { | ||
| V1(ForwardEpochSyncResponseV1), | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub enum ForwardEpochSyncResponseV1 { | ||
| Prepared(Box<ForwardEpochSyncManifest>), | ||
| Batch(ForwardEpochSyncBatch), | ||
| Error(ForwardEpochSyncError), | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub struct ForwardEpochSyncManifest { | ||
| pub epoch: u64, | ||
| pub manifest_id: HashValue, | ||
| /// First block available for this epoch on the canonical path. | ||
| pub first_block_number: u64, | ||
| /// The block-number target for this epoch sync. Fetch batches are ordinary pages; the client | ||
| /// stops once this block has a verified ledger info and is durably committed. | ||
| pub target_block_number: u64, | ||
| pub target_block_id: HashValue, | ||
| pub target_ledger_info: LedgerInfoWithSignatures, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub struct ForwardEpochSyncRecord { | ||
| pub block: Block, | ||
| /// Execution block number, when this consensus block was ordered. A certifying suffix after | ||
| /// a non-blocking epoch boundary can legitimately have no execution block number. | ||
| pub block_number: Option<u64>, | ||
| pub randomness: Option<Vec<u8>>, | ||
| pub quorum_cert: QuorumCert, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub struct ForwardEpochSyncBatch { | ||
| pub epoch: u64, | ||
| pub manifest_id: HashValue, | ||
| /// Echo of the fetch cursor. The first returned block must be its direct child. | ||
| pub anchor_block_number: u64, | ||
| pub anchor_block_id: HashValue, | ||
| pub records: Vec<ForwardEpochSyncRecord>, | ||
| /// Zero or more proofs whose certifying QC is present in this batch. A proof target may have | ||
| /// been persisted by an earlier batch; batch boundaries have no consensus meaning. | ||
| pub ledger_infos: Vec<LedgerInfoWithSignatures>, | ||
| /// Cursor for the next ordinary page. This is always the response tail. | ||
| pub next_anchor_block_number: u64, | ||
| pub next_anchor_block_id: HashValue, | ||
| } | ||
|
|
||
| #[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
| pub enum ForwardEpochSyncError { | ||
| EpochNotFound, | ||
| AnchorMismatch, | ||
| ManifestMismatch, | ||
| InvalidBatchSize, | ||
| BatchBoundaryNotFound, | ||
| Busy, | ||
| Internal, | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
A Byzantine serving peer can answer the initial zero-ID epoch request with
SucceededWithTarget, no blocks, and an invalid high-version epoch-ending ledger info whose boundary matches the local commit root.NetworkSender::request_blockskips verification for that zero-ID request,retrieve_block_by_epochaccepts the response, and this branch selects the unverified proof and returns success after merely queueing it.RoundManagerthen setswait_change_epoch_flag, whileEpochManager::initiate_new_epochlater rejects the signature, so subsequent epoch-change events are ignored and the node remains stuck until restart. Validate the selected ledger info with the epoch verifier before callingsend_committed_epoch_change; the response described above is a minimal reproduction.AGENTS.md reference: AGENTS.md:L5-L8
Useful? React with 👍 / 👎.