Skip to content

Commit

Permalink
[Documentation] Cosmovisor (#768)
Browse files Browse the repository at this point in the history
## Summary

Adds documentation on how to deploy a Validator and a Full Node using
Cosmovisor.

## Issue

- #526 

## Type of change

Select one or more:

- [ ] New feature, functionality or library
- [ ] Bug fix
- [ ] Code health or cleanup
- [x] Documentation
- [ ] Other (specify)

## Testing

- [ ] **Documentation**: `make docusaurus_start`; only needed if you
make doc changes
- [ ] **Unit Tests**: `make go_develop_and_test`
- [ ] **LocalNet E2E Tests**: `make test_e2e`
- [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR.

## Sanity Checklist

- [ ] I have tested my changes using the available tooling
- [ ] I have commented my code
- [ ] I have performed a self-review of my own code; both comments &
source code
- [ ] I create and reference any new tickets, if applicable
- [ ] I have left TODOs throughout the codebase, if applicable

---------

Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
okdas and Olshansk authored Sep 9, 2024
1 parent d0a379a commit 5ee73d4
Show file tree
Hide file tree
Showing 14 changed files with 493 additions and 54 deletions.
4 changes: 2 additions & 2 deletions cmd/poktrolld/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func queryCommand() *cobra.Command {
authcmd.QueryTxCmd(),
server.QueryBlockResultsCmd(),
)
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
cmd.PersistentFlags().String(flags.FlagChainID, DefaultChainID, "The network chain ID")

return cmd
}
Expand All @@ -114,7 +114,7 @@ func txCommand() *cobra.Command {
authcmd.GetDecodeCommand(),
authcmd.GetSimulateCmd(),
)
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
cmd.PersistentFlags().String(flags.FlagChainID, DefaultChainID, "The network chain ID")

return cmd
}
Expand Down
43 changes: 40 additions & 3 deletions cmd/poktrolld/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"sync"
"time"

cmtcfg "github.com/cometbft/cometbft/config"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
Expand Down Expand Up @@ -45,20 +46,46 @@ func checkOrInitSDKConfig() {
config.Seal()
}

// initCometBFTConfig helps to override default CometBFT Config values.
// return cmtcfg.DefaultConfig if no custom configuration is required for the application.
// The values set here become the default configuration for newly initialized nodes.
// However, it's crucial to note that:
// 1. These defaults only apply when a node is first initialized using `poktrolld init`.
// 2. Changing these values in the code will not automatically update existing node configurations.
// 3. Node operators can still manually override these defaults in their local config files.
//
// Therefore, it's critical to choose sensible default values carefully, as they will form
// the baseline configuration for most network participants. Any future changes to these
// defaults will only affect newly initialized nodes, not existing ones.

// As we use `ignite` CLI to provision the first validator it is important to note that the configuration files
// provisioned by ignite have additional overrides adjusted in ignite's `config.yml`

// initCometBFTConfig helps to override default CometBFT Config (config.toml) values.
// These values are going to be rendered into the config file on `poktrolld init`.
// TODO_MAINNET: Reconsider values - check `config.toml` for possible options.
func initCometBFTConfig() *cmtcfg.Config {
cfg := cmtcfg.DefaultConfig()

// these values put a higher strain on node memory
// cfg.P2P.MaxNumInboundPeers = 100
// cfg.P2P.MaxNumOutboundPeers = 40

cfg.Consensus.TimeoutPropose = 60 * time.Second
cfg.Consensus.TimeoutProposeDelta = 5 * time.Second
cfg.Consensus.TimeoutPrevote = 10 * time.Second
cfg.Consensus.TimeoutPrevoteDelta = 5 * time.Second
cfg.Consensus.TimeoutPrecommit = 10 * time.Second
cfg.Consensus.TimeoutPrecommitDelta = 5 * time.Second
cfg.Consensus.TimeoutCommit = 60 * time.Second
cfg.Instrumentation.Prometheus = true
cfg.LogLevel = "info"

return cfg
}

// initAppConfig helps to override default appConfig template and configs.
// initAppConfig helps to override default appConfig (app.toml) template and configs.
// These values are going to be rendered into the config file on `poktrolld init`.
// return "", nil if no custom configuration is required for the application.
// TODO_MAINNET: Reconsider values - check `app.toml` for possible options.
func initAppConfig() (string, interface{}) {
// The following code snippet is just for reference.
type CustomAppConfig struct {
Expand All @@ -83,6 +110,16 @@ func initAppConfig() (string, interface{}) {
// srvCfg.MinGasPrices = "0stake"
// srvCfg.BaseConfig.IAVLDisableFastNode = true // disable fastnode by default

srvCfg.MinGasPrices = "0.000000001upokt" // Also adjust ignite's `config.yml`.
srvCfg.Mempool.MaxTxs = 10000
srvCfg.Telemetry.Enabled = true
srvCfg.Telemetry.PrometheusRetentionTime = 60 // in seconds. This turns on Prometheus support.
srvCfg.Telemetry.MetricsSink = "mem"
srvCfg.Pruning = "nothing" // archiving node by default
srvCfg.API.Enable = true
srvCfg.GRPC.Enable = true
srvCfg.GRPCWeb.Enable = true

customAppConfig := CustomAppConfig{
Config: *srvCfg,
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/poktrolld/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"log"
"os"
"strings"

"cosmossdk.io/client/v2/autocli"
clientv2keyring "cosmossdk.io/client/v2/autocli/keyring"
Expand All @@ -31,6 +30,9 @@ import (
relayercmd "github.com/pokt-network/poktroll/pkg/relayer/cmd"
)

// TODO_MAINNET: adjust chain ID for the mainnet if it's going to change
const DefaultChainID = "poktroll"

// NewRootCmd creates a new root command for poktrolld. It is called once in the main function.
func NewRootCmd() *cobra.Command {
InitSDKConfig()
Expand Down Expand Up @@ -118,7 +120,7 @@ func NewRootCmd() *cobra.Command {
initRootCmd(rootCmd, clientCtx.TxConfig, clientCtx.InterfaceRegistry, clientCtx.Codec, moduleBasicManager)

if err := overwriteFlagDefaults(rootCmd, map[string]string{
flags.FlagChainID: strings.ReplaceAll(app.Name, "-", ""),
flags.FlagChainID: DefaultChainID,
flags.FlagKeyringBackend: "test",
}); err != nil {
log.Fatal(err)
Expand Down
6 changes: 6 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ client:
validators:
- name: validator1
bonded: 900000000upokt
# DEV_NOTE: adjust `cmd/poktrolld/cmd/config.go` to change the default options. The section below **ONLY** changes
# the values for the first validator, and the config is rendered using `ignite` cli. This is primarily used for
# LocalNet. Other participants of the network are relying on `poktrolld init`, which gets values from `cmd/config.go`.
app:
# DEV_NOTE: Ignite does not carry over all defaults, so we are going to match `minimum-gas-prices` with `cmd/config.go`.
# See the enhancement request here: https://github.com/ignite/cli/issues/4340
minimum-gas-prices: 0.000000001upokt
telemetry:
enabled: true
prometheus-retention-time: "600" # seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ The endpoint you want to send request to is: `http://your_node:appgate_server_po
represented by `0021`:

```bash
curl http://$NODE_HOSTNAME:85/00\
curl http://$NODE_HOSTNAME:85/0021 \
-X POST \
-H "Content-Type: application/json" \
--data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}'
Expand Down Expand Up @@ -658,7 +658,7 @@ To ensure you get a response, you may need to run the request a few times:

```bash
for i in {1..10}; do
curl http://$NODE_HOSTNAME:85/00\
curl http://$NODE_HOSTNAME:85/0021 \
-X POST \
-H "Content-Type: application/json" \
--data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}' \
Expand Down
7 changes: 6 additions & 1 deletion docusaurus/docs/operate/run_a_node/appgate_server.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
title: AppGate Server
sidebar_position: 3
sidebar_position: 4
---

# Run an AppGate Server <!-- omit in toc -->

- [What is AppGate Server?](#what-is-appgate-server)
- [AppGate Server Operation Requirements](#appgate-server-operation-requirements)
- [Hardware requirements](#hardware-requirements)
- [Docker Compose Example](#docker-compose-example)
- [Kubernetes Example](#kubernetes-example)

Expand All @@ -29,6 +30,10 @@ It is crucial to deploy a [Full Node](full_node_docker.md) prior to setting up a
This ensures the necessary infrastructure for blockchain communication is in place.
:::

## Hardware requirements

Please see the [Hardware Requirements](./hardware_requirements.md#appgate-server--gateway) page.

## Docker Compose Example

Please refer to the `Deploying an AppGate Server` section in [poktroll-docker-compose-example](https://github.com/pokt-network/poktroll-docker-compose-example#deploying-an-appgate-server)
Expand Down
111 changes: 89 additions & 22 deletions docusaurus/docs/operate/run_a_node/full_node_cosmovisor.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,108 @@
---
title: Full Node - Cosmovisor
sidebar_position: 1
sidebar_position: 2
---

# Run a Full Node using Cosmovisor <!-- omit in toc -->
## Run a Full Node using Cosmovisor <!-- omit in toc -->

This document provides instructions on using the official Cosmos SDK [Cosmosvisor](https://docs.cosmos.network/v0.45/run-node/cosmovisor.html) to run a full Pocket Network node.

- [What is a Full Node](#what-is-a-full-node)
- [What is Cosmovisor](#what-is-cosmovisor)
- [Setting up Cosmovisor](#setting-up-cosmovisor)
- [Upgrading with Cosmovisor](#upgrading-with-cosmovisor)
- [Installation Instructions](#installation-instructions)
- [Prerequisites](#prerequisites)
- [Installation Steps](#installation-steps)
- [Useful Command Cheat Sheet](#useful-command-cheat-sheet)
- [Check the status of your node](#check-the-status-of-your-node)
- [View the logs](#view-the-logs)
- [Stop the node](#stop-the-node)
- [Start the node](#start-the-node)
- [Restart the node](#restart-the-node)

### What is a Full Node

In blockchain networks, a full node retains continuous synchs and updates the latest copy of the ledger. It may either be a pruned full node (the latest data only) or an archival full node (including complete and historical data).

You can visit the [Cosmos SDK documentation](https://docs.cosmos.network/main/user/run-node/run-node) for more information on Full Nodes.

### What is Cosmovisor

[Cosmovisor](https://docs.cosmos.network/main/build/tooling/cosmovisor) is a tool that automates the version management for our blockchain. It allows operators to automatically upgrade their full nodes and validators without downtime and reduce maintenance overhead.

### Installation Instructions

To install and set up a Poktroll Full Node using Cosmovisor, we provide a comprehensive installation script. This script will handle all the necessary steps, including user creation, dependency installation, Cosmovisor and Poktrolld setup, and system configuration.

#### Prerequisites

- A Linux-based system (Debian-based distributions are fully supported, others may work as well)
- Root or sudo access
- A dedicated server or a virtual machine (any provider should work, Vultr and Hetzner have been tested)

#### Installation Steps

## What is a Full Node
1. Download the installation script:

In blockchain networks, a full node retains continuous synchs and updates the latest copy of the
ledger. It may either be pruned full node (the latest data only) or an archival full node (including
complete and historical data).
```bash
curl -O https://raw.githubusercontent.com/pokt-network/poktroll/main/tools/installer/full-node.sh
```

You can visit the [Cosmos SDK documentation](https://docs.cosmos.network/main/user/run-node/run-node)
for more information on Full Nodes.
2. Make the script executable:

## What is Cosmovisor
```bash
chmod +x full-node.sh
```

As an alternative to our [Full Node - Docker](./full_node_docker.md) guide, we also provide documentation on how to deploy
a Full Node using Cosmovisor.
3. Run the script with sudo privileges:

[Cosmovisor](https://docs.cosmos.network/main/build/tooling/cosmovisor) is a tool that automates the version management
for our blockchain. It allows operators to automatically upgrade their full nodes and validators without downtime and
reduce maintenance overhead.
```bash
sudo ./full-node.sh
```

:::info
TODO(@okdas): finish this tutorial as a part of [#526](https://github.com/pokt-network/poktroll/issues/526).
4. Follow the prompts to provide the necessary information:
- Desired username to run poktrolld (`default: poktroll`)
- Node moniker (`default: hostname`)
- Seeds (`default: fetched` [from the official source](https://github.com/pokt-network/pocket-network-genesis/tree/master/poktrolld))
- Chain ID (`default: poktroll-testnet`)

The script will then proceed with the installation and setup process.

### Useful Command Cheat Sheet

After the installation is complete, your Poktroll Full Node should be up and running.

:::tip
Remember to keep your system updated and monitor your node regularly to ensure its proper functioning and security.
:::

## Setting up Cosmovisor
Here are some useful commands for managing your node:

#### Check the status of your node

```bash
sudo systemctl status cosmovisor.service
```

#### View the logs

```bash
sudo journalctl -u cosmovisor.service -f
```

#### Stop the node

```bash
sudo systemctl stop cosmovisor.service
```

#### Start the node

[Content to be added]
```bash
sudo systemctl start cosmovisor.service
```

## Upgrading with Cosmovisor
#### Restart the node

[Content to be added]
```bash
sudo systemctl restart cosmovisor.service
```
16 changes: 10 additions & 6 deletions docusaurus/docs/operate/run_a_node/full_node_docker.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Full Node - Docker
sidebar_position: 2
sidebar_position: 3
---

# Run a Full Node using Docker <!-- omit in toc -->
Expand All @@ -9,6 +9,7 @@ sidebar_position: 2
- [Roles \& Responsibilities](#roles--responsibilities)
- [Types of Full Nodes](#types-of-full-nodes)
- [Pocket Network Full Nodes](#pocket-network-full-nodes)
- [Hardware requirements](#hardware-requirements)
- [Docker Compose Example](#docker-compose-example)
- [Kubernetes Example](#kubernetes-example)

Expand All @@ -19,6 +20,7 @@ In blockchain networks, a Full Node retains a complete copy of the ledger.
You can visit the [Cosmos SDK documentation](https://docs.cosmos.network/main/user/run-node/run-node)
for more information on Full Nodes.


## Roles & Responsibilities

It is usually responsible for:
Expand Down Expand Up @@ -47,14 +49,16 @@ nodes needed for off-chain entities like [RelayMiners](./relay_miner.md) and
[AppGates](./appgate_server.md), which rely on interaction with the Pocket Network
blockchain for full functionality.

This guide outlines how to configure, deploy nad maintain Full Nodes.
This guide outlines how to configure, deploy and maintain Full Nodes.

## Docker Compose Example
## Hardware requirements

Please refer to the `Deploying a Full Node` section in [poktroll-docker-compose-example](https://github.com/pokt-network/poktroll-docker-compose-example#deploying-a-full-node)
GitHub repository on how to deploy an AppGate Server using `docker-compose`.
Please see the [Hardware Requirements](./hardware_requirements.md#validator--full-node) page.

## Docker Compose Example

_TODO: Move over the relevant information from the `poktroll-docker-compose-example` repository into the docs_
Please refer to the `Deploying a Full Node` section in [Docker Compose Walkthrough](../quickstart/docker_compose_walkthrough.md)
on how to deploy a Full Node using `docker-compose`.

## Kubernetes Example

Expand Down
Loading

0 comments on commit 5ee73d4

Please sign in to comment.