opoll / opollminer

Official mining application for OpenPoll Platform
1 stars 0 forks source link

Mining Application

Purpose: This document holds the very basic necessities that the mining application will need. The mining application supports two different types of mining: (1) mining the OpenPoll main blockchain, and (2) mining multiple different shard blockchains. All miners at the time of initial launch are required to operate full nodes, until a light miner is released. Before understanding the architecture and design of the mining application, you should understand the theory behind the OpenPoll main and shard blockchains. This document describes the software implementation of the mining application, however, it does not describe the higher level theory behind the main blockchain, or individual shard chains.


Mining Application Responsibilities

The mining application has many different responsibilities, but principally, it has the ability to transform a computer into a node running optionally on the main blockchain, or turn a single computer into a node for many shard blockchains.


Shard Mining Process

A miner running the OpenPoll mining application has the ability to choose which shards he or she would like to mine. Given that a user has chosen to mine a specific shard, as indicated by a shardId. The module responsible for performing shard mining once a shardId has been provided is called the ShardMinerModule which follows the flow below.

The ShardMinerModule has the following constraints:

Component Breakdown


Peer-to-Peer Communication

In addition to direct API calls with the Facilitator application, peers must be able to communicate with each other. Peer communication occurs through a RESTful API made available by every node on the network. P2P communication contains /main if it relates to the main blockchain, and /shard/:shardId if it is communication relating to a specific shard. A versioning schema is to be determined.

Shard P2P Endpoints

All requests to a peer associated with a shard are prefixed with /shard/:shardId. In the event a request is made to a peer regarding a shard which the peer is not actively mining, the node will return an HTTP 404 error code.

Latest Block

**GET /shard/:shardId/latest?full=[true/false]**

Returns the latest block associated with the shard that the peer is aware of. For partial loading (when full=false) only a blockId is returned. However for full loading the entire block is returned.

Example Use Case: During the shard mining flow a node needs to know if they are currently on the latest block or not. For this simple determination, the node can do partial loading using this endpoint to peers to learn if they still are up to date.

Example Use Case: If a miner learns they do not have the latest block, they can retrieve the latest block on the chain (for situations when there was a low amount of time elapsed between the last successful latest check and unsuccessful check).

POST /shard/:shardId/latest

This endpoint is used during the broadcasting component of the shard mining flow. Once a shard miner creates a new block on the shard blockchain, the miner must ensure other peers on the network are aware of the new block to begin working on a block successive to theirs. Shard miners are responsible for pushing their block to peers on the network using this endpoint. This endpoint takes a PollShardBlock object. When this endpoint is called, it verifies the block. If the block is fully valid, the node stores the block locally and updates it's reference of the last block to the provided block.

Response Pooling

When responses are received by respondents, they are polled by miners until they are incorporated into a block within the shard blockchain. These endpoints help to ensure responses can propagate through the network and be incorporated into shard blocks.

**GET /shard/:shardId/pool**

Miners are responsible for seeking pooled responses from other miners on the network in the event a respondent does not directly push a response to them. This request provides a peer with responses pooled by the local miner for incorporation in future shard blocks. This endpoint returns an array of PollResponseSigned objects which the node has stored locally in its pool.

**POST /shard/:shardId/pool**

This endpoint allows responses to propagate through the network on a push basis from respondents. When a respondent has a response they wish to be incorporated into the shard blockchain, they can push their response to nodes operating the shard through this endpoint. This endpoint takes a PollResponseSigned parameter. The endpoint verifies the data received and, if valid, pools the signed poll response.

Peer Loading

In order to build a P2P network, peers must have a method to learn of other peers on the network. This occurs through peer to peer propagation where nodes can learn from other nodes who is on the network. These endpoints are not currently being developed in the beta version and initial release due to the Facilitator providing and maintaining a list of peers.


Node CLI Commands

Miners must be able to interface with the application and know the state of their operations. Miners must be able to know what pollId's are available for them to work on, be able to start or drop working on any pollId (or the main chain), and they must be able to know what they have won a mining race and will be rewarded eventually. We can use [commander](https://www.npmjs.com/package/commander) to take terminal input and let users interface with internal application state that way.

Basic Top-Level Commands To Support

shards

status

fetch <pollId>

purge <pollId>

startmine <pollId>

stopmine <pollId>

blockchain <pollId>

block <blockIndex> <pollId>

rescan <pollId>

walletcreate <password>

walletall

walletaddresses <walletId>

walletbalance <walletId>

start

stop

info

How Miners Will Run The Application

1.) We will specify the bin property in package.json to map the command om to run bin/opollminer.js which holds our scripts

2.) The user must be in the same directory as the application before we create a symlink

3.) All the user will have to do on their end is run npm link to create a symlink (and npm unlink to undo the symlink)

4.) Finally, a user can call om [command name] [args] globally and now the user can use the CLI more conveniently to interface with our application


Mining Application Internal Implementation

This will roughly outline the exact classes, functions, and interfacing portions the application will support and implement.