Skip to content

Commit

Permalink
Merge pull request #3948 from Fraser999/version-bumps
Browse files Browse the repository at this point in the history
Version bumps
  • Loading branch information
Fraser999 authored May 10, 2023
2 parents 648d547 + 999ae37 commit 84f0643
Show file tree
Hide file tree
Showing 37 changed files with 569 additions and 477 deletions.
751 changes: 420 additions & 331 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions ci/casper_updater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
version = "0.3.0"

[dependencies]
casper-types = { path = "../../types" }
clap = "2"
once_cell = "1"
regex = "1"
clap = { version = "4.2.7", features = ["cargo", "deprecated", "wrap_help"] }
once_cell = "1.17.1"
regex = "1.8.1"
semver = "1.0.17"
20 changes: 8 additions & 12 deletions ci/casper_updater/src/chainspec.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use std::{
convert::TryFrom,
io::{self, Write},
};
use std::io::{self, Write};

use regex::Regex;

use casper_types::SemVer;
use semver::Version;

use crate::{package, regex_data};

Expand All @@ -15,7 +11,7 @@ const CAPTURE_INDEX: usize = 2;
/// updated.
pub struct Chainspec {
/// The current production protocol version.
current_protocol_version: SemVer,
current_protocol_version: Version,
/// The current production activation point.
current_activation_point: String,
}
Expand Down Expand Up @@ -50,8 +46,8 @@ impl Chainspec {

let protocol_version = find_value(&regex_data::chainspec_protocol_version::REGEX);
let current_activation_point = find_value(&regex_data::chainspec_activation_point::REGEX);
let current_protocol_version = SemVer::try_from(protocol_version.as_str())
.expect("should parse current protocol version");
let current_protocol_version =
Version::parse(&protocol_version).expect("should parse current protocol version");

Chainspec {
current_protocol_version,
Expand All @@ -66,7 +62,7 @@ impl Chainspec {
self.current_protocol_version
);
if let Some(bump_version) = crate::bump_version() {
let updated_protocol_version = bump_version.update(self.current_protocol_version);
let updated_protocol_version = bump_version.update(&self.current_protocol_version);
println!("Will be updated to {}", updated_protocol_version);
}
println!("Files affected by the protocol version:");
Expand Down Expand Up @@ -97,12 +93,12 @@ impl Chainspec {
let updated_protocol_version = match crate::bump_version() {
None => match package::get_updated_version_from_user(
"chainspec protocol",
self.current_protocol_version,
&self.current_protocol_version,
) {
Some(version) => version,
None => return,
},
Some(bump_version) => bump_version.update(self.current_protocol_version),
Some(bump_version) => bump_version.update(&self.current_protocol_version),
};

for dependent_file in &*regex_data::chainspec_protocol_version::DEPENDENT_FILES {
Expand Down
73 changes: 35 additions & 38 deletions ci/casper_updater/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,28 @@ use std::{
env,
path::{Path, PathBuf},
process::Command,
str::FromStr,
};

use clap::{crate_version, App, Arg};
use clap::{
builder::{PathBufValueParser, PossibleValue, RangedU64ValueParser},
crate_version, Arg, ArgAction, Command as App,
};
use once_cell::sync::Lazy;

use casper_types::SemVer;
use semver::Version;

use chainspec::Chainspec;
use package::Package;

const APP_NAME: &str = "Casper Updater";

const ROOT_DIR_ARG_NAME: &str = "root-dir";
const ROOT_DIR_ARG_SHORT: &str = "r";
const ROOT_DIR_ARG_SHORT: char = 'r';
const ROOT_DIR_ARG_VALUE_NAME: &str = "PATH";
const ROOT_DIR_ARG_HELP: &str =
"Path to casper-node root directory. If not supplied, assumes it is at ../..";

const BUMP_ARG_NAME: &str = "bump";
const BUMP_ARG_SHORT: &str = "b";
const BUMP_ARG_SHORT: char = 'b';
const BUMP_ARG_VALUE_NAME: &str = "VERSION-COMPONENT";
const BUMP_ARG_HELP: &str =
"Increases all crates' versions automatically without asking for user input. For a crate at \
Expand All @@ -72,14 +73,14 @@ const MINOR: &str = "minor";
const PATCH: &str = "patch";

const ACTIVATION_POINT_ARG_NAME: &str = "activation-point";
const ACTIVATION_POINT_ARG_SHORT: &str = "a";
const ACTIVATION_POINT_ARG_SHORT: char = 'a';
const ACTIVATION_POINT_ARG_VALUE_NAME: &str = "INTEGER";
const ACTIVATION_POINT_ARG_HELP: &str =
"Sets the activation point for the new version. If this option is specified, --bump must also \
be specified.";

const DRY_RUN_ARG_NAME: &str = "dry-run";
const DRY_RUN_ARG_SHORT: &str = "d";
const DRY_RUN_ARG_SHORT: char = 'd';
const DRY_RUN_ARG_HELP: &str = "Checks all regexes get matches in current casper-node repo";

const ALLOW_EARLIER_VERSION_NAME: &str = "allow-earlier-version";
Expand All @@ -93,11 +94,11 @@ pub(crate) enum BumpVersion {
}

impl BumpVersion {
pub(crate) fn update(self, current_version: SemVer) -> SemVer {
pub(crate) fn update(self, current_version: &Version) -> Version {
match self {
BumpVersion::Major => SemVer::new(current_version.major + 1, 0, 0),
BumpVersion::Minor => SemVer::new(current_version.major, current_version.minor + 1, 0),
BumpVersion::Patch => SemVer::new(
BumpVersion::Major => Version::new(current_version.major + 1, 0, 0),
BumpVersion::Minor => Version::new(current_version.major, current_version.minor + 1, 0),
BumpVersion::Patch => Version::new(
current_version.major,
current_version.minor,
current_version.patch + 1,
Expand Down Expand Up @@ -145,53 +146,52 @@ fn get_args() -> Args {
let arg_matches = App::new(APP_NAME)
.version(crate_version!())
.arg(
Arg::with_name(ROOT_DIR_ARG_NAME)
Arg::new(ROOT_DIR_ARG_NAME)
.long(ROOT_DIR_ARG_NAME)
.short(ROOT_DIR_ARG_SHORT)
.value_name(ROOT_DIR_ARG_VALUE_NAME)
.help(ROOT_DIR_ARG_HELP)
.takes_value(true),
.value_parser(PathBufValueParser::new()),
)
.arg(
Arg::with_name(BUMP_ARG_NAME)
Arg::new(BUMP_ARG_NAME)
.long(BUMP_ARG_NAME)
.short(BUMP_ARG_SHORT)
.value_name(BUMP_ARG_VALUE_NAME)
.help(BUMP_ARG_HELP)
.takes_value(true)
.possible_values(&[MAJOR, MINOR, PATCH])
.value_parser([
PossibleValue::new(MAJOR),
PossibleValue::new(MINOR),
PossibleValue::new(PATCH),
])
.requires(ACTIVATION_POINT_ARG_NAME),
)
.arg(
Arg::with_name(ACTIVATION_POINT_ARG_NAME)
Arg::new(ACTIVATION_POINT_ARG_NAME)
.long(ACTIVATION_POINT_ARG_NAME)
.short(ACTIVATION_POINT_ARG_SHORT)
.value_name(ACTIVATION_POINT_ARG_VALUE_NAME)
.help(ACTIVATION_POINT_ARG_HELP)
.takes_value(true)
.validator(|value| {
value
.parse::<u64>()
.map(drop)
.map_err(|error| error.to_string())
})
.value_parser(RangedU64ValueParser::<u64>::new())
.requires(BUMP_ARG_NAME),
)
.arg(
Arg::with_name(DRY_RUN_ARG_NAME)
Arg::new(DRY_RUN_ARG_NAME)
.long(DRY_RUN_ARG_NAME)
.short(DRY_RUN_ARG_SHORT)
.action(ArgAction::SetTrue)
.help(DRY_RUN_ARG_HELP),
)
.arg(
Arg::with_name(ALLOW_EARLIER_VERSION_NAME)
Arg::new(ALLOW_EARLIER_VERSION_NAME)
.long(ALLOW_EARLIER_VERSION_NAME)
.action(ArgAction::SetTrue)
.help(ALLOW_EARLIER_VERSION_HELP),
)
.get_matches();

let root_dir = match arg_matches.value_of(ROOT_DIR_ARG_NAME) {
Some(path) => PathBuf::from_str(path).expect("should be a valid unicode path"),
let root_dir = match arg_matches.get_one::<PathBuf>(ROOT_DIR_ARG_NAME) {
Some(path) => path.clone(),
None => env::current_dir()
.expect("should be able to access current working dir")
.parent()
Expand All @@ -202,24 +202,21 @@ fn get_args() -> Args {
};

let bump_version = arg_matches
.value_of(BUMP_ARG_NAME)
.map(|value| match value {
.get_one::<&str>(BUMP_ARG_NAME)
.map(|value| match *value {
MAJOR => BumpVersion::Major,
MINOR => BumpVersion::Minor,
PATCH => BumpVersion::Patch,
_ => unreachable!(),
});

let activation_point = arg_matches
.value_of(ACTIVATION_POINT_ARG_NAME)
.map(|value| {
// Safe to unwrap, as the arg is validated as being able to be parsed as a `u64`.
value.parse().unwrap()
});
.get_one::<u64>(ACTIVATION_POINT_ARG_NAME)
.copied();

let dry_run = arg_matches.is_present(DRY_RUN_ARG_NAME);
let dry_run = arg_matches.get_flag(DRY_RUN_ARG_NAME);

let allow_earlier_version = arg_matches.is_present(ALLOW_EARLIER_VERSION_NAME);
let allow_earlier_version = arg_matches.get_flag(ALLOW_EARLIER_VERSION_NAME);

Args {
root_dir,
Expand Down
22 changes: 10 additions & 12 deletions ci/casper_updater/src/package.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::{
convert::TryFrom,
io::{self, Write},
path::Path,
};

use regex::Regex;

use casper_types::SemVer;
use semver::Version;

use crate::{
dependent_file::DependentFile,
Expand All @@ -24,7 +22,7 @@ pub struct Package {
/// This package's name as specified in its manifest.
name: String,
/// This package's current version as specified in its manifest.
current_version: SemVer,
current_version: Version,
/// Files which must be updated if this package's version is changed, including this package's
/// own manifest file. The other files will often be from a different package.
dependent_files: &'static Vec<DependentFile>,
Expand Down Expand Up @@ -127,7 +125,7 @@ impl Package {

let name = find_value(T::name_regex());
let version = find_value(T::version_regex());
let current_version = SemVer::try_from(&*version).expect("should parse current version");
let current_version = Version::parse(&version).expect("should parse current version");

Package {
name,
Expand All @@ -143,7 +141,7 @@ impl Package {
self.name, self.current_version
);
if let Some(bump_version) = crate::bump_version() {
let updated_version = bump_version.update(self.current_version);
let updated_version = bump_version.update(&self.current_version);
println!("Will be updated to {}", updated_version);
}
println!("Files affected by this package's version:");
Expand All @@ -155,11 +153,11 @@ impl Package {
}

let updated_version = match crate::bump_version() {
None => match get_updated_version_from_user(&self.name, self.current_version) {
None => match get_updated_version_from_user(&self.name, &self.current_version) {
Some(version) => version,
None => return,
},
Some(bump_version) => bump_version.update(self.current_version),
Some(bump_version) => bump_version.update(&self.current_version),
};

for dependent_file in self.dependent_files {
Expand All @@ -173,7 +171,7 @@ impl Package {
}
}

pub fn get_updated_version_from_user(name: &str, current_version: SemVer) -> Option<SemVer> {
pub fn get_updated_version_from_user(name: &str, current_version: &Version) -> Option<Version> {
loop {
print!(
"Current {} version is {}. Enter new version (leave blank for unchanged): ",
Expand All @@ -188,15 +186,15 @@ pub fn get_updated_version_from_user(name: &str, current_version: SemVer) -> Opt
return None;
}

let new_version = match SemVer::try_from(&*input) {
let new_version = match Version::parse(&input) {
Ok(version) => version,
Err(error) => {
println!("\n{} is not a valid version: {}.", input, error);
continue;
}
};

if new_version < current_version {
if new_version < *current_version {
println!(
"Updated version ({}) is lower than current version ({})",
new_version, current_version
Expand All @@ -208,7 +206,7 @@ pub fn get_updated_version_from_user(name: &str, current_version: SemVer) -> Opt
}
}

return if new_version == current_version {
return if new_version == *current_version {
None
} else {
Some(new_version)
Expand Down
5 changes: 5 additions & 0 deletions ci/casper_updater/src/regex_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ pub mod types {

pub static DEPENDENT_FILES: Lazy<Vec<DependentFile>> = Lazy::new(|| {
vec![
DependentFile::new(
"hashing/Cargo.toml",
Regex::new(r#"(?m)(^casper-types = \{[^\}]*version = )"(?:[^"]+)"#).unwrap(),
replacement,
),
DependentFile::new(
"execution_engine/Cargo.toml",
Regex::new(r#"(?m)(^casper-types = \{[^\}]*version = )"(?:[^"]+)"#).unwrap(),
Expand Down
5 changes: 2 additions & 3 deletions execution_engine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file. The format
[comment]: <> (Security: in case of vulnerabilities)


## Unreleased
## 5.0.0

### Added
* Add a new entry point `redelegate` to the Auction system contract which allows users to redelegate to another validator without having to unbond. The function signature for the entrypoint is: `redelegate(delegator: PublicKey, validator: PublicKey, amount: U512, new_validator: PublicKey)`
Expand All @@ -21,9 +21,8 @@ All notable changes to this project will be documented in this file. The format
* Fix some integer casts.
* Change both genesis and upgrade functions to write `ChainspecRegistry` under the fixed `Key::ChainspecRegistry`.
* Lift the temporary limit of the size of individual values stored in global state.
* Lift the temporary limit of the global maximum delegator capacity.
* Providing incorrect Wasm for execution will cause the default 2.5CSPR to be charged.
* Update the default `control_flow` opcode cost from `440` to `440000`.
* Update the default `control_flow` opcode cost from `440` to `440_000`.



Expand Down
6 changes: 3 additions & 3 deletions execution_engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "casper-execution-engine"
version = "4.0.0" # when updating, also update 'html_root_url' in lib.rs
version = "5.0.0" # when updating, also update 'html_root_url' in lib.rs
authors = ["Henry Till <[email protected]>", "Ed Hastings <[email protected]>"]
edition = "2018"
description = "CasperLabs execution engine crates."
Expand All @@ -14,8 +14,8 @@ license = "Apache-2.0"
anyhow = "1.0.33"
base16 = "0.2.1"
bincode = "1.3.1"
casper-hashing = { version = "1.4.4", path = "../hashing" }
casper-types = { version = "2.0.0", path = "../types", default-features = false, features = ["datasize", "gens", "json-schema"] }
casper-hashing = { version = "2.0.0", path = "../hashing" }
casper-types = { version = "3.0.0", path = "../types", default-features = false, features = ["datasize", "gens", "json-schema"] }
casper-wasm-utils = "1.0.0"
datasize = "0.2.4"
either = "1.8.1"
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The engine which executes smart contracts on the Casper network.
#![doc(html_root_url = "https://docs.rs/casper-execution-engine/4.0.0")]
#![doc(html_root_url = "https://docs.rs/casper-execution-engine/5.0.0")]
#![doc(
html_favicon_url = "https://raw.githubusercontent.com/CasperLabs/casper-node/master/images/CasperLabs_Logo_Favicon_RGB_50px.png",
html_logo_url = "https://raw.githubusercontent.com/CasperLabs/casper-node/master/images/CasperLabs_Logo_Symbol_RGB.png",
Expand Down
Loading

0 comments on commit 84f0643

Please sign in to comment.