mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
feat: stricter bestCLHeightDiff checks
This commit is contained in:
parent
b316be7680
commit
4e86bda4dc
@ -330,7 +330,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
|
||||
}
|
||||
|
||||
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) {
|
||||
return true;
|
||||
@ -351,7 +351,8 @@ bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex,
|
||||
return true;
|
||||
}
|
||||
|
||||
auto prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(pindex);
|
||||
if (check_clhdiff) {
|
||||
auto prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(pindex->pprev);
|
||||
// If std::optional prevBlockCoinbaseChainlock is empty, then up to the previous block, coinbase Chainlock is null.
|
||||
if (prevBlockCoinbaseChainlock.has_value()) {
|
||||
// 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
|
||||
@ -359,12 +360,11 @@ bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex,
|
||||
// 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 (curBlockCoinbaseCLHeight < prevBlockCoinbaseCLHeight) {
|
||||
if (opt_cbTx->bestCLHeightDiff > prevBlockCoinbaseChainlock.value().second + 1) {
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-older-clsig");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IsNull() doesn't exist for CBLSSignature: we assume that a valid BLS sig is non-null
|
||||
if (opt_cbTx->bestCLSignature.IsValid()) {
|
||||
|
@ -96,7 +96,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
|
||||
BlockValidationState& state);
|
||||
|
||||
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,
|
||||
uint32_t& bestCLHeightDiff, CBLSSignature& bestCLSignature);
|
||||
|
||||
|
@ -200,7 +200,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
|
||||
nTimeMerkle += nTime5 - nTime4;
|
||||
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
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user