diff --git a/src/net_processing.cpp b/src/net_processing.cpp index d8b6339f34..3655ec3b13 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1042,9 +1042,9 @@ static bool IsLimitedPeer(const Peer& peer) static uint16_t GetHeadersLimit(const CNode& pfrom, const std::string& msg_type) { if (pfrom.GetCommonVersion() >= INCREASE_MAX_HEADERS2_VERSION && msg_type == NetMsgType::GETHEADERS2) { - return MAX_HEADERS2_RESULTS; + return MAX_HEADERS_COMPRESSED_RESULT; } - return MAX_HEADERS_RESULTS; + return MAX_HEADERS_UNCOMPRESSED_RESULTS; } static void PushInv(Peer& peer, const CInv& inv) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 0aa5a2dfdc..1932325458 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -996,7 +996,7 @@ static RPCHelpMan getblockheaders() "If verbose is true, each item is an Object with information about a single blockheader.\n", { {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, - {"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS2_RESULTS), ""}, + {"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS_COMPRESSED_RESULT), ""}, {"verbose", RPCArg::Type::BOOL, /* default */ "true", "true for a json object, false for the hex-encoded data"}, }, { @@ -1054,11 +1054,11 @@ static RPCHelpMan getblockheaders() throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); } - int nCount = MAX_HEADERS2_RESULTS; + int nCount = MAX_HEADERS_COMPRESSED_RESULT; if (!request.params[1].isNull()) nCount = request.params[1].get_int(); - if (nCount <= 0 || nCount > (int)MAX_HEADERS2_RESULTS) + if (nCount <= 0 || nCount > (int)MAX_HEADERS_COMPRESSED_RESULT) throw JSONRPCError(RPC_INVALID_PARAMETER, "Count is out of range"); bool fVerbose = true; @@ -1134,7 +1134,7 @@ static RPCHelpMan getmerkleblocks() { {"filter", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex-encoded bloom filter"}, {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, - {"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS2_RESULTS), ""}, + {"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS_COMPRESSED_RESULT), ""}, }, RPCResult{ RPCResult::Type::ARR, "", "", @@ -1163,11 +1163,11 @@ static RPCHelpMan getmerkleblocks() throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); } - int nCount = MAX_HEADERS2_RESULTS; + int nCount = MAX_HEADERS_COMPRESSED_RESULT; if (!request.params[2].isNull()) nCount = request.params[2].get_int(); - if (nCount <= 0 || nCount > (int)MAX_HEADERS2_RESULTS) { + if (nCount <= 0 || nCount > (int)MAX_HEADERS_COMPRESSED_RESULT) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Count is out of range"); } diff --git a/src/validation.h b/src/validation.h index 75b7590ffe..5e0b3b323d 100644 --- a/src/validation.h +++ b/src/validation.h @@ -85,8 +85,8 @@ static const int MAX_SCRIPTCHECK_THREADS = 15; static const int DEFAULT_SCRIPTCHECK_THREADS = 0; /** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends * less than this number, we reached its tip. Changing this value is a protocol upgrade. */ -static const unsigned int MAX_HEADERS_RESULTS = 2000; -static const unsigned int MAX_HEADERS2_RESULTS = 8000; +static const unsigned int MAX_HEADERS_UNCOMPRESSED_RESULTS = 2000; +static const unsigned int MAX_HEADERS_COMPRESSED_RESULT = 8000; static const int64_t DEFAULT_MAX_TIP_AGE = 6 * 60 * 60; // ~144 blocks behind -> 2 x fork detection time, was 24 * 60 * 60 in bitcoin diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py index 66adad810e..7efba787f7 100755 --- a/test/functional/p2p_invalid_messages.py +++ b/test/functional/p2p_invalid_messages.py @@ -10,8 +10,8 @@ from test_framework.messages import ( CInv, msg_ping, ser_string, - MAX_HEADERS_RESULTS, - MAX_HEADERS2_RESULTS, + MAX_HEADERS_UNCOMPRESSED_RESULTS, + MAX_HEADERS_COMPRESSED_RESULT, MAX_INV_SIZE, MAX_PROTOCOL_MESSAGE_LENGTH, msg_getdata, @@ -154,11 +154,11 @@ class InvalidMessagesTest(BitcoinTestFramework): self.test_oversized_msg(msg_getdata([CInv(MSG_TX, 1)] * size), size) def test_oversized_headers_msg(self): - size = MAX_HEADERS_RESULTS + 1 + size = MAX_HEADERS_UNCOMPRESSED_RESULTS + 1 self.test_oversized_msg(msg_headers([CBlockHeader()] * size), size) def test_oversized_headers2_msg(self): - size = MAX_HEADERS2_RESULTS + 1 + size = MAX_HEADERS_COMPRESSED_RESULT + 1 self.test_oversized_msg(msg_headers2([CBlockHeader()] * size), size) def test_resource_exhaustion(self): diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index dec3e75788..876ff1f27d 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -42,8 +42,8 @@ MAX_MONEY = 21000000 * COIN BIP125_SEQUENCE_NUMBER = 0xfffffffd # Sequence number that is BIP 125 opt-in and BIP 68-opt-out MAX_PROTOCOL_MESSAGE_LENGTH = 3 * 1024 * 1024 # Maximum length of incoming protocol messages -MAX_HEADERS_RESULTS = 2000 # Number of headers sent in one getheaders result -MAX_HEADERS2_RESULTS = 8000 # Number of headers2 sent in one getheaders2 result +MAX_HEADERS_UNCOMPRESSED_RESULTS = 2000 # Number of headers sent in one getheaders result +MAX_HEADERS_COMPRESSED_RESULT = 8000 # Number of headers2 sent in one getheaders2 result MAX_INV_SIZE = 50000 # Maximum number of entries in an 'inv' protocol message NODE_NETWORK = (1 << 0) diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index 8e79ed75e1..14e25286e9 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -31,8 +31,8 @@ import threading from test_framework.messages import ( CBlockHeader, CompressibleBlockHeader, - MAX_HEADERS_RESULTS, - MAX_HEADERS2_RESULTS, + MAX_HEADERS_UNCOMPRESSED_RESULTS, + MAX_HEADERS_COMPRESSED_RESULT, NODE_HEADERS_COMPRESSED, msg_addr, msg_addrv2, @@ -734,7 +734,7 @@ class P2PDataStore(P2PInterface): break # Truncate the list if there are too many headers - max_results = MAX_HEADERS2_RESULTS if use_headers2 else MAX_HEADERS_RESULTS + max_results = MAX_HEADERS_COMPRESSED_RESULT if use_headers2 else MAX_HEADERS_UNCOMPRESSED_RESULTS headers_list = headers_list[:-max_results - 1:-1] return headers_list