Advertise node software version in gossip (#9981)

* Advertise node version in gossip

* Remove solana_clap_utils::version! macro
This commit is contained in:
Michael Vines
2020-05-11 15:02:01 -07:00
committed by GitHub
parent 965204b8e0
commit 2521f75c18
50 changed files with 223 additions and 66 deletions

2
version/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target/
/farf/

20
version/Cargo.toml Normal file
View File

@ -0,0 +1,20 @@
[package]
name = "solana-version"
version = "1.2.0"
description = "Solana Version"
authors = ["Solana Maintainers <maintainers@solana.com>"]
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
edition = "2018"
[dependencies]
serde = "1.0.110"
serde_derive = "1.0.103"
solana-sdk = { path = "../sdk", version = "1.2.0" }
[lib]
name = "solana_version"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

49
version/src/lib.rs Normal file
View File

@ -0,0 +1,49 @@
extern crate serde_derive;
use serde_derive::{Deserialize, Serialize};
use solana_sdk::sanitize::Sanitize;
use std::fmt;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Version {
major: u16,
minor: u16,
patch: u16,
commit: Option<u32>, // first 4 bytes of the sha1 commit hash
}
impl Default for Version {
fn default() -> Self {
Self {
major: env!("CARGO_PKG_VERSION_MAJOR").parse().unwrap(),
minor: env!("CARGO_PKG_VERSION_MINOR").parse().unwrap(),
patch: env!("CARGO_PKG_VERSION_PATCH").parse().unwrap(),
commit: option_env!("CI_COMMIT")
.map(|sha1| u32::from_str_radix(&sha1[..8], 16).unwrap()),
}
}
}
impl fmt::Display for Version {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}.{}.{} {}",
self.major,
self.minor,
self.patch,
match self.commit {
None => "devbuild".to_string(),
Some(commit) => format!("{:08x}", commit),
}
)
}
}
impl Sanitize for Version {}
#[macro_export]
macro_rules! version {
() => {
&*format!("{}", $crate::Version::default())
};
}