Ethereum

最後更新: 2018-03-14

目錄

 


ethminer

 

HomePage: https://github.com/ethereum-mining/ethminer

Features

  • OpenCL mining
  • Nvidia CUDA mining
  • realistic benchmarking against arbitrary epoch/DAG/blocknumber
  • on-GPU DAG generation (no more DAG files on disk)
  • stratum mining without proxy
  • OpenCL devices picking
  • farm failover (getwork + stratum)

Install

[用 ppa] 不太建議用 ppa, 因為它的版本較舊

[download releases]

https://github.com/ethereum-mining/ethminer/releases

wget https://github.com/ethereum-mining/ethminer/releases/download/v0.13.0/et...

tar -zxf ethminer-0.13.0-Linux.tar.gz

mv bin/ethminer /usr/bin/ethminer

rmdir bin

Changelog

0.14.0

  • Secure TLS stratum pool connections now fully supported.
  • Expanded support for up to 32 GPUs.
  • 用 "-P URL" 去 Set specify a pool URL

0.13.0

........

 


ethminer Usage

 

ethminer --version

ethminer version 1.2.9
Build: Linux/g++/Interpreter/RelWithDebInfo

ethminer --list-devices

[OPENCL]:
Listing OpenCL devices.
FORMAT: [deviceID] deviceName
[0] GeForce GTX 1060 6GB
        CL_DEVICE_TYPE: GPU
        CL_DEVICE_GLOBAL_MEM_SIZE: 6367739904
        CL_DEVICE_MAX_MEM_ALLOC_SIZE: 1591934976
        CL_DEVICE_MAX_WORK_GROUP_SIZE: 1024

Benchmark

ethminer -M -G

-M means "run benchmark" and the -G is for GPU mining.

    --benchmark-trials <n>  Set the number of trials for the benchmark tests (default: 5).
    --phone-home <on/off>  When benchmarking, publish results (default: on)

Mining configuration:

    -C,--cpu  When mining, use the CPU.
    -G,--opencl  When mining use the GPU via OpenCL.

other opt

--farm-recheck <n>  n ms between poll geth (or eth-proxy) for new work (Default: 500)

mining

# 用 GPU 0, 1 去掘

# opencl

ethminer --opencl-device 0 1 -t 2 --farm-recheck 200 -G -F http://127.0.0.1:8080/M1

# cuda

--cuda-devices 0 1

V 0.13.0

-O, --userpass <username.workername:password> Stratum login credentials

-U,--cuda  When mining use the GPU via CUDA.

ethminer -U --list-devices

Listing CUDA devices.
FORMAT: [deviceID] deviceName
[0] GeForce GTX 1060 6GB
        Compute version: 6.1
        cudaDeviceProp::totalGlobalMem: 6373572608
[1] GeForce GTX 1060 6GB
        Compute version: 6.1
        cudaDeviceProp::totalGlobalMem: 6373572608

-HWMON

Displays gpu temp and fan percent.

CUDA configuration:

--cuda-devices <0 1 ..n> Select which CUDA GPUs to mine on. Default is to use all

--cuda-parallel-hash <1 2 ..8> Define how many hashes to calculate in a kernel, can be scaled to achieve better performance. Default=4

--cuda-block-size Set the CUDA block work size. Default is 128

--cuda-grid-size Set the CUDA grid size. Default is 8192

--cuda-streams Set the number of CUDA streams. Default is 2

--cuda-schedule <mode> Set the schedule mode for CUDA threads waiting for CUDA devices to finish work. Default is 'sync'. Possible values are:
        auto  - Uses a heuristic based on the number of active CUDA contexts in the process C and the number of logical processors in the system P. If C > P, then yield else spin.
        spin  - Instruct CUDA to actively spin when waiting for results from the device.
        yield - Instruct CUDA to yield its thread when waiting for results from the device.
        sync  - Instruct CUDA to block the CPU thread on a synchronization primitive when waiting for the results from the device.

 


Stratum-Port

 

https://en.bitcoin.it/wiki/Stratum_mining_protocol

--work-timeout <n>

reconnect/failover after n seconds of working on the same (stratum) job. Defaults to 180. Don't set lower than max. avg. block time

-SC, --stratum-client <n>  Stratum client version. Defaults to 1 (async client). Use 2 to use the new synchronous client.

-SP, --stratum-protocol <n> Choose which stratum protocol to use:

0: official stratum spec: ethpool, ethermine, coinotron, mph, nanopool (default)

1: eth-proxy compatible: dwarfpool, f2pool, nanopool (required for hashrate reporting to work with nanopool)

2: EthereumStratum/1.0.0: nicehash

-RH, --report-hashrate

Report current hashrate to pool (please only enable on pools supporting this)

-SE, --stratum-email <s>

Email address used in eth-proxy (optional)

--farm-recheck <n> 

Leave n ms between checks for changed work (default: 500).

When using stratum, use a high value (i.e. 2000) to get more stable hashrate output
 

i.e.

# V0.14

用 "-P URL" 去 Set specify a pool URL, The 1st for for the primary pool, and the 2nd for the failover pool.

nanopool.sh

#!/bin/sh
# --cuda-devices 0 1 2 \

ethminer -U \
 -L sequential \
 -RH \
 --farm-recheck 1000 \
 -P stratum1+tcp://0x?@eth-jp1.nanopool.org:9999/MyRig/Email \
 -P stratum1+tcp://0x?eth-asia1.nanopool.org:9999/MyRig/Email

# V0.13

nanopool.sh

#!/bin/sh
# --cuda-devices 0 1 2 \

ethminer -U \
 -L sequential \
 -SP 1 \
 -RH \
 -SC 1 \
 --cuda-parallel-hash 4 \
 -S  eth-asia1.nanopool.org:9999 \
 -SF eth-jp1.nanopool.org:9999 \
 --farm-recheck 1000 \
 -O 0x?.MyRig/Email

dwarfpool.sh

ethminer -U --cl-parallel-hash 8 \
 --cuda-devices 0 1 2 3 4 5 6 7 9 \
 -L sequential \
 -SP 1 \
 -S eth-hk.dwarfpool.com:8008 \
 -SF eth-sg.dwarfpool.com:8008 \
 -HWMON --farm-recheck 2000 -RH \
 -O 0x?.MyRig:Email


ethminer api

 

# Use 0 to disable. Default=0,
# use negative numbers to run in readonly mode. for example -3333.

--api-port <portnum>

Messages exchanged through this channel must conform the Jsonrpc v.2 specifications

 

Example: A collection of statistical data (miner_getstat1)

echo '{"id": 1,"jsonrpc": "2.0","method": "miner_getstat1"}' | netcat 127.0.0.1 3333 | jq

{
   "id":1,
   "jsonrpc":"2.0",
   "result":[  
    "0.16.0.dev0+commit.41639944",          // The actual release of ethminer
    "48",                                   // Total running time in minutes
    "87221;54;0",                           // ETH hashrate in KH/s, submitted shares, rejected shares
    "14683;14508;14508;14508;14508;14508",  // Detailed ETH hashrate in KH/s per GPU
    "0;0;0",                                // (not used) DCR hashrate in KH/s, submitted shares, rejected shares
    "off;off;off;off;off;off",              // (not used) Detailed DCR hashrate in KH/s per GPU
    "53;90;50;90;56;90;58;90;61;90;60;90",  // Temp and fan speed pairs per GPU
    "eu1.ethermine.org:4444",               // Mining pool currently active
    "0;0;0;0"                               // ETH invalid shares, ETH pool switches, DCR invalid shares, DCR pool switches
   ]
}

miner_shuffle

The mining process is nothing more that finding the right number (nonce) which,

applied to an algorithm (ethash) and some data, gives a result which is below or equal to a given target.

This in very very (very) short !

The range of nonces to be searched is a huge number: 2^64 = 18446744073709600000~ possible values.

Each one has the same probability to be the right one.

Every time ethminer receives a job from a pool you'd expect the miner to begin searching from the first but that would be boring.

So the concept of scramble nonce has been introduced to achieve these goals:

All miner_shuffle method does is to re-initialize a new random scramble nonce to start from in next jobs.

{"id": 1, "jsonrpc": "2.0", "method": "miner_shuffle"}

miner_restart

useful if you detect one, or more, GPU are in error but in a recoverable state

(eg. no hashrate but the GPU has not fallen off the bus).

( restart ethminer without loosing connection to the pool )

過程

  1. Stop actual mining work
  2. Unload generated DAG files
  3. Reset devices (GPU)
  4. Regenerate DAG files
  5. Restart mining

echo '{"id": 1, "jsonrpc": "2.0", "method": "miner_restart"}' | netcat 127.0.0.1 3333

miner_ping

echo '{"id":0,"jsonrpc":"2.0","method":"miner_ping"}' | netcat 127.0.0.1 3333

Doc

https://github.com/ethereum-mining/ethminer/blob/master/API_DOCUMENTATION.md

 

 


eth-proxy

 

HomePage: https://github.com/Atrides/eth-proxy

Install:

cd /opt

git clone https://github.com/Atrides/eth-proxy.git

Config:

eth-proxy.conf

COIN = "ETH"
HOST = "0.0.0.0"
PORT = 8080

WALLET = "XXXXXX"
ENABLE_WORKER_ID = True

Run it

apt-get install python-twisted

 


Ethash is the PoW system

 

It requires ~ 6G dataset @ 20180129

Location:

$(HOME)/.ethash/full-R<REVISION>-<SEEDHASH>

 


miner not work

 

If you don't see your miner on the stats page, 99.9% that you have corrupted DAG file.

You must delete it and restart ethminer.

 


geth

 

功能

  • mine real ether
  • transfer funds between addresses
  • create contracts and send transactions
  • explore block history

Source:

https://github.com/ethereum/go-ethereum

Install

apt-get install software-properties-common

add-apt-repository -y ppa:ethereum/ethereum

apt update

apt-get install ethereum

Help (-h)

opts

--datadir "/root/.ethereum"  Data directory for the databases and keystore

Folder

Data directory: ~/.ethereum

Ethash DAG: ~/.ethereum/geth

console Command:

geth console

Welcome to the Geth JavaScript console!

instance: Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9
coinbase: 0xYOUR_ADDRESS
at block: 0 (Thu, 01 Jan 1970 08:00:00 HKT)
 datadir: /root/.ethereum
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

Check Balances

web3.fromWei(eth.getBalance(web3.eth.accounts[0]), "ether")

Account Command:

   list         # Print summary of existing accounts
   new       # Create a new account
   update   # Update an existing account
   import    # Import a private key into a new account

ie.

geth --datadir /data/ethereum account list

Account #0: {YOUR_ADDRESS} keystore:///data/ethereum/keystore/<date>--YOUR_ADDRESS

Verify Password

# 用改 Password 去驗證 Password

geth account update 0x?

Passphrase:
INFO [02-06|23:09:30] Unlocked account                         address=0x?
Please give a new password. Do not forget this password.
Passphrase:

見到入新 Password 時按 Ctrl+C

geth console

> personal.unlockAccount("address", "password")

Network

Geth continuously attempts to connect to other nodes on the network until it has peers. (UDP)

--nodiscover

To start geth without the discovery protocol

--bootnode

bootstrap nodes whose endpoints are recorded in the source code.

# In Shell

net.listening

net.peerCount

# To get more information
admin.nodeInfo

admin.peers

# NAT

Ethereum clients use a listener (TCP) port and a discovery (UDP) port, both on 30303 by default.

--nat value           NAT port mapping mechanism (any|none|upnp|pmp|extip:<IP>) (default: "any")

--verbosity value         Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 3)

 

# Example

geth --light --nat "extip:x.x.x.x" console

 

Light Client

# Client 的分別

# BlockVerification: No-Ancient, AvailableBlocks: Recent, AvailableStates: Recent

--no-ancient-blocks

# BlockVerification: Headers-Only, AvailableBlocks: NONE, AvailableStates: NONE

# --syncmode "fast"                     Blockchain sync mode ("fast", "full", or "light")

--light

# Blockchain Size

294.14GB@20180313

https://bitinfocharts.com/ethereum/

Chain is Bloated

Block

    A bundle of transactions which, after proper execution, update the state.

    Each transaction-bundling block gets a number, has some difficulty, and contains the most recent state.

State

    The state is made up of all initialized Ethereum accounts.

    At the time of writing, there are around 12 million known accounts and contracts growing at a rate of roughly 100k new accounts per day.
 

# Start Client

geth --syncmode "light"    /     geth --light

# Console

# --cache value           #  Megabytes of memory allocated to internal caching (min 16MB / database forced) (default: 128)

geth --light console

INFO [03-13|17:41:35] Maximum peer count                       ETH=0 LES=100 total=25
INFO [03-13|17:41:35] Starting peer-to-peer node               instance=Geth/v1.8.1-stable-1e67410e/linux-amd64/go1.9.4
INFO [03-13|17:41:35] Allocated cache and file handles         database=/root/.ethereum/geth/lightchaindata cache=768 handles=1024
INFO [03-13|17:41:35] Initialised chain configuration          config="..."
INFO [03-13|17:41:35] Disk storage enabled for ethash caches   dir=/root/.ethereum/geth/ethash count=3
INFO [03-13|17:41:35] Disk storage enabled for ethash DAGs     dir=/root/.ethash               count=2
INFO [03-13|17:41:35] Added trusted checkpoint                 chain=mainnet block=5046271 hash=04c211…ca1d63
INFO [03-13|17:41:35] Loaded most recent local header          number=5247226 hash=05d957…ebc8c3 td=3019748917866238965670
INFO [03-13|17:41:35] Starting P2P networking
INFO [03-13|17:41:37] UDP listener up                          net=enode://...
WARN [03-13|17:41:37] Light client mode is an experimental feature
INFO [03-13|17:41:37] RLPx listener up                         self="enode://..."
INFO [03-13|17:41:37] IPC endpoint opened                      url=/root/.ethereum/geth.ipc
Welcome to the Geth JavaScript console!

# 一段時間後會開始 Headers-Only sync

# https://etherscan.io/       <== LAST BLOCK: 5247450  
INFO [03-13|18:35:21] Imported new block headers               count=1  elapsed=9.180ms   number=5247448 hash=7dfd2b…bdc1b2 ignored=0
INFO [03-13|18:35:21] Imported new block headers               count=1  elapsed=6.738ms   number=5247449 hash=311b64…e0b494 ignored=0
INFO [03-13|18:35:37] Imported new block headers               count=1  elapsed=8.111ms   number=5247450 hash=2cbff2…bfc90b ignored=0

# 很多時都要一段時間後才開始 Sync, 因為 Full Sync Client 有以下 Default Setting

  --lightserv value                     Maximum percentage of time allowed for serving LES requests (0-90) (default: 0)

  --lightpeers value                    Maximum number of LES client peers (default: 20)

在未 Sync 到 Peer 的情況下行 cmd 會見到 "Error: no suitable peers available"

 


MyEtherWallet

 

https://www.myetherwallet.com

 * Open-source, client-side interface

 * Directly with the blockchain while remaining in full control of your keys
    (The handling of your keys happens entirely on your computer, inside your browser.)

-----------

To Run MyEtherWallet Offline and Locally

https://github.com/kvhnuke/etherwallet/releases/tag/v3.21.02

-----------

Send Offline

MyEtherWallet, is able to generate a valid public key (wallet address)

based on programmatic algorithms and "rules" that work on the public "online" blockchain.

The software alone generates this as a unique key.

You can generate a transaction offline using the same MyEtherWallet software,

in an offline environment, and then broadcast that transaction code using an online device.

-----------

TX Pool

TX Pool of the node you are connected to.

It is currently pending (waiting to be mined).

Checking

https://etherscan.io/txsPending

Transaction Not Found:

This transaction cannot be found in the TX Pool of the node you are connected to.

However, it could be in a different TX Pool, waiting to be mined.

Once we send a transaction to blockchain, it goes to transaction pool with other transactions.

Once the transaction is picked by any miner and included in a block, the transaction is removed from the transaction pool

 


Pool

 

較多人用的 Pool

Dwarfpool

TZ: -7

http://dwarfpool.com/eth

Server

# Only Stratum-Port (proxy+claymore): 8008

HK-Server: eth-hk.dwarfpool.com (Hong Kong/香港)
SG-Server: eth-sg.dwarfpool.com (Singapore)

# Port: 80 and Stratum-Port (proxy+claymore): 8008

US-Server: eth-us.dwarfpool.com
ASIA-Server: eth-asia.dwarfpool.com (Taiwan)

Calculated Hashrate

Calculated Hashrate takes the amount of valid shares your miner has submitted over a period of time and uses a formula to convert this into a readable hashrate. This number can fluctuate, sometimes being lower or higher than your actual miner's output hashrate in the console.

Reported Hashrate

Reported Hashrate is utilized by ethminer, a piece of mining software. It submits the hashrate of your actual hardware (what you see in your console) to the pool. This allows you to compare it to your calculated hashrate.

Reported Hashrate is just a convenience item and not required to mine on the Ethereum pool. However, it does allow you to compare your submitted hashrate to your calculated hashrate which can be useful to you.

Reported Hashrate does not affect payout.

json api

http://dwarfpool.com/eth/api?wallet=YOUR_WALLET&email=YOUR_EMAIL

status

http://dwarfpool.com/eth/address?wallet=YOUR_ACCOUNT_ADDRESS_WITHOUT_THE_0x

Nanopool

https://eth.nanopool.org/search?address=0xYOUR_ACCOUNT_ADDRESS

nanopool api

workers

# 600s 更新一次

https://api.nanopool.org/v1/eth/workers/0x?

{"status":true,"data":[{"uid":3060561,"id":"H1","hashrate":136,"lastShare":1528883828,"rating":141928},....

https://api.nanopool.org/v1/eth/history/0x?

https://api.nanopool.org/v1/eth/shareratehistory/0x?

Doc

https://eth.nanopool.org/api

Ethpool

http://ethpool.org/credits

http://ethpool.org/miners/YOUR_ACCOUNT_ADDRESS_WITHOUT_THE_0x

 


Sending ether

 

> var sender = eth.accounts[0];
> var receiver = '0x???';

# Transaction values are expressed in weis
> var amount = web3.toWei(0.01, "ether")

> eth.sendTransaction({from:sender, to:receiver, value: amount})

eth.sendTransaction({from: eth.accounts[0], to: '0x???', value: web3.toWei(0.001, "ether")})

 


Gas Price

 

預計所需 Gas 及 Price

https://ethgasstation.info/

If you do not have the ether to cover all the gas requirements to complete running your code,

the processing aborts and all intermediate state changes roll back to the pre-transaction snapshot.

Unit

1 Ether = 10^18 Wei

1Gwei = 10^9

 


Sell / Convert

 

Binance (https://www.binance.com/) is a good way to convert ETH into other coins,

Coinbase is an easy place to sell ETH to your bank account in the USA, Europe, Australia and Singapore.

收入

208W x 24h = 4992Wh ~ 5 kWh = 5 度電 ~ HK$5

以 $9k 一粒 ETH 計, 一日掘到 0.00169068 ETH (@20MHs), 收入 $15.2

---------------------------------------------

賺 = $15 - $5 = $10

 


術語

 

Ethereum DAG Size EPOCH

rigs 鑽機

 


Ethash

 

Ethash is the PoW system. This typically takes hours to generate so we tend to memorise it.

Ethash PoW is memory hard, making it basically ASIC resistant.

Clients wishing to store the DAG in a cache should conform to this spec in order to share the cache with other clients:

Location

Linux: $(HOME)/.ethash/full-R<REVISION>-<SEEDHASH>

<REVISION> is a decimal integer
<SEEDHASH> is 16 lowercase hex digits specifying the first 8 bytes of the epoch's seed hash.

ie.

full-R23-0000000000000000
full-R23-3aa8f28cac16bdd8
full-R23-b683d2a971567602

There may be many such DAGs stored in this directory; it is up to the client and/or user to remove out of date ones.

Format

Each file should begin with an 8-byte magic number,
0xfee1deadbaddcafe, written in little-endian format (i.e., bytes fe ca dd ba ad de e1 fe).

The Ethash algorithm expects the DAG as a two-dimensional array of uint32s (4-byte unsigned ints), with dimension (n × 16) where n is a large number. (n starts at 16777186 and grows from there.) Following the magic number, the rows of the DAG should be written sequentially into the file, with no delimiter between rows and each unint32 encoded in little-endian format.

Seed hash:

The seed hash is different for every epoch.
For the first epoch it is the Keccak-256 hash of a series of 32 bytes of zeros.
For every other epoch it is always the Keccak-256 hash of the previous seed hash.

The EthHash algorithm works by defining two critical structures:

A 16 MB cache, which is generated from a seed, which is changed every epoch. Every node (including light clients) generates this cache and stores it.

A 1 GB DAG, which is generated from the cache in such a way that each part of the DAG depends on a small number of pseudo-randomly chosen elements from the cache.

Each round of the algorithm only requires 64 lookups to the DAG, however.

This means that given a nonce, a non-mining client can use the cache to generate only the small portion of the DAG that is actually used.
 


Next DAG Epoch

 

Every 30,000 blocks - where 30,000 blocks is called an epoch - a new DAG file is generated.

PoW requires choosing subsets of a fixed resource dependent on the nonce and block header.

Ethash uses a DAG (directed acyclic graph) for the proof of work algorithm,

this is generated for each epoch, i.e every 30000 blocks (100 hours).

The DAG takes a long time to generate.

https://github.com/ethereum/wiki/wiki/Mining

Ethereum DAG Size EPOCH

https://investoon.com/tools/dag_size

DAG file is locating directly in your GPU memory.

And if DAG file is bigger than your GPU memory so your GPUs become useless.

 


Difficulty

 

Difficulty does not impact your individual hash rate. 

Difficulty affects productivity of a given hash rate.

More difficulty will slow down the Ether (or any other coin) production of the network. 

there are several factors affecting ETH mining/profits:

 - difficulty
 - ice-age
 - RX hashrate drop
 - coming PoS
 - possible reward reduction

The Ethereum Ice Age is a difficulty adjustment scheme that was put in place to ensure that everyone has an incentive to move to the new blockchain once the hard-fork is implemented.

 


Ethereum Wallet 與 Mist 分別

 

Mist is the browser for decentralized web apps.

What Mozilla Firefox or Google Chrome are for the Web 2.0,

the Mist Browser will be for the Web 3.0 (which will be decentralized).

These releases are therefore called Ethereum Wallet as it only offers a bundle of the Mist browser with a single DApp: the wallet.

 


Nonce

 

There are two types of nonce used in Ethereum:

  • Account nonce
  • Proof of work nonce

Account nonce

It's simply the transaction count of an account

To keep transaction related to an account in order.

This prevents replay attacks where a transaction sending
    
eg.

20 coins from A to B can be replayed by B over and over to continually drain A's balance.

eg.

If there is a transaction with nonce 3 related to some account in the txpool and
some transaction will nonce 4 arrived then that transaction won't be mined until and
unless transaction with nonce 3 is mined.

Proof of work nonce

The random value in a block that was used get the proof of work satisfied (depending on the difficulty at the time).

 


ChangeLog

 

v0.15.0

--HWMON

0 - Displays gpu temp, fan percent.
1 - and power usage.

Note for Linux: The program uses sysfs for power, which requires running with root privileges.

--tstop UINT=0

Stop mining on a GPU if temperature exceeds value. 0 is disabled, valid: 30..100

--tstart UINT=40

Restart mining on a GPU if the temperature drops below, valid: 30..100

--http-port UINT=0

Set the web api port, the miner should listen to. Use 0 to disable.

Data shown depends on hwmon setting

Troubleshot

start 時:

Error: Insufficient CUDA driver: 9010

要用 cuda 9.2

Linux x86_64/AMD64/EM64T

  • Latest Long Lived Branch version: 390.77
  • Latest Short Lived Branch version: 396.54      <-- 這 Version
  • Latest Legacy GPU version (340.xx series): 340.107

Download:

http://us.download.nvidia.com/XFree86/Linux-x86_64/396.54/NVIDIA-Linux-x86_64-396.54.run