From 05352ee90c66034703e7e82ae43b6a18de9ee0e5 Mon Sep 17 00:00:00 2001 From: Anish gehlot Date: Thu, 26 Feb 2026 11:48:32 +0530 Subject: [PATCH] refactor: update deploy surge full sh scriptadd steps functionality --- README.md | 124 ++++++++++++++++ deploy-surge-full.sh | 338 +++++++++++++++++++++++++++++++------------ 2 files changed, 369 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 90e5f401..8a1dba92 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,130 @@ This repository is ideal for easy set up operating Layer 2 (L2) solutions, simpl For detailed deployment and removal instructions, see [DEPLOYMENT.md](./DEPLOYMENT.md). +## `deploy-surge-full.sh` Help + +```bash +./deploy-surge-full.sh --help +``` + +### Usage + +```text +./deploy-surge-full.sh [OPTIONS] +``` + +### Description + +Deploy complete Surge stack with L1 (optional devnet) and L2 components. + +### Options + +- `--environment ENV` - Surge environment (`devnet|staging|testnet`) **[REQUIRED]** +- `--deploy-devnet BOOL` - Deploy new devnet or use existing chain (devnet only, `true|false`) +- `--deployment TYPE` - Deployment type (`local|remote`) +- `--deployment-key KEY` - Private key for contract deployment (will be verified) +- `--stack-option NUM` - L2 stack option (`1-6`, see details below) +- `--running-provers BOOL` - Setup provers (devnet only, `true|false`) +- `--deposit-bond BOOL` - Deposit bond (devnet only, `true|false`) +- `--bond-amount NUM` - Bond amount in ETH (default: `1000`) +- `--start-relayers BOOL` - Start relayers (`true|false`) +- `--mode MODE` - Execution mode (`silence|debug`) +- `-f, --force` - Skip confirmation prompts +- `-h, --help` - Show this help message + +### Stack Options + +- `1` - Driver only +- `2` - Driver + Proposer +- `3` - Driver + Proposer + Spammer +- `4` - Driver + Proposer + Prover + Spammer +- `5` - All except spammer +- `6` - All components (default) + +### Execution Modes + +- `silence` - Silent mode with progress indicators (default) +- `debug` - Debug mode with full output + +### Examples + +```bash +./deploy-surge-full.sh --environment devnet --deploy-devnet true --mode debug +./deploy-surge-full.sh --environment staging --stack-option 3 --start-relayers true +``` + +### Functional Steps (Execution Flow) + +When you run `./deploy-surge-full.sh`, the script performs these steps in order: + +1. Parse CLI args and show help if requested. +2. Validate prerequisites (`docker`, `git`, `jq`, `curl`, `bc`, `cast`) and create required folders. +3. Initialize git submodules. +4. Select/load environment (`devnet`, `staging`, `testnet`) and load `.env` settings. +5. Configure endpoint URLs for local/remote deployment context. +6. For `devnet`, choose L1 path: + - Deploy new devnet, or + - Use existing chain (WIP path). +7. For `devnet`, run protocol deployment flow: + - simulate L1 deploy, + - extract deployment outputs, + - generate L2 genesis, + - deploy L1 contracts, + - deploy Pacaya contracts, + - extract outputs again, + - optionally deploy provers. +8. Start L2 stack based on selected `--stack-option`. +9. Switch fork configuration. +10. Optionally start relayers (and deploy L2 contracts first when needed). +11. Optionally start tx spammer (for stack options including spammer). +12. Verify RPC endpoints and print deployment summary. + + +#### Steps: +```bash + preflight - Validate deps, init submodules, load env, configure endpoints + l1-infra - Deploy/check L1 devnet infrastructure (devnet only) + l1-contracts - Run L1 contracts flow up to broadcast (devnet only) + pacaya - Deploy Pacaya contracts + extract + optional provers (devnet only) + l2-stack - Start L2 stack + switch-fork - Switch fork profile + l2-contracts - Deploy L2 contracts (devnet only) + relayers - Start relayers and bridge UI + verify - Verify RPC endpoints + summary - Print deployment summary +``` + +### Step-by-Step Usage + +#### 1) Full devnet (recommended defaults) + +```bash +./deploy-surge-full.sh --environment devnet --deploy-devnet true --force +``` + +#### 2) Use existing L1 chain for devnet flow + +```bash +./deploy-surge-full.sh --environment devnet --deploy-devnet false --mode debug +``` + +#### 3) Staging with partial stack and relayers + +```bash +./deploy-surge-full.sh \ + --environment staging \ + --deployment remote \ + --stack-option 3 \ + --start-relayers true \ + --mode debug +``` + +#### 4) Testnet with non-interactive prompts + +```bash +./deploy-surge-full.sh --environment testnet --force +``` + ## Documentation - **[DEPLOYMENT.md](./DEPLOYMENT.md)** - Complete guide for deploying and removing the Surge stack diff --git a/deploy-surge-full.sh b/deploy-surge-full.sh index 44a08f93..82ea708c 100755 --- a/deploy-surge-full.sh +++ b/deploy-surge-full.sh @@ -51,6 +51,7 @@ bond_amount="" start_relayers="" mode="" force="" +steps="" # verify_key_only="" # Colors for output @@ -77,6 +78,14 @@ log_error() { echo -e "\n${RED}[ERROR]${NC} $1" >&2 } +# Step logging helper +log_step() { + local step="$1" + local title="$2" + local total_steps=7 + echo -e "\n${BLUE}[STEP ${step}/${total_steps}]${NC} ${title}" +} + # Show usage help show_help() { echo "Usage:" @@ -96,6 +105,7 @@ show_help() { echo " --deposit-bond BOOL Deposit bond (devnet only, true|false)" echo " --bond-amount NUM Bond amount in ETH (default: 1000)" echo " --start-relayers BOOL Start relayers (true|false)" + echo " --steps LIST Run selected steps only (comma-separated)" echo " --mode MODE Execution mode (silence|debug)" # echo " --verify-key-only Only verify private key, don't deploy" echo " -f, --force Skip confirmation prompts" @@ -116,9 +126,77 @@ show_help() { echo "Examples:" echo " $0 --environment devnet --deploy-devnet true --mode debug" echo " $0 --environment staging --stack-option 3 --start-relayers true" + echo " $0 --environment devnet --steps preflight,l1-infra,l1-contracts,pacaya" + echo + echo "Steps:" + echo " preflight - Validate deps, init submodules, load env, configure endpoints" + echo " l1-infra - Deploy/check L1 devnet infrastructure (devnet only)" + echo " l1-contracts - Run L1 contracts flow up to broadcast (devnet only)" + echo " pacaya - Deploy Pacaya contracts + extract + optional provers (devnet only)" + echo " l2-stack - Start L2 stack" + echo " switch-fork - Switch fork profile" + echo " l2-contracts - Deploy L2 contracts (devnet only)" + echo " relayers - Start relayers and bridge UI" + echo " verify - Verify RPC endpoints" + echo " summary - Print deployment summary" exit 0 } +custom_steps_mode="false" +selected_steps="" + +configure_selected_steps() { + local input_steps="$1" + local normalized="${input_steps//,/ }" + + if [[ -z "$normalized" ]]; then + log_error "Empty --steps value" + return 1 + fi + + selected_steps="" + for raw_step in $normalized; do + local step + step=$(echo "$raw_step" | tr '[:upper:]' '[:lower:]') + case "$step" in + preflight|l1-infra|l1-contracts|pacaya|l2-stack|switch-fork|l2-contracts|relayers|verify|summary) + if [[ " $selected_steps " != *" $step "* ]]; then + selected_steps="$selected_steps $step" + fi + ;; + all) + custom_steps_mode="false" + selected_steps="" + return 0 + ;; + *) + log_error "Invalid step in --steps: $raw_step" + log_error "Run with --help to see available steps" + return 1 + ;; + esac + done + + custom_steps_mode="true" + + # Later steps rely on env and endpoint setup, so ensure preflight is always included. + if [[ " $selected_steps " != *" preflight "* ]]; then + log_warning "Auto-including preflight for step dependencies" + selected_steps=" preflight$selected_steps" + fi + + return 0 +} + +should_run_step() { + local step="$1" + if [[ "$custom_steps_mode" != "true" ]]; then + return 0 + fi + + [[ " $selected_steps " == *" $step "* ]] +} + # Parse command line arguments parse_arguments() { while [[ $# -gt 0 ]]; do @@ -167,6 +245,10 @@ parse_arguments() { mode="$2" shift 2 ;; + --steps) + steps="$2" + shift 2 + ;; # --verify-key-only) # verify_key_only="true" # shift @@ -2127,6 +2209,7 @@ start_l2_stack() { start_relayers() { local should_start_relayers="$1" local environment="$2" + local skip_l2_contracts="${3:-false}" if [[ "$should_start_relayers" == "1" ]]; then log_info "Skipping relayers as requested" @@ -2134,7 +2217,7 @@ start_relayers() { fi # Deploy L2 SCs first for devnet environment - if [[ "$environment" == "1" || "$environment" == "devnet" ]]; then + if [[ "$skip_l2_contracts" != "true" ]] && [[ "$environment" == "1" || "$environment" == "devnet" ]]; then if ! deploy_l2; then log_error "Failed to deploy L2 contracts, cannot start relayers" return 1 @@ -2401,29 +2484,47 @@ main() { # Parse arguments parse_arguments "$@" + + if [[ -n "${steps:-}" ]]; then + if ! configure_selected_steps "$steps"; then + exit 1 + fi + if [[ "$custom_steps_mode" == "true" ]]; then + log_info "Custom steps mode enabled:${selected_steps}" + fi + fi log_info "Starting $SCRIPT_NAME..." - # Validate prerequisites - if ! validate_prerequisites; then - log_error "Prerequisites validation failed" - exit 1 - fi + local mode_choice="debug" + local slow_mode=false + local stack_choice=6 + local mock_proof=0 - # Initialize submodules - initialize_submodules + # Step 1: Preflight + Environment Selection + if should_run_step preflight; then + log_step 1 "Preflight, environment selection and base URL configuration" + + # Validate prerequisites + if ! validate_prerequisites; then + log_error "Prerequisites validation failed" + exit 1 + fi + + # Initialize submodules + initialize_submodules + + # If verify-key-only is set, just verify the key and exit (WIP due to using existing chain) + # if [[ "$verify_key_only" == "true" ]]; then + # if [[ -z "$deployment_key" ]] || [[ -z "$l1-rpc_url" ]]; then + # log_error "Both --deployment-key and --l1-rpc-url are required for --verify-key-only" + # exit 1 + # fi + # verify_private_key_on_chain "$deployment_key" "$l1_rpc_url" "provided chain" + # exit $? + # fi + fi - # If verify-key-only is set, just verify the key and exit (WIP due to using existing chain) - # if [[ "$verify_key_only" == "true" ]]; then - # if [[ -z "$deployment_key" ]] || [[ -z "$l1_rpc_url" ]]; then - # log_error "Both --deployment-key and --l1-rpc-url are required for --verify-key-only" - # exit 1 - # fi - # verify_private_key_on_chain "$deployment_key" "$l1_rpc_url" "provided chain" - # exit $? - # fi - - # Step 1: Environment Selection local env_choice if [[ -z "${environment:-}" ]]; then if [[ "$force" == "true" ]]; then @@ -2487,11 +2588,13 @@ main() { log_error "Failed to configure environment URLs" exit 1 fi - + # Step 2: L1 Infrastructure Decision + if should_run_step l1-infra; then + log_step 2 "L1 infrastructure decision" + fi local deploy_devnet_choice - local slow_mode - if [[ "$env_choice" == "1" || "$env_choice" == "devnet" ]]; then + if should_run_step l1-infra && [[ "$env_choice" == "1" || "$env_choice" == "devnet" ]]; then # Devnet: prompt for deploy devnet or use existing if [[ -z "${deploy_devnet:-}" ]]; then if [[ "$force" == "true" ]]; then @@ -2577,11 +2680,16 @@ main() { fi fi - # Step 3: L1 Protocol Deployment (ONLY for devnet) - if [[ "$env_choice" == "1" || "$env_choice" == "devnet" ]]; then + # Step 3a/3b: L1 contracts + Pacaya (devnet only) + if [[ "$env_choice" == "1" || "$env_choice" == "devnet" ]] && { should_run_step l1-contracts || should_run_step pacaya; }; then + if [[ -n "${mode:-}" ]]; then + case "$mode" in + 0|"silence"|"silent") mode_choice="silence" ;; + 1|"debug") mode_choice="debug" ;; + *) mode_choice="$mode" ;; + esac + fi - # Deploy L1 contracts - local mock_proof if [[ "$force" == "true" ]]; then mock_proof=0 # default: mock prover else @@ -2597,46 +2705,54 @@ main() { read -p "Enter choice [0]: " mock_proof mock_proof=${mock_proof:-0} fi - - # Run L1 contracts simulation - if ! deploy_l1_contracts "$mode_choice" false $mock_proof false; then - log_error "Failed to deploy L1 smart contracts" - exit 1 - fi - # Extract L1 deployment results - if ! extract_l1_deployment_results; then - log_error "Failed to extract L1 deployment results" - exit 1 - fi + if should_run_step l1-contracts; then + log_step 3 "L1 contracts flow (devnet only)" - # Generate L2 Genesis - if ! generate_l2_genesis "$mode_choice"; then - log_error "Failed to generate L2 genesis" - exit 1 - fi + # Run L1 contracts simulation + if ! deploy_l1_contracts "$mode_choice" false $mock_proof false; then + log_error "Failed to deploy L1 smart contracts" + exit 1 + fi - # Deploy L1 contracts - if ! deploy_l1_contracts "$mode_choice" true $mock_proof $slow_mode; then - log_error "Failed to deploy L1 smart contracts" - exit 1 - fi + # Extract L1 deployment results + if ! extract_l1_deployment_results; then + log_error "Failed to extract L1 deployment results" + exit 1 + fi - # Deploy Pacaya contracts - if ! deploy_pacaya_contracts "$mode_choice" $slow_mode; then - log_error "Failed to deploy Pacaya smart contracts" - exit 1 - fi + # Generate L2 Genesis + if ! generate_l2_genesis "$mode_choice"; then + log_error "Failed to generate L2 genesis" + exit 1 + fi - # Extract L1 deployment results - if ! extract_l1_deployment_results; then - log_error "Failed to extract L1 deployment results" - exit 1 + # Deploy L1 contracts + if ! deploy_l1_contracts "$mode_choice" true $mock_proof $slow_mode; then + log_error "Failed to deploy L1 smart contracts" + exit 1 + fi fi - # Deploy Provers (optional) - must be after Pacaya contracts for PACAYA_TAIKO - if ! deploy_provers $mock_proof; then - log_warning "Prover deployment had issues, but continuing..." + if should_run_step pacaya; then + log_step 3 "Pacaya + provers flow (devnet only)" + + # Deploy Pacaya contracts + if ! deploy_pacaya_contracts "$mode_choice" $slow_mode; then + log_error "Failed to deploy Pacaya smart contracts" + exit 1 + fi + + # Extract L1 deployment results + if ! extract_l1_deployment_results; then + log_error "Failed to extract L1 deployment results" + exit 1 + fi + + # Deploy Provers (optional) - must be after Pacaya contracts for PACAYA_TAIKO + if ! deploy_provers $mock_proof; then + log_warning "Prover deployment had issues, but continuing..." + fi fi # Deposit bond (optional) @@ -2654,55 +2770,91 @@ main() { fi # Step 4: L2 Stack Deployment (ALL environments) - local stack_choice - if [[ -z "${stack_option:-}" ]]; then - if [[ "$force" == "true" ]]; then - stack_choice=6 # default: all components + if should_run_step l2-stack; then + log_step 4 "L2 stack deployment" + if [[ -z "${stack_option:-}" ]]; then + if [[ "$force" == "true" ]]; then + stack_choice=6 # default: all components + else + stack_choice=$(prompt_stack_option_selection) + fi else - stack_choice=$(prompt_stack_option_selection) + stack_choice=$stack_option + fi + + if ! start_l2_stack "$stack_choice"; then + log_error "Failed to start L2 stack" + exit 1 fi - else - stack_choice=$stack_option - fi - - if ! start_l2_stack "$stack_choice"; then - log_error "Failed to start L2 stack" - exit 1 fi - # Switch fork - if ! switch_fork "$mode_choice"; then - log_error "Failed to switch fork" - exit 1 + # Step 5: Switch fork + if should_run_step switch-fork; then + log_step 5 "Switch fork profile" + if ! switch_fork "$mode_choice"; then + log_error "Failed to switch fork" + exit 1 + fi fi - # Step 5: Start Relayers (optional) - local relayers_choice - if [[ -z "${start_relayers:-}" ]]; then - if [[ "$force" == "true" ]]; then - relayers_choice=0 # default: deploy relayers + # Step 6: L2 contracts (devnet only, optional standalone step) + if should_run_step l2-contracts; then + log_step 6 "L2 contracts deployment (devnet only)" + if [[ "$env_choice" == "1" || "$env_choice" == "devnet" ]]; then + if ! deploy_l2; then + log_error "Failed to deploy L2 smart contracts" + exit 1 + fi else - relayers_choice=$(prompt_relayers_selection) + log_info "Skipping l2-contracts step (not devnet)" fi - else - relayers_choice=$start_relayers fi - - if ! start_relayers "$relayers_choice" "$env_choice"; then - log_warning "Relayer startup had issues, but continuing..." + + # Step 7: Start Relayers (optional) + if should_run_step relayers; then + log_step 7 "Relayer startup (optional)" + local relayers_choice + if [[ -z "${start_relayers:-}" ]]; then + if [[ "$force" == "true" ]]; then + relayers_choice=0 # default: deploy relayers + else + relayers_choice=$(prompt_relayers_selection) + fi + else + relayers_choice=$start_relayers + fi + + local skip_l2_for_relayer="false" + if [[ "$custom_steps_mode" == "true" ]]; then + # In custom step mode, keep l2-contracts as an explicit standalone step. + skip_l2_for_relayer="true" + fi + + if ! start_relayers "$relayers_choice" "$env_choice" "$skip_l2_for_relayer"; then + log_warning "Relayer startup had issues, but continuing..." + fi fi # Step 5b: Start spammer now that L2 deploy is done (if stack option included it) - if [[ "$stack_choice" == "3" || "$stack_choice" == "4" || "$stack_choice" == "6" || -z "$stack_choice" ]]; then - log_info "Starting tx spammer..." - docker compose --profile spammer up -d tx-spammer >/dev/null 2>&1 || true + if should_run_step l2-stack; then + log_info "Step 5b: Optional tx spammer startup" + if [[ "$stack_choice" == "3" || "$stack_choice" == "4" || "$stack_choice" == "6" || -z "$stack_choice" ]]; then + log_info "Starting tx spammer..." + docker compose --profile spammer up -d tx-spammer >/dev/null 2>&1 || true + fi fi - # Step 6: Verification - verify_rpc_endpoints + # Step 8: Verification + if should_run_step verify; then + log_step 8 "RPC verification" + verify_rpc_endpoints + fi - # Step 7: Display Summary - display_deployment_summary + # Step 9: Display Summary + if should_run_step summary; then + log_step 9 "Deployment summary" + display_deployment_summary + fi log_success "Surge Full Stack deployment complete!" }