diff --git a/src/coins.cpp b/src/coins.cpp index f5e2c4f..6ce6d8d 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -155,6 +155,9 @@ const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const { bool CCoinsViewCache::HaveCoin(const COutPoint &outpoint) const { CCoinsMap::const_iterator it = FetchCoin(outpoint); + + LogPrintf("%s: %s\n", __func__, it->second.coin.IsSpent() ? "true": "false"); + return (it != cacheCoins.end() && !it->second.coin.IsSpent()); } @@ -277,8 +280,8 @@ CAmountMap CCoinsViewCache::GetValueInMap(const CTransaction& tx) const }else{ asset = Params().GetConsensus().subsidy_asset; amount = AccessCoin(prevout).out.nValue; - } - + } + nResult[asset] += amount; } diff --git a/src/init.cpp b/src/init.cpp index 238d73c..29e992e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -2196,6 +2197,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA }, DUMP_BANS_INTERVAL); node.scheduler->scheduleEvery(std::bind(&ThreadNodeSync, std::ref(*node.connman)), std::chrono::milliseconds{1000}); + node.scheduler->scheduleEvery(std::bind(&NodeMinter, std::ref(Params()), std::ref(*node.connman)), std::chrono::milliseconds{5000}); #if HAVE_SYSTEM StartupNotify(args); diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index 3aa9ad2..ab6a1d6 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -217,10 +217,6 @@ class ChainImpl : public Chain return ::GetAllAssets(); } - void startStake(bool fStake, CWallet *pwallet)override{ - ::Stake(fStake, pwallet); - } - CContract getContract(std::string name) override { return ::GetContract(name); diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index c15a9c3..504e945 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -94,7 +94,6 @@ class Chain virtual CAsset getAsset(std::string sAssetName) = 0; virtual std::vector getAllAssets() =0; virtual CTxMemPool& getMempool() = 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. diff --git a/src/miner.cpp b/src/miner.cpp index 6808fae..97cb13e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -636,12 +636,7 @@ void ThreadStakeMiner(CWallet *pwallet) } } } - // - // Create new block - // - //LOCK(pwallet->cs_wallet); - if(pwallet->HaveAvailableCoinsForStaking()) - { + // First just create an empty block. No need to process transactions until we know we can create a block std::unique_ptr pblocktemplate(BlockAssembler(mempool, Params()).CreateNewBlock(dummyscript, pwallet, true)); @@ -662,11 +657,7 @@ void ThreadStakeMiner(CWallet *pwallet) LogPrintf("ThreadStakeMiner : ProcessBlock, block not accepted \n"); return; } - } - else { - LogPrintf("%s: no available coins\n", __func__); - UninterruptibleSleep(std::chrono::seconds{600}); - } + } } catch (const std::runtime_error &e) @@ -682,24 +673,3 @@ void ThreadStakeMiner(CWallet *pwallet) LogPrintf("ThreadStakeMiner exiting\n"); } -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); }); }); - } -} diff --git a/src/miner.h b/src/miner.h index 004516d..8727dea 100644 --- a/src/miner.h +++ b/src/miner.h @@ -197,8 +197,6 @@ class BlockAssembler * of updated descendants. */ 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); /** Modify the extranonce in a block */ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce); diff --git a/src/nodeconfig.cpp b/src/nodeconfig.cpp index 7b31f87..0ba16ad 100755 --- a/src/nodeconfig.cpp +++ b/src/nodeconfig.cpp @@ -62,39 +62,20 @@ bool CNodeConfig::read(std::string& strErr) return false; } } + /*std::remove(ip.begin(), ip.end(), ' '); + std::size_t pos = ip.find(":"); + std::string sport = ip.substr(pos); + int port = stoi(sport); - if(Params().NetworkIDString() == CBaseChainParams::MAIN) { - if(CService(ip).GetPort() != 9340) { - strErr = ("Invalid port detected in ") + getFileName() + "\n" + - strprintf("Line: %d", linenumber) + "\n\"" + line + "\"" + "\n" + - ("(must be 9340 for mainnet)"); - streamConfig.close(); - return false; - } - } else if (Params().NetworkIDString() == CBaseChainParams::TESTNET) { - if(CService(ip).GetPort() != 18333) { - strErr = ("Invalid port detected in ") + getFileName() + "\n" + - strprintf("Line: %d", linenumber) + "\n\"" + line + "\"" + "\n" + - ("(must be 18333 for testnet)"); - streamConfig.close(); - return false; - } - } else if(CService(ip).GetPort() == 9340) { + LogPrintf("%s: ALIAS: %s, IP: %s, \n", __func__, alias, ip); + + if(CService(ip).GetPort() != Params().GetDefaultPort()) { strErr = ("Invalid port detected in ") + getFileName() + "\n" + - strprintf("Line: %d", linenumber) + "\n\"" + line + "\"" + "\n" + - ("(9340 could be used only on mainnet)"); + strprintf("Line: %d\n", linenumber) + strprintf("GOT: %d", CService(ip).GetPort()) + "\n\"" + line + "\"" + "\n" + + strprintf("(GOT %d, must be %d for %s)", CService(ip).GetPort(), Params().GetDefaultPort(), Params().NetworkIDString()); streamConfig.close(); return false; - } - // TODO fix - //if (Params().NetworkIDString() != CBaseChainParams::DEVNET && !(CService(ip).IsIPv4() && CService(ip).IsRoutable())) { - // strErr = _("Invalid Address detected in ") + getFileName() + "\n" + - // strprintf(_("Line: %d"), linenumber) + "\n\"" + line + "\"" + "\n" + - // _("(IPV4 ONLY)"); - // streamConfig.close(); - // return false; - //} - + }*/ add(alias, ip, privKey, txHash, outputIndex); } diff --git a/src/validation.cpp b/src/validation.cpp index 68a0205..75948ec 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1847,7 +1847,9 @@ int ApplyTxInUndo(Coin&& undo, CCoinsViewCache& view, const COutPoint& out) if (view.HaveCoin(out)){ fClean = false; // overwriting transaction output - //LogPrintf("%s %s \n", __func__, fClean ? "true": "false"); + + if(!fClean) + LogPrintf("%s PROBLEM %s\n", __func__, !fClean ? "true": "false"); } if (undo.nHeight == 0) { @@ -1940,8 +1942,8 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI if (!is_spent || tx.vpout[o] != coin.out || pindex->nHeight != coin.nHeight || is_coinbase != coin.fCoinBase || is_coinstake != coin.fCoinStake) { if(!tx.vpout[o].IsEmpty()) fClean = false; // transaction output mismatch - //LogPrintf("fClean %s , SPENT %s , OUT %s, CB %s, CS %s\n", fClean ? "true": "false", is_spent ? "true": "false", tx.vpout[o] != coin.out ? "true": "false", is_coinbase != coin.fCoinBase ? "true": "false",is_coinstake != coin.fCoinStake ? "true": "false"); - //LogPrintf("VOUT %s \n %s \n", tx.vpout[o].ToString(), coin.out.ToString()); + LogPrintf("fClean %s , SPENT %s , OUT %s, CB %s, CS %s\n", fClean ? "true": "false", is_spent ? "true": "false", tx.vpout[o] != coin.out ? "true": "false", is_coinbase != coin.fCoinBase ? "true": "false",is_coinstake != coin.fCoinStake ? "true": "false"); + LogPrintf("VOUT %s \n %s \n", tx.vpout[o].ToString(), coin.out.ToString()); } } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8d48d22..66db6c8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -5417,27 +5417,3 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat return ret; } - -bool CWallet::HaveAvailableCoinsForStaking() const -{ - std::vector vCoins; - CCoinControl coin_control; - LOCK(cs_wallet); - - //To do , either map out or make calls for each stakable asset - AvailableCoins(vCoins, true, &coin_control, 1, MAX_MONEY, 0, MAX_MONEY, &Params().GetConsensus().subsidy_asset); - - //CAmountMap reserved {{Params().GetConsensus().subsidy_asset,gArgs.GetArg("-reserve-balance", DEFAULT_RESERVE_BALANCE)}}; - CAmountMap balance = GetAvailableBalance(&coin_control); - - //balance -= reserved; - LogPrintf("Balance = %s, vCoins.size()= %d \n", balance, vCoins.size()); - //return (balance > CAmountMap() && vCoins.size() > 0); - return (balance > CAmountMap()); - -} - -void CWallet::Stake(bool fStake) -{ - m_chain->startStake(fStake, this, stakeThread); -} diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 0b02ed8..528188b 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -874,7 +874,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati */ void AvailableCoins(std::vector& vCoins, bool fOnlySafe = true, const CCoinControl* coinControl = nullptr, const CAmount& nMinimumAmount = 1, const CAmount& nMaximumAmount = MAX_MONEY, const CAmount& nMinimumSumAmount = MAX_MONEY, const uint64_t nMaximumCount = 0, const CAsset* asset_filter=nullptr) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void AvailableCoins2(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, AvailableCoinsType coin_type=ALL_COINS, bool useIX = false) const; - bool HaveAvailableCoinsForStaking() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); std::map > AvailableCoinsByAddress(bool fConfirmed = true, CAmount maxCoinValue = 0); /** * Return list of available coins and locked coins grouped by non-change output address. @@ -1364,9 +1363,9 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati bool GetActiveMasternode(CMasternode*& activeStakingNode); bool GetActiveSystemnode(CSystemnode*& activeStakingNode); uint256 GenerateStakeModifier(const CBlockIndex* prewardBlockIndex) const; - bool CreateCoinStake(const int nHeight, const uint32_t& nBits, const uint32_t& nTime, CMutableTransaction& txCoinStake, uint32_t& nTxNewTime, StakePointer& stakePointer); + //bool CreateCoinStake(const int nHeight, const uint32_t& nBits, const uint32_t& nTime, CMutableTransaction& txCoinStake, uint32_t& nTxNewTime, StakePointer& stakePointer); - void Stake(bool fStake); + //void Stake(bool fStake); }; /**