Files
aitbc/docs/apps/mining/miner.md
aitbc 522655ef92
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 10s
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
CLI Tests / test-cli (push) Failing after 4s
Documentation Validation / validate-docs (push) Successful in 8s
Documentation Validation / validate-policies-strict (push) Successful in 4s
Integration Tests / test-service-integration (push) Successful in 38s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 3s
Security Scanning / security-scan (push) Successful in 40s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 15s
Smart Contract Tests / lint-solidity (push) Successful in 8s
Move blockchain app READMEs to centralized documentation
- Relocate blockchain-event-bridge README content to docs/apps/blockchain/blockchain-event-bridge.md
- Relocate blockchain-explorer README content to docs/apps/blockchain/blockchain-explorer.md
- Replace app READMEs with redirect notices pointing to new documentation location
- Consolidate documentation in central docs/ directory for better organization
2026-04-23 12:24:48 +02:00

212 lines
4.4 KiB
Markdown

# Miner
## Status
✅ Operational
## Overview
Mining and block validation service for the AITBC blockchain using Proof-of-Authority consensus.
## Architecture
### Core Components
- **Block Validator**: Validates blocks from the network
- **Block Proposer**: Proposes new blocks (for authorized proposers)
- **Transaction Validator**: Validates transactions before inclusion
- **Reward Claimer**: Claims mining rewards
- **Sync Manager**: Manages blockchain synchronization
## Quick Start (End Users)
### Prerequisites
- Python 3.13+
- Access to blockchain RPC endpoint
- Valid proposer credentials (if proposing blocks)
### Installation
```bash
cd /opt/aitbc/apps/miner
.venv/bin/pip install -r requirements.txt
```
### Configuration
Set environment variables in `.env`:
```bash
BLOCKCHAIN_RPC_URL=http://localhost:8006
PROPOSER_ID=your-proposer-id
PROPOSER_PRIVATE_KEY=encrypted-key
MINING_ENABLED=true
VALIDATION_ENABLED=true
```
### Running the Service
```bash
.venv/bin/python main.py
```
## Developer Guide
### Development Setup
1. Clone the repository
2. Create virtual environment: `python -m venv .venv`
3. Install dependencies: `pip install -r requirements.txt`
4. Configure blockchain RPC endpoint
5. Configure proposer credentials (if proposing)
6. Run tests: `pytest tests/`
### Project Structure
```
miner/
├── src/
│ ├── block_validator/ # Block validation
│ ├── block_proposer/ # Block proposal
│ ├── transaction_validator/ # Transaction validation
│ ├── reward_claimer/ # Reward claiming
│ └── sync_manager/ # Sync management
├── tests/ # Test suite
└── pyproject.toml # Project configuration
```
### Testing
```bash
# Run all tests
pytest tests/
# Run block validator tests
pytest tests/test_validator.py
# Run block proposer tests
pytest tests/test_proposer.py
```
## API Reference
### Block Validation
#### Validate Block
```http
POST /api/v1/mining/validate/block
Content-Type: application/json
{
"block": {},
"chain_id": "ait-mainnet"
}
```
#### Get Validation Status
```http
GET /api/v1/mining/validation/status
```
### Block Proposal
#### Propose Block
```http
POST /api/v1/mining/propose/block
Content-Type: application/json
{
"chain_id": "ait-mainnet",
"transactions": [{}],
"timestamp": "2024-01-01T00:00:00Z"
}
```
#### Get Proposal Status
```http
GET /api/v1/mining/proposal/status
```
### Transaction Validation
#### Validate Transaction
```http
POST /api/v1/mining/validate/transaction
Content-Type: application/json
{
"transaction": {},
"chain_id": "ait-mainnet"
}
```
#### Get Validation Queue
```http
GET /api/v1/mining/validation/queue?limit=100
```
### Reward Claiming
#### Claim Reward
```http
POST /api/v1/mining/rewards/claim
Content-Type: application/json
{
"block_height": 1000,
"proposer_id": "string"
}
```
#### Get Reward History
```http
GET /api/v1/mining/rewards/history?proposer_id=string
```
### Sync Management
#### Get Sync Status
```http
GET /api/v1/mining/sync/status
```
#### Trigger Sync
```http
POST /api/v1/mining/sync/trigger
Content-Type: application/json
{
"from_height": 1000,
"to_height": 2000
}
```
## Configuration
### Environment Variables
- `BLOCKCHAIN_RPC_URL`: Blockchain RPC endpoint
- `PROPOSER_ID`: Proposer identifier
- `PROPOSER_PRIVATE_KEY`: Encrypted proposer private key
- `MINING_ENABLED`: Enable block proposal
- `VALIDATION_ENABLED`: Enable block validation
- `SYNC_INTERVAL`: Sync interval in seconds
### Consensus Parameters
- **Block Time**: Time between blocks (default: 10s)
- **Max Transactions**: Maximum transactions per block
- **Block Size**: Maximum block size in bytes
### Validation Rules
- **Signature Validation**: Validate block signatures
- **Transaction Validation**: Validate transaction format
- **State Validation**: Validate state transitions
## Troubleshooting
**Block validation failed**: Check block signature and state transitions.
**Proposal rejected**: Verify proposer authorization and block validity.
**Sync not progressing**: Check blockchain RPC connectivity and network status.
**Reward claim failed**: Verify proposer ID and block height.
## Security Notes
- Secure proposer private key storage
- Validate all blocks before acceptance
- Monitor for double-spending attacks
- Implement rate limiting for proposal
- Regularly audit mining operations
- Use secure key management