From 4b9f6cd3a9aed783c08e1c1961e6a5fdd24abb75 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 5 Apr 2019 13:39:29 +0200 Subject: [PATCH] Use big endian inversed height in BuildInversedHeightKey Otherwise keys are not properly sorted. --- src/llmq/quorums_blockprocessor.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/llmq/quorums_blockprocessor.cpp b/src/llmq/quorums_blockprocessor.cpp index 209f64cb9..793ab1ed3 100644 --- a/src/llmq/quorums_blockprocessor.cpp +++ b/src/llmq/quorums_blockprocessor.cpp @@ -25,7 +25,7 @@ CQuorumBlockProcessor* quorumBlockProcessor; static const std::string DB_MINED_COMMITMENT = "q_mc"; static const std::string DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT = "q_mcih"; -static const std::string DB_BEST_BLOCK_UPGRADE = "q_bbu"; +static const std::string DB_BEST_BLOCK_UPGRADE = "q_bbu2"; void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman) { @@ -168,9 +168,10 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* // We store a mapping from minedHeight->quorumHeight in the DB // minedHeight is inversed so that entries are traversable in reversed order -static std::tuple BuildInversedHeightKey(Consensus::LLMQType llmqType, int nMinedHeight) +static std::tuple BuildInversedHeightKey(Consensus::LLMQType llmqType, int nMinedHeight) { - return std::make_tuple(DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT, (uint8_t)llmqType, std::numeric_limits::max() - nMinedHeight); + // nMinedHeight must be converted to big endian to make it comparable when serialized + return std::make_tuple(DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT, (uint8_t)llmqType, htobe32(std::numeric_limits::max() - nMinedHeight)); } bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state) @@ -422,7 +423,7 @@ std::vector CQuorumBlockProcessor::GetMinedCommitmentsUntilB break; } - int nMinedHeight = std::numeric_limits::max() - std::get<2>(curKey); + uint32_t nMinedHeight = std::numeric_limits::max() - be32toh(std::get<2>(curKey)); if (nMinedHeight > pindex->nHeight) { break; }