From aaba1f2bc55376a1940c99e47f58bcf839eb6716 Mon Sep 17 00:00:00 2001 From: Marcelo Politzer <251334+mpolitzer@users.noreply.github.com> Date: Fri, 1 Nov 2024 10:36:09 -0300 Subject: [PATCH] feat(contracts): migrate to 2.0.0-rc.12, use artifacts, remove submodule --- .dockerignore | 1 + .gitignore | 1 + .gitmodules | 4 - Dockerfile | 16 ---- Makefile | 25 +++-- .../root/app/deploy/deploy.go | 2 +- rollups-contracts | 1 - test/devnet/Dockerfile | 94 +++++++------------ test/devnet/Dockerfile.dockerignore | 1 + 9 files changed, 54 insertions(+), 91 deletions(-) delete mode 160000 rollups-contracts diff --git a/.dockerignore b/.dockerignore index 70b807e71..7f7ce6a87 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,3 +7,4 @@ cartesi-rollups-evm-reader cartesi-rollups-node cartesi-rollups-advancer cartesi-rollups-validator +/rollups-contracts diff --git a/.gitignore b/.gitignore index a6667a6b2..f5301e814 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ machine-snapshot/** /cartesi-rollups-advancer /cartesi-rollups-validator /cartesi-rollups-claimer +/rollups-contracts diff --git a/.gitmodules b/.gitmodules index f3826772f..e69de29bb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +0,0 @@ -[submodule "rollups-contracts"] - path = rollups-contracts - url = https://github.com/cartesi/rollups-contracts - branch = v2.0.0-rc.6 diff --git a/Dockerfile b/Dockerfile index 4aac59387..9c26a675f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,21 +26,6 @@ EOF USER cartesi -# ============================================================================= -# STAGE: contracts-artifacts -# -# - Generate the contracts artifacts. -# ============================================================================= - -FROM node:20-slim AS contracts-artifacts - -ENV PNPM_HOME="/pnpm" -ENV PATH="$PNPM_HOME:$PATH" -RUN corepack enable -COPY rollups-contracts /build/rollups-contracts -WORKDIR /build/rollups-contracts -RUN pnpm install --frozen-lockfile && pnpm export - # ============================================================================= # STAGE: go-installer # @@ -99,7 +84,6 @@ ARG GO_BUILD_PATH # Build application. COPY --chown=cartesi:cartesi . ${GO_BUILD_PATH}/rollups-node/ -COPY --from=contracts-artifacts /build/rollups-contracts/export/artifacts ${GO_BUILD_PATH}/rollups-node/rollups-contracts/export/artifacts RUN cd ${GO_BUILD_PATH}/rollups-node && make build-go diff --git a/Makefile b/Makefile index de6611ac0..dc5d83137 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,10 @@ TARGET_OS?=$(shell uname) export TARGET_OS ROLLUPS_NODE_VERSION := 2.0.0 +CONTRACTS_VERSION := 2.0.0-rc.12 +CONTRACTS_URL:=https://github.com/cartesi/rollups-contracts/releases/download/ +CONTRACTS_ARTIFACT:=rollups-contracts-$(CONTRACTS_VERSION)-artifacts.tar.gz +CONTRACTS_SHA256:=6d2cd0d5f562342b5171766b0574043a39b8f74b276052b2150cdc26ec7a9fdf IMAGE_TAG ?= devel @@ -50,7 +54,8 @@ endif GO_TEST_PACKAGES ?= ./... -ROLLUPS_CONTRACTS_ABI_BASEDIR:= rollups-contracts/export/artifacts/contracts +ROLLUPS_CONTRACTS_ABI_BASEDIR_ROOT := rollups-contracts +ROLLUPS_CONTRACTS_ABI_BASEDIR:= $(ROLLUPS_CONTRACTS_ABI_BASEDIR_ROOT)/export/artifacts/contracts all: build @@ -86,7 +91,7 @@ $(GO_ARTIFACTS): tidy-go: @go mod tidy -generate: $(ROLLUPS_CONTRACTS_ABI_BASEDIR) ## Generate the file that are committed to the repo +generate: $(ROLLUPS_CONTRACTS_ABI_BASEDIR)/.stamp ## Generate the file that are committed to the repo @echo "Generating Go files" @go generate ./internal/... ./pkg/... @@ -99,11 +104,16 @@ check-generate: generate ## Check whether the generated files are in sync exit 1; \ fi -contracts: $(ROLLUPS_CONTRACTS_ABI_BASEDIR) ## Export the rollups-contracts artifacts +contracts: $(ROLLUPS_CONTRACTS_ABI_BASEDIR)/.stamp ## Export the rollups-contracts artifacts -$(ROLLUPS_CONTRACTS_ABI_BASEDIR): - @echo "Exporting rollups-contracts artifacts" - @cd rollups-contracts && pnpm install --frozen-lockfile && pnpm export +$(ROLLUPS_CONTRACTS_ABI_BASEDIR)/.stamp: + @echo "Downloading rollups-contracts artifacts" + @mkdir -p $(ROLLUPS_CONTRACTS_ABI_BASEDIR) + @curl -sSL $(CONTRACTS_URL)/v$(CONTRACTS_VERSION)/$(CONTRACTS_ARTIFACT) -o $(CONTRACTS_ARTIFACT) + @echo "$(CONTRACTS_SHA256) $(CONTRACTS_ARTIFACT)" | shasum -a 256 --check > /dev/null + @tar -zxf $(CONTRACTS_ARTIFACT) -C $(ROLLUPS_CONTRACTS_ABI_BASEDIR) + @touch $@ + @rm $(CONTRACTS_ARTIFACT) migrate: ## Run migration on development database @echo "Running PostgreSQL migration" @@ -122,7 +132,8 @@ clean-go: ## Clean Go artifacts clean-contracts: ## Clean contract artifacts @echo "Cleaning contract artifacts" - @cd rollups-contracts && rm -rf artifacts cache export/artifacts node_modules src && git checkout . + @rm -rf $(ROLLUPS_CONTRACTS_ABI_BASEDIR)/{.stamp,*} + @rmdir -p $(ROLLUPS_CONTRACTS_ABI_BASEDIR) clean-docs: ## Clean the documentation @echo "Cleaning the documentation" diff --git a/cmd/cartesi-rollups-cli/root/app/deploy/deploy.go b/cmd/cartesi-rollups-cli/root/app/deploy/deploy.go index 987e9e130..9761659ff 100644 --- a/cmd/cartesi-rollups-cli/root/app/deploy/deploy.go +++ b/cmd/cartesi-rollups-cli/root/app/deploy/deploy.go @@ -106,7 +106,7 @@ func init() { &appFactoryAddr, "app-factory", "a", - "0x1d4CfBD2622d802A07CeB4C3401Bbb455c9dbdC3", + "0xd7d4d184b82b1a4e08f304DDaB0A2A7a301C2620", "Application Factory Address", ) diff --git a/rollups-contracts b/rollups-contracts deleted file mode 160000 index c789e04fa..000000000 --- a/rollups-contracts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c789e04fabc4120c9bbe2e84d967faa9f1bc224e diff --git a/test/devnet/Dockerfile b/test/devnet/Dockerfile index 243592f1c..5644921d9 100644 --- a/test/devnet/Dockerfile +++ b/test/devnet/Dockerfile @@ -1,7 +1,12 @@ ARG EMULATOR_VERSION=0.18.1 -ARG FOUNDRY_NIGHTLY_VERSION=9dbfb2f1115466b28f2697e158131f90df6b2590 +ARG FOUNDRY_NIGHTLY_VERSION=2044faec64f99a21f0e5f0094458a973612d0712 +ARG CONTRACTS_VERSION=2.0.0-rc.12 +ARG DEVNET_BUILD_PATH=/opt/cartesi/rollups-contracts -FROM cartesi/machine-emulator:${EMULATOR_VERSION} AS devnet-base +FROM cartesi/machine-emulator:${EMULATOR_VERSION} AS rollups-node-devnet +ARG FOUNDRY_NIGHTLY_VERSION +ARG CONTRACTS_VERSION +ARG DEVNET_BUILD_PATH USER root @@ -10,83 +15,48 @@ ENV DEBIAN_FRONTEND=noninteractive RUN < ${DEVNET_BUILD_PATH}/deployment.jq + . as $root | .contracts | + reduce to_entries[] as $c ( + {"name": $root.name, "ChainId": $root.chainId | tonumber}; + . + {($c.key): ($c.value.address)} + ) EOF -COPY rollups-contracts /opt/cartesi/rollups-contracts - RUN < anvil.log 2>&1 & - ANVIL_PID=$! - pnpm install - if ! pnpm run deploy:development; then - echo "Failed to deploy contracts" - cat anvil.log - exit 1 - fi - cd deployments/localhost - jq -c -n --argjson chainId $(cat .chainId) '[inputs | { (input_filename | gsub(".*/|[.]json$"; "")) : .address }] | add | .ChainId = $chainId' *.json > ../../deployment.json - kill -15 ${ANVIL_PID} - elapsed=0 - TIMEOUT=30 - while kill -0 ${ANVIL_PID} 2>/dev/null; do - if [ $elapsed -ge $TIMEOUT ]; then - echo "Error: Anvil state dump timed out after ${TIMEOUT} seconds" >&2 - exit 1 - fi - sleep 1 - elapsed=$((elapsed + 1)) - done + URL=https://github.com/cartesi/rollups-contracts/releases/download + VERSION=v${CONTRACTS_VERSION} + ARTIFACT=rollups-contracts-${CONTRACTS_VERSION}-anvil-nightly-${FOUNDRY_NIGHTLY_VERSION}.tar.gz + curl -sSL ${URL}/${VERSION}/${ARTIFACT} -o /tmp/contracts.tar.gz + echo "691d229e16b866f97ee5cf27b88573d8434f064a959061c8755e91a048c2a811 /tmp/contracts.tar.gz" | sha256sum --check + tar -zxf /tmp/contracts.tar.gz -C ${DEVNET_BUILD_PATH}/ + mkdir -p /usr/share/devnet + jq -cf ${DEVNET_BUILD_PATH}/deployment.jq < ${DEVNET_BUILD_PATH}/localhost.json > /usr/share/devnet/deployment.json + mv ${DEVNET_BUILD_PATH}/state.json /usr/share/devnet/anvil_state.json EOF -# ============================================================================= -# STAGE: rollups-node-devnet -# -# This stage contains the Ethereum node that the rollups node uses for testing. -# It copies the anvil state from the builder stage and starts the local anvil -# instance. -# -# It also requires the machine-snapshot built in the snapshot-builder stage. -# ============================================================================= - -FROM devnet-base AS rollups-node-devnet - -# Copy anvil state file and devnet deployment info. -ARG DEVNET_BUILD_PATH=/opt/cartesi/rollups-contracts -COPY --from=devnet-deployer ${DEVNET_BUILD_PATH}/anvil_state.json /usr/share/devnet/anvil_state.json -COPY --from=devnet-deployer ${DEVNET_BUILD_PATH}/deployment.json /usr/share/devnet/deployment.json - HEALTHCHECK --interval=1s --timeout=1s --retries=5 \ CMD curl \ -X \ diff --git a/test/devnet/Dockerfile.dockerignore b/test/devnet/Dockerfile.dockerignore index 3786b6e30..f827f7d51 100644 --- a/test/devnet/Dockerfile.dockerignore +++ b/test/devnet/Dockerfile.dockerignore @@ -24,3 +24,4 @@ cartesi-rollups-authority-claimer cartesi-rollups-cli cartesi-rollups-evm-reader cartesi-rollups-node +/rollups-contracts