-
Notifications
You must be signed in to change notification settings - Fork 877
Add genesis sync test to CI #7561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2430a42
add genesis test
chong-he c0a364c
update time
chong-he b7056a4
Add CI
chong-he c7607f8
exclude jobs
chong-he 3c858de
Merge remote-tracking branch 'origin/unstable' into add-genesis-sync-…
chong-he ff7c910
merge unstable
chong-he 70b50b9
exclude genesis test
chong-he 725ec9c
revise
chong-he 3d7e83c
yml file
chong-he 8ef5283
Merge branch 'unstable' into add-genesis-sync-test
chong-he cb643bf
update script
chong-he 0f4f6b1
Merge branch 'add-genesis-sync-test' of https://github.com/chong-he/l…
chong-he e44df3c
minimal
chong-he 04093d2
minimal
chong-he 8c0a3ea
-b false no rebuild image
chong-he 635fbe6
have to rebuild image
chong-he 67de688
Merge branch 'unstable' into add-genesis-sync-test
chong-he 56a4b2c
delete comment
chong-he 61b496e
Merge branch 'add-genesis-sync-test' of https://github.com/chong-he/l…
chong-he 01f2812
rebuild image
chong-he 8254067
change to -b false
chong-he 3f76dbe
add spec-minimal to build Lighthouse
chong-he 020da9f
features spec-minimal
chong-he d7b0926
docker spec-minimal
chong-he da06778
remove test-suite change
chong-he File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,22 @@ | ||
# Kurtosis config file for testing sync on a local devnet. | ||
participants: | ||
- cl_type: lighthouse | ||
cl_image: lighthouse:local | ||
count: 2 | ||
# nodes without validators, used for testing sync. | ||
- cl_type: lighthouse | ||
cl_image: lighthouse:local | ||
supernode: true # no supernode in Electra, this is for future proof | ||
validator_count: 0 | ||
- cl_type: lighthouse | ||
cl_image: lighthouse:local | ||
supernode: false | ||
validator_count: 0 | ||
network_params: | ||
seconds_per_slot: 6 | ||
electra_fork_epoch: 0 | ||
preset: "minimal" | ||
additional_services: | ||
- tx_fuzz | ||
- spamoor | ||
global_log_level: debug |
This file contains hidden or 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,22 @@ | ||
# Kurtosis config file for testing sync on a local devnet. | ||
participants: | ||
- cl_type: lighthouse | ||
cl_image: lighthouse:local | ||
count: 2 | ||
# nodes without validators, used for testing sync. | ||
- cl_type: lighthouse | ||
cl_image: lighthouse:local | ||
supernode: true | ||
validator_count: 0 | ||
- cl_type: lighthouse | ||
cl_image: lighthouse:local | ||
supernode: false | ||
validator_count: 0 | ||
network_params: | ||
seconds_per_slot: 6 | ||
fulu_fork_epoch: 0 | ||
preset: "minimal" | ||
additional_services: | ||
- tx_fuzz | ||
- spamoor | ||
global_log_level: debug |
This file contains hidden or 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,151 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Genesis sync test on a local network. | ||
# | ||
# Start a local testnet, shut down non-validator nodes for a period, then restart them | ||
# and monitor their sync progress from genesis to head. | ||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
|
||
ENCLAVE_NAME=${1:-genesis-sync-testnet} | ||
CONFIG=${2:-$SCRIPT_DIR/genesis-sync-config-electra.yaml} | ||
FORK_TYPE=${3:-electra} # electra or fulu | ||
OFFLINE_DURATION_SECS=${4:-120} # stopped duration of non validating nodes | ||
|
||
# Test configuration | ||
# ------------------------------------------------------ | ||
# Interval for polling the /lighthouse/syncing endpoint for sync status | ||
# Reduce the polling time so that some progress can be seen | ||
POLL_INTERVAL_SECS=0.5 | ||
# Timeout for this test, if the nodes fail to sync, fail the test. | ||
TIMEOUT_MINS=5 | ||
TIMEOUT_SECS=$((TIMEOUT_MINS * 60)) | ||
# ------------------------------------------------------ | ||
|
||
echo "Starting genesis sync test with:" | ||
echo " Fork: $FORK_TYPE" | ||
echo " Offline duration: ${OFFLINE_DURATION_SECS}s" | ||
|
||
# Polls a node's sync status | ||
poll_node() { | ||
local node_type=$1 | ||
local url=${node_urls[$node_type]} | ||
|
||
response=$(curl -s "${url}/lighthouse/syncing" 2>/dev/null) | ||
|
||
if [ -z "$response" ] || [ "$response" = "null" ]; then | ||
echo "${node_type} status: No response or null response" | ||
return | ||
fi | ||
|
||
# Print syncing status | ||
sync_state=$(echo "$response" | jq -r 'if (.data | type) == "object" then "object" else "string" end' 2>/dev/null) | ||
|
||
if [ "$sync_state" = "object" ]; then | ||
status=$(echo "$response" | jq -r '.data | keys[0] // "Unknown"') | ||
fields=$(echo "$response" | jq -r ".data.${status} | to_entries | map(\"\(.key): \(.value)\") | join(\", \")") | ||
echo "${node_type} status: ${status}, ${fields}" | ||
else | ||
status=$(echo "$response" | jq -r '.data' 2>/dev/null) | ||
echo "${node_type} status: ${status:-Unknown}" | ||
|
||
# The test is complete when the node is synced | ||
if [ "$status" = "Synced" ]; then | ||
jimmygchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mark_node_complete "$node_type" | ||
fi | ||
fi | ||
} | ||
|
||
# Marks a node as complete and record time | ||
mark_node_complete() { | ||
local node_type=$1 | ||
if [ "${node_completed[$node_type]}" = false ]; then | ||
node_completed[$node_type]=true | ||
node_complete_time[$node_type]=$(date +%s) | ||
echo "${node_type} completed sync in $((node_complete_time[$node_type] - sync_start_time)) seconds" | ||
fi | ||
} | ||
|
||
exit_and_dump_logs() { | ||
local exit_code=$1 | ||
echo "Shutting down..." | ||
$SCRIPT_DIR/../local_testnet/stop_local_testnet.sh $ENCLAVE_NAME | ||
echo "Test completed with exit code $exit_code." | ||
exit $exit_code | ||
} | ||
|
||
# Start the nodes | ||
$SCRIPT_DIR/../local_testnet/start_local_testnet.sh -e $ENCLAVE_NAME -b false -n $CONFIG | ||
if [ $? -ne 0 ]; then | ||
echo "Failed to start local testnet" | ||
exit_and_dump_logs 1 | ||
fi | ||
|
||
# Wait for 10s before stopping non-validating nodes | ||
sleep 10 | ||
|
||
# These are non validating nodes | ||
supernode="cl-3-lighthouse-geth" | ||
fullnode="cl-4-lighthouse-geth" | ||
|
||
# Stop the non-validator nodes | ||
kurtosis service stop $ENCLAVE_NAME $supernode | ||
kurtosis service stop $ENCLAVE_NAME $fullnode | ||
|
||
echo "Non-validator nodes stopped. Waiting ${OFFLINE_DURATION_SECS} seconds..." | ||
|
||
# Display the time every 10s when the nodes are stopped | ||
remaining_time=$OFFLINE_DURATION_SECS | ||
while [ $remaining_time -gt 0 ]; do | ||
sleep 10 | ||
remaining_time=$((remaining_time - 10)) | ||
echo "Nodes are stopped for $((OFFLINE_DURATION_SECS - remaining_time))s, ${remaining_time}s remains..." | ||
done | ||
|
||
echo "Resuming non-validator nodes..." | ||
|
||
# Resume the non validating nodes | ||
kurtosis service start $ENCLAVE_NAME $supernode | ||
kurtosis service start $ENCLAVE_NAME $fullnode | ||
|
||
# The time at which syncing starts after the node was stopped | ||
sync_start_time=$(date +%s) | ||
|
||
# Get beacon API URLs for non validating nodes for query | ||
supernode_url=$(kurtosis port print $ENCLAVE_NAME $supernode http) | ||
fullnode_url=$(kurtosis port print $ENCLAVE_NAME $fullnode http) | ||
|
||
# Initialize statuses | ||
declare -A node_completed | ||
declare -A node_complete_time | ||
declare -A node_urls | ||
|
||
node_urls["supernode"]="$supernode_url" | ||
node_urls["fullnode"]="$fullnode_url" | ||
node_completed["supernode"]=false | ||
node_completed["fullnode"]=false | ||
|
||
echo "Polling sync status until nodes are synced or timeout of ${TIMEOUT_MINS} mins" | ||
|
||
while [ "${node_completed[supernode]}" = false ] || [ "${node_completed[fullnode]}" = false ]; do | ||
current_time=$(date +%s) | ||
elapsed=$((current_time - sync_start_time)) | ||
|
||
if [ "$elapsed" -ge "$TIMEOUT_SECS" ]; then | ||
echo "ERROR: Nodes timed out syncing after ${TIMEOUT_MINS} minutes. Exiting." | ||
exit_and_dump_logs 1 | ||
fi | ||
|
||
# Poll each node that hasn't completed yet | ||
for node in "supernode" "fullnode"; do | ||
if [ "${node_completed[$node]}" = false ]; then | ||
poll_node "$node" | ||
fi | ||
done | ||
|
||
sleep $POLL_INTERVAL_SECS | ||
done | ||
|
||
echo "Genesis sync test complete! Both supernode and fullnode have synced successfully." | ||
echo "Supernode time: $((node_complete_time[supernode] - sync_start_time)) seconds" | ||
echo "Fullnode time: $((node_complete_time[fullnode] - sync_start_time)) seconds" | ||
exit_and_dump_logs 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.