clique的挖矿的信任节点
来源:互联网 发布:mac 图标不放大 编辑:程序博客网 时间:2024/05/24 00:21
// Snapshot is the state of the authorization voting at a given point in time.type Snapshot struct { config *params.CliqueConfig // Consensus engine parameters to fine tune behavior sigcache *lru.ARCCache // Cache of recent block signatures to speed up ecrecover Number uint64 `json:"number"` // Block number where the snapshot was created Hash common.Hash `json:"hash"` // Block hash where the snapshot was created Signers map[common.Address]struct{} `json:"signers"` // Set of authorized signers at this moment Recents map[uint64]common.Address `json:"recents"` // Set of recent signers for spam protections Votes []*Vote `json:"votes"` // List of votes cast in chronological order Tally map[common.Address]Tally `json:"tally"` // Current vote tally to avoid recalculating}
func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error) { ... number := header.Number.Uint64() ... signer, signFn := c.signer, c.signFn ... // Bail out if we're unauthorized to sign a block snap, err := c.snapshot(chain, number-1, header.ParentHash, nil) ... // If we're amongst the recent signers, wait for the next block for seen, recent := range snap.Recents { if recent == signer { // Signer is among recents, only wait if the current block doesn't shift it out if limit := uint64(len(snap.Signers)/2 + 1); number < limit || seen > number-limit { log.Info("Signed recently, must wait for others") <-stop return nil, nil } } } ...}
// validVote returns whether it makes sense to cast the specified vote in the// given snapshot context (e.g. don't try to add an already authorized signer).func (s *Snapshot) validVote(address common.Address, authorize bool) bool { _, signer := s.Signers[address] return (signer && !authorize) || (!signer && authorize)}
func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) { ... snap := s.copy() for _, header := range headers { // Remove any votes on checkpoint blocks number := header.Number.Uint64() if number%s.config.Epoch == 0 { snap.Votes = nil snap.Tally = make(map[common.Address]Tally) } ... signer, err := ecrecover(header, s.sigcache) ... // If the vote passed, update the list of signers if tally := snap.Tally[header.Coinbase]; tally.Votes > len(snap.Signers)/2 { if tally.Authorize { snap.Signers[header.Coinbase] = struct{}{} } else { delete(snap.Signers, header.Coinbase) ... } } } ...}
阅读全文
0 0
- clique的挖矿的信任节点
- SUSE+linux+配置节点间的SSH信任关系
- 信任的力量
- 信任 MySQL 的性能
- 信任是最美的原谅
- ssh的信任关系
- 母亲的信任
- rac_/home/oracle权限过大引发的节点信任关系错误
- 物链:如何用区块链技术解决供应链生态内节点间的信任问题?
- 9. 信任成员的管理
- 客户信任度的建立
- 信任是最好的管理
- 受信任站点的批处理
- 你身边的信任危机
- 激发信任的领导行为
- 如何获得他人的信任
- 网站的信任度分析
- 9. 信任成员的管理
- 餐馆问题
- andorid compile
- [LeetCode-Algorithms-11] "Container With Most Water" (2017.10.2-WEEK5)
- 详解Python中的下划线
- 1047. 编程团体赛(20)
- clique的挖矿的信任节点
- 深度解剖~ FreeRtos阅读笔记3 freertos调度器启动、中断优先级管理、中断优先级分组
- TypeError: a bytes-like object is required, not 'str'
- java (281)手写SORM之总体架构图解
- 高性能计算库
- iostat -dmx输出的解释
- java中length,length(),size()区别
- poj 2456 Aggressive cows
- Codeforces Round #435 (Div. 2) 题解