diff --git a/.gitlab/pipeline/zombienet/bridges.yml b/.gitlab/pipeline/zombienet/bridges.yml index f2de526c870..16cabad6cca 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/environments/rococo-westend/spawn.sh b/bridges/zombienet/environments/rococo-westend/spawn.sh index dbdc58d5fa1..550eee04bd6 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 00000000000..c57d4f1a437 --- /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/helpers/only-mandatory-headers-synced-when-idle.js b/bridges/zombienet/helpers/only-mandatory-headers-synced-when-idle.js index 3a3432cfaf3..979179245eb 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 5a5542b56df..f6e9f5623b4 100644 --- a/bridges/zombienet/helpers/utils.js +++ b/bridges/zombienet/helpers/utils.js @@ -98,6 +98,6 @@ module.exports = { throw new Error("Unexpected parachain header import: " + newParachainHeaders + " / " + maxNewParachainHeaders); } - return newParachainHeaders; + return hasBestBridgedParachainHeader; }, } diff --git a/bridges/zombienet/run-new-test.sh b/bridges/zombienet/run-new-test.sh index 3bfcb6d83e9..2ed2a412b8a 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 07951a0e321..8a053ee7209 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 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 00000000000..d4283b36129 --- /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 00000000000..423f4a1bcc0 --- /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 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 + 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 00000000000..1ea4c92a345 --- /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