Skip to content

Commit

Permalink
LocalNet documentation using playground (#1535)
Browse files Browse the repository at this point in the history
# Description

Add documentation on how to use [e2e-stack](https://github.com/pokt-foundation/pocket-e2e-stack), [tx-bot](https://github.com/pokt-network/tx-bot) and [local_playground](https://github.com/pokt-network/local_playground) to run a 4 node LocalNet that enables hot reloading of our [Tendermint fork](https://github.com/pokt-network/tendermint).

## Import Note

Note that this is a hacky & ugly reuse of existing infrastructure and is not meant to be an elegant long-term solution. It is just enough to test & ship new features while v1 is in development.

## Dependencies

- Changes in [tx-bot](pokt-network/tx-bot#6)
- Changes in [pocket-e2e-stack](pokt-foundation/pocket-e2e-stack#30)
- Introduce of [local_playground](https://github.com/pokt-network/local_playground); see [this comment](pokt-network/playground#52 (comment)) for more details

## Demo

https://user-images.githubusercontent.com/1892194/225497350-3817b262-f5d5-483b-bb8f-47fb0b614321.mov
  • Loading branch information
Olshansk authored Apr 5, 2023
1 parent 5a55424 commit fa1923f
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 298 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ app/data/*

**/.DS_Store


output_*.dlv
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,3 @@ To start the disclosure process, please send an email containing all evidence, d
#### Public disclosure

Once the vulnerability has been patched and deployed to the appropiate environments, the team will create a public disclosure announcement, acknowledging the vulnerability and giving credit to the original discloser or disclosers in case more than one person identifies and discloses the vulnerability.

18 changes: 9 additions & 9 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8754,7 +8754,7 @@ var mainnetGenesis = `{
"jailed": true,
"status": 2,
"tokens": "4900000000000",
"service_url": "https://node1.poktnodes.com:443",
"service_url": "https://node1.dev.poktnodes.com:443",
"chains": [
"0001",
"0021"
Expand All @@ -8767,7 +8767,7 @@ var mainnetGenesis = `{
"jailed": true,
"status": 2,
"tokens": "4900000000000",
"service_url": "https://node2.poktnodes.com:443",
"service_url": "https://node2.dev.poktnodes.com:443",
"chains": [
"0001",
"0021"
Expand All @@ -8780,7 +8780,7 @@ var mainnetGenesis = `{
"jailed": true,
"status": 2,
"tokens": "200000000000",
"service_url": "https://node3.poktnodes.com:443",
"service_url": "https://node3.dev.poktnodes.com:443",
"chains": [
"0001",
"0021"
Expand Down Expand Up @@ -12121,7 +12121,7 @@ var mainnetGenesis = `{
"jailed": true,
"status": 2,
"tokens": "152527740000",
"service_url": "https://node1.pokt.net:443",
"service_url": "https://node3.dev.pokt.net:443",
"chains": [
"0001",
"0021"
Expand All @@ -12134,7 +12134,7 @@ var mainnetGenesis = `{
"jailed": true,
"status": 2,
"tokens": "148041630000",
"service_url": "https://node2.pokt.net:443",
"service_url": "https://node2.dev.pokt.net:443",
"chains": [
"0001",
"0021"
Expand All @@ -12147,7 +12147,7 @@ var mainnetGenesis = `{
"jailed": true,
"status": 2,
"tokens": "148041630000",
"service_url": "https://node3.pokt.net:4433",
"service_url": "https://node3.dev.pokt.net:4433",
"chains": [
"0001",
"0021"
Expand Down Expand Up @@ -14799,7 +14799,7 @@ var mainnetGenesis = `{
"jailed": true,
"status": 2,
"tokens": "18083175000000",
"service_url": "https://node1.pokt.foundation:443",
"service_url": "https://node3.dev.pokt.foundation:443",
"chains": [
"0001",
"0021"
Expand All @@ -14812,7 +14812,7 @@ var mainnetGenesis = `{
"jailed": true,
"status": 2,
"tokens": "18083175000000",
"service_url": "https://node2.pokt.foundation:443",
"service_url": "https://node2.dev.pokt.foundation:443",
"chains": [
"0001",
"0021"
Expand All @@ -14825,7 +14825,7 @@ var mainnetGenesis = `{
"jailed": true,
"status": 2,
"tokens": "18631150000000",
"service_url": "https://node3.pokt.foundation:443",
"service_url": "https://node3.dev.pokt.foundation:443",
"chains": [
"0001",
"0021"
Expand Down
52 changes: 22 additions & 30 deletions doc/guides/changesAndfeatures8.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pocket nodes stake custodial <fromAddr> <amount> <relayChainIDs> <serviceURI> <n

The updated command expects 1 new parameter:

* `<isBefore8.0>`: true or false depending if non-custodial upgrade is activated.
- `<isBefore8.0>`: true or false depending if non-custodial upgrade is activated.

Before the upgrade is activated be sure to use `true` for `<isBefore8.0>` or the transaction won't go through

Expand All @@ -33,9 +33,9 @@ pocket nodes stake non-custodial <operatorPublicKey> <outputAddress> <amount> <R

The new stake command expects 3 new parameters:

* `<operatorPublicKey>`: operatorAddress is the only valid signer for blocks & relays. Should match the running node.
* `<outputAddress>`: outputAddress is where reward and staked funds are directed.
* `<isBefore8.0>`: true or false depending if non custodial upgrade is activated.
- `<operatorPublicKey>`: operatorAddress is the only valid signer for blocks & relays. Should match the running node.
- `<outputAddress>`: outputAddress is where reward and staked funds are directed.
- `<isBefore8.0>`: true or false depending if non custodial upgrade is activated.

Replacing the `<fromAddr>` we have the `<operatorPublicKey>`, notice the change from using an address to using the
public key of the node. Also, we have the `<outputAddress>`, where rewards and funds will be delivered after the update
Expand Down Expand Up @@ -67,48 +67,40 @@ check or update your hosted chains.

To use the endpoint:

* First make sure to set `"chains_hot_reload": false` before beginning, hot reloading and the update endpoint can't be
- First make sure to set `"chains_hot_reload": false` before beginning, hot reloading and the update endpoint can't be
used at the same time (enabling hot reload disables the update endpoint).
* Locate your `auth.json` file in the config directory, this file contains your `authtoken` you need its value to send
- Locate your `auth.json` file in the config directory, this file contains your `authtoken` you need its value to send
request to protected endpoints (../v1/private/..).
```json
{
"Value": "<TOKEN>",
"Issued": "2022-04-08T07:35:35.858373-04:00"
}
```
* Copy the token value and replace the placeholder `<TOKEN>` with its value on this example call
```json
{
"Value": "<TOKEN>",
"Issued": "2022-04-08T07:35:35.858373-04:00"
}
```
- Copy the token value and replace the placeholder `<TOKEN>` with its value on this example call
```text
curl --location --request POST 'http://localhost:8081/v1/private/updatechains?authtoken=<TOKEN>' \
--header 'Content-Type: application/json' \
--data-raw '[
{
"id": "0001",
"url": "http://localhost:8081",
"basic_auth": {
"username": "",
"password": ""
}
}
]'
```
* Check If your request is successful using this other call
```
- Check If your request is successful using this other call
```
curl --location --request POST 'http://localhost:8081/v1/private/chains?authtoken=<TOKEN>'
```
you should receive a response like this :
```json
{
"0001": {
"basic_auth": {
"password": "",
"username": ""
},
"id": "0001",
"url": "http://localhost:8081"
}
"0001": {
"id": "0001",
"url": "http://localhost:8081"
}
}
```
* Remember to manually update your chains.json with the desired changes before or after using this method as any changes
```
- Remember to manually update your chains.json with the desired changes before or after using this method as any changes
done using the `updatechains` endpoint will be overwritten at restart by loading the chains.json
* Also, if you are writing any automations remember the `authtoken` is recreated on every restart.
- Also, if you are writing any automations remember the `authtoken` is recreated on every restart.
151 changes: 151 additions & 0 deletions doc/guides/localnet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# V0 LocalNet <!-- omit in toc -->

<!-- https://docs.google.com/presentation/d/1mk0XogopENCI_4WXXvSYm1_DG8EhRLIpwpZQNIA5vqM/edit#slide=id.p -->

- [Prerequisites](#prerequisites)
- [Dependencies](#dependencies)
- [Download Repos](#download-repos)
- [Playground](#playground)
- [Setup E2E Stack Environment](#setup-e2e-stack-environment)
- [Pocket E2E Stack](#pocket-e2e-stack)
- [1. Prepare Stack](#1-prepare-stack)
- [2. Run Stack](#2-run-stack)
- [3. Watch the network](#3-watch-the-network)
- [4. Cleanup Stack](#4-cleanup-stack)
- [5. Cleaning containers](#5-cleaning-containers)
- [Tx Bot](#tx-bot)
- [Configuration changes](#configuration-changes)
- [TODO](#todo)

## Prerequisites

### Dependencies

This repository is intended to be deprecated within the next 12 months as of writing this document. It is only intended for experienced Pocket developers.

It is intentionally non-exhaustive so newcomers may find it difficult to follow as it is not the intended audience.

### Download Repos

```bash
mkdir v0_localnet
cd v0_localnet

git clone git@github.com:pokt-network/pocket-core.git
git clone git@github.com:pokt-network/tendermint.git
git clone git@github.com:pokt-network/tx-bot.git
git clone --recurse-submodules git@github.com:pokt-network/pocket-e2e-stack.git
```

Run `pwd` and identify the current path as it will be referenced to as `POCKET_CORE_REPOS_PATH` below

## Playground

### Setup E2E Stack Environment

1. Copy the template env variables

```bash
cd pocket-e2e-stack
cp .env.template .env
cp .playground.env.example .playground.env
```

2. Update `POCKET_CORE_REPOS_PATH` in the appropriate `.env` variables:

```bash
# Update `POCKET_CORE_REPOS_PATH` in `.env` to be the full path reflecting where you downloaded all the repos.
sed -i 's|^POCKET_CORE_REPOS_PATH=.*$|POCKET_CORE_REPOS_PATH='$PWD'|' pocket-e2e-stack/.env
# Update `POCKET_CORE_REPOS_PATH` in `.playground.env` to be the full path reflecting the path where you downloaded all the
sed -i 's|^POCKET_CORE_REPOS_PATH=.*$|POCKET_CORE_REPOS_PATH='$PWD'|' pocket-e2e-stack/.playground.env
```

3. Update the Ethereum & Polygon altruist nodes

```bash
# Update `ETH_ALTRUIST` and `POLY_ALTRUIST` appropriately.
sed -i 's|^# ETH_ALTRUIST=.*$|ETH_ALTRUIST=<Your or public Ethereum endpoint>|' pocket-e2e-stack/.env
sed -i 's|^# POLY_ALTRUIST=.*$|POLY_ALTRUIST=<Your or public Polygon endpoint>|' pocket-e2e-stack/.env
```

```bash
source .env
source .playground.env
```

### Pocket E2E Stack

```bash
cd pocket-e2e-stack
```

#### 1. Prepare Stack

```bash
./bin/pokt-net/playground.sh scaffold
```

#### 2. Run Stack

```bash
./bin/pokt-net/playground.sh up
```

**What am I running?**

- Four containerized `Validator` nodes
- A local version of the `Tendermint` library
- Hot reloading code in both `Tendermint` and `Pocket-Core`
- A bot that can be used to send transactions to the network
- Pocket RPC endpoints are exposed at 8082, 8083, 8084, and 8085/tcp on each node respectively
- Tendermint RPC endpoints are exposed at 26658, 26659, 26660, 26661/tcp respectively

https://user-images.githubusercontent.com/1892194/225497350-3817b262-f5d5-483b-bb8f-47fb0b614321.mov

**IMPORTANT: Inspect the logs in case something looks abnormal or an error occurred.**

#### 3. Watch the network

```bash
watch -n 5 "curl -s -X 'POST' 'http://localhost:8084/v1/query/height'"
```

The full RPC spec can be found [here](https://editor.swagger.io/?url=https://github.com/raw/pokt-network/pocket-core/staging/doc/specs/rpc-spec.yaml).

**IMPORTANT: It might take up to 5 minutes for the first height to start incrementing while the node prepares.**

#### 4. Cleanup Stack

```bash
./bin/pokt-net/playground.sh cleanup
```

**IMPORTANT: You will need to run `cleanup` every time you create a new setup.**

#### 5. Cleaning containers

If you make any changes to the scripts or need a cleaner start, you'll need to remove the containers and docker image:

```bash
docker rm node1.dev.pokt node2.dev.pokt node3.dev.pokt node4.dev.pokt && docker rmi playground/pocket-core
```

### Tx Bot

```bash
cd tx-bot
make start
# Make a selection
```

### Configuration changes

- We are using the `homogenous` network is in `pokt-net`
- You can update configs by modifying `pocket-e2e-stack/.playground.env`
- You can further update configs by modifying `pocket-e2e-stack/playground/templates/config.template.json`
- Make sure to run `clean, scaffold & up` after changing configs

## TODO

- [ ] How to enable the monitoring stack?
- [ ] How to setup a heterogenous network?
6 changes: 1 addition & 5 deletions doc/guides/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,17 +451,13 @@ Use the CLI or Manually Edit: `$HOME/.pocket/config/chains.json`
{% hint style="info" %} Relay Chain ID's and docs can be
found [here](https://docs.pokt.network/supported-blockchains/). {% endhint %}

These are external blockchain nodes such as ethereum, polygon and harmony. You will need to set these up by following their respective documentation. Once they are synced, you can enter the url and credentials into the following file.
These are external blockchain nodes such as ethereum, polygon and harmony. You will need to set these up by following their respective documentation. Once they are synced, you can enter the url and credentials into the following file.

```text
[
{
"id": "0002",
"url": "http://eth-geth.com",
"basic_auth": {
"username": "",
"password": ""
}
}
]
```
Expand Down
Loading

0 comments on commit fa1923f

Please sign in to comment.