Skip to content

Commit

Permalink
ci: add rust_ci.yaml github workflow (#15)
Browse files Browse the repository at this point in the history
* ci: add rust_ci.yaml github workflow

* ci: remove benchmark from rust_ci since we don't have any

* test: add dummy test in eigenda_data just to make `just test` not complain

* style: fix lint issues

* style: beautify justfile layout to make it easier to read

* ci: add unused deps job to rust_ci workflow

* ci: remove build job from rust_ci workflow

* chore: fix justfile (lint was being redefined twice)

* ci: fix unused-deps job, need to install machete, not unused-deps

* ci: properly install cargo-machete in rust_ci

* ci: wrong name for cargo-udeps

* ci: increase unused-deps job timeout to 5 mins

* style: stringify EigenDACommitment hint as "eigenda-commitment" instead of "altda-commitment"
  • Loading branch information
samlaf authored Dec 17, 2024
1 parent 8c2dfa3 commit f9ef680
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 95 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/rust_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Rust CI

on:
push:
branches: [master]
merge_group:
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
cargo-tests:
runs-on: ubuntu-latest
timeout-minutes: 20
name: test
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- name: Install Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- uses: taiki-e/install-action@nextest
- name: cargo test
run: just test
cargo-lint:
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
# TODO: add back cannon and asterisc once we are using them
# See https://github.com/Layr-Labs/kona/blob/main/.github/workflows/rust_ci.yaml
target: ["native"]
name: lint-${{ matrix.target }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- name: Install Rust nightly toolchain
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
prefix-key: ${{ matrix.target }}
- name: Log into ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: fmt + lint
run: just lint-${{ matrix.target }}
- name: chown target
run: |
sudo chown -R $(id -u):$(id -g) ./target
cargo-doc:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- name: Install Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: doclint
run: just lint-docs
- name: doctest
run: just test-docs
cargo-hack:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- name: Install Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: cargo hack
run: just hack
unused-deps:
runs-on: ubuntu-latest
timeout-minutes: 5 # machete runs very quickly but need longer timeout to install the tools
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: taiki-e/install-action@v2
with:
tool: just, cargo-udeps
- name: Install cargo-machete
run: cargo install cargo-machete
- name: Install Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: just unused-deps
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["bin/*"]
members = ["bin/*", "crates/*"]

[workspace.dependencies]
# Workspace
Expand Down
2 changes: 1 addition & 1 deletion bin/host/src/eigenda_blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloy_primitives::Bytes;
use anyhow::Ok;
use reqwest;

/// An online implementation of the [EigenDABlobProvider] trait.
/// Fetches blobs from EigenDA via an eigenda-proxy instance.
#[derive(Debug, Clone)]
pub struct OnlineEigenDABlobProvider {
/// The base url.
Expand Down
2 changes: 1 addition & 1 deletion bin/host/src/fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ where
kv_write_lock.set(key.into(), preimage.into())?;
}
}
HintType::AltDACommitment => {
HintType::EigenDACommitment => {
let cert = hint_data;
info!(target: "fetcher", "Fetching AltDACommitment cert: {:?}", cert);
// Fetch the blob sidecar from the blob provider.
Expand Down
2 changes: 0 additions & 2 deletions bin/host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use kona_host::cli::HostCli;

use kona_host::kv;

use hokulea_client;

use crate::eigenda_blobs::OnlineEigenDABlobProvider;
use anyhow::{anyhow, Result};
use fetcher::Fetcher;
Expand Down
64 changes: 33 additions & 31 deletions crates/eigenda/src/eigenda_blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,38 @@ where
}
}

/// Fetches the next blob from the source.
pub async fn next(&mut self, altda_commitment: &Bytes) -> PipelineResult<Bytes> {
info!(target: "eigenda-blobsource", "next");
self.load_blobs(altda_commitment).await?;
info!(target: "eigenda-blobsource", "next 1");
let next_data = match self.next_data() {
Ok(d) => d,
Err(e) => return e,
};
info!(target: "eigenda-blobsource", "next 2");
// Decode the blob data to raw bytes.
// Otherwise, ignore blob and recurse next.
match next_data.decode() {
Ok(d) => {
info!(target: "eigenda-blobsource", "next 3");
Ok(d)
}
Err(_) => {
warn!(target: "blob-source", "Failed to decode blob data, skipping");
panic!()
// todo need to add recursion
// self.next(altda_commitment).await
}
}
}

/// Clears the source.
pub fn clear(&mut self) {
self.data.clear();
self.open = false;
}

/// Loads blob data into the source if it is not open.
async fn load_blobs(&mut self, altda_commitment: &Bytes) -> Result<(), BlobProviderError> {
if self.open {
Expand All @@ -60,7 +92,7 @@ where
}
Err(_) => {
self.open = true;
return Ok(());
Ok(())
}
}
}
Expand All @@ -73,34 +105,4 @@ where
}
Ok(self.data.remove(0))
}

pub async fn next(&mut self, altda_commitment: &Bytes) -> PipelineResult<Bytes> {
info!(target: "eigenda-blobsource", "next");
self.load_blobs(altda_commitment).await?;
info!(target: "eigenda-blobsource", "next 1");
let next_data = match self.next_data() {
Ok(d) => d,
Err(e) => return e,
};
info!(target: "eigenda-blobsource", "next 2");
// Decode the blob data to raw bytes.
// Otherwise, ignore blob and recurse next.
match next_data.decode() {
Ok(d) => {
info!(target: "eigenda-blobsource", "next 3");
Ok(d)
}
Err(_) => {
warn!(target: "blob-source", "Failed to decode blob data, skipping");
panic!()
// todo need to add recursion
// self.next(altda_commitment).await
}
}
}

pub fn clear(&mut self) {
self.data.clear();
self.open = false;
}
}
33 changes: 33 additions & 0 deletions crates/eigenda/src/eigenda_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use alloy_primitives::Bytes;
use kona_derive::errors::BlobDecodingError;

#[derive(Default, Clone, Debug)]
/// Represents the data structure for EigenDA Blob.
pub struct EigenDABlobData {
/// The calldata
pub(crate) blob: Bytes,
Expand All @@ -17,3 +18,35 @@ impl EigenDABlobData {
Ok(self.blob.clone())
}
}

#[cfg(test)]
mod tests {
use super::*;
use alloc::vec;
use alloy_primitives::Bytes;

#[test]
fn test_decode_success() {
let data = EigenDABlobData {
blob: Bytes::from(vec![1, 2, 3, 4]),
};
let result = data.decode();
assert!(result.is_ok());
assert_eq!(result.unwrap(), Bytes::from(vec![1, 2, 3, 4]));
}

#[test]
fn test_decode_empty_blob() {
let data = EigenDABlobData {
blob: Bytes::from(vec![]),
};
let result = data.decode();
assert!(result.is_ok());
assert_eq!(result.unwrap(), Bytes::from(vec![]));
}

#[test]
fn test_decode_invalid_blob() {
// TODO: implement this once decode actually does something
}
}
6 changes: 5 additions & 1 deletion crates/eigenda/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ use async_trait::async_trait;
use core::fmt::Display;
use kona_derive::errors::PipelineErrorKind;

/// A trait for providing EigenDA blobs.
/// TODO: add explanation for why we need this to be a trait.
#[async_trait]
pub trait EigenDABlobProvider {
/// The error type for the [EigenDAProvider].
/// The error type for the [EigenDABlobProvider].
type Error: Display + ToString + Into<PipelineErrorKind>;

/// Fetches a blob.
async fn get_blob(&mut self, cert: &Bytes) -> Result<Bytes, Self::Error>;

/// Fetches an element from a blob.
async fn get_element(&mut self, cert: &Bytes, element: &Bytes) -> Result<Bytes, Self::Error>;
}
6 changes: 3 additions & 3 deletions crates/proof/src/eigenda_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<T: CommsClient + Sync + Send> EigenDABlobProvider for OracleEigenDAProvider

async fn get_blob(&mut self, cert: &Bytes) -> Result<Bytes, Self::Error> {
self.oracle
.write(&HintType::AltDACommitment.encode_with(&[&cert]))
.write(&HintType::EigenDACommitment.encode_with(&[cert]))
.await
.map_err(OracleProviderError::Preimage)?;
let data = self
Expand All @@ -45,14 +45,14 @@ impl<T: CommsClient + Sync + Send> EigenDABlobProvider for OracleEigenDAProvider

async fn get_element(&mut self, cert: &Bytes, element: &Bytes) -> Result<Bytes, Self::Error> {
self.oracle
.write(&HintType::AltDACommitment.encode_with(&[&cert]))
.write(&HintType::EigenDACommitment.encode_with(&[cert]))
.await
.map_err(OracleProviderError::Preimage)?;

let cert_point_key = Bytes::copy_from_slice(&[cert.to_vec(), element.to_vec()].concat());

self.oracle
.write(&HintType::AltDACommitment.encode_with(&[&cert_point_key]))
.write(&HintType::EigenDACommitment.encode_with(&[&cert_point_key]))
.await
.map_err(OracleProviderError::Preimage)?;
let data = self
Expand Down
8 changes: 4 additions & 4 deletions crates/proof/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ pub enum HintType {
/// A hint that specifies bulk storage of all the code, state and keys generated by an
/// execution witness.
L2PayloadWitness,
///
AltDACommitment,
/// A hint that specifies the EigenDA commitment.
EigenDACommitment,
}

impl HintType {
Expand Down Expand Up @@ -109,7 +109,7 @@ impl TryFrom<&str> for HintType {
"l2-account-proof" => Ok(Self::L2AccountProof),
"l2-account-storage-proof" => Ok(Self::L2AccountStorageProof),
"l2-payload-witness" => Ok(Self::L2PayloadWitness),
"altda-commitment" => Ok(Self::AltDACommitment),
"eigenda-commitment" => Ok(Self::EigenDACommitment),
_ => Err(HintParsingError(value.to_string())),
}
}
Expand All @@ -131,7 +131,7 @@ impl From<HintType> for &str {
HintType::L2AccountProof => "l2-account-proof",
HintType::L2AccountStorageProof => "l2-account-storage-proof",
HintType::L2PayloadWitness => "l2-payload-witness",
HintType::AltDACommitment => "altda-commitment",
HintType::EigenDACommitment => "eigenda-commitment",
}
}
}
Expand Down
Loading

0 comments on commit f9ef680

Please sign in to comment.