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
- 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
246 lines
5.3 KiB
Markdown
246 lines
5.3 KiB
Markdown
# Blockchain Operational Features
|
|
|
|
## Overview
|
|
|
|
This document describes operational features for managing AITBC blockchain synchronization and data management.
|
|
|
|
## Auto Sync
|
|
|
|
### Overview
|
|
|
|
Automatic bulk sync is implemented in the blockchain node to automatically detect and resolve block gaps without manual intervention.
|
|
|
|
### Configuration
|
|
|
|
Configuration parameters in `/etc/aitbc/.env`:
|
|
|
|
| Parameter | Default | Description |
|
|
|-----------|---------|-------------|
|
|
| `auto_sync_enabled` | `true` | Enable/disable automatic bulk sync |
|
|
| `auto_sync_threshold` | `10` | Block gap threshold to trigger sync |
|
|
| `auto_sync_max_retries` | `3` | Max retry attempts for sync |
|
|
| `min_bulk_sync_interval` | `60` | Minimum seconds between sync attempts |
|
|
|
|
### Enabling Auto Sync
|
|
|
|
To enable on a node:
|
|
|
|
1. Add `auto_sync_enabled=true` to `/etc/aitbc/.env`
|
|
2. Restart the blockchain node service:
|
|
```bash
|
|
sudo systemctl restart aitbc-blockchain-node.service
|
|
```
|
|
|
|
### Sync Triggers
|
|
|
|
Automatic sync triggers when:
|
|
- A block arrives via gossip
|
|
- Import fails due to gap detection
|
|
- Gap exceeds `auto_sync_threshold`
|
|
- Time since last sync exceeds `min_bulk_sync_interval`
|
|
|
|
### Code Location
|
|
|
|
Implementation is located in:
|
|
- `apps/blockchain-node/src/aitbc_chain/config.py` - Configuration
|
|
- `apps/blockchain-node/src/aitbc_chain/main.py` - Main loop
|
|
- `apps/blockchain-node/src/aitbc_chain/sync.py` - Sync logic
|
|
|
|
## Force Sync
|
|
|
|
### Overview
|
|
|
|
Force synchronization allows manual triggering of blockchain data synchronization between nodes.
|
|
|
|
### API Endpoints
|
|
|
|
#### Trigger Force Sync
|
|
|
|
```http
|
|
POST /rpc/force_sync
|
|
Content-Type: application/json
|
|
|
|
{
|
|
"chain_id": "ait-mainnet",
|
|
"from_height": 1000,
|
|
"to_height": 2000
|
|
}
|
|
```
|
|
|
|
#### Check Sync Status
|
|
|
|
```http
|
|
GET /rpc/sync/status
|
|
```
|
|
|
|
### Usage
|
|
|
|
To manually trigger synchronization:
|
|
|
|
```bash
|
|
curl -X POST http://localhost:8006/rpc/force_sync \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"chain_id":"ait-mainnet","from_height":0,"to_height":1000}'
|
|
```
|
|
|
|
## Export
|
|
|
|
### Overview
|
|
|
|
Export blockchain data for backup, migration, or analysis purposes.
|
|
|
|
### API Endpoints
|
|
|
|
#### Export Blocks
|
|
|
|
```http
|
|
POST /rpc/export/blocks
|
|
Content-Type: application/json
|
|
|
|
{
|
|
"chain_id": "ait-mainnet",
|
|
"from_height": 0,
|
|
"to_height": 1000
|
|
}
|
|
```
|
|
|
|
#### Export Transactions
|
|
|
|
```http
|
|
POST /rpc/export/transactions
|
|
Content-Type: application/json
|
|
|
|
{
|
|
"chain_id": "ait-mainnet",
|
|
"from_height": 0,
|
|
"to_height": 1000
|
|
}
|
|
```
|
|
|
|
### Usage
|
|
|
|
Export blocks to file:
|
|
|
|
```bash
|
|
curl -X POST http://localhost:8006/rpc/export/blocks \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"chain_id":"ait-mainnet","from_height":0,"to_height":1000}' \
|
|
> blocks_export.json
|
|
```
|
|
|
|
## Import
|
|
|
|
### Overview
|
|
|
|
Import blockchain data from exported files for node initialization or recovery.
|
|
|
|
### API Endpoints
|
|
|
|
#### Import Blocks
|
|
|
|
```http
|
|
POST /rpc/import/blocks
|
|
Content-Type: application/json
|
|
|
|
{
|
|
"chain_id": "ait-mainnet",
|
|
"file": "/path/to/blocks_export.json"
|
|
}
|
|
```
|
|
|
|
#### Import Transactions
|
|
|
|
```http
|
|
POST /rpc/import/transactions
|
|
Content-Type: application/json
|
|
|
|
{
|
|
"chain_id": "ait-mainnet",
|
|
"file": "/path/to/transactions_export.json"
|
|
}
|
|
```
|
|
|
|
### Usage
|
|
|
|
Import blocks from file:
|
|
|
|
```bash
|
|
curl -X POST http://localhost:8006/rpc/import/blocks \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"chain_id":"ait-mainnet","file":"/path/to/blocks_export.json"}'
|
|
```
|
|
|
|
### Import Chain
|
|
|
|
```http
|
|
POST /rpc/import/chain
|
|
Content-Type: application/json
|
|
|
|
{
|
|
"chain_id": "ait-mainnet",
|
|
"file": "/path/to/chain_export.json"
|
|
}
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Auto Sync Not Triggering
|
|
|
|
**Symptoms**: Block gaps not detected or sync not starting.
|
|
|
|
**Solutions**:
|
|
- Verify `auto_sync_enabled=true` in `/etc/aitbc/.env`
|
|
- Check `auto_sync_threshold` is appropriate for your network
|
|
- Verify blockchain node service is running
|
|
- Check logs: `journalctl -u aitbc-blockchain-node.service -f`
|
|
|
|
### Force Sync Failing
|
|
|
|
**Symptoms**: Force sync returns error or times out.
|
|
|
|
**Solutions**:
|
|
- Verify target node is accessible
|
|
- Check chain_id matches target node
|
|
- Verify height range is valid
|
|
- Check network connectivity
|
|
- Review logs for specific error messages
|
|
|
|
### Export Failing
|
|
|
|
**Symptoms**: Export returns error or incomplete data.
|
|
|
|
**Solutions**:
|
|
- Verify sufficient disk space
|
|
- Check chain_id exists
|
|
- Verify height range is valid
|
|
- Check database connectivity
|
|
|
|
### Import Failing
|
|
|
|
**Symptoms**: Import returns error or data not persisted.
|
|
|
|
**Solutions**:
|
|
- Verify export file exists and is valid JSON
|
|
- Check chain_id matches
|
|
- Verify file format matches expected structure
|
|
- Check database write permissions
|
|
- Verify import lock is not held by another process
|
|
|
|
## Security Notes
|
|
|
|
- Auto sync uses same authentication as blockchain RPC
|
|
- Force sync requires admin privileges
|
|
- Export/Import operations should be performed on trusted nodes only
|
|
- Export files may contain sensitive transaction data - secure appropriately
|
|
- Import operations can overwrite existing data - use with caution
|
|
- Validate export files before importing from untrusted sources
|
|
|
|
## Performance Considerations
|
|
|
|
- Auto sync runs in background with minimal impact on node performance
|
|
- Force sync may temporarily increase resource usage
|
|
- Export operations can be memory-intensive for large ranges
|
|
- Import operations may lock database during processing
|
|
- Use appropriate batch sizes for large exports/imports
|
|
- Schedule exports during low-traffic periods when possible
|