玩 Ethereum Blockchain

- GPU Mining on Google Cloud 分享 -

王銘德 @mingderwang

集先鋒

以太坊

GCPUG Taiwan Meetup #24

  •  

2018 FPU edition

自我介紹

王銘德, 集先鋒有限公司 (ELK as a Service)

 

Taipei Ethereum Meetup

Taipei DevOps Meetup

GCPUC.TW

Docker Taipei Meetup

Taipei Ethereum Meetup 社團

以色龍 Ethereum 以太坊 臉書

ethertw.slack.com 討論區

Medium 以太坊社群專欄

什麼是 blockchain?

比特幣, ” 以太幣 “ 都是一種架構在 blockchain 上的虛擬幣

銀行電匯

台灣的銀行

  • 手續費  NTD$ 100
  • 郵電費  NTD$ 220

 

100 + 220 = 320 台幣 +

美國的銀行 USD18 = 594 台幣

Ethereum

Tx Cost

  • Gas Price: 2e-8 Ether
  • Gas Used: 21,000
  • Tx Price: 0.00042 Ether

 

0.00042 * 10 * 33 = 0.14 台幣

The Cost of Remit Some Money to US

942 倍

* 還有, PayPal 也是過氣, 2.9% 手續費 + 30 cents, 瘋了!跟信用卡 (Visa, MasterCard) 一樣貴了

May 22, 2010, 10,000 比特幣只值 $40, 只能買兩個 pizzas. 現在值台幣 357,109,805, 三億五千多萬, 可以買 3~4 台 Bugatti Chiron 跑車

2017

2010 

共同帳本, 每個 node 有一份

de-centralized 設計 (p2p)

...

...

  • 所有的 miners 去算下一個 block 的 hash 值, 前面最多個零小過一個數, 就赢得該次獎金!
  • 每個 block 包含上一個 block 的 hash 值, 再去做 hash
  • 每個 block 裡有這次所有交易資料或 smart contracts 的程式譯碼
  • 這些獎金哪裡來?

etherscan.io

用 docker 架設一個 node

怎麼用 Google Cloud?

將 docker image 上載到 Google Cloud Repo (grc.io)

docker tag mingder78/parity asia.gcr.io/winter-wonder-647/instance-parity

gcloud docker -- push asia.gcr.io/winter-wonder-647/instance-parity

確認 docker image 上載成功

sha256:c6818af08c9763d2b360eb118995794d965ed76aa92d897989080ffa3d592a79 size: 2197

gcloud docker -- push asia.gcr.io/winter-wonder-647/instance-parity

Container Registry

c6818af08c97

gcloud docker -- push asia.gcr.io/winter-wonder-647/instance-parity

Check Your GPU Quota

4 x 8 = 32 個 NVIDIA K80

Check Your GPU model

其實我們只需要 2GB GDDR5 each core (10GB 浪費掉了)

Check Your GPU Cost !!!

GPUs 不能 attach 到 Preemptible Instances

First Trial

* 相同的 Project, Instance 裡 docker 抓不到自己的 gcr

$ METADATA=http://metadata.google.internal/computeMetadata/v1
$ SVC_ACCT=$METADATA/instance/service-accounts/default
$ ACCESS_TOKEN=$(curl -H 'Metadata-Flavor: Google' $SVC_ACCT/token \
    | cut -d'"' -f 4)
$ docker login -e 1234@5678.com -u _token -p $ACCESS_TOKEN https://gcr.io
$ docker run --rm gcr.io/<your-project>/<your-image> <command>

 

Second Run

經過自我授權後, 抓到 docker images 了

3rd Run

加 volume 跟 port 的參數, 改 google firewall 開放 8545

sudo docker run -it -v /var/parity/mainnet:/root/.parity -p 8545:8545 -p 8080:8080 -p 8180:8180 -n my-parity mingder78/instance-parity oot/.parity -p 8545:8545 -p 8080:8080 -p 8180:8180 -n my-parity mingder78/instance-parity 

re-sync from #3356450 to 5611447  (now in 5/14/2018)

1 ether = 50 USD to "707" now.

成功抓到 blocks

但 THE LAST BLOCK is 3462125 

 

利用 web3.js + devtool 連線

成功透過該 Ethereum node 查詢到第 48 個 block 的資料

跟 Etherscan 資料比對

第 48 個 block 的 Mined By: 0x1b70474b ... 相同

web3.js 透過自己的 node

了解整個 Ethereum Blockchain 的所有交易和紀錄

(例如, 查詢現在最近一個 block 是幾號)

then?

什麼是 mining 挖礦?

(Proof of work)

沒有適當的鼓勵或誘因, 誰會願意架設 node 來維持共同帳本的運作 ?

Bitcoin

10 mins per block

404,638 blocks (6 years)

1 BTC ~= 417 USD

Adam Back hashcash

HR: 1,201,761,024 GH/s

Diff: 165,496,835,118

Block Reward: 25 BTC

Reward: 12.50 (in 2017)

BTC

0.0000968 US$ (R7 240 card)

Ethereum

15 sec per block

1,220,351 blocks (8 months)

1 ETH ~= 10 USD

Ethash (a modified version of Dagger-Hashimoto )

HashRate (1,443 GH/s)

Diff: 21.04 TH/s (from 8)

Block Reward: 5.00588 ETH

Ether, Gas, Uncle?, Wei

12.5 US$/ 月 (R7 240 card)

不同在哪裡?(2016/4)

Bitcoin

10 mins per block

460,134 blocks (7 years)

1 BTC ~= 1,147 USD

Adam Back hashcash

 

HR: 3,799,849,871 GH/s

Diff: 499,635,929,817

Block Reward: 12.5 BTC

不能寫 smart contracts

BTC

0.0003441 US$ (R9 720 card)

Ethereum

15 sec per block

3,466,539 blocks (19 months)

1 ETH ~= 50 USD

Ethash (a modified version of Dagger-Hashimoto )

HashRate (16,016.45 GH/s)

Diff: 223.89 TH/s

Block Reward: 5.01321 ETH

可以寫 Smart contracts

Ether, Gas, Uncle?, Wei

82 US$/ 月 (R9 720 card)

不同在哪裡?(2017/4)

為何我又要開始 Mining

從年初 1 Ether = 9.85 美金, 3 月中漲到 50 美金

如果 Google Cloud GPU 比自己

買繪圖卡來 mining 還便宜, 價格好就自動挖, 價格不好就停

GPU

19.43 MH/s

??? MH/s

ROI ???

how ?

我需要安裝, eth, geth, 或 ethminer 

在 Google Computer Engine 裡先安裝 geth 與 ethminer. 在把 snapshot 起來, 可以利用 snapshot 開啟 GPU instance.

 

"Attaching GPUs to Instances"

誤導了我 !!!

我需要換有 GPU 的 Instance

只有以下幾個 Data Centers 有 GPUs

 

  • us-west1-b (我無 quota)
  • us-east1-d
  • europe-west1-b
  • asia-east1-a

因為要搬 docker 但又不想

重頭開始 sync 3,466,539 blocks (至少需三天三夜)

$ docker commit a9f asia.gcr.io/winter-wonder-647/instance-parity:block_3466539

$ gcloud docker -- push

asia.gcr.io/winter-wonder-647/instance-parity:block_3466539

Instance-Parity (我發明的方法)

把舊的 blocks 直接包在 docker images 裡 (但安全嗎?)

My First Mine on Google Cloud

 Got work package:
miner  05:41:58.936|ethminer    Header-hash: e7e70f40cd84dc6a156cefa09d155407cc24d2c2325cf625cfb9c0df8fe031d5
miner  05:41:58.936|ethminer    Seedhash: fd8498fade3673e1123a9d82267a3e966bd05069e9933ed95a8cd9c35f7d85d4
miner  05:41:58.936|ethminer    Target: 0000000000015c55b42af7f2b8747f86904b8326ea66b34587106cb67e7dda06

越少 0 的人贏 (14 秒內) -> 獎金約 NTD$7,500

左邊先用 CPU mine, 右邊安裝

GPU driver

右邊安裝好了, 開始用 GPU mine

0 H/s -> 12552014 H/s (6291456 hashes / 0.544 s)

自己 GPU (左), 跟 CPU (右) 比賽

當然還要跟所有的 miners 比 (運氣)

或參加 mining pools

或參加 mining pools

so ?

Scale out! (8 GPUs)

發現 CPU and memory is my limitation !!

最後 8CPUs + 7.2 GB + 8GPUs 才夠

8 CPUs

x 3

7.2 GB 就夠了

火力全開, 一小時 0.042674 Ether

(1 Ether = 11 USD 來推算)

312.69 MH/s

只用了 3/4 就榮登 Top 1 miner

結論

  1. 不要用 default OS - Debian, ethminer 很難編譯 (Ubuntu 16.04 is a good choice)
  2. 用 Instance-Parity docker images, 可以快速的產生 node
  3. 用 image snapshots, 我們可以快速產生新的 mining machines.
  4. 用別人的 docker images 或 OS images, 確定替自己帳號在 mining, 否則挖到也是別人的.
  5. scale out 到 8 GPUs x 4 area, 每台主機 8 CPUs + 7.2 GB RAM + 8 GPUs 至少. (考慮一下 the total cost, 代價太高)
  6. 結論應該是: 台灣電費很便宜, 應該是 Google Cloud 蓋台灣 Data Center 主要的原因吧 !!

謝謝大家

( 好玩就好 )

參考資料

https://medium.com/decentralized-capital/setting-up-a-parity-ethereum-node-in-docker-and-connect-safely-f881faa17686

 

https://github.com/ethereum/wiki/wiki/JavaScript-API

 

https://medium.com/google-cloud/running-jupyter-notebooks-on-gpu-on-google-cloud-d44f57d22dbd

Google User Group #24 4/7/2017-> FPU edition

By Ming-der Wang

Google User Group #24 4/7/2017-> FPU edition

GCPUG Taiwan Meetup #24 (updated for new Google FPU edition)

  • 1,547