Skip to content

Commit

Permalink
feat(node): migrate to go claimer
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer authored and vfusco committed Oct 31, 2024
1 parent 16b96cd commit 88730e0
Show file tree
Hide file tree
Showing 37 changed files with 192 additions and 8,597 deletions.
78 changes: 0 additions & 78 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,83 +116,6 @@ jobs:
- name: Check auto generated files
run: make check-generate


test-rust:
runs-on: ubuntu-22.04
env:
RUSTFLAGS: -D warnings -C debuginfo=0
defaults:
run:
working-directory: cmd/authority-claimer
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: depot/setup-action@v1
- name: Build dependency images
uses: depot/bake-action@v1
with:
files: |
./docker-bake.hcl
./docker-bake.override.hcl
./docker-bake.platforms.hcl
targets: |
rollups-node-snapshot
project: ${{ vars.DEPOT_PROJECT }}
workdir: build
load: true

- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
./cmd/authority-claimer/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-

- name: Update Rust
run: rustup update

- name: Install cargo sweep
run: cargo install cargo-sweep
continue-on-error: true

- name: Install cargo cache
run: cargo install cargo-cache
continue-on-error: true

- name: Install cargo-machete
run: cargo install cargo-machete
continue-on-error: true

- name: Set sweep timestamp
run: cargo sweep -s

- name: Analyze dependencies
run: cargo machete .

- name: Check code format
run: cargo fmt --all -- --check

- name: Run linter
run: cargo clippy -- -A clippy::module_inception -A clippy::mixed_attributes_style

- name: Build binaries and tests
run: cargo build --all-targets

- name: Clean old build files
run: cargo sweep -f

- name: Clean dependencies source files
run: cargo cache --autoclean

- name: Run tests
run: cargo test

test-go:
runs-on: ubuntu-22.04
container:
Expand Down Expand Up @@ -241,7 +164,6 @@ jobs:
runs-on: ubuntu-22.04
needs:
- do-basic-checks
- test-rust
- test-go
steps:
- uses: actions/checkout@v4
Expand Down
80 changes: 4 additions & 76 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@
# syntax=docker.io/docker/dockerfile:1

ARG EMULATOR_VERSION=0.18.1
ARG RUST_VERSION=1.78.0

# Build directories.
ARG RUST_BUILD_PATH=/build/cartesi/rust
ARG GO_BUILD_PATH=/build/cartesi/go

FROM cartesi/machine-emulator:${EMULATOR_VERSION} AS common-env

USER root

# Re-declare ARGs so they can be used in the RUN block
ARG RUST_BUILD_PATH
ARG GO_BUILD_PATH

# Install ca-certificates and curl (setup).
RUN <<EOF
set -e
apt-get update
apt-get install -y --no-install-recommends ca-certificates curl wget build-essential pkg-config libssl-dev
mkdir -p /opt/rust/rustup /opt/go ${RUST_BUILD_PATH} ${GO_BUILD_PATH}/rollups-node
chown -R cartesi:cartesi /opt/rust /opt/go ${RUST_BUILD_PATH} ${GO_BUILD_PATH}
mkdir -p /opt/go ${GO_BUILD_PATH}/rollups-node
chown -R cartesi:cartesi /opt/go ${GO_BUILD_PATH}
EOF

USER cartesi
Expand All @@ -44,68 +41,6 @@ COPY rollups-contracts /build/rollups-contracts
WORKDIR /build/rollups-contracts
RUN pnpm install --frozen-lockfile && pnpm export

# =============================================================================
# STAGE: rust-installer
#
# - Install rust and cargo-chef.
# =============================================================================

FROM common-env AS rust-installer

# Get Rust
ENV CARGO_HOME=/opt/rust/cargo
ENV RUSTUP_HOME=/opt/rust/rustup

RUN <<EOF
set -e
cd /tmp
wget https://github.com/rust-lang/rustup/archive/refs/tags/1.27.0.tar.gz
echo "3d331ab97d75b03a1cc2b36b2f26cd0a16d681b79677512603f2262991950ad1 1.27.0.tar.gz" | sha256sum --check
tar xzf 1.27.0.tar.gz
bash rustup-1.27.0/rustup-init.sh \
-y \
--no-modify-path \
--default-toolchain 1.78 \
--component rustfmt \
--profile minimal
rm -rf 1.27.0*
$CARGO_HOME/bin/cargo install cargo-chef
EOF

ENV PATH="${CARGO_HOME}/bin:${PATH}"

ARG RUST_BUILD_PATH
WORKDIR ${RUST_BUILD_PATH}

# =============================================================================
# STAGE: rust-prepare
#
# This stage prepares the recipe with just the external dependencies.
# =============================================================================

FROM rust-installer AS rust-prepare
COPY ./cmd/authority-claimer/ .
RUN cargo chef prepare --recipe-path recipe.json

# =============================================================================
# STAGE: rust-builder
#
# This stage builds the Rust binaries. First it builds the external
# dependencies and then it builds the node binaries.
# =============================================================================

FROM rust-installer AS rust-builder

# Build external dependencies with cargo chef.
COPY --from=rust-prepare ${RUST_BUILD_PATH}/recipe.json .
RUN cargo chef cook --release --recipe-path recipe.json

COPY --chown=cartesi:cartesi ./cmd/authority-claimer/ .
COPY --from=contracts-artifacts /build/rollups-contracts/export/artifacts ${RUST_BUILD_PATH}/../../rollups-contracts/export/artifacts

# Build application.
RUN cargo build --release

# =============================================================================
# STAGE: go-installer
#
Expand Down Expand Up @@ -147,8 +82,8 @@ ENV GOENV=${GO_BUILD_PATH}/.config/go/env
ENV GOPATH=${GO_BUILD_PATH}/.go

# Download external dependencies.
COPY go.mod ${GO_BUILD_PATH}/rollups-node/
COPY go.sum ${GO_BUILD_PATH}/rollups-node/
COPY --chown=cartesi:cartesi go.mod ${GO_BUILD_PATH}/rollups-node/
COPY --chown=cartesi:cartesi go.sum ${GO_BUILD_PATH}/rollups-node/
RUN cd ${GO_BUILD_PATH}/rollups-node && go mod download

# =============================================================================
Expand Down Expand Up @@ -198,13 +133,6 @@ RUN <<EOF
chown -R cartesi:cartesi ${NODE_RUNTIME_DIR}
EOF

# Copy Rust binaries.
# Explicitly copy each binary to avoid adding unnecessary files to the runtime
# image.
ARG RUST_BUILD_PATH
ARG RUST_TARGET=${RUST_BUILD_PATH}/target/release
COPY --from=rust-builder ${RUST_TARGET}/cartesi-rollups-authority-claimer /usr/bin

# Copy Go binary.
ARG GO_BUILD_PATH
COPY --from=go-builder ${GO_BUILD_PATH}/rollups-node/cartesi-rollups-* /usr/bin
Expand Down
28 changes: 4 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ else
PREFIX ?= /usr
endif

# Rust artifacts
CLAIMER := cmd/authority-claimer/target/$(BUILD_TYPE)/cartesi-rollups-authority-claimer
RUST_ARTIFACTS := $(CLAIMER)

# Go artifacts
GO_ARTIFACTS := cartesi-rollups-node cartesi-rollups-cli cartesi-rollups-evm-reader cartesi-rollups-advancer cartesi-rollups-validator cartesi-rollups-claimer

Expand Down Expand Up @@ -61,9 +57,7 @@ all: build
# =============================================================================
# Build
# =============================================================================
build: build-go build-rust ## Build all artifacts

build-rust: $(RUST_ARTIFACTS) ## Build rust artifacts (claimer)
build: build-go ## Build all artifacts

build-go: $(GO_ARTIFACTS) ## Build Go artifacts (node, cli, evm-reader)

Expand All @@ -89,11 +83,6 @@ $(GO_ARTIFACTS):
@echo "Building Go artifact $@"
go build $(GO_BUILD_PARAMS) ./cmd/$@

$(CLAIMER): | $(ROLLUPS_CONTRACTS_ABI_BASEDIR)
@echo "Building Rust artifact $@"
@cd cmd/authority-claimer && cargo build $(CARGO_BUILD_PARAMS)
@cp cmd/authority-claimer/target/release/cartesi-rollups-authority-claimer .

tidy-go:
@go mod tidy

Expand Down Expand Up @@ -124,18 +113,13 @@ migrate: ## Run migration on development database
# Clean
# =============================================================================

clean: clean-go clean-rust clean-contracts clean-docs clean-devnet-files clean-dapps ## Clean all artifacts
clean: clean-go clean-contracts clean-docs clean-devnet-files clean-dapps ## Clean all artifacts

clean-go: ## Clean Go artifacts
@echo "Cleaning Go artifacts"
@go clean -i -r -cache
@rm -f $(GO_ARTIFACTS)

clean-rust: ## Clean Rust artifacts
@echo "Cleaning Rust artifacts"
@cd cmd/authority-claimer && cargo clean
@rm -f cartesi-rollups-authority-claimer

clean-contracts: ## Clean contract artifacts
@echo "Cleaning contract artifacts"
@cd rollups-contracts && rm -rf artifacts cache export/artifacts node_modules src && git checkout .
Expand All @@ -155,17 +139,13 @@ clean-dapps: ## Clean the dapps
# =============================================================================
# Tests
# =============================================================================
test: unit-test-go unit-test-rust ## Execute all tests
test: unit-test-go ## Execute all tests

unit-test-go: deployment.json ## Execute go unit tests
@echo "Running go unit tests"
@go clean -testcache
@go test -p 1 $(GO_BUILD_PARAMS) $(GO_TEST_PACKAGES)

unit-test-rust: ## Execute unit tests
@echo "Running rust unit tests"
@cd cmd/authority-claimer && cargo test

e2e-test: ## Execute e2e tests
@echo "Running end-to-end tests"
@go test -count=1 ./test --tags=endtoendtests
Expand Down Expand Up @@ -272,4 +252,4 @@ shutdown-compose: ## Remove the containers and volumes from previous compose run
help: ## Show help for each of the Makefile recipes
@grep "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/:.*##\(.*\)/:\n\t\1\n/'

.PHONY: build build-go build-rust clean clean-go clean-rust test unit-test-go unit-test-rust e2e-test lint fmt vet escape md-lint devnet image run-with-compose shutdown-compose help docs $(GO_ARTIFACTS)
.PHONY: build build-go clean clean-go test unit-test-go e2e-test lint fmt vet escape md-lint devnet image run-with-compose shutdown-compose help docs $(GO_ARTIFACTS)
1 change: 0 additions & 1 deletion cmd/authority-claimer/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/authority-claimer/.rustfmt.toml

This file was deleted.

Loading

0 comments on commit 88730e0

Please sign in to comment.