Skip to content

Commit 0c7cfd9

Browse files
committed
refactor: make CheckCreditPoolDiffForBlock private and tidy up it
1 parent a7fe377 commit 0c7cfd9

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/evo/specialtxman.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <evo/specialtxman.h>
66

77
#include <chainparams.h>
8+
#include <consensus/amount.h>
89
#include <consensus/validation.h>
910
#include <deploymentstatus.h>
1011
#include <evo/assetlocktx.h>
@@ -150,8 +151,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
150151
LogPrint(BCLog::BENCHMARK, " - Loop: %.2fms [%.2fs]\n", 0.001 * (nTime3 - nTime2), nTimeLoop * 0.000001);
151152

152153
if (fCheckCbTxMerkleRoots && block.vtx[0]->nType == TRANSACTION_COINBASE) {
153-
CAmount blockSubsidy = GetBlockSubsidy(pindex, m_consensus_params);
154-
if (!CheckCreditPoolDiffForBlock(block, pindex, *opt_cbTx, blockSubsidy, state)) {
154+
if (!CheckCreditPoolDiffForBlock(block, pindex, *opt_cbTx, state)) {
155155
return error("CSpecialTxProcessor: CheckCreditPoolDiffForBlock for block %s failed with %s",
156156
pindex->GetBlockHash().ToString(), state.ToString());
157157
}
@@ -275,21 +275,22 @@ bool CSpecialTxProcessor::UndoSpecialTxsInBlock(const CBlock& block, const CBloc
275275
}
276276

277277
bool CSpecialTxProcessor::CheckCreditPoolDiffForBlock(const CBlock& block, const CBlockIndex* pindex, const CCbTx& cbTx,
278-
const CAmount blockSubsidy, BlockValidationState& state)
278+
BlockValidationState& state)
279279
{
280280
AssertLockHeld(cs_main);
281281

282-
try {
283-
if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_DIP0003)) return true;
284-
if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_DIP0008)) return true;
285-
if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_V20)) return true;
282+
if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_DIP0008)) return true;
283+
if (!DeploymentActiveAt(*pindex, m_consensus_params, Consensus::DEPLOYMENT_V20)) return true;
286284

287-
auto creditPoolDiff = GetCreditPoolDiffForBlock(m_cpoolman, m_chainman.m_blockman, m_qman, block, pindex->pprev, m_consensus_params, blockSubsidy, state);
285+
try {
286+
const CAmount blockSubsidy = GetBlockSubsidy(pindex, m_consensus_params);
287+
const auto creditPoolDiff = GetCreditPoolDiffForBlock(m_cpoolman, m_chainman.m_blockman, m_qman, block,
288+
pindex->pprev, m_consensus_params, blockSubsidy, state);
288289
if (!creditPoolDiff.has_value()) return false;
289290

290-
CAmount target_balance{cbTx.creditPoolBalance};
291+
const CAmount target_balance{cbTx.creditPoolBalance};
291292
// But it maybe not included yet in previous block yet; in this case value must be 0
292-
CAmount locked_calculated{creditPoolDiff->GetTotalLocked()};
293+
const CAmount locked_calculated{creditPoolDiff->GetTotalLocked()};
293294
if (target_balance != locked_calculated) {
294295
LogPrintf("CSpecialTxProcessor::%s -- mismatched locked amount in CbTx: %lld against re-calculated: %lld\n", __func__, target_balance, locked_calculated);
295296
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-assetlocked-amount");

src/evo/specialtxman.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#ifndef BITCOIN_EVO_SPECIALTXMAN_H
66
#define BITCOIN_EVO_SPECIALTXMAN_H
77

8-
#include <consensus/amount.h>
98
#include <sync.h>
109
#include <threadsafety.h>
1110

@@ -71,10 +70,10 @@ class CSpecialTxProcessor
7170
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
7271
bool UndoSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, std::optional<MNListUpdates>& updatesRet)
7372
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
74-
// TODO: make it private and remove forward declaration CCbTx
73+
74+
private:
7575
bool CheckCreditPoolDiffForBlock(const CBlock& block, const CBlockIndex* pindex, const CCbTx& cbTx,
76-
const CAmount blockSubsidy, BlockValidationState& state)
77-
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
76+
BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
7877
};
7978

8079
#endif // BITCOIN_EVO_SPECIALTXMAN_H

0 commit comments

Comments
 (0)