Ethereumのprivate networkのblock timeを一定に指定する方法
Ethereumのprivate networkをパソコンに立ち上げました。
その際、block confirmationをするblock timeがポワソン分布に従って、一定ではなく保たれています。
しかし、実験のためにblock timeを一定に指定する必要があったため、その設定をしました。
結果、一定間隔でブロックが生成されるようになりました。
0:現在使っているgo-ethereum (geth)をアンインストール/ファイルを削除して、githubからファイルをクローンしてくる。
$ git clone https://github.com/ethereum/go-ethereum
1:ソースコードの編集
最新バージョンgethにおいて編集するコード:
go-ethereum/consensus/ethash/consensus.go:
上のfunctionの中身を以下に置き換える:
return big.NewInt(1)
ソースコード編集結果:
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
return big.NewInt(1)
// next := new(big.Int).Add(parent.Number, big1)
// switch {
// case config.IsByzantium(next):
// return calcDifficultyByzantium(time, parent)
// case config.IsHomestead(next):
// return calcDifficultyHomestead(time, parent)
// default:
// return calcDifficultyFrontier(time, parent)
}
2:goのmakeコマンドでソースコードをビルドする
➜ go-ethereum git:(master) ✗ make geth
build/env.sh go run build/ci.go install ./cmd/geth
>>> /usr/local/Cellar/go/1.9.2/libexec/bin/go install -ldflags -X main.gitCommit=908faf8cd715c873e4b5fdbb7af8d4f496702d84 -s -v ./cmd/geth
github.com/ethereum/go-ethereum/consensus/ethash
...
Done building.
Run "/Users/HO/go-ethereum/build/bin/geth" to launch geth.
3:2で ビルドエラーが出た場合
エラー内容:
$ cd go-ethereum
$ go-ethereum git:(master) ✗ make geth
build/env.sh go run build/ci.go install ./cmd/geth
>>> /usr/local/Cellar/go/1.9.2/libexec/bin/go install -ldflags -X main.gitCommit=908faf8cd715c873e4b5fdbb7af8d4f496702d84 -s -v ./cmd/geth
github.com/ethereum/go-ethereum/consensus/ethash
# github.com/ethereum/go-ethereum/consensus/ethash
consensus/ethash/consensus.go:299:42: next declared and not used
util.go:45: exit status 2
exit status 1
make: *** [geth] Error 1
➜ go-ethereum git:(master) ✗ geth version
zsh: command not found: geth
解決: Macを最新のOSへアップグレード
同エラー:
Error installing go-ethereum on Mac OS X · Issue #117 · ethereum/homebrew-ethereum · GitHub
---
参考:
https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Mac