# Halt stage0 and start stage1

Once all the participants have completed their onboarding, stage0 laconicd chain can be halted and stage1 chain can be initialized and started

## Login

* Log in as `dev` user on the deployments VM

* All the deployments are placed in the `/srv` directory:

  ```bash
  cd /srv
  ```

## Halt stage0

* Confirm the the currently running node is for stage0 chain:

  ```bash
  cd /srv/laconicd

  laconic-so deployment --dir stage0-deployment logs laconicd -f --tail 30
  ```

* Stop the stage0 deployment:

  ```bash
  laconic-so deployment --dir stage0-deployment stop
  ```

## Start stage1

* Rebuild laconicd container with `>=v0.1.7` to enable `slashing` module:

  ```bash
  # laconicd source
  cd ~/cerc/laconicd

  # Pull latest changes
  git pull

  # Confirm the latest commit hash
  git log

  # Rebuild the containers
  cd /srv/laconicd

  laconic-so --stack ~/cerc/fixturenet-laconicd-stack/stack-orchestrator/stacks/fixturenet-laconicd build-containers --force-rebuild
  ```

* Fetch the generated genesis file with stage1 participants and token allocations:

  ```bash
  # Place in stage1 deployment directory
  wget -O /srv/laconicd/stage1-deployment/data/genesis-config/genesis.json https://git.vdb.to/cerc-io/testnet-laconicd-stack/raw/branch/main/ops/stage1/genesis-accounts.json
  ```

* Start the stage1 deployment:

  ```bash
  laconic-so deployment --dir stage1-deployment start
  ```

* Check status of stage1 laconicd:

  ```bash
  # List down the container and check health status
  docker ps -a | grep laconicd

  # Follow logs for laconicd container, check that new blocks are getting created
  laconic-so deployment --dir stage1-deployment logs laconicd -f
  ```

* Query the list of registered participants in stage1 laconicd:

  ```bash
  laconic-so deployment --dir stage1-deployment exec laconicd "laconicd query onboarding list"

  # Confirm that all onboarded participants on stage0 appear in the list
  ```

* Get the node's peer adddress and stage1 genesis file to share with the participants:

  * Get the node id:

    ```bash
    echo $(laconic-so deployment --dir stage1-deployment exec laconicd "laconicd cometbft show-node-id")@laconicd.laconic.com:26656
    ```

  * Get the genesis file:

    ```bash
    scp dev@<deployments-server-hostname>:/srv/laconicd/stage1-deployment/data/laconicd-data/config/genesis.json </path/to/local/directory>
    ```

* Now users can follow the steps to [Join as a validator on stage1](../testnet-onboarding-validator.md#join-as-a-validator-on-stage1)

## Bank Transfer

* Transfer tokens to an address:

  ```bash
  cd /srv/laconicd

  RECEIVER_ADDRESS=
  AMOUNT=

  laconic-so deployment --dir stage1-deployment exec laconicd "laconicd tx bank send alice ${RECEIVER_ADDRESS} ${AMOUNT}alnt --from alice --fees 1000000alnt"
  ```

* Check balance:

  ```bash
  laconic-so deployment --dir stage1-deployment exec laconicd "laconicd query bank balances ${RECEIVER_ADDRESS}"
  ```

---

## Generating stage1 genesis

* Following steps to be run on a local machine

* Clone repos:

  ```bash
  git clone git@git.vdb.to:cerc-io/testnet-laconicd-stack.git

  git clone git@git.vdb.to:cerc-io/fixturenet-laconicd-stack.git
  ```

* Create stage1 participants and allocations using provided validators list:

  * Prerequisite: `validators.csv` file with list of laconic addresses, example:

    ```csv
    laconic13ftz0c6cg6ttfda7ct4r6pf2j976zsey7l4wmj
    laconic1he4wjpfm5atwfvqurpg57ctp8chmxt9swf02dx
    laconic1wpsdkwz0t4ejdm7gcl7kn8989z88dd6wwy04np
    ...
    ```

  * Build

    ```bash
    # Change to scripts dir
    cd testnet-laconicd-stack/scripts

    # Install dependencies and build
    yarn && yarn build
    ```

  * Run script

    ```bash
    yarn participants-with-filtered-validators --validators-csv ./validators.csv --participant-alloc 200000000000 --validator-alloc 1000200000000000 --output stage1-participants-$(date +"%Y-%m-%dT%H%M%S").json --output-allocs stage1-allocs-$(date +"%Y-%m-%dT%H%M%S").json

    # This should create two json files with stage1 participants and allocations
    ```

* Create stage1 genesis file:

  ```bash
  # Change to fixturenet-laconicd stack dir
  cd fixturenet-laconicd-stack/stack-orchestrator/stacks/fixturenet-laconicd

  # Generate genesis file
  # Provide absolute paths to generated stage1-participants and stage1-allocs files
  ./scripts/generate-stage1-genesis-from-json.sh /path/to/testnet-laconicd-stack/scripts/stage1-participants.json /path/to/testnet-laconicd-stack/scripts/stage1-allocs.json

  # This should generate the required genesis file at output/genesis.json
  ```
