mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +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,18 +351,18 @@ bool CheckCbTxBestChainlock(const CBlock& block, const CBlockIndex* pindex,
|
||||
return true;
|
||||
}
|
||||
|
||||
auto prevBlockCoinbaseChainlock = GetNonNullCoinbaseChainlock(pindex);
|
||||
// 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
|
||||
if (!opt_cbTx->bestCLSignature.IsValid()) {
|
||||
// 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) {
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-older-clsig");
|
||||
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
|
||||
if (!opt_cbTx->bestCLSignature.IsValid()) {
|
||||
// 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");
|
||||
}
|
||||
if (opt_cbTx->bestCLHeightDiff > prevBlockCoinbaseChainlock.value().second + 1) {
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-older-clsig");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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