What changed, and why it matters
This commit removes libevent from the Bitcoin Core build system and deletes the associated helper header and unit tests. It is a dependency cleanup, not a security fix. There is no indication in the commit that this addresses a vulnerability.
No security action required. Treat as ordinary dependency removal and verify downstream builds no longer require libevent.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit deletes cmake/module/FindLibevent.cmake, src/support/events.h, and src/test/raii_event_tests.cpp, and removes libevent::core/extra/pthreads link targets from src/CMakeLists.txt, src/test/CMakeLists.txt, and src/test/fuzz/CMakeLists.txt. It also removes the find_package(Libevent) call from the top-level CMakeLists.txt. This is a build-system and code-cleanup change that eliminates libevent as a dependency. No functional runtime code changes or security patches are present in the diff.
Changed components
CMake build systemsrc/support/events.hsrc/test/raii_event_tests.cppInspect captured patch +0 / −230
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 69ee5461..69db01f2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -221,10 +221,6 @@ target_link_libraries(core_interface INTERFACE
include(AddBoostIfNeeded)
add_boost_if_needed()
-if(BUILD_DAEMON OR BUILD_GUI OR BUILD_CLI OR BUILD_TESTS OR BUILD_BENCH OR BUILD_FUZZ_BINARY)
- find_package(Libevent 2.1.8 MODULE REQUIRED)
-endif()
-
if(ENABLE_WALLET)
if(VCPKG_TARGET_TRIPLET)
# Use of the `unofficial::` namespace is a vcpkg package manager convention.
diff --git a/cmake/module/FindLibevent.cmake b/cmake/module/FindLibevent.cmake
deleted file mode 100644
index c006b43d..00000000
--- a/cmake/module/FindLibevent.cmake
+++ /dev/null
@@ -1,86 +0,0 @@
-# Copyright (c) 2024-present The Bitcoin Core developers
-# Distributed under the MIT software license, see the accompanying
-# file COPYING or https://opensource.org/license/mit/.
-
-#[=======================================================================[
-FindLibevent
-------------
-
-Finds the Libevent headers and libraries.
-
-This is a wrapper around find_package()/pkg_check_modules() commands that:
- - facilitates searching in various build environments
- - prints a standard log message
-
-#]=======================================================================]
-
-# Check whether evhttp_connection_get_peer expects const char**.
-# See https://github.com/libevent/libevent/commit/a18301a2bb160ff7c3ffaf5b7653c39ffe27b385
-function(check_evhttp_connection_get_peer target)
- include(CMakePushCheckState)
- cmake_push_check_state(RESET)
- set(CMAKE_REQUIRED_LIBRARIES ${target})
- include(CheckCXXSourceCompiles)
- check_cxx_source_compiles("
- #include <cstdint>
- #include <event2/http.h>
-
- int main()
- {
- evhttp_connection* conn = (evhttp_connection*)1;
- const char* host;
- uint16_t port;
- evhttp_connection_get_peer(conn, &host, &port);
- }
- " HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR
- )
- cmake_pop_check_state()
- target_compile_definitions(${target} INTERFACE
- $<$<BOOL:${HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR}>:HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR>
- )
-endfunction()
-
-set(_libevent_components core extra)
-if(NOT WIN32)
- list(APPEND _libevent_components pthreads)
-endif()
-
-find_package(Libevent ${Libevent_FIND_VERSION} QUIET
- NO_MODULE
-)
-
-include(FindPackageHandleStandardArgs)
-if(Libevent_FOUND)
- find_package(Libevent ${Libevent_FIND_VERSION} QUIET
- REQUIRED COMPONENTS ${_libevent_components}
- NO_MODULE
- )
- find_package_handle_standard_args(Libevent
- REQUIRED_VARS Libevent_DIR
- VERSION_VAR Libevent_VERSION
- )
- check_evhttp_connection_get_peer(libevent::extra)
-else()
- find_package(PkgConfig REQUIRED)
- foreach(component IN LISTS _libevent_components)
- pkg_check_modules(libevent_${component}
- REQUIRED QUIET
- IMPORTED_TARGET GLOBAL
- libevent_${component}>=${Libevent_FIND_VERSION}
- )
- if(TARGET PkgConfig::libevent_${component} AND NOT TARGET libevent::${component})
- add_library(libevent::${component} ALIAS PkgConfig::libevent_${component})
- endif()
- endforeach()
- find_package_handle_standard_args(Libevent
- REQUIRED_VARS libevent_core_LIBRARY_DIRS
- VERSION_VAR libevent_core_VERSION
- )
- check_evhttp_connection_get_peer(PkgConfig::libevent_extra)
-endif()
-
-unset(_libevent_components)
-
-mark_as_advanced(Libevent_DIR)
-mark_as_advanced(_event_h)
-mark_as_advanced(_event_lib)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 524c2816..8c0977f0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -290,9 +290,6 @@ target_link_libraries(bitcoin_node
minisketch
univalue
Boost::headers
- $<TARGET_NAME_IF_EXISTS:libevent::core>
- $<TARGET_NAME_IF_EXISTS:libevent::extra>
- $<TARGET_NAME_IF_EXISTS:libevent::pthreads>
$<TARGET_NAME_IF_EXISTS:USDT::headers>
)
if(WITH_EMBEDDED_ASMAP)
diff --git a/src/support/events.h b/src/support/events.h
deleted file mode 100644
index a118ba32..00000000
--- a/src/support/events.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) 2016-present The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#ifndef BITCOIN_SUPPORT_EVENTS_H
-#define BITCOIN_SUPPORT_EVENTS_H
-
-#include <ios>
-#include <memory>
-
-#include <event2/event.h>
-#include <event2/http.h>
-
-#define MAKE_RAII(type) \
-/* deleter */\
-struct type##_deleter {\
- void operator()(struct type* ob) {\
- type##_free(ob);\
- }\
-};\
-/* unique ptr typedef */\
-typedef std::unique_ptr<struct type, type##_deleter> raii_##type
-
-MAKE_RAII(event_base);
-MAKE_RAII(event);
-MAKE_RAII(evhttp);
-
-inline raii_event_base obtain_event_base() {
- auto result = raii_event_base(event_base_new());
- if (!result.get())
- throw std::runtime_error("cannot create event_base");
- return result;
-}
-
-inline raii_event obtain_event(struct event_base* base, evutil_socket_t s, short events, event_callback_fn cb, void* arg) {
- return raii_event(event_new(base, s, events, cb, arg));
-}
-
-inline raii_evhttp obtain_evhttp(struct event_base* base) {
- return raii_evhttp(evhttp_new(base));
-}
-
-#endif // BITCOIN_SUPPORT_EVENTS_H
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt
index a25d9f90..e5619064 100644
--- a/src/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -82,7 +82,6 @@ add_executable(test_bitcoin
prevector_tests.cpp
private_broadcast_tests.cpp
psbt_tests.cpp
- raii_event_tests.cpp
random_tests.cpp
rbf_tests.cpp
rest_tests.cpp
@@ -168,7 +167,6 @@ target_link_libraries(test_bitcoin
minisketch
secp256k1
Boost::headers
- libevent::extra
$<TARGET_NAME_IF_EXISTS:USDT::headers>
)
diff --git a/src/test/fuzz/CMakeLists.txt b/src/test/fuzz/CMakeLists.txt
index a159ef7e..2d1fa3b7 100644
--- a/src/test/fuzz/CMakeLists.txt
+++ b/src/test/fuzz/CMakeLists.txt
@@ -154,7 +154,6 @@ target_link_libraries(fuzz
univalue
secp256k1
Boost::headers
- libevent::extra
)
if(ENABLE_WALLET)
diff --git a/src/test/raii_event_tests.cpp b/src/test/raii_event_tests.cpp
deleted file mode 100644
index 3a797dff..00000000
--- a/src/test/raii_event_tests.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (c) 2016-present The Bitcoin Core developers
-// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-
-#include <event2/event.h>
-
-#include <cstdlib>
-#include <map>
-
-#include <support/events.h>
-
-#include <test/util/setup_common.h>
-
-#include <boost/test/unit_test.hpp>
-
-BOOST_FIXTURE_TEST_SUITE(raii_event_tests, BasicTestingSetup)
-
-#ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
-
-static std::map<void*, short> tags;
-static std::map<void*, uint16_t> orders;
-static uint16_t tagSequence = 0;
-
-static void* tag_malloc(size_t sz) {
- void* mem = malloc(sz);
- if (!mem) return mem;
- tags[mem]++;
- orders[mem] = tagSequence++;
- return mem;
-}
-
-static void tag_free(void* mem) {
- tags[mem]--;
- orders[mem] = tagSequence++;
- free(mem);
-}
-
-BOOST_AUTO_TEST_CASE(raii_event_creation)
-{
- event_set_mem_functions(tag_malloc, realloc, tag_free);
-
- void* base_ptr = nullptr;
- {
- auto base = obtain_event_base();
- base_ptr = (void*)base.get();
- BOOST_CHECK(tags[base_ptr] == 1);
- }
- BOOST_CHECK(tags[base_ptr] == 0);
-
- void* event_ptr = nullptr;
- {
- auto base = obtain_event_base();
- auto event = obtain_event(base.get(), -1, 0, nullptr, nullptr);
-
- base_ptr = (void*)base.get();
- event_ptr = (void*)event.get();
-
- BOOST_CHECK(tags[base_ptr] == 1);
- BOOST_CHECK(tags[event_ptr] == 1);
- }
- BOOST_CHECK(tags[base_ptr] == 0);
- BOOST_CHECK(tags[event_ptr] == 0);
-
- event_set_mem_functions(malloc, realloc, free);
-}
-
-BOOST_AUTO_TEST_CASE(raii_event_order)
-{
- event_set_mem_functions(tag_malloc, realloc, tag_free);
-
- void* base_ptr = nullptr;
- void* event_ptr = nullptr;
- {
- auto base = obtain_event_base();
- auto event = obtain_event(base.get(), -1, 0, nullptr, nullptr);
-
- base_ptr = (void*)base.get();
- event_ptr = (void*)event.get();
-
- // base should have allocated before event
- BOOST_CHECK(orders[base_ptr] < orders[event_ptr]);
- }
- // base should be freed after event
- BOOST_CHECK(orders[base_ptr] > orders[event_ptr]);
-
- event_set_mem_functions(malloc, realloc, free);
-}
-
-#endif // EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
-
-BOOST_AUTO_TEST_SUITE_END()
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.