From 07876b2c4a539b55bac476ee8a2241cff3c2a3aa Mon Sep 17 00:00:00 2001 From: pasta Date: Fri, 6 Sep 2024 15:13:47 -0500 Subject: [PATCH] use `MAX_HEADERS_UNCOMPRESSED_RESULT` not `MAX_HEADERS_UNCOMPRESSED_RESULTS` ; use `MAX_HEADERS_UNCOMPRESSED_RESULT` in RPC to avoid breaking changes --- src/net_processing.cpp | 2 +- src/rpc/blockchain.cpp | 12 ++++++------ src/validation.h | 2 +- test/functional/p2p_invalid_messages.py | 4 ++-- test/functional/test_framework/messages.py | 2 +- test/functional/test_framework/p2p.py | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 3655ec3b13..d38b972fdc 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1044,7 +1044,7 @@ 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_HEADERS_COMPRESSED_RESULT; } - return MAX_HEADERS_UNCOMPRESSED_RESULTS; + return MAX_HEADERS_UNCOMPRESSED_RESULT; } static void PushInv(Peer& peer, const CInv& inv) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 1932325458..d55e8d120a 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_HEADERS_COMPRESSED_RESULT), ""}, + {"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS_UNCOMPRESSED_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_HEADERS_COMPRESSED_RESULT; + int nCount = MAX_HEADERS_UNCOMPRESSED_RESULT; if (!request.params[1].isNull()) nCount = request.params[1].get_int(); - if (nCount <= 0 || nCount > (int)MAX_HEADERS_COMPRESSED_RESULT) + if (nCount <= 0 || nCount > (int)MAX_HEADERS_UNCOMPRESSED_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_HEADERS_COMPRESSED_RESULT), ""}, + {"count", RPCArg::Type::NUM, /* default */ strprintf("%s", MAX_HEADERS_UNCOMPRESSED_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_HEADERS_COMPRESSED_RESULT; + int nCount = MAX_HEADERS_UNCOMPRESSED_RESULT; if (!request.params[2].isNull()) nCount = request.params[2].get_int(); - if (nCount <= 0 || nCount > (int)MAX_HEADERS_COMPRESSED_RESULT) { + if (nCount <= 0 || nCount > (int)MAX_HEADERS_UNCOMPRESSED_RESULT) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Count is out of range"); } diff --git a/src/validation.h b/src/validation.h index 5e0b3b323d..2365aead49 100644 --- a/src/validation.h +++ b/src/validation.h @@ -85,7 +85,7 @@ 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_UNCOMPRESSED_RESULTS = 2000; +static const unsigned int MAX_HEADERS_UNCOMPRESSED_RESULT = 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 7efba787f7..fb4691445f 100755 --- a/test/functional/p2p_invalid_messages.py +++ b/test/functional/p2p_invalid_messages.py @@ -10,7 +10,7 @@ from test_framework.messages import ( CInv, msg_ping, ser_string, - MAX_HEADERS_UNCOMPRESSED_RESULTS, + MAX_HEADERS_UNCOMPRESSED_RESULT, MAX_HEADERS_COMPRESSED_RESULT, MAX_INV_SIZE, MAX_PROTOCOL_MESSAGE_LENGTH, @@ -154,7 +154,7 @@ class InvalidMessagesTest(BitcoinTestFramework): self.test_oversized_msg(msg_getdata([CInv(MSG_TX, 1)] * size), size) def test_oversized_headers_msg(self): - size = MAX_HEADERS_UNCOMPRESSED_RESULTS + 1 + size = MAX_HEADERS_UNCOMPRESSED_RESULT + 1 self.test_oversized_msg(msg_headers([CBlockHeader()] * size), size) def test_oversized_headers2_msg(self): diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 876ff1f27d..a39d44b67a 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -42,7 +42,7 @@ 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_UNCOMPRESSED_RESULTS = 2000 # Number of headers sent in one getheaders result +MAX_HEADERS_UNCOMPRESSED_RESULT = 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 diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index 14e25286e9..bb17959b0c 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -31,7 +31,7 @@ import threading from test_framework.messages import ( CBlockHeader, CompressibleBlockHeader, - MAX_HEADERS_UNCOMPRESSED_RESULTS, + MAX_HEADERS_UNCOMPRESSED_RESULT, MAX_HEADERS_COMPRESSED_RESULT, NODE_HEADERS_COMPRESSED, msg_addr, @@ -734,7 +734,7 @@ class P2PDataStore(P2PInterface): break # Truncate the list if there are too many headers - max_results = MAX_HEADERS_COMPRESSED_RESULT if use_headers2 else MAX_HEADERS_UNCOMPRESSED_RESULTS + max_results = MAX_HEADERS_COMPRESSED_RESULT if use_headers2 else MAX_HEADERS_UNCOMPRESSED_RESULT headers_list = headers_list[:-max_results - 1:-1] return headers_list