mirror of
https://github.com/aljazceru/lnflow.git
synced 2025-12-18 21:14:22 +01:00
fixes
This commit is contained in:
130
README.md
130
README.md
@@ -1,59 +1,59 @@
|
||||
# ⚡ Lightning Policy Manager
|
||||
# Lightning Policy Manager
|
||||
|
||||
Next-generation Lightning Network channel fee optimization with advanced inbound fee strategies, machine learning, and automatic rollback protection.
|
||||
|
||||
## 🚀 Overview
|
||||
## Overview
|
||||
|
||||
Lightning Policy Manager is an intelligent fee management system that enhances the popular **charge-lnd** tool with:
|
||||
- ✅ **Advanced inbound fee strategies** (beyond simple discounts)
|
||||
- ✅ **Automatic rollback protection** for safety
|
||||
- ✅ **Machine learning optimization** from historical data
|
||||
- ✅ **Revenue maximization focus** vs simple rule-based approaches
|
||||
- ✅ **High-performance gRPC integration** with REST fallback
|
||||
- ✅ **Comprehensive security** with method whitelisting
|
||||
- ✅ **Complete charge-lnd compatibility**
|
||||
- **Advanced inbound fee strategies** (beyond simple discounts)
|
||||
- **Automatic rollback protection** for safety
|
||||
- **Machine learning optimization** from historical data
|
||||
- **Revenue maximization focus** vs simple rule-based approaches
|
||||
- **High-performance gRPC integration** with REST fallback
|
||||
- **Comprehensive security** with method whitelisting
|
||||
- **Complete charge-lnd compatibility**
|
||||
|
||||
## 📁 Repository Structure
|
||||
## Repository Structure
|
||||
|
||||
```
|
||||
lightning-fee-optimizer/
|
||||
├── 📄 README.md # This file
|
||||
├── ⚙️ pyproject.toml # Modern Python project config
|
||||
├── 📋 requirements.txt # Python dependencies
|
||||
├── 🚫 .gitignore # Git ignore rules
|
||||
├── README.md # This file
|
||||
├── pyproject.toml # Modern Python project config
|
||||
├── requirements.txt # Python dependencies
|
||||
├── .gitignore # Git ignore rules
|
||||
├──
|
||||
├── 📂 src/ # Main application source
|
||||
│ ├── 🔧 main.py # Application entry point
|
||||
│ ├── 🏛️ api/ # LND API clients
|
||||
│ ├── 🧪 experiment/ # Experiment framework
|
||||
│ ├── 📊 analysis/ # Channel analysis
|
||||
│ ├── 🎯 policy/ # Policy management engine
|
||||
│ ├── 📈 strategy/ # Fee optimization strategies
|
||||
│ ├── 🔧 utils/ # Utilities & database
|
||||
│ └── 📋 models/ # Data models
|
||||
├── src/ # Main application source
|
||||
│ ├── main.py # Application entry point
|
||||
│ ├── api/ # LND API clients
|
||||
│ ├── experiment/ # Experiment framework
|
||||
│ ├── analysis/ # Channel analysis
|
||||
│ ├── policy/ # Policy management engine
|
||||
│ ├── strategy/ # Fee optimization strategies
|
||||
│ ├── utils/ # Utilities & database
|
||||
│ └── models/ # Data models
|
||||
├──
|
||||
├── 📂 scripts/ # Automation scripts
|
||||
│ ├── ⚡ setup_grpc.sh # Secure gRPC setup
|
||||
│ ├── 📊 advanced_fee_strategy.sh # Advanced fee management
|
||||
│ └── 🔧 *.sh # Other automation scripts
|
||||
├── scripts/ # Automation scripts
|
||||
│ ├── setup_grpc.sh # Secure gRPC setup
|
||||
│ ├── advanced_fee_strategy.sh # Advanced fee management
|
||||
│ └── *.sh # Other automation scripts
|
||||
├──
|
||||
├── 📂 examples/ # Configuration examples
|
||||
├── examples/ # Configuration examples
|
||||
│ ├── basic_policy.conf # Simple policy example
|
||||
│ └── advanced_policy.conf # Advanced features demo
|
||||
├──
|
||||
├── 📂 docs/ # Documentation
|
||||
│ ├── 📖 LIGHTNING_POLICY_README.md # Detailed guide
|
||||
│ ├── 🛡️ SECURITY_ANALYSIS_REPORT.md # Security audit
|
||||
│ ├── 🚀 GRPC_UPGRADE.md # gRPC integration
|
||||
│ └── 📊 *.md # Other documentation
|
||||
├── docs/ # Documentation
|
||||
│ ├── LIGHTNING_POLICY_README.md # Detailed guide
|
||||
│ ├── SECURITY_ANALYSIS_REPORT.md # Security audit
|
||||
│ ├── GRPC_UPGRADE.md # gRPC integration
|
||||
│ └── *.md # Other documentation
|
||||
├──
|
||||
├── 🔧 lightning_policy.py # Main CLI tool
|
||||
├── 🧪 lightning_experiment.py # Experiment runner
|
||||
├── 📊 analyze_data.py # Data analysis tool
|
||||
└── 🧪 test_*.py # Test files
|
||||
├── lightning_policy.py # Main CLI tool
|
||||
├── lightning_experiment.py # Experiment runner
|
||||
├── analyze_data.py # Data analysis tool
|
||||
└── test_*.py # Test files
|
||||
```
|
||||
|
||||
## 🏃 Quick Start
|
||||
## Quick Start
|
||||
|
||||
### 1. Setup Environment
|
||||
```bash
|
||||
@@ -89,9 +89,9 @@ pip install -r requirements.txt
|
||||
./lightning_policy.py --prefer-rest -c my_policy.conf apply
|
||||
```
|
||||
|
||||
## 💡 Key Features
|
||||
## Key Features
|
||||
|
||||
### 🎯 Intelligent Inbound Fee Strategies
|
||||
### Intelligent Inbound Fee Strategies
|
||||
```ini
|
||||
[balance-drain-channels]
|
||||
chan.min_ratio = 0.8 # High local balance
|
||||
@@ -99,7 +99,7 @@ strategy = balance_based
|
||||
inbound_fee_ppm = -100 # Encourage inbound flow
|
||||
```
|
||||
|
||||
### 🛡️ Automatic Rollback Protection
|
||||
### Automatic Rollback Protection
|
||||
```ini
|
||||
[revenue-channels]
|
||||
strategy = revenue_max
|
||||
@@ -107,34 +107,34 @@ enable_auto_rollback = true # Monitor performance
|
||||
rollback_threshold = 0.25 # Rollback if revenue drops >25%
|
||||
```
|
||||
|
||||
### ⚡ High-Performance gRPC
|
||||
### High-Performance gRPC
|
||||
- **10x faster** fee updates than REST
|
||||
- **Native LND interface** (same as charge-lnd)
|
||||
- **Automatic fallback** to REST if gRPC unavailable
|
||||
- **Secure by design** - only fee management operations allowed
|
||||
|
||||
### 📊 Advanced Analytics
|
||||
### Advanced Analytics
|
||||
- **Policy performance tracking**
|
||||
- **Revenue optimization reports**
|
||||
- **Channel analysis and insights**
|
||||
- **Historical data learning**
|
||||
|
||||
## 🔒 Security Features
|
||||
## Security Features
|
||||
|
||||
- ✅ **Method whitelisting** - only fee management operations allowed
|
||||
- ✅ **Runtime validation** - dangerous operations blocked
|
||||
- ✅ **Comprehensive audit** - all operations logged
|
||||
- ✅ **No fund movement** - only channel fee updates
|
||||
- ✅ **Production-ready** - enterprise security standards
|
||||
- **Method whitelisting** - only fee management operations allowed
|
||||
- **Runtime validation** - dangerous operations blocked
|
||||
- **Comprehensive audit** - all operations logged
|
||||
- **No fund movement** - only channel fee updates
|
||||
- **Production-ready** - enterprise security standards
|
||||
|
||||
## 📚 Documentation
|
||||
## Documentation
|
||||
|
||||
- **[Lightning Policy Guide](docs/LIGHTNING_POLICY_README.md)** - Complete feature overview
|
||||
- **[Security Analysis](docs/SECURITY_ANALYSIS_REPORT.md)** - Comprehensive security audit
|
||||
- **[gRPC Integration](docs/GRPC_UPGRADE.md)** - High-performance setup guide
|
||||
- **[Experiment Guide](docs/EXPERIMENT_GUIDE.md)** - Advanced experimentation
|
||||
|
||||
## 🔧 CLI Commands
|
||||
## CLI Commands
|
||||
|
||||
```bash
|
||||
# Policy Management
|
||||
@@ -151,7 +151,7 @@ rollback_threshold = 0.25 # Rollback if revenue drops >25%
|
||||
./lightning_policy.py generate-config # Create sample config
|
||||
```
|
||||
|
||||
## ⚙️ Configuration Options
|
||||
## Configuration Options
|
||||
|
||||
```bash
|
||||
# gRPC (preferred - 10x faster)
|
||||
@@ -167,19 +167,19 @@ rollback_threshold = 0.25 # Rollback if revenue drops >25%
|
||||
--macaroon-path admin.macaroon # Macaroon file
|
||||
```
|
||||
|
||||
## 🆚 Comparison with charge-lnd
|
||||
## Comparison with charge-lnd
|
||||
|
||||
| Feature | charge-lnd | Lightning Policy Manager |
|
||||
|---------|------------|-------------------------|
|
||||
| **Basic Fee Management** | ✅ | ✅ Enhanced |
|
||||
| **Inbound Fee Support** | ⚠️ Limited | ✅ Advanced strategies |
|
||||
| **Performance Monitoring** | ❌ | ✅ Automatic rollbacks |
|
||||
| **Machine Learning** | ❌ | ✅ Data-driven optimization |
|
||||
| **API Performance** | gRPC only | ✅ gRPC + REST fallback |
|
||||
| **Security** | Basic | ✅ Enterprise-grade |
|
||||
| **Revenue Focus** | Rule-based | ✅ Revenue optimization |
|
||||
| **Basic Fee Management** | Yes | Enhanced |
|
||||
| **Inbound Fee Support** | Limited | Advanced strategies |
|
||||
| **Performance Monitoring** | No | Automatic rollbacks |
|
||||
| **Machine Learning** | No | Data-driven optimization |
|
||||
| **API Performance** | gRPC only | gRPC + REST fallback |
|
||||
| **Security** | Basic | Enterprise-grade |
|
||||
| **Revenue Focus** | Rule-based | Revenue optimization |
|
||||
|
||||
## 🧪 Testing
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
# Run tests
|
||||
@@ -192,7 +192,7 @@ python -m pytest test_optimizer.py
|
||||
./lightning_policy.py -c your_config.conf test-channel CHANNEL_ID
|
||||
```
|
||||
|
||||
## 🤝 Contributing
|
||||
## Contributing
|
||||
|
||||
1. Fork the repository
|
||||
2. Create a feature branch
|
||||
@@ -201,15 +201,15 @@ python -m pytest test_optimizer.py
|
||||
5. Ensure security standards are maintained
|
||||
6. Submit a pull request
|
||||
|
||||
## 📄 License
|
||||
## License
|
||||
|
||||
This project enhances and builds upon the open-source charge-lnd tool while adding significant new capabilities for Lightning Network fee optimization.
|
||||
|
||||
## 🔗 Related Projects
|
||||
## Related Projects
|
||||
|
||||
- **[charge-lnd](https://github.com/accumulator/charge-lnd)** - Original fee management tool
|
||||
- **[LND](https://github.com/lightningnetwork/lnd)** - Lightning Network Daemon
|
||||
|
||||
---
|
||||
|
||||
**⚡ Supercharge your Lightning Network channel fee management with intelligent, automated optimization!** 🚀
|
||||
**Supercharge your Lightning Network channel fee management with intelligent, automated optimization!**
|
||||
@@ -1,92 +1,92 @@
|
||||
# 🎯 Repository Setup Complete
|
||||
# Repository Setup Complete
|
||||
|
||||
## ✅ **SUCCESSFULLY ORGANIZED & COMMITTED**
|
||||
## **SUCCESSFULLY ORGANIZED & COMMITTED**
|
||||
|
||||
The Lightning Policy Manager repository has been professionally organized and committed to git with proper structure and security.
|
||||
|
||||
---
|
||||
|
||||
## 📊 **Repository Statistics**
|
||||
## **Repository Statistics**
|
||||
|
||||
- **✅ 53 files committed** (14,745 lines of code)
|
||||
- **✅ Professional folder structure** implemented
|
||||
- **✅ Comprehensive .gitignore** protecting sensitive data
|
||||
- **✅ All essential code** safely committed
|
||||
- **✅ Data and logs** properly excluded
|
||||
- **53 files committed** (14,745 lines of code)
|
||||
- **Professional folder structure** implemented
|
||||
- **Comprehensive .gitignore** protecting sensitive data
|
||||
- **All essential code** safely committed
|
||||
- **Data and logs** properly excluded
|
||||
|
||||
---
|
||||
|
||||
## 🗂️ **Folder Organization**
|
||||
## **Folder Organization**
|
||||
|
||||
### ✅ **COMMITTED** - Essential Files
|
||||
### **COMMITTED** - Essential Files
|
||||
|
||||
```
|
||||
📁 Repository Structure:
|
||||
├── 📄 README.md # Project overview & quick start
|
||||
├── ⚙️ pyproject.toml # Modern Python project config
|
||||
├── 📋 requirements.txt # Dependencies
|
||||
├── 🚫 .gitignore # Comprehensive ignore rules
|
||||
Repository Structure:
|
||||
├── README.md # Project overview & quick start
|
||||
├── pyproject.toml # Modern Python project config
|
||||
├── requirements.txt # Dependencies
|
||||
├── .gitignore # Comprehensive ignore rules
|
||||
├──
|
||||
├── 📂 src/ # Main application (13 files)
|
||||
│ ├── 🏛️ api/ # LND API clients
|
||||
│ ├── 🧪 experiment/ # Experiment framework + secure gRPC
|
||||
│ ├── 📊 analysis/ # Channel analysis
|
||||
│ ├── 🎯 policy/ # Policy management engine
|
||||
│ ├── 📈 strategy/ # Fee optimization strategies
|
||||
│ ├── 🔧 utils/ # Database & utilities
|
||||
│ └── 📋 models/ # Data models
|
||||
├── src/ # Main application (13 files)
|
||||
│ ├── api/ # LND API clients
|
||||
│ ├── experiment/ # Experiment framework + secure gRPC
|
||||
│ ├── analysis/ # Channel analysis
|
||||
│ ├── policy/ # Policy management engine
|
||||
│ ├── strategy/ # Fee optimization strategies
|
||||
│ ├── utils/ # Database & utilities
|
||||
│ └── models/ # Data models
|
||||
├──
|
||||
├── 📂 scripts/ # Shell automation (6 files)
|
||||
│ ├── ⚡ setup_grpc.sh # Secure gRPC setup
|
||||
│ ├── 📊 advanced_fee_strategy.sh # Advanced fee management
|
||||
│ └── 🔧 *.sh # Fee update automation
|
||||
├── scripts/ # Shell automation (6 files)
|
||||
│ ├── setup_grpc.sh # Secure gRPC setup
|
||||
│ ├── advanced_fee_strategy.sh # Advanced fee management
|
||||
│ └── *.sh # Fee update automation
|
||||
├──
|
||||
├── 📂 examples/ # Configuration examples (2 files)
|
||||
├── examples/ # Configuration examples (2 files)
|
||||
│ ├── basic_policy.conf # Simple policy example
|
||||
│ └── advanced_policy.conf # Advanced features demo
|
||||
├──
|
||||
├── 📂 docs/ # Documentation (8 files)
|
||||
│ ├── 📖 LIGHTNING_POLICY_README.md # Complete feature guide
|
||||
│ ├── 🛡️ SECURITY_ANALYSIS_REPORT.md # Security audit report
|
||||
│ ├── 🚀 GRPC_UPGRADE.md # gRPC integration guide
|
||||
│ └── 📊 *.md # Additional documentation
|
||||
├── docs/ # Documentation (8 files)
|
||||
│ ├── LIGHTNING_POLICY_README.md # Complete feature guide
|
||||
│ ├── SECURITY_ANALYSIS_REPORT.md # Security audit report
|
||||
│ ├── GRPC_UPGRADE.md # gRPC integration guide
|
||||
│ └── *.md # Additional documentation
|
||||
├──
|
||||
├── 🔧 *.py # CLI tools & analysis scripts
|
||||
└── 🧪 test_*.py # Test files
|
||||
├── *.py # CLI tools & analysis scripts
|
||||
└── test_*.py # Test files
|
||||
```
|
||||
|
||||
### 🚫 **EXCLUDED** - Data & Build Artifacts
|
||||
### **EXCLUDED** - Data & Build Artifacts
|
||||
|
||||
```
|
||||
🚫 Properly Ignored:
|
||||
├── 🗄️ data_samples/ # Sample Lightning data (5000+ files)
|
||||
├── 📊 experiment_data/ # Experiment results & database
|
||||
├── 📝 *.log # Application logs
|
||||
├── 🔄 __pycache__/ # Python cache files
|
||||
├── 🏗️ venv/ # Virtual environment (372MB)
|
||||
├── 📄 *_details.json # Generated channel data
|
||||
├── 📊 *_analysis.csv # Generated analysis reports
|
||||
├── ⚡ charge-lnd-original/ # Third-party embedded repository
|
||||
└── 🔧 Generated scripts & temp files
|
||||
Properly Ignored:
|
||||
├── data_samples/ # Sample Lightning data (5000+ files)
|
||||
├── experiment_data/ # Experiment results & database
|
||||
├── *.log # Application logs
|
||||
├── __pycache__/ # Python cache files
|
||||
├── venv/ # Virtual environment (372MB)
|
||||
├── *_details.json # Generated channel data
|
||||
├── *_analysis.csv # Generated analysis reports
|
||||
├── charge-lnd-original/ # Third-party embedded repository
|
||||
└── Generated scripts & temp files
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔒 **Security & Quality Measures**
|
||||
## **Security & Quality Measures**
|
||||
|
||||
### ✅ **Data Protection**
|
||||
### **Data Protection**
|
||||
- **Sensitive channel data** properly excluded from repository
|
||||
- **Private node information** not committed
|
||||
- **Authentication files** (.macaroon, .cert) ignored
|
||||
- **Runtime logs** excluded to prevent data leaks
|
||||
|
||||
### ✅ **Repository Hygiene**
|
||||
### **Repository Hygiene**
|
||||
- **No build artifacts** or temporary files committed
|
||||
- **Virtual environments** properly excluded (saved 372MB)
|
||||
- **Generated files** automatically ignored
|
||||
- **Professional .gitignore** with comprehensive rules
|
||||
|
||||
### ✅ **Code Organization**
|
||||
### **Code Organization**
|
||||
- **Modular architecture** with clear separation of concerns
|
||||
- **Comprehensive documentation** for all features
|
||||
- **Test coverage** included
|
||||
@@ -94,7 +94,7 @@ The Lightning Policy Manager repository has been professionally organized and co
|
||||
|
||||
---
|
||||
|
||||
## 📋 **Git Ignore Rules Applied**
|
||||
## **Git Ignore Rules Applied**
|
||||
|
||||
```gitignore
|
||||
# Critical exclusions applied:
|
||||
@@ -112,7 +112,7 @@ admin.macaroon* # Authentication files
|
||||
|
||||
---
|
||||
|
||||
## 🚀 **What You Can Do Now**
|
||||
## **What You Can Do Now**
|
||||
|
||||
### 1. **Clone & Setup**
|
||||
```bash
|
||||
@@ -140,37 +140,37 @@ pip install -r requirements.txt
|
||||
|
||||
---
|
||||
|
||||
## 🎯 **Repository Quality Score**
|
||||
## **Repository Quality Score**
|
||||
|
||||
| Aspect | Status | Notes |
|
||||
|--------|---------|-------|
|
||||
| **Code Organization** | ✅ Excellent | Professional modular structure |
|
||||
| **Documentation** | ✅ Comprehensive | 8 detailed guides included |
|
||||
| **Security** | ✅ Enterprise-grade | Full security audit completed |
|
||||
| **Ignore Rules** | ✅ Comprehensive | All sensitive data protected |
|
||||
| **File Structure** | ✅ Professional | Modern Python project standards |
|
||||
| **Commit Quality** | ✅ Detailed | Clear commit message with features |
|
||||
| **Code Organization** | Excellent | Professional modular structure |
|
||||
| **Documentation** | Comprehensive | 8 detailed guides included |
|
||||
| **Security** | Enterprise-grade | Full security audit completed |
|
||||
| **Ignore Rules** | Comprehensive | All sensitive data protected |
|
||||
| **File Structure** | Professional | Modern Python project standards |
|
||||
| **Commit Quality** | Detailed | Clear commit message with features |
|
||||
|
||||
---
|
||||
|
||||
## 🏆 **Achievement Summary**
|
||||
## **Achievement Summary**
|
||||
|
||||
**✅ Successfully transformed a development workspace into a production-ready repository:**
|
||||
**Successfully transformed a development workspace into a production-ready repository:**
|
||||
|
||||
1. **🗂️ Organized** 500MB+ of files into proper structure
|
||||
2. **🔒 Protected** sensitive Lightning Network data
|
||||
3. **📝 Documented** all features comprehensively
|
||||
4. **🚫 Excluded** 372MB+ of unnecessary build artifacts
|
||||
5. **✅ Committed** only essential source code (53 files)
|
||||
6. **🛡️ Secured** repository with enterprise-grade practices
|
||||
7. **🚀 Prepared** for immediate production deployment
|
||||
1. **Organized** 500MB+ of files into proper structure
|
||||
2. **Protected** sensitive Lightning Network data
|
||||
3. **Documented** all features comprehensively
|
||||
4. **Excluded** 372MB+ of unnecessary build artifacts
|
||||
5. **Committed** only essential source code (53 files)
|
||||
6. **Secured** repository with enterprise-grade practices
|
||||
7. **Prepared** for immediate production deployment
|
||||
|
||||
**The Lightning Policy Manager repository is now ready for:**
|
||||
- ✅ Open source collaboration
|
||||
- ✅ Production deployment
|
||||
- ✅ Professional development
|
||||
- ✅ Security-conscious operations
|
||||
- Open source collaboration
|
||||
- Production deployment
|
||||
- Professional development
|
||||
- Security-conscious operations
|
||||
|
||||
---
|
||||
|
||||
🎉 **Repository setup completed successfully!** The Lightning Policy Manager is now a properly organized, secure, and professional repository ready for use. 🚀
|
||||
**Repository setup completed successfully!** The Lightning Policy Manager is now a properly organized, secure, and professional repository ready for use.
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## What We Built
|
||||
|
||||
### 🧪 **Controlled Experimental Framework**
|
||||
### **Controlled Experimental Framework**
|
||||
- **Hypothesis Testing**: 5 specific testable hypotheses about Lightning fee optimization
|
||||
- **Scientific Method**: Control groups, randomized assignment, statistical analysis
|
||||
- **Risk Management**: Automatic rollbacks, safety limits, real-time monitoring
|
||||
@@ -16,7 +16,7 @@
|
||||
4. **H4: Inbound Fee Effectiveness** - Do inbound fees improve channel management?
|
||||
5. **H5: Time-Based Patterns** - Are there optimal times for fee adjustments?
|
||||
|
||||
### 🛠️ **Technical Implementation**
|
||||
### **Technical Implementation**
|
||||
|
||||
#### **Advanced Algorithms**
|
||||
- **Game Theory Integration**: Nash equilibrium considerations for competitive markets
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# ⚡ gRPC Upgrade: Supercharged LND Integration
|
||||
# gRPC Upgrade: Supercharged LND Integration
|
||||
|
||||
## 🚀 Why gRPC is Better Than REST
|
||||
## Why gRPC is Better Than REST
|
||||
|
||||
Our implementation now uses **gRPC as the primary LND interface** (with REST fallback), matching charge-lnd's proven approach but with significant improvements.
|
||||
|
||||
### 📊 Performance Comparison
|
||||
### Performance Comparison
|
||||
|
||||
| Metric | REST API | gRPC API | Improvement |
|
||||
|--------|----------|----------|-------------|
|
||||
@@ -15,7 +15,7 @@ Our implementation now uses **gRPC as the primary LND interface** (with REST fal
|
||||
| **Connection Pooling** | Manual | Built-in | **Automatic** |
|
||||
| **Error Handling** | HTTP status codes | Rich gRPC status | **More detailed** |
|
||||
|
||||
### 🔧 Technical Advantages
|
||||
### Technical Advantages
|
||||
|
||||
#### 1. **Native LND Interface**
|
||||
```python
|
||||
@@ -58,7 +58,7 @@ async with httpx.AsyncClient() as client:
|
||||
response2 = await client.post(url2, json=data2) # New connection
|
||||
```
|
||||
|
||||
## 🛠️ Our Implementation
|
||||
## Our Implementation
|
||||
|
||||
### Smart Dual-Protocol Support
|
||||
```python
|
||||
@@ -95,7 +95,7 @@ await lnd_client.update_channel_policy(
|
||||
# Automatically uses the fastest available protocol
|
||||
```
|
||||
|
||||
## ⚡ Real-World Performance
|
||||
## Real-World Performance
|
||||
|
||||
### Large Node Scenario (100 channels)
|
||||
```bash
|
||||
@@ -123,7 +123,7 @@ time ./lightning_policy.py apply --prefer-grpc
|
||||
# Low latency, persistent connection
|
||||
```
|
||||
|
||||
## 🔧 Setup & Usage
|
||||
## Setup & Usage
|
||||
|
||||
### 1. Install gRPC Dependencies
|
||||
```bash
|
||||
@@ -155,31 +155,31 @@ time ./lightning_policy.py apply --prefer-grpc
|
||||
--macaroon-path ~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
|
||||
```
|
||||
|
||||
## 📈 Compatibility Matrix
|
||||
## Compatibility Matrix
|
||||
|
||||
### LND Versions
|
||||
| LND Version | gRPC Support | Inbound Fees | Our Support |
|
||||
|-------------|--------------|--------------|-------------|
|
||||
| 0.17.x | ✅ Full | ❌ No | ✅ Works (no inbound) |
|
||||
| 0.18.0+ | ✅ Full | ✅ Yes | ✅ **Full features** |
|
||||
| 0.19.0+ | ✅ Enhanced | ✅ Enhanced | ✅ **Optimal** |
|
||||
| 0.17.x | Full | No | Works (no inbound) |
|
||||
| 0.18.0+ | Full | Yes | **Full features** |
|
||||
| 0.19.0+ | Enhanced | Enhanced | **Optimal** |
|
||||
|
||||
### Protocol Fallback Chain
|
||||
1. **gRPC** (localhost:10009) - *Preferred*
|
||||
2. **REST** (https://localhost:8080) - *Fallback*
|
||||
3. **Error** - Both failed
|
||||
|
||||
## 🎯 Migration from REST
|
||||
## Migration from REST
|
||||
|
||||
### Existing Users
|
||||
**No changes needed!** The system automatically detects and uses the best protocol.
|
||||
|
||||
### charge-lnd Users
|
||||
**Perfect compatibility!** We use the same gRPC approach as charge-lnd but with:
|
||||
- ✅ Advanced inbound fee strategies
|
||||
- ✅ Automatic rollback protection
|
||||
- ✅ Machine learning optimization
|
||||
- ✅ Performance monitoring
|
||||
- Advanced inbound fee strategies
|
||||
- Automatic rollback protection
|
||||
- Machine learning optimization
|
||||
- Performance monitoring
|
||||
|
||||
### Performance Testing
|
||||
```bash
|
||||
@@ -193,25 +193,25 @@ time ./lightning_policy.py apply --prefer-grpc
|
||||
./lightning_policy.py --prefer-rest -c config.conf apply --dry-run
|
||||
```
|
||||
|
||||
## 🏆 Summary
|
||||
## Summary
|
||||
|
||||
### ✅ Benefits Achieved
|
||||
### Benefits Achieved
|
||||
- **10x faster fee updates** via native gRPC
|
||||
- **5x less bandwidth** with binary protocols
|
||||
- **Better reliability** with connection pooling
|
||||
- **charge-lnd compatibility** using same gRPC approach
|
||||
- **Automatic fallback** ensures it always works
|
||||
|
||||
### 🚀 Performance Gains
|
||||
### Performance Gains
|
||||
- **Large nodes**: 15+ seconds → 2-3 seconds
|
||||
- **Daemon mode**: 100ms → 10ms per cycle
|
||||
- **Memory usage**: Reduced connection overhead
|
||||
- **Network efficiency**: Persistent connections
|
||||
|
||||
### 🔧 Zero Migration Effort
|
||||
### Zero Migration Effort
|
||||
- **Existing configs work unchanged**
|
||||
- **Same CLI commands**
|
||||
- **Automatic protocol detection**
|
||||
- **Graceful REST fallback**
|
||||
|
||||
**Your Lightning Policy Manager is now supercharged with gRPC while maintaining full backward compatibility!** ⚡🚀
|
||||
**Your Lightning Policy Manager is now supercharged with gRPC while maintaining full backward compatibility!**
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
A modern, intelligent fee management system that combines the flexibility of charge-lnd with advanced inbound fee strategies, machine learning, and automatic safety mechanisms.
|
||||
|
||||
## 🚀 Key Improvements Over charge-lnd
|
||||
## Key Improvements Over charge-lnd
|
||||
|
||||
### 1. **Advanced Inbound Fee Strategies**
|
||||
- **charge-lnd**: Basic inbound fee support (mostly negative discounts)
|
||||
@@ -73,7 +73,7 @@ flow.7d.min = 1000000 # Based on recent activity
|
||||
./lightning_policy.py daemon --watch --interval 10
|
||||
```
|
||||
|
||||
## 🔧 Installation & Setup
|
||||
## Installation & Setup
|
||||
|
||||
### Requirements
|
||||
```bash
|
||||
@@ -94,7 +94,7 @@ pip install httpx pydantic click pandas numpy tabulate python-dotenv
|
||||
./lightning_policy.py -c examples/my_policy.conf test-channel 123456x789x1
|
||||
```
|
||||
|
||||
## 📋 Configuration Syntax
|
||||
## Configuration Syntax
|
||||
|
||||
### Basic Structure (Compatible with charge-lnd)
|
||||
```ini
|
||||
@@ -134,7 +134,7 @@ min_fee_ppm = 100
|
||||
max_inbound_fee_ppm = 50
|
||||
```
|
||||
|
||||
## 🎯 Strategies Available
|
||||
## Strategies Available
|
||||
|
||||
| Strategy | Description | charge-lnd Equivalent |
|
||||
|----------|-------------|----------------------|
|
||||
@@ -145,7 +145,7 @@ max_inbound_fee_ppm = 50
|
||||
| `inbound_discount` | Focused on inbound fee optimization | New |
|
||||
| `cost_recovery` | Channel opening cost recovery | `cost` |
|
||||
|
||||
## 🚀 Usage Examples
|
||||
## Usage Examples
|
||||
|
||||
### 1. Basic Setup (Similar to charge-lnd)
|
||||
```bash
|
||||
@@ -184,7 +184,7 @@ max_inbound_fee_ppm = 50
|
||||
./lightning_policy.py -c examples/advanced_policy.conf test-channel 123456x789x1 --verbose
|
||||
```
|
||||
|
||||
## 🔄 Migration from charge-lnd
|
||||
## Migration from charge-lnd
|
||||
|
||||
### Step 1: Convert Configuration
|
||||
Most charge-lnd configurations work with minimal changes:
|
||||
@@ -227,7 +227,7 @@ rollback_threshold = 0.25 # Rollback if revenue drops >25%
|
||||
./lightning_policy.py -c migrated_config.conf daemon --watch
|
||||
```
|
||||
|
||||
## 📊 Performance Monitoring
|
||||
## Performance Monitoring
|
||||
|
||||
### Real-time Status
|
||||
```bash
|
||||
@@ -248,7 +248,7 @@ rollback_threshold = 0.25 # Rollback if revenue drops >25%
|
||||
./lightning_policy.py -c config.conf rollback --execute --macaroon-path ~/.lnd/admin.macaroon
|
||||
```
|
||||
|
||||
## 🎯 Inbound Fee Strategies
|
||||
## Inbound Fee Strategies
|
||||
|
||||
### Liquidity-Based Discounts
|
||||
```ini
|
||||
@@ -279,7 +279,7 @@ network.min_alternatives = 5
|
||||
# Automatically adjusts based on peer fee rates
|
||||
```
|
||||
|
||||
## ⚠️ Safety Features
|
||||
## Safety Features
|
||||
|
||||
### Automatic Rollbacks
|
||||
- Monitors revenue performance after fee changes
|
||||
@@ -334,7 +334,7 @@ strategy = revenue_max # Optimize mature, active channels
|
||||
learning_enabled = true
|
||||
```
|
||||
|
||||
## 📈 Expected Results
|
||||
## Expected Results
|
||||
|
||||
### Revenue Optimization
|
||||
- **10-30% revenue increase** through data-driven fee optimization
|
||||
@@ -351,7 +351,7 @@ learning_enabled = true
|
||||
- **Intelligent defaults** that learn from performance
|
||||
- **Comprehensive reporting** for decision making
|
||||
|
||||
## 🤝 Compatibility
|
||||
## Compatibility
|
||||
|
||||
### charge-lnd Migration
|
||||
- **100% compatible** configuration syntax
|
||||
@@ -363,14 +363,14 @@ learning_enabled = true
|
||||
- **Standard REST API** for fee changes
|
||||
- **Macaroon authentication** for security
|
||||
|
||||
## 🎉 Summary
|
||||
## Summary
|
||||
|
||||
This Lightning Policy Manager represents the **next evolution** of charge-lnd:
|
||||
|
||||
✅ **All charge-lnd features** + **advanced inbound fee strategies**
|
||||
✅ **Machine learning** + **automatic rollback protection**
|
||||
✅ **Revenue optimization** + **comprehensive safety mechanisms**
|
||||
✅ **Real-time monitoring** + **historical performance tracking**
|
||||
✅ **Easy migration** + **powerful new capabilities**
|
||||
**All charge-lnd features** + **advanced inbound fee strategies**
|
||||
**Machine learning** + **automatic rollback protection**
|
||||
**Revenue optimization** + **comprehensive safety mechanisms**
|
||||
**Real-time monitoring** + **historical performance tracking**
|
||||
**Easy migration** + **powerful new capabilities**
|
||||
|
||||
Perfect for node operators who want **intelligent, automated fee management** that **maximizes revenue** while **minimizing risk**.
|
||||
@@ -151,14 +151,14 @@ For each channel category, different optimization approaches:
|
||||
```
|
||||
Lightning Fee Optimizer
|
||||
|
||||
✅ Checking node connection...
|
||||
Checking node connection...
|
||||
📦 Current block height: 906504
|
||||
|
||||
📊 Fetching channel data...
|
||||
🔗 Found 41 channels
|
||||
Fetching channel data...
|
||||
Found 41 channels
|
||||
|
||||
🔬 Analyzing channel performance...
|
||||
✅ Successfully analyzed 41 channels
|
||||
Successfully analyzed 41 channels
|
||||
|
||||
╭────────────────────────────── Network Overview ──────────────────────────────╮
|
||||
│ Total Channels: 41 │
|
||||
@@ -176,7 +176,7 @@ High Performers: 8 channels
|
||||
│ 721508x1824x1 │ node_way_jose │ 87.5 │ 9,561 │ 65.5M │
|
||||
└───────────────┴────────────────┴───────┴────────┴───────┘
|
||||
|
||||
⚡ Generating fee optimization recommendations...
|
||||
Generating fee optimization recommendations...
|
||||
|
||||
╭────────────────────────── Fee Optimization Results ──────────────────────────╮
|
||||
│ Total Recommendations: 23 │
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
# 🛡️ SECURITY ANALYSIS REPORT
|
||||
# SECURITY ANALYSIS REPORT
|
||||
## Lightning Policy Manager - Complete Security Audit
|
||||
|
||||
---
|
||||
|
||||
## 🎯 **EXECUTIVE SUMMARY**
|
||||
## **EXECUTIVE SUMMARY**
|
||||
|
||||
**SECURITY STATUS: ✅ SECURE**
|
||||
**SECURITY STATUS: SECURE**
|
||||
|
||||
The Lightning Policy Manager has undergone comprehensive security analysis and hardening. **All identified vulnerabilities have been RESOLVED**. The system is now **SECURE for production use** with strict limitations to fee management operations only.
|
||||
|
||||
---
|
||||
|
||||
## 📋 **SECURITY AUDIT FINDINGS**
|
||||
## **SECURITY AUDIT FINDINGS**
|
||||
|
||||
### ✅ **RESOLVED CRITICAL VULNERABILITIES**
|
||||
### **RESOLVED CRITICAL VULNERABILITIES**
|
||||
|
||||
#### 1. **Initial gRPC Security Risk** - **RESOLVED**
|
||||
- **Risk:** Dangerous protobuf files with fund movement capabilities
|
||||
@@ -32,20 +32,20 @@ The Lightning Policy Manager has undergone comprehensive security analysis and h
|
||||
|
||||
---
|
||||
|
||||
## 🔒 **SECURITY MEASURES IMPLEMENTED**
|
||||
## **SECURITY MEASURES IMPLEMENTED**
|
||||
|
||||
### 1. **Secure gRPC Integration**
|
||||
|
||||
**Safe Protobuf Files Only:**
|
||||
```
|
||||
✅ lightning_pb2.py - Fee management operations only
|
||||
✅ lightning_pb2_grpc.py - Safe gRPC client stubs
|
||||
✅ __init__.py - Standard Python package file
|
||||
lightning_pb2.py - Fee management operations only
|
||||
lightning_pb2_grpc.py - Safe gRPC client stubs
|
||||
__init__.py - Standard Python package file
|
||||
|
||||
🚫 walletkit_pb2* - BLOCKED: Wallet operations (fund movement)
|
||||
🚫 signer_pb2* - BLOCKED: Private key operations
|
||||
🚫 router_pb2* - BLOCKED: Routing operations
|
||||
🚫 circuitbreaker_pb2* - BLOCKED: Advanced features
|
||||
walletkit_pb2* - BLOCKED: Wallet operations (fund movement)
|
||||
signer_pb2* - BLOCKED: Private key operations
|
||||
router_pb2* - BLOCKED: Routing operations
|
||||
circuitbreaker_pb2* - BLOCKED: Advanced features
|
||||
```
|
||||
|
||||
### 2. **Method Whitelisting System**
|
||||
@@ -92,7 +92,7 @@ def _validate_grpc_operation(method_name: str) -> bool:
|
||||
raise SecurityError("Potential fund theft attempt!")
|
||||
|
||||
if method_name not in ALLOWED_GRPC_METHODS:
|
||||
logger.error(f"🔒 Non-whitelisted method: {method_name}")
|
||||
logger.error(f"SECURITY: Non-whitelisted method: {method_name}")
|
||||
raise SecurityError("Method not whitelisted for fee management")
|
||||
|
||||
return True
|
||||
@@ -100,11 +100,11 @@ def _validate_grpc_operation(method_name: str) -> bool:
|
||||
|
||||
---
|
||||
|
||||
## 🔍 **COMPREHENSIVE SECURITY ANALYSIS**
|
||||
## **COMPREHENSIVE SECURITY ANALYSIS**
|
||||
|
||||
### **Network Operations Audit**
|
||||
|
||||
**✅ LEGITIMATE NETWORK CALLS ONLY:**
|
||||
**LEGITIMATE NETWORK CALLS ONLY:**
|
||||
|
||||
1. **LND Manage API (localhost:18081)**
|
||||
- Channel data retrieval
|
||||
@@ -120,7 +120,7 @@ def _validate_grpc_operation(method_name: str) -> bool:
|
||||
|
||||
### **File System Operations Audit**
|
||||
|
||||
**✅ LEGITIMATE FILE OPERATIONS ONLY:**
|
||||
**LEGITIMATE FILE OPERATIONS ONLY:**
|
||||
|
||||
- Configuration files (.conf)
|
||||
- Log files (policy.log, experiment.log)
|
||||
@@ -132,7 +132,7 @@ def _validate_grpc_operation(method_name: str) -> bool:
|
||||
|
||||
### **Authentication & Authorization**
|
||||
|
||||
**✅ PROPER SECURITY MECHANISMS:**
|
||||
**PROPER SECURITY MECHANISMS:**
|
||||
|
||||
- LND macaroon authentication (industry standard)
|
||||
- TLS certificate verification
|
||||
@@ -142,7 +142,7 @@ def _validate_grpc_operation(method_name: str) -> bool:
|
||||
|
||||
### **Business Logic Verification**
|
||||
|
||||
**✅ LEGITIMATE LIGHTNING OPERATIONS ONLY:**
|
||||
**LEGITIMATE LIGHTNING OPERATIONS ONLY:**
|
||||
|
||||
1. **Channel fee policy updates** (ONLY write operation)
|
||||
2. **Performance tracking** (for optimization)
|
||||
@@ -154,7 +154,7 @@ def _validate_grpc_operation(method_name: str) -> bool:
|
||||
|
||||
---
|
||||
|
||||
## 🛡️ **SECURITY FEATURES**
|
||||
## **SECURITY FEATURES**
|
||||
|
||||
### 1. **Defense in Depth**
|
||||
- Multiple layers of security validation
|
||||
@@ -182,29 +182,29 @@ def _validate_grpc_operation(method_name: str) -> bool:
|
||||
|
||||
---
|
||||
|
||||
## 🎯 **SECURITY TEST RESULTS**
|
||||
## **SECURITY TEST RESULTS**
|
||||
|
||||
### **Penetration Testing**
|
||||
✅ **PASSED:** No unauthorized operations possible
|
||||
✅ **PASSED:** Dangerous methods properly blocked
|
||||
✅ **PASSED:** Security validation functioning
|
||||
✅ **PASSED:** Fallback mechanisms secure
|
||||
**PASSED:** No unauthorized operations possible
|
||||
**PASSED:** Dangerous methods properly blocked
|
||||
**PASSED:** Security validation functioning
|
||||
**PASSED:** Fallback mechanisms secure
|
||||
|
||||
### **Code Audit Results**
|
||||
✅ **PASSED:** No malicious code detected
|
||||
✅ **PASSED:** All network calls legitimate
|
||||
✅ **PASSED:** File operations appropriate
|
||||
✅ **PASSED:** No backdoors or hidden functionality
|
||||
**PASSED:** No malicious code detected
|
||||
**PASSED:** All network calls legitimate
|
||||
**PASSED:** File operations appropriate
|
||||
**PASSED:** No backdoors or hidden functionality
|
||||
|
||||
### **Runtime Security Testing**
|
||||
✅ **PASSED:** Method whitelisting enforced
|
||||
✅ **PASSED:** Security violations detected and blocked
|
||||
✅ **PASSED:** Logging and monitoring functional
|
||||
✅ **PASSED:** Error handling secure
|
||||
**PASSED:** Method whitelisting enforced
|
||||
**PASSED:** Security violations detected and blocked
|
||||
**PASSED:** Logging and monitoring functional
|
||||
**PASSED:** Error handling secure
|
||||
|
||||
---
|
||||
|
||||
## 📊 **COMPARISON: Before vs After Security Hardening**
|
||||
## **COMPARISON: Before vs After Security Hardening**
|
||||
|
||||
| Security Aspect | Before | After |
|
||||
|-----------------|---------|-------|
|
||||
@@ -239,26 +239,26 @@ lncli bakemacaroon offchain:read offchain:write onchain:read info:read \
|
||||
|
||||
---
|
||||
|
||||
## 🏆 **FINAL SECURITY VERDICT**
|
||||
## **FINAL SECURITY VERDICT**
|
||||
|
||||
### ✅ **APPROVED FOR PRODUCTION USE**
|
||||
### **APPROVED FOR PRODUCTION USE**
|
||||
|
||||
**The Lightning Policy Manager is SECURE and ready for production deployment:**
|
||||
|
||||
1. **✅ NO fund movement capabilities**
|
||||
2. **✅ NO private key access**
|
||||
3. **✅ NO wallet operations**
|
||||
4. **✅ ONLY fee management operations**
|
||||
5. **✅ Comprehensive security monitoring**
|
||||
6. **✅ Defense-in-depth architecture**
|
||||
7. **✅ Secure development practices**
|
||||
8. **✅ Professional security audit completed**
|
||||
1. **NO fund movement capabilities**
|
||||
2. **NO private key access**
|
||||
3. **NO wallet operations**
|
||||
4. **ONLY fee management operations**
|
||||
5. **Comprehensive security monitoring**
|
||||
6. **Defense-in-depth architecture**
|
||||
7. **Secure development practices**
|
||||
8. **Professional security audit completed**
|
||||
|
||||
### 📈 **Security Confidence Level: HIGH**
|
||||
### **Security Confidence Level: HIGH**
|
||||
|
||||
This system demonstrates **enterprise-grade security practices** appropriate for **production Lightning Network deployments** with **financial assets at risk**.
|
||||
|
||||
**RECOMMENDATION: DEPLOY WITH CONFIDENCE** 🚀
|
||||
**RECOMMENDATION: DEPLOY WITH CONFIDENCE**
|
||||
|
||||
---
|
||||
|
||||
@@ -270,6 +270,6 @@ For security concerns or questions about this analysis:
|
||||
- Test in dry-run mode for additional safety
|
||||
- Use limited-permission macaroons only
|
||||
|
||||
**Security Audit Completed: ✅**
|
||||
**Security Audit Completed: YES**
|
||||
**Status: PRODUCTION READY**
|
||||
**Risk Level: LOW**
|
||||
@@ -257,7 +257,7 @@ class CLIExperimentRunner:
|
||||
new_fee = change.get('new_fee', 'N/A')
|
||||
reason = change['reason'][:50] + "..." if len(change['reason']) > 50 else change['reason']
|
||||
|
||||
status_indicator = "🔙" if is_rollback else "⚡"
|
||||
status_indicator = "ROLLBACK" if is_rollback else "UPDATE"
|
||||
|
||||
table_data.append([
|
||||
change['timestamp'].strftime('%H:%M:%S'),
|
||||
@@ -278,7 +278,7 @@ class CLIExperimentRunner:
|
||||
return False
|
||||
|
||||
try:
|
||||
print(f"⚡ Running experiment cycle...")
|
||||
print(f"Running experiment cycle...")
|
||||
|
||||
# Monkey patch the fee application if dry run
|
||||
if dry_run:
|
||||
@@ -369,9 +369,9 @@ def init(ctx, duration, macaroon_path, cert_path, dry_run):
|
||||
print("Use --dry-run to simulate without LND connection")
|
||||
return
|
||||
else:
|
||||
print("🧪 Running in DRY-RUN mode (no actual fee changes)")
|
||||
print("Running in DRY-RUN mode (no actual fee changes)")
|
||||
|
||||
print("📊 Analyzing channels and assigning segments...")
|
||||
print("Analyzing channels and assigning segments...")
|
||||
success = await runner.controller.initialize_experiment(duration)
|
||||
|
||||
if success:
|
||||
@@ -484,7 +484,7 @@ def run(ctx, interval, max_cycles, dry_run, macaroon_path, cert_path):
|
||||
print("Use --dry-run to simulate")
|
||||
return
|
||||
|
||||
print(f"🚀 Starting experiment run (interval: {interval} minutes)")
|
||||
print(f"Starting experiment run (interval: {interval} minutes)")
|
||||
if max_cycles:
|
||||
print(f"Will run maximum {max_cycles} cycles")
|
||||
print("Press Ctrl+C to stop")
|
||||
@@ -501,11 +501,11 @@ def run(ctx, interval, max_cycles, dry_run, macaroon_path, cert_path):
|
||||
should_continue = await runner.run_single_cycle(dry_run)
|
||||
|
||||
if not should_continue:
|
||||
print("🎉 Experiment completed!")
|
||||
print("Experiment completed!")
|
||||
break
|
||||
|
||||
if max_cycles and cycle_count >= max_cycles:
|
||||
print(f"📊 Reached maximum cycles ({max_cycles})")
|
||||
print(f"Reached maximum cycles ({max_cycles})")
|
||||
break
|
||||
|
||||
print(f"⏳ Waiting {interval} minutes until next cycle...")
|
||||
@@ -517,7 +517,7 @@ def run(ctx, interval, max_cycles, dry_run, macaroon_path, cert_path):
|
||||
await asyncio.sleep(1)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n⏹️ Experiment stopped by user")
|
||||
print("\nExperiment stopped by user")
|
||||
|
||||
print("Generating final report...")
|
||||
runner.save_report()
|
||||
@@ -559,7 +559,7 @@ def reset(ctx, backup):
|
||||
runner.controller.experiment_start = None
|
||||
runner.controller.current_phase = ExperimentPhase.BASELINE
|
||||
|
||||
print("🔄 Experiment reset. Use 'init' to start new experiment.")
|
||||
print("Experiment reset. Use 'init' to start new experiment.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -90,10 +90,10 @@ def apply(ctx, dry_run, macaroon_path, cert_path):
|
||||
|
||||
async def _apply():
|
||||
if dry_run:
|
||||
print("🧪 DRY-RUN MODE: Showing policy recommendations without applying changes")
|
||||
print("DRY-RUN MODE: Showing policy recommendations without applying changes")
|
||||
else:
|
||||
protocol = "gRPC" if ctx.obj.get('prefer_grpc', True) else "REST"
|
||||
print(f"⚡ Applying policy-based fee changes via {protocol} API...")
|
||||
print(f"Applying policy-based fee changes via {protocol} API...")
|
||||
|
||||
results = await manager.apply_policies(
|
||||
dry_run=dry_run,
|
||||
@@ -200,7 +200,7 @@ def rollback(ctx, execute, macaroon_path, cert_path):
|
||||
manager = ctx.obj['manager']
|
||||
|
||||
async def _rollback():
|
||||
print("🔍 Checking rollback conditions...")
|
||||
print("Checking rollback conditions...")
|
||||
|
||||
rollback_info = await manager.check_rollback_conditions()
|
||||
|
||||
@@ -229,7 +229,7 @@ def rollback(ctx, execute, macaroon_path, cert_path):
|
||||
tablefmt="grid"))
|
||||
|
||||
if execute:
|
||||
print(f"\n⚡ Executing {len(rollback_info['actions'])} rollbacks...")
|
||||
print(f"\nExecuting {len(rollback_info['actions'])} rollbacks...")
|
||||
|
||||
# Initialize LND connection
|
||||
from src.experiment.lnd_integration import LNDRestClient
|
||||
@@ -254,7 +254,7 @@ def rollback(ctx, execute, macaroon_path, cert_path):
|
||||
for error in rollback_results['errors']:
|
||||
print(f"• {error}")
|
||||
else:
|
||||
print(f"\n🧪 DRY-RUN: Use --execute to actually perform rollbacks")
|
||||
print(f"\nDRY-RUN: Use --execute to actually perform rollbacks")
|
||||
|
||||
asyncio.run(_rollback())
|
||||
|
||||
@@ -389,7 +389,7 @@ def daemon(ctx, watch, interval, macaroon_path, cert_path):
|
||||
print(f"Applied {results['fee_changes']} fee changes")
|
||||
|
||||
if results['errors']:
|
||||
print(f"⚠️ {len(results['errors'])} errors occurred")
|
||||
print(f"WARNING: {len(results['errors'])} errors occurred")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Policy application failed: {e}")
|
||||
@@ -437,7 +437,7 @@ def test_channel(ctx, channel_id, verbose):
|
||||
manager = ctx.obj['manager']
|
||||
|
||||
async def _test():
|
||||
print(f"🔍 Testing policy evaluation for channel: {channel_id}")
|
||||
print(f"Testing policy evaluation for channel: {channel_id}")
|
||||
|
||||
# Get channel data
|
||||
from src.api.client import LndManageClient
|
||||
|
||||
@@ -65,7 +65,7 @@ class ExperimentRunner:
|
||||
console.print("")
|
||||
|
||||
# Initialize experiment
|
||||
console.print("[cyan]📊 Initializing experiment...[/cyan]")
|
||||
console.print("[cyan]Initializing experiment...[/cyan]")
|
||||
try:
|
||||
success = await self.controller.initialize_experiment(duration_days)
|
||||
if not success:
|
||||
@@ -75,7 +75,7 @@ class ExperimentRunner:
|
||||
console.print(f"[red]❌ Initialization failed: {e}[/red]")
|
||||
return
|
||||
|
||||
console.print("[green]✅ Experiment initialized successfully[/green]")
|
||||
console.print("[green]Experiment initialized successfully[/green]")
|
||||
|
||||
# Display experiment setup
|
||||
self._display_experiment_setup()
|
||||
@@ -90,7 +90,7 @@ class ExperimentRunner:
|
||||
should_continue = await self.controller.run_experiment_cycle()
|
||||
|
||||
if not should_continue:
|
||||
console.print("\n[green]🎉 Experiment completed successfully![/green]")
|
||||
console.print("\n[green]Experiment completed successfully![/green]")
|
||||
break
|
||||
|
||||
self.cycle_count += 1
|
||||
@@ -135,7 +135,7 @@ Safety Limits:
|
||||
• Rollback triggers: {self.controller.ROLLBACK_REVENUE_THRESHOLD:.0%} revenue drop or {self.controller.ROLLBACK_FLOW_THRESHOLD:.0%} flow reduction
|
||||
"""
|
||||
|
||||
console.print(Panel(setup_info.strip(), title="📋 Experiment Setup"))
|
||||
console.print(Panel(setup_info.strip(), title="Experiment Setup"))
|
||||
|
||||
def _create_status_display(self):
|
||||
"""Create live status display"""
|
||||
@@ -201,8 +201,8 @@ Safety Limits:
|
||||
# Combine displays
|
||||
from rich.columns import Columns
|
||||
|
||||
status_panel = Panel(status_table, title="📊 Experiment Status")
|
||||
activity_panel = Panel(activity_table, title="⚡ Recent Activity")
|
||||
status_panel = Panel(status_table, title="Experiment Status")
|
||||
activity_panel = Panel(activity_table, title="Recent Activity")
|
||||
|
||||
return Columns([status_panel, activity_panel], equal=True)
|
||||
|
||||
@@ -233,7 +233,7 @@ Safety Limits:
|
||||
async def _generate_final_report(self):
|
||||
"""Generate and display final experiment report"""
|
||||
|
||||
console.print("\n[cyan]📋 Generating final experiment report...[/cyan]")
|
||||
console.print("\n[cyan]Generating final experiment report...[/cyan]")
|
||||
|
||||
try:
|
||||
report = self.controller.generate_experiment_report()
|
||||
@@ -250,11 +250,11 @@ Phases Completed: {', '.join(report['experiment_summary']['phases_completed'])}
|
||||
Safety Events: {len(report['safety_events'])} rollbacks occurred
|
||||
"""
|
||||
|
||||
console.print(Panel(summary_text.strip(), title="📊 Final Results"))
|
||||
console.print(Panel(summary_text.strip(), title="Final Results"))
|
||||
|
||||
# Performance by group
|
||||
if report['performance_by_group']:
|
||||
console.print("\n[bold]📈 Performance by Group[/bold]")
|
||||
console.print("\n[bold]Performance by Group[/bold]")
|
||||
|
||||
perf_table = Table(show_header=True, header_style="bold magenta")
|
||||
perf_table.add_column("Group")
|
||||
@@ -276,7 +276,7 @@ Safety Events: {len(report['safety_events'])} rollbacks occurred
|
||||
|
||||
# Safety events
|
||||
if report['safety_events']:
|
||||
console.print("\n[bold yellow]⚠️ Safety Events[/bold yellow]")
|
||||
console.print("\n[bold yellow]Safety Events[/bold yellow]")
|
||||
|
||||
safety_table = Table(show_header=True)
|
||||
safety_table.add_column("Channel")
|
||||
@@ -300,7 +300,7 @@ Safety Events: {len(report['safety_events'])} rollbacks occurred
|
||||
with open(report_path, 'w') as f:
|
||||
json.dump(report, f, indent=2, default=str)
|
||||
|
||||
console.print(f"\n[green]📄 Detailed report saved to {report_path}[/green]")
|
||||
console.print(f"\n[green]Detailed report saved to {report_path}[/green]")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to generate report: {e}")
|
||||
@@ -322,7 +322,7 @@ def main(lnd_manage_url: str, lnd_rest_url: str, config: str, duration: int, int
|
||||
console.print("[yellow]🔬 Running in DRY-RUN mode - no actual fee changes will be made[/yellow]")
|
||||
|
||||
if resume:
|
||||
console.print("[cyan]🔄 Attempting to resume existing experiment...[/cyan]")
|
||||
console.print("[cyan]Attempting to resume existing experiment...[/cyan]")
|
||||
|
||||
try:
|
||||
runner = ExperimentRunner(lnd_manage_url, lnd_rest_url, config)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
echo "⚡ Lightning Fee Optimizer - Advanced Inbound Fee Strategy"
|
||||
echo "Lightning Fee Optimizer - Advanced Inbound Fee Strategy"
|
||||
echo "========================================================="
|
||||
echo ""
|
||||
echo "This strategy uses BOTH outbound and inbound fees for optimal liquidity management:"
|
||||
@@ -26,7 +26,7 @@ echo ""
|
||||
|
||||
read -p "Have you added 'accept-positive-inbound-fees=true' to lnd.conf? (yes/no): " inbound_ready
|
||||
if [[ $inbound_ready != "yes" ]]; then
|
||||
echo "⚠️ Please add 'accept-positive-inbound-fees=true' to lnd.conf and restart LND first"
|
||||
echo "WARNING: Please add 'accept-positive-inbound-fees=true' to lnd.conf and restart LND first"
|
||||
echo "This enables positive inbound fees for advanced liquidity management"
|
||||
exit 1
|
||||
fi
|
||||
@@ -74,12 +74,12 @@ update_channel_advanced() {
|
||||
# Uncomment to execute:
|
||||
# eval $cmd
|
||||
|
||||
echo "✅ Advanced policy prepared (not executed)"
|
||||
echo "Advanced policy prepared (not executed)"
|
||||
echo ""
|
||||
}
|
||||
|
||||
echo ""
|
||||
echo "🛡️ DRAIN PROTECTION STRATEGY"
|
||||
echo "DRAIN PROTECTION STRATEGY"
|
||||
echo "Protect high-earning channels from being drained by setting inbound fees"
|
||||
echo ""
|
||||
|
||||
@@ -102,7 +102,7 @@ update_channel_advanced "900023x1554x0" 22 -15 0 "Channel has 99.9% local balanc
|
||||
update_channel_advanced "903561x1516x0" 72 -25 0 "Overly balanced channel - encourage some inbound flow" "LIQUIDITY_ATTRACTION"
|
||||
|
||||
echo ""
|
||||
echo "⚖️ BALANCED OPTIMIZATION STRATEGY"
|
||||
echo "BALANCED OPTIMIZATION STRATEGY"
|
||||
echo "Fine-tune both inbound and outbound fees on high-performing channels"
|
||||
echo ""
|
||||
|
||||
@@ -114,7 +114,7 @@ update_channel_advanced "890401x1900x1" 11 5 0 "Strong performer - minimal inbou
|
||||
update_channel_advanced "721508x1824x1" 11 5 0 "Excellent flow - minimal inbound adjustment" "BALANCED_OPTIMIZATION"
|
||||
|
||||
echo ""
|
||||
echo "🔄 FLOW OPTIMIZATION STRATEGY"
|
||||
echo "FLOW OPTIMIZATION STRATEGY"
|
||||
echo "Optimize bidirectional flow with asymmetric fee strategies"
|
||||
echo ""
|
||||
|
||||
@@ -125,7 +125,7 @@ update_channel_advanced "904664x2249x4" 104 10 0 "Well balanced - small inbound
|
||||
update_channel_advanced "903294x1253x1" 102 10 0 "Good balance - small inbound fee to preserve" "FLOW_OPTIMIZATION"
|
||||
|
||||
echo ""
|
||||
echo "🚀 ACTIVATION STRATEGY"
|
||||
echo "ACTIVATION STRATEGY"
|
||||
echo "Use aggressive inbound discounts to activate dormant channels"
|
||||
echo ""
|
||||
|
||||
@@ -135,7 +135,7 @@ update_channel_advanced "691153x813x1" 7 -30 0 "Low activity - large inbound dis
|
||||
update_channel_advanced "896882x554x1" 49 -40 0 "Underused channel - significant inbound discount" "ACTIVATION"
|
||||
|
||||
echo ""
|
||||
echo "📊 MONITORING COMMANDS FOR INBOUND FEES"
|
||||
echo "MONITORING COMMANDS FOR INBOUND FEES"
|
||||
echo "════════════════════════════════════════"
|
||||
echo ""
|
||||
|
||||
@@ -155,10 +155,10 @@ echo "# Track forwarding events with fee breakdown:"
|
||||
echo "lncli fwdinghistory --max_events 20 | jq '.forwarding_events[] | {chan_id_in, chan_id_out, fee_msat, amt_msat}'"
|
||||
|
||||
echo ""
|
||||
echo "⚡ INBOUND FEE STRATEGY EXPLANATION"
|
||||
echo "INBOUND FEE STRATEGY EXPLANATION"
|
||||
echo "══════════════════════════════════════"
|
||||
echo ""
|
||||
echo "🛡️ DRAIN PROTECTION: Positive inbound fees (50-150 ppm)"
|
||||
echo "DRAIN PROTECTION: Positive inbound fees (50-150 ppm)"
|
||||
echo " • Discourages peers from pushing all their funds through you"
|
||||
echo " • Compensates you for the liquidity service"
|
||||
echo " • Protects your most valuable routing channels"
|
||||
@@ -168,16 +168,16 @@ echo " • Provides discounts to encourage inbound payments"
|
||||
echo " • Helps rebalance channels with too much local liquidity"
|
||||
echo " • Backwards compatible (older nodes see it as regular discount)"
|
||||
echo ""
|
||||
echo "⚖️ BALANCED OPTIMIZATION: Small positive inbound fees (5-25 ppm)"
|
||||
echo "BALANCED OPTIMIZATION: Small positive inbound fees (5-25 ppm)"
|
||||
echo " • Fine-tunes flow on high-performing channels"
|
||||
echo " • Prevents over-utilization in one direction"
|
||||
echo " • Maximizes total fee income"
|
||||
echo ""
|
||||
echo "🔄 FLOW OPTIMIZATION: Mixed strategy based on current balance"
|
||||
echo "FLOW OPTIMIZATION: Mixed strategy based on current balance"
|
||||
echo " • Asymmetric fees to encourage bidirectional flow"
|
||||
echo " • Dynamic based on current liquidity distribution"
|
||||
echo ""
|
||||
echo "🚀 ACTIVATION: Aggressive negative inbound fees (-30 to -50 ppm)"
|
||||
echo "ACTIVATION: Aggressive negative inbound fees (-30 to -50 ppm)"
|
||||
echo " • Last resort for dormant channels"
|
||||
echo " • Makes your channels very attractive for routing"
|
||||
echo " • Higher risk but potential for activation"
|
||||
@@ -194,7 +194,7 @@ echo ""
|
||||
echo "Total estimated additional benefit: +10,000-20,000 sats/month"
|
||||
|
||||
echo ""
|
||||
echo "⚠️ IMPLEMENTATION NOTES"
|
||||
echo "IMPLEMENTATION NOTES"
|
||||
echo "════════════════════════════"
|
||||
echo ""
|
||||
echo "1. COMPATIBILITY: Inbound fees require updated nodes"
|
||||
@@ -204,7 +204,7 @@ echo "4. GRADUAL: Apply inbound fee strategy gradually over 2-3 weeks"
|
||||
echo "5. BALANCE: Keep total fees (inbound + outbound) reasonable"
|
||||
|
||||
echo ""
|
||||
echo "🔧 ROLLBACK COMMANDS (inbound fees back to 0)"
|
||||
echo "ROLLBACK COMMANDS (inbound fees back to 0)"
|
||||
echo "═══════════════════════════════════════════════"
|
||||
echo ""
|
||||
echo "# Remove all inbound fees (set to 0):"
|
||||
@@ -221,5 +221,5 @@ echo "3. Uncomment the 'eval \$cmd' line"
|
||||
echo "4. Apply in phases: Drain Protection → Liquidity Attraction → Optimization"
|
||||
echo "5. Monitor routing success rates closely"
|
||||
echo ""
|
||||
echo "📈 This advanced strategy should increase your monthly revenue by 35-40% total"
|
||||
echo "This advanced strategy should increase your monthly revenue by 35-40% total"
|
||||
echo " (24.6% from outbound optimization + 10-15% from inbound fee management)"
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
echo "🔍 Lightning Fee Optimizer - Fee Update Script"
|
||||
echo "⚠️ WARNING: This will modify your channel fees!"
|
||||
echo "Lightning Fee Optimizer - Fee Update Script"
|
||||
echo "WARNING: This will modify your channel fees!"
|
||||
echo ""
|
||||
read -p "Are you sure you want to continue? (yes/no): " confirm
|
||||
|
||||
@@ -26,7 +26,7 @@ if [[ $confirm != "yes" ]]; then
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "📊 Applying fee recommendations..."
|
||||
echo "Applying fee recommendations..."
|
||||
echo "💾 Consider backing up current policies first:"
|
||||
echo " lncli describegraph > channel_policies_backup.json"
|
||||
echo ""
|
||||
@@ -76,7 +76,7 @@ update_channel_fee() {
|
||||
# Uncomment the next line to actually execute the command
|
||||
# eval $cmd
|
||||
|
||||
echo "✅ Command prepared (not executed - remove comments to apply)"
|
||||
echo "Command prepared (not executed - remove comments to apply)"
|
||||
echo ""
|
||||
}
|
||||
|
||||
@@ -179,15 +179,15 @@ echo "lncli updatechanpolicy --chan_id 845867x2612x0 --fee_rate 100"
|
||||
echo "# ... (add more as needed)"
|
||||
|
||||
echo ""
|
||||
echo "🎯 IMPLEMENTATION STRATEGY:"
|
||||
echo "IMPLEMENTATION STRATEGY:"
|
||||
echo "1. Start with HIGH PRIORITY recommendations (high confidence)"
|
||||
echo "2. Wait 24-48 hours and monitor routing activity"
|
||||
echo "3. Apply MEDIUM PRIORITY balance management changes gradually"
|
||||
echo "4. Monitor for 1 week before applying low activity changes"
|
||||
echo "5. Keep detailed logs of what you change and when"
|
||||
echo ""
|
||||
echo "⚠️ Remember: Channel fee changes take time to propagate through the network!"
|
||||
echo "📊 Monitor your earnings and routing activity after each change."
|
||||
echo "WARNING: Remember: Channel fee changes take time to propagate through the network!"
|
||||
echo "Monitor your earnings and routing activity after each change."
|
||||
echo ""
|
||||
echo "To execute this script and actually apply changes:"
|
||||
echo "1. Review each command carefully"
|
||||
|
||||
@@ -12,7 +12,7 @@ echo "PREREQUISITE: Add to lnd.conf and restart LND:"
|
||||
echo "accept-positive-inbound-fees=true"
|
||||
echo ""
|
||||
|
||||
echo "🛡️ PHASE 1: DRAIN PROTECTION (Apply first)"
|
||||
echo "PHASE 1: DRAIN PROTECTION (Apply first)"
|
||||
echo "Protect your most valuable channels from being drained"
|
||||
echo ""
|
||||
|
||||
@@ -23,7 +23,7 @@ echo "lncli updatechanpolicy --chan_id 691130x155x1 --fee_rate 282 --base_fee_ms
|
||||
echo "lncli updatechanpolicy --chan_id 903613x2575x1 --fee_rate 303 --base_fee_msat 0 --time_lock_delta 80 --inbound_fee_rate_ppm 100 --inbound_base_fee_msat 0 # Moderate protection"
|
||||
echo ""
|
||||
|
||||
echo "⚡ PHASE 2: HIGH-PERFORMANCE OPTIMIZATION (Apply after 48h)"
|
||||
echo "PHASE 2: HIGH-PERFORMANCE OPTIMIZATION (Apply after 48h)"
|
||||
echo "Optimize your best channels with small inbound fees for balance"
|
||||
echo ""
|
||||
|
||||
@@ -46,7 +46,7 @@ echo "lncli updatechanpolicy --chan_id 900023x1554x0 --fee_rate 22 --base_fee_ms
|
||||
echo "lncli updatechanpolicy --chan_id 893297x1850x1 --fee_rate 23 --base_fee_msat 0 --time_lock_delta 80 --inbound_fee_rate_ppm -10 --inbound_base_fee_msat 0 # Too much local"
|
||||
echo ""
|
||||
|
||||
echo "🚀 PHASE 4: DORMANT CHANNEL ACTIVATION (Apply after 2 weeks)"
|
||||
echo "PHASE 4: DORMANT CHANNEL ACTIVATION (Apply after 2 weeks)"
|
||||
echo "Aggressive inbound discounts to try activating unused channels"
|
||||
echo ""
|
||||
|
||||
@@ -56,7 +56,7 @@ echo "lncli updatechanpolicy --chan_id 691153x813x1 --fee_rate 7 --base_fee_msat
|
||||
echo "lncli updatechanpolicy --chan_id 896882x554x1 --fee_rate 49 --base_fee_msat 0 --time_lock_delta 80 --inbound_fee_rate_ppm -40 --inbound_base_fee_msat 0 # Low activity"
|
||||
echo ""
|
||||
|
||||
echo "📊 MONITORING COMMANDS"
|
||||
echo "MONITORING COMMANDS"
|
||||
echo "═══════════════════════"
|
||||
echo ""
|
||||
|
||||
@@ -76,7 +76,7 @@ echo "# Check for routing failures (inbound fee related):"
|
||||
echo "lncli listpayments | jq '.payments[-10:] | .[] | select(.status==\"FAILED\") | {creation_date, failure_reason}'"
|
||||
|
||||
echo ""
|
||||
echo "🎯 INBOUND FEE STRATEGY SUMMARY"
|
||||
echo "INBOUND FEE STRATEGY SUMMARY"
|
||||
echo "═══════════════════════════════"
|
||||
echo ""
|
||||
echo "POSITIVE INBOUND FEES (+5 to +150 ppm):"
|
||||
@@ -109,7 +109,7 @@ echo "Original estimate was: +24.6% (outbound only)"
|
||||
echo "Additional from inbound: +10-20% (inbound optimization)"
|
||||
|
||||
echo ""
|
||||
echo "⚠️ SAFETY CONSIDERATIONS"
|
||||
echo "SAFETY CONSIDERATIONS"
|
||||
echo "═════════════════════════"
|
||||
echo ""
|
||||
echo "1. COMPATIBILITY: Some older nodes may not understand positive inbound fees"
|
||||
@@ -119,7 +119,7 @@ echo "4. TOTAL FEES: Keep combined inbound+outbound fees competitive"
|
||||
echo "5. MARKET RESPONSE: Other nodes may adjust their fees in response"
|
||||
|
||||
echo ""
|
||||
echo "🔧 QUICK ROLLBACK (remove all inbound fees)"
|
||||
echo "QUICK ROLLBACK (remove all inbound fees)"
|
||||
echo "═══════════════════════════════════════════"
|
||||
echo ""
|
||||
echo "# Reset all inbound fees to 0 (keep outbound changes):"
|
||||
@@ -135,7 +135,7 @@ echo "lncli updatechanpolicy --chan_id 779651x576x1 --fee_rate 10 --inbound_fee_
|
||||
echo "lncli updatechanpolicy --chan_id 880360x2328x1 --fee_rate 88 --inbound_fee_rate_ppm 0"
|
||||
|
||||
echo ""
|
||||
echo "📈 IMPLEMENTATION TIMELINE"
|
||||
echo "IMPLEMENTATION TIMELINE"
|
||||
echo "═════════════════════════"
|
||||
echo ""
|
||||
echo "Week 1: Phase 1 (Drain Protection) + monitor routing success"
|
||||
@@ -143,4 +143,4 @@ echo "Week 2: Phase 2 (Performance Optimization) + assess balance impact"
|
||||
echo "Week 3: Phase 3 (Liquidity Rebalancing) + monitor channel health"
|
||||
echo "Week 4: Phase 4 (Dormant Activation) + evaluate overall performance"
|
||||
echo ""
|
||||
echo "🎯 Expected Result: 35-45% total revenue increase with better channel longevity"
|
||||
echo "Expected Result: 35-45% total revenue increase with better channel longevity"
|
||||
@@ -29,7 +29,7 @@ echo "lncli updatechanpolicy --chan_id 721508x1824x1 --fee_rate 11 # 10→11 p
|
||||
echo "lncli updatechanpolicy --chan_id 776941x111x1 --fee_rate 11 # 10→11 ppm (+10%) - B4BYM"
|
||||
echo ""
|
||||
|
||||
echo "⚖️ BALANCE MANAGEMENT RECOMMENDATIONS (Monitor closely)"
|
||||
echo "BALANCE MANAGEMENT RECOMMENDATIONS (Monitor closely)"
|
||||
echo "These address channel liquidity imbalances:"
|
||||
echo ""
|
||||
|
||||
@@ -53,7 +53,7 @@ echo "lncli updatechanpolicy --chan_id 878853x1612x1 --fee_rate 445 # 297→445
|
||||
echo "lncli updatechanpolicy --chan_id 799714x355x0 --fee_rate 367 # 245→367 ppm (+49.8%)"
|
||||
echo ""
|
||||
|
||||
echo "🔄 LOW ACTIVITY CHANNEL ACTIVATION (Lower confidence)"
|
||||
echo "LOW ACTIVITY CHANNEL ACTIVATION (Lower confidence)"
|
||||
echo "Reduce fees to try activating dormant channels:"
|
||||
echo ""
|
||||
|
||||
@@ -63,7 +63,7 @@ echo "lncli updatechanpolicy --chan_id 691153x813x1 --fee_rate 7 # 10→7 pp
|
||||
echo "lncli updatechanpolicy --chan_id 896882x554x1 --fee_rate 49 # 71→49 ppm (-31%)"
|
||||
echo ""
|
||||
|
||||
echo "📊 MONITORING COMMANDS"
|
||||
echo "MONITORING COMMANDS"
|
||||
echo "Use these to track your changes:"
|
||||
echo ""
|
||||
|
||||
@@ -79,7 +79,7 @@ echo "# Check specific channel balance:"
|
||||
echo "lncli listchannels --chan_id CHANNEL_ID"
|
||||
echo ""
|
||||
|
||||
echo "🚀 RECOMMENDED IMPLEMENTATION ORDER:"
|
||||
echo "RECOMMENDED IMPLEMENTATION ORDER:"
|
||||
echo ""
|
||||
echo "Week 1: Apply HIGH CONFIDENCE recommendations (10 channels)"
|
||||
echo " Expected revenue increase: ~+15,000 sats/month"
|
||||
@@ -94,7 +94,7 @@ echo "Week 4: Try low activity activation (3 channels)"
|
||||
echo " Lowest confidence - may not have significant impact"
|
||||
echo ""
|
||||
|
||||
echo "⚠️ SAFETY REMINDERS:"
|
||||
echo "SAFETY REMINDERS:"
|
||||
echo "- Changes take time to propagate through the network"
|
||||
echo "- Monitor for 48+ hours before making more changes"
|
||||
echo "- Keep a log of what you change and when"
|
||||
|
||||
@@ -37,11 +37,11 @@ fi
|
||||
echo "✅ gRPC setup complete!"
|
||||
echo ""
|
||||
echo "Benefits of gRPC over REST:"
|
||||
echo " • 🚀 ~10x faster fee updates"
|
||||
echo " • 📊 Better type safety with protobuf"
|
||||
echo " • 🔗 Native LND interface (same as charge-lnd)"
|
||||
echo " • ~10x faster fee updates"
|
||||
echo " • Better type safety with protobuf"
|
||||
echo " • Native LND interface (same as charge-lnd)"
|
||||
echo " • 📱 Lower network overhead"
|
||||
echo " • 🛡️ Built-in connection pooling"
|
||||
echo " • Built-in connection pooling"
|
||||
echo ""
|
||||
echo "Your Lightning Policy Manager will now use gRPC by default!"
|
||||
echo "To test: ./lightning_policy.py -c test_config.conf apply --dry-run"
|
||||
@@ -11,13 +11,13 @@ from datetime import datetime
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 🔒 SECURITY: Only import SAFE protobuf definitions for fee management
|
||||
# SECURITY: Only import SAFE protobuf definitions for fee management
|
||||
try:
|
||||
# Only import fee-management related protobuf definitions
|
||||
from .grpc_generated import lightning_pb2_grpc as lnrpc
|
||||
from .grpc_generated import lightning_pb2 as ln
|
||||
GRPC_AVAILABLE = True
|
||||
logger.info("🔒 Secure gRPC mode: Only fee management operations enabled")
|
||||
logger.info("SECURITY: Secure gRPC mode: Only fee management operations enabled")
|
||||
except ImportError:
|
||||
logger.warning("gRPC stubs not available, falling back to REST (secure)")
|
||||
GRPC_AVAILABLE = False
|
||||
@@ -58,16 +58,16 @@ MESSAGE_SIZE_MB = 50 * 1024 * 1024
|
||||
|
||||
|
||||
def _validate_grpc_operation(method_name: str) -> bool:
|
||||
"""🔒 SECURITY: Validate that gRPC operation is allowed for fee management only"""
|
||||
"""SECURITY: Validate that gRPC operation is allowed for fee management only"""
|
||||
if method_name in DANGEROUS_GRPC_METHODS:
|
||||
logger.critical(f"🚨 SECURITY VIOLATION: Attempted to use DANGEROUS gRPC method: {method_name}")
|
||||
raise SecurityError(f"SECURITY: Method {method_name} is not allowed - potential fund theft attempt!")
|
||||
|
||||
if method_name not in ALLOWED_GRPC_METHODS:
|
||||
logger.error(f"🔒 SECURITY: Attempted to use non-whitelisted gRPC method: {method_name}")
|
||||
logger.error(f"SECURITY: Attempted to use non-whitelisted gRPC method: {method_name}")
|
||||
raise SecurityError(f"SECURITY: Method {method_name} is not whitelisted for fee management")
|
||||
|
||||
logger.debug(f"✅ SECURITY: Validated safe gRPC method: {method_name}")
|
||||
logger.debug(f"SECURITY: Validated safe gRPC method: {method_name}")
|
||||
return True
|
||||
|
||||
|
||||
@@ -182,11 +182,11 @@ class LNDgRPCClient:
|
||||
return combined_credentials
|
||||
|
||||
def get_info(self) -> Dict[str, Any]:
|
||||
"""🔒 SECURE: Get LND node info (cached)"""
|
||||
"""SECURE: Get LND node info (cached)"""
|
||||
_validate_grpc_operation('GetInfo')
|
||||
|
||||
if self.info_cache is None:
|
||||
logger.info("🔒 SECURITY: Executing safe GetInfo operation")
|
||||
logger.info("SECURITY: Executing safe GetInfo operation")
|
||||
response = self.lightning_stub.GetInfo(ln.GetInfoRequest())
|
||||
self.info_cache = {
|
||||
'identity_pubkey': response.identity_pubkey,
|
||||
@@ -290,7 +290,7 @@ class LNDgRPCClient:
|
||||
inbound_fee_rate_ppm: int = None,
|
||||
inbound_base_fee_msat: int = None) -> Dict[str, Any]:
|
||||
"""
|
||||
🔒 SECURE: Update channel policy via gRPC - ONLY FEE MANAGEMENT
|
||||
SECURE: Update channel policy via gRPC - ONLY FEE MANAGEMENT
|
||||
|
||||
This is the core function that actually changes fees!
|
||||
SECURITY: This method ONLY changes channel fees - NO fund movement!
|
||||
@@ -298,7 +298,7 @@ class LNDgRPCClient:
|
||||
# 🚨 CRITICAL SECURITY CHECK
|
||||
_validate_grpc_operation('UpdateChannelPolicy')
|
||||
|
||||
logger.info(f"🔒 SECURITY: Updating channel fees for {chan_point} - NO fund movement!")
|
||||
logger.info(f"SECURITY: Updating channel fees for {chan_point} - NO fund movement!")
|
||||
logger.debug(f"Fee params: base={base_fee_msat}, rate={fee_rate_ppm}ppm, "
|
||||
f"inbound_rate={inbound_fee_rate_ppm}ppm")
|
||||
# Parse channel point
|
||||
|
||||
@@ -30,7 +30,7 @@ class OptimizationComparison:
|
||||
console.print("[cyan]Running optimization comparison...[/cyan]")
|
||||
|
||||
# Run simple optimization
|
||||
console.print("📊 Running simple optimization...")
|
||||
console.print("Running simple optimization...")
|
||||
simple_recommendations = self.simple_optimizer.optimize_fees(metrics)
|
||||
|
||||
# Run advanced optimization
|
||||
@@ -129,11 +129,11 @@ Key Improvements:
|
||||
• Different fee strategies: {comparison['channels_with_different_recommendations']} channels
|
||||
"""
|
||||
|
||||
console.print(Panel(summary_text.strip(), title="📊 Comparison Summary"))
|
||||
console.print(Panel(summary_text.strip(), title="Comparison Summary"))
|
||||
|
||||
# Detailed differences table
|
||||
if comparison['differences']:
|
||||
console.print("\n[bold]🔍 Significant Strategy Differences[/bold]")
|
||||
console.print("\n[bold]Significant Strategy Differences[/bold]")
|
||||
|
||||
table = Table(show_header=True, header_style="bold magenta")
|
||||
table.add_column("Channel", width=16)
|
||||
@@ -173,7 +173,7 @@ Key Improvements:
|
||||
if not advanced_recs or not hasattr(advanced_recs[0], 'risk_assessment'):
|
||||
return
|
||||
|
||||
console.print("\n[bold]⚠️ Risk Analysis (Advanced Only)[/bold]")
|
||||
console.print("\n[bold]Risk Analysis (Advanced Only)[/bold]")
|
||||
|
||||
# Risk distribution
|
||||
risk_levels = {'low': 0, 'medium': 0, 'high': 0}
|
||||
@@ -210,7 +210,7 @@ Average Risk Score: {avg_risk:.2f} (0-1 scale)
|
||||
|
||||
# Show high-risk recommendations
|
||||
if high_risk_channels:
|
||||
console.print("\n[bold red]⚠️ High-Risk Recommendations[/bold red]")
|
||||
console.print("\n[bold red]High-Risk Recommendations[/bold red]")
|
||||
|
||||
table = Table(show_header=True)
|
||||
table.add_column("Channel")
|
||||
@@ -232,7 +232,7 @@ Average Risk Score: {avg_risk:.2f} (0-1 scale)
|
||||
def _display_implementation_comparison(self, simple_recs, advanced_recs) -> None:
|
||||
"""Compare implementation strategies"""
|
||||
|
||||
console.print("\n[bold]🚀 Implementation Strategy Comparison[/bold]")
|
||||
console.print("\n[bold]Implementation Strategy Comparison[/bold]")
|
||||
|
||||
# Simple approach
|
||||
simple_text = f"""
|
||||
@@ -275,7 +275,7 @@ Average Risk Score: {avg_risk:.2f} (0-1 scale)
|
||||
console.print(columns)
|
||||
|
||||
# Recommendation
|
||||
console.print("\n[bold green]💡 Recommendation[/bold green]")
|
||||
console.print("\n[bold green]Recommendation[/bold green]")
|
||||
if len(advanced_recs) > 0 and hasattr(advanced_recs[0], 'risk_assessment'):
|
||||
console.print("Use the Advanced Optimizer for:")
|
||||
console.print("• Higher total returns with risk management")
|
||||
|
||||
@@ -20,14 +20,14 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
async def test_system():
|
||||
"""Test the complete optimization system"""
|
||||
print("🔍 Testing Lightning Fee Optimizer")
|
||||
print("Testing Lightning Fee Optimizer")
|
||||
|
||||
# Initialize configuration
|
||||
config_file = Path("config/default.json")
|
||||
config = Config.load(str(config_file) if config_file.exists() else None)
|
||||
|
||||
async with LndManageClient(config.api.base_url) as client:
|
||||
print("\n✅ Checking node connection...")
|
||||
print("\nChecking node connection...")
|
||||
if not await client.is_synced():
|
||||
print("❌ Node is not synced to chain!")
|
||||
return
|
||||
@@ -35,7 +35,7 @@ async def test_system():
|
||||
block_height = await client.get_block_height()
|
||||
print(f"📦 Current block height: {block_height}")
|
||||
|
||||
print("\n📊 Fetching channel data...")
|
||||
print("\nFetching channel data...")
|
||||
# Get first few channels for testing
|
||||
response = await client.get_open_channels()
|
||||
if isinstance(response, dict) and 'channels' in response:
|
||||
@@ -47,25 +47,25 @@ async def test_system():
|
||||
print("❌ No channels found!")
|
||||
return
|
||||
|
||||
print(f"🔗 Found {len(channel_ids)} channels to test with")
|
||||
print(f"Found {len(channel_ids)} channels to test with")
|
||||
|
||||
# Analyze channels
|
||||
analyzer = ChannelAnalyzer(client, config)
|
||||
print("\n🔬 Analyzing channel performance...")
|
||||
try:
|
||||
metrics = await analyzer.analyze_channels(channel_ids)
|
||||
print(f"✅ Successfully analyzed {len(metrics)} channels")
|
||||
print(f"Successfully analyzed {len(metrics)} channels")
|
||||
|
||||
# Print analysis
|
||||
print("\n📈 Channel Analysis Results:")
|
||||
print("\nChannel Analysis Results:")
|
||||
analyzer.print_analysis(metrics)
|
||||
|
||||
# Test optimization
|
||||
print("\n⚡ Generating fee optimization recommendations...")
|
||||
print("\nGenerating fee optimization recommendations...")
|
||||
optimizer = FeeOptimizer(config.optimization, OptimizationStrategy.BALANCED)
|
||||
recommendations = optimizer.optimize_fees(metrics)
|
||||
|
||||
print(f"✅ Generated {len(recommendations)} recommendations")
|
||||
print(f"Generated {len(recommendations)} recommendations")
|
||||
optimizer.print_recommendations(recommendations)
|
||||
|
||||
# Save recommendations
|
||||
|
||||
Reference in New Issue
Block a user