Purpose
This article describes blocks in a blockchain and how they function.
Assumptions Made
This article assumes the reader understands the information in the following articles:
Summary
A Blockchain is a collection of blocks chained together in a series. In most Blockchains, each block contains data about transactions, hashes, and a nonce. For now, hashes may be thought of as a long number representing the data held in a block, and a nonce as a shorter number used to maintain order in the blockchain and prevent duplicate blocks similar to a queue. Both hashes and nonces are explained in much more detail in the articles Hashes and Nonces.
Blocks use nonces to maintain the correct sequence of events as they come into the blockchain. This ensures there are no duplicate blocks as each nonce will be unique. Additionally, the hash is calculated like a summary of the block’s information, including the previous block’s hash (shown in the illustration below). Using this system, blocks are chained together, and the “next” hash of the previous block must be the same as the “previous” hash of the next block.
By following this ruleset, the blockchain stores information in an immutable manner since any change done to a previous block would alter the “next” hash of the next block and every block proceeding it.
How blockchain processes transactions is similar to a group of people sitting in a room with notepads ready to do some math. Since this is the first page, they have already labeled it “Page 1” just like a nonce would describe what block we are currently on. The announcer comes in and states everyone needs to write “+5” to their notepad. Everyone writes “+5” then waits for the next number. This process continues until everyone has filled their first page similar to how transactions fill up a block. Once the page is complete, the total is calculated and written on the bottom of the page like a hash being determined for a block. After this is done, everyone flips to the top of the next page and writes the next page as “Page 2” followed by the total at the bottom of the previous page, symbolic of starting a new block with 1 higher nonce and the “previous” hash being the same as the previous block’s “next” hash. If at any time someone were to decide they want to write in a different number or total, it would immediately be recognized as the outlier in the room and rejected, maintaining the integrity of the chain.