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

HTTP Rollup Server #34

Closed
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
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
push: false
load: true
build-args: |
CMT_TAR_GZ=${{ env.CMT_TAR_GZ }}
TOOLS_DEB=${{ env.TOOLS_DEB }}
IMAGE_KERNEL_VERSION=${{ env.IMAGE_KERNEL_VERSION }}
LINUX_VERSION=${{ env.LINUX_VERSION }}
Expand Down Expand Up @@ -87,6 +88,7 @@ jobs:
run: |
sha512sum ${{ env.TOOLS_DEB }} > ${{ env.TOOLS_DEB }}.sha512
sha512sum ${{ env.TOOLS_ROOTFS }} > ${{ env.TOOLS_ROOTFS }}.sha512
sha512sum ${{ env.CMT_TAR_GZ }} > ${{ env.CMT_TAR_GZ }}.sha512

- uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
Expand All @@ -97,6 +99,8 @@ jobs:
${{ env.TOOLS_DEB }}.sha512
${{ env.TOOLS_ROOTFS }}
${{ env.TOOLS_ROOTFS }}.sha512
${{ env.CMT_TAR_GZ }}
${{ env.CMT_TAR_GZ }}.sha512

test-rollup-http-server:
runs-on: ubuntu-22.04
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Added a value field to vouchers
- Tools are now implemented in terms of libcmt
- Added libcmt

## [0.14.1] - 2023-12-18
### Fixed
Expand Down
140 changes: 83 additions & 57 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,83 +31,107 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
ca-certificates \
git \
wget \
pkg-config \
crossbuild-essential-riscv64 \
gcc-12-riscv64-linux-gnu \
g++-12-riscv64-linux-gnu \
&& \
wget -O ${LINUX_HEADERS_FILEPATH} ${LINUX_HEADERS_URLPATH} && \
echo "efdb2243d9b6828e90c826be0f178110f0cc590cb00e8fa588cb20723126c2a4 ${LINUX_HEADERS_FILEPATH}" | sha256sum --check && \
echo "4ef81562b1d85220bde9fd4ff01d149469a500f22cc319a02c32bfd1c0698ae1 ${LINUX_HEADERS_FILEPATH}" | sha256sum --check && \
apt-get install -y --no-install-recommends ${LINUX_HEADERS_FILEPATH} && \
adduser developer -u 499 --gecos ",,," --disabled-password && \
mkdir -p ${BUILD_BASE}/tools && chown -R developer:developer ${BUILD_BASE}/tools && \
rm -rf /var/lib/apt/lists/* ${LINUX_HEADERS_FILEPATH}

# Setup latest cross compiler as default
# ------------------------------------------------------------------------------
RUN <<EOF
for tool in cpp g++ gcc gcc-ar gcc-nm gcc-ranlib gcov gcov-dump gcov-tool; do
for version in 12; do
update-alternatives --install \
/usr/bin/riscv64-linux-gnu-$tool riscv64-linux-gnu-$tool \
/usr/bin/riscv64-linux-gnu-$tool-$version $version
done
done
EOF

ENV RISCV_ARCH="rv64gc"
ENV RISCV_ABI="lp64d"
ENV CFLAGS="-march=$RISCV_ARCH -mabi=$RISCV_ABI"
ENV TOOLCHAIN_PREFIX="riscv64-linux-gnu-"
ENV TOOLCHAIN_SUFFIX="-12"

FROM tools-env as builder
COPY --chown=developer:developer sys-utils/ ${BUILD_BASE}/tools/sys-utils/

# build C/C++ tools
# ------------------------------------------------------------------------------
FROM builder as c-builder
USER developer
RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all

# build rust tools
# ------------------------------------------------------------------------------
FROM tools-env as rust-env
ENV PATH="/home/developer/.cargo/bin:${PATH}"
ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt
ARG CMT_TAR_GZ=libcmt-v0.14.1-dev.tar.gz
ARG BUILD_BASE=/opt/cartesi

USER developer
RUN make -C ${CMT_BASE} -j$(nproc) ioctl.build mock.build
USER root
RUN make -C ${CMT_BASE} -j$(nproc) ioctl.install \
TARGET_PREFIX=${CMT_BASE}/install && \
tar czf ${BUILD_BASE}/${CMT_TAR_GZ} -C ${CMT_BASE}/install .
RUN make -C ${BUILD_BASE}/tools/sys-utils/libcmt/ -j$(nproc) ioctl.install mock.install \
PREFIX=/usr/x86_64-linux-gnu TARGET_PREFIX=/usr/riscv64-linux-gnu
USER developer
RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all

RUN cd && \
wget https://github.com/rust-lang/rustup/archive/refs/tags/1.26.0.tar.gz && \
echo "6f20ff98f2f1dbde6886f8d133fe0d7aed24bc76c670ea1fca18eb33baadd808 1.26.0.tar.gz" | sha256sum --check && \
tar -xzf 1.26.0.tar.gz && \
bash rustup-1.26.0/rustup-init.sh \
-y \
--default-toolchain 1.74.0 \
--profile minimal \
--target riscv64gc-unknown-linux-gnu && \
rm -rf rustup-1.26.0 1.26.0.tar.gz

FROM rust-env as rust-builder
COPY --chown=developer:developer rollup-http/rollup-init ${BUILD_BASE}/tools/rollup-http/rollup-init
COPY --chown=developer:developer rollup-http/rollup-http-client ${BUILD_BASE}/tools/rollup-http/rollup-http-client
COPY --chown=developer:developer rollup-http/.cargo ${BUILD_BASE}/tools/rollup-http/.cargo

# build rollup-http-server dependencies
FROM rust-builder as http-server-dep-builder
COPY --chown=developer:developer rollup-http/rollup-http-server/Cargo.toml rollup-http/rollup-http-server/Cargo.lock ${BUILD_BASE}/tools/rollup-http/rollup-http-server/
RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && \
mkdir src/ && \
echo "fn main() {}" > src/main.rs && \
echo "pub fn dummy() {}" > src/lib.rs && \
cargo build --target riscv64gc-unknown-linux-gnu --release

# build rollup-http-server
FROM http-server-dep-builder as http-server-builder
COPY --chown=developer:developer rollup-http/rollup-http-server/build.rs ${BUILD_BASE}/tools/rollup-http/rollup-http-server/
COPY --chown=developer:developer rollup-http/rollup-http-server/src ${BUILD_BASE}/tools/rollup-http/rollup-http-server/src
RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && touch build.rs src/* && \
cargo build --target riscv64gc-unknown-linux-gnu --release

# build echo-dapp dependencies
FROM rust-builder as echo-dapp-dep-builder
COPY --chown=developer:developer rollup-http/echo-dapp/Cargo.toml rollup-http/echo-dapp/Cargo.lock ${BUILD_BASE}/tools/rollup-http/echo-dapp/
RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && \
mkdir src/ && echo "fn main() {}" > src/main.rs && \
cargo build --target riscv64gc-unknown-linux-gnu --release

# build echo-dapp
FROM echo-dapp-dep-builder as echo-dapp-builder
COPY --chown=developer:developer rollup-http/echo-dapp/src ${BUILD_BASE}/tools/rollup-http/echo-dapp/src
RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && touch src/* && \
cargo build --target riscv64gc-unknown-linux-gnu --release
## build rust tools
## ------------------------------------------------------------------------------
#FROM tools-env as rust-env
#ENV PATH="/home/developer/.cargo/bin:${PATH}"
#
#USER developer
#
#RUN cd && \
# wget https://github.com/rust-lang/rustup/archive/refs/tags/1.26.0.tar.gz && \
# echo "6f20ff98f2f1dbde6886f8d133fe0d7aed24bc76c670ea1fca18eb33baadd808 1.26.0.tar.gz" | sha256sum --check && \
# tar -xzf 1.26.0.tar.gz && \
# bash rustup-1.26.0/rustup-init.sh \
# -y \
# --default-toolchain 1.74.0 \
# --profile minimal \
# --target riscv64gc-unknown-linux-gnu && \
# rm -rf rustup-1.26.0 1.26.0.tar.gz
#
#FROM rust-env as rust-builder
#COPY --chown=developer:developer rollup-http/rollup-init ${BUILD_BASE}/tools/rollup-http/rollup-init
#COPY --chown=developer:developer rollup-http/rollup-http-client ${BUILD_BASE}/tools/rollup-http/rollup-http-client
#COPY --chown=developer:developer rollup-http/.cargo ${BUILD_BASE}/tools/rollup-http/.cargo
#
## build rollup-http-server dependencies
#FROM rust-builder as http-server-dep-builder
#COPY --chown=developer:developer rollup-http/rollup-http-server/Cargo.toml rollup-http/rollup-http-server/Cargo.lock ${BUILD_BASE}/tools/rollup-http/rollup-http-server/
#RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && \
# mkdir src/ && \
# echo "fn main() {}" > src/main.rs && \
# echo "pub fn dummy() {}" > src/lib.rs && \
# cargo build --target riscv64gc-unknown-linux-gnu --release
#
## build rollup-http-server
#FROM http-server-dep-builder as http-server-builder
#COPY --chown=developer:developer rollup-http/rollup-http-server/build.rs ${BUILD_BASE}/tools/rollup-http/rollup-http-server/
#COPY --chown=developer:developer rollup-http/rollup-http-server/src ${BUILD_BASE}/tools/rollup-http/rollup-http-server/src
#RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && touch build.rs src/* && \
# cargo build --target riscv64gc-unknown-linux-gnu --release
#
## build echo-dapp dependencies
#FROM rust-builder as echo-dapp-dep-builder
#COPY --chown=developer:developer rollup-http/echo-dapp/Cargo.toml rollup-http/echo-dapp/Cargo.lock ${BUILD_BASE}/tools/rollup-http/echo-dapp/
#RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && \
# mkdir src/ && echo "fn main() {}" > src/main.rs && \
# cargo build --target riscv64gc-unknown-linux-gnu --release
#
## build echo-dapp
#FROM echo-dapp-dep-builder as echo-dapp-builder
#COPY --chown=developer:developer rollup-http/echo-dapp/src ${BUILD_BASE}/tools/rollup-http/echo-dapp/src
#RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && touch src/* && \
# cargo build --target riscv64gc-unknown-linux-gnu --release

# pack tools (deb)
# ------------------------------------------------------------------------------
Expand All @@ -117,6 +141,7 @@ ARG STAGING_BASE=${BUILD_BASE}/_install
ARG STAGING_DEBIAN=${STAGING_BASE}/DEBIAN
ARG STAGING_SBIN=${STAGING_BASE}/usr/sbin
ARG STAGING_BIN=${STAGING_BASE}/usr/bin
ARG CMT_TAR_GZ=libcmt-v0.14.1-dev.tar.gz

RUN mkdir -p ${STAGING_DEBIAN} ${STAGING_SBIN} ${STAGING_BIN} ${STAGING_BASE}/etc && \
echo "cartesi-machine" > ${staging_base}/etc/hostname
Expand All @@ -125,12 +150,13 @@ COPY control ${STAGING_DEBIAN}/control

COPY --from=builder ${BUILD_BASE}/tools/sys-utils/cartesi-init/cartesi-init ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/xhalt/xhalt ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/yield/yield ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/rollup/rollup ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/ioctl-echo-loop/ioctl-echo-loop ${STAGING_BIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/yield/yield ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/misc/* ${STAGING_BIN}
COPY --from=rust-builder ${BUILD_BASE}/tools/rollup-http/rollup-init/rollup-init ${STAGING_SBIN}
COPY --from=http-server-builder ${BUILD_BASE}/tools/rollup-http/rollup-http-server/target/riscv64gc-unknown-linux-gnu/release/rollup-http-server ${STAGING_BIN}
COPY --from=echo-dapp-builder ${BUILD_BASE}/tools/rollup-http/echo-dapp/target/riscv64gc-unknown-linux-gnu/release/echo-dapp ${STAGING_BIN}
#COPY --from=rust-builder ${BUILD_BASE}/tools/rollup-http/rollup-init/rollup-init ${STAGING_SBIN}
#COPY --from=http-server-builder ${BUILD_BASE}/tools/rollup-http/rollup-http-server/target/riscv64gc-unknown-linux-gnu/release/rollup-http-server ${STAGING_BIN}
#COPY --from=echo-dapp-builder ${BUILD_BASE}/tools/rollup-http/echo-dapp/target/riscv64gc-unknown-linux-gnu/release/echo-dapp ${STAGING_BIN}

RUN dpkg-deb -Zxz --root-owner-group --build ${STAGING_BASE} ${BUILD_BASE}/${TOOLS_DEB}
COPY --from=c-builder ${BUILD_BASE}/${CMT_TAR_GZ} ${BUILD_BASE}/${CMT_TAR_GZ}
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
MAJOR := 0
MINOR := 14
PATCH := 1
LABEL :=
LABEL :=-dev
VERSION := $(MAJOR).$(MINOR).$(PATCH)$(LABEL)

TOOLS_DEB := machine-emulator-tools-v$(VERSION).deb
TOOLS_IMAGE := cartesi/machine-emulator-tools:$(VERSION)
TOOLS_ROOTFS := rootfs-tools-v$(VERSION).ext2
CMT_TAR_GZ := libcmt-$(VERSION).tar.gz

IMAGE_KERNEL_VERSION ?= v0.19.1
IMAGE_KERNEL_VERSION ?= v0.20.0-output-unification-rc1
LINUX_VERSION ?= 6.5.9-ctsi-1
LINUX_HEADERS_URLPATH := https://github.com/cartesi/image-kernel/releases/download/${IMAGE_KERNEL_VERSION}/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb

Expand All @@ -33,6 +34,7 @@ all: fs
build: control
@docker buildx build --load \
--build-arg TOOLS_DEB=$(TOOLS_DEB) \
--build-arg CMT_TAR_GZ=$(CMT_TAR_GZ) \
--build-arg IMAGE_KERNEL_VERSION=$(IMAGE_KERNEL_VERSION) \
--build-arg LINUX_VERSION=$(LINUX_VERSION) \
--build-arg LINUX_HEADERS_URLPATH=$(LINUX_HEADERS_URLPATH) \
Expand All @@ -44,6 +46,7 @@ build: control
copy:
@ID=`docker create $(TOOLS_IMAGE)` && \
docker cp $$ID:/opt/cartesi/$(TOOLS_DEB) . && \
docker cp $$ID:/opt/cartesi/$(CMT_TAR_GZ) . && \
docker rm $$ID

$(TOOLS_DEB) deb: build
Expand All @@ -63,6 +66,7 @@ $(TOOLS_ROOTFS) fs: $(TOOLS_DEB)
rm -f rootfs.gnutar rootfs.tar

env:
@echo CMT_TAR_GZ=$(CMT_TAR_GZ)
@echo TOOLS_DEB=$(TOOLS_DEB)
@echo TOOLS_ROOTFS=$(TOOLS_ROOTFS)
@echo TOOLS_IMAGE=$(TOOLS_IMAGE)
Expand Down
2 changes: 1 addition & 1 deletion fs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RUN mkdir benchmarks && cd benchmarks && \

# Final image
FROM --platform=linux/riscv64 riscv64/ubuntu:22.04
ARG TOOLS_DEB=machine-emulator-tools-v0.14.0.deb
ARG TOOLS_DEB=machine-emulator-tools-v0.14.1-dev.deb
ADD ${TOOLS_DEB} /tmp/
RUN apt-get update && \
apt-get install -y --no-install-recommends \
Expand Down
1 change: 1 addition & 0 deletions rollup-http/rollup-http-client/src/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct Notice {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Voucher {
pub destination: String,
pub data: String,
pub payload: String,
}

Expand Down
2 changes: 1 addition & 1 deletion rollup-http/rollup-http-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tonic-build = "0.5"

[dev-dependencies]
rollup-http-client = {path = "../rollup-http-client"}

rand = "0.8.5"


[profile.release]
Expand Down
14 changes: 1 addition & 13 deletions rollup-http/rollup-http-server/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,5 @@
extern crate cc;

fn main() {
println!("cargo:rerun-if-changed=src/rollup/bindings.c,src/rollup/bindings.h,tests/rollup_test_bindings.c,tests/rollup_test.h");
let test = std::env::var("USE_ROLLUP_BINDINGS_MOCK").unwrap_or("0".to_string());
if test == "1" {
cc::Build::new()
.file("tests/rollup_test_bindings.c")
.compile("libtest_bindings.a");
println!("cargo:rustc-link-lib=test_bindings");
} else {
cc::Build::new()
.file("src/rollup/bindings.c")
.compile("libbindings.a");
println!("cargo:rustc-link-lib=bindings");
}
println!("cargo:rustc-link-lib=cmt");
}
6 changes: 3 additions & 3 deletions rollup-http/rollup-http-server/src/dapp_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use std::sync::Arc;
use async_mutex::Mutex;
use tokio::process::Command;

use crate::rollup::{self, Exception};
use crate::rollup::{self, Exception, RollupFd};

/// Execute the dapp command and throw a rollup exception if it fails or exits
pub async fn run(args: Vec<String>, rollup_fd: Arc<Mutex<RawFd>>) {
pub async fn run(args: Vec<String>, rollup_fd: Arc<Mutex<RollupFd>>) {
log::info!("starting dapp: {}", args.join(" "));
let task = tokio::task::spawn_blocking(move || Command::new(&args[0]).args(&args[1..]).spawn());
let message = match task.await {
Expand All @@ -40,7 +40,7 @@ pub async fn run(args: Vec<String>, rollup_fd: Arc<Mutex<RawFd>>) {
let exception = Exception {
payload: String::from("0x") + &hex::encode(message),
};
match rollup::rollup_throw_exception(*rollup_fd.lock().await, &exception) {
match rollup::rollup_throw_exception(&*rollup_fd.lock().await, &exception) {
Ok(_) => {
log::debug!("exception successfully thrown {:#?}", exception);
}
Expand Down
Loading