Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/llmq/snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include <univalue.h>

#include <algorithm>

namespace {
constexpr std::string_view DB_QUORUM_SNAPSHOT{"llmq_S"};

Expand Down Expand Up @@ -74,10 +76,9 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan
}
baseBlockIndexes.push_back(blockIndex);
}
if (use_legacy_construction) {
std::sort(baseBlockIndexes.begin(), baseBlockIndexes.end(),
[](const CBlockIndex* a, const CBlockIndex* b) { return a->nHeight < b->nHeight; });
}
std::sort(baseBlockIndexes.begin(), baseBlockIndexes.end(),
[](const CBlockIndex* a, const CBlockIndex* b) { return a->nHeight < b->nHeight; });
baseBlockIndexes.erase(std::unique(baseBlockIndexes.begin(), baseBlockIndexes.end()), baseBlockIndexes.end());
}

const CBlockIndex* tipBlockIndex = chainman.ActiveChain().Tip();
Expand Down
34 changes: 34 additions & 0 deletions src/test/llmq_snapshot_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <test/util/llmq_tests.h>
#include <test/util/setup_common.h>

#include <chain.h>
#include <streams.h>
#include <univalue.h>

Expand Down Expand Up @@ -176,6 +177,39 @@ BOOST_AUTO_TEST_CASE(quorum_rotation_info_construction_test)
// Note: CQuorumRotationInfo serialization requires complex setup
// This is better tested in functional tests

BOOST_AUTO_TEST_CASE(get_last_base_block_hash_repeated_base_blocks_test)
{
std::vector<CBlockIndex> blocks(4);
std::vector<uint256> hashes{
GetTestBlockHash(10),
GetTestBlockHash(20),
GetTestBlockHash(30),
GetTestBlockHash(40),
};
for (size_t i{0}; i < blocks.size(); ++i) {
blocks[i].nHeight = static_cast<int>((i + 1) * 10);
blocks[i].phashBlock = &hashes[i];
}

std::vector<const CBlockIndex*> unsorted_repeated_base_blocks{
&blocks[2],
&blocks[0],
&blocks[1],
&blocks[1],
};
BOOST_CHECK(GetLastBaseBlockHash(unsorted_repeated_base_blocks, &blocks[3], false) == hashes[2]);
BOOST_CHECK(GetLastBaseBlockHash(unsorted_repeated_base_blocks, &blocks[1], false) == hashes[1]);

std::vector<const CBlockIndex*> sorted_repeated_base_blocks{
&blocks[0],
&blocks[1],
&blocks[1],
&blocks[2],
};
BOOST_CHECK(GetLastBaseBlockHash(sorted_repeated_base_blocks, &blocks[3], true) == hashes[2]);
BOOST_CHECK(GetLastBaseBlockHash(sorted_repeated_base_blocks, &blocks[1], true) == hashes[1]);
}

BOOST_AUTO_TEST_CASE(get_quorum_rotation_info_serialization_test)
{
CGetQuorumRotationInfo getInfo;
Expand Down
3 changes: 3 additions & 0 deletions test/functional/feature_llmq_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ def run_test(self):
hmc_base_blockhash = self.nodes[0].getblockhash(block_count - (block_count % 24) - 24 - 8)
best_block_hash = self.nodes[0].getbestblockhash()
rpc_qr_info = self.nodes[0].quorum("rotationinfo", best_block_hash, False, [hmc_base_blockhash])
rpc_qr_info_repeated_base = self.nodes[0].quorum("rotationinfo", best_block_hash, False,
[hmc_base_blockhash, hmc_base_blockhash])
assert_equal(rpc_qr_info_repeated_base, rpc_qr_info)
assert_equal(rpc_qr_info["mnListDiffTip"]["blockHash"], best_block_hash)
assert_equal(rpc_qr_info["mnListDiffTip"]["baseBlockHash"], rpc_qr_info["mnListDiffH"]["blockHash"])
assert_equal(rpc_qr_info["mnListDiffH"]["baseBlockHash"], rpc_qr_info["mnListDiffAtHMinusC"]["blockHash"])
Expand Down
Loading