@@ -717,11 +717,8 @@ static inline bool ProcessBlockFound(const CBlock* pblock, const CChainParams& c
717717 // LogPrintf("generated %s\n", FormatMoney(pblock->IsProofOfStake() ? pblock->vtx[1]->GetValueOut() : pblock->vtx[0]->GetValueOut()));
718718
719719 // Found a solution
720- {
721- LOCK (cs_main);
722- if (pblock->hashPrevBlock != ::ChainActive ().Tip ()->GetBlockHash ())
723- return error (" XEPMiner: generated block is stale" );
724- }
720+ if (pblock->hashPrevBlock != ::ChainActive ().Tip ()->GetBlockHash ())
721+ return error (" XEPMiner: generated block is stale" );
725722
726723 // Process this block the same as if we had received it from another node
727724 std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
@@ -734,7 +731,6 @@ static inline bool ProcessBlockFound(const CBlock* pblock, const CChainParams& c
734731static inline void PoSMiner (std::shared_ptr<CWallet> pwallet, ChainstateManager* chainman, CConnman* connman, CTxMemPool* mempool)
735732{
736733 LogPrintf (" CPUMiner started for proof-of-stake\n " );
737- util::ThreadRename (" xep-stake-minter" );
738734
739735 unsigned int nExtraNonce = 0 ;
740736
@@ -750,13 +746,13 @@ static inline void PoSMiner(std::shared_ptr<CWallet> pwallet, ChainstateManager*
750746 LogPrintf (" Set proof-of-stake timeout: %ums for %u UTXOs\n " , pos_timio, vCoins.size ());
751747 }
752748
753- std::string strMintMessage = _ (" Info: Minting suspended due to locked wallet." ).translated ;
754- std::string strMintSyncMessage = _ (" Info: Minting suspended while synchronizing wallet." ).translated ;
755- std::string strMintDisabledMessage = _ (" Info: Minting disabled by 'nostaking' option." ).translated ;
756- std::string strMintBlockMessage = _ (" Info: Minting suspended due to block creation failure." ).translated ;
757- std::string strMintEmpty = " " ;
749+ const std::string strMintMessage = _ (" Info: Minting suspended due to locked wallet." ).translated ;
750+ const std::string strMintSyncMessage = _ (" Info: Minting suspended while synchronizing wallet." ).translated ;
751+ const std::string strMintDisabledMessage = _ (" Info: Minting disabled by 'nostaking' option." ).translated ;
752+ const std::string strMintBlockMessage = _ (" Info: Minting suspended due to block creation failure." ).translated ;
753+ const std::string strMintEmpty = " " ;
758754 if (!gArgs .GetBoolArg (" -staking" , true )) {
759- strMintWarning = strMintDisabledMessage;
755+ SetMintWarning ( strMintDisabledMessage) ;
760756 LogPrintf (" proof-of-stake minter disabled\n " );
761757 return ;
762758 }
@@ -765,8 +761,8 @@ static inline void PoSMiner(std::shared_ptr<CWallet> pwallet, ChainstateManager*
765761 bool fNeedToClear = false ;
766762 while (true ) {
767763 while (pwallet->IsLocked ()) {
768- if (strMintWarning != strMintMessage) {
769- strMintWarning = strMintMessage;
764+ if (GetMintWarning () != strMintMessage) {
765+ SetMintWarning ( strMintMessage) ;
770766 uiInterface.NotifyAlertChanged ();
771767 }
772768 fNeedToClear = true ;
@@ -778,8 +774,8 @@ static inline void PoSMiner(std::shared_ptr<CWallet> pwallet, ChainstateManager*
778774 // Busy-wait for the network to come online so we don't waste time mining
779775 // on an obsolete chain. In regtest mode we expect to fly solo.
780776 while (connman == nullptr || connman->GetNodeCount (CConnman::CONNECTIONS_ALL) == 0 || ::ChainstateActive ().IsInitialBlockDownload ()) {
781- if (strMintWarning != strMintSyncMessage) {
782- strMintWarning = strMintSyncMessage;
777+ if (GetMintWarning () != strMintSyncMessage) {
778+ SetMintWarning ( strMintSyncMessage) ;
783779 uiInterface.NotifyAlertChanged ();
784780 }
785781 fNeedToClear = true ;
@@ -790,16 +786,16 @@ static inline void PoSMiner(std::shared_ptr<CWallet> pwallet, ChainstateManager*
790786
791787 while (GuessVerificationProgress (Params ().TxData (), ::ChainActive ().Tip ()) < 0.996 ) {
792788 LogPrintf (" Minter thread sleeps while sync at %f\n " , GuessVerificationProgress (Params ().TxData (), ::ChainActive ().Tip ()));
793- if (strMintWarning != strMintSyncMessage) {
794- strMintWarning = strMintSyncMessage;
789+ if (GetMintWarning () != strMintSyncMessage) {
790+ SetMintWarning ( strMintSyncMessage) ;
795791 uiInterface.NotifyAlertChanged ();
796792 }
797793 fNeedToClear = true ;
798794 if (!connman->interruptNet .sleep_for (std::chrono::seconds (10 )))
799795 return ;
800796 }
801797 if (fNeedToClear ) {
802- strMintWarning = strMintEmpty;
798+ SetMintWarning ( strMintEmpty) ;
803799 uiInterface.NotifyAlertChanged ();
804800 fNeedToClear = false ;
805801 }
@@ -824,7 +820,7 @@ static inline void PoSMiner(std::shared_ptr<CWallet> pwallet, ChainstateManager*
824820 return ;
825821 continue ;
826822 }
827- strMintWarning = strMintBlockMessage;
823+ SetMintWarning ( strMintBlockMessage) ;
828824 uiInterface.NotifyAlertChanged ();
829825 LogPrintf (" Error in XEPMiner: Keypool ran out, please call keypoolrefill before restarting the staking thread\n " );
830826 if (!connman->interruptNet .sleep_for (std::chrono::seconds (10 )))
@@ -837,6 +833,7 @@ static inline void PoSMiner(std::shared_ptr<CWallet> pwallet, ChainstateManager*
837833 bool pubkeyInSig = true ;
838834 {
839835 LOCK (pwallet->cs_wallet );
836+
840837 if (!pwallet->GetBlockSigningPubKey (*pblock, signingPubKey, pubkeyInSig)) {
841838 LogPrintf (" PoSMiner(): failed to get signing pubkey for PoS block\n " );
842839 continue ;
@@ -847,6 +844,7 @@ static inline void PoSMiner(std::shared_ptr<CWallet> pwallet, ChainstateManager*
847844 // peercoin: if proof-of-stake block found then process block
848845 {
849846 LOCK (pwallet->cs_wallet );
847+
850848 if (!pwallet->SignBlock (*pblock, signingPubKey)) {
851849 LogPrintf (" PoSMiner(): failed to sign PoS block\n " );
852850 continue ;
@@ -873,22 +871,23 @@ static inline void PoSMiner(std::shared_ptr<CWallet> pwallet, ChainstateManager*
873871}
874872
875873// peercoin: stake minter thread
876- static void ThreadStakeMinter (std::shared_ptr<CWallet> pwallet, ChainstateManager* chainman, CConnman* connman, CTxMemPool* mempool)
874+ static void ThreadStakeMinter (std::shared_ptr<CWallet> pwallet, const unsigned int walletNum, ChainstateManager* chainman, CConnman* connman, CTxMemPool* mempool)
877875{
878- LogPrintf (" ThreadStakeMinter started\n " );
876+ util::ThreadRename (" xep-stake-minter-" + std::to_string (walletNum));
877+ LogPrintf (" ThreadStakeMinter #%u started\n " , walletNum);
879878 try {
880879 PoSMiner (pwallet, chainman, connman, mempool);
881880 } catch (std::exception& e) {
882881 PrintExceptionContinue (&e, " ThreadStakeMinter()" );
883882 } catch (...) {
884883 PrintExceptionContinue (NULL , " ThreadStakeMinter()" );
885884 }
886- LogPrintf (" ThreadStakeMinter exiting\n " );
885+ LogPrintf (" ThreadStakeMinter #%u exiting\n " , walletNum );
887886}
888887
889888// peercoin: stake minter
890- void MintStake (boost::thread_group& threadGroup, std::shared_ptr<CWallet> pwallet, ChainstateManager* chainman, CConnman* connman, CTxMemPool* mempool)
889+ void MintStake (boost::thread_group& threadGroup, std::shared_ptr<CWallet> pwallet, const unsigned int walletNum, ChainstateManager* chainman, CConnman* connman, CTxMemPool* mempool)
891890{
892891 // peercoin: mint proof-of-stake blocks in the background
893- threadGroup.create_thread (boost::bind (&ThreadStakeMinter, pwallet, chainman, connman, mempool));
892+ threadGroup.create_thread (boost::bind (&ThreadStakeMinter, pwallet, walletNum, chainman, connman, mempool));
894893}
0 commit comments