Transactions on Blockchains
Article Summary :- In this article we will try to understand various layers involved in Blockchains & how each layer plays a pivotal role in making transactions possible. if you are new to the space, consider starting here first to understand how the ledger looks.
Layers in Blockchain Transactions
The transactions require delving into various pieces around the architecture beyond the DB itself. To start with , you can imagine any blockchain to have 3 broad abstract layers,
The 3 layers can be summarised as :-
Network Layer:- How the peer to peer nodes on the blockchain interact with each other for sharing ledger & other relevant data.
Consensus Layer:- The methods & the rules which ensure all the nodes are in alignment with respect to “correct version” of the blockchain.
Incentives layer:- It captures how are rewards calculated & distributed among relevant participants.
We will attempt to define functions & attributes of each layers.
Terminology Revision
Before we proceed further, a quick refresher on few major terminologies we became family with in the article here :-
Blockchain :- It is a public database distributed across nodes on computers spread across the world. ”Block” in blockchain indicates that data is stored in batches or blocks & the blocks are “chained” together cryptographically.
Participating Nodes :- Each participant on the network which downloads the ledger & interacts with the network is called Node.
Accountant Nodes/Miners :- A subset of participating nodes can become miners to have the privilege of updating the blockchain & receiving rewards.
Native cryptocurrency :- Each blockchain will have its own native currency - Ether in ethereum & bitcoin on Bitcoin blockchain. Bitcoin & Ethereum are the blockchains .Whereas bitcoin & ether are the native currencies.
Layer - 1: Network Layer
The network layer hosts the node i.e. the individual user who has downloaded the ledger copy & is part of blockchain network. The node itself can be imagined as an object with variables such as local ledger copy, balance, NodeID & broadcast protocol. The “broadcast protocol” is how this node receives new instructions or sends across transactions requests. Since the nodes in the network can be geographically distributed & various other parameters such as network speed might delay updating of information , the broadcast protocol can be implemented in variety of ways to account for required impact. Hence in summary, you can imagine network layer as shown below :-
Signatures
It is crucial to ensure identity while initiating transaction request to the network i.e. if a node, say Node A, is broadcasting to the network a transaction request for transfer to 50 ether to Node B, then 2 checks must be done ,
The transaction request indeed originated from Node - A & not some other node say D.
Node - A has requisite minimum balance of 50 ether for the payment to become successful.
The first check is enforced with private keys & signature . For our example, we will use the below random key pair & Address combination. For more on Key-Pairs- go through the article on Wallets here.
Essentially, Node-A while sending out the transaction instruction to the network, signs the transaction with its private keys. This produces the signature.
In the above example, i am using a random “private key” & the message is “Hello There”. In actual transaction, it will contain transaction relevant data.
During propagation to other nodes on the network, the “Signature” is propagated. If you combine the message “Hello There” & the signature, the address corresponding to the Private key used above will be generated as output.
Since, Node-A public key & address will be know to all participating nodes , the verification can be completed. In reality, the blockchain itself will perform these checks & any manual step verification, as shown above, is not required.
Layer - 2: Consensus Layer
This layer defines the rules so that each nodes on the blockchain network can communicate with each other & agree on the state of the final Blockchain ledger - without the need to know each other or relay on a central intermediary for trust. The major attributes of this layer can be imagined as :-
Transactions :- Each unique transactions initiated on the network from any of the nodes involved.
Transactions Pool :- Each of the “yet to be committed to ledger” transactions received are added to a transaction pool.
Blocks :- From the transaction pool, few of the transactions are combined in a block that is to be added to the ledger. How the transactions is selected form the tool for adding it into Block can depend on many factors. However, generally miners attempt to maximise their profit & hence transactions that yield highest fees are prioritised into blocks.
Updated Ledger :- The blocks are added to previous blockchain ledger to update it & propagated across the network to other nodes.
Imagine it for simplicity as :-
Transactions you can view as a simple request of transfer to funds from Node-A to Node-B. However, once you add smart contract & other complexities, transactions definition become more complex.
Transaction will have various attributes such as - transaction ID, timestamp, transaction content and transaction fee. These are mere sample attributes & based on the specific blockchain implementation, the attributes might differ.
Once a transaction is created by the initiating node, it is propagated to all the nodes on the network so that it is added to the “transaction pool” for the Miners to select.
Blocks in “Blockchain” are essential element which result in updating the ledger copy.Blocks are made-up of transactions selected from “transaction pool”.
Once verified & added to the blockchain ledger, the transaction -part of the latest block- are removed from transactions pool. The selection of transactions that form blocks are done by miners. The blocks will have attributes such as - blockid, transaction count, previous blockid , timestamp & minerid.
The various consensus algorithms such as proof of work( solving random puzzles using hardware) or proof of stake( miners have to stake their assets for mining privilege) decide how a miner might be able to update blocks. In proof of stake, for example, the miner is selected randomly. Whereas in Proof of work , miners compete amongst themselves for updating the block.
Once the miner has propagated the block to other nodes, the other nodes need to verify the validity of block. Subsequently, the block will be added to the local blockchain ledger & transactions committed as part of the newest block will be removed from local transactions pool.
The above steps are extremely simplified version of how actual transactions work. For example, sometimes due to network delay, few of the networks might be out of sync with the rest of the network. This might lead to temporary fork. Each of the networks define rules to resolve such issues & for nodes to identify the correct ledger. Bitcoin & Ethereum for example uses longest chain as resolving parameter.
Layer 3 - Incentive Layer
Incentive layer is how few of the nodes in the network are incentivised to become Miners( In proof of work) or Validators ( In Proof of Stake). There are 2 parts to incentivising nodes :-
Transaction fee:- Whenever a transaction initiated, it costs transaction fee( e.g. called gas fee in Ethereum). This amount is paid by the Transaction initiator.
Block Rewards :- Every time a new block is added to the ledger, a certain amount of new native coins are generated & shared with the miner/validator.
Both the transaction fee & block rewards are calculated in the native cryptocurrency of the blockchain- e.g. ether on ethereum.