I'm trying to get a better grip on Bitcoin, but there's this thing that's got me confused, and honestly, I don’t even know how to ask about it (so please, no harsh feedback!).
How exactly are these "blocks" put together? In my mining pool, I can see blocks being formed from transactions. I know my miner is basically trying to solve problems, and when a block gets completed, the nodes all receive this new block along with its transactions. But what's the process for fitting those transactions into a block?
I've heard that if all the electricity disappeared, you just need one person to fire up a node, and Bitcoin would be up and running again (and I guess you'd need at least one miner to start hashing too). So if all it takes is a node and a miner, I feel like I'm missing some steps in between.
What’s the piece I'm overlooking? Because the info I have doesn't really connect the dots for me.
Like the other day, I combined around 30 UTXOs, and I noticed that on Mempool it showed up as a consolidation. So where does that fit into the Bitcoin system? Is it the miners, the nodes, or some other part I haven't come across yet?
Miners (or mining pools) build a candidate block and then they solve the proof of work problem which is actually finding a number.
To build the candidate block, miners are free to include any valid transaction. Since the block size is limited, miners usually prioritize transactions based on their fee rate to maximize their profit.
Once you broadcast a transaction, it's sent to some nodes. Those nodes validate your transaction and if it's valid they put your transaction in their mempool and then send it to some other nodes.
After a few seconds, almost all nodes should have your transaction in their mempool. Mempool is like a waiting room for unconfirmed transactions and each node can have its own mempool.
Miners (or a mining pool) pick some transactions from their mempool, build a candidate block and then try to solve the proof of work problem. Once a miner (or a mining pool) mines a block, all the tranactions that were picked by the miner go to the blockchain and become confirmed.
So if there were a single miner and node, then all candidate transactions would be stored in that nodes memory pool until the miner figured out the correct hash and then the block containing those transactions would be formed and added to the blockchain, obviously with just a single node and miner the difficulty level would have to brought right down to fit the 10 minute time slot.
Thanks guys!
Correct.
If miners shut down their devices now and there's only one miner, the network hash rate will decrease significantly and to maintan the average block time of 10 minutes, the difficulty should decrease. But there will be two problems here.
1. The difficulty is adjusted every 2016 blocks and it may take years until difficulty is adjusted.
2. Every time difficulty is adjusted, it can't be decreased by more than 75%.
Take note that I am talking about the theory and in practice the above scenario is very unlikely to happen.
Now that`s interesting, I never knew that!
I know I read somewhere that the dificulty is adjusted every 2 weeks, but that`s probably only true for the current hashrate.
The difficulty is adjusted every 2016 blocks. Since a new block is mined every ∼ 10 minutes on average, it's estimated that the difficulty is adjusted every 2 weeks.
If blocks are mined less than 10 minutes on average, the difficulty would be adjusted before 2 weeks and if they are mined more than 10 minutes on average, the difficulty would be adjusted after 2 weeks.
A lot to learn you have, young padawan.
As hosseinimr93 states, difficulty adjustment is done after 2016 blocks have been mined in a difficulty period. This 2016 period length was likely chosen to have a difficulty adjustment in about every two weeks. Significantly shorter or longer adjustment periods have serious disadvantages and likely two weeks is a good compromise.
Then there's another rule in the node's code which hosseinimr93 mentioned, that difficulty adjustment can't exceed a change more than 4x or less than 1/4 of current difficulty. The reason is to prevent some sort of attack, but I forgot the details.