Closes #5029
Accept unix:<path> in options -rpcbind= (server) and -rpcconnect= (bitcoin-cli). Creates a unix socket at the path provided (not relative to datadir so aboslute path recommended). Because access is handled by the filesystem, -rpcallowip is ignored for unix sockets and not required at all if we are only binding to unix sockets.
Authentication by username/password/cookie is still required.
A new option --httpunix is added to the test framework and added to test_runner for rpc_bind.py and interface_http.py for CI, but (like --usecli) most other tests should also pass with that option. When set, bitcoind is started with -rpcbind=unix...which overrides tcp://localhost entirely. AuthProxy has been extended to connect directly to the unix socket.
Try it out!
bitcoind -regtest -rpcbind=unix:/tmp/bitcoin.sock
bitcoin-cli -regtest -rpcconnect=unix:/tmp/bitcoin.sock getbestblockhash
Refactored code:
Back in #27375 we added unix socket support but it was isloated to the Proxy class. That created a bit of tech debt which we pay off in this PR. Two new classes are implemented:
UnixSocketAddrreflects theCServiceAPI for generic unix sockets, without bitcoin-p2p-specific attributesSocketAddrholds a variant ofUnixSocketAddrandCserviceso classes likeProxyandHTTPServercan operate on an abstract level, with either socket type.CNetAddrandCServiceare left untouched -- they are somewhat dirty combinations of generic socket classes and bitcoin p2p code, adding unix sockets to those classes wouldn't make sense for bitcoin p2p operations and that's why this design was chosen.
Follow-up suggestions:
- On macos the default unix socket buffer size is only ~8k. In the functional tests we have to bump the python client socket buffer up to ~256k or the "throttle" tests will stall on macos. We could apply this socket option on the server side as well, only on macos... requires some bike shedding.
- This option replaces TCP but it does not replace HTTP, there may be a more efficient transport protocol.
Production code and test framework changes designed and authored by my own cranial meatball. Unit tests added by Opus. C++ cleaned up by Fable, security tightened by Kimi-k3 🧠🤖 🤖 🤖