diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bench/prevector.cpp | 28 | ||||
-rw-r--r-- | src/httpserver.cpp | 3 | ||||
-rw-r--r-- | src/httpserver.h | 2 | ||||
-rw-r--r-- | src/init.cpp | 8 | ||||
-rw-r--r-- | src/interfaces/wallet.cpp | 2 | ||||
-rw-r--r-- | src/net.cpp | 3 | ||||
-rw-r--r-- | src/net.h | 2 | ||||
-rw-r--r-- | src/net_processing.cpp | 91 | ||||
-rw-r--r-- | src/rpc/server.cpp | 3 | ||||
-rw-r--r-- | src/rpc/server.h | 2 | ||||
-rw-r--r-- | src/script/sign.cpp | 1 | ||||
-rw-r--r-- | src/script/sign.h | 20 | ||||
-rw-r--r-- | src/sync.h | 4 | ||||
-rw-r--r-- | src/threadsafety.h | 2 | ||||
-rw-r--r-- | src/torcontrol.cpp | 5 | ||||
-rw-r--r-- | src/txdb.cpp | 3 | ||||
-rw-r--r-- | src/txdb.h | 2 | ||||
-rw-r--r-- | src/txmempool.cpp | 6 | ||||
-rw-r--r-- | src/txmempool.h | 4 | ||||
-rw-r--r-- | src/validation.cpp | 8 | ||||
-rw-r--r-- | src/validation.h | 2 | ||||
-rw-r--r-- | src/wallet/rpcdump.cpp | 43 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 42 | ||||
-rw-r--r-- | src/wallet/wallet.h | 16 | ||||
-rw-r--r-- | src/wallet/walletdb.cpp | 12 |
25 files changed, 159 insertions, 155 deletions
diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp index 09c7020848..7986d0da79 100644 --- a/src/bench/prevector.cpp +++ b/src/bench/prevector.cpp @@ -4,12 +4,17 @@ #include <compat.h> #include <prevector.h> +#include <serialize.h> +#include <streams.h> #include <bench/bench.h> struct nontrivial_t { int x; nontrivial_t() :x(-1) {} + ADD_SERIALIZE_METHODS + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action) {READWRITE(x);} }; static_assert(!IS_TRIVIALLY_CONSTRUCTIBLE<nontrivial_t>::value, "expected nontrivial_t to not be trivially constructible"); @@ -62,6 +67,28 @@ static void PrevectorResize(benchmark::State& state) } } +template <typename T> +static void PrevectorDeserialize(benchmark::State& state) +{ + CDataStream s0(SER_NETWORK, 0); + prevector<28, T> t0; + t0.resize(28); + for (auto x = 0; x < 900; ++x) { + s0 << t0; + } + t0.resize(100); + for (auto x = 0; x < 101; ++x) { + s0 << t0; + } + while (state.KeepRunning()) { + prevector<28, T> t1; + for (auto x = 0; x < 1000; ++x) { + s0 >> t1; + } + s0.Init(SER_NETWORK, 0); + } +} + #define PREVECTOR_TEST(name, nontrivops, trivops) \ static void Prevector ## name ## Nontrivial(benchmark::State& state) { \ Prevector ## name<nontrivial_t>(state); \ @@ -75,3 +102,4 @@ static void PrevectorResize(benchmark::State& state) PREVECTOR_TEST(Clear, 28300, 88600) PREVECTOR_TEST(Destructor, 28800, 88900) PREVECTOR_TEST(Resize, 28900, 90300) +PREVECTOR_TEST(Deserialize, 6800, 52000) diff --git a/src/httpserver.cpp b/src/httpserver.cpp index bd08b04c0f..3a3a26b7db 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -423,7 +423,7 @@ std::thread threadHTTP; std::future<bool> threadResult; static std::vector<std::thread> g_thread_http_workers; -bool StartHTTPServer() +void StartHTTPServer() { LogPrint(BCLog::HTTP, "Starting HTTP server\n"); int rpcThreads = std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L); @@ -435,7 +435,6 @@ bool StartHTTPServer() for (int i = 0; i < rpcThreads; i++) { g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue); } - return true; } void InterruptHTTPServer() diff --git a/src/httpserver.h b/src/httpserver.h index 8132c887b5..8a3adaf91f 100644 --- a/src/httpserver.h +++ b/src/httpserver.h @@ -26,7 +26,7 @@ bool InitHTTPServer(); * This is separate from InitHTTPServer to give users race-condition-free time * to register their handlers between InitHTTPServer and StartHTTPServer. */ -bool StartHTTPServer(); +void StartHTTPServer(); /** Interrupt HTTP server threads */ void InterruptHTTPServer(); /** Stop HTTP server */ diff --git a/src/init.cpp b/src/init.cpp index c7ea40817d..18402ef5d7 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -731,14 +731,12 @@ static bool AppInitServers() RPCServer::OnStopped(&OnRPCStopped); if (!InitHTTPServer()) return false; - if (!StartRPC()) - return false; + StartRPC(); if (!StartHTTPRPC()) return false; if (gArgs.GetBoolArg("-rest", DEFAULT_REST_ENABLE) && !StartREST()) return false; - if (!StartHTTPServer()) - return false; + StartHTTPServer(); return true; } @@ -927,7 +925,7 @@ bool AppInitParameterInteraction() // also see: InitParameterInteraction() if (!fs::is_directory(GetBlocksDir(false))) { - return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist.\n"), gArgs.GetArg("-blocksdir", "").c_str())); + return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), gArgs.GetArg("-blocksdir", "").c_str())); } // if using block pruning, then disallow txindex diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 28081c7c2c..55a6f771e5 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -90,7 +90,7 @@ WalletTxStatus MakeWalletTxStatus(const CWalletTx& wtx) WalletTxStatus result; auto mi = ::mapBlockIndex.find(wtx.hashBlock); CBlockIndex* block = mi != ::mapBlockIndex.end() ? mi->second : nullptr; - result.block_height = (block ? block->nHeight : std::numeric_limits<int>::max()), + result.block_height = (block ? block->nHeight : std::numeric_limits<int>::max()); result.blocks_to_maturity = wtx.GetBlocksToMaturity(); result.depth_in_main_chain = wtx.GetDepthInMainChain(); result.time_received = wtx.nTimeReceived; diff --git a/src/net.cpp b/src/net.cpp index 67a73fa9fc..0ebfefa757 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -235,12 +235,11 @@ bool AddLocal(const CNetAddr &addr, int nScore) return AddLocal(CService(addr, GetListenPort()), nScore); } -bool RemoveLocal(const CService& addr) +void RemoveLocal(const CService& addr) { LOCK(cs_mapLocalHost); LogPrintf("RemoveLocal(%s)\n", addr.ToString()); mapLocalHost.erase(addr); - return true; } /** Make a particular network entirely off-limits (no automatic connects to it) */ @@ -505,7 +505,7 @@ bool IsLimited(enum Network net); bool IsLimited(const CNetAddr& addr); bool AddLocal(const CService& addr, int nScore = LOCAL_NONE); bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE); -bool RemoveLocal(const CService& addr); +void RemoveLocal(const CService& addr); bool SeenLocal(const CService& addr); bool IsLocal(const CService& addr); bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr); diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 5267f96f70..d5d664b27e 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -76,7 +76,7 @@ std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(g_cs_orphans); void EraseOrphansFor(NodeId peer); /** Increase a node's misbehavior score. */ -void Misbehaving(NodeId nodeid, int howmuch, const std::string& message=""); +void Misbehaving(NodeId nodeid, int howmuch, const std::string& message="") EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** Average delay between local address broadcasts in seconds. */ static constexpr unsigned int AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL = 24 * 60 * 60; @@ -96,22 +96,20 @@ static constexpr unsigned int MAX_FEEFILTER_CHANGE_DELAY = 5 * 60; // Internal stuff namespace { /** Number of nodes with fSyncStarted. */ - int nSyncStarted = 0; + int nSyncStarted GUARDED_BY(cs_main) = 0; /** * Sources of received blocks, saved to be able to send them reject - * messages or ban them when processing happens afterwards. Protected by - * cs_main. + * messages or ban them when processing happens afterwards. * Set mapBlockSource[hash].second to false if the node should not be * punished if the block is invalid. */ - std::map<uint256, std::pair<NodeId, bool>> mapBlockSource; + std::map<uint256, std::pair<NodeId, bool>> mapBlockSource GUARDED_BY(cs_main); /** * Filter for transactions that were recently rejected by * AcceptToMemoryPool. These are not rerequested until the chain tip - * changes, at which point the entire filter is reset. Protected by - * cs_main. + * changes, at which point the entire filter is reset. * * Without this filter we'd be re-requesting txs from each of our peers, * increasing bandwidth consumption considerably. For instance, with 100 @@ -127,38 +125,38 @@ namespace { * * Memory used: 1.3 MB */ - std::unique_ptr<CRollingBloomFilter> recentRejects; - uint256 hashRecentRejectsChainTip; + std::unique_ptr<CRollingBloomFilter> recentRejects GUARDED_BY(cs_main); + uint256 hashRecentRejectsChainTip GUARDED_BY(cs_main); - /** Blocks that are in flight, and that are in the queue to be downloaded. Protected by cs_main. */ + /** Blocks that are in flight, and that are in the queue to be downloaded. */ struct QueuedBlock { uint256 hash; const CBlockIndex* pindex; //!< Optional. bool fValidatedHeaders; //!< Whether this block has validated headers at the time of request. std::unique_ptr<PartiallyDownloadedBlock> partialBlock; //!< Optional, used for CMPCTBLOCK downloads }; - std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> > mapBlocksInFlight; + std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> > mapBlocksInFlight GUARDED_BY(cs_main); /** Stack of nodes which we have set to announce using compact blocks */ - std::list<NodeId> lNodesAnnouncingHeaderAndIDs; + std::list<NodeId> lNodesAnnouncingHeaderAndIDs GUARDED_BY(cs_main); /** Number of preferable block download peers. */ - int nPreferredDownload = 0; + int nPreferredDownload GUARDED_BY(cs_main) = 0; /** Number of peers from which we're downloading blocks. */ - int nPeersWithValidatedDownloads = 0; + int nPeersWithValidatedDownloads GUARDED_BY(cs_main) = 0; /** Number of outbound peers with m_chain_sync.m_protect. */ - int g_outbound_peers_with_protect_from_disconnect = 0; + int g_outbound_peers_with_protect_from_disconnect GUARDED_BY(cs_main) = 0; /** When our tip was last updated. */ std::atomic<int64_t> g_last_tip_update(0); - /** Relay map, protected by cs_main. */ + /** Relay map */ typedef std::map<uint256, CTransactionRef> MapRelay; - MapRelay mapRelay; - /** Expiration-time ordered list of (expire time, relay map entry) pairs, protected by cs_main). */ - std::deque<std::pair<int64_t, MapRelay::iterator>> vRelayExpiration; + MapRelay mapRelay GUARDED_BY(cs_main); + /** Expiration-time ordered list of (expire time, relay map entry) pairs. */ + std::deque<std::pair<int64_t, MapRelay::iterator>> vRelayExpiration GUARDED_BY(cs_main); std::atomic<int64_t> nTimeBestReceived(0); // Used only to inform the wallet of when we last received a block @@ -302,18 +300,17 @@ struct CNodeState { } }; -/** Map maintaining per-node state. Requires cs_main. */ -static std::map<NodeId, CNodeState> mapNodeState; +/** Map maintaining per-node state. */ +static std::map<NodeId, CNodeState> mapNodeState GUARDED_BY(cs_main); -// Requires cs_main. -static CNodeState *State(NodeId pnode) { +static CNodeState *State(NodeId pnode) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { std::map<NodeId, CNodeState>::iterator it = mapNodeState.find(pnode); if (it == mapNodeState.end()) return nullptr; return &it->second; } -static void UpdatePreferredDownload(CNode* node, CNodeState* state) +static void UpdatePreferredDownload(CNode* node, CNodeState* state) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { nPreferredDownload -= state->fPreferredDownload; @@ -344,10 +341,9 @@ static void PushNodeVersion(CNode *pnode, CConnman* connman, int64_t nTime) } } -// Requires cs_main. // Returns a bool indicating whether we requested this block. // Also used if a block was /not/ received and timed out or started with another peer -static bool MarkBlockAsReceived(const uint256& hash) { +static bool MarkBlockAsReceived(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash); if (itInFlight != mapBlocksInFlight.end()) { CNodeState *state = State(itInFlight->second.first); @@ -370,10 +366,9 @@ static bool MarkBlockAsReceived(const uint256& hash) { return false; } -// Requires cs_main. // returns false, still setting pit, if the block was already in flight from the same peer // pit will only be valid as long as the same cs_main lock is being held -static bool MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlockIndex* pindex = nullptr, std::list<QueuedBlock>::iterator** pit = nullptr) { +static bool MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlockIndex* pindex = nullptr, std::list<QueuedBlock>::iterator** pit = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { CNodeState *state = State(nodeid); assert(state != nullptr); @@ -407,7 +402,7 @@ static bool MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlock } /** Check whether the last unknown block a peer advertised is not yet known. */ -static void ProcessBlockAvailability(NodeId nodeid) { +static void ProcessBlockAvailability(NodeId nodeid) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { CNodeState *state = State(nodeid); assert(state != nullptr); @@ -423,7 +418,7 @@ static void ProcessBlockAvailability(NodeId nodeid) { } /** Update tracking information about which blocks a peer is assumed to have. */ -static void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { +static void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { CNodeState *state = State(nodeid); assert(state != nullptr); @@ -447,7 +442,8 @@ static void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { * lNodesAnnouncingHeaderAndIDs, and keeping that list under a certain size by * removing the first element if necessary. */ -static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman* connman) { +static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman* connman) +{ AssertLockHeld(cs_main); CNodeState* nodestate = State(nodeid); if (!nodestate || !nodestate->fSupportsDesiredCmpctVersion) { @@ -463,11 +459,13 @@ static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman* connma } } connman->ForNode(nodeid, [connman](CNode* pfrom){ + AssertLockHeld(cs_main); uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices() & NODE_WITNESS) ? 2 : 1; if (lNodesAnnouncingHeaderAndIDs.size() >= 3) { // As per BIP152, we only get 3 of our peers to announce // blocks using compact encodings. connman->ForNode(lNodesAnnouncingHeaderAndIDs.front(), [connman, nCMPCTBLOCKVersion](CNode* pnodeStop){ + AssertLockHeld(cs_main); connman->PushMessage(pnodeStop, CNetMsgMaker(pnodeStop->GetSendVersion()).Make(NetMsgType::SENDCMPCT, /*fAnnounceUsingCMPCTBLOCK=*/false, nCMPCTBLOCKVersion)); return true; }); @@ -480,7 +478,7 @@ static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman* connma } } -static bool TipMayBeStale(const Consensus::Params &consensusParams) +static bool TipMayBeStale(const Consensus::Params &consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { AssertLockHeld(cs_main); if (g_last_tip_update == 0) { @@ -489,14 +487,12 @@ static bool TipMayBeStale(const Consensus::Params &consensusParams) return g_last_tip_update < GetTime() - consensusParams.nPowTargetSpacing * 3 && mapBlocksInFlight.empty(); } -// Requires cs_main -static bool CanDirectFetch(const Consensus::Params &consensusParams) +static bool CanDirectFetch(const Consensus::Params &consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return chainActive.Tip()->GetBlockTime() > GetAdjustedTime() - consensusParams.nPowTargetSpacing * 20; } -// Requires cs_main -static bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex) +static bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { if (state->pindexBestKnownBlock && pindex == state->pindexBestKnownBlock->GetAncestor(pindex->nHeight)) return true; @@ -507,7 +503,8 @@ static bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex) /** Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has * at most count entries. */ -static void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<const CBlockIndex*>& vBlocks, NodeId& nodeStaller, const Consensus::Params& consensusParams) { +static void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<const CBlockIndex*>& vBlocks, NodeId& nodeStaller, const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main) +{ if (count == 0) return; @@ -797,10 +794,8 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) /** * Mark a misbehaving peer to be banned depending upon the value of `-banscore`. - * - * Requires cs_main. */ -void Misbehaving(NodeId pnode, int howmuch, const std::string& message) +void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { if (howmuch == 0) return; @@ -898,10 +893,10 @@ void PeerLogicValidation::BlockConnected(const std::shared_ptr<const CBlock>& pb // All of the following cache a recent block, and are protected by cs_most_recent_block static CCriticalSection cs_most_recent_block; -static std::shared_ptr<const CBlock> most_recent_block; -static std::shared_ptr<const CBlockHeaderAndShortTxIDs> most_recent_compact_block; -static uint256 most_recent_block_hash; -static bool fWitnessesPresentInMostRecentCompactBlock; +static std::shared_ptr<const CBlock> most_recent_block GUARDED_BY(cs_most_recent_block); +static std::shared_ptr<const CBlockHeaderAndShortTxIDs> most_recent_compact_block GUARDED_BY(cs_most_recent_block); +static uint256 most_recent_block_hash GUARDED_BY(cs_most_recent_block); +static bool fWitnessesPresentInMostRecentCompactBlock GUARDED_BY(cs_most_recent_block); /** * Maintain state about the best-seen block and fast-announce a compact block @@ -930,6 +925,8 @@ void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std: } connman->ForEachNode([this, &pcmpctblock, pindex, &msgMaker, fWitnessEnabled, &hashBlock](CNode* pnode) { + AssertLockHeld(cs_main); + // TODO: Avoid the repeated-serialization here if (pnode->nVersion < INVALID_CB_NO_BAN_VERSION || pnode->fDisconnect) return; @@ -1327,7 +1324,7 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm } } -static uint32_t GetFetchFlags(CNode* pfrom) { +static uint32_t GetFetchFlags(CNode* pfrom) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { uint32_t nFetchFlags = 0; if ((pfrom->GetLocalServices() & NODE_WITNESS) && State(pfrom->GetId())->fHaveWitness) { nFetchFlags |= MSG_WITNESS_FLAG; @@ -3160,6 +3157,8 @@ void PeerLogicValidation::EvictExtraOutboundPeers(int64_t time_in_seconds) LOCK(cs_main); connman->ForEachNode([&](CNode* pnode) { + AssertLockHeld(cs_main); + // Ignore non-outbound peers, or nodes marked for disconnect already if (!IsOutboundDisconnectionCandidate(pnode) || pnode->fDisconnect) return; CNodeState *state = State(pnode->GetId()); @@ -3173,6 +3172,8 @@ void PeerLogicValidation::EvictExtraOutboundPeers(int64_t time_in_seconds) }); if (worst_peer != -1) { bool disconnected = connman->ForNode(worst_peer, [&](CNode *pnode) { + AssertLockHeld(cs_main); + // Only disconnect a peer that has been connected to us for // some reasonable fraction of our check-frequency, to give // it time for new information to have arrived. diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index b420e9d8b3..e46bf2f765 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -301,12 +301,11 @@ bool CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd) return true; } -bool StartRPC() +void StartRPC() { LogPrint(BCLog::RPC, "Starting RPC\n"); fRPCRunning = true; g_rpcSignals.Started(); - return true; } void InterruptRPC() diff --git a/src/rpc/server.h b/src/rpc/server.h index 373914885c..a9dbfbd21f 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -198,7 +198,7 @@ extern CAmount AmountFromValue(const UniValue& value); extern std::string HelpExampleCli(const std::string& methodname, const std::string& args); extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args); -bool StartRPC(); +void StartRPC(); void InterruptRPC(); void StopRPC(); std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq); diff --git a/src/script/sign.cpp b/src/script/sign.cpp index c2ae4ff2ea..d10b1c4fd7 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -474,6 +474,7 @@ void PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt) for (unsigned int i = 0; i < outputs.size(); ++i) { outputs[i].Merge(psbt.outputs[i]); } + unknown.insert(psbt.unknown.begin(), psbt.unknown.end()); } bool PartiallySignedTransaction::IsSane() const diff --git a/src/script/sign.h b/src/script/sign.h index 250b637035..d12d0b5874 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -284,12 +284,16 @@ struct PSBTInput case PSBT_IN_NON_WITNESS_UTXO: if (non_witness_utxo) { throw std::ios_base::failure("Duplicate Key, input non-witness utxo already provided"); + } else if (key.size() != 1) { + throw std::ios_base::failure("Non-witness utxo key is more than one byte type"); } UnserializeFromVector(s, non_witness_utxo); break; case PSBT_IN_WITNESS_UTXO: if (!witness_utxo.IsNull()) { throw std::ios_base::failure("Duplicate Key, input witness utxo already provided"); + } else if (key.size() != 1) { + throw std::ios_base::failure("Witness utxo key is more than one byte type"); } UnserializeFromVector(s, witness_utxo); break; @@ -319,6 +323,8 @@ struct PSBTInput case PSBT_IN_SIGHASH: if (sighash_type > 0) { throw std::ios_base::failure("Duplicate Key, input sighash type already provided"); + } else if (key.size() != 1) { + throw std::ios_base::failure("Sighash type key is more than one byte type"); } UnserializeFromVector(s, sighash_type); break; @@ -326,6 +332,8 @@ struct PSBTInput { if (!redeem_script.empty()) { throw std::ios_base::failure("Duplicate Key, input redeemScript already provided"); + } else if (key.size() != 1) { + throw std::ios_base::failure("Input redeemScript key is more than one byte type"); } s >> redeem_script; break; @@ -334,6 +342,8 @@ struct PSBTInput { if (!witness_script.empty()) { throw std::ios_base::failure("Duplicate Key, input witnessScript already provided"); + } else if (key.size() != 1) { + throw std::ios_base::failure("Input witnessScript key is more than one byte type"); } s >> witness_script; break; @@ -347,6 +357,8 @@ struct PSBTInput { if (!final_script_sig.empty()) { throw std::ios_base::failure("Duplicate Key, input final scriptSig already provided"); + } else if (key.size() != 1) { + throw std::ios_base::failure("Final scriptSig key is more than one byte type"); } s >> final_script_sig; break; @@ -355,6 +367,8 @@ struct PSBTInput { if (!final_script_witness.IsNull()) { throw std::ios_base::failure("Duplicate Key, input final scriptWitness already provided"); + } else if (key.size() != 1) { + throw std::ios_base::failure("Final scriptWitness key is more than one byte type"); } UnserializeFromVector(s, final_script_witness.stack); break; @@ -442,6 +456,8 @@ struct PSBTOutput { if (!redeem_script.empty()) { throw std::ios_base::failure("Duplicate Key, output redeemScript already provided"); + } else if (key.size() != 1) { + throw std::ios_base::failure("Output redeemScript key is more than one byte type"); } s >> redeem_script; break; @@ -450,6 +466,8 @@ struct PSBTOutput { if (!witness_script.empty()) { throw std::ios_base::failure("Duplicate Key, output witnessScript already provided"); + } else if (key.size() != 1) { + throw std::ios_base::failure("Output witnessScript key is more than one byte type"); } s >> witness_script; break; @@ -564,6 +582,8 @@ struct PartiallySignedTransaction { if (tx) { throw std::ios_base::failure("Duplicate Key, unsigned tx already provided"); + } else if (key.size() != 1) { + throw std::ios_base::failure("Global unsigned tx key is more than one byte type"); } CMutableTransaction mtx; UnserializeFromVector(s, mtx); diff --git a/src/sync.h b/src/sync.h index 3c451af376..882ad5dc4c 100644 --- a/src/sync.h +++ b/src/sync.h @@ -74,13 +74,13 @@ public: void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false); void LeaveCritical(); std::string LocksHeld(); -void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs); +void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) ASSERT_EXCLUSIVE_LOCK(cs); void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs); void DeleteLock(void* cs); #else void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {} void static inline LeaveCritical() {} -void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {} +void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) ASSERT_EXCLUSIVE_LOCK(cs) {} void static inline AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {} void static inline DeleteLock(void* cs) {} #endif diff --git a/src/threadsafety.h b/src/threadsafety.h index 61e63dbc7a..d847269dff 100644 --- a/src/threadsafety.h +++ b/src/threadsafety.h @@ -31,6 +31,7 @@ #define EXCLUSIVE_LOCKS_REQUIRED(...) __attribute__((exclusive_locks_required(__VA_ARGS__))) #define SHARED_LOCKS_REQUIRED(...) __attribute__((shared_locks_required(__VA_ARGS__))) #define NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis)) +#define ASSERT_EXCLUSIVE_LOCK(...) __attribute((assert_exclusive_lock(__VA_ARGS__))) #else #define LOCKABLE #define SCOPED_LOCKABLE @@ -50,6 +51,7 @@ #define EXCLUSIVE_LOCKS_REQUIRED(...) #define SHARED_LOCKS_REQUIRED(...) #define NO_THREAD_SAFETY_ANALYSIS +#define ASSERT_EXCLUSIVE_LOCK(...) #endif // __GNUC__ #endif // BITCOIN_THREADSAFETY_H diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 1f42ab8fa8..fbc193c2cf 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -91,7 +91,7 @@ public: /** * Disconnect from Tor control port. */ - bool Disconnect(); + void Disconnect(); /** Send a command, register a handler for the reply. * A trailing CRLF is automatically added. @@ -223,12 +223,11 @@ bool TorControlConnection::Connect(const std::string &target, const ConnectionCB return true; } -bool TorControlConnection::Disconnect() +void TorControlConnection::Disconnect() { if (b_conn) bufferevent_free(b_conn); b_conn = nullptr; - return true; } bool TorControlConnection::Command(const std::string &cmd, const ReplyHandlerCB& reply_handler) diff --git a/src/txdb.cpp b/src/txdb.cpp index 1fc7919442..cbea550739 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -160,9 +160,8 @@ bool CBlockTreeDB::WriteReindexing(bool fReindexing) { return Erase(DB_REINDEX_FLAG); } -bool CBlockTreeDB::ReadReindexing(bool &fReindexing) { +void CBlockTreeDB::ReadReindexing(bool &fReindexing) { fReindexing = Exists(DB_REINDEX_FLAG); - return true; } bool CBlockTreeDB::ReadLastBlockFile(int &nFile) { diff --git a/src/txdb.h b/src/txdb.h index 100adb428d..84011097ce 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -92,7 +92,7 @@ public: bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info); bool ReadLastBlockFile(int &nFile); bool WriteReindexing(bool fReindexing); - bool ReadReindexing(bool &fReindexing); + void ReadReindexing(bool &fReindexing); bool WriteFlag(const std::string &name, bool fValue); bool ReadFlag(const std::string &name, bool &fValue); bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 2108e6ba2d..9d705e3d23 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -357,7 +357,7 @@ void CTxMemPool::AddTransactionsUpdated(unsigned int n) nTransactionsUpdated += n; } -bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate) +void CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate) { NotifyEntryAdded(entry.GetSharedTx()); // Add to memory pool without checking anything. @@ -412,8 +412,6 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, vTxHashes.emplace_back(tx.GetWitnessHash(), newit); newit->vTxHashesIdx = vTxHashes.size() - 1; - - return true; } void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason) @@ -933,7 +931,7 @@ int CTxMemPool::Expire(int64_t time) { return stage.size(); } -bool CTxMemPool::addUnchecked(const uint256&hash, const CTxMemPoolEntry &entry, bool validFeeEstimate) +void CTxMemPool::addUnchecked(const uint256&hash, const CTxMemPoolEntry &entry, bool validFeeEstimate) { LOCK(cs); setEntries setAncestors; diff --git a/src/txmempool.h b/src/txmempool.h index f3b8a68a9d..bb676cf05d 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -539,8 +539,8 @@ public: // Note that addUnchecked is ONLY called from ATMP outside of tests // and any other callers may break wallet's in-mempool tracking (due to // lack of CValidationInterface::TransactionAddedToMempool callbacks). - bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool validFeeEstimate = true); - bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate = true); + void addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool validFeeEstimate = true); + void addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate = true); void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN); void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags); diff --git a/src/validation.cpp b/src/validation.cpp index f1b63b5b44..702a8d7e05 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -178,7 +178,7 @@ public: // Manual block validity manipulation: bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main); bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); - bool ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); bool ReplayBlocks(const CChainParams& params, CCoinsView* view); bool RewindBlockIndex(const CChainParams& params); @@ -2882,7 +2882,7 @@ bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, C return g_chainstate.InvalidateBlock(state, chainparams, pindex); } -bool CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) { +void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) { AssertLockHeld(cs_main); int nHeight = pindex->nHeight; @@ -2914,9 +2914,9 @@ bool CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) { } pindex = pindex->pprev; } - return true; } -bool ResetBlockFailureFlags(CBlockIndex *pindex) { + +void ResetBlockFailureFlags(CBlockIndex *pindex) { return g_chainstate.ResetBlockFailureFlags(pindex); } diff --git a/src/validation.h b/src/validation.h index 1aff10f025..ce46a5a782 100644 --- a/src/validation.h +++ b/src/validation.h @@ -449,7 +449,7 @@ bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIn bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** Remove invalidity status from a block and its descendants. */ -bool ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); +void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** The currently-connected chain of blocks (protected by cs_main). */ extern CChain& chainActive; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 4e1f6548df..3cb4050f01 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -86,6 +86,17 @@ static bool GetWalletAddressesForKey(CWallet * const pwallet, const CKeyID &keyi return fLabelFound; } +static const int64_t TIMESTAMP_MIN = 0; + +static void RescanWallet(CWallet& wallet, const WalletRescanReserver& reserver, int64_t time_begin = TIMESTAMP_MIN, bool update = true) +{ + int64_t scanned_time = wallet.RescanFromTime(time_begin, reserver, update); + if (wallet.IsAbortingRescan()) { + throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); + } else if (scanned_time > time_begin) { + throw JSONRPCError(RPC_WALLET_ERROR, "Rescan was unable to fully rescan the blockchain. Some transactions may be missing."); + } +} UniValue importprivkey(const JSONRPCRequest& request) { @@ -172,13 +183,7 @@ UniValue importprivkey(const JSONRPCRequest& request) } } if (fRescan) { - int64_t scanned_time = pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); - if (pwallet->IsAbortingRescan()) { - throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); - } - if (scanned_time > TIMESTAMP_MIN) { - throw JSONRPCError(RPC_WALLET_ERROR, "Rescan was unable to fully rescan the blockchain. Some transactions may be missing."); - } + RescanWallet(*pwallet, reserver); } return NullUniValue; @@ -318,13 +323,7 @@ UniValue importaddress(const JSONRPCRequest& request) } if (fRescan) { - int64_t scanned_time = pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); - if (pwallet->IsAbortingRescan()) { - throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); - } - if (scanned_time > TIMESTAMP_MIN) { - throw JSONRPCError(RPC_WALLET_ERROR, "Rescan was unable to fully rescan the blockchain. Some transactions may be missing."); - } + RescanWallet(*pwallet, reserver); pwallet->ReacceptWalletTransactions(); } @@ -496,13 +495,7 @@ UniValue importpubkey(const JSONRPCRequest& request) } if (fRescan) { - int64_t scanned_time = pwallet->RescanFromTime(TIMESTAMP_MIN, reserver, true /* update */); - if (pwallet->IsAbortingRescan()) { - throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); - } - if (scanned_time > TIMESTAMP_MIN) { - throw JSONRPCError(RPC_WALLET_ERROR, "Rescan was unable to fully rescan the blockchain. Some transactions may be missing."); - } + RescanWallet(*pwallet, reserver); pwallet->ReacceptWalletTransactions(); } @@ -630,13 +623,7 @@ UniValue importwallet(const JSONRPCRequest& request) pwallet->UpdateTimeFirstKey(nTimeBegin); } uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI - int64_t scanned_time = pwallet->RescanFromTime(nTimeBegin, reserver, false /* update */); - if (pwallet->IsAbortingRescan()) { - throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user."); - } - if (scanned_time > nTimeBegin) { - throw JSONRPCError(RPC_WALLET_ERROR, "Rescan was unable to fully rescan the blockchain. Some transactions may be missing."); - } + RescanWallet(*pwallet, reserver, nTimeBegin, false /* update */); pwallet->MarkDirty(); if (!fGood) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3ec6aefaec..4918100b30 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -304,20 +304,18 @@ bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, } } -bool CWallet::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &meta) +void CWallet::LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &meta) { AssertLockHeld(cs_wallet); // mapKeyMetadata UpdateTimeFirstKey(meta.nCreateTime); mapKeyMetadata[keyID] = meta; - return true; } -bool CWallet::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &meta) +void CWallet::LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &meta) { AssertLockHeld(cs_wallet); // m_script_metadata UpdateTimeFirstKey(meta.nCreateTime); m_script_metadata[script_id] = meta; - return true; } bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) @@ -470,11 +468,11 @@ void CWallet::ChainStateFlushed(const CBlockLocator& loc) batch.WriteBestBlock(loc); } -bool CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in, bool fExplicit) +void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in, bool fExplicit) { LOCK(cs_wallet); // nWalletVersion if (nWalletVersion >= nVersion) - return true; + return; // when doing an explicit upgrade, if we pass the max version permitted, upgrade all the way if (fExplicit && nVersion > nWalletMaxVersion) @@ -492,8 +490,6 @@ bool CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in, if (!batch_in) delete batch; } - - return true; } bool CWallet::SetMaxVersion(int nVersion) @@ -703,9 +699,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) // if we are using HD, replace the HD seed with a new one if (IsHDEnabled()) { - if (!SetHDSeed(GenerateNewSeed())) { - return false; - } + SetHDSeed(GenerateNewSeed()); } NewKeyPool(); @@ -1006,7 +1000,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose) return true; } -bool CWallet::LoadToWallet(const CWalletTx& wtxIn) +void CWallet::LoadToWallet(const CWalletTx& wtxIn) { uint256 hash = wtxIn.GetHash(); const auto& ins = mapWallet.emplace(hash, wtxIn); @@ -1025,8 +1019,6 @@ bool CWallet::LoadToWallet(const CWalletTx& wtxIn) } } } - - return true; } bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate) @@ -1478,7 +1470,7 @@ CPubKey CWallet::DeriveNewSeed(const CKey& key) return seed; } -bool CWallet::SetHDSeed(const CPubKey& seed) +void CWallet::SetHDSeed(const CPubKey& seed) { LOCK(cs_wallet); // store the keyid (hash160) together with @@ -1488,18 +1480,15 @@ bool CWallet::SetHDSeed(const CPubKey& seed) newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE; newHdChain.seed_id = seed.GetID(); SetHDChain(newHdChain, false); - - return true; } -bool CWallet::SetHDChain(const CHDChain& chain, bool memonly) +void CWallet::SetHDChain(const CHDChain& chain, bool memonly) { LOCK(cs_wallet); if (!memonly && !WalletBatch(*database).WriteHDChain(chain)) throw std::runtime_error(std::string(__func__) + ": writing chain failed"); hdChain = chain; - return true; } bool CWallet::IsHDEnabled() const @@ -3899,10 +3888,9 @@ bool CWallet::EraseDestData(const CTxDestination &dest, const std::string &key) return WalletBatch(*database).EraseDestData(EncodeDestination(dest), key); } -bool CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value) +void CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value) { mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); - return true; } bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const @@ -4091,9 +4079,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(const std::string& name, // generate a new master key CPubKey masterPubKey = walletInstance->GenerateNewSeed(); - if (!walletInstance->SetHDSeed(masterPubKey)) { - throw std::runtime_error(std::string(__func__) + ": Storing master key failed"); - } + walletInstance->SetHDSeed(masterPubKey); hd_upgrade = true; } // Upgrade to HD chain split if necessary @@ -4109,7 +4095,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(const std::string& name, // Regenerate the keypool if upgraded to HD if (hd_upgrade) { if (!walletInstance->TopUpKeyPool()) { - InitError(_("Unable to generate keys") += "\n"); + InitError(_("Unable to generate keys")); return nullptr; } } @@ -4130,14 +4116,12 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(const std::string& name, } else { // generate a new seed CPubKey seed = walletInstance->GenerateNewSeed(); - if (!walletInstance->SetHDSeed(seed)) { - throw std::runtime_error(std::string(__func__) + ": Storing HD seed failed"); - } + walletInstance->SetHDSeed(seed); } // Top up the keypool if (!walletInstance->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && !walletInstance->TopUpKeyPool()) { - InitError(_("Unable to generate initial keys") += "\n"); + InitError(_("Unable to generate initial keys")); return nullptr; } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 122649d575..9f9501cf72 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -64,8 +64,6 @@ static const bool DEFAULT_WALLET_RBF = false; static const bool DEFAULT_WALLETBROADCAST = true; static const bool DEFAULT_DISABLE_WALLET = false; -static const int64_t TIMESTAMP_MIN = 0; - class CBlockIndex; class CCoinControl; class COutput; @@ -887,8 +885,8 @@ public: //! Adds a key to the store, without saving it to disk (used by LoadWallet) bool LoadKey(const CKey& key, const CPubKey &pubkey) { return CCryptoKeyStore::AddKeyPubKey(key, pubkey); } //! Load metadata (used by LoadWallet) - bool LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); - bool LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + void LoadKeyMetadata(const CKeyID& keyID, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + void LoadScriptMetadata(const CScriptID& script_id, const CKeyMetadata &metadata) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool LoadMinVersion(int nVersion) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; } void UpdateTimeFirstKey(int64_t nCreateTime) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); @@ -905,7 +903,7 @@ public: //! Erases a destination data tuple in the store and on disk bool EraseDestData(const CTxDestination &dest, const std::string &key); //! Adds a destination data tuple to the store, without saving it to disk - bool LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value); + void LoadDestData(const CTxDestination &dest, const std::string &key, const std::string &value); //! Look up a destination data tuple in the store, return true if found false otherwise bool GetDestData(const CTxDestination &dest, const std::string &key, std::string *value) const; //! Get all destination values matching a prefix. @@ -938,7 +936,7 @@ public: void MarkDirty(); bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true); - bool LoadToWallet(const CWalletTx& wtxIn); + void LoadToWallet(const CWalletTx& wtxIn); void TransactionAddedToMempool(const CTransactionRef& tx) override; void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) override; void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) override; @@ -1077,7 +1075,7 @@ public: } //! signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower - bool SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr, bool fExplicit = false); + void SetMinVersion(enum WalletFeature, WalletBatch* batch_in = nullptr, bool fExplicit = false); //! change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format) bool SetMaxVersion(int nVersion); @@ -1148,7 +1146,7 @@ public: bool BackupWallet(const std::string& strDest); /* Set the HD chain model (chain child index counters) */ - bool SetHDChain(const CHDChain& chain, bool memonly); + void SetHDChain(const CHDChain& chain, bool memonly); const CHDChain& GetHDChain() const { return hdChain; } /* Returns true if HD is enabled */ @@ -1164,7 +1162,7 @@ public: Sets the seed's version based on the current wallet version (so the caller must ensure the current wallet version is correct before calling this function). */ - bool SetHDSeed(const CPubKey& key); + void SetHDSeed(const CPubKey& key); /** * Blocks until the wallet state is up-to-date to /at least/ the current diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 67fcaa725b..43e4747317 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -495,21 +495,13 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, ssKey >> strAddress; ssKey >> strKey; ssValue >> strValue; - if (!pwallet->LoadDestData(DecodeDestination(strAddress), strKey, strValue)) - { - strErr = "Error reading wallet database: LoadDestData failed"; - return false; - } + pwallet->LoadDestData(DecodeDestination(strAddress), strKey, strValue); } else if (strType == "hdchain") { CHDChain chain; ssValue >> chain; - if (!pwallet->SetHDChain(chain, true)) - { - strErr = "Error reading wallet database: SetHDChain failed"; - return false; - } + pwallet->SetHDChain(chain, true); } else if (strType == "flags") { uint64_t flags; ssValue >> flags; |