Skip to content

Commit

Permalink
Fortuna CI workflows (#1120)
Browse files Browse the repository at this point in the history
* CI and docker

* cleanup

* erc

* whoops
  • Loading branch information
jayantk authored Oct 20, 2023
1 parent d87cd7c commit 4776bdc
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 44 deletions.
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
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(())
}
6 changes: 3 additions & 3 deletions fortuna/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub enum Options {
pub struct ConfigOptions {
/// Path to a configuration file containing the list of supported blockchains
#[arg(long = "config")]
#[arg(env = "PYTH_CONFIG")]
#[arg(env = "FORTUNA_CONFIG")]
#[arg(default_value = "config.yaml")]
pub config: String,
}
Expand All @@ -75,13 +75,13 @@ pub struct ConfigOptions {
pub struct RandomnessOptions {
/// A secret used for generating new hash chains. A 64-char hex string.
#[arg(long = "secret")]
#[arg(env = "PYTH_SECRET")]
#[arg(env = "FORTUNA_SECRET")]
#[arg(default_value = "0000000000000000000000000000000000000000000000000000000000000000")]
pub secret: String,

/// The length of the hash chain to generate.
#[arg(long = "chain-length")]
#[arg(env = "PYTH_CHAIN_LENGTH")]
#[arg(env = "FORTUNA_CHAIN_LENGTH")]
#[arg(default_value = "32")]
pub chain_length: u64,
}
Expand Down
2 changes: 1 addition & 1 deletion fortuna/src/config/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct GenerateOptions {

/// Retrieve a randomness request to this provider
#[arg(long = "chain-id")]
#[arg(env = "PYTH_CHAIN_ID")]
#[arg(env = "FORTUNA_CHAIN_ID")]
pub chain_id: ChainId,

/// A 20-byte (40 char) hex encoded Ethereum private key.
Expand Down
6 changes: 3 additions & 3 deletions fortuna/src/config/get_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ pub struct GetRequestOptions {

/// Retrieve a randomness request to this provider
#[arg(long = "chain-id")]
#[arg(env = "PYTH_CHAIN_ID")]
#[arg(env = "FORTUNA_CHAIN_ID")]
pub chain_id: ChainId,

/// Retrieve a randomness request to this provider
#[arg(long = "provider")]
#[arg(env = "PYTH_PROVIDER")]
#[arg(env = "FORTUNA_PROVIDER")]
#[arg(default_value = "0x368397bDc956b4F23847bE244f350Bde4615F25E")]
pub provider: Address,

/// The sequence number of the request to retrieve
#[arg(long = "sequence")]
#[arg(env = "PYTH_SEQUENCE")]
#[arg(env = "FORTUNA_SEQUENCE")]
#[arg(default_value = "0")]
pub sequence: u64,
}
2 changes: 1 addition & 1 deletion fortuna/src/config/register_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct RegisterProviderOptions {

/// Retrieve a randomness request to this provider
#[arg(long = "chain-id")]
#[arg(env = "PYTH_CHAIN_ID")]
#[arg(env = "FORTUNA_CHAIN_ID")]
pub chain_id: ChainId,

/// A 20-byte (40 char) hex encoded Ethereum private key.
Expand Down
4 changes: 2 additions & 2 deletions fortuna/src/config/request_randomness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct RequestRandomnessOptions {

/// Request randomness on this blockchain.
#[arg(long = "chain-id")]
#[arg(env = "PYTH_CHAIN_ID")]
#[arg(env = "FORTUNA_CHAIN_ID")]
pub chain_id: ChainId,

/// A 20-byte (40 char) hex encoded Ethereum private key.
Expand All @@ -27,7 +27,7 @@ pub struct RequestRandomnessOptions {

/// Submit a randomness request to this provider
#[arg(long = "provider")]
#[arg(env = "PYTH_PROVIDER")]
#[arg(env = "FORTUNA_PROVIDER")]
#[arg(default_value = "0x368397bDc956b4F23847bE244f350Bde4615F25E")]
pub provider: Address,
}
2 changes: 1 addition & 1 deletion fortuna/src/config/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct RunOptions {

/// The public key of the provider whose requests the server will respond to.
#[arg(long = "provider")]
#[arg(env = "PYTH_PROVIDER")]
#[arg(env = "FORTUNA_PROVIDER")]
#[arg(default_value = "0x368397bDc956b4F23847bE244f350Bde4615F25E")]
pub provider: Address,
}
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?
contract PythRandom is PythRandomState, PythRandomEvents {
// TODO: Use an upgradeable proxy
constructor(uint pythFeeInWei) {
Expand Down

0 comments on commit 4776bdc

Please sign in to comment.