Skip to content

Commit

Permalink
Avoid printing DIP3/DIP4 related logs twice (#2525)
Browse files Browse the repository at this point in the history
All logging that happens in BuildNewListFromBlock is currently printed twice.
This is because BuildNewListFromBlock is called while processing the block
and also while calculating the DIP4 MN list commitment.

This commit adds the debugLogs to this method to allow omitting logs while
called from the DIP4 code.
  • Loading branch information
codablock authored Dec 6, 2018
1 parent 08dc178 commit 6086797
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/evo/cbtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev
LOCK(deterministicMNManager->cs);

CDeterministicMNList tmpMNList;
if (!deterministicMNManager->BuildNewListFromBlock(block, pindexPrev, state, tmpMNList)) {
if (!deterministicMNManager->BuildNewListFromBlock(block, pindexPrev, state, tmpMNList, false)) {
return false;
}

Expand Down
67 changes: 42 additions & 25 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ int CDeterministicMNList::CalcPenalty(int percent) const
return (CalcMaxPoSePenalty() * percent) / 100;
}

void CDeterministicMNList::PoSePunish(const uint256& proTxHash, int penalty)
void CDeterministicMNList::PoSePunish(const uint256& proTxHash, int penalty, bool debugLogs)
{
assert(penalty > 0);

Expand All @@ -288,13 +288,17 @@ void CDeterministicMNList::PoSePunish(const uint256& proTxHash, int penalty)
newState->nPoSePenalty += penalty;
newState->nPoSePenalty = std::min(maxPenalty, newState->nPoSePenalty);

LogPrintf("CDeterministicMNList::%s -- punished MN %s, penalty %d->%d (max=%d)\n",
__func__, proTxHash.ToString(), dmn->pdmnState->nPoSePenalty, newState->nPoSePenalty, maxPenalty);
if (debugLogs) {
LogPrintf("CDeterministicMNList::%s -- punished MN %s, penalty %d->%d (max=%d)\n",
__func__, proTxHash.ToString(), dmn->pdmnState->nPoSePenalty, newState->nPoSePenalty, maxPenalty);
}

if (newState->nPoSePenalty >= maxPenalty && newState->nPoSeBanHeight == -1) {
newState->nPoSeBanHeight = nHeight;
LogPrintf("CDeterministicMNList::%s -- banned MN %s at height %d\n",
__func__, proTxHash.ToString(), nHeight);
if (debugLogs) {
LogPrintf("CDeterministicMNList::%s -- banned MN %s at height %d\n",
__func__, proTxHash.ToString(), nHeight);
}
}
UpdateMN(proTxHash, newState);
}
Expand Down Expand Up @@ -431,7 +435,7 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde
int nHeight = pindexPrev->nHeight + 1;

CDeterministicMNList newList;
if (!BuildNewListFromBlock(block, pindexPrev, _state, newList)) {
if (!BuildNewListFromBlock(block, pindexPrev, _state, newList, true)) {
return false;
}

Expand Down Expand Up @@ -486,7 +490,7 @@ void CDeterministicMNManager::UpdatedBlockTip(const CBlockIndex* pindex)
tipBlockHash = pindex->GetBlockHash();
}

bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, CValidationState& _state, CDeterministicMNList& mnListRet)
bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, CValidationState& _state, CDeterministicMNList& mnListRet, bool debugLogs)
{
AssertLockHeld(cs);

Expand Down Expand Up @@ -529,8 +533,10 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
if (dmn && dmn->collateralOutpoint == in.prevout) {
newList.RemoveMN(dmn->proTxHash);

LogPrintf("CDeterministicMNManager::%s -- MN %s removed from list because collateral was spent. collateralOutpoint=%s, nHeight=%d, mapCurMNs.allMNsCount=%d\n",
__func__, dmn->proTxHash.ToString(), dmn->collateralOutpoint.ToStringShort(), nHeight, newList.GetAllMNsCount());
if (debugLogs) {
LogPrintf("CDeterministicMNManager::%s -- MN %s removed from list because collateral was spent. collateralOutpoint=%s, nHeight=%d, mapCurMNs.allMNsCount=%d\n",
__func__, dmn->proTxHash.ToString(), dmn->collateralOutpoint.ToStringShort(), nHeight, newList.GetAllMNsCount());
}
}
}

Expand Down Expand Up @@ -568,8 +574,10 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
// In that case the new ProRegTx will replace the old one. This means the old one is removed
// and the new one is added like a completely fresh one, which is also at the bottom of the payment list
newList.RemoveMN(replacedDmn->proTxHash);
LogPrintf("CDeterministicMNManager::%s -- MN %s removed from list because collateral was used for a new ProRegTx. collateralOutpoint=%s, nHeight=%d, mapCurMNs.allMNsCount=%d\n",
__func__, replacedDmn->proTxHash.ToString(), dmn->collateralOutpoint.ToStringShort(), nHeight, newList.GetAllMNsCount());
if (debugLogs) {
LogPrintf("CDeterministicMNManager::%s -- MN %s removed from list because collateral was used for a new ProRegTx. collateralOutpoint=%s, nHeight=%d, mapCurMNs.allMNsCount=%d\n",
__func__, replacedDmn->proTxHash.ToString(), dmn->collateralOutpoint.ToStringShort(), nHeight, newList.GetAllMNsCount());
}
}

if (newList.HasUniqueProperty(proTx.addr)) {
Expand All @@ -594,8 +602,10 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C

newList.AddMN(dmn);

LogPrintf("CDeterministicMNManager::%s -- MN %s added at height %d: %s\n",
__func__, tx.GetHash().ToString(), nHeight, proTx.ToString());
if (debugLogs) {
LogPrintf("CDeterministicMNManager::%s -- MN %s added at height %d: %s\n",
__func__, tx.GetHash().ToString(), nHeight, proTx.ToString());
}
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_SERVICE) {
CProUpServTx proTx;
if (!GetTxPayload(tx, proTx)) {
Expand All @@ -621,15 +631,18 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
newState->nPoSeBanHeight = -1;
newState->nPoSeRevivedHeight = nHeight;

LogPrintf("CDeterministicMNManager::%s -- MN %s revived at height %d\n",
__func__, proTx.proTxHash.ToString(), nHeight);
if (debugLogs) {
LogPrintf("CDeterministicMNManager::%s -- MN %s revived at height %d\n",
__func__, proTx.proTxHash.ToString(), nHeight);
}
}
}

newList.UpdateMN(proTx.proTxHash, newState);

LogPrintf("CDeterministicMNManager::%s -- MN %s updated at height %d: %s\n",
__func__, proTx.proTxHash.ToString(), nHeight, proTx.ToString());
if (debugLogs) {
LogPrintf("CDeterministicMNManager::%s -- MN %s updated at height %d: %s\n",
__func__, proTx.proTxHash.ToString(), nHeight, proTx.ToString());
}
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REGISTRAR) {
CProUpRegTx proTx;
if (!GetTxPayload(tx, proTx)) {
Expand All @@ -652,8 +665,10 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C

newList.UpdateMN(proTx.proTxHash, newState);

LogPrintf("CDeterministicMNManager::%s -- MN %s updated at height %d: %s\n",
__func__, proTx.proTxHash.ToString(), nHeight, proTx.ToString());
if (debugLogs) {
LogPrintf("CDeterministicMNManager::%s -- MN %s updated at height %d: %s\n",
__func__, proTx.proTxHash.ToString(), nHeight, proTx.ToString());
}
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REVOKE) {
CProUpRevTx proTx;
if (!GetTxPayload(tx, proTx)) {
Expand All @@ -671,15 +686,17 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C

newList.UpdateMN(proTx.proTxHash, newState);

LogPrintf("CDeterministicMNManager::%s -- MN %s revoked operator key at height %d: %s\n",
__func__, proTx.proTxHash.ToString(), nHeight, proTx.ToString());
if (debugLogs) {
LogPrintf("CDeterministicMNManager::%s -- MN %s revoked operator key at height %d: %s\n",
__func__, proTx.proTxHash.ToString(), nHeight, proTx.ToString());
}
} else if (tx.nType == TRANSACTION_QUORUM_COMMITMENT) {
llmq::CFinalCommitmentTxPayload qc;
if (!GetTxPayload(tx, qc)) {
assert(false); // this should have been handled already
}
if (!qc.commitment.IsNull()) {
HandleQuorumCommitment(qc.commitment, newList);
HandleQuorumCommitment(qc.commitment, newList, debugLogs);
}
}
}
Expand All @@ -697,7 +714,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
return true;
}

void CDeterministicMNManager::HandleQuorumCommitment(llmq::CFinalCommitment& qc, CDeterministicMNList& mnList)
void CDeterministicMNManager::HandleQuorumCommitment(llmq::CFinalCommitment& qc, CDeterministicMNList& mnList, bool debugLogs)
{
// The commitment has already been validated at this point so it's safe to use members of it

Expand All @@ -712,7 +729,7 @@ void CDeterministicMNManager::HandleQuorumCommitment(llmq::CFinalCommitment& qc,
// The idea is to immediately ban a MN when it fails 2 DKG sessions with only a few blocks in-between
// If there were enough blocks between failures, the MN has a chance to recover as he reduces his penalty by 1 for every block
// If it however fails 3 times in the timespan of a single payment cycle, it should definitely get banned
mnList.PoSePunish(members[i]->proTxHash, mnList.CalcPenalty(66));
mnList.PoSePunish(members[i]->proTxHash, mnList.CalcPenalty(66), debugLogs);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class CDeterministicMNList
* @param proTxHash
* @param penalty
*/
void PoSePunish(const uint256& proTxHash, int penalty);
void PoSePunish(const uint256& proTxHash, int penalty, bool debugLogs);

/**
* Decrease penalty score of MN by 1.
Expand Down Expand Up @@ -459,8 +459,8 @@ class CDeterministicMNManager
void UpdatedBlockTip(const CBlockIndex* pindex);

// the returned list will not contain the correct block hash (we can't know it yet as the coinbase TX is not updated yet)
bool BuildNewListFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, CValidationState& state, CDeterministicMNList& mnListRet);
void HandleQuorumCommitment(llmq::CFinalCommitment& qc, CDeterministicMNList& mnList);
bool BuildNewListFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, CValidationState& state, CDeterministicMNList& mnListRet, bool debugLogs);
void HandleQuorumCommitment(llmq::CFinalCommitment& qc, CDeterministicMNList& mnList, bool debugLogs);
void DecreasePoSePenalties(CDeterministicMNList& mnList);

CDeterministicMNList GetListForBlock(const uint256& blockHash);
Expand Down

0 comments on commit 6086797

Please sign in to comment.