3.5 Consensus Mechanism
Last updated
Last updated
Miners Select Transactions
Miners choose transactions from the memory pool (mempool) that are pending processing, often selecting transactions with higher fees to increase profits.
Creating a Candidate Block
Miners package the selected transactions into a candidate block, which includes the following information :
Block Header
Transaction List
State Root
Transaction Root
Calculating Hash
Miners need to calculate the hash value of the candidate block to find a hash that meets specific conditions. The specific steps are as follows: hash the block header information (including version number, parent block hash, timestamp, difficulty, nonce, etc.). The goal is to find a hash value that is less than the current difficulty target. This process involves continuously adjusting the nonce value until the appropriate hash is found.
Difficulty Adjustment
The difficulty of PemChain adjusts dynamically based on the network's overall hash rate. Every 10,000 blocks, the difficulty is adjusted based on the block production time of the past 10,000 blocks to maintain an average block production time of approximately 15 seconds.
D_previous: The difficulty of the previous block.
T_target: The target time (usually 15 seconds).
T_actual: The average time it took to generate the last 10,000 blocks.
Submission of a New Block
Once a miner finds a valid hash, they broadcast the candidate block to the network. Other nodes verify the validity of the block, including:
Confirming the validity of the transactions.
Checking if the block header's hash meets the difficulty requirements.
Verifying if the state changes in the block are correct.
Block Reward
If the new block is successfully added to the blockchain, the miner will receive a block reward. This typically includes:
A fixed block reward (which may vary at different stages of PemChain).
Transaction fees (fees from all transactions included in the block).
Reorganization and Orphan Blocks
Due to network latency and competition among miners, it is possible for multiple miners to find a valid block almost simultaneously. In such cases, "orphan blocks" may occur. PemChain handles orphan blocks based on the principle of the longest chain, with the final confirmed chain being the one that contains the most proof of work (PoW).
Security
The security of the PoW mechanism relies on the expenditure of work effort; an attacker would need to control more than 50% of the network's hash rate to mount an effective attack, such as a double spend.