Skip to content

Commit

Permalink
Merge branch 'zkevm' into xiong/cache-tx-sender
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Staykov authored Dec 3, 2024
2 parents a0c5594 + 82415f5 commit a7a347b
Show file tree
Hide file tree
Showing 170 changed files with 9,824 additions and 2,640 deletions.
74 changes: 74 additions & 0 deletions .github/actions/setup-kurtosis/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

name: "Setup Kurtosis"
description: "Setup Kurtosis CDK for tests"
runs:
using: "composite"
steps:
- name: Checkout cdk-erigon
uses: actions/checkout@v4
with:
path: cdk-erigon

- name: Checkout kurtosis-cdk
uses: actions/checkout@v4
with:
repository: 0xPolygon/kurtosis-cdk
ref: v0.2.24
path: kurtosis-cdk

- name: Install Kurtosis CDK tools
uses: ./kurtosis-cdk/.github/actions/setup-kurtosis-cdk

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install polycli
shell: bash
run: |
tmp_dir=$(mktemp -d) && curl -L https://github.com/0xPolygon/polygon-cli/releases/download/v0.1.48/polycli_v0.1.48_linux_amd64.tar.gz | tar -xz -C "$tmp_dir" && mv "$tmp_dir"/* /usr/local/bin/polycli && rm -rf "$tmp_dir"
sudo chmod +x /usr/local/bin/polycli
/usr/local/bin/polycli version
- name: Install yq
shell: bash
run: |
sudo curl -L https://github.com/mikefarah/yq/releases/download/v4.44.2/yq_linux_amd64 -o /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
/usr/local/bin/yq --version
- name: Build docker image
working-directory: ./cdk-erigon
shell: bash
run: docker build -t cdk-erigon:local --file Dockerfile .

- name: Remove unused flags
working-directory: ./kurtosis-cdk
shell: bash
run: |
sed -i '/zkevm.sequencer-batch-seal-time:/d' templates/cdk-erigon/config.yml
sed -i '/zkevm.sequencer-non-empty-batch-seal-time:/d' templates/cdk-erigon/config.yml
sed -i '/zkevm\.sequencer-initial-fork-id/d' ./templates/cdk-erigon/config.yml
sed -i '/sentry.drop-useless-peers:/d' templates/cdk-erigon/config.yml
sed -i '/zkevm\.pool-manager-url/d' ./templates/cdk-erigon/config.yml
sed -i '$a\zkevm.disable-virtual-counters: true' ./templates/cdk-erigon/config.yml
sed -i '/zkevm.l2-datastreamer-timeout:/d' templates/cdk-erigon/config.yml
- name: Create params.yml overrides
working-directory: ./kurtosis-cdk
shell: bash
run: |
echo 'args:' > params.yml
echo ' cdk_erigon_node_image: cdk-erigon:local' >> params.yml
echo ' el-1-geth-lighthouse: ethpandaops/lighthouse@sha256:4902d9e4a6b6b8d4c136ea54f0e51582a32f356f3dec7194a1adee13ed2d662e' >> params.yml
/usr/local/bin/yq -i '.args.data_availability_mode = "${{ matrix.da-mode }}"' params.yml
sed -i 's/"londonBlock": [0-9]\+/"londonBlock": 0/' ./templates/cdk-erigon/chainspec.json
sed -i 's/"normalcyBlock": [0-9]\+/"normalcyBlock": 0/' ./templates/cdk-erigon/chainspec.json
sed -i 's/"shanghaiTime": [0-9]\+/"shanghaiTime": 0/' ./templates/cdk-erigon/chainspec.json
sed -i 's/"cancunTime": [0-9]\+/"cancunTime": 0/' ./templates/cdk-erigon/chainspec.json
sed -i '/"terminalTotalDifficulty"/d' ./templates/cdk-erigon/chainspec.json
- name: Deploy Kurtosis CDK package
working-directory: ./kurtosis-cdk
shell: bash
run: |
kurtosis run --enclave cdk-v1 --args-file params.yml --image-download always . '{"args": {"erigon_strict_mode": false, "cdk_erigon_node_image": "cdk-erigon:local"}}'
136 changes: 136 additions & 0 deletions .github/scripts/cpu_monitor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/bin/bash

# Configuration
THRESHOLD=80
MEASUREMENTS_FILE="/tmp/cpu_measurements.txt"
MONITOR_INTERVAL=5 # seconds
PROCESS_NAME="cdk-erigon"
DETAILED_LOG="/tmp/cpu_detailed.log"

# Function to get CPU usage for all matching processes
get_process_cpu() {
# Clear previous detailed log
> "$DETAILED_LOG"

# Get PIDs of cdk-erigon processes
pids=$(pgrep -f "[c]dk-erigon")

if [ -n "$pids" ]; then
# Use top in batch mode for each PID to get current CPU usage
for pid in $pids; do
# Get process command
if [[ "$OSTYPE" == "darwin"* ]]; then
cmd=$(ps -p $pid -o command=)
cpu=$(top -l 1 -pid $pid | tail -1 | awk '{print $3}')
else
cmd=$(ps -p $pid -o cmd=)
cpu=$(top -b -n 1 -p $pid | tail -1 | awk '{print $9}')
fi
# Get current CPU usage
echo "$pid $cpu $cmd" >> "$DETAILED_LOG"
done
fi

# Sum total CPU usage
total_cpu=$(awk '{sum += $2} END {printf "%.1f", sum}' "$DETAILED_LOG")

# Return 0 if no process found
if [ -z "$total_cpu" ]; then
echo "0.0"
else
echo "$total_cpu"
fi
}

# Function to show current process details
show_process_details() {
if [ -s "$DETAILED_LOG" ]; then
echo "Individual process details:"
printf "%-10s %-8s %-s\n" "PID" "CPU%" "Command"
echo "----------------------------------------"
while read -r line; do
pid=$(echo "$line" | awk '{print $1}')
cpu=$(echo "$line" | awk '{print $2}')
cmd=$(echo "$line" | cut -d' ' -f3-)
printf "%-10s %-8.1f %-s\n" "$pid" "$cpu" "$cmd"
done < "$DETAILED_LOG"
echo "----------------------------------------"
else
echo "No $PROCESS_NAME processes found"
fi
}

# Function to analyze CPU measurements
analyze_cpu() {
if [ -f "$MEASUREMENTS_FILE" ]; then
# Calculate statistics
avg_cpu=$(awk '{ sum += $1 } END { print sum/NR }' "$MEASUREMENTS_FILE")
avg_cpu_rounded=$(printf "%.1f" "$avg_cpu")
max_cpu=$(awk 'BEGIN{max=0} {if($1>max) max=$1} END{print max}' "$MEASUREMENTS_FILE")
measurement_count=$(wc -l < "$MEASUREMENTS_FILE")

echo ""
echo "=== CPU Usage Analysis for all $PROCESS_NAME processes ==="
echo "Number of measurements: $measurement_count"
echo "Average Combined CPU Usage: $avg_cpu_rounded%"
echo "Peak Combined CPU Usage: $max_cpu%"
echo "Threshold: $THRESHOLD%"

# Get final process details for the report
echo ""
echo "Final process state:"
show_process_details

# Compare with threshold
if [ "$(echo "$avg_cpu > $THRESHOLD" | bc -l)" -eq 1 ]; then
echo ""
echo "ERROR: Average CPU usage ($avg_cpu_rounded%) exceeded threshold of $THRESHOLD%"
cleanup_and_exit 1
else
echo ""
echo "SUCCESS: CPU usage ($avg_cpu_rounded%) is within threshold of $THRESHOLD%"
cleanup_and_exit 0
fi
else
echo "ERROR: No CPU measurements found at $MEASUREMENTS_FILE"
cleanup_and_exit 1
fi
}

# Function to clean up and exit
cleanup_and_exit() {
exit_code=$1
rm -f "$DETAILED_LOG"
exit $exit_code
}

# Function to handle interruption
handle_interrupt() {
echo ""
echo "Monitoring interrupted. Analyzing collected data..."
analyze_cpu
}

# Set up trap for various signals
trap handle_interrupt TERM INT

# Clear measurements file
> "$MEASUREMENTS_FILE"
> "$DETAILED_LOG"

echo "Starting CPU monitoring for all '$PROCESS_NAME' processes"
echo "Storing measurements in $MEASUREMENTS_FILE"
echo "Monitoring interval: ${MONITOR_INTERVAL}s"
echo "Press Ctrl+C to stop monitoring and see analysis"
echo ""

# Start monitoring loop
while true; do
# Get CPU usage for all matching processes
cpu_usage=$(get_process_cpu)
echo "$cpu_usage" >> "$MEASUREMENTS_FILE"
echo "$(date '+%Y-%m-%d %H:%M:%S') - Combined CPU Usage: $cpu_usage%"
show_process_details
echo ""
sleep "$MONITOR_INTERVAL"
done
47 changes: 42 additions & 5 deletions .github/scripts/test_resequence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ get_latest_l2_batch() {
}

get_latest_l1_verified_batch() {
current_batch=$(cast logs --rpc-url "$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)" --address 0x1Fe038B54aeBf558638CA51C91bC8cCa06609e91 --from-block 0 -j | jq -r '.[] | select(.topics[0] == "0x9c72852172521097ba7e1482e6b44b351323df0155f97f4ea18fcec28e1f5966" or .topics[0] == "0xd1ec3a1216f08b6eff72e169ceb548b782db18a6614852618d86bb19f3f9b0d3") | .topics[1]' | tail -n 1 | sed 's/^0x//')
current_batch=$(cast logs --rpc-url "$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)" --address 0x1Fe038B54aeBf558638CA51C91bC8cCa06609e91 --from-block 0 --json | jq -r '.[] | select(.topics[0] == "0x9c72852172521097ba7e1482e6b44b351323df0155f97f4ea18fcec28e1f5966" or .topics[0] == "0xd1ec3a1216f08b6eff72e169ceb548b782db18a6614852618d86bb19f3f9b0d3") | .topics[1]' | tail -n 1 | sed 's/^0x//')
current_batch_dec=$((16#$current_batch))
echo "$current_batch_dec"
}
Expand Down Expand Up @@ -46,10 +46,11 @@ wait_for_l1_batch() {
fi

if [ "$batch_type" = "virtual" ]; then
current_batch=$(cast logs --rpc-url "$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)" --address 0x1Fe038B54aeBf558638CA51C91bC8cCa06609e91 --from-block 0 -j | jq -r '.[] | select(.topics[0] == "0x3e54d0825ed78523037d00a81759237eb436ce774bd546993ee67a1b67b6e766") | .topics[1]' | tail -n 1 | sed 's/^0x//')

current_batch=$(cast logs --rpc-url "$(kurtosis port print cdk-v1 el-1-geth-lighthouse rpc)" --address 0x1Fe038B54aeBf558638CA51C91bC8cCa06609e91 --from-block 0 --json | jq -r '.[] | select(.topics[0] == "0x3e54d0825ed78523037d00a81759237eb436ce774bd546993ee67a1b67b6e766") | .topics[1]' | tail -n 1 | sed 's/^0x//')
current_batch=$((16#$current_batch))
elif [ "$batch_type" = "verified" ]; then
current_batch=$(cast rpc zkevm_verifiedBatchNumber --rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-node-001 rpc)" | sed 's/^"//;s/"$//')
current_batch=$(cast rpc zkevm_verifiedBatchNumber --rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-rpc-001 rpc)" | sed 's/^"//;s/"$//')
else
echo "Invalid batch type. Use 'virtual' or 'verified'."
return 1
Expand All @@ -70,6 +71,33 @@ wait_for_l1_batch() {
done
}


wait_for_l2_block_number() {
local block_number=$1
local node_url=$2
local latest_block=0
local tries=0

#while latest_block lower than block_number
#if more than 5 attempts - throw error
while [ "$latest_block" -lt "$block_number" ]; do
latest_block=$(cast block latest --rpc-url "$node_url" | grep "number" | awk '{print $2}')
if [[ $? -ne 0 ]]; then
echo "Error: Failed to get latest block number" >&2
return 1
fi

if [ "$tries" -ge 5 ]; then
echo "Error: Failed to get block number $block_number" >&2
return 1
fi
tries=$((tries + 1))

echo "Current block number on $node_url: $latest_block, needed: $block_number. Waiting to try again."
sleep 60
done
}

stop_cdk_erigon_sequencer() {
echo "Stopping cdk-erigon"
kurtosis service exec cdk-v1 cdk-erigon-sequencer-001 "pkill -SIGTRAP proc-runner.sh" || true
Expand All @@ -93,7 +121,7 @@ kurtosis service exec cdk-v1 cdk-erigon-sequencer-001 "nohup cdk-erigon --pprof=
sleep 30

echo "Running loadtest using polycli"
/usr/local/bin/polycli loadtest --rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-node-001 rpc)" --private-key "0x12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625" --verbosity 600 --requests 2000 --rate-limit 500 --mode uniswapv3 --legacy
/usr/local/bin/polycli loadtest --rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-rpc-001 rpc)" --private-key "0x12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625" --verbosity 600 --requests 2000 --rate-limit 500 --mode uniswapv3 --legacy

echo "Waiting for batch virtualization"
if ! wait_for_l1_batch 600 "virtual"; then
Expand Down Expand Up @@ -139,11 +167,20 @@ echo "Calculating comparison block number"
comparison_block=$((latest_block - 10))
echo "Block number to compare (10 blocks behind): $comparison_block"

echo "Waiting some time for the syncer to catch up"
sleep 30

echo "Getting block hash from sequencer"
sequencer_hash=$(cast block $comparison_block --rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-sequencer-001 rpc)" | grep "hash" | awk '{print $2}')

# wait for block to be available on sync node
if ! wait_for_l2_block_number $comparison_block "$(kurtosis port print cdk-v1 cdk-erigon-rpc-001 rpc)"; then
echo "Failed to wait for batch verification"
exit 1
fi

echo "Getting block hash from node"
node_hash=$(cast block $comparison_block --rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-node-001 rpc)" | grep "hash" | awk '{print $2}')
node_hash=$(cast block $comparison_block --rpc-url "$(kurtosis port print cdk-v1 cdk-erigon-rpc-001 rpc)" | grep "hash" | awk '{print $2}')

echo "Sequencer block hash: $sequencer_hash"
echo "Node block hash: $node_hash"
Expand Down
Loading

0 comments on commit a7a347b

Please sign in to comment.