<story><title>Tinychain: a pocket-sized implementation of Bitcoin</title><url>https://github.com/jamesob/tinychain</url></story><parent_chain><item><author>PaulBGD_</author><text>I&amp;#x27;m working on my own blockchain (not specifically bitcoin) implementation just to wrap my head around everything. One thing I&amp;#x27;m not getting that also wasn&amp;#x27;t answered by the source code is how you check timestamps.&lt;p&gt;I understand the whole network time = median offset + local time thing, however I&amp;#x27;m a bit fuzzy on how you check timestamps on previous blocks when you&amp;#x27;re initially downloading the chain. How do you know that you need to check the timestamp if you can&amp;#x27;t know if you&amp;#x27;re on the latest block?</text></item></parent_chain><comment><author>Taek</author><text>You need to check two things. First you need to check that this block had a timestamp higher than the median of the past 11 blocks (it&amp;#x27;s a consensus rule). Second you need to check that the timestamp is not unacceptably far in the future. For historic blocks, it definitely won&amp;#x27;t be because the timestamp will be far in the past (as the block was created far in the past).&lt;p&gt;Latest block or not, it just needs to follow those rules. That &lt;i&gt;does&lt;/i&gt; mean it&amp;#x27;s possible for a block with an invalid timestamp to become valid after some time has passed. But if it is invalid, nobody will be mining on it, so it&amp;#x27;s unlikely to remain part of the longest chain.</text></comment>
<story><title>Tinychain: a pocket-sized implementation of Bitcoin</title><url>https://github.com/jamesob/tinychain</url></story><parent_chain><item><author>PaulBGD_</author><text>I&amp;#x27;m working on my own blockchain (not specifically bitcoin) implementation just to wrap my head around everything. One thing I&amp;#x27;m not getting that also wasn&amp;#x27;t answered by the source code is how you check timestamps.&lt;p&gt;I understand the whole network time = median offset + local time thing, however I&amp;#x27;m a bit fuzzy on how you check timestamps on previous blocks when you&amp;#x27;re initially downloading the chain. How do you know that you need to check the timestamp if you can&amp;#x27;t know if you&amp;#x27;re on the latest block?</text></item></parent_chain><comment><author>Ded7xSEoPKYNsDd</author><text>In my toy blockchain implementation, I just went with two constraints:
1) every timestamp must be strictly larger than the one of the previous block (this makes difficulty calculation easier)
2) timestamps may not be in the future (except for a little wiggle room for unsynchronized clocks)&lt;p&gt;My reasoning was roughly as follows:&lt;p&gt;Miners are incentivized to pick very large timestamps, because the longer it takes to mine X blocks, the easier becomes the proof of work they need to solve, giving them more block rewards and transaction fees in the long run. But if they want the network to accept their blocks, they can&amp;#x27;t pick timestamps in the future, so the best they can do is pick the current time as their timestamp.</text></comment>