diodechain / diode_server

Diode Server
https://diode.io
Other
36 stars 9 forks source link

diode logo

Secure. Super Light. Web3.

An Ethereum Chain Fork for the Web3

Build Status

Diode Miner & Traffic Gateway

This server is the main Diode blockchain node. It implements both Diode PEER and EDGE protocols. After startup it will automatically connect to the network, and start mining and start acting as a traffic relay.

Traffic Gateways should always be setup on publicly reachable interfaces with a public IP. If the Node is not reachable from other nodes it might eventually blocked.

By default it will mine using 75% of one CPU. This number can be controlled or set to 'disabled' using the environment variable WORKER_MODE

Alternative it can be specified using an additional config file in config/diode.exs:

use Mix.Config

System.put_env("WORKER_MODE", "50")
# System.put_env("WORKER_MODE", "disabled")

Default Ports

TCP port bindings can be controlled through environment variables. The default bindings are:

Variable Description Default Port(s)
RPC_PORT Ethereum JSON API endpoint 8545
RPCS_PORT SSL version of RPC_PORT* 8443
EDGE2_PORT Client Communication Port 41046,443,993,1723,10000
PEER_PORT Miner-To-Miner Communication Port 51054

RPCS_PORT is only used & needed for access from Web2 services such as the blockchain explorer at https://diode.io/prenet/ - the port can be ignored in most deployments.

EDGE2_PORT and PEER_PORT support multiple port numbers given by a comma separated list.

Defining the Wallet to be used

By default the miner will autogenerate a Wallet on startup. This wallet can be inspected on the remote shell:

> ./remsh
iex> Wallet.printable(Diode.miner())

And it's private key can be printed and saved for backup using:

> ./remsh
iex> Base16.encode(Wallet.privkey!(Diode.miner()))

To inject a stored Wallet into the server the enviornment variable PRIVATE can be setup, before starting the miner.

export PRIVATE=0xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
supervise .

Pre-Requisites

Building

mix deps.get
mix compile

erl_nif.h not found

In case you receive the erl_nif.h not found error add this:

export CFLAGS=-I`erl -eval 'io:format("~s", [lists:concat([code:root_dir(), "/erts-", erlang:system_info(version), "/include"])])' -s init stop -noshell`

Building on macOS

On macOS after installing boost with brew you might need to add it to the environment variables, so the compiler can find it:

brew install boost
export CFLAGS=-I`brew --prefix boost`/include 
export LDFLAGS=-L`brew --prefix boost`/lib

Running tests

make test

Using for smart contract development

The diode server can be used as RPC server for Smart Contract development. To start a local network similiar to ganache there is a predefined shell script. Just run:

./dev

And a dedicated local rpc server start-up

Running

The initial syncing of the network will take multiple hours. So it's advised to start directly with a superviser such as from the daemontools. To start with that on macOS or linux run:

supervise .

Diferences from main Ethereuem (geth)