Skip to content
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

Fortuna CI workflows #1120

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 20 additions & 0 deletions .github/workflows/ci-fortuna.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Check Fortuna

on:
pull_request:
paths: [fortuna/**]
push:
branches: [main]
paths: [fortuna/**]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2023-07-23
override: true
- name: Run executor tests
run: cargo test --manifest-path ./fortuna/Cargo.toml
Copy link
Contributor Author

Choose a reason for hiding this comment

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

there aren't any unit tests right now, but this checks the build and will run the tests once we add some

44 changes: 44 additions & 0 deletions .github/workflows/push-fortuna-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and Push Fortuna Image
on:
push:
tags:
- fortuna-v*
workflow_dispatch:
inputs:
dispatch_description:
description: "Dispatch description"
required: true
type: string
permissions:
contents: read
id-token: write
jobs:
fortuna-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set image tag to version of the git tag
if: ${{ startsWith(github.ref, 'refs/tags/fortuna-v') }}
run: |
PREFIX="refs/tags/fortuna-"
VERSION="${GITHUB_REF:${#PREFIX}}"
echo "IMAGE_TAG=${VERSION}" >> "${GITHUB_ENV}"
- name: Set image tag to the git commit hash
if: ${{ !startsWith(github.ref, 'refs/tags/fortuna-v') }}
run: |
echo "IMAGE_TAG=${{ github.sha }}" >> "${GITHUB_ENV}"
- uses: aws-actions/configure-aws-credentials@8a84b07f2009032ade05a88a28750d733cc30db1
with:
role-to-assume: arn:aws:iam::192824654885:role/github-actions-ecr
aws-region: eu-west-2
- uses: docker/login-action@v2
with:
registry: public.ecr.aws
env:
AWS_REGION: us-east-1
- run: |
DOCKER_BUILDKIT=1 docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f fortuna/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
env:
ECR_REGISTRY: public.ecr.aws
ECR_REPOSITORY: pyth-network/fortuna
62 changes: 31 additions & 31 deletions fortuna/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions fortuna/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG RUST_VERSION=1.66.1

FROM rust:${RUST_VERSION} AS build

# Set default toolchain
RUN rustup default nightly-2023-07-23

# Build
WORKDIR /src
COPY fortuna fortuna

WORKDIR /src/fortuna

RUN --mount=type=cache,target=/root/.cargo/registry cargo build --release


FROM rust:${RUST_VERSION}
# Copy artifacts from other images
COPY --from=build /src/fortuna/target/release/fortuna /usr/local/bin/
14 changes: 12 additions & 2 deletions fortuna/src/command/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use {
ethereum::SignablePythContract,
},
anyhow::Result,
base64::{
engine::general_purpose::STANDARD as base64_standard_engine,
Engine as _,
},
std::sync::Arc,
};

Expand Down Expand Up @@ -40,7 +44,10 @@ pub async fn generate(opts: &GenerateOptions) -> Result<()> {
.json::<GetRandomValueResponse>()
.await?;

tracing::info!(response = resp, "Retrieved the provider's random value.",);
tracing::info!(
response = base64_standard_engine.encode(resp.value),
"Retrieved the provider's random value.",
);
let provider_randomness = resp.value;

// Submit the provider's and our values to the contract to reveal the random number.
Expand All @@ -53,7 +60,10 @@ pub async fn generate(opts: &GenerateOptions) -> Result<()> {
)
.await?;

tracing::info!(number = random_value, "Random number generated.");
tracing::info!(
number = base64_standard_engine.encode(random_value),
"Random number generated."
);

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import "./PythRandomEvents.sol";
// - gas optimizations
// - function to check invariants??
// - need to increment pyth fees if someone transfers funds to the contract via another method
// - off-chain data ERC support?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

drive by so we remember

contract PythRandom is PythRandomState, PythRandomEvents {
// TODO: Use an upgradeable proxy
constructor(uint pythFeeInWei) {
Expand Down