Skip to content

Commit 2301f7e

Browse files
committed
fix: testnet commits
1 parent dc83bed commit 2301f7e

File tree

6 files changed

+233
-91
lines changed

6 files changed

+233
-91
lines changed

push-node-manager/.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ MONIKER="My Awesome Validator"
66
# Network is automatically set to testnet
77
NETWORK=testnet
88

9+
# Auto-update configuration
10+
# Set to 'true' to automatically update the binary when starting the validator
11+
# Set to 'false' to require manual updates with './push-node-manager update'
12+
# Default: false (manual updates for safety)
13+
AUTO_UPDATE=false
14+
915
# That's it! Everything else is automatic 🚀

push-node-manager/Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,28 @@ RUN pip3 install tomlkit
2424

2525
# Binary configuration
2626
ARG BINARY_VERSION=latest
27-
ARG BINARY_URL=https://github.com/push-protocol/push-chain/releases/download
27+
ARG BINARY_URL=https://github.com/pushchain/push-chain-node/releases/download
2828
ARG BINARY_CHECKSUM=""
29+
ARG TARGETARCH=amd64
2930

3031
# Download and verify binary
3132
RUN if [ "$BINARY_VERSION" = "latest" ]; then \
32-
DOWNLOAD_URL="${BINARY_URL}/latest/download/pchaind-linux-amd64"; \
33+
# Get latest release version
34+
LATEST_VERSION=$(curl -s https://api.github.com/repos/pushchain/push-chain-node/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') && \
35+
if [ -z "$LATEST_VERSION" ]; then \
36+
echo "Failed to get latest version, using fallback" && \
37+
LATEST_VERSION="v1.0.5"; \
38+
fi && \
39+
DOWNLOAD_URL="${BINARY_URL}/${LATEST_VERSION}/pchaind-${LATEST_VERSION}-linux-${TARGETARCH}.tar.gz"; \
3340
else \
34-
DOWNLOAD_URL="${BINARY_URL}/${BINARY_VERSION}/pchaind-linux-amd64"; \
41+
DOWNLOAD_URL="${BINARY_URL}/${BINARY_VERSION}/pchaind-${BINARY_VERSION}-linux-${TARGETARCH}.tar.gz"; \
3542
fi && \
3643
echo "Downloading binary from $DOWNLOAD_URL" && \
37-
curl -sSL "$DOWNLOAD_URL" -o /usr/local/bin/pchaind && \
44+
curl -sSL "$DOWNLOAD_URL" -o /tmp/pchaind.tar.gz && \
45+
tar -xzf /tmp/pchaind.tar.gz -C /tmp && \
46+
mv /tmp/pchaind /usr/local/bin/pchaind && \
3847
chmod +x /usr/local/bin/pchaind && \
48+
rm -f /tmp/pchaind.tar.gz && \
3949
# Verify checksum if provided
4050
if [ -n "$BINARY_CHECKSUM" ]; then \
4151
echo "$BINARY_CHECKSUM /usr/local/bin/pchaind" | sha256sum -c || \

push-node-manager/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,47 @@ After registration completes:
103103

104104
</details>
105105

106+
<details>
107+
<summary><b>🔄 Keeping Your Node Updated</b></summary>
108+
109+
**Automatic Binary Updates:**
110+
The node manager automatically downloads the latest `pchaind` binary from GitHub releases. No manual binary management needed!
111+
112+
**Manual Updates (Default - Safe):**
113+
```bash
114+
./push-node-manager update # Download latest binary and rebuild
115+
./push-node-manager restart # Apply changes
116+
./push-node-manager status # Verify everything works
117+
```
118+
119+
**Automatic Updates (Optional):**
120+
```bash
121+
# Enable auto-updates in .env file
122+
echo "AUTO_UPDATE=true" >> .env
123+
124+
# Now updates happen automatically when starting
125+
./push-node-manager start # Checks for updates first
126+
```
127+
128+
**Update Process:**
129+
- Pull latest scripts and configuration
130+
- Download latest `pchaind` binary from GitHub releases
131+
- Rebuild the validator image with the new binary
132+
- Preserve all your wallets and configuration
133+
- Skip auto-update if validator is actively validating (for safety)
134+
135+
**Update Notifications:**
136+
- `./push-node-manager status` always shows if updates are available
137+
- Provides current vs latest version information
138+
- Shows instructions for updating
139+
140+
**Version Information:**
141+
- Node Manager: v2.0.0 (now uses GitHub release binaries)
142+
- Binary: Latest from [pushchain/push-chain-node releases](https://github.com/pushchain/push-chain-node/releases)
143+
- Auto-detects your system architecture (amd64/arm64)
144+
145+
</details>
146+
106147
<details>
107148
<summary><b>💾 System Requirements</b></summary>
108149

push-node-manager/docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
args:
77
- BINARY_VERSION=${BINARY_VERSION:-latest}
88
- BINARY_CHECKSUM=${BINARY_CHECKSUM:-}
9+
- TARGETARCH=${TARGETARCH:-amd64}
910
image: push-node-manager:${BINARY_VERSION:-latest}
1011
container_name: push-node-manager
1112
restart: unless-stopped
@@ -19,8 +20,6 @@ services:
1920
- "8545:8545" # EVM JSON-RPC
2021
- "8546:8546" # EVM JSON-RPC WebSocket
2122
volumes:
22-
# Mount local binary for development (until GitHub releases are available)
23-
- ../build/pchaind:/usr/local/bin/pchaind:ro
2423
# Data directory
2524
- ./data:/root/.pchain
2625
# Scripts

push-node-manager/push-node-manager

Lines changed: 171 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ show_banner() {
4848
echo " / ____/ /_/ (__ ) / / / / /___/ / / / /_/ / / / / / "
4949
echo "/_/ \\__,_/____/_/ /_/ \\____/_/ /_/\\__,_/_/_/ /_/ "
5050
echo -e "${NC}"
51-
echo -e "${BOLD}${YELLOW} Push Node Manager v1.0.0${NC}"
51+
echo -e "${BOLD}${YELLOW} Push Node Manager v2.0.0${NC}"
5252
echo -e "${GREEN} ═══════════════════════════════${NC}"
5353
echo
5454
}
@@ -65,6 +65,134 @@ else
6565
DOCKER_COMPOSE="docker-compose"
6666
fi
6767

68+
# Update detection functions
69+
check_for_updates() {
70+
# Cache file for GitHub API responses (to avoid rate limiting)
71+
local CACHE_FILE="/tmp/push_node_manager_update_check"
72+
local CACHE_DURATION=3600 # 1 hour
73+
local CURRENT_TIME=$(date +%s)
74+
75+
# Check if cache is still valid
76+
if [ -f "$CACHE_FILE" ]; then
77+
local CACHE_TIME=$(stat -f %m "$CACHE_FILE" 2>/dev/null || stat -c %Y "$CACHE_FILE" 2>/dev/null || echo "0")
78+
local CACHE_AGE=$((CURRENT_TIME - CACHE_TIME))
79+
80+
if [ $CACHE_AGE -lt $CACHE_DURATION ]; then
81+
# Use cached result
82+
cat "$CACHE_FILE" 2>/dev/null || echo ""
83+
return 0
84+
fi
85+
fi
86+
87+
# Fetch latest release from GitHub API
88+
local LATEST_RELEASE=$(curl -s --connect-timeout 10 \
89+
"https://api.github.com/repos/pushchain/push-chain-node/releases/latest" 2>/dev/null)
90+
91+
if [ -n "$LATEST_RELEASE" ] && echo "$LATEST_RELEASE" | grep -q '"tag_name"'; then
92+
echo "$LATEST_RELEASE" > "$CACHE_FILE"
93+
echo "$LATEST_RELEASE"
94+
else
95+
# Return empty if failed
96+
echo ""
97+
fi
98+
}
99+
100+
get_latest_version() {
101+
local RELEASE_DATA=$(check_for_updates)
102+
if [ -n "$RELEASE_DATA" ]; then
103+
echo "$RELEASE_DATA" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' || echo ""
104+
else
105+
echo ""
106+
fi
107+
}
108+
109+
get_current_binary_version() {
110+
# Try to get version from the binary if it's running
111+
if $DOCKER_COMPOSE ps | grep -q "push-node-manager.*Up"; then
112+
local VERSION=$($DOCKER_COMPOSE exec -T validator pchaind version --long 2>/dev/null | \
113+
grep "version:" | awk '{print $2}' 2>/dev/null || echo "")
114+
115+
if [ -n "$VERSION" ] && [ "$VERSION" != "null" ]; then
116+
echo "$VERSION"
117+
else
118+
echo "unknown"
119+
fi
120+
else
121+
echo "unknown"
122+
fi
123+
}
124+
125+
compare_versions() {
126+
local CURRENT="$1"
127+
local LATEST="$2"
128+
129+
# If we can't determine versions, assume update needed
130+
if [ -z "$CURRENT" ] || [ "$CURRENT" = "unknown" ] || [ -z "$LATEST" ]; then
131+
return 1 # Update available (unknown state)
132+
fi
133+
134+
# Simple string comparison for now (works for semantic versions)
135+
if [ "$CURRENT" != "$LATEST" ]; then
136+
return 0 # Update available
137+
else
138+
return 1 # No update needed
139+
fi
140+
}
141+
142+
check_and_notify_updates() {
143+
local LATEST_VERSION=$(get_latest_version)
144+
local CURRENT_VERSION=$(get_current_binary_version)
145+
146+
if [ -n "$LATEST_VERSION" ] && compare_versions "$CURRENT_VERSION" "$LATEST_VERSION"; then
147+
echo
148+
print_warning "📦 Update Available!"
149+
echo -e " Current: ${YELLOW}$CURRENT_VERSION${NC}"
150+
echo -e " Latest: ${GREEN}$LATEST_VERSION${NC}"
151+
echo
152+
echo -e " Run ${BOLD}${GREEN}'./push-node-manager update'${NC} to update"
153+
if [ "${AUTO_UPDATE:-false}" != "true" ]; then
154+
echo -e " Or set ${BOLD}AUTO_UPDATE=true${NC} in .env for automatic updates"
155+
fi
156+
echo
157+
return 0 # Update available
158+
fi
159+
return 1 # No update available
160+
}
161+
162+
perform_auto_update() {
163+
local LATEST_VERSION=$(get_latest_version)
164+
local CURRENT_VERSION=$(get_current_binary_version)
165+
166+
if [ -n "$LATEST_VERSION" ] && compare_versions "$CURRENT_VERSION" "$LATEST_VERSION"; then
167+
print_status "🔄 Auto-updating to $LATEST_VERSION..."
168+
169+
# Check if validator is actively validating (has voting power)
170+
if $DOCKER_COMPOSE ps | grep -q "push-node-manager.*Up"; then
171+
local VOTING_POWER=$($DOCKER_COMPOSE exec -T validator pchaind status --home /root/.pchain 2>/dev/null | \
172+
jq -r '.validator_info.voting_power // "0"' 2>/dev/null || echo "0")
173+
174+
if [ "$VOTING_POWER" != "0" ] && [ "$VOTING_POWER" != "null" ]; then
175+
print_warning "⚠️ Validator is actively validating (voting power: $VOTING_POWER)"
176+
echo "Skipping auto-update to avoid disruption."
177+
echo "Run './push-node-manager update' manually when ready."
178+
return 1
179+
fi
180+
fi
181+
182+
# Perform the update
183+
print_status "🔨 Rebuilding image with latest binary..."
184+
$DOCKER_COMPOSE build --no-cache --quiet || {
185+
print_error "❌ Auto-update failed!"
186+
echo "Try running './push-node-manager update' manually."
187+
return 1
188+
}
189+
190+
print_success "✅ Auto-update complete!"
191+
echo "Using binary version: $LATEST_VERSION"
192+
return 0
193+
fi
194+
return 1 # No update needed
195+
}
68196

69197
# Show banner for interactive commands (not for status checks)
70198
case "$1" in
@@ -85,8 +213,16 @@ case "$1" in
85213
exit 0
86214
fi
87215

216+
# Check for auto-update if enabled
217+
if [ "${AUTO_UPDATE:-false}" = "true" ]; then
218+
print_status "🔍 Checking for updates (AUTO_UPDATE=true)..."
219+
if perform_auto_update; then
220+
print_status "Continuing with startup using updated binary..."
221+
fi
222+
fi
223+
88224
# Build image if needed
89-
if ! docker images | grep -q "push-node-manager.*local"; then
225+
if ! docker images | grep -q "push-node-manager"; then
90226
print_status "🔨 Building validator image..."
91227
$DOCKER_COMPOSE build
92228
fi
@@ -355,6 +491,9 @@ case "$1" in
355491
echo -e " ${GREEN}${NC} Getting tokens from the faucet"
356492
echo -e " ${GREEN}${NC} Registering as a validator"
357493
fi
494+
495+
# Check for available updates
496+
check_and_notify_updates
358497
;;
359498

360499
logs)
@@ -498,9 +637,31 @@ case "$1" in
498637

499638
update)
500639
print_status "🔄 Updating validator..."
640+
echo "This will:"
641+
echo " • Pull latest scripts and configuration"
642+
echo " • Download latest pchaind binary from GitHub releases"
643+
echo " • Rebuild the validator image"
644+
echo
645+
646+
read -p "Continue with update? (yes/no): " confirm
647+
if [[ ! "$confirm" =~ ^[Yy][Ee][Ss]$ ]]; then
648+
echo "Update cancelled"
649+
exit 0
650+
fi
651+
652+
# Pull latest repository changes
653+
print_status "📥 Updating repository..."
501654
git pull
502-
$DOCKER_COMPOSE pull
503-
print_success "✅ Update complete. Restart validator to apply changes."
655+
656+
# Rebuild image with latest binary
657+
print_status "🔨 Rebuilding image with latest binary..."
658+
$DOCKER_COMPOSE build --no-cache
659+
660+
print_success "✅ Update complete!"
661+
echo
662+
echo "Next steps:"
663+
echo " • Restart validator: ./push-node-manager restart"
664+
echo " • Check status: ./push-node-manager status"
504665
;;
505666

506667
validators|list-validators)
@@ -1070,7 +1231,7 @@ $(echo -e "${BOLD}${GREEN}Wallet & Keys:${NC}")
10701231
$(echo -e "${BOLD}${GREEN}Maintenance:${NC}")
10711232
reset-data Reset blockchain data (keeps wallets)
10721233
reset-all $(echo -e "${RED}DANGER:${NC}") Complete reset - deletes EVERYTHING!
1073-
update Update node software to latest version
1234+
update Update node software to latest version (or set AUTO_UPDATE=true)
10741235
public-setup Setup HTTPS endpoints for public access (Linux only)
10751236
help Show this help message
10761237
@@ -1095,6 +1256,11 @@ $(echo -e "${BOLD}Wallet Management:${NC}")
10951256
./push-node-manager keys show mykey # Show address for 'mykey'
10961257
./push-node-manager backup # Backup your keys
10971258
1259+
$(echo -e "${BOLD}Updates:${NC}")
1260+
./push-node-manager update # Manual update (default)
1261+
echo "AUTO_UPDATE=true" >> .env # Enable automatic updates
1262+
./push-node-manager start # Auto-updates if enabled
1263+
10981264
$(echo -e "${BOLD}Troubleshooting:${NC}")
10991265
./push-node-manager test # Run health checks
11001266
./push-node-manager reset-data # Reset blockchain data

0 commit comments

Comments
 (0)