Stratum: Use RwLock for connection_mapping to avoid blocking RPC
2026-03-251 min read
In review
Braidpool
Hardness: Easy
## Thread-Safe Connection Mapping with RwLock
Wrap connection_mapping in Arc<RwLock<ConnectionMapping>> so that:
-
getminerinfoand theNotifieruse read locks, preventing Stratum from being blocked when:- miners are added/removed
- job notifications are sent
-
Stratum add/remove operations use write locks, keeping the critical sections short.
Updates
main.rs
- Create
connection_mappingusingRwLock.
stratum.rs
- Server and Notifier now use read/write locks.
- Tests updated accordingly.
rpc_server.rs
get_miner_infonow usesread().await.run_rpc_serverand tests updated to useRwLockfor the mapping.