Skip to content

Commit

Permalink
Merge feat/cosmovisor
Browse files Browse the repository at this point in the history
- Add SETUP.md for how to setup a cosmovisor based validator node
- Provide pulumi script for provision GCP/Azure resource
- Provide systemd service template
- Update docker-compose template for cosmovisor
  • Loading branch information
rickmak committed Mar 3, 2022
2 parents ab00361 + 02d3486 commit aabee90
Show file tree
Hide file tree
Showing 21 changed files with 1,587 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ docker-compose.yml

artifacts
build
dist
release
dist/
deploy/liked.service
20 changes: 19 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
FROM likecoin/rbuilder:cf0d1a9f3731e30540bbfa36a36d13e4dcccf5eb as builder

USER root
ARG LIKED_VERSION=unknown
ARG LIKED_COMMIT=unknown

WORKDIR /cosmovisor
RUN wget https://github.com/cosmos/cosmos-sdk/releases/download/cosmovisor%2Fv1.1.0/cosmovisor-v1.1.0-linux-amd64.tar.gz
RUN tar -xzvf cosmovisor-v1.1.0-linux-amd64.tar.gz

USER builder
COPY . /sources
WORKDIR /sources

Expand All @@ -16,6 +22,18 @@ RUN /bin/bash -c /sources/.build.sh

FROM debian:buster

WORKDIR /usr/bin
RUN groupadd --gid 1000 likechain \
&& useradd --uid 1000 --gid likechain --shell /bin/bash likechain
WORKDIR /likechain
RUN mkdir -p /likechain/.liked/cosmovisor/genesis/bin
RUN chown -R likechain:likechain /likechain
RUN chmod -R g+w /likechain
ENV DAEMON_NAME liked
ENV DAEMON_HOME /likechain/.liked
ENV DAEMON_ALLOW_DOWNLOAD_BINARIES true
ENV DAEMON_RESTART_AFTER_UPGRADE true
RUN apt-get update && apt-get install -y curl
COPY --from=builder /cosmovisor/cosmovisor /usr/bin/cosmovisor
COPY --from=builder ./home/builder/artifacts/liked-*-linux-amd64 /usr/bin/liked
USER likechain:likechain
RUN cp /usr/bin/liked /likechain/.liked/cosmovisor/genesis/bin/liked
154 changes: 154 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Node Setup

This document describe how to setup cosmovisor and respective likecoin node. The intended audience is developer would like to test out locally. For a more validator production setup document, one should found at https://docs.like.co

The developer team maintains 3 way on running the node software, they are:

1. `systemd` based.
2. `docker` and `docker-compose` based.
3. Run at shell.

It depends on the situation which one is better. Since the development resource is limiting, we are planning to drop maintaining `docker-compose` way. So if you are new to the ecosystem, I recommend to check out the `systemd` way.

## systemd based, recommended

Following is assuming your OS is Linux based with systemd installed.

Following command will download a pre-compiled binary from Github. For compiling locally, please checkout `RELEASE.md` for details.

To setup a node using our setup script, please run the following command in the project root folder

```
make -C deploy setup-node MONIKER=$MONIKER
```

After the initialization, you may run the following commands to start the node as a service.

```
make -C deploy initialize-systemctl
make -C deploy start-node
```

Above command is warp around `systemctl`. For checking logs, you can run

```
journalctl -u liked.service -f
```

For more advance usage, please checkout the doc of `systemctl` and `journalctl`.

**NOTE: If any existing liked instance is running, Please terminate them before starting a new node to prevent double signing**

For converting the full node into validator, you should able to interact with `liked` directly.

### Advanced Setup

By default, the [node-setup.sh](../deploy/scripts/node-setup.sh) script would download the latest cosmovisor and like binary to the working folder to setup the node automatically. Please refer to the table below for environment variables you can override.

| Env | Description | Default |
| ------------------ | ----------------------------------------------------------------------------------- | ------------------------------------ |
| MONIKER | Moniker identifier for the node, this is mandatory for the node setup | Empty |
| LIKED_VERSION | Release version of the latest like binary | Latest tag using git describe --tags |
| COSMOVISOR_VERSION | Release version of the latest cosmovisor binary | 1.1.0 |
| LIKED_WORKDIR | Working directory, binaries will be downloaded here | $HOME |
| LIKED_HOME | Home directory for the like node, chain data and configurations will be stored here | $HOME/.liked |
| LIKED_USER | User used for 'liked.service' to run on behalf of | $USER |

## Docker based

**NOTE: The docker image is only for amd64, arm(i.e. Apple M1) is currently unsupported.**

### Setting up a full node

1. Get the URL of the genesis file and other parameters (e.g. seed node) of the network.
2. Copy `.env.template` to `.env`, and also `docker-compose.yml.template` to `docker-compose.yml`.
3. Edit `.env` for config on `LIKECOIN_CHAIN_ID`, `LIKECOIN_MONIKER`, `LIKECOIN_GENESIS_URL` and `LIKECOIN_SEED_NODES`. See comments in the file.
4. Run `docker-compose run --rm init` to setup node data in `.liked` folder.
5. Run `docker-compose up -d` to start up the node and wait for synchronization.
6. Then you may check the logs by `docker-compose logs --tail 1000 -f`.

### Converting a full not into validator node

1. Setup a full node by following the section above.
2. Make sure the node is synchronized, by checking `localhost:26657/status` and see if `result.sync_info.catching_up` is `false`.
3. Setup validator key by `docker-compose run --rm liked-command keys add validator` and follow the instructions. This will generate a key named `validator` in the keystore.
4. Get the address and mnemonic words from the output of the command above. Jot down the address (`cosmos1...`) and backup the mnemonic words.
5. Deposit some LIKE in the above address. LIKE tokens are needed for creating validator.
6. Run `docker-compose run --rm create-validator --amount <AMOUNT> --details <DETAILS> --commission-rate <COMMISSION_RATE>` to create and activate validator. `<AMOUNT>` is the amount for self-delegation (e.g. `100000000000nanolike` for 100 LIKE), `<DETAILS>` is the introduction of the validator, `<COMMISSION_RATE>` is the commission you receive from delegators (e.g. `0.1` for 10%).
7. After sending the create validator transaction, your node should become a validator.

## Run node at shell locally for development or testing

If you wish to start the node locally, run the following commands

```
MONIKER=<your moniker> make -C deploy setup-node
export DAEMON_NAME=liked
export DAEMON_HOME="$HOME/.liked"
$(LIKED_WORKDIR)/cosmovisor run start
```

# Upgrades

As a process manager, Cosmovisor automatically download and upgrade binary as upgrade proposals are approved on chain.

There are two methods to upgrading the chain version using cosmovisor.

## Automatic Upgrade

An automatic upgrade will be executed if an upgrade proposal is submitted and approved with the upgrade info attached. With this method, no extra action is required and cosmovisor will be able to download the suitable binary and replace the current executable in which the process will restart itself automatically when the upgrade block is reached. However, one should monitor the upgrade process to ensure the upgrade is executed successfully.

## Manual Upgrade

If a manual upgrade is expected, the new binary should be placed inside

```
$HOME/.liked/cosmovisor/upgrades/<upgrade_name>/bin
```

Once the upgrade block is reached, cosmovisor should be able to link the `current` folder to the destinated upgrade folder and automatically restart itself to continue the block syncing process with the latest binary. An extra `upgrade-info.json` file will be generated to indicate the metadata for the upgrade.

## Upgrade Proposal

To submit an auto upgrade proposal, execute the following command

```
./liked tx gov submit-proposal software-upgrade $UPGRADED_VERSION \
--title "$TITLE" \
--description "$DESCRIPTION" \
--from $ACCOUNT \
--upgrade-height $UPGRADE_HEIGHT \
--upgrade-info '{"binaries":{"linux/amd64":"$BINARY_URL","darwin/amd64":"$BINARY_URL"}}' \
--deposit 10000000nanolike \
--chain-id $CHAIN_ID \
-y
```

Query the proposal to ensure its existance

```
./liked query gov proposal $PROPOSAL_ID
```

Deposite a certain amount of `LIKE` to the proposal

```
./liked tx gov deposit $PROPOSAL_ID 10000000nanolike --from $ACCOUNT --yes
```

Proceed to submit a `Yes` vote for the proposal

```
./liked tx gov vote $PROPOSAL_ID yes --from $ACCOUNT --chain-id $CHAIN_ID -y
```

To submit a manual uprade proposal, remove `--upgrade-info` from the proposal submission command above.
Note that this will require the new binary to be placed in `/.liked/cosmovisor/upgrades/$UPGRADED_VERSION/bin` for the
upgrade to be executed successfully.

# Dependencies

[Cosmovisor](https://docs.cosmos.network/master/run-node/cosmovisor.html)
3 changes: 3 additions & 0 deletions deploy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
Pulumi.*.yaml
id_rsa*
29 changes: 29 additions & 0 deletions deploy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
STACK ?= validator
CLOUD ?= azure

include ./cmd/deploy/assets/Makefile

.PHONY: setup-pulumi
setup-pulumi:
pulumi stack init $(STACK)
cp ./Pulumi.$(CLOUD).yaml.template "./Pulumi.$(STACK).yaml"

.PHONY: ssh-key
ssh-key:
ssh-keygen -t rsa -f id_rsa -m PEM
pulumi config set -s $(STACK) \
likecoin-skynet:resource-group-name $(RESOURCE_GROUP)
pulumi config set -s $(STACK) \
likecoin-skynet:vm-ssh-allow-list $(SSH_WHITELIST)
pulumi config set -s $(STACK) \
likecoin-skynet:vm-password --secret $(PASSWORD)
cat id_rsa.pub | pulumi config set likecoin-skynet:vm-public-key --
cat id_rsa | pulumi config set likecoin-skynet:vm-private-key --secret --

.PHONY: deploy
deploy:
pulumi up -s $(STACK)

.PHONY: destroy
destroy:
pulumi destroy -s $(STACK)
13 changes: 13 additions & 0 deletions deploy/Pulumi.azure.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
config:
likecoin-skynet:cloud-provider: azure
likecoin-skynet:node-genesis: https://raw.githubusercontent.com/oursky/likecoin-skynet/master/genesis.json
likecoin-skynet:node-moniker: likecoin
likecoin-skynet:node-seeds: [email protected]:26656,[email protected]:26656
likecoin-skynet:resource-group-name: likecoin
likecoin-skynet:vm-password:
likecoin-skynet:vm-private-key:
likecoin-skynet:vm-public-key:
likecoin-skynet:vm-ssh-allow-list: ""
likecoin-skynet:vm-username: likecoin
likecoin-skynet:vm-hardware: Standard_B2s
likecoin-skynet:vm-disk-size: 50
14 changes: 14 additions & 0 deletions deploy/Pulumi.gcp.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
config:
likecoin-skynet:cloud-provider: gcp
likecoin-skynet:network-region: asia-southeast1
likecoin-skynet:node-genesis: https://raw.githubusercontent.com/oursky/likecoin-skynet/master/genesis.json
likecoin-skynet:node-moniker: likecoin
likecoin-skynet:node-seeds: [email protected]:26656,[email protected]:26656
likecoin-skynet:project-id: likecoin-devnet
likecoin-skynet:vm-private-key:
likecoin-skynet:vm-public-key:
likecoin-skynet:vm-ssh-allow-list: ""
likecoin-skynet:vm-disk-size: "50"
likecoin-skynet:vm-username: likecoin
likecoin-skynet:vm-hardware: e2-medium
likecoin-skynet:vm-zone: asia-southeast1-b
4 changes: 4 additions & 0 deletions deploy/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: likecoin-skynet
runtime: go
main: cmd/deploy
description: likecoin-skynet-deployment
Loading

0 comments on commit aabee90

Please sign in to comment.