refactor: Move HasChainLock() calls out of loops

This commit is contained in:
UdjinM6 2024-11-02 00:18:57 +03:00
parent 6370c7a9e5
commit 38a0b5ac04
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9
2 changed files with 4 additions and 2 deletions

View File

@ -1124,13 +1124,14 @@ void CInstantSendManager::BlockConnected(const std::shared_ptr<const CBlock>& pb
}
if (m_mn_sync.IsBlockchainSynced()) {
const bool has_chainlock = clhandler.HasChainLock(pindex->nHeight, pindex->GetBlockHash());
for (const auto& tx : pblock->vtx) {
if (tx->IsCoinBase() || tx->vin.empty()) {
// coinbase and TXs with no inputs can't be locked
continue;
}
if (!IsLocked(tx->GetHash()) && !clhandler.HasChainLock(pindex->nHeight, pindex->GetBlockHash())) {
if (!IsLocked(tx->GetHash()) && !has_chainlock) {
ProcessTx(*tx, true, Params().GetConsensus());
// TX is not locked, so make sure it is tracked
AddNonLockedTx(tx, pindex);

View File

@ -2186,11 +2186,12 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
if (m_isman->RejectConflictingBlocks()) {
// Require other nodes to comply, send them some data in case they are missing it.
const bool has_chainlock = m_clhandler->HasChainLock(pindex->nHeight, pindex->GetBlockHash());
for (const auto& tx : block.vtx) {
// skip txes that have no inputs
if (tx->vin.empty()) continue;
while (llmq::CInstantSendLockPtr conflictLock = m_isman->GetConflictingLock(*tx)) {
if (m_clhandler->HasChainLock(pindex->nHeight, pindex->GetBlockHash())) {
if (has_chainlock) {
LogPrint(BCLog::ALL, "ConnectBlock(DASH): chain-locked transaction %s overrides islock %s\n",
tx->GetHash().ToString(), ::SerializeHash(*conflictLock).ToString());
m_isman->RemoveConflictingLock(::SerializeHash(*conflictLock), *conflictLock);