Skip to content

Commit

Permalink
add flag to enable unrealized vote counting
Browse files Browse the repository at this point in the history
  • Loading branch information
realbigsean committed Jul 7, 2022
1 parent 6b71365 commit d0f6f9e
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2661,6 +2661,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&state,
payload_verification_status,
&self.spec,
self.config.count_unrealized,
)
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
}
Expand Down
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ where
store.clone(),
Some(current_slot),
&self.spec,
self.chain_config.count_unrealized,
)?;
}

Expand Down
2 changes: 2 additions & 0 deletions beacon_node/beacon_chain/src/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct ChainConfig {
///
/// If set to 0 then block proposal will not wait for fork choice at all.
pub fork_choice_before_proposal_timeout_ms: u64,
pub count_unrealized: bool,
}

impl Default for ChainConfig {
Expand All @@ -35,6 +36,7 @@ impl Default for ChainConfig {
enable_lock_timeouts: true,
max_network_size: 10 * 1_048_576, // 10M
fork_choice_before_proposal_timeout_ms: DEFAULT_FORK_CHOICE_BEFORE_PROPOSAL_TIMEOUT,
count_unrealized: false,
}
}
}
2 changes: 2 additions & 0 deletions beacon_node/beacon_chain/src/fork_revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
store: Arc<HotColdDB<E, Hot, Cold>>,
current_slot: Option<Slot>,
spec: &ChainSpec,
count_unrealized: bool,
) -> Result<ForkChoice<BeaconForkChoiceStore<E, Hot, Cold>, E>, String> {
// Fetch finalized block.
let finalized_checkpoint = head_state.finalized_checkpoint();
Expand Down Expand Up @@ -193,6 +194,7 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
&state,
payload_verification_status,
spec,
count_unrealized,
)
.map_err(|e| format!("Error applying replayed block to fork choice: {:?}", e))?;
}
Expand Down
7 changes: 7 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,4 +708,11 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.default_value("250")
.takes_value(true)
)
.arg(
Arg::with_name("count-unrealized")
.long("count-unrealized")
.help("**EXPERIMENTAL** Enables an alternative, potentially more performant FFG \
vote tracking method.")
.takes_value(false)
)
}
3 changes: 3 additions & 0 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ pub fn get_config<E: EthSpec>(
client_config.chain.fork_choice_before_proposal_timeout_ms = timeout;
}

client_config.chain.count_unrealized =
clap_utils::parse_required(cli_args, "count-unrealized")?;

Ok(client_config)
}

Expand Down
6 changes: 5 additions & 1 deletion consensus/fork_choice/src/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ where
state: &BeaconState<E>,
payload_verification_status: PayloadVerificationStatus,
spec: &ChainSpec,
count_unrealized: bool,
) -> Result<(), Error<T::Error>> {
let current_slot = self.update_time(current_slot, spec)?;

Expand Down Expand Up @@ -654,7 +655,8 @@ where
)?;

// Update unrealized justified/finalized checkpoints.
let (unrealized_justified_checkpoint, unrealized_finalized_checkpoint) = {
let (unrealized_justified_checkpoint, unrealized_finalized_checkpoint) = if count_unrealized
{
let justification_and_finalization_state = match block {
BeaconBlockRef::Merge(_) | BeaconBlockRef::Altair(_) => {
let participation_cache =
Expand Down Expand Up @@ -714,6 +716,8 @@ where
Some(unrealized_justified_checkpoint),
Some(unrealized_finalized_checkpoint),
)
} else {
(None, None)
};

let target_slot = block
Expand Down
2 changes: 2 additions & 0 deletions consensus/fork_choice/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ impl ForkChoiceTest {
&state,
PayloadVerificationStatus::Verified,
&self.harness.chain.spec,
false,
)
.unwrap();
self
Expand Down Expand Up @@ -334,6 +335,7 @@ impl ForkChoiceTest {
&state,
PayloadVerificationStatus::Verified,
&self.harness.chain.spec,
false,
)
.err()
.expect("on_block did not return an error");
Expand Down
7 changes: 4 additions & 3 deletions testing/ef_tests/src/cases/fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use std::future::Future;
use std::sync::Arc;
use std::time::Duration;
use types::{
Attestation, BeaconBlock, BeaconState, Checkpoint, EthSpec, ExecutionBlockHash, ForkName,
Hash256, IndexedAttestation, SignedBeaconBlock, Slot, Uint256,
Attestation, AttesterSlashing, BeaconBlock, BeaconState, Checkpoint, EthSpec,
ExecutionBlockHash, ForkName, Hash256, IndexedAttestation, SignedBeaconBlock, Slot, Uint256,
};

#[derive(Default, Debug, PartialEq, Clone, Deserialize, Decode)]
Expand Down Expand Up @@ -341,7 +341,7 @@ impl<E: EthSpec> Tester<E> {
.chain
.canonical_head
.fork_choice_write_lock()
.update_time(slot)
.update_time(slot, &self.spec)
.unwrap();
}

Expand Down Expand Up @@ -406,6 +406,7 @@ impl<E: EthSpec> Tester<E> {
&state,
PayloadVerificationStatus::Irrelevant,
&self.harness.chain.spec,
self.harness.chain.config.count_unrealized,
);

if result.is_ok() {
Expand Down

0 comments on commit d0f6f9e

Please sign in to comment.