Skip to content
Closed
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: 4 additions & 5 deletions src/llmq/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,12 +869,11 @@ std::optional<CInv> CQuorumBlockProcessor::AddMineableCommitment(const CFinalCom
minableCommitments.try_emplace(commitmentHash, fqc);
return true;
} else {
auto& insertedQuorumHash = itInserted->second;
const auto& oldFqc = minableCommitments.at(insertedQuorumHash);
if (fqc.CountSigners() > oldFqc.CountSigners()) {
auto& knownCommitmentHash = itInserted->second;
if (fqc.CountSigners() > minableCommitments.at(knownCommitmentHash).CountSigners()) {
// new commitment has more signers, so override the known one
insertedQuorumHash = commitmentHash;
minableCommitments.erase(insertedQuorumHash);
minableCommitments.erase(knownCommitmentHash);
knownCommitmentHash = commitmentHash;
minableCommitments.try_emplace(commitmentHash, fqc);
return true;
}
Expand Down
41 changes: 41 additions & 0 deletions src/test/llmq_blockprocessor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,45 @@ BOOST_FIXTURE_TEST_CASE(unrequested_qfcommit_is_dropped_and_scored, TestChain100
SetMockTime(0s);
}

// net_processing answers AlreadyHave for QFCOMMITMENT invs with HasMineableCommitment and GETDATA
// with GetMineableCommitmentByHash, so a superseded commitment that either lookup still finds is one
// this node keeps serving to peers.
BOOST_FIXTURE_TEST_CASE(superseded_mineable_commitment_is_dropped, RegTestingSetup)
{
auto& blockprocessor = *m_node.llmq_ctx->quorum_block_processor;
const auto& llmq_params = GetLLMQParams(Consensus::LLMQType::LLMQ_TEST);
const uint256 quorum_hash = GetTestQuorumHash(1);

auto worse = CreateValidCommitment(llmq_params, quorum_hash);
worse.signers = CreateBitVector(llmq_params.size, {0, 1});
auto better = CreateValidCommitment(llmq_params, quorum_hash);
auto tied = better;
tied.quorumVvecHash = InsecureRand256();
const uint256 worse_hash = ::SerializeHash(worse);
const uint256 better_hash = ::SerializeHash(better);
const uint256 tied_hash = ::SerializeHash(tied);

const auto worse_inv = blockprocessor.AddMineableCommitment(worse);
BOOST_REQUIRE(worse_inv.has_value());
BOOST_CHECK(worse_inv->hash == worse_hash);
BOOST_CHECK(blockprocessor.HasMineableCommitment(worse_hash));

const auto better_inv = blockprocessor.AddMineableCommitment(better);
BOOST_REQUIRE(better_inv.has_value());
BOOST_CHECK(better_inv->hash == better_hash);

CFinalCommitment found;
BOOST_CHECK(blockprocessor.GetMineableCommitmentByHash(better_hash, found));
BOOST_CHECK(::SerializeHash(found) == better_hash);
BOOST_CHECK(!blockprocessor.HasMineableCommitment(worse_hash));
BOOST_CHECK(!blockprocessor.GetMineableCommitmentByHash(worse_hash, found));

// Neither a worse nor an equally good commitment displaces the kept one, and neither is stored.
BOOST_CHECK(!blockprocessor.AddMineableCommitment(worse).has_value());
BOOST_CHECK(!blockprocessor.AddMineableCommitment(tied).has_value());
BOOST_CHECK(blockprocessor.HasMineableCommitment(better_hash));
BOOST_CHECK(!blockprocessor.HasMineableCommitment(worse_hash));
BOOST_CHECK(!blockprocessor.HasMineableCommitment(tied_hash));
}

BOOST_AUTO_TEST_SUITE_END()
Loading