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 88730e0 commit 9811c0f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ machine-snapshot/**
/cartesi-rollups-advancer
/cartesi-rollups-validator
/cartesi-rollups-claimer
/rollups-contracts
rollups-contracts-*-artifacts.tar.gz
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
18 changes: 13 additions & 5 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 @@ -101,9 +105,13 @@ check-generate: generate ## Check whether the generated files are in sync

contracts: $(ROLLUPS_CONTRACTS_ABI_BASEDIR) ## 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)" | sha256sum --check
tar -zxf $(CONTRACTS_ARTIFACT) -C $(ROLLUPS_CONTRACTS_ABI_BASEDIR)
@touch $@

migrate: ## Run migration on development database
@echo "Running PostgreSQL migration"
Expand All @@ -122,7 +130,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_ABI_BASEDIR)

clean-docs: ## Clean the documentation
@echo "Cleaning the documentation"
Expand Down
1 change: 0 additions & 1 deletion rollups-contracts
Submodule rollups-contracts deleted from c789e0
82 changes: 34 additions & 48 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 devnet-base
ARG FOUNDRY_NIGHTLY_VERSION
ARG CONTRACTS_VERSION
ARG DEVNET_BUILD_PATH

USER root

Expand All @@ -10,64 +15,45 @@ 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" | sha256sum --check ;;
arm64) echo "5fe5913841c56b79ee5c15aefc2e9730bd6beb07cba0e2112447b822d78b079d /tmp/foundry.tar.gz" | sha256sum --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};
. + {($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}/
jq -f ${DEVNET_BUILD_PATH}/deployment.jq < ${DEVNET_BUILD_PATH}/localhost.json > ${DEVNET_BUILD_PATH}/deployment.json
EOF

# =============================================================================
Expand All @@ -81,11 +67,11 @@ EOF
# =============================================================================

FROM devnet-base AS rollups-node-devnet
ARG DEVNET_BUILD_PATH

# 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
COPY --from=devnet-base ${DEVNET_BUILD_PATH}/state.json /usr/share/devnet/anvil_state.json
COPY --from=devnet-base ${DEVNET_BUILD_PATH}/deployment.json /usr/share/devnet/deployment.json

HEALTHCHECK --interval=1s --timeout=1s --retries=5 \
CMD curl \
Expand Down

0 comments on commit 9811c0f

Please sign in to comment.