node: include git hash into user agent

This commit is contained in:
ardocrat
2026-05-02 20:55:32 +03:00
parent 95486a4bc0
commit 5bebacd605
6 changed files with 55 additions and 6 deletions
Generated
+1
View File
@@ -1110,6 +1110,7 @@ name = "grin_p2p"
version = "5.4.0"
dependencies = [
"bitflags 1.3.2",
"built",
"bytes 0.5.6",
"chrono",
"enum_primitive",
+3 -2
View File
@@ -95,7 +95,7 @@ impl Status {
Status {
chain: global::get_chain_type().shortname(),
protocol_version: ser::ProtocolVersion::local().into(),
user_agent: p2p::msg::USER_AGENT.to_string(),
user_agent: p2p::msg::user_agent().to_string(),
connections: connections,
tip: Tip::from_tip(current_tip),
sync_status,
@@ -465,7 +465,8 @@ impl<'de> serde::de::Deserialize<'de> for OutputPrintable {
}
if output_type.is_none()
|| commit.is_none() || spent.is_none()
|| commit.is_none()
|| spent.is_none()
|| proof_hash.is_none()
|| mmr_index.is_none()
{
+4
View File
@@ -8,6 +8,7 @@ repository = "https://github.com/mimblewimble/grin"
keywords = [ "crypto", "grin", "mimblewimble" ]
workspace = ".."
edition = "2018"
build = "src/build/build.rs"
[dependencies]
bitflags = "1"
@@ -29,3 +30,6 @@ grin_chain = { path = "../chain", version = "5.4.0" }
[dev-dependencies]
grin_pool = { path = "../pool", version = "5.4.0" }
[build-dependencies]
built = { version = "0.8.0", features = ["git2"]}
+28
View File
@@ -0,0 +1,28 @@
// Copyright 2026 The Grin Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Build hooks to spit out version info
use std::env;
use std::path::Path;
fn main() {
// build and versioning information
let out_dir_path = format!("{}{}", env::var("OUT_DIR").unwrap(), "/built.rs");
// don't fail the build if something's missing, may just be cargo release
let _ = built::write_built_file_with_opts(
Some(Path::new(env!("CARGO_MANIFEST_DIR"))),
Path::new(&out_dir_path),
);
}
+3 -3
View File
@@ -16,7 +16,7 @@ use crate::conn::Tracker;
use crate::core::core::hash::Hash;
use crate::core::pow::Difficulty;
use crate::core::ser::ProtocolVersion;
use crate::msg::{read_message, write_message, Hand, Msg, Shake, Type, USER_AGENT};
use crate::msg::{read_message, user_agent, write_message, Hand, Msg, Shake, Type};
use crate::peer::Peer;
use crate::types::{Capabilities, Direction, Error, P2PConfig, PeerAddr, PeerInfo, PeerLiveInfo};
use crate::util::RwLock;
@@ -120,7 +120,7 @@ impl Handshake {
total_difficulty,
sender_addr: self_addr,
receiver_addr: peer_addr,
user_agent: USER_AGENT.to_string(),
user_agent: user_agent().to_string(),
};
// write and read the handshake response
@@ -225,7 +225,7 @@ impl Handshake {
capabilities: capab,
genesis: self.genesis,
total_difficulty: total_difficulty,
user_agent: USER_AGENT.to_string(),
user_agent: user_agent().to_string(),
};
let msg = Msg::new(Type::Shake, shake, negotiated_version)?;
+16 -1
View File
@@ -40,8 +40,23 @@ use std::io::{Read, Write};
use std::sync::Arc;
use std::{fmt, thread, time::Duration};
// include build information
pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
fn version() -> &'static str {
built_info::GIT_COMMIT_HASH_SHORT.unwrap_or("+")
}
/// Grin's user agent with current version
pub const USER_AGENT: &str = concat!("MW/Grim ", env!("CARGO_PKG_VERSION"), "+");
pub fn user_agent() -> String {
format!(
"MW/Grim {}{}",
env!("CARGO_PKG_VERSION"),
built_info::GIT_COMMIT_HASH_SHORT.map_or_else(|| "+".to_owned(), |v| ".".to_owned() + v)
)
}
/// Magic numbers expected in the header of every message
const OTHER_MAGIC: [u8; 2] = [73, 43];