Skip to content

Commit

Permalink
fix: blockReward should be provided for cbtx-es only, assert that in …
Browse files Browse the repository at this point in the history
…ProcessTransaction
  • Loading branch information
UdjinM6 committed Sep 29, 2023
1 parent bd2673c commit 10fdfb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/evo/creditpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void CCreditPoolDiff::AddRewardRealloced(const CAmount reward) {
platformReward += reward;
}

bool CCreditPoolDiff::SetTarget(const CTransaction& tx, const std::optional<CAmount> blockReward, TxValidationState& state)
bool CCreditPoolDiff::SetTarget(const CTransaction& tx, const CAmount blockReward, TxValidationState& state)
{
CCbTx cbTx;
if (!GetTxPayload(tx, cbTx)) {
Expand All @@ -241,9 +241,7 @@ bool CCreditPoolDiff::SetTarget(const CTransaction& tx, const std::optional<CAmo

if (!llmq::utils::IsMNRewardReallocationActive(pindex)) return true;

assert(blockReward.has_value());

platformReward = MasternodePayments::PlatformShare(GetMasternodePayment(cbTx.nHeight, blockReward.value(), params.BRRHeight));
platformReward = MasternodePayments::PlatformShare(GetMasternodePayment(cbTx.nHeight, blockReward, params.BRRHeight));
LogPrintf("CreditPool: set target to %lld with MN reward %lld\n", *targetBalance, platformReward);

return true;
Expand Down Expand Up @@ -292,7 +290,12 @@ bool CCreditPoolDiff::Unlock(const CTransaction& tx, TxValidationState& state)
bool CCreditPoolDiff::ProcessTransaction(const CTransaction& tx, const std::optional<CAmount> blockReward, TxValidationState& state)
{
if (tx.nVersion != 3) return true;
if (tx.nType == TRANSACTION_COINBASE) return SetTarget(tx, blockReward, state);

assert(blockReward.has_value() == (tx.nType == TRANSACTION_COINBASE));

if (tx.nType == TRANSACTION_COINBASE) {
return SetTarget(tx, blockReward.value(), state);
}

if (tx.nType != TRANSACTION_ASSET_LOCK && tx.nType != TRANSACTION_ASSET_UNLOCK) return true;

Expand Down
2 changes: 1 addition & 1 deletion src/evo/creditpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CCreditPoolDiff {
}

private:
bool SetTarget(const CTransaction& tx, const std::optional<CAmount> blockReward, TxValidationState& state);
bool SetTarget(const CTransaction& tx, const CAmount blockReward, TxValidationState& state);
bool Lock(const CTransaction& tx, TxValidationState& state);
bool Unlock(const CTransaction& tx, TxValidationState& state);
};
Expand Down

0 comments on commit 10fdfb0

Please sign in to comment.