Skip to content

Commit 3944ae4

Browse files
authored
Add basic bitacross worker ci integration tests (#2934)
* rpc method for checking musig2 ceremony correctness * test sign_bitcoin by enclave account * ts code to test sign_bitcoin * build bitacross docker image * add bitacross integration tests * enable enclave tests * adjust test * add reject unauthorized to ws client * increase wait time for workers startup * update filefilter * trigger bitacross rebuild * remove bitacross cache
1 parent 1b73b8a commit 3944ae4

File tree

14 files changed

+1160
-16
lines changed

14 files changed

+1160
-16
lines changed

.github/file-filter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bitacross_src: &bitacross_src
4747
- 'bitacross-worker/build.Dockerfile'
4848
- 'bitacross-worker/enclave-runtime/**'
4949

50-
bitacross_test: &bitacross_src
50+
bitacross_test: &bitacross_test
5151
- 'bitacross-worker/ts-tests/**'
5252
- 'bitacross-worker/cli/*.sh'
5353
- 'docker/**'

.github/workflows/ci.yml

Lines changed: 164 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ on:
5555
description: rebuild-tee-docker
5656
required: true
5757
default: true
58+
rebuild-bitacross-docker:
59+
type: boolean
60+
description: rebuild-bitacross-docker
61+
required: true
62+
default: true
5863
push-docker:
5964
type: boolean
6065
description: push-docker
@@ -140,7 +145,7 @@ jobs:
140145
echo "push_docker=$push_docker" | tee -a $GITHUB_OUTPUT
141146
echo "run_parachain_test=$run_parachain_test" | tee -a $GITHUB_OUTPUT
142147
echo "run_tee_test=$run_tee_test" | tee -a $GITHUB_OUTPUT
143-
echo "run_bitacross_test=$$run_tee_test" | tee -a $GITHUB_OUTPUT
148+
echo "run_bitacross_test=$run_bitacross_test" | tee -a $GITHUB_OUTPUT
144149
145150
fmt:
146151
runs-on: ubuntu-latest
@@ -511,6 +516,88 @@ jobs:
511516
if: failure()
512517
uses: andymckay/cancel-action@0.5
513518

519+
bitacross-build:
520+
runs-on: ubuntu-latest
521+
needs:
522+
- fmt
523+
- set-condition
524+
- sequentialise
525+
steps:
526+
- name: Free up disk space
527+
if: startsWith(runner.name, 'GitHub Actions')
528+
uses: jlumbroso/free-disk-space@main
529+
with:
530+
tool-cache: true
531+
swap-storage: false
532+
large-packages: false
533+
534+
- uses: actions/checkout@v4
535+
536+
- name: Set up Docker Buildx
537+
uses: docker/setup-buildx-action@v3
538+
with:
539+
# use the docker driver to access the local image
540+
# we don't need external caches or multi platforms here
541+
# see https://docs.docker.com/build/drivers/
542+
driver: docker
543+
544+
- name: Build local builder
545+
if: needs.set-condition.outputs.rebuild_bitacross == 'true'
546+
uses: docker/build-push-action@v6
547+
with:
548+
context: .
549+
file: bitacross-worker/build.Dockerfile
550+
tags: local-builder:latest
551+
target: builder
552+
build-args: |
553+
WORKER_MODE_ARG=offchain-worker
554+
ADDITIONAL_FEATURES_ARG=
555+
556+
- name: Build worker
557+
if: needs.set-condition.outputs.rebuild_bitacross == 'true'
558+
uses: docker/build-push-action@v6
559+
with:
560+
context: .
561+
file: bitacross-worker/build.Dockerfile
562+
tags: litentry/bitacross-worker:latest
563+
target: deployed-worker
564+
565+
- name: Build cli
566+
if: needs.set-condition.outputs.rebuild_bitacross == 'true'
567+
uses: docker/build-push-action@v6
568+
with:
569+
context: .
570+
file: bitacross-worker/build.Dockerfile
571+
tags: litentry/bitacross-cli:latest
572+
target: deployed-client
573+
574+
- name: Pull and tag worker and cli image optionally
575+
if: needs.set-condition.outputs.rebuild_bitacross == 'false'
576+
run: |
577+
docker pull litentry/bitacross-worker:latest
578+
docker pull litentry/bitacross-cli:latest
579+
580+
- run: docker images --all
581+
582+
- name: Test enclave
583+
if: needs.set-condition.outputs.rebuild_bitacross == 'true'
584+
# cargo test is not supported in the enclave
585+
# see https://github.com/apache/incubator-teaclave-sgx-sdk/issues/232
586+
run: docker run litentry/bitacross-worker:latest test --all
587+
588+
- name: Save docker images
589+
run: docker save litentry/bitacross-worker:latest litentry/bitacross-cli:latest | gzip > litentry-bitacross.tar.gz
590+
591+
- name: Upload docker images
592+
uses: actions/upload-artifact@v4
593+
with:
594+
name: litentry-bitacross
595+
path: litentry-bitacross.tar.gz
596+
if-no-files-found: error
597+
- name: Fail early
598+
if: failure()
599+
uses: andymckay/cancel-action@0.5
600+
514601
parachain-ts-test:
515602
runs-on: ubuntu-latest
516603
needs:
@@ -806,6 +893,82 @@ jobs:
806893
if-no-files-found: ignore
807894
retention-days: 3
808895

896+
bitacross-worker-test:
897+
runs-on: ubuntu-latest
898+
needs:
899+
- set-condition
900+
- parachain-build-dev
901+
- bitacross-build
902+
strategy:
903+
fail-fast: false
904+
matrix:
905+
include:
906+
- test_name: lit-sign-bitcoin
907+
steps:
908+
- uses: actions/checkout@v4
909+
910+
- name: Pull polkadot image
911+
run: |
912+
docker pull parity/polkadot
913+
914+
- uses: actions/download-artifact@v4
915+
with:
916+
name: litentry-parachain-dev
917+
918+
- uses: actions/download-artifact@v4
919+
with:
920+
name: litentry-bitacross
921+
922+
- name: Load docker image
923+
run: |
924+
docker load < litentry-parachain-dev.tar.gz
925+
docker load < litentry-bitacross.tar.gz
926+
docker images
927+
928+
- name: Enable corepack and pnpm
929+
run: corepack enable && corepack enable pnpm
930+
931+
- name: Generate parachain artefacts
932+
run: |
933+
./tee-worker/scripts/litentry/generate_parachain_artefacts.sh
934+
ls -l docker/generated-rococo/
935+
ls -l bitacross-worker/docker/litentry/
936+
937+
- name: Build litentry parachain docker images
938+
run: |
939+
cd tee-worker/docker
940+
docker compose -f litentry-parachain.build.yml build
941+
942+
- name: Integration bitacross worker test ${{ matrix.test_name }}
943+
if: needs.set-condition.outputs.run_bitacross_test == 'true'
944+
timeout-minutes: 40
945+
run: |
946+
cd bitacross-worker/docker
947+
docker compose -f multiworker-docker-compose.yml -f ${{ matrix.test_name }}.yml up --no-build --exit-code-from ${{ matrix.test_name }} ${{ matrix.test_name }}
948+
949+
- name: Stop integration multi worker docker containers
950+
if: needs.set-condition.outputs.run_bitacross_test == 'true'
951+
run: |
952+
cd bitacross-worker/docker
953+
docker compose -f multiworker-docker-compose.yml -f ${{ matrix.test_name }}.yml stop
954+
955+
- name: Collect docker logs if test fails
956+
continue-on-error: true
957+
uses: jwalton/gh-docker-logs@v2
958+
if: failure()
959+
with:
960+
tail: all
961+
dest: docker-logs
962+
963+
- name: Upload docker logs if test fails
964+
uses: actions/upload-artifact@v4
965+
if: failure()
966+
with:
967+
name: ${{ matrix.test_name }}-docker-logs
968+
path: docker-logs
969+
if-no-files-found: ignore
970+
retention-days: 3
971+
809972
# Secrets are not passed to the runner when a workflow is triggered from a forked repository,
810973
# see https://docs.github.com/en/actions/security-guides/encrypted-secrets#using-encrypted-secrets-in-a-workflow
811974
#

bitacross-worker/bitacross/core/bc-task-processor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub fn run_bit_across_handler_runner<SKR, SIGNINGAK, EKR, BKR, S, H, O, RRL, ERL
289289

290290
command_threads_pool.join();
291291
event_threads_pool.join();
292-
warn!("bit_across_task_receiver loop terminated");
292+
warn!("bit_across_handler_runner loop terminated");
293293
}
294294

295295
#[allow(clippy::type_complexity)]

bitacross-worker/build.Dockerfile

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,8 @@ ENV SGX_COMMERCIAL_KEY=$SGX_COMMERCIAL_KEY
5959
WORKDIR $HOME/bitacross-worker
6060
COPY . $HOME
6161

62-
RUN \
63-
if [ "$IMAGE_FOR_RELEASE" = "true" ]; then \
64-
echo "Omit cache for release image"; \
65-
unset RUSTC_WRAPPER; \
66-
make; \
67-
else \
68-
rm -rf /opt/rust/registry/cache && mv /home/ubuntu/worker-cache/registry/cache /opt/rust/registry && \
69-
rm -rf /opt/rust/registry/index && mv /home/ubuntu/worker-cache/registry/index /opt/rust/registry && \
70-
rm -rf /opt/rust/git/db && mv /home/ubuntu/worker-cache/git/db /opt/rust/git && \
71-
rm -rf /opt/rust/sccache && mv /home/ubuntu/worker-cache/sccache /opt/rust && \
72-
make && sccache --show-stats; \
73-
fi
74-
62+
RUN unset RUSTC_WRAPPER;
63+
RUN make
7564
RUN make mrenclave 2>&1 | grep MRENCLAVE | awk '{print $2}' > mrenclave.txt
7665
RUN cargo test --release
7766

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020-2024 Trust Computing GmbH.
4+
5+
set -euo pipefail
6+
7+
while getopts ":p:A:u:W:V:C:" opt; do
8+
case $opt in
9+
p)
10+
NPORT=$OPTARG
11+
;;
12+
A)
13+
WORKER1PORT=$OPTARG
14+
;;
15+
u)
16+
NODEURL=$OPTARG
17+
;;
18+
W)
19+
NODEHTTPURL=$OPTARG
20+
;;
21+
V)
22+
WORKER1URL=$OPTARG
23+
;;
24+
C)
25+
CLIENT_BIN=$OPTARG
26+
;;
27+
esac
28+
done
29+
30+
# Using default port if none given as arguments.
31+
NPORT=${NPORT:-9912}
32+
NODEURL=${NODEURL:-"ws://litentry-node"}
33+
NODEHTTPURL=${NODEHTTPURL:-"http://litentry-node"}
34+
WORKER1PORT=${WORKER1PORT:-2011}
35+
WORKER1URL=${WORKER1URL:-"ws://bitacross-worker-1"}
36+
37+
CLIENT_BIN=${CLIENT_BIN:-"/usr/local/bin/bitacross-cli"}
38+
39+
CLIENT="${CLIENT_BIN} -p ${NPORT} -P ${WORKER1PORT} -u ${NODEURL} -U ${WORKER1URL}"
40+
41+
function usage() {
42+
echo ""
43+
echo "This is a script for bitacross-worker integration ts tests. Pass test name as first argument"
44+
echo ""
45+
}
46+
47+
[ $# -ne 1 ] && (usage; exit 1)
48+
TEST=$1
49+
50+
echo "Using client binary $CLIENT_BIN"
51+
echo "Using node uri $NODEURL:$NPORT"
52+
echo "Using trusted-worker uri $WORKER1URL:$WORKER1PORT"
53+
echo "Using node http uri $NODEHTTPURL:$NPORT"
54+
echo ""
55+
56+
cd /ts-tests
57+
pnpm install
58+
59+
NODE_ENV=staging pnpm --filter integration-tests run test $TEST
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
services:
2+
lit-sign-bitcoin:
3+
image: litentry/bitacross-cli:latest
4+
container_name: litentry-sign-bitcoin-test
5+
volumes:
6+
- ../ts-tests:/ts-tests
7+
- ../cli:/usr/local/worker-cli
8+
build:
9+
context: ..
10+
dockerfile: build.Dockerfile
11+
target: deployed-client
12+
depends_on:
13+
litentry-node:
14+
condition: service_healthy
15+
bitacross-worker-1:
16+
condition: service_healthy
17+
bitacross-worker-2:
18+
condition: service_healthy
19+
bitacross-worker-3:
20+
condition: service_healthy
21+
networks:
22+
- litentry-test-network
23+
entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh sign_bitcoin.test.ts 2>&1' "
24+
restart: "no"
25+
networks:
26+
litentry-test-network:
27+
driver: bridge

bitacross-worker/docker/multiworker-docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,38 @@ services:
162162
-u ws://litentry-node -U ws://bitacross-worker-2 -P 2011 -w 2101 -p 9912 -h 4645
163163
run --dev --skip-ra --request-state"
164164
restart: "no"
165+
bitacross-worker-3:
166+
image: litentry/bitacross-worker:latest
167+
container_name: bitacross-worker-3
168+
build:
169+
context: ${PWD}/..
170+
dockerfile: build.Dockerfile
171+
target: deployed-worker
172+
depends_on:
173+
litentry-node:
174+
condition: service_healthy
175+
bitacross-worker-2:
176+
condition: service_healthy
177+
devices:
178+
- "${SGX_PROVISION:-/dev/null}:/dev/sgx/provision"
179+
- "${SGX_ENCLAVE:-/dev/null}:/dev/sgx/enclave"
180+
volumes:
181+
- "${AESMD:-/dev/null}:/var/run/aesmd"
182+
- "${SGX_QCNL:-/dev/null}:/etc/sgx_default_qcnl.conf"
183+
environment:
184+
- RUST_LOG=info,litentry_worker=debug,ws=warn,sp_io=error,substrate_api_client=warn,itc_parentchain_light_client=info,jsonrpsee_ws_client=warn,jsonrpsee_ws_server=warn,enclave_runtime=debug,ita_stf=debug,its_rpc_handler=warn,itc_rpc_client=warn,its_consensus_common=debug,its_state=warn,its_consensus_aura=warn,aura*=warn,its_consensus_slots=warn,itp_attestation_handler=debug,http_req=debug,lc_mock_server=warn,itc_rest_client=debug,lc_credentials=debug,lc_identity_verification=debug,lc_stf_task_receiver=debug,lc_stf_task_sender=debug,lc_data_providers=debug,itp_top_pool=debug,itc_parentchain_indirect_calls_executor=debug,
185+
networks:
186+
- litentry-test-network
187+
healthcheck:
188+
test: curl -s -f http://bitacross-worker-3:4645/is_initialized || exit 1
189+
interval: 30s
190+
timeout: 10s
191+
retries: 20
192+
entrypoint:
193+
"/usr/local/bin/bitacross-worker --clean-reset --ws-external -M bitacross-worker-3 -T wss://bitacross-worker-3
194+
-u ws://litentry-node -U ws://bitacross-worker-3 -P 2011 -w 2101 -p 9912 -h 4645
195+
run --dev --skip-ra --request-state"
196+
restart: "no"
165197
volumes:
166198
? relaychain-alice
167199
? relaychain-bob
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
NODE_ENV = local
2+
WORKER_ENDPOINT = ws://localhost:2000
3+
NODE_ENDPOINT = ws://localhost:9944
4+
BINARY_DIR=../../bin
5+
LITENTRY_CLI_DIR=../../bin/bitacross-cli
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
NODE_ENV = staging
2+
WORKER_ENDPOINT = ws://bitacross-worker-1:2011
3+
NODE_ENDPOINT = "ws://litentry-node:9912"
4+
BINARY_DIR=/usr/local/bin
5+
LITENTRY_CLI_DIR=/usr/local/bin/bitacross-cli

0 commit comments

Comments
 (0)