[POC] Full Libevent removal #34411

pull fanquake wants to merge 40 commits into bitcoin:master from fanquake:full_libevent_removal changing 55 files +2997 −1489
  1. fanquake commented at 12:35 pm on January 26, 2026: member

    This builds on all the work being done by pinheadmz and fjahr (#32061, #34342, #34158), to demo a libevent-less bitcoind.

    One thing we could decide to change, or not, is the libevent logging catergory. Other than that, any remaining references to libevent, should be in documentation/code comments.

  2. http: enclose libevent-dependent code in a namespace
    This commit is a no-op to isolate HTTP methods and objects that
    depend on libevent. Following commits will add replacement objects
    and methods in a new namespace for testing and review before
    switching over the server.
    f630d349c6
  3. http: Implement HTTPHeaders class
    see:
    https://www.rfc-editor.org/rfc/rfc2616#section-4.2
    https://www.rfc-editor.org/rfc/rfc7231#section-5
    https://www.rfc-editor.org/rfc/rfc7231#section-7
    https://httpwg.org/specs/rfc9111.html#header.field.definitions
    dbb90ffa76
  4. http: Implement HTTPResponse class
    HTTP Response message:
    https://datatracker.ietf.org/doc/html/rfc1945#section-6
    
    Status line (first line of response):
    https://datatracker.ietf.org/doc/html/rfc1945#section-6.1
    
    Status code definitions:
    https://datatracker.ietf.org/doc/html/rfc1945#section-9
    
    This commit also moves StringToBuffer to test/util/str
    since it is now used in more than one test.
    346e6b212d
  5. http: Implement HTTPRequest class
    HTTP Request message:
    https://datatracker.ietf.org/doc/html/rfc1945#section-5
    
    Request Line aka Control Line aka first line:
    https://datatracker.ietf.org/doc/html/rfc1945#section-5.1
    
    See message_read_status() in libevent http.c for how
    `MORE_DATA_EXPECTED` is handled there
    69a39d72ed
  6. http: Introduce HTTPServer class and implement binding to listening socket
    Introduce a new low-level socket managing class `HTTPServer`.
    
    BindAndStartListening() was copied from CConnMan's BindListenPort()
    in net.cpp and modernized.
    
    Unit-test it with a new class `SocketTestingSetup` which mocks
    `CreateSock()` and will enable mock client I/O in future commits.
    
    Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
    ea8c754dc1
  7. HTTPServer: implement and test AcceptConnection()
    AcceptConnection() is mostly copied from CConmann in net.cpp
    and then modernized.
    
    Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
    db90059915
  8. HTTPServer: generate sequential Ids for each newly accepted connection
    Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
    e489694a91
  9. http: Introduce HTTPClient class 75106931b3
  10. HTTPServer: start an I/O loop in a new thread and accept connections
    Socket handling methods are copied from CConnMan:
    
    `CConnman::GenerateWaitSockets()`
    `CConnman::SocketHandlerListening()`
    `CConnman::ThreadSocketHandler()` and `CConnman::SocketHandler()` are combined into ThreadSocketHandler()`.
    
    Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
    51673b3092
  11. HTTPServer: read requests from connected clients
    `SocketHandlerConnected()` adapted from CConnman
    
    Testing this requires adding a new feature to the SocketTestingSetup,
    inserting a "request" payload into the mock client that connects
    to us.
    
    Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
    616842248e
  12. HTTPserver: support "chunked" Transfer-Encoding ac47f1336d
  13. HTTPServer: compose and send replies to connected clients
    Sockets-touching bits copied and adapted from `CConnman::SocketSendData()`
    
    Testing this requires adding a new feature to the SocketTestingSetup,
    returning the DynSock I/O pipes from the mock socket so the received
    data can be checked.
    
    Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
    259751e02f
  14. HTTPServer: disconnect clients 0785338ad6
  15. Allow http workers to send data optimistically as an optimization 289a8ff3b0
  16. HTTPServer: use a queue to pipeline requests from each connected client
    See https://www.rfc-editor.org/rfc/rfc7230#section-6.3.2
    
    > A server MAY process a sequence of pipelined requests in
      parallel if they all have safe methods (Section 4.2.1 of [RFC7231]),
      but it MUST send the corresponding responses in the same order that
      the requests were received.
    
    We choose NOT to process requests in parallel. They are executed in
    the order recevied as well as responded to in the order received.
    This prevents race conditions where old state may get sent in response
    to requests that are very quick to process but were requested later on
    in the queue.
    71a02f82ee
  17. define HTTP request methods at module level outside of class
    This is a refactor to prepare for matching the API of HTTPRequest
    definitions in both namespaces http_bitcoin and http_libevent. In
    particular, to provide a consistent return type for GetRequestMethod()
    in both classes.
    ce10682e89
  18. Add helper methods to HTTPRequest to match original API
    These methods are called by http_request_cb() and are present in the
    original http_libevent::HTTPRequest.
    f89c72d5f0
  19. refactor: split http_request_cb into libevent callback and dispatch
    The original function is passed to libevent as a callback when HTTP
    requests are received and processed. It wrapped the libevent request
    object in a http_libevent::HTTPRequest and then handed that off to
    bitcoin for basic checks and finally dispatch to worker threads.
    
    In this commit we split the function after the
    http_libevent::HTTPRequest is created, and pass that object to a new
    function that maintains the logic of checking and dispatching.
    
    This will be the merge point for http_libevent and http_bitcoin,
    where HTTPRequest objects from either namespace have the same
    downstream lifecycle.
    c408f08715
  20. refactor: split HTTPBindAddresses into config parse and libevent setup
    The original function was already naturally split into two chunks:
    First, we parse and validate the users' RPC configuration for IPs and
    ports. Next we bind libevent's http server to the appropriate
    endpoints.
    
    This commit splits these chunks into two separate functions, leaving
    the argument parsing in the common space of the module and moving the
    libevent-specific binding into the http_libevent namespace.
    
    A future commit will implement http_bitcoin::HTTPBindAddresses to
    bind the validate list of endpoints by the new HTTP server.
    338064c951
  21. HTTPServer: implement control methods to match legacy API 3ee91bcda2
  22. HTTPServer: disconnect after idle timeout (-rpcservertimeout) 4fe8ff00a8
  23. http: switch servers from libevent to bitcoin f8a5841f75
  24. fuzz: switch http_libevent::HTTPRequest to http_bitcoin::HTTPRequest 03e32b03e6
  25. http: delete libevent! 56d6529666
  26. common: Add unused UrlEncode function dfe2664e8f
  27. http: Add HTTPHeader file in common
    This will be shared between the http server and the bitcoin-cli http client code.
    ef19f1a16a
  28. cli: Remove libevent usage
    Replace libevent-based HTTP client with a simple synchronous implementation using the Sock class directly.
    3783225eaa
  29. refactor: Use constexpr in torcontrol where possible bfba17ee54
  30. refactor: Modernize member variable names in torcontrol c313a43d30
  31. refactor: Get rid of unnecessary newlines in logs 83067266c6
  32. torcontrol: Remove libevent usage
    Replace libevent-based approach with using the Sock class and CThreadInterrupt.
    f82cd92f2f
  33. fuzz: Improve torcontrol fuzz test
    Gets rid of the Dummy class and adds coverage of get_socks_cb.
    4b0003c236
  34. test: Add simple functional test for torcontrol 2dff31f492
  35. test: Add test for partial message handling in torcontrol c447f0268a
  36. test: remove raii_event_tests 8381a6ae87
  37. cmake: remove libevent 6ae32eaeb3
  38. depends: remove libevent 7fad3c4d00
  39. ci: remove libevent 90c9bdbe8d
  40. DrahtBot commented at 12:35 pm on January 26, 2026: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34411.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34408 (ci: remove gnu-getopt usage by fanquake)
    • #34143 (build: Prevent system header fallback and include path pollution by hebasto)
    • #33974 (cmake: Check dependencies after build option interaction by hebasto)
    • #32297 (bitcoin-cli: Add -ipcconnect option by ryanofsky)
    • #31929 (http: Make server shutdown more robust by hodlinator)
    • #31723 (qa: Facilitate debugging bitcoind inside functional tests by hodlinator)
    • #31425 (RFC: Riscv bare metal CI job by sedited)
    • #31260 (scripted-diff: Type-safe settings retrieval by ryanofsky)
    • #30342 (kernel, logging: Pass Logger instances to kernel objects by ryanofsky)
    • #26022 (Add util::ResultPtr class by ryanofsky)
    • #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)
    • #25665 (refactor: Add util::Result failure types and ability to merge result values by ryanofsky)
    • #21283 (Implement BIP 370 PSBTv2 by achow101)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • Unrecoverbale -> Unrecoverable [spelling error in log message “Unrecoverbale error, log and disconnect client.”]

    Possible places where comparison-specific test macros should replace generic comparisons:

    • [src/test/httpserver_tests.cpp] BOOST_CHECK_THROW(req.LoadControlData(reader), std::runtime_error) -> recommendation: use BOOST_CHECK_EXCEPTION(req.LoadControlData(reader), std::runtime_error, HasReason(“expected error message”)) to assert on the exception message (replace “expected error message” with the exact reason).
    • [src/test/httpserver_tests.cpp] BOOST_CHECK_THROW(req.LoadControlData(reader), std::runtime_error) -> recommendation: use BOOST_CHECK_EXCEPTION(req.LoadControlData(reader), std::runtime_error, HasReason(“expected error message”)).
    • [src/test/httpserver_tests.cpp] BOOST_CHECK_THROW(req.LoadControlData(reader), std::runtime_error) -> recommendation: use BOOST_CHECK_EXCEPTION(req.LoadControlData(reader), std::runtime_error, HasReason(“expected error message”)).
    • [src/test/httpserver_tests.cpp] BOOST_CHECK_THROW(req.LoadControlData(reader), std::runtime_error) -> recommendation: use BOOST_CHECK_EXCEPTION(req.LoadControlData(reader), std::runtime_error, HasReason(“expected error message”)).
    • [src/test/httpserver_tests.cpp] BOOST_CHECK_THROW(req.LoadControlData(reader), std::runtime_error) -> recommendation: use BOOST_CHECK_EXCEPTION(req.LoadControlData(reader), std::runtime_error, HasReason(“expected error message”)).
    • [src/test/httpserver_tests.cpp] BOOST_CHECK_THROW(req.LoadHeaders(reader), std::runtime_error) -> recommendation: use BOOST_CHECK_EXCEPTION(req.LoadHeaders(reader), std::runtime_error, HasReason(“expected error message”)).
    • [src/test/httpserver_tests.cpp] BOOST_CHECK_THROW(req.LoadBody(reader), std::runtime_error) -> recommendation: use BOOST_CHECK_EXCEPTION(req.LoadBody(reader), std::runtime_error, HasReason(“expected error message”)).
    • [src/test/httpserver_tests.cpp] BOOST_CHECK_THROW(req.LoadBody(reader), std::runtime_error) -> recommendation: use BOOST_CHECK_EXCEPTION(req.LoadBody(reader), std::runtime_error, HasReason(“expected error message”)).
    • [src/test/httpserver_tests.cpp] BOOST_CHECK_THROW(req.LoadBody(reader), std::runtime_error) -> recommendation: use BOOST_CHECK_EXCEPTION(req.LoadBody(reader), std::runtime_error, HasReason(“expected error message”)).

    No bare Python “assert a == b” comparisons were added in test/functional/.

    2026-01-26 13:18:14

  41. vcpkg: remove libevent 328f343dfe
  42. doc: remove libevent cd010075ca
  43. fanquake force-pushed on Jan 26, 2026
  44. DrahtBot added the label CI failed on Jan 26, 2026
  45. pinheadmz commented at 4:05 pm on January 26, 2026: member
    nit: Pull request description should be replaced by the lyrics of Taylor Swift’s “We Are Never Ever Getting Back Together” before merging.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-01-27 06:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me