gethで立ち上げた複数のノードへ同時にオーダーを出す方法

並列処理:
実行に時間がかかるスクリプトを並列実行するには - Kesin's diary

シェルスクリプトで単純に並列実行・直列実行を行う - Qiita

Gethコマンド:
Ethereum Geth コンソールコマンド一覧 - Qiita

                    • -

0:用意するもの
・tx.commandファイル
bash tx.commandによって全てのコマンドをコントロールする。
・gethで立ち上げた複数のノードのgeth console
・それぞれのノードへ接続できるtruffleプロジェクト
・simpletx.jsファイル (truffleコンソールでそれぞれのノードに送りたいコマンドリスト)

1: tx.command作成

(cd fullnode01; truffle exec /path_to/simpletx_node01.js > /path_to/miner01.log) & (cd fullnode02; truffle exec /path_to/simpletx_node02.js > /path_to/miner02.log)

2:geth立ち上げ
例:

$ /geth --datadir /path_to/datadir01 init /path_to/customgenesis.json
$ geth --networkid "1" --nodiscover --datadir "/path_to/datadir01" console 2>> /path_to/miner01.log


3: geth console: それぞれのノードで、送金などに用いるアカウント権限を得る(アカウントをunlockする)
> personal.unlockAccount("0xdcbc0772aeb3gh6e90fbd96a13e0be95669dde3da", "test")
true

注: これができていないとコマンドを打った時以下のようなエラーが出る

/usr/local/lib/node_modules/truffle/build/cli.bundled.js:316780
        throw errors.InvalidResponse(result);
        ^
Error: authentication needed: password or unlock


4: simpletx.jsを作成
truffle コンソールで実行したいコマンドをここにまとめる。
truffleプロジェクトごとに作成する。
サンプル:

module.exports = function(callback) {
  console.log("1:");
  console.log(Date.now());
  web3.eth.sendTransaction({from:"0xd4da6b3c39f2d855794aa42c171a02cce52d8c51", to:"0xdcbc0772aeb3gh6e90fbd96a13e0be95669dde3da", value: 1})
  console.log("end time:");
  console.log(Date.now());
}


このファイルの場所を知っておく
例:
$ pwd
/Users/username/blockchain_projects/truffledir/fullnode01/simpletx.js


5: ターミナルから、並列処理のコマンドを打つ
bash tx.command