News for hackers. Stuff that matters.
Re:Bitcoin From Scratch – Part 1 by martinko on Saturday July 04, 2020 @03:40AM (#23730800)
How is network consensus achieved on the difficulty adjustment?
Re:Bitcoin From Scratch – Part 1 by johnpaulkiser on Saturday July 04, 2020 @04:04AM (#23730892)
Each node independently comes to the new difficulty on their own in an entirely deterministic way.

After 2 weeks there should be 2016 blocks mined, 1 block every 10 minutes. After each 2 week period every node recalculates the new difficulty based on the actual number of blocks mined in the last 2 weeks. If the actual number of blocks produced was 25% higher than the target of 2016, then simply increase the difficulty by 25%.

Re:Bitcoin From Scratch – Part 1 by martinko on Saturday July 04, 2020 @04:08AM (#23730912)
Thanks. Given that this relies on subjective timestamps, is this really entirely deterministic? I can imagine that one node counted 2014 blocks in the past two weeks, another 2015. What happens in such cases?
Re:Bitcoin From Scratch – Part 1 by tromp on Saturday July 04, 2020 @04:17AM (#23730946)
Difficulty only changes at heights that are a multiple of 2016.
Re:Bitcoin From Scratch – Part 1 by tromp on Saturday July 04, 2020 @04:06AM (#23730900)
It is computed using only information embedded in the block chain, specifically the timestamps of blocks 2016 * i and 2016 * (i+1).
Re:Bitcoin From Scratch – Part 1 by martinko on Saturday July 04, 2020 @04:09AM (#23730915)
But aren't blockchain timestamps unreliable? It was my understanding that difficulty was based on subjective node timestamps..
Re:Bitcoin From Scratch – Part 1 by tromp on Saturday July 04, 2020 @04:15AM (#23730940)
The miner embeds their current (local) timestamp in the header, so there can be small variations. In fact the only requirement on the next timestamp is that it not be less than the median of the past 11 timestamps.

Once embedded in the header, everyone will agree on past timestamps as they agree on the chain with the most accumulated difficulty.