No Geek Speak: Blockchain Transactions
11 min read
A blockchain is a decentralised, time-stamped, transparent, immutable ledger. Entries made to this ledger are permanent, transparent, and searchable, making it possible for anyone to view every entry made to the ledger, in its entirety. Each update to this ledger is a new "block" added to the end of the "chain". Each "block" is linked to other blocks since every new "block" contains information about the previous block in an attempt to maintain history and also to prevent that "block", in isolation, to be altered maliciously. This link between blocks makes a blockchain conceptually a linked-list. It is basically a series of blocks connected to one-another. But the thing is, the reason it is actually not a linked list is because:
-
While in a linked list, the pointer that maintains link between the current block and the next block is basically the address of the next block in the memory, it is not so in a blockchain. The link between the 2 blocks is a hash pointer that is comprised of the hash of the next block's header. This, along with a few other data points, is what makes it very difficult to tamper with.
-
Unlike a linked list, the blockchain is an append-only data structure i.e. blocks once added, cannot be removed from it.
Once a block (a bundle of verified transactions) is attached to the blockchain, they can effectively never be changed. This is because the chain is designed to be highly resistant to outages, manipulations and unnecessary complexity.
Instead of a centralised governing authority, a protocol (called a consensus mechanism) manages how new updates are initiated, validated, recorded, and distributed. Since a protocol is tasked with governance of updates, blockchain has ensured that cryptography has replaced third-party intermediaries as the keeper of trust.
A blockchain "transaction" is a transfer of information between two parties. The information could represent transactions, contracts, assets, identities, or practically anything else that can be described in digital form. It is considered successful when it has been signed, broadcast, and verified by block creators (either miners or validators), and added to a block in the blockchain.
Once the sender initiates the transaction, they are required to sign the transaction with their private key. This attaches a "validity" to the transaction, which lets the entire network know that this transaction was signed by the right sender.
"Signing", in the context of blockchain, is the process of using cryptographic techniques to authenticate a digital message or transaction. In layman terms, whenever a user initiates a transaction, they sign this transaction using their private key, and attach their digital signature to this transaction, whenever it is propagated across the network. The recipient will use the consequent public key to verify the user's digital signature confirm the identity of the user and verify the authenticity of the message to ensure no malicious transaction was issued by an assuming identity.
Every user that owns a digital wallet and transacts on the blockchain has a pair of keys: private and public. These keys are nothing but files. The private key is always stored within a user's wallet since it is highly confidential and hence, cannot be propagated freely.
That is not the case with public keys. A public key is derived from the private key, but it is impossible to derive the private key from the public key. And so, public keys are freely propagated across the network since they cannot be used to steal funds. Instead, they are used to check the "validity" of a signed transaction. A transaction signed with a certain private key can only be decrypted using that very pair's public key.
The transaction, once signed, is sent by the user's wallet, to a node in the blockchain. The node proceeds to send copies of the signed transaction to all the nodes it is linked with, and they send it to the ones they are linked with. This continues on until the transaction is propagated to every node in the network. Since a blockchain network is made up of a large number of nodes, propagation can sometimes take a bit of time. This is called as "Propagation Delay". The longer the delay, the slower the transaction gets processed and the slower the miners get their rewards. So, the incentive on the network is to minimise this propagation delay and ensure quicker timely transaction processing. Thereby, networks try to use efficient network protocols, optimise block propagation algorithms, and implement relay networks to reduce propagation delays. Once the transaction is broadcast to the entire network, it is verified against all the older blockchain transactions to avoid double spending.
"Double spend" is a situation wherein a single token (or a set of tokens) can be spent twice. When digital tokens are transferred from one wallet to another, the transaction needs to be verified. Before tokens are received by the receiver (kept waiting due to a time-consuming verification process), the sender can send the same tokens to another receiver, creating a second transaction. Eventually when the 2 transactions are verified and approved, the sender would have spent the same amount of tokens twice, thereby, defrauding the system. Blockchains take this very seriously and aim to mitigate this problem.
In most Proof-of-Work (PoW) blockchains, a "nonce" is used as a unique value to secure the network and to ensure that this problem of "double spend" does not occur. A "nonce" is a unique number that is generated by the sender's wallet which serves as a transaction counter for each account i.e. every time a new transaction is initiated by the wallet, this nonce is incremented, making this nonce sequence unique per wallet and independent of the blockchain network and other wallet addresses. If a sender were to try to double spend their funds, they would need to resend the same transaction with a different nonce. However, the miner would immediately reject the transaction because the nonce would not be unique. It is this nonce which is also used to maintain order and uniqueness of transactions from a specific sender address. When miners / validators are building a block, they sort the pending transactions in order of their nonce. This helps to prevent miners from reordering transactions to their advantage.
Once this is verified, it is put in the node's local memory pool (which is a temporary storage area where the pending transactions are placed), waiting to get validated.
As mentioned above, a blockchain relies on protocols, instead of a centralised governing entity, for how entries or updates are made to a system. Since a blockchain is designed to be decentralised with every node being an equal member of the network, it relies on "consensus" from the network to execute important actions - like validating a transaction, adding a new block to the chain, among other things. A "consensus mechanism" is a way to achieve distributed agreements in a blockchain system, about the ledger's state.
Blockchains utilise different kinds of consensus mechanisms to validate a transaction. Proof of Work (PoW), heavily popularised the Bitcoin blockchain, is a mechanism in which "miners" compete to solve computationally complex mathemtical puzzles wherein the first miner to complete the puzzle is rewarded with new coins and the opportunity to add a new block of transactions to the chain. Despite its popularity, ease of implementation and very high security, there are efforts being undertaken towards new consensus mechanisms since it is very energy-hungry, has high transaction fees and slower transaction speeds. Proof of Stake (PoS), hevaily popularised by the Ethereum blockchain, is a mechanism in which "validators" lock up or stake their own coins to earn rewards for validating transactions and producing new blocks. The higher the amount of coins staked, the higher the chances of the validator validating a transaction, and thereby increasing their chances of getting a reward. These consensus mechanisms ensure that a valid transaction cannot be maliciously altered or removed.
Carrying out this validation activity incurs a transaction fee since the miners had to spend money, time and / or energy to validate the signed transaction.
Whenever a user initiates a transaction for it to get accepted to the chain, they pay a fee. This fee is called "transaction fee". The fee incentivizes miners or validators to process and validate transactions and include them in blocks. The fee determines how prioritized a transaction is, with higher fees generally resulting in faster processing. Network congestion can also affect transaction fees, with higher fees required to ensure that transactions are processed quickly during congested periods.
Once this validation is complete, it is bundled with other transactions into a single block and attached to the blockchain. Adding a transaction to a block means that this validated transaction is now a permanent record, and has become a part of the public ledger. Once it becomes a part of the ledger, alteration or removal is impossible without consensus from the entire network.
Even though the transaction becomes a part of the ledger, it is still important to wait for multiple confirmation messages before considering it to be final. This is because there are a few rare cases where a transaction may be rejected after it has been included in a block. For example, this can happen if there is a fork in the blockchain or if the transaction fails to meet certain criteria. The more confirmations a transaction has, the less likely it is to be reversed.
There are multiple reasons why a transaction can be rejected: network congestion, insufficient gas fees, etc. But the thing is, if the intended transaction only has a few confirmations and a reorganisation happens, the transaction may end up on an orphaned branch that gets discarded, leading to an unsuccessful transaction. Now why may a reorganisation happen? Since a blockchain is a decentralised network, with multiple miners / validators aiming to mine new blocks to earn rewards, there can be a scenario where two different miners find a valid block at the same time. This happens because the blockchain is usually a massive netwirk, and propagation of information across the network, to all the nodes, take a bit of time, and in this time, it is possible for multiple miners to find a valid block without ever knowing about the other valid blocks. This leads to the network temporarily having competing chains. But the thing is that a blockchain is a single chain, and so, the incentive is now to get rid of competing chains. So the nodes then add blocks on the chain they received first. And once a chain has more blocks than the other chain, the shorter chain will be discarded and the blocks on that chain will become orphaned. All this makes multiple confirmations an important part of the blockchain system to ensure to a user that their transaction has been successfully accepted.
A "confirmation" refers to the blocks added to the blockchain after the intended transaction has been accepted and added to the network. The Bitcoin blockchain specifies that 6 confirmation messages (or 6 blocks being added on top of the block with the intended transaction) is enough to determine that the transaction has been successfully accepted by the network. On the other hand, the Ethereum blockchain does not have a defined consensus on how many confirmations is needed to consider a transaction successful. Since confirmations act like layers of protection that ensure the transactions are secure, the higher the number of confirmations, the greater the security of the transactions in the blockchain.
To recap, the sender initiates the transaction, signs it, and then this transaction gets broadcasted from the sender's wallet to every node in the network. Once accepted by the miners as a verified broadcast, they work to validate the transaction and group it into a block of transactions. Once the block is ready, it is attached to the chain, making the transaction a permanent, immutable public record. And so, from initiation to attachment into the chain, this is the lifecycle of a blockchain transaction.