diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/net_processing.cpp | 2 | ||||
-rw-r--r-- | src/netbase.h | 3 | ||||
-rw-r--r-- | src/node/coinstats.cpp | 3 | ||||
-rw-r--r-- | src/policy/feerate.h | 1 | ||||
-rw-r--r-- | src/rpc/net.cpp | 22 | ||||
-rw-r--r-- | src/script/interpreter.h | 28 | ||||
-rw-r--r-- | src/script/sign.cpp | 8 | ||||
-rw-r--r-- | src/test/fuzz/util.cpp | 8 | ||||
-rw-r--r-- | src/test/fuzz/util.h | 8 | ||||
-rw-r--r-- | src/test/validation_chainstatemanager_tests.cpp | 5 | ||||
-rw-r--r-- | src/util/sock.h | 2 | ||||
-rw-r--r-- | src/validation.cpp | 34 | ||||
-rw-r--r-- | src/validation.h | 2 | ||||
-rw-r--r-- | src/wallet/interfaces.cpp | 2 | ||||
-rw-r--r-- | src/wallet/rpcwallet.cpp | 2 | ||||
-rw-r--r-- | src/wallet/scriptpubkeyman.cpp | 2 | ||||
-rw-r--r-- | src/wallet/sqlite.cpp | 81 |
17 files changed, 109 insertions, 104 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index d98d47fd2a..84c26c3df1 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2062,7 +2062,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer, /** * Reconsider orphan transactions after a parent has been accepted to the mempool. * - * @param[in/out] orphan_work_set The set of orphan transactions to reconsider. Generally only one + * @param[in,out] orphan_work_set The set of orphan transactions to reconsider. Generally only one * orphan will be reconsidered on each call of this function. This set * may be added to if accepting an orphan causes its children to be * reconsidered. diff --git a/src/netbase.h b/src/netbase.h index 1f35c29dcb..6a87c338a0 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -172,7 +172,6 @@ CService LookupNumeric(const std::string& name, uint16_t portDefault = 0, DNSLoo * @param strSubnet A string representation of a subnet of the form `network * address [ "/", ( CIDR-style suffix | netmask ) ]`(e.g. * `2001:db8::/32`, `192.0.2.0/255.255.255.0`, or `8.8.8.8`). - * @param ret The resulting internal representation of a subnet. * * @returns Whether the operation succeeded or not. */ @@ -235,7 +234,7 @@ void InterruptSocks5(bool interrupt); * @param port The destination port. * @param auth The credentials with which to authenticate with the specified * SOCKS5 proxy. - * @param sock The SOCKS5 proxy socket. + * @param socket The SOCKS5 proxy socket. * * @returns Whether or not the operation succeeded. * diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp index 268580c6e6..f8f0fff43f 100644 --- a/src/node/coinstats.cpp +++ b/src/node/coinstats.cpp @@ -94,7 +94,8 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& { LOCK(cs_main); assert(std::addressof(g_chainman.m_blockman) == std::addressof(blockman)); - stats.nHeight = blockman.LookupBlockIndex(stats.hashBlock)->nHeight; + const CBlockIndex* block = blockman.LookupBlockIndex(stats.hashBlock); + stats.nHeight = Assert(block)->nHeight; } PrepareHash(hash_obj, stats); diff --git a/src/policy/feerate.h b/src/policy/feerate.h index 86ae507957..0e4f9914b8 100644 --- a/src/policy/feerate.h +++ b/src/policy/feerate.h @@ -47,7 +47,6 @@ public: * * @param[in] nFeePaid CAmount fee rate to construct with * @param[in] nBytes size_t bytes (units) to construct with - * @returns fee rate */ CFeeRate(const CAmount& nFeePaid, size_t nBytes); /** diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 96533a50c8..9ace33d529 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -835,7 +835,7 @@ static RPCHelpMan setnetworkactive() static RPCHelpMan getnodeaddresses() { return RPCHelpMan{"getnodeaddresses", - "\nReturn known addresses which can potentially be used to find new nodes in the network\n", + "\nReturn known addresses, which can potentially be used to find new nodes in the network.\n", { {"count", RPCArg::Type::NUM, /* default */ "1", "The maximum number of addresses to return. Specify 0 to return all known addresses."}, }, @@ -844,10 +844,11 @@ static RPCHelpMan getnodeaddresses() { {RPCResult::Type::OBJ, "", "", { - {RPCResult::Type::NUM_TIME, "time", "The " + UNIX_EPOCH_TIME + " of when the node was last seen"}, - {RPCResult::Type::NUM, "services", "The services offered"}, + {RPCResult::Type::NUM_TIME, "time", "The " + UNIX_EPOCH_TIME + " when the node was last seen"}, + {RPCResult::Type::NUM, "services", "The services offered by the node"}, {RPCResult::Type::STR, "address", "The address of the node"}, - {RPCResult::Type::NUM, "port", "The port of the node"}, + {RPCResult::Type::NUM, "port", "The port number of the node"}, + {RPCResult::Type::STR, "network", "The network (" + Join(GetNetworkNames(), ", ") + ") the node connected through"}, }}, } }, @@ -862,15 +863,11 @@ static RPCHelpMan getnodeaddresses() throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); } - int count = 1; - if (!request.params[0].isNull()) { - count = request.params[0].get_int(); - if (count < 0) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range"); - } - } + const int count{request.params[0].isNull() ? 1 : request.params[0].get_int()}; + if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range"); + // returns a shuffled list of CAddress - std::vector<CAddress> vAddr = node.connman->GetAddresses(count, /* max_pct */ 0); + const std::vector<CAddress> vAddr{node.connman->GetAddresses(count, /* max_pct */ 0)}; UniValue ret(UniValue::VARR); for (const CAddress& addr : vAddr) { @@ -879,6 +876,7 @@ static RPCHelpMan getnodeaddresses() obj.pushKV("services", (uint64_t)addr.nServices); obj.pushKV("address", addr.ToStringIP()); obj.pushKV("port", addr.GetPort()); + obj.pushKV("network", GetNetworkName(addr.GetNetClass())); ret.push_back(obj); } return ret; diff --git a/src/script/interpreter.h b/src/script/interpreter.h index b4c163c841..effbc055d4 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -272,6 +272,34 @@ public: using TransactionSignatureChecker = GenericTransactionSignatureChecker<CTransaction>; using MutableTransactionSignatureChecker = GenericTransactionSignatureChecker<CMutableTransaction>; +class DeferringSignatureChecker : public BaseSignatureChecker +{ +protected: + BaseSignatureChecker& m_checker; + +public: + DeferringSignatureChecker(BaseSignatureChecker& checker) : m_checker(checker) {} + + bool CheckECDSASignature(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override + { + return m_checker.CheckECDSASignature(scriptSig, vchPubKey, scriptCode, sigversion); + } + + bool CheckSchnorrSignature(Span<const unsigned char> sig, Span<const unsigned char> pubkey, SigVersion sigversion, const ScriptExecutionData& execdata, ScriptError* serror = nullptr) const override + { + return m_checker.CheckSchnorrSignature(sig, pubkey, sigversion, execdata, serror); + } + + bool CheckLockTime(const CScriptNum& nLockTime) const override + { + return m_checker.CheckLockTime(nLockTime); + } + bool CheckSequence(const CScriptNum& nSequence) const override + { + return m_checker.CheckSequence(nSequence); + } +}; + bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* error = nullptr); bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* error = nullptr); bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CScriptWitness* witness, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror = nullptr); diff --git a/src/script/sign.cpp b/src/script/sign.cpp index dba5ce621a..3c8f6d22ea 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -250,17 +250,17 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato } namespace { -class SignatureExtractorChecker final : public BaseSignatureChecker +class SignatureExtractorChecker final : public DeferringSignatureChecker { private: SignatureData& sigdata; - BaseSignatureChecker& checker; public: - SignatureExtractorChecker(SignatureData& sigdata, BaseSignatureChecker& checker) : sigdata(sigdata), checker(checker) {} + SignatureExtractorChecker(SignatureData& sigdata, BaseSignatureChecker& checker) : DeferringSignatureChecker(checker), sigdata(sigdata) {} + bool CheckECDSASignature(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override { - if (checker.CheckECDSASignature(scriptSig, vchPubKey, scriptCode, sigversion)) { + if (m_checker.CheckECDSASignature(scriptSig, vchPubKey, scriptCode, sigversion)) { CPubKey pubkey(vchPubKey); sigdata.signatures.emplace(pubkey.GetID(), SigPair(pubkey, scriptSig)); return true; diff --git a/src/test/fuzz/util.cpp b/src/test/fuzz/util.cpp index d786ac1db1..cf5244e314 100644 --- a/src/test/fuzz/util.cpp +++ b/src/test/fuzz/util.cpp @@ -7,6 +7,14 @@ #include <util/rbf.h> #include <version.h> +bool FuzzedSock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred ) const +{ + if (!m_fuzzed_data_provider.ConsumeBool()) { + return false; + } + if (occurred) *occurred = 0; + return true; +} void FillNode(FuzzedDataProvider& fuzzed_data_provider, CNode& node, bool init_version) noexcept { diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index 50d3ac66e5..adcdd71748 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -738,12 +738,10 @@ public: return 0; } - bool Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred = nullptr) const override - { - return m_fuzzed_data_provider.ConsumeBool(); - } + bool Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred = nullptr) const override; - bool IsConnected(std::string& errmsg) const override { + bool IsConnected(std::string& errmsg) const override + { if (m_fuzzed_data_provider.ConsumeBool()) { return true; } diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index 94d4277019..35e087c899 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -259,6 +259,11 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Determi // Coins count is smaller than coins in file metadata.m_coins_count -= 1; })); + BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot( + m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) { + // Wrong hash + metadata.m_base_blockhash = uint256::ONE; + })); BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(m_node, m_path_root)); diff --git a/src/util/sock.h b/src/util/sock.h index c4ad0cbc43..a4df7cd21b 100644 --- a/src/util/sock.h +++ b/src/util/sock.h @@ -161,7 +161,7 @@ public: /** * Check if still connected. - * @param[out] err The error string, if the socket has been disconnected. + * @param[out] errmsg The error string, if the socket has been disconnected. * @return true if connected */ virtual bool IsConnected(std::string& errmsg) const; diff --git a/src/validation.cpp b/src/validation.cpp index 19363c0efb..619d3cea98 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5423,6 +5423,15 @@ bool ChainstateManager::PopulateAndValidateSnapshot( assert(coins_cache.GetBestBlock() == base_blockhash); + CBlockIndex* snapshot_start_block = WITH_LOCK(::cs_main, return m_blockman.LookupBlockIndex(base_blockhash)); + + if (!snapshot_start_block) { + // Needed for GetUTXOStats to determine the height + LogPrintf("[snapshot] Did not find snapshot start blockheader %s\n", + base_blockhash.ToString()); + return false; + } + CCoinsStats stats; auto breakpoint_fnc = [] { /* TODO insert breakpoint here? */ }; @@ -5435,31 +5444,6 @@ bool ChainstateManager::PopulateAndValidateSnapshot( return false; } - // Ensure that the base blockhash appears in the known chain of valid headers. We're willing to - // wait a bit here because the snapshot may have been loaded on startup, before we've - // received headers from the network. - - int max_secs_to_wait_for_headers = 60 * 10; - CBlockIndex* snapshot_start_block = nullptr; - - while (max_secs_to_wait_for_headers > 0) { - snapshot_start_block = WITH_LOCK(::cs_main, - return m_blockman.LookupBlockIndex(base_blockhash)); - --max_secs_to_wait_for_headers; - - if (!snapshot_start_block) { - std::this_thread::sleep_for(std::chrono::seconds(1)); - } else { - break; - } - } - - if (snapshot_start_block == nullptr) { - LogPrintf("[snapshot] timed out waiting for snapshot start blockheader %s\n", - base_blockhash.ToString()); - return false; - } - // Assert that the deserialized chainstate contents match the expected assumeutxo value. int base_height = snapshot_start_block->nHeight; diff --git a/src/validation.h b/src/validation.h index 21e63947fa..9f2c244482 100644 --- a/src/validation.h +++ b/src/validation.h @@ -1029,7 +1029,7 @@ inline bool IsBlockPruned(const CBlockIndex* pblockindex) /** * Return the expected assumeutxo value for a given height, if one exists. * - * @param height[in] Get the assumeutxo value for this height. + * @param[in] height Get the assumeutxo value for this height. * * @returns empty if no assumeutxo configuration exists for the given height. */ diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index da5b84ce83..0a284dd43e 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -522,7 +522,7 @@ public: #ifdef ENABLE_EXTERNAL_SIGNER for (const CRPCCommand& command : GetSignerRPCCommands()) { m_rpc_commands.emplace_back(command.category, command.name, [this, &command](const JSONRPCRequest& request, UniValue& result, bool last_handler) { - return command.actor({request, m_context}, result, last_handler); + return command.actor({request, &m_context}, result, last_handler); }, command.argNames, command.unique_id); m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back())); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 45f292055e..672ee3e7a4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1281,7 +1281,7 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest) /** * List transactions based on the given criteria. * - * @param pwallet The wallet. + * @param wallet The wallet. * @param wtx The wallet transaction. * @param nMinDepth The minimum confirmation depth. * @param fLong Whether to include the JSON version of the transaction. diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 54319ca662..9a75002b6c 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -84,7 +84,7 @@ bool HaveKeys(const std::vector<valtype>& pubkeys, const LegacyScriptPubKeyMan& //! Recursively solve script and return spendable/watchonly/invalid status. //! //! @param keystore legacy key and script store -//! @param script script to solve +//! @param scriptPubKey script to solve //! @param sigversion script type (top-level / redeemscript / witnessscript) //! @param recurse_scripthash whether to recurse into nested p2sh and p2wsh //! scripts or simply treat any script that has been diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp index 975974cb6a..91891c5fc2 100644 --- a/src/wallet/sqlite.cpp +++ b/src/wallet/sqlite.cpp @@ -16,6 +16,9 @@ #include <sqlite3.h> #include <stdint.h> +#include <utility> +#include <vector> + static constexpr int32_t WALLET_SCHEMA_VERSION = 0; static Mutex g_sqlite_mutex; @@ -69,30 +72,21 @@ SQLiteDatabase::SQLiteDatabase(const fs::path& dir_path, const fs::path& file_pa void SQLiteBatch::SetupSQLStatements() { - int res; - if (!m_read_stmt) { - if ((res = sqlite3_prepare_v2(m_database.m_db, "SELECT value FROM main WHERE key = ?", -1, &m_read_stmt, nullptr)) != SQLITE_OK) { - throw std::runtime_error(strprintf("SQLiteDatabase: Failed to setup SQL statements: %s\n", sqlite3_errstr(res))); - } - } - if (!m_insert_stmt) { - if ((res = sqlite3_prepare_v2(m_database.m_db, "INSERT INTO main VALUES(?, ?)", -1, &m_insert_stmt, nullptr)) != SQLITE_OK) { - throw std::runtime_error(strprintf("SQLiteDatabase: Failed to setup SQL statements: %s\n", sqlite3_errstr(res))); - } - } - if (!m_overwrite_stmt) { - if ((res = sqlite3_prepare_v2(m_database.m_db, "INSERT or REPLACE into main values(?, ?)", -1, &m_overwrite_stmt, nullptr)) != SQLITE_OK) { - throw std::runtime_error(strprintf("SQLiteDatabase: Failed to setup SQL statements: %s\n", sqlite3_errstr(res))); - } - } - if (!m_delete_stmt) { - if ((res = sqlite3_prepare_v2(m_database.m_db, "DELETE FROM main WHERE key = ?", -1, &m_delete_stmt, nullptr)) != SQLITE_OK) { - throw std::runtime_error(strprintf("SQLiteDatabase: Failed to setup SQL statements: %s\n", sqlite3_errstr(res))); - } - } - if (!m_cursor_stmt) { - if ((res = sqlite3_prepare_v2(m_database.m_db, "SELECT key, value FROM main", -1, &m_cursor_stmt, nullptr)) != SQLITE_OK) { - throw std::runtime_error(strprintf("SQLiteDatabase: Failed to setup SQL statements : %s\n", sqlite3_errstr(res))); + const std::vector<std::pair<sqlite3_stmt**, const char*>> statements{ + {&m_read_stmt, "SELECT value FROM main WHERE key = ?"}, + {&m_insert_stmt, "INSERT INTO main VALUES(?, ?)"}, + {&m_overwrite_stmt, "INSERT or REPLACE into main values(?, ?)"}, + {&m_delete_stmt, "DELETE FROM main WHERE key = ?"}, + {&m_cursor_stmt, "SELECT key, value FROM main"}, + }; + + for (const auto& [stmt_prepared, stmt_text] : statements) { + if (*stmt_prepared == nullptr) { + int res = sqlite3_prepare_v2(m_database.m_db, stmt_text, -1, stmt_prepared, nullptr); + if (res != SQLITE_OK) { + throw std::runtime_error(strprintf( + "SQLiteDatabase: Failed to setup SQL statements: %s\n", sqlite3_errstr(res))); + } } } } @@ -353,31 +347,22 @@ void SQLiteBatch::Close() } // Free all of the prepared statements - int ret = sqlite3_finalize(m_read_stmt); - if (ret != SQLITE_OK) { - LogPrintf("SQLiteBatch: Batch closed but could not finalize read statement: %s\n", sqlite3_errstr(ret)); - } - ret = sqlite3_finalize(m_insert_stmt); - if (ret != SQLITE_OK) { - LogPrintf("SQLiteBatch: Batch closed but could not finalize insert statement: %s\n", sqlite3_errstr(ret)); - } - ret = sqlite3_finalize(m_overwrite_stmt); - if (ret != SQLITE_OK) { - LogPrintf("SQLiteBatch: Batch closed but could not finalize overwrite statement: %s\n", sqlite3_errstr(ret)); - } - ret = sqlite3_finalize(m_delete_stmt); - if (ret != SQLITE_OK) { - LogPrintf("SQLiteBatch: Batch closed but could not finalize delete statement: %s\n", sqlite3_errstr(ret)); - } - ret = sqlite3_finalize(m_cursor_stmt); - if (ret != SQLITE_OK) { - LogPrintf("SQLiteBatch: Batch closed but could not finalize cursor statement: %s\n", sqlite3_errstr(ret)); + const std::vector<std::pair<sqlite3_stmt**, const char*>> statements{ + {&m_read_stmt, "read"}, + {&m_insert_stmt, "insert"}, + {&m_overwrite_stmt, "overwrite"}, + {&m_delete_stmt, "delete"}, + {&m_cursor_stmt, "cursor"}, + }; + + for (const auto& [stmt_prepared, stmt_description] : statements) { + int res = sqlite3_finalize(*stmt_prepared); + if (res != SQLITE_OK) { + LogPrintf("SQLiteBatch: Batch closed but could not finalize %s statement: %s\n", + stmt_description, sqlite3_errstr(res)); + } + *stmt_prepared = nullptr; } - m_read_stmt = nullptr; - m_insert_stmt = nullptr; - m_overwrite_stmt = nullptr; - m_delete_stmt = nullptr; - m_cursor_stmt = nullptr; } bool SQLiteBatch::ReadKey(CDataStream&& key, CDataStream& value) |