Breaking News

How does Bitcoin work? – Prime Number EP2

hello everyone welcome to prime number today I'd like to talk about how Bitcoin works in high level using a use case Alice wants to send coins to Bob and Bob wants to send some coins to Charlie let's take a look here we have a bunch of nodes represent the Bitcoin network in reality the Bitcoin network could be fairly large from tens of thousands of nodes to millions of nodes this is just to show how it works each individual nodes is not connecting to everybody it only connects to several we call neighbors for example we have here node #1 connects to node #2 and #3

#2 connects to #4 and #5 #3 connects to #5 and #6 #4 connects to #6 and now we have someone called Alice again she has a mobile phone with a wallet app installed in it she wants to send bitcoins to Bob so she can just send the transaction to any of the nodes in the Bitcoin network the transaction has to be signed by her private key in her cell phone saying she sent the transaction to node #1 and each node received a transaction while using we called the gossip protocol or flooding the transaction to the whole Bitcoin network in doing from sending the transaction to its neighbors the node #1 will send the transaction to node #2 as well as node #3 node #2 will relay to node #4 and #5 and #4 will relay to node #6 to prevent the endless loop the node will not relay if it already seen this transaction so remember each transaction has a hash value can just compare the hash value whether it's already in the pool or not so by doing that all the Bitcoin network will have the same transaction but it doesn't mean the transaction is in the blockchain it just received the transaction and let's make it more complicated someone Bob is using his computer to send money to to send coins to Charlie and he's doing this by sending to another node node #5 so #5 will have this transaction and it will relay to node #2 and node #3 and node #2 will relay to node #1 and node #4 and the node #3 will relay to node #6 not all the nodes have to have the same outstanding transactions it could be not synced at all

for example node #1 may have some other transactions C sends coins to D node #4 may have transaction D sends coins to E but it doesn't matter it's just all the transactions all the nodes received from all the different geography places and at the same time all the node is producing blocks by picking up the transactions it wants to put into a block the block has a limit on the block size so it has to be only several transactions can be put into a single block let's say node #1 wants to put those two transactions into the block in node #4 wants to put those two transactions in the block and to produce the block In Bitcoin it has a mechanism called proof-of-work you have to guess an nonce that having that nonce in the block you can calculate a hash value of this block by having a certain number of leading zeroes the number of zeros is adjustable based on how how complicated how difficult we want to have so let's say at this time node #1 successfully guessed the nonce and produced the block once it produced a block it's using the same protocol the gossip protocol to broadcasting yay I'm successfully produced a block please relay this block and append to your block chain so he will append the block to his own block in his node and broadcasting to node #2 and #3

the node #2 will do the same thing it will validate the block validate the transaction validate the nonce whether the hash value is the same as the hash value it declared so if everything validates successfully the node will append the block into a blockchain so by doing that all the nodes will have the same block appended to the blockchain so this is called the consensus the consensus means even though each individual node may have different transactions in the pool and it may come up with its own blocks but we have to agree on what blocks we want to append to the blockchain there are chances two nodes may come up with the both are valid blocks at almost the same time but Bitcoin always recognized the longest one so there could be a soft fork and but that could be resolved by the following blocks append to the previous one to make sure each node only respect the longest blockchain we've covered several concepts in Bitcoin such as block transaction consensus algorithm and p2p network but in a fairly high level I will dive into each individual topics in the following videos thanks for watching comments below what you want to see in my channel and subscribe if you liked it thank you