Ethereum的Whisper通信介绍
Whisper是Ethereum P2P协议的一部分,可以让消息在同一个区块链内的用户之间传递。
- Whisper的使用场景==> link
- Whisper的介绍==> link
- Whisper的web3接口==> link
Whisper是独立于区块链之外的协议,智能合约不能够使用。
开启Whisper协议, geth -shh
节点默认不会回复消息。所以必须直连到接收人,否者消息将无法发送。
Whisper是Ethereum P2P协议的一部分,可以让消息在同一个区块链内的用户之间传递。
Whisper是独立于区块链之外的协议,智能合约不能够使用。
开启Whisper协议, geth -shh
节点默认不会回复消息。所以必须直连到接收人,否者消息将无法发送。
1 | > eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(1, "ether"), nonce:0}) |
1 | > txpool.status |
1 | > txpool.status |
在应用本地保存nonce在数据库中,并且,数据库中的nonce值更新时需要访问锁保护。不建议将nonce保存在内存中,那样的话,在应用死机或者重启时,nonce将丢失。目前思考 Redis DB 是比较好的选择。
如果本地nonce出了问题,可以使用 web3.eth.getTransactionCount(ethAddress) 来恢复。但是 web3.eth.getTransactionCount(ethAddress) 是内存中的值,不是实时准确的,不建议实时使用。
另外:
即使交易池(queue)中有交易存在,nonce正确的交易仍然可以继续进行。
当共识停止工作了,nonce正确的交易进入到pending队列中,nonce较高的交易进入到queue队列中。当共识重新正常工作时,pending队列中的交易会被自动处理而清空。
同时节点具有每隔一个小时,重新处理一次本地交易的能力。(handle local transaction journal rotation)
参考链接 ==> https://ethereum.stackexchange.com/questions/2808/what-happens-when-a-transaction-nonce-is-too-high
参考代码 ==>
1 | ethereum/go-ethereum/core/tx_pool.go |
本问题调查过程中,使用到的命令==>
1 | eth.getTransactionCount(eth.accounts[0]) |
开源是社会化协作的基础。随着软件越来越昂贵、风险越来越大,单靠一个企业内的合作已经不够了,需要全球供应链、全球生产链来共同生产软件、维护软件、交付软件。开源也是社会化生产的需要。经过20年的发展,开源已经今非昔比。20年前,开源是一种软件的开发和交付方式;2020年,开源已经演进发展为一种生态竞争的模式。
开源的生产交付模式已发展成熟。2019年,70%的财富50强企业为GitHub(代码托管网站)贡献了开源代码。开源已经形成了两种模式:基金会主导模式(Linux模式)和企业主导模式(Android模式)。码农数量激增,因为码农是数字社会先进生产力的代表。
总而言之,开源几乎是躲不掉的,99%的组织已经在其 IT系统中使用了开源软件。2019年,中国的代码贡献量上升了48%。在中国,过去,开源的核心是国际项目本土化,现在,国内开源的焦点是本土项目国际化。重要的是,要将风险管控前置来治理开源。
参考链接:
go-ethereum 在 2019 年 7 月推出了 Geth v1.9.x 版本。
Geth 可以通过 --metrics 命令符收集运行状态信息。 Geth v1.9.x 有3套独立的监控体系,ExpVars,InfluxDB 和 Prometheus:
是将Golang系统公共指标暴露给到HTTP接口。Geth 用 pprof 来作为埋点暴露这些公共参数。
运行 Geth –metrics –pprof 将暴露指标成为ExpVars的格式,于地址
http://127.0.0.1:6060/debug/metrics。
ExpVars 有 Golang 非常好的支持。
同理 ExpVars,运行 Geth –metrics –pprof 将暴露指标成为Prometheus的格式,于地址
http://127.0.0.1:6060/debug/metrics/prometheus。
Prometheus更加接近业界的标准。
ExpVars 和 Prometheus 是拉取pull数据的监控方式。InfluxDB 是推送push数据的监控方式。
InfluxDB的启用有些麻烦,请参见 geth help 中的 --metrics.influxdb 及其子标识。
推荐使用 Grafana,建议使用 geth-prometheus 项目中给出的图表,参考链接==> https://github.com/karalabe/geth-prometheus。效果如下图:

参考文档==> Geth v1.9.0 Six months distilled
具体功能如下:
仪表板的监控指标:
关于PBFT的监控,已tendermint为例,已经具备 Prometheus 监控能力。

具体参数请参见 ==> https://docs.tendermint.com/master/tendermint-core/metrics.html
The following metrics are available:
| Name | Type | Since | Tags | Description |
|---|---|---|---|---|
| consensus_height | Gauge | 0.21.0 | Height of the chain | |
| consensus_validators | Gauge | 0.21.0 | Number of validators | |
| consensus_validators_power | Gauge | 0.21.0 | Total voting power of all validators | |
| consensus_validator_power | Gauge | 0.33.0 | Voting power of the node if in the validator set | |
| consensus_validator_last_signed_height | Gauge | 0.33.0 | Last height the node signed a block, if the node is a validator | |
| consensus_validator_missed_blocks | Gauge | 0.33.0 | Total amount of blocks missed for the node, if the node is a validator | |
| consensus_missing_validators | Gauge | 0.21.0 | Number of validators who did not sign | |
| consensus_missing_validators_power | Gauge | 0.21.0 | Total voting power of the missing validators | |
| consensus_byzantine_validators | Gauge | 0.21.0 | Number of validators who tried to double sign | |
| consensus_byzantine_validators_power | Gauge | 0.21.0 | Total voting power of the byzantine validators | |
| consensus_block_interval_seconds | Histogram | 0.21.0 | Time between this and last block (Block.Header.Time) in seconds | |
| consensus_rounds | Gauge | 0.21.0 | Number of rounds | |
| consensus_num_txs | Gauge | 0.21.0 | Number of transactions | |
| consensus_total_txs | Gauge | 0.21.0 | Total number of transactions committed | |
| consensus_block_parts | counter | on dev | peer_id | number of blockparts transmitted by peer |
| consensus_latest_block_height | gauge | on dev | /status sync_info number | |
| consensus_fast_syncing | gauge | on dev | either 0 (not fast syncing) or 1 (syncing) | |
| consensus_block_size_bytes | Gauge | 0.21.0 | Block size in bytes | |
| p2p_peers | Gauge | 0.21.0 | Number of peers node’s connected to | |
| p2p_peer_receive_bytes_total | counter | on dev | peer_id, chID | number of bytes per channel received from a given peer |
| p2p_peer_send_bytes_total | counter | on dev | peer_id, chID | number of bytes per channel sent to a given peer |
| p2p_peer_pending_send_bytes | gauge | on dev | peer_id | number of pending bytes to be sent to a given peer |
| p2p_num_txs | gauge | on dev | peer_id | number of transactions submitted by each peer_id |
| p2p_pending_send_bytes | gauge | on dev | peer_id | amount of data pending to be sent to peer |
| mempool_size | Gauge | 0.21.0 | Number of uncommitted transactions | |
| mempool_tx_size_bytes | histogram | on dev | transaction sizes in bytes | |
| mempool_failed_txs | counter | on dev | number of failed transactions | |
| mempool_recheck_times | counter | on dev | number of transactions rechecked in the mempool | |
| state_block_processing_time | histogram | on dev | time between BeginBlock and EndBlock in ms |