@@ -168,13 +168,13 @@ bool CreateCoinbaseTx(CBlock* pblock, const CScript& scriptPubKeyIn, CBlockIndex
168168 return true ;
169169}
170170
171- bool SolveProofOfStake (CBlock* pblock, CBlockIndex* pindexPrev, CWallet* pwallet)
171+ bool SolveProofOfStake (CBlock* pblock, CBlockIndex* pindexPrev, CWallet* pwallet, std::vector<COutput>* availableCoins )
172172{
173173 boost::this_thread::interruption_point ();
174174 pblock->nBits = GetNextWorkRequired (pindexPrev, pblock);
175175 CMutableTransaction txCoinStake;
176176 int64_t nTxNewTime = 0 ;
177- if (!pwallet->CreateCoinStake (*pwallet, pindexPrev, pblock->nBits , txCoinStake, nTxNewTime)) {
177+ if (!pwallet->CreateCoinStake (*pwallet, pindexPrev, pblock->nBits , txCoinStake, nTxNewTime, availableCoins )) {
178178 LogPrint (BCLog::STAKING, " %s : stake not found\n " , __func__);
179179 return false ;
180180 }
@@ -190,7 +190,7 @@ bool SolveProofOfStake(CBlock* pblock, CBlockIndex* pindexPrev, CWallet* pwallet
190190 return true ;
191191}
192192
193- CBlockTemplate* CreateNewBlock (const CScript& scriptPubKeyIn, CWallet* pwallet, bool fProofOfStake )
193+ CBlockTemplate* CreateNewBlock (const CScript& scriptPubKeyIn, CWallet* pwallet, bool fProofOfStake , std::vector<COutput>* availableCoins )
194194{
195195 // Create new block
196196 std::unique_ptr<CBlockTemplate> pblocktemplate (new CBlockTemplate ());
@@ -214,7 +214,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
214214 }
215215
216216 // Depending on the tip height, try to find a coinstake who solves the block or create a coinbase tx.
217- if (!(fProofOfStake ? SolveProofOfStake (pblock, pindexPrev, pwallet)
217+ if (!(fProofOfStake ? SolveProofOfStake (pblock, pindexPrev, pwallet, availableCoins )
218218 : CreateCoinbaseTx (pblock, scriptPubKeyIn, pindexPrev))) {
219219 return nullptr ;
220220 }
@@ -556,13 +556,13 @@ bool fGenerateBitcoins = false;
556556bool fStakeableCoins = false ;
557557int nMintableLastCheck = 0 ;
558558
559- void CheckForCoins (CWallet* pwallet, const int minutes)
559+ void CheckForCoins (CWallet* pwallet, const int minutes, std::vector<COutput>* availableCoins )
560560{
561561 // control the amount of times the client will check for mintable coins
562562 int nTimeNow = GetTime ();
563563 if ((nTimeNow - nMintableLastCheck > minutes * 60 )) {
564564 nMintableLastCheck = nTimeNow;
565- fStakeableCoins = pwallet->StakeableCoins ();
565+ fStakeableCoins = pwallet->StakeableCoins (availableCoins );
566566 }
567567}
568568
@@ -578,9 +578,10 @@ void BitcoinMiner(CWallet* pwallet, bool fProofOfStake)
578578 Optional<CReserveKey> opReservekey{nullopt };
579579 if (!fProofOfStake ) {
580580 opReservekey = CReserveKey (pwallet);
581-
582581 }
583582
583+ // Available UTXO set
584+ std::vector<COutput> availableCoins;
584585 unsigned int nExtraNonce = 0 ;
585586
586587 while (fGenerateBitcoins || fProofOfStake ) {
@@ -597,13 +598,13 @@ void BitcoinMiner(CWallet* pwallet, bool fProofOfStake)
597598 }
598599
599600 // update fStakeableCoins (5 minute check time);
600- CheckForCoins (pwallet, 5 );
601+ CheckForCoins (pwallet, 5 , &availableCoins );
601602
602603 while ((g_connman && g_connman->GetNodeCount (CConnman::CONNECTIONS_ALL) == 0 && Params ().MiningRequiresPeers ())
603604 || pwallet->IsLocked () || !fStakeableCoins || masternodeSync.NotCompleted ()) {
604605 MilliSleep (5000 );
605606 // Do a separate 1 minute check here to ensure fStakeableCoins is updated
606- if (!fStakeableCoins ) CheckForCoins (pwallet, 1 );
607+ if (!fStakeableCoins ) CheckForCoins (pwallet, 1 , &availableCoins );
607608 }
608609
609610 // search our map of hashed blocks, see if bestblock has been hashed yet
@@ -626,7 +627,7 @@ void BitcoinMiner(CWallet* pwallet, bool fProofOfStake)
626627 unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated ();
627628
628629 std::unique_ptr<CBlockTemplate> pblocktemplate ((fProofOfStake ?
629- CreateNewBlock (CScript (), pwallet, fProofOfStake ) :
630+ CreateNewBlock (CScript (), pwallet, true , &availableCoins ) :
630631 CreateNewBlockWithKey (*opReservekey, pwallet)));
631632 if (!pblocktemplate.get ()) continue ;
632633 CBlock* pblock = &pblocktemplate->block ;
0 commit comments