Skip to content

Commit

Permalink
ProcessSpecialTxsInBlock should respect fJustCheck
Browse files Browse the repository at this point in the history
Also invoke it after subsidy/payee checks
  • Loading branch information
UdjinM6 committed Jan 27, 2019
1 parent 7ee31cb commit f2354ae
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
6 changes: 5 additions & 1 deletion src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ CDeterministicMNManager::CDeterministicMNManager(CEvoDB& _evoDb) :
{
}

bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& _state)
bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& _state, bool fJustCheck)
{
CDeterministicMNList oldList, newList;
CDeterministicMNListDiff diff;
Expand All @@ -458,6 +458,10 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde
return false;
}

if (fJustCheck) {
return true;
}

if (newList.GetHeight() == -1) {
newList.SetHeight(nHeight);
}
Expand Down
2 changes: 1 addition & 1 deletion src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ class CDeterministicMNManager
public:
CDeterministicMNManager(CEvoDB& _evoDb);

bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state);
bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck);
bool UndoBlock(const CBlock& block, const CBlockIndex* pindex);

void UpdatedBlockTip(const CBlockIndex* pindex);
Expand Down
6 changes: 3 additions & 3 deletions src/evo/specialtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool UndoSpecialTx(const CTransaction& tx, const CBlockIndex* pindex)
return false;
}

bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state)
bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck)
{
for (int i = 0; i < (int)block.vtx.size(); i++) {
const CTransaction& tx = *block.vtx[i];
Expand All @@ -98,11 +98,11 @@ bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, CV
}
}

if (!llmq::quorumBlockProcessor->ProcessBlock(block, pindex, state)) {
if (!llmq::quorumBlockProcessor->ProcessBlock(block, pindex, state, fJustCheck)) {
return false;
}

if (!deterministicMNManager->ProcessBlock(block, pindex, state)) {
if (!deterministicMNManager->ProcessBlock(block, pindex, state, fJustCheck)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/evo/specialtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CBlockIndex;
class CValidationState;

bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state);
bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state);
bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck);
bool UndoSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex);

template <typename T>
Expand Down
12 changes: 7 additions & 5 deletions src/llmq/quorums_blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strC
}
}

bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state)
bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck)
{
AssertLockHeld(cs_main);

Expand Down Expand Up @@ -144,14 +144,14 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex*

for (auto& p : qcs) {
auto& qc = p.second;
if (!ProcessCommitment(pindex, qc, state)) {
if (!ProcessCommitment(pindex, qc, state, fJustCheck)) {
return false;
}
}
return true;
}

bool CQuorumBlockProcessor::ProcessCommitment(const CBlockIndex* pindex, const CFinalCommitment& qc, CValidationState& state)
bool CQuorumBlockProcessor::ProcessCommitment(const CBlockIndex* pindex, const CFinalCommitment& qc, CValidationState& state, bool fJustCheck)
{
auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)qc.llmqType);

Expand Down Expand Up @@ -186,8 +186,10 @@ bool CQuorumBlockProcessor::ProcessCommitment(const CBlockIndex* pindex, const C
return state.DoS(100, false, REJECT_INVALID, "bad-qc-invalid");
}

// Store commitment in DB
evoDb.Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair((uint8_t)params.type, quorumHash)), qc);
if (!fJustCheck) {
// Store commitment in DB
evoDb.Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair((uint8_t)params.type, quorumHash)), qc);
}

LogPrintf("CQuorumBlockProcessor::%s -- processed commitment from block. type=%d, quorumHash=%s, signers=%s, validMembers=%d, quorumPublicKey=%s\n", __func__,
qc.llmqType, quorumHash.ToString(), qc.CountSigners(), qc.CountValidMembers(), qc.quorumPublicKey.ToString());
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/quorums_blockprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CQuorumBlockProcessor

void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);

bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state);
bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck);
bool UndoBlock(const CBlock& block, const CBlockIndex* pindex);

void AddMinableCommitment(const CFinalCommitment& fqc);
Expand All @@ -48,7 +48,7 @@ class CQuorumBlockProcessor

private:
bool GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, std::map<Consensus::LLMQType, CFinalCommitment>& ret, CValidationState& state);
bool ProcessCommitment(const CBlockIndex* pindex, const CFinalCommitment& qc, CValidationState& state);
bool ProcessCommitment(const CBlockIndex* pindex, const CFinalCommitment& qc, CValidationState& state, bool fJustCheck);
bool IsMiningPhase(Consensus::LLMQType llmqType, int nHeight);
bool IsCommitmentRequired(Consensus::LLMQType llmqType, int nHeight);
uint256 GetQuorumBlockHash(Consensus::LLMQType llmqType, int nHeight);
Expand Down
11 changes: 6 additions & 5 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2179,11 +2179,6 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
int64_t nTime3 = GetTimeMicros(); nTimeConnect += nTime3 - nTime2;
LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime3 - nTime2), 0.001 * (nTime3 - nTime2) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime3 - nTime2) / (nInputs-1), nTimeConnect * 0.000001);

if (!ProcessSpecialTxsInBlock(block, pindex, state)) {
return error("ConnectBlock(): ProcessSpecialTxsInBlock for block %s failed with %s",
pindex->GetBlockHash().ToString(), FormatStateMessage(state));
}

// DASH : MODIFIED TO CHECK MASTERNODE PAYMENTS AND SUPERBLOCKS

// It's possible that we simply don't have enough data and this could fail
Expand All @@ -2203,6 +2198,12 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
return state.DoS(0, error("ConnectBlock(DASH): couldn't find masternode or superblock payments"),
REJECT_INVALID, "bad-cb-payee");
}

if (!ProcessSpecialTxsInBlock(block, pindex, state, fJustCheck)) {
return error("ConnectBlock(DASH): ProcessSpecialTxsInBlock for block %s failed with %s",
pindex->GetBlockHash().ToString(), FormatStateMessage(state));
}

// END DASH

if (!control.Wait())
Expand Down

0 comments on commit f2354ae

Please sign in to comment.