What is Mining? The Blockchain

A brief explanation of Bitcoin's mining process

niftynei’s shitcoin chronicles is a paid Substack. This post is one of very few free posts. If you’re not already a paying subscriber, you’re missing out.

So far we’ve talked about my hunt for bitcoin miners, what to look for for a bitcoin miner, and some updates on my not-so-hot Chia mining attempts.

We haven’t really discussed what mining is though, or how it works.

Understanding bitcoin is a good starting place for branching out to explore the rest of the blockchain-based crypto economy, given that most chains borrowed a lot of ideas from how it works.

Let’s start with “what is a blockchain?”, specifically “what is the bitcoin blockchain?”

What is the bitcoin blockchain?

One good analogy for understanding how the bitcoin blockchain works is by comparing it to a filing cabinet.

In a lot of ways, a blockchain is exactly like a filing cabinet filled with folders. Each of those folders is filled with sheets of paper.

When you want to make a transaction that will live on the blockchain, you write the transaction down on a piece of paper. I

n order for this transaction on a piece of paper to be considered “valid”, you need to get it into a folder.

That folder then gets added to the great stack of other folders full of transactions.

Together this stack of folders live in the filing cabinet. This is the blockchain.

Ordering Folders

The folders in the filing cabinet have a very specific order that they have to be sorted in. Every time a new folder is added, it’s basically put at the top of the stack.

Each folder has a unique id. Each folder contains the id of the folder that came immediately before it.

You can’t calculate the unique id of any folder without knowing the id of the folder that came before it. In this way, the order can’t ever be changed or moved around. If you do, you’d know because the calculation to figure out the folder’s id wouldn’t work.

Getting a Transaction into a Folder

Ok so there are folders and there are papers. The papers are go in the folders, the folders get added to the great big stack of folders in the filing cabinet.

But where do new folders come from? Who decides what papers to put in each of the folders?

The answer is miners.

Miners are the ones who pick out which transactions papers will go into the next folder that’s created. They’re kind of like a big librarian workforce at the filing farm.

People who want to get their transaction confirmed, or included in a folder, put the paper into a little vacuum tube. The vacuum tubes all dump out into a big pile at the base of the librarian’s work space.

The librarians pick through all of the unconfirmed transactions. (An ‘unconfirmed’ transaction is one that hasn’t been included in a folder yet.)

The folders have a size limit — only so many pieces of paper can fit in a folder. The papers also pay a small bribe to the librarian that puts them into a folder.

So most librarians pick through the big pile of transaction papers and find the ones that are the smallest and also pay the best bribes. These are the ones that they put into a folder.

Finding the Folder’s Identifier

Once the librarian has a folder put together that they like, they start running the folder through a … well, a trash compactor.

That trash compactor outputs a unique identifier that goes on the folder.

The identifiers are all numbers. Really really big numbers. If you slightly change what the folder looks like, and run it through the trash compactor again, you’ll get a different number out of the trash compactor.

So let’s say you run a green folder full of transactions through the trash compactor. It says the number of that green folder is 101823182091823.

Then you take a red folder full of the same transactions and run it through the trash compactor again. It says the number of that red folder is 29383812918313847401.

You can do this infinitely. As long as you put a slightly different input into the trash compactor, it’ll spit out a completely different number. There’s no way to predict what the trash compactor will spit out until you put something through it.

Adding a Folder to the Filing Cabinet

Ok so you’ve got a bunch of different versions of the same folder. You’re running them through the trash compactor.

Purple folder, 1038472918374.

Magenta folder, 38472829379928129811.

You’re trying to be the first librarian who finds a folder with an id less than 500000000.

No luck yet. In fact you’re pretty far away so far.

Gold folder, 299999888.

Poppy folder, 103847577388218.

Wait a second. That gold folder. 299999888 is less than 500000000.

You’ve done it. You’ve found the next folder. There’s another special set of tubes that you send “found” folders out on. So you send this shiny gold folder, with all of the papers inside of it, out to all the other librarians and people on the network.

When a librarian gets it, they run it through the trash compactor themselves, and verify that the number that comes out is in fact less than 500000000.

Since it passes the filter, they add it to their filing cabinet with all the other folders.

On average, a folder with a “valid” identifier is found every 10 minutes.

Updating the Search for the Next Folder

Then, every single librarian looks through the papers inside the gold folder and removes them from the big pile of transactions that were waiting to get filed.

This is called “removing mined transactions from the mempool”.

Then they change the folder they’re using to run through the trash compactor. The ‘folder’ has the id of the last ‘mined’ folder on it. So they update it to the gold folder’s identifier, 299999888.

Then, using the remaining pile of unmined transactions plus any new ones that have arrived since the gold folder got created, the librarians go back to running folders through the trash compactor, looking for the next winning folder.

This is mining.

Getting Paid

Miners earn the bribes that are paid on each transaction that’s included in a folder (also known as a block). They add up all the bribes and write down the total on a special piece of paper that they add to the folder before they run it through the trash compactor. This special, “miner addition” transaction is called the coinbase.

The coinbase includes both the librarian bribes plus a special bonus amount. The bonus amount is called the “block reward”. It’s handed out as a special incentive to librarians for doing the work of putting all the different folder colors and combinations through the trash compactor.

For bitcoin, the value of the block reward changes every 210,000 folders. It gets cut in half from whatever the previous value was.

Figuring out the block reward

Let’s figure out what the current bitcoin block reward is.

According to blockstream.info[1], the current block is 681,051[2].

This is block (‘folder’) 681,051. The identifier for it is the big hex you see here. We can convert the hex to a decimal number or 1136095161817572004901029042821299460327790747940723402. This is the “folder identifier” value. The 0’s at the front are a measure of how small it is.

681,051 ÷ 210,000 is 3.24.

The block reward for bitcoin has been cut in half three times.

When bitcoin first started, the block reward was 50 bitcoin. That means that every new folder that was added to the filing cabinet would pay out 50 new bitcoin in the coinbase transaction, to the librarian that found the folder with a valid identifier.

We’ve had 3 ‘halvings’ since then. So the block reward has been cut in half three times.

50 ÷ 2 is 25. That’s one halving.

25 ÷ 2 is 12.5. That’s two halvings.

12.5 ÷ 2 is 6.25. That’s three halvings.

Currently each bitcoin block pays out 6.25 bitcoins to the person who creates the coinbase transaction.

[1] This is a bitcoin ‘block explorer’. It lets you wander through the folders and all the papers in the filing cabinet that is the bitcoin ‘blockchain’.

In Exitus

That's pretty much all of it. You now have a pretty good understanding of how bitcoin mining works.

Footnote about the 500000000 number

I left off the part about where the “500000000” number is determined. It’s updated every 2016 blocks, or about every two weeks. (2016 blocks every 10 minutes is 20160 minutes, or 336 hours, or 14 days.)

Another name for this number is the “difficulty”[1]. If the last 2016 blocks were created faster than 10 minutes, on average, the number gets adjusted down. This means more trash compactor attempts will be required to find a valid folder.

If the last 2016 blocks were created, on average, slower than every 10 minutes, then the number gets adjusted upwards.

This is done to ensure that new folders are found every ten minutes, no matter how many librarians are hunting for new blocks, or how many trash compactors they’re running.

If you want to know more about ‘difficulty adjustments’, you should check out this article on the bitcoin wiki.

[1] Also referred to as the target.

This was a great post. You should share it with a friend.