Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT - POC for managing version across binaries #5469

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions libsigner/src/libsigner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ use blockstack_lib::version_string;
use clarity::codec::StacksMessageCodec;
use clarity::vm::types::QualifiedContractIdentifier;
use lazy_static::lazy_static;
use stacks_common::util::versions::get_long_version;


pub use crate::error::{EventError, RPCError};
pub use crate::events::{
Expand Down Expand Up @@ -80,7 +82,6 @@ pub trait SignerMessage<T: MessageSlotID>: 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"));
version_string("stacks-signer", pkg_version)
get_long_version("stacks-signer")
};
}
34 changes: 28 additions & 6 deletions stacks-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
[package]
name = "stacks-common"
version = "0.0.1"
authors = [ "Jude Nelson <[email protected]>",
"Aaron Blankstein <[email protected]>",
"Ludo Galabru <[email protected]>" ]
authors = [
"Jude Nelson <[email protected]>",
"Aaron Blankstein <[email protected]>",
"Ludo Galabru <[email protected]>",
]
license = "GPLv3"
homepage = "https://github.com/blockstack/stacks-blockchain"
repository = "https://github.com/blockstack/stacks-blockchain"
description = "Common modules for blockstack_lib, libclarity"
keywords = [ "stacks", "stx", "bitcoin", "crypto", "blockstack", "decentralized", "dapps", "blockchain" ]
keywords = [
"stacks",
"stx",
"bitcoin",
"crypto",
"blockstack",
"decentralized",
"dapps",
"blockchain",
]
readme = "README.md"
resolver = "2"
edition = "2021"
Expand All @@ -22,23 +33,34 @@ rand = { workspace = true }
serde = "1"
serde_derive = "1"
serde_stacker = "0.1"
serde_yaml = "0.9"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need serde_yaml outside of build_dependencies

sha3 = "0.10.1"
ripemd = "0.1.1"
lazy_static = "1.4.0"
percent-encoding = "2.1.0"
slog = { version = "2.5.2", features = [ "max_level_trace" ] }
slog = { version = "2.5.2", features = ["max_level_trace"] }
slog-term = "2.6.0"
slog-json = { version = "2.3.0", optional = true }
chrono = "0.4.19"
libc = "0.2.82"
hashbrown = { workspace = true }
rusqlite = { workspace = true, optional = true }

[build-dependencies]
serde = "1"
serde_derive = "1"
serde_yaml = "0.9"

[target.'cfg(unix)'.dependencies]
nix = "0.23"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["consoleapi", "handleapi", "synchapi", "winbase"] }
winapi = { version = "0.3", features = [
"consoleapi",
"handleapi",
"synchapi",
"winbase",
] }

[target.'cfg(windows)'.dev-dependencies]
winapi = { version = "0.3", features = ["fileapi", "processenv", "winnt"] }
Expand Down
60 changes: 60 additions & 0 deletions stacks-common/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use serde_derive::Serialize;
use serde_derive::Deserialize;
use std::fs::File;
use std::io::Write;
use std::env;

#[derive(Serialize, Deserialize, Debug)]
struct Versions {
stacks_node: String,
stacks_signer: String,
blockstack_cli: String,
clarity_cli: String,
relay_server: String,
stacks_inspect: String,
}

// get Versions struct from versions.yaml
fn get_build_versions() -> Versions {
let file = File::open("versions.yaml").expect("Unable to open file");
let versions: Versions = serde_yaml::from_reader(file).expect("Unable to read file");
versions
}

// override build versions with environment variables if they exist otherwise use passed in Versions struct
fn set_build_versions() {

let mut versions = get_build_versions();

if let Ok(val) = env::var("STACKS_NODE_VERSION") {
versions.stacks_node = val;
}
if let Ok(val) = env::var("STACKS_SIGNER_VERSION") {
versions.stacks_signer = val;
}
if let Ok(val) = env::var("BLOCKSTACK_CLI_VERSION") {
versions.blockstack_cli = val;
}
if let Ok(val) = env::var("CLARITY_CLI_VERSION") {
versions.clarity_cli = val;
}
if let Ok(val) = env::var("RELAY_SERVER_VERSION") {
versions.relay_server = val;
}
if let Ok(val) = env::var("STACKS_INSPECT_VERSION") {
versions.stacks_inspect = val;
}
write_build_versions(&versions, "versions.yaml");
}



fn write_build_versions(versions: &Versions, path: &str) {
let yaml_string = serde_yaml::to_string(&versions).unwrap();
let mut file = File::create(path).expect("Unable to create file");
file.write_all(yaml_string.as_bytes()).expect("Unable to write data to path");
}

fn main() {
set_build_versions();
}
1 change: 1 addition & 0 deletions stacks-common/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod pipe;
pub mod retry;
pub mod secp256k1;
pub mod uint;
pub mod versions;
pub mod vrf;

use std::collections::HashMap;
Expand Down
82 changes: 82 additions & 0 deletions stacks-common/src/util/versions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use serde::Serialize;
use serde::Deserialize;
use std::fs::File;

#[derive(Serialize, Deserialize)]
struct Versions {
stacks_node: String,
stacks_signer: String,
blockstack_cli: String,
clarity_cli: String,
relay_server: String,
stacks_inspect: String,
}

pub fn get_build_version(binary: &str) -> String {
let versions = get_build_versions();
match binary {
"stacks-node" => versions.stacks_node,
"stacks-signer" => versions.stacks_signer,
"blockstack-cli" => versions.blockstack_cli,
"clarity-cli" => versions.clarity_cli,
"relay-server" => versions.relay_server,
"stacks-inspect" => versions.stacks_inspect,
_ => panic!("Binary not found"),
}
}

pub fn get_long_version(binary: &str) -> String {
let build_version = get_build_version(binary);
format!("{} ({}, {}, {})", build_version, get_target_build_type(), get_target_os(), get_target_arch())
}
Comment on lines +27 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have the version_string util, which includes the arch, build type, and also git info. I think we should keep that, as it's also a part of our CI process (ie setting the git info via ENV).


fn get_target_arch() -> String {
let architecture = if cfg!(target_arch = "x86") {
"x86"
}
else if cfg!(target_arch = "x86_64") {
"x86_64"
}
else if cfg!(target_arch = "arm") {
"ARM"
}
else if cfg!(target_arch = "aarch64") {
"AArch64"
}
else {
"unknown"
};
architecture.to_string()
}

fn get_target_os() -> String {
let os = if cfg!(target_os = "linux") {
"Linux"
}
else if cfg!(target_os = "macos") {
"macOS"
}
else if cfg!(target_os = "windows") {
"Windows"
}
else {
"unknown"
};
os.to_string()
}

fn get_target_build_type() -> String {
let build_type = if cfg!(debug_assertions) {
"Debug"
}
else {
"Release"
};
build_type.to_string()
}

fn get_build_versions() -> Versions {
let versions_content = include_str!("../../versions.yaml");
let versions: Versions = serde_yaml::from_str(versions_content).expect("Unable to read versions.yaml");
versions
}
6 changes: 6 additions & 0 deletions stacks-common/versions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
stacks_node: 3.0.0.0
stacks_signer: 3.0.0.0.2
blockstack_cli: 3.0.0.0.2
clarity_cli: 3.0.0.0.2
relay_server: 3.0.0.0.2
stacks_inspect: 3.0.0.0.2
5 changes: 5 additions & 0 deletions stacks-signer/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ pub struct MonitorSignersArgs {
pub max_age: u64,
}

#[derive(Parser, Debug, Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this already has a --version command in line 46

/// Arguments for the Version command
pub struct VersionArgs {
}

#[derive(Clone, Debug, PartialEq)]
/// Wrapper around `Pox4SignatureTopic` to implement `ValueEnum`
pub struct StackingSignatureMethod(Pox4SignatureTopic);
Expand Down
2 changes: 2 additions & 0 deletions stacks-signer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use libstackerdb::StackerDBChunkData;
use slog::{slog_debug, slog_error};
use stacks_common::util::hash::to_hex;
use stacks_common::util::secp256k1::MessageSignature;
use stacks_common::util::versions::get_build_version;
use stacks_common::{debug, error};
use stacks_signer::cli::{
Cli, Command, GenerateStackingSignatureArgs, GenerateVoteArgs, GetChunkArgs,
Expand Down Expand Up @@ -203,6 +204,7 @@ fn handle_monitor_signers(args: MonitorSignersArgs) {
}

fn main() {

let cli = Cli::parse();

tracing_subscriber::registry()
Expand Down