Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactoring] Clean budget manager code redundancies #2752

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions src/budget/budgetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1625,40 +1625,21 @@ bool CheckCollateral(const uint256& nTxCollateralHash, const uint256& nExpectedH
return false;
}

if (txCollateral->vout.size() < 1) return false;
if (txCollateral->vout.empty()) return false;
if (txCollateral->nLockTime != 0) return false;

CScript findScript;
findScript << OP_RETURN << ToByteVector(nExpectedHash);
CScript findScript = CScript() << OP_RETURN << ToByteVector(nExpectedHash);
furszy marked this conversation as resolved.
Show resolved Hide resolved
CAmount expectedAmount = fBudgetFinalization ? BUDGET_FEE_TX : PROPOSAL_FEE_TX;

bool foundOpReturn = false;
for (const CTxOut &o : txCollateral->vout) {
if (!o.scriptPubKey.IsPayToPublicKeyHash() && !o.scriptPubKey.IsUnspendable()) {
strError = strprintf("Invalid Script %s", txCollateral->ToString());
return false;
}
if (fBudgetFinalization) {
// Collateral for budget finalization
// Note: there are still old valid budgets out there, but the check for the new 5 PIV finalization collateral
// will also cover the old 50 PIV finalization collateral.
LogPrint(BCLog::MNBUDGET, "Final Budget: o.scriptPubKey(%s) == findScript(%s) ?\n", HexStr(o.scriptPubKey), HexStr(findScript));
if (o.scriptPubKey == findScript) {
LogPrint(BCLog::MNBUDGET, "Final Budget: o.nValue(%ld) >= BUDGET_FEE_TX(%ld) ?\n", o.nValue, BUDGET_FEE_TX);
if(o.nValue >= BUDGET_FEE_TX) {
foundOpReturn = true;
break;
}
}
} else {
// Collateral for normal budget proposal
LogPrint(BCLog::MNBUDGET, "Normal Budget: o.scriptPubKey(%s) == findScript(%s) ?\n", HexStr(o.scriptPubKey), HexStr(findScript));
if (o.scriptPubKey == findScript) {
LogPrint(BCLog::MNBUDGET, "Normal Budget: o.nValue(%ld) >= PROPOSAL_FEE_TX(%ld) ?\n", o.nValue, PROPOSAL_FEE_TX);
if(o.nValue >= PROPOSAL_FEE_TX) {
foundOpReturn = true;
break;
}
}
if (o.scriptPubKey == findScript && o.nValue == expectedAmount) {
foundOpReturn = true;
break;
}
}

Expand Down