Skip to content

Commit

Permalink
- make ocv rust image less cluttered
Browse files Browse the repository at this point in the history
- add GH workflow for rust pr checks

- cargofmt: fix formatting

- add crate caching

- change deprecated fmt option
  • Loading branch information
simisimis committed Dec 20, 2024
1 parent 5f792de commit 76d2d33
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 16 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/check-rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: PR checks for rust server backend

on:
pull_request:

concurrency:
group: '${{ github.workflow }} @ ${{ github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
changed-files:
name: Check changes for rust server app
runs-on: minafoundation-default-interruptible-runners
steps:
- name: 📥 Checkout
uses: actions/checkout@v4
- uses: tj-actions/changed-files@v39
id: changed
with:
files_yaml: |
server:
- 'server/**'
write_output_files: true
outputs:
modified_keys: ${{ steps.changed.outputs.modified_keys }}
rust-checks:
env:
CARGO_TERM_COLOR: always
needs: changed-files
if: needs.changed-files.outputs.modified_keys != '[]' && needs.changed-files.outputs.modified_keys != ''
name: Rust PR Checks
runs-on: minafoundation-default-interruptible-runners
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal
- uses: Swatinem/rust-cache@v2
with:
workspaces: ./server
- name: ✍️ Check formatting
run: cargo fmt --all -- --check
working-directory: ./server
- name: 🧐 Check linting
run: cargo clippy -- -D warnings -D clippy::unwrap_used
working-directory: ./server
- name: 🏗️ Build the app
run: cargo build --release
working-directory: ./server
- name: 📋 Run the tests
run: cargo test --locked --all-features --all-targets
working-directory: ./server
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: minafoundation-default-runners
steps:
- name: 📥 Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: 🦀 Get on-chain-voting server version from Cargo.toml.
id: ocv-server
uses: dante-signal31/[email protected]
Expand Down Expand Up @@ -56,8 +56,8 @@ jobs:
runs-on: minafoundation-default-runners
steps:
- name: 📥 Checkout
uses: actions/checkout@v3
- name: 🦀 Get on-chain-voting web version from package.json
uses: actions/checkout@v4
- name: 🇹🇸 Get on-chain-voting web version from package.json
id: ocv-web
uses: martinbeentjes/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ tab_spaces = 2
use_field_init_shorthand = true
use_small_heuristics = "Max"
use_try_shorthand = true
version = "Two"
style_edition = "2024"
wrap_comments = true
28 changes: 27 additions & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,31 @@ RUN cargo install diesel_cli --no-default-features --features postgres
COPY --chown=mina:mina . .
RUN cargo build --release

FROM debian:bullseye-slim
RUN apt-get update && \
apt-get install -y \
curl \
libpq5 \
libffi7 \
libgmp10 \
libkrb5-3 \
libidn2-0 \
libsasl2-2 \
libtasn1-6 \
libnettle8 \
libcom-err2 \
libgnutls30 \
libp11-kit0 \
libhogweed6 \
libk5crypto3 \
libkeyutils1 \
libldap-2.4-2 \
libunistring2 \
libkrb5support0 \
libgssapi-krb5-2 \
postgresql-client \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/mina_ocv /app
# start the server
CMD ["./target/release/mina_ocv"]
CMD ["./mina_ocv"]
9 changes: 3 additions & 6 deletions server/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Ledger {
Self::download(ocv, hash, &dest).await?;
}
let contents = fs::read(dest)?;
Ok(Ledger(serde_json::from_slice(&contents[..]).unwrap()))
Ok(Ledger(serde_json::from_slice(&contents[..]).expect("Expecting a valid list of ledger accounts.")))
}

async fn download(ocv: &Ocv, hash: &String, to: &PathBuf) -> Result<()> {
Expand All @@ -30,10 +30,7 @@ impl Ledger {
.await?
.contents
.and_then(|objects| {
objects
.into_iter()
.find(|object| object.key.as_ref().map_or(false, |key| key.contains(hash)))
.and_then(|x| x.key)
objects.into_iter().find(|object| object.key.as_ref().is_some_and(|key| key.contains(hash))).and_then(|x| x.key)
})
.ok_or(anyhow!("Could not retrieve dump corresponding to {hash}"))?;
let bytes =
Expand All @@ -42,7 +39,7 @@ impl Ledger {
let mut archive = Archive::new(tar_gz);
for entry in archive.entries()? {
let mut entry = entry?;
let path = entry.path()?.to_str().unwrap().to_owned();
let path = entry.path()?.to_str().expect("Expecting a valid path").to_owned();
if s3_path.contains(&path) {
let mut buffer = Vec::new();
entry.read_to_end(&mut buffer)?;
Expand Down
13 changes: 8 additions & 5 deletions server/src/ocv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,20 @@ impl Ocv {
///
/// # Arguments
///
/// * `total_positive_community_votes` - Total number of positive votes from the community.
/// * `total_negative_community_votes` - Total number of negative votes from the community.
/// * `total_positive_community_votes` - Total number of positive votes from
/// the community.
/// * `total_negative_community_votes` - Total number of negative votes from
/// the community.
///
/// # Returns
///
/// Returns `true` if the positive votes meet the threshold for the current release stage,
/// otherwise `false`.
/// Returns `true` if the positive votes meet the threshold for the current
/// release stage, otherwise `false`.
///
/// # Description
///
/// - For the `Production` release stage, the minimum threshold for positive votes is 10.
/// - For the `Production` release stage, the minimum threshold for positive
/// votes is 10.
/// - For other release stages, the threshold is 2.
pub fn has_met_vote_threshold(
&self,
Expand Down

0 comments on commit 76d2d33

Please sign in to comment.