diff --git a/Cargo.lock b/Cargo.lock index 84301144a..327e3b009 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -424,6 +424,7 @@ dependencies = [ "futures 0.3.5", "genesis", "hyper 0.13.7", + "lighthouse_version", "logging", "node_test_rig", "rand 0.7.3", @@ -434,7 +435,6 @@ dependencies = [ "store", "tokio 0.2.22", "types", - "version", ] [[package]] @@ -1546,6 +1546,7 @@ dependencies = [ "lazy_static", "libp2p", "lighthouse_metrics", + "lighthouse_version", "lru", "parking_lot 0.11.0", "rand 0.7.3", @@ -1565,7 +1566,6 @@ dependencies = [ "tokio-util", "types", "unsigned-varint 0.3.3 (git+https://github.com/sigp/unsigned-varint?branch=latest-codecs)", - "version", "void", ] @@ -2591,6 +2591,7 @@ dependencies = [ "futures 0.3.5", "genesis", "hex 0.4.2", + "lighthouse_version", "log 0.4.11", "rand 0.7.3", "regex", @@ -2990,7 +2991,7 @@ dependencies = [ "environment", "eth2_testnet_config", "futures 0.3.5", - "git-version", + "lighthouse_version", "logging", "slog", "slog-async", @@ -3011,6 +3012,14 @@ dependencies = [ "prometheus", ] +[[package]] +name = "lighthouse_version" +version = "0.1.0" +dependencies = [ + "git-version", + "target_info", +] + [[package]] name = "linked-hash-map" version = "0.5.3" @@ -4342,6 +4351,7 @@ dependencies = [ "itertools 0.9.0", "lazy_static", "lighthouse_metrics", + "lighthouse_version", "network", "node_test_rig", "operation_pool", @@ -4363,7 +4373,6 @@ dependencies = [ "types", "uhttp_sse", "url 2.1.1", - "version", ] [[package]] @@ -6179,13 +6188,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" -[[package]] -name = "version" -version = "0.1.2" -dependencies = [ - "target_info", -] - [[package]] name = "version_check" version = "0.1.5" diff --git a/Cargo.toml b/Cargo.toml index df882251f..35fd77d44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ members = [ "beacon_node/rest_api", "beacon_node/store", "beacon_node/timer", - "beacon_node/version", "beacon_node/websocket_server", "boot_node", @@ -27,6 +26,7 @@ members = [ "common/eth2_wallet_manager", "common/hashset_delay", "common/lighthouse_metrics", + "common/lighthouse_version", "common/logging", "common/remote_beacon_node", "common/rest_types", diff --git a/beacon_node/Cargo.toml b/beacon_node/Cargo.toml index b9f8e8f36..ae795f0b6 100644 --- a/beacon_node/Cargo.toml +++ b/beacon_node/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "beacon_node" version = "0.1.2" -authors = ["Paul Hauner ", "Age Manning ", "Sigma Prime "] edition = "2018" [lib] @@ -20,7 +20,6 @@ beacon_chain = { path = "beacon_chain" } types = { path = "../consensus/types" } store = { path = "./store" } client = { path = "client" } -version = { path = "version" } clap = "2.33.0" rand = "0.7.3" slog = { version = "2.5.2", features = ["max_level_trace", "release_max_level_trace"] } @@ -40,3 +39,4 @@ eth2_ssz = "0.1.2" serde = "1.0.110" clap_utils = { path = "../common/clap_utils" } hyper = "0.13.5" +lighthouse_version = { path = "../common/lighthouse_version" } diff --git a/beacon_node/beacon_chain/Cargo.toml b/beacon_node/beacon_chain/Cargo.toml index 154da4f1e..24db773a9 100644 --- a/beacon_node/beacon_chain/Cargo.toml +++ b/beacon_node/beacon_chain/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "beacon_chain" version = "0.1.2" -authors = ["Paul Hauner ", "Age Manning "] +authors = ["Paul Hauner "] edition = "2018" [features] diff --git a/beacon_node/eth2_libp2p/Cargo.toml b/beacon_node/eth2_libp2p/Cargo.toml index 402e76961..8a7b67e17 100644 --- a/beacon_node/eth2_libp2p/Cargo.toml +++ b/beacon_node/eth2_libp2p/Cargo.toml @@ -14,7 +14,7 @@ serde_derive = "1.0.110" eth2_ssz = "0.1.2" eth2_ssz_derive = "0.1.0" slog = { version = "2.5.2", features = ["max_level_trace"] } -version = { path = "../version" } +lighthouse_version = { path = "../../common/lighthouse_version" } tokio = { version = "0.2.21", features = ["time", "macros"] } futures = "0.3.5" error-chain = "0.12.2" diff --git a/beacon_node/eth2_libp2p/src/behaviour/mod.rs b/beacon_node/eth2_libp2p/src/behaviour/mod.rs index d5f0ab84c..adf391e0c 100644 --- a/beacon_node/eth2_libp2p/src/behaviour/mod.rs +++ b/beacon_node/eth2_libp2p/src/behaviour/mod.rs @@ -77,7 +77,7 @@ impl Behaviour { let identify = Identify::new( "lighthouse/libp2p".into(), - version::version(), + lighthouse_version::version_with_platform(), local_key.public(), ); diff --git a/beacon_node/eth2_libp2p/src/config.rs b/beacon_node/eth2_libp2p/src/config.rs index 4cc66d332..288fff227 100644 --- a/beacon_node/eth2_libp2p/src/config.rs +++ b/beacon_node/eth2_libp2p/src/config.rs @@ -131,7 +131,7 @@ impl Default for Config { discv5_config, boot_nodes: vec![], libp2p_nodes: vec![], - client_version: version::version(), + client_version: lighthouse_version::version_with_platform(), disable_discovery: false, topics, } diff --git a/beacon_node/rest_api/Cargo.toml b/beacon_node/rest_api/Cargo.toml index 78a9208c8..364454adb 100644 --- a/beacon_node/rest_api/Cargo.toml +++ b/beacon_node/rest_api/Cargo.toml @@ -12,7 +12,6 @@ beacon_chain = { path = "../beacon_chain" } network = { path = "../network" } eth2_libp2p = { path = "../eth2_libp2p" } store = { path = "../store" } -version = { path = "../version" } serde = { version = "1.0.110", features = ["derive"] } serde_json = "1.0.52" serde_yaml = "0.8.11" @@ -40,6 +39,7 @@ environment = { path = "../../lighthouse/environment" } uhttp_sse = "0.5.1" bus = "2.2.3" itertools = "0.9.0" +lighthouse_version = { path = "../../common/lighthouse_version" } [dev-dependencies] assert_matches = "1.3.0" diff --git a/beacon_node/rest_api/src/node.rs b/beacon_node/rest_api/src/node.rs index c9b2cad33..e779bb090 100644 --- a/beacon_node/rest_api/src/node.rs +++ b/beacon_node/rest_api/src/node.rs @@ -2,13 +2,14 @@ use crate::response_builder::ResponseBuilder; use crate::{ApiError, ApiResult}; use eth2_libp2p::{types::SyncState, NetworkGlobals}; use hyper::{Body, Request}; +use lighthouse_version::version_with_platform; use rest_types::{Health, SyncingResponse, SyncingStatus}; use std::sync::Arc; use types::{EthSpec, Slot}; /// Read the version string from the current Lighthouse build. pub fn get_version(req: Request) -> ApiResult { - ResponseBuilder::new(&req)?.body_no_ssz(&version::version()) + ResponseBuilder::new(&req)?.body_no_ssz(&version_with_platform()) } pub fn syncing( diff --git a/beacon_node/rest_api/tests/test.rs b/beacon_node/rest_api/tests/test.rs index 7ec81ffba..d5bda936b 100644 --- a/beacon_node/rest_api/tests/test.rs +++ b/beacon_node/rest_api/tests/test.rs @@ -24,7 +24,6 @@ use types::{ RelativeEpoch, Signature, SignedAggregateAndProof, SignedBeaconBlock, SignedRoot, Slot, SubnetId, Validator, }; -use version; type E = MinimalEthSpec; @@ -764,7 +763,11 @@ fn get_version() { .block_on(remote_node.http.node().get_version()) .expect("should fetch eth2 config from http api"); - assert_eq!(version::version(), version, "result should be as expected"); + assert_eq!( + lighthouse_version::version_with_platform(), + version, + "result should be as expected" + ); } #[test] diff --git a/beacon_node/src/cli.rs b/beacon_node/src/cli.rs index 588ce25cd..0bd1e4da2 100644 --- a/beacon_node/src/cli.rs +++ b/beacon_node/src/cli.rs @@ -1,11 +1,5 @@ use clap::{App, Arg}; -// Default text included in blocks. -// Must be 32-bytes or will not build. -// -// |-------must be this long------| -const DEFAULT_GRAFFITI: &str = "sigp/lighthouse-0.1.2-prerelease"; - pub fn cli_app<'a, 'b>() -> App<'a, 'b> { App::new("beacon_node") .visible_aliases(&["b", "bn", "beacon"]) @@ -248,9 +242,11 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> { .arg( Arg::with_name("graffiti") .long("graffiti") - .help("Specify your custom graffiti to be included in blocks.") + .help( + "Specify your custom graffiti to be included in blocks. \ + Defaults to the current version and commit, truncated to fit in 32 bytes. " + ) .value_name("GRAFFITI") - .default_value(DEFAULT_GRAFFITI) .takes_value(true) ) } diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 5bfe8d93b..c917d572f 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -6,6 +6,7 @@ use eth2_libp2p::{Enr, Multiaddr}; use eth2_testnet_config::Eth2TestnetConfig; use slog::{crit, info, Logger}; use ssz::Encode; +use std::cmp; use std::fs; use std::net::{IpAddr, Ipv4Addr, ToSocketAddrs}; use std::net::{TcpListener, UdpSocket}; @@ -350,21 +351,22 @@ pub fn get_config( client_config.genesis = ClientGenesis::DepositContract; } - if let Some(graffiti) = cli_args.value_of("graffiti") { - let graffiti_bytes = graffiti.as_bytes(); - if graffiti_bytes.len() > GRAFFITI_BYTES_LEN { + let raw_graffiti = if let Some(graffiti) = cli_args.value_of("graffiti") { + if graffiti.len() > GRAFFITI_BYTES_LEN { return Err(format!( "Your graffiti is too long! {} bytes maximum!", GRAFFITI_BYTES_LEN )); - } else { - // `client_config.graffiti` is initialized by default to be all 0. - // We simply copy the bytes from `graffiti_bytes` in there. - // - // Panic-free because `graffiti_bytes.len()` <= `GRAFFITI_BYTES_LEN`. - client_config.graffiti[..graffiti_bytes.len()].copy_from_slice(graffiti_bytes); } - } + + graffiti.as_bytes() + } else { + lighthouse_version::VERSION.as_bytes() + }; + + let trimmed_graffiti_len = cmp::min(raw_graffiti.len(), GRAFFITI_BYTES_LEN); + client_config.graffiti[..trimmed_graffiti_len] + .copy_from_slice(&raw_graffiti[..trimmed_graffiti_len]); Ok(client_config) } diff --git a/beacon_node/version/Cargo.toml b/beacon_node/version/Cargo.toml deleted file mode 100644 index 4aec692c6..000000000 --- a/beacon_node/version/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "version" -version = "0.1.2" -authors = ["Sigma Prime "] -edition = "2018" - -[dependencies] -target_info = "0.1.0" diff --git a/beacon_node/version/src/lib.rs b/beacon_node/version/src/lib.rs deleted file mode 100644 index 3dcd57bef..000000000 --- a/beacon_node/version/src/lib.rs +++ /dev/null @@ -1,25 +0,0 @@ -//TODO: Build the version and hash of the built lighthouse binary - -/// Version information for the Lighthouse beacon node. -// currently only supports unstable release -extern crate target_info; - -use target_info::Target; - -const TRACK: &str = "unstable"; - -/// Provides the current platform -pub fn platform() -> String { - format!("{}-{}", Target::arch(), Target::os()) -} - -/// Version of the beacon node. -// TODO: Find the sha3 hash, date and rust version used to build the beacon_node binary -pub fn version() -> String { - format!( - "Lighthouse/v{}-{}/{}", - env!("CARGO_PKG_VERSION"), - TRACK, - platform() - ) -} diff --git a/common/lighthouse_version/Cargo.toml b/common/lighthouse_version/Cargo.toml new file mode 100644 index 000000000..a9778787a --- /dev/null +++ b/common/lighthouse_version/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "lighthouse_version" +version = "0.1.0" +authors = ["Paul Hauner "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +git-version = "0.3.4" +target_info = "0.1.0" diff --git a/common/lighthouse_version/src/lib.rs b/common/lighthouse_version/src/lib.rs new file mode 100644 index 000000000..3be1edbd0 --- /dev/null +++ b/common/lighthouse_version/src/lib.rs @@ -0,0 +1,24 @@ +use git_version::git_version; +use target_info::Target; + +/// Returns the current version of this build of Lighthouse. +/// +/// A plus-sign (`+`) is appended to the git commit if the tree is dirty. +/// +/// ## Example +/// +/// `Lighthouse/v0.2.0-1419501f2+` +pub const VERSION: &str = git_version!( + args = ["--always", "--dirty=+"], + prefix = "Lighthouse/v0.2.0/", + fallback = "unknown" +); + +/// Returns `VERSION`, but with platform information appended to the end. +/// +/// ## Example +/// +/// `Lighthouse/v0.2.0-1419501f2+/x86_64-linux` +pub fn version_with_platform() -> String { + format!("{}/{}-{}", VERSION, Target::arch(), Target::os()) +} diff --git a/lcli/Cargo.toml b/lcli/Cargo.toml index d6335f4d2..0b86cb5f2 100644 --- a/lcli/Cargo.toml +++ b/lcli/Cargo.toml @@ -34,3 +34,4 @@ eth2_libp2p = { path = "../beacon_node/eth2_libp2p" } validator_dir = { path = "../common/validator_dir", features = ["insecure_keys"] } rand = "0.7.2" eth2_keystore = { path = "../crypto/eth2_keystore" } +lighthouse_version = { path = "../common/lighthouse_version" } diff --git a/lcli/src/main.rs b/lcli/src/main.rs index 3a396a20a..4ae720d88 100644 --- a/lcli/src/main.rs +++ b/lcli/src/main.rs @@ -1,6 +1,5 @@ #[macro_use] extern crate log; - mod change_genesis_time; mod check_deposit_data; mod deploy_deposit_contract; @@ -29,6 +28,7 @@ fn main() { simple_logger::init_with_level(Level::Info).expect("logger should initialize"); let matches = App::new("Lighthouse CLI Tool") + .version(lighthouse_version::VERSION) .about( "Performs various testing-related tasks, including defining testnets.", ) diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index 660630866..5f8ba3b28 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -31,7 +31,7 @@ validator_client = { "path" = "../validator_client" } account_manager = { "path" = "../account_manager" } clap_utils = { path = "../common/clap_utils" } eth2_testnet_config = { path = "../common/eth2_testnet_config" } -git-version = "0.3.4" +lighthouse_version = { path = "../common/lighthouse_version" } [dev-dependencies] tempfile = "3.1.0" diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index d7091e0db..aeb545664 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -1,23 +1,15 @@ -#[macro_use] -extern crate clap; - use beacon_node::ProductionBeaconNode; use clap::{App, Arg, ArgMatches}; use env_logger::{Builder, Env}; use environment::EnvironmentBuilder; use eth2_testnet_config::{Eth2TestnetConfig, DEFAULT_HARDCODED_TESTNET}; -use git_version::git_version; +use lighthouse_version::VERSION; use slog::{crit, info, warn}; use std::path::PathBuf; use std::process::exit; use types::EthSpec; use validator_client::ProductionValidatorClient; -pub const VERSION: &str = git_version!( - args = ["--always", "--dirty=(modified)"], - prefix = concat!(crate_version!(), "-"), - fallback = crate_version!() -); pub const DEFAULT_DATA_DIR: &str = ".lighthouse"; pub const ETH2_CONFIG_FILENAME: &str = "eth2-spec.toml";