mozyのかきおき

mozyの読書感想文や思考置き場

Docker上でイーサリアムのプライベートネットワークを構築してみる その1

何をするか

イーサリアムのスマートコントラクトに興味が湧いてきたため、色々と遊んでみたい。

やること

Docker上にイーサリアムのプライベートネットワークを構築して、まずは、動作テストをしてみる。

作業記録

公式が出しているイメージがあったため、とりあえず、Dockerのimageをpullする。

https://hub.docker.com/r/ethereum/client-go/

クライアントの実装は複数あるが、今回は一番メジャーらしきgo製のものを選択した。

Docker-test ❯ docker pull ethereum/client-go
Using default tag: latest
latest: Pulling from ethereum/client-go
ff3a5c916c92: Already exists 
621caa86389d: Pull complete 
bd6d857b7542: Pull complete 
Digest: sha256:2ff3324b43093b5edff3d0ce5260768a91d11182c1fce8fc0115d1eb71616ff9
Status: Downloaded newer image for ethereum/client-go:latest

そうしたらこんな感じになった。

docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
ethereum/client-go      latest              0cd307c2f2f4        25 minutes ago      42.3MB

とりあえず、-d オプションをつけて、バックグラウンドプロセスとして、runしてみる。

docker run -d --name ethereum-node -v $HOME/ethereum-data:/root \
            -p 8545:8545 -p 30303:30303 \
            ethereum/client-go --fast --cache=512

logを見てみると、

Docker-test ❯ docker logs -f ethereum-node
INFO [05-09|13:35:55] Maximum peer count                       ETH=25 LES=0 total=25
INFO [05-09|13:35:56] Starting peer-to-peer node               instance=Geth/v1.8.8-unstable-7beccb29/linux-amd64/go1.10.2
INFO [05-09|13:35:56] Allocated cache and file handles         database=/root/.ethereum/geth/chaindata cache=384 handles=1024
INFO [05-09|13:35:56] Writing default main-net genesis block 
INFO [05-09|13:35:57] Persisted trie from memory database      nodes=12356 size=2.34mB time=231.1108ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-09|13:35:57] Initialised chain configuration          config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: <nil> Engine: ethash}"
INFO [05-09|13:35:57] Disk storage enabled for ethash caches   dir=/root/.ethereum/geth/ethash count=3
INFO [05-09|13:35:57] Disk storage enabled for ethash DAGs     dir=/root/.ethash               count=2
INFO [05-09|13:35:57] Initialising Ethereum protocol           versions="[63 62]" network=1
INFO [05-09|13:35:57] Loaded most recent local header          number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [05-09|13:35:57] Loaded most recent local full block      number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [05-09|13:35:57] Loaded most recent local fast block      number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [05-09|13:35:57] Regenerated local transaction journal    transactions=0 accounts=0
INFO [05-09|13:35:57] Starting P2P networking 
INFO [05-09|13:35:59] UDP listener up                          self=enode://591157ed0651158beeff8b4e79252ab83e00a12118f5308bdd4125f3a9e9b6150c781f667ccf715a4a4e42e0f66d2daed14672758036ff60b12358d5ffe53716@[::]:30303
INFO [05-09|13:35:59] RLPx listener up                         self=enode://591157ed0651158beeff8b4e79252ab83e00a12118f5308bdd4125f3a9e9b6150c781f667ccf715a4a4e42e0f66d2daed14672758036ff60b12358d5ffe53716@[::]:30303
INFO [05-09|13:35:59] IPC endpoint opened                      url=/root/.ethereum/geth.ipc
INFO [05-09|13:36:19] Block synchronisation started 
WARN [05-09|13:36:20] Node data write error                    err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:20] Synchronisation failed, retrying         err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:30] Node data write error                    err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:30] Synchronisation failed, retrying         err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:40] Node data write error                    err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:40] Synchronisation failed, retrying         err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:54] Node data write error                    err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:54] Synchronisation failed, retrying         err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
INFO [05-09|13:37:05] Imported new block headers               count=192 elapsed=3.832s number=192 hash=723899…123390 ignored=0
INFO [05-09|13:37:05] Imported new block receipts              count=2   elapsed=2.177ms number=2   hash=b495a1…4698c9 size=8.00B  ignored=0
INFO [05-09|13:37:06] Imported new block receipts              count=4   elapsed=2.038ms number=6   hash=1f1aed…6b326e size=1.10kB ignored=0
INFO [05-09|13:37:15] Imported new block receipts              count=186 elapsed=8.338ms number=192 hash=723899…123390 size=23.40kB ignored=0
INFO [05-09|13:37:26] Imported new state entries               count=439 elapsed=20.453ms processed=439 pending=6377 retry=0 duplicate=0 unexpected=0
INFO [05-09|13:37:30] Imported new state entries               count=945 elapsed=5.209ms  processed=1384 pending=7265 retry=0 duplicate=0 unexpected=0
INFO [05-09|13:37:31] Imported new state entries               count=762 elapsed=9.751ms  processed=2146 pending=6584 retry=3 duplicate=0 unexpected=0
INFO [05-09|13:37:33] Imported new state entries               count=1135 elapsed=20.362ms processed=3281 pending=6484 retry=7 duplicate=0 unexpected=0
INFO [05-09|13:37:34] Imported new state entries               count=1138 elapsed=9.992ms  processed=4419 pending=7552 retry=7 duplicate=0 unexpected=0
INFO [05-09|13:37:36] Imported new state entries               count=1515 elapsed=19.731ms processed=5934 pending=7202 retry=0 duplicate=0 unexpected=0
INFO [05-09|13:37:39] Imported new state entries               count=1515 elapsed=14.048ms processed=7449 pending=5943 retry=0 duplicate=0 unexpected=0
INFO [05-09|13:37:41] Imported new state entries               count=1131 elapsed=12.412ms processed=8580 pending=5545 retry=7 duplicate=0 unexpected=0
INFO [05-09|13:37:43] Imported new state entries               count=1136 elapsed=11.578ms processed=9716 pending=5263 retry=0 duplicate=0 unexpected=0
INFO [05-09|13:37:45] Imported new state entries               count=1128 elapsed=14.792ms processed=10844 pending=5164 retry=8 duplicate=0 unexpected=0
INFO [05-09|13:37:47] Imported new state entries               count=1135 elapsed=11.881ms processed=11979 pending=4555 retry=9 duplicate=0 unexpected=0
INFO [05-09|13:37:51] Imported new state entries               count=1136 elapsed=9.862ms  processed=13115 pending=4687 retry=8 duplicate=0 unexpected=0
INFO [05-09|13:37:52] Imported new state entries               count=1136 elapsed=26.089ms processed=14251 pending=3651 retry=8 duplicate=0 unexpected=0
INFO [05-09|13:37:53] Imported new state entries               count=362  elapsed=4.607ms  processed=14613 pending=5899 retry=22 duplicate=0 unexpected=0
INFO [05-09|13:37:56] Imported new state entries               count=1087 elapsed=7.865ms  processed=15700 pending=5996 retry=21 duplicate=0 unexpected=0
INFO [05-09|13:37:56] Imported new state entries               count=384  elapsed=2.582ms  processed=16084 pending=9501 retry=0  duplicate=0 unexpected=0
INFO [05-09|13:37:58] Imported new state entries               count=1087 elapsed=23.781ms processed=17171 pending=9113 retry=22 duplicate=0 unexpected=0
INFO [05-09|13:37:59] Imported new state entries               count=1108 elapsed=23.035ms processed=18279 pending=9275 retry=22 duplicate=0 unexpected=0
INFO [05-09|13:38:02] Imported new state entries               count=1086 elapsed=21.992ms processed=19365 pending=8924 retry=22 duplicate=0 unexpected=0

お、なんかいい感じに構築できているっぽい。
一旦ここまで。

参考

qiita.com

【解決済】geth でバックグラウンド実行したプロセスがkillできない時

おきたこと

イーサリアムの勉強中に、採掘等のためにGethをバックグラウンドで常時起動して置くために & を使って以下のようなプロセスを走らせた。
geth --networkid "15" --nodiscover --datadir "eth_private_net/" console 2> eth_private_net/geth_err.log &

その後、ターミナルで普通にプロセスを普通に killしようと思ったらできないことがあった。

解決策

kill -SIGKILL {pid}のように-SIGKILLオプションをつけることで解決した。
ps aux | grep geth なりで該当のpidを確認してkillすると良いと思う。

Fiat money のFiat の意味

Fiat moneyとは

仮想通貨周りで聞くことがあるFiat moneyってなんだろうと思って調べてみた。

Fiat って単語は車のメーカーではなくって、「権威」とか「権力」を表すので、法定通貨を暗号通貨と区別して表現する時に使うらしい。

権威や権力の後ろ盾がある通過って意味で、Fiat moneyなんだね。覚えた。

Weexってな超イケてるネイティブアプリフレームワークを試してみる【25分でインストール&実機テストまで】

Weexてなによ

アリババが主導で開発していた、ネイティブアプリフレームワーク。 今はapacheプロジェクトに移管されている。
中身はVue。素敵。

weex.apache.org

インストール編

とりあえず、
npm -g i weex-toolkit webpack webpack-dev-server を叩いてライブラリ等をインストールする。
そして、サンプルプロジェクトを作る。
weex create weex-sample

以下が実行結果。インタラクティブに回答していけばいい感じにしてくれる。

weex ❯ weex create weex-sample
? May weex-toolkit anonymously report usage statistics to improve the tool over time? Yes
? Which npm registry you perfer to use? npm
23:48:51 : Set telemetry => true
23:48:51 : Set registry => http://registry.npmjs.org
Set telemetry = true
Set registry = "http://registry.npmjs.org"
23:48:51 : You can config this configuration again by using `weex config [key] [value]`
23:48:51 : Enjoying your coding time!

This command need to install weexpack. Installing...
? Project name weex-sample
? Project description A weex project
? Author MozyOk <mozy.okubo@gmail.com>
? Select weex web render lts
? Babel compiler (https://babeljs.io/docs/plugins/#stage-x-experimental-presets) stage-0
? Use vue-router to manage your view router? (not recommended) No
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Set up unit tests Yes
? Should we run `npm install` for you after the project has been created? (recommended) npm
23:53:26 : Generated weex-sample

ファイル生成が終わると、以下のように、コマンド一覧が出るのもナイス。

Success! Created weex-sample at /Users/mozyok/Test/weex/weex-sample

Inside that directory, you can run several commands:


  npm start
  Starts the development server for you to preview your weex page on browser
  You can also scan the QR code using weex playground to preview weex page on native

  npm run dev
  Open the code compilation task in watch mode

  npm run ios
  (Mac only, requires Xcode)
  Starts the development server and loads your app in an iOS simulator

  npm run android
  (Requires Android build tools)
  Starts the development server and loads your app on a connected Android device or emulator

  npm run pack:ios
  (Mac only, requires Xcode)
  Packaging ios project into ipa package

  npm run pack:android
  (Requires Android build tools)
  Packaging android project into apk package

  npm run pack:web
  Packaging html5 project into `web/build` folder

  npm run test
  Starts the test runner

To get started:

  cd weex-sample
  npm start

Enjoy your hacking time!

実行してみる

とりあえず、コマンド一覧にしたがって、

$ cd weex-sample
$ npm start

を叩いたら、ブラウザで以下のようなサンプルが実行された f:id:mozy_ok:20180421235904p:plain

このアプリをiPhoneなりにインストールして、QRコードを読み込んでみる。

Weex Playground

Weex Playground

  • Taobao (China) Software CO.,LTD
  • ユーティリティ
  • 無料

そうすると、実機のPlayground環境でも動作が試せた。めっちゃお手軽。すごい。 f:id:mozy_ok:20180422000638j:plain

まとめ

マジで15分で実機のPlayground環境で動作確認するまでできた。
Vueなので最近知見も多いし、ガシガシ書いていくと楽しそう。

証拠

1ポモドーロの間に間に合ったぜ。。 f:id:mozy_ok:20180422001402p:plain

【解決】MySQLのpasswordをなしにする

起きた事

local環境で色々遊んでいたところ、databaseを流し込もうとした時に以下のような、password があっていない時に出るエラーが起きた。

Access denied for user 'root'@'localhost' (using password: NO)
Couldn't drop database 'test_dev'

解決策

ちょっと手間だったので、mysqlにログインして、passwordの設定をなしにした。

$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.6.39 Homebrew

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password='' where User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
$ mysql -uroot   
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.6.39 Homebrew

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

passwordなしでログインできるようになった。やったね。

その他

MYSQL_ROOT_PASSWORD とか色々設定方法はあるけど、今回は一瞬だったので、簡単な方法で解決した。

3番地コードってなんだろ

3番地コードとは

拙い理解だと

output = input1 + input2

みたいに分解できる入出力の最小単位の処理を3つとするから? 3アドレスのコードというのかな。

x := i + m * n; は

t <- m * n

x <- i + t

という風に分解できるし。

 

他に、プロセッサの命令セットにおける3オペランド形式の場合、RISCプロセッサで、命令フォーマットから豊富なメモリアドレッシングを排して空いた空間を利用して、従来のCISCプロセッサに多かった2オペランド形式から、より最適化などに適した3オペランド形式としたRISCプロセッサが多いという経緯がある

3番地コード - Wikipedia

 

キーワード