Skip to content

Commit 190a405

Browse files
committed
Merge #17762: net: Log to net category for exceptions in ProcessMessages
4bdd68f Add missing typeinfo includes (Wladimir J. van der Laan) 4d88c3d net: Log to net category for exceptions in ProcessMessages (Wladimir J. van der Laan) Pull request description: Remove the forest of special exceptions based on string matching, and simply log a short message to the NET logging category when an exception happens during packet processing. It is not good to panick end users with verbose errors (let alone writing to stderr) when any peer can generate them. ACKs for top commit: MarcoFalke: re-ACK 4bdd68f (only change is adding includes) 🕕 promag: ACK 4bdd68f, could squash. Tree-SHA512: a005591a3202b005c75e01dfa54249db3992e2f9eefa8b3d9d435acf66130417716ed926ce4e045179cf43788f1abc7362d999750681a9c80b318373d611c366
2 parents 52900a7 + 4bdd68f commit 190a405

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

src/net_processing.cpp

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <util/validation.h>
3030

3131
#include <memory>
32+
#include <typeinfo>
3233

3334
#if defined(NDEBUG)
3435
# error "Bitcoin cannot be compiled without assertions."
@@ -3333,32 +3334,10 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
33333334
return false;
33343335
if (!pfrom->vRecvGetData.empty())
33353336
fMoreWork = true;
3336-
}
3337-
catch (const std::ios_base::failure& e)
3338-
{
3339-
if (strstr(e.what(), "end of data")) {
3340-
// Allow exceptions from under-length message on vRecv
3341-
LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' caught, normally caused by a message being shorter than its stated length\n", __func__, SanitizeString(strCommand), nMessageSize, e.what());
3342-
} else if (strstr(e.what(), "size too large")) {
3343-
// Allow exceptions from over-long size
3344-
LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what());
3345-
} else if (strstr(e.what(), "non-canonical ReadCompactSize()")) {
3346-
// Allow exceptions from non-canonical encoding
3347-
LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what());
3348-
} else if (strstr(e.what(), "Superfluous witness record")) {
3349-
// Allow exceptions from illegal witness encoding
3350-
LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what());
3351-
} else if (strstr(e.what(), "Unknown transaction optional data")) {
3352-
// Allow exceptions from unknown witness encoding
3353-
LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what());
3354-
} else {
3355-
PrintExceptionContinue(&e, "ProcessMessages()");
3356-
}
3357-
}
3358-
catch (const std::exception& e) {
3359-
PrintExceptionContinue(&e, "ProcessMessages()");
3337+
} catch (const std::exception& e) {
3338+
LogPrint(BCLog::NET, "%s(%s, %u bytes): Exception '%s' (%s) caught\n", __func__, SanitizeString(strCommand), nMessageSize, e.what(), typeid(e).name());
33603339
} catch (...) {
3361-
PrintExceptionContinue(nullptr, "ProcessMessages()");
3340+
LogPrint(BCLog::NET, "%s(%s, %u bytes): Unknown exception caught\n", __func__, SanitizeString(strCommand), nMessageSize);
33623341
}
33633342

33643343
if (!fRet) {

src/util/system.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#endif
6565

6666
#include <thread>
67+
#include <typeinfo>
6768
#include <univalue.h>
6869

6970
// Application startup time (used for uptime calculation)

0 commit comments

Comments
 (0)