What is mining in blockchain?

Understand the consensus of blockchains and how blocks are linked together using proof of work

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

Lesson Transcript

  • [00:00 - 01:05] Okay, so let's talk about what our mind is. So far we've talked about the consensus mechanism and a little bit about proof of work. Now let's see how everything fits together through mining. So in a distributed pay-to-pay network, everyone has the same privileges. So how do we ever confirm that the transaction is indeed now confirmed? For example, let's say Alice sends some currency like Bitcoin to Paul. How does Paul know that Alice hasn't also sent this to Charlie? This is known as a double spending problem. Since there isn't a central party like a bank to keep track of transactions and accounts, people can double spend what they have. And this is the problem that Bitcoin solved in a distributed way. The idea is very simple. Everyone is considered equal and they are special type of nodes which are known as miners. The job for miner is to create blocks and confirm transactions. Miner is incentivized to do this in mainly two ways.

  • [01:06 - 03:18] Block rewards and transaction fees. Block rewards are the main way miners make money. In Bitcoin's case, this is hot-coded in the protocol and are halved every four years roughly. And transaction fees is the second way miners make money. Every transaction has a fees associated with it that goes to the miner who encloses this transaction in the block. Blocks have limited space so they can be propagated faster to all the peers in the network. The miner is incentiv ized to only include transactions which pay them the highest amount of fees. This means that transactions with zero fees can still get confirmed but transactions with higher fees will always be picked up first by a rational miner. Now let's talk about what a miner actually does. Mining, yes that's correct but there is more to it. Essentially they are solving mathematical puzzle. For example, if I ask you to find two prime numbers which multiply to get 15. Now finding these numbers is harder than verifying them. Since 15 is a small number, we can say that 3 and 5 but it's much simpler to multiply 3 and 5 to get 15 than to find two prime numbers which multiply to get 15. This is the difficulty in Bitcoin. The higher the prime number, the harder it is to find and therefore the difficulty is higher. This is how Bitcoin maintains a block time of 10 minutes. If the miners solve the puzzle too fast, the difficulty will get increased so the number will get higher. If the difficulty is too high, it will take longer time and if for consistent times it takes longer than 10 minutes, the difficulty will be reduced. So essentially stabilizing the time to be roughly 10 minutes. In Ethereum, this is currently around 15 seconds.

  • [03:19 - 03:22] We will talk more about this in the coming modules.

  • [00:00 - 01:05] Okay, so let's talk about what our mind is. So far we've talked about the consensus mechanism and a little bit about proof of work. Now let's see how everything fits together through mining. So in a distributed pay-to-pay network, everyone has the same privileges. So how do we ever confirm that the transaction is indeed now confirmed? For example, let's say Alice sends some currency like Bitcoin to Paul. How does Paul know that Alice hasn't also sent this to Charlie? This is known as a double spending problem. Since there isn't a central party like a bank to keep track of transactions and accounts, people can double spend what they have. And this is the problem that Bitcoin solved in a distributed way. The idea is very simple. Everyone is considered equal and they are special type of nodes which are known as miners. The job for miner is to create blocks and confirm transactions. Miner is incentivized to do this in mainly two ways.

    [01:06 - 03:18] Block rewards and transaction fees. Block rewards are the main way miners make money. In Bitcoin's case, this is hot-coded in the protocol and are halved every four years roughly. And transaction fees is the second way miners make money. Every transaction has a fees associated with it that goes to the miner who encloses this transaction in the block. Blocks have limited space so they can be propagated faster to all the peers in the network. The miner is incentiv ized to only include transactions which pay them the highest amount of fees. This means that transactions with zero fees can still get confirmed but transactions with higher fees will always be picked up first by a rational miner. Now let's talk about what a miner actually does. Mining, yes that's correct but there is more to it. Essentially they are solving mathematical puzzle. For example, if I ask you to find two prime numbers which multiply to get 15. Now finding these numbers is harder than verifying them. Since 15 is a small number, we can say that 3 and 5 but it's much simpler to multiply 3 and 5 to get 15 than to find two prime numbers which multiply to get 15. This is the difficulty in Bitcoin. The higher the prime number, the harder it is to find and therefore the difficulty is higher. This is how Bitcoin maintains a block time of 10 minutes. If the miners solve the puzzle too fast, the difficulty will get increased so the number will get higher. If the difficulty is too high, it will take longer time and if for consistent times it takes longer than 10 minutes, the difficulty will be reduced. So essentially stabilizing the time to be roughly 10 minutes. In Ethereum, this is currently around 15 seconds.

    [03:19 - 03:22] We will talk more about this in the coming modules.