diff --git a/src/Makefile.am b/src/Makefile.am index 26b54e2a1d..9be2d74f74 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -240,7 +240,6 @@ BITCOIN_CORE_H = \ node/transaction.h \ node/utxo_snapshot.h \ noui.h \ - optional.h \ policy/feerate.h \ policy/fees.h \ policy/policy.h \ diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index ea0823e0b0..704e0a007a 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index a82080495c..3a739cc943 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -25,6 +25,7 @@ #include #include +#include #include const std::function G_TRANSLATION_FUN = nullptr; diff --git a/src/evo/cbtx.cpp b/src/evo/cbtx.cpp index 444a81cbf8..76519f4b73 100644 --- a/src/evo/cbtx.cpp +++ b/src/evo/cbtx.cpp @@ -229,7 +229,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre int64_t nTime1 = GetTimeMicros(); auto retVal = CachedGetQcHashesQcIndexedHashes(pindexPrev, quorum_block_processor); - if (retVal == std::nullopt) { + if (!retVal) { return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "commitment-not-found"); } // The returned quorums are in reversed order, so the most recent one is at index 0 diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index 37de6ab1df..ac07fc1e8e 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -139,23 +139,23 @@ class ChainImpl : public Chain { public: explicit ChainImpl(NodeContext& node) : m_node(node) {} - Optional getHeight() override + std::optional getHeight() override { LOCK(cs_main); int height = ::ChainActive().Height(); if (height >= 0) { return height; } - return nullopt; + return std::nullopt; } - Optional getBlockHeight(const uint256& hash) override + std::optional getBlockHeight(const uint256& hash) override { LOCK(cs_main); CBlockIndex* block = LookupBlockIndex(hash); if (block && ::ChainActive().Contains(block)) { return block->nHeight; } - return nullopt; + return std::nullopt; } uint256 getBlockHash(int height) override { @@ -184,7 +184,7 @@ public: CBlockIndex* block = ::ChainActive()[height]; return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0; } - Optional findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) override + std::optional findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) override { LOCK(cs_main); CBlockIndex* block = ::ChainActive().FindEarliestAtLeast(time, height); @@ -192,9 +192,9 @@ public: if (hash) *hash = block->GetBlockHash(); return block->nHeight; } - return nullopt; + return std::nullopt; } - Optional findPruned(int start_height, Optional stop_height) override + std::optional findPruned(int start_height, std::optional stop_height) override { LOCK(cs_main); if (::fPruneMode) { @@ -206,9 +206,9 @@ public: block = block->pprev; } } - return nullopt; + return std::nullopt; } - Optional findFork(const uint256& hash, Optional* height) override + std::optional findFork(const uint256& hash, std::optional* height) override { LOCK(cs_main); const CBlockIndex* block = LookupBlockIndex(hash); @@ -223,20 +223,20 @@ public: if (fork) { return fork->nHeight; } - return nullopt; + return std::nullopt; } CBlockLocator getTipLocator() override { LOCK(cs_main); return ::ChainActive().GetLocator(); } - Optional findLocatorFork(const CBlockLocator& locator) override + std::optional findLocatorFork(const CBlockLocator& locator) override { LOCK(cs_main); if (CBlockIndex* fork = FindForkInGlobalIndex(::ChainActive(), locator)) { return fork->nHeight; } - return nullopt; + return std::nullopt; } bool checkFinalTx(const CTransaction& tx) override { diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 7513c4c2ff..7309cb177d 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -5,11 +5,11 @@ #ifndef BITCOIN_INTERFACES_CHAIN_H #define BITCOIN_INTERFACES_CHAIN_H -#include // For Optional and nullopt #include // For CTransactionRef #include // For util::SettingsValue #include +#include #include #include #include @@ -76,12 +76,12 @@ public: //! Get current chain height, not including genesis block (returns 0 if //! chain only contains genesis block, nullopt if chain does not contain //! any blocks) - virtual Optional getHeight() = 0; + virtual std::optional getHeight() = 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. - virtual Optional getBlockHeight(const uint256& hash) = 0; + virtual std::optional getBlockHeight(const uint256& hash) = 0; //! Get block hash. Height must be valid or this function will abort. virtual uint256 getBlockHash(int height) = 0; @@ -102,11 +102,11 @@ public: //! given height, or nullopt if there is no block with a high enough //! timestamp and height. Also return the block hash as an optional output parameter //! (to avoid the cost of a second lookup in case this information is needed.) - virtual Optional findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) = 0; + virtual std::optional findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) = 0; //! Return height of last block in the specified range which is pruned, or //! nullopt if no block in the range is pruned. Range is inclusive. - virtual Optional findPruned(int start_height = 0, Optional stop_height = nullopt) = 0; + virtual std::optional findPruned(int start_height = 0, std::optional stop_height = std::nullopt) = 0; //! Return height of the specified block if it is on the chain, otherwise //! return the height of the highest block on chain that's an ancestor @@ -114,7 +114,7 @@ public: //! Also return the height of the specified block as an optional output //! parameter (to avoid the cost of a second hash lookup in case this //! information is desired). - virtual Optional findFork(const uint256& hash, Optional* height) = 0; + virtual std::optional findFork(const uint256& hash, std::optional* height) = 0; //! Get locator for the current chain tip. virtual CBlockLocator getTipLocator() = 0; @@ -122,7 +122,7 @@ public: //! Return height of the highest block on chain in common with the locator, //! which will either be the original block used to create the locator, //! or one of its ancestors. - virtual Optional findLocatorFork(const CBlockLocator& locator) = 0; + virtual std::optional findLocatorFork(const CBlockLocator& locator) = 0; //! Check if transaction will be final given chain height current time. virtual bool checkFinalTx(const CTransaction& tx) = 0; diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index bc01312035..198ed10176 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -369,7 +369,7 @@ public: if (mi == m_wallet->mapWallet.end()) { return false; } - if (Optional height = m_wallet->chain().getHeight()) { + if (std::optional height = m_wallet->chain().getHeight()) { block_time = m_wallet->chain().getBlockTime(*height); } else { block_time = -1; diff --git a/src/llmq/blockprocessor.h b/src/llmq/blockprocessor.h index 18a3b0e476..904f0de049 100644 --- a/src/llmq/blockprocessor.h +++ b/src/llmq/blockprocessor.h @@ -13,6 +13,7 @@ #include #include #include + #include class CNode; diff --git a/src/llmq/snapshot.cpp b/src/llmq/snapshot.cpp index 9d570d7c6d..dee8cc1a81 100644 --- a/src/llmq/snapshot.cpp +++ b/src/llmq/snapshot.cpp @@ -291,8 +291,8 @@ bool BuildQuorumRotationInfo(const CGetQuorumRotationInfo& request, CQuorumRotat response.mnListDiffAtHMinus4C = std::move(mn4c); } else { response.extraShare = false; - response.quorumSnapshotAtHMinus4C = std::nullopt; - response.mnListDiffAtHMinus4C = std::nullopt; + response.quorumSnapshotAtHMinus4C.reset(); + response.mnListDiffAtHMinus4C.reset(); } std::set snapshotHeightsNeeded; diff --git a/src/llmq/utils.h b/src/llmq/utils.h index 2c4505ed54..35cfcae5eb 100644 --- a/src/llmq/utils.h +++ b/src/llmq/utils.h @@ -11,9 +11,10 @@ #include #include #include +#include + #include #include -#include class CConnman; class CBlockIndex; diff --git a/src/miner.cpp b/src/miner.cpp index 937f11f417..e431d47f8a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -107,9 +107,6 @@ void BlockAssembler::resetBlock() nFees = 0; } -Optional BlockAssembler::m_last_block_num_txs{nullopt}; -Optional BlockAssembler::m_last_block_size{nullopt}; - std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn) { int64_t nTimeStart = GetTimeMicros(); diff --git a/src/miner.h b/src/miner.h index 28f8472b14..eba984efd3 100644 --- a/src/miner.h +++ b/src/miner.h @@ -6,12 +6,12 @@ #ifndef BITCOIN_MINER_H #define BITCOIN_MINER_H -#include #include #include #include #include +#include #include #include @@ -178,8 +178,8 @@ public: /** Construct a new block template with coinbase to scriptPubKeyIn */ std::unique_ptr CreateNewBlock(const CScript& scriptPubKeyIn); - static Optional m_last_block_num_txs; - static Optional m_last_block_size; + inline static std::optional m_last_block_num_txs{}; + inline static std::optional m_last_block_size{}; private: // utility functions diff --git a/src/net.cpp b/src/net.cpp index 9da63bda20..ce02a27928 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -662,7 +662,7 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete if (m_deserializer->Complete()) { // decompose a transport agnostic CNetMessage from the deserializer uint32_t out_err_raw_size{0}; - Optional result{m_deserializer->GetMessage(nTimeMicros, out_err_raw_size)}; + std::optional result{m_deserializer->GetMessage(nTimeMicros, out_err_raw_size)}; if (!result) { // Message deserialization failed. Drop the message but don't disconnect the peer. // store the size of the corrupt message @@ -780,10 +780,10 @@ const uint256& V1TransportDeserializer::GetMessageHash() const return data_hash; } -Optional V1TransportDeserializer::GetMessage(int64_t time, uint32_t& out_err_raw_size) +std::optional V1TransportDeserializer::GetMessage(int64_t time, uint32_t& out_err_raw_size) { // decompose a single CNetMessage from the TransportDeserializer - Optional msg(std::move(vRecv)); + std::optional msg(std::move(vRecv)); // store command string, time, and sizes msg->m_command = hdr.GetCommand(); @@ -804,12 +804,12 @@ Optional V1TransportDeserializer::GetMessage(int64_t time, uint32_t HexStr(Span(hdr.pchChecksum, hdr.pchChecksum+CMessageHeader::CHECKSUM_SIZE)), m_node_id); out_err_raw_size = msg->m_raw_message_size; - msg = nullopt; + msg.reset(); } else if (!hdr.IsCommandValid()) { LogPrint(BCLog::NET, "HEADER ERROR - COMMAND (%s, %u bytes), peer=%d\n", hdr.GetCommand(), msg->m_message_size, m_node_id); out_err_raw_size = msg->m_raw_message_size; - msg = nullopt; + msg.reset(); } // Always reset the network deserializer (prepare for the next message) diff --git a/src/net.h b/src/net.h index 9a6778b030..f94181c5a7 100644 --- a/src/net.h +++ b/src/net.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -36,6 +35,7 @@ #include #include #include +#include #include #ifndef WIN32 @@ -854,7 +854,7 @@ public: // read and deserialize data virtual int Read(const char *data, unsigned int bytes) = 0; // decomposes a message from the context - virtual Optional GetMessage(int64_t time, uint32_t& out_err) = 0; + virtual std::optional GetMessage(int64_t time, uint32_t& out_err) = 0; virtual ~TransportDeserializer() {} }; @@ -913,7 +913,7 @@ public: if (ret < 0) Reset(); return ret; } - Optional GetMessage(int64_t time, uint32_t& out_err_raw_size) override; + std::optional GetMessage(int64_t time, uint32_t& out_err_raw_size) override; }; /** The TransportSerializer prepares messages for the network transport diff --git a/src/optional.h b/src/optional.h deleted file mode 100644 index c42c742767..0000000000 --- a/src/optional.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2017 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#ifndef BITCOIN_OPTIONAL_H -#define BITCOIN_OPTIONAL_H - -#include -#include - -//! Substitute for C++17 std::optional -//! DEPRECATED use std::optional in new code. -template -using Optional = std::optional; - -//! Substitute for C++17 std::nullopt -//! DEPRECATED use std::nullopt in new code. -static auto& nullopt = std::nullopt; - -#endif // BITCOIN_OPTIONAL_H diff --git a/src/psbt.h b/src/psbt.h index fbd066f1fd..7cd12568c4 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -7,13 +7,14 @@ #include #include -#include #include #include #include #include