Skip to content

Commit

Permalink
Merge branch 'fc-refactor' of https://github.com/realbigsean/lighthouse
Browse files Browse the repository at this point in the history
… into fc-refactor
  • Loading branch information
realbigsean committed Jun 21, 2022
2 parents 2421281 + c8315e1 commit a7b1e82
Show file tree
Hide file tree
Showing 15 changed files with 699 additions and 528 deletions.
2 changes: 2 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.slot()?,
verified.indexed_attestation(),
AttestationFromBlock::False,
&self.spec,
)
.map_err(Into::into)
}
Expand Down Expand Up @@ -2701,6 +2702,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
current_slot,
&indexed_attestation,
AttestationFromBlock::True,
&self.spec,
) {
Ok(()) => Ok(()),
// Ignore invalid attestations whilst importing attestations from a block. The
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ fn unaggregated_attestations_added_to_fork_choice_some_none() {
// Move forward a slot so all queued attestations can be processed.
harness.advance_slot();
fork_choice
.update_time(harness.chain.slot().unwrap())
.update_time(harness.chain.slot().unwrap(), &MinimalEthSpec)
.unwrap();

let validator_slots: Vec<(usize, Slot)> = (0..VALIDATOR_COUNT)
Expand Down Expand Up @@ -566,7 +566,7 @@ fn unaggregated_attestations_added_to_fork_choice_all_updated() {
// Move forward a slot so all queued attestations can be processed.
harness.advance_slot();
fork_choice
.update_time(harness.chain.slot().unwrap())
.update_time(harness.chain.slot().unwrap(), MinimalEthSpec)
.unwrap();

let validators: Vec<usize> = (0..VALIDATOR_COUNT).collect();
Expand Down
3 changes: 2 additions & 1 deletion common/eth2_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,6 @@ define_hardcoded_nets!(
(prater, "prater", GENESIS_STATE_IS_KNOWN),
(gnosis, "gnosis", GENESIS_STATE_IS_KNOWN),
(kiln, "kiln", GENESIS_STATE_IS_KNOWN),
(ropsten, "ropsten", GENESIS_STATE_IS_KNOWN)
(ropsten, "ropsten", GENESIS_STATE_IS_KNOWN),
(sepolia, "sepolia", GENESIS_STATE_IS_KNOWN)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- enr:-Iq4QMCTfIMXnow27baRUb35Q8iiFHSIDBJh6hQM5Axohhf4b6Kr_cOCu0htQ5WvVqKvFgY28893DHAg8gnBAXsAVqmGAX53x8JggmlkgnY0gmlwhLKAlv6Jc2VjcDI1NmsxoQK6S-Cii_KmfFdUJL2TANL3ksaKUnNXvTCv1tLwXs0QgIN1ZHCCIyk
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Extends the mainnet preset
PRESET_BASE: 'mainnet'
CONFIG_NAME: 'sepolia'

# Genesis
# ---------------------------------------------------------------
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 1300
# Sunday, June 19, 2022 2:00:00 PM +UTC
MIN_GENESIS_TIME: 1655647200
GENESIS_FORK_VERSION: 0x90000069
GENESIS_DELAY: 86400


# Forking
# ---------------------------------------------------------------
# Some forks are disabled for now:
# - These may be re-assigned to another fork-version later
# - Temporarily set to max uint64 value: 2**64 - 1

# Altair
ALTAIR_FORK_VERSION: 0x90000070
ALTAIR_FORK_EPOCH: 50

# Merge
BELLATRIX_FORK_VERSION: 0x90000071
BELLATRIX_FORK_EPOCH: 100
TERMINAL_TOTAL_DIFFICULTY: 100000000000000000000000
TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615

# Capella
CAPELLA_FORK_VERSION: 0x03001020
CAPELLA_FORK_EPOCH: 18446744073709551615

# Sharding
SHARDING_FORK_VERSION: 0x04001020
SHARDING_FORK_EPOCH: 18446744073709551615

# Time parameters
# ---------------------------------------------------------------
# 12 seconds
SECONDS_PER_SLOT: 12
# 14 (estimate from Eth1 mainnet)
SECONDS_PER_ETH1_BLOCK: 14
# 2**8 (= 256) epochs ~27 hours
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
# 2**8 (= 256) epochs ~27 hours
SHARD_COMMITTEE_PERIOD: 256
# 2**11 (= 2,048) Eth1 blocks ~8 hours
ETH1_FOLLOW_DISTANCE: 2048


# Validator cycle
# ---------------------------------------------------------------
# 2**2 (= 4)
INACTIVITY_SCORE_BIAS: 4
# 2**4 (= 16)
INACTIVITY_SCORE_RECOVERY_RATE: 16
# 2**4 * 10**9 (= 16,000,000,000) Gwei
EJECTION_BALANCE: 16000000000
# 2**2 (= 4)
MIN_PER_EPOCH_CHURN_LIMIT: 4
# 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 65536


# Fork choice
# ---------------------------------------------------------------
# 40%
PROPOSER_SCORE_BOOST: 40

# Deposit contract
# ---------------------------------------------------------------
DEPOSIT_CHAIN_ID: 11155111
DEPOSIT_NETWORK_ID: 11155111
DEPOSIT_CONTRACT_ADDRESS: 0x7f02C3E3c98b133055B8B348B2Ac625669Ed295D
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1273020
Binary file not shown.
32 changes: 22 additions & 10 deletions consensus/fork_choice/src/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ssz_derive::{Decode, Encode};
use std::cmp::Ordering;
use std::marker::PhantomData;
use std::time::Duration;
use types::MainnetEthSpec;
use types::{
consts::merge::INTERVALS_PER_SLOT, AttestationShufflingId, BeaconBlock, BeaconState,
BeaconStateError, ChainSpec, Checkpoint, Epoch, EthSpec, ExecPayload, ExecutionBlockHash,
Expand Down Expand Up @@ -302,7 +303,7 @@ where
},
);

let proto_array = ProtoArrayForkChoice::new(
let proto_array = ProtoArrayForkChoice::new::<E>(
finalized_block_slot,
finalized_block_state_root,
*fc_store.justified_checkpoint(),
Expand Down Expand Up @@ -405,7 +406,7 @@ where
current_slot: Slot,
spec: &ChainSpec,
) -> Result<Hash256, Error<T::Error>> {
self.update_time(current_slot)?;
self.update_time(current_slot, spec)?;

let store = &mut self.fc_store;

Expand Down Expand Up @@ -450,8 +451,7 @@ where
current_slot: Slot,
spec: &ChainSpec,
) -> Result<bool, Error<T::Error>> {
//TODO(sean) update_time -> on_tick -> update_checkpoints -> should_update_justified_checkpoint -> update_time
self.update_time(current_slot)?;
self.update_time(current_slot, spec)?;

if compute_slots_since_epoch_start::<E>(self.fc_store.get_current_slot())
< spec.safe_slots_to_update_justified
Expand Down Expand Up @@ -536,7 +536,7 @@ where
payload_verification_status: PayloadVerificationStatus,
spec: &ChainSpec,
) -> Result<(), Error<T::Error>> {
let current_slot = self.update_time(current_slot)?;
let current_slot = self.update_time(current_slot, spec)?;

// Parent block must be known.
if !self.proto_array.contains_block(&block.parent_root()) {
Expand Down Expand Up @@ -698,7 +698,7 @@ where

// This does not apply a vote to the block, it just makes fork choice aware of the block so
// it can still be identified as the head even if it doesn't have any votes.
self.proto_array.process_block(
self.proto_array.process_block::<E>(
ProtoBlock {
slot: block.slot(),
root: block_root,
Expand Down Expand Up @@ -903,9 +903,10 @@ where
current_slot: Slot,
attestation: &IndexedAttestation<E>,
is_from_block: AttestationFromBlock,
spec: &ChainSpec,
) -> Result<(), Error<T::Error>> {
// Ensure the store is up-to-date.
self.update_time(current_slot)?;
self.update_time(current_slot, spec)?;

// Ignore any attestations to the zero hash.
//
Expand Down Expand Up @@ -950,13 +951,16 @@ where

/// Call `on_tick` for all slots between `fc_store.get_current_slot()` and the provided
/// `current_slot`. Returns the value of `self.fc_store.get_current_slot`.
pub fn update_time(&mut self, current_slot: Slot) -> Result<Slot, Error<T::Error>> {
pub fn update_time(
&mut self,
current_slot: Slot,
spec: &ChainSpec,
) -> Result<Slot, Error<T::Error>> {
while self.fc_store.get_current_slot() < current_slot {
let previous_slot = self.fc_store.get_current_slot();
// Note: we are relying upon `on_tick` to update `fc_store.time` to ensure we don't
// get stuck in a loop.
//TODO(sean) fix chain spec
self.on_tick(previous_slot + 1, &ChainSpec::mainnet())?
self.on_tick(previous_slot + 1, spec)?
}

// Process any attestations that might now be eligible.
Expand Down Expand Up @@ -1158,6 +1162,14 @@ where
*self.fc_store.best_justified_checkpoint()
}

pub fn unrealized_justified_checkpoint(&self) -> Checkpoint {
*self.fc_store.unrealized_justified_checkpoint()
}

pub fn unrealized_finalized_checkpoint(&self) -> Checkpoint {
*self.fc_store.unrealized_finalized_checkpoint()
}

/// Returns the latest message for a given validator, if any.
///
/// Returns `(block_root, block_slot)`.
Expand Down
2 changes: 1 addition & 1 deletion consensus/fork_choice/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl ForkChoiceTest {
.chain
.fork_choice
.write()
.update_time(self.harness.chain.slot().unwrap())
.update_time(self.harness.chain.slot().unwrap(), &self.harness.spec)
.unwrap();
func(self.harness.chain.fork_choice.read().queued_attestations());
self
Expand Down
16 changes: 9 additions & 7 deletions consensus/proto_array/src/fork_choice_test_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl ForkChoiceTestDefinition {

let junk_shuffling_id =
AttestationShufflingId::from_components(Epoch::new(0), Hash256::zero());
let mut fork_choice = ProtoArrayForkChoice::new(
let mut fork_choice = ProtoArrayForkChoice::new::<MainnetEthSpec>(
self.finalized_block_slot,
Hash256::zero(),
self.justified_checkpoint,
Expand Down Expand Up @@ -198,12 +198,14 @@ impl ForkChoiceTestDefinition {
unrealized_justified_checkpoint: None,
unrealized_finalized_checkpoint: None,
};
fork_choice.process_block(block, slot).unwrap_or_else(|e| {
panic!(
"process_block op at index {} returned error: {:?}",
op_index, e
)
});
fork_choice
.process_block::<MainnetEthSpec>(block, slot)
.unwrap_or_else(|e| {
panic!(
"process_block op at index {} returned error: {:?}",
op_index, e
)
});
check_bytes_round_trip(&fork_choice);
}
Operation::ProcessAttestation {
Expand Down
Loading

0 comments on commit a7b1e82

Please sign in to comment.