mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 19:32:55 +00:00
## Limit Backfill Sync This PR transitions Lighthouse from syncing all the way back to genesis to only syncing back to the weak subjectivity point (~ 5 months) when syncing via a checkpoint sync. There are a number of important points to note with this PR: - Firstly and most importantly, this PR fundamentally shifts the default security guarantees of checkpoint syncing in Lighthouse. Prior to this PR, Lighthouse could verify the checkpoint of any given chain by ensuring the chain eventually terminates at the corresponding genesis. This guarantee can still be employed via the new CLI flag --genesis-backfill which will prompt lighthouse to the old behaviour of downloading all blocks back to genesis. The new behaviour only checks the proposer signatures for the last 5 months of blocks but cannot guarantee the chain matches the genesis chain. - I have not modified any of the peer scoring or RPC responses. Clients syncing from gensis, will downscore new Lighthouse peers that do not possess blocks prior to the WSP. This is by design, as Lighthouse nodes of this form, need a mechanism to sort through peers in order to find useful peers in order to complete their genesis sync. We therefore do not discriminate between empty/error responses for blocks prior or post the local WSP. If we request a block that a peer does not posses, then fundamentally that peer is less useful to us than other peers. - This will make a radical shift in that the majority of nodes will no longer store the full history of the chain. In the future we could add a pruning mechanism to remove old blocks from the db also. Co-authored-by: Paul Hauner <paul@paulhauner.com>
129 lines
6.4 KiB
Rust
129 lines
6.4 KiB
Rust
pub use proto_array::{DisallowedReOrgOffsets, ReOrgThreshold};
|
|
use serde_derive::{Deserialize, Serialize};
|
|
use std::time::Duration;
|
|
use types::{Checkpoint, Epoch};
|
|
|
|
pub const DEFAULT_RE_ORG_THRESHOLD: ReOrgThreshold = ReOrgThreshold(20);
|
|
pub const DEFAULT_RE_ORG_MAX_EPOCHS_SINCE_FINALIZATION: Epoch = Epoch::new(2);
|
|
/// Default to 1/12th of the slot, which is 1 second on mainnet.
|
|
pub const DEFAULT_RE_ORG_CUTOFF_DENOMINATOR: u32 = 12;
|
|
pub const DEFAULT_FORK_CHOICE_BEFORE_PROPOSAL_TIMEOUT: u64 = 250;
|
|
|
|
/// Default fraction of a slot lookahead for payload preparation (12/3 = 4 seconds on mainnet).
|
|
pub const DEFAULT_PREPARE_PAYLOAD_LOOKAHEAD_FACTOR: u32 = 3;
|
|
|
|
/// Fraction of a slot lookahead for fork choice in the state advance timer (500ms on mainnet).
|
|
pub const FORK_CHOICE_LOOKAHEAD_FACTOR: u32 = 24;
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
|
|
pub struct ChainConfig {
|
|
/// Maximum number of slots to skip when importing a consensus message (e.g., block,
|
|
/// attestation, etc).
|
|
///
|
|
/// If `None`, there is no limit.
|
|
pub import_max_skip_slots: Option<u64>,
|
|
/// A user-input `Checkpoint` that must exist in the beacon chain's sync path.
|
|
///
|
|
/// If `None`, there is no weak subjectivity verification.
|
|
pub weak_subjectivity_checkpoint: Option<Checkpoint>,
|
|
/// Determine whether to reconstruct historic states, usually after a checkpoint sync.
|
|
pub reconstruct_historic_states: bool,
|
|
/// Whether timeouts on `TimeoutRwLock`s are enabled or not.
|
|
pub enable_lock_timeouts: bool,
|
|
/// The max size of a message that can be sent over the network.
|
|
pub max_network_size: usize,
|
|
/// Maximum percentage of committee weight at which to attempt re-orging the canonical head.
|
|
pub re_org_threshold: Option<ReOrgThreshold>,
|
|
/// Maximum number of epochs since finalization for attempting a proposer re-org.
|
|
pub re_org_max_epochs_since_finalization: Epoch,
|
|
/// Maximum delay after the start of the slot at which to propose a reorging block.
|
|
pub re_org_cutoff_millis: Option<u64>,
|
|
/// Additional epoch offsets at which re-orging block proposals are not permitted.
|
|
///
|
|
/// By default this list is empty, but it can be useful for reacting to network conditions, e.g.
|
|
/// slow gossip of re-org blocks at slot 1 in the epoch.
|
|
pub re_org_disallowed_offsets: DisallowedReOrgOffsets,
|
|
/// Number of milliseconds to wait for fork choice before proposing a block.
|
|
///
|
|
/// If set to 0 then block proposal will not wait for fork choice at all.
|
|
pub fork_choice_before_proposal_timeout_ms: u64,
|
|
/// Number of skip slots in a row before the BN refuses to use connected builders during payload construction.
|
|
pub builder_fallback_skips: usize,
|
|
/// Number of skip slots in the past `SLOTS_PER_EPOCH` before the BN refuses to use connected
|
|
/// builders during payload construction.
|
|
pub builder_fallback_skips_per_epoch: usize,
|
|
/// Number of epochs since finalization before the BN refuses to use connected builders during
|
|
/// payload construction.
|
|
pub builder_fallback_epochs_since_finalization: usize,
|
|
/// Whether any chain health checks should be considered when deciding whether to use the builder API.
|
|
pub builder_fallback_disable_checks: bool,
|
|
/// When set to `true`, forget any valid/invalid/optimistic statuses in fork choice during start
|
|
/// up.
|
|
pub always_reset_payload_statuses: bool,
|
|
/// Whether to apply paranoid checks to blocks proposed by this beacon node.
|
|
pub paranoid_block_proposal: bool,
|
|
/// Optionally set timeout for calls to checkpoint sync endpoint.
|
|
pub checkpoint_sync_url_timeout: u64,
|
|
/// The offset before the start of a proposal slot at which payload attributes should be sent.
|
|
///
|
|
/// Low values are useful for execution engines which don't improve their payload after the
|
|
/// first call, and high values are useful for ensuring the EL is given ample notice.
|
|
pub prepare_payload_lookahead: Duration,
|
|
/// Use EL-free optimistic sync for the finalized part of the chain.
|
|
pub optimistic_finalized_sync: bool,
|
|
/// The size of the shuffling cache,
|
|
pub shuffling_cache_size: usize,
|
|
/// If using a weak-subjectivity sync, whether we should download blocks all the way back to
|
|
/// genesis.
|
|
pub genesis_backfill: bool,
|
|
/// Whether to send payload attributes every slot, regardless of connected proposers.
|
|
///
|
|
/// This is useful for block builders and testing.
|
|
pub always_prepare_payload: bool,
|
|
/// Whether backfill sync processing should be rate-limited.
|
|
pub enable_backfill_rate_limiting: bool,
|
|
}
|
|
|
|
impl Default for ChainConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
import_max_skip_slots: None,
|
|
weak_subjectivity_checkpoint: None,
|
|
reconstruct_historic_states: false,
|
|
enable_lock_timeouts: true,
|
|
max_network_size: 10 * 1_048_576, // 10M
|
|
re_org_threshold: Some(DEFAULT_RE_ORG_THRESHOLD),
|
|
re_org_max_epochs_since_finalization: DEFAULT_RE_ORG_MAX_EPOCHS_SINCE_FINALIZATION,
|
|
re_org_cutoff_millis: None,
|
|
re_org_disallowed_offsets: DisallowedReOrgOffsets::default(),
|
|
fork_choice_before_proposal_timeout_ms: DEFAULT_FORK_CHOICE_BEFORE_PROPOSAL_TIMEOUT,
|
|
// Builder fallback configs that are set in `clap` will override these.
|
|
builder_fallback_skips: 3,
|
|
builder_fallback_skips_per_epoch: 8,
|
|
builder_fallback_epochs_since_finalization: 3,
|
|
builder_fallback_disable_checks: false,
|
|
always_reset_payload_statuses: false,
|
|
paranoid_block_proposal: false,
|
|
checkpoint_sync_url_timeout: 60,
|
|
prepare_payload_lookahead: Duration::from_secs(4),
|
|
// This value isn't actually read except in tests.
|
|
optimistic_finalized_sync: true,
|
|
shuffling_cache_size: crate::shuffling_cache::DEFAULT_CACHE_SIZE,
|
|
genesis_backfill: false,
|
|
always_prepare_payload: false,
|
|
enable_backfill_rate_limiting: true,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ChainConfig {
|
|
/// The latest delay from the start of the slot at which to attempt a 1-slot re-org.
|
|
pub fn re_org_cutoff(&self, seconds_per_slot: u64) -> Duration {
|
|
self.re_org_cutoff_millis
|
|
.map(Duration::from_millis)
|
|
.unwrap_or_else(|| {
|
|
Duration::from_secs(seconds_per_slot) / DEFAULT_RE_ORG_CUTOFF_DENOMINATOR
|
|
})
|
|
}
|
|
}
|