From 40ccade5ccb2853f3bebd4556aa1e5b9ae98c52a Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 17 Jun 2020 01:32:16 +0900 Subject: [PATCH] Update to rust 1.44.0 (#10585) * Update rust 1.44.0 * Update rust nightly 1.46.0 * Update docs * Fix clippy errors * Compile all source code with stable and nightly * Add another note * script tweaks * Fix a test... * Add another workaround * Add hack * Increase timeout... * Revert "Add hack" This reverts commit 5960f087203be8792ec0728a6755288c317a2788. * Revert "Add another workaround" This reverts commit e14300d01ffd1b8e86e676662177545549b45c13. * Require nightly rustfmt and use older nightly a bit * Improve document a bit * Revert now not-existing clippy check... --- bench-tps/src/main.rs | 2 +- ci/docker-run.sh | 6 ++++++ ci/docker-rust-nightly/Dockerfile | 3 ++- ci/docker-rust-nightly/README.md | 10 +++++++--- ci/docker-rust/Dockerfile | 2 +- ci/docker-rust/README.md | 6 +++++- ci/rust-version.sh | 4 ++-- ci/test-checks.sh | 7 +++++-- ci/test-coverage.sh | 6 +++++- multinode-demo/validator.sh | 2 +- sdk/src/timing.rs | 10 ++++++---- 11 files changed, 41 insertions(+), 17 deletions(-) diff --git a/bench-tps/src/main.rs b/bench-tps/src/main.rs index 15632cb50..6b77d6306 100644 --- a/bench-tps/src/main.rs +++ b/bench-tps/src/main.rs @@ -115,7 +115,7 @@ fn main() { // Sort keypairs so that do_bench_tps() uses the same subset of accounts for each run. // This prevents the amount of storage needed for bench-tps accounts from creeping up // across multiple runs. - keypairs.sort_by(|x, y| x.pubkey().to_string().cmp(&y.pubkey().to_string())); + keypairs.sort_by_key(|x| x.pubkey().to_string()); (keypairs, None) } else { generate_and_fund_keypairs( diff --git a/ci/docker-run.sh b/ci/docker-run.sh index d62026be4..fb6f96329 100755 --- a/ci/docker-run.sh +++ b/ci/docker-run.sh @@ -60,6 +60,12 @@ if [[ -z "$SOLANA_DOCKER_RUN_NOSETUID" ]]; then ARGS+=(--user "$(id -u):$(id -g)") fi +if [[ -n $SOLANA_ALLOCATE_TTY ]]; then + # Colored output, progress bar and Ctrl-C: + # https://stackoverflow.com/a/41099052/10242004 + ARGS+=(--interactive --tty) +fi + # Environment variables to propagate into the container ARGS+=( --env BUILDKITE diff --git a/ci/docker-rust-nightly/Dockerfile b/ci/docker-rust-nightly/Dockerfile index 889ebdcca..f616c663c 100644 --- a/ci/docker-rust-nightly/Dockerfile +++ b/ci/docker-rust-nightly/Dockerfile @@ -1,9 +1,10 @@ -FROM solanalabs/rust:1.43.0 +FROM solanalabs/rust:1.44.0 ARG date RUN set -x \ && rustup install nightly-$date \ && rustup component add clippy --toolchain=nightly-$date \ + && rustup component add rustfmt --toolchain=nightly-$date \ && rustup show \ && rustc --version \ && cargo --version \ diff --git a/ci/docker-rust-nightly/README.md b/ci/docker-rust-nightly/README.md index 1f3bdc945..63f8c2875 100644 --- a/ci/docker-rust-nightly/README.md +++ b/ci/docker-rust-nightly/README.md @@ -2,23 +2,27 @@ Docker image containing rust nightly and some preinstalled crates used in CI. This image may be manually updated by running `CI=true ./build.sh` if you are a member of the [Solana Labs](https://hub.docker.com/u/solanalabs/) Docker Hub -organization, but it is also automatically updated periodically by -[this automation](https://buildkite.com/solana-labs/solana-ci-docker-rust-nightly). +organization. ## Moving to a newer nightly +NOTE: Follow instructions in docker-rust/README.md before this when updating the stable +rust version as well. + We pin the version of nightly (see the `ARG nightly=xyz` line in `Dockerfile`) to avoid the build breaking at unexpected times, as occasionally nightly will introduce breaking changes. To update the pinned version: +1. Edit `Dockerfile` to match the desired stable rust version to base on if needed. 1. Run `ci/docker-rust-nightly/build.sh` to rebuild the nightly image locally, or potentially `ci/docker-rust-nightly/build.sh YYYY-MM-DD` if there's a specific YYYY-MM-DD that is desired (default is today's build). Check https://rust-lang.github.io/rustup-components-history/ for build status 1. Update `ci/rust-version.sh` to reflect the new nightly `YYY-MM-DD` -1. Run `SOLANA_DOCKER_RUN_NOSETUID=1 ci/docker-run.sh --nopull solanalabs/rust-nightly:YYYY-MM-DD ci/test-coverage.sh` +1. Run `SOLANA_ALLOCATE_TTY=1 SOLANA_DOCKER_RUN_NOSETUID=1 ci/docker-run.sh --nopull solanalabs/rust-nightly:YYYY-MM-DD ci/test-checks.sh` + and `SOLANA_ALLOCATE_TTY=1 SOLANA_DOCKER_RUN_NOSETUID=1 ci/docker-run.sh --nopull solanalabs/rust-nightly:YYYY-MM-DD ci/test-coverage.sh [args]...` to confirm the new nightly image builds. Fix any issues as needed 1. Run `docker login` to enable pushing images to Docker Hub, if you're authorized. 1. Run `CI=true ci/docker-rust-nightly/build.sh YYYY-MM-DD` to push the new nightly image to dockerhub.com. diff --git a/ci/docker-rust/Dockerfile b/ci/docker-rust/Dockerfile index 3514cef20..64d2a794c 100644 --- a/ci/docker-rust/Dockerfile +++ b/ci/docker-rust/Dockerfile @@ -1,6 +1,6 @@ # Note: when the rust version is changed also modify # ci/rust-version.sh to pick up the new image tag -FROM rust:1.43.0 +FROM rust:1.44.0 # Add Google Protocol Buffers for Libra's metrics library. ENV PROTOC_VERSION 3.8.0 diff --git a/ci/docker-rust/README.md b/ci/docker-rust/README.md index 62a6a3d94..3984a6490 100644 --- a/ci/docker-rust/README.md +++ b/ci/docker-rust/README.md @@ -1,7 +1,11 @@ Docker image containing rust and some preinstalled packages used in CI. +NOTE: Recreate rust-nightly docker image after this when updating the stable rust +version! Both of docker images must be updated in tandem. + This image manually maintained: 1. Edit `Dockerfile` to match the desired rust version -2. Run `./build.sh` to publish the new image, if you are a member of the [Solana +1. Run `docker login` to enable pushing images to Docker Hub, if you're authorized. +1. Run `./build.sh` to publish the new image, if you are a member of the [Solana Labs](https://hub.docker.com/u/solanalabs/) Docker Hub organization. diff --git a/ci/rust-version.sh b/ci/rust-version.sh index 54582c095..f3a0e1a2a 100644 --- a/ci/rust-version.sh +++ b/ci/rust-version.sh @@ -18,13 +18,13 @@ if [[ -n $RUST_STABLE_VERSION ]]; then stable_version="$RUST_STABLE_VERSION" else - stable_version=1.43.0 + stable_version=1.44.0 fi if [[ -n $RUST_NIGHTLY_VERSION ]]; then nightly_version="$RUST_NIGHTLY_VERSION" else - nightly_version=2020-04-23 + nightly_version=2020-06-10 fi diff --git a/ci/test-checks.sh b/ci/test-checks.sh index 8fbd41dc8..f917912e3 100755 --- a/ci/test-checks.sh +++ b/ci/test-checks.sh @@ -28,14 +28,17 @@ echo --- build environment export RUST_BACKTRACE=1 export RUSTFLAGS="-D warnings" -if _ scripts/cargo-for-all-lock-files.sh +"$rust_nightly" check --locked --all-targets; then +# Exclude --benches as it's not available in rust stable yet +if _ scripts/cargo-for-all-lock-files.sh +"$rust_stable" check --locked --tests --bins --examples; then true else check_status=$? - echo "Some Cargo.lock is outdated; please update them as well" + echo "Some Cargo.lock might be outdated; update them (or just be a compilation error?)" echo "protip: you can use ./scripts/cargo-for-all-lock-files.sh [check|update] ..." exit "$check_status" fi +# Ensure nightly and --benches +_ scripts/cargo-for-all-lock-files.sh +"$rust_nightly" check --locked --all-targets _ ci/order-crates-for-publishing.py _ cargo +"$rust_stable" fmt --all -- --check diff --git a/ci/test-coverage.sh b/ci/test-coverage.sh index 360fbb645..89dc8c7f0 100755 --- a/ci/test-coverage.sh +++ b/ci/test-coverage.sh @@ -11,7 +11,11 @@ annotate() { source ci/upload-ci-artifact.sh source scripts/ulimit-n.sh -scripts/coverage.sh +scripts/coverage.sh "$@" + +if [[ -z $CI ]]; then + exit +fi report=coverage-"${CI_COMMIT:0:9}".tar.gz mv target/cov/report.tar.gz "$report" diff --git a/multinode-demo/validator.sh b/multinode-demo/validator.sh index 222815ec6..b9b156635 100755 --- a/multinode-demo/validator.sh +++ b/multinode-demo/validator.sh @@ -285,7 +285,7 @@ setup_validator_accounts() { return 0 } -rpc_url=$($solana_gossip rpc-url --entrypoint "$gossip_entrypoint") +rpc_url=$($solana_gossip rpc-url --timeout 180 --entrypoint "$gossip_entrypoint") [[ -r "$identity" ]] || $solana_keygen new --no-passphrase -so "$identity" [[ -r "$vote_account" ]] || $solana_keygen new --no-passphrase -so "$vote_account" diff --git a/sdk/src/timing.rs b/sdk/src/timing.rs index de717facb..17625382e 100644 --- a/sdk/src/timing.rs +++ b/sdk/src/timing.rs @@ -40,10 +40,12 @@ pub fn years_as_slots(years: f64, tick_duration: &Duration, ticks_per_slot: u64) /// From slots per year to slot duration pub fn slot_duration_from_slots_per_year(slots_per_year: f64) -> Duration { - // Regarding division by zero potential below: for some reason, if Rust stores an `inf` f64 and - // then converts it to a u64 on use, it always returns 0, as opposed to std::u64::MAX or any - // other huge value - let slot_in_ns = (SECONDS_PER_YEAR * 1_000_000_000.0) / slots_per_year; + // Recently, rust changed from infinity as usize being zero to 2^64-1; ensure it's zero here + let slot_in_ns = if slots_per_year != 0.0 { + (SECONDS_PER_YEAR * 1_000_000_000.0) / slots_per_year + } else { + 0.0 + }; Duration::from_nanos(slot_in_ns as u64) }