forked from ReamLabs/ream
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: sync past finalized to head #19
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
Open
vuonghuuhung
wants to merge
9
commits into
ream-collective:develop
Choose a base branch
from
vuonghuuhung:feat/1550-range-syncer-head-sync
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
06b2d04
fix(rpc): resolve the head and genesis block ids
perfogic 702d527
style: format kurtosis integration changes
perfogic 39172ce
fix(syncer): sync past finalized to head, and stop crashing on post-F…
vuonghuuhung 80df15d
feat: harden range sync against thin peer votes, permanent stalls, an…
vuonghuuhung b1b2032
fix: tighten range-sync quorum, candidate pool, and response validation
vuonghuuhung d5db4ab
fix: fix peer-stuck and duplicate-response bugs in range sync
vuonghuuhung ac36815
feat: add stuck/fork recovery and peer-quality tracking to range sync
vuonghuuhung a0ef3f3
fix: adapt to upstream's P2PCallbackError after rebasing onto develop
vuonghuuhung cbd3037
fix: naming convention
vuonghuuhung 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,18 @@ use std::sync::Arc; | |
| use libp2p::{PeerId, swarm::ConnectionId}; | ||
| use ream_consensus_beacon::{blob_sidecar::BlobIdentifier, data_column_sidecar::ColumnIdentifier}; | ||
| use ream_p2p::network::beacon::network_state::NetworkState; | ||
| use ream_req_resp::beacon::messages::{ | ||
| BeaconRequestMessage, BeaconResponseMessage, | ||
| blob_sidecars::{BlobSidecarsByRangeV1Request, BlobSidecarsByRootV1Request}, | ||
| blocks::{BeaconBlocksByRangeV2Request, BeaconBlocksByRootV2Request}, | ||
| data_column_sidecars::{DataColumnSidecarsByRangeV1Request, DataColumnSidecarsByRootV1Request}, | ||
| use ream_req_resp::{ | ||
| beacon::messages::{ | ||
| BeaconRequestMessage, BeaconResponseMessage, | ||
| blob_sidecars::{BlobSidecarsByRangeV1Request, BlobSidecarsByRootV1Request}, | ||
| blocks::{BeaconBlocksByRangeV2Request, BeaconBlocksByRootV2Request}, | ||
| data_column_sidecars::{ | ||
| DataColumnSidecarsByRangeV1Request, DataColumnSidecarsByRootV1Request, | ||
| }, | ||
| }, | ||
| constants::{ | ||
| MAX_REQUEST_BLOCKS, MAX_REQUEST_BLOCKS_DENEB, MAX_REQUEST_DATA_COLUMN_SIDECARS_PER_COLUMN, | ||
| }, | ||
| }; | ||
| use ream_storage::{ | ||
| db::beacon::BeaconDB, | ||
|
|
@@ -50,16 +57,41 @@ pub async fn handle_req_resp_message( | |
| count, | ||
| .. | ||
| }) => { | ||
| for slot in start_slot..start_slot + count { | ||
| let Ok(Some(block_root)) = ream_db.slot_index_provider().get(slot) else { | ||
| trace!("No block root found for slot {slot}"); | ||
| p2p_sender.send_error_response( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!("No block root found for slot {slot}"), | ||
| ); | ||
| return; | ||
| if count > MAX_REQUEST_BLOCKS { | ||
| p2p_sender.send_invalid_request( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!("Requested count {count} exceeds MAX_REQUEST_BLOCKS"), | ||
| ); | ||
| return; | ||
| } | ||
| let Some(end_slot_exclusive) = start_slot.checked_add(count) else { | ||
| p2p_sender.send_invalid_request( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!("start_slot {start_slot} + count {count} overflows"), | ||
| ); | ||
| return; | ||
| }; | ||
|
|
||
| for slot in start_slot..end_slot_exclusive { | ||
| let block_root = match ream_db.slot_index_provider().get(slot) { | ||
| Ok(Some(block_root)) => block_root, | ||
| Ok(None) => { | ||
| trace!("No block root found for slot {slot}"); | ||
| continue; | ||
| } | ||
| Err(err) => { | ||
| p2p_sender.send_error_response( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!("Failed to read slot index for slot {slot}: {err:?}"), | ||
| ); | ||
| return; | ||
| } | ||
| }; | ||
| let Ok(Some(block)) = ream_db.block_provider().get(block_root) else { | ||
| trace!("No block found for root {block_root}"); | ||
|
|
@@ -109,16 +141,41 @@ pub async fn handle_req_resp_message( | |
| start_slot, | ||
| count, | ||
| }) => { | ||
| for slot in start_slot..start_slot + count { | ||
| let Ok(Some(block_root)) = ream_db.slot_index_provider().get(slot) else { | ||
| trace!("No block root found for slot {slot}"); | ||
| p2p_sender.send_error_response( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!("No block root found for slot {slot}"), | ||
| ); | ||
| return; | ||
| if count > MAX_REQUEST_BLOCKS_DENEB { | ||
|
Comment on lines
143
to
+144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets avoid using hardcoded const when we can read from the beacon state: |
||
| p2p_sender.send_invalid_request( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!("Requested count {count} exceeds MAX_REQUEST_BLOCKS_DENEB"), | ||
| ); | ||
| return; | ||
| } | ||
| let Some(end_slot_exclusive) = start_slot.checked_add(count) else { | ||
| p2p_sender.send_invalid_request( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!("start_slot {start_slot} + count {count} overflows"), | ||
| ); | ||
| return; | ||
| }; | ||
|
|
||
| for slot in start_slot..end_slot_exclusive { | ||
| let block_root = match ream_db.slot_index_provider().get(slot) { | ||
| Ok(Some(block_root)) => block_root, | ||
| Ok(None) => { | ||
| trace!("No block root found for slot {slot}"); | ||
| continue; | ||
| } | ||
| Err(err) => { | ||
| p2p_sender.send_error_response( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!("Failed to read slot index for slot {slot}: {err:?}"), | ||
| ); | ||
| return; | ||
| } | ||
| }; | ||
| let Ok(Some(block)) = ream_db.block_provider().get(block_root) else { | ||
| trace!("No block found for root {block_root}"); | ||
|
|
@@ -232,10 +289,43 @@ pub async fn handle_req_resp_message( | |
| count, | ||
| columns, | ||
| }) => { | ||
| for slot in start_slot..start_slot + count { | ||
| let Ok(Some(block_root)) = ream_db.slot_index_provider().get(slot) else { | ||
| trace!("No block root found for slot {slot}"); | ||
| continue; | ||
| if count > MAX_REQUEST_DATA_COLUMN_SIDECARS_PER_COLUMN { | ||
| p2p_sender.send_invalid_request( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!( | ||
| "Requested count {count} exceeds MAX_REQUEST_DATA_COLUMN_SIDECARS_PER_COLUMN" | ||
| ), | ||
| ); | ||
| return; | ||
| } | ||
| let Some(end_slot_exclusive) = start_slot.checked_add(count) else { | ||
| p2p_sender.send_invalid_request( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!("start_slot {start_slot} + count {count} overflows"), | ||
| ); | ||
| return; | ||
| }; | ||
|
|
||
| for slot in start_slot..end_slot_exclusive { | ||
| let block_root = match ream_db.slot_index_provider().get(slot) { | ||
| Ok(Some(block_root)) => block_root, | ||
| Ok(None) => { | ||
| trace!("No block root found for slot {slot}"); | ||
| continue; | ||
| } | ||
| Err(err) => { | ||
| p2p_sender.send_error_response( | ||
| peer_id, | ||
| connection_id, | ||
| stream_id, | ||
| &format!("Failed to read slot index for slot {slot}: {err:?}"), | ||
| ); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| for &column_index in &columns { | ||
|
|
||
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.
Same here, let's read from the beacon state:
beacon_network_spec().max_request_blocks