feat: stricter bestCLHeightDiff checks

This commit is contained in:
UdjinM6 2024-06-28 20:37:47 +03:00
parent b316be7680
commit 4e86bda4dc
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9
3 changed files with 15 additions and 15 deletions

View File

@ -330,7 +330,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
} }
bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex, bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex,
const llmq::CChainLocksHandler& chainlock_handler, BlockValidationState& state) const llmq::CChainLocksHandler& chainlock_handler, BlockValidationState& state, const bool check_clhdiff)
{ {
if (block.vtx[0]->nType != TRANSACTION_COINBASE) { if (block.vtx[0]->nType != TRANSACTION_COINBASE) {
return true; return true;
@ -351,18 +351,18 @@ bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex,
return true; return true;
} }
auto prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(pindex); if (check_clhdiff) {
// If std::optional prevBlockCoinbaseChainlock is empty, then up to the previous block, coinbase Chainlock is null. auto prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(pindex->pprev);
if (prevBlockCoinbaseChainlock.has_value()) { // If std::optional prevBlockCoinbaseChainlock is empty, then up to the previous block, coinbase Chainlock is null.
// Previous block Coinbase has a non-null Chainlock: current block's Chainlock must be non-null and at least as new as the previous one if (prevBlockCoinbaseChainlock.has_value()) {
if (!opt_cbTx->bestCLSignature.IsValid()) { // Previous block Coinbase has a non-null Chainlock: current block's Chainlock must be non-null and at least as new as the previous one
// IsNull() doesn't exist for CBLSSignature: we assume that a non valid BLS sig is null if (!opt_cbTx->bestCLSignature.IsValid()) {
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-null-clsig"); // IsNull() doesn't exist for CBLSSignature: we assume that a non valid BLS sig is null
} return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-null-clsig");
int prevBlockCoinbaseCLHeight = pindex->nHeight - static_cast<int>(prevBlockCoinbaseChainlock.value().second) - 1; }
int curBlockCoinbaseCLHeight = pindex->nHeight - static_cast<int>(opt_cbTx->bestCLHeightDiff) - 1; if (opt_cbTx->bestCLHeightDiff > prevBlockCoinbaseChainlock.value().second + 1) {
if (curBlockCoinbaseCLHeight < prevBlockCoinbaseCLHeight) { return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-older-clsig");
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-older-clsig"); }
} }
} }

View File

@ -96,7 +96,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
BlockValidationState& state); BlockValidationState& state);
bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindexPrev, bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindexPrev,
const llmq::CChainLocksHandler& chainlock_handler, BlockValidationState& state); const llmq::CChainLocksHandler& chainlock_handler, BlockValidationState& state, const bool check_clhdiff);
bool CalcCbTxBestChainlock(const llmq::CChainLocksHandler& chainlock_handler, const CBlockIndex* pindexPrev, bool CalcCbTxBestChainlock(const llmq::CChainLocksHandler& chainlock_handler, const CBlockIndex* pindexPrev,
uint32_t& bestCLHeightDiff, CBLSSignature& bestCLSignature); uint32_t& bestCLHeightDiff, CBLSSignature& bestCLSignature);

View File

@ -200,7 +200,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
nTimeMerkle += nTime5 - nTime4; nTimeMerkle += nTime5 - nTime4;
LogPrint(BCLog::BENCHMARK, " - CheckCbTxMerkleRoots: %.2fms [%.2fs]\n", 0.001 * (nTime5 - nTime4), nTimeMerkle * 0.000001); LogPrint(BCLog::BENCHMARK, " - CheckCbTxMerkleRoots: %.2fms [%.2fs]\n", 0.001 * (nTime5 - nTime4), nTimeMerkle * 0.000001);
if (fCheckCbTxMerkleRoots && !CheckCbTxBestChainlock(block, pindex, m_clhandler, state)) { if (fCheckCbTxMerkleRoots && !CheckCbTxBestChainlock(block, pindex, m_clhandler, state, DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_MN_RR))) {
// pass the state returned by the function above // pass the state returned by the function above
return false; return false;
} }