From 275a601be5c8b9db4509410b32ea9e05e7188b5b Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Tue, 13 Feb 2024 11:54:23 +0100 Subject: [PATCH 1/4] Add --start-relayer arg --- .../environments/rococo-westend/spawn.sh | 17 +++++++------- .../rococo-westend/start_relayer.sh | 23 +++++++++++++++++++ bridges/zombienet/run-new-test.sh | 4 ++-- .../tests/0001-asset-transfer/run.sh | 2 +- 4 files changed, 34 insertions(+), 12 deletions(-) create mode 100755 bridges/zombienet/environments/rococo-westend/start_relayer.sh diff --git a/bridges/zombienet/environments/rococo-westend/spawn.sh b/bridges/zombienet/environments/rococo-westend/spawn.sh index dbdc58d5fa1b..550eee04bd6e 100755 --- a/bridges/zombienet/environments/rococo-westend/spawn.sh +++ b/bridges/zombienet/environments/rococo-westend/spawn.sh @@ -4,11 +4,11 @@ set -e trap "trap - SIGTERM && kill -9 -$$" SIGINT SIGTERM EXIT -source "${BASH_SOURCE%/*}/../../utils/common.sh" source "${BASH_SOURCE%/*}/../../utils/zombienet.sh" # whether to init the chains (open HRMP channels, set XCM version, create reserve assets, etc) init=0 +start_relayer=0 while [ $# -ne 0 ] do arg="$1" @@ -16,6 +16,9 @@ do --init) init=1 ;; + --start-relayer) + start_relayer=1 + ;; esac shift done @@ -55,17 +58,13 @@ if [[ $init -eq 1 ]]; then run_zndsl ${BASH_SOURCE%/*}/westend-init.zndsl $westend_dir fi -relay_log=$logs_dir/relay.log -echo -e "Starting rococo-westend relay. Logs available at: $relay_log\n" -start_background_process "$helper_script run-relay" $relay_log relay_pid +if [[ $start_relayer -eq 1 ]]; then + ${BASH_SOURCE%/*}/start_relayer.sh $rococo_dir $westend_dir relayer_pid +fi -run_zndsl ${BASH_SOURCE%/*}/rococo.zndsl $rococo_dir echo $rococo_dir > $TEST_DIR/rococo.env -echo - -run_zndsl ${BASH_SOURCE%/*}/westend.zndsl $westend_dir echo $westend_dir > $TEST_DIR/westend.env echo -wait -n $rococo_pid $westend_pid $relay_pid +wait -n $rococo_pid $westend_pid $relayer_pid kill -9 -$$ diff --git a/bridges/zombienet/environments/rococo-westend/start_relayer.sh b/bridges/zombienet/environments/rococo-westend/start_relayer.sh new file mode 100755 index 000000000000..c57d4f1a4374 --- /dev/null +++ b/bridges/zombienet/environments/rococo-westend/start_relayer.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +source "${BASH_SOURCE%/*}/../../utils/common.sh" +source "${BASH_SOURCE%/*}/../../utils/zombienet.sh" + +rococo_dir=$1 +westend_dir=$2 +__relayer_pid=$3 + +logs_dir=$TEST_DIR/logs +helper_script="${BASH_SOURCE%/*}/helper.sh" + +relayer_log=$logs_dir/relayer.log +echo -e "Starting rococo-westend relayer. Logs available at: $relayer_log\n" +start_background_process "$helper_script run-relay" $relayer_log relayer_pid + +run_zndsl ${BASH_SOURCE%/*}/rococo.zndsl $rococo_dir +run_zndsl ${BASH_SOURCE%/*}/westend.zndsl $westend_dir + +eval $__relayer_pid="'$relayer_pid'" + diff --git a/bridges/zombienet/run-new-test.sh b/bridges/zombienet/run-new-test.sh index 3bfcb6d83e9a..2ed2a412b8a7 100755 --- a/bridges/zombienet/run-new-test.sh +++ b/bridges/zombienet/run-new-test.sh @@ -2,6 +2,8 @@ set -e +trap 'kill -9 -$$ || echo "Environment already teared down"' SIGINT SIGTERM EXIT + test=$1 shift @@ -43,5 +45,3 @@ export TEST_DIR=`mktemp -d /tmp/bridges-tests-run-XXXXX` echo -e "Test folder: $TEST_DIR\n" ${BASH_SOURCE%/*}/tests/$test/run.sh - -kill -9 -$$ || echo "Environment already teared down" \ No newline at end of file diff --git a/bridges/zombienet/tests/0001-asset-transfer/run.sh b/bridges/zombienet/tests/0001-asset-transfer/run.sh index 07951a0e321a..8a053ee72097 100755 --- a/bridges/zombienet/tests/0001-asset-transfer/run.sh +++ b/bridges/zombienet/tests/0001-asset-transfer/run.sh @@ -5,7 +5,7 @@ set -e source "${BASH_SOURCE%/*}/../../utils/common.sh" source "${BASH_SOURCE%/*}/../../utils/zombienet.sh" -${BASH_SOURCE%/*}/../../environments/rococo-westend/spawn.sh --init & +${BASH_SOURCE%/*}/../../environments/rococo-westend/spawn.sh --init --start-relayer & env_pid=$! ensure_process_file $env_pid $TEST_DIR/rococo.env 400 From ac0f3640a27a27f3826a3ab5aa946d4f861b4b1c Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Sun, 11 Feb 2024 16:49:23 +0100 Subject: [PATCH 2/4] Migrate test 0002 to new orchestrator --- .gitlab/pipeline/zombienet/bridges.yml | 7 ++++ bridges/zombienet/helpers/utils.js | 3 +- .../rococo-to-westend.zndsl | 8 +++++ .../run.sh | 35 +++++++++++++++++++ .../westend-to-rococo.zndsl | 7 ++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/rococo-to-westend.zndsl create mode 100755 bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh create mode 100644 bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/westend-to-rococo.zndsl diff --git a/.gitlab/pipeline/zombienet/bridges.yml b/.gitlab/pipeline/zombienet/bridges.yml index f2de526c8705..16cabad6ccab 100644 --- a/.gitlab/pipeline/zombienet/bridges.yml +++ b/.gitlab/pipeline/zombienet/bridges.yml @@ -53,3 +53,10 @@ zombienet-bridges-0001-asset-transfer-works: script: - /home/nonroot/bridges-polkadot-sdk/bridges/zombienet/run-new-test.sh 0001-asset-transfer --docker - echo "Done" + +zombienet-bridges-0002-mandatory-headers-synced-while-idle: + extends: + - .zombienet-bridges-common + script: + - /home/nonroot/bridges-polkadot-sdk/bridges/zombienet/run-new-test.sh 0002-mandatory-headers-synced-while-idle --docker + - echo "Done" diff --git a/bridges/zombienet/helpers/utils.js b/bridges/zombienet/helpers/utils.js index 5a5542b56dfc..a0c9b7415df5 100644 --- a/bridges/zombienet/helpers/utils.js +++ b/bridges/zombienet/helpers/utils.js @@ -88,6 +88,7 @@ module.exports = { const bestBridgedParachainHeader = await apiAtParent.query[bridgedChain.parachainsPalletName].parasInfo(bridgedChain.bridgedBridgeHubParaId);; const hasBestBridgedParachainHeader = bestBridgedParachainHeader.isSome; + const oldParachainHeaders = hasBestBridgedParachainHeader ? 1: 0; // we expect to see: no more than `1` bridged parachain header if there were no parachain header before. const maxNewParachainHeaders = hasBestBridgedParachainHeader ? 0 : 1; const newParachainHeaders = module.exports.countParachainHeaderImports(bridgedChain, currentEvents); @@ -98,6 +99,6 @@ module.exports = { throw new Error("Unexpected parachain header import: " + newParachainHeaders + " / " + maxNewParachainHeaders); } - return newParachainHeaders; + return oldParachainHeaders + newParachainHeaders; }, } diff --git a/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/rococo-to-westend.zndsl b/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/rococo-to-westend.zndsl new file mode 100644 index 000000000000..d4283b361296 --- /dev/null +++ b/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/rococo-to-westend.zndsl @@ -0,0 +1,8 @@ +Description: While relayer is idle, we only sync mandatory Rococo (and a single Rococo BH) headers to Westend BH. +Network: ../../../../cumulus/zombienet/bridge-hubs/bridge_hub_westend_local_network.toml +Creds: config + +# ensure that relayer is only syncing mandatory headers while idle. This includes both headers that were +# generated while relay was offline and those in the next 100 seconds while script is active. +bridge-hub-westend-collator1: js-script ../../helpers/only-mandatory-headers-synced-when-idle.js with "300,rococo-at-westend" within 600 seconds + diff --git a/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh b/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh new file mode 100755 index 000000000000..8e22cba874bc --- /dev/null +++ b/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -e + +source "${BASH_SOURCE%/*}/../../utils/common.sh" +source "${BASH_SOURCE%/*}/../../utils/zombienet.sh" + +# We use `--relayer-delay` in order to sleep some time before starting relayer. +# We want to sleep for at least 1 session, which is expected to be 60 seconds for test environment. +${BASH_SOURCE%/*}/../../environments/rococo-westend/spawn.sh & +env_pid=$! + +ensure_process_file $env_pid $TEST_DIR/rococo.env 400 +rococo_dir=`cat $TEST_DIR/rococo.env` +echo + +ensure_process_file $env_pid $TEST_DIR/westend.env 180 +westend_dir=`cat $TEST_DIR/westend.env` +echo + +# Sleep for some time before starting the relayer. We want to sleep for at least 1 session, +# which is expected to be 60 seconds for the test environment. +echo -e "Sleeping 90s before starting relayer ...\n" +sleep 90 +${BASH_SOURCE%/*}/../../environments/rococo-westend/start_relayer.sh $rococo_dir $westend_dir relayer_pid + +# Sometimes the relayer syncs 2 parachain heads in the begining leading to test failures. +# We do this as a workaround. +# TODO: investigate. Not sure if it's expected. +echo -e "Sleeping 90s before runing the tests ...\n" +sleep 90 + +run_zndsl ${BASH_SOURCE%/*}/rococo-to-westend.zndsl $westend_dir +run_zndsl ${BASH_SOURCE%/*}/westend-to-rococo.zndsl $rococo_dir + diff --git a/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/westend-to-rococo.zndsl b/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/westend-to-rococo.zndsl new file mode 100644 index 000000000000..1ea4c92a3458 --- /dev/null +++ b/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/westend-to-rococo.zndsl @@ -0,0 +1,7 @@ +Description: While relayer is idle, we only sync mandatory Westend (and a single Westend BH) headers to Rococo BH. +Network: ../../../../cumulus/zombienet/bridge-hubs/bridge_hub_rococo_local_network.toml +Creds: config + +# ensure that relayer is only syncing mandatory headers while idle. This includes both headers that were +# generated while relay was offline and those in the next 100 seconds while script is active. +bridge-hub-rococo-collator1: js-script ../../helpers/only-mandatory-headers-synced-when-idle.js with "300,westend-at-rococo" within 600 seconds From a07298796bd47199d4a05f3a5b1cfd6126937926 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 14 Feb 2024 10:31:32 +0100 Subject: [PATCH 3/4] fix --- .gitlab/pipeline/zombienet/bridges.yml | 15 +++++++++------ .../only-mandatory-headers-synced-when-idle.js | 6 +++--- bridges/zombienet/helpers/utils.js | 3 +-- .../run.sh | 6 ------ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.gitlab/pipeline/zombienet/bridges.yml b/.gitlab/pipeline/zombienet/bridges.yml index 16cabad6ccab..7a625eefed02 100644 --- a/.gitlab/pipeline/zombienet/bridges.yml +++ b/.gitlab/pipeline/zombienet/bridges.yml @@ -54,9 +54,12 @@ zombienet-bridges-0001-asset-transfer-works: - /home/nonroot/bridges-polkadot-sdk/bridges/zombienet/run-new-test.sh 0001-asset-transfer --docker - echo "Done" -zombienet-bridges-0002-mandatory-headers-synced-while-idle: - extends: - - .zombienet-bridges-common - script: - - /home/nonroot/bridges-polkadot-sdk/bridges/zombienet/run-new-test.sh 0002-mandatory-headers-synced-while-idle --docker - - echo "Done" +# Sometimes the relayer syncs multiple parachain heads in the beginning leading to test failures. +# Issue: https://github.com/paritytech/parity-bridges-common/issues/2838 +# TODO: uncomment test after issue is fixed +#zombienet-bridges-0002-mandatory-headers-synced-while-idle: +# extends: +# - .zombienet-bridges-common +# script: +# - /home/nonroot/bridges-polkadot-sdk/bridges/zombienet/run-new-test.sh 0002-mandatory-headers-synced-while-idle --docker +# - echo "Done" diff --git a/bridges/zombienet/helpers/only-mandatory-headers-synced-when-idle.js b/bridges/zombienet/helpers/only-mandatory-headers-synced-when-idle.js index 3a3432cfaf38..979179245ebe 100644 --- a/bridges/zombienet/helpers/only-mandatory-headers-synced-when-idle.js +++ b/bridges/zombienet/helpers/only-mandatory-headers-synced-when-idle.js @@ -10,7 +10,7 @@ async function run(nodeName, networkInfo, args) { // start listening to new blocks let totalGrandpaHeaders = 0; - let totalParachainHeaders = 0; + let initialParachainHeaderImported = false; api.rpc.chain.subscribeNewHeads(async function (header) { const apiAtParent = await api.at(header.parentHash); const apiAtCurrent = await api.at(header.hash); @@ -22,7 +22,7 @@ async function run(nodeName, networkInfo, args) { apiAtCurrent, currentEvents, ); - totalParachainHeaders += await utils.ensureOnlyInitialParachainHeaderImported( + initialParachainHeaderImported = await utils.ensureOnlyInitialParachainHeaderImported( bridgedChain, apiAtParent, apiAtCurrent, @@ -36,7 +36,7 @@ async function run(nodeName, networkInfo, args) { if (totalGrandpaHeaders == 0) { throw new Error("No bridged relay chain headers imported"); } - if (totalParachainHeaders == 0) { + if (!initialParachainHeaderImported) { throw new Error("No bridged parachain headers imported"); } } diff --git a/bridges/zombienet/helpers/utils.js b/bridges/zombienet/helpers/utils.js index a0c9b7415df5..f6e9f5623b47 100644 --- a/bridges/zombienet/helpers/utils.js +++ b/bridges/zombienet/helpers/utils.js @@ -88,7 +88,6 @@ module.exports = { const bestBridgedParachainHeader = await apiAtParent.query[bridgedChain.parachainsPalletName].parasInfo(bridgedChain.bridgedBridgeHubParaId);; const hasBestBridgedParachainHeader = bestBridgedParachainHeader.isSome; - const oldParachainHeaders = hasBestBridgedParachainHeader ? 1: 0; // we expect to see: no more than `1` bridged parachain header if there were no parachain header before. const maxNewParachainHeaders = hasBestBridgedParachainHeader ? 0 : 1; const newParachainHeaders = module.exports.countParachainHeaderImports(bridgedChain, currentEvents); @@ -99,6 +98,6 @@ module.exports = { throw new Error("Unexpected parachain header import: " + newParachainHeaders + " / " + maxNewParachainHeaders); } - return oldParachainHeaders + newParachainHeaders; + return hasBestBridgedParachainHeader; }, } diff --git a/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh b/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh index 8e22cba874bc..3261b84bb5f0 100755 --- a/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh +++ b/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh @@ -24,12 +24,6 @@ echo -e "Sleeping 90s before starting relayer ...\n" sleep 90 ${BASH_SOURCE%/*}/../../environments/rococo-westend/start_relayer.sh $rococo_dir $westend_dir relayer_pid -# Sometimes the relayer syncs 2 parachain heads in the begining leading to test failures. -# We do this as a workaround. -# TODO: investigate. Not sure if it's expected. -echo -e "Sleeping 90s before runing the tests ...\n" -sleep 90 - run_zndsl ${BASH_SOURCE%/*}/rococo-to-westend.zndsl $westend_dir run_zndsl ${BASH_SOURCE%/*}/westend-to-rococo.zndsl $rococo_dir From 0c4a14d8abd6c528757d09ac2789b2f9f8c23134 Mon Sep 17 00:00:00 2001 From: Serban Iorga Date: Wed, 14 Feb 2024 11:19:31 +0100 Subject: [PATCH 4/4] Add test back to CI --- .gitlab/pipeline/zombienet/bridges.yml | 15 ++++++--------- .../run.sh | 6 ++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitlab/pipeline/zombienet/bridges.yml b/.gitlab/pipeline/zombienet/bridges.yml index 7a625eefed02..16cabad6ccab 100644 --- a/.gitlab/pipeline/zombienet/bridges.yml +++ b/.gitlab/pipeline/zombienet/bridges.yml @@ -54,12 +54,9 @@ zombienet-bridges-0001-asset-transfer-works: - /home/nonroot/bridges-polkadot-sdk/bridges/zombienet/run-new-test.sh 0001-asset-transfer --docker - echo "Done" -# Sometimes the relayer syncs multiple parachain heads in the beginning leading to test failures. -# Issue: https://github.com/paritytech/parity-bridges-common/issues/2838 -# TODO: uncomment test after issue is fixed -#zombienet-bridges-0002-mandatory-headers-synced-while-idle: -# extends: -# - .zombienet-bridges-common -# script: -# - /home/nonroot/bridges-polkadot-sdk/bridges/zombienet/run-new-test.sh 0002-mandatory-headers-synced-while-idle --docker -# - echo "Done" +zombienet-bridges-0002-mandatory-headers-synced-while-idle: + extends: + - .zombienet-bridges-common + script: + - /home/nonroot/bridges-polkadot-sdk/bridges/zombienet/run-new-test.sh 0002-mandatory-headers-synced-while-idle --docker + - echo "Done" diff --git a/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh b/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh index 3261b84bb5f0..423f4a1bcc0f 100755 --- a/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh +++ b/bridges/zombienet/tests/0002-mandatory-headers-synced-while-idle/run.sh @@ -24,6 +24,12 @@ echo -e "Sleeping 90s before starting relayer ...\n" sleep 90 ${BASH_SOURCE%/*}/../../environments/rococo-westend/start_relayer.sh $rococo_dir $westend_dir relayer_pid +# Sometimes the relayer syncs multiple parachain heads in the begining leading to test failures. +# See issue: https://github.com/paritytech/parity-bridges-common/issues/2838. +# TODO: Remove this sleep after the issue is fixed. +echo -e "Sleeping 180s before runing the tests ...\n" +sleep 180 + run_zndsl ${BASH_SOURCE%/*}/rococo-to-westend.zndsl $westend_dir run_zndsl ${BASH_SOURCE%/*}/westend-to-rococo.zndsl $rococo_dir