Understanding how new blocks are created in Ethereum requires diving into its core mechanics—mining and consensus algorithms. This deep dive explores the inner workings of Ethereum’s block creation process, from transaction assembly to final sealing via consensus. Whether you're a blockchain developer or an enthusiast, this guide unpacks the technical layers behind Ethereum’s decentralized security model.
How a New Block Is Assembled in Ethereum
At the heart of Ethereum’s mining mechanism lies the miner package, responsible for generating new blocks through a structured workflow. The primary components include:
- Miner: The entry point that exposes mining functionality.
- Worker: Manages the mining process and coordinates data preparation.
- Agent(s): Execute the actual mining task; currently, only
CpuAgentis implemented. - Work: Carries contextual data needed during mining.
The Worker prepares a complete block environment—transactions, uncle blocks, executed receipts—and sends it to registered Agent instances. Once an agent completes mining, it returns a signed block and updated work data.
👉 Discover how blockchain networks validate transactions securely and efficiently.
A unique feature is the unconfirmedBlocks list, which tracks locally mined blocks. After some time, these are checked against the canonical chain to confirm inclusion, logging results for transparency.
Key Phases of Block Creation
Block Assembly
Performed by theworker, this phase includes:- Selecting pending transactions from the transaction pool (
TxPool) - Executing all transactions and collecting receipts
- Gathering valid uncle blocks
- Building the block header with basic fields (number, parent hash, timestamp)
- Selecting pending transactions from the transaction pool (
- Block Sealing (Authorization)
Handled by theAgentusing a consensus engine (Engine). This step finalizes the block by setting cryptographic proofs likeDifficulty,Nonce, andMixDigest.
This separation ensures efficiency: one component focuses on data integrity, while another handles computational validation.
Core Functions Behind Mining Workflow
Miner Initialization: New() and Update()
The mining process starts with Miner.New(), where:
- A new
workerinstance is created - Agents (e.g.,
CpuAgent) are registered - A background goroutine runs
miner.Update()to monitor sync events
Update() listens for downloader events:
- On
StartEvent: Halts mining during synchronization - On
DoneEventorFailEvent: Resumes mining after sync ends
This prevents conflicts between local mining and network synchronization—ensuring each node processes only one source of truth for new blocks.
Worker Operations
worker.update()
Listens to three key events:
- ChainHeadEvent: A new block becomes the chain head → trigger next round of mining
- ChainSideEvent: A sidechain block appears → add to
possibleUncles[] - TxPreEvent: New transaction in
TxPool→ execute and queue for next block
Notably, when a miner successfully adds a block, it emits its own ChainHeadEvent, enabling continuous mining.
worker.wait()
Waits on a channel for completed blocks from agents. Upon receipt:
- Saves block to database
- Emits
NewMinedBlockEvent - Allows other nodes to validate and accept the block
commitNewWork()
This critical function orchestrates block assembly under mutex protection:
- Sets block time (must be > parent block time)
- Increments block number
- Assigns parent hash
- Calls
Engine.Prepare()to initialize header fields - Applies hard fork rules (e.g., DAO fork logic if applicable)
- Creates a new
Workobject - Executes transactions from
TxPool - Selects up to two uncles from
possibleUncles Calls
Engine.Finalize()to set:- State root (
Header.Root) - Transaction hash (
TxHash) - Receipt hash (
ReceiptHash) - Uncle hash (
UncleHash)
- State root (
- Sends the prepared
Workto all agents via channel
Once finalized, the block is ready for sealing.
Consensus Algorithms: The Heart of Mining
Ethereum uses the Engine interface to abstract consensus logic. Two main implementations exist:
- Ethash: Proof-of-Work (PoW), used in mainnet
- Clique: Proof-of-Authority (PoA), used in testnets
Key Engine Interface Methods
| Method | Purpose |
|---|---|
VerifyHeader() | Validates individual block headers |
VerifyHeaders() | Batch validation of headers |
VerifyUncles() | Ensures uncle blocks meet criteria |
Prepare() | Initializes header fields before sealing |
Finalize() | Finalizes block after transaction execution |
Seal() | Performs final authorization (mining) |
VerifySeal() | Validates whether a block was properly sealed |
Among these, Seal() is central to mining—it produces a cryptographically valid block.
Ethash: Ethereum’s Proof-of-Work Algorithm
Ethash, also known as Proof-of-Work (PoW), secures Ethereum through computational effort.
Core Equation
RAND(h, n) ≤ M / dWhere:
h= block header hash (Header.HashNoNonce())n= nonce valueM= maximum possible value (e.g., 2²⁵⁶ – 1)d= difficulty level
The goal is to find a nonce such that the result of RAND() falls below the target threshold (M / d). Higher difficulty means fewer valid solutions—increasing mining time.
Mining Process in Ethash
The mine() function runs in parallel across multiple threads (Ethash.threads). Each thread:
- Computes
hashimotoFull(dataset, hash, nonce) - Checks if result ≤ target
- If successful: sets
Nonce,MixDigest, and returns sealed block
Nonce increments with every iteration, ensuring uniqueness.
👉 Learn how consensus algorithms maintain trust in decentralized systems.
The Role of Hashimoto Functions
Two variants support different use cases:
hashimotoFull(): Used by miners; accesses full dataset (~several GB)hashimotoLight(): Used for verification; relies on smaller cache (~100s MB)
Both call the core hashimoto() function but differ in data access patterns.
Inside hashimoto()
This function performs complex hashing operations:
- Combines header hash and nonce → SHA-512 seed (64 bytes)
- Expands seed into a 32-element uint32 array (
mix[]) - Uses
lookup()to fetch data from large datasets (dataset[]) - Mixes in 64 rounds using FNV-style XOR operations
- Compresses final mix → digest (32 bytes)
Returns:
digest: Stored inHeader.MixDigestresult: Compared against target difficulty
The use of non-linear table lookups makes memory access patterns unpredictable—resisting ASIC dominance and promoting fairness.
Dataset and Cache Generation
Due to their size, Ethash uses memory-mapped files for efficiency.
Cache and Dataset Structure
Both share similar structures:
- cache{}: Smaller, used for verification
- dataset{}: Larger (~multi-gigabyte), used for mining
Each corresponds to an "epoch" (every 30,000 blocks).
Size Calculation
For epoch beyond 2048:
size = 2^24 + 2^17 * epoch - 64Then adjusted to the nearest prime number for cryptographic strength.
Even cache sizes exceed 256MB, making lightweight verification feasible while keeping mining resource-intensive.
Seed Generation
Each epoch uses a unique seed derived from repeated Keccak256 hashing:
seed = keccak256^(epoch) initial_seedThis ensures dataset uniqueness per epoch.
Clique: Proof-of-Authority for Testnets
Clique implements Proof-of-Authority (PoA) using digital signatures instead of computational work.
Sealing Logic
Uses ECDSA to sign block headers:
signature = ECDSA(private_key, header_hash)Only authorized signers can produce valid blocks.
Dynamic Authorization via Voting
Nodes vote to add or remove validators:
- Votes are stored in
proposals(unidentified) When a block is sealed:
- Signer (voter) is identified from signature
- Coinbase address = proposed candidate
- Nonce indicates vote type (authorize/revoke)
Votes accumulate in snapshots. A change passes when:
Votes ≥ 50% of current signers
Snapshot applies changes only after several confirmations—preventing rapid manipulation.
👉 See how blockchain consensus models compare across networks.
Frequently Asked Questions (FAQ)
Q1: What is the difference between Ethash and Clique?
A: Ethash uses Proof-of-Work requiring heavy computation; Clique uses Proof-of-Authority where trusted nodes sign blocks. Ethash secures mainnet; Clique powers testnets like Rinkeby.
Q2: Why does Ethereum separate block assembly from sealing?
A: Separation allows parallelization and modularity. Worker handles transaction processing efficiently, while agents focus on computationally intensive sealing—improving performance and scalability.
Q3: How does Ethash resist ASIC dominance?
A: By relying on large memory datasets and non-linear lookups, Ethash favors high-bandwidth memory over raw compute speed—making specialized hardware less advantageous.
Q4: What role do uncle blocks play in Ethereum?
A: Uncles improve network efficiency by rewarding stale blocks. They increase security by incorporating otherwise wasted computation into consensus.
Q5: Can anyone become a validator in Clique?
A: No—only pre-authorized addresses can sign blocks. New members require approval via voting by existing signers, ensuring controlled governance.
Q6: Is mining still relevant in Ethereum post-Merge?
A: Not in its current form. After Ethereum's transition to Proof-of-Stake (PoS), traditional PoW mining ended. However, understanding Ethash remains valuable for legacy chains and academic insight.
Summary: From Code to Consensus
Creating a new Ethereum block involves two stages:
- Assembly: Gather transactions, execute them, finalize state roots.
- Sealing: Apply consensus rules—either PoW (Ethash) or PoA (Clique).
While Ethash relies on brute-force computation secured by massive datasets, Clique leverages trusted identities with democratic governance. Both reflect different trade-offs between decentralization, performance, and security.
Though Ethereum has moved to Proof-of-Stake, studying these mechanisms offers deep insights into blockchain design principles—from incentive structures to anti-centralization tactics.
Whether you're building dApps or auditing smart contracts, understanding how blocks are formed strengthens your foundation in decentralized systems.
Core Keywords: Ethereum source code analysis, mining process, consensus algorithm, Ethash, Clique, Proof-of-Work, Proof-of-Authority, blockchain development