Skip to content

Commit

Permalink
feat(contracts): migrate to 2.0.0-rc.12, use artifacts, remove submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Nov 1, 2024
1 parent 1bd233b commit 20cc5ac
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 90 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cartesi-rollups-evm-reader
cartesi-rollups-node
cartesi-rollups-advancer
cartesi-rollups-validator
/rollups-contracts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ machine-snapshot/**
/cartesi-rollups-advancer
/cartesi-rollups-validator
/cartesi-rollups-claimer
/rollups-contracts
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
[submodule "rollups-contracts"]
path = rollups-contracts
url = https://github.com/cartesi/rollups-contracts
branch = v2.0.0-rc.6
16 changes: 0 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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

Expand Down
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -86,7 +90,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/...

Expand All @@ -99,11 +103,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"
Expand All @@ -122,7 +131,7 @@ 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

clean-docs: ## Clean the documentation
@echo "Cleaning the documentation"
Expand Down
2 changes: 1 addition & 1 deletion cmd/cartesi-rollups-cli/root/app/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func init() {
&appFactoryAddr,
"app-factory",
"a",
"0x1d4CfBD2622d802A07CeB4C3401Bbb455c9dbdC3",
"0xd7d4d184b82b1a4e08f304DDaB0A2A7a301C2620",
"Application Factory Address",
)

Expand Down
1 change: 0 additions & 1 deletion rollups-contracts
Submodule rollups-contracts deleted from c789e0
94 changes: 32 additions & 62 deletions test/devnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,83 +15,48 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -e
apt-get update
apt-get install -y --no-install-recommends ca-certificates curl git
apt-get install -y --no-install-recommends ca-certificates curl git jq
EOF

# Install Foundry from downloaded pre-compiled binaries.
ARG FOUNDRY_NIGHTLY_VERSION
RUN <<EOF
set -ex
set -e
URL=https://github.com/foundry-rs/foundry/releases/download
VERSION=nightly-${FOUNDRY_NIGHTLY_VERSION}
ARCH=$(dpkg --print-architecture)
ARTIFACT=foundry_nightly_linux_${ARCH}.tar.gz
curl -sSL ${URL}/${VERSION}/${ARTIFACT} | tar -zx -C /usr/local/bin
curl -sSL ${URL}/${VERSION}/${ARTIFACT} -o /tmp/foundry.tar.gz
case $ARCH in
amd64) echo "c53d77f7f0266ef8bc9daf8d4a8ce39ca5fdce859b5d028b1e55bded7da687e2 /tmp/foundry.tar.gz" | shasum -a 256 --check ;;
arm64) echo "5fe5913841c56b79ee5c15aefc2e9730bd6beb07cba0e2112447b822d78b079d /tmp/foundry.tar.gz" | shasum -a 256 --check ;;
esac
tar -zxf /tmp/foundry.tar.gz -C /usr/local/bin
EOF

# =============================================================================
# STAGE: devnet-deployer
#
# This stage builds the devnet state that will be loaded in Anvil.
# =============================================================================

FROM devnet-base AS devnet-deployer

# Install nodejs & pnpm.
ENV DEBIAN_FRONTEND=noninteractive
RUN <<EOF
set -e
apt-get install -y --no-install-recommends gnupg jq
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y --no-install-recommends nodejs
npm install -g @pnpm/exe
# Install anvil state file and devnet deployment info.
RUN mkdir -p ${DEVNET_BUILD_PATH}
RUN cat <<'EOF' > ${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 <<EOF
set -e
cd /opt/cartesi/rollups-contracts
anvil --preserve-historical-states --dump-state=anvil_state.json > 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 \
Expand Down
1 change: 1 addition & 0 deletions test/devnet/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ cartesi-rollups-authority-claimer
cartesi-rollups-cli
cartesi-rollups-evm-reader
cartesi-rollups-node
/rollups-contracts

0 comments on commit 20cc5ac

Please sign in to comment.