Episode 20 - Double Spend
In the case of fiat currency, when you spend it, you physically hand over the currency note to the other party. Also, in case of a bank transfer of fiat currency, the update of balances in sender and receiver accounts is done by a centralized server having full control of the transaction and the accounts. In both scenarios, in fiat currency, it is made sure that what is spent is actually spent.
But in the case of a decentralized system with digital currency, there could be scenarios that the already spent currency could be spent again. This is called the problem of double-spending.
Before we go further into double-spending, it would be good to get a refresher on transactions, blocks, finality, and consensus.
Let’s take an example — if you have a balance of 10 coins on a blockchain. Now you send these 10 coins to a user in a transaction. Then you send the same 10 coins to another user in another transaction. You send both these transactions to two different nodes in the blockchain network. What you have tried to do here is a double spend because you tried to spend the same coins twice.
In a normal situation, one of these transactions will be marked invalid as soon as another one is already included in a block. However, in a rare situation, a network delay could cause a temporary fork on the chain and both of these transactions could be included in different blocks at the same height. In such a scenario, the blockchain could take some time to recover from the fork. Once the canon chain is decided using the consensus and finality rules, one of the blocks would be considered final while the other one invalid. In the interim, both transactions would be considered valid by different nodes and that could cause confusion between the receivers.
When transacting on a blockchain, you must wait for the block, having your transaction, to be finalized before you buy/sell any goods/services based on that transaction.