A Blockchain Primer › Module 2 › Lesson 2.5
Lesson 2.5: Packing Transactions into Blocks — The Chain Structure and Change Detection
- #1. The Core Question
- #2. An Everyday Analogy
- #3. Core Concepts Explained
- #4. Diagrams
- #5. Key Takeaways
- #6. Quiz
The last lesson showed how a single transaction gets signed and authorized. But the ledger doesn't keep just one transaction. It keeps the entire history. This lesson looks at how the blockchain data structure packs huge numbers of transactions in order and makes any change easy to expose.
1. The Core Question
If every transaction were stored on its own, how would you know what order they came in? If someone deleted an old transaction or changed a record from the past, how would anyone notice?
This lesson answers three questions: What exactly is inside a block? How do blocks connect? And why does this structure keep things in order and catch changes?
The short version: The block header handles order and links. Hash references protect the transaction data. And a series of block headers forms a chain by each one pointing back to the one before it.
2. An Everyday Analogy
The Library Card Catalog
An old-fashioned library has rows of card catalogs. Each card records a book's key details: author, title, publication date, and shelf location. The cards are filed by some rule, and readers use the catalog to find books.
The books themselves sit on the shelves. The card catalog doesn't hold any books. It only tells you where a book is and which book it is.
The blockchain data structure works a lot like this catalog:
- The block header is like a catalog card. It records order and connections.
- The transaction data is like the books in the stacks, stored separately.
- The block header points to its transaction data through a hash reference, which makes sure nobody has swapped out what the catalog points to.
Knitting a Sweater
When you knit a sweater, each stitch loops through the next one. If you find a wrong stitch in the middle, you can't just pull out that one stitch and fix it. You have to start from the end, unravel every stitch after it one by one, fix the mistake, and then knit everything back.
Changing old records on a blockchain works the same way. Adding a new block at the end is like knitting the next stitch, which is easy. Changing an old block in the middle is like unraveling every stitch after it and knitting them all again.
3. Core Concepts Explained
3.1 What a Block Consists Of
In the simplified blockchain data structure, a block has two parts:
- The block header.
- The structure that holds the transaction data, usually a Merkle Patricia Trie.
The block header doesn't hold the transactions themselves. It stores a reference to the transaction data. Specifically, the block header keeps the root hash of the transaction data structure.
That way, the block header stays small but still stands for a large batch of transaction data. The transaction data can be stored somewhere else, but the root hash ties it to the block header.
3.2 The Three Most Critical Things in a Block Header
This lesson sticks to the core structure. Three things in the block header are most worth remembering:
- Its own block hash: the block header itself gets hashed, which produces a hash value that identifies it.
- A hash reference to the previous block header: this points to the parent block and keeps the order and the connection.
- The root hash of the transaction data structure: this points to the block's transaction data.
Real systems put other information in the block header too, but this lesson focuses on these three.
3.3 How Blocks Connect into a Chain
The first block has no block before it, so its header has no "previous block" reference.
From the second block on, every block header contains a hash reference to the block header before it. So the headers form one straight chain:
Block header 1 ← Block header 2 ← Block header 3
The arrows mean "points back to the one before." To check whether a block has been replaced, recompute its hash and see whether the reference in the next block header still matches.
3.4 Header and Head Are Not the Same Thing
These two words are easy to mix up:
- header: every block has its own block header, one header per block.
- head: the whole chain has only one head, which points to the most recently added block header. New blocks usually get attached after the head.
So a chain has many headers but only one head.
3.5 Why This Structure Preserves Order
Transaction data may go into the structure in the order it arrives, but what makes the order checkable is the way block headers reference each other.
Every block header points to the one before it. As long as you keep the latest head, you can trace the entire history backward along the references. Even if the data is scattered across different places, the hash references preserve the logical order.
This is different from an ordinary book. A book keeps its order with binding and page numbers. A blockchain keeps its logical order by having each block header reference the block header before it.
3.6 The Three Steps of Appending New Transactions
Say the chain currently has block 1, which holds transactions 1 and 2. Now we want to add transactions 3 and 4.
Step one: build a new transaction data structure. Put the new transactions 3 and 4 into a new Merkle Patricia Trie, which gives you a new root hash.
Step two: create a new block header. The new header stores two key references:
- The hash of the previous block header (pointing to block 1).
- The root hash of the new transaction data structure (pointing to transactions 3 and 4).
Step three: hash the new block header and make it the new head. Hashing the new header produces a new hash, and that hash becomes the chain's latest head.
Nobody rewrote the old block. The new block just got attached after it. That's the basic move behind append-only.
3.7 Alter One Transaction — Where Does the Breakage Start?
Say someone directly changes the amount or the receiving account in transaction 2 without updating any hash references.
Transaction 2's contents changed, so its hash value changed. The hash reference R2 that pointed to transaction 2 still holds the old hash. It doesn't match anymore, so R2 breaks.
That's just the first layer. R2 is part of the transaction data structure, so when R2 changes, the structure's root hash R12 changes too. R12 is the root hash stored in block 1's header, so when R12 changes, block 1's header hash changes. And once block 1's hash changes, the "previous block hash" stored in block 2 no longer matches.
So changing one transaction isn't just changing one field. The change spreads upward along the entire chain of references.
3.8 Change the Hash References Too — the Breakage Continues
What if the attacker is smarter and changes transaction 2 and also updates R2 to match the new transaction 2's hash?
Now transaction 2 and R2 match, for the moment. But R2 is part of the data structure that R12 stands for. R2 changed, so R12 changes. R12 changed, so block 1's header hash changes. Block 1's hash changed, so block 2's parent reference breaks again.
You can keep going down the chain if you want: change R12, change block 1's header, change the parent reference stored in block 2. But once block 1's header changes, its own hash changes. Once the parent reference in block 2's header changes, block 2's hash changes too. And once block 2's hash changes, whatever references block 2 breaks next.
This is cascade failure: each layer protects the one after it, and changing any layer sends the effect upward.
3.9 Replacing a Transaction and Modifying One Have the Same Consequence
Someone might think: what if I don't edit the original transaction and just swap transaction 2 out for a transaction 5? Would that slip by?
No. After the swap, transaction 5's hash doesn't match the original R2, so R2 breaks. Even if R2 gets updated to point to transaction 5, R12 changes, and the chain keeps breaking from there.
As far as the data structure is concerned, changing a transaction's contents and replacing the whole transaction have exactly the same result: both break the hash reference that points to it.
3.10 All or Nothing
The blockchain data structure takes a hard line on changes: either update every hash reference from the point of change all the way to the head, or don't change anything.
If you change half of it, or stop after a few layers, there's always a broken reference left behind. The chain is never "partly valid." One mismatched reference anywhere, and the whole structure is judged inconsistent.
Motive doesn't matter here. Whether the change was malicious, an accident, or a system failure, a mismatched hash reference means the structure counts as altered. It doesn't judge who changed it or why. It only checks whether the references are consistent.
3.11 This Isn't "Unchangeable" Yet
Here's what this lesson establishes: changing old records gets caught, and it means recomputing everything from the point of change to the head, which is expensive.
But the structure in this lesson, on its own, can't make changes completely impossible for someone with enough computing power. An attacker who's willing to recompute every hash reference after the change could, in theory, still rebuild a chain that's consistent with itself.
The next lesson covers how to make that recomputation harder, and Module 3 covers how nodes decide which chain to accept. For now, get a firm grip on this layer: changes cascade and break references.
4. Diagrams
Figure 2-5-1: Block Structure and Chain Linkage
Figure 2-5-2: The Cascade Failure of Altering an Old Record
5. Key Takeaways
- A block is made up of a block header and a transaction data structure. The transaction data usually lives in a Merkle Patricia Trie.
- The block header doesn't hold the transactions themselves. It stores the root hash of the transaction data structure.
- The three most critical things in a block header: its own hash, the reference to the previous block header, and the root hash of the transaction data.
- Block headers connect into a chain through hash references, and the first block has no parent block. Every block has a header, but the whole chain has only one head.
- Adding a new block doesn't rewrite old blocks. The new block attaches after the head. That's append-only.
- Changing a transaction changes its hash, and the change spreads through the reference, the root hash, the block header hash, and the parent references after it.
- Modifying a transaction and replacing it have the same result: both break references.
- Blockchain treats changes as all or nothing: either update everything all the way to the head, or leave everything as it was.
6. Quiz
Part 1: Single Choice (1–4)
Question 1
What two parts does a block usually have?
A. The block header and the transaction data structure
B. The public key and the private key
C. The fee and the username
D. Images and videos
Show answer
Answer: A
Explanation: A block is made up of the block header and the transaction data structure. Public keys, private keys, and fees aren't part of how a block's structure is defined.
Question 2
What connects block headers to each other?
A. Identical file names
B. A hash reference to the previous block header
C. The same number of transactions
D. Random numbers
Show answer
Answer: B
Explanation: Block headers connect by holding hash references to the previous block header, and that forms the chain.
Question 3
If someone directly changes transaction 2's contents, what breaks first?
A. The hash reference pointing to transaction 2
B. Every user's private key
C. Block 1's block header
D. The entire network
Show answer
Answer: A
Explanation: Changing the transaction contents changes the transaction hash, so the reference pointing directly to it breaks first. Private keys, block headers, and the whole network don't change on their own because of it.
Question 4
What's the difference between head and header?
A. Every block has a head, and there's only one header
B. Every block has a header, and the head is the single, latest head of the chain
C. They're exactly the same
D. The head exists only in the first block
Show answer
Answer: B
Explanation: Every block has a header. The whole chain has only one head, which points to the latest block header.
Part 2: Multiple Choice (5–7)
Question 5
What key information does a block header usually contain?
A. Its own hash
B. A hash reference to the previous block header
C. The root hash of the transaction data structure
D. The complete original text of every transaction
Show answer
Answer: A, B, C
Explanation: The block header stores its own hash, the reference to the parent block, and the root hash of the transaction data structure. The complete transaction text lives in the transaction data structure, not in the header.
Question 6
Through which layers can a change to an old transaction spread?
A. The transaction hash
B. References inside the transaction data structure
C. The root hash of the transaction data structure
D. The block header hash and the parent references in later blocks
Show answer
Answer: A, B, C, D
Explanation: A change spreads from the transaction hash all the way to the root hash, the block header hash, and the parent references after it.
Question 7
Which statements about how blockchain treats changes are correct?
A. It only checks whether hash references are consistent
B. It doesn't care about the motive behind a change
C. A partial change leaves things in an inconsistent state
D. It automatically makes every change legitimate
Show answer
Answer: A, B, C
Explanation: The structure only looks at whether references are consistent, not at motive, and a partial change leaves broken references behind. D is wrong: it never makes changes legitimate on its own.
Part 3: True or False (8–9)
Question 8
True or false: if you change a transaction's contents and then update the hash reference that points directly to it, nothing anywhere will give the change away.
Show answer
Answer: False
Explanation: Even if you update the direct reference, the root hash above it, the block header hash, and the parent references after it still change. The change keeps spreading upward.
Question 9
True or false: the structure in this lesson already makes it completely impossible for anyone with enough computing power to rebuild the chain.
Show answer
Answer: False
Explanation: This lesson only establishes that changes get exposed and that you'd have to recompute everything up to the head. Someone with enough computing power could, in theory, still rebuild a chain that's consistent with itself. Making tampering harder depends on the mechanisms in later lessons.
Part 4: Scenario Analysis (10)
Question 10
A chain has block 1 and block 2. Block 1's transaction data structure contains transaction 2, and block 2's header stores block 1's hash. An attacker changes transaction 2 and also updates the reference that points directly to transaction 2.
Answer the following:
- Which value changes next?
- After that, which block header is affected?
- What does the attacker have to do to end up with a chain that's consistent with itself?
Show answer
Answer:
- The root hash above it in the transaction data structure changes, because the direct reference has already changed.
- Block 1's header hash changes, which in turn breaks the parent reference stored in block 2.
- Starting from transaction 2, the attacker has to recompute the direct reference, the root hash, block 1's header hash, block 2's parent reference, and every related hash reference all the way to the head. Only then is the chain consistent with itself.