diff --git a/Cargo.lock b/Cargo.lock index 47621472bc..d6f205b2e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3298,6 +3298,7 @@ dependencies = [ "slog-json", "slog-term", "time 0.2.27", + "toml", "winapi 0.3.9", ] diff --git a/docs/release-process.md b/docs/release-process.md index b96d3d2beb..3d7d32545c 100644 --- a/docs/release-process.md +++ b/docs/release-process.md @@ -64,10 +64,11 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to - Add cherry-picked commits to the `feat/X.Y.Z.A.n-pr_number` branch - Merge `feat/X.Y.Z.A.n-pr_number` into `release/X.Y.Z.A.n`. -4. Open a PR to update the [CHANGELOG](../CHANGELOG.md) file in the `release/X.Y.Z.A.n` branch. +4. Open a PR to update the [CHANGELOG](../CHANGELOG.md) in the `release/X.Y.Z.A.n` branch. - Create a chore branch from `release/X.Y.Z.A.n`, ex: `chore/X.Y.Z.A.n-changelog`. - Add summaries of all Pull Requests to the `Added`, `Changed` and `Fixed` sections. + - Update the `stacks_node_version` string in [versions.toml](../versions.toml) to match this release. - Pull requests merged into `develop` can be found [here](https://github.com/stacks-network/stacks-core/pulls?q=is%3Apr+is%3Aclosed+base%3Adevelop+sort%3Aupdated-desc). diff --git a/libsigner/src/libsigner.rs b/libsigner/src/libsigner.rs index b1b760af6d..2eb0fa850a 100644 --- a/libsigner/src/libsigner.rs +++ b/libsigner/src/libsigner.rs @@ -53,6 +53,7 @@ use blockstack_lib::version_string; use clarity::codec::StacksMessageCodec; use clarity::vm::types::QualifiedContractIdentifier; use lazy_static::lazy_static; +use stacks_common::versions::STACKS_SIGNER_VERSION; pub use crate::error::{EventError, RPCError}; pub use crate::events::{ @@ -80,7 +81,16 @@ pub trait SignerMessage: StacksMessageCodec { lazy_static! { /// The version string for the signer pub static ref VERSION_STRING: String = { - let pkg_version = option_env!("STACKS_NODE_VERSION").unwrap_or(env!("CARGO_PKG_VERSION")); + let pkg_version = option_env!("STACKS_NODE_VERSION").or(Some(STACKS_SIGNER_VERSION)); version_string("stacks-signer", pkg_version) }; } + +#[test] +fn test_version_string() { + let version = VERSION_STRING.to_string(); + assert_eq!( + version.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str()), + true + ); +} diff --git a/stacks-common/Cargo.toml b/stacks-common/Cargo.toml index 81b4326d4c..661b61be29 100644 --- a/stacks-common/Cargo.toml +++ b/stacks-common/Cargo.toml @@ -12,6 +12,7 @@ keywords = [ "stacks", "stx", "bitcoin", "crypto", "blockstack", "decentralized" readme = "README.md" resolver = "2" edition = "2021" +build = "build.rs" [lib] name = "stacks_common" @@ -79,6 +80,9 @@ bech32_std = [] bech32_strict = [] strason = [] +[build-dependencies] +toml = "0.5.6" + [target.'cfg(all(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"), not(any(target_os="windows"))))'.dependencies] sha2 = { version = "0.10", features = ["asm"] } diff --git a/stacks-common/build.rs b/stacks-common/build.rs new file mode 100644 index 0000000000..00db6c24db --- /dev/null +++ b/stacks-common/build.rs @@ -0,0 +1,43 @@ +use std::path::Path; +use std::{env, fs}; + +use toml::Value; + +fn main() { + let toml_content = + fs::read_to_string("../versions.toml").expect("Failed to read versions.toml"); + + let config: Value = toml::from_str(&toml_content).expect("Failed to parse TOML"); + + let mut rust_code = String::from("// Auto-generated code from versions.toml\n\n"); + + match config { + Value::Table(table) => { + for (key, val) in table { + match val { + Value::String(s) => { + let const_value = format!("\"{}\"", s); + rust_code.push_str(&format!( + "pub const {}: &str = {};\n", + key.to_uppercase(), + const_value + )); + } + _ => { + panic!("Invalid value type in versions.toml: {:?}", val); + } + }; + } + } + _ => { + panic!("Invalid value type in versions.toml: {:?}", config); + } + } + + let out_dir = env::var_os("OUT_DIR").unwrap(); + let dest_path = Path::new(&out_dir).join("versions.rs"); + fs::write(&dest_path, rust_code).expect("Failed to write generated code"); + + // Tell Cargo to rerun this script if the TOML file changes + println!("cargo:rerun-if-changed=../versions.toml"); +} diff --git a/stacks-common/src/libcommon.rs b/stacks-common/src/libcommon.rs index 04c3acc1ea..853176455d 100644 --- a/stacks-common/src/libcommon.rs +++ b/stacks-common/src/libcommon.rs @@ -99,6 +99,10 @@ pub mod consts { pub const MICROSTACKS_PER_STACKS: u32 = 1_000_000; } +pub mod versions { + include!(concat!(env!("OUT_DIR"), "/versions.rs")); +} + /// This test asserts that the constant above doesn't change. /// This exists because the constant above is used by Epoch 2.5 instantiation code. /// diff --git a/stacks-signer/release-process.md b/stacks-signer/release-process.md index 71d47a3e26..54bebafad0 100644 --- a/stacks-signer/release-process.md +++ b/stacks-signer/release-process.md @@ -63,10 +63,11 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to - Add cherry-picked commits to the `feat/signer-X.Y.Z.A.n.x-pr_number` branch - Merge `feat/signer-X.Y.Z.A.n.x-pr_number` into `release/signer-X.Y.Z.A.n.x`. -4. Open a PR to update the [CHANGELOG](./CHANGELOG.md) file in the `release/signer-X.Y.Z.A.n.x` branch. +4. Open a PR to update the [CHANGELOG](./CHANGELOG.md) in the `release/signer-X.Y.Z.A.n.x` branch. - Create a chore branch from `release/signer-X.Y.Z.A.n.x`, ex: `chore/signer-X.Y.Z.A.n.x-changelog`. - Add summaries of all Pull Requests to the `Added`, `Changed` and `Fixed` sections. + - Update the `stacks_signer_version` string in [versions.toml](../versions.toml) to match this release. - Pull requests merged into `develop` can be found [here](https://github.com/stacks-network/stacks-core/pulls?q=is%3Apr+is%3Aclosed+base%3Adevelop+sort%3Aupdated-desc). diff --git a/stackslib/src/lib.rs b/stackslib/src/lib.rs index 190ef8a1f0..a9eb1b2aa5 100644 --- a/stackslib/src/lib.rs +++ b/stackslib/src/lib.rs @@ -45,6 +45,7 @@ extern crate stacks_common; #[macro_use] pub extern crate clarity; +use stacks_common::versions::STACKS_NODE_VERSION; pub use stacks_common::{address, codec, types, util}; #[macro_use] @@ -79,7 +80,8 @@ const BUILD_TYPE: &'static str = "debug"; #[cfg(not(debug_assertions))] const BUILD_TYPE: &'static str = "release"; -pub fn version_string(pkg_name: &str, pkg_version: &str) -> String { +pub fn version_string(pkg_name: &str, pkg_version: Option<&str>) -> String { + let pkg_version = pkg_version.unwrap_or(STACKS_NODE_VERSION); let git_branch = GIT_BRANCH .map(|x| format!("{}", x)) .unwrap_or("".to_string()); diff --git a/stackslib/src/main.rs b/stackslib/src/main.rs index 76a9d63c21..ccb7e79103 100644 --- a/stackslib/src/main.rs +++ b/stackslib/src/main.rs @@ -316,7 +316,7 @@ fn main() { "{}", &blockstack_lib::version_string( option_env!("CARGO_PKG_NAME").unwrap_or(&argv[0]), - option_env!("CARGO_PKG_VERSION").unwrap_or("0.0.0.0") + option_env!("STACKS_NODE_VERSION") ) ); process::exit(0); diff --git a/stackslib/src/net/api/getinfo.rs b/stackslib/src/net/api/getinfo.rs index d95b94803a..02251480f6 100644 --- a/stackslib/src/net/api/getinfo.rs +++ b/stackslib/src/net/api/getinfo.rs @@ -111,12 +111,7 @@ impl RPCPeerInfoData { coinbase_height: u64, ibd: bool, ) -> RPCPeerInfoData { - let server_version = version_string( - "stacks-node", - option_env!("STACKS_NODE_VERSION") - .or(option_env!("CARGO_PKG_VERSION")) - .unwrap_or("0.0.0.0"), - ); + let server_version = version_string("stacks-node", option_env!("STACKS_NODE_VERSION")); let (unconfirmed_tip, unconfirmed_seq) = match chainstate.unconfirmed_state { Some(ref unconfirmed) => { if unconfirmed.num_mined_txs() > 0 { diff --git a/stackslib/src/net/api/getstxtransfercost.rs b/stackslib/src/net/api/getstxtransfercost.rs index 78e6e66851..c8675e2867 100644 --- a/stackslib/src/net/api/getstxtransfercost.rs +++ b/stackslib/src/net/api/getstxtransfercost.rs @@ -42,7 +42,6 @@ use crate::net::httpcore::{ }; use crate::net::p2p::PeerNetwork; use crate::net::{Error as NetError, HttpServerError, StacksNodeState}; -use crate::version_string; pub(crate) const SINGLESIG_TX_TRANSFER_LEN: u64 = 180; diff --git a/testnet/stacks-node/src/main.rs b/testnet/stacks-node/src/main.rs index 7916de9d00..f44f384fd2 100644 --- a/testnet/stacks-node/src/main.rs +++ b/testnet/stacks-node/src/main.rs @@ -433,12 +433,7 @@ fn main() { } fn version() -> String { - stacks::version_string( - "stacks-node", - option_env!("STACKS_NODE_VERSION") - .or(option_env!("CARGO_PKG_VERSION")) - .unwrap_or("0.0.0.0"), - ) + stacks::version_string("stacks-node", option_env!("STACKS_NODE_VERSION")) } fn print_help() { @@ -456,7 +451,7 @@ SUBCOMMANDS: mainnet\t\tStart a node that will join and stream blocks from the public mainnet. -mocknet\t\tStart a node based on a fast local setup emulating a burnchain. Ideal for smart contract development. +mocknet\t\tStart a node based on a fast local setup emulating a burnchain. Ideal for smart contract development. helium\t\tStart a node based on a local setup relying on a local instance of bitcoind. \t\tThe following bitcoin.conf is expected: diff --git a/testnet/stacks-node/src/neon_node.rs b/testnet/stacks-node/src/neon_node.rs index 2d4dc7fadd..2dcd534a19 100644 --- a/testnet/stacks-node/src/neon_node.rs +++ b/testnet/stacks-node/src/neon_node.rs @@ -2213,12 +2213,7 @@ impl BlockMinerThread { /// Only used in mock signing to generate a peer info view fn generate_peer_info(&self) -> PeerInfo { // Create a peer info view of the current state - let server_version = version_string( - "stacks-node", - option_env!("STACKS_NODE_VERSION") - .or(option_env!("CARGO_PKG_VERSION")) - .unwrap_or("0.0.0.0"), - ); + let server_version = version_string("stacks-node", option_env!("STACKS_NODE_VERSION")); let stacks_tip_height = self.burn_block.canonical_stacks_tip_height; let stacks_tip = self.burn_block.canonical_stacks_tip_hash; let stacks_tip_consensus_hash = self.burn_block.canonical_stacks_tip_consensus_hash; diff --git a/versions.toml b/versions.toml new file mode 100644 index 0000000000..3e8150cc95 --- /dev/null +++ b/versions.toml @@ -0,0 +1,4 @@ +# Update these values when a new release is created. +# `stacks-common/build.rs` will automatically update `versions.rs` with these values. +stacks_node_version = "3.1.0.0.2" +stacks_signer_version = "3.1.0.0.2.0"