From ebc4ab721b0371c0ef217c0f5bd7d42613e951e6 Mon Sep 17 00:00:00 2001 From: fanquake Date: Mon, 15 Mar 2021 11:59:05 +0800 Subject: refactor: post Optional<> removal cleanups --- src/bench/wallet_balance.cpp | 3 ++- src/bitcoin-cli.cpp | 2 +- src/bitcoind.cpp | 1 + src/interfaces/chain.h | 2 +- src/miner.cpp | 3 --- src/miner.h | 6 +++--- src/net.cpp | 4 ++-- src/net.h | 2 +- src/net_processing.cpp | 1 + src/node/interfaces.cpp | 1 + src/node/psbt.h | 8 +++++--- src/psbt.h | 3 ++- src/script/descriptor.cpp | 1 + src/script/descriptor.h | 2 +- src/test/descriptor_tests.cpp | 1 + src/test/fuzz/deserialize.cpp | 2 +- src/test/fuzz/net.cpp | 2 +- src/test/fuzz/p2p_transport_deserializer.cpp | 1 + src/test/fuzz/psbt.cpp | 2 +- src/test/fuzz/script_descriptor_cache.cpp | 2 +- src/test/net_tests.cpp | 2 +- src/test/util_tests.cpp | 2 +- src/txmempool.cpp | 5 +++-- src/txmempool.h | 2 +- src/util/system.h | 2 +- src/util/tokenpipe.cpp | 1 + src/validation.cpp | 2 +- src/validation.h | 5 ++--- src/wallet/coincontrol.h | 3 ++- src/wallet/coinselection.cpp | 3 ++- src/wallet/db.h | 2 +- src/wallet/rpcdump.cpp | 2 +- src/wallet/rpcwallet.cpp | 4 ++-- src/wallet/scriptpubkeyman.cpp | 2 ++ src/wallet/wallet.cpp | 4 ++-- src/wallet/wallet.h | 1 + src/wallet/walletdb.cpp | 1 + 37 files changed, 53 insertions(+), 39 deletions(-) diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index 867be7296b..d7cc167885 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -5,13 +5,14 @@ #include #include #include -#include #include #include #include #include #include +#include + static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_watchonly, const bool add_mine) { const auto test_setup = MakeNoLogFileContext(); diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index de3c73c78a..ecd08c62eb 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -24,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 32f06aec2c..1b4ca3e9a8 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -25,6 +25,7 @@ #include #include +#include const std::function G_TRANSLATION_FUN = nullptr; UrlDecodeFn* const URL_DECODE = urlDecode; diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 50294ee375..3395741b1b 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -5,12 +5,12 @@ #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 #include diff --git a/src/miner.cpp b/src/miner.cpp index 53404e2b9d..fe7a54c052 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -96,9 +96,6 @@ void BlockAssembler::resetBlock() nFees = 0; } -std::optional BlockAssembler::m_last_block_num_txs{std::nullopt}; -std::optional BlockAssembler::m_last_block_weight{std::nullopt}; - std::unique_ptr BlockAssembler::CreateNewBlock(CChainState& chainstate, const CScript& scriptPubKeyIn) { int64_t nTimeStart = GetTimeMicros(); diff --git a/src/miner.h b/src/miner.h index 236d792f1e..023635814c 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 @@ -160,8 +160,8 @@ public: /** Construct a new block template with coinbase to scriptPubKeyIn */ std::unique_ptr CreateNewBlock(CChainState& chainstate, const CScript& scriptPubKeyIn); - static std::optional m_last_block_num_txs; - static std::optional m_last_block_weight; + inline static std::optional m_last_block_num_txs{}; + inline static std::optional m_last_block_weight{}; private: // utility functions diff --git a/src/net.cpp b/src/net.cpp index fb8e06d14b..6a2469f950 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -39,6 +38,7 @@ #include #include #include +#include #include #include @@ -752,7 +752,7 @@ std::optional V1TransportDeserializer::GetMessage(const std::chrono 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 = std::nullopt; + msg.reset(); } // Always reset the network deserializer (prepare for the next message) diff --git a/src/net.h b/src/net.h index 2eab20f243..48d37084a0 100644 --- a/src/net.h +++ b/src/net.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +34,7 @@ #include #include #include +#include #include #include diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 4d9dc2204d..b600cc3a1a 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -34,6 +34,7 @@ #include #include +#include #include /** How long to cache transactions in mapRelay for normal relay */ diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 7a4fa0a613..50c8c29175 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -50,6 +50,7 @@ #endif #include +#include #include using interfaces::BlockTip; diff --git a/src/node/psbt.h b/src/node/psbt.h index 009e0941e1..def4385c09 100644 --- a/src/node/psbt.h +++ b/src/node/psbt.h @@ -7,6 +7,8 @@ #include +#include + /** * Holds an analysis of one input from a PSBT */ @@ -28,9 +30,9 @@ struct PSBTAnalysis { std::optional estimated_vsize; //!< Estimated weight of the transaction std::optional estimated_feerate; //!< Estimated feerate (fee / weight) of the transaction std::optional fee; //!< Amount of fee being paid by the transaction - std::vector inputs; //!< More information about the individual inputs of the transaction - PSBTRole next; //!< Which of the BIP 174 roles needs to handle the transaction next - std::string error; //!< Error message + std::vector inputs; //!< More information about the individual inputs of the transaction + PSBTRole next; //!< Which of the BIP 174 roles needs to handle the transaction next + std::string error; //!< Error message void SetInvalid(std::string err_msg) { diff --git a/src/psbt.h b/src/psbt.h index 319eb48cb0..96ae39fdb8 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -7,13 +7,14 @@ #include #include -#include #include #include #include #include