From 15f623ce9ff698ebd539474f476d4e754edf1f34 Mon Sep 17 00:00:00 2001 From: Serge Farny Date: Thu, 23 May 2024 15:16:55 +0200 Subject: [PATCH] Clients: log git commit info at start time (#965) (cherry picked from commit 53829cb6e5f45b89635703e85eea1978a7f55d0e) --- Cargo.lock | 28 ++++++++++++++++++++++++++-- bin/keeper/src/main.rs | 1 + bin/liquidator/src/main.rs | 1 + bin/settler/src/main.rs | 1 + lib/client/Cargo.toml | 5 +++++ lib/client/build.rs | 11 +++++++++++ lib/client/src/util.rs | 14 ++++++++++++++ 7 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 lib/client/build.rs diff --git a/Cargo.lock b/Cargo.lock index 7b423022e..5dc87d6cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -315,9 +315,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "arc-swap" @@ -3491,6 +3491,7 @@ dependencies = [ "tokio-tungstenite 0.17.2", "tracing", "tracing-subscriber", + "vergen", ] [[package]] @@ -4229,6 +4230,15 @@ dependencies = [ "syn 2.0.37", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "number_prefix" version = "0.4.0" @@ -8392,6 +8402,8 @@ checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" dependencies = [ "deranged", "itoa", + "libc", + "num_threads", "serde", "time-core", "time-macros", @@ -9277,6 +9289,18 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "vergen" +version = "8.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525" +dependencies = [ + "anyhow", + "cfg-if 1.0.0", + "rustversion", + "time 0.3.29", +] + [[package]] name = "version_check" version = "0.1.5" diff --git a/bin/keeper/src/main.rs b/bin/keeper/src/main.rs index ba1fc1085..4e778f0fd 100644 --- a/bin/keeper/src/main.rs +++ b/bin/keeper/src/main.rs @@ -89,6 +89,7 @@ enum Command { #[tokio::main] async fn main() -> Result<(), anyhow::Error> { mango_v4_client::tracing_subscriber_init(); + mango_v4_client::print_git_version(); let args = if let Ok(cli_dotenv) = CliDotenv::try_parse() { dotenv::from_path(cli_dotenv.dotenv)?; diff --git a/bin/liquidator/src/main.rs b/bin/liquidator/src/main.rs index 74b724f3e..42442cc6e 100644 --- a/bin/liquidator/src/main.rs +++ b/bin/liquidator/src/main.rs @@ -44,6 +44,7 @@ pub fn encode_address(addr: &Pubkey) -> String { #[tokio::main] async fn main() -> anyhow::Result<()> { mango_v4_client::tracing_subscriber_init(); + mango_v4_client::print_git_version(); let args: Vec = if let Ok(cli_dotenv) = CliDotenv::try_parse() { dotenv::from_path(cli_dotenv.dotenv)?; diff --git a/bin/settler/src/main.rs b/bin/settler/src/main.rs index d1be966c4..e32c37e1d 100644 --- a/bin/settler/src/main.rs +++ b/bin/settler/src/main.rs @@ -80,6 +80,7 @@ pub fn encode_address(addr: &Pubkey) -> String { #[tokio::main] async fn main() -> anyhow::Result<()> { mango_v4_client::tracing_subscriber_init(); + mango_v4_client::print_git_version(); let args = if let Ok(cli_dotenv) = CliDotenv::try_parse() { dotenv::from_path(cli_dotenv.dotenv)?; diff --git a/lib/client/Cargo.toml b/lib/client/Cargo.toml index b23dc9d15..268c7d800 100644 --- a/lib/client/Cargo.toml +++ b/lib/client/Cargo.toml @@ -2,10 +2,15 @@ name = "mango-v4-client" version = "0.3.0" edition = "2021" +build = "build.rs" [lib] doctest = false +[build-dependencies] +anyhow = "1.0" +vergen = { version = "8.3.1", features = ["git", "gitcl"] } + [dependencies] anchor-client = { workspace = true } anchor-lang = { workspace = true } diff --git a/lib/client/build.rs b/lib/client/build.rs new file mode 100644 index 000000000..d2cdb1dec --- /dev/null +++ b/lib/client/build.rs @@ -0,0 +1,11 @@ +use vergen::EmitBuilder; + +pub fn main() -> anyhow::Result<()> { + EmitBuilder::builder() + .git_sha(true) + .git_dirty(false) + .git_commit_date() + .emit()?; + + Ok(()) +} diff --git a/lib/client/src/util.rs b/lib/client/src/util.rs index f54d6cac9..45f68545a 100644 --- a/lib/client/src/util.rs +++ b/lib/client/src/util.rs @@ -3,6 +3,7 @@ use solana_sdk::instruction::Instruction; use anchor_lang::prelude::{AccountMeta, Pubkey}; use anyhow::Context; +use tracing::info; /// Some Result<> types don't convert to anyhow::Result nicely. Force them through stringification. pub trait AnyhowWrap { @@ -59,6 +60,19 @@ pub fn tracing_subscriber_init() { .init(); } +pub fn print_git_version() { + info!( + "version is {}[{}{}]", + env!("VERGEN_GIT_SHA"), + env!("VERGEN_GIT_COMMIT_DATE"), + if env!("VERGEN_GIT_DIRTY") == "true" { + "-dirty" + } else { + "" + } + ); +} + pub async fn http_error_handling( response: reqwest::Response, ) -> anyhow::Result {