to read later: RSK & faster block time + security audit reports

hi there, I have some questions concerning the choice of confirmation time ? why 10 sec ? I just read an article by Mr Lerner aoub t a 5 sec confirmation time
https://bitslog.wordpress.com/2014/02/17/5-sec-block-interval
It is something that we can apply to rootstock sidechain ?

 

Sergio @SergioDemianLerner Jan 19 00:57
@jeamick In theory a pure PoW-based cryptocurrency can have 5-sec block intervals if it's miners are not heavily clustered into pools. When miners are clustered into pools then the pool bandwidth consumption increases considerably if the block time gets shorter. Pools generally have a few centralized servers, so increasing the load on these few servers is not good to them. On the other side, this can be a good deterrent from centralized pools to form. Other factor that has to be taken into account is state block rates. A cryptocurrency can have a 5-sec block interval as long as the consensus protocol is "inclusive" or cooperative, which means that uncle blocks are counted towards the accumulated chain work. If the cryptocurrency mining is not inclusive, then there will be huge benefits for centralization.
In the case of RSK, we could in the future reduce the block time, however, because RSK processes smart-contracts, and because contract processing cannot be generally pre-processed, RSK has a limitation(where an UTXO like cryptocurrency wouldn't have this limitation). This can be corrected by headers-first block-propagation, and in fact this is something we researched at RSK.

 

 

----

Adrián Eidelman @aeidelman Jan 18 22:11
@/all RSK Security Audit Results --> https://media.rsk.co/rsk-security-audit-results/

コマンドまとめ ETH, RSK, Truffle

gethコマンド

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

実験用まとめ

 

/Users/name/go-ethereum/build/bin/geth --datadir /Users/name/blockchain_projects/gethdir/miner01 -verbosity 4 --ipcdisable --port 30301 --rpcport 4444 --rpc --targetgaslimit 5000000 --gasprice "1000" console 2>> /Users/name/blockchain_projects/gethdir/testcontractgasset.log

共通:

personal.newAccount("test")

eth.getBalance(eth.accounts[0])
web3.eth.getBalance(web3.eth.accounts[0])
 

web3.personal.unlockAccount(web3.personal.listAccounts[0],"test", 1500000)

web3.eth.sendTransaction({from:web3.eth.accounts[1], to:web3.eth.accounts[0], value: 100})

TX:

 

Smart Contracts:

truffle(development)> SimpleStorage.deployed().then(function(instance){return instance.set(4);});

 

ok:

➜ truffledir /Users/HOkaniwa/go-ethereum/build/bin/geth --datadir /Users/HOkaniwa/blockchain_projects/gethdir/miner01 -verbosity 6 --ipcdisable --port 30302 --rpcport 8102 --rpc console 2>> /Users/HOkaniwa/blockchain_projects/gethdir/miner01.log

ok:
/Users/HOkaniwa/go-ethereum/build/bin/geth --datadir /Users/HOkaniwa/blockchain_projects/gethdir/miner01 -verbosity 6 --ipcdisable --port 30301 --rpcport 8101 --rpc console 2>> /Users/HOkaniwa/blockchain_projects/gethdir/miner01.log
 

not ok:

/Users/HOkaniwa/go-ethereum/build/bin/geth --datadir "/Users/HOkaniwa/blockchain_projects/gethdir/test03" -verbosity 6 --ipcdisable --port 30301 --rpcport 8101 --rpc -nodiscover console 2 >> /Users/HOkaniwa/blockchain_projects/gethdir/geth_err_genesis05.log

 

log:

DEBUG[01-04|20:34:56.930] FS scan times                            list=97.835µs set=2.868µs diff=6.568µs
INFO [01-04|20:34:56.939] Starting peer-to-peer node               instance=Geth/v1.8.0-unstable-908faf8c/darwin-amd64/go1.9.2
INFO [01-04|20:34:56.939] Allocated cache and file handles         database=/Users/HOkaniwa/blockchain_projects/gethdir/test03/geth/chaindata cache=128 handles=1024
WARN [01-04|20:34:56.953] Upgrading database to use lookup entries
INFO [01-04|20:34:56.954] Database deduplication successful        deduped=0
INFO [01-04|20:34:56.954] Initialised chain configuration          config="{ChainID: <nil> Homestead: <nil> DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: <nil> EIP158: <nil> Byzantium: <nil> Engine: unknown}"
INFO [01-04|20:34:56.955] Disk storage enabled for ethash caches   dir=/Users/HOkaniwa/blockchain_projects/gethdir/test03/geth/ethash count=3
INFO [01-04|20:34:56.955] Disk storage enabled for ethash DAGs     dir=/Users/HOkaniwa/.ethash                                        count=2
INFO [01-04|20:34:56.956] Initialising Ethereum protocol           versions="[63 62]" network=1
INFO [01-04|20:34:56.958] Loaded most recent local header          number=0 hash=6231b0…a0300b td=1024
INFO [01-04|20:34:56.958] Loaded most recent local full block      number=0 hash=6231b0…a0300b td=1024
INFO [01-04|20:34:56.958] Loaded most recent local fast block      number=0 hash=6231b0…a0300b td=1024
DEBUG[01-04|20:34:56.958] Reinjecting stale transactions           count=0
INFO [01-04|20:34:56.959] Regenerated local transaction journal    transactions=0 accounts=0
DEBUG[01-04|20:34:56.960] Recalculated downloader QoS values       rtt=20s confidence=1.000 ttl=1m0s
INFO [01-04|20:34:56.966] Starting P2P networking
INFO [01-04|20:34:56.968] RLPx listener up                         self="enode://b7cc11c3be83189ccb5d2a623fe96fb410b6b1cdbd71fb46e5e583f6f7a98d796d2d387a7db0374cc27f989b4ff4e0cbf511acaa68879f5bbec2bfed3eeba2f7@[::]:30301?discport=0"
DEBUG[01-04|20:34:56.970] InProc registered *node.PrivateAdminAPI under 'admin'
DEBUG[01-04|20:34:56.971] InProc registered *node.PublicAdminAPI under 'admin'
DEBUG[01-04|20:34:56.971] InProc registered *debug.HandlerT under 'debug'
DEBUG[01-04|20:34:56.971] InProc registered *node.PublicDebugAPI under 'debug'
DEBUG[01-04|20:34:56.972] InProc registered *node.PublicWeb3API under 'web3'
DEBUG[01-04|20:34:56.972] InProc registered *ethapi.PublicEthereumAPI under 'eth'
DEBUG[01-04|20:34:56.972] Couldn't add port mapping                proto=tcp extport=30301 intport=30301 interface="UPnP or NAT-PMP" err="no UPnP or NAT-PMP router discovered"
DEBUG[01-04|20:34:56.972] InProc registered *ethapi.PublicBlockChainAPI under 'eth'
DEBUG[01-04|20:34:56.973] InProc registered *ethapi.PublicTransactionPoolAPI under 'eth'
DEBUG[01-04|20:34:56.973] InProc registered *ethapi.PublicTxPoolAPI under 'txpool'
DEBUG[01-04|20:34:56.973] InProc registered *ethapi.PublicDebugAPI under 'debug'
DEBUG[01-04|20:34:56.973] InProc registered *ethapi.PrivateDebugAPI under 'debug'
DEBUG[01-04|20:34:56.973] InProc registered *ethapi.PublicAccountAPI under 'eth'
DEBUG[01-04|20:34:56.973] Executing EVM call finished              runtime=1.483762ms
DEBUG[01-04|20:34:56.973] Release oracle not found                 contract=0xFA7B9770Ca4cb04296Cac84F37736d4041251CDF
DEBUG[01-04|20:34:56.973] InProc registered *ethapi.PrivateAccountAPI under 'personal'
DEBUG[01-04|20:34:56.973] InProc registered *eth.PublicEthereumAPI under 'eth'
DEBUG[01-04|20:34:56.973] InProc registered *eth.PublicMinerAPI under 'eth'
DEBUG[01-04|20:34:56.974] InProc registered *downloader.PublicDownloaderAPI under 'eth'
DEBUG[01-04|20:34:56.974] InProc registered *eth.PrivateMinerAPI under 'miner'
DEBUG[01-04|20:34:56.974] InProc registered *filters.PublicFilterAPI under 'eth'
DEBUG[01-04|20:34:56.974] InProc registered *eth.PrivateAdminAPI under 'admin'
DEBUG[01-04|20:34:56.974] InProc registered *eth.PublicDebugAPI under 'debug'
DEBUG[01-04|20:34:56.974] InProc registered *eth.PrivateDebugAPI under 'debug'
DEBUG[01-04|20:34:56.974] InProc registered *ethapi.PublicNetAPI under 'net'
DEBUG[01-04|20:34:56.974] HTTP registered *node.PublicWeb3API under 'web3'
DEBUG[01-04|20:34:56.974] HTTP registered *ethapi.PublicEthereumAPI under 'eth'
DEBUG[01-04|20:34:56.974] HTTP registered *ethapi.PublicBlockChainAPI under 'eth'
DEBUG[01-04|20:34:56.975] HTTP registered *ethapi.PublicTransactionPoolAPI under 'eth'
DEBUG[01-04|20:34:56.975] HTTP registered *ethapi.PublicAccountAPI under 'eth'
DEBUG[01-04|20:34:56.975] HTTP registered *eth.PublicEthereumAPI under 'eth'
DEBUG[01-04|20:34:56.975] HTTP registered *eth.PublicMinerAPI under 'eth'
DEBUG[01-04|20:34:56.975] HTTP registered *downloader.PublicDownloaderAPI under 'eth'
DEBUG[01-04|20:34:56.975] HTTP registered *filters.PublicFilterAPI under 'eth'
DEBUG[01-04|20:34:56.975] HTTP registered *ethapi.PublicNetAPI under 'net'
INFO [01-04|20:34:56.975] HTTP endpoint opened: http://127.0.0.1:8101
TRACE[01-04|20:34:57.120]                                          msg="sending {\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"rpc_modules\",\"params\":null}"
TRACE[01-04|20:34:57.121]                                          msg="<-readResp: response {\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"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\"}}"
TRACE[01-04|20:34:57.129]                                          msg="sending {\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"web3_clientVersion\",\"params\":[]}"
TRACE[01-04|20:34:57.129]                                          msg="<-readResp: response {\"jsonrpc\":\"2.0\",\"id\":2,\"result\":\"Geth/v1.8.0-unstable-908faf8c/darwin-amd64/go1.9.2\"}"
TRACE[01-04|20:34:57.130]                                          msg="sending {\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"eth_coinbase\",\"params\":[]}"
TRACE[01-04|20:34:57.130]                                          msg="<-readResp: response {\"jsonrpc\":\"2.0\",\"id\":3,\"error\":{\"code\":-32000,\"message\":\"etherbase must be explicitly specified\"}}"
TRACE[01-04|20:34:57.130]                                          msg="sending {\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"rpc_modules\",\"params\":null}"
TRACE[01-04|20:34:57.131]                                          msg="<-readResp: response {\"jsonrpc\":\"2.0\",\"id\":4,\"result\":{\"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\"}}"
TRACE[01-04|20:34:57.908] Started watching keystore folder         path=/Users/HOkaniwa/blockchain_projects/gethdir/test03/keystore


DEBUG[01-04|20:35:16.962] Recalculated downloader QoS values       rtt=20s confidence=1.000 ttl=1m0s
DEBUG[01-04|20:35:36.963] Recalculated downloader QoS values       rtt=20s confidence=1.000 ttl=1m0s
DEBUG[01-04|20:35:56.965] Recalculated downloader QoS values       rtt=20s confidence=1.000 ttl=1m0s

 

 

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

gethでEthereumのlocal cluster(複数ノードのあるprivate network)を作る方法

サイト: Overall: 

https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster

Connecting to the network · ethereum/go-ethereum Wiki · GitHub https://blog.coinfabrik.com/how-to-run-multiple-geth-instances-on-our-private-ethereum-blockchain/

1: Build geth tool https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum

2: set up 1 node in private network https://qiita.com/oggata/items/eea4d5e37f38785f6079

3: Config nodes in network https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster


1: genesis.json作成

{
"nonce": "0x0000000000000042",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x400",
"alloc": {},
"coinbase": "0x3333333333333333333333333333333333333333",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x",
"gasLimit": "0x8000000",
"config": {}
} 

2: genesis init

2つのノードを立ち上げる。異なるデータディレクトリと同じgenesis.jsonファイルを用いる。

➜  go-ethereum git:(master) ✗ /Users/username/go-ethereum/build/bin/geth --datadir /Users/username/blockchain_projects/gethdir/miner01 init /Users/username/blockchain_projects/gethdir/customgenesis.json

3:ネットワーク立ち上げ それぞれのデータディレクトリを指定して以下のコマンドを打つ。 geth consoleが出てきたら成功。

➜  go-ethereum git:(master) ✗ /Users/username/go-ethereum/build/bin/geth --datadir /Users/username/blockchain_projects/gethdir/miner01 -verbosity 6 --ipcdisable --port 30301 --rpcport 8101 --rpc console 2>> /Users/username/blockchain_projects/gethdir/miner01.log

Welcome to the Geth JavaScript console!
instance: Geth/v1.8.0-unstable-908faf8c/darwin-amd64/go1.9.2
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
>

4: enodeURL確認

> admin.nodeInfo.enode
"enode://3524a52d94a5b5cdc698a5757447c5644d0e22049be81829720368c71f4fbfa7f6ef652cc06e77fc0b4fd0303d0590482be3bd988aac882439d6ac3c8878d65d@124.213.106.195:30301"

5: パソコン環境の中で使えるポート番号を確認 gethのconsoleではなくターミナルから:

➜  ~ ifconfig|grep netmask|awk '{print $2}'
127.0.0.1
192.168.0.4

4で確認した、「124.213.106.195」というポートは使えないことがわかる。 実際にこちらのenodeURLでpeerを追加しようとしても、peerCountは変わらない。

5: enodeURLによるpeerの追加 使えるポートの番号を用いて次のステップを実行。 片方のノードで、もう片方のノードを追加すると、相互に接続ができる。

> admin.addPeer("enode://3524a52d94a5b5cdc698a5757447c5644d0e22049be81829720368c71f4fbfa7f6ef652cc06e77fc0b4fd0303d0590482be3bd988aac882439d6ac3c8878d65d@127.0.0.1:30301")

*...127.0.0.1のポート番号は 4で確認したものを変更した。

6:追加を確認

geth console:
> net.peerCount
1

 

gethのlogをms単位で取得する方法

やりたいこと:

今回は、gethのlogにおいて、ミリセカンド単位まで時間を表示させたい。

 

アプローチ:

logの時間はTimeFormatという変数で設定されている。

これは、geth, azureの設定ファイルで go言語で以下のように設定されているものだ。

go-ethereum/vendor/github.com/Azure/go-autorest/autorest/date/time.go

https://github.com/ethereum/go-ethereum/blob/master/vendor/github.com/Azure/go-autorest/autorest/date/time.go

この書式に基づいて、logのフォーマットを決めている箇所を編集すれば良い。

 

0: 編集するコード:

go-ethereum/log/format.go

https://github.com/ethereum/go-ethereum/blob/3991745c5f72033bdefb1ca5931f48857d8d9973/log/format.go

 

1: 編集箇所:

const (

timeFormat     = "2006-01-02T15:04:05-0700"

termTimeFormat = "01-02|15:04:05"

floatFormat    = 'f'

termMsgJust    = 40

)

 

2: 編集

timeFormat     = "2006-01-02T15:04:05.000-0700"

// timeFormat     = "2006-01-02T15:04:05-0700"

termTimeFormat = "01-02|15:04:05.000" 

// termTimeFormat = "01-02|15:04:05"

*...ミリセカンド以下の単位を表示したい場合は、小数点以下の0を増やしていけば良い。

 

3: ビルド

➜ go-ethereum git:(master) ✗ make geth

 

4: 結果

INFO [01-03|14:52:37.800] --
INFO [01-03|14:52:37.801] --

 

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:

f:id:haruokny:20180103001118p:plain

https://github.com/ethereum/go-ethereum/blob/908faf8cd715c873e4b5fdbb7af8d4f496702d84/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へアップグレード

f:id:haruokny:20180103001422p:plain

 

同エラー:

Error installing go-ethereum on Mac OS X · Issue #117 · ethereum/homebrew-ethereum · GitHub

"util.go:45: exit status 2 exit status 1 make: *** [all] Error 1" when executing brew install ethereum on El Capitan · Issue #132 · ethereum/homebrew-ethereum · GitHub

 

---

参考:

https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Mac

https://ethereum.stackexchange.com/questions/2539/how-do-i-decrease-the-difficulty-on-a-private-testnet

https://ethereum.stackexchange.com/questions/7141/is-it-possible-to-change-the-block-target-time/7142

https://github.com/ethereum/go-ethereum/blob/5f55d95aea433ef97c48ae927835d833772350de/core/block_validator.go#L265-L312