Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/evo/specialtxman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,11 @@ bool CSpecialTxProcessor::UndoSpecialTxsInBlock(const Chainstate& chainstate, co
return true;
}

void CSpecialTxProcessor::RemoveMineableCommitmentsForBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindex)
{
m_qblockman.RemoveMineableCommitmentsForBlock(block, pindex);
}

bool CSpecialTxProcessor::CheckCreditPoolDiffForBlock(const CBlock& block, const CBlockIndex* pindex, const CCbTx& cbTx,
CAmount blockSubsidy, BlockValidationState& state)
{
Expand Down
2 changes: 2 additions & 0 deletions src/evo/specialtxman.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class CSpecialTxProcessor
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
bool UndoSpecialTxsInBlock(const Chainstate& chainstate, const CBlock& block, const CBlockIndex* pindex, MNListUpdates& updatesRet)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
void RemoveMineableCommitmentsForBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindex)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);


// the returned list will not contain the correct block hash (we can't know it yet as the coinbase TX is not updated yet)
Expand Down
28 changes: 20 additions & 8 deletions src/llmq/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <evo/specialtx.h>
#include <llmq/commitment.h>
#include <llmq/utils.h>
#include <util/check.h>
#include <util/helpers.h>
#include <util/std23.h>

Expand Down Expand Up @@ -253,8 +254,7 @@ bool CQuorumBlockProcessor::ProcessBlock(Chainstate& chainstate, const CBlock& b

// ProcessCommitment accepts a commitment identical to the stored one, so
// rotation's multiple commitments per type need an explicit per-block check.
// It runs before any commitment is processed, because ProcessCommitment
// updates in-memory state that a rejected block would not restore.
// It runs before the signature checks, so a duplicate is rejected cheaply.
// Null commitments stay exempt: they were never subject to bad-qc-dup.
std::set<std::pair<Consensus::LLMQType, uint256>> seen_quorums;
for (const auto& [_, qc] : qcs) {
Expand Down Expand Up @@ -444,12 +444,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(Chainstate& chainstate, int nHeigh
// invalidation should not depend on that.
DropQcHashesCache();

{
LOCK(minableCommitmentsCs);
mapMinedCommitmentBlockCache.erase(qc.llmqType, qc.quorumHash);
minableCommitmentsByQuorum.erase(cacheKey);
minableCommitments.erase(::SerializeHash(qc));
}
WITH_LOCK(minableCommitmentsCs, mapMinedCommitmentBlockCache.erase(qc.llmqType, qc.quorumHash));

LogPrint(BCLog::LLMQ, "%s -- processed commitment from block. type=%d, quorumIndex=%d, quorumHash=%s\n", __func__,
std23::to_underlying(qc.llmqType), qc.quorumIndex, quorumHash.ToString());
Expand Down Expand Up @@ -560,6 +555,23 @@ bool CQuorumBlockProcessor::UndoBlock(const Chainstate& chainstate, const CBlock
return true;
}

void CQuorumBlockProcessor::RemoveMineableCommitmentsForBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindex)
{
AssertLockHeld(::cs_main);

std::multimap<Consensus::LLMQType, CFinalCommitment> qcs;
if (BlockValidationState dummy; !Assume(GetCommitmentsFromBlock(block, pindex, qcs, dummy))) {
return;
}

LOCK(minableCommitmentsCs);
for (const auto& [_, qc] : qcs) {
if (qc.IsNull()) continue;
minableCommitmentsByQuorum.erase(std::make_pair(qc.llmqType, qc.quorumHash));
minableCommitments.erase(::SerializeHash(qc));
}
}

std::shared_ptr<const CFinalCommitmentTxPayload> CQuorumBlockProcessor::GetCommitmentTxPayload(const CTransaction& tx) const
{
const uint256& tx_hash{tx.GetHash()};
Expand Down
3 changes: 3 additions & 0 deletions src/llmq/blockprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class CQuorumBlockProcessor
EXCLUSIVE_LOCKS_REQUIRED(::cs_main, !minableCommitmentsCs, !m_qc_hashes_cache_mutex, !m_commitment_payload_mutex);
bool UndoBlock(const Chainstate& chainstate, const CBlock& block, gsl::not_null<const CBlockIndex*> pindex)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main, !minableCommitmentsCs, !m_qc_hashes_cache_mutex, !m_commitment_payload_mutex);
//! Drop the commitments mined by a block that has been fully connected from the mineable pool.
void RemoveMineableCommitmentsForBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindex)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main, !minableCommitmentsCs, !m_commitment_payload_mutex);

//! The parsed payload of a quorum commitment transaction, or nullptr if it does not parse.
std::shared_ptr<const CFinalCommitmentTxPayload> GetCommitmentTxPayload(const CTransaction& tx) const
Expand Down
2 changes: 2 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3108,6 +3108,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,

// Block is committed: keep the scheme it switched to (fJustCheck dry runs returned above).
bls_scheme_guard.Commit();
m_special_tx.RemoveMineableCommitmentsForBlock(block, pindex);

if (this == &m_chainman.ActiveChainstate() && mnlist_updates.diff.HasChanges()) {
GetMainSignals().NotifyMasternodeListChanged(false, mnlist_updates.old_list, mnlist_updates.diff);
Expand Down Expand Up @@ -5386,6 +5387,7 @@ bool Chainstate::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& in
return false;
}
RecordBackgroundMNListHash(pindex, mnlist_updates.new_list);
m_special_tx.RemoveMineableCommitmentsForBlock(block, pindex);

for (size_t i = 0; i < block.vtx.size(); i++) {
const CTransactionRef& tx = block.vtx[i];
Expand Down
11 changes: 11 additions & 0 deletions test/functional/feature_llmq_dkgerrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ def test_qc(self):
# TODO: test signers
# TODO: test validMembers

# The commitment is mineable again after invalidateblock and must stay so when a block that
# carries it is rejected by a check that runs after the commitments were processed
assert self.node_has_quorum_commitment(self.nodes[0], quorumHash, 100)
bad_block = copy.deepcopy(block)
bad_block.vtx[0].vout[0].nValue += 1
bad_block.vtx[0].rehash()
bad_block.hashMerkleRoot = bad_block.calc_merkle_root()
bad_block.solve()
assert_equal(self.nodes[0].submitblock(bad_block.serialize().hex()), 'bad-cb-amount')
assert self.node_has_quorum_commitment(self.nodes[0], quorumHash, 100)

self.nodes[0].reconsiderblock(best)
# Mine 8 (SIGN_HEIGHT_OFFSET) more blocks to make sure that the new quorum gets eligible for signing sessions
self.generate(self.nodes[0], 8, sync_fun=lambda: self.sync_blocks(self.nodes))
Expand Down
Loading