兄弟连区块链入门教程以太坊源码分析hashimoto源码分析(二)

兄弟连区块链培训 · · 834 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

兄弟连区块链入门教程以太坊源码分析hashimoto源码分析(二)。
“超级计算机是将计算受限问题转化为I / O约束问题的一种设备。”
Ken Batcher
Instead, an algorithm will have little room to be sped up by new hardware if it acts in a way that commodity computer systems are already optimized for.
相反,如果一种算法以商品计算机系统已经优化的方式运行,那么算法将没有多少空间可以被新硬件加速。
Since I/O bounds are what decades ofcomputing research has gone towards solving, it’s unlikely that the relatively small motivation ofmining a few coins would be able to advance the state ofthe art in cache hierarchies. In the case that advances are made, they will be likely to impact the entire industry of computer hardware.
由于I / O界限是几十年来计算研究已经解决的问题,挖掘一些加密货币的相对较小的动机将不可能提高缓存层次结构的艺术水平。 在取得进展的情况下,可能会影响整个计算机硬件产业。
Fortuitously, all nodes participating in current implementations ofcryptocurrency have a large set of mutually agreed upon data; indeed this “blockchain” is the foundation ofthe currency. Using this large data set can both limit the advantage ofspecialized hardware, and require working nodes to have the entire data set.
幸运的是,参与当前加密货币实施的所有节点都有大量相互同意的数据;实际上,“区块链”是货币的基础。 使用这个大数据集既可以限制专用硬件的优点,又可以让工作节点拥有整个数据集。
Hashimoto is based offBitcoin’s proofofwork2. In Bitcoin’s case, as in Hashimoto, a successful
proofsatisfies the following inequality:
Hashimoto是基于比特币的工作量证明。 在比特币的情况下,和Hashimoto一样,一个成功的证明满足以下不等式:
hash_output < target
For bitcoin, the hash_output is determined by
在比特币中, hash_output是由下面决定的。
hash_output = sha256(prev_hash, merkle_root, nonce)
where prev_hash is the previous block’s hash and cannot be changed. The merkle_root is based on the transactions included in the block, and will be different for each individual node. The nonce is rapidly incremented as hash_outputs are calculated and do not satisfy the inequality. Thus the bottleneck of the proofis the sha256 function, and increasing the speed ofsha256 or parallelizing it is something ASICs can do very effectively.
prev_hash是前一个区块的hash值,而且不能更改。merkle_root是基于区块中的交易生成的,并且对于每个单独的节点将是不同的。我们通过修改nonce的值来让上面的不等式成立。这样整个工作量证明的瓶颈在于sha256方法,而且通过ASIC可以极大增加sha256的计算速度,或者并行的运行它。
Hashimoto uses this hash output as a starting point, which is used to generated inputs for a second hash function. We call the original hash hash_output_A, and the final result of the prooffinal_output.
Hashimoto使用这个hash_output作为一个起点,用来生成第二个hash函数的输入。我们称原始的hash为hash_output_A, 最终的结果为 prooffinal_output.
Hash_output_A can be used to select many transactions from the shared blockchain, which are then used as inputs to the second hash. Instead of organizing transactions into blocks, for this purpose it is simpler to organize all transactions sequentially. For example, the 47th transaction of the 815th block might be termed transaction 141,918. We will use 64 transactions, though higher and lower numbers could work, with different access properties. We define the following functions:
hash_output_a可用于从共享区块链中选择多个事务,然后将其用作第二个散列的输入。 而不是组织交易成块,为此目的是顺序组织所有交易更简单。 例如,第815个区块的第47个交易可能被称为交易141,918。 我们将使用64个交易,尽管更高和更低的数字可以工作,具有不同的访问属性。 我们定义以下功能:
nonce 64­bits. A new nonce is created for each attempt.
get_txid(T) return the txid (a hash ofa transaction) of transaction number T from block B.
block_height the current height ofthe block chain, which increases at each new block
nonce 64­bits. 每次尝试会生成一个新的nonce值.
get_txid(T) 从block B中通过交易序号来获取交易id
block_height 当前的区块高度
Hashimoto chooses transactions by doing the following:
Hashimoto 通过下面的算法来挑选交易:

hash_output_A = sha256(prev_hash, merkle_root, nonce)
for i = 0 to 63 do
    shifted_A = hash_output_A >> i
    transaction = shifted_A mod total_transactions
    txid[i] = get_txid(transaction) << i
end for
txid_mix = txid[0] ⊕ txid[1] … ⊕ txid[63]
final_output = txid_mix ⊕ (nonce << 192)

The target is then compared with final_output, and smaller values are accepted as proofs.
如果 final_output 比 target小,那么就会被接受。


有疑问加站长微信联系(非本文作者)

本文来自:Segmentfault

感谢作者:兄弟连区块链培训

查看原文:兄弟连区块链入门教程以太坊源码分析hashimoto源码分析(二)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

834 次点击  
加入收藏 微博
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传