Skip to content

Commit

Permalink
FillBlockPayee: reworked to not require chainActive.Tip redundant acc…
Browse files Browse the repository at this point in the history
…ess.
  • Loading branch information
furszy committed Sep 2, 2020
1 parent 920652b commit 377f87e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/masternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,10 @@ void CBudgetManager::CheckAndRemove()

}

void CBudgetManager::FillBlockPayee(CMutableTransaction& txNew, bool fProofOfStake)
void CBudgetManager::FillBlockPayee(CMutableTransaction& txNew, const CBlockIndex* pindexPrev, bool fProofOfStake)
{
LOCK(cs);

CBlockIndex* pindexPrev = chainActive.Tip();
if (!pindexPrev) return;
LOCK(cs);

int nHighestCount = 0;
CScript payee;
Expand Down
2 changes: 1 addition & 1 deletion src/masternode-budget.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class CBudgetManager
bool PropExists(uint256 nHash);
TrxValidationStatus IsTransactionValid(const CTransaction& txNew, int nBlockHeight);
std::string GetRequiredPaymentsString(int nBlockHeight);
void FillBlockPayee(CMutableTransaction& txNew, bool fProofOfStake);
void FillBlockPayee(CMutableTransaction& txNew, const CBlockIndex* pindexPrev, bool fProofOfStake);

void CheckOrphanVotes();
void Clear()
Expand Down
10 changes: 4 additions & 6 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,14 @@ bool IsBlockPayeeValid(const CBlock& block, int nBlockHeight)
}


void FillBlockPayee(CMutableTransaction& txNew, bool fProofOfStake, bool fZPIVStake)
void FillBlockPayee(CMutableTransaction& txNew, const CBlockIndex* pindexPrev, bool fProofOfStake, bool fZPIVStake)
{
CBlockIndex* pindexPrev = chainActive.Tip();
if (!pindexPrev) return;

if (sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) && budget.IsBudgetPaymentBlock(pindexPrev->nHeight + 1)) {
budget.FillBlockPayee(txNew, fProofOfStake);
budget.FillBlockPayee(txNew, pindexPrev, fProofOfStake);
} else {
masternodePayments.FillBlockPayee(txNew, fProofOfStake, fZPIVStake);
masternodePayments.FillBlockPayee(txNew, pindexPrev, fProofOfStake, fZPIVStake);
}
}

Expand All @@ -343,9 +342,8 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
}
}

void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, bool fProofOfStake, bool fZPIVStake)
void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, const CBlockIndex* pindexPrev, bool fProofOfStake, bool fZPIVStake)
{
CBlockIndex* pindexPrev = chainActive.Tip();
if (!pindexPrev) return;

bool hasPayment = true;
Expand Down
4 changes: 2 additions & 2 deletions src/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDa
bool IsBlockPayeeValid(const CBlock& block, int nBlockHeight);
std::string GetRequiredPaymentsString(int nBlockHeight);
bool IsBlockValueValid(const CBlock& block, CAmount nExpectedValue, CAmount nMinted);
void FillBlockPayee(CMutableTransaction& txNew, bool fProofOfStake, bool fZPIVStake);
void FillBlockPayee(CMutableTransaction& txNew, const CBlockIndex* pindexPrev, bool fProofOfStake, bool fZPIVStake);

void DumpMasternodePayments();

Expand Down Expand Up @@ -279,7 +279,7 @@ class CMasternodePayments
int GetMinMasternodePaymentsProto();
void ProcessMessageMasternodePayments(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
std::string GetRequiredPaymentsString(int nBlockHeight);
void FillBlockPayee(CMutableTransaction& txNew, bool fProofOfStake, bool fZPIVStake);
void FillBlockPayee(CMutableTransaction& txNew, const CBlockIndex* pindexPrev, bool fProofOfStake, bool fZPIVStake);
std::string ToString() const;
int GetOldestBlock();
int GetNewestBlock();
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
txNew.vout[0].scriptPubKey = scriptPubKeyIn;

//Masternode and general budget payments
FillBlockPayee(txNew, fProofOfStake, false);
FillBlockPayee(txNew, pindexPrev, fProofOfStake, false);

txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
//Make payee
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2822,7 +2822,7 @@ bool CWallet::CreateCoinStake(
return error("%s : exceeded coinstake size limit", __func__);

// Masternode payment
FillBlockPayee(txNew, true, false);
FillBlockPayee(txNew, pindexPrev, true, false);

uint256 hashTxOut = txNew.GetHash();
CTxIn in;
Expand Down

0 comments on commit 377f87e

Please sign in to comment.