Skip to content

Commit 2fb06c0

Browse files
committed
refactor: drop confusing CheckCbTxMerkleRoots, move its logic into ProcessSpecialTxsInBlock
1 parent fe00c23 commit 2fb06c0

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

src/evo/cbtx.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,6 @@ bool CheckCbTx(const CCbTx& cbTx, const CBlockIndex* pindexPrev, TxValidationSta
4343
return true;
4444
}
4545

46-
bool CheckCbTxMerkleRoots(const CBlock& block, const CCbTx& cbTx, const CBlockIndex* pindex,
47-
const llmq::CQuorumBlockProcessor& quorum_block_processor, BlockValidationState& state)
48-
{
49-
if (pindex && cbTx.nVersion >= CCbTx::Version::MERKLE_ROOT_QUORUMS) {
50-
uint256 calculatedMerkleRoot;
51-
if (!CalcCbTxMerkleRootQuorums(block, pindex->pprev, quorum_block_processor, calculatedMerkleRoot, state)) {
52-
// pass the state returned by the function above
53-
return false;
54-
}
55-
if (calculatedMerkleRoot != cbTx.merkleRootQuorums) {
56-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-quorummerkleroot");
57-
}
58-
}
59-
60-
return true;
61-
}
62-
6346
using QcHashMap = std::map<Consensus::LLMQType, std::vector<uint256>>;
6447
using QcIndexedHashMap = std::map<Consensus::LLMQType, std::map<int16_t, uint256>>;
6548

src/evo/cbtx.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ template<> struct is_serializable_enum<CCbTx::Version> : std::true_type {};
6363

6464
bool CheckCbTx(const CCbTx& cbTx, const CBlockIndex* pindexPrev, TxValidationState& state);
6565

66-
// This can only be done after the block has been fully processed, as otherwise we won't have the finished MN list
67-
bool CheckCbTxMerkleRoots(const CBlock& block, const CCbTx& cbTx, const CBlockIndex* pindex,
68-
const llmq::CQuorumBlockProcessor& quorum_block_processor, BlockValidationState& state);
6966
bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPrev,
7067
const llmq::CQuorumBlockProcessor& quorum_block_processor, uint256& merkleRootRet,
7168
BlockValidationState& state);

src/evo/specialtxman.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
499499
static int64_t nTimeQuorum = 0;
500500
static int64_t nTimeDMN = 0;
501501
static int64_t nTimeMerkleMNL = 0;
502-
static int64_t nTimeMerkle = 0;
502+
static int64_t nTimeMerkleQuorums = 0;
503503
static int64_t nTimeCbTxCL = 0;
504504
static int64_t nTimeMnehf = 0;
505505
static int64_t nTimePayload = 0;
@@ -606,12 +606,12 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
606606
LogPrint(BCLog::BENCHMARK, " - m_dmnman: %.2fms [%.2fs]\n", 0.001 * (nTime6 - nTime5), nTimeDMN * 0.000001);
607607

608608
if (opt_cbTx.has_value()) {
609-
uint256 calculatedMerkleRoot;
610-
if (!CalcCbTxMerkleRootMNList(calculatedMerkleRoot, CSimplifiedMNList{std::move(mn_list)}, state)) {
609+
uint256 calculatedMerkleRootMNL;
610+
if (!CalcCbTxMerkleRootMNList(calculatedMerkleRootMNL, CSimplifiedMNList{std::move(mn_list)}, state)) {
611611
// pass the state returned by the function above
612612
return false;
613613
}
614-
if (calculatedMerkleRoot != opt_cbTx->merkleRootMNList) {
614+
if (calculatedMerkleRootMNL != opt_cbTx->merkleRootMNList) {
615615
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-mnmerkleroot");
616616
}
617617

@@ -620,16 +620,22 @@ bool CSpecialTxProcessor::ProcessSpecialTxsInBlock(const CBlock& block, const CB
620620
LogPrint(BCLog::BENCHMARK, " - CalcCbTxMerkleRootMNList: %.2fms [%.2fs]\n",
621621
0.001 * (nTime6_1 - nTime6), nTimeMerkleMNL * 0.000001);
622622

623-
if (!CheckCbTxMerkleRoots(block, *opt_cbTx, pindex, m_qblockman, state)) {
624-
// pass the state returned by the function above
625-
return false;
623+
if (opt_cbTx->nVersion >= CCbTx::Version::MERKLE_ROOT_QUORUMS) {
624+
uint256 calculatedMerkleRootQuorums;
625+
if (!CalcCbTxMerkleRootQuorums(block, pindex->pprev, m_qblockman, calculatedMerkleRootQuorums, state)) {
626+
// pass the state returned by the function above
627+
return false;
628+
}
629+
if (calculatedMerkleRootQuorums != opt_cbTx->merkleRootQuorums) {
630+
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cbtx-quorummerkleroot");
631+
}
626632
}
627633

628634
int64_t nTime6_2 = GetTimeMicros();
629-
nTimeMerkle += nTime6_2 - nTime6_1;
635+
nTimeMerkleQuorums += nTime6_2 - nTime6_1;
630636

631-
LogPrint(BCLog::BENCHMARK, " - CheckCbTxMerkleRoots: %.2fms [%.2fs]\n", 0.001 * (nTime6_2 - nTime6_1),
632-
nTimeMerkle * 0.000001);
637+
LogPrint(BCLog::BENCHMARK, " - CalcCbTxMerkleRootQuorums: %.2fms [%.2fs]\n",
638+
0.001 * (nTime6_2 - nTime6_1), nTimeMerkleQuorums * 0.000001);
633639

634640
if (!CheckCbTxBestChainlock(*opt_cbTx, pindex, m_clhandler, state)) {
635641
// pass the state returned by the function above

0 commit comments

Comments
 (0)