tests: regtest: make test_just_in_time less flaky
What changed, and why it matters
This commit only changes a test script. It adds a wait helper so a test that opens two Lightning channels in a row does not fail randomly on continuous integration. There is no change to Electrum's actual wallet or Lightning code, so users are not affected.
No security action needed. Treat as a normal test-stability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies tests/regtest/regtest.sh. It introduces wait_for_chain_tip(), which polls until a named Electrum daemon reports a blockchain_height matching bitcoind’s block count, then calls wait_for_sync. The just_in_time test scenario now calls this helper for ‘bob’ after mining three blocks and before the second JIT channel open. The stated reason is to avoid a race where Bob has not processed the new blocks, causing the second anchor channel open to be refused due to key-derivation constraints. This is purely a test reliability fix.
Changed components
tests/regtest/regtest.shInspect captured patch +23 / −0
diff --git a/tests/regtest/regtest.sh b/tests/regtest/regtest.sh
index f5df1e5..30edab0 100755
--- a/tests/regtest/regtest.sh
+++ b/tests/regtest/regtest.sh
@@ -144,6 +144,28 @@ function wait_until_spent()
printf "\n"
}
+function wait_for_chain_tip()
+{
+ msg="waiting until $1 catches up to chain tip"
+ cmd="./run_electrum --regtest -D /tmp/$1"
+ declare -i timeout_sec=120
+ declare -i elapsed_sec=0
+
+ printf "$msg"
+ while (( $($cmd getinfo | jq '.blockchain_height') < $($bitcoin_cli getblockcount) )); do
+ if ((elapsed_sec > timeout_sec)); then
+ printf "Timeout of %i s exceeded\n" "$elapsed_sec"
+ exit 1
+ fi
+ sleep 1
+ elapsed_sec=$((elapsed_sec + 1))
+ printf '.'
+ done
+
+ $cmd wait_for_sync > /dev/null
+ printf "\n"
+}
+
function assert_utxo_exists()
{
utxo=$($bitcoin_cli gettxout $1 $2)
@@ -781,6 +803,7 @@ if [[ $1 == "just_in_time" ]]; then
fi
# try again, multiple jit openings should work without issues
new_blocks 3
+ wait_for_chain_tip bob
echo "carol pays alice again"
invoice=$($alice add_request 0.04 --lightning --memo "invoice2" | jq -r ".lightning_invoice")
success=$($carol lnpay $invoice | jq -r ".success")
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.