1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# Mining Feature: Squash-Merge Execution Plan
## Overview
Squash-merge `feature/mining-payment` into `master`, update relay config, push.
## Status: COMPLETED
## Repositories
- **Shared repo:** `/home/c03rad0r/esp32-tollgate` (master)
- ~~**Mining worktree:** `/home/c03rad0r/esp32-tollgate-mining` (removed)~~
- **Backup:** `/home/c03rad0r/mining-work-backup/feature-mining-payment.bundle`
## Checklist
### Phase 1: Documentation & Config Updates
- [x] 1.1 Write this MERGE_PLAN.md
- [x] 1.2 Update `config.c` — add relays to nostr_seed_relays (8/8) and nostr_relays (4/4)
- [x] 1.3 Update `AGENTS.md` — reflect new relay lists in shared repo
- [x] 1.4 Commit relay config changes to worktree
### Phase 2: Rebase & Test
- [x] 2.1 Rebase `feature/mining-payment` onto `master` (skipped — resolved conflicts at merge instead)
- [x] 2.2 Run `make test-unit` — all 19 suites pass
### Phase 3: Backup
- [x] 3.1 Backup branch to `/home/c03rad0r/mining-work-backup/`
### Phase 4: Squash-Merge
- [x] 4.1 Squash-merge `feature/mining-payment` into `master` with detailed body
- [x] 4.2 Run `make test-unit` on master — 19 suites, all pass
- [ ] 4.3 Run `idf.py build` on master to confirm clean build (needs ESP-IDF)
### Phase 5: Push & Cleanup
- [x] 5.1 Push master to origin (state event published to relay.ngit.dev)
- [x] 5.2 Remove git worktree + delete feature branch
- [x] 5.3 Update MINING_WORKTREE_PLAN.md checklist
## Relay Updates
### nostr_seed_relays (TOLLGATE_MAX_SEED_RELAYS = 8)
| Slot | Relay | Latency | Notes |
|------|-------|---------|-------|
| 0 | wss://relay.orangesync.tech | existing | NIP-77 |
| 1 | wss://relay.damus.io | existing | |
| 2 | wss://nos.lol | existing | |
| 3 | wss://relay.nostr.band | existing | |
| 4 | wss://relay.anzenkodo.workers.dev | 90ms | FR, NIP-01 |
| 5 | wss://nostr.koning-degraaf.nl | 91ms | NL, NIP-01 |
| 6 | wss://knostr.neutrine.com | 103ms | FR, NIP-01 |
| 7 | wss://nostr.einundzwanzig.space | 106ms | DE |
### nostr_relays (TOLLGATE_MAX_RELAYS = 4)
| Slot | Relay | Notes |
|------|-------|-------|
| 0 | wss://relay.damus.io | existing |
| 1 | wss://nos.lol | existing |
| 2 | wss://relay.anzenkodo.workers.dev | NEW |
| 3 | wss://nostr.koning-degraaf.nl | NEW |
## Squash Commit Message
```
feat(mining): Bitcoin mining-for-bandwidth payment system
New modules:
- mining_payment.c/h: hashprice calc (nbits->difficulty->sat/GH/s/day),
share validation, client stats, allotment conversion (ms + bytes)
- stratum_client.c/h: SV1 upstream pool connection (subscribe/authorize/submit)
- stratum_proxy.c/h: Local SV1 TCP server for downstream miners, job broadcast
- sw_miner.c/h: Software SHA256d miner (ESP32 CPU fallback)
- asic_miner.c/h: ASIC detection stub (BM1366/BM1368 SPI)
Config:
- config.h/c: mining_payout_mode_t enum (auto/pool/upstream/proxy_only),
stratum pool settings, mining port, hashprice override, sandbox mint access
- Defaults fill nostr_seed_relays (8/8) and nostr_relays (4/4) with fast relays
Integration into existing modules:
- session.h/c: payment_method_t enum (CASHU/MINING/BYTES)
- firewall.h/c: firewall_set_mining_port(), firewall_set_sandbox_mint_access()
- tollgate_api.c: GET /mining/job, POST /mining/share, GET /mining/stats
- tollgate_client.h/c: TG_CLIENT_MINING state, mining discovery tag parsing
- tollgate_main.c: mining init in start_services(), stratum_client_tick() in loop
- captive_portal.c: tabbed Cashu/Mine UI with live hashrate polling
Unit tests (69 new assertions across 4 suites):
- test_mining_payment (23 tests): nbits->difficulty, hashprice, client stats, allotment
- test_stratum_proxy (21 tests): job set/get, stats, type validation
- test_session_payment_method (12 tests): PAYMENT_METHOD enum, bytes/cashu methods
- test_tollgate_client_mining (20 tests): mining tag parsing, discovery struct
- test_firewall_sandbox (16 tests): client grant/revoke, max clients, setters
Enhanced test stubs:
- BaseType_t/pdPASS in freertos/task.h
- lwip: sockets.h, etharp.h, prot/ip.h, prot/ip4.h, prot/tcp.h, netif.h
- dns_server.h, esp_wifi_ap_get_sta_list.h
Build fixes:
- cvm_server.c: replace esp_timer_get_time() with xTaskGetTickCount(),
fix process_relay_message() 3-arg call to 2-arg
- stratum_proxy.c: widen task_name buffer 16->20
- sw_miner.c: add missing #include esp_random.h
- nucula_src: save_proofs() moved to public in wallet.hpp
Nostr relay updates:
- nostr_seed_relays: +relay.anzenkodo.workers.dev, +nostr.koning-degraaf.nl,
+knostr.neutrine.com, +nostr.einundzwanzig.space (8/8 slots)
- nostr_relays: +relay.anzenkodo.workers.dev, +nostr.koning-degraaf.nl (4/4 slots)
Binary: 1.2MB, 70% partition free (ESP32-S3, 16MB flash)
```
## Commits on feature/mining-payment (before squash)
1. `c75230e` — feat(mining): add new mining source files and unit tests
2. `beb73a2` — feat(mining): integrate mining subsystem into existing modules
3. `473b4d1` — fix: build errors in cvm_server, stratum_proxy, sw_miner + nucula visibility
4. `ef9ae98` — test: add 4 new unit test suites for mining modules
## Rules
- No comments in code unless explicitly requested
- Commit + push after each checkpoint
- Shared repo must stay on master, clean
|