Skip to content

Commit

Permalink
Merge pull request #111 from BlockMechanic/segwit
Browse files Browse the repository at this point in the history
DDD
  • Loading branch information
BlockMechanic authored Sep 27, 2022
2 parents 72432a6 + 18181c6 commit f1cfe31
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ class ChainImpl : public Chain
return ::GetAllAssets();
}

void startStake(bool fStake, CWallet *pwallet, std::thread* stakeThread)override{
::Stake(fStake, pwallet, stakeThread);
void startStake(bool fStake, CWallet *pwallet)override{
::Stake(fStake, pwallet);
}

CContract getContract(std::string name) override
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Chain
virtual CAsset getAsset(std::string sAssetName) = 0;
virtual std::vector<CAsset> getAllAssets() =0;
virtual CTxMemPool& getMempool() = 0;
virtual void startStake(bool fStake, CWallet *pwallet, std::thread* stakeThread) = 0;
virtual void startStake(bool fStake, CWallet *pwallet) = 0;
//! Get block height above genesis block. Returns 0 for genesis block,
//! 1 for following block, and so on. Returns nullopt for a block not
//! included in the current chain.
Expand Down
10 changes: 9 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,16 +682,24 @@ void ThreadStakeMiner(CWallet *pwallet)
LogPrintf("ThreadStakeMiner exiting\n");
}

void Stake(bool fStake, CWallet *pwallet, std::thread* stakeThread)
std::thread* stakeThread = nullptr;

void Stake(bool fStake, CWallet *pwallet)
{
if (stakeThread != nullptr)
{
LogPrintf("%s: Destroying Stake thread\n", __func__);

if (stakeThread->joinable())
stakeThread->join();
stakeThread = nullptr;
LogPrintf("%s: Stake thread destroyed \n", __func__);

}
if(fStake)
{
LogPrintf("%s: Creating Stake thread\n", __func__);

stakeThread = new std::thread([&, pwallet] { TraceThread("stake", [&, pwallet] { ThreadStakeMiner(pwallet); }); });
}
}
2 changes: 1 addition & 1 deletion src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class BlockAssembler
int UpdatePackagesForAdded(const CTxMemPool::setEntries& alreadyAdded, indexed_modified_transaction_set& mapModifiedTx) EXCLUSIVE_LOCKS_REQUIRED(m_mempool.cs);
};
/** Generate a new block, without valid proof-of-work */
void Stake(bool fStake, CWallet *pwallet, std::thread* stakeThread);
void Stake(bool fStake, CWallet *pwallet);

/** Modify the extranonce in a block */
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
Expand Down
3 changes: 3 additions & 0 deletions src/wallet/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ void WalletInit::AddWalletOptions(ArgsManager& argsman) const
argsman.AddArg("-privdb", strprintf("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)", DEFAULT_WALLET_PRIVDB), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
argsman.AddArg("-walletrejectlongchains", strprintf("Wallet will not create transactions that violate mempool chain limits (default: %u)", DEFAULT_WALLET_REJECT_LONG_CHAINS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);

argsman.AddArg("-stake", strprintf("Run a thread for staking default: %u)", true), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);


argsman.AddHiddenArgs({"-zapwallettxes"});
}

Expand Down
1 change: 1 addition & 0 deletions src/wallet/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void StartWallets(CScheduler& scheduler, const ArgsManager& args)
{
for (const std::shared_ptr<CWallet>& pwallet : GetWallets()) {
pwallet->postInitProcess();
if (args.GetBoolArg("-stake", true))
pwallet->Stake(true);
}

Expand Down
2 changes: 0 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ std::shared_ptr<CWallet> CreateWallet(interfaces::Chain& chain, const std::strin
AddWallet(wallet);
wallet->postInitProcess();

wallet->Stake(true);

// Write the wallet settings
UpdateWalletSetting(chain, name, load_on_start, warnings);

Expand Down
2 changes: 0 additions & 2 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
*/
uint256 m_last_block_processed GUARDED_BY(cs_wallet);

std::thread* stakeThread = nullptr;

/* Height of last block processed is used by wallet to know depth of transactions
* without relying on Chain interface beyond asynchronous updates. For safety, we
* initialize it to -1. Height is a pointer on node's tip and doesn't imply
Expand Down

0 comments on commit f1cfe31

Please sign in to comment.