Emyrk 11 months ago
commit
9265e2afad

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.idea
+config/pegnet.ini
+config/factomd.conf

+ 26 - 0
README.md

@@ -0,0 +1,26 @@
+# QuickStart
+
+```
+git clone https://git.factoid.org/TFA/pegnet-mining.git
+cd pegnet-mining/miner
+```
+
+Copy the `tfapegnet-miner.ini` from discord. It has some private keys.
+Add your key into it.
+
+Move it to this repo:
+```
+mv tfapegnet.ini config/pegnet.ini
+```
+
+Create docker volume for miner:
+```
+docker volume create pegnet_miner
+```
+
+Run the miner
+```
+MINERS=4 docker-compose up -d
+```
+
+Done!

+ 169 - 0
coordinator/README.md

@@ -0,0 +1,169 @@
+# PegNet Compose
+
+PegNet Compose leverages Docker Compose to help you start and manage a PegNet miner.
+
+## Requirements
+
+-   [Docker Engine 1.13.0+](https://docs.docker.com/install/)
+-   [Docker Compose](https://docs.docker.com/compose/install/)
+
+## Setup
+
+This is the initial setup process. You will only need to do this once.
+
+#### 1. Clone and cd into this repo
+
+```
+git clone https://github.com/pegnet/pegnet-compose.git && cd pegnet-compose
+```
+
+#### 2. Create Docker volumes
+
+PegNet Compose uses 3 Docker volumes to persist data.
+
+```
+docker volume create factom_database
+docker volume create factom_wallet
+docker volume create pegnet
+```
+
+#### 3. Create a factomd.conf
+
+It is necessary to create a factomd.conf file in the config folder. The default settings should work out of the box for most people.
+
+```
+cp config/factomd.conf.EXAMPLE config/factomd.conf
+```
+
+#### 4. Start factomd and walletd
+
+Begin syncing the blockchain and start the wallet. This command looks like it only brings walletd up, but it brings factomd up too.
+
+```
+docker-compose run --name walletd -d walletd
+```
+
+#### 5. Create or add an entry credit address
+
+##### a. Create an entry credit address
+
+```
+docker exec -it walletd \
+curl -X GET \
+--data-binary '{"jsonrpc": "2.0", "id": 0, "method": "generate-ec-address"}' \
+-H 'content-type:text/plain;' http://localhost:8089/v2
+```
+
+Copy down the public address you see in the output as you will need it later. It should begin with `EC`.
+
+**OR**
+
+##### b. Add an entry credit address
+
+Replace the secret key with your own secret key. It should begin with `Es`. Note: be careful not to change the formatting when copying over your secret key. Check the quotation marks.
+
+```
+docker exec -it walletd \
+curl -X GET --data-binary \
+'{"jsonrpc": "2.0", "id": 0, "method": "import-addresses", "params":{"addresses":[{"secret":"Es3tXbGBVKZDhUWzDKzQtg4rcpmmHPXAY9vxSM2JddwJSD5td3f8"}]}}' \
+-H 'content-type:text/plain;' http://localhost:8089/v2
+```
+
+#### 6. OPTIONAL: Create a FCT address
+
+If you do not already have a FCT address, you can create one in walletd.
+
+```
+docker exec -it walletd \
+curl -X GET \
+--data-binary '{"jsonrpc": "2.0", "id": 0, "method": "generate-factoid-address"}' \
+-H 'content-type:text/plain;' http://localhost:8089/v2
+```
+
+Copy down the public address, you will need it later.
+
+#### 7. Fund your entry credit address
+
+The cheapest way to buy entry credits is to create them yourself using FCT. You can do that using several different Factom wallets, including [MyFactomWallet](https://myfactomwallet.com/#/) (web), [Enterprise Wallet](https://docs.factomprotocol.org/wallets/enterprise-wallet) (desktop) or walletd (cli), which we have running here.
+
+Alternatively, you can buy EC directly from [Factom Inc](https://shop.factom.com/) or [De Facto](https://ec.de-facto.pro/) who will deposit EC directly into your entry credit address.
+
+#### 8. Create the PegNet config file
+
+Copy the example config file to use as a template.
+
+```
+cp config/pegnet.ini.EXAMPLE config/pegnet.ini
+```
+
+Open the config file in a text editor.
+
+```
+nano config/pegnet.ini
+```
+
+Change the following items:
+
+-   `ECAddress` to the public EC address created or added to the wallet in step 5.
+-   `FCTAddress` and `CoinbaseAddress` to your FCT address.
+-   `IdentityChain` to any alphanumeric string (no spaces!) that will help you identity your miner amongst the rest.
+
+Your miner needs to be able to get asset prices from an oracle. Complete the `[Oracle]` and `[OracleDataSources]` section of the config. The comments in the config file will guide you.
+
+#### 9. Wait for factomd to finish syncing
+
+The initial sync might take anywhere from 12 to 48 hours. You can close the shell whilst this is happening if you wish.
+
+You will be able to see the progress of the factomd sync in your web browser by visiting `host:8090`, where `host` is the IP address of your machine. If you're doing this on your local machine, `host` will be `localhost`.
+
+You can also track it at the command line with the following command.
+
+```
+docker exec -it factomd \
+curl -X POST --data-binary \
+'{"jsonrpc": "2.0", "id": 0, "method": "heights"}' -H 'content-type:text/plain;' http://localhost:8088/v2
+```
+
+It has finished syncing when all the heights are the same.
+
+#### 10. Stop and remove walletd
+
+We will bring it up again later when we start PegNet.
+
+```
+docker stop walletd && docker rm walletd
+```
+
+## Start
+
+When you start PegNet, you need to pass the number of miners you want it to run as an environment variable. Each miner will require a single CPU core.
+
+Make sure you're in the pegnet-compose directory.
+
+```
+MINERS=4 docker-compose up -d
+```
+
+Check the log output to make sure it is healthy. Mining will start once factomd begins to make progress, which may take a while.
+
+```
+docker-compose logs
+```
+
+The first time you start PegNet it will build a ByteMap table. This can take 10 to 15 minutes. The ByteMap table is persisted to disc, so it will not need to build it again when you start it in the future.
+
+## Stop
+
+You can stop and remove the pegnet container without stopping factomd and walletd (for instance, if you want to change the number of miners).
+
+```
+docker stop pegnet && docker rm pegnet
+```
+
+If you ever want to take everything down.
+
+```
+docker-compose down
+```
+
+In either case, you can to bring it all back online with the [start](#start) command above.

+ 1 - 0
coordinator/config/.gitignore

@@ -0,0 +1 @@
+pegnet.ini

+ 84 - 0
coordinator/config/pegnet.ini.EXAMPLE

@@ -0,0 +1,84 @@
+[Debug]
+# Randomize adds a random factor +/- the give percent.  3.1 for 3.1%
+  Randomize=0.0
+# Turns on logging so the user can see the OPRs and mining balances as they update
+  Logging=true
+# Puts the logs in a file.  If not specified, logs are written to stdout
+  LogFile=
+
+[Miner]
+  # Factom Connection Options
+  FactomdLocation="factomd:8088"
+  WalletdLocation="factom_walletd:8089"
+
+  # Options to setup a networked miner to a coordinator
+  MiningCoordinatorPort=:7777
+  MiningCoordinatorHost=localhost:7777
+
+  # This is used to authenticate via challenge + response to the coordinator.
+  # If the coordinator and miner have different secrets, they will not connect to each
+  # other.
+  CoordinatorSecret="hunter2"
+  UseCoordinatorAuthentication=true
+
+  NumberOfMiners=1
+# The number of records to submit per block. The top N records are chosen, where N is the config value
+  RecordsPerBlock=3
+
+# The targeted cutoff. If our difficulty will land us in the top 300 (estimated), we will submit our OPR.
+# <=0 will disable this check.
+  SubmissionCutOff=200
+  Protocol=PegNet 
+  Network=MainNet
+
+  ECAddress=CHANGEME
+  FCTAddress=CHANGEME
+  CoinbaseAddress=CHANGEME
+  IdentityChain=CHANGEME
+
+# This section must ONLY include data sources and their priorities. Any configuration
+# related to a source should be specified in the [Oracle] section.
+# -1 == disabled
+[OracleDataSources]
+  # Always rank this the highest at 0. It pegs USD at 1USD = 1USD.
+  # This is not a website, this is a hardcoded '1'. Don't change this
+  FixedUSD=0
+
+  # ----------------
+  # Paid Sources
+  APILayer=-1
+  1Forge=-1
+
+  # ----------------
+  # Free sources, signup required
+  CoinMarketCap=-1
+  #   Hourly data for the commodities
+  OpenExchangeRates=9
+
+  # ----------------
+  #  Free sources, no signup required
+  FreeForexAPI=3
+  AlternativeMe=1
+  CoinCap=-1
+
+  #   Web scraping, rank it low
+  Kitco=-1
+
+# Insert keys for any data source you ahve specified above where the priority is > -1
+[Oracle]
+
+  # Must get a key from here https://apilayer.com/
+  APILayerKey=CHANGEME
+  # Must get an api key here https://openexchangerates.org/
+  OpenExchangeRatesKey=CHANGEME
+  # Must get an api key here https://coinmarketcap.com/api/
+  CoinMarketCapKey=CHANGEME
+  # Must get an api key here https://1forge.com/forex-data-api
+  1ForgeKey=CHANGEME
+
+
+# This section should be done with caution. There is no error handling
+# if you put in a bad order or use datasources that you did not enable.
+[OracleAssetDataSourcesPriority]
+  # Example to overrride BTC order
+  # XBT=CoinMarketCap,OpenExchangeRates,CoinCap

+ 43 - 0
coordinator/docker-compose.yml

@@ -0,0 +1,43 @@
+version: '3'
+services:
+    walletd:
+        network_mode: host
+        # Check https://hub.docker.com/r/factominc/factom-walletd/tags for latest stable release
+        image: factominc/factom-walletd:v2.2.14-alpine
+        volumes:
+            # Volume where wallet information is stored
+            - factom_wallet:/root/.factom/wallet
+            # Volume that holds the factomd.conf file
+            - ./config/factomd.conf:/root/.factom/m2/factomd.conf:ro
+        expose:
+            # Wallet API
+            - 8089
+        restart: unless-stopped
+        container_name: factom_walletd
+    coordinator:
+        network_mode: host
+        # Check https://hub.docker.com/r/pegnet/pegnet/tags for latest stable release
+        image: pegnet/pegnet:v0.1.0
+        volumes:
+            - ./config/pegnet.ini:/root/.pegnet/defaultconfig.ini:ro
+            # ByteMap table
+            - pegnet_coordinator:/root/.lxrhash
+        ports:
+            # Control panel
+            - 8080:8080
+            # Miner API
+            - 8099:8099
+            # Coordinator
+            - 7420:7420
+        depends_on:
+            - walletd
+        container_name: pegnet-netcoordinator
+        entrypoint: ./pegnet
+        restart: always
+        command: ["netcoordinator", "--log", "debug"]
+    
+volumes:
+    factom_wallet:
+        external: true
+    pegnet_coordinator:
+        external: true

+ 1 - 0
coordinator/start.sh

@@ -0,0 +1 @@
+docker-compose up -d --no-deps --build $1

+ 169 - 0
miner/README.md

@@ -0,0 +1,169 @@
+# PegNet Compose
+
+PegNet Compose leverages Docker Compose to help you start and manage a PegNet miner.
+
+## Requirements
+
+-   [Docker Engine 1.13.0+](https://docs.docker.com/install/)
+-   [Docker Compose](https://docs.docker.com/compose/install/)
+
+## Setup
+
+This is the initial setup process. You will only need to do this once.
+
+#### 1. Clone and cd into this repo
+
+```
+git clone https://github.com/pegnet/pegnet-compose.git && cd pegnet-compose
+```
+
+#### 2. Create Docker volumes
+
+PegNet Compose uses 3 Docker volumes to persist data.
+
+```
+docker volume create factom_database
+docker volume create factom_wallet
+docker volume create pegnet
+```
+
+#### 3. Create a factomd.conf
+
+It is necessary to create a factomd.conf file in the config folder. The default settings should work out of the box for most people.
+
+```
+cp config/factomd.conf.EXAMPLE config/factomd.conf
+```
+
+#### 4. Start factomd and walletd
+
+Begin syncing the blockchain and start the wallet. This command looks like it only brings walletd up, but it brings factomd up too.
+
+```
+docker-compose run --name walletd -d walletd
+```
+
+#### 5. Create or add an entry credit address
+
+##### a. Create an entry credit address
+
+```
+docker exec -it walletd \
+curl -X GET \
+--data-binary '{"jsonrpc": "2.0", "id": 0, "method": "generate-ec-address"}' \
+-H 'content-type:text/plain;' http://localhost:8089/v2
+```
+
+Copy down the public address you see in the output as you will need it later. It should begin with `EC`.
+
+**OR**
+
+##### b. Add an entry credit address
+
+Replace the secret key with your own secret key. It should begin with `Es`. Note: be careful not to change the formatting when copying over your secret key. Check the quotation marks.
+
+```
+docker exec -it walletd \
+curl -X GET --data-binary \
+'{"jsonrpc": "2.0", "id": 0, "method": "import-addresses", "params":{"addresses":[{"secret":"Es3tXbGBVKZDhUWzDKzQtg4rcpmmHPXAY9vxSM2JddwJSD5td3f8"}]}}' \
+-H 'content-type:text/plain;' http://localhost:8089/v2
+```
+
+#### 6. OPTIONAL: Create a FCT address
+
+If you do not already have a FCT address, you can create one in walletd.
+
+```
+docker exec -it walletd \
+curl -X GET \
+--data-binary '{"jsonrpc": "2.0", "id": 0, "method": "generate-factoid-address"}' \
+-H 'content-type:text/plain;' http://localhost:8089/v2
+```
+
+Copy down the public address, you will need it later.
+
+#### 7. Fund your entry credit address
+
+The cheapest way to buy entry credits is to create them yourself using FCT. You can do that using several different Factom wallets, including [MyFactomWallet](https://myfactomwallet.com/#/) (web), [Enterprise Wallet](https://docs.factomprotocol.org/wallets/enterprise-wallet) (desktop) or walletd (cli), which we have running here.
+
+Alternatively, you can buy EC directly from [Factom Inc](https://shop.factom.com/) or [De Facto](https://ec.de-facto.pro/) who will deposit EC directly into your entry credit address.
+
+#### 8. Create the PegNet config file
+
+Copy the example config file to use as a template.
+
+```
+cp config/pegnet.ini.EXAMPLE config/pegnet.ini
+```
+
+Open the config file in a text editor.
+
+```
+nano config/pegnet.ini
+```
+
+Change the following items:
+
+-   `ECAddress` to the public EC address created or added to the wallet in step 5.
+-   `FCTAddress` and `CoinbaseAddress` to your FCT address.
+-   `IdentityChain` to any alphanumeric string (no spaces!) that will help you identity your miner amongst the rest.
+
+Your miner needs to be able to get asset prices from an oracle. Complete the `[Oracle]` and `[OracleDataSources]` section of the config. The comments in the config file will guide you.
+
+#### 9. Wait for factomd to finish syncing
+
+The initial sync might take anywhere from 12 to 48 hours. You can close the shell whilst this is happening if you wish.
+
+You will be able to see the progress of the factomd sync in your web browser by visiting `host:8090`, where `host` is the IP address of your machine. If you're doing this on your local machine, `host` will be `localhost`.
+
+You can also track it at the command line with the following command.
+
+```
+docker exec -it factomd \
+curl -X POST --data-binary \
+'{"jsonrpc": "2.0", "id": 0, "method": "heights"}' -H 'content-type:text/plain;' http://localhost:8088/v2
+```
+
+It has finished syncing when all the heights are the same.
+
+#### 10. Stop and remove walletd
+
+We will bring it up again later when we start PegNet.
+
+```
+docker stop walletd && docker rm walletd
+```
+
+## Start
+
+When you start PegNet, you need to pass the number of miners you want it to run as an environment variable. Each miner will require a single CPU core.
+
+Make sure you're in the pegnet-compose directory.
+
+```
+MINERS=4 docker-compose up -d
+```
+
+Check the log output to make sure it is healthy. Mining will start once factomd begins to make progress, which may take a while.
+
+```
+docker-compose logs
+```
+
+The first time you start PegNet it will build a ByteMap table. This can take 10 to 15 minutes. The ByteMap table is persisted to disc, so it will not need to build it again when you start it in the future.
+
+## Stop
+
+You can stop and remove the pegnet container without stopping factomd and walletd (for instance, if you want to change the number of miners).
+
+```
+docker stop pegnet && docker rm pegnet
+```
+
+If you ever want to take everything down.
+
+```
+docker-compose down
+```
+
+In either case, you can to bring it all back online with the [start](#start) command above.

+ 1 - 0
miner/config/.gitignore

@@ -0,0 +1 @@
+pegnet.ini

+ 84 - 0
miner/config/pegnet.ini.EXAMPLE

@@ -0,0 +1,84 @@
+[Debug]
+# Randomize adds a random factor +/- the give percent.  3.1 for 3.1%
+  Randomize=0.0
+# Turns on logging so the user can see the OPRs and mining balances as they update
+  Logging=true
+# Puts the logs in a file.  If not specified, logs are written to stdout
+  LogFile=
+
+[Miner]
+  # Factom Connection Options
+  FactomdLocation="factomd:8088"
+  WalletdLocation="factom_walletd:8089"
+
+  # Options to setup a networked miner to a coordinator
+  MiningCoordinatorPort=:7777
+  MiningCoordinatorHost=localhost:7777
+
+  # This is used to authenticate via challenge + response to the coordinator.
+  # If the coordinator and miner have different secrets, they will not connect to each
+  # other.
+  CoordinatorSecret="hunter2"
+  UseCoordinatorAuthentication=true
+
+  NumberOfMiners=1
+# The number of records to submit per block. The top N records are chosen, where N is the config value
+  RecordsPerBlock=3
+
+# The targeted cutoff. If our difficulty will land us in the top 300 (estimated), we will submit our OPR.
+# <=0 will disable this check.
+  SubmissionCutOff=200
+  Protocol=PegNet 
+  Network=MainNet
+
+  ECAddress=CHANGEME
+  FCTAddress=CHANGEME
+  CoinbaseAddress=CHANGEME
+  IdentityChain=CHANGEME
+
+# This section must ONLY include data sources and their priorities. Any configuration
+# related to a source should be specified in the [Oracle] section.
+# -1 == disabled
+[OracleDataSources]
+  # Always rank this the highest at 0. It pegs USD at 1USD = 1USD.
+  # This is not a website, this is a hardcoded '1'. Don't change this
+  FixedUSD=0
+
+  # ----------------
+  # Paid Sources
+  APILayer=-1
+  1Forge=-1
+
+  # ----------------
+  # Free sources, signup required
+  CoinMarketCap=-1
+  #   Hourly data for the commodities
+  OpenExchangeRates=9
+
+  # ----------------
+  #  Free sources, no signup required
+  FreeForexAPI=3
+  AlternativeMe=1
+  CoinCap=-1
+
+  #   Web scraping, rank it low
+  Kitco=-1
+
+# Insert keys for any data source you ahve specified above where the priority is > -1
+[Oracle]
+
+  # Must get a key from here https://apilayer.com/
+  APILayerKey=CHANGEME
+  # Must get an api key here https://openexchangerates.org/
+  OpenExchangeRatesKey=CHANGEME
+  # Must get an api key here https://coinmarketcap.com/api/
+  CoinMarketCapKey=CHANGEME
+  # Must get an api key here https://1forge.com/forex-data-api
+  1ForgeKey=CHANGEME
+
+
+# This section should be done with caution. There is no error handling
+# if you put in a bad order or use datasources that you did not enable.
+[OracleAssetDataSourcesPriority]
+  # Example to overrride BTC order
+  # XBT=CoinMarketCap,OpenExchangeRates,CoinCap

+ 25 - 0
miner/docker-compose.yml

@@ -0,0 +1,25 @@
+version: '3'
+services:
+    netminer:
+        network_mode: host
+        # Check https://hub.docker.com/r/pegnet/pegnet/tags for latest stable release
+        image: pegnet/pegnet:v0.1.0
+        volumes:
+            - ./config/pegnet.ini:/root/.pegnet/defaultconfig.ini:ro
+            # ByteMap table
+            - pegnet_miner:/root/.lxrhash
+        ports:
+            # Control panel
+            - 8080:8080
+            # Miner API
+            - 8099:8099
+        container_name: pegnet-netminer
+        entrypoint: ./pegnet
+        restart: always
+        command: ["netminer", "--miners", "${MINERS:-1}", "--log", "debug"]
+    
+volumes:
+    factom_wallet:
+        external: true
+    pegnet_miner:
+        external: true