mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
feat: update some asserts related to CreditPool in consensus code to exceptions
This commit is contained in:
parent
877aa08144
commit
c97f5f5ca5
@ -134,9 +134,13 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const CBlockIndex* const blo
|
||||
if (!block) {
|
||||
// If reading of previous block is not successfully, but
|
||||
// prev contains credit pool related data, something strange happened
|
||||
assert(prev.locked == 0);
|
||||
assert(prev.indexes.IsEmpty());
|
||||
|
||||
if (prev.locked != 0) {
|
||||
throw std::runtime_error(strprintf("Failed to create CreditPool but previous block has value"));
|
||||
}
|
||||
if (!prev.indexes.IsEmpty()) {
|
||||
throw std::runtime_error(
|
||||
strprintf("Failed to create CreditPool but asset unlock transactions already mined"));
|
||||
}
|
||||
CCreditPool emptyPool;
|
||||
AddToCache(block_index->GetBlockHash(), block_index->nHeight, emptyPool);
|
||||
return emptyPool;
|
||||
@ -184,9 +188,7 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const CBlockIndex* const blo
|
||||
currentLimit = std::min(currentLimit, LimitAmountHigh - latelyUnlocked);
|
||||
}
|
||||
|
||||
assert(currentLimit >= 0);
|
||||
|
||||
if (currentLimit > 0 || latelyUnlocked > 0 || locked > 0) {
|
||||
if (currentLimit != 0 || latelyUnlocked > 0 || locked > 0) {
|
||||
LogPrint(BCLog::CREDITPOOL, /* Continued */
|
||||
"CCreditPoolManager: asset unlock limits on height: %d locked: %d.%08d limit: %d.%08d "
|
||||
"unlocked-in-window: %d.%08d\n",
|
||||
@ -194,6 +196,11 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const CBlockIndex* const blo
|
||||
latelyUnlocked / COIN, latelyUnlocked % COIN);
|
||||
}
|
||||
|
||||
if (currentLimit < 0) {
|
||||
throw std::runtime_error(
|
||||
strprintf("Negative limit for CreditPool: %d.%08d\n", currentLimit / COIN, currentLimit % COIN));
|
||||
}
|
||||
|
||||
CCreditPool pool{locked, currentLimit, latelyUnlocked, indexes};
|
||||
AddToCache(block_index->GetBlockHash(), block_index->nHeight, pool);
|
||||
return pool;
|
||||
|
Loading…
Reference in New Issue
Block a user