Base Consensus (hierachain/consensus/base_consensus.py)
Overview
BaseConsensus is the abstract base class defining the standard framework for all consensus algorithms in the HieraChain system. It ensures consistency between different protocols (PoA, PoF, BFT) and enforces the core business rules of an enterprise blockchain platform.
Core Responsibilities
-
Protocol Definition
Defines mandatory methods like
validate_block,finalize_block, andcan_create_blockso upper-layer modules (such as Ordering Service) can interact uniformly. -
Content Filtering (Enterprise Filtering)
Automatically scans and rejects events containing forbidden cryptocurrency terms (
mining,coin,token,wallet). This is a critical protection layer to maintain HieraChain's enterprise purpose. -
Integrity Verification
Integrates hash verification mechanisms, digital signatures, and Zero-Knowledge (ZK) Proof support to ensure block data cannot be altered.
Abstract API Methods
Every consensus algorithm inheriting from BaseConsensus must implement the following methods:
| Method | Description |
|---|---|
validate_block(block, prev_block) |
Validates the new block against the previous block. |
finalize_block(block) |
Performs final steps (signing, nonce assignment) before saving the block. |
can_create_block(node_id) |
Checks whether the current node has permission to create a block. |
get_consensus_info() |
Returns current status and configuration information of the protocol. |
Event Validation Rules
The system enforces strict forbidden keyword filtering:
* Checked data: All fields in details and event content.
* Excluded fields: Cryptographic fields such as signature, hash, merkle_root, and zk_proof are ignored to avoid false identification of random strings.
* Action: If a violation keyword is detected, validate_event_for_consensus returns False, causing the block to be rejected.
Zero-Knowledge (ZK) Integration
BaseConsensus provides helper functions for ZK proof verification (_verify_block_zk_proof). When settings.ENABLE_ZK_PROOFS is enabled, every consensus block must carry a valid proof to demonstrate the correctness of state changes without revealing raw data.