diff --git a/src/headerssync.cpp b/src/headerssync.cpp index e14de004f5..06d282162b 100644 --- a/src/headerssync.cpp +++ b/src/headerssync.cpp @@ -13,15 +13,16 @@ // contrib/devtools/headerssync-params.py. //! Store one header commitment per HEADER_COMMITMENT_PERIOD blocks. -constexpr size_t HEADER_COMMITMENT_PERIOD{606}; +constexpr size_t HEADER_COMMITMENT_PERIOD{59}; //! Only feed headers to validation once this many headers on top have been //! received and validated against commitments. -constexpr size_t REDOWNLOAD_BUFFER_SIZE{14441}; // 14441/606 = ~23.8 commitments +constexpr size_t REDOWNLOAD_BUFFER_SIZE{741}; // 741/59 = ~12.6 commitments -// Our memory analysis assumes 48 bytes for a CompressedHeader (so we should +// Our memory analysis assumes 176 bytes for a CompressedHeader (so we should // re-calculate parameters if we compress further) -static_assert(sizeof(CompressedHeader) == 48); +// 160 bytes for a CompressedHeader is for ARM Linux +static_assert(sizeof(CompressedHeader) == 176 || sizeof(CompressedHeader) == 160); HeadersSyncState::HeadersSyncState(NodeId id, const Consensus::Params& consensus_params, const CBlockIndex* chain_start, const arith_uint256& minimum_required_work) : @@ -146,7 +147,8 @@ bool HeadersSyncState::ValidateAndStoreHeadersCommitments(const std::vector vchBlockSigDlgt; CompressedHeader() { hashMerkleRoot.SetNull(); + hashStateRoot.SetNull(); + hashUTXORoot.SetNull(); + vchBlockSigDlgt.clear(); + prevoutStake.SetNull(); } CompressedHeader(const CBlockHeader& header) @@ -38,6 +46,10 @@ struct CompressedHeader { nTime = header.nTime; nBits = header.nBits; nNonce = header.nNonce; + hashStateRoot = header.hashStateRoot; + hashUTXORoot = header.hashUTXORoot; + vchBlockSigDlgt = header.vchBlockSigDlgt; + prevoutStake = header.prevoutStake; } CBlockHeader GetFullHeader(const uint256& hash_prev_block) { @@ -48,6 +60,10 @@ struct CompressedHeader { ret.nTime = nTime; ret.nBits = nBits; ret.nNonce = nNonce; + ret.hashStateRoot = hashStateRoot; + ret.hashUTXORoot = hashUTXORoot; + ret.vchBlockSigDlgt = vchBlockSigDlgt; + ret.prevoutStake = prevoutStake; return ret; }; }; diff --git a/src/net.cpp b/src/net.cpp index 7c82f01d75..aedb902c69 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -725,8 +725,8 @@ int V1Transport::readHeader(Span msg_bytes) return -1; } - // reject messages larger than MAX_SIZE or MAX_PROTOCOL_MESSAGE_LENGTH - if (hdr.nMessageSize > MAX_SIZE || hdr.nMessageSize > MAX_PROTOCOL_MESSAGE_LENGTH) { + // reject messages larger than MAX_SIZE or dgpMaxProtoMsgLength + if (hdr.nMessageSize > MAX_SIZE || hdr.nMessageSize > dgpMaxProtoMsgLength) { LogPrint(BCLog::NET, "Header error: Size too large (%s, %u bytes), peer=%d\n", SanitizeString(hdr.GetCommand()), hdr.nMessageSize, m_node_id); return -1; } @@ -1175,9 +1175,9 @@ bool V2Transport::ProcessReceivedPacketBytes() noexcept // - 0x00 byte: indicating long message type encoding // - 12 bytes of message type // - payload - static constexpr size_t MAX_CONTENTS_LEN = + size_t MAX_CONTENTS_LEN = 1 + CMessageHeader::COMMAND_SIZE + - std::min(MAX_SIZE, MAX_PROTOCOL_MESSAGE_LENGTH); + std::min(MAX_SIZE, dgpMaxProtoMsgLength); if (m_recv_buffer.size() == BIP324Cipher::LENGTH_LEN) { // Length descriptor received. @@ -3626,7 +3626,7 @@ bool CConnman::OutboundTargetReached(bool historicalBlockServingLimit) const { // keep a large enough buffer to at least relay each block once const std::chrono::seconds timeLeftInCycle = GetMaxOutboundTimeLeftInCycle_(); - const uint64_t buffer = timeLeftInCycle / std::chrono::minutes{10} * MAX_BLOCK_SERIALIZED_SIZE; + const uint64_t buffer = timeLeftInCycle / std::chrono::minutes{10} * dgpMaxBlockSerSize; if (buffer >= nMaxOutboundLimit || nMaxOutboundTotalBytesSentInCycle >= nMaxOutboundLimit - buffer) return true; } diff --git a/src/net.h b/src/net.h index e78e122c44..322bf71496 100644 --- a/src/net.h +++ b/src/net.h @@ -64,8 +64,8 @@ static constexpr std::chrono::minutes TIMEOUT_INTERVAL{20}; static constexpr auto FEELER_INTERVAL = 2min; /** Run the extra block-relay-only connection loop once every 5 minutes. **/ static constexpr auto EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL = 5min; -/** Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable). */ -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1000 * 1000; +/** Maximum length of incoming protocol messages (no message over 20 MB is currently acceptable). */ +extern unsigned int dgpMaxProtoMsgLength; /** Maximum length of the user agent string in `version` message */ static const unsigned int MAX_SUBVERSION_LENGTH = 256; /** Maximum number of automatic outgoing nodes over which we'll relay everything (blocks, tx, addrs, etc) */ diff --git a/src/policy/policy.h b/src/policy/policy.h index 6a7980c312..c064fdce11 100644 --- a/src/policy/policy.h +++ b/src/policy/policy.h @@ -121,6 +121,11 @@ static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS{STANDARD_SCRIP /** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */ static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE}; +/** The number of sender stack items in a standard sender signature script */ +static constexpr unsigned int STANDARD_SENDER_STACK_ITEMS{2}; +/** The maximum size of each sender stack item in a standard sender signature script */ +static constexpr unsigned int MAX_STANDARD_SENDER_STACK_ITEM_SIZE{80}; + CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee); bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee); diff --git a/src/rest.cpp b/src/rest.cpp index 91184745c8..88f8576dcd 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -587,7 +587,7 @@ static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std: switch (rf) { case RESTResponseFormat::JSON: { - JSONRPCRequest jsonRequest; + JSONRPCRequestLong jsonRequest(req); jsonRequest.context = context; jsonRequest.params = UniValue(UniValue::VARR); UniValue chainInfoObject = getblockchaininfo().HandleRequest(jsonRequest); diff --git a/src/test/fuzz/process_message.cpp b/src/test/fuzz/process_message.cpp index 56b391ed5c..6a09ab302c 100644 --- a/src/test/fuzz/process_message.cpp +++ b/src/test/fuzz/process_message.cpp @@ -75,7 +75,7 @@ FUZZ_TARGET(process_message, .init = initialize_process_message) CSerializedNetMsg net_msg; net_msg.m_type = random_message_type; - net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider, MAX_PROTOCOL_MESSAGE_LENGTH); + net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider, dgpMaxProtoMsgLength); connman.FlushSendBuffer(p2p_node); (void)connman.ReceiveMsgFrom(p2p_node, std::move(net_msg)); diff --git a/src/test/fuzz/process_messages.cpp b/src/test/fuzz/process_messages.cpp index 6b264907b5..4de90a63ec 100644 --- a/src/test/fuzz/process_messages.cpp +++ b/src/test/fuzz/process_messages.cpp @@ -71,7 +71,7 @@ FUZZ_TARGET(process_messages, .init = initialize_process_messages) CSerializedNetMsg net_msg; net_msg.m_type = random_message_type; - net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider, MAX_PROTOCOL_MESSAGE_LENGTH); + net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider, dgpMaxProtoMsgLength); CNode& random_node = *PickValue(fuzzed_data_provider, peers); diff --git a/src/validation.cpp b/src/validation.cpp index 419f7844df..2e8601fdfa 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -33,11 +34,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -45,6 +48,7 @@ #include