Header Ads

Header ADS

What is mining difficulties ?

  what mining is? In a nutshell, mining is the process of creating a new block for a blockchain and filling that block with transactions. But what I didn't explain is the mining difficulty. To understand what it is, let's look again at the problem that blockchain is trying to solve, creating consensus amongst a bunch of computers or nodes on the Internet, and the case of a cryptocurrency that is agreeing about how individual users have spent their coins. It might not seem like it, but this is a challenging problem to solve. Nodes on this network aren't always honest, and they can appear or disappear whenever they like. Now imagine you want to join the Bitcoin network. Your computer goes out on the Internet and looks for other nodes that are participating. But how does your computer know which one to trust? Every one of these nodes could be trying to game the system and make themselves rich. The solution proposed by the creator of Bitcoin was simple, the longest valid chain  is the one to pick, but this alone isn't enough.
What is mining difficulties ?


 If you are an attacker, you could fabricate a very long chain with false transactions and everyone will think that yours contains the truth. Like to solve this problem, Satoshi slowed down the process of creating new blocks with the proof of work algorithm. This is almost like a lottery where your computer is doing a bunch of random calculations to try and be the first to solve a cryptographic puzzle. Your chances of solving it are actually quite low, it's almost like all miners in the world are trying to pick the same complex lock. Everyone tries a bunch of combinations, but in the end only one can solve it first, and when that happens you have to start all over again to create the next block. On average, there is one computer every 10 minutes that solves the puzzle and gets the mining reward for creating a new block. This time delay of 10 minutes makes it impossible to artificially create the longest chain. Because the probability that your computer alone can pick this lock is highly unlikely. You need many people trying many random combinations to get it done within the time frame. Awesome. Problem solved. Uh, but hold on, there is one more issue. Our computers get faster over time, so newer computers could perform more calculations and potentially create blocks in under 10 minutes. Meaning an attacker could purchase a bunch of really fast computers and trying to get ahead of everyone else. Luckily, Satoshi thought of this as well, and this brings us finally to the mining difficulty. This is a number that controls how hard your computer has to work to create a new block. And this isn't a fixed number. It's automatically adjusted every 2016 block. The system looks at how fast these blocks were created. Normally this should take exactly 2 weeks. If more blocks were created in that time period, the difficulty is increased, and if less blocks were created, the difficulty is reduced. That seems simple enough. But why would the difficulty have to be adjusted every two weeks? We don't get massive computer upgrades every two weeks, right? While the system also has to compensate for the amount of people that are mining, more miners mean that there is a higher chance of someone solving the puzzle in a shorter time frame, which means the difficulty should be increased to maintain it. And the opposite is true as well. If a lot of people stop mining, the creation of blocks will be longer and does the difficulty has to be reduced.

 So in summary, the difficulty adjustments make sure that mining new blocks always takes around 10 minutes, no matter how fast our computers are and no matter how many people are mining. Grid system but it has one big drawback, it tends to lead to centralization. See, the main reason why people are mining is because of the profits. As long as your mining operation is profitable, you keep it going. However, an increase in difficulty could mean that your mining operation now consumes more electricity than it generates in rewards. At which point you're forced to stop your mining operation, and this means that only bigger miners remain active because they have economies of scale. In the case of Bitcoin, we see a few big mining farms and mining pools taking a significant portion of this mining market. Not only does this centralized a technology that was meant to be completely distributed, but it also opens the door for these large mining firms to run attacks against the network. Solutions for this problem are being discussed though, but that's for another content. Fun side fact, if you're a developer like me, you might be thinking that this Satoshi guy is brilliant because he thought of all of this. But he's not perfect and also makes mistakes. There's a small bug in the difficulty adjustment code of Bitcoin. After 2016 blocks, the difficulty is recalculated, but the code only looks at the 1st 2015 blocks. So if all blocks took exactly 10 minutes to mine, and the last block took 100 days to mine, it wouldn't affect the difficulty at all. What a rookie mistake! So don't feel too bad about your own coding skills. Thank you so much for reading.

 

No comments

Powered by Blogger.