Skip to content

Commit d906329

Browse files
committed
Merge bitcoin/bitcoin#24681: build: Bump libevent minimum version up to 2.1.8
e40779a refactor: Remove outdated libevent logging code (Fabian Jahr) 0598f36 refactor: account for requiring libevent 2.1.8+ (fanquake) aaf72d6 build: Bump libevent minimum version up to 2.1.8 (Hennadii Stepanov) Pull request description: Required to support new functionality in bitcoin/bitcoin#19420. `libevent` availability: https://repology.org/project/libevent/versions ACKs for top commit: laanwj: Code review ACK e40779a fanquake: ACK e40779a Tree-SHA512: ccb14ea2f591484a3df5bc4a19f4f5400ef6b1cfb7dc45dd99f96cb948748215ed3b5debc34869763c91b8c7a26993fdb9b870950c0743c4d01038ab27c5e4e2
2 parents bbb83f0 + e40779a commit d906329

File tree

7 files changed

+12
-51
lines changed

7 files changed

+12
-51
lines changed

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,9 +1537,9 @@ fi
15371537
dnl libevent check
15381538

15391539
if test "$build_bitcoin_cli$build_bitcoind$bitcoin_enable_qt$use_tests$use_bench" != "nonononono"; then
1540-
PKG_CHECK_MODULES([EVENT], [libevent >= 2.0.21], [use_libevent=yes], [AC_MSG_ERROR([libevent version 2.0.21 or greater not found.])])
1540+
PKG_CHECK_MODULES([EVENT], [libevent >= 2.1.8], [use_libevent=yes], [AC_MSG_ERROR([libevent version 2.1.8 or greater not found.])])
15411541
if test "$TARGET_OS" != "windows"; then
1542-
PKG_CHECK_MODULES([EVENT_PTHREADS], [libevent_pthreads >= 2.0.21],, [AC_MSG_ERROR([libevent_pthreads version 2.0.21 or greater not found.])])
1542+
PKG_CHECK_MODULES([EVENT_PTHREADS], [libevent_pthreads >= 2.1.8], [], [AC_MSG_ERROR([libevent_pthreads version 2.1.8 or greater not found.])])
15431543
fi
15441544

15451545
if test "$suppress_external_warnings" != "no"; then

doc/dependencies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ You can find installation instructions in the `build-*.md` file for your platfor
1818
| Dependency | Version used | Minimum required | Runtime |
1919
| --- | --- | --- | --- |
2020
| [Boost](https://www.boost.org/users/download/) | 1.77.0 | [1.64.0](https://github.com/bitcoin/bitcoin/pull/22320) | No |
21-
| [libevent](https://github.com/libevent/libevent/releases) | 2.1.12-stable | [2.0.21](https://github.com/bitcoin/bitcoin/pull/18676) | No |
21+
| [libevent](https://github.com/libevent/libevent/releases) | 2.1.12-stable | [2.1.8](https://github.com/bitcoin/bitcoin/pull/24681) | No |
2222
| [glibc](https://www.gnu.org/software/libc/) | N/A | [2.18](https://github.com/bitcoin/bitcoin/pull/23511) | Yes |
2323

2424
## Optional

src/bitcoin-cli.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ struct HTTPReply
184184
static std::string http_errorstring(int code)
185185
{
186186
switch(code) {
187-
#if LIBEVENT_VERSION_NUMBER >= 0x02010300
188187
case EVREQ_HTTP_TIMEOUT:
189188
return "timeout reached";
190189
case EVREQ_HTTP_EOF:
@@ -197,7 +196,6 @@ static std::string http_errorstring(int code)
197196
return "request was canceled";
198197
case EVREQ_HTTP_DATA_TOO_LONG:
199198
return "response body is larger than allowed";
200-
#endif
201199
default:
202200
return "unknown";
203201
}
@@ -228,13 +226,11 @@ static void http_request_done(struct evhttp_request *req, void *ctx)
228226
}
229227
}
230228

231-
#if LIBEVENT_VERSION_NUMBER >= 0x02010300
232229
static void http_error_cb(enum evhttp_request_error err, void *ctx)
233230
{
234231
HTTPReply *reply = static_cast<HTTPReply*>(ctx);
235232
reply->error = err;
236233
}
237-
#endif
238234

239235
/** Class that handles the conversion from a command-line to a JSON-RPC request,
240236
* as well as converting back to a JSON object that can be shown as result.
@@ -745,11 +741,11 @@ static UniValue CallRPC(BaseRequestHandler* rh, const std::string& strMethod, co
745741

746742
HTTPReply response;
747743
raii_evhttp_request req = obtain_evhttp_request(http_request_done, (void*)&response);
748-
if (req == nullptr)
744+
if (req == nullptr) {
749745
throw std::runtime_error("create http request failed");
750-
#if LIBEVENT_VERSION_NUMBER >= 0x02010300
746+
}
747+
751748
evhttp_request_set_error_cb(req.get(), http_error_cb);
752-
#endif
753749

754750
// Get credentials
755751
std::string strRPCUserColonPass;

src/httpserver.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,8 @@ bool InitHTTPServer()
360360

361361
// Redirect libevent's logging to our own log
362362
event_set_log_callback(&libevent_log_cb);
363-
// Update libevent's log handling. Returns false if our version of
364-
// libevent doesn't support debug logging, in which case we should
365-
// clear the BCLog::LIBEVENT flag.
366-
if (!UpdateHTTPServerLogging(LogInstance().WillLogCategory(BCLog::LIBEVENT))) {
367-
LogInstance().DisableCategory(BCLog::LIBEVENT);
368-
}
363+
// Update libevent's log handling.
364+
UpdateHTTPServerLogging(LogInstance().WillLogCategory(BCLog::LIBEVENT));
369365

370366
#ifdef WIN32
371367
evthread_use_windows_threads();
@@ -404,18 +400,12 @@ bool InitHTTPServer()
404400
return true;
405401
}
406402

407-
bool UpdateHTTPServerLogging(bool enable) {
408-
#if LIBEVENT_VERSION_NUMBER >= 0x02010100
403+
void UpdateHTTPServerLogging(bool enable) {
409404
if (enable) {
410405
event_enable_debug_logging(EVENT_DBG_ALL);
411406
} else {
412407
event_enable_debug_logging(EVENT_DBG_NONE);
413408
}
414-
return true;
415-
#else
416-
// Can't update libevent logging if version < 02010100
417-
return false;
418-
#endif
419409
}
420410

421411
static std::thread g_thread_http;

src/httpserver.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ void InterruptHTTPServer();
3232
/** Stop HTTP server */
3333
void StopHTTPServer();
3434

35-
/** Change logging level for libevent. Removes BCLog::LIBEVENT from log categories if
36-
* libevent doesn't support debug logging.*/
37-
bool UpdateHTTPServerLogging(bool enable);
35+
/** Change logging level for libevent. */
36+
void UpdateHTTPServerLogging(bool enable);
3837

3938
/** Handler for requests to a certain HTTP path */
4039
typedef std::function<bool(HTTPRequest* req, const std::string &)> HTTPRequestHandler;

src/rpc/misc.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -646,17 +646,8 @@ static RPCHelpMan logging()
646646
uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
647647

648648
// Update libevent logging if BCLog::LIBEVENT has changed.
649-
// If the library version doesn't allow it, UpdateHTTPServerLogging() returns false,
650-
// in which case we should clear the BCLog::LIBEVENT flag.
651-
// Throw an error if the user has explicitly asked to change only the libevent
652-
// flag and it failed.
653649
if (changed_log_categories & BCLog::LIBEVENT) {
654-
if (!UpdateHTTPServerLogging(LogInstance().WillLogCategory(BCLog::LIBEVENT))) {
655-
LogInstance().DisableCategory(BCLog::LIBEVENT);
656-
if (changed_log_categories == BCLog::LIBEVENT) {
657-
throw JSONRPCError(RPC_INVALID_PARAMETER, "libevent logging cannot be updated when using libevent before v2.1.1.");
658-
}
659-
}
650+
UpdateHTTPServerLogging(LogInstance().WillLogCategory(BCLog::LIBEVENT));
660651
}
661652

662653
UniValue result(UniValue::VOBJ);

src/test/fuzz/http_request.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,8 @@
1919
#include <string>
2020
#include <vector>
2121

22-
// workaround for libevent versions before 2.1.1,
23-
// when internal functions didn't have underscores at the end
24-
#if LIBEVENT_VERSION_NUMBER < 0x02010100
25-
extern "C" int evhttp_parse_firstline(struct evhttp_request*, struct evbuffer*);
26-
extern "C" int evhttp_parse_headers(struct evhttp_request*, struct evbuffer*);
27-
inline int evhttp_parse_firstline_(struct evhttp_request* r, struct evbuffer* b)
28-
{
29-
return evhttp_parse_firstline(r, b);
30-
}
31-
inline int evhttp_parse_headers_(struct evhttp_request* r, struct evbuffer* b)
32-
{
33-
return evhttp_parse_headers(r, b);
34-
}
35-
#else
3622
extern "C" int evhttp_parse_firstline_(struct evhttp_request*, struct evbuffer*);
3723
extern "C" int evhttp_parse_headers_(struct evhttp_request*, struct evbuffer*);
38-
#endif
3924

4025
std::string RequestMethodString(HTTPRequest::RequestMethod m);
4126

0 commit comments

Comments
 (0)