Hands-On Cybersecurity with Blockchain
上QQ阅读APP看书,第一时间看更新

Block

A distributed ledger is stored in a database and updated by each participant in the blockchain network. A ledger is represented in a series of units called blocks. To understand the block, lets start with the underlying traditional data model and then jump to the blockchain network to understand how the block is chained together.

Let's first understand the regular means of information exchange over the internet. In the world of the TCP/IP stack, information is transferred through a client/server model where the client can store and modify the data on a centralized server. However, the control of the database remains with a designated administrator. If the security of the administrator is compromised, the entire database can be altered or deleted. Theoretically, a server is no different from a user machine; however, in practice, the purpose of a server is to serve several end users concurrently. Take a look at the following diagram:

The blockchain network consists of a network of several independent machines named nodes. Unlike traditional databases that store entire information on a centralized database server, Blockchain nodes keep the copy of the entire database with an administrative role. Even if one node goes down, the information will remain available for the other nodes, as shown in the following diagram:

The moment a node joins the blockchain network, it downloads the updated blockchain ledger. Each node is responsible for managing and updating its ledger with validated blocks. The node maintains the ledger and organizes it in the form of blocks connected to the hashing algorithm, as shown in the following diagram:

Multiple transactions are bundled together to form a block, and in its simplest form, it's a data structure. Every cryptocurrency has its own blockchain with its own customized properties. For example, a block in a Bitcoin blockchain is generated every 10 minutes and the size of each block is 1 MB, whereas a block in an Ethereum blockchain is generated every 12-14 seconds, and the size of each block is 2 KB. Take a look at the following diagram:

Let's understand more about blocks. A block consists of a block header and a block body:

  • Block header: A block header helps us identify a specific block in the blockchain. It contains a set of metadata:

The components of the block are explained as follows:

    • Version: It's a 4-byte field that's used to track software or protocol grades.
    • Timestamp: This is a 4-byte field that indicates the creation time of the block in seconds.
    • Hash of the previous block: This is a 32-byte field that indicates the hash of the previous block in the chain.
    • Nonce: This is a 4-byte field that's used to track the PoW algorithm counter.
    • Hash of Merkle root: This is a 32-byte field that is a hash of the root of the Merkle tree of the block transaction.
    • Block body: This part of the block consists of a list of transactions. In the Bitcoin world, one block consists of more than 500 transactions on average. Each transaction has to be digitally signed; otherwise, it is treated as invalid. To do that, a hashing function is used to apply the algorithm over an actual transaction with a private key/secret key.