diff --git a/.github/workflows/test.yml b/.github/workflows/build_test.yml similarity index 84% rename from .github/workflows/test.yml rename to .github/workflows/build_test.yml index 84fc6908..86cf4945 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/build_test.yml @@ -2,6 +2,8 @@ name: Cargo Build & Test on: push: + branches: + - main pull_request: env: @@ -25,8 +27,6 @@ jobs: # The toolchain action should definitely be run before the cache action - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - # use toolchain version from rust-toolchain.toml - components: rustfmt, clippy cache: true # avoid the default "-D warnings" which thrashes cache rustflags: "" @@ -47,10 +47,5 @@ jobs: run: | cargo build --locked --workspace --all-targets - - name: Run fmt+clippy - run: | - cargo fmt --all --check - cargo clippy --locked --workspace --all-targets - - name: Run Tests run: RUST_LOG=info cargo test diff --git a/.github/workflows/clippy_test.yml b/.github/workflows/clippy_test.yml new file mode 100644 index 00000000..368c0636 --- /dev/null +++ b/.github/workflows/clippy_test.yml @@ -0,0 +1,52 @@ +name: Cargo Nightly Clippy + +on: + push: + branches: + - main + pull_request: + +env: + CARGO_TERM_COLOR: always + SCCACHE_GHA_ENABLED: true + RUSTC_WRAPPER: sccache + SCCACHE_CACHE_SIZE: "1G" + +jobs: + build_and_test: + name: lite-rpc full build + runs-on: ubuntu-22.04 + steps: + - name: Install Linux Packages + run: | + sudo apt-get update -y + sudo apt-get install libssl-dev openssl -y + + - uses: actions/checkout@v4 + + # The toolchain action should definitely be run before the cache action + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + # use toolchain version from rust-toolchain.toml + toolchain: nightly + components: rustfmt, clippy + cache: true + # avoid the default "-D warnings" which thrashes cache + rustflags: "" + + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.3 + + # https://github.com/actions/cache/blob/main/examples.md#rust---cargo + # https://blog.arriven.wtf/posts/rust-ci-cache/ + - uses: Swatinem/rust-cache@v2 + with: + # will be covered by sscache + cache-targets: false + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + + - name: Run fmt+clippy + run: | + cargo fmt --all --check + cargo clippy --locked --workspace --all-targets -- -D warnings diff --git a/.github/workflows/test_with_validator.yml b/.github/workflows/test_with_validator.yml index 1c074dbc..4fc48404 100644 --- a/.github/workflows/test_with_validator.yml +++ b/.github/workflows/test_with_validator.yml @@ -2,6 +2,8 @@ name: Integration Test with Validator on: push: + branches: + - main pull_request: env: diff --git a/ci/cargo-command.sh b/ci/cargo-command.sh new file mode 100755 index 00000000..567fb2b6 --- /dev/null +++ b/ci/cargo-command.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# Function to display help message +show_help() { + echo "Usage: $0 [stable|nightly] [command]" + echo + echo "This script is used to run a specified cargo command with either the stable or nightly Rust toolchain." + echo + echo "Arguments:" + echo " stable - Use the stable Rust toolchain." + echo " nightly - Use the nightly Rust toolchain." + echo " command - The cargo command to run (e.g., clippy, build)." + echo + echo "Examples:" + echo " $0 stable clippy - Run clippy with the stable Rust version." + echo " $0 nightly build - Build with the nightly Rust version." +} + +# Function to run a specified cargo command with a specified toolchain +run_cargo_command() { + local toolchain=$1 + local command=$2 + echo "Running cargo $command with Rust $toolchain version..." + cargo +"$toolchain" "$command" +} + +# Check if the first argument is -h or --help +if [[ $1 == "-h" || $1 == "--help" ]]; then + show_help + exit 0 +fi + +# Check if the second argument is not provided +if [[ -z $2 ]]; then + echo "Error: No command specified." + show_help + exit 1 +fi + +# Path to the rust-version.sh script +rust_version_script="./ci/rust-version.sh" + +# Check if rust-version.sh exists and is executable +if [[ -f "$rust_version_script" && -x "$rust_version_script" ]]; then + # Source the rust-version.sh script + source "$rust_version_script" +else + echo "Error: rust-version.sh not found or not executable." + exit 1 +fi + + +# Main execution logic based on passed arguments +case $1 in + stable) + # Check if Rust stable version is set + if [[ -z $rust_stable ]]; then + echo "Error: Rust stable version is not set." + exit 1 + fi + run_cargo_command "$rust_stable" "$2" + ;; + nightly) + # Check if Rust nightly version is set + if [[ -z $rust_nightly ]]; then + echo "Error: Rust nightly version is not set." + exit 1 + fi + run_cargo_command "$rust_nightly" "$2" + ;; + *) + echo "Usage: $0 [stable|nightly] [command]" + exit 1 + ;; +esac diff --git a/ci/rust-version.sh b/ci/rust-version.sh new file mode 100755 index 00000000..2cf88003 --- /dev/null +++ b/ci/rust-version.sh @@ -0,0 +1,62 @@ +readCargoVariable() { + declare variable="$1" + declare Cargo_toml="$2" + + while read -r name equals value _; do + if [[ $name = "$variable" && $equals = = ]]; then + echo "${value//\"/}" + return + fi + done < <(cat "$Cargo_toml") + echo "Unable to locate $variable in $Cargo_toml" 1>&2 +} + +if [[ -n $RUST_STABLE_VERSION ]]; then + stable_version="$RUST_STABLE_VERSION" +else + # read rust version from rust-toolchain.toml file + base="$(dirname "${BASH_SOURCE[0]}")" + stable_version=$(readCargoVariable channel "$base/../rust-toolchain.toml") +fi + +if [[ -n $RUST_NIGHTLY_VERSION ]]; then + nightly_version="$RUST_NIGHTLY_VERSION" +else + nightly_version=2023-11-16 +fi + +echo "stable_version: $stable_version" +echo "nightly_version: $nightly_version" + +export rust_stable="$stable_version" +export rust_nightly=nightly-"$nightly_version" + +[[ -z $1 ]] || ( + + rustup_install() { + declare toolchain=$1 + if ! cargo +"$toolchain" -V > /dev/null; then + echo "$0: Missing toolchain? Installing...: $toolchain" >&2 + rustup install "$toolchain" + cargo +"$toolchain" -V + fi + } + + set -e + cd "$(dirname "${BASH_SOURCE[0]}")" + case $1 in + stable) + rustup_install "$rust_stable" + ;; + nightly) + rustup_install "$rust_nightly" + ;; + all) + rustup_install "$rust_stable" + rustup_install "$rust_nightly" + ;; + *) + echo "$0: Note: ignoring unknown argument: $1" >&2 + ;; + esac +) diff --git a/cluster-endpoints/src/grpc_subscription.rs b/cluster-endpoints/src/grpc_subscription.rs index 33eacd2f..698954bd 100644 --- a/cluster-endpoints/src/grpc_subscription.rs +++ b/cluster-endpoints/src/grpc_subscription.rs @@ -370,8 +370,8 @@ pub fn create_grpc_subscription( let message = message?; let Some(update) = message.update_oneof else { - continue; - }; + continue; + }; match update { UpdateOneof::Slot(slot) => { diff --git a/core/src/structures/epoch.rs b/core/src/structures/epoch.rs index ff49a469..521d22ce 100644 --- a/core/src/structures/epoch.rs +++ b/core/src/structures/epoch.rs @@ -60,9 +60,11 @@ impl EpochCache { let res_epoch = rpc_client .get_account(&solana_sdk::sysvar::epoch_schedule::id()) .await?; - let Some(SysvarAccountType::EpochSchedule(epoch_schedule)) = bincode::deserialize(&res_epoch.data[..]) - .ok() - .map(SysvarAccountType::EpochSchedule) else { + let Some(SysvarAccountType::EpochSchedule(epoch_schedule)) = + bincode::deserialize(&res_epoch.data[..]) + .ok() + .map(SysvarAccountType::EpochSchedule) + else { bail!("Error during bootstrap epoch. SysvarAccountType::EpochSchedule can't be deserilized. Epoch can't be calculated."); }; diff --git a/history/src/block_stores/postgres_block_store.rs b/history/src/block_stores/postgres_block_store.rs index a45edc3b..003e49e4 100644 --- a/history/src/block_stores/postgres_block_store.rs +++ b/history/src/block_stores/postgres_block_store.rs @@ -88,9 +88,9 @@ impl BlockStorageInterface for PostgresBlockStore { Ok(()) } - async fn get(&self, slot: Slot, _config: RpcBlockConfig) -> Result { - let range = self.get_slot_range().await; - if range.contains(&slot) {} + async fn get(&self, _slot: Slot, _config: RpcBlockConfig) -> Result { + //let _range = self.get_slot_range().await; + //if range.contains(&slot) {} todo!() } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 22048ac5..8142c301 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.70.0" +channel = "1.73.0"