Skip to content

Init Mithril Client #110

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

Merged
merged 9 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
151 changes: 143 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
override: true

- uses: actions/cache@v2.1.5
name: Cache mithril-core/Cargo.toml
name: Cache mithril-core/Cargo.lock
with:
path: |
~/.cargo/registry
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
override: true

- uses: actions/cache@v2.1.5
name: Cache mithril-network/mithril-aggregator/Cargo.toml
name: Cache mithril-network/mithril-aggregator/Cargo.lock
with:
path: |
~/.cargo/registry
Expand Down Expand Up @@ -161,6 +161,68 @@ jobs:
with:
name: mithril-aggregator
path: mithril-network/mithril-aggregator/target/release/mithril-aggregator

build-mithril-client:
Copy link

Choose a reason for hiding this comment

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

Perhaps there's a way to have client and aggregator in the same project but as different exes or crates? That would speed things up and simplify build

Copy link
Member Author

Choose a reason for hiding this comment

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

It's possible to have multiple binary built in a src/bin configuration of the project: this would allow us to build all executable files in the same job.

We can investigate further to see if it is a wise architectural choice 🤔

Copy link

Choose a reason for hiding this comment

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

I agree that it introduces coupling between the client and the aggregator via the datatypes, and it can lead down the road to hard-to-change code and deep dependencies, if we are not cautious about more dependencies to creep in.

if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy, rustfmt
override: true

- uses: actions/cache@v2.1.5
name: Cache mithril-network/mithril-client/Cargo.toml
with:
path: |
~/.cargo/registry
~/.cargo/git
mithril-network/mithril-client/target
key: ${{ runner.os }}-${{ hashFiles('mithril-network/mithril-client/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-key

- name: Cargo build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --manifest-path ./mithril-network/mithril-client/Cargo.toml

- name: Cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --release --all-targets --manifest-path ./mithril-network/mithril-client/Cargo.toml

- name: Cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --manifest-path ./mithril-network/mithril-client/Cargo.toml -- --check

- name: Clippy Check
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --manifest-path ./mithril-network/mithril-client/Cargo.toml --all-features

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --release --manifest-path ./mithril-network/mithril-client/Cargo.toml

- name: Publish client
uses: actions/upload-artifact@v3
with:
name: mithril-client
path: mithril-network/mithril-client/target/release/mithril-client

build-mithril-node-poc:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -311,20 +373,73 @@ jobs:
push: ${{ env.PUSH_PACKAGES }}
tags: ${{ steps.meta.outputs.tags }}

docker-mithril-client:
runs-on: ubuntu-latest
needs: [ build-mithril-core, build-mithril-client ]
permissions:
contents: read
packages: write

env:
PUSH_PACKAGES: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/mithril-client
DOCKER_FILE: ./mithril-network/mithril-client/Dockerfile
CONTEXT: .
GITHUB_REF: ${{ github.ref}}

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set outputs
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags:
type=raw,value={{branch}}-{{sha}}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ${{ env.CONTEXT }}
file: ${{ env.DOCKER_FILE }}
push: ${{ env.PUSH_PACKAGES }}
tags: ${{ steps.meta.outputs.tags }}

generate-publish-docs:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
needs: [ build-mithril-core, build-mithril-aggregator ]
needs: [ build-mithril-core, build-mithril-aggregator, build-mithril-client ]
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Cache mithril-core/Cargo.toml
- name: Cache mithril-core/Cargo.lock
uses: actions/cache@v2.1.5
with:
path: |
~/.cargo/registry
~/.cargo/git
mithril-core/target
key: ${{ runner.os }}-${{ hashFiles('mithril-core/Cargo.toml') }}
key: ${{ runner.os }}-${{ hashFiles('mithril-core/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-key

Expand All @@ -335,19 +450,38 @@ jobs:
args: --manifest-path ./mithril-core/Cargo.toml --target-dir ./github-pages/mithril-core

- uses: actions/cache@v2.1.5
name: Cache mithril-network/mithril-aggregator/Cargo.toml
name: Cache mithril-network/mithril-aggregator/Cargo.lock
with:
path: |
~/.cargo/registry
~/.cargo/git
mithril-network/mithril-aggregator/target
key: ${{ runner.os }}-${{ hashFiles('mithril-network/mithril-aggregator/Cargo.toml') }}
key: ${{ runner.os }}-${{ hashFiles('mithril-network/mithril-aggregator/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-key

- name: Mithril Aggregator / Generate doc
uses: actions-rs/cargo@v1
with:
command: doc
args: --manifest-path ./mithril-core/Cargo.toml --target-dir ./github-pages/mithril-network/mithril-aggregator
args: --manifest-path ./mithril-network/mithril-aggregator/Cargo.toml --target-dir ./github-pages/mithril-network/mithril-aggregator

- uses: actions/cache@v2.1.5
name: Cache mithril-network/mithril-client/Cargo.lock
with:
path: |
~/.cargo/registry
~/.cargo/git
mithril-network/mithril-client/target
key: ${{ runner.os }}-${{ hashFiles('mithril-network/mithril-client/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-key

- name: Mithril Client / Generate doc
uses: actions-rs/cargo@v1
with:
command: doc
args: --manifest-path ./mithril-network/mithril-client/Cargo.toml --target-dir ./github-pages/mithril-network/mithril-client

- name: Mithril Aggregator / Generate OpenAPI UI
uses: Legion2/swagger-ui-action@v1
Expand Down Expand Up @@ -420,3 +554,4 @@ jobs:

- name: Test
run: nix-shell --run '.github/workflows/ci-test.sh'

3 changes: 3 additions & 0 deletions mithril-network/mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ description = "A Mithril Aggregator server"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["lib", "cdylib", "staticlib"]

[dependencies]
log = { version = "0.4.14", features = ["max_level_debug", "release_max_level_warn"] }
env_logger = "0.8.4"
Expand Down
1 change: 0 additions & 1 deletion mithril-network/mithril-aggregator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ WORKDIR /app/
USER appuser

# Run the executable
EXPOSE 8080
ENTRYPOINT ["/app/bin/mithril-aggregator","-vvv"]
16 changes: 8 additions & 8 deletions mithril-network/mithril-aggregator/src/fake_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
use crate::entities;

/// Fake Beacon
pub(crate) fn beacon() -> entities::Beacon {
pub fn beacon() -> entities::Beacon {
let network = "testnet".to_string();
let epoch = 196;
let block = 3443000;
entities::Beacon::new(network, epoch, block)
}

/// Fake ProtocolParameters
pub(crate) fn protocol_parameters() -> entities::ProtocolParameters {
pub fn protocol_parameters() -> entities::ProtocolParameters {
let k = 5;
let m = 100;
let phi_f = 0.2;
entities::ProtocolParameters::new(k, m, phi_f)
}

/// Fake CertificatePending
pub(crate) fn certificate_pending() -> entities::CertificatePending {
pub fn certificate_pending() -> entities::CertificatePending {
// Beacon
let beacon = beacon();

Expand All @@ -34,7 +34,7 @@ pub(crate) fn certificate_pending() -> entities::CertificatePending {
}

/// Fake Certificate
pub(crate) fn certificate(certificate_hash: String) -> entities::Certificate {
pub fn certificate(certificate_hash: String) -> entities::Certificate {
// Beacon
let beacon = beacon();

Expand Down Expand Up @@ -65,7 +65,7 @@ pub(crate) fn certificate(certificate_hash: String) -> entities::Certificate {
}

/// Fake SignersWithStake
pub(crate) fn signers_with_stakes(total: u64) -> Vec<entities::SignerWithStake> {
pub fn signers_with_stakes(total: u64) -> Vec<entities::SignerWithStake> {
(1..total + 1)
.map(|signer_id| {
let party_id = signer_id;
Expand All @@ -77,15 +77,15 @@ pub(crate) fn signers_with_stakes(total: u64) -> Vec<entities::SignerWithStake>
}

/// Fake Signers
pub(crate) fn signers(total: u64) -> Vec<entities::Signer> {
pub fn signers(total: u64) -> Vec<entities::Signer> {
signers_with_stakes(total)
.iter()
.map(|signer| entities::Signer::new(signer.party_id, signer.verification_key.clone()))
.collect::<Vec<entities::Signer>>()
}

/// Fake SingleSignatures
pub(crate) fn single_signatures(total: u64) -> Vec<entities::SingleSignature> {
pub fn single_signatures(total: u64) -> Vec<entities::SingleSignature> {
(1..total + 1)
.map(|signature_id| {
let party_id = signature_id;
Expand All @@ -97,7 +97,7 @@ pub(crate) fn single_signatures(total: u64) -> Vec<entities::SingleSignature> {
}

/// Fake Snapshots
pub(crate) fn snapshots(total: u64) -> Vec<entities::Snapshot> {
pub fn snapshots(total: u64) -> Vec<entities::Snapshot> {
(1..total + 1)
.map(|snapshot_id| {
let digest = format!("1{}", snapshot_id).repeat(20);
Expand Down
4 changes: 4 additions & 0 deletions mithril-network/mithril-aggregator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod apispec;
pub mod entities;
pub mod fake_data;
pub mod http_server;
3 changes: 3 additions & 0 deletions mithril-network/mithril-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
mithril-client
.DS_Store
Loading