Data layer

Blockchain is a decentralized, massively replicated database (distributed ledger), where transactions are arranged in blocks, and placed in a P2P network. The current state of all accounts is stored in such a database. A network (public or private) is comprised of many nodes and without a common consensus, data cannot be altered. The data structure of a blockchain can be represented as a linked-list of blocks, where transactions are ordered. The blockchain's data structure includes two primary components—pointers and a linked list. The pointers are the variables, which refer to the location of another variable, and linked list is a list of chained blocks, where each block has data and pointers to the previous block. A Merkle tree is a binary tree of hashes. Each block contains a hash of the Merkle root with information such as the hash of the previous block, timestamp, nonce, the block version number, and the current difficulty target. A Merkle tree offers security, integrity, and irrefutability for the blockchain technology. Merkle trees, along with cryptography and consensus algorithms, are the basis of the blockchain technology. For example, Ethereum blockchain uses a Patricia tree database to store information. Patricia tree (Trie) is a Merkle tree, which is like a key-value store. Just like Merkle tree, a Patricia tree has a root hash. This root hash can be used to refer to the entire tree. Hence, you cannot modify the content of the tree without modifying the root hash. Each block contains a list of transactions that happened since the last block, and after applying those transactions, the root hash of the Patricia tree represents the new state (state tree).

The genesis block (the first block) does not contain the pointer, as it's the first in the chain. The following diagram shows the connected list of blocks in a blockchain:

Blockchain structure

Depending on the type of blockchain, data is stored in blocks. For example, Hyperledger Fabric's blocks will include channel information, while a Bitcoin blockchain will have data about the sender, receiver, and the amount. We've used the term hash a few times already. A hash is a unique digest of the data. A cryptographic hash algorithm (such as the SHA 256 algorithm) can generate a fixed length hash value of the data. These hashes help in identifying blocks easily and also help to detect any changes that are made to the blocks. Each block has a hash of the previous block; hence, blockchain is essentially a chain of hashes. Any new node connected to the blockchain will receive a copy of the blockchain network. Only upon consensus are blocks added to the local blockchain.

Transactions are digitally signed on the blockchain to ensure the security and integrity of the data stored on it. They secure information about the block, transactions, transacting parties, and so via a digital signature, which uses asymmetric cryptography. Transactions are signed using a private key, and anyone in possession of the public key can verify the signer. The digital signature checks for tampering. Digital signatures guarantee integrity as the data that is encrypted is also signed. Hence, any tampering will invalidate the signature. As the data is already encrypted, it cannot be detected. Even if it is detected, it cannot be tampered with. A digital signature secures the sender's (owner) identity as well. Private keys are linked to owners (users); hence, signatures are legally associated with the owner and cannot be repudiated. In this section, we talked about transactions in detail. We will walk through the transaction flow for Ethereum-based blockchain platforms in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset