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

[Merged by Bors] - Shift networking configuration #4426

Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b97fe50
Adding networking configurations into ChainSpec
armaganyildirak Jun 21, 2023
18c02d2
Finishing gossip_max_size
armaganyildirak Jun 21, 2023
3c770a7
Finishing max_request_blocks?
armaganyildirak Jun 21, 2023
e01ab7b
Finishing max_chunk_size
armaganyildirak Jun 21, 2023
e8f86cd
Finishing ttfb_timeout
armaganyildirak Jun 21, 2023
2cccf6a
Finishing resp_timeout
armaganyildirak Jun 21, 2023
72f92af
Finishing message_domain_valid_snappy
armaganyildirak Jun 21, 2023
489558c
Finishing maximum_gossip_clock_disparity?
armaganyildirak Jun 21, 2023
5e28c2e
Finishing maximum_gossip_clock_disparity
armaganyildirak Jun 21, 2023
563ce17
Finishing for the PR
armaganyildirak Jun 22, 2023
c0ac9dc
Fixing conflicts
armaganyildirak Jun 22, 2023
47d1ae7
use chain instead of calling default_spec() function
armaganyildirak Jun 22, 2023
0724ae0
use chain instead of default_spec()
armaganyildirak Jun 22, 2023
a0f3b39
Adding gossip_max_size function ChainSpec object
armaganyildirak Jun 23, 2023
816ebec
Adding ChainSpec object to other parts
armaganyildirak Jun 24, 2023
b7e009c
Adding ChainSpec object to other parts
armaganyildirak Jun 27, 2023
d3d9b8f
Add the networking constants to Config object
armaganyildirak Jun 27, 2023
7090979
Add ChainSpec object to max_rpc_size function
armaganyildirak Jun 28, 2023
eec5813
remove the needless borrows
armaganyildirak Jun 28, 2023
6ca24e9
Fixing some test errors
armaganyildirak Jun 28, 2023
8f3b9a4
Fix the other tests
armaganyildirak Jun 28, 2023
e003f20
Resolve the some reviews
armaganyildirak Jun 29, 2023
49074a3
fmt
armaganyildirak Jun 29, 2023
ba59277
change self instead of &self for removing clone and unnecessary consu…
armaganyildirak Jun 29, 2023
7ce9005
Changes after review
armaganyildirak Jul 10, 2023
323ddda
Merge branch 'sigp:stable' into shift-networking-configuration
armaganyildirak Jul 10, 2023
214a5ff
Merge branch 'unstable' into shift-networking-configuration
divagant-martian Jul 10, 2023
d478314
Merge pull request #1 from divagant-martian/shift-networking-configur…
armaganyildirak Jul 10, 2023
2c403d9
patch merge
divagant-martian Jul 10, 2023
819ff45
fmt
divagant-martian Jul 10, 2023
3a0c57b
Merge pull request #2 from divagant-martian/shift-networking-configur…
armaganyildirak Jul 10, 2023
965ca75
fixing test errors
armaganyildirak Jul 10, 2023
d4ea7ad
Add sanity check to spawn_reprocess_scheduler function
armaganyildirak Jul 11, 2023
24ef86d
fmt
armaganyildirak Jul 11, 2023
d17b3c2
Merge branch 'unstable' into shift-networking-configuration
armaganyildirak Jul 13, 2023
75fcfbf
Remove unnecessary comment
armaganyildirak Jul 17, 2023
42cf723
fix merge conflicts
armaganyildirak Jul 17, 2023
0e67472
fixes after review
armaganyildirak Jul 18, 2023
821dab2
Set ATTESTATION_SUBNET_EXTRA_BITS value to 0
armaganyildirak Jul 18, 2023
9502596
clippy
armaganyildirak Jul 18, 2023
3608b1a
Add serde default impls to `Config`
paulhauner Jul 27, 2023
82fc995
Changes after review
armaganyildirak Jul 27, 2023
7c61007
Diva's patch. Seems to add subnet prefix back also
AgeManning Aug 1, 2023
165a1c2
change after review
armaganyildirak Aug 1, 2023
a5368b0
change after review
armaganyildirak Aug 1, 2023
e9e1ff9
fix the confilicts
armaganyildirak Aug 2, 2023
7fa9a17
fmt
armaganyildirak Aug 2, 2023
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
20 changes: 9 additions & 11 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
mod batch;

use crate::{
beacon_chain::{MAXIMUM_GOSSIP_CLOCK_DISPARITY, VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT},
metrics,
observed_aggregates::ObserveOutcome,
observed_attesters::Error as ObservedAttestersError,
beacon_chain::VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT, metrics,
observed_aggregates::ObserveOutcome, observed_attesters::Error as ObservedAttestersError,
BeaconChain, BeaconChainError, BeaconChainTypes,
};
use bls::verify_signature_sets;
Expand All @@ -57,8 +55,8 @@ use std::borrow::Cow;
use strum::AsRefStr;
use tree_hash::TreeHash;
use types::{
Attestation, BeaconCommittee, CommitteeIndex, Epoch, EthSpec, Hash256, IndexedAttestation,
SelectionProof, SignedAggregateAndProof, Slot, SubnetId,
Attestation, BeaconCommittee, ChainSpec, CommitteeIndex, Epoch, EthSpec, Hash256,
IndexedAttestation, SelectionProof, SignedAggregateAndProof, Slot, SubnetId,
};

pub use batch::{batch_verify_aggregated_attestations, batch_verify_unaggregated_attestations};
Expand Down Expand Up @@ -454,7 +452,7 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
// MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance).
//
// We do not queue future attestations for later processing.
verify_propagation_slot_range(&chain.slot_clock, attestation)?;
verify_propagation_slot_range(&chain.slot_clock, attestation, &chain.spec)?;

// Check the attestation's epoch matches its target.
if attestation.data.slot.epoch(T::EthSpec::slots_per_epoch())
Expand Down Expand Up @@ -718,7 +716,7 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
// MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance).
//
// We do not queue future attestations for later processing.
verify_propagation_slot_range(&chain.slot_clock, attestation)?;
verify_propagation_slot_range(&chain.slot_clock, attestation, &chain.spec)?;

// Check to ensure that the attestation is "unaggregated". I.e., it has exactly one
// aggregation bit set.
Expand Down Expand Up @@ -1033,11 +1031,11 @@ fn verify_head_block_is_known<T: BeaconChainTypes>(
pub fn verify_propagation_slot_range<S: SlotClock, E: EthSpec>(
slot_clock: &S,
attestation: &Attestation<E>,
spec: &ChainSpec,
) -> Result<(), Error> {
let attestation_slot = attestation.data.slot;

let latest_permissible_slot = slot_clock
.now_with_future_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
.now_with_future_tolerance(spec.clone().maximum_gossip_clock_disparity())
.ok_or(BeaconChainError::UnableToReadSlot)?;
if attestation_slot > latest_permissible_slot {
return Err(Error::FutureSlot {
Expand All @@ -1048,7 +1046,7 @@ pub fn verify_propagation_slot_range<S: SlotClock, E: EthSpec>(

// Taking advantage of saturating subtraction on `Slot`.
let earliest_permissible_slot = slot_clock
.now_with_past_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
.now_with_past_tolerance(spec.clone().maximum_gossip_clock_disparity())
.ok_or(BeaconChainError::UnableToReadSlot)?
- E::slots_per_epoch();
if attestation_slot < earliest_permissible_slot {
Expand Down
5 changes: 0 additions & 5 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ pub enum OverrideForkchoiceUpdate {
AlreadyApplied,
}

/// The accepted clock drift for nodes gossiping blocks and attestations. See:
///
/// https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/p2p-interface.md#configuration
pub const MAXIMUM_GOSSIP_CLOCK_DISPARITY: Duration = Duration::from_millis(500);

#[derive(Debug, PartialEq)]
pub enum AttestationProcessingOutcome {
Processed,
Expand Down
6 changes: 4 additions & 2 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use crate::validator_pubkey_cache::ValidatorPubkeyCache;
use crate::{
beacon_chain::{
BeaconForkChoice, ForkChoiceError, BLOCK_PROCESSING_CACHE_LOCK_TIMEOUT,
MAXIMUM_GOSSIP_CLOCK_DISPARITY, VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT,
VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT,
},
metrics, BeaconChain, BeaconChainError, BeaconChainTypes,
};
Expand Down Expand Up @@ -695,7 +695,9 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
// Do not gossip or process blocks from future slots.
let present_slot_with_tolerance = chain
.slot_clock
.now_with_future_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
.now_with_future_tolerance(Duration::from_millis(
chain.spec.maximum_gossip_clock_disparity_millis,
))
pawanjay176 marked this conversation as resolved.
Show resolved Hide resolved
.ok_or(BeaconChainError::UnableToReadSlot)?;
if block.slot() > present_slot_with_tolerance {
return Err(BlockError::FutureSlot {
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub use self::beacon_chain::{
AttestationProcessingOutcome, BeaconChain, BeaconChainTypes, BeaconStore, ChainSegmentResult,
ForkChoiceError, OverrideForkchoiceUpdate, ProduceBlockVerification, StateSkipConfig,
WhenSlotSkipped, INVALID_FINALIZED_MERGE_TRANSITION_BLOCK_SHUTDOWN_REASON,
INVALID_JUSTIFIED_PAYLOAD_SHUTDOWN_REASON, MAXIMUM_GOSSIP_CLOCK_DISPARITY,
INVALID_JUSTIFIED_PAYLOAD_SHUTDOWN_REASON,
};
pub use self::beacon_snapshot::BeaconSnapshot;
pub use self::chain_config::ChainConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::{
beacon_chain::MAXIMUM_GOSSIP_CLOCK_DISPARITY, BeaconChain, BeaconChainError, BeaconChainTypes,
};
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};
use derivative::Derivative;
use slot_clock::SlotClock;
use std::time::Duration;
Expand Down Expand Up @@ -103,7 +101,9 @@ impl<T: BeaconChainTypes> VerifiedLightClientFinalityUpdate<T> {
// verify that enough time has passed for the block to have been propagated
match start_time {
Some(time) => {
if seen_timestamp + MAXIMUM_GOSSIP_CLOCK_DISPARITY < time + one_third_slot_duration
if seen_timestamp
+ Duration::from_millis(chain.spec.maximum_gossip_clock_disparity_millis)
< time + one_third_slot_duration
pawanjay176 marked this conversation as resolved.
Show resolved Hide resolved
{
return Err(Error::TooEarly);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::{
beacon_chain::MAXIMUM_GOSSIP_CLOCK_DISPARITY, BeaconChain, BeaconChainError, BeaconChainTypes,
};
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};
use derivative::Derivative;
use eth2::types::Hash256;
use slot_clock::SlotClock;
Expand Down Expand Up @@ -103,7 +101,9 @@ impl<T: BeaconChainTypes> VerifiedLightClientOptimisticUpdate<T> {
// verify that enough time has passed for the block to have been propagated
match start_time {
Some(time) => {
if seen_timestamp + MAXIMUM_GOSSIP_CLOCK_DISPARITY < time + one_third_slot_duration
if seen_timestamp
+ Duration::from_millis(chain.spec.maximum_gossip_clock_disparity_millis)
< time + one_third_slot_duration
pawanjay176 marked this conversation as resolved.
Show resolved Hide resolved
{
return Err(Error::TooEarly);
}
Expand Down
19 changes: 9 additions & 10 deletions beacon_node/beacon_chain/src/sync_committee_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@

use crate::observed_attesters::SlotSubcommitteeIndex;
use crate::{
beacon_chain::{MAXIMUM_GOSSIP_CLOCK_DISPARITY, VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT},
metrics,
observed_aggregates::ObserveOutcome,
BeaconChain, BeaconChainError, BeaconChainTypes,
beacon_chain::VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT, metrics,
observed_aggregates::ObserveOutcome, BeaconChain, BeaconChainError, BeaconChainTypes,
};
use bls::{verify_signature_sets, PublicKeyBytes};
use derivative::Derivative;
Expand All @@ -43,8 +41,9 @@ use state_processing::signature_sets::{
sync_committee_contribution_signature_set_from_pubkeys,
sync_committee_message_set_from_pubkeys,
};
use std::borrow::Cow;
use types::ChainSpec;
use std::collections::HashMap;
use std::borrow::Cow;
use strum::AsRefStr;
use tree_hash::TreeHash;
use types::consts::altair::SYNC_COMMITTEE_SUBNET_COUNT;
Expand Down Expand Up @@ -287,7 +286,7 @@ impl<T: BeaconChainTypes> VerifiedSyncContribution<T> {
let subcommittee_index = contribution.subcommittee_index as usize;

// Ensure sync committee contribution is within the MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance.
verify_propagation_slot_range(&chain.slot_clock, contribution)?;
verify_propagation_slot_range(&chain.slot_clock, contribution, &chain.spec)?;

// Validate subcommittee index.
if contribution.subcommittee_index >= SYNC_COMMITTEE_SUBNET_COUNT {
Expand Down Expand Up @@ -442,7 +441,7 @@ impl VerifiedSyncCommitteeMessage {
// MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance).
//
// We do not queue future sync committee messages for later processing.
verify_propagation_slot_range(&chain.slot_clock, &sync_message)?;
verify_propagation_slot_range(&chain.slot_clock, &sync_message, &chain.spec)?;

// Ensure the `subnet_id` is valid for the given validator.
let pubkey = chain
Expand Down Expand Up @@ -558,11 +557,11 @@ impl VerifiedSyncCommitteeMessage {
pub fn verify_propagation_slot_range<S: SlotClock, U: SlotData>(
slot_clock: &S,
sync_contribution: &U,
spec: &ChainSpec,
) -> Result<(), Error> {
let message_slot = sync_contribution.get_slot();

let latest_permissible_slot = slot_clock
.now_with_future_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
.now_with_future_tolerance(spec.clone().maximum_gossip_clock_disparity())
.ok_or(BeaconChainError::UnableToReadSlot)?;
if message_slot > latest_permissible_slot {
return Err(Error::FutureSlot {
Expand All @@ -572,7 +571,7 @@ pub fn verify_propagation_slot_range<S: SlotClock, U: SlotData>(
}

let earliest_permissible_slot = slot_clock
.now_with_past_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
.now_with_past_tolerance(spec.clone().maximum_gossip_clock_disparity())
.ok_or(BeaconChainError::UnableToReadSlot)?;

if message_slot < earliest_permissible_slot {
Expand Down
9 changes: 5 additions & 4 deletions beacon_node/http_api/src/attester_duties.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//! Contains the handler for the `GET validator/duties/attester/{epoch}` endpoint.

use crate::state_id::StateId;
use beacon_chain::{
BeaconChain, BeaconChainError, BeaconChainTypes, MAXIMUM_GOSSIP_CLOCK_DISPARITY,
};
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes};
use eth2::types::{self as api_types};
use slot_clock::SlotClock;
use state_processing::state_advance::partial_state_advance;
use std::time::Duration;
use types::{
AttestationDuty, BeaconState, ChainSpec, CloneConfig, Epoch, EthSpec, Hash256, RelativeEpoch,
};
Expand All @@ -32,7 +31,9 @@ pub fn attester_duties<T: BeaconChainTypes>(
// will equal `current_epoch + 1`
let tolerant_current_epoch = chain
.slot_clock
.now_with_future_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
.now_with_future_tolerance(Duration::from_millis(
chain.spec.maximum_gossip_clock_disparity_millis,
pawanjay176 marked this conversation as resolved.
Show resolved Hide resolved
))
.ok_or_else(|| warp_utils::reject::custom_server_error("unable to read slot clock".into()))?
.epoch(T::EthSpec::slots_per_epoch());

Expand Down
8 changes: 5 additions & 3 deletions beacon_node/http_api/src/proposer_duties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
use crate::state_id::StateId;
use beacon_chain::{
beacon_proposer_cache::{compute_proposer_duties_from_head, ensure_state_is_in_epoch},
BeaconChain, BeaconChainError, BeaconChainTypes, MAXIMUM_GOSSIP_CLOCK_DISPARITY,
BeaconChain, BeaconChainError, BeaconChainTypes,
};
use eth2::types::{self as api_types};
use safe_arith::SafeArith;
use slog::{debug, Logger};
use slot_clock::SlotClock;
use std::cmp::Ordering;
use std::{cmp::Ordering, time::Duration};
use types::{CloneConfig, Epoch, EthSpec, Hash256, Slot};

/// The struct that is returned to the requesting HTTP client.
Expand All @@ -33,7 +33,9 @@ pub fn proposer_duties<T: BeaconChainTypes>(
// will equal `current_epoch + 1`
let tolerant_current_epoch = chain
.slot_clock
.now_with_future_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
.now_with_future_tolerance(Duration::from_millis(
chain.spec.maximum_gossip_clock_disparity_millis,
pawanjay176 marked this conversation as resolved.
Show resolved Hide resolved
))
.ok_or_else(|| warp_utils::reject::custom_server_error("unable to read slot clock".into()))?
.epoch(T::EthSpec::slots_per_epoch());

Expand Down
7 changes: 5 additions & 2 deletions beacon_node/http_api/src/sync_committees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use beacon_chain::sync_committee_verification::{
};
use beacon_chain::{
validator_monitor::timestamp_now, BeaconChain, BeaconChainError, BeaconChainTypes,
StateSkipConfig, MAXIMUM_GOSSIP_CLOCK_DISPARITY,
StateSkipConfig,
};
use eth2::types::{self as api_types};
use lighthouse_network::PubsubMessage;
Expand All @@ -15,6 +15,7 @@ use slog::{debug, error, warn, Logger};
use slot_clock::SlotClock;
use std::cmp::max;
use std::collections::HashMap;
use std::time::Duration;
use tokio::sync::mpsc::UnboundedSender;
use types::{
slot_data::SlotData, BeaconStateError, Epoch, EthSpec, SignedContributionAndProof,
Expand Down Expand Up @@ -85,7 +86,9 @@ fn duties_from_state_load<T: BeaconChainTypes>(
let current_epoch = chain.epoch()?;
let tolerant_current_epoch = chain
.slot_clock
.now_with_future_tolerance(MAXIMUM_GOSSIP_CLOCK_DISPARITY)
.now_with_future_tolerance(Duration::from_millis(
chain.spec.maximum_gossip_clock_disparity_millis,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one as well

))
.ok_or(BeaconChainError::UnableToReadSlot)?
.epoch(T::EthSpec::slots_per_epoch());

Expand Down
13 changes: 8 additions & 5 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use beacon_chain::test_utils::RelativeSyncCommittee;
use beacon_chain::{
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType},
BeaconChain, StateSkipConfig, WhenSlotSkipped, MAXIMUM_GOSSIP_CLOCK_DISPARITY,
BeaconChain, StateSkipConfig, WhenSlotSkipped,
};
use environment::null_logger;
use eth2::{
Expand Down Expand Up @@ -2259,7 +2259,9 @@ impl ApiTester {
.unwrap();

self.chain.slot_clock.set_current_time(
current_epoch_start - MAXIMUM_GOSSIP_CLOCK_DISPARITY - Duration::from_millis(1),
current_epoch_start
- Duration::from_millis(self.chain.spec.maximum_gossip_clock_disparity_millis)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here

- Duration::from_millis(1),
);

let dependent_root = self
Expand Down Expand Up @@ -2296,9 +2298,10 @@ impl ApiTester {
"should not get attester duties outside of tolerance"
);

self.chain
.slot_clock
.set_current_time(current_epoch_start - MAXIMUM_GOSSIP_CLOCK_DISPARITY);
self.chain.slot_clock.set_current_time(
current_epoch_start
- Duration::from_millis(self.chain.spec.maximum_gossip_clock_disparity_millis),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

);

self.client
.get_validator_duties_proposer(current_epoch)
Expand Down
Loading
Loading