Skip to content

Commit

Permalink
Enable multisig proposal after v6
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Mar 29, 2023
1 parent a161b1d commit 7310fc4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/budget/budgetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,18 @@ bool CBudgetManager::AddProposal(CBudgetProposal& budgetProposal)
{
AssertLockNotHeld(cs_proposals); // need to lock cs_main here (CheckCollateral)
const uint256& nHash = budgetProposal.GetHash();

int nCurrentHeight = GetBestHeight();
if (WITH_LOCK(cs_proposals, return mapProposals.count(nHash))) {
LogPrint(BCLog::MNBUDGET,"%s: proposal %s already added\n", __func__, nHash.ToString());
return false;
}

if (!budgetProposal.IsWellFormed(GetTotalBudget(budgetProposal.GetBlockStart()))) {
if (!budgetProposal.IsWellFormed(GetTotalBudget(budgetProposal.GetBlockStart()), nCurrentHeight)) {
LogPrint(BCLog::MNBUDGET,"%s: Invalid budget proposal %s %s\n", __func__, nHash.ToString(), budgetProposal.IsInvalidLogStr());
return false;
}

std::string strError;
int nCurrentHeight = GetBestHeight();
const uint256& feeTxId = budgetProposal.GetFeeTXHash();
if (!CheckCollateral(feeTxId, nHash, strError, budgetProposal.nTime, nCurrentHeight, false)) {
LogPrint(BCLog::MNBUDGET,"%s: invalid budget proposal (%s) collateral id=%s - %s\n",
Expand Down
12 changes: 6 additions & 6 deletions src/budget/budgetproposal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ bool CBudgetProposal::CheckAmount(const CAmount& nTotalBudget)
return true;
}

bool CBudgetProposal::CheckAddress()
bool CBudgetProposal::CheckAddress(const int nCurrentHeight)
{
// !TODO: There might be an issue with multisig in the coinbase on mainnet
// we will add support for it in a future release.
if (address.IsPayToScriptHash()) {
// Multisig is supported only after v6
bool isV6Enforced = Params().GetConsensus().NetworkUpgradeActive(nCurrentHeight, Consensus::UPGRADE_V6_0);
if (!isV6Enforced && address.IsPayToScriptHash()) {
strInvalid = "Multisig is not currently supported.";
return false;
}
Expand Down Expand Up @@ -160,9 +160,9 @@ bool CBudgetProposal::CheckStrings()
}
}

bool CBudgetProposal::IsWellFormed(const CAmount& nTotalBudget)
bool CBudgetProposal::IsWellFormed(const CAmount& nTotalBudget, const int nCurrentHeight)
{
return CheckStartEnd() && CheckAmount(nTotalBudget) && CheckAddress();
return CheckStartEnd() && CheckAmount(nTotalBudget) && CheckAddress(nCurrentHeight);
}

bool CBudgetProposal::updateExpired(int nCurrentHeight)
Expand Down
4 changes: 2 additions & 2 deletions src/budget/budgetproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CBudgetProposal
bool updateExpired(int nCurrentHeight);
bool CheckStartEnd();
bool CheckAmount(const CAmount& nTotalBudget);
bool CheckAddress();
bool CheckAddress(const int nCurrentHeight);
bool CheckStrings();

protected:
Expand Down Expand Up @@ -71,7 +71,7 @@ class CBudgetProposal
// sets fValid and strInvalid, returns fValid
bool UpdateValid(int nHeight, int mnCount);
// Static checks that should be done only once - sets strInvalid
bool IsWellFormed(const CAmount& nTotalBudget);
bool IsWellFormed(const CAmount& nTotalBudget, const int nCurrentHeight);
bool IsValid() const { return fValid; }
void SetStrInvalid(const std::string& _strInvalid) { strInvalid = _strInvalid; }
std::string IsInvalidReason() const { return strInvalid; }
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/governancemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ OperationResult GovernanceModel::createProposal(const std::string& strProposalNa

// Validate proposal
CBudgetProposal proposal(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, UINT256_ZERO);
if (!proposal.IsWellFormed(g_budgetman.GetTotalBudget(proposal.GetBlockStart()))) {
if (!proposal.IsWellFormed(g_budgetman.GetTotalBudget(proposal.GetBlockStart()), clientModel->getNumBlocks())) {
return {false, strprintf(_("Proposal is not valid %s"), proposal.IsInvalidReason())};
}

Expand Down
2 changes: 1 addition & 1 deletion src/rpc/budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ UniValue preparebudget(const JSONRPCRequest& request)
// create transaction 15 minutes into the future, to allow for confirmation time
CBudgetProposal proposal(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, UINT256_ZERO);
const uint256& nHash = proposal.GetHash();
if (!proposal.IsWellFormed(g_budgetman.GetTotalBudget(proposal.GetBlockStart())))
if (!proposal.IsWellFormed(g_budgetman.GetTotalBudget(proposal.GetBlockStart()), GetChainTip()->nHeight))
throw std::runtime_error("Proposal is not valid " + proposal.IsInvalidReason());

CTransactionRef wtx;
Expand Down

0 comments on commit 7310fc4

Please sign in to comment.