Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: ffe on August 21, 2012, 05:59:47 PM



Title: Obscure question about calculating the hash rate
Post by: ffe on August 21, 2012, 05:59:47 PM
Clients must agree on the next mining difficulty level every so many blocks. To do that they must effectively calculate the hash rate over the last period. To do that, an estimate of the time elapsed since the last update must be agreed to.

How do all the clients collectively agree on a consistent time?

Are the blocks time-stamped by the miner that solved it? If so, what is the validity check that other client execute against the time stamp of a newly minted block?



Title: Re: Obscure question about calculating the hash rate
Post by: DeathAndTaxes on August 21, 2012, 06:09:32 PM
The network uses loose time syncing.  The node finding the block includes a timestamp in the block header.  This can't be altered without altering the block hash.  Other nodes don't require that timestamp to be exact (obviously unworkable) but they will reject new blocks which have a timestamp that deviates by more than 3 hours from the expected.  Yes this means blocks can have timestamps "in the past".  If you check blockchain.info they show both the block timestamp and the detected timestamp.  Sometimes block timestamps will be out of sequence.


So some manipulation of the timestamps and difficulty is possible but the real world effect is minimal.  A miner trying to exploit this would need to solve either the first or last block and even then at most could manipulate the difficulty by ~1% (3 hours vs 2016*10/60 = 334 hours).


Title: Re: Obscure question about calculating the hash rate
Post by: twmz on August 21, 2012, 06:12:15 PM
Yes, every block has a timestamp in it and the difficulty adjustment algorithm looks at these timestamps when deciding how to adjust difficulty.

Nodes trust the timestamp in a given block based on pre-defined rules:

Quote
A timestamp is accepted as valid if it is greater than the median timestamp of previous 11 blocks, and less than the network-adjusted time + 2 hours. "Network-adjusted time" is the median of the timestamps returned by all nodes connected to you.

https://en.bitcoin.it/wiki/Block_timestamp


Title: Re: Obscure question about calculating the hash rate
Post by: ffe on August 21, 2012, 07:09:34 PM
Thanks guys


Title: Re: Obscure question about calculating the hash rate
Post by: kjj on August 21, 2012, 08:44:44 PM
Heh, this is one of the things that I really wish Satoshi had done better.  NTP has been around since forever, and there is no reason why bitcoin couldn't have insisted on accurate clocking.  A +/- window of 10 minutes would have been plenty to account for just about any possible network conditions.

But, like D&T said, it doesn't really matter in practice.  The natural variation in the random process of solving blocks is dominant over the 3 hour window allowed.