Skip to content

Commit

Permalink
feat: run random beacon
Browse files Browse the repository at this point in the history
  • Loading branch information
phuctd95 committed Jun 26, 2024
1 parent 256c327 commit bc8e87b
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 0 deletions.
204 changes: 204 additions & 0 deletions docs/validators/setup/random-beacon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
---
description: Run a Random Beacon Service.
title: Run a Random Beacon Service
---

## Overview

This guide demonstrates how to run a Random Beacon Service to [generate random beacon](https://github.com/ronin-chain/REPs/blob/main/REP-0010/REP-0010.md#compute-random-beacon). If you're an active Ronin Governing Validator, you need to run this service.

Governing Validators can choose to run the Random Beacon Service in standalone mode or combined mode. We suggest to use standalone mode to increase the security and stability of the system.

## Prerequisites

Before setting up the Random Beacon Service, we need to prepare:
- Docker
- Registered the [VRF key](../manage/vrf-key.mdx)

Check warning on line 16 in docs/validators/setup/random-beacon.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.Acronyms] Spell out 'VRF', if it's unfamiliar to the audience. Raw Output: {"message": "[Google.Acronyms] Spell out 'VRF', if it's unfamiliar to the audience.", "location": {"path": "docs/validators/setup/random-beacon.md", "range": {"start": {"line": 16, "column": 19}}}, "severity": "INFO"}
- A Ronin address to submit the random beacon. This can be any address.

## Run Random Beacon Service in standalone mode

Check warning on line 19 in docs/validators/setup/random-beacon.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.Headings] 'Run Random Beacon Service in standalone mode' should use sentence-style capitalization. Raw Output: {"message": "[Google.Headings] 'Run Random Beacon Service in standalone mode' should use sentence-style capitalization.", "location": {"path": "docs/validators/setup/random-beacon.md", "range": {"start": {"line": 19, "column": 4}}}, "severity": "WARNING"}

1. Setup directories and create a directory for postgres db data
```
mkdir -p ~/ronin-random-beacon/docker
cd ~/ronin-random-beacon
mkdir -p ~/ronin-random-beacon/db
```

2. In the docker directory, create a `docker-compose.yml` file with the following configuration:

```
version: '3.5'
services:
ronin-random-beacon-chain:
image: ${NODE_IMAGE}
restart: always
logging:
options:
max-size: 10m
max-file: "3"
environment:
RONIN_RANDOM_BEACON_PARAMS: ${RONIN_RANDOM_BEACON_PARAMS}
RONIN_PRIVATE_KEY: ${RONIN_PRIVATE_KEY}
RONIN_SECRET_KEY: ${RONIN_SECRET_KEY}
RONIN_RPC_ENDPOINT: ${RONIN_RPC_ENDPOINT}
RONIN_VERBOSITY: ${RONIN_VERBOSITY}
RONIN_DATABASE_URL: postgresql://${DB_USER}:${DB_PASS}@ronin-random-beacon-chain-db:5432/${DB_NAME}?sslmode=disable
depends_on:
- ronin-random-beacon-chain-db
ronin-random-beacon-chain-db:
image: postgres:14
restart: always
ports:
- "127.0.0.1:5432:5432"
logging:
options:
max-size: 10m
max-file: "3"
volumes:
- ~/ronin-random-beacon/db:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER}"]
interval: 30s
timeout: 30s
retries: 3
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
```

This compose file defines the ronin-random-beacon service that pulls a Ronin random beacon image from the GitHub Container Registry. ( https://github.com/ronin-chain/ronin-random-beacon/pkgs/container/ronin-random-beacon)

Check warning on line 71 in docs/validators/setup/random-beacon.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.Parens] Use parentheses judiciously. Raw Output: {"message": "[Google.Parens] Use parentheses judiciously.", "location": {"path": "docs/validators/setup/random-beacon.md", "range": {"start": {"line": 71, "column": 1}}}, "severity": "INFO"}

**Note.** In case you want to connect to node container in different docker-compose in the same machine, please check [here](https://docs.docker.com/compose/networking/#use-a-pre-existing-network) for reusing the existing network in the above setting for making a connection between random-beacon service with rpc node service.

Check warning on line 73 in docs/validators/setup/random-beacon.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.WordList] Use 'select' instead of 'check'. Raw Output: {"message": "[Google.WordList] Use 'select' instead of 'check'.", "location": {"path": "docs/validators/setup/random-beacon.md", "range": {"start": {"line": 73, "column": 113}}}, "severity": "WARNING"}

Check warning on line 73 in docs/validators/setup/random-beacon.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.WordList] Use 'preceding' instead of 'above'. Raw Output: {"message": "[Google.WordList] Use 'preceding' instead of 'above'.", "location": {"path": "docs/validators/setup/random-beacon.md", "range": {"start": {"line": 73, "column": 238}}}, "severity": "WARNING"}

For example if the current docker network of node containers you wanna connect is `ronin_default`. Then put this block in per service inside the above docker-compose to connect to the existing network.

Check warning on line 75 in docs/validators/setup/random-beacon.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.WordList] Use 'preceding' instead of 'above'. Raw Output: {"message": "[Google.WordList] Use 'preceding' instead of 'above'.", "location": {"path": "docs/validators/setup/random-beacon.md", "range": {"start": {"line": 75, "column": 146}}}, "severity": "WARNING"}

```
...
ronin-random-beacon-chain:
image: ${NODE_IMAGE}
restart: always
networks:
- ronin_default
...
ronin-random-beacon-chain-db:
image: postgres:14
restart: always
networks:
- ronin_default
...
```

3. In the docker directory, create an `.env` file and add the following content, replacing the `<...>` placeholder values with your information:

```
NODE_IMAGE=<NODE_IMAGE>
DB_USER=<DB_USER>
DB_PASS=<DB_PASS>
DB_NAME=<DB_NAME>
# your ronin private key with the 0x prefix for submitting the transactions to chain.
RONIN_PRIVATE_KEY=<RONIN_PRIVATE_KEY>
# Your VRF Secret key with the 0x prefix
RONIN_SECRET_KEY=<RONIN_SECRET_KEY>
RONIN_RANDOM_BEACON_PARAMS=--config-file /opt/config/mainnet/
RONIN_RPC_ENDPOINT=<YOUR_RPC_ENDPOINT>
RONIN_VERBOSITY=4
```

4. Start the node

```
cd ~/ronin-random-beacon && docker-compose up -d
```

5. Review the log

```
docker logs ronin-random-beacon-chain -f –tail 100
```

## Run Random Beacon Service in combined mode

Check warning on line 121 in docs/validators/setup/random-beacon.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.Headings] 'Run Random Beacon Service in combined mode' should use sentence-style capitalization. Raw Output: {"message": "[Google.Headings] 'Run Random Beacon Service in combined mode' should use sentence-style capitalization.", "location": {"path": "docs/validators/setup/random-beacon.md", "range": {"start": {"line": 121, "column": 4}}}, "severity": "WARNING"}

1. Setup directory for postgres db data (assume that your node directory is as same as setting in [here](./mainnet/run-validator.md))

```
cd ~/ronin
mkdir -p ronin-random-beacon-db
```

2. In the docker directory, append the current docker-compose.yml file with the following configuration:

```
version: '3.5'
services:
...
...
ronin-random-beacon-chain:
image: ${RONIN_RANDOM_BEACON_CHAIN_IMAGE}
restart: always
logging:
options:
max-size: 10m
max-file: "3"
environment:
RONIN_RANDOM_BEACON_PARAMS: ${RONIN_RANDOM_BEACON_PARAMS}
RONIN_PRIVATE_KEY: ${RONIN_RANDOM_BEACON_CHAIN_PRIVATE_KEY}
RONIN_SECRET_KEY: ${RONIN_RANDOM_BEACON_CHAIN_SECRET_KEY}
RONIN_RPC_ENDPOINT: ${RONIN_RANDOM_BEACON_CHAIN_RPC_ENDPOINT}
RONIN_VERBOSITY: ${RONIN_RANDOM_BEACON_CHAIN_VERBOSITY}
RONIN_DATABASE_URL: postgresql://${RONIN_RANDOM_BEACON_DB_USER}:${RONIN_RANDOM_BEACON_DB_PASS}@ronin-random-beacon-chain-db:5432/${RONIN_RANDOM_BEACON_DB_NAME}?sslmode=disable
depends_on:
- ronin-random-beacon-chain-db
ronin-random-beacon-chain-db:
image: postgres:14
restart: always
ports:
- "127.0.0.1:5432:5432"
logging:
options:
max-size: 10m
max-file: "3"
volumes:
- ~/ronin/ronin-random-beacon-db:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${RONIN_RANDOM_BEACON_DB_USER}"]
interval: 30s
timeout: 30s
retries: 3
environment:
POSTGRES_USER: ${RONIN_RANDOM_BEACON_DB_USER}
POSTGRES_PASSWORD: ${RONIN_RANDOM_BEACON_DB_PASS}
```

This compose file defines the `ronin-random-beacon` service that pulls a Ronin random beacon image from the GitHub Container Registry.

3. In the docker directory, create an `.env` file and add the following content, replacing the `<...>` placeholder values with your information:

```
RONIN_RANDOM_BEACON_CHAIN_IMAGE=<RONIN_RANDOM_BEACON_CHAIN_IMAGE>
RONIN_RANDOM_BEACON_DB_USER=<RONIN_RANDOM_BEACON_DB_USER>
RONIN_RANDOM_BEACON_DB_PASS=<RONIN_RANDOM_BEACON_DB_PASS>
RONIN_RANDOM_BEACON_DB_NAME=<RONIN_RANDOM_BEACON_DB_NAME>
# your ronin private key with the 0x prefix for submitting the transactions to chain.
RONIN_RANDOM_BEACON_CHAIN_PRIVATE_KEY=<RONIN_RANDOM_BEACON_CHAIN_PRIVATE_KEY>
# Your VRF Secret key with the 0x prefix
RONIN_RANDOM_BEACON_CHAIN_SECRET_KEY=<RONIN_RANDOM_BEACON_CHAIN_SECRET_KEY>
RONIN_RANDOM_BEACON_PARAMS=--config-file /opt/config/mainnet/
RONIN_RANDOM_BEACON_CHAIN_RPC_ENDPOINT=http://node:8545
RONIN_RANDOM_BEACON_CHAIN_VERBOSITY=4
```

4. Start the node

```
cd ~/ronin && docker-compose up -d
```

5. Review the log

```
docker logs ronin-random-beacon-chain -f –tail 100
```
2 changes: 2 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ const sidebars = {
'validators/setup/cli',
// Latest version
'validators/setup/upgrade-validator',
// Latest version
'validators/setup/random-beacon',
// Clean data
'validators/setup/clean-data',
// Network parameters
Expand Down

0 comments on commit bc8e87b

Please sign in to comment.