Skip to content

Update pow一致性算法.md #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pow一致性算法.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
在CPU挖矿部分,CpuAgent的mine函数,执行挖矿操作的时候调用了self.engine.Seal函数。这里的engine是就是共识引擎。Seal为其中很重要的一个接口。它实现了nonce值的寻找和hash的计算。并且该函数是保证共识并且不能伪造的一个重要的函数。
再PoW共识算法中,Seal函数实现了工作证明。该部分源码在consensus/ethhash下。
### 共识引擎接口
```
type Engine interface {
// 获取区块挖掘者, 即coinbase
Author(header *types.Header) (common.Address, error)
Expand Down Expand Up @@ -39,6 +40,7 @@ type Engine interface {
// APIs 返回由共识引擎提供的RPC APIs
APIs(chain ChainReader) []rpc.API
}
```
### ethhash 实现分析
#### ethhash 结构体
```
Expand Down Expand Up @@ -621,4 +623,4 @@ func hashimotoLight(size uint64, cache []uint32, hash []byte, nonce uint64) ([]b
}
return hashimoto(hash, nonce, size, lookup)
}
```
```