Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions scripts/bw-compatibility-test/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ function open_channel() {
echo "🔗 Opened channel between $node1 and $node2"
}

# Function to check if a node's graph has the expected number of channels
# wait_graph_sync waits until the node's graph contains the expected number of
# channels AND every channel has both direction policies populated. Seeing a
# channel in the graph (via getnetworkinfo) does not guarantee that both
# channel_update messages have arrived. Without both policies the pathfinder
# cannot build a complete route, leading to NO_ROUTE failures.
wait_graph_sync() {
if [[ $# -ne 2 ]]; then
echo "❌ Error: graph_synced requires exactly 2 arguments (node and num_chans)"
Expand All @@ -185,14 +189,23 @@ wait_graph_sync() {
while :; do
num_channels=$($node getnetworkinfo | jq -r '.num_channels')

# Ensure num_channels is a valid number before proceeding
if [[ "$num_channels" =~ ^[0-9]+$ ]]; then
echo -ne "⌛ $node sees $num_channels channels...\r"
# Ensure num_channels is a valid number before proceeding.
if [[ "$num_channels" =~ ^[0-9]+$ ]] && \
[[ "$num_channels" -eq num_chans ]]; then

if [[ "$num_channels" -eq num_chans ]]; then
echo "👀 $node sees all the channels!"
break # Exit loop when num_channels reaches num_chans
# Also verify that every edge has both policies. An edge
# without both node1_policy and node2_policy means a
# channel_update is still in flight.
missing=$($node describegraph | jq '[.edges[] | select(.node1_policy == null or .node2_policy == null)] | length')

if [[ "$missing" -eq 0 ]]; then
echo "👀 $node sees all $num_chans channels with full policies!"
break
fi
Comment on lines +199 to 204
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There's a potential race condition here. If describegraph returns an empty object ({}) or {"edges": null} because it hasn't updated yet, the jq command will result in missing being 0. This would cause the loop to break prematurely, even though the graph is not fully synced.

To make this more robust, we should also verify that the number of edges in the graph matches the expected number of channels before breaking the loop.

Suggested change
missing=$($node describegraph | jq '[.edges[] | select(.node1_policy == null or .node2_policy == null)] | length')
if [[ "$missing" -eq 0 ]]; then
echo "👀 $node sees all $num_chans channels with full policies!"
break
fi
graph_json=$($node describegraph)
num_edges=$(echo "$graph_json" | jq '.edges | length // 0')
missing=$(echo "$graph_json" | jq '[.edges[] | select(.node1_policy == null or .node2_policy == null)] | length')
if [[ $num_edges -eq $num_chans && $missing -eq 0 ]]; then
echo "👀 $node sees all $num_chans channels with full policies!"
break
fi


echo -ne "⌛ $node sees $num_channels channels ($missing missing policies)...\r"
else
echo -ne "⌛ $node sees ${num_channels:-0}/$num_chans channels...\r"
fi

sleep 1
Expand Down
Loading