Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 0 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ int_to_bytes = { workspace = true }
itertools = { workspace = true }
kzg = { workspace = true }
lighthouse_tracing = { workspace = true }
lighthouse_version = { workspace = true }
logging = { workspace = true }
lru = { workspace = true }
merkle_proof = { workspace = true }
Expand Down Expand Up @@ -73,6 +72,7 @@ zstd = { workspace = true }

[dev-dependencies]
criterion = { workspace = true }
lighthouse_version = { workspace = true }
maplit = { workspace = true }
mockall = { workspace = true }
mockall_double = { workspace = true }
Expand Down
9 changes: 9 additions & 0 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub struct BeaconChainBuilder<T: BeaconChainTypes> {
spec: Arc<ChainSpec>,
chain_config: ChainConfig,
beacon_graffiti: GraffitiOrigin,
commit_prefix: String,
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,6 +140,7 @@ where
spec: Arc::new(E::default_spec()),
chain_config: ChainConfig::default(),
beacon_graffiti: GraffitiOrigin::default(),
commit_prefix: String::new(),
slasher: None,
pending_io_batch: vec![],
kzg,
Expand Down Expand Up @@ -709,6 +711,12 @@ where
self
}

/// Sets the `commit_prefix` field used by the graffiti calculator.
pub fn commit_prefix(mut self, commit_prefix: String) -> Self {
self.commit_prefix = commit_prefix;
self
}

/// Sets the `ChainConfig` that determines `BeaconChain` runtime behaviour.
pub fn chain_config(mut self, config: ChainConfig) -> Self {
self.chain_config = config;
Expand Down Expand Up @@ -1040,6 +1048,7 @@ where
self.beacon_graffiti,
self.execution_layer,
slot_clock.slot_duration() * E::slots_per_epoch() as u32,
self.commit_prefix,
),
slasher: self.slasher.clone(),
validator_monitor: RwLock::new(validator_monitor),
Expand Down
30 changes: 19 additions & 11 deletions beacon_node/beacon_chain/src/graffiti_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ impl GraffitiOrigin {

impl Default for GraffitiOrigin {
fn default() -> Self {
let version_bytes = lighthouse_version::VERSION.as_bytes();
Self::from_version(concat!("Lighthouse/v", env!("CARGO_PKG_VERSION")))
}
}

impl GraffitiOrigin {
pub fn from_version(version: &str) -> Self {
let version_bytes = version.as_bytes();
let trimmed_len = std::cmp::min(version_bytes.len(), GRAFFITI_BYTES_LEN);
let mut bytes = [0u8; GRAFFITI_BYTES_LEN];
bytes[..trimmed_len].copy_from_slice(&version_bytes[..trimmed_len]);
Expand Down Expand Up @@ -72,18 +78,21 @@ pub struct GraffitiCalculator<T: BeaconChainTypes> {
pub beacon_graffiti: GraffitiOrigin,
execution_layer: Option<ExecutionLayer<T::EthSpec>>,
pub epoch_duration: Duration,
commit_prefix: String,
}

impl<T: BeaconChainTypes> GraffitiCalculator<T> {
pub fn new(
beacon_graffiti: GraffitiOrigin,
execution_layer: Option<ExecutionLayer<T::EthSpec>>,
epoch_duration: Duration,
commit_prefix: String,
) -> Self {
Self {
beacon_graffiti,
execution_layer,
epoch_duration,
commit_prefix,
}
}

Expand Down Expand Up @@ -150,16 +159,15 @@ impl<T: BeaconChainTypes> GraffitiCalculator<T> {
return default_graffiti;
}

let lighthouse_commit_prefix =
CommitPrefix::try_from(lighthouse_version::COMMIT_PREFIX.to_string())
.unwrap_or_else(|error_message| {
// This really shouldn't happen but we want to definitly log if it does
crit!(
error = error_message,
"Failed to parse lighthouse commit prefix"
);
CommitPrefix("00000000".to_string())
});
let lighthouse_commit_prefix = CommitPrefix::try_from(self.commit_prefix.clone())
.unwrap_or_else(|error_message| {
// This really shouldn't happen but we want to definitly log if it does
crit!(
error = error_message,
"Failed to parse lighthouse commit prefix"
);
CommitPrefix("00000000".to_string())
});

engine_version.calculate_graffiti(lighthouse_commit_prefix, validator_graffiti)
}
Expand Down
1 change: 0 additions & 1 deletion beacon_node/builder_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ bls = { workspace = true }
context_deserialize = { workspace = true }
eth2 = { workspace = true }
ethereum_ssz = { workspace = true }
lighthouse_version = { workspace = true }
reqwest = { workspace = true }
sensitive_url = { workspace = true }
serde = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/builder_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub const DEFAULT_TIMEOUT_MILLIS: u64 = 15000;
pub const DEFAULT_GET_HEADER_TIMEOUT_MILLIS: u64 = 1000;

/// Default user agent for HTTP requests.
pub const DEFAULT_USER_AGENT: &str = lighthouse_version::VERSION;
pub const DEFAULT_USER_AGENT: &str = concat!("Lighthouse/v", env!("CARGO_PKG_VERSION"));

/// The value we set on the `ACCEPT` http header to indicate a preference for ssz response.
pub const PREFERENCE_ACCEPT_VALUE: &str = "application/octet-stream;q=1.0,application/json;q=0.9";
Expand Down
19 changes: 17 additions & 2 deletions beacon_node/client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::config::{ClientGenesis, Config as ClientConfig};
use crate::notifier::spawn_notifier;
use beacon_chain::attestation_simulator::start_attestation_simulator_service;
use beacon_chain::data_availability_checker::start_availability_cache_maintenance_service;
use beacon_chain::graffiti_calculator::start_engine_version_cache_refresh_service;
use beacon_chain::graffiti_calculator::{
GraffitiOrigin, start_engine_version_cache_refresh_service,
};
use beacon_chain::proposer_prep_service::start_proposer_prep_service;
use beacon_chain::schema_change::migrate_schema;
use beacon_chain::{
Expand Down Expand Up @@ -90,6 +92,7 @@ pub struct ClientBuilder<T: BeaconChainTypes> {
beacon_processor_channels: Option<BeaconProcessorChannels<T::EthSpec>>,
light_client_server_rv: Option<Receiver<LightClientProducerEvent<T::EthSpec>>>,
eth_spec_instance: T::EthSpec,
version_with_platform: String,
}

impl<TSlotClock, E, THotStore, TColdStore>
Expand Down Expand Up @@ -123,6 +126,7 @@ where
beacon_processor_config: None,
beacon_processor_channels: None,
light_client_server_rv: None,
version_with_platform: String::new(),
}
}

Expand Down Expand Up @@ -158,12 +162,20 @@ where
config: ClientConfig,
node_id: [u8; 32],
) -> Result<Self, String> {
self.version_with_platform = config.version_with_platform.clone();

let store = self.store.clone();
let chain_spec = self.chain_spec.clone();
let runtime_context = self.runtime_context.clone();
let eth_spec_instance = self.eth_spec_instance.clone();
let chain_config = config.chain.clone();
let beacon_graffiti = config.beacon_graffiti;
let beacon_graffiti = if matches!(config.beacon_graffiti, GraffitiOrigin::Calculated(_))
&& !config.version.is_empty()
{
GraffitiOrigin::from_version(&config.version)
} else {
config.beacon_graffiti
};

let store = store.ok_or("beacon_chain_start_method requires a store")?;
let runtime_context =
Expand Down Expand Up @@ -208,6 +220,7 @@ where
)
.chain_config(chain_config)
.beacon_graffiti(beacon_graffiti)
.commit_prefix(config.commit_prefix.clone())
.event_handler(event_handler)
.execution_layer(execution_layer)
.node_custody_type(config.chain.node_custody_type)
Expand Down Expand Up @@ -639,6 +652,7 @@ where
network_globals: self.network_globals.clone(),
beacon_processor_send: Some(beacon_processor_channels.beacon_processor_tx.clone()),
sse_logging_components: runtime_context.sse_logging_components.clone(),
version: self.version_with_platform.clone(),
});

let exit = runtime_context.executor.exit();
Expand Down Expand Up @@ -669,6 +683,7 @@ where
db_path: self.db_path.clone(),
freezer_db_path: self.freezer_db_path.clone(),
gossipsub_registry: self.libp2p_registry.take().map(std::sync::Mutex::new),
version: self.version_with_platform.clone(),
});

let exit = runtime_context.executor.exit();
Expand Down
12 changes: 12 additions & 0 deletions beacon_node/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ pub enum ClientGenesis {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
data_dir: PathBuf,
/// Version string (e.g. "Lighthouse/v5.0.0-abc12345/x86_64-linux"). Set by the binary.
#[serde(skip)]
pub version: String,
/// Version with platform info for identifying this node in HTTP headers.
#[serde(skip)]
pub version_with_platform: String,
/// First 8 chars of the git commit hash.
#[serde(skip)]
pub commit_prefix: String,
/// Name of the directory inside the data directory where the main "hot" DB is located.
pub db_name: String,
/// Path where the freezer database will be located.
Expand Down Expand Up @@ -85,6 +94,9 @@ impl Default for Config {
fn default() -> Self {
Self {
data_dir: PathBuf::from(DEFAULT_ROOT_DIR),
version: String::new(),
version_with_platform: String::new(),
commit_prefix: String::new(),
db_name: "chain_db".to_string(),
freezer_db_path: None,
blobs_db_path: None,
Expand Down
1 change: 0 additions & 1 deletion beacon_node/execution_layer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ hex = { workspace = true }
jsonwebtoken = "9"
keccak-hash = "0.10.0"
kzg = { workspace = true }
lighthouse_version = { workspace = true }
logging = { workspace = true }
lru = { workspace = true }
metrics = { workspace = true }
Expand Down
Loading
Loading