src/TAO/Ledger/tritium_minter.cpp
void TritiumMinter::TritiumMinterThread(TritiumMinter* pTritiumMinter)
        {

            debug::log(0, FUNCTION, "Stake Minter Started");
            pTritiumMinter->nSleepTime = 5000;
            bool fLocalTestnet = config::fTestNet.load() && !config::GetBoolArg("-dns", true);

            /* If the system is still syncing/connecting on startup, wait to run minter */
            while((TAO::Ledger::ChainState::Synchronizing() || (LLP::TRITIUM_SERVER->GetConnectionCount() == 0 && !fLocalTestnet))
                    && !TritiumMinter::fStop.load() && !config::fShutdown.load())
            {
                runtime::sleep(pTritiumMinter->nSleepTime);
            }

            /* Check stop/shutdown status after sync/connect wait ends. If shutdown, wait for stop to return (stop issues join) */
            if(TritiumMinter::fStop.load() || config::fShutdown.load())
            {
                while(!TritiumMinter::fStop.load())
                    runtime::sleep(100);

                return;
            }

            debug::log(0, FUNCTION, "Stake Minter Initialized");

            pTritiumMinter->nSleepTime = 1000;

            /* Minting thread will continue repeating this loop until stop minter or shutdown */
            while(!TritiumMinter::fStop.load() && !config::fShutdown.load())
            {
                runtime::sleep(pTritiumMinter->nSleepTime);

                /* Check stop/shutdown status after wakeup */
                if(TritiumMinter::fStop.load() || config::fShutdown.load())
                    continue;

                /* Save the current best block hash immediately in case it changes while we do setup */
                pTritiumMinter->hashLastBlock = TAO::Ledger::ChainState::hashBestChain.load();

                /* Check that user account still unlocked for minting (locking should stop minter, but still verify) */
                if(!pTritiumMinter->CheckUser())
                    break;

                /* Get the active, unlocked sigchain. Requires session 0 */
                memory::encrypted_ptr<TAO::Ledger::SignatureChain>& user = TAO::API::users->GetAccount(0);
                if(!user)
                {
                    debug::error(0, FUNCTION, "Stake minter could not retrieve the unlocked signature chain.");
                    break;
                }

                SecureString strPIN = TAO::API::users->GetActivePin();

                /* Retrieve the latest trust account data */
                if(!pTritiumMinter->FindTrustAccount(user->Genesis()))
                    break;

                /* Set up the candidate block the minter is attempting to mine */
                if(!pTritiumMinter->CreateCandidateBlock(user, strPIN))
                    continue;

                /* Updates weights for new candidate block */
                if(!pTritiumMinter->CalculateWeights())
                    continue;

                /* Attempt to mine the current proof of stake block */
                pTritiumMinter->MintBlock(user, strPIN);

            }

            /* If break because cannot continue (error retrieving user account or FindTrust failed), wait for stop or shutdown */
            while(!TritiumMinter::fStop.load() && !config::fShutdown.load())
                runtime::sleep(pTritiumMinter->nSleepTime);

            /* If get here because fShutdown set, wait for join. Stop issues join, and must be called during shutdown */
            while(!TritiumMinter::fStop.load())
                runtime::sleep(100);

            /* Stop has been issued. Now thread can end. */
        }
/* Method run on its own thread to oversee stake minter operation. */
Method run on its own thread to oversee stake minter operation.
Method run on its own thread to oversee stake minter operation .
void TritiumMinter::TritiumMinterThread(TritiumMinter* pTritiumMinter)
        {
            debug::log(0, FUNCTION, "Stake Minter Started");
            pTritiumMinter->nSleepTime = 5000;
            bool fLocalTestnet = config::fTestNet.load() && !config::GetBoolArg("-dns", true);
            while((TAO::Ledger::ChainState::Synchronizing() || (LLP::TRITIUM_SERVER->GetConnectionCount() == 0 && !fLocalTestnet))
                    && !TritiumMinter::fStop.load() && !config::fShutdown.load())
            {
                runtime::sleep(pTritiumMinter->nSleepTime);
            }
            if(TritiumMinter::fStop.load() || config::fShutdown.load())
            {
                while(!TritiumMinter::fStop.load())
                    runtime::sleep(100);
                return;
            }
            debug::log(0, FUNCTION, "Stake Minter Initialized");
            pTritiumMinter->nSleepTime = 1000;
            while(!TritiumMinter::fStop.load() && !config::fShutdown.load())
            {
                runtime::sleep(pTritiumMinter->nSleepTime);
                if(TritiumMinter::fStop.load() || config::fShutdown.load())
                    continue;
                pTritiumMinter->hashLastBlock = TAO::Ledger::ChainState::hashBestChain.load();
                if(!pTritiumMinter->CheckUser())
                    break;
                memory::encrypted_ptr<TAO::Ledger::SignatureChain>& user = TAO::API::users->GetAccount(0);
                if(!user)
                {
                    debug::error(0, FUNCTION, "Stake minter could not retrieve the unlocked signature chain.");
                    break;
                }
                SecureString strPIN = TAO::API::users->GetActivePin();
                if(!pTritiumMinter->FindTrustAccount(user->Genesis()))
                    break;
                if(!pTritiumMinter->CreateCandidateBlock(user, strPIN))
                    continue;
                if(!pTritiumMinter->CalculateWeights())
                    continue;
                pTritiumMinter->MintBlock(user, strPIN);
            }
            while(!TritiumMinter::fStop.load() && !config::fShutdown.load())
                runtime::sleep(pTritiumMinter->nSleepTime);
            while(!TritiumMinter::fStop.load())
                runtime::sleep(100);
        }
void TritiumMinter :: TritiumMinterThread ( TritiumMinter * pTritiumMinter ) { debug :: log ( 0 , FUNCTION , " " ) ; pTritiumMinter -> nSleepTime = 5000 ; bool fLocalTestnet = config :: fTestNet . load ( ) && ! config :: GetBoolArg ( " " , true ) ; while ( ( TAO :: Ledger :: ChainState :: Synchronizing ( ) || ( LLP :: TRITIUM_SERVER -> GetConnectionCount ( ) == 0 && ! fLocalTestnet ) ) && ! TritiumMinter :: fStop . load ( ) && ! config :: fShutdown . load ( ) ) { runtime :: sleep ( pTritiumMinter -> nSleepTime ) ; } if ( TritiumMinter :: fStop . load ( ) || config :: fShutdown . load ( ) ) { while ( ! TritiumMinter :: fStop . load ( ) ) runtime :: sleep ( 100 ) ; return ; } debug :: log ( 0 , FUNCTION , " " ) ; pTritiumMinter -> nSleepTime = 1000 ; while ( ! TritiumMinter :: fStop . load ( ) && ! config :: fShutdown . load ( ) ) { runtime :: sleep ( pTritiumMinter -> nSleepTime ) ; if ( TritiumMinter :: fStop . load ( ) || config :: fShutdown . load ( ) ) continue ; pTritiumMinter -> hashLastBlock = TAO :: Ledger :: ChainState :: hashBestChain . load ( ) ; if ( ! pTritiumMinter -> CheckUser ( ) ) break ; memory :: encrypted_ptr < TAO :: Ledger :: SignatureChain > & user = TAO :: API :: users -> GetAccount ( 0 ) ; if ( ! user ) { debug :: error ( 0 , FUNCTION , " " ) ; break ; } SecureString strPIN = TAO :: API :: users -> GetActivePin ( ) ; if ( ! pTritiumMinter -> FindTrustAccount ( user -> Genesis ( ) ) ) break ; if ( ! pTritiumMinter -> CreateCandidateBlock ( user , strPIN ) ) continue ; if ( ! pTritiumMinter -> CalculateWeights ( ) ) continue ; pTritiumMinter -> MintBlock ( user , strPIN ) ; } while ( ! TritiumMinter :: fStop . load ( ) && ! config :: fShutdown . load ( ) ) runtime :: sleep ( pTritiumMinter -> nSleepTime ) ; while ( ! TritiumMinter :: fStop . load ( ) ) runtime :: sleep ( 100 ) ; }
Method run on its own thread to oversee stake minter operation.
Method run on its own thread to oversee stake minter operation .
/* If the system is still syncing/connecting on startup, wait to run minter */ /* Check stop/shutdown status after sync/connect wait ends. If shutdown, wait for stop to return (stop issues join) */ /* Minting thread will continue repeating this loop until stop minter or shutdown */ /* Check stop/shutdown status after wakeup */ /* Save the current best block hash immediately in case it changes while we do setup */ /* Check that user account still unlocked for minting (locking should stop minter, but still verify) */ /* Get the active, unlocked sigchain. Requires session 0 */ /* Retrieve the latest trust account data */ /* Set up the candidate block the minter is attempting to mine */ /* Updates weights for new candidate block */ /* Attempt to mine the current proof of stake block */ /* If break because cannot continue (error retrieving user account or FindTrust failed), wait for stop or shutdown */ /* If get here because fShutdown set, wait for join. Stop issues join, and must be called during shutdown */ /* Stop has been issued. Now thread can end. */