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

Encode Execution Engine Client Version In Graffiti #5290

Merged
merged 9 commits into from
Apr 24, 2024
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions beacon_node/beacon_chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ operation_pool = { workspace = true }
rayon = { workspace = true }
serde = { workspace = true }
ethereum_serde_utils = { workspace = true }
lighthouse_version = { workspace = true }
slog = { workspace = true }
sloggers = { workspace = true }
slot_clock = { workspace = true }
Expand Down
17 changes: 8 additions & 9 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::eth1_finalization_cache::{Eth1FinalizationCache, Eth1FinalizationData
use crate::events::ServerSentEventHandler;
use crate::execution_payload::{get_execution_payload, NotifyExecutionLayer, PreparePayloadHandle};
use crate::fork_choice_signal::{ForkChoiceSignalRx, ForkChoiceSignalTx, ForkChoiceWaitResult};
use crate::graffiti_calculator::GraffitiCalculator;
use crate::head_tracker::{HeadTracker, HeadTrackerReader, SszHeadTracker};
use crate::historical_blocks::HistoricalBlockError;
use crate::light_client_finality_update_verification::{
Expand Down Expand Up @@ -480,7 +481,7 @@ pub struct BeaconChain<T: BeaconChainTypes> {
/// Logging to CLI, etc.
pub(crate) log: Logger,
/// Arbitrary bytes included in the blocks.
pub(crate) graffiti: Graffiti,
pub(crate) graffiti_calculator: GraffitiCalculator<T>,
/// Optional slasher.
pub slasher: Option<Arc<Slasher<T::EthSpec>>>,
/// Provides monitoring of a set of explicitly defined validators.
Expand Down Expand Up @@ -4777,6 +4778,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
//
// Perform the state advance and block-packing functions.
let chain = self.clone();
let graffiti = self
.graffiti_calculator
.get_graffiti(validator_graffiti)
.await;
let mut partial_beacon_block = self
.task_executor
.spawn_blocking_handle(
Expand All @@ -4786,7 +4791,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state_root_opt,
produce_at_slot,
randao_reveal,
validator_graffiti,
graffiti,
builder_boost_factor,
block_production_version,
)
Expand Down Expand Up @@ -4884,7 +4889,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state_root_opt: Option<Hash256>,
produce_at_slot: Slot,
randao_reveal: Signature,
validator_graffiti: Option<Graffiti>,
graffiti: Graffiti,
builder_boost_factor: Option<u64>,
block_production_version: BlockProductionVersion,
) -> Result<PartialBeaconBlock<T::EthSpec>, BlockProductionError> {
Expand Down Expand Up @@ -4989,12 +4994,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}
drop(unagg_import_timer);

// Override the beacon node's graffiti with graffiti from the validator, if present.
let graffiti = match validator_graffiti {
Some(graffiti) => graffiti,
None => self.graffiti,
};

let attestation_packing_timer =
metrics::start_timer(&metrics::BLOCK_PRODUCTION_ATTESTATION_TIMES);

Expand Down
24 changes: 15 additions & 9 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::eth1_chain::{CachingEth1Backend, SszEth1};
use crate::eth1_finalization_cache::Eth1FinalizationCache;
use crate::fork_choice_signal::ForkChoiceSignalTx;
use crate::fork_revert::{reset_fork_choice_to_finalization, revert_to_fork_boundary};
use crate::graffiti_calculator::{GraffitiCalculator, GraffitiOrigin};
use crate::head_tracker::HeadTracker;
use crate::light_client_server_cache::LightClientServerCache;
use crate::migrate::{BackgroundMigrator, MigratorConfig};
Expand Down Expand Up @@ -39,8 +40,8 @@ use std::time::Duration;
use store::{Error as StoreError, HotColdDB, ItemStore, KeyValueStoreOp};
use task_executor::{ShutdownReason, TaskExecutor};
use types::{
BeaconBlock, BeaconState, BlobSidecarList, ChainSpec, Checkpoint, Epoch, EthSpec, Graffiti,
Hash256, Signature, SignedBeaconBlock, Slot,
BeaconBlock, BeaconState, BlobSidecarList, ChainSpec, Checkpoint, Epoch, EthSpec, Hash256,
Signature, SignedBeaconBlock, Slot,
};

/// An empty struct used to "witness" all the `BeaconChainTypes` traits. It has no user-facing
Expand Down Expand Up @@ -96,7 +97,7 @@ pub struct BeaconChainBuilder<T: BeaconChainTypes> {
spec: ChainSpec,
chain_config: ChainConfig,
log: Option<Logger>,
graffiti: Graffiti,
beacon_graffiti: GraffitiOrigin,
slasher: Option<Arc<Slasher<T::EthSpec>>>,
// Pending I/O batch that is constructed during building and should be executed atomically
// alongside `PersistedBeaconChain` storage when `BeaconChainBuilder::build` is called.
Expand Down Expand Up @@ -139,7 +140,7 @@ where
spec: E::default_spec(),
chain_config: ChainConfig::default(),
log: None,
graffiti: Graffiti::default(),
beacon_graffiti: GraffitiOrigin::default(),
slasher: None,
pending_io_batch: vec![],
kzg: None,
Expand Down Expand Up @@ -649,9 +650,9 @@ where
self
}

/// Sets the `graffiti` field.
pub fn graffiti(mut self, graffiti: Graffiti) -> Self {
self.graffiti = graffiti;
/// Sets the `beacon_graffiti` field.
pub fn beacon_graffiti(mut self, beacon_graffiti: GraffitiOrigin) -> Self {
self.beacon_graffiti = beacon_graffiti;
self
}

Expand Down Expand Up @@ -920,7 +921,7 @@ where
observed_attester_slashings: <_>::default(),
observed_bls_to_execution_changes: <_>::default(),
eth1_chain: self.eth1_chain,
execution_layer: self.execution_layer,
execution_layer: self.execution_layer.clone(),
genesis_validators_root,
genesis_time,
canonical_head,
Expand Down Expand Up @@ -953,7 +954,12 @@ where
.shutdown_sender
.ok_or("Cannot build without a shutdown sender.")?,
log: log.clone(),
graffiti: self.graffiti,
graffiti_calculator: GraffitiCalculator::new(
self.beacon_graffiti,
self.execution_layer,
slot_clock.slot_duration() * E::slots_per_epoch() as u32,
log.clone(),
),
slasher: self.slasher.clone(),
validator_monitor: RwLock::new(validator_monitor),
genesis_backfill_slot,
Expand Down
Loading
Loading