Understand the Ethereum block chain structure: Does a block contain the transaction list or just the Merkle tree?
As a blockchain enthusiast, it is likely to have heard about Ethereum and its decentralized digital accounting technology. A fundamental aspect of Ethereum’s architecture is that it stores not only the current state of the block chain (the transaction list) but also several other data structures to facilitate efficient consultations, manipulation and verification of transactions. In this article, we will deepen how a block in a transactional Ethereum network encodes its set of transactions and will explore if it includes the Merkle tree or if it only stores the hash.
The paper of the blocks in Ethereum
In Ethereum’s blockchain architecture, the blocks are the fundamental units that store a collection of transactions. A single block typically contains multiple transactions, which are grouped into “extracted” categories (that is, verified) and “not extracted” (that is, not yet verified). The first lines of code in each block contain metadata on the block itself, including its hash, time of time and other essential information.
The Merkle tree: a key data structure
Now, let’s talk about the Merkle tree. A Merkle tree is a data structure similar to a tree that helps verify the integrity and authenticity of transactions into a block. Each node in the tree represents a transaction, and its hash value serves as a fingerprint to identify it. By combining multiple hashes of different nodes in a single hash (the root), creates a unique identifier for each transaction.
The Merkle tree is generated at the time of the creation of blocks using the transactions stored inside the block. This process implies that the individual elements with hashated recursively in the tree until reaching a leaf node, which has then been done to generate their parents’ hash. The resulting hash value is used as the root of the Merkle tree.
Does Ethereum store the transaction list or just the Merkle tree?
So, does an Ethereum block contain both the list of transactions and the Merkle tree? In short, yes, yes! The first lines of code in each block serve as metadata that include:
- Transaction data : Real transactions stored inside the block.
- Merkle Tree : A digital representation of transactions, built from their hashes.
In other words, a block contains a list of transactions (the matrix of ‘Transactions ) and a Merkle tree (the
`variable') to facilitate the verification and consultation of transactions.
Example code fragments
To illustrate this concept, let's consider an example that uses solidity, the Ethereum intelligent contract language:
SOLIDITY
Pragma solidity ^0.8.0;
Hire Elereo Simple {
// The first lines of code in each block contain metadata around the block.
Builder () public {
uint256 _timestamp = block.timestamp;
Chain memory _Hash = keccak256 (abi.encodepacked (_timestamp));
bytes memory _blockhash = keccak256 (abi.encodepacked (_hash, "mytransaction"));
emit metadata (_blockhash);
}
Struct BlockMetadata {
Uint256 Time brand;
Bytes32 hash;
}
// In the function of the builderBlockMetadata...
Public BlockMetadata Metadata;
// When a block is created ...
modifier before blocking (Uint256 _timestamp) {
Require (_timestamp <= block.timestamp, "Timestamp is not in the past");
emit metadata (block.hash);
return true;
}
}
In this example, themetadatavariable within the contract 'Simpleshereshreum
represents a block with its time brand and hash. When creating a new block, call the function of the builder Metadatos
to generate a structureBlockMetadata
`containing both metadata values.