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

Use chainActive.Tip() instead of pindexBestHeader #442

Merged
merged 2 commits into from Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/main.cpp
Expand Up @@ -1186,7 +1186,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
nValueOut += txout.nValue;
if (!MoneyRange(nValueOut))
return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge");
if(txout.scriptPubKey.IsColdStaking() && !IsColdStakingEnabled(pindexBestHeader, Params().GetConsensus()))
if(txout.scriptPubKey.IsColdStaking() && !IsColdStakingEnabled(chainActive.Tip(), Params().GetConsensus()))
return state.DoS(100, false, REJECT_INVALID, "cold-staking-not-enabled");
}

Expand Down Expand Up @@ -1245,11 +1245,11 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
if (!CheckTransaction(tx, state))
return false; // state filled in by CheckTransaction

if (IsCommunityFundEnabled(pindexBestHeader, Params().GetConsensus()) && tx.nVersion < CTransaction::TXDZEEL_VERSION_V2)
if (IsCommunityFundEnabled(chainActive.Tip(), Params().GetConsensus()) && tx.nVersion < CTransaction::TXDZEEL_VERSION_V2)
return state.DoS(100, false, REJECT_INVALID, "old-version");

if (IsCommunityFundEnabled(pindexBestHeader, Params().GetConsensus())) {
bool fReducedQuorum = IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus());
if (IsCommunityFundEnabled(chainActive.Tip(), Params().GetConsensus())) {
bool fReducedQuorum = IsReducedCFundQuorumEnabled(chainActive.Tip(), Params().GetConsensus());
int nMaxVersionProposal = fReducedQuorum ? Params().GetConsensus().nProposalMaxVersion : 2;
int nMaxVersionPaymentRequest = fReducedQuorum ? Params().GetConsensus().nPaymentRequestMaxVersion : 2;

Expand Down Expand Up @@ -2375,7 +2375,7 @@ bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockI
uint256 hash = tx.GetHash();

if(IsCommunityFundEnabled(pindex->pprev, Params().GetConsensus())) {
bool fReducedQuorum = IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus());
bool fReducedQuorum = IsReducedCFundQuorumEnabled(chainActive.Tip(), Params().GetConsensus());
int nMaxVersionProposal = fReducedQuorum ? Params().GetConsensus().nProposalMaxVersion : 2;
int nMaxVersionPaymentRequest = fReducedQuorum ? Params().GetConsensus().nPaymentRequestMaxVersion : 2;

Expand Down Expand Up @@ -3140,7 +3140,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
}

if(IsCommunityFundEnabled(pindex->pprev, Params().GetConsensus())) {
bool fReducedQuorum = IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus());
bool fReducedQuorum = IsReducedCFundQuorumEnabled(chainActive.Tip(), Params().GetConsensus());
int nMaxVersionProposal = fReducedQuorum ? Params().GetConsensus().nProposalMaxVersion : 2;
int nMaxVersionPaymentRequest = fReducedQuorum ? Params().GetConsensus().nPaymentRequestMaxVersion : 2;

Expand Down Expand Up @@ -5052,8 +5052,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
if (!IsFinalTx(tx, nHeight, nLockTimeCutoff)) {
return state.DoS(10, false, REJECT_INVALID, "bad-txns-nonfinal", false, "non-final transaction");
}
if(IsCommunityFundEnabled(pindexBestHeader, Params().GetConsensus())) {
bool fReducedQuorum = IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus());
if(IsCommunityFundEnabled(chainActive.Tip(), Params().GetConsensus())) {
bool fReducedQuorum = IsReducedCFundQuorumEnabled(chainActive.Tip(), Params().GetConsensus());
int nMaxVersionProposal = fReducedQuorum ? Params().GetConsensus().nProposalMaxVersion : 2;
int nMaxVersionPaymentRequest = fReducedQuorum ? Params().GetConsensus().nPaymentRequestMaxVersion : 2;

Expand Down
2 changes: 1 addition & 1 deletion src/qt/communityfundcreatepaymentrequestdialog.cpp
Expand Up @@ -218,7 +218,7 @@ void CommunityFundCreatePaymentRequestDialog::click_pushButtonSubmitPaymentReque
strDZeel.push_back(Pair("s",Signature));
strDZeel.push_back(Pair("r",sRandom));
strDZeel.push_back(Pair("i",id));
strDZeel.push_back(Pair("v",IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus()) ? CFund::CPaymentRequest::CURRENT_VERSION : 2));
strDZeel.push_back(Pair("v",IsReducedCFundQuorumEnabled(chainActive.Tip(), Params().GetConsensus()) ? CFund::CPaymentRequest::CURRENT_VERSION : 2));

wtx.strDZeel = strDZeel.write();
wtx.nCustomVersion = CTransaction::PAYMENT_REQUEST_VERSION;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/communityfundcreateproposaldialog.cpp
Expand Up @@ -130,7 +130,7 @@ void CommunityFundCreateProposalDialog::click_pushButtonCreateProposal()
strDZeel.push_back(Pair("a",Address));
strDZeel.push_back(Pair("d",nDeadline));
strDZeel.push_back(Pair("s",sDesc));
strDZeel.push_back(Pair("v",IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus()) ? CFund::CProposal::CURRENT_VERSION : 2));
strDZeel.push_back(Pair("v",IsReducedCFundQuorumEnabled(chainActive.Tip(), Params().GetConsensus()) ? CFund::CProposal::CURRENT_VERSION : 2));

wtx.strDZeel = strDZeel.write();
wtx.nCustomVersion = CTransaction::PROPOSAL_VERSION;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/getaddresstoreceive.cpp
Expand Up @@ -77,7 +77,7 @@ void getAddressToReceive::getNewAddress()

void getAddressToReceive::getColdStakingAddress()
{
if (!IsCommunityFundEnabled(pindexBestHeader,Params().GetConsensus()))
if (!IsCommunityFundEnabled(chainActive.Tip(),Params().GetConsensus()))
QMessageBox::warning(this, tr("Action not available"),
"<qt>Cold Staking is not active yet.</qt>");
else {
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Expand Up @@ -1028,7 +1028,7 @@ UniValue cfundstats(const UniValue& params, bool fHelp)
vp.push_back(Pair("current", chainActive.Tip()->nHeight));
UniValue consensus(UniValue::VOBJ);
consensus.push_back(Pair("blocksPerVotingCycle",Params().GetConsensus().nBlocksPerVotingCycle));
if (!IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus())){
if (!IsReducedCFundQuorumEnabled(chainActive.Tip(), Params().GetConsensus())){
consensus.push_back(Pair("minSumVotesPerVotingCycle",Params().GetConsensus().nBlocksPerVotingCycle * Params().GetConsensus().nMinimumQuorum));
} else {
consensus.push_back(Pair("minSumVotesPerVotingCycle",Params().GetConsensus().nBlocksPerVotingCycle * Params().GetConsensus().nMinimumQuorumFirstHalf));
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rawtransaction.cpp
Expand Up @@ -541,7 +541,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
rawTx.strDZeel = params[2].get_str();
}

rawTx.nVersion = IsCommunityFundEnabled(pindexBestHeader,Params().GetConsensus()) ? CTransaction::TXDZEEL_VERSION_V2 : CTransaction::TXDZEEL_VERSION;
rawTx.nVersion = IsCommunityFundEnabled(chainActive.Tip(),Params().GetConsensus()) ? CTransaction::TXDZEEL_VERSION_V2 : CTransaction::TXDZEEL_VERSION;

int nout = -1;

Expand Down
6 changes: 3 additions & 3 deletions src/wallet/rpcwallet.cpp
Expand Up @@ -173,7 +173,7 @@ UniValue getcoldstakingaddress(const UniValue& params, bool fHelp)

);

if (!IsColdStakingEnabled(pindexBestHeader,Params().GetConsensus()))
if (!IsColdStakingEnabled(chainActive.Tip(),Params().GetConsensus()))
throw runtime_error(
"Cold Staking is not active yet.");

Expand Down Expand Up @@ -592,7 +592,7 @@ UniValue createproposal(const UniValue& params, bool fHelp)
strDZeel.push_back(Pair("a",Address));
strDZeel.push_back(Pair("d",nDeadline));
strDZeel.push_back(Pair("s",sDesc));
strDZeel.push_back(Pair("v",IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus()) ? CFund::CProposal::CURRENT_VERSION : 2));
strDZeel.push_back(Pair("v",IsReducedCFundQuorumEnabled(chainActive.Tip(), Params().GetConsensus()) ? CFund::CProposal::CURRENT_VERSION : 2));

wtx.strDZeel = strDZeel.write();
wtx.nCustomVersion = CTransaction::PROPOSAL_VERSION;
Expand Down Expand Up @@ -705,7 +705,7 @@ UniValue createpaymentrequest(const UniValue& params, bool fHelp)
strDZeel.push_back(Pair("s",Signature));
strDZeel.push_back(Pair("r",sRandom));
strDZeel.push_back(Pair("i",id));
strDZeel.push_back(Pair("v",IsReducedCFundQuorumEnabled(pindexBestHeader, Params().GetConsensus()) ? CFund::CPaymentRequest::CURRENT_VERSION : 2));
strDZeel.push_back(Pair("v",IsReducedCFundQuorumEnabled(chainActive.Tip(), Params().GetConsensus()) ? CFund::CPaymentRequest::CURRENT_VERSION : 2));

wtx.strDZeel = strDZeel.write();
wtx.nCustomVersion = CTransaction::PAYMENT_REQUEST_VERSION;
Expand Down
10 changes: 5 additions & 5 deletions src/wallet/wallet.cpp
Expand Up @@ -268,7 +268,7 @@ void CWallet::AvailableCoinsForStaking(vector<COutput>& vCoins, unsigned int nSp
((IsMine(pcoin->vout[i]) & (ISMINE_SPENDABLE)) != ISMINE_NO &&
!pcoin->vout[i].scriptPubKey.IsColdStaking()) ||
((IsMine(pcoin->vout[i]) & (ISMINE_STAKABLE)) != ISMINE_NO &&
IsColdStakingEnabled(pindexBestHeader, Params().GetConsensus()))));
IsColdStakingEnabled(chainActive.Tip(), Params().GetConsensus()))));
}
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
{
static int nMaxStakeSearchInterval = 60;
bool fKernelFound = false;
for (unsigned int n=0; n<min(nSearchInterval,(int64_t)nMaxStakeSearchInterval) && !fKernelFound && pindexPrev == pindexBestHeader; n++)
for (unsigned int n=0; n<min(nSearchInterval,(int64_t)nMaxStakeSearchInterval) && !fKernelFound && pindexPrev == chainActive.Tip(); n++)
{
boost::this_thread::interruption_point();
// Search backward in time from the given txNew timestamp
Expand Down Expand Up @@ -475,7 +475,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
if (!TransactionGetCoinAge(ptxNew, nCoinAge))
return error("CreateCoinStake : failed to calculate coin age");

nReward = GetProofOfStakeReward(pindexPrev->nHeight + 1, nCoinAge, nFees, pindexBestHeader);
nReward = GetProofOfStakeReward(pindexPrev->nHeight + 1, nCoinAge, nFees, chainActive.Tip());
if (nReward <= 0)
return false;

Expand Down Expand Up @@ -619,7 +619,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
}
}

txNew.nVersion = IsCommunityFundEnabled(pindexBestHeader,Params().GetConsensus()) ? CTransaction::TXDZEEL_VERSION_V2 : CTransaction::TXDZEEL_VERSION;
txNew.nVersion = IsCommunityFundEnabled(chainActive.Tip(),Params().GetConsensus()) ? CTransaction::TXDZEEL_VERSION_V2 : CTransaction::TXDZEEL_VERSION;

// Sign
int nIn = 0;
Expand Down Expand Up @@ -2816,7 +2816,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt

CMutableTransaction txNew;

txNew.nVersion = IsCommunityFundEnabled(pindexBestHeader,Params().GetConsensus()) ? CTransaction::TXDZEEL_VERSION_V2 : CTransaction::TXDZEEL_VERSION;
txNew.nVersion = IsCommunityFundEnabled(chainActive.Tip(),Params().GetConsensus()) ? CTransaction::TXDZEEL_VERSION_V2 : CTransaction::TXDZEEL_VERSION;

if(wtxNew.nCustomVersion > 0) txNew.nVersion = wtxNew.nCustomVersion;

Expand Down