diff --git a/src/chainparamsseeds.h b/src/chainparamsseeds.h index bd94ff0cab..62231e9697 100644 --- a/src/chainparamsseeds.h +++ b/src/chainparamsseeds.h @@ -43,5 +43,6 @@ static const uint8_t chainparams_seed_main[] = { }; static const uint8_t chainparams_seed_test[] = { + 0x01,0x04,0x00,0x00,0x00,0x00,0x20,0x8e, }; #endif // BITCOIN_CHAINPARAMSSEEDS_H diff --git a/src/miner.cpp b/src/miner.cpp index 8aa581c5fc..fab10b1043 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -255,6 +255,7 @@ BlockAssembler::TxAllowedForNamecoin (const CTransaction& tx) const if (nameOutFound && nameOpOut.getNameOp () == OP_NAME_FIRSTUPDATE) { bool nameNewFound = false; + LOCK (cs_main); const auto& coinsTip = ::ChainstateActive ().CoinsTip (); for (const auto& txIn : tx.vin) { diff --git a/src/names/main.h b/src/names/main.h index 060bffe576..a5ca95d086 100644 --- a/src/names/main.h +++ b/src/names/main.h @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -19,6 +20,8 @@ class ChainstateManager; class CTxMemPool; class TxValidationState; +extern RecursiveMutex cs_main; + /* Some constants defining name limits. */ constexpr unsigned MAX_VALUE_LENGTH = 1023; constexpr unsigned MAX_NAME_LENGTH = 255; @@ -105,7 +108,7 @@ void ApplyNameTransaction (const CTransaction& tx, unsigned nHeight, /** * Expire all names at the given height. This removes their coins * from the UTXO set. - * @param height The new block height. + * @param nHeight The new block height. * @param view The coins view to update. * @param undo The block undo object to record undo information. * @param names List all expired names here. @@ -132,6 +135,6 @@ bool UnexpireNames (unsigned nHeight, CBlockUndo& undo, * this throws an assertion failure. * @param disconnect Whether we are disconnecting blocks. */ -void CheckNameDB (ChainstateManager& chainman, bool disconnect); +void CheckNameDB (ChainstateManager& chainman, bool disconnect) EXCLUSIVE_LOCKS_REQUIRED (cs_main); #endif // H_BITCOIN_NAMES_MAIN diff --git a/src/names/mempool.cpp b/src/names/mempool.cpp index c27060d4dc..07ae2b3317 100644 --- a/src/names/mempool.cpp +++ b/src/names/mempool.cpp @@ -36,7 +36,7 @@ namespace * there is any. The txid must be for an entry in the mempool. */ COutPoint -getNameOutput (const CTxMemPool& pool, const uint256& txid) +getNameOutput (const CTxMemPool& pool, const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED (pool.cs) { AssertLockHeld (pool.cs); @@ -57,7 +57,7 @@ getNameOutput (const CTxMemPool& pool, const uint256& txid) } // anonymous namespace COutPoint -CNameMemPool::lastNameOutput (const valtype& name) const +CNameMemPool::lastNameOutput (const valtype& name) const EXCLUSIVE_LOCKS_REQUIRED (pool.cs) { const auto itUpd = updates.find (name); if (itUpd != updates.end ()) @@ -102,7 +102,7 @@ CNameMemPool::lastNameOutput (const valtype& name) const } void -CNameMemPool::addUnchecked (const CTxMemPoolEntry& entry) +CNameMemPool::addUnchecked (const CTxMemPoolEntry& entry) EXCLUSIVE_LOCKS_REQUIRED (pool.cs) { AssertLockHeld (pool.cs); @@ -137,7 +137,7 @@ CNameMemPool::addUnchecked (const CTxMemPoolEntry& entry) } void -CNameMemPool::remove (const CTxMemPoolEntry& entry) +CNameMemPool::remove (const CTxMemPoolEntry& entry) EXCLUSIVE_LOCKS_REQUIRED (pool.cs) { AssertLockHeld (pool.cs); @@ -162,7 +162,7 @@ CNameMemPool::remove (const CTxMemPoolEntry& entry) } void -CNameMemPool::removeConflicts (const CTransaction& tx) +CNameMemPool::removeConflicts (const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED (pool.cs) { AssertLockHeld (pool.cs); @@ -188,7 +188,7 @@ CNameMemPool::removeConflicts (const CTransaction& tx) } void -CNameMemPool::removeUnexpireConflicts (const std::set& unexpired) +CNameMemPool::removeUnexpireConflicts (const std::set& unexpired) EXCLUSIVE_LOCKS_REQUIRED (pool.cs) { AssertLockHeld (pool.cs); @@ -209,7 +209,7 @@ CNameMemPool::removeUnexpireConflicts (const std::set& unexpired) } void -CNameMemPool::removeExpireConflicts (const std::set& expired) +CNameMemPool::removeExpireConflicts (const std::set& expired) EXCLUSIVE_LOCKS_REQUIRED (pool.cs) { AssertLockHeld (pool.cs); @@ -238,7 +238,7 @@ CNameMemPool::removeExpireConflicts (const std::set& expired) } void -CNameMemPool::check (ChainstateManager& chainman, CChainState& active_chainstate) const +CNameMemPool::check (ChainstateManager& chainman, CChainState& active_chainstate) const EXCLUSIVE_LOCKS_REQUIRED (pool.cs, cs_main) { AssertLockHeld (pool.cs); @@ -309,7 +309,7 @@ CNameMemPool::check (ChainstateManager& chainman, CChainState& active_chainstate } bool -CNameMemPool::checkTx (const CTransaction& tx) const +CNameMemPool::checkTx (const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED (pool.cs) { AssertLockHeld (pool.cs); diff --git a/src/names/mempool.h b/src/names/mempool.h index 7475565489..97e23cb41f 100644 --- a/src/names/mempool.h +++ b/src/names/mempool.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/src/rest.cpp b/src/rest.cpp index a232de922b..ba4c148adc 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -741,6 +741,7 @@ static bool rest_name(const std::any& context, HTTPRequest* req, const std::stri return RESTERR(req, HTTP_BAD_REQUEST, "Invalid encoded name: " + encodedName); + LOCK (cs_main); CNameData data; if (!::ChainstateActive ().CoinsTip ().GetName(plainName, data)) return RESTERR(req, HTTP_NOT_FOUND, diff --git a/src/rpc/names.cpp b/src/rpc/names.cpp index b24da36f69..dd6cde70e5 100644 --- a/src/rpc/names.cpp +++ b/src/rpc/names.cpp @@ -136,7 +136,7 @@ addExpirationInfo (const ChainstateManager& chainman, */ void addOwnershipInfo (const CScript& addr, const CWallet* pwallet, - UniValue& data) + UniValue& data) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { if (pwallet == nullptr) return; @@ -311,9 +311,11 @@ class MaybeWalletForRequest */ void addOwnershipInfo (const CScript& addr, const MaybeWalletForRequest& wallet, - UniValue& data) + UniValue& data) EXCLUSIVE_LOCKS_REQUIRED(wallet.getLock()) { #ifdef ENABLE_WALLET + LOCK (wallet.getWallet()->cs_wallet); // This is unneccessary, but the type analyzer can't conclude wallet.getLock() == wallet.getWallet()->cs_wallet + //LOCK (wallet.getLock()); // This is unneccessary, but the type analyzer can't conclude wallet.getLock() == wallet.getWallet()->cs_wallet addOwnershipInfo (addr, wallet.getWallet (), data); #endif } @@ -325,7 +327,7 @@ addOwnershipInfo (const CScript& addr, const MaybeWalletForRequest& wallet, UniValue getNameInfo (const ChainstateManager& chainman, const UniValue& options, const valtype& name, const CNameData& data, - const MaybeWalletForRequest& wallet) + const MaybeWalletForRequest& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.getLock()) { UniValue res = getNameInfo (chainman, options, name, data); addOwnershipInfo (data.getAddress (), wallet, res); diff --git a/src/txdb.h b/src/txdb.h index 37a1725c3a..b2b74cef86 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -65,7 +65,7 @@ class CCoinsViewDB final : public CCoinsView CNameIterator* IterateNames() const override; bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const CNameCache &names) override; CCoinsViewCursor *Cursor() const override; - bool ValidateNameDB(ChainstateManager& chainman, const std::function& interruption_point) const override; + bool ValidateNameDB(ChainstateManager& chainman, const std::function& interruption_point) const override EXCLUSIVE_LOCKS_REQUIRED(cs_main); //! Attempt to update from an older database format. Returns whether an error occurred. bool Upgrade(); diff --git a/src/wallet/rpcnames.cpp b/src/wallet/rpcnames.cpp index eeba4ab058..64e5f3b44c 100644 --- a/src/wallet/rpcnames.cpp +++ b/src/wallet/rpcnames.cpp @@ -318,7 +318,7 @@ namespace * @return True on success, false otherwise */ bool -getNameSalt(CWallet* const pwallet, const valtype& name, const CScript& output, valtype& rand) +getNameSalt(CWallet* const pwallet, const valtype& name, const CScript& output, valtype& rand) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { AssertLockHeld(pwallet->cs_wallet); @@ -467,7 +467,7 @@ namespace * @return True if the output could be found. */ bool -getNamePrevout (const uint256& txid, CTxOut& txOut, CTxIn& txIn) +getNamePrevout (const uint256& txid, CTxOut& txOut, CTxIn& txIn) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { AssertLockHeld (cs_main); @@ -871,7 +871,7 @@ sendtoname () the user could have gotten from another RPC command prior to now. */ pwallet->BlockUntilSyncedToCurrentChain(); - LOCK(pwallet->cs_wallet); + LOCK2 (pwallet->cs_wallet, cs_main); /* sendtoname does not support an options argument (e.g. to override the configured name/value encodings). That would just add to the already diff --git a/src/wallet/rpcwallet.h b/src/wallet/rpcwallet.h index 232f013573..ddd97c61a4 100644 --- a/src/wallet/rpcwallet.h +++ b/src/wallet/rpcwallet.h @@ -14,7 +14,6 @@ #include class CCoinControl; -class CRecipient; class CRPCCommand; class CWallet; class CWalletTx; @@ -22,6 +21,7 @@ class JSONRPCRequest; class LegacyScriptPubKeyMan; class UniValue; class CTransaction; +struct CRecipient; struct PartiallySignedTransaction; struct WalletContext; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 871c5b107c..ff397563f7 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -57,6 +57,7 @@ const std::map WALLET_FLAG_CAVEATS{ static const size_t OUTPUT_GROUP_MAX_ENTRIES = 10; +RecursiveMutex cs_wallet; RecursiveMutex cs_wallets; static std::vector> vpwallets GUARDED_BY(cs_wallets); static std::list g_load_wallet_fns GUARDED_BY(cs_wallets); @@ -1977,7 +1978,7 @@ CAmount CWalletTx::GetCachableAmount(AmountType type, const isminefilter& filter return amount.m_value[filter]; } -CAmount CWalletTx::GetDebit(const isminefilter& filter) const +CAmount CWalletTx::GetDebit(const isminefilter& filter) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { if (tx->vin.empty()) return 0; @@ -2742,7 +2743,7 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC bool CWallet::FindValueInNameInput (const CTxIn& nameInput, CAmount& value, const CWalletTx*& walletTx, - bilingual_str& error) const + bilingual_str& error) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { walletTx = GetWalletTx (nameInput.prevout.hash); if (!walletTx) @@ -2903,6 +2904,7 @@ bool CWallet::CreateTransactionInternal( additionally to the selected coins. */ CAmount nInputValue = 0; const CWalletTx* withInputTx = nullptr; + LOCK(cs_wallet); if (withInput) { if (!FindValueInNameInput (*withInput, nInputValue, withInputTx, error)) @@ -2919,7 +2921,6 @@ bool CWallet::CreateTransactionInternal( int nBytes; { std::set setCoins; - LOCK(cs_wallet); txNew.nLockTime = GetLocktimeForNewTransaction(chain(), GetLastBlockHash(), GetLastBlockHeight()); { std::vector vAvailableCoins;