Skip to content

Commit

Permalink
Merge pull request #601 from oasisprotocol/matevz/feature/sapphire-mo…
Browse files Browse the repository at this point in the history
…ck-sgx

sapphire-localnet: Use Mock SGX for spinning up Oasis stack
  • Loading branch information
ptrus authored Sep 5, 2024
2 parents 8529fe5 + fa6c4d7 commit 4970ceb
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 118 deletions.
37 changes: 19 additions & 18 deletions .github/workflows/ci-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ jobs:
ports:
- 5432:5432
env:
OASIS_CORE_VERSION: "24.1"
OASIS_NODE: ${{ github.workspace }}/oasis_core/oasis-node
OASIS_NET_RUNNER: ${{ github.workspace }}/oasis_core/oasis-net-runner
OASIS_CORE_VERSION: "24.2"
OASIS_NODE_BINARY: ${{ github.workspace }}/oasis_core/oasis-node
OASIS_NET_RUNNER_BINARY: ${{ github.workspace }}/oasis_core/oasis-net-runner
EMERALD_PARATIME_VERSION: 11.0.0-testnet
GATEWAY__CHAIN_ID: 42260
EMERALD_PARATIME: ${{ github.workspace }}/oasis_core/emerald-paratime
Expand All @@ -56,10 +56,10 @@ jobs:
sudo apt update && sudo apt install bubblewrap unzip -y
wget "https://github.com/oasisprotocol/oasis-core/releases/download/v${OASIS_CORE_VERSION}/oasis_core_${OASIS_CORE_VERSION}_linux_amd64.tar.gz"
tar xfvz "oasis_core_${OASIS_CORE_VERSION}_linux_amd64.tar.gz"
mkdir -p "$(dirname ${OASIS_NODE})"
mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-node" "${OASIS_NODE}"
mkdir -p "$(dirname ${OASIS_NET_RUNNER})"
mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-net-runner" "${OASIS_NET_RUNNER}"
mkdir -p "$(dirname ${OASIS_NODE_BINARY})"
mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-node" "${OASIS_NODE_BINARY}"
mkdir -p "$(dirname ${OASIS_NET_RUNNER_BINARY})"
mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-net-runner" "${OASIS_NET_RUNNER_BINARY}"
mkdir -p "$(dirname ${EMERALD_PARATIME})"
wget "https://github.com/oasisprotocol/emerald-paratime/releases/download/v${EMERALD_PARATIME_VERSION}/localnet-emerald-paratime.orc" -O "${EMERALD_PARATIME}.orc"
unzip "${EMERALD_PARATIME}.orc"
Expand All @@ -68,7 +68,7 @@ jobs:
- name: Spinup oasis-node
run:
PARATIME="${EMERALD_PARATIME}" PARATIME_VERSION="${EMERALD_PARATIME_VERSION}" tests/tools/spinup-oasis-stack.sh > /dev/null &
PARATIME_BINARY="${EMERALD_PARATIME}" PARATIME_VERSION="${EMERALD_PARATIME_VERSION}" tests/tools/spinup-oasis-stack.sh > /dev/null &
sleep 60

- name: Unit tests with coverage
Expand Down Expand Up @@ -106,14 +106,14 @@ jobs:
ports:
- 5432:5432
env:
OASIS_CORE_VERSION: "24.1"
OASIS_NODE: ${{ github.workspace }}/oasis_core/oasis-node
OASIS_NET_RUNNER: ${{ github.workspace }}/oasis_core/oasis-net-runner
SAPPHIRE_PARATIME_VERSION: 0.8.1-testnet
OASIS_CORE_VERSION: "24.2"
OASIS_NODE_BINARY: ${{ github.workspace }}/oasis_core/oasis-node
OASIS_NET_RUNNER_BINARY: ${{ github.workspace }}/oasis_core/oasis-net-runner
SAPPHIRE_PARATIME_VERSION: 0.8.2-testnet
GATEWAY__CHAIN_ID: 23293
GATEWAY__OASIS_RPCS: true
SAPPHIRE_PARATIME: ${{ github.workspace }}/oasis_core/sapphire-paratime
KEYMANAGER_ARTIFACT_URL: https://buildkite.com/organizations/oasisprotocol/pipelines/oasis-core-ci/builds/13622/jobs/018fb976-afd1-442d-a628-7b61a0c234a5/artifacts/018fb97b-3100-4035-b1ca-4295076e9ec3 # Find this at https://buildkite.com/oasisprotocol/oasis-core-ci/builds?branch=stable%2F<...> under "Build runtimes".
KEYMANAGER_ARTIFACT_URL: https://buildkite.com/organizations/oasisprotocol/pipelines/oasis-core-ci/builds/14038/jobs/0191c151-b95b-402c-9854-4e58effc95ab/artifacts/0191c156-f366-45b2-819b-e1eb9fd9ba16 # Find this at https://buildkite.com/oasisprotocol/oasis-core-ci/builds?branch=stable%2F<...> under "Build runtimes": simple-keymanager.mocksgx.
KEYMANAGER_BINARY: ${{ github.workspace }}/oasis_core/simple-keymanager
OASIS_NODE_DATADIR: /tmp/eth-runtime-test
steps:
Expand All @@ -131,10 +131,10 @@ jobs:
# oasis-core
wget "https://github.com/oasisprotocol/oasis-core/releases/download/v${OASIS_CORE_VERSION}/oasis_core_${OASIS_CORE_VERSION}_linux_amd64.tar.gz"
tar xfvz "oasis_core_${OASIS_CORE_VERSION}_linux_amd64.tar.gz"
mkdir -p "$(dirname ${OASIS_NODE})"
mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-node" "${OASIS_NODE}"
mkdir -p "$(dirname ${OASIS_NET_RUNNER})"
mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-net-runner" "${OASIS_NET_RUNNER}"
mkdir -p "$(dirname ${OASIS_NODE_BINARY})"
mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-node" "${OASIS_NODE_BINARY}"
mkdir -p "$(dirname ${OASIS_NET_RUNNER_BINARY})"
mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-net-runner" "${OASIS_NET_RUNNER_BINARY}"
mkdir -p "$(dirname ${SAPPHIRE_PARATIME})"
# sapphire-paratime
wget "https://github.com/oasisprotocol/sapphire-paratime/releases/download/v${SAPPHIRE_PARATIME_VERSION}/localnet-sapphire-paratime.orc" -O "${SAPPHIRE_PARATIME}.orc"
Expand All @@ -146,7 +146,7 @@ jobs:
- name: Spinup oasis-node
run:
PARATIME="${SAPPHIRE_PARATIME}" PARATIME_VERSION="${SAPPHIRE_PARATIME_VERSION}" tests/tools/spinup-oasis-stack.sh > /dev/null &
PARATIME_BINARY="${SAPPHIRE_PARATIME}" PARATIME_VERSION="${SAPPHIRE_PARATIME_VERSION}" OASIS_UNSAFE_SKIP_AVR_VERIFY=1 OASIS_UNSAFE_ALLOW_DEBUG_ENCLAVES=1 OASIS_UNSAFE_MOCK_SGX=1 tests/tools/spinup-oasis-stack.sh > /dev/null &
sleep 60

- name: Unit tests with coverage
Expand All @@ -165,6 +165,7 @@ jobs:
name: oasis-node-logs-c10l
path: |
${{ env.OASIS_NODE_DATADIR }}/**/*.log
${{ env.OASIS_NODE_DATADIR }}/**/config.yaml
${{ env.OASIS_NODE_DATADIR }}/fixture.json
- name: Upload to codecov.io
Expand Down
30 changes: 15 additions & 15 deletions docker/common/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# ParaTime.
# Mandatory ENV Variables:
# - all ENV variables required by spinup-oasis-stack.sh
# - OASIS_WEB3_GATEWAY: path to oasis-web3-gateway binary
# - OASIS_WEB3_GATEWAY_BINARY: path to oasis-web3-gateway binary
# - OASIS_WEB3_GATEWAY_CONFIG_FILE: path to oasis-web3-gateway config file
# - OASIS_DEPOSIT: path to oasis-deposit binary
# - OASIS_DEPOSIT_BINARY: path to oasis-deposit binary
# - BEACON_BACKEND: beacon epoch transition mode 'mock' (default) or 'default'
# - OASIS_SINGLE_COMPUTE_NODE: (default: true) if non-empty only run a single compute node

Expand All @@ -21,8 +21,8 @@ export OASIS_DOCKER_DEBUG_DISK_AND_CPU_USAGE=${OASIS_DOCKER_DEBUG_DISK_AND_CPU_U

export OASIS_SINGLE_COMPUTE_NODE=${OASIS_SINGLE_COMPUTE_NODE:-1}

OASIS_WEB3_GATEWAY_VERSION=$(${OASIS_WEB3_GATEWAY} -v | head -n1 | cut -d " " -f 3 | sed -r 's/^v//')
OASIS_CORE_VERSION=$(${OASIS_NODE} -v | head -n1 | cut -d " " -f 3 | sed -r 's/^v//')
OASIS_WEB3_GATEWAY_VERSION=$(${OASIS_WEB3_GATEWAY_BINARY} -v | head -n1 | cut -d " " -f 3 | sed -r 's/^v//')
OASIS_CORE_VERSION=$(${OASIS_NODE_BINARY} -v | head -n1 | cut -d " " -f 3 | sed -r 's/^v//')
VERSION=$(cat /VERSION)

echo "${PARATIME_NAME}-localnet ${VERSION} (oasis-core: ${OASIS_CORE_VERSION}, ${PARATIME_NAME}-paratime: ${PARATIME_VERSION}, oasis-web3-gateway: ${OASIS_WEB3_GATEWAY_VERSION})"
Expand Down Expand Up @@ -126,7 +126,7 @@ if [[ $OASIS_DOCKER_NO_GATEWAY == 'yes' ]]; then
notice "Skipping oasis-web3-gateway start-up...\n"
else
notice "Starting oasis-web3-gateway...\n"
${OASIS_WEB3_GATEWAY} --config ${OASIS_WEB3_GATEWAY_CONFIG_FILE} 2>1 &>/var/log/oasis-web3-gateway.log &
${OASIS_WEB3_GATEWAY_BINARY} --config ${OASIS_WEB3_GATEWAY_CONFIG_FILE} 2>1 &>/var/log/oasis-web3-gateway.log &
OASIS_WEB3_GATEWAY_PID=$!
fi

Expand All @@ -135,27 +135,27 @@ notice "Bootstrapping network (this might take a minute)"
if [[ ${BEACON_BACKEND} == 'mock' ]]; then
echo -n .
notice_debug -l "Waiting for nodes to be ready..."
${OASIS_NODE} debug control wait-nodes -n 2 -a unix:${OASIS_NODE_SOCKET}
${OASIS_NODE_BINARY} debug control wait-nodes -n 2 -a unix:${OASIS_NODE_SOCKET}

echo -n .
notice_debug -l "Setting epoch to 1..."
${OASIS_NODE} debug control set-epoch --epoch 1 -a unix:${OASIS_NODE_SOCKET}
${OASIS_NODE_BINARY} debug control set-epoch --epoch 1 -a unix:${OASIS_NODE_SOCKET}

# Transition to the final epoch when the KM generates ephemeral secret.
if [[ ${PARATIME_NAME} == 'sapphire' ]]; then
notice_debug -l "Waiting for key manager to generate ephemeral secret..."
while (${OASIS_NODE} control status -a unix:${OASIS_KM_SOCKET} | jq -e ".keymanager.secrets.worker.ephemeral_secrets.last_generated_epoch!=2" >/dev/null); do
while (${OASIS_NODE_BINARY} control status -a unix:${OASIS_KM_SOCKET} | jq -e ".keymanager.secrets.worker.ephemeral_secrets.last_generated_epoch!=2" >/dev/null); do
sleep 0.5
done
fi

echo -n .
notice_debug -l "Setting epoch to 2..."
${OASIS_NODE} debug control set-epoch --epoch 2 -a unix:${OASIS_NODE_SOCKET}
${OASIS_NODE_BINARY} debug control set-epoch --epoch 2 -a unix:${OASIS_NODE_SOCKET}
else
echo -n ...
notice_debug -l "Waiting for nodes to be ready..."
${OASIS_NODE} debug control wait-ready -a unix:${OASIS_NODE_SOCKET}
${OASIS_NODE_BINARY} debug control wait-ready -a unix:${OASIS_NODE_SOCKET}
fi
echo

Expand All @@ -169,9 +169,9 @@ if [[ $OASIS_DOCKER_NO_GATEWAY != 'yes' && $PARATIME_NAME == 'sapphire' ]]; then
}
until is_km_ready; do
if [[ ${BEACON_BACKEND} == 'mock' ]]; then
epoch=`${OASIS_NODE} control status -a unix:${OASIS_NODE_SOCKET} | jq '.consensus.latest_epoch'`
epoch=`${OASIS_NODE_BINARY} control status -a unix:${OASIS_NODE_SOCKET} | jq '.consensus.latest_epoch'`
epoch=$((epoch + 1))
${OASIS_NODE} debug control set-epoch --epoch $epoch -a unix:${OASIS_NODE_SOCKET}
${OASIS_NODE_BINARY} debug control set-epoch --epoch $epoch -a unix:${OASIS_NODE_SOCKET}
fi

echo -n .
Expand All @@ -184,7 +184,7 @@ else
fi

notice "Populating accounts...\n\n"
${OASIS_DEPOSIT} -sock unix:${OASIS_NODE_SOCKET} "$@"
${OASIS_DEPOSIT_BINARY} -sock unix:${OASIS_NODE_SOCKET} "$@"

T_END="$(date +%s)"

Expand Down Expand Up @@ -223,9 +223,9 @@ if [[ ${BEACON_BACKEND} == 'mock' ]]; then

sleep $((60*10))

epoch=`${OASIS_NODE} control status -a unix:${OASIS_NODE_SOCKET} | jq '.consensus.latest_epoch'`
epoch=`${OASIS_NODE_BINARY} control status -a unix:${OASIS_NODE_SOCKET} | jq '.consensus.latest_epoch'`
epoch=$((epoch + 1))
${OASIS_NODE} debug control set-epoch --epoch $epoch -a unix:${OASIS_NODE_SOCKET}
${OASIS_NODE_BINARY} debug control set-epoch --epoch $epoch -a unix:${OASIS_NODE_SOCKET}
done
else
wait
Expand Down
31 changes: 16 additions & 15 deletions docker/emerald-localnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build oasis-web3-gateway
FROM golang:1.22 AS oasis-web3-gateway
FROM golang:1.22.3 AS oasis-web3-gateway

COPY . /go/oasis-web3-gateway
RUN cd oasis-web3-gateway && make && strip -S -x oasis-web3-gateway docker/common/oasis-deposit/oasis-deposit
Expand All @@ -10,42 +10,43 @@ RUN apk add --no-cache bash gcompat libseccomp jq binutils \
&& su -c "POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres /usr/local/bin/docker-entrypoint.sh postgres &" postgres

# Docker-specific variables
ENV OASIS_CORE_VERSION=24.0
ENV OASIS_CLI_VERSION=0.8.1
ENV OASIS_CORE_VERSION=24.2
ENV OASIS_CLI_VERSION=0.10.0
ENV PARATIME_VERSION=11.0.0-testnet
ENV PARATIME_NAME=emerald
ENV GATEWAY__CHAIN_ID=0xa514

# start.sh and spinup-oasis-stack.sh ENV variables.
ENV OASIS_NODE=/oasis-node
ENV OASIS_NET_RUNNER=/oasis-net-runner
ENV OASIS_NODE_BINARY=/oasis-node
ENV OASIS_NET_RUNNER_BINARY=/oasis-net-runner
ENV OASIS_NODE_DATADIR=/serverdir/node
ENV OASIS_WEB3_GATEWAY=/oasis-web3-gateway
ENV OASIS_DEPOSIT=/oasis-deposit
ENV OASIS_WEB3_GATEWAY_BINARY=/oasis-web3-gateway
ENV OASIS_DEPOSIT_BINARY=/oasis-deposit
ENV OASIS_WEB3_GATEWAY_CONFIG_FILE=/localnet.yml
ENV PARATIME=/runtime.elf
ENV PARATIME_BINARY=/runtime.elf
ENV KEYMANAGER_BINARY=""
ENV OASIS_CLI_BINARY=/oasis

ARG VERSION

# oasis-web3-gateway binary, config, spinup-* scripts and staking_genesis.json.
COPY --from=oasis-web3-gateway /go/oasis-web3-gateway/oasis-web3-gateway ${OASIS_WEB3_GATEWAY}
COPY --from=oasis-web3-gateway /go/oasis-web3-gateway/docker/common/oasis-deposit/oasis-deposit ${OASIS_DEPOSIT}
COPY --from=oasis-web3-gateway /go/oasis-web3-gateway/oasis-web3-gateway ${OASIS_WEB3_GATEWAY_BINARY}
COPY --from=oasis-web3-gateway /go/oasis-web3-gateway/docker/common/oasis-deposit/oasis-deposit ${OASIS_DEPOSIT_BINARY}
COPY docker/common/localnet.yml ${OASIS_WEB3_GATEWAY_CONFIG_FILE}
COPY docker/common/start.sh /
COPY tests/tools/* /

# Configure oasis-node and oasis-net-runner.
RUN wget --quiet "https://github.com/oasisprotocol/oasis-core/releases/download/v${OASIS_CORE_VERSION}/oasis_core_${OASIS_CORE_VERSION}_linux_amd64.tar.gz" \
&& tar xfvz "oasis_core_${OASIS_CORE_VERSION}_linux_amd64.tar.gz" \
&& mkdir -p "$(dirname ${OASIS_NODE})" "$(dirname ${OASIS_NET_RUNNER})" \
&& mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-node" "${OASIS_NODE}" \
&& mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-net-runner" "${OASIS_NET_RUNNER}" \
&& mkdir -p "$(dirname ${OASIS_NODE_BINARY})" "$(dirname ${OASIS_NET_RUNNER_BINARY})" \
&& mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-node" "${OASIS_NODE_BINARY}" \
&& mv "oasis_core_${OASIS_CORE_VERSION}_linux_amd64/oasis-net-runner" "${OASIS_NET_RUNNER_BINARY}" \
&& rm "oasis_core_${OASIS_CORE_VERSION}_linux_amd64.tar.gz" \
&& rm -rf "oasis_core_${OASIS_CORE_VERSION}_linux_amd64" \
&& echo "" \
&& echo "Configure the ParaTime." \
&& mkdir -p "$(dirname ${PARATIME})" \
&& mkdir -p "$(dirname ${PARATIME_BINARY})" \
&& wget --quiet "https://github.com/oasisprotocol/${PARATIME_NAME}-paratime/releases/download/v${PARATIME_VERSION}/localnet-${PARATIME_NAME}-paratime.orc" -O "/paratime.orc" \
&& unzip "paratime.orc" \
&& chmod a+x "runtime.elf" \
Expand All @@ -60,7 +61,7 @@ RUN wget --quiet "https://github.com/oasisprotocol/oasis-core/releases/download/
&& echo "" \
&& echo "Write VERSION information." \
&& echo "${VERSION}" > /VERSION \
&& strip -S -x /oasis-net-runner /oasis-node /oasis
&& strip -S -x ${OASIS_NET_RUNNER_BINARY} ${OASIS_NODE_BINARY} ${OASIS_CLI_BINARY}

# Web3 gateway http and ws ports.
EXPOSE 8545/tcp
Expand Down
Loading

0 comments on commit 4970ceb

Please sign in to comment.