Skip to content
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

[Epoch Sync] Enable epoch sync by default in configs. #12352

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions chain/client/src/sync/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ impl EpochSync {
highest_height: BlockHeight,
highest_height_peers: &[HighestHeightPeerInfo],
) -> Result<(), Error> {
if !self.config.enabled {
if self.config.disable_epoch_sync_for_bootstrapping {
return Ok(());
}
let tip_height = chain.chain_store().header_head()?.height;
Expand Down Expand Up @@ -966,9 +966,8 @@ impl EpochSync {
impl Handler<EpochSyncRequestMessage> for ClientActorInner {
#[perf]
fn handle(&mut self, msg: EpochSyncRequestMessage) {
if !self.client.epoch_sync.config.enabled {
// TODO(#11937): before we have rate limiting, don't respond to epoch sync requests
// unless config is enabled.
if self.client.epoch_sync.config.ignore_epoch_sync_network_requests {
// Temporary killswitch for the rare case there were issues with this network request.
return;
}
let store = self.client.chain.chain_store.store().clone();
Expand Down
23 changes: 21 additions & 2 deletions core/chain-configs/src/client_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,35 @@ impl SyncConfig {

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub struct EpochSyncConfig {
pub enabled: bool,
/// If true, even if the node started from genesis, it will not perform epoch sync.
/// There should be no reason to set this flag in production, because on both mainnet
/// and testnet it would be infeasible to catch up from genesis without epoch sync.
#[serde(default)]
pub disable_epoch_sync_for_bootstrapping: bool,
/// If true, the node will ignore epoch sync requests from the network. It is strongly
/// recommended not to set this flag, because it will prevent other nodes from
/// bootstrapping. This flag is only included as a kill-switch and may be removed in a
/// future release. Please note that epoch sync requests are heavily rate limited and
/// cached, and therefore should not affect the performance of the node or introduce
/// any non-negligible increase in network traffic.
#[serde(default)]
pub ignore_epoch_sync_network_requests: bool,
/// This serves as two purposes: (1) the node will not epoch sync and instead resort to
/// header sync, if the genesis block is within this many blocks from the current block;
/// (2) the node will reject an epoch sync proof if the provided proof is for an epoch
/// that is more than this many blocks behind the current block.
pub epoch_sync_horizon: BlockHeightDelta,
/// Timeout for epoch sync requests. The node will continue retrying indefinitely even
/// if this timeout is exceeded.
#[serde(with = "near_time::serde_duration_as_std")]
pub timeout_for_epoch_sync: Duration,
}

impl Default for EpochSyncConfig {
fn default() -> Self {
Self {
enabled: false,
disable_epoch_sync_for_bootstrapping: false,
ignore_epoch_sync_network_requests: false,
// Mainnet is 43200 blocks per epoch, so let's default to epoch sync if
// we're more than 5 epochs behind, and we accept proofs up to 2 epochs old.
// (Epoch sync should not be picking a target epoch more than 2 epochs old.)
Expand Down
1 change: 0 additions & 1 deletion integration-tests/src/test_loop/tests/epoch_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ fn bootstrap_node_via_epoch_sync(setup: TestNetworkSetup, source_node: usize) ->
.test_loop_data_dir(tempdir)
.config_modifier(|config, _| {
// Enable epoch sync, and make the horizon small enough to trigger it.
config.epoch_sync.enabled = true;
config.epoch_sync.epoch_sync_horizon = 30;
// Make header sync horizon small enough to trigger it.
config.block_header_fetch_horizon = 8;
Expand Down
Loading