-
Notifications
You must be signed in to change notification settings - Fork 894
Backfill peer attribution #7762
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
pawanjay176
wants to merge
10
commits into
sigp:unstable
Choose a base branch
from
pawanjay176:peer-attribution-backfill
base: unstable
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 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0293d0a
Address some of lion's comments from the other PR
pawanjay176 9bd0f28
Add retries on backfill
pawanjay176 432f68c
Cleanup
pawanjay176 d5bcf9f
Merge branch 'unstable' into peer-attribution-backfill
pawanjay176 5246a20
Add max retry logic
pawanjay176 718e703
lint
pawanjay176 646033b
Use self-hosted runners for Fusaka devnet testing.
jimmygchen 41ad1a9
Run devnet sync test on `Kurtosis` runner.
jimmygchen b96a6e9
Empty commit to trigger CI.
jimmygchen 166468a
Cleanup some retry logic
pawanjay176 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
//! sync as failed, log an error and attempt to retry once a new peer joins the node. | ||
|
||
use crate::network_beacon_processor::ChainSegmentProcessId; | ||
use crate::sync::block_sidecar_coupling::CouplingError; | ||
use crate::sync::manager::BatchProcessResult; | ||
use crate::sync::network_context::{ | ||
RangeRequestId, RpcRequestSendError, RpcResponseError, SyncNetworkContext, | ||
|
@@ -28,7 +29,7 @@ use std::collections::{ | |
}; | ||
use std::sync::Arc; | ||
use tracing::{debug, error, info, instrument, warn}; | ||
use types::{Epoch, EthSpec}; | ||
use types::{ColumnIndex, Epoch, EthSpec}; | ||
|
||
/// Blocks are downloaded in batches from peers. This constant specifies how many epochs worth of | ||
/// blocks per batch are requested _at most_. A batch may request less blocks to account for | ||
|
@@ -223,9 +224,11 @@ impl<T: BeaconChainTypes> BackFillSync<T> { | |
.network_globals | ||
.peers | ||
.read() | ||
.synced_peers() | ||
.synced_peers_for_epoch(self.to_be_downloaded, None) | ||
.next() | ||
.is_some() | ||
// backfill can't progress if we do not have peers in the required subnets post peerdas. | ||
&& self.good_peers_on_sampling_subnets(self.to_be_downloaded, network) | ||
{ | ||
// If there are peers to resume with, begin the resume. | ||
debug!(start_epoch = ?self.current_start, awaiting_batches = self.batches.len(), processing_target = ?self.processing_target, "Resuming backfill sync"); | ||
|
@@ -334,6 +337,48 @@ impl<T: BeaconChainTypes> BackFillSync<T> { | |
err: RpcResponseError, | ||
) -> Result<(), BackFillError> { | ||
if let Some(batch) = self.batches.get_mut(&batch_id) { | ||
if let RpcResponseError::BlockComponentCouplingError(coupling_error) = &err { | ||
match coupling_error { | ||
CouplingError::PeerFailure { | ||
error, | ||
faulty_peers, | ||
action, | ||
} => { | ||
debug!(?batch_id, error, "Block components coupling error"); | ||
// Note: we don't fail the batch here because a `CouplingError` is | ||
// recoverable by requesting from other honest peers. | ||
let mut failed_columns = HashSet::new(); | ||
let mut failed_peers = HashSet::new(); | ||
for (column, peer) in faulty_peers { | ||
failed_columns.insert(*column); | ||
failed_peers.insert(*peer); | ||
} | ||
for peer in failed_peers.iter() { | ||
network.report_peer(*peer, *action, "failed to return columns"); | ||
} | ||
|
||
return self.retry_partial_batch( | ||
network, | ||
batch_id, | ||
request_id, | ||
failed_columns, | ||
failed_peers, | ||
); | ||
} | ||
CouplingError::ExceededMaxRetries(peers, action) => { | ||
for peer in peers.iter() { | ||
network.report_peer( | ||
*peer, | ||
*action, | ||
"failed to return columns, exceeded retry attempts", | ||
); | ||
} | ||
} | ||
CouplingError::InternalError(msg) => { | ||
debug!(?batch_id, msg, "Block components coupling internal error"); | ||
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. should this be 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. user can't really do much about this no? |
||
} | ||
} | ||
} | ||
// A batch could be retried without the peer failing the request (disconnecting/ | ||
// sending an error /timeout) if the peer is removed from the chain for other | ||
// reasons. Check that this block belongs to the expected peer | ||
|
@@ -903,12 +948,16 @@ impl<T: BeaconChainTypes> BackFillSync<T> { | |
network: &mut SyncNetworkContext<T>, | ||
batch_id: BatchId, | ||
) -> Result<(), BackFillError> { | ||
if matches!(self.state(), BackFillState::Paused) { | ||
return Err(BackFillError::Paused); | ||
} | ||
if let Some(batch) = self.batches.get_mut(&batch_id) { | ||
debug!(?batch_id, "Sending backfill batch"); | ||
let synced_peers = self | ||
.network_globals | ||
.peers | ||
.read() | ||
.synced_peers() | ||
.synced_peers_for_epoch(batch_id, None) | ||
.cloned() | ||
.collect::<HashSet<_>>(); | ||
|
||
|
@@ -967,6 +1016,54 @@ impl<T: BeaconChainTypes> BackFillSync<T> { | |
Ok(()) | ||
} | ||
|
||
/// Retries partial column requests within the batch by creating new requests for the failed columns. | ||
#[instrument(parent = None, | ||
fields(service = "backfill_sync"), | ||
name = "backfill_sync", | ||
skip_all | ||
)] | ||
pub fn retry_partial_batch( | ||
&mut self, | ||
network: &mut SyncNetworkContext<T>, | ||
batch_id: BatchId, | ||
id: Id, | ||
failed_columns: HashSet<ColumnIndex>, | ||
mut failed_peers: HashSet<PeerId>, | ||
) -> Result<(), BackFillError> { | ||
if let Some(batch) = self.batches.get_mut(&batch_id) { | ||
failed_peers.extend(&batch.failed_peers()); | ||
let req = batch.to_blocks_by_range_request().0; | ||
|
||
let synced_peers = network | ||
.network_globals() | ||
.peers | ||
.read() | ||
.synced_peers() | ||
.cloned() | ||
.collect::<HashSet<_>>(); | ||
|
||
match network.retry_columns_by_range( | ||
id, | ||
&synced_peers, | ||
&failed_peers, | ||
req, | ||
&failed_columns, | ||
) { | ||
Ok(_) => { | ||
debug!( | ||
?batch_id, | ||
id, "Retried column requests from different peers" | ||
); | ||
return Ok(()); | ||
} | ||
Err(e) => { | ||
debug!(?batch_id, id, e, "Failed to retry partial batch"); | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// When resuming a chain, this function searches for batches that need to be re-downloaded and | ||
/// transitions their state to redownload the batch. | ||
#[instrument(parent = None, | ||
|
@@ -1057,6 +1154,11 @@ impl<T: BeaconChainTypes> BackFillSync<T> { | |
return None; | ||
} | ||
|
||
if !self.good_peers_on_sampling_subnets(self.to_be_downloaded, network) { | ||
debug!("Waiting for peers to be available on custody column subnets"); | ||
return None; | ||
} | ||
|
||
let batch_id = self.to_be_downloaded; | ||
// this batch could have been included already being an optimistic batch | ||
match self.batches.entry(batch_id) { | ||
|
@@ -1089,6 +1191,36 @@ impl<T: BeaconChainTypes> BackFillSync<T> { | |
} | ||
} | ||
|
||
/// Checks all sampling column subnets for peers. Returns `true` if there is at least one peer in | ||
/// every sampling column subnet. | ||
/// | ||
/// Returns `true` if peerdas isn't enabled for the epoch. | ||
fn good_peers_on_sampling_subnets( | ||
&self, | ||
epoch: Epoch, | ||
network: &SyncNetworkContext<T>, | ||
) -> bool { | ||
if network.chain.spec.is_peer_das_enabled_for_epoch(epoch) { | ||
// Require peers on all sampling column subnets before sending batches | ||
let peers_on_all_custody_subnets = network | ||
.network_globals() | ||
.sampling_subnets() | ||
.iter() | ||
.all(|subnet_id| { | ||
let peer_count = network | ||
.network_globals() | ||
.peers | ||
.read() | ||
.good_range_sync_custody_subnet_peers(*subnet_id) | ||
.count(); | ||
peer_count > 0 | ||
}); | ||
peers_on_all_custody_subnets | ||
} else { | ||
true | ||
} | ||
} | ||
|
||
/// Resets the start epoch based on the beacon chain. | ||
/// | ||
/// This errors if the beacon chain indicates that backfill sync has already completed or is | ||
|
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.
Created a separate PR to fix and test this. #7804