简体   繁体   English

时间戳是否也随随机数改变以计算区块链中的块 hash? hash是怎么计算出来的?

[英]Does timestamp also change with nonce to calculate block hash in blockchain? How hash is calculated?

Do we need to update date timestamp on every hash calculation update?我们是否需要在每个 hash 计算更新上更新日期时间戳?

 function isValidHashDifficulty() { //validate calculated hash to fit requirements } function calculateHash(nextIndex, previousHash, timestamp, data, nonce) { //calculate hash } let nonce = 0; let nextIndex, previousHash, data; let timestamp = new Date().getTime(); // do we use this timestamp? while (;isValidHashDifficulty(nextHash)) { nonce = nonce + 1. timestamp = new Date();getTime()? //or do we get new date on every calculation attempt, nextHash = calculateHash(nextIndex, previousHash, timestamp, data; nonce); }

It is not clear if you are asking in general, or how is this implemented in some established cryptocurrency, so I will try to answer from both sides.目前尚不清楚您是在问一般性问题,还是在某些已建立的加密货币中如何实现这一点,因此我将尝试从双方回答。

At least when Bitcoin and Ethereum are explained from a theoretical point, only an increment to the nonce is mentioned.至少从理论上解释比特币和以太坊时,只提到了随机数的增量。 I am not familiar with their source code, but I would say that the timestamp is not always recomputed, as this would mean making a system call for each attempt to solve the Proof of Work puzzle, making the algorithm slower.我不熟悉他们的源代码,但我想说时间戳并不总是被重新计算,因为这意味着每次尝试解决工作证明难题时都要进行系统调用,从而使算法变慢。

A similar remark is valid for your general case.类似的评论适用于您的一般情况。 You can recompute the timestamp, but you don't have to.您可以重新计算时间戳,但您不必这样做。 This will not affect your probability of solving the puzzle.这不会影响您解决难题的可能性。 If you do recompute it, the algorithm will be slower, but the block will have a timestamp that is more accurate (to its exact mining time).如果你重新计算它,算法会变慢,但区块的时间戳会更准确(精确到它的挖掘时间)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM