How exactly is network time sampled?

Is it as simple as one node stamping data right before being sent, the receiving node logging the current time before all other activity, and taking the difference? Or is there something more complex involved?

Links to code would be much appreciated.


Bitcoin block headers serve as the timestamp system for bitcoin. Whichever miner finds the next block includes their systems timestamp and the network either agrees it is valid or throws it out for being outside their margin of acceptance.

Bitcoin verifies the time with a margin of nTimeOffset, which is set by bitcoin asking other nodes what time they think it is and taking the median. You can find this code by looking at AddTimeData in util.cpp, found here: https://github.com/bitcoin/bitcoin/blob/master/src/util.cpp

It should also be noted that some miners, principally ASICs, do so much hashing that they actually push their timestamps a few seconds into the future using rolltime to get extra work sets: https://en.bitcoin.it/wiki/Getwork#rollntime

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy