## Issue Addressed
NA
## Proposed Changes
- Moves the git-based versioning we were doing into the `lighthouse_version` crate in `common`.
- Removes the `beacon_node/version` crate, replacing it with `lighthouse_version`.
- Bumps the version to `v0.2.0`.
## Additional Info
There are now two types of version string:
1. `const VERSION: &str = Lighthouse/v0.2.0-1419501f2+`
1. `version_with_platform() = Lighthouse/v0.2.0-1419501f2+/x86_64-linux`
(1) is handy cause it's a `const` and shorter. (2) has platform info so it's more useful. Note that the plus-sign (`+`) indicates the the git commit is dirty (it used to be `(modified)` but I had to shorten it to fit into graffiti).
These version strings are now included on:
- `lighthouse --version`
- `lcli --version`
- `curl localhost:5052/node/version`
- p2p messages when we communicate our version
You can update the version by changing this constant (version is not related to a `Cargo.toml`):
b9ad7102d5/common/lighthouse_version/src/lib.rs (L4-L15)
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
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<Body>) -> ApiResult {
|
|
ResponseBuilder::new(&req)?.body_no_ssz(&version_with_platform())
|
|
}
|
|
|
|
pub fn syncing<T: EthSpec>(
|
|
req: Request<Body>,
|
|
network: Arc<NetworkGlobals<T>>,
|
|
current_slot: Slot,
|
|
) -> ApiResult {
|
|
let (starting_slot, highest_slot) = match network.sync_state() {
|
|
SyncState::SyncingFinalized {
|
|
start_slot,
|
|
head_slot,
|
|
..
|
|
}
|
|
| SyncState::SyncingHead {
|
|
start_slot,
|
|
head_slot,
|
|
} => (start_slot, head_slot),
|
|
SyncState::Synced | SyncState::Stalled => (Slot::from(0u64), current_slot),
|
|
};
|
|
|
|
let sync_status = SyncingStatus {
|
|
starting_slot,
|
|
current_slot,
|
|
highest_slot,
|
|
};
|
|
|
|
ResponseBuilder::new(&req)?.body(&SyncingResponse {
|
|
is_syncing: network.is_syncing(),
|
|
sync_status,
|
|
})
|
|
}
|
|
|
|
pub fn get_health(req: Request<Body>) -> ApiResult {
|
|
let health = Health::observe().map_err(ApiError::ServerError)?;
|
|
|
|
ResponseBuilder::new(&req)?.body_no_ssz(&health)
|
|
}
|