Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
CLI Tests / test-cli (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Successful in 2s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Successful in 2s
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Deploy to Testnet / deploy-testnet (push) Successful in 1m12s
Documentation Validation / validate-docs (push) Failing after 8s
Documentation Validation / validate-policies-strict (push) Successful in 3s
Integration Tests / test-service-integration (push) Successful in 2m6s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 2s
Multi-Node Blockchain Health Monitoring / health-check (push) Failing after 4s
P2P Network Verification / p2p-verification (push) Successful in 4s
Package Tests / Python package - aitbc-agent-sdk (push) Successful in 32s
Package Tests / Python package - aitbc-core (push) Successful in 14s
Package Tests / Python package - aitbc-crypto (push) Successful in 12s
Package Tests / Python package - aitbc-sdk (push) Successful in 9s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 8s
Package Tests / JavaScript package - aitbc-token (push) Successful in 17s
Python Tests / test-python (push) Successful in 15s
Security Scanning / security-scan (push) Successful in 27s
Node Failover Simulation / failover-test (push) Successful in 7s
Multi-Node Stress Testing / stress-test (push) Successful in 6s
Cross-Node Transaction Testing / transaction-test (push) Successful in 4s
- Add SQLCipher encryption for ait-mainnet database with configurable flag - Add db_encryption_enabled and db_encryption_key_path config settings - Implement encryption key loading and PRAGMA key setup via connection events - Add shutdown_db function for proper database cleanup - Export middleware classes in aitbc/__init__.py - Fix import path in sync.py for settings - Remove duplicate agent documentation from docs
137 lines
4.4 KiB
Markdown
137 lines
4.4 KiB
Markdown
# Consensus Mechanism
|
|
Understand AITBC's hybrid Proof-of-Authority/Proof-of-Stake consensus mechanism.
|
|
|
|
## Overview
|
|
|
|
AITBC uses a hybrid PoA/PoS consensus mechanism with:
|
|
- Fixed block time: 2 seconds
|
|
- Multi-validator authority set with role-based permissions
|
|
- Stake-weighted proposer selection and validator rotation
|
|
- Byzantine fault tolerance via PBFT protocol
|
|
- Transaction finality on each block
|
|
|
|
## Block Production
|
|
|
|
### Multi-Validator Architecture
|
|
|
|
AITBC supports multiple validators with distinct roles:
|
|
- **PROPOSER**: Authorized to propose new blocks
|
|
- **VALIDATOR**: Participates in consensus and validates blocks
|
|
- **STANDBY**: Waiting to be promoted to active role
|
|
|
|
### Proposer Selection
|
|
|
|
Multiple selection strategies are available:
|
|
- **Round-robin**: Validators take turns in fixed order
|
|
- **Stake-weighted**: Higher stake increases selection probability
|
|
- **Reputation-based**: Performance metrics influence selection
|
|
- **Hybrid**: Combines stake and reputation scores (default)
|
|
|
|
Proposers are selected from active validators with PROPOSER or VALIDATOR roles.
|
|
|
|
### Block Structure
|
|
|
|
```json
|
|
{
|
|
"header": {
|
|
"height": 100,
|
|
"timestamp": "2026-02-13T10:00:00Z",
|
|
"proposer": "ait-devnet-proposer-1",
|
|
"parent_hash": "0xabc123...",
|
|
"state_root": "0xdef456...",
|
|
"tx_root": "0xghi789..."
|
|
},
|
|
"transactions": [...],
|
|
"receipts": [...]
|
|
}
|
|
```
|
|
|
|
## Consensus Rules
|
|
|
|
1. **Block Time**: 2 seconds minimum
|
|
2. **Block Size**: 1 MB maximum
|
|
3. **Transactions**: 500 maximum per block
|
|
4. **Fee**: Minimum 0 (configurable)
|
|
5. **Validator Stake**: 1000 AITBC minimum
|
|
6. **Fault Tolerance**: Up to 1/3 of validators can be Byzantine (PBFT)
|
|
|
|
## Validator Requirements
|
|
|
|
| Requirement | Value |
|
|
|-------------|-------|
|
|
| Stake | 1000 AITBC minimum |
|
|
| Uptime | 99% minimum |
|
|
| Latency | < 100ms to peers |
|
|
| Reputation | 0.7 threshold (for reputation-based rotation) |
|
|
|
|
## Byzantine Fault Tolerance (PBFT)
|
|
|
|
AITBC implements Practical Byzantine Fault Tolerance for safety:
|
|
- **Pre-prepare phase**: Proposer broadcasts block proposal
|
|
- **Prepare phase**: Validators acknowledge proposal
|
|
- **Commit phase**: Validators commit to block execution
|
|
- **Execute phase**: Block is finalized and executed
|
|
|
|
The system tolerates up to 1/3 faulty validators while maintaining safety and liveness.
|
|
|
|
## Validator Rotation
|
|
|
|
Validators rotate automatically based on configured strategy:
|
|
- **Rotation interval**: Every 100 blocks (configurable)
|
|
- **Maximum validators**: 10 (configurable)
|
|
- **Strategies**: Round-robin, stake-weighted, reputation-based, or hybrid
|
|
|
|
Rotation ensures decentralization and prevents single-point failures.
|
|
|
|
## Network Partition Handling
|
|
|
|
The consensus mechanism detects and handles network partitions:
|
|
- Partitioned validators are marked and excluded from consensus
|
|
- Consensus requires majority of active validators (not partitioned)
|
|
- 5-second cooldown after partition healing before resuming consensus
|
|
- Byzantine behavior detection identifies malicious validators
|
|
|
|
## Fork Selection
|
|
|
|
Longest chain rule applies:
|
|
- Validators always extend the longest known chain
|
|
- Reorgs occur only on conflicting blocks within the last 10 blocks
|
|
|
|
## Finality
|
|
|
|
Blocks are considered final after:
|
|
- 1 confirmation for normal transactions
|
|
- 3 confirmations for high-value transactions
|
|
|
|
## Configuration
|
|
|
|
### Environment Variables
|
|
|
|
```bash
|
|
CONSENSUS_MODE=poa # Consensus algorithm
|
|
PROPOSER_ID=<address> # Default proposer (single-validator mode)
|
|
ROTATION_INTERVAL=100 # Blocks between rotations
|
|
MAX_VALIDATORS=10 # Maximum active validators
|
|
MIN_STAKE=1000.0 # Minimum validator stake
|
|
REPUTATION_THRESHOLD=0.7 # Minimum reputation for rotation
|
|
```
|
|
|
|
### Single vs Multi-Validator Mode
|
|
|
|
- **Single-validator**: Use `PROPOSER_ID` for simple setup (genesis wallet only)
|
|
- **Multi-validator**: Configure validator set via API or CLI for production
|
|
|
|
## Implementation
|
|
|
|
The consensus is implemented in:
|
|
- `apps/blockchain-node/src/aitbc_chain/consensus/multi_validator_poa.py` - Core PoA logic
|
|
- `apps/blockchain-node/src/aitbc_chain/consensus/pbft.py` - PBFT protocol
|
|
- `apps/blockchain-node/src/aitbc_chain/consensus/rotation.py` - Validator rotation
|
|
- `apps/blockchain-node/src/aitbc_chain/consensus/slashing.py` - Slashing conditions
|
|
|
|
## Next
|
|
|
|
- [Quick Start](./1_quick-start.md) — Get started
|
|
- [Validator Operations](./5_validator.md) - Validator guide
|
|
- [Networking](./6_networking.md) - P2P networking
|