Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Foundations of Blockchain

You're reading from  Foundations of Blockchain

Product type Book
Published in Jan 2019
Publisher Packt
ISBN-13 9781789139396
Pages 372 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Koshik Raj Koshik Raj
Profile icon Koshik Raj
Toc

Table of Contents (14) Chapters close

Preface 1. Introduction 2. A Bit of Cryptography 3. Cryptography in Blockchain 4. Networking in Blockchain 5. Cryptocurrency 6. Diving into Blockchain - Proof of Existence 7. Diving into Blockchain - Proof of Ownership 8. Blockchain Projects 9. Blockchain Optimizations and Enhancements 10. Blockchain Security 11. When Shouldn't We Use Blockchain? 12. Blockchain Use Cases 13. Other Books You May Enjoy

Overview of blocks

Now that we have a fair understanding of blockchain, we're going to give an overview of blocks, which are responsible for building a blockchain.

Block attributes

If we consider a blockchain as a data structure, then the blocks are aggregated sets of data that are used for formation of the blockchain. Blockchain formation is similar to linked list formation, where each node has a reference to the next node in the sequence. In the case of blockchain, each block has a reference to the previous node, thus forming a link all the way to the initial block (known as the genesis block) of the chain. As we mentioned earlier, a blockchain can be stored in either flat file or database format. Bitcoin uses LevelDB to store metadata about all the blocks that are downloaded to the disk.

Just like a linked list node, each block has a pointer, which is the identifier of the block. These are just hashed values of the block's header data. More detail about hashing will be covered in Chapter 2, A Bit of Cryptography. We can consider the hash as a unique identifier of a fixed size that represents each block; no two blocks will have the same identifier. Since all the blocks are linked together by this hash value, each block will have the identifier of the previous block. The previous block is referred to as the parent block, and each block can have only one parent.

Each block could also be referenced by the height of the blockchain. This height is nothing but the distance of the block, or the block count, from the genesis block. Height is an important attribute of the blockchain, as it's easier to refer to a block with a plain number rather than a lengthy hash value. The block hash is not a hash value of the entire block, but rather the hash value of the block header, which consists only of metadata. In Bitcoin, a SHA256 hashing algorithm is used to hash the block header and to create a unique identifier for the block.

Structure of the block

Although all blockchains consist of linking blocks together to form an immutable ledger, different block structures can be adopted depending on the application. Permissioned and permissionless blockchains, for instance, have slight variations in their block structure. We'

We'll be using Bitcoin's permissionless block structure as a reference to try and identify its characteristics:

Figure 1.3: Structure of a block

A block consists of the components mentioned in Figure 1.3. Block Header and Transactions are the most important parts of the block, as they are responsible for the hash value, which is the identity of the block. The Block Size is the size of the entire block. The Block Header contains all the metadata of the block, and the Transaction Counter has the count of transactions. Finally, all the Transactions are stored in the block.

As mentioned before, a blockchain starts with an initial block called the genesis block. If the chain is traversed backward from any given block, it will end up at the genesis block, proving that the entire chain is legitimate and valid. The genesis block is often statically coded in a public or permissionless blockchain, but it's created by the first participant in the case of the permissioned blockchain.

Block header

The block header, as stated before, consists of the metadata of the block. This holds the information that's needed to link the blocks in the blockchain:

Figure 1.4: Structure of a block header

Each block header will have the components outlined in Figure 1.4. These are the minimum fields required in a permissionless blockchain, such as Bitcoin, to efficiently create a block that can be appended to an immutable blockchain. The Previous Block Hash field is a reference to the last block created. The Merkle Root is the value of the Merkle hash tree; it summarizes all the transactions in the block. Timestamp, Difficulty Target, and Nonce are used by the PoW consensus algorithm to solve the hash puzzle. We'll be revisiting these concepts in more depth throughout the book.

Note: Unlike in a permissionless blockchain, where consensus algorithms are used to generate blocks, permissioned blockchains use the signature of the block creator to represent the block identity. However, blocks in permissioned blockchains maintain previous block identifiers, just as permissionless blockchains do.

Linking blocks

As we know, blocks are linked in a blockchain using references, just like in a linked list, but here the blocks are linked by referencing the hash value (identifier) of the previous block. Each full node in a blockchain network will maintain a complete blockchain and append a new block whenever it has one to append. Due to the decentralized nature of the blockchain, each node will verify the block before linking it to the local blockchain record.

The computed hash value of each block is the combination of the hash of the previous block and its own block data. This results in a dependency between neighboring blocks and nearly unbreakable links:

Figure 1.5: Linking blocks using hashes, from Bitcoin: A Peer-to-Peer Electronic Cash System, S. Nakamoto

Satoshi explained how the concept of timestamping should be used. All the items are hashed and the block is timestamped, meaning that the subsequent block will include this timestamp, creating an ordered chain of blocks.

Each node in the blockchain network follows a simple process for appending new blocks to its existing local blockchain. Whenever a node receives a block from the network, it checks for the previous block hash. If the hash value matches with the hash value of the last block on the node's local blockchain, then the node accepts this block and appends it to the current blockchain. As long as this is the longest known blockchain, the blocks would be considered valid by all the peers in the network in a PoW-based blockchain.

You have been reading a chapter from
Foundations of Blockchain
Published in: Jan 2019 Publisher: Packt ISBN-13: 9781789139396
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime