Skip to content

Commit

Permalink
Merge pull request dominant-strategies#13 from Juuddi/main
Browse files Browse the repository at this point in the history
Miner + Node setup
  • Loading branch information
Juuddi authored Aug 16, 2023
2 parents 01d6889 + bc728e8 commit 51166ef
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 55 deletions.
147 changes: 147 additions & 0 deletions docs/participate/run-quai/miner-overview/cpu-miner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
---
title: CPU Miner
description: How to install and run a Quai Network GPU miner.
slug: /cpu-miner
hide_table_of_contents: false
sidebar_position: 1
---

# CPU Miner

## Environment Setup

Here, we'll be installing quai-cpu-miner, the Go implementation of a Quai Network CPU miner.

### Install Dependencies

To run an instance of quai-cpu-miner, you'll need to have installed and configured a Quai node. The [prerequisites](../node-overview/run-a-node.md#install-dependencies) to install and run the miner are the same as a node.

If you haven't set up your node, we recommend going through the [Run A Node page](../node-overview/run-a-node.md) before proceeding.

### Install quai-cpu-miner

Now that we've installed the base dependencies and configured our node, we can go ahead and clone the [quai-cpu-miner repo](https://github.com/dominant-strategies/quai-cpu-miner).

To install quai-cpu-miner and navigate to its directory, run the following commands:

```bash
git clone https://github.com/dominant-strategies/quai-cpu-miner.git
cd quai-cpu-miner
```

This will install the main branch to your local machine.

### Configuration

Simply copy the configuration template file `config.yaml.dist` into a local configuration file named `config.yaml`. This can be done by navigating to the config directory and running:

```bash
cp config.yaml.dist config.yaml
```

The default configuration will suffice for the duration of this tutorial. For more advanced users, the config file can be used to set up a connection to the [Quai stratum proxy](https://github.com/dominant-strategies/go-quai-stratum).

Before continuing, make sure to navigate back to the quai-cpu-miner root directory.

## Run the Miner

### Build

Similar to the node, we'll need to build the source to run the miner.
To build the source via Makefile, run:

```bash
make quai-cpu-miner
```

### Start

Prior to running the miner, you must connect to a fully synced node, either local or remote. Once you've connected to a synced node, you can spin up an instance of the miner.

Similar to a [base node](../node-overview/run-a-node.md#run-a-base-node), a miner mines a "slice" down the network hierarchy that includes prime, one region, and one zone chain. To start the miner, you'll need to specify the region, and zone chains that you'd like to mine. Region and zone indices are 0-indexed and range from 0-2.

To start the miner, select a region and zone index and run:

```bash
# run in terminal
make run-mine region=0 zone=1

# run in background, save log output
make run-mine-background region=2 zone=1
```

When choosing which contexts to mine, there are a few important things to consider:

- Block difficulty in each context (lower difficulty = higher chance of finding a block)
- Peer connection latency (related to geographic distance from peers)

Optimizing for latency **drastically decreases** the chance of finding an uncle block for which a decreased block reward is awarded. Miners who select contexts with the **lowest block difficulties** in tandem with **minimizing peer latencies** will generally be the most successful. Our team has provided a [guide to inform optimal context selection](../../../learn/advanced-introduction/hierarchical-structure/latency.md#networking-latencies) based on your geographical location for miners.

### Verify

Depending on whether or not the miner is running in background, logs will be viewable in different locations.

If you're running in the terminal, logs will be piped directly to the terminal and will not be saved. If the miner is running in the background, the miner output will be piped to a mining location specific .log file with the path `logs/slice-R-Z.log`. To view the last 100 lines of log output in Cyprus-1, run:

```bash
tail -f 100 logs/slice-0-0.log
```

You can also easily view miner logs via your favorite IDE, we recommend using this method. Logs are the best way to verify that your miner is running correctly and view information on efficiency and blocks mined.

A miner that is actively mining should have log outputs similar to:

```bash
2023/01/11 12:51:23 Mining Block: [16 22 78] location [0 0] difficulty [29209917 7353733 1913341]
2023/01/11 12:51:25 Zone block : [16 22 78] 0x0000086297dd6d1f635b01e3dc3d0c27d0ed9a571ae4e3e22ba89e876e71e398
2023/01/11 12:51:25 Mining Block: [16 22 79] location [0 0] difficulty [29209917 7353733 1914275]
2023/01/11 12:51:30 Zone block : [16 22 79] 0x000007c8d5b6ce6e7958eef2e3d12524538602400d1291744358efc43f57f266
2023/01/11 12:51:30 Mining Block: [16 22 80] location [0 0] difficulty [29209917 7353733 1915209]
2023/01/11 12:51:31 Zone block : [16 22 80] 0x000008094cf87697189620a51357b54827828fb9a693cc1e082b36736a406fcd
2023/01/11 12:51:31 Mining Block: [16 22 81] location [0 0] difficulty [29209917 7353733 1915209]
2023/01/11 12:51:33 Zone block : [16 22 81] 0x000006fb38aa98adddc3a6b0e5b887a55ea21065f05a5801ddca6aca0deba290
2023/01/11 12:51:33 Mining Block: [16 22 82] location [0 0] difficulty [29209917 7353733 1916144]
2023/01/11 12:51:34 Quai Miner : Hashes per second: 734038.5899168133
```

:::info
The miner logs provide the current block being mined, block type, the hash/second of your machine, and a number of other useful pieces of data.
:::

### Stop

You should stop the miner anytime you plan to pull an update, stop your node for any reason, or are shutting down your machine. A miner instance running the in background can be terminated by running:

```bash
make stop
```

If the miner is running inside your terminal, you can use CTRL+C to kill the process.

### Maintain

Making sure your miner is running correctly is crucial to being successful as a miner and the network as a whole. There are a few ways to verify that your miner is running smoothly.

#### Updating

Prior to updating your miner, make sure to kill any instances of quai-cpu-miner using the stop command above. After stopping your miner, pull any new code by running:

```bash
git pull
```

After pulling the latest code, you'll need to rebuild the source by running:

```bash
make quai-cpu-miner
```

After completing the steps above, you can restart the miner and continue mining.

:::warning
Starting the miner update process while the node or miner are running could cause issues. Make sure to stop all processes before updating.
:::

```bash

```
9 changes: 9 additions & 0 deletions docs/participate/run-quai/miner-overview/gpu-miner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: GPU Miner
description: How to install and run a Quai Network GPU miner.
slug: /gpu-miner
hide_table_of_contents: false
sidebar_position: 2
---

# GPU Miner
3 changes: 1 addition & 2 deletions docs/participate/run-quai/miner-overview/miner-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ title: Miner Overview
description: Overview of the implemenation of a Quai Network Miner.
slug: /miner-overview
hide_table_of_contents: false
sidebar_position: 2
---

# Miner Overview
Expand All @@ -14,7 +13,7 @@ A miner is a computer performing complex mathematical calculations, known as has

The specific types of mathematical calculations being done by a miner is referred to as the hashing algorithm of the network. Quai Network utilizes the ProgPoW hashing algorithm, an evolution of Ethash designed for improved ASIC resistance.

The ProgPoW algorithm was chosen due to the difficulty of creating application-specific integrated circuits (ASICs) that can mine ProgPoW. The use of ASIC-able algorithms such as SHA-256 quickly renders consumer-grade hardware impractical, resulting in large barrier to entry for competitive mining.
The ProgPoW algorithm was chosen due to the difficulty of creating application-specific integrated circuits (ASICs) that can mine ProgPoW. The use of ASIC-able algorithms such as SHA-256 quickly renders consumer-grade hardware impractical, resulting in large barrier to entry for competitive mining.

ProgPoW was developed as an EIP to replace Ethash, but was discarded due to the merge. The original ProgPoW EIP (EIP-1057) can be found [here](https://github.com/ethereum/EIPs/pull/1057). Additional information on ProgPoW can be found on the ETH Magicians forum [here](https://ethereum-magicians.org/t/progpow-a-compilation-of-reference-material/3040/4).

Expand Down

This file was deleted.

9 changes: 9 additions & 0 deletions docs/participate/run-quai/miner-overview/stratum-proxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Stratum Proxy
description: How to install and configure the Quai Stratum Proxy.
slug: /stratum
hide_table_of_contents: false
sidebar_position: 3
---

# Stratum Proxy
42 changes: 32 additions & 10 deletions docs/participate/run-quai/node-overview/node-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ sidebar_position: 1

# Node Overview

A node is a computer running an instance of Quai that communicates (peers) with other nodes. The web of communication between nodes makes up Quai Network.
A node is a computer running an instance of Quai that communicates (peers) with other nodes. The web of
communication between nodes makes up Quai Network.

Nodes are responsible for validating and propagating transactions across Quai Network. Each node maintains a copy of all or a subset of chains within the network, and handles the computation of state changes when a new block is added to their local copy of the ledger. Nodes uphold the integrity of Quai by ensuring the validity and accurate recording of all transactions.
Nodes are responsible for validating and propagating transactions across Quai Network. Each node maintains a
copy of all or a subset of chains within the network, and handles the computation of state changes when a new
block is added to their local copy of the ledger. Nodes uphold the integrity of Quai by ensuring the validity
and accurate recording of all transactions.

There are 4 unique kinds of nodes that exist within Quai Network that manage different subsets of data, serve different purposes, and have differing hardware requirements.
There are 4 unique kinds of nodes that exist within Quai Network that manage different subsets of data, serve
different purposes, and have differing hardware requirements.

## Node Types

### Full Node

A full node on Quai Network maintains the ledger and generates proposed blocks for mining in all shards. Full nodes operate by sending and receiving the latest blocks along with their header data to its peers in the network. Full nodes also have the ability to serve requests that query each of the shards through WebSockets and HTTP. Currently, full nodes on Quai Network serve as archive nodes since historical state is not pruned.
A full node on Quai Network maintains the ledger and generates proposed blocks for mining in all shards. Full
nodes operate by sending and receiving the latest blocks along with their header data to its peers in the
network. Full nodes also have the ability to serve requests that query each of the shards through WebSockets
and HTTP. Currently, full nodes on Quai Network serve as archive nodes since historical state is not pruned.

The hardware requirement to run a full node:

Expand All @@ -29,7 +37,11 @@ The hardware requirement to run a full node:

### Slice Node

A slice node on the network is a subset of a full node that validates Prime, a single Region, and a single Zone. An example of a slice node would be the combination of Prime, Cyprus, and Cyprus1. The benefit to running a slice node is that a node needs fewer resources. The trade-off is that cross-slice validation is delegated to the peered full nodes or coordinate slices. A slice node is the smallest subset of the network that a node can run and still trustlessly access the network.
A slice node on the network is a subset of a full node that validates Prime, a single Region, and a single
Zone. An example of a slice node would be the combination of Prime, Cyprus, and Cyprus1. The benefit to
running a slice node is that a node needs fewer resources. The trade-off is that cross-slice validation is
delegated to the peered full nodes or coordinate slices. A slice node is the smallest subset of the network
that a node can run and still trustlessly access the network.

The hardware requirement to run a full node:

Expand All @@ -40,25 +52,35 @@ The hardware requirement to run a full node:

### Extended Slice Node

An extended slice node is a slice node that is also running one or more additional Region or Zone chains coordinate to the selected slice. Extended slice nodes can be beneficial to node operators because it allows them to identify coordinate chain contention more quickly, lowering their uncle rate.
An extended slice node is a slice node that is also running one or more additional Region or Zone chains
coordinate to the selected slice. Extended slice nodes can be beneficial to node operators because it allows
them to identify coordinate chain contention more quickly, lowering their uncle rate.

Extended slice nodes are not currently a pre-set configuration, however advanced node operators can explore this construction.
Extended slice nodes are not currently a pre-set configuration, however advanced node operators can explore
this construction.

### Watcher Node

Watcher nodes are Quai Network nodes that observe a single subordinate Quai blockchain. Watcher nodes can be useful for organizations and businesses that are primarily monitoring a single Quai Network context, and are not concerned with coordinate or dominant chains. Watcher nodes are not a trustless way to interact with Quai Network, as they trust in the benevolence of dominant contexts.
Watcher nodes are Quai Network nodes that observe a single subordinate Quai blockchain. Watcher nodes can be
useful for organizations and businesses that are primarily monitoring a single Quai Network context, and are
not concerned with coordinate or dominant chains. Watcher nodes are not a trustless way to interact with Quai
Network, as they trust in the benevolence of dominant contexts.

Watcher nodes are not currently a pre-set configuration.

## Network Optimized Multi-Slice Setup

Quai Network incentivizes miners to self-select a slice to run their nodes which has the lowest peer latencies, thus optimizing network performance and throughput. Miners and nodes optimize latency for the following reasons:
Quai Network incentivizes miners to self-select a slice to run their nodes which has the lowest peer
latencies, thus optimizing network performance and throughput. Miners and nodes optimize latency for the
following reasons:

1. Maximize block rewards by minimizing uncle count.
2. Decrease network latency by collocating with same slice peers.
3. Efficiently distribute network compute across multiple contexts.

To achieve this set up, users will run many individual slice nodes that combine to make a globally distributed full node. These nodes are connected through secure WebSockets and validate an individual slice on the respective instance.
To achieve this set up, users will run many individual slice nodes that combine to make a globally distributed
full node. These nodes are connected through secure WebSockets and validate an individual slice on the
respective instance.

## Networking

Expand Down
Loading

0 comments on commit 51166ef

Please sign in to comment.