|
| 1 | +# Debug Handbook |
| 2 | + |
| 3 | +This directory contains debugging guides for common issues encountered in taproot-assets development. Each guide provides pattern recognition techniques, debugging flowcharts, and proven resolution strategies. |
| 4 | + |
| 5 | +## Available Guides |
| 6 | + |
| 7 | +### [PSBT Finalization Failures](./psbt-finalization-failures.md) |
| 8 | +Comprehensive guide for debugging PSBT signing and finalization issues, particularly those involving: |
| 9 | +- BIP32 key derivation mismatches |
| 10 | +- Missing tapscript merkle roots |
| 11 | +- Supply commitment key storage problems |
| 12 | + |
| 13 | +## How to Use This Handbook |
| 14 | + |
| 15 | +1. **Identify symptoms** - Match error messages or behaviors to guide titles |
| 16 | +2. **Follow the flowchart** - Each guide has a decision tree for systematic debugging |
| 17 | +3. **Check common causes** - Most issues follow predictable patterns |
| 18 | +4. **Apply the fix pattern** - Use provided code examples as templates |
| 19 | +5. **Verify resolution** - Run the suggested verification steps |
| 20 | + |
| 21 | +## Contributing New Guides |
| 22 | + |
| 23 | +When you solve a difficult debugging problem, consider adding a guide: |
| 24 | + |
| 25 | +### Guide Template |
| 26 | + |
| 27 | +```markdown |
| 28 | +# [Issue Name] - Debug Handbook |
| 29 | + |
| 30 | +## Quick Identification |
| 31 | +- List symptoms |
| 32 | +- Common error messages |
| 33 | +- Affected components |
| 34 | + |
| 35 | +## Debug Flow Chart |
| 36 | +- Mermaid flowchart showing decision points |
| 37 | +- Clear paths to root causes |
| 38 | + |
| 39 | +## Detailed Debugging Steps |
| 40 | +- Step-by-step investigation process |
| 41 | +- Where to look in code |
| 42 | +- What to check in logs |
| 43 | + |
| 44 | +## Common Pitfalls |
| 45 | +- Things that often trip people up |
| 46 | +- Non-obvious failure modes |
| 47 | + |
| 48 | +## Prevention Strategies |
| 49 | +- How to avoid this issue in the future |
| 50 | +- Best practices |
| 51 | + |
| 52 | +## External References |
| 53 | +- Links to relevant documentation |
| 54 | +- Related specifications or RFCs |
| 55 | + |
| 56 | +## Quick Checklist |
| 57 | +- [ ] Actionable debugging steps |
| 58 | +``` |
| 59 | + |
| 60 | +### Good Guide Characteristics |
| 61 | + |
| 62 | +1. **Symptom-focused** - Start with what developers will see |
| 63 | +2. **Systematic approach** - Provide clear debugging methodology |
| 64 | +3. **Code examples** - Show both wrong and right patterns |
| 65 | +4. **Tool commands** - Include exact commands to run |
| 66 | +5. **Cross-references** - Link to relevant code and docs |
| 67 | +6. **Battle-tested** - Based on actual debugging experience |
| 68 | + |
| 69 | +## General Debugging Tips |
| 70 | + |
| 71 | +### Enable Comprehensive Logging |
| 72 | +```bash |
| 73 | +# Maximum verbosity for all components |
| 74 | +export TAPD_DEBUG_LEVEL=debug |
| 75 | +export LND_DEBUG_LEVEL=debug |
| 76 | +export BTCD_DEBUG_LEVEL=debug |
| 77 | +``` |
| 78 | + |
| 79 | +### Useful Log Grep Patterns |
| 80 | +```bash |
| 81 | +# Find errors across all logs |
| 82 | +grep -i "error\|fail\|skip\|warn" itest/regtest/*.log |
| 83 | + |
| 84 | +# Track RPC calls |
| 85 | +grep "interceptor.go.*requested" *.log |
| 86 | + |
| 87 | +# Find state transitions |
| 88 | +grep -i "state.*transition\|ProcessEvent" *.log |
| 89 | + |
| 90 | +# Database operations |
| 91 | +grep -i "insert\|update\|upsert" *.log |
| 92 | +``` |
| 93 | + |
| 94 | +### Component Interaction Points |
| 95 | + |
| 96 | +Key interfaces where issues often occur: |
| 97 | +- **tapd ↔ lnd**: PSBT signing, wallet operations |
| 98 | +- **tapd ↔ btcd**: Transaction broadcast, block notifications |
| 99 | +- **tapd ↔ universe**: Proof synchronization, supply commits |
| 100 | +- **Database layer**: Key storage, state persistence |
| 101 | + |
| 102 | +### Testing Strategies |
| 103 | + |
| 104 | +1. **Isolate the failure** |
| 105 | + - Run single test case: `make itest icase=specific_test` |
| 106 | + - Use unit tests when possible: `go test -v -run TestSpecific` |
| 107 | + |
| 108 | +2. **Simplify the scenario** |
| 109 | + - Reduce to minimum inputs |
| 110 | + - Remove unnecessary components |
| 111 | + - Test with regtest before testnet/mainnet |
| 112 | + |
| 113 | +3. **Add strategic logging** |
| 114 | + ```go |
| 115 | + log.Debugf("Key details: family=%d, index=%d, pubkey=%x", |
| 116 | + key.Family, key.Index, key.PubKey.SerializeCompressed()) |
| 117 | + ``` |
| 118 | + |
| 119 | +4. **Verify assumptions** |
| 120 | + - Check database state matches expectations |
| 121 | + - Verify RPC responses contain expected fields |
| 122 | + - Ensure configuration is correct |
| 123 | + |
| 124 | +## Debugging Tools |
| 125 | + |
| 126 | +### Database Inspection |
| 127 | +```bash |
| 128 | +# SQLite database inspection |
| 129 | +sqlite3 ~/.tapd/data/regtest/tapd.db |
| 130 | + |
| 131 | +# Common queries |
| 132 | +.tables # List all tables |
| 133 | +.schema supply_commitments # Show table structure |
| 134 | +SELECT * FROM internal_keys WHERE key_index != 0; # Find non-zero indices |
| 135 | +``` |
| 136 | + |
| 137 | +### PSBT Decoding |
| 138 | +```bash |
| 139 | +# Decode PSBT to human-readable format |
| 140 | +bitcoin-cli decodepsbt "cHNidP8B..." |
| 141 | + |
| 142 | +# Using btcdecode tool |
| 143 | +echo "cHNidP8B..." | btcdecode -psbt |
| 144 | +``` |
| 145 | + |
| 146 | +### Transaction Analysis |
| 147 | +```bash |
| 148 | +# Decode raw transaction |
| 149 | +bitcoin-cli decoderawtransaction "0200000001..." |
| 150 | + |
| 151 | +# Get transaction details |
| 152 | +bitcoin-cli getrawtransaction "txid" true |
| 153 | +``` |
| 154 | + |
| 155 | +## Common Abbreviations |
| 156 | + |
| 157 | +- **PSBT**: Partially Signed Bitcoin Transaction |
| 158 | +- **BIP32**: Hierarchical Deterministic key derivation |
| 159 | +- **SMT/MSSMT**: Sparse Merkle Tree / Merkle Sum Sparse Merkle Tree |
| 160 | +- **tapd**: Taproot Assets Daemon |
| 161 | +- **lnd**: Lightning Network Daemon |
| 162 | + |
| 163 | +## Learning Resources |
| 164 | + |
| 165 | +- [Bitcoin Optech](https://bitcoinops.org/) - Bitcoin technology explained |
| 166 | +- [BIPs Repository](https://github.com/bitcoin/bips) - Bitcoin Improvement Proposals |
| 167 | +- [Taproot Assets Docs](https://docs.lightning.engineering/the-lightning-network/taproot-assets) - Official documentation |
| 168 | +- [lnd Developer Docs](https://dev.lightning.community/) - Lightning Network development |
0 commit comments