# Cosmovisor

### Cosmovisor

> Please refer to the Cosmovisor documentation for further information. <https://docs.cosmos.network/main/build/tooling/cosmovisor>

> `cosmovisor` is a process manager for Cosmos SDK application binaries that automates application binary switch at chain upgrades. It polls the `upgrade-info.json` file that is created by the x/upgrade module at upgrade height, and then can automatically download the new binary, stop the current binary, switch from the old binary to the new one, and finally restart the node with the new binary.
>
> ‼️
>
> If you have been running without using Cosmovisor for a while and are now preparing to use Cosmovisor, please note that you need to check if `upgrade-info.json` file exists under `WORKSPACE/data/` Please remove it during the initial run Cosmovisor.

**To Install the latest version.**

```bash
go  install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest
```

**Setup**

```bash
cd $WORKSPACE
mkdir -p cosmovisor/genesis/bin
mkdir -p cosmovisor/upgrades

cp bbcored cosmovisor/genesis/bin/  # copy current version of bbcored
```

**Systemd** `update -> /etc/systemd/system/bouncebit.service`

```bash
[Unit]
Description=Bouncebit Mainnet
After=network-online.target
[Service]
Type=simple
User=bouncebit 
ExecStart=cosmovisor run start --log_level info --home <WORKSPACE> --chain-id bouncebit_6001-1 --moniker <YOUR_NODE_NAME>
KillMode=process
Restart=on-failure
RestartSec=3
Environment="DAEMON_HOME=<WORKSPACE>" # replace!
Environment="DAEMON_NAME=bbcored"
Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=false"
Environment="DAEMON_RESTART_AFTER_UPGRADE=true"
Environment="UNSAFE_SKIP_BACKUP=true"
[Install]
WantedBy=multi-user.target
```

```bash
systemctl daemon-reload
systemctl start bouncebit.service
systemctl enable bouncebit.service
```

**When requested to upgrade to the new version.**

```bash
cd $WORKSPACE

# download the new bbcored (v1.5.0)
 
mkdir -p cosmovisor/upgrades/v1.5.0/bin  # replace version
cp bbcored cosmovisor/upgrades/v1.5.0/bin/  
```

\<aside> ‼️ **Please ensure to use StateSync or Archive Snapshot to synchronize the mainnet node.**

\</aside>

#### StateSync

> With state sync, your node will download and verify data only related to the head or near the head of the chain.

Fetch the latest block height.

```bash
curl -s <http://34.126.185.25:26657/block> | jq -r '.result.block.header.height'

224136
```

Fetch the trust hash of the latest block height.

```bash
curl -s "<http://34.126.185.25:26657/block?height=224136>" | jq -r '.result.block_id.hash'

FC1E650D149713BF9AB0072C084CE4B7CAD0ABA503C32CD64F759651BB66A7C2
```

Enable state-sync, add RPC servers

**config.toml**

```bash
[statesync]

enable = true
rpc_servers = "34.126.185.25:26657,35.247.178.93:26657"
trust_height = 224136
trust_hash = "FC1E650D149713BF9AB0072C084CE4B7CAD0ABA503C32CD64F759651BB66A7C2"

```

**app.toml**

```bash
[rosetta]

enable = false
```

#### Archive Snapshot (pruning nothing)

✅ bouncebit\_archive\_snapshot\_2024\_12\_06.lz4

```bash
curl -o - -sL [<https://bouncebit-snapshot.s3.ap-southeast-1.amazonaws.com/>](<https://bouncebit-snapshot.s3.ap-southeast-1.amazonaws.com/bouncebit_archive_snapshot_2024-08-25.lz4>){{snapshot_file}} | lz4 -c -d - | tar -x -C  $HOME 
```
