From e5f78e1eb9e8eb2cc0583a840a90cab182e57d9e Mon Sep 17 00:00:00 2001 From: alexpaynex <55271826-alexpaynex@users.noreply.replit.com> Date: Wed, 18 Mar 2026 18:34:48 +0000 Subject: [PATCH] Add interactive configuration for sweep thresholds and frequency Introduce a new command `bash ops.sh configure-sweep` to interactively set and update auto-sweep parameters, including cold address, on-chain thresholds, and sweep frequency, while also updating the cron schedule and providing user-friendly feedback in `ops.sh sweep`. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 418bf6f8-212b-4bb0-a7a5-8231a061da4e Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 3c6bbb97-1029-4402-bba7-d04e3f992bd6 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9f85e954-647c-46a5-90a7-396e495a805a/418bf6f8-212b-4bb0-a7a5-8231a061da4e/sPDHkg8 Replit-Helium-Checkpoint-Created: true --- infrastructure/lnd-init.sh | 11 ++--- infrastructure/ops.sh | 85 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 11 deletions(-) diff --git a/infrastructure/lnd-init.sh b/infrastructure/lnd-init.sh index 428a0e2..9ee4d47 100755 --- a/infrastructure/lnd-init.sh +++ b/infrastructure/lnd-init.sh @@ -155,20 +155,17 @@ SWEEP_CONF="$INFRA_DIR/sweep.conf" if [[ -n "$COLD_ADDRESS" ]]; then cat > "$SWEEP_CONF" <> $INFRA_DIR/sweep.conf" diff --git a/infrastructure/ops.sh b/infrastructure/ops.sh index 0b0c528..f6c585f 100755 --- a/infrastructure/ops.sh +++ b/infrastructure/ops.sh @@ -115,16 +115,22 @@ case "${1:-help}" in echo -e "\n${CYAN}── Sweep config ──────────────────────────────${NC}" if [[ -f "$SWEEP_CONF" ]]; then - grep -v '^#' "$SWEEP_CONF" | grep -v '^$' || echo "(empty)" + COLD_ADDRESS=""; KEEP_SATS=300000; MIN_SWEEP=50000 + SWEEP_FREQ_LABEL="daily at 3am UTC"; SWEEP_CRON="0 3 * * *" + source "$SWEEP_CONF" + echo " Cold address : ${COLD_ADDRESS:-(not set — sweep disabled)}" + echo " Keep on-chain: ${KEEP_SATS} sats" + echo " Min to sweep : ${MIN_SWEEP} sats" + echo " Frequency : ${SWEEP_FREQ_LABEL}" else - echo -e "${YELLOW}No sweep.conf found — sweep is disabled${NC}" - echo " To enable: run lnd-init.sh, or create $SWEEP_CONF manually" + echo -e " ${YELLOW}No sweep.conf found — sweep is disabled${NC}" + echo " To configure: bash ops.sh configure-sweep" fi echo -e "\n${CYAN}── Current on-chain balance ──────────────────${NC}" docker exec lnd lncli --network=mainnet walletbalance 2>/dev/null \ | jq '{confirmed_balance, unconfirmed_balance}' \ - || echo "LND not ready" + || echo " LND not ready" echo -e "\n${CYAN}── Last 5 sweep log entries ──────────────────${NC}" if [[ -f "$SWEEP_LOG" && -s "$SWEEP_LOG" ]]; then @@ -135,6 +141,76 @@ case "${1:-help}" in echo "" ;; + configure-sweep) + SWEEP_CONF="$INFRA_DIR/sweep.conf" + + # Load current values as defaults + COLD_ADDRESS=""; KEEP_SATS=300000; MIN_SWEEP=50000 + SWEEP_CRON="0 3 * * *"; SWEEP_FREQ_LABEL="daily at 3am UTC" + [[ -f "$SWEEP_CONF" ]] && source "$SWEEP_CONF" + + echo -e "\n${CYAN}══════════════════════════════════════════${NC}" + echo -e "${CYAN} Configure Auto-Sweep (Enter = keep current)${NC}" + echo -e "${CYAN}══════════════════════════════════════════${NC}\n" + + # Cold address + echo -e " Current cold address: ${YELLOW}${COLD_ADDRESS:-(none)}${NC}" + read -rp " New cold address: " INPUT + [[ -n "$INPUT" ]] && COLD_ADDRESS="$INPUT" + + # Keep threshold + echo -e "\n Current keep-on-chain threshold: ${YELLOW}${KEEP_SATS} sats${NC}" + read -rp " New keep threshold (sats): " INPUT + [[ "$INPUT" =~ ^[0-9]+$ ]] && KEEP_SATS="$INPUT" + + # Min sweep floor + echo -e "\n Current minimum sweep amount: ${YELLOW}${MIN_SWEEP} sats${NC}" + read -rp " New minimum sweep (sats): " INPUT + [[ "$INPUT" =~ ^[0-9]+$ ]] && MIN_SWEEP="$INPUT" + + # Frequency + echo -e "\n Current frequency: ${YELLOW}${SWEEP_FREQ_LABEL}${NC}" + echo " Choose a new frequency (Enter to keep current):" + echo " 1) Hourly" + echo " 2) Every 6 hours" + echo " 3) Daily at 3am UTC" + echo " 4) Weekly (Sunday 3am UTC)" + read -rp " Choice [1-4]: " FREQ_CHOICE + case "$FREQ_CHOICE" in + 1) SWEEP_CRON="0 * * * *"; SWEEP_FREQ_LABEL="hourly" ;; + 2) SWEEP_CRON="0 */6 * * *"; SWEEP_FREQ_LABEL="every 6 hours" ;; + 3) SWEEP_CRON="0 3 * * *"; SWEEP_FREQ_LABEL="daily at 3am UTC" ;; + 4) SWEEP_CRON="0 3 * * 0"; SWEEP_FREQ_LABEL="weekly (Sunday 3am UTC)" ;; + esac + + # Write sweep.conf — quote values that may contain spaces + cat > "$SWEEP_CONF" </dev/null | grep -v "timmy-node.*sweep" | crontab - || true + (crontab -l 2>/dev/null; echo "# Timmy Node — auto-sweep ($SWEEP_FREQ_LABEL)") | crontab - + (crontab -l 2>/dev/null; echo "$SWEEP_CRON bash $INFRA_DIR/sweep.sh > /dev/null 2>&1") | crontab - + + echo -e "\n${GREEN}Sweep configured:${NC}" + echo " Cold address : ${COLD_ADDRESS:-(not set — sweep disabled)}" + echo " Keep on-chain: ${KEEP_SATS} sats" + echo " Min to sweep : ${MIN_SWEEP} sats" + echo " Frequency : ${SWEEP_FREQ_LABEL}" + echo "" + echo -e " Run now to test: ${CYAN}bash ops.sh run-sweep${NC}" + echo "" + ;; + run-sweep) echo -e "${CYAN}Running sweep now...${NC}" bash "$INFRA_DIR/sweep.sh" @@ -154,6 +230,7 @@ case "${1:-help}" in echo " bash ops.sh update — pull latest Docker images" echo " bash ops.sh backup — backup LND channel state" echo " bash ops.sh sweep — show sweep config, balance, and last sweep log" + echo " bash ops.sh configure-sweep — interactively set address, thresholds, frequency" echo " bash ops.sh run-sweep — run sweep immediately (outside of cron schedule)" echo "" ;;