resilience

This commit is contained in:
goldsquid
2025-12-18 08:53:41 +07:00
parent dd18b750fe
commit 5bd83eed3d

View File

@@ -10,8 +10,8 @@
# If not provided, use the same compose file for both source and target # If not provided, use the same compose file for both source and target
# #
# Exit codes: # Exit codes:
# 0 - Both nodes connected successfully # 0 - At least one node connected successfully (bidirectional or one-way)
# 1 - Failed to connect (see output for details) # 1 - Failed to connect to both nodes (see output for details)
set -euo pipefail set -euo pipefail
@@ -317,19 +317,24 @@ echo ""
echo -e "${CYAN}--- Adding Static Peers ---${NC}" echo -e "${CYAN}--- Adding Static Peers ---${NC}"
echo "" echo ""
SOURCE_SUCCESS=false
TARGET_SUCCESS=false
ERRORS=0 ERRORS=0
# Add target's enode to source # Add target's enode to source
echo -n "Adding target to source... " echo -n "Adding target to source... "
if [[ "$SOURCE_HAS_TARGET" == "connected" ]]; then if [[ "$SOURCE_HAS_TARGET" == "connected" ]]; then
echo -e "${YELLOW}skipped (already connected)${NC}" echo -e "${YELLOW}skipped (already connected)${NC}"
SOURCE_SUCCESS=true
elif [[ "$DRY_RUN" == true ]]; then elif [[ "$DRY_RUN" == true ]]; then
echo -e "${CYAN}dry run${NC}" echo -e "${CYAN}dry run${NC}"
echo -e " Would run: admin_addStaticPeer(\"${TARGET_ENODE:0:50}...\")" echo -e " Would run: admin_addStaticPeer(\"${TARGET_ENODE:0:50}...\")"
SOURCE_SUCCESS=true
else else
RESULT=$(add_static_peer "$SOURCE_URL" "$TARGET_ENODE") RESULT=$(add_static_peer "$SOURCE_URL" "$TARGET_ENODE")
if [[ "$RESULT" =~ "true" ]]; then if [[ "$RESULT" =~ "true" ]]; then
echo -e "${GREEN}OK${NC}" echo -e "${GREEN}OK${NC}"
SOURCE_SUCCESS=true
else else
echo -e "${RED}FAILED${NC}" echo -e "${RED}FAILED${NC}"
echo -e " Response: $RESULT" echo -e " Response: $RESULT"
@@ -341,13 +346,16 @@ fi
echo -n "Adding source to target... " echo -n "Adding source to target... "
if [[ "$TARGET_HAS_SOURCE" == "connected" ]]; then if [[ "$TARGET_HAS_SOURCE" == "connected" ]]; then
echo -e "${YELLOW}skipped (already connected)${NC}" echo -e "${YELLOW}skipped (already connected)${NC}"
TARGET_SUCCESS=true
elif [[ "$DRY_RUN" == true ]]; then elif [[ "$DRY_RUN" == true ]]; then
echo -e "${CYAN}dry run${NC}" echo -e "${CYAN}dry run${NC}"
echo -e " Would run: admin_addStaticPeer(\"${SOURCE_ENODE:0:50}...\")" echo -e " Would run: admin_addStaticPeer(\"${SOURCE_ENODE:0:50}...\")"
TARGET_SUCCESS=true
else else
RESULT=$(add_static_peer "$TARGET_URL" "$SOURCE_ENODE") RESULT=$(add_static_peer "$TARGET_URL" "$SOURCE_ENODE")
if [[ "$RESULT" =~ "true" ]]; then if [[ "$RESULT" =~ "true" ]]; then
echo -e "${GREEN}OK${NC}" echo -e "${GREEN}OK${NC}"
TARGET_SUCCESS=true
else else
echo -e "${RED}FAILED${NC}" echo -e "${RED}FAILED${NC}"
echo -e " Response: $RESULT" echo -e " Response: $RESULT"
@@ -391,19 +399,37 @@ fi
echo -e "${CYAN}--- Summary ---${NC}" echo -e "${CYAN}--- Summary ---${NC}"
echo "" echo ""
if [[ $ERRORS -eq 0 ]]; then
if [[ "$DRY_RUN" == true ]]; then if [[ "$DRY_RUN" == true ]]; then
echo -e "${GREEN}Dry run completed - no changes made${NC}" echo -e "${GREEN}Dry run completed - no changes made${NC}"
else echo ""
echo -e "${GREEN}Nodes connected successfully${NC}" exit 0
elif [[ "$SOURCE_SUCCESS" == true && "$TARGET_SUCCESS" == true ]]; then
echo -e "${GREEN}Nodes connected successfully (bidirectional)${NC}"
echo "" echo ""
echo "Both nodes should now discover each other's peers via the" echo "Both nodes should now discover each other's peers via the"
echo "devp2p discovery protocol. Give it a few minutes to propagate." echo "devp2p discovery protocol. Give it a few minutes to propagate."
echo ""
exit 0
elif [[ "$SOURCE_SUCCESS" == true || "$TARGET_SUCCESS" == true ]]; then
echo -e "${YELLOW}Partial success - peer added to one node${NC}"
if [[ "$SOURCE_SUCCESS" == true ]]; then
echo -e " ${GREEN}${NC} Target peer added to source node"
else
echo -e " ${RED}${NC} Failed to add target peer to source node"
fi fi
if [[ "$TARGET_SUCCESS" == true ]]; then
echo -e " ${GREEN}${NC} Source peer added to target node"
else
echo -e " ${RED}${NC} Failed to add source peer to target node"
fi
echo ""
echo "One-way connection established. The node that successfully added"
echo "the peer should be able to connect. Retry later to establish"
echo "bidirectional connection."
echo "" echo ""
exit 0 exit 0
else else
echo -e "${RED}Connection failed with $ERRORS error(s)${NC}" echo -e "${RED}Connection failed - could not add peer to either node${NC}"
echo "" echo ""
exit 1 exit 1
fi fi