-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: native tmux-based network e2e (#9036)
For debugging <img width="1798" alt="Screenshot 2024-10-06 at 10 17 30 PM" src="https://github.com/user-attachments/assets/05b1819f-c117-46f6-a7b7-407d978d122d">
- Loading branch information
Showing
26 changed files
with
628 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,7 @@ terraform.tfstate* | |
.bb_tmp | ||
|
||
# Terraform | ||
*.tfvars | ||
*.tfvars | ||
|
||
# tmux | ||
tmux-client-*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
# Usage: run_bg_args.sh <main command> <background commands>... | ||
# Runs the main command with output logging and background commands without logging. | ||
# Finishes when the main command exits. | ||
|
||
# Check if at least two commands are provided (otherwise what is the point) | ||
if [ "$#" -lt 2 ]; then | ||
echo "Usage: $0 <main-command> <background commands>..." | ||
exit 1 | ||
fi | ||
|
||
main_cmd="$1" | ||
shift | ||
|
||
# Function to run a command and prefix the output | ||
function run_command() { | ||
local cmd="$1" | ||
while IFS= read -r line; do | ||
echo "[$cmd] $line" | ||
done < <($cmd 2>&1) | ||
} | ||
|
||
# Run the main command, piping output through the run_command function | ||
run_command "$main_cmd" & | ||
main_pid=$! | ||
|
||
# Run background commands without logging output | ||
declare -a bg_pids | ||
for cmd in "$@"; do | ||
run_command "$cmd" & | ||
bg_pids+=($!) | ||
done | ||
|
||
# Wait for the main command to finish and capture its exit code | ||
wait $main_pid | ||
main_exit_code=$? | ||
|
||
# Kill any remaining background jobs | ||
for pid in "${bg_pids[@]}"; do | ||
kill "$pid" 2>/dev/null || true | ||
done | ||
|
||
# Exit with the same code as the main command | ||
exit $main_exit_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
# Usage: tmux_splits_args.sh <session-name> <main command> <background commands>... | ||
# Runs commands in parallel in a tmux window. | ||
# *Finishes when the main command exits.* | ||
|
||
# Check if at least two commands are provided (otherwise what is the point) | ||
if [ "$#" -lt 2 ]; then | ||
echo "Usage: $0 <main-command> <background commands>..." | ||
exit 1 | ||
fi | ||
|
||
# Launches tmux with 1 window that has as many panes as commands | ||
session_name=$1 | ||
|
||
# Kill any existing tmux session with the same name | ||
tmux kill-session -t "$session_name" 2>/dev/null || true | ||
|
||
# Start a new tmux session | ||
tmux new-session -d -s "$session_name" | ||
|
||
shift 1 | ||
commands=("$@") | ||
|
||
# Set pane-border-status to top and pane-border-format to display pane title | ||
tmux set-option -t "$session_name" pane-border-status top | ||
tmux set-option -t "$session_name" pane-border-format "#{pane_title}" | ||
|
||
# Create the necessary number of panes and set titles | ||
num_commands=${#commands[@]} | ||
for ((i=0; i<num_commands; i++)); do | ||
if [[ $i -gt 0 ]]; then | ||
# Split the first pane each time | ||
tmux split-window -t "$session_name:0.0" -h | ||
tmux select-layout -t "$session_name:0" tiled | ||
fi | ||
# Set the pane title | ||
tmux select-pane -t "$session_name:0.$i" -T "${commands[i]}" | ||
done | ||
|
||
# Ensure this finishes when pane 0 is finished | ||
tmux set-hook -t "$session_name" pane-exited "if-shell -F '#{==:#{pane_index},0}' 'kill-session -t \"$session_name\"'" | ||
|
||
# Now send commands to each pane | ||
for ((i=0; i<num_commands; i++)); do | ||
tmux send-keys -t "$session_name:0.$i" "${commands[$i]}" C-m | ||
done | ||
|
||
# Attach to the session | ||
tmux attach-session -t "$session_name" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
import subprocess | ||
import json | ||
import heapq | ||
|
||
# Get the list of pods | ||
pods = subprocess.check_output( | ||
['kubectl', 'get', 'pods', '-n', 'transfer', '-o', 'custom-columns=:metadata.name', '--no-headers'], | ||
universal_newlines=True | ||
).splitlines() | ||
|
||
# Create a min-heap for sorting logs based on timestamp | ||
heap = [] | ||
|
||
for pod in pods: | ||
# Get logs for each pod | ||
logs = subprocess.check_output(['kubectl', 'logs', '-n', 'transfer', pod], universal_newlines=True).splitlines() | ||
for line in logs: | ||
# Prefix with pod name | ||
prefixed_line = f'[{pod}] {line}' | ||
try: | ||
# Remove the pod prefix | ||
if line.startswith('['): | ||
closing_bracket_index = line.find(']') | ||
if closing_bracket_index != -1: | ||
# Assume there's a space after the closing bracket | ||
json_part = line[closing_bracket_index + 2:] | ||
else: | ||
json_part = line # No closing bracket found | ||
else: | ||
json_part = line | ||
|
||
# Parse the JSON part | ||
log_json = json.loads(json_part) | ||
|
||
# Ensure log_json is a dictionary | ||
if isinstance(log_json, dict): | ||
timestamp = log_json.get('timestamp') | ||
if timestamp: | ||
# Use timestamp as the key for sorting | ||
heapq.heappush(heap, (timestamp, prefixed_line)) | ||
else: | ||
# log_json is not a dictionary; skip this line | ||
continue | ||
except (json.JSONDecodeError, ValueError, AttributeError) as e: | ||
# Optionally print the error and the problematic line for debugging | ||
# print(f"Error parsing line: {line}\nError: {e}") | ||
continue # Skip lines that are not valid JSON dictionaries | ||
|
||
# Extract and print logs in order | ||
while heap: | ||
_, log_line = heapq.heappop(heap) | ||
print(log_line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
l1-contracts.env | ||
l2-contracts.env | ||
*.log |
41 changes: 41 additions & 0 deletions
41
yarn-project/end-to-end/scripts/native-network/boot-node.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
# Get the name of the script without the path and extension | ||
SCRIPT_NAME=$(basename "$0" .sh) | ||
|
||
# Redirect stdout and stderr to <script_name>.log while also printing to the console | ||
exec > >(tee -a "$(dirname $0)/logs/${SCRIPT_NAME}.log") 2> >(tee -a "$(dirname $0)/logs/${SCRIPT_NAME}.log" >&2) | ||
|
||
# Starts the Boot Node | ||
|
||
# Set environment variables | ||
export PORT="8080" | ||
export LOG_LEVEL="debug" | ||
export DEBUG="aztec:*,-aztec:avm_simulator:*" | ||
export ETHEREUM_HOST="http://127.0.0.1:8545" | ||
export P2P_ENABLED="true" | ||
export VALIDATOR_DISABLED="true" | ||
export SEQ_MAX_SECONDS_BETWEEN_BLOCKS="0" | ||
export SEQ_MIN_TX_PER_BLOCK="1" | ||
export P2P_TCP_ANNOUNCE_ADDR="127.0.0.1:40400" | ||
export P2P_UDP_ANNOUNCE_ADDR="127.0.0.1:40400" | ||
export P2P_TCP_LISTEN_ADDR="0.0.0.0:40400" | ||
export P2P_UDP_LISTEN_ADDR="0.0.0.0:40400" | ||
export VALIDATOR_PRIVATE_KEY="0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a" | ||
REPO=$(git rev-parse --show-toplevel) | ||
|
||
echo "Waiting for l1 contracts to be deployed..." | ||
until [ -f "$REPO"/yarn-project/end-to-end/scripts/native-network/l1-contracts.env ] ; do | ||
sleep 1 | ||
done | ||
echo "Done waiting." | ||
|
||
source "$REPO"/yarn-project/end-to-end/scripts/native-network/l1-contracts.env | ||
|
||
function filter_noise() { | ||
grep -Ev "node_getProvenBlockNumber|getBlocks|Last block mined|Running random nodes query|Not creating block because not enough txs in the pool|Peers to connect" | ||
} | ||
|
||
# Start the Aztec node with the sequencer and archiver | ||
node --no-warnings "$REPO"/yarn-project/aztec/dest/bin/index.js start --node --archiver --sequencer --pxe 2>&1 | filter_noise |
Oops, something went wrong.